summaryrefslogtreecommitdiff
path: root/source/presentation/InfoPanel.h
blob: 9af6a70b9cff995438cc8ac34a234c4490a5ae28 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef INFOPANEL_H
#define INFOPANEL_H

#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>

#include <sstream>
using namespace std;

#include "../presentation/ScreenPanel.h"
#include "../presentation/ColourStore.h"
#include "../logic/Maze.h"
#include "../logic/GameObject.h"
#include "../logic/PlayerCar.h"
#include "../logic/EnemyCar.h"
#include "../logic/Checkpoint.h"
#include "../logic/AllegroWrappers.h"

/**
* @brief ScreenPanel to be drawn on the screen to give the player information.
*
* This includes the minimap, a scaled down version of the entire maze that does not scroll, with
* icons to represent the PlayerCar, EnemyCars, and Checkpoints. Text is drawn to show the player the
* number of Checkpoints that needed to be collected for victory, and a rectangle is drawn representing
* the amount of petrol that the PlayerCar has left.
*
* @author Justin Wernick
* @author David Schneider
*/
class InfoPanel : public ScreenPanel
{
    public:
        /**
        * @brief Creates an InfoPanel from the given back and front buffers.
        *
        * The sub-bitmaps that InfoPanel uses are created from a rectangular region on back and front
        * that has its top left corner at the coordinate x,y, is width long in the x direction, and
        * height long in the y direction.
        *
        * @param [in] back The current back buffer of the display being sub-bitmapped.
        * @param [in] front The current front buffer (image currently being displayed) of the display being sub-bitmapped.
        * @param [in] x The x coordinate of the left side of the sub-bitmap in pixels.
        * @param [in] y The x coordinate of the top of the sub-bitmap in pixels.
        * @param [in] width The length in the x direction of the new sub-bitmap in pixels.
        * @param [in] height The length in the y direction of the new sub-bitmap in pixels.
        */
        InfoPanel(ALLEGRO_BITMAP* back, ALLEGRO_BITMAP* front, int x, int y, int width, int height);

        /**
        * @brief Destructor that ensured that the font created is destroyed.
        *
        * The memory for the sub-bitmaps are handled by the parent class, ScreenPanel.
        */
        ~InfoPanel();

        /**
        * @brief Draws the InfoPanel using the given objects.
        *
        * Not all of the provided objects are needed for the drawing process, but they are included
        * to give the most general drawing case. This is to support polymorphism, where the InfoPanel
        * can be told to draw its sub-bitmap in the same manner as any other ScreenPanel.
        *
        * The scale of the minimap is determined at the beginning of each frame, so that it will
        * always fit even if the maze is larger than on the last frame.
        *
        * @param [in] maze The Maze that all of the objects are in.
        * @param [in] players The list of PlayerCars to be drawn.
        * @param [in] enemies The list of EnemyCars to be drawn.
        * @param [in] checkpoints The list of Checkpoints to be drawn.
        * @param [in] rocks Rocks are not actually drawn.
        * @param [in] smokescreens Smokescreens are not actually drawn.
        * @param [in] popups DestroyedObjectPopups are not actually drawn.
        */
        virtual void draw(const Maze& maze, const list<PlayerCar>& players, const list<EnemyCar>& enemies, const list<Checkpoint>& checkpoints, const list<Rock>& rocks, const list<Smokescreen>& smokescreens, const list<DestroyedObjectPopup>& popups);
    private:
        /**
        * @brief Copy constructor not implemented, ScreenPanels should not be copied.
        */
        InfoPanel(const InfoPanel& ref);
        /**
        * @brief Assignment operator not implemented, ScreenPanels should not be copied.
        */
        InfoPanel& operator=(const InfoPanel& rhs);
        /**
        * @brief Converts an x game coordinate value to its equivalent in pixels.
        *
        * Converting to the pixel coordinates happens for every object every frame. To increase
        * performance, the parameters are passed in by constant reference instead of by value.
        *
        * @param [in] x The game coordinate to be converted into pixels.
        */
        float getPanelX(const double& x) const;
        /**
        * @brief Converts a y game coordinate value to its equivalent in pixels.
        *
        * Converting to the pixel coordinates happens for every object every frame. To increase
        * performance, the parameters are passed in by constant reference instead of by value.
        *
        * @param [in] y The game coordinate to be converted into pixels.
        */
        float getPanelY(const double& y) const;

        /**
        * @brief Draws a Maze on the panel.
        *
        * The Maze is constructed of coloured squares. The colour of the squares is retrieved from
        * the ColourStore.
        *
        * Unlike in the GamePanel, the entire Maze is drawn.
        *
        * @param [in] maze The Maze to be drawn.
        */
        void draw(const Maze& maze);

        /**
        * @brief Draws a single GameObject on the panel.
        *
        * The GameObject is represented by a coloured circle in the Maze. The colour is based on
        * the GameObject's image and is retrieved from the ColourStore.
        *
        * @param [in] object The GameObject to be drawn.
        */
        void draw(const GameObject& object);

        AllegroDrawingInit _drawing; ///< Handles dependencies on Allegro's primitive drawing functions.
        ColourStore _colourStore; ///< Caches colours for drawing.

        float _petrolHeadingY; ///< The y coordinate of the heading for the petrol guage.
        float _petrolGuageY; ///< The y coordinate of top of the petrol guage.
        float _petrolGuageHeight; ///< The height of the rectangle that is the petrol guage.
        float _checkpointHeadingY; ///< The y coordinate of the heading for the number of remaining checkpoints.
        float _checkpointValueY; ///< The y coordinate of the text stating the number of remaining checkpoints.
        float _miniMazeY; ///< The y coordinate of the top of the Maze.
        float _miniMazeHeight; ///< The height of the Maze.
        float _miniMazeblockWidth; ///< The width of each Maze block being drawn.

        ALLEGRO_FONT* _panelFont; ///< The font being used to write the headings and number of checkpoints remaining.
};

#endif // INFOPANEL_H