Ejemplo n.º 1
0
void Bulldog_Physics::Move( Component_Game_Actor& actor, Map &map, float timeStep )
{        
    int previousx = tempNewX;
    int previousy = tempNewY;
    //Temporary holdings for the speeds
    tempNewX += (int)xVelocity * timeStep;
    tempNewY += (int)yVelocity * timeStep;    

    actorBox.x = tempNewX;
    actorBox.y = tempNewY;

    //moving right
    if( xVelocity > 0 )
    {
        //Check out of bounds right
        if( tempNewX + actorBox.w > map.GetMapWidth() ) {
            tempNewX = map.GetMapWidth() - actor.GetGraphics()->GetDestination().w;
            StopX();
            SetXVelocity( NEGATIVE_MOVEMENT );
        }
    }

    //moving left
    else if( xVelocity < 0 )
    {
        //Check out of bounds left
        if( tempNewX < 0 ) {           
            tempNewX = 0;
            StopX();
            SetXVelocity( POSITIVE_MOVEMENT );
        }
    }

    actor.GetGraphics()->SetDestinationX( tempNewX );
    actor.GetGraphics()->SetDestinationY( tempNewY );
}
Ejemplo n.º 2
0
void Corgi_Physics::Move( Component_Game_Actor& actor, Map &map, float timeStep )
{        
    int previousx = tempNewX;
    int previousy = tempNewY;
    //Temporary holdings for the speeds
    tempNewX += (int)xVelocity * timeStep;
    tempNewY += (int)yVelocity * timeStep;    

    actorBox.x = tempNewX;
    actorBox.y = tempNewY;

    //moving right
    if( xVelocity > 0 )
    {
        //Check out of bounds right
        if( tempNewX + actorBox.w < map.GetMapWidth() ) {
            //Get the tile where the actor is
            xTile       = ( tempNewX + actorBox.w ) / TILE_SIZE;
            yTile       = tempNewY / TILE_SIZE;
            int midTile = ( tempNewY + ( actorBox.h / 2 ) ) / TILE_SIZE;
            //int botTile = ( tempNewY + actorBox.h - 1 ) / TILE_SIZE;
            //Check the tile just to the right
            if( map.GetCollision( xTile, yTile ) || map.GetCollision( xTile, midTile ) ) {
                //Check box collision for all tiles in front of the character.
                if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, yTile ), actorBox ) ) {
                    actorBox.x = previousx;
                    tempNewX = previousx;
                    StopX();
                    SetXVelocity( NEGATIVE_MOVEMENT );
                } else if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, midTile ), actorBox ) ) {
                    actorBox.x = previousx;
                    tempNewX = previousx;
                    StopX();
                    SetXVelocity( NEGATIVE_MOVEMENT );
                } /*else if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, botTile ), actorBox ) ) {
                    actorBox.x = previousx;
                    tempNewX = previousx;
                } */
            }
            
        } else {
            tempNewX = map.GetMapWidth() - actor.GetGraphics()->GetDestination().w - TILE_SIZE;
            StopX();
            SetXVelocity( NEGATIVE_MOVEMENT );
        }
    }

    //moving left
    else if( xVelocity < 0 )
    {
        //Check out of bounds left
        if( tempNewX > 0 ) {
            //Get the tile where the actor is
            xTile       = tempNewX / TILE_SIZE;
            yTile       = tempNewY / TILE_SIZE;
            int midTile = ( tempNewY + ( actorBox.h / 2 ) ) / TILE_SIZE;
            //int botTile = ( tempNewY + actorBox.h - 1) / TILE_SIZE;
            //Check the tile just to the right
            if( map.GetCollision( xTile, yTile ) || map.GetCollision( xTile, midTile ) ) {
                //Check box collision for all tiles in front of the character.a
                if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, yTile ), actorBox ) ) {
                    actorBox.x = previousx;
                    tempNewX = previousx;
                    StopX();
                    SetXVelocity( POSITIVE_MOVEMENT );
                } else if ( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, midTile ), actorBox ) ) {
                    actorBox.x = previousx;
                    tempNewX = previousx;
                    StopX();
                    SetXVelocity( POSITIVE_MOVEMENT );
                }/* else if ( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, botTile ), actorBox ) ) {
                    actorBox.x = previousx;
                    tempNewX = previousx;
                }  */ 
            }
        } else  {
            tempNewX = 0;
            StopX();
            SetXVelocity( POSITIVE_MOVEMENT );
            }
    }

    //Falling
    //if( yVelocity > 0 ) {
        //Check bounds bottom
        if( tempNewY + actor.GetGraphics()->GetDestination().h < SCREEN_HEIGHT ) {
            // left side of the sprite underneath
            yTile = ( tempNewY + actorBox.h ) / TILE_SIZE;
            xTile = tempNewX / TILE_SIZE;
            //middle underneath
            int midX   = ( tempNewX + ( actorBox.w / 2 ) ) / TILE_SIZE;
            // right side of the sprite underneath
            int rightX = ( tempNewX + actorBox.w ) / TILE_SIZE;
            //Check both undersides of the sprite to see if it should stop falling
            if( map.GetCollision( xTile, yTile ) || map.GetCollision( rightX, yTile ) || map.GetCollision( midX, yTile ) ) {
                if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, yTile ), actorBox ) ) {
                        actor.SetState( ACTOR_STAND );
                        jumpTotal = 0;
                        tempNewY = map.GetTileDest( xTile, yTile ).y - actorBox.h;
                        actorBox.y = tempNewY;
                        StopY();
                } else if( Game_Collision::CheckCollisionBox( map.GetTileDest( rightX, yTile ), actorBox ) ) {
                        actor.SetState( ACTOR_STAND );
                        jumpTotal = 0;
                        tempNewY = map.GetTileDest( rightX, yTile ).y - actorBox.h;
                        actorBox.y = tempNewY;
                        StopY();
                } else if( Game_Collision::CheckCollisionBox( map.GetTileDest( midX, yTile ), actorBox ) ) {
                        actor.SetState( ACTOR_STAND );
                        jumpTotal = 0;
                        tempNewY = map.GetTileDest( midX, yTile ).y - actorBox.h;
                        actorBox.y = tempNewY;
                        StopY();
                }
            } else {
                yVelocity = MAX_FALL;
            }
        //Check bounds top
        } else if( tempNewY < 0 ) {
            tempNewY = 0;
            StopY();
        }
    //}

    //Jumping up
    if( tempNewY < 0 ) {
        tempNewY = 0;

        StopY();
    }    

    actor.GetGraphics()->SetDestinationX( tempNewX );
    actor.GetGraphics()->SetDestinationY( tempNewY );
}
Ejemplo n.º 3
0
void Prisoner::Tick(double deltaTime)
{
	//Key input setting the speed.	

	m_Pos.x += m_Velocity.x*deltaTime;
	  
	m_Pos.y += m_Velocity.y*deltaTime;

	//Positions the hitboxes

	m_HitRegionPtr->SetPos(m_Pos);	

	switch (m_CurrentState) 
	{

	case STATE_BOUND : 

		if (m_SlowDownAnimations>0)
		{
			m_SlowDownAnimations=RESET_SLOW_DOWN;
			m_TickCount+=1;

			if (m_TickCount==BOUND_FRAMES)
			{
				m_TickCount=0;

				//Makes the prisoner randomly wave to the player
				int urgeToWave=rand()%5;
				if (urgeToWave==0)
				{
					m_CurrentState = STATE_WAVING;
				}
			}

			
		}		

		m_SlowDownAnimations+=BOUND_ANIMATION_SPEED*deltaTime;		

		break;

	case STATE_WAVING : 

		if (m_SlowDownAnimations>0)
		{
			m_SlowDownAnimations=RESET_SLOW_DOWN;
			m_TickCount+=1;

			if (m_TickCount==WAVING_FRAMES)
			{
				m_TickCount=0;
				m_CurrentState = STATE_BOUND;
			}
		}
		m_SlowDownAnimations+=WAVING_ANIMATION_SPEED*deltaTime;	

		break;

	case STATE_ESCAPING : 
		
		if (m_SlowDownAnimations>0)
		{
			m_SlowDownAnimations=RESET_SLOW_DOWN;
			m_TickCount+=1;

			if (m_TickCount==ESCAPING_FRAMES)
			{
				m_TickCount=0;
				
				m_CurrentState=STATE_WALKING;
			}			
			

		}
		m_SlowDownAnimations+=ESCAPING_ANIMATION_SPEED*deltaTime;	
        
		break;
		
	case STATE_WALKING : 
		
		if (m_SlowDownAnimations>0)
		{
			m_SlowDownAnimations=RESET_SLOW_DOWN;
			SetXVelocity(-45);
			m_TickCount+=1;

			if (m_TickCount>=WALKING_FRAMES+1)
			{
				m_TickCount=0;
			}			
			
			//Code to show reward animations
			int rewardPlayer=rand()%5;
			if (rewardPlayer==0)
			{
				m_TickCount=0;
				m_CurrentState = STATE_REWARDING;
			}

		}
		m_SlowDownAnimations+=WALKING_ANIMATION_SPEED*deltaTime;	
	
		break;

	case STATE_REWARDING : 
		
		if (m_SlowDownAnimations>0)
		{
			m_SlowDownAnimations=RESET_SLOW_DOWN;
			SetXVelocity(0);
			m_TickCount+=1;

			if (m_TickCount==REWARDING_FRAMES)
			{
				m_TickCount=0;
				m_CurrentState = STATE_RUNNING;
			}			
			
		}
		m_SlowDownAnimations+= REWARDING_ANIMATION_SPEED*deltaTime;	
	
		break;

	case STATE_RUNNING : 
		
		if (m_SlowDownAnimations>0)
		{
			m_SlowDownAnimations=RESET_SLOW_DOWN;
			SetXVelocity(-150);
			m_TickCount+=1;

			if (m_TickCount==RUNNING_FRAMES)
			{
				m_TickCount=0;
			}			
			
		}
		m_SlowDownAnimations+=RUNNING_ANIMATION_SPEED*deltaTime;	
	
		break;

	}


}