debut car
This commit is contained in:
parent
17446bf1f0
commit
d05feafb86
2 changed files with 50 additions and 3 deletions
48
js/class.js
48
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
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue