-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathcherrybomb.cpp
46 lines (42 loc) · 1.17 KB
/
cherrybomb.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
#include "cherrybomb.h"
CherryBomb::CherryBomb()
{
atk = 1800;
hp = 300;
setMovie(":/images/CherryBomb.gif");
}
QRectF CherryBomb::boundingRect() const
{
return state ? QRectF(-150, -150, 300, 300) : Plant::boundingRect();
}
void CherryBomb::advance(int phase)
{
if (!phase)
return;
update();
if (hp <= 0)
delete this;
else if (state == 0 && movie->currentFrameNumber() == movie->frameCount() - 1)
{
state = 1;
setMovie(":/images/Boom.gif");
QList<QGraphicsItem *> items = collidingItems();
foreach (QGraphicsItem *item, items)
{
Zombie *zombie = qgraphicsitem_cast<Zombie *>(item);
zombie->hp -= atk;
if (zombie->hp <= 0)
{
zombie->state = 3;
zombie->setMovie(":/images/Burn.gif");
}
}
}
else if (state == 1 && movie->currentFrameNumber() == movie->frameCount() - 1)
delete this;
}
bool CherryBomb::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const
{
Q_UNUSED(mode)
return other->type() == Zombie::Type && QLineF(pos(), other->pos()).length() < 160;
}