When i press 'w' the character flies up.
Player.cpp
Code:
void Player::HandleEvents( SDL_Event event )
{
if( event.type == SDL_KEYDOWN )
{
switch( event.key.keysym.sym )
{
case SDLK_w:
if( !jumping )
jumping = true;
}
}
if( jumping )
{
yVel -= gravity;
gravity += 2;
if( yPos <= MAX_JUMP_HEIGHT )
{
yVel += gravity;
gravity -= 2;
jumping = false;
}
}
else
{
yVel += 2;
}
}
bool Player::CollisionWithGround()
{
if( yVel > 0 )
{
return true;
}
return false;
}
And in Game.cpp
Code:
void Game::Logic()
{
//Collision with floor
if( player.CollisionWithGround() )
{
player.yVel -= 1;
player.jumping = false;
}
player.yPos += player.yVel;
}