Game Development Reference
In-Depth Information
from the Flee state to the Hiding state does not, because the No Players transition
is evaluated prior to the High Health transition. If High Health evaluates at all,
then players are known to be present; the transition does not need to check for
them again.)
Games are written in many languages, and few of them include out-of-the-box
support for FSMs. We will write the structure ourselves. We could write all
AI code ad hoc, but the amount of work to build a structure is less than
the amount of work needed to debug ad hoc methods. We will write the
structure in such a way as to minimize the number of errors we can make in
the code.
The project itself will be to implement the simple monster AI in code. Our AI will
do more than think; it will think ''out loud'' for our benefit. That is, our monster
will emit text messages for us to read, enabling us to see clearly what it is thinking.
Note that as an added benefit, doing so improves our ability to debug the code.
More importantly, doing so reinforces the good habit of making the AI pro-
grammer look for ways to show the player what the AI is thinking. Games that
show the player what the game is thinking are perceived to be smarter than games
that do not.
A Brief Foray into Object-Oriented Programming
If you are familiar with object-oriented programming, you can safely skip this
section. If not, the ''Fundamental Concepts'' section of the Wikipedia entry on
the subject is quite good as a place to start [Wikipedia09].
In object-oriented programming, behavior and internal data are combined as an
object. An object is one of something. The kind, or type, of an object is its class.
An object named Bob might be of type Human. The Human class does not by
itself do anything; objects of that class certainly do, however. The actions a
programmer can ask an object to do are called the methods of that object. From
this description, you may have realized that we have been dealing with objects all
along. For example, in Chapter 2, we passed a World object of type House to the
RunAI subroutine.
For our purposes, we will exploit the fact that objects have control over their
internal data. Instead of manipulating the data directly, code outside the object
Search Nedrilad ::

Custom Search