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
|
#ifndef GAMEPANEL_H
#define GAMEPANEL_H
#include "../presentation/ScreenPanel.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 ScreenPanel to be drawn on the screen to draw the area where the game takes place.
*
* This includes the scrolling maze and all of the GameObjects.
*
* @author Justin Wernick
* @author David Schneider
*/
class GamePanel : public ScreenPanel
{
public:
/**
* @brief Creates a GamePanel from the given back and front buffers.
*
* The sub-bitmaps that GamePanel 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.
*/
GamePanel(ALLEGRO_BITMAP* back, ALLEGRO_BITMAP* front, int x, int y, int width, int height);
/**
* @brief Draws the given objects on the screen.
*
* The drawing is offset so that the first entry in players is in the middle of the panel.
* However, the offset will never be such that the drawing area will be outside of the maze.
*
* @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);
private:
/**
* @brief Copy constructor not implemented, ScreenPanels should not be copied.
*/
GamePanel(const GamePanel& ref);
/**
* @brief Assignment operator not implemented, ScreenPanels should not be copied.
*/
GamePanel& operator=(const GamePanel& 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 screen.
*
* Bitmaps used to represent solid and non-solid parts of the Maze are stored in the
* BitmapStore.
*
* @param [in] maze The Maze to be drawn.
*/
void draw(const Maze& maze);
/**
* @brief Draws a single GameObject on the screen.
*
* The bitmap to be drawn is retrieved from the BitmapStore using the GameObject's image.
*
* @param [in] object The GameObject to be drawn.
*/
void draw(const GameObject& object);
const static int BLOCKS_PER_ROW = 15; ///< The number of Maze blocks in one row shown on the panel at a time. Used to determine the scale.
unsigned int _mazeblockWidth; ///< The width of one (square) Maze block on the screen, in pixels.
float _offsetX; ///< The amount that drawing should be offset to the right, recalculated every frame.
float _offsetY; ///< The amount that drawing should be offset downwards, recalculated every frame.
BitmapStore _bitmapStore; ///< Used to cache ALLEGRO_BITMAPs, so that they only need to be drawn once.
AllegroInit _allegro; ///< Handles dependencies on Allegro.
};
#endif // GAMEPANEL_H
|