Game Development Reference
In-Depth Information
++?]lpqnapda_qnnajplkoepekjejpdakh`T]j`kh`Ur]ne]^hao
kh`T9pailkn]nuT7
kh`U9pailkn]nuU7
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:
lner]pabqj_pekjkjIkpekjBejeodT$arajp6Arajp%
w
r]npsaajK^fa_p6Psaaj9arajp*p]ncap]oPsaaj7
psaajK^fa_p*^acej9nk^kp*t7
psaajK^fa_p*bejeod9ikqoaT7
psaajK^fa_p*op]np$%7
y
lner]pabqj_pekjkjIkpekjBejeodU$arajp6Arajp%
w
r]npsaajK^fa_p6Psaaj9arajp*p]ncap]oPsaaj7
psaajK^fa_p*^acej9nk^kp*u7
psaajK^fa_p*bejeod9ikqoaU7
psaajK^fa_p*op]np$%7
y
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.
 
Search Nedrilad ::




Custom Search