actually working Date + leaderBoard

This commit is contained in:
Victor Lasserre 2023-12-08 20:02:04 +01:00
parent 3103b0974f
commit eec1013c6c
3 changed files with 12 additions and 9 deletions

View file

@ -218,9 +218,13 @@ class Car
Update()
{
if(this.tick==0 && new Date.getSeconds()%20==this.spawn) {
if(this.tick==0 && new Date().getSeconds()%20==this.spawn) {
this.tick=1;
}
if(this.tick==0)
return;
this.ChangeDirection();
switch (this.dir) {
@ -238,10 +242,7 @@ class Car
break;
}
if(this.drift > 0) {
renderer.RenderCar(this.x,this.y, this.angle+2.1)
this.drift--
} else {
renderer.RenderCar(this.x,this.y, this.angle)
}
}

View file

@ -3,11 +3,11 @@ class LeaderBoard {
this.canvas = document.getElementById(idCanvas);
this.ctx = this.canvas.getContext("2d");
this.nbjoueur=0
this.px=10;
this.py=10;
}
ReloadAff() {
let px=10;
let py=10;
let LBplayers=[];
players.forEach((p) => {
if(p != null) {
@ -19,10 +19,9 @@ class LeaderBoard {
LBplayers.sort(function (a, b) {
return b.kill - a.kill;
});
// tableau du leaderboard (le fonc "blanc")
this.ctx.fillStyle = 'rgba(255, 255, 255, 0.7)';
this.ctx.fillRect(this.px, this.py, this.px+240, this.py+100+this.nbjoueur*20);
this.ctx.fillRect(this.px, this.py, this.px+240, this.py+100+LBplayers.length*20);
this.nbjoueur=0;
this.ctx.font = '20px Arial';
this.ctx.fillStyle = '#000000';
@ -38,7 +37,7 @@ class LeaderBoard {
this.ctx.lineTo(this.px+250, this.py+100);
this.ctx.stroke();
//donné user
//donnee user
this.ctx.fillStyle = '#000000';
this.ctx.font = '15px Arial';
this.ctx.fillText('#', this.px+10, this.py+80);

View file

@ -91,6 +91,9 @@ class Render {
this.ctx.canvas.height = mapHeight;
this.ctx.drawImage(fond, 0, 0, mapWidth, mapHeight);
this.RenderPlayer(player,true);
cars.forEach((car) => {
this.RenderCar(car.x,car.y,car.angle+(car.drift>0?2.1:0));
});
players.forEach((player) => {
this.RenderPlayer(player,false);
})