cars !!!!

This commit is contained in:
Baptiste 2023-12-07 12:04:32 +01:00
parent d05feafb86
commit 62b594bd3e
2 changed files with 49 additions and 8 deletions

View file

@ -188,10 +188,10 @@ class Circle
class Car class Car
{ {
constructor(Renderer) constructor(Renderer, x, y)
{ {
this.x=1200//220; this.x=x;
this.y=75; this.y=y;
this.dir=1; this.dir=1;
this.angle=0; this.angle=0;
this.tick=1; this.tick=1;
@ -218,10 +218,13 @@ class Car
this.Renderer.RenderCar(this.x,this.y, this.angle) this.Renderer.RenderCar(this.x,this.y, this.angle)
} }
pseudoaleatoire() {
return Math.floor(Date.now()/1000)%10
}
ChangeDirection() ChangeDirection()
{ {
//console.log(this.x, this.y) if(this.x == 1280 && this.y==75) {
if(this.x > 1280 && this.y==75) {
this.dir=2 this.dir=2
this.y=60 this.y=60
this.angle=-Math.PI/2 this.angle=-Math.PI/2
@ -229,7 +232,43 @@ class Car
this.dir=2 this.dir=2
this.x=947 this.x=947
this.y=1000 this.y=1000
} else if(this.x==947 && this.y==875 ) {
if(this.pseudoaleatoire()>7) {
//tourner à droite
this.dir=1
this.angle=0
}
} else if(this.x==947 && this.y==839 ) {
if(this.pseudoaleatoire()>4) {
//tourner à gauche
this.dir=3
this.angle=-Math.PI
}
} else if(this.x==947 && this.y==587) {
this.dir=1
this.angle=0
} else if(this.x==1280 && this.y>400) {
this.dir=2
this.angle=-Math.PI/2
} else if(this.x==228 && this.y==839) {
this.y==823
this.dir=2
this.angle=-Math.PI/2
} else if(this.x==228 && this.y==587) {
this.dir=1
this.angle=0
} else if(this.x==644 && this.y==587) {
this.dir=2
this.angle=-Math.PI/2
} else if(this.dir==2 && this.y==295) {
this.dir=3
this.angle=-Math.PI
} else if(this.x==468 && this.y==295) {
this.dir=2
this.angle=-Math.PI/2
} else if(this.x==468 && this.y==75) {
this.dir=1
this.angle=0
} }
} }
} }

View file

@ -11,7 +11,7 @@ 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); cars = [new Car(Renderer, 220, 75),new Car(Renderer, 500, 75),new Car(Renderer, 900,75),new Car(Renderer, 228,587),new Car(Renderer, 947,587)]
let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), Renderer); let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), Renderer);
@ -146,8 +146,10 @@ function game() {
players[i].update(squares, circles, dt); players[i].update(squares, circles, dt);
} }
Renderer.ReloadAff(); Renderer.ReloadAff();
cars.forEach((c) => {
c.Update();
})
updateBullets(dt); updateBullets(dt);
Cars.Update();
LB.ReloadAff(players, player); LB.ReloadAff(players, player);
} }