From 87d078a34d04b9dd7c99a63dc4a04702115f7bda Mon Sep 17 00:00:00 2001 From: Baptiste Date: Thu, 7 Dec 2023 18:53:44 +0100 Subject: [PATCH] correction son en parametre => plus propre --- js/game.js | 2 +- js/input.js | 4 ++-- js/sound.js | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/js/game.js b/js/game.js index a98f6ff..a85d509 100644 --- a/js/game.js +++ b/js/game.js @@ -27,7 +27,7 @@ let players = []; let bullets = []; let player = null; -Inp = new Input("canvas", Net,Renderer); +Inp = new Input("canvas", Net,Renderer, sound); playerId=Net.playerId; player=Net.clientPlayer; diff --git a/js/input.js b/js/input.js index f4ca8c3..b980d73 100644 --- a/js/input.js +++ b/js/input.js @@ -1,5 +1,5 @@ class Input { - constructor(id, net,renderer) { + constructor(id, net,renderer, sound) { this.keysDown = new Set() this.dir = 0; this.player=null; @@ -23,7 +23,7 @@ class Input { let dx = this.mouseX-this.player.x; let dy = this.mouseY-this.player.y; let norm = Math.sqrt(dx*dx+dy*dy); - let b = new Bullet(this.player.x,this.player.y,dx/norm,dy/norm,this.player.id); + let b = new Bullet(this.player.x,this.player.y,dx/norm,dy/norm,this.player.id, sound); this.bullets.push(b); this.renderer.addBullet(b); diff --git a/js/sound.js b/js/sound.js index 8b934dc..01f0e07 100644 --- a/js/sound.js +++ b/js/sound.js @@ -7,6 +7,8 @@ class Sound{ console.log(this.assetsUrl + "shoot.mp3") this.shootSound = new Audio(this.assetsUrl + "shoot.mp3"); this.shootSound.type = "audio/mp3"; + this.driftsound = new Audio(this.assetsUrl + "drift.mp3"); + this.driftsound.type = "audio/mp3"; } shoot(){ @@ -14,4 +16,10 @@ class Sound{ this.shootSound.currentTime=0; this.shootSound.play() } + + drift(){ + this.driftsound.pause() + this.driftsound.currentTime=0; + this.driftsound.play() + } } \ No newline at end of file