Game Development Reference
Implementing a chase feature
With just a very small change to the code, you can implement the basis of a simple but very effective
enemy artificial intelligence system. In the code you're using, a random t and u position were assigned
for the animation's new bejeod point. But what if you assigned a value that isn't random? You can give
the nk^kp the appearance of intelligently moving around the stage:
1. Make the following changes to the kjIkpekjBejeodT and kjIkpekjBejeodU event handlers:
2. Save the I]ej[N]j`kiPsaaj*]o file and test the project. The robot sets its destination to the
mouse's position each time the animation restarts and it chases the mouse around the stage
(see Figure 10-12).
Figure 10-12. Each time the robot starts its
new animation sequence, the mouse's position
becomes the new finish point.