-
Notifications
You must be signed in to change notification settings - Fork 0
/
fireball.cpp
61 lines (56 loc) · 1.27 KB
/
fireball.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
59
60
#include "fireball.h"
#include <QTimer>
#include <QGraphicsScene>
fireball::fireball(int value)
{
direction = value;
if (direction == 0){
setPixmap(QPixmap(":/images/fireball_up.png"));
}
else if (direction == 1){
setPixmap(QPixmap(":/images/fireball_down.png"));
}
else if (direction == 2){
setPixmap(QPixmap(":/images/fireball_left.png"));
}
else if (direction == 3){
setPixmap(QPixmap(":/images/fireball_right.png"));
}
QTimer* timer = new QTimer();
connect(timer, SIGNAL(timeout()),this, SLOT(move()));
timer->start(30);
}
fireball::~fireball()
{
}
void fireball::move()
{
if(direction == 0){
setPos(x(),y() - 5);
if (y() < 0){
scene()->removeItem(this);
delete this;
}
}
else if (direction == 1){
setPos(x(),y()+5);
if(y() > 530){
scene()->removeItem(this);
delete this;
}
}
else if (direction == 2){
setPos(x() - 5, y());
if (x() < 0){
scene()->removeItem(this);
delete this;
}
}
else if (direction == 3){
setPos(x() + 5, y());
if (x() > 530){
scene()->removeItem(this);
delete this;
}
}
}