Basically I'm adding 1 to the player's velocity for every frame that he falls. So, the farther he falls, the faster his Y position moves.
I'm kind of flying blind here
the variable "jumping" is initialized to true before anything else happens. Maybe a better name would be "inAir".
if( playerEvent.type == SDL_KEYDOWN )
{
switch( playerEvent.key.keysym.sym )
{
case SDLK_RIGHT: xVelocity += 8; break;
case SDLK_LEFT: xVelocity -= 8; break;
case SDLK_SPACE: jumping = true; jumpPower = 10; break;
}
}
I'm just trying to get him to stop at an invisible line for now (500px down from the top).
if(jumping)
{
if(jumpPower > 0)
{
fallPower = 0;
yVelocity -= jumpPower;
slowing++;
jumpPower -= slowing;
}
else
{
yVelocity = fallPower;
fallPower += 1;
}
}
if(yPosition >= 500)
{
yPosition -= yVelocity;
yVelocity = 0;
jumping = false;
slowing = 0;
}
else
{
yPosition += yVelocity;
}
xPosition += xVelocity;
Another problem is that it looks like he's bumping his head on an invisible ceiling when he jumps.