-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcob.cpp
91 lines (80 loc) · 1.68 KB
/
cob.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
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
#include "cob.h"
#include "Constants.h"
#include <QTimer>
#include <QDebug>
#define COB_FLY_TIME 3
Cob::Cob(QPoint &p):
target(p)
{
setZValue(20);
transform.rotate(180);
up = true;
// QTimer::singleShot(COB_FLY_TIME*1000,this,SLOT(reverse()));
timer = new Timer(COB_FLY_TIME);
timer->setSingleShot();
connect(timer,SIGNAL(timeout()),this,SLOT(reverse()));
timer->start();
// qDebug()<<"Cob at location "<<(long)this;
}
Cob::~Cob()
{
timer->deleteLater();
}
int Cob::type() const
{
return Type;
}
QRectF Cob::boundingRect() const
{
qreal adjust = 5;
return QRectF(0 - adjust, 0 - adjust,
100 + adjust, 180 + adjust);
}
QPainterPath Cob::shape() const
{
QPainterPath path;
path.addRect(0,0,78,162);
return path;
}
void Cob::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
if (up)
painter->drawPixmap(0,0,QPixmap(":/images/cob.png"));
else
painter->drawPixmap(0,0,QPixmap(":/images/cob.png").transformed(transform));
}
void Cob::advance(int step)
{
// qDebug()<<"come in Cob::advance";
if (!step)
return;
if (up)
setPos(mapToParent(0,-8));
else
setPos(mapToParent(0,8));
if (pos().x()==target.x() && pos().y()>= target.y()-162+GRID_Y/2){
emit explode(this);
}
// qDebug()<<"leave Cob::advance";
}
void Cob::pause()
{
// qDebug()<<"come to Cob::pause";
if (up)
timer->pause();
}
void Cob::restore()
{
// qDebug()<<"come to Cob::restore";
if (up)
timer->restore();
}
void Cob::reverse()
{
up = false;
setPos(target.x(),pos().y());
}
QPoint Cob::getTarget()
{
return target;
}