2023-12-08 18:02:42 +01:00
|
|
|
let cars = [new Car(renderer, 0, 0),
|
|
|
|
new Car(renderer, 0, 7),
|
|
|
|
new Car(renderer, 1, 7),
|
|
|
|
new Car(renderer, 1, 13),
|
|
|
|
new Car(renderer, 1, 14),
|
|
|
|
new Car(renderer, 0, 15)];
|
2023-11-15 09:09:13 +01:00
|
|
|
|
2023-11-29 16:21:20 +01:00
|
|
|
|
2023-12-09 14:53:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
PNJS.push(new PNJ(500, 100));
|
|
|
|
PNJS.push(new PNJ(700, 100));
|
|
|
|
PNJS.push(new PNJ(500, 600));
|
|
|
|
PNJS.push(new PNJ(200, 700));
|
2023-12-06 09:50:34 +01:00
|
|
|
|
2023-12-06 10:46:06 +01:00
|
|
|
function updateBullets(dt)
|
2023-12-06 09:50:34 +01:00
|
|
|
{
|
2023-12-06 10:46:06 +01:00
|
|
|
for(let i = bullets.length-1;i>=0;i--)
|
2023-12-06 09:50:34 +01:00
|
|
|
{
|
2023-12-06 10:46:06 +01:00
|
|
|
bullets[i].update(dt);
|
2023-12-08 18:02:42 +01:00
|
|
|
bullets[i].checkCollisions(squares,circles);
|
2023-12-06 10:46:06 +01:00
|
|
|
if(bullets[i].deleted)
|
2023-12-06 09:50:34 +01:00
|
|
|
{
|
2023-12-06 10:46:06 +01:00
|
|
|
bullets.splice(i,1);
|
2023-12-06 09:50:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-09 14:53:07 +01:00
|
|
|
let dt = 1.;
|
2023-11-29 19:03:50 +01:00
|
|
|
let currentTime = new Date();
|
2023-11-15 09:09:13 +01:00
|
|
|
function game() {
|
2023-12-08 18:41:57 +01:00
|
|
|
if(player==null)
|
2023-12-08 18:02:42 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
player.update(squares, circles, dt);
|
|
|
|
for (let i = 0;i<players.length; i++) {
|
|
|
|
players[i].update(squares, circles, dt);
|
2023-11-29 17:25:40 +01:00
|
|
|
}
|
2023-12-09 10:58:00 +01:00
|
|
|
|
2023-12-08 18:02:42 +01:00
|
|
|
cars.forEach((c) => {
|
|
|
|
c.Update();
|
|
|
|
if(c.collide(player.x,player.y))
|
|
|
|
{
|
|
|
|
net.died(player.id,-1);
|
|
|
|
player.x=-50;
|
|
|
|
player.deaths++;
|
|
|
|
player.health=10;
|
2023-11-29 17:25:40 +01:00
|
|
|
}
|
2023-12-08 18:02:42 +01:00
|
|
|
});
|
2023-12-09 14:53:07 +01:00
|
|
|
|
|
|
|
PNJS.forEach((pnj)=>{
|
|
|
|
pnj.update(dt);
|
|
|
|
})
|
|
|
|
|
2023-12-08 18:02:42 +01:00
|
|
|
updateBullets(dt);
|
2023-12-08 18:41:57 +01:00
|
|
|
renderer.ReloadAff();
|
2023-12-08 18:02:42 +01:00
|
|
|
LB.ReloadAff();
|
|
|
|
|
2023-11-29 19:03:50 +01:00
|
|
|
let newTime = new Date();
|
|
|
|
dt=newTime - currentTime;
|
2023-12-06 09:50:34 +01:00
|
|
|
currentTime=newTime;
|
2023-11-19 19:20:02 +01:00
|
|
|
}
|
|
|
|
|
2023-12-08 18:02:42 +01:00
|
|
|
net.connect(); //connect to server, create a player, and retrieve all players info
|
2023-11-29 17:06:30 +01:00
|
|
|
|
|
|
|
|
2023-12-06 09:50:34 +01:00
|
|
|
setInterval(game);
|