summaryrefslogtreecommitdiff
path: root/source/logic/EnemyCar.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/logic/EnemyCar.h')
-rw-r--r--source/logic/EnemyCar.h97
1 files changed, 97 insertions, 0 deletions
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 <cmath>
+
+#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<PlayerCar>& players, const list<Rock>& 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<Rock>& 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<Rock>& rocks);
+};
+
+#endif // ENEMYCAR_H