Hey guys I'm stuck trying to implement a jump when the up key is pressed with c++ in Visual Studio.I would like momentum as in while in air you can still use the right and left keys to move eg Super mario :D
This is Basically What I Have for my Main Class
(MyProjectMain):
void MyProjectMain::KeyDown(int iKeyCode)
{
switch ( iKeyCode )
{
case SDLK_ESCAPE: // End program when escape is pressed
SetExitWithCode( 0 );
break;
case SDLK_SPACE: // SPACE Pauses
break;
case SDLK_UP:
Player::JumpPlayer();
break;
}
}
(Player class):
void Player::DoUpdate(int iCurrentTime)
{
/*
// Change speed if player presses a key
if ( GetEngine()->IsKeyPressed( SDLK_UP ) )
m_iCurrentScreenY -= 5;
if ( GetEngine()->IsKeyPressed( SDLK_DOWN ) )
m_iCurrentScreenY += 5;
*/
if ( GetEngine()->IsKeyPressed( SDLK_LEFT ) )
m_iCurrentScreenX -= 3;
if ( GetEngine()->IsKeyPressed( SDLK_RIGHT ) )
m_iCurrentScreenX += 3;
if ( m_iCurrentScreenX < 0 )
m_iCurrentScreenX = 0;
if ( m_iCurrentScreenX >= GetEngine()->GetScreenWidth() - m_iDrawWidth )
m_iCurrentScreenX = GetEngine()->GetScreenWidth() - m_iDrawWidth;
if ( m_iCurrentScreenY < 0 )
m_iCurrentScreenY = 0;
if ( m_iCurrentScreenY >= GetEngine()->GetScreenHeight() - m_iDrawHeight)
m_iCurrentScreenY = GetEngine()->GetScreenHeight() - m_iDrawHeight;
// Ensure that the object gets redrawn on the display, if something changed
RedrawObjects();
}
void Player::JumpPlayer(void)
{
}
I must Mention That I have successfully made the sprite move left and right its just this jump that has been taking me so long. I would love if you can include your solution in the jump Function
Thanks A whole Lot !!!