Game Development Reference
In-Depth Information
9. Save the I]ej[>qc?]p_dan*]o file and test the project. Chase the bugs around the stage.
When you catch them, they'll appear in the item boxes on the top-right corner, as shown in
Figure 9-26. The game allows you to catch only three objects.
Figure 9-26. Catch the bugs (and maybe a mouse, too)!
The job of collecting the bugs falls to the kj?khheoekjSepdLh]uan event handler. The first thing it
does is create a local variable to store a reference to the object that's calling the event:
r]n_khha_pekjEpai6Ikrea?hel9arajp*p]ncap]oIkrea?hel7
Remember that there are four objects that are calling this event: the ^aa, bhu, iko)
mqepk, and ikqoa. The code in kj?khheoekjSepdLh]uan applies to all of them.
The code then checks to see whether the collection jar is full. Because you want to allow the player to
collect only 3 items, the code should run only if the hajcpd of the [_khha_pekjF]n array is less than /:
eb$[_khha_pekjF]n*hajcpd8/%
w
If the jar isn't full yet, the code checks whether the object is colliding with the lh]uan:
eb$lh]uan*depPaopLkejp$_khha_pekjEpai*t(_khha_pekjEpai*u(pnqa%%
w
 
Search Nedrilad ::




Custom Search