-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirework.js
53 lines (47 loc) · 1.38 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 () {
this.hu = random(255);
this.firework = new Partical(random(width), height, this.hu, true)
this.exploded = false;
this.particles = [];
this.isOffBound = function() {
return this.firework.isOffbound()
}
this.done = function() {
if (this.exploded && this.particles.length === 0) {
return true
} else {
return false
}
}
this.update = function() {
if (!this.exploded) {
this.firework.applyForce(gravity)
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].applyForce(gravity)
this.particles[i].update()
if (this.particles[i].done()) {
this.particles.splice(i, 1)
}
}
}
this.explode = function() {
for (var i = 0; i < 100; i++) {
var p = new Partical(this.firework.pos.x, this.firework.pos.y, this.hu, false)
this.particles.push(p)
}
}
this.show = function() {
if (!this.exploded) {
this.firework.show()
}
for (var i = 0; i < this.particles.length; i++) {
this.particles[i].show()
}
}
}