Castle Battle  1.0
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
GameManager Class Reference

GameManager is the main manager of the gameplay. More...

#include <gamemanager.h>

Public Member Functions

 GameManager (scene::ISceneManager *smgr, video::IVideoDriver *driver, IrrlichtDevice *device, core::vector3df worldPosition, Physics *physics, core::stringw *names=0)
 Default constructor. More...
 
 ~GameManager ()
 
void initGamePlay (core::stringw *names=0)
 Create players and start gameplay. More...
 
bool loop ()
 Main Gameplay loop. More...
 
int getWinner ()
 Get the winner. More...
 
core::stringw * getNames ()
 Get player names. More...
 

Public Attributes

bool stop
 If someone win, stop is set to true. More...
 

Private Member Functions

void initKeyboard ()
 Set the Irrlicht device event receiver with a Keyboard instance. More...
 

Private Attributes

scene::ISceneManager * smgr
 
video::IVideoDriver * driver
 
IrrlichtDevice * device
 
Physicsphysics
 
Playerplayers [2]
 Array of players. More...
 
bool turn
 Turn to play: true: first player, false second player. More...
 
core::vector3df worldPosition
 World initial position, by default is setted to Terrain center. More...
 
HUD::HUDhud
 HUD of the gameplay. More...
 
Keyboard keyboard
 The keyboard map of each players. More...
 
core::stringw * names
 Player names. More...
 

Detailed Description

GameManager is the main manager of the gameplay.

It will create the players, castle, cannons and will start the loop of the gameplay.

Constructor & Destructor Documentation

◆ GameManager()

GameManager::GameManager ( scene::ISceneManager *  smgr,
video::IVideoDriver *  driver,
IrrlichtDevice *  device,
core::vector3df  worldPosition,
Physics physics,
core::stringw *  names = 0 
)

Default constructor.

Given players names, and Application Irrlicht and Physics instances, this will create players, castle, mapping keyboard and start the gameplay.

Parameters
Irrlichtinstances and Physic instance
namesstringw array of names. Optional. If no specified Player1 and Player2 will be the names.
See also
Launcher.
Player.
Application.
Application::loop().
10  {
11  this->smgr = smgr;
12  this->device = device;
13  this->driver = driver;
14  this->physics = physics;
16  this->turn = true;
17  this->stop = false;
19  initKeyboard();
20 }
video::IVideoDriver * driver
Definition: gamemanager.h:14
void initKeyboard()
Set the Irrlicht device event receiver with a Keyboard instance.
Definition: gamemanager.cpp:60
Physics * physics
Definition: gamemanager.h:16
IrrlichtDevice * device
Definition: gamemanager.h:15
scene::ISceneManager * smgr
Definition: gamemanager.h:13
bool stop
If someone win, stop is set to true.
Definition: gamemanager.h:33
core::stringw * names
Player names.
Definition: gamemanager.h:28
bool turn
Turn to play: true: first player, false second player.
Definition: gamemanager.h:20
void initGamePlay(core::stringw *names=0)
Create players and start gameplay.
Definition: gamemanager.cpp:25
core::vector3df worldPosition
World initial position, by default is setted to Terrain center.
Definition: gamemanager.h:22

◆ ~GameManager()

GameManager::~GameManager ( )
21  {
22  // delete this->players;
23 }

Member Function Documentation

◆ getNames()

core::stringw * GameManager::getNames ( )

Get player names.

67  {
68  return this->names;
69 }
core::stringw * names
Player names.
Definition: gamemanager.h:28

◆ getWinner()

int GameManager::getWinner ( )

Get the winner.

64  {
65  return turn ? 0 : 1; // return !turn is better?
66 }
bool turn
Turn to play: true: first player, false second player.
Definition: gamemanager.h:20

◆ initGamePlay()

void GameManager::initGamePlay ( core::stringw *  names = 0)

Create players and start gameplay.

