Game Development Reference
In-Depth Information
Before we start putting these blocks together, we need to ensure that we have
them built correctly. To establish the compartmentalized confidence we talked
about in Chapter 13, we need to ensure that we are comfortable with each compo-
nent. Only then can we trust that what we build with the blocks will be valid.
P UTTING I TIN C ODE
There are three major components in this example: the agent (us), Dudes, and
weapons. Accordingly, we create classes for the three types of entities ( CAgent ,
CDude , and CWeapon ). Additionally, for Dudes and weapons, we create collection
classes to hold the individual objects (Figure 14.9). We will look at the basics of each
of the classes for clarity.
FIGURE 14.9 The class structure for the “Shoot Dudes� example.
CDudeCollection contains a vector of CDude objects.
CWeaponCollection contains an array of four CWeapon objects.
This logical arrangement is optional, of course. This topic is not meant to be an
educational tome on design patterns or memory management. I have stripped
the example down to a simple, easy-to-understand model. Feel free to insert the
AI logic into a design of your own choosing.
Weapons
Because we utilize CWeapon in both CDude and CAgent , we will begin by defining it.
First, we should note that we have enumerated a type to make referencing the
weapons easier throughout the entire program.
Search WWH ::




Custom Search