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
|
#include "InfoPanel.h"
InfoPanel::InfoPanel(ALLEGRO_BITMAP* back, ALLEGRO_BITMAP* front, int x, int y, int width, int height)
:ScreenPanel(back, front, x, y, width, height),
_petrolHeadingY(_width/10),
_petrolGuageY(_petrolHeadingY + _width/10),
_petrolGuageHeight(_width/10),
_checkpointHeadingY(_petrolGuageY + _petrolGuageHeight + _width/10),
_checkpointValueY(_checkpointHeadingY + _width/10),
_miniMazeY(_checkpointValueY + _width/5),
_miniMazeHeight(_height - _miniMazeY),
_miniMazeblockWidth(0)
{
_panelFont = al_load_font("junction 02.ttf", _width/10, 0);
if (_panelFont == NULL)
{
al_show_native_message_box(NULL, "Fatal error", "Fatal error", "The file 'junction 02.ttf' was not found. Ensure that it is located in the working directory.", NULL, ALLEGRO_MESSAGEBOX_ERROR);
throw InstallFailure();
}
}
InfoPanel::~InfoPanel()
{
al_destroy_font(_panelFont);
}
void InfoPanel::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)
{
ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
al_set_target_bitmap(_back);
double petrol = 0;
if (!players.empty())
{
petrol = players.front().petrol();
}
al_clear_to_color(_colourStore.getColour(BitmapStore::MAZE_FLOOR));
//gets a mazeblock width the fits the current maze
_miniMazeblockWidth = min(static_cast<float>(_width)/maze.width(), static_cast<float>(_miniMazeHeight)/maze.height());
//draws petrol heading and bar
al_draw_text(_panelFont, al_map_rgb(255,255,255), 1, _petrolHeadingY, ALLEGRO_ALIGN_LEFT , "Petrol");
al_draw_filled_rectangle(0,_petrolGuageY,_width*petrol, _petrolGuageY+_petrolGuageHeight, al_map_rgb(255,128,0));
//draws checkpoints remaining heading and value
al_draw_text(_panelFont, al_map_rgb(255,255,255), 1, _checkpointHeadingY, ALLEGRO_ALIGN_LEFT , "Checkpoints");
stringstream checkpointCountString;
checkpointCountString << Checkpoint::checkpointCount();
al_draw_text(_panelFont, al_map_rgb(255,255,255), 1, _checkpointValueY, ALLEGRO_ALIGN_LEFT , checkpointCountString.str().c_str());
draw(maze);
for (list<PlayerCar>::const_iterator iter = players.begin(); iter != players.end(); ++iter)
{
draw(*iter);
}
for (list<EnemyCar>::const_iterator iter = enemies.begin(); iter != enemies.end(); ++iter)
{
draw(*iter);
}
for (list<Checkpoint>::const_iterator iter = checkpoints.begin(); iter != checkpoints.end(); ++iter)
{
draw(*iter);
}
//restore draw target
al_set_target_bitmap(prev_draw);
}
void InfoPanel::draw(const Maze& maze)
{
ALLEGRO_COLOR wallColour = _colourStore.getColour(BitmapStore::MAZE_WALL);
ALLEGRO_COLOR floorColour = _colourStore.getColour(BitmapStore::MAZE_FLOOR);
for (int x=0; x<maze.width(); ++x)
{
for (int y=0; y<maze.height(); ++y)
{
float x1 = getPanelX(x);
float x2 = x1 + _miniMazeblockWidth;
float y1 = getPanelY(y) + _miniMazeY;
float y2 = y1 + _miniMazeblockWidth;
if (maze.getSolid(x,y))
{
al_draw_filled_rectangle(x1, y1, x2, y2, wallColour);
}
else
{
al_draw_filled_rectangle(x1, y1, x2, y2, floorColour);
}
}
}
}
void InfoPanel::draw(const GameObject& object)
{
float r = _miniMazeblockWidth/2;
float cx = getPanelX(object.x()) + r;
float cy = getPanelY(object.y()) + _miniMazeY + r;
al_draw_filled_circle(cx, cy, r, _colourStore.getColour(object.image()));
}
float InfoPanel::getPanelX(const double& x) const
{
return static_cast<float>(x*_miniMazeblockWidth);
}
float InfoPanel::getPanelY(const double& y) const
{
return static_cast<float>(y*_miniMazeblockWidth);
}
|