correction son en parametre => plus propre

This commit is contained in:
Baptiste 2023-12-07 18:53:44 +01:00
parent 97fac63998
commit 87d078a34d
3 changed files with 11 additions and 3 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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()
}
}