This class contains methods about the enemies character in the game. More...
#include <EnemyObject.hpp>
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... | |
Component * | getComponent (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... | |
This class contains methods about the enemies character in the game.
EnemyObject::EnemyObject | ( | int | x, |
int | y, | ||
int | walkSpd, | ||
int | runSpd, | ||
int | dmg, | ||
Mix_Chunk * | hitSound, | ||
Mix_Chunk * | hurtSound | ||
) |
Constructor.
x | The x location of this enemy's initial position. |
y | The x location of this enemy's initial position. |
walkSpd | The walk speed. |
runSpd | The run speed. |
dmg | The damage value of an enemy. |
hitSound | Enemy getting hit sound effect. |
hurtSound | Enemy hurts player sound effect. |
EnemyObject::~EnemyObject | ( | ) |
Destructor.
void EnemyObject::Angry | ( | ) |
Detect player's positon and change enemy's state to angry.
void EnemyObject::beAttacked | ( | Position | hitDirection | ) |
a function to trigger be-hit behaviors: knock back and lose health
hitDirection | The direction of the knock back. |
void EnemyObject::checkCollisionWithPlayer | ( | ) |
Check if the enemy is colliding with the player.
bool EnemyObject::DetectPlayer | ( | int | playerX, |
int | playerY | ||
) |
Detect player's position.
playerX | The x location of player's position. |
playerY | The x location of player's position. |
void EnemyObject::GetDirection | ( | ) |
|
inline |
get the enemy's health
void EnemyObject::GetNewDest | ( | bool | chasingPlayer | ) |
Get the new moving direction from the pathfinder.
chasingPlayer | whether the enemy is chasing player or going to random position |
|
inline |
get the enemy's pos x
|
inline |
get the enemy's pos y
void EnemyObject::init | ( | ) |
initialize enemy stats
void EnemyObject::Move | ( | ) |
void EnemyObject::ProcessCollision | ( | ) |
do the collision check codes. update collider pos, process collisions and retrieve updated positions
|
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.
e | A SDL_Event that contains structures for the different event types. |
Reimplemented from GameObject.
|
overridevirtual |
Render the enemy to the active viewport.
ren | Reference to SDL renderer. |
Reimplemented from GameObject.
void EnemyObject::resetPos | ( | ) |
reset the enemy pos to default pos
void EnemyObject::Rest | ( | ) |
Detect player's positon and change enemy's state to moving.
|
inline |
set the collider
newCollider | the given collider |
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.
void EnemyObject::setCurrTileMap | ( | TileMap * | newMap | ) |
Set current tilemap the enemy is in.
newMap | New tilemap. |
|
inline |
set the enemy's health
HP | The amount of the health of the enemy. |
|
inline |
set the enemy's pos x
x | new pos x |
|
inline |
set the enemy's pos y
y | new pos y |
void EnemyObject::StateMachine | ( | ) |
Update the enemy's animation state according to the time checkers.
|
overridevirtual |
Update the position and animation of a enemy.
x | The x location of player's position. |
y | The x location of player's position. |
params | An int array stores additional data. |
Reimplemented from GameObject.