O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Let’s take a look at some of these classes in more detail.
The Raven_Game Class
The Raven_Game class is the project’s hub. This class owns an instance of a
Raven_Map, a container of bots, and a container of any active projectiles
(rockets, slugs, etc.). Among others, the
Raven_Game class has methods for
loading maps and their associated navigation graphs, updating and render
-
ing the game entities and geometry, querying the world with line-of-sight
requests, and handling user input.
Raven: An Overview | 297
Overview of the Game Architecture
Figure 7.1. The Raven architecture
Following is a partial listing of the Raven_Game class declaration. Have a
quick glance to familiarize yourself with it.
class Raven_Game
{
private:
Raven_Map* m_pMap;
std::list<Raven_Bot*> m_Bots;
//the user may select a bot to control manually. This member
//holds a pointer to that bot
Raven_Bot* m_pSelectedBot;
//this list contains any active projectiles (slugs, rockets,
//shotgun pellets, etc.)
std::list<Raven_Projectile*> m_Projectiles;
/* EXTRANEOUS DETAIL OMITTED FOR CLARITY */
public:
//the usual suspects
void Render();
void Update();
//loads an environment from a file
bool LoadMap(const std::string& FileName);
//returns true if a bot of size BoundingRadius cannot move from A to B
//without bumping into world geometry
bool isPathObstructed(Vector2D A, Vector2D B, double BoundingRadius = 0)const;
//returns a vector of pointers to bots in the FOV of the given bot
std::vector<Raven_Bot*> GetAllBotsInFOV(const Raven_Bot* pBot)const;
//returns true if the second bot is unobstructed by walls and in the field
//of view of the first.
bool isSecondVisibleToFirst(const Raven_Bot* pFirst,
const Raven_Bot* pSecond)const;
/* EXTRANEOUS DETAIL OMITTED FOR CLARITY */
};
z
TIP Note that GetAllBotsInFOV does not limit the number of bots returned by
the method. This is not necessary for the demo, but for games where there
might frequently be dozens or even hundreds of other agents in view, it’s a
good idea to cap the number to the n closest the agent can see.
298 | Chapter 7
Overview of the Game Architecture

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required