-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulletSystem.js
48 lines (43 loc) · 1.09 KB
/
bulletSystem.js
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
class BulletSystem {
constructor() {
this.bullets = [];
}
run() {
this.move();
this.draw();
this.edges();
}
fire(x, y, mouseDir, dirOffset) {
let bullet = new Bullet(x, y);
bullet.dir = mouseDir;
bullet.dir.setMag(bullet.speed);
bullet.initialPos = dirOffset;
bullet.location = bullet.initialPos.copy();
this.bullets.push(bullet);
}
draw() {
fill(255);
for (var i = 0; i < this.bullets.length; i++) {
this.bullets[i].draw();
// ellipse(this.bullets[i].location.x, this.bullets[i].location.y, this.bullets[i].diam, this.bullets[i].diam);
}
}
move() {
for (var i = 0; i < this.bullets.length; i++) {
this.bullets[i].move();
}
}
edges() {
for (let i = 0; i < this.bullets.length; i++) {
if (
this.bullets[i].location.x > playBox.width / 2 ||
this.bullets[i].location.x < -playBox.width / 2 ||
this.bullets[i].location.y > playBox.height / 2 ||
this.bullets[i].location.y < -playBox.height / 2
) {
this.bullets.splice(i, 1);
i--;
}
}
}
}