Game Class Reference

The main game class. More...

#include <Game.h>

Collaboration diagram for Game:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Game (Engine *pEngine)
 The game constructor.
 ~Game ()
 The game destructor.
void Initialize ()
 Initializes the engine.
void Update (const int nDelta)
 Updates or steps the game 1 cycle.
void Render (AbstractRenderer *pRenderer, const int nDelta)
 Renders any entities that have an attached visual component.
void Save (const std::wstring &file)
 Saves the game to a file.
bool Load (const std::wstring &file)
 Loads the game from a file.
bool LoadStage (const int nStage)
 Loads a stage into memory.
bool LoadNextStage ()
 Loads the next stage in the map cycle.
int GetCurrentStage () const
 Retrieves the current stage.
void Clear ()
 Clear the game.
GameEntityCreateEntity ()
 Creates a new entity with no components and attaches it to the game.
void DestroyEntity (const UNIQUEID &id)
 Destroys an entity that possess the given unique identifier.
EngineGetEngine () const
b2World * GetPhysics () const
GameEntityGetPlayer () const

Detailed Description

The main game class.

The game class works ontop of the engine class and treats the engine class as a kind of virtual machine. The game class is responsible for keeping track of all gameplay and the player.


Constructor & Destructor Documentation

Game::Game ( Engine pEngine  ) 

The game constructor.

Parameters:
pEngine A pointer to the engine which is creating the game.
Game::~Game (  ) 

The game destructor.

Destroys created entities, the physics etc.


Member Function Documentation

void Game::Clear (  ) 

Clear the game.

Destroy's all entities and resets the game configuration to default (so player score etc.). Called before a new stage is loaded.

GameEntity * Game::CreateEntity (  ) 

Creates a new entity with no components and attaches it to the game.

Use this function to create an entity to which components can then be added, this function will give the entity a valid entity id and make sure the entity is set up to be used.

Returns:
A pointer to the newly created game entity.
void Game::DestroyEntity ( const UNIQUEID &  id  ) 

Destroys an entity that possess the given unique identifier.

The game entity map is searched for the id, if the id is found the entity is deleted and removed from the game, if not this function does nothing.

Parameters:
id The unique identifier assigned to the entity when it was created.
See also:
GameEntity
int Game::GetCurrentStage (  )  const [inline]

Retrieves the current stage.

Returns:
The current stage in the map cycle.
Engine* Game::GetEngine (  )  const [inline]
Returns:
a pointer to the engine which created this game.
b2World* Game::GetPhysics (  )  const [inline]
Returns:
a pointer to the physics system in use, the box2d world in this case.
GameEntity* Game::GetPlayer (  )  const [inline]
Returns:
a pointer to the player entity, which is treated as a special case by the game.
void Game::Initialize (  ) 

Initializes the engine.

This function is responsible for initializing the physics system and loading data such as materials and the current map cycle.

bool Game::Load ( const std::wstring &  file  ) 

Loads the game from a file.

This function is used to stream data out of a file into the game and into any entities that are stored within the file. This function called FromStream to every entity in the stream and passes a stream from the file, this allows entities to do custom loading.

Parameters:
file The filename of the file to stream the data out of.
Returns:
True or False depending on whether loading was successful.
bool Game::LoadNextStage (  ) 

Loads the next stage in the map cycle.

Calls the LoadStage function with m_nCurrentStage + 1.

Returns:
True or False depending on whether the next stage could be loaded.
bool Game::LoadStage ( const int  nStage  ) 

Loads a stage into memory.

Loads a stage in the mapcycle into memory, all remnents of the last stage are cleared before hand. The stage will always start at the beginning. This function loads an Attribute tree for the given stage, it then uses the attribute tree to initialize any entities contained within it.

Parameters:
nStage The stage in the map cycle to load.
Returns:
True or False depending on whether that stage could be successfully loaded.
void Game::Render ( AbstractRenderer pRenderer,
const int  nDelta 
)

Renders any entities that have an attached visual component.

For each entity it checks whether it has a visual component, if it has it calls that visual components render function.

Parameters:
pRenderer A pointer to the renderer that will be used to draw to the screen.
nDelta The difference in time (ms) between this frame and the last.
void Game::Save ( const std::wstring &  file  ) 

Saves the game to a file.

This function is used to stream the current state of the game as well as teh current state of any entities into a file. This function calls ToStream on every entity registered and passes a filestream to the given file.

Parameters:
file The filename of the file to stream the data into.
void Game::Update ( const int  nDelta  ) 

Updates or steps the game 1 cycle.

This function starts by updating the physics component and proceeds to update all of the game entities in turn.

Parameters:
nDelta The difference in time (ms) between this update and the last.

The documentation for this class was generated from the following files:
 All Classes Functions Variables

Generated on Fri Nov 20 15:29:20 2009 for PhysTank by  doxygen 1.6.1