-
Notifications
You must be signed in to change notification settings - Fork 0
/
Explosions.js
69 lines (65 loc) · 2.02 KB
/
Explosions.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*Stores all explosions*/
function Explosions() {
this.explosions = new Array();
}
/*Adds an Explosion
* @param {Point} position The initial x / y position of the explosion
* @param {Number} initialRadius How big the explosion is when it first fires
* @param {Number} fullSizeRadius how big is the full size radius?
* @param {Integer} growthFrames How many frames does it take the explosion to grow?
* @param {Number} initialAlpha The initial transparency of the explosion (0.0 clear, 1.0 opaque)
* @param {Number} fullSizeAlpha What alpha should the explosion be when full?( 0.0-1.0)
* @param {Number} fadeFrames How many frames should the explosion last before fading?
* @param {Number} finalAlpha What alpha should the explosion be before it fades (0.0-1.0)
* @param {Integer} targetFrame What frame should we be before starting the animation?
*/
Explosions.prototype.add = function (
position,
color,
initialRadius,
fullSizeRadius,
growthFrames,
initialAlpha,
fullSizeAlpha,
fadeFrames,
finalAlpha,
targetFrame
) {
var explosion = new Explosion(
position,
color,
initialRadius,
fullSizeRadius,
growthFrames,
initialAlpha,
fullSizeAlpha,
fadeFrames,
finalAlpha,
targetFrame
);
this.explosions.push(explosion);
};
/*Remove an Explosions
*@param {Integer} index, The element to remove
*/
Explosions.prototype.remove = function (index) {
this.explosions.splice(index, 1);
};
/*Remove all Explosions
*/
Explosions.prototype.removeAll = function () {
for (var i = this.explosions.length - 1; i >= 0; i--) {
this.remove(i);
}
};
/*Draws all explosions, deletes all explosions that have reached the end of their life
* @param {Canvas Drawing Context} ctx
*/
Explosions.prototype.drawAll = function (ctx, frame) {
ctx.clearRect(0, 0, Background.WIDTH, Background.HEIGHT);
for (var i = this.explosions.length - 1; i >= 0; i--) {
if (this.explosions[i].draw(ctx)) {
this.remove(i);
}
}
};