summaryrefslogtreecommitdiff
path: root/source/logic/PlayerCar.h
blob: 8e9338d56ed6fb0f891e95110604e030476d70be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef PLAYERCAR_H
#define PLAYERCAR_H

#include <cmath>
#include <list>
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<Smokescreen>& 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<Smokescreen>& 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