Game Development Reference
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:
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:
Finally, you have to remove the kj?khheoekjSepdLh]uan event itself:
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:
If the hajcpd of the [_khha_pekjF]n is /, all the objects have been collected, and the
kjAj`C]ia event listener is added.