Пример #1
0
void RenderComponent::VUpdate()
{
	/*

		All of this code must go!!! This is shit! Rewrite animation system as a seperate component, starting with a virtual base
		class (AnimationComponent) that can then fork off into a bunch of other more specific animation types (e.g. HumanoidAnimationComponent,
		MachineAnimationComponent, ParticleAnimationComponent, etc.).

	*/
	if(_animated)
	{
		PhysicsComponent* physicsComponent = GetOwner()->GetComponent<PhysicsComponent>(COMPONENT_PHYSICS);

		const uint UP = 1, DOWN = 0, RIGHT = 2, LEFT = 3;
		int direction = -1;// By default, don't change

		if(physicsComponent->GetVelocity().x > 0.5)
		{
			direction = RIGHT;
		}
		else if(physicsComponent->GetVelocity().x < -0.5)
		{
			direction = LEFT;
		}
		else if(physicsComponent->GetVelocity().y > 0.5)
		{
			direction = DOWN;
		}
		else if(physicsComponent->GetVelocity().y < -0.5)
		{
			direction = UP;
		}

		if(direction != -1)// If the texture should change...
		{
			_textureY = direction*(_textureHeight/4);
			_textureX = _currentAnimationFrame*(_textureWidth/3);

			if(SDL_GetTicks() - _lastAnimationChange >= (100))
			{
				_currentAnimationFrame++;
				if(_currentAnimationFrame == 3)
					_currentAnimationFrame = 0;

				_lastAnimationChange = SDL_GetTicks();
			}
		}
		else
		{
			_textureX = 0;
		}
	}
}
void LocomotionSystem::Update( float i_dt )
{
    for ( std::map<EntityHandle, Component*>::iterator it = m_components.begin(); it != m_components.end(); it++ )
    {
        LocomotionComponent* pComponent = (LocomotionComponent*) it->second;
        if ( pComponent )
        {
            if ( pComponent->m_locomotionMode )
            {
                pComponent->m_locomotionMode->Update( i_dt );
            }
            PhysicsComponent* pPhysicsComponent = EntitySystem::GetInstance()->GetComponent<PhysicsComponent>( pComponent->m_entityHandle );
            if ( pPhysicsComponent )
            {
                float yVel = pPhysicsComponent->GetVelocity().y;
                JumpState pJumpState;
                if ( yVel > 0.5f )
                {
                    pJumpState = JumpState::JUMPING;
                }
                else if ( yVel < 0.5f )
                {
                    pJumpState = JumpState::FALLING;
                }
                else if ( yVel == 0.0f )
                {
                    pJumpState = JumpState::NOT_JUMPING;
                }
                
                if ( pJumpState == JumpState::FALLING && pComponent->m_jumpState == JumpState::JUMPING )
                {
                    EventManager::GetInstance()->SendEvent( "VelocityApexReached", &pComponent->m_entityHandle );
                }
                
                pComponent->m_jumpState = pJumpState;
            }
        }
    }
}