-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMissiles.cpp
60 lines (50 loc) · 1.17 KB
/
Missiles.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
// River Raid 2018
// Made by Micha³ Berdzik, AGH, 2018 ©
//------------------------------------------------------------------
#include "Missiles.h"
Missiles::Missiles()
{
frequency = sf::milliseconds(100);
infinite = true;
ammunition = 500;
}
Missiles::~Missiles()
{
}
void Missiles::Add(vector3d pos,vector3d vec,float Yaw,float Pitch) {
SingleBullet a;
a.loc = pos;
a.loc_buff = vec;
a.Yaw = Yaw;
a.Pitch = Pitch;
if (timer.getElapsedTime() >= frequency && (ammunition >= 0 || infinite))
{
p_bullets.push_back(a);
factor.push_back(pos);
timer.restart();
if (!infinite) ammunition--;
}
}
void Missiles::update(float vel) {
for (int i = 0;i < p_bullets.size();i++) {
p_bullets[i].speed = vel;
if (abs(p_bullets[i].loc_buff.x - p_bullets[i].loc.x) > 100 ||
abs(p_bullets[i].loc_buff.y - p_bullets[i].loc.y) > 100 ||
abs(p_bullets[i].loc_buff.z - p_bullets[i].loc.z) > 100) {
remove(i);
}
}
}
void Missiles::remove(int it)
{
for (int i = it;i<p_bullets.size() - 1;i++)
{
std::swap(p_bullets[i], p_bullets[i + 1]);
}
p_bullets.resize(factor.size());
}
void Missiles::render() {
for (int i = 0; i < p_bullets.size();i++) {
p_bullets[i].Make();
}
}