Пример #1
0
void RenderSystem::receive(const AnimationChangedMessage& msg)
{
    auto animatedSprite = getAnimatedSprite(msg.entity);
    auto render = entityx::Entity(msg.entity).component<RenderComponent>();
    if(render->currentAnimation != animatedSprite->getCurrentAnimation())
    {
        std::string oldAnimation = animatedSprite->getCurrentAnimation();
        animatedSprite->setCurrentAnimation(render->currentAnimation);

        if(render->onAnimationChangedFunc.valid())
            render->onAnimationChangedFunc.call(EntityHandle(msg.entity), oldAnimation, render->currentAnimation);
    }
}
    void PlayerComponent::onPostSimulationUpdate(float elapsedTime)
    {
        // Play animation if different
        if(_state != _previousState)
        {
            _animations[_previousState]->stop();
            getCurrentAnimation()->play();
        }

        // Scale the animation speed using the movement scale
        if(_state == State::Walking || _state == State::Climbing)
        {
            getCurrentAnimation()->setSpeed(fabs(_state == State::Climbing ? _verticalMovementScale : _horizontalMovementScale));
        }

        _previousState = _state;

        getCurrentAnimation()->update(elapsedTime);
    }
Пример #3
0
void EnemyObject::update(float tick_ms, GameLevel* game_level)
{
	getCurrentAnimation()->update(tick_ms);
	m_EnemyBehavior(tick_ms, game_level);

	// Just for demonstration, set up a behavior where the
	// enemy fires a projectile at the player.
	m_EnemyBehavior = [this](float tick_ms, GameLevel* level) {
		sf::Clock& clock = this->m_Clock;
		sf::Int32 delayBetweenBulletsInMs = 600;

		if( clock.getElapsedTime().asMilliseconds() > delayBetweenBulletsInMs )
		{
			clock.restart();
		}
		else
		{
			return;
		}

		float firingDistance = 1000;
		const sf::Vector2f& playerLocation = level->getPlayerLocation();
		
		float xdiff = (this->getLocation().x - playerLocation.x);
		float ydiff = (this->getLocation().y - playerLocation.y);
		float dist = sqrt(xdiff*xdiff+ydiff*ydiff);
		sf::Vector2f projectileHeading(xdiff/dist, ydiff/dist);

		if(dist <= firingDistance)
		{
			ProjectileObject* projectile = new ProjectileObject( ProjectileType::PROJECTILE_BASIC, CollidesWith::PLAYERS, this );
			projectile->init(getDispatcher(), m_GameLevel);
			projectile->setLocation(getLocation().x, getLocation().y);

			projectile->setVelocity( -projectileHeading.x * 300, -projectileHeading.y * 300);

			ProjectileFiredEvent e(projectile);
			this->getDispatcher()->dispatchEvent(&e);
		}
	};
}
Пример #4
0
const Recti & AnimationMgr::getCurrentTextureRect() const
{
   return getCurrentAnimation()->getCurrentFrameRect();
}
Пример #5
0
const sf::Texture * AnimationMgr::getCurrentTexture() const
{
   return getCurrentAnimation()->getCurrentTexture();
}
Пример #6
0
void AnimationMgr::update()
{
   getCurrentAnimation()->update();
}