Introducing Bob
Here, we can add the meat to the bones of your Player
class. However, this section won't be the last time we revisit the Player
class. Now, we will add the necessary functionality to allow Bob to move. Immediately after we have done this, we will add the code to allow the player to use the forthcoming collision detection code and the Animation
class.
First of all, we need to add some members to the Player
class. The Player
class will need to know how fast it can move, when the player is pressing the left or right controls, and if it is falling or jumping. In addition, the Player
class needs to know how long it has been jumping and how long it should jump for.
The next block of code provides variables for us to monitor all these things. We will very soon see, how we use them to make Bob do what we want.
Now, we know what the variables are for. We can add this code right after the class declaration as shown:
public class Player extends GameObject {
final float MAX_X_VELOCITY...