diff --git a/js/class.js b/js/class.js index d53c10d..1449765 100644 --- a/js/class.js +++ b/js/class.js @@ -188,10 +188,10 @@ class Circle class Car { - constructor(Renderer) + constructor(Renderer, x, y) { - this.x=1200//220; - this.y=75; + this.x=x; + this.y=y; this.dir=1; this.angle=0; this.tick=1; @@ -218,10 +218,13 @@ class Car this.Renderer.RenderCar(this.x,this.y, this.angle) } + pseudoaleatoire() { + return Math.floor(Date.now()/1000)%10 + } + 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.y=60 this.angle=-Math.PI/2 @@ -229,7 +232,43 @@ class Car 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 } - } } \ No newline at end of file diff --git a/js/game.js b/js/game.js index af1368a..925abe3 100644 --- a/js/game.js +++ b/js/game.js @@ -11,7 +11,7 @@ function CookiePseudo() { Renderer = new Render("canvas", "./assets/map/map7_recadr.png"); 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); @@ -146,8 +146,10 @@ function game() { players[i].update(squares, circles, dt); } Renderer.ReloadAff(); + cars.forEach((c) => { + c.Update(); + }) updateBullets(dt); - Cars.Update(); LB.ReloadAff(players, player); }