-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzombie.cpp
More file actions
100 lines (85 loc) · 1.18 KB
/
zombie.cpp
File metadata and controls
100 lines (85 loc) · 1.18 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "zombie.h"
#include <cstdlib>
/*
int xpos;
int ypos;
QRect zombieRect;
QImage zombieImage;
int speed;
int health;
int range;
deque<zombieMove> moveQueue;
*/
Zombie::Zombie(int xpo, int ypo)
{
speed = 2;
this->xpos = xpo;
this->ypos = ypo;
zombieRect.moveTo(xpos, ypos);
this->isDead = 0;
this->health = 10;
int randnum = rand() % 4;
if (randnum == 0)
{
xdir = -1;
ydir = -1;
}
else if (randnum == 1)
{
xdir = 1;
ydir = 1;
}
else if (randnum == 2)
{
xdir = 1;
ydir = -1;
}
else
{
xdir = -1;
ydir = 1;
}
zombieImage.load("zombie.png");
zombieRect = zombieImage.rect();
}
void Zombie::attack(int playerx, int playery)
{
//do nothing
}
void Zombie::shot(int damage)
{
health += -damage;
if (health <= 0)
isDead = 1;
}
void Zombie::calculateDirection(int playerx, int playery)
{
if (xpos < playerx)
{
xdir = 1;
}
else
{
xdir = -1;
}
if (ypos < playery)
{
ydir = 1;
}
else
{
ydir = -1;
}
int randint = rand() % 10000000000000;
if (randint == 1)
{
xdir = -xdir;
ydir = -ydir;
}
}
void Zombie::move()
{
zombieRect.translate(xdir, ydir);
xpos = zombieRect.x();
ypos = zombieRect.y();
}