From 98ba22e7064db57316dfff1ae127feb3dceeb73e Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Thu, 31 Jul 2014 13:58:22 +0200 Subject: Initial commit --- source/logic/EnemyCar.h | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 source/logic/EnemyCar.h (limited to 'source/logic/EnemyCar.h') diff --git a/source/logic/EnemyCar.h b/source/logic/EnemyCar.h new file mode 100644 index 0000000..b56c9d3 --- /dev/null +++ b/source/logic/EnemyCar.h @@ -0,0 +1,97 @@ +#ifndef ENEMYCAR_H +#define ENEMYCAR_H + +#include + +#include "../presentation/BitmapStore.h" + +#include "../logic/Car.h" +#include "../logic/PlayerCar.h" +#include "../logic/Rock.h" +#include "../logic/MazeMath.h" + +/** +* @brief GameObject that chases the player around the maze. +* +* Attempts to collide with the player, causing the player to lose. +* +* @author Justin Wernick +* @author David Schneider +*/ +class EnemyCar: public Car +{ + public: + /** + * @brief Creates an EnemyCar at the given coordinates. + * + * @param [in] x The x coordinate of the EnemyCar's initial position. + * @param [in] y The y coordinate of the EnemyCar's initial position. + */ + EnemyCar(double x, double y); + + //assignment and copy constructors have been left with the compiler generated versions + + /** + * @brief 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. + * + * @param maze The maze that confines the EnemyCar's movements. + * @param players The list of PlayerCars that the EnemyCar can chase. + * @param rocks The list of Rocks that need to be avoided. + */ + void update(const Maze& maze, const list& players, const list& rocks); + + /** + * @brief Function that is called when an EnemyCar crashes into a PlayerCar. + */ + void crash(); + + /** + * @brief Function that is called when an EnemyCar drives into a Smokescreen. + */ + void blind(); + + private: + /** + * @brief 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. + */ + enum States { + 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. + }; + + 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. + + /** + * @brief 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. + * + * @param [in] maze The maze that confines the EnemyCar's movements. + * @param [in] chasingX The x coordinate that the EnemyCar is ultimately trying to reach. + * @param [in] chasingY The y coordinate that the EnemyCar is ultimately trying to reach. + * @param [in] rocks The Rocks that the EnemyCar needs to avoid. + */ + void checkFacing(const Maze& maze, double chasingX, double chasingY, const list& rocks); + + /** + * @brief Iterates through a list of Rocks and determines if moving to a given position would result in a collision. + * + * @param [in] x The potential new x coordinate. + * @param [in] y The potential new y coordinate. + * @param [in] rocks The Rocks that are checked for a collision at x and y. + */ + bool rockAtLocation(double x, double y, const list& rocks); +}; + +#endif // ENEMYCAR_H -- cgit v1.2.3