Ejemplo n.º 1
0
void cBicho::PickStar() {
    if (IsDying()) {
        return;
    }
    starActivated = true;
    starTime = 0;
}
Ejemplo n.º 2
0
bool cBicho::Collides(const cRect &rect) {
    if (IsDying()) {
        return false;
    }
    return (y + h > rect.bottom) && (y < rect.top) &&
           (x + w > rect.left) && (x < rect.right);
}
Ejemplo n.º 3
0
int cBicho::GetAttack() const {
    if (IsDying() || IsDead()) {
        return 0;
    }
    if (starActivated) {
        return 1337;
    }
    return attack;
}
Ejemplo n.º 4
0
void cBicho::Logic(const cMap &map) {
    UpdateProtected();
    if (IsDying()) {
        if (++dieTime > maxDieTime) {
            Die();
        }
        return;
    }
    SpecificLogic(map);
}
Ejemplo n.º 5
0
void Player::Draw() {
  TexCoords tc = Engine::Get().Scripts()->GetPlayerSprite(GetType(), 
                                                          GetDirection(), 
                                                          IsDying(), 
                                                          SDL_GetTicks() - m_current_action_start_time);

//   std::cerr << "type = " << GetType() << ", direction = " << GetDirection().x() << ", " << GetDirection().y()
// 	    << ", is dying = " << IsDying() << "dt = " << SDL_GetTicks() - m_current_action_start_time << "\n";
//   std::cerr << "tc = " << tc.left << ", " << tc.bottom << ", " << tc.width << ", " << tc.height << "\n";

  Engine::Get().Renderer()->DrawSprite(tc, GetPosition());
  if (g_render_aabbs)
    Engine::Get().Renderer()->DrawAABB(GetAABB());
}
Ejemplo n.º 6
0
bool CCrate::Die()
{
	if (!IsDying())
	{
		ChangeAnimation(death);
		dying = true;
	}
	timeToDie -= g_time;
	if (timeToDie > 0)
	{
		return false;
	}
	else return true;
}
Ejemplo n.º 7
0
void Unit::OnCollide(Entity& entity, const sf::FloatRect& overlap)
{
	if (IsDying() || entity.IsDying())
	{
		return;
	}
	switch (entity.GetCollideEffect())
	{
		case FX_REJECTION:
			// repoussement horizontal ?
			if (overlap.GetHeight() < overlap.GetWidth())
			{
				// vers le haut ou le bas
				knocked_dir_ = entity.GetPosition().y > GetPosition().y ? UP : DOWN;
			}
			else // vertical
			{
				// vers la gauche ou la droite
				knocked_dir_ = entity.GetPosition().x > GetPosition().x ? LEFT : RIGHT;
			}
			knocked_start_ = Game::GetInstance().GetElapsedTime();
			knocked_speed_ = KNOCK_INITIAL_SPEED;
			is_knocked_ = true;
			break;

		case FX_STOP:
			{
				Direction dir;
				float dist;
				if (overlap.GetHeight() < overlap.GetWidth())
				{
					dir = entity.GetPosition().y > GetPosition().y ? UP : DOWN;
					dist = overlap.GetHeight();
				}
				else
				{
					dir = entity.GetPosition().x > GetPosition().x ? LEFT : RIGHT;
					dist = overlap.GetWidth();
				}
				Move(dir, dist);
			}
			break;
		case FX_NOTING:
			break;
	}
}
Ejemplo n.º 8
0
bool cBicho::Move(const cMap& map, Direction dir, int sceneX, int sceneY) {
    if (IsDying() || IsDead()) {
        return false;
    }
	float &axis = (dir == Direction::Left || dir == Direction::Right) ? x : y;
	int mult = 1;
	bool canMove = true;
	if (dir == Direction::Left || dir == Direction::Down) {
		mult = -1;
	}
	// What's next tile
	if (int(axis) % TILE_SIZE == 0) {
		float aux = axis;
		axis += stepLength * mult;
		if (ReachesMapLimit(map, sceneX, sceneY)) {
			canMove = ReachLimit(dir);
			axis = aux;
		} else if (CollidesMap(map)) {
			axis = aux;
			state = State::Look;
			canMove = false;
		}
	} else {
		// Advance
		axis += stepLength * mult;
	}
	// Always set direction
	direction = dir;
	if (canMove && state != State::Walk) {
		state = State::Walk;
	}
    // Calculate if entering DungeonDoor from below.
    int cellx = x/TILE_SIZE;
    int celly = y/TILE_SIZE;
    if (!ReachesMapLimit(map, sceneX, sceneY) && map.DungeonDoor(cellx, celly)) {
        InDungeonDoor();
    }


	return canMove;
}
Ejemplo n.º 9
0
void FolderWatcher::Run ()
{
    Assert (_folderEvent.IsValid ());
    HANDLE objects [2];
    objects [0] = _folderEvent.ToNative ();
    objects [1] = _event.ToNative ();
    for (;;)
    {
        // Wait for change notification
        DWORD waitStatus = ::WaitForMultipleObjects (2, objects, FALSE, INFINITE);
        if (waitStatus == WAIT_OBJECT_0)
        {
            if (IsDying ())
                return;
			//------------------------
			Win::Lock lock (_critSect);
			LokPostChange (_folderEvent.GetDir ());

			// Continue change notification
			if (!_folderEvent.ContinueNotification ())
			{
				// Continuation failed
				return;
			}
			//------------------------
        }
        else if (WAIT_OBJECT_0 + 1 == waitStatus)
        {
            // End of watch duty - _event was released
            return;
        }
        else
        {
            // Wait failed
			throw Win::Exception ("Failed wait for changes in folder", 
									_folderEvent.GetDir ().c_str ());
			return;
        }
    }
}
Ejemplo n.º 10
0
void MultiFolderWatcher::Run ()
{
    std::vector<HANDLE> objects;			// events for watched folders
	std::vector<int>	objectToFolderIdx; // there are more folders than object
    for (;;)
    {
		{
			//------------------------
			Win::Lock lock (_critSect);
			if (_refresh)
			{
				// Remove stopped watchers from the watch list
				size_t i = 0;
				while (i < _folders.size ())
				{
					if (_folders [i]->IsMarkedStopWatching ())
					{
						_folders.erase (i);	// Removes item and moves up items after the removed one
					}
					else
						++i;
				}
				// Copy file change events for watched folders
				// and close change events for not watched folders
				objects.clear ();
				objectToFolderIdx.clear ();
				for (size_t i = 0; i < _folders.size (); ++i)
				{
					WatchedFolder * folder = _folders [i];
					if (objects.size () < MAXIMUM_WAIT_OBJECTS - 1)
					{
						objects.push_back (folder->GetEvent ());
						objectToFolderIdx.push_back (i);
					}
					else
					{
						folder->StopWatching ();
						// During next refresh, change event will be closed
					}
				}
				Assert (objects.size () == objectToFolderIdx.size ());
				objects.push_back (_event.ToNative ());
				Assert (objects.size () <= MAXIMUM_WAIT_OBJECTS);
				_refresh = false;
			}
			//------------------------
		}
        //----- Wait for change notification -------
        DWORD waitStatus = ::WaitForMultipleObjects (objects.size (), &(objects [0]), FALSE, INFINITE);
		if (IsDying ())
			return;

		if (waitStatus == WAIT_TIMEOUT)
			continue;
		if (waitStatus == WAIT_FAILED)
			throw Win::Exception ("Directory watcher failed");
        unsigned int eventIdx = waitStatus - WAIT_OBJECT_0;
		if (eventIdx >= objects.size ())
			throw Win::Exception ("Unexpected status in directory watcher");
		Assert (objects.size () == objectToFolderIdx.size () + 1);
        if (eventIdx < objectToFolderIdx.size ())
        {
            // Folder change notification
			//------------------------
			Win::Lock lock (_critSect);
			// Translate wait event index to folder index
			unsigned int idx = objectToFolderIdx [eventIdx];
			Assert (0 <= idx && idx < _folders.size ());
			WatchedFolder * folder = _folders [idx];
			if (!folder->IsMarkedStopWatching ())
			{
				LokPostChange (folder->GetDir ());
				// Continue change notification
				if (!folder->ContinueNotification ())
				{
					// Continuation failed -- stop watching folder
					folder->MarkStopWatching ();
					_refresh = true;	// Refresh the watch list
				}
			}
			else
			{
				// Refresh the watch list
				_refresh = true;
			}
			//------------------------
        }
    }
}
Ejemplo n.º 11
0
void HealthPickup::LogicUpdate(const float Dt)
{
    if (!IsDying() && m_Timer.IsExpired()) {
        Destroy();
    }
}