forked from GeeeekExplorer/PVZ
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conezombie.cpp
46 lines (44 loc) · 1003 Bytes
/
conezombie.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 "conezombie.h"
ConeZombie::ConeZombie()
{
hp = 640;
atk = 100 * 33 / 1000;
speed = 80.0 * 33 / 1000 / 4.7;
setMovie(":/images/ConeZombieWalk.gif");
}
void ConeZombie::advance(int phase)
{
if (!phase)
return;
update();
if (hp <= 0)
{
if (state < 2)
{
state = 2;
setMovie(":/images/ZombieDie.gif");
setHead(":/images/ZombieHead.gif");
}
else if (movie->currentFrameNumber() == movie->frameCount() - 1)
delete this;
return;
}
QList<QGraphicsItem *> items = collidingItems();
if (!items.isEmpty())
{
Plant *plant = qgraphicsitem_cast<Plant *>(items[0]);
plant->hp -= atk;
if (state != 1)
{
state = 1;
setMovie(":/images/ConeZombieAttack.gif");
}
return;
}
if (state)
{
state = 0;
setMovie(":/images/ConeZombieWalk.gif");
}
setX(x() - speed);
}