67 lines
No EOL
1.2 KiB
JavaScript
67 lines
No EOL
1.2 KiB
JavaScript
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)];
|
|
|
|
|
|
|
|
|
|
PNJS.push(new PNJ(500, 100));
|
|
PNJS.push(new PNJ(700, 100));
|
|
PNJS.push(new PNJ(500, 600));
|
|
PNJS.push(new PNJ(200, 700));
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
let dt = 1.;
|
|
let currentTime = new Date();
|
|
function game() {
|
|
if(player==null)
|
|
return;
|
|
|
|
player.update(squares, circles, dt);
|
|
for (let i = 0;i<players.length; i++) {
|
|
players[i].update(squares, circles, dt);
|
|
}
|
|
|
|
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;
|
|
}
|
|
});
|
|
|
|
PNJS.forEach((pnj)=>{
|
|
pnj.update(dt);
|
|
})
|
|
|
|
updateBullets(dt);
|
|
renderer.ReloadAff();
|
|
LB.ReloadAff();
|
|
|
|
let newTime = new Date();
|
|
dt=newTime - currentTime;
|
|
currentTime=newTime;
|
|
}
|
|
|
|
net.connect(); //connect to server, create a player, and retrieve all players info
|
|
|
|
|
|
setInterval(game); |