Path: blob/main/static/src/gs/public/radius-raid/js/powerup.js
1330 views
/*==============================================================================1Init2==============================================================================*/3$.Powerup = function( opt ) {4for( var k in opt ) {5this[k] = opt[k];6}7var text = $.text( {8ctx: $.ctxmg,9x: 0,10y: 0,11text: this.title,12hspacing: 1,13vspacing: 0,14halign: 'top',15valign: 'left',16scale: 1,17snap: 0,18render: 019} );20this.hpadding = 8;21this.vpadding = 8;22this.width = text.width + this.hpadding * 2;23this.height = text.height + this.vpadding * 2;24this.x = this.x - this.width / 2;25this.y = this.y - this.height / 2;26this.direction = $.util.rand( 0, $.twopi );27this.speed = $.util.rand( 0.5, 2 );28};2930/*==============================================================================31Update32==============================================================================*/33$.Powerup.prototype.update = function( i ) {34/*==============================================================================35Apply Forces36==============================================================================*/37this.x += Math.cos( this.direction ) * this.speed * $.dt;38this.y += Math.sin( this.direction ) * this.speed * $.dt;3940/*==============================================================================41Check Bounds42==============================================================================*/43if( !$.util.rectInRect( this.x, this.y, this.width, this.height, 0, 0, $.ww, $.wh ) ){44$.powerups.splice( i, 1 );45}4647/*==============================================================================48Check Collection Collision49==============================================================================*/50if( $.hero.life > 0 && $.util.arcIntersectingRect( $.hero.x, $.hero.y, $.hero.radius + 2, this.x, this.y, this.width, this.height ) ){51$.audio.play( 'powerup' );52$.powerupTimers[ this.type ] = 300;53$.particleEmitters.push( new $.ParticleEmitter( {54x: this.x + this.width / 2,55y: this.y + this.height / 2,56count: 15,57spawnRange: 0,58friction: 0.85,59minSpeed: 2,60maxSpeed: 15,61minDirection: 0,62maxDirection: $.twopi,63hue: 0,64saturation: 065} ) );66$.powerups.splice( i, 1 );67$.powerupsCollected++;68}69};7071/*==============================================================================72Render73==============================================================================*/74$.Powerup.prototype.render = function( i ) {7576$.ctxmg.fillStyle = '#000';77$.ctxmg.fillRect( this.x - 2, this.y - 2, this.width + 4, this.height + 4 );78$.ctxmg.fillStyle = '#555';79$.ctxmg.fillRect( this.x - 1, this.y - 1, this.width + 2, this.height + 2 );8081$.ctxmg.fillStyle = '#111';82$.ctxmg.fillRect( this.x, this.y, this.width, this.height );8384$.ctxmg.beginPath();85$.text( {86ctx: $.ctxmg,87x: this.x + this.hpadding,88y: this.y + this.vpadding + 1,89text: this.title,90hspacing: 1,91vspacing: 0,92halign: 'top',93valign: 'left',94scale: 1,95snap: 0,96render: true97} );98$.ctxmg.fillStyle = '#000';99$.ctxmg.fill();100101$.ctxmg.beginPath();102$.text( {103ctx: $.ctxmg,104x: this.x + this.hpadding,105y: this.y + this.vpadding,106text: this.title,107hspacing: 1,108vspacing: 0,109halign: 'top',110valign: 'left',111scale: 1,112snap: 0,113render: true114} );115$.ctxmg.fillStyle = 'hsl(' + this.hue + ', ' + this.saturation + '%, ' + this.lightness + '%)';116$.ctxmg.fill();117118$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, 0.2)';119$.ctxmg.fillRect( this.x, this.y, this.width, this.height / 2 );120121}122123