-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatusbar.cpp
More file actions
170 lines (145 loc) · 7 KB
/
Copy pathstatusbar.cpp
File metadata and controls
170 lines (145 loc) · 7 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "statusbar.h"
#include "gamedialog.h"
namespace game {
StatusBar::StatusBar(GameDialog* dialog) : plasmaEnergy(100), barrierEnergy(0), gd(dialog), plasmaDrained(false)
{}
/**
this is the initialise method to be run before other method. TO initialise internal variables
*/
void StatusBar::buildBrush(){
// determine location for status bar
statusBar = QRect(0, gd->SCALEDHEIGHT, gd->SCALEDWIDTH, gd->STATUSBARHEIGHT);
// build for the main status bar
QLinearGradient statusBarBrush(0, gd->SCALEDHEIGHT, 0, gd->SCALEDHEIGHT + gd->STATUSBARHEIGHT);
statusBarBrush.setColorAt(0.05, QColor::fromRgb(10, 10, 10));
statusBarBrush.setColorAt(0.2, QColor::fromRgb(100, 100, 100));
statusBarBrush.setColorAt(0.5, QColor::fromRgb(120, 120, 120));
statusBarBrush.setColorAt(0.8, QColor::fromRgb(100, 100, 100));
this->statusBarBrush = statusBarBrush;
// determine the dimension of the energy bar
int barWidth = static_cast<int>(gd->SCALEDWIDTH*0.175);
int barHeight = static_cast<int>(gd->STATUSBARHEIGHT*0.6);
// build the energy bar container
containerOuter = QRect(0, 0, barWidth*1.1, barHeight*1.3);
containerInner = QRect(containerOuter.width() - barWidth,
(containerOuter.height() - barHeight) / 2,
barWidth, barHeight);
// determine location for plasma bar
plasmaBar = QRect(gd->SCALEDWIDTH*0.80, gd->SCALEDHEIGHT + gd->STATUSBARHEIGHT*0.3,
gd->SCALEDWIDTH*0.175, gd->STATUSBARHEIGHT*0.6);
// build brush for the plasma bar
QLinearGradient plasmabarBrush(0, gd->SCALEDHEIGHT, 0, gd->SCALEDHEIGHT + gd->STATUSBARHEIGHT);
plasmabarBrush.setColorAt(0.2, QColor::fromRgb(0, 0, 180));
plasmabarBrush.setColorAt(0.4, QColor::fromRgb(0, 0, 250));
plasmabarBrush.setColorAt(0.6, QColor::fromRgb(0, 0, 250));
plasmabarBrush.setColorAt(0.8, QColor::fromRgb(0, 0, 180));
this->plasmaBarBrush = plasmabarBrush;
// determine location for barrier bar
barrierBar = QRect(gd->SCALEDWIDTH*0.55, gd->SCALEDHEIGHT + gd->STATUSBARHEIGHT*0.3,
gd->SCALEDWIDTH*0.175, gd->STATUSBARHEIGHT*0.6);
// build brush for the barrier bar
QLinearGradient barrierbarBrush(0, gd->SCALEDHEIGHT, 0, gd->SCALEDHEIGHT + gd->STATUSBARHEIGHT);
barrierbarBrush.setColorAt(0.2, QColor::fromRgb(180, 0, 0));
barrierbarBrush.setColorAt(0.4, QColor::fromRgb(250, 0, 0));
barrierbarBrush.setColorAt(0.6, QColor::fromRgb(250, 0, 0));
barrierbarBrush.setColorAt(0.8, QColor::fromRgb(180, 0, 0));
this->barrierBarBrush = barrierbarBrush;
}
void StatusBar::draw(QPainter* p){
p->setPen(Qt::NoPen);
//////////////////////////////////////////
////// STATUS BAR BACKGROUND
//////////////////////////////////////////
// first draw the background of status bar
p->setBrush(statusBarBrush);
p->drawRect(statusBar);
//////////////////////////////////////////
////// PLASMA BAR
//////////////////////////////////////////
// draw the container for plasma bar
containerInner.moveTo(plasmaBar.x(), plasmaBar.y());
containerOuter.moveTo(containerInner.x() - (containerOuter.width() - containerInner.width()),
plasmaBar.y() - (containerOuter.height() - containerInner.height()) / 2);
p->setBrush(QColor::fromRgb(96, 80, 43));
p->drawRect(containerOuter);
p->setBrush(QColor::fromRgb(45, 40, 26));
p->drawRect(containerInner);
// draw the plasma Bar, with scaling of the plasma energy
p->setBrush(plasmaBarBrush);
p->drawRect(plasmaBar.x(), plasmaBar.y(),
plasmaBar.width() * plasmaEnergy / 100.0, plasmaBar.height());
// if plasma bar is fully drained, draw a transparent rect represent it cannot be used currently
// OR if barrier energy bar is active. (since only one cursor can be active at any given time)
if(plasmaDrained || barrierEnergy > 0)
p->fillRect(containerOuter, QBrush(QColor(0, 0, 0, 128)));
//////////////////////////////////////////
////// BARRiER BAR
//////////////////////////////////////////
// draw the container for barrier bar
containerInner.moveTo(barrierBar.x(), barrierBar.y());
containerOuter.moveTo(containerInner.x() - (containerOuter.width() - containerInner.width()),
barrierBar.y() - (containerOuter.height() - containerInner.height()) / 2);
p->setBrush(QColor::fromRgb(96, 80, 43));
p->drawRect(containerOuter);
p->setBrush(QColor::fromRgb(45, 40, 26));
p->drawRect(containerInner);
// draw the barrier Bar, with scaling of the plasma energy
p->setBrush(barrierBarBrush);
p->drawRect(barrierBar.x(), barrierBar.y(),
barrierBar.width() * barrierEnergy / 100.0, barrierBar.height());
// if barrier bar is fully drained, draw a transparent rect represent it cannot be used currently
if(barrierEnergy <= 0)
p->fillRect(containerOuter, QBrush(QColor(0, 0, 0, 128)));
//////////////////////////////////////////
////// CURRENT STAGE
//////////////////////////////////////////
p->setPen(Qt::yellow);
QFont f("monospace");
f.setStyleHint(QFont::TypeWriter);
f.setFamily("courier");
f.setPointSize(static_cast<int>(gd->STATUSBARHEIGHT * 0.1));
p->setFont(f);
p->drawText(gd->SCALEDWIDTH*0.02, gd->SCALEDHEIGHT + gd->STATUSBARHEIGHT*0.3, "Stage: ");
f.setPointSize(static_cast<int>(gd->STATUSBARHEIGHT * 0.3));
p->setFont(f);
p->drawText(gd->SCALEDWIDTH*0.03, gd->SCALEDHEIGHT + gd->STATUSBARHEIGHT*0.8, QString::number(gd->curStageNum));
//////////////////////////////////////////
////// CURRENT SCORE
//////////////////////////////////////////
p->setPen(Qt::white);
f.setPointSize(static_cast<int>(gd->STATUSBARHEIGHT * 0.1));
p->setFont(f);
p->drawText(gd->SCALEDWIDTH*0.1, gd->SCALEDHEIGHT + gd->STATUSBARHEIGHT*0.3, "Score: ");
f.setPointSize(static_cast<int>(gd->STATUSBARHEIGHT * 0.55));
p->setFont(f);
p->drawText(gd->SCALEDWIDTH*0.12, gd->SCALEDHEIGHT + gd->STATUSBARHEIGHT*0.875, QString::number(gd->gameScore));
//////////////////////////////////////////
////// DRAW CANNON
//////////////////////////////////////////
p->setPen(Qt::yellow);
f.setPointSize(static_cast<int>(gd->STATUSBARHEIGHT * 0.25));
p->setFont(f);
QString str;
if(gd->ship->cannonAmmo < 0)
str = "∞";
else
str = QString::number(gd->ship->cannonAmmo);
QPixmap pixmap;
switch(gd->ship->cannonType){
case(Normal):
pixmap.load(":/Images/Gun.png");
break;
case(Laser):
pixmap.load(":/Images/LaserGun.png");
break;
case(MachineGun):
pixmap.load(":/Images/MachineGun.png");
break;
}
pixmap = pixmap.scaledToWidth(gd->STATUSBARHEIGHT*0.8);
p->drawPixmap(gd->SCALEDWIDTH*0.25, gd->SCALEDHEIGHT + gd->STATUSBARHEIGHT*0.2, pixmap);
p->drawText(gd->SCALEDWIDTH*0.27+pixmap.width(), gd->SCALEDHEIGHT + gd->STATUSBARHEIGHT*0.75, str);
}
void StatusBar::update(){
}
}