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 by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.