Building Game Engines
Player Class Reference

#include <Player.h>

Inheritance diagram for Player:
Inheritance graph
Collaboration diagram for Player:
Collaboration graph

Public Member Functions

 Player (int x, int y, TileMap *newMap, Mix_Chunk *attackSound)
 Constructor. More...
 
 ~Player ()
 Destructor. More...
 
void Update (int x, int y, int *params) override
 Update the position and animation of player as well as camera's position. More...
 
void Render (SDL_Renderer *ren) override
 Render the main character to the active viewport. More...
 
void processInput (SDL_Event e) override
 Process user input. More...
 
void setCurrTileMap (TileMap *newMap)
 Update current tilemap. More...
 
void setCurrController (PlayerController *newController)
 Update current controller. More...
 
PlayerControllergetCurrController ()
 Get current controller. More...
 
void respondToInput (std::vector< bool > &keyPressed)
 
std::pair< int, int > GetPos ()
 Get player's current position. More...
 
void ResetPos ()
 Reset Player's Position. More...
 
void SetPos (int x, int y)
 Map generate use only. More...
 
void SetHP (int amount)
 increment Player's hp by certain amount More...
 
int GetHP ()
 Get player's current HP. More...
 
void AttackEnemies (std::vector< Position > &attackPivots)
 attempt to attck enemies. checks if any of the enemies is in attack range More...
 
void SetEnemies (std::vector< GameObject * > enemies)
 set the reference to all enemies More...
 
void CheckIfDie ()
 Check if player's HP is equal to 0. More...
 
void SetCurrMap (Map *map)
 Set the current map. More...
 
- Public Member Functions inherited from GameObject
 GameObject ()
 Constructor. More...
 
 ~GameObject ()
 Destructor. More...
 
void removeComponent (std::string key)
 Remove a component in this gameobject. More...
 
void addComponent (std::string key, Component *component)
 Add a component in this gameobject. More...
 
ComponentgetComponent (std::string key)
 Get an reference of a component. More...
 
void setActive (bool newState)
 activate / deactivate game object. inactive object won't be updated and rendered More...
 
bool isActive ()
 Get the state of the game. More...
 
int getID ()
 Get the unique id of the gameobject. More...
 

Additional Inherited Members

- Static Public Attributes inherited from GameObject
static int idCounter = 0
 
- Protected Attributes inherited from GameObject
std::map< std::string, Component * > m_components
 Store all the game components in a map. More...
 
bool objState
 deactivated objects won't get updated/rendered More...
 
int id
 the unique id More...
 

Constructor & Destructor Documentation

◆ Player()

Player::Player ( int  x,
int  y,
TileMap newMap,
Mix_Chunk *  attackSound 
)

Constructor.

Parameters
xThe x location of player's initial position.
yThe x location of player's initial position.
newMapReference to the player's tilemap.
attackSoundPlayer attack sound effect.

◆ ~Player()

Player::~Player ( )

Destructor.

Member Function Documentation

◆ AttackEnemies()

void Player::AttackEnemies ( std::vector< Position > &  attackPivots)

attempt to attck enemies. checks if any of the enemies is in attack range

◆ CheckIfDie()

void Player::CheckIfDie ( )

Check if player's HP is equal to 0.

◆ getCurrController()

PlayerController * Player::getCurrController ( )

Get current controller.

◆ GetHP()

int Player::GetHP ( )

Get player's current HP.

Returns
int.

◆ GetPos()

std::pair< int, int > Player::GetPos ( )

Get player's current position.

Returns
A pair which stores two elements.

◆ processInput()

void Player::processInput ( SDL_Event  e)
overridevirtual

Process user input.

Parameters
eA SDL_Event that contains structures for the different event types.

Reimplemented from GameObject.

◆ Render()

void Player::Render ( SDL_Renderer *  ren)
overridevirtual

Render the main character to the active viewport.

Parameters
renReference to SDL renderer.

Reimplemented from GameObject.

◆ ResetPos()

void Player::ResetPos ( )

Reset Player's Position.

◆ respondToInput()

void Player::respondToInput ( std::vector< bool > &  keyPressed)

◆ setCurrController()

void Player::setCurrController ( PlayerController newController)

Update current controller.

Parameters
newControllerThe new controller where the player is using.

◆ SetCurrMap()

void Player::SetCurrMap ( Map map)

Set the current map.

◆ setCurrTileMap()

void Player::setCurrTileMap ( TileMap newMap)

Update current tilemap.

Parameters
newMapThe new map where the player is in.

◆ SetEnemies()

void Player::SetEnemies ( std::vector< GameObject * >  enemies)

set the reference to all enemies

◆ SetHP()

void Player::SetHP ( int  amount)

increment Player's hp by certain amount

◆ SetPos()

void Player::SetPos ( int  x,
int  y 
)

Map generate use only.

◆ Update()

void Player::Update ( int  x,
int  y,
int *  params 
)
overridevirtual

Update the position and animation of player as well as camera's position.

Parameters
xThe x location of player's position.
yThe x location of player's position.
paramsAn int array stores additional data.

Reimplemented from GameObject.