Game Development Reference
In-Depth Information
2. Save the I]ej[>qc?]p_dan*]o file and test the project. When the bugs come within 50 pixels
of the frog, they fly away quickly and display the word Frog! in the Output window, as shown in
Figure 9-23.
Figure 9-23. The bugs reverse direction if they come within 50 pixels of the frog.
The code pushes the bug out of the collision area and then reverses its velocity using the bounce
formula. Again, this is simple code, but the effect is startlingly realistic.
The way that the bugs interact with the cat is only slightly more complex. The bugs have two different
behaviors, depending on whether the cat is moving or not moving. When the cat's velocity is less than
- on either axis, the bugs have the same behavior as they have with the frog. When the cat is moving,
however, the bugs enter panic mode. They add the player's velocity to their own and multiply their
random motion by /,, which makes their movement much more erratic.
Search Nedrilad ::

Custom Search