Tower Defence 2
Public Member Functions | Friends | List of all members
GameEngine Class Reference

#include <engine.h>

Public Member Functions

 GameEngine (double time, double timestep, int score, GameLevel &game_level, GameMap &game_map)
 
double time () const
 
const double timestep () const
 
int score () const
 
int money () const
 
int lives () const
 
void change_game_speed (GameSpeed new_speed)
 Change the game speed to fast or normal.
 
void increment_time ()
 Increments the game time by one timestep.
 
void add_score (int amount)
 Change player's score. Game score can't go below zero.
 
bool add_money (int amount)
 
void reduce_life ()
 
void upgrade_tower (int x, int y, int index)
 Upgrade existing tower into new one.
 
void change_targeting (TargetingPolicy new_policy)
 Change targeting policy of all towers.
 
void add_enemy (Enemy *enemy)
 Add new enemy to game map.
 
void advance_game_level ()
 
void enemy_movement ()
 
Enemyfind_targets (Tower *tower, Enemies &enemies)
 
void towers_attack (graphicsEngine &gE)
 
GameState update (graphicsEngine &gE)
 
GameMap game_map ()
 Getter for game map.
 

Friends

bool update_high_score (const std::string &filename, GameEngine engine)
 

Detailed Description

Game class contains the game map, enemies, towers and game stats. This class is also responsible for the implementation of the main game loop which modifies the properties of the objects by using the rules of the game logic.

Member Function Documentation

bool GameEngine::add_money ( int  amount)

Change player's money.

Returns
false and doesn't change the value if the amount of change would reduce player's money below zero otherwise true and changes the money based on the amount given.
void GameEngine::advance_game_level ( )

Handles level specific tasks such as spawning new enemies according to the game level description.

void GameEngine::enemy_movement ( )

Move enemies along the path.

  • If enemy reaches the end of the path
    • Remove enemy from the game
    • Reduce players score
    • Reduce one life from player
Enemy * GameEngine::find_targets ( Tower tower,
Enemies &  enemies 
)

Other combat objects that this object can target.

  • withing the attack range
  • targeting policy
void GameEngine::reduce_life ( )

Reduce one life from the player. Player dies if lives reach zero.

Returns
true if player dies else false.
void GameEngine::towers_attack ( graphicsEngine &  gE)

Towers attack enemies. Increase score and money if enemies die and remove dead enemies from the game.

GameState GameEngine::update ( graphicsEngine &  gE)

Updates the game loop. In practice this method will be called by the main graphics loop.

Friends And Related Function Documentation

bool update_high_score ( const std::string &  filename,
GameEngine  engine 
)
friend

Updates high score if needed, takes the name of the file where high scores are kept Returns true if high scores were changed High scores are visible on the menu screen


The documentation for this class was generated from the following files: