Building Game Engines
EnemyObject Class Reference

This class contains methods about the enemies character in the game. More...

#include <EnemyObject.hpp>

Inheritance diagram for EnemyObject:
Inheritance graph
Collaboration diagram for EnemyObject:
Collaboration graph

Public Member Functions

 EnemyObject (int x, int y, int walkSpd, int runSpd, int dmg, Mix_Chunk *hitSound, Mix_Chunk *hurtSound)
 Constructor. More...
 
 ~EnemyObject ()
 Destructor. More...
 
void init ()
 initialize enemy stats More...
 
void Update (int x, int y, int *params) override
 Update the position and animation of a enemy. More...
 
void Render (SDL_Renderer *ren) override
 Render the enemy to the active viewport. More...
 
void processInput (SDL_Event e) override
 Process user input. More...
 
void GetDirection ()
 
void Move ()
 
bool DetectPlayer (int playerX, int playerY)
 Detect player's position. More...
 
void setCurrTileMap (TileMap *newMap)
 Set current tilemap the enemy is in. More...
 
void setCurrPlayer (GameObject *newplr)
 Set current player. More...
 
void Angry ()
 Detect player's positon and change enemy's state to angry. More...
 
void Rest ()
 Detect player's positon and change enemy's state to moving. More...
 
void StateMachine ()
 Update the enemy's animation state according to the time checkers. More...
 
void checkCollisionWithPlayer ()
 Check if the enemy is colliding with the player. More...
 
void GetNewDest (bool chasingPlayer)
 Get the new moving direction from the pathfinder. More...
 
void setPosX (int x)
 set the enemy's pos x More...
 
void setPosY (int y)
 set the enemy's pos y More...
 
int getPosX ()
 get the enemy's pos x More...
 
int getPosY ()
 get the enemy's pos y More...
 
void setHP (int HP)
 set the enemy's health More...
 
int getHP ()
 get the enemy's health More...
 
void setCollider (CollisionComponent *newCollider)
 set the collider More...
 
void resetPos ()
 reset the enemy pos to default pos More...
 
void ProcessCollision ()
 do the collision check codes. update collider pos, process collisions and retrieve updated positions More...
 
void beAttacked (Position hitDirection)
 a function to trigger be-hit behaviors: knock back and lose health 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...
 

Detailed Description

This class contains methods about the enemies character in the game.

Constructor & Destructor Documentation

◆ EnemyObject()

EnemyObject::EnemyObject ( int  x,
int  y,
int  walkSpd,
int  runSpd,
int  dmg,
Mix_Chunk *  hitSound,
Mix_Chunk *  hurtSound 
)

Constructor.

Parameters
xThe x location of this enemy's initial position.
yThe x location of this enemy's initial position.
walkSpdThe walk speed.
runSpdThe run speed.
dmgThe damage value of an enemy.
hitSoundEnemy getting hit sound effect.
hurtSoundEnemy hurts player sound effect.

◆ ~EnemyObject()

EnemyObject::~EnemyObject ( )

Destructor.

Member Function Documentation

◆ Angry()

void EnemyObject::Angry ( )

Detect player's positon and change enemy's state to angry.

◆ beAttacked()

void EnemyObject::beAttacked ( Position  hitDirection)

a function to trigger be-hit behaviors: knock back and lose health

Parameters
hitDirectionThe direction of the knock back.

◆ checkCollisionWithPlayer()

void EnemyObject::checkCollisionWithPlayer ( )

Check if the enemy is colliding with the player.

◆ DetectPlayer()

bool EnemyObject::DetectPlayer ( int  playerX,
int  playerY 
)

Detect player's position.

Parameters
playerXThe x location of player's position.
playerYThe x location of player's position.

◆ GetDirection()

void EnemyObject::GetDirection ( )

◆ getHP()

int EnemyObject::getHP ( )
inline

get the enemy's health

Returns
the enemy's health

◆ GetNewDest()

void EnemyObject::GetNewDest ( bool  chasingPlayer)

Get the new moving direction from the pathfinder.

Parameters
chasingPlayerwhether the enemy is chasing player or going to random position

◆ getPosX()

int EnemyObject::getPosX ( )
inline

get the enemy's pos x

Returns
int current pos x

◆ getPosY()

int EnemyObject::getPosY ( )
inline

get the enemy's pos y

Returns
int current pos y

◆ init()

void EnemyObject::init ( )

initialize enemy stats

◆ Move()

void EnemyObject::Move ( )

◆ ProcessCollision()

void EnemyObject::ProcessCollision ( )

do the collision check codes. update collider pos, process collisions and retrieve updated positions

◆ processInput()

void EnemyObject::processInput ( SDL_Event  e)
overridevirtual

Process user input.

This class is not useful in current development our enemy has implemented AI technologies. However, we may add some new features in the future.

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

Reimplemented from GameObject.

◆ Render()

void EnemyObject::Render ( SDL_Renderer *  ren)
overridevirtual

Render the enemy to the active viewport.

Parameters
renReference to SDL renderer.

Reimplemented from GameObject.

◆ resetPos()

void EnemyObject::resetPos ( )

reset the enemy pos to default pos

◆ Rest()

void EnemyObject::Rest ( )

Detect player's positon and change enemy's state to moving.

◆ setCollider()

void EnemyObject::setCollider ( CollisionComponent newCollider)
inline

set the collider

Parameters
newColliderthe given collider

◆ setCurrPlayer()

void EnemyObject::setCurrPlayer ( GameObject newplr)

Set current player.

This function aims to refresh the enemy's target player. Identify the user's location aims to refersh the animation states of the enemy.

◆ setCurrTileMap()

void EnemyObject::setCurrTileMap ( TileMap newMap)

Set current tilemap the enemy is in.

Parameters
newMapNew tilemap.

◆ setHP()

void EnemyObject::setHP ( int  HP)
inline

set the enemy's health

Parameters
HPThe amount of the health of the enemy.

◆ setPosX()

void EnemyObject::setPosX ( int  x)
inline

set the enemy's pos x

Parameters
xnew pos x

◆ setPosY()

void EnemyObject::setPosY ( int  y)
inline

set the enemy's pos y

Parameters
ynew pos y

◆ StateMachine()

void EnemyObject::StateMachine ( )

Update the enemy's animation state according to the time checkers.

◆ Update()

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

Update the position and animation of a enemy.

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

Reimplemented from GameObject.