sync cars

This commit is contained in:
Baptiste 2023-12-07 17:18:15 +01:00
parent 7bfc91379c
commit 5be0ab50c6
2 changed files with 37 additions and 14 deletions

View file

@ -198,20 +198,38 @@ class Circle
class Car
{
constructor(Renderer, x, y, type, dir, angle)
constructor(Renderer, type, spawn)
{
this.type=type // 0 circule à droite vers le haut
this.type=type // 0 circule vers le haut
// 1 circule vers le bas
this.x=x;
this.y=y;
this.dir=dir;
this.angle=angle;
this.tick=1;
if(this.type == 1) { //vers le bas
this.x=1247;
this.y=-40;
this.dir=4;
this.angle=Math.PI/2;
} else { //vers le haut
this.x=947;
this.y=1000;
this.dir=2;
this.angle=-Math.PI/2;
}
this.spawn=spawn
this.tick=0;
this.Renderer=Renderer;
//1247,-40
//947,1000
}
Update()
{
if(this.tick==0) {
if(new Date().getSeconds()%20==this.spawn) {
this.tick=1
}
}
this.ChangeDirection()
switch (this.dir) {
case 1:
@ -291,6 +309,11 @@ class Car
//vers le bas
this.dir=4
this.angle=Math.PI/2
} else if(this.y>1000) {
//tp
this.x=1247
this.y=-40
this.tick=0;
}
} else {
if(this.x == 1280 && this.y==75) {
@ -301,6 +324,7 @@ class Car
this.dir=2
this.x=947
this.y=1000
this.tick=0;
} else if(this.x==947 && this.y==875 ) {
if(this.pseudoaleatoire()>7) {
//tourner à droite

View file

@ -11,13 +11,12 @@ function CookiePseudo() {
Renderer = new Render("canvas", "./assets/map/map7_recadr.png");
LB = new LeaderBoard("canvas");
cars = [new Car(Renderer, 220, 75, 0, 1, 0),
new Car(Renderer, 500, 75, 0, 1, 0),
new Car(Renderer, 900,75, 0, 1, 0),
new Car(Renderer, 228,587, 0, 1, 0),
new Car(Renderer, 947,587, 0, 1, 0),
new Car(Renderer, 1247,600, 1, 4, Math.PI/2),
new Car(Renderer, 607,330, 1, 4, Math.PI/2)]
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);