-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexplosion.js
51 lines (47 loc) · 1.96 KB
/
explosion.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
/*==============================================================================
Init
==============================================================================*/
$.Explosion = function( opt ) {
for( var k in opt ) {
this[k] = opt[k];
}
this.tick = 0;
this.tickMax = 20;
if( $.slow ) {
$.audio.play( 'explosionAlt' );
} else {
$.audio.play( 'explosion' );
}
};
/*==============================================================================
Update
==============================================================================*/
$.Explosion.prototype.update = function( i ) {
if( this.tick >= this.tickMax ) {
$.explosions.splice( i, 1 );
} else {
this.tick += $.dt;
}
};
/*==============================================================================
Render
==============================================================================*/
$.Explosion.prototype.render = function( i ) {
if( $.util.arcInRect( this.x, this.y, this.radius, -$.screen.x, -$.screen.y, $.cw, $.ch ) ) {
var radius = 1 + ( this.tick / ( this.tickMax / 2 ) ) * this.radius,
lineWidth = $.util.rand( 1, this.radius / 2 );
$.util.strokeCircle( $.ctxmg, this.x, this.y, radius, 'hsla(' + this.hue + ', ' + this.saturation + '%, ' + $.util.rand( 40, 80 ) + '%, ' + Math.min( 1, Math.max( 0, ( 1 - ( this.tick / this.tickMax ) ) ) ) + ')', lineWidth);
$.ctxmg.beginPath();
var size = $.util.rand( 1, 1.5 );
for( var i = 0; i < 20; i++ ) {
var angle = $.util.rand( 0, $.twopi ),
x = this.x + Math.cos( angle ) * radius,
y = this.y + Math.sin( angle ) * radius;
$.ctxmg.rect( x - size / 2, y - size / 2, size, size );
}
$.ctxmg.fillStyle = 'hsla(' + this.hue + ', ' + this.saturation + '%, ' + $.util.rand( 50, 100 ) + '%, 1)';
$.ctxmg.fill();
$.ctxmg.fillStyle = 'hsla(' + this.hue + ', ' + this.saturation + '%, 50%, ' + Math.min( 1, Math.max( 0, ( 0.03 - ( this.tick / this.tickMax ) * 0.03 ) ) ) + ')';
$.ctxmg.fillRect( -$.screen.x, -$.screen.y, $.cw, $.ch );
}
};