Game Development Reference
In-Depth Information
Updating a score
Most games keep track of whether a player has won or lost by updating a score, based on how well
the player is performing. The following example shows you how to update a score and end the game
when a certain score has been reached.
You'll write this code in three parts. The first part gets the basic system running, but you'll immediately
see a problem with it that will illustrate a valuable concept to keep in mind when dealing with collision
detection. You'll solve the problem in the second part.
1. You first need to create a new qejp variable call o_kna to store the player's score. Update the
I]ej[Lh]ucnkqj` class definition and the ejep method with the following new code in bold:
lq^he__h]ooI]ej[Lh]ucnkqj`atpaj`oIkrea?hel
w
r]nrt6ejp7
r]nru6ejp7
r]no_kna6qejp7
lq^he_bqj_pekjI]ej[Lh]ucnkqj`$%
w
ejep$%7
y
bqj_pekjejep$%6rke`
w
++ejepe]hevar]ne]^hao
rt9,7
ru9,7
o_kna9,7
++ejepe]hevak^fa_po
ajaiu*opkl$%7
++=``arajpheopajano
op]ca*]``ArajpHeopajan$Gau^k]n`Arajp*GAU[@KSJ(kjGau@ksj%7
op]ca*]``ArajpHeopajan$Gau^k]n`Arajp*GAU[QL(kjGauQl%7
]``ArajpHeopajan$Arajp*AJPAN[BN=IA(kjAjpanBn]ia%7
y
2. Add the following new code to the kjAjpanBn]ia method:
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
 
Search Nedrilad ::




Custom Search