How to make a character jump up and down again

Started by
0 comments, last by rip-off 14 years, 3 months ago
I have been working on my own game so far this is what I have so far for the jump function. do { PlayerPosY= PlayerPosY+ 1; LoadContent(); UpdateEnemies(); loopUp++; } while (loopUp <= 10); do { PlayerPosY= PlayerPosY- 1; LoadContent(); UpdateEnemies(); loopDown++; } while (loopDown >= 10); Now all it does is stay in one place. I have updated everything but could not get a delay in there that would work. Any answers as to how to make this work?
Advertisement
Jumping is typically handled by giving some additional values to the player state, a velocity and/or acceleration depending on your games complexity. You want to process the jump asynchonously, allowing the standard game loop to continue while the player is jumping.

Your jump function, if you got it to work, would be quite limited. The player could only jump straight up or down, but could not jump in a parabola.

You will need to add conditions to the rest of your code to prevent, for example, the player walking while jumping, again depending on the game (some games allow the player limited control of the character even in the air). You might need to record whether the player is on the ground or jumping with a boolean condition variable. You will want some collision detection to determine if the player hits the ceiling (if any), other characters and when it hits the ground again.

This topic is closed to new replies.

Advertisement