Game Development Reference
In-Depth Information
'
As you can see, there
s really not a lot to this class. In fact, its entire purpose is to
override various virtual functions from the base class. It acts as a configuration class
of sorts. The BaseGameApp class calls these functions (some of which have no mean-
ingful base class implementation) and expects that they will do the appropriate thing.
For example, V RegisterGameEvents() is defined like this in BaseGameApp :
virtual void VRegisterGameEvents(void) {}
This function is called in BaseGameApp::InitInstance() , and its purpose is to
allow the game-specific subclass to register all of its game events in the appropriate
place during game initialization. This is a very common design pattern called the
Template Method Pattern (not to be confused with C++ templates).
The VCreateGameAndView() function is responsible for creating the concrete,
game-specific logic and human view objects. This is one of the functions you abso-
lutely must override in your subclass since it
s defined as pure virtual in the base
class. The other three are VGetGameTitle() , VGetGameAppDirectory() , and
VGetIcon() . You can see these functions in TeapotWars.h and TeapotWars.cpp.
That
'
s all there is to the Teapot Wars application layer. The base class GameCodeApp
does almost all the work for you.
'
The Game Logic
The game logic is where all of the C++ game logic resides, and it is where most of
your gameplay events will get handled and where a lot of the game management will
take place. In Teapot Wars, this class is called TeapotWarsLogic, and it is derived
from BaseGameLogic . As you learned in Chapter 2, What ' s in a Game? , the game
logic represents the game itself, separated from the operating system and rendering.
Before we dig into the internals of the game logic, let
s take a look at how the Teapot
Wars game itself is organized. Every game of Teapot Wars starts with the main
menu, which you can see in Figure 21.3.
The player is presented with two main options: He can create a new game, or he can
join an existing game. If you create a new game, you choose the level XML file you
want to load, the number of AI teapots, and the number of players involved. If you
choose to join a game, all you need to do is fill out the port number and host name.
When everything is set, you click on the Start Game button at the bottom. This will
take you right into the game.
In reality, there
'
s a lot more going on under the hood when you click on Start Game.
First, the game environment is loaded. If this is a network game, the host tells each
attached client which level XML file to load, but all loading happens from your local
'
 
 
Search WWH ::




Custom Search