Game Development Reference
In-Depth Information
Why are you setting the object to an t and u position of zero? Remember that the object is now
a child of one of the item boxes. The coordinates it uses no longer refer to coordinates on the main
stage. , is a local coordinate : the center of the item box.
Next, you push the object into the [_khha_pekjF]n array:
[_khha_pekjF]n*lqod$_khha_pekjEpai%7
The last job is to remove the event listeners. You have a small problem because the bugs all use the
kj>qcIkra event listener, but the ikqoa doesn't. kj>qcIkra is what makes the bugs move and also
includes their artificial intelligence. Remember, the ikqoa doesn't do anything; it's just an obstacle
for the lh]uan to avoid. You have to be careful not to try to remove the kj>qcIkra listener from the
ikqoa; otherwise, the code will generate an error.
An easy way around this is just to run the code if the object that's called the kj?khheoekjSepdLh]uan
event is not a mouse. A simple eb statement takes care of that:
eb$_khha_pekjEpai9ikqoa%
w
_khha_pekjEpai*naikraArajpHeopajan$Arajp*AJPAN[BN=IA(kj>qcIkra%7
y
Finally, you have to remove the kj?khheoekjSepdLh]uan event itself:
_khha_pekjEpai*naikraArajpHeopajan$Arajp*AJPAN[BN=IA( ±
kj?khheoekjSepdLh]uan%7
Now that you can collect bugs, you need to find out how to end the game.
Winning and losing conditions
The best place to check for the end of the game is in the kj?khheoekjSepdLh]uan event handler.
1. Add the following code just before the directives that remove the event listeners:
***
[_khha_pekjF]n*lqod$_khha_pekjEpai%7
++?da_gbknaj`kbc]ia
eb$[_khha_pekjF]n*hajcpd99/%
w
]``ArajpHeopajan$Arajp*AJPAN[BN=IA(kjAj`C]ia%7
y
++Naikraheopajanokb_khha_pa`epaio
eb$_khha_pekjEpai9ikqoa%
w
***
If the hajcpd of the [_khha_pekjF]n is /, all the objects have been collected, and the
kjAj`C]ia event listener is added.
 
Search Nedrilad ::




Custom Search