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. ...

Get Android: Game Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.