25  {
26  //for now all the players will have the same HUD
27 
28  this->hud = new HUD::HUD(device,driver);
29  log1("HUD initialized");
30  this->players[0] = new Player(
31  this->device,
32  this->smgr,
33  this->driver,
34  this->worldPosition,
35  this->physics,
36  &this->keyboard,
37  HUMAN,
38  STRAIGHT);
39  this->players[0]->name = (names) ? names[0] : L"Player 1";
40  this->players[1] = new Player(
41  this->device,
42  this->smgr,
43  this->driver,
44  core::vector3df(this->worldPosition.X, 0, this->players[0]->getCannonRange().Z),
45  this->physics,
46  &this->keyboard,
47  HUMAN,
48  OPPOSITE);
49  this->players[1]->name = (names) ? names[1] : L"Player 2";
50  this->players[1]->setCannon();
51  this->players[0]->focusCamera();
52  this->hud->env->drawAll();
53  this->hud->setPlayerName(this->players[0]->name);
54  this->turn = true;
55  this->keyboard.resetLastKey();
56  this->names = names;
57  log1("Default turn start: PLAYER 1");
58 
59 }
Definition: player.h:17
video::IVideoDriver * driver
Definition: gamemanager.h:14
Physics * physics
Definition: gamemanager.h:16
IrrlichtDevice * device
Definition: gamemanager.h:15
HUD::HUD * hud
HUD of the gameplay.
Definition: gamemanager.h:24
void focusCamera()
Set Active camera.
Definition: player.cpp:59
scene::ISceneManager * smgr
Definition: gamemanager.h:13
gui::IGUIEnvironment * env
Irrlicht GUI Enviroment.
Definition: hud.h:48
#define log1(_Message)
Log message of 1 level verbosity.
Definition: Logger.h:28
void setCannon()
Setup cannon based on player side.
Definition: player.cpp:82
HUD of the gameplay.
Definition: hud.h:19
Player * players[2]
Array of players.
Definition: gamemanager.h:18
void resetLastKey()
Reset last key pressed variable.
Definition: keyboard.cpp:53
core::stringw name
Name of the player.
Definition: player.h:49
core::stringw * names
Player names.
Definition: gamemanager.h:28
bool turn
Turn to play: true: first player, false second player.
Definition: gamemanager.h:20
void setPlayerName(core::stringw name)
Set player name.
Definition: hud.cpp:58
Keyboard keyboard
The keyboard map of each players.
Definition: gamemanager.h:26
Definition: player.h:25
core::vector3df worldPosition
World initial position, by default is setted to Terrain center.
Definition: gamemanager.h:22
Player handles everthing about player-releated context, that means Castle, Cannon, Target, Ball, Camera.
Definition: player.h:31
Definition: player.h:24

◆ initKeyboard()

void GameManager::initKeyboard ( )
private

Set the Irrlicht device event receiver with a Keyboard instance.

60  {
61  this->device->setEventReceiver(&this->keyboard);
62  log1("Keyboard mapped");
63 }
IrrlichtDevice * device
Definition: gamemanager.h:15
#define log1(_Message)
Log message of 1 level verbosity.
Definition: Logger.h:28
Keyboard keyboard
The keyboard map of each players.
Definition: gamemanager.h:26

◆ loop()

bool GameManager::loop ( )

Main Gameplay loop.

The Application main loop is propagate here. This loop is propagate to Player::loop()

Returns
true if someone win.
See also
Application::loop().
Player::loop().
70  {
71  this->hud->env->drawAll();
72  if(stop) return true;
73  if(this->turn){
74  if(!this->players[0]->loop(hud)){
75  this->turn = false;
76  this->players[1]->reset();
77  this->players[1]->focusCamera();
78  hud->setPlayerName(this->players[1]->name);
79  hud->resetPower();
80  log1("TURN: PLAYER2");
81  }
82  if(this->players[1]->checkTarget()){ stop = true; return true; }
83 
84  }
85  else {
86  if(!this->players[1]->loop(hud)){
87  this->turn = true;
88  this->players[0]->reset();
89  this->players[0]->focusCamera();
90  hud->setPlayerName(this->players[0]->name);
91  hud->resetPower();
92  log1("TURN: PLAYER1");
93  }
94  if(this->players[0]->checkTarget()){ stop = true; return true; }
95 
96 
97  }
98  // never goes here;
99  return false;
100 }
HUD::HUD * hud
HUD of the gameplay.
Definition: gamemanager.h:24
void focusCamera()
Set Active camera.
Definition: player.cpp:59
void reset()
Reset cannon angle and rotation.
Definition: player.cpp:94
bool loop()
Main Gameplay loop.
Definition: gamemanager.cpp:70
gui::IGUIEnvironment * env
Irrlicht GUI Enviroment.
Definition: hud.h:48
#define log1(_Message)
Log message of 1 level verbosity.
Definition: Logger.h:28
bool stop
If someone win, stop is set to true.
Definition: gamemanager.h:33
Player * players[2]
Array of players.
Definition: gamemanager.h:18
bool turn
Turn to play: true: first player, false second player.
Definition: gamemanager.h:20
void setPlayerName(core::stringw name)
Set player name.
Definition: hud.cpp:58
void resetPower()
Reset power.
Definition: hud.cpp:62

Member Data Documentation

◆ device

IrrlichtDevice* GameManager::device
private

◆ driver

video::IVideoDriver* GameManager::driver
private

◆ hud

HUD::HUD* GameManager::hud
private

HUD of the gameplay.

For now all the players will have the same HUD

◆ keyboard

Keyboard GameManager::keyboard
private

The keyboard map of each players.

For now all players will have same Keyboard map

◆ names

core::stringw* GameManager::names
private

Player names.

◆ physics

Physics* GameManager::physics
private

◆ players

Player* GameManager::players[2]
private

Array of players.

◆ smgr

scene::ISceneManager* GameManager::smgr
private

◆ stop

bool GameManager::stop

If someone win, stop is set to true.

◆ turn

bool GameManager::turn
private

Turn to play: true: first player, false second player.

◆ worldPosition

core::vector3df GameManager::worldPosition
private

World initial position, by default is setted to Terrain center.


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