Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Incognito-old
Path: blob/main/static/src/gs/public/radius-raid/js/explosion.js
1324 views
1
/*==============================================================================
2
Init
3
==============================================================================*/
4
$.Explosion = function( opt ) {
5
for( var k in opt ) {
6
this[k] = opt[k];
7
}
8
this.tick = 0;
9
this.tickMax = 20;
10
if( $.slow ) {
11
$.audio.play( 'explosionAlt' );
12
} else {
13
$.audio.play( 'explosion' );
14
}
15
};
16
17
/*==============================================================================
18
Update
19
==============================================================================*/
20
$.Explosion.prototype.update = function( i ) {
21
if( this.tick >= this.tickMax ) {
22
$.explosions.splice( i, 1 );
23
} else {
24
this.tick += $.dt;
25
}
26
};
27
28
/*==============================================================================
29
Render
30
==============================================================================*/
31
$.Explosion.prototype.render = function( i ) {
32
if( $.util.arcInRect( this.x, this.y, this.radius, -$.screen.x, -$.screen.y, $.cw, $.ch ) ) {
33
var radius = 1 + ( this.tick / ( this.tickMax / 2 ) ) * this.radius,
34
lineWidth = $.util.rand( 1, this.radius / 2 );
35
$.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);
36
$.ctxmg.beginPath();
37
var size = $.util.rand( 1, 1.5 );
38
for( var i = 0; i < 20; i++ ) {
39
var angle = $.util.rand( 0, $.twopi ),
40
x = this.x + Math.cos( angle ) * radius,
41
y = this.y + Math.sin( angle ) * radius;
42
43
$.ctxmg.rect( x - size / 2, y - size / 2, size, size );
44
}
45
$.ctxmg.fillStyle = 'hsla(' + this.hue + ', ' + this.saturation + '%, ' + $.util.rand( 50, 100 ) + '%, 1)';
46
$.ctxmg.fill();
47
48
$.ctxmg.fillStyle = 'hsla(' + this.hue + ', ' + this.saturation + '%, 50%, ' + Math.min( 1, Math.max( 0, ( 0.03 - ( this.tick / this.tickMax ) * 0.03 ) ) ) + ')';
49
$.ctxmg.fillRect( -$.screen.x, -$.screen.y, $.cw, $.ch );
50
}
51
};
52