Path: blob/main/static/src/gs/public/radius-raid/js/explosion.js
1324 views
/*==============================================================================1Init2==============================================================================*/3$.Explosion = function( opt ) {4for( var k in opt ) {5this[k] = opt[k];6}7this.tick = 0;8this.tickMax = 20;9if( $.slow ) {10$.audio.play( 'explosionAlt' );11} else {12$.audio.play( 'explosion' );13}14};1516/*==============================================================================17Update18==============================================================================*/19$.Explosion.prototype.update = function( i ) {20if( this.tick >= this.tickMax ) {21$.explosions.splice( i, 1 );22} else {23this.tick += $.dt;24}25};2627/*==============================================================================28Render29==============================================================================*/30$.Explosion.prototype.render = function( i ) {31if( $.util.arcInRect( this.x, this.y, this.radius, -$.screen.x, -$.screen.y, $.cw, $.ch ) ) {32var radius = 1 + ( this.tick / ( this.tickMax / 2 ) ) * this.radius,33lineWidth = $.util.rand( 1, this.radius / 2 );34$.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);35$.ctxmg.beginPath();36var size = $.util.rand( 1, 1.5 );37for( var i = 0; i < 20; i++ ) {38var angle = $.util.rand( 0, $.twopi ),39x = this.x + Math.cos( angle ) * radius,40y = this.y + Math.sin( angle ) * radius;4142$.ctxmg.rect( x - size / 2, y - size / 2, size, size );43}44$.ctxmg.fillStyle = 'hsla(' + this.hue + ', ' + this.saturation + '%, ' + $.util.rand( 50, 100 ) + '%, 1)';45$.ctxmg.fill();4647$.ctxmg.fillStyle = 'hsla(' + this.hue + ', ' + this.saturation + '%, 50%, ' + Math.min( 1, Math.max( 0, ( 0.03 - ( this.tick / this.tickMax ) * 0.03 ) ) ) + ')';48$.ctxmg.fillRect( -$.screen.x, -$.screen.y, $.cw, $.ch );49}50};5152