let cars = [new Car(Renderer, 0, 0, sound), new Car(Renderer, 0, 7, sound), new Car(Renderer, 1, 7, sound), new Car(Renderer, 1, 13, sound), new Car(Renderer, 1, 14, sound), new Car(Renderer, 0, 15, sound)]; let dt = 1; function update() { if(player.y>470 && player.y<480 && player.x>237 && player.x<310) { player.x=2510 player.y=2714 } else if (player.x>2588 && player.x<2687 && player.y>2129 && player.y<2180) { player.x=270 player.y=250 } let playerToUpdate = Net.getPlayersToUpdate(); for (let i = 0;i { console.log("New player: ",p.id); players.push(p); Renderer.AddPlayer(p); }); } function remPlayers() { let playerToRemove = Net.getPlayersToRemove(); for(let i=0;i { bullets.push(b); Renderer.addBullet(b); }); } function updateBullets(dt) { for(let i = bullets.length-1;i>=0;i--) { bullets[i].update(dt); bullets[i].checkCollisions(player,squares,circles,Net); if(bullets[i].deleted) { Renderer.remBullet(bullets[i]); bullets.splice(i,1); } } } function updateKills() { let deaths = Net.getDeathToAdd(); deaths.forEach((object) => { let dead = object.id; let killer = object.killerId; if(player.id==killer) player.kill++; for(let i=0;i { Renderer.AddPlayer(p) }); players.push(new Player(-1,-50,-50,"VOITURE",0,null)); LB.ReloadAff(players, player); } } else { update(); addPlayers(); remPlayers(); addBullets(); updateKills(); player.update(squares, circles, dt); for (var i = players.length - 1; i >= 0; i--) { players[i].update(squares, circles, dt); } Renderer.ReloadAff(); 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; } }); updateBullets(dt); LB.ReloadAff(players, player); } let newTime = new Date(); dt=newTime - currentTime; currentTime=newTime; } Net.connect(); //connect to server, create a player, and retrieve all players info setInterval(game);