Path: blob/main/static/src/gs/public/radius-raid/js/bullet.js
1330 views
/*==============================================================================1Init2==============================================================================*/3$.Bullet = function( opt ) {4for( var k in opt ) {5this[k] = opt[k];6}7this.enemiesHit = [];8this.inView = 0;9$.particleEmitters.push( new $.ParticleEmitter( {10x: this.x,11y: this.y,12count: 1,13spawnRange: 1,14friction: 0.75,15minSpeed: 2,16maxSpeed: 10,17minDirection: 0,18maxDirection: $.twopi,19hue: 0,20saturation: 021} ) );22};2324/*==============================================================================25Update26==============================================================================*/27$.Bullet.prototype.update = function( i ) {28/*==============================================================================29Apply Forces30==============================================================================*/31this.x += Math.cos( this.direction ) * ( this.speed * $.dt );32this.y += Math.sin( this.direction ) * ( this.speed * $.dt );33this.ex = this.x - Math.cos( this.direction ) * this.size;34this.ey = this.y - Math.sin( this.direction ) * this.size;3536/*==============================================================================37Check Collisions38==============================================================================*/39var ei = $.enemies.length;40while( ei-- ) {41var enemy = $.enemies[ ei ];42if( $.util.distance( this.x, this.y, enemy.x, enemy.y ) <= enemy.radius ) {43if( this.enemiesHit.indexOf( enemy.index ) == -1 ){44$.particleEmitters.push( new $.ParticleEmitter( {45x: this.x,46y: this.y,47count: Math.floor( $.util.rand( 1, 4 ) ),48spawnRange: 0,49friction: 0.85,50minSpeed: 5,51maxSpeed: 12,52minDirection: ( this.direction - $.pi ) - $.pi / 5,53maxDirection: ( this.direction - $.pi ) + $.pi / 5,54hue: enemy.hue55} ) );5657this.enemiesHit.push( enemy.index );58enemy.receiveDamage( ei, this.damage );5960if( this.enemiesHit.length > 3 ) {61$.bullets.splice( i, 1 );62}63}64if( !this.piercing ) {65$.bullets.splice( i, 1 );66}67}68}6970/*==============================================================================71Lock Bounds72==============================================================================*/73if( !$.util.pointInRect( this.ex, this.ey, 0, 0, $.ww, $.wh ) ) {74$.bullets.splice( i, 1 );75}7677/*==============================================================================78Update View79==============================================================================*/80if( $.util.pointInRect( this.ex, this.ey, -$.screen.x, -$.screen.y, $.cw, $.ch ) ) {81this.inView = 1;82} else {83this.inView = 0;84}85};8687/*==============================================================================88Render89==============================================================================*/90$.Bullet.prototype.render = function( i ) {91if( this.inView ) {92$.ctxmg.beginPath();93$.ctxmg.moveTo( this.x, this.y );94$.ctxmg.lineTo( this.ex, this.ey );95$.ctxmg.lineWidth = this.lineWidth;96$.ctxmg.strokeStyle = this.strokeStyle;97$.ctxmg.stroke();98}99};100101