Wolf3D
Public Types | Public Member Functions | List of all members
Enemy Class Reference

Public Types

enum  state {
  DIE = 0 , PAIN = 4 , IDLE = 6 , SHOOT = 14 ,
  WALK = 17
}
 States that the Enemy's animation could be in.
 

Public Member Functions

 Enemy (int id, std::string type, double position_x, double position_y, double direction, Player *player, std::vector< std::vector< int >> *world_map)
 Construct the Enemy object. More...
 
double calculate_rotation (double position_x, double position_y, bool angle=false)
 Calculate the rotation of the Enemy relative to a target's Postion X/Y. More...
 
void ai (double *position_x, double *position_y, std::vector< std::vector< int >> *world_map, json *sprite)
 Perform the Enemy's Artificial Intelligence. More...
 
void handle_shot (double *position_x, double *position_y)
 A subset of the Enemy's Artificial Intelligence for when the Player shoots within a certain range to the Enemy. More...
 
std::pair< bool, double > line_of_sight (double *position_x, double *position_y, std::vector< std::vector< int >> *world_map)
 Calculating if the Enemy has Line of Sight with the provided coordinates and wall collisions with the world map. More...
 
int get_id ()
 Get the Enemy's id. More...
 
std::string get_type ()
 Get the Enemy's type. More...
 
double get_position_x ()
 Get the Enemy's position x. More...
 
double get_position_y ()
 Get the Enemy's position y. More...
 
int get_direction ()
 Get the Enemy's direction. More...
 
void set_rotation (int rotation)
 Set the Enemy's rotation. More...
 
double get_health ()
 Get the Enemy's health. More...
 
double remove_health (double health)
 Remove health from the Enemy's health. More...
 
void set_health (double health)
 Set the Enemy's health. More...
 
bool is_alive ()
 If the Enemy is alive. More...
 
int get_state ()
 Get the Enemy's animation state. More...
 
void set_state (int state)
 Set the Enemy's animation state. More...
 
void play_sound (int sound, double arg0)
 Play a sound effect. More...
 
void set_tracking_player (bool tracking_player)
 Set if the Enemy is tracking the Player. More...
 
void init_texture (RenderWindow *window)
 Load the textures into memory. More...
 
std::vector< Uint32 > get_texture ()
 Get the Enemy's current texture accounting for their state. More...
 
void update ()
 Update the timer.
 

Constructor & Destructor Documentation

◆ Enemy()

Enemy::Enemy ( int  id,
std::string  type,
double  position_x,
double  position_y,
double  direction,
Player player,
std::vector< std::vector< int >> *  world_map 
)

Construct the Enemy object.

Parameters
idIndex of the Enemy
typeType of the Enemy
position_xThe Enemy's Position X
position_yThe Enemy's Position Y
directionThe Enemy's Direction (0-359)
playerThe Player Class
world_mapThe vector of the world map

Member Function Documentation

◆ ai()

void Enemy::ai ( double *  position_x,
double *  position_y,
std::vector< std::vector< int >> *  world_map,
json *  sprite 
)

Perform the Enemy's Artificial Intelligence.

Parameters
position_xThe Player's Position X
position_yThe Player's Position Y
world_mapThe vector of the world map
spriteThe "vector" of the sprites

◆ calculate_rotation()

double Enemy::calculate_rotation ( double  position_x,
double  position_y,
bool  angle = false 
)

Calculate the rotation of the Enemy relative to a target's Postion X/Y.

Parameters
position_xThe target's Position X
position_yThe target's Position Y
angleIf false, return the rotation (1-8). If true, return the angle (0-359)
Returns
double

◆ get_direction()

int Enemy::get_direction ( )

Get the Enemy's direction.

Returns
int

◆ get_health()

double Enemy::get_health ( )

Get the Enemy's health.

Returns
double

◆ get_id()

int Enemy::get_id ( )

Get the Enemy's id.

Returns
int

◆ get_position_x()

double Enemy::get_position_x ( )

Get the Enemy's position x.

Returns
double

◆ get_position_y()

double Enemy::get_position_y ( )

Get the Enemy's position y.

Returns
double

◆ get_state()

int Enemy::get_state ( )

Get the Enemy's animation state.

Returns
int

◆ get_texture()

std::vector< Uint32 > Enemy::get_texture ( )

Get the Enemy's current texture accounting for their state.

Returns
std::vector<Uint32>

◆ get_type()

std::string Enemy::get_type ( )

Get the Enemy's type.

Returns
std::string

◆ handle_shot()

void Enemy::handle_shot ( double *  position_x,
double *  position_y 
)

A subset of the Enemy's Artificial Intelligence for when the Player shoots within a certain range to the Enemy.

Parameters
position_xThe Player's Position X
position_yThe Player's Position Y

◆ init_texture()

void Enemy::init_texture ( RenderWindow window)

Load the textures into memory.

Parameters
windowRenderWindow Renderer to use to load the textures from

◆ is_alive()

bool Enemy::is_alive ( )

If the Enemy is alive.

Returns
true The Enemy is alive
false The Enemy is not alive

◆ line_of_sight()

std::pair< bool, double > Enemy::line_of_sight ( double *  position_x,
double *  position_y,
std::vector< std::vector< int >> *  world_map 
)

Calculating if the Enemy has Line of Sight with the provided coordinates and wall collisions with the world map.

Parameters
position_xThe Player's Position X
position_yThe Player's Position Y
world_mapThe vector of the world map
Returns
std::pair<bool, double> Bool = If there is Line Of Sight Double = Perpendicular distance from the Enemy to the target

◆ play_sound()

void Enemy::play_sound ( int  sound,
double  arg0 
)

Play a sound effect.

Parameters
soundThe corresponding ::state of the sound effect to play
arg0Argument 0 for sound effect playback

◆ remove_health()

double Enemy::remove_health ( double  health)

Remove health from the Enemy's health.

Parameters
healthHeath to remove from the Enemy's health
Returns
double The new health of the Enemy

◆ set_health()

void Enemy::set_health ( double  health)

Set the Enemy's health.

Parameters
healthHeath to set the Enemy's health to

◆ set_rotation()

void Enemy::set_rotation ( int  rotation)

Set the Enemy's rotation.

Parameters
rotationRotation of the Enemy (1-8)

◆ set_state()

void Enemy::set_state ( int  state)

Set the Enemy's animation state.

Parameters
stateThe state to set

◆ set_tracking_player()

void Enemy::set_tracking_player ( bool  tracking_player)

Set if the Enemy is tracking the Player.

Parameters
tracking_player

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