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

Player handles everthing about player-releated context, that means Castle, Cannon, Target, Ball, Camera. More...

#include <player.h>

Public Member Functions

 Player (IrrlichtDevice *device, scene::ISceneManager *smgr, video::IVideoDriver *driver, core::vector3df position, Physics *physics, Keyboard *keyboard, PLAYER_TYPE type, PLAYER_POSITION side=STRAIGHT)
 Default constructor. More...
 
 ~Player ()
 
scene::IMeshSceneNode * getNode ()
 Get cannon irrlicht node. More...
 
core::vector3df getCannonRange ()
 Get how far Z the cannon can SHOOT. More...
 
void focusCamera ()
 Set Active camera. More...
 
void setCannon ()
 Setup cannon based on player side. More...
 
bool loop (HUD::HUD *hud)
 Main loop of player. More...
 
void reset ()
 Reset cannon angle and rotation. More...
 
bool checkTarget ()
 Check if target position is the same or it is changed. More...
 

Public Attributes

Keyboardkeyboard
 Keyboard of the player. More...
 
core::stringw name
 Name of the player. More...
 
PLAYER_TYPE type
 Type of player PLAYER_TYPE. More...
 

Private Attributes

scene::ISceneManager * smgr
 
video::IVideoDriver * driver
 
irr::IrrlichtDevice * device
 
Cameracamera
 Main camera of the player. More...
 
Physicsphysics
 
Castlecastle
 Castle of the player. More...
 
Cannoncannon
 Cannon of the player. More...
 
PLAYER_POSITION side
 Side of the player PLAYER_POSITION. More...
 

Detailed Description

Player handles everthing about player-releated context, that means Castle, Cannon, Target, Ball, Camera.

There are 2 type of player: AI or HUMAN. Only HUMAN is available for now. This class will build castle, setting up cannons, handles user inputs.

Constructor & Destructor Documentation

◆ Player()

Player::Player ( IrrlichtDevice *  device,
scene::ISceneManager *  smgr,
video::IVideoDriver *  driver,
core::vector3df  position,
Physics physics,
Keyboard keyboard,
PLAYER_TYPE  type,
PLAYER_POSITION  side = STRAIGHT 
)

Default constructor.

This Will initialize cannon, castle and keyboard.

Parameters
positionvector3df position of the castle.
keyboard::Keyboard keyboard map of the player
typePLAYER_TYPE type of player
sidePLAYER_POSITION side of player
See also
Cannon
GameManager::loop();
KEYBOARD::Keyboard::OnEvent();
Castle
11  {
12  this->type = type;
13  this->smgr = smgr;
14  this->driver = driver;
15  this->physics = physics;
16  this->keyboard = keyboard;
17  this->device = device;
18  this->camera = 0;
19  this->side = side;
20  this->castle = new Castle(this->smgr,this->physics, device, this->driver, position);
21  position = this->castle->calculateAbsoluteCenter() + core::vector3df(0,0,this->castle->getSideSize('l').X);
22  this->cannon = new Cannon(device, smgr,driver,position,physics);
23  if(type == HUMAN) { log1("Player type HUMAN"); }
24  else { log1("Player type AI"); }
25 }
Definition: player.h:17
irr::IrrlichtDevice * device
Definition: player.h:35
Cannon handles the cannon object.
Definition: cannon.h:17
The Castle handles all things related to the Castles Building, treasure, physics and collisions...
Definition: castle.h:16
PLAYER_POSITION side
Side of the player PLAYER_POSITION.
Definition: player.h:44
PLAYER_TYPE type
Type of player PLAYER_TYPE.
Definition: player.h:51
Cannon * cannon
Cannon of the player.
Definition: player.h:42
Physics * physics
Definition: player.h:38
#define log1(_Message)
Log message of 1 level verbosity.
Definition: Logger.h:28
Keyboard * keyboard
Keyboard of the player.
Definition: player.h:47
Castle * castle
Castle of the player.
Definition: player.h:40
Camera * camera
Main camera of the player.
Definition: player.h:37
core::vector3df calculateAbsoluteCenter()
Get center of the castle in Irrlicht world coordinates.
Definition: castle.cpp:179
video::IVideoDriver * driver
Definition: player.h:34
scene::ISceneManager * smgr
Definition: player.h:33
core::vector3df getSideSize(char side)
Get size from a side.
Definition: castle.cpp:156

