Game Development Reference
In-Depth Information
uses the methods the object provides. Using a real-world metaphor, an instance
of a Painter object might have a method called PaintTheTrim(somecolor) . The
Painter object internally decides whether it needs to use masking tape or to paint
freehand. The Painter object picks which paintbrush to use. A well-implemented
object does not allow direct manipulation of the details, and the programmer
using the object does not want to micromanage those details. In short, if the
programmer gets the class right, he or she can quit worrying about the internals
and use the objects at a much higher level of abstraction.
In our code, the Public and Private keywords are how a class marks methods
that can be called outside of an object. You can make some of the internal data of
an object visible outside of the object by marking it public , but this should be
done sparingly. Consider the complexity discussions of Chapter 2. Object-
oriented programming helps keep the internal complexity of our AI additive as it
grows instead of multiplicative.
Another common feature of object-oriented programming is inheritance. A
class, say of type Dragon, can inherit from another class, say of type Monster. In
that case, all object of the class Dragon have all the methods of the Monster class
plus the methods specific to the Dragon class. So all objects of the Monster class
might have a method to indicate their health, but the ability to breathe fire
would be implemented only by objects of the Dragon class. We will use
inheritance very sparingly. We will use it to get different kinds of objects that
inherit from a common class to act the same way. You should never be able to
create an object of certain classes. For example, we might not want there to ever
be an instance of a generic monster. In VB, we would mark the Monster class
MustInherit to enforce this. We can create objects of classes that inherit from
Monster, such as Dragon or Orc, but we cannot create an object of type Monster
FSM Objects
So what objects do we need for our FSM AI? We need states, the states need
transitions, and the states need some machine that runs them. In addition, that
machine needs some changing environment to live in; that environment will
be our monster. If the FSM needs data, it asks the monster. The monster will
either have that data or get it from the rest of the world. We will not consider
the outside world; all the world data needed by the FSM will reside in the
Search Nedrilad ::

Custom Search