diff --git a/js/audio/fx/thruster.mp3 b/js/audio/fx/thruster.mp3 new file mode 100644 index 0000000..b0aa587 Binary files /dev/null and b/js/audio/fx/thruster.mp3 differ diff --git a/js/entities/Player.js b/js/entities/Player.js index e4a3447..39e3ec2 100644 --- a/js/entities/Player.js +++ b/js/entities/Player.js @@ -32,6 +32,8 @@ export default class Player { this.lastFired = 0; this.invincible = false; this.invincibleUntil = 0; + + this.thrusterSound = scene.sound.add('sfx_thruster', { loop: true, volume: 0.6 }); } update(time, delta) { @@ -67,8 +69,10 @@ export default class Player { this.sprite.body.velocity.x += Math.cos(rad) * THRUST_ACCEL * dt; this.sprite.body.velocity.y += Math.sin(rad) * THRUST_ACCEL * dt; this.sprite.setTexture('player_thrust'); + if (!this.thrusterSound.isPlaying) this.thrusterSound.play(); } else { this.sprite.setTexture('player'); + if (this.thrusterSound.isPlaying) this.thrusterSound.stop(); } // Cap total speed @@ -102,6 +106,7 @@ export default class Player { // Hide the ship and go invincible immediately – call before delaying respawn die() { this.alive = false; + if (this.thrusterSound.isPlaying) this.thrusterSound.stop(); this.invincible = true; this.invincibleUntil = this.scene.time.now + 99999; this.sprite.body.setVelocity(0, 0); @@ -173,6 +178,7 @@ export default class Player { destroy() { this.alive = false; + if (this.thrusterSound) { this.thrusterSound.stop(); this.thrusterSound.destroy(); } if (this.sprite && this.sprite.active) { this.sprite.destroy(); } diff --git a/js/scenes/BootScene.js b/js/scenes/BootScene.js index faec8d0..9e57e5f 100644 --- a/js/scenes/BootScene.js +++ b/js/scenes/BootScene.js @@ -23,6 +23,7 @@ export default class BootScene extends Phaser.Scene { this.load.audio('sfx_missle', 'js/audio/fx/missle.mp3'); this.load.audio('sfx_impact', 'js/audio/fx/impact.mp3'); this.load.audio('sfx_alien_death', 'js/audio/fx/alien_death.mp3'); + this.load.audio('sfx_thruster', 'js/audio/fx/thruster.mp3'); } create() {