-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhealth.cpp
More file actions
41 lines (34 loc) · 930 Bytes
/
health.cpp
File metadata and controls
41 lines (34 loc) · 930 Bytes
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
#include "health.h"
#include "player.h"
#include "galaga.h"
#include <QFont>
extern Galaga * galaga;
Health::Health(QGraphicsItem *parent): QGraphicsTextItem(parent)
{
//health is initially 3
health = 3;
//health text
setPlainText(QString("Lives: ")+QString::number(health));
//changing the text color
setDefaultTextColor(Qt::red);
//name of the font and size of font
setFont(QFont("times",20));
}
void Health::decreaseHealth()
{
health--;
//updates number of lives
if(health>=0)
setPlainText(QString("Lives: ")+QString::number(health));
if(health == 0){
setPlainText(QString("GAME OVER!"));
setFont(QFont("times",55));
for(int i = 0, n = galaga->scene->items().size();i<n;i++){
galaga->scene->items()[i]->setEnabled(false);
}
}
}
int Health::getHealth()
{
return health;
}