-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathrepeater.cpp
41 lines (38 loc) · 929 Bytes
/
repeater.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
#include "repeater.h"
Repeater::Repeater()
{
atk = 25;
hp = 300;
time = int(1.4 * 1000 / 33);
setMovie(":/images/Repeater.gif");
}
void Repeater::advance(int phase)
{
if (!phase)
return;
update();
if (hp <= 0)
delete this;
else if (++counter >= time)
{
counter = 0;
QList<QGraphicsItem *> items = collidingItems();
if (!collidingItems().isEmpty())
{
Pea *pea = new Pea(atk);
pea->setX(x() + 32);
pea->setY(y());
scene()->addItem(pea);
pea = new Pea(atk);
pea->setX(x() + 64);
pea->setY(y());
scene()->addItem(pea);
return;
}
}
}
bool Repeater::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const
{
Q_UNUSED(mode)
return other->type() == Zombie::Type && qFuzzyCompare(other->y(), y());
}