-
Notifications
You must be signed in to change notification settings - Fork 0
/
Foe.cpp
86 lines (70 loc) · 2.38 KB
/
Foe.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
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
#include "Foe.h"
void Foe::addRoutePoint(glm::vec4 point)
{
route.push_back(point);
}
void Foe::updatePos(glm::mat4 V)
{
std::chrono::time_point<std::chrono::system_clock> now;
glm::vec4 pos = position[3];
// computing position of enemy in world space
pos[3] = position[3][3];
glm::vec4 posV = V * pos; // computing position in eye space
now = std::chrono::system_clock::now();
std::chrono::duration<float> elapsedTime = now - lastTime;
lastTime = now;
if (glm::length(posV) < 20) // player needs to be in correct distance to the enemy for it to follow him
{
glm::vec4 mov = glm::transpose(position) * glm::transpose(V) * glm::normalize(posV * -1.f) * elapsedTime.count() * speed;
float angle = glm::orientedAngle(glm::normalize(glm::vec2(mov.x, mov.z)), glm::normalize(glm::vec2(position[2][0], position[2][2])));
// angle between enemy's facing direction and direction of it's movement
position = glm::translate(position, glm::vec3(mov.x, mov.y, mov.z)); // move enemy
position = glm::rotate(position, glm::clamp(glm::radians(10.f), 0.f, glm::radians(angle)), glm::vec3(0.f, 1.f, 0.f)); // rotate the enemy
}
else if (route.size() > 0)
{
if(abs(glm::distance(pos, route[count])) < 1)
{
count++;
count %= route.size();
}
else
{
glm::vec4 mov = glm::transpose(position) * glm::normalize(route[count] - pos) * elapsedTime.count() * speed;
float angle = glm::orientedAngle(glm::normalize(glm::vec2(mov.x, mov.z)), glm::normalize(glm::vec2(position[2][0], position[2][2])));
// angle between enemy's facing direction and direction of it's movement
position = glm::translate(position, glm::vec3(mov.x, mov.y, mov.z));
position = glm::rotate(position, glm::clamp(glm::radians(10.f), 0.f, glm::radians(angle)), glm::vec3(0.f, 1.f, 0.f)); // rotate the enemy
}
}
}
void Foe::kill_this_bastard()
{
health--;
}
bool Foe::is_bastard_alive()
{
if (health) return true;
else return false;
}
//debugging
std::chrono::time_point<std::chrono::system_clock> Foe::lS()
{
return lastShoot;
}
void Foe::setlS(std::chrono::time_point<std::chrono::system_clock> time)
{
lastShoot = time;
}
Model* Foe::returnBullet()
{
return bullet;
}
float Foe::getSpeed()
{
return speed;
}
void Foe::updatePos(float* shift)
{
position = glm::translate(position, glm::vec3(shift[0], shift[1], shift[2]));
}