-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpotatomine.cpp
77 lines (66 loc) · 1.48 KB
/
potatomine.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
#include "potatomine.h"
#include <QDebug>
#define MINE_POTATO_CHARGE_TIME 5
PotatoMine::PotatoMine(QObject *parent) :
Plant("potatoMine")
{
prepare = false;
hasZombie = false;
counter = 10;
}
PotatoMine::~PotatoMine()
{
timer->deleteLater();
}
void PotatoMine::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
//painter->drawPixmap(0,0,QPixmap(":/images/"+plantName+".gif"));
// painter->drawPixmap(0,0,movie->currentPixmap());
painter->drawImage(xShift,yShift,movie->currentImage());
painter->setBrush(QColor(127,0,0,127));
if (prepare)
painter->drawText(QPoint(0,0),"ready");
else
painter->drawText(QPoint(0,0),"charging");
// painter->drawRect(0,0,90,100);
}
void PotatoMine::explode()
{
emit sendHitBox(myRow, myCol, 90);
emit destroyMe(this);
}
void PotatoMine::ready()
{
prepare = true;
}
void PotatoMine::setPlanted()
{
timer = new Timer(MINE_POTATO_CHARGE_TIME);
connect(timer,SIGNAL(timeout()),this,SLOT(ready()));
timer->setSingleShot();
timer->start();
planted = true;
}
void PotatoMine::pause()
{
Plant::pause();
timer->pause();
}
void PotatoMine::restore()
{
Plant::restore();
timer->restore();
}
void PotatoMine::seeZombie(int row, int col)
{
if (row == myRow && col == myCol && prepare && !hasZombie)
hasZombie = true;
}
void PotatoMine::sendPea()
{
if (hasZombie){
counter--;
if (counter ==0)
explode();
}
}