-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZombie.cpp
61 lines (52 loc) · 1.16 KB
/
Zombie.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
56
57
58
59
60
61
#include "Zombie.h"
#include <random>
#include <ctime>
#include "Human.h"
Zombie::Zombie()
{
}
Zombie::~Zombie()
{
}
Human* Zombie::getNerestHuman(std::vector<Human*>& humans){
Human* cloestHuman = nullptr;
float samllestDistace = 999999.0f;
for (int i = 0; i < humans.size();i++){
glm::vec2 distVec = humans[i]->getAgentPos() - _position;
float distance = glm::length(distVec);
if (distance<samllestDistace){
samllestDistace = distance;
cloestHuman = humans[i];
}
}
return cloestHuman;
}
void Zombie::update(const std::vector<std::string>& levelData,
std::vector<Human*>& humans,
std::vector<Zombie*>& zombies,
float deltaTime ){
Human* cloestHuman = getNerestHuman(humans);
if (cloestHuman!=nullptr){
_direction = glm::normalize(cloestHuman->getAgentPos() - _position);
_position += _direction*_speed*deltaTime;
}
collideWithLevel(levelData);
}
void Zombie::init(float speed, glm::vec2 pos){
_color.r = 200;
_color.g = 0;
_color.b = 0;
_color.a = 255;
_health = 50;
_damage = 20;
_speed = speed;
_position = pos;
}
void Zombie::beStronger(){
_health += 30;
_damage += 10;
_speed += 0.001f;
if (_color.r>30){
_color.r -= 30;
}
}