diff --git a/js/class.js b/js/class.js index 14fdb09..7ee245a 100644 --- a/js/class.js +++ b/js/class.js @@ -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 } } } \ No newline at end of file diff --git a/js/game.js b/js/game.js index a991517..4b82e6e 100644 --- a/js/game.js +++ b/js/game.js @@ -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); diff --git a/js/render.js b/js/render.js index b2e3b21..47387a7 100644 --- a/js/render.js +++ b/js/render.js @@ -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);