2023-12-08 13:50:49 +01:00
|
|
|
let player = null;
|
|
|
|
let players = [];
|
|
|
|
let renderer = new Render("canvas");
|
|
|
|
let LB = new LeaderBoard("canvas");
|
|
|
|
let bulletSound = new Sound("./assets/sounds/shoot.mp3");
|
|
|
|
let driftSound = new Sound("./assets/sounds/drift.mp3");
|
2023-12-09 10:44:37 +01:00
|
|
|
let net = new Network("wss://ws.gta6.insat.fr:8080?name=" + getCookie("pseudo"));
|
2023-12-08 13:50:49 +01:00
|
|
|
let inp = new Input("canvas");
|
|
|
|
let bullets = [];
|
2023-12-08 18:02:42 +01:00
|
|
|
let circles = [];
|
|
|
|
let squares = [];
|
2023-12-12 13:53:55 +01:00
|
|
|
let PNJS = [new PNJ(500, 100,0),
|
|
|
|
new PNJ(700, 100,0),
|
|
|
|
new PNJ(500, 600,0),
|
|
|
|
new PNJ(200, 700,0)];
|
2023-12-09 14:57:46 +01:00
|
|
|
|
2023-12-12 13:53:55 +01:00
|
|
|
let cars = [new Car(0, 0),
|
|
|
|
new Car(1, 7),
|
|
|
|
new Car(1, 13),
|
|
|
|
new Car(1, 14),
|
|
|
|
new Car(0, 7),
|
|
|
|
new Car(0, 15)];
|
2023-12-09 14:57:46 +01:00
|
|
|
|
2023-12-13 14:11:21 +01:00
|
|
|
players.push(new Player(-1,-50,-50,-1,"VOITURES",0));
|
2023-12-08 13:50:49 +01:00
|
|
|
|
|
|
|
function updatePlayer(data)
|
|
|
|
{
|
|
|
|
if(data.id==player.id)
|
|
|
|
{
|
|
|
|
player.x=data.x;
|
|
|
|
player.y=data.y;
|
2023-12-12 13:53:55 +01:00
|
|
|
player.z=data.z;
|
2023-12-08 13:50:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(let i=0;i<players.length;i++)
|
|
|
|
{
|
|
|
|
if(data.id==players[i].id)
|
|
|
|
{
|
|
|
|
players[i].x=data.x;
|
|
|
|
players[i].y=data.y;
|
2023-12-12 13:53:55 +01:00
|
|
|
if(data.z==undefined)
|
|
|
|
data.z=0;
|
|
|
|
players[i].z=data.z;
|
2023-12-08 13:50:49 +01:00
|
|
|
players[i].dir=data.dir;
|
|
|
|
players[i].visibleDir=data.visibleDir;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addPlayer(data)
|
|
|
|
{
|
2023-12-12 13:53:55 +01:00
|
|
|
let np = new Player(data.id, data.x, data.y, 0, data.name, data.dir);
|
2023-12-08 13:50:49 +01:00
|
|
|
players.push(np);
|
|
|
|
}
|
|
|
|
|
2023-12-12 13:53:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-08 13:50:49 +01:00
|
|
|
function removePlayer(id)
|
|
|
|
{
|
|
|
|
for(let i=0;i<players.length;i++)
|
|
|
|
{
|
|
|
|
if(players[i].id==id)
|
|
|
|
{
|
|
|
|
players.splice(i,1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addKill(idKilled,idKiller)
|
|
|
|
{
|
|
|
|
if(player.id==idKiller)
|
|
|
|
player.kill++;
|
|
|
|
players.forEach((p) => {
|
|
|
|
if(p.id==idKilled)
|
|
|
|
p.death++;
|
|
|
|
if(p.id==idKiller)
|
|
|
|
p.kill++;
|
|
|
|
});
|
2023-12-09 14:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateBullets(dt)
|
|
|
|
{
|
|
|
|
for(let i = bullets.length-1;i>=0;i--)
|
|
|
|
{
|
|
|
|
bullets[i].update(dt);
|
|
|
|
bullets[i].checkCollisions(squares,circles);
|
|
|
|
if(bullets[i].deleted)
|
|
|
|
{
|
|
|
|
bullets.splice(i,1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|