◆ ~Player()

Player::~Player ( )
26  {
27  // delete this->castle;
28  // delete this->cannon;
29 }

Member Function Documentation

◆ checkTarget()

bool Player::checkTarget ( )

Check if target position is the same or it is changed.

Returns
true if target is moved enough(that means it is hitted hard)
See also
Castle::checkTarget()
33  {
34  return this->castle->checkTarget();
35 }
bool checkTarget()
Check if target is moved TARGET_OFFSET is the max offset of the target from initial position...
Definition: castle.cpp:185
Castle * castle
Castle of the player.
Definition: player.h:40

◆ focusCamera()

void Player::focusCamera ( )

Set Active camera.

59  {
60  #if (DEBUG_OUTPUT_MASK & 2)
61  return;
62  #endif
63  if(this->type == HUMAN){
64  core::vector3df offset;
65  switch(this->side){
66  case STRAIGHT:
67  offset = core::vector3df(
68  0,
69  this->cannon->getBoundingBox().MaxEdge.Y+0.6f,
70  -2.f);
71  break;
72  case OPPOSITE:
73  offset = core::vector3df(
74  0,
75  this->cannon->getBoundingBox().MaxEdge.Y+0.6f,
76  -2.f);
77  };
78  core::vector3df rotation = this->cannon->getCannon()->getRotation();
79  this->cannon->setCamera(offset,rotation,smgr,this->cannon->getCannon());
80  }
81 }
void setCamera(core::vector3df offset, core::vector3df rotation, scene::ISceneManager *smgr, scene::ISceneNode *node)
Set camera of the cannon.
Definition: cannon.cpp:259
Definition: player.h:17
PLAYER_POSITION side
Side of the player PLAYER_POSITION.
Definition: player.h:44
PLAYER_TYPE type
Type of player PLAYER_TYPE.
Definition: player.h:51
scene::IMeshSceneNode * getCannon()
Get meshnode of the cannon.
Definition: cannon.cpp:142
Cannon * cannon
Cannon of the player.
Definition: player.h:42
core::aabbox3df getBoundingBox()
Get bounding box of the cannon.
Definition: cannon.cpp:139
Definition: player.h:25
scene::ISceneManager * smgr
Definition: player.h:33
Definition: player.h:24

◆ getCannonRange()

core::vector3df Player::getCannonRange ( )

Get how far Z the cannon can SHOOT.

The value is random withing cannon power. It is used to setup the second castle position

56  {
57 return this->cannon->getRange();
58 }
core::vector3df getRange()
With some randomness get a position Z based on the cannon power- So there always be a trajectory to h...
Definition: cannon.cpp:266
Cannon * cannon
Cannon of the player.
Definition: player.h:42

◆ getNode()

scene::IMeshSceneNode * Player::getNode ( )

Get cannon irrlicht node.

Returns
IMeshscene node
30  {
31  return this->cannon->getCannon();
32 }
scene::IMeshSceneNode * getCannon()
Get meshnode of the cannon.
Definition: cannon.cpp:142
Cannon * cannon
Cannon of the player.
Definition: player.h:42

◆ loop()

bool Player::loop ( HUD::HUD hud)

Main loop of player.

