Game Development Reference
In-Depth Information
From a technical point of view, the simple factory that you've looked at here is not
regarded as a full-blown design pattern in the strictest sense. It's certainly very helpful
and will help train you to get used to using helper classes in your programs. However,
for a truly bullet-proof elaboration of this system, do a bit of research into the “factory
pattern” or “factory method.” Although similar to a simple factory, the factory pattern
has a few more checks and balances that make it much more robust. The trade-off, of
course, is added complexity. You'll need to decide for yourself whether it's a fair trade
based on the project you're working on.
Enemy AI systems
You might be surprised to learn that if you can create an object that follows the mouse, you've already
got the basis of an artificial intelligence (AI) system that you can modify for use in a wide variety of
game situations. All you need to do is mix and match some of the techniques you learned about in this
chapter, and you can design enemies that do the following:
Follow the player
Run away from the player
Aim and fire bullets at the player
You'll find the source files for these examples in a folder called =EOuopaio.
In the Library of the ]eOuopaio*bh] file is a symbol called Nk^kp. I'll demonstrate the three AI exam-
ples by asking you to bind the following classes to the Nk^kp symbol as you need them:
Nk^kp[Bkhhks
Nk^kp[Nqj
Nk^kp[Odkkp
These classes contain the logic that the robot will need.
Following the player
Open the ]eOuopaio*bh] file. Select the Nk^kp symbol in the Library and bind it to the Nk^kp[Bkhhks
class.
Test the project. You'll see that the robot follows the player around the stage if the player is within
a 200-pixel range. Figure 10-18 illustrates what you will see.
 
Search Nedrilad ::




Custom Search