-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirework.js
53 lines (44 loc) · 1.03 KB
/
firework.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
49
50
51
52
53
function Firework(x,y,numParticles) {
this.x = x;
this.y = y;
this.firework = new Particle(this.x, this.y, true);
this.exploded = false;
this.particles = [];
this.numParticles = numParticles;
this.done = function() {
if (this.exploded && this.particles.length ===0) {
return true;
} else {
return false;
}
}
this.update = function() {
if (!this.exploded) {
this.firework.update();
//if (this.firework.vel.y >= 0) {
this.exploded = true;
this.explode();
//}
}
for (var i = this.particles.length - 1; i >= 0 ; i--) {
this.particles[i].update();
if (this.particles[i].done()) {
this.particles.splice(i , 1);
}
}
}
this.explode = function() {
for (var i = 0; i < this.numParticles; i++) {
var p = new Particle(this.firework.pos.x,this.firework.pos.y, false);
this.particles.push(p);
}
}
this.show = function() {
if (!this.exploded) {
this.firework.show();
}
for (var i = this.particles.length - 1; i >= 0 ; i--) {
this.particles[i].show();
}
}
}