Game Development Reference
Now all you need to do is program the health meter. As a bonus, the words Game Over! display in the
iaoo]ca@eolh]u text field when its width is reduced to zero.
1. Modify the kjAjpanBn]ia method so that it looks like the following. The bold text indicates the
new code, but notice that the two directives that displayed the words No collision and Ouch!!
have been removed. It was done to simplify the code a little so you won't have a conflict with
the Game Over! message.
2. Save the I]ej[Lh]ucnkqj`*]o file and test the project. When the player touches the enemy, the
health meter decreases. When it disappears, the words Game Over! are displayed. Figure 7-14
shows an example of what you'll see.
Figure 7-14. Using a health meter to end the game