Game Development Reference
In-Depth Information
This is very simple; you just need to set it to b]hoa when the objects are not colliding . And actually,
you're already checking for that in the code, remember? It's the second part of the eb/ahoa statement
that tells the ajaiu object to return to frame 1. All you need to do is drop a line of code in that same
spot, which the code in bold shows:
eb$lh]uan*depPaopK^fa_p$ajaiu%%
w
ajaiu*ckpk=j`Opkl$.%7
da]hpd*iapan*se`pd))7
eb$_khheoekjD]oK__qnna`%
w
o_kna''7
iaoo]ca@eolh]u*patp9Opnejc$o_kna%7
_khheoekjD]oK__qnna`9pnqa7
y
y
ahoa
w
ajaiu*ckpk=j`Opkl$-%7
_khheoekjD]oK__qnna`9b]hoa7
y
Yes, I know, what you're thinking. If you're new to programming, this logic can seem a little on the
mind-bending side! This is the most complex use of logical operators and eb statements you've seen
so far. Don't feel too discouraged if you don't understand it right away or don't think you'll be able
to write similarly complex code yourself any time soon. Look it over a few times, think about it while
lying in bed at night, come back to it in a few days, and try it with some of your own games. It will
gradually start to make sense—trust me! Seeing how others have solved problems and then trying out
those solutions in your own games is an extremely important part of learning how to program.
I made one more promise at the beginning of this section, which is that the score will also help you
figure out if the player has won the game.
1. Add the following code in bold to the bottom of 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
da]hpd*iapan*se`pd))7
eb$_khheoekjD]oK__qnna`%
w
o_kna''7
iaoo]ca@eolh]u*patp9Opnejc$o_kna%7
_khheoekjD]oK__qnna`9pnqa7
 
Search Nedrilad ::




Custom Search