-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntities.cpp
201 lines (169 loc) · 4.67 KB
/
Entities.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include "Entities.h"
bool Entities::isAttacked = false;
Entities::Entities(std::string wayToMesh, std::string wayToTextureMesh, Save &save, float speed, float hpRegen, float maxHp)
{
static unsigned int nr = 0;
id = nr;
entity = Figures(wayToMesh, wayToTextureMesh, save);
entity.setTransform(glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, glm::vec3(1.0f, 1.0f, 1.0f));
entitiesStatistict.hp = maxHp;
entities.rand = std::mt19937((unsigned int)std::time(nullptr));
std::uniform_real_distribution<float>distX(-10, 10);
entities.xMove = distX(entities.rand);
std::uniform_real_distribution<float>distZ(-10, 10);
entities.zMove = distZ(entities.rand);
std::uniform_real_distribution<float>distC(0, 10);
entities.cooldawn = distC(entities.rand);
entitiesStatistict.hp = save.statistics[id][0];
entitiesStatistict.speed = speed;
entitiesStatistict.hpRegeneration = hpRegen;
entitiesStatistict.maxHp = maxHp;
nr++;
std::cout << entitiesStatistict.hp;
}
Entities::~Entities()
{
}
void Entities::drawEntity(GLint &textureSlot, GLint &transforms, Save &save)
{
static ClockTimer hpRegen;
if (entitiesStatistict.hp > 0)
{
if (!entities.isAgressive)
{
if (entities.clock.getTimeAsSeconds() > entities.cooldawn)
{
entities.rand = std::mt19937((unsigned int)std::time(nullptr));
std::uniform_real_distribution<float>distX(-10, 10);
entities.xMove = distX(entities.rand);
std::uniform_real_distribution<float>distZ(-10, 10);
entities.zMove = distZ(entities.rand);
std::uniform_real_distribution<float>distC(0, 10);
entities.cooldawn = distC(entities.rand);
entities.clock.restart();
}
entity.movingTo(glm::vec3(entities.xMove, 0.0f, entities.zMove), entitiesStatistict.speed);
}
if (hpRegen.getTimeAsSeconds() >= 1.0f && entitiesStatistict.hp < entitiesStatistict.maxHp)
{
entitiesStatistict.hp += entitiesStatistict.hpRegeneration;
if (entitiesStatistict.hp > entitiesStatistict.maxHp)
{
entitiesStatistict.hp = entitiesStatistict.maxHp;
}
}
entity.draw(textureSlot, 0, transforms, save);
}
save.statistics[id][0] = entitiesStatistict.hp;
}
void Entities::attack(float distance, float damage, float attackSpeed, Game &game, glm::vec3 &playerPos, std::string damageType)
{
entitiesStatistict.damage = damage;
entitiesStatistict.attackSpeed = attackSpeed;
if (Auxiliary::getDistance(entity.position, playerPos, distance))
{
if (entities.attackSpeedTimer.getTimeAsSeconds() >= entitiesStatistict.attackSpeed)
{
game.life -= game.damages(entitiesStatistict.damage, damageType);
entities.attackSpeedTimer.restart();
}
}
}
void Entities::aggresive(glm::vec3 &playerPos, float distance)
{
if (Auxiliary::getDistance(playerPos, entity.position, distance))
{
entities.isAgressive = true;
entity.movingTo(playerPos, entitiesStatistict.speed);
}
else if (!Auxiliary::getDistance(playerPos, entity.position, distance))
{
entities.isAgressive = false;
}
}
void Entities::getDamage(Window &window, Game &game)
{
if (isAttacked && Auxiliary::getDistance(window.camera_position, entity.position, 0.5))
{
entitiesStatistict.hp -= damage(game, PHISICAL);
}
}
float Entities::damage(Game &game, std::string damageType)
{
float returnedDamage = 0;
if (damageType == "phisical")
{
returnedDamage = game.damage - entitiesDefense.armor / 2.0f;
if (returnedDamage < 0)
{
return 0;
}
else
{
return returnedDamage;
}
}
else if (damageType == "poison")
{
returnedDamage = game.damage - entitiesDefense.poisonArmor / 1.5f;
if (returnedDamage < 0)
{
return 0;
}
else
{
return returnedDamage;
}
}
else if (damageType == "fire")
{
returnedDamage = game.damage - entitiesDefense.fireArmor / 2.0f;
if (returnedDamage < 0)
{
return 0;
}
else
{
return returnedDamage;
}
}
else if (damageType == "magic")
{
returnedDamage = game.damage - entitiesDefense.magicArmor / 3.0f;
if (returnedDamage < 0)
{
return 0;
}
else
{
return returnedDamage;
}
}
else if (damageType == "ice")
{
returnedDamage = game.damage - entitiesDefense.iceArmor / 2.0f;
if (returnedDamage < 0)
{
return 0;
}
else
{
return returnedDamage;
}
}
else
{
damageType = "phisical";
}
}
EntitiesDefense::EntitiesDefense(float armor, float fireArmor, float iceArmor, float magicArmor, float poisonArmor)
{
this->armor = armor;
this->fireArmor = fireArmor;
this->iceArmor = iceArmor;
this->magicArmor = magicArmor;
this->poisonArmor = poisonArmor;
}
EntitiesDefense::EntitiesDefense()
{
}