-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathpotatomine.cpp
56 lines (51 loc) · 1.4 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
#include "potatomine.h"
PotatoMine::PotatoMine()
{
atk = 1800;
hp = 300;
time = int(15.0 * 1000 / 33);
setMovie(":/images/PotatoMine1.gif");
}
QRectF PotatoMine::boundingRect() const
{
return state == 2 ? QRectF(-75, -75, 150, 150) : Plant::boundingRect();
}
void PotatoMine::advance(int phase)
{
if (!phase)
return;
update();
if (hp <= 0)
delete this;
else if (state == 0 && ++counter >= time)
{
state = 1;
counter = 0;
time = int(1.0 * 1000 / 33);
setMovie(":/images/PotatoMine.gif");
}
else if (state == 1 && ++counter >= time)
{
counter = 0;
QList<QGraphicsItem *> items = collidingItems();
if (!items.isEmpty())
{
state = 2;
setMovie(":/images/PotatoMineBomb.gif");
foreach (QGraphicsItem *item, items)
{
Zombie *zombie = qgraphicsitem_cast<Zombie *>(item);
zombie->hp -= atk;
if (zombie->hp <= 0)
delete zombie;
}
}
}
else if (state == 2 && movie->currentFrameNumber() == movie->frameCount() - 1)
delete this;
}
bool PotatoMine::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const
{
Q_UNUSED(mode)
return other->type() == Zombie::Type && qFuzzyCompare(other->y(), y()) && qAbs(other->x() - x()) < 50;
}