Building a HUD class to display the player's control buttons and text
The HUD
, as usual, will display all the onscreen information to the player. The HUD for this game (as we saw at the start of the chapter) is a bit more advanced and as well as regular features such as the score and the player's lives, it has the control buttons.
The control buttons are basically slightly transparent rectangles drawn on the screen. It is important that when we detect the player's touches, we determine accurately whether a touch happened within one of these rectangles as well as in which rectangle.
An entire class dedicated to these rectangles (as well as the usual text) seems like a good idea.
Furthermore, as we did with the Snake
and Apple
classes in the previous project, the HUD
class will also be responsible for drawing itself when requested. Create a class called HUD
, add the import
directives, and edit its code to match the following, including adding the member variables...