ajout du drift

This commit is contained in:
Baptiste 2023-12-07 18:53:34 +01:00
parent a4c8e32a26
commit 97fac63998
4 changed files with 30 additions and 16 deletions

BIN
assets/sounds/drift.mp3 Normal file

Binary file not shown.

View file

@ -7,9 +7,6 @@ const bulletSpeed=playerSpeed*2;
const halfSqrtTwo=0.70710678118; const halfSqrtTwo=0.70710678118;
const defaulthealth=10.; const defaulthealth=10.;
let sound = new Sound("./assets/sounds/");
sound.loadSounds();
class Player class Player
{ {
constructor (id,x,y,name, dir) constructor (id,x,y,name, dir)
@ -114,7 +111,7 @@ class Player
class Bullet class Bullet
{ {
constructor (x,y,dx,dy,id) constructor (x,y,dx,dy,id, sound)
{ {
sound.shoot(); sound.shoot();
this.x=x; this.x=x;
@ -198,8 +195,9 @@ class Circle
class Car class Car
{ {
constructor(Renderer, type, spawn) constructor(Renderer, type, spawn, sound)
{ {
this.sound=sound
this.type=type // 0 circule vers le haut this.type=type // 0 circule vers le haut
// 1 circule vers le bas // 1 circule vers le bas
@ -215,6 +213,8 @@ class Car
this.angle=-Math.PI/2; this.angle=-Math.PI/2;
} }
this.drift=0;
this.spawn=spawn this.spawn=spawn
this.tick=0; this.tick=0;
@ -227,7 +227,12 @@ class Car
{ {
let cx=this.x-carSize/2; let cx=this.x-carSize/2;
let cy=this.y-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() Update()
@ -252,8 +257,13 @@ class Car
this.y=this.y+this.tick this.y=this.y+this.tick
break; break;
} }
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) this.Renderer.RenderCar(this.x,this.y, this.angle)
} }
}
pseudoaleatoire() { pseudoaleatoire() {
return Math.floor(Date.now()/1000)%10 return Math.floor(Date.now()/1000)%10

View file

@ -11,13 +11,15 @@ function CookiePseudo() {
Renderer = new Render("canvas", "./assets/map/map7_recadr.png"); Renderer = new Render("canvas", "./assets/map/map7_recadr.png");
LB = new LeaderBoard("canvas"); LB = new LeaderBoard("canvas");
cars = [new Car(Renderer, 0, 0), let sound = new Sound("./assets/sounds/");
new Car(Renderer, 0, 7), sound.loadSounds();
new Car(Renderer, 1, 7), cars = [new Car(Renderer, 0, 0, sound),
new Car(Renderer, 1, 13), new Car(Renderer, 0, 7, sound),
new Car(Renderer, 1, 14), new Car(Renderer, 1, 7, sound),
new Car(Renderer, 0, 15)] new Car(Renderer, 1, 13, sound),
let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), Renderer); 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 let playerId = null; //id of client player

View file

@ -1,5 +1,5 @@
class Network{ class Network{
constructor(adress){ constructor(adress, bulletsound){
this.adress = adress; this.adress = adress;
this.connected = false; this.connected = false;
@ -10,6 +10,7 @@ class Network{
this.playersToUpdate = []; this.playersToUpdate = [];
this.bulletsToAdd = []; this.bulletsToAdd = [];
this.deathToAdd = []; this.deathToAdd = [];
this.sound=bulletsound;
} }
message(data){ message(data){
@ -36,7 +37,8 @@ class Network{
this.playersToRemove.push(data.data.id); this.playersToRemove.push(data.data.id);
break; break;
case "newBullet": 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; break;
case "died": case "died":
console.log("player",data.data.id,"was killed by",data.data.killerId); console.log("player",data.data.id,"was killed by",data.data.killerId);