Rally X
ELEN3009 Project by Justin Wernick and David Schneider
|
GameObject that chases the player around the maze. More...
#include <EnemyCar.h>
Public Member Functions | |
EnemyCar (double x, double y) | |
Creates an EnemyCar at the given coordinates. | |
void | update (const Maze &maze, const list< PlayerCar > &players, const list< Rock > &rocks) |
Processes one frame's worth of activity for the object, called every frame. | |
void | crash () |
Function that is called when an EnemyCar crashes into a PlayerCar. | |
void | blind () |
Function that is called when an EnemyCar drives into a Smokescreen. | |
Private Types | |
enum | States { BLINDED, CHASING } |
States that define how the EnemyCar's AI should behave. More... | |
Private Member Functions | |
void | checkFacing (const Maze &maze, double chasingX, double chasingY, const list< Rock > &rocks) |
Updates the direction that the EnemyCar is facing, if neccesary. | |
bool | rockAtLocation (double x, double y, const list< Rock > &rocks) |
Iterates through a list of Rocks and determines if moving to a given position would result in a collision. | |
Private Attributes | |
States | _state |
The state that the object is currently in. | |
double | _targetX |
The x coordinate that the EnemyCar is driving towards. | |
double | _targetY |
The y coordinate that the EnemyCar is driving towards. |
GameObject that chases the player around the maze.
Attempts to collide with the player, causing the player to lose.
Definition at line 21 of file EnemyCar.h.
enum EnemyCar::States [private] |
States that define how the EnemyCar's AI should behave.
This would need to be expanded to include more states in order to make the enemies appear smarter.
BLINDED |
The EnemyCar can not see, and so does not move. |
CHASING |
The EnemyCar tries to drive to the block that the player is currently on. |
Definition at line 61 of file EnemyCar.h.
EnemyCar::EnemyCar | ( | double | x, |
double | y | ||
) |
Creates an EnemyCar at the given coordinates.
[in] | x | The x coordinate of the EnemyCar's initial position. |
[in] | y | The y coordinate of the EnemyCar's initial position. |
Definition at line 3 of file EnemyCar.cpp.
void EnemyCar::blind | ( | ) |
Function that is called when an EnemyCar drives into a Smokescreen.
Definition at line 100 of file EnemyCar.cpp.
void EnemyCar::checkFacing | ( | const Maze & | maze, |
double | chasingX, | ||
double | chasingY, | ||
const list< Rock > & | rocks | ||
) | [private] |
Updates the direction that the EnemyCar is facing, if neccesary.
The facing is only changed once the current _targetX and _targetY are reached. After that, a facing is chosen that points into an empty block (no maze walls or rocks) that is closest to the chasing x and y using a straight line. This results in the enemy not always taking the shortest route, but it makes it possible to escape enemies. _targetX and _targetY are updated to one block in the new facing direction. The enemy may only turn around and head backwards if there is no other options, so once the enemy starts driving down narrow a path it will continue to the end of the path.
[in] | maze | The maze that confines the EnemyCar's movements. |
[in] | chasingX | The x coordinate that the EnemyCar is ultimately trying to reach. |
[in] | chasingY | The y coordinate that the EnemyCar is ultimately trying to reach. |
[in] | rocks | The Rocks that the EnemyCar needs to avoid. |
Definition at line 26 of file EnemyCar.cpp.
void EnemyCar::crash | ( | ) |
Function that is called when an EnemyCar crashes into a PlayerCar.
Definition at line 95 of file EnemyCar.cpp.
bool EnemyCar::rockAtLocation | ( | double | x, |
double | y, | ||
const list< Rock > & | rocks | ||
) | [private] |
Iterates through a list of Rocks and determines if moving to a given position would result in a collision.
[in] | x | The potential new x coordinate. |
[in] | y | The potential new y coordinate. |
[in] | rocks | The Rocks that are checked for a collision at x and y. |
Definition at line 86 of file EnemyCar.cpp.
void EnemyCar::update | ( | const Maze & | maze, |
const list< PlayerCar > & | players, | ||
const list< Rock > & | rocks | ||
) |
Processes one frame's worth of activity for the object, called every frame.
Primarily adjusts the facing if neccesary and then moves using the inhereted move function.
maze | The maze that confines the EnemyCar's movements. |
players | The list of PlayerCars that the EnemyCar can chase. |
rocks | The list of Rocks that need to be avoided. |
Definition at line 11 of file EnemyCar.cpp.
States EnemyCar::_state [private] |
The state that the object is currently in.
Definition at line 66 of file EnemyCar.h.
double EnemyCar::_targetX [private] |
The x coordinate that the EnemyCar is driving towards.
Definition at line 67 of file EnemyCar.h.
double EnemyCar::_targetY [private] |
The y coordinate that the EnemyCar is driving towards.
Definition at line 68 of file EnemyCar.h.