In our last tutorial we programmed the background so that it scrolls when we control it with the arrow keys. But as cool as that is, it isn’t enough. Right now the player is nothing more than a a static object on the side of the stage. What we’re going to do in this tutorial is program the player to interact with the background.
What code do we add for the player? That’s a BIG question… the fate of our entire game pretty much depends upon how the player interacts with the environment. In order to stay organized, I’ll outline all the basic concepts the player should follow:
- Smooth Movement: The player should accelerate smoothly upon pressing the arrow key, and glide to a stop due to friction when the arrow key is released.
- Collisions: The player should not be able to walk through walls, fall through the ground, or jump through ceilings.
- Gravity: The player should be pulled downwards unless he is standing on the ground.
- Jumping: If the player is standing on the ground, he should be able to jump upwards.