Parameters
hudHUD hud of player.
Returns
bool true when player consume his turn. That means the ball is on ground and the user has consumed the SHOOT event
See also
GameManager::loop();
HUD::HUD::animatePower();
::Keyboard::IsKeyDown();
Cannon::shoot();
Ball::moveCamera();
36  {
37  Key* key = this->keyboard->IsKeyDown();
38  ACTION_KEYBOARD action = key == 0 ? ACTION_NULL : key->action;
39  if(!this->cannon->moveCannon(action)) return false;
40  switch(action){
41  case SHOOT:
42  hud->animatePower();
43  break;
44  default:
45  if(this->keyboard->getLastKey()->action == SHOOT){
46  this->cannon->shoot(hud->getPower());
47  this->keyboard->resetLastKey();
48  #if (DEBUG_OUTPUT_MASK & 2)
49  return false;
50  #endif
51  }
52  break;
53  };
54  return true;
55 }
void animatePower()
Animate power bar.
Definition: hud.cpp:36
ACTION_KEYBOARD
Definition: keyboard.h:10
void shoot(f32 power)
Based on the angles vector: initBarrelVector and the cannon power, this will shoot a Ball...
Definition: cannon.cpp:89
f32 getPower()
Get ratio of the power selected out of total power.
Definition: hud.cpp:53
Key * getLastKey()
Get last key pressed.
Definition: keyboard.cpp:50
ACTION_KEYBOARD action
Definition: keyboard.h:26
Definition: keyboard.h:19
Cannon * cannon
Cannon of the player.
Definition: player.h:42
Keyboard * keyboard
Keyboard of the player.
Definition: player.h:47
Definition: keyboard.h:20
void resetLastKey()
Reset last key pressed variable.
Definition: keyboard.cpp:53
Key is a class that describe a irrlicht EKEY_CODE and what ACTION_KEYBOARD is referring.
Definition: keyboard.h:23
bool moveCannon(ACTION_KEYBOARD action)
Handle moves in cannon left or right top and down (only angles )
Definition: cannon.cpp:210
Key * IsKeyDown()
Return a pressed ::Key.
Definition: keyboard.cpp:24

◆ reset()

void Player::reset ( )

Reset cannon angle and rotation.

94  {
95  // core::vector3df position = this->cannon->getCannon()->getAbsolutePosition();
96  core::vector3df rotation = this->cannon->rotation;
97  log1("Reset player");
98  this->cannon->setRotation(rotation);
99 
100 }
void setRotation(core::vector3df rotation)
Set rotation of the cannon.
Definition: cannon.cpp:286
Cannon * cannon
Cannon of the player.
Definition: player.h:42
#define log1(_Message)
Log message of 1 level verbosity.
Definition: Logger.h:28
core::vector3df rotation
Definition: cannon.h:47

◆ setCannon()

void Player::setCannon ( )

Setup cannon based on player side.

82  {
83  core::vector3df position = core::vector3df(0,0,0);
84  switch(this->side){
85 
86  case OPPOSITE:
87  position = this->castle->calculateAbsoluteCenter() - core::vector3df(0,0,this->castle->getSideSize('l').X);
88  this->cannon->initCannon(position, core::vector3df(0,180,0));
89  break;
90 
91  default: break;
92  }
93 }
PLAYER_POSITION side
Side of the player PLAYER_POSITION.
Definition: player.h:44
Cannon * cannon
Cannon of the player.
Definition: player.h:42
void initCannon(core::vector3df position, core::vector3df rotation)
Initialize with desired position and rotation.
Definition: cannon.cpp:199
Castle * castle
Castle of the player.
Definition: player.h:40
core::vector3df calculateAbsoluteCenter()
Get center of the castle in Irrlicht world coordinates.
Definition: castle.cpp:179
Definition: player.h:25
core::vector3df getSideSize(char side)
Get size from a side.
Definition: castle.cpp:156

Member Data Documentation

◆ camera

Camera* Player::camera
private

Main camera of the player.

◆ cannon

Cannon* Player::cannon
private

Cannon of the player.

◆ castle

Castle* Player::castle
private

Castle of the player.

◆ device

irr::IrrlichtDevice* Player::device
private

◆ driver

video::IVideoDriver* Player::driver
private

◆ keyboard

Keyboard* Player::keyboard

Keyboard of the player.

◆ name

core::stringw Player::name

Name of the player.

◆ physics

Physics* Player::physics
private

◆ side

PLAYER_POSITION Player::side
private

Side of the player PLAYER_POSITION.

◆ smgr

scene::ISceneManager* Player::smgr
private

◆ type

PLAYER_TYPE Player::type

Type of player PLAYER_TYPE.


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