-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboxEnemy.cpp
58 lines (52 loc) · 1.33 KB
/
boxEnemy.cpp
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
#include "boxEnemy.h"
BoxEnemy::BoxEnemy(QWidget* widget)
{
this->Load();
box=new QLabel(widget);
box->setPixmap(boxDef);
box->setFixedSize(150,150);
box->setScaledContents(true);
box->show();
health=new QLabel(widget);
health->move(x+50,y-30);
string_health_number= QString::number(health_number, 10);
health->setFont(QFont("Microsoft YaHei", 20, QFont::Bold));
health->setStyleSheet("color:red;");
health->setText(string_health_number);
box->move(x,y);
health->show();
}
BoxEnemy::~BoxEnemy(){
delete box;
delete box_hurt_r;
delete box_hurt_l;
}
void BoxEnemy::Hurt(Dir dir){
health_number-=10;
string_health_number= QString::number(health_number, 10);
health->setText(string_health_number);
if(dir==right){
box->setMovie(box_hurt_r);
box_hurt_r->start();
delay(200);
box_hurt_r->stop();
box->setPixmap(boxDef);
}else{
box->setMovie(box_hurt_l);
box_hurt_l->start();
delay(200);
box_hurt_l->stop();
box->setPixmap(boxDef);
}
}
int BoxEnemy::GetX(){
return x;
}
int BoxEnemy::GetHealth(){
return health_number;
}
void BoxEnemy::Load(){
boxDef.load("Images/box.png");
box_hurt_r=new QMovie("Images/box_hurt_r.gif");
box_hurt_l=new QMovie("Images/box_hurt_l.gif");
}