-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMegaWeapon.cpp
More file actions
87 lines (78 loc) · 1.93 KB
/
MegaWeapon.cpp
File metadata and controls
87 lines (78 loc) · 1.93 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
#include "MegaWeapon.hpp"
MegaWeapon::MegaWeapon(void) {
int j;
int tmp_vec[2];
this->upgradeLvl = 4;
this->type = "MEGA";
this->toFire = new Bullet*[maxLvl];
for (int i = 0; i < maxLvl; i++) {
toFire[i] = new Bullet[5 * (i + 1)];
for (j = 0; j < 5 * (i + 1); j++) {
tmp_vec[0] = this->toFire[i][j].getVector()[0];
tmp_vec[1] = -1 * this->toFire[i][j].getVector()[1];
this->toFire[i][j].setVector(tmp_vec);
}
}
}
MegaWeapon::MegaWeapon(MegaWeapon const & ref) : Weapon(ref) {
int j;
this->toFire = new Bullet*[maxLvl];
for (int i = 0; i < maxLvl; i++) {
this->toFire[i] = new Bullet[i + 1];
for (j = 0; j < (i + 1); j++) {
this->toFire[i][j] = Bullet(ref.toFire[i][j]);
}
}
}
MegaWeapon & MegaWeapon::operator=(MegaWeapon const & ref) {
int i;
int j;
this->type = ref.type;
this->upgradeLvl = ref.upgradeLvl;
for (i = 0; i < maxLvl; i++) {
delete [] this->toFire[i];
}
delete this->toFire;
this->toFire = new Bullet*[maxLvl];
for (i = 0; i < maxLvl; i++) {
this->toFire[i] = new Bullet[i + 1];
for (j = 0; j < (i + 1); j++) {
this->toFire[i][j] = Bullet(ref.toFire[i][j]);
}
}
return *this;
}
MegaWeapon::~MegaWeapon(void) {
for (int i = 0; i < maxLvl; i++) {
delete [] this->toFire[i];
}
delete this->toFire;
}
void MegaWeapon::fire(int y, int x, t_bullets **alist) const {
Bullet *tmp;
t_bullets *to_add;
int bulletHeight;
int tmp_vec[2];
if (alist == nullptr)
return ;
for (int i = 0; i < 5 * (this->upgradeLvl + 1); i++) {
tmp = new Bullet(this->toFire[upgradeLvl][i]);
bulletHeight = y;
bulletHeight += i - (2 * i * (i % 2));
tmp->setY(bulletHeight);
tmp->setX(x);
tmp_vec[0] = tmp->getVector()[0];
tmp_vec[1] = tmp->getVector()[1];
tmp_vec[0] += 2 * (i % 2) - 1;
tmp_vec[1] -= i;
tmp->setVector(tmp_vec);
to_add = new t_bullets;
to_add->bullet = tmp;
if (*alist)
to_add->next = *alist;
else
to_add->next = nullptr;
*alist = to_add;
}
return ;
}