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
|
#ifndef SCREENPANEL_H
#define SCREENPANEL_H
#include <allegro5/allegro.h>
#include "../logic/Maze.h"
#include "../logic/GameObject.h"
#include "../logic/PlayerCar.h"
#include "../logic/EnemyCar.h"
#include "../logic/Checkpoint.h"
#include "../logic/Rock.h"
#include "../logic/Smokescreen.h"
#include "../logic/DestroyedObjectPopup.h"
#include "../logic/AllegroWrappers.h"
/**
* @brief Parent class for panels that are drawn on the screen.
*
* Panels are given a sub-bitmap of the Screen bitmap, which they draw their panel specific outputs on.
* The ScreenPanel class is subclassed to give specific drawing functions, like drawing the Maze and
* GameObjects on the screen.
*
* When the object is created, the back bitmap and front bitmap should correspond to the back and front buffers
* of the display respectively. This should be kept in sync by calling flip every time the display is flipped.
*
* @author Justin Wernick
* @author David Schneider
*/
class ScreenPanel
{
public:
/**
* @brief Creates a ScreenPanel from the given back and front buffers.
*
* The sub-bitmaps that ScreenPanel 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.
*/
ScreenPanel(ALLEGRO_BITMAP* back, ALLEGRO_BITMAP* front, int x, int y, int width, int height);
/**
* @brief Destructor to ensure that sub-bitmap memory is deallocated.
*/
virtual ~ScreenPanel();
/**
* @brief Pure virtual method for drawing a collection of objects onto the panel.
*
* Implementations do not need to draw all of the objects if it is not neccesary for the
* type of panel, but the interface accepts all of them to be general.
*
* @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 The list of Rocks to be drawn.
* @param [in] smokescreens The list of Smokescreens to be drawn.
* @param [in] popups The list of DestroyedObjectPopups to be 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) = 0;
/**
* @brief Swaps the front and back buffers.
*
* This function should be called every time the display is flipped.
*/
virtual void flip();
protected:
static const ALLEGRO_COLOR BLANK; ///< Colour used to clear the screen at the beginning of drawing operations.
ALLEGRO_BITMAP* _back; ///< The back buffer. Only the back buffer can be drawn to.
int _width; ///< The width of the sub-bitmaps being drawn to in pixels.
int _height; ///< The height of the sub-bitmaps being drawn to in pixels.
private:
/**
* @brief Copy constructor not implemented, ScreenPanels should not be copied.
*/
ScreenPanel(const ScreenPanel& ref);
/**
* @brief Assignment operator not implemented, ScreenPanels should not be copied.
*/
ScreenPanel& operator=(const ScreenPanel& rhs);
AllegroInit _allegro; ///< Handles dependencies on Allegro being initialised.
ALLEGRO_BITMAP* _front; ///< The front buffer, that is currently being shown on the screen.
};
#endif // SCREENPANEL_H
|