Rally X
ELEN3009 Project by Justin Wernick and David Schneider
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
Game Class Reference

The object that controls the flow of the game, and the launch point of the game. More...

#include <Game.h>

List of all members.

Public Member Functions

 Game ()
 Constructor, that creates the relevant Allegro entities.
 ~Game ()
 Constructor, that destroys the relevant Allegro entities.
void start ()
 Entry point for the program. This should be called from main.

Static Public Attributes

static const unsigned int FPS = 30
 Frames per second, the number of times the gameloop is run every second.

Private Member Functions

 Game (const Game &ref)
 Unimplemented copy constructor, prevents copying of Game objects.
Gameoperator= (const Game &rhs)
 Unimplemented assignment operator.
void initLevel (const string &levelFile)
 Initialises all of the GameObject lists using a file.
void runloop ()
 Main part of the game, performs the actions in each frame FPS times per second until the game is over.
void update ()
 Calls the update method on each of the GameObjects in the game.
void cleanup ()
 Removes any GameObjects that have been destroyed from their lists.
void clearLists ()
 Destroys all GameObjects in the game, resetting the lists for a new level to be loaded.

Private Attributes

AllegroInit _allegro
 Handles dependencies on Allegro being installed.
Config _config
 Loads configuration from file on construction, used to set resolution of screen.
Screen _screen
 Handles all drawing operations.
ALLEGRO_TIMER * _timer
 Creates FPS events per second, that are put into _timerEvents.
ALLEGRO_EVENT_QUEUE * _timerEvents
 Catches events from _timer, used to regulate speed of runloop.
Maze _maze
 The environment that confines the movements of GameObjects, specifically Cars.
list< PlayerCar_players
 Typically a single PlayerCar, controlled by the person playing the game.
list< EnemyCar_enemies
 List of all EnemyCars chasing the player.
list< Checkpoint_checkpoints
 List of checkpoints that the player needs to collect.
list< Rock_rocks
 List of rocks that the player and EnemyCars need to avoid.
list< Smokescreen_smokescreens
 List of Smokescreen objects that are currently able to delay EnemyCars.
list< DestroyedObjectPopup_popups
 List of purely visual DestroyedObjectPopups that need to be drawn.
CollisionDetector _collisionDetector
 Object that checks for collisions each frame.

Detailed Description

The object that controls the flow of the game, and the launch point of the game.

Game contains the various components, including the screen, the maze, and all of the objects in the maze. The timing of the gameloop also falls under Game's control. Essencially, Game is the central point that everything connects to.

Author:
Justin Wernick
David Schneider

Definition at line 36 of file Game.h.


Constructor & Destructor Documentation

Game::Game ( )

Constructor, that creates the relevant Allegro entities.

Definition at line 3 of file Game.cpp.

Game::~Game ( )

Constructor, that destroys the relevant Allegro entities.

Definition at line 12 of file Game.cpp.

Game::Game ( const Game ref) [private]

Unimplemented copy constructor, prevents copying of Game objects.

Copying a Game is unneccesary as there should only be a single Game object.


Member Function Documentation

void Game::cleanup ( ) [private]

Removes any GameObjects that have been destroyed from their lists.

Definition at line 104 of file Game.cpp.

void Game::clearLists ( ) [private]

Destroys all GameObjects in the game, resetting the lists for a new level to be loaded.

This should always be called before a new level is loaded.

Definition at line 177 of file Game.cpp.

void Game::initLevel ( const string &  levelFile) [private]

Initialises all of the GameObject lists using a file.

Parameters:
[in]levelFileThe path of the file that contains the level layout.

Definition at line 32 of file Game.cpp.

Game& Game::operator= ( const Game rhs) [private]

Unimplemented assignment operator.

See also:
Game::Game(const Game& ref)
void Game::runloop ( ) [private]

Main part of the game, performs the actions in each frame FPS times per second until the game is over.

Each frame runs the update methods of each of the GameObjects in the lists. The CollisionDetector then checks for collisions between objects. Any GameObjects that have been destroyed are then removed from their lists. Finally, the Screen is called to draw all of the GameObjects that still exist in their new positions.

Before the next iteration begins, a check is done for the victory and loss conditions. The loop is ended if either of these are met, or if the player has quit the game.

Definition at line 39 of file Game.cpp.

void Game::start ( )

Entry point for the program. This should be called from main.

Definition at line 19 of file Game.cpp.

void Game::update ( ) [private]

Calls the update method on each of the GameObjects in the game.

Definition at line 82 of file Game.cpp.


Member Data Documentation

Handles dependencies on Allegro being installed.

Definition at line 106 of file Game.h.

list<Checkpoint> Game::_checkpoints [private]

List of checkpoints that the player needs to collect.

Definition at line 127 of file Game.h.

Object that checks for collisions each frame.

Definition at line 132 of file Game.h.

Config Game::_config [private]

Loads configuration from file on construction, used to set resolution of screen.

Definition at line 108 of file Game.h.

list<EnemyCar> Game::_enemies [private]

List of all EnemyCars chasing the player.

Definition at line 126 of file Game.h.

Maze Game::_maze [private]

The environment that confines the movements of GameObjects, specifically Cars.

Definition at line 113 of file Game.h.

list<PlayerCar> Game::_players [private]

Typically a single PlayerCar, controlled by the person playing the game.

A list was used for _players to allow the Game object to be constructed without needing to initialise a meaningless PlayerCar object. This also allows the PlayerCar to be destroyed by Rocks or EnemyCars. An added benefit is that it adds the ease of extending the game to allow multiple players. To add multiplayer, the KeyboardHandler would need to be modified to allow different sets of input keys, and the Screen would need to be modified to keep all players visible, but the Game class would be able to remain largely unchanged.

Definition at line 124 of file Game.h.

List of purely visual DestroyedObjectPopups that need to be drawn.

Definition at line 130 of file Game.h.

list<Rock> Game::_rocks [private]

List of rocks that the player and EnemyCars need to avoid.

Definition at line 128 of file Game.h.

Screen Game::_screen [private]

Handles all drawing operations.

Definition at line 109 of file Game.h.

List of Smokescreen objects that are currently able to delay EnemyCars.

Definition at line 129 of file Game.h.

ALLEGRO_TIMER* Game::_timer [private]

Creates FPS events per second, that are put into _timerEvents.

Definition at line 110 of file Game.h.

ALLEGRO_EVENT_QUEUE* Game::_timerEvents [private]

Catches events from _timer, used to regulate speed of runloop.

Definition at line 111 of file Game.h.

const unsigned int Game::FPS = 30 [static]

Frames per second, the number of times the gameloop is run every second.

Definition at line 39 of file Game.h.


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