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/PlayerCar.h | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 source/logic/PlayerCar.h (limited to 'source/logic/PlayerCar.h') diff --git a/source/logic/PlayerCar.h b/source/logic/PlayerCar.h new file mode 100644 index 0000000..8e9338d --- /dev/null +++ b/source/logic/PlayerCar.h @@ -0,0 +1,99 @@ +#ifndef PLAYERCAR_H +#define PLAYERCAR_H + +#include +#include +using namespace std; + +#include "../presentation/KeyboardHandler.h" +#include "../presentation/BitmapStore.h" + +#include "../logic/Car.h" +#include "../logic/Maze.h" +#include "../logic/Smokescreen.h" + +/** +* @brief A GameObject that is controlled by the player. +* +* Contains a KeyboardHandler to accept user input. +* +* @author Justin Wernick +* @author David Schneider +*/ +class PlayerCar: public Car +{ + public: + /** + * @brief Creates a PlayerCar at the given location facing in the given direction. + * + * In the current form of the level files, there is no way to distinguish the direction + * that the player is facing, so the default of UP is used. However, the ability to + * pass in a facing is useful in the unit tests. + * + * @param [in] x The x coordinate of the object's initial position. + * @param [in] y The y coordinate of the object's initial position. + * @param [in] facing The direction that the object is initially facing. + */ + PlayerCar(double x, double y, Maze::Direction facing=Maze::UP); + + //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. + * + * The Keyboard handler is called for the user's input. Based on this, the direction + * can be changed, and a Smokescreen can be created and added to the list of already + * existing Smokescreens. The PlayerCar is then moved. + * Petrol is decreased by PETROL_USE_RATE on every update. + * + * @param [in] maze The Maze that confines the PlayerCar's movement. + * @param [in,out] currentSmoke The list of Smokescreens being drawn, that the new Smokescreens will be added to the back of. + */ + void update(const Maze& maze, list& currentSmoke); + + /** + * @brief Creates a Smokescreen one block behind the player if the action is viable. + * + * The action is viable if the object has more than PETROL_USE_SMOKESCREEN petrol. Further, + * the position must not overlap with existing Smokescreens. This allows the player to hold down + * the Smokescreen button without creating a new Smokescreen every frame. + * Creating a Smokescreen decreases the petrol by PETROL_USE_SMOKESCREEN. + * + * @param [in,out] currentSmoke The list of Smokescreens being drawn, that the new Smokescreens will be added to the back of. + */ + void makeSmoke(list& currentSmoke); + + /** + * @brief Function that is called when the PlayerCar collides with a Checkpoint. + * + * Increases the amount of petrol by PETROL_FROM_CHECKPOINT. + */ + void gotCheckpoint(); + + /** + * @brief Function that is called when the PlayerCar collides with an EnemyCar. + */ + void crash(); + + /** + * @brief Function to allow access to the amount of petrol that the PlayerCar still has. + */ + double petrol() const; + + private: + KeyboardHandler _input; ///< Object that handles all interaction with the player. + + /** + * @brief The amount of petrol that the PlayerCar still has. + * + * Measured as a fraction, with 1 being a full tank and 0 being empty. When the petrol reaches + * 0, it is kept at zero and the PlayerCar's speed is halved. + */ + double _petrol; + + static const double PETROL_USE_RATE = 0.0007; ///< The amount of petrol used every frame. + static const double PETROL_USE_SMOKESCREEN = 0.05; ///< The amount of petrol used to create a Smokescreen. + static const double PETROL_FROM_CHECKPOINT = 0.2; ///< The amount of petrol gained from collecting a Checkpoint. +}; + +#endif // PLAYERCAR_H -- cgit v1.2.3