diff --git a/assets/sounds/drift.mp3 b/assets/sounds/drift.mp3 new file mode 100644 index 0000000..2929b23 Binary files /dev/null and b/assets/sounds/drift.mp3 differ diff --git a/js/class.js b/js/class.js index daaa6d6..9fa9690 100644 --- a/js/class.js +++ b/js/class.js @@ -7,9 +7,6 @@ const bulletSpeed=playerSpeed*2; const halfSqrtTwo=0.70710678118; const defaulthealth=10.; -let sound = new Sound("./assets/sounds/"); -sound.loadSounds(); - class Player { constructor (id,x,y,name, dir) @@ -114,7 +111,7 @@ class Player class Bullet { - constructor (x,y,dx,dy,id) + constructor (x,y,dx,dy,id, sound) { sound.shoot(); this.x=x; @@ -198,8 +195,9 @@ class Circle class Car { - constructor(Renderer, type, spawn) + constructor(Renderer, type, spawn, sound) { + this.sound=sound this.type=type // 0 circule vers le haut // 1 circule vers le bas @@ -215,6 +213,8 @@ class Car this.angle=-Math.PI/2; } + this.drift=0; + this.spawn=spawn this.tick=0; @@ -227,7 +227,12 @@ class Car { let cx=this.x-carSize/2; let cy=this.y-carSize/2; - return (cx<=x && x<=cx+carSize && cy<=y && y<=cy+carSize); + let collide = (cx<=x && x<=cx+carSize && cy<=y && y<=cy+carSize); + if(collide) { + this.sound.drift() + this.drift=300; + } + return collide } Update() @@ -252,7 +257,12 @@ class Car this.y=this.y+this.tick break; } - this.Renderer.RenderCar(this.x,this.y, this.angle) + if(this.drift > 0) { + this.Renderer.RenderCar(this.x,this.y, this.angle+90) + this.drift-- + } else { + this.Renderer.RenderCar(this.x,this.y, this.angle) + } } pseudoaleatoire() { diff --git a/js/game.js b/js/game.js index c1100df..a98f6ff 100644 --- a/js/game.js +++ b/js/game.js @@ -11,13 +11,15 @@ function CookiePseudo() { Renderer = new Render("canvas", "./assets/map/map7_recadr.png"); LB = new LeaderBoard("canvas"); -cars = [new Car(Renderer, 0, 0), - new Car(Renderer, 0, 7), - new Car(Renderer, 1, 7), - new Car(Renderer, 1, 13), - new Car(Renderer, 1, 14), - new Car(Renderer, 0, 15)] -let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), Renderer); +let sound = new Sound("./assets/sounds/"); +sound.loadSounds(); +cars = [new Car(Renderer, 0, 0, sound), + new Car(Renderer, 0, 7, sound), + new Car(Renderer, 1, 7, sound), + new Car(Renderer, 1, 13, sound), + new Car(Renderer, 1, 14, sound), + new Car(Renderer, 0, 15, sound)] +let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), sound); let playerId = null; //id of client player diff --git a/js/network.js b/js/network.js index 8fa2638..74d9340 100644 --- a/js/network.js +++ b/js/network.js @@ -1,5 +1,5 @@ class Network{ - constructor(adress){ + constructor(adress, bulletsound){ this.adress = adress; this.connected = false; @@ -10,6 +10,7 @@ class Network{ this.playersToUpdate = []; this.bulletsToAdd = []; this.deathToAdd = []; + this.sound=bulletsound; } message(data){ @@ -36,7 +37,8 @@ class Network{ this.playersToRemove.push(data.data.id); break; case "newBullet": - this.bulletsToAdd.push(new Bullet(data.data.x,data.data.y,data.data.dx,data.data.dy,data.data.id)); + console.log(this.sound) + this.bulletsToAdd.push(new Bullet(data.data.x,data.data.y,data.data.dx,data.data.dy,data.data.id, this.sound)); break; case "died": console.log("player",data.data.id,"was killed by",data.data.killerId);