This commit is contained in:
Baptiste 2023-12-07 16:29:34 +01:00
parent 84794fe5c3
commit dbb0e87054
3 changed files with 109 additions and 43 deletions

View file

@ -194,12 +194,14 @@ class Circle
class Car
{
constructor(Renderer, x, y)
constructor(Renderer, x, y, type, dir, angle)
{
this.type=type // 0 circule à droite vers le haut
// 1 circule vers le bas
this.x=x;
this.y=y;
this.dir=1;
this.angle=0;
this.dir=dir;
this.angle=angle;
this.tick=1;
this.Renderer=Renderer;
}
@ -230,51 +232,109 @@ class Car
ChangeDirection()
{
if(this.x == 1280 && this.y==75) {
this.dir=2
this.y=60
this.angle=-Math.PI/2
} else if(this.y<-40) {
this.dir=2
this.x=947
this.y=1000
} else if(this.x==947 && this.y==875 ) {
if(this.pseudoaleatoire()>7) {
if(this.type == 1) {
if(this.x==1247 && this.y==36) {
this.dir=3
this.angle=-Math.PI
} else if(this.x==430 && this.y==36) {
this.dir=4
this.angle=Math.PI/2
} else if(this.x==430 && this.y==330) {
//tourner à droite
this.dir=1
this.angle=0
} else if(this.x==607 && this.y==330) {
if(this.pseudoaleatoire()>5) {
//vers le bas
this.dir=4
this.angle=Math.PI/2
}
} else if(this.x==1247 && this.y==330) {
//vers le bas
this.dir=4
this.angle=Math.PI/2
} else if(this.x==607 && this.y==551) {
//vers la gauche
this.dir=3
this.angle=Math.PI
} else if(this.x==190 && this.y==551) {
//vers le bas
this.dir=4
this.angle=Math.PI/2
} else if(this.x==190 && this.y==877) {
//vers la droite
this.dir=1
this.angle=0
} else if(this.x==907 && this.y==877) {
//vers la droite
this.dir=4
this.angle=Math.PI/2
} else if(this.x==1247 && this.y==550) {
if(this.pseudoaleatoire()>5) {
//vers la gauche
this.dir=3
this.angle=Math.PI
}
} else if(this.x==910 && this.y==550) {
//vers le bas
this.dir=4
this.angle=Math.PI/2
} else if(this.x==1247 && this.y==840) {
//vers la gauche
this.dir=3
this.angle=Math.PI
} else if(this.x==907 && this.y==840) {
//vers le bas
this.dir=4
this.angle=Math.PI/2
}
} else if(this.x==947 && this.y==839 ) {
if(this.pseudoaleatoire()>4) {
//tourner à gauche
} else {
if(this.x == 1280 && this.y==75) {
this.dir=2
this.y=60
this.angle=-Math.PI/2
} else if(this.y<-40) {
this.dir=2
this.x=947
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
}
} 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,13 @@ function CookiePseudo() {
Renderer = new Render("canvas", "./assets/map/map7_recadr.png");
LB = new LeaderBoard("canvas");
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)]
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)]
let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), Renderer);

View file

@ -65,7 +65,7 @@ class Render {
}
}
RenderCar(x,y, angle) {
RenderCar(x,y,angle) {
this.ctx.save();
this.ctx.translate(x, y);
this.ctx.rotate(angle);