The main game class. More...
#include <Game.h>
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. | |
GameEntity * | CreateEntity () |
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. | |
Engine * | GetEngine () const |
b2World * | GetPhysics () const |
GameEntity * | GetPlayer () const |
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.
Game::Game | ( | Engine * | pEngine | ) |
The game constructor.
pEngine | A pointer to the engine which is creating the game. |
Game::~Game | ( | ) |
The game destructor.
Destroys created entities, the physics etc.
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.
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.
id | The unique identifier assigned to the entity when it was created. |
int Game::GetCurrentStage | ( | ) | const [inline] |
Retrieves the current stage.
Engine* Game::GetEngine | ( | ) | const [inline] |
b2World* Game::GetPhysics | ( | ) | const [inline] |
GameEntity* Game::GetPlayer | ( | ) | const [inline] |
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.
file | The filename of the file to stream the data out of. |
bool Game::LoadNextStage | ( | ) |
Loads the next stage in the map cycle.
Calls the LoadStage function with m_nCurrentStage + 1.
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.
nStage | The stage in the map cycle to load. |
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.
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.
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.
nDelta | The difference in time (ms) between this update and the last. |