From d05feafb86271293bad71c71efb72fca303be77d Mon Sep 17 00:00:00 2001 From: Baptiste Date: Thu, 7 Dec 2023 10:45:31 +0100 Subject: [PATCH] debut car --- js/class.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ js/game.js | 5 ++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/js/class.js b/js/class.js index 6e157bb..d53c10d 100644 --- a/js/class.js +++ b/js/class.js @@ -184,4 +184,52 @@ class Circle { return ((point.x-this.x)**2+(point.y-this.y)**2<=this.r**2); } +} + +class Car +{ + constructor(Renderer) + { + this.x=1200//220; + this.y=75; + this.dir=1; + this.angle=0; + this.tick=1; + this.Renderer=Renderer; + } + + Update() + { + this.ChangeDirection() + switch (this.dir) { + case 1: + this.x=this.x+this.tick + break; + case 2: + this.y=this.y-this.tick + break; + case 3: + this.x=this.x-this.tick + break; + case 4: + this.y=this.y+this.tick + break; + } + this.Renderer.RenderCar(this.x,this.y, this.angle) + } + + ChangeDirection() + { + //console.log(this.x, this.y) + 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 + } + + } } \ No newline at end of file diff --git a/js/game.js b/js/game.js index 72c3c1f..af1368a 100644 --- a/js/game.js +++ b/js/game.js @@ -11,6 +11,7 @@ function CookiePseudo() { Renderer = new Render("canvas", "./assets/map/map7_recadr.png"); LB = new LeaderBoard("canvas"); +Cars = new Car(Renderer); let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), Renderer); @@ -108,7 +109,6 @@ function updateBullets(dt) } let currentTime = new Date(); -let carx=0 function game() { if(playerId==null) { @@ -147,14 +147,13 @@ function game() { } Renderer.ReloadAff(); updateBullets(dt); - Renderer.RenderCar(200+carx,75, 0); + Cars.Update(); LB.ReloadAff(players, player); } let newTime = new Date(); dt=newTime - currentTime; currentTime=newTime; - carx=carx+3 } Net.connect(); //connect to server, create a player, and retrieve all players info