Game Development Reference
In-Depth Information
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.
bqj_pekjkjAjpanBn]ia$arajp6Arajp%6rke`
w
++Ikrapdalh]uan
lh]uan*t'9rt7
lh]uan*u'9ru7
++?khheoekj`apa_pekj
eb$lh]uan*depPaopK^fa_p$ajaiu%%
w
ajaiu*ckpk=j`Opkl$.%7
da]hpd*iapan*se`pd))7
y
ahoa
w
ajaiu*ckpk=j`Opkl$-%7
y
++?da_gbknaj`kbc]ia
eb$da]hpd*iapan*se`pd8-%
w
iaoo]ca@eolh]u*patp9C]iaKran7
y
y
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
 
Search Nedrilad ::




Custom Search