function CookiePseudo() { nom = "pseudo="; var liste = document. cookie. split (';'); for (var i = 0; i < liste.length; i++) { var c = liste[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nom) == 0) return c.substring(nom.length, c.length); } return null; } Renderer = new Render("canvas", "./assets/map/map7_recadr.png"); LB = new LeaderBoard("canvas"); cars = [new Car(Renderer, 220, 75),new Car(Renderer, 500, 75),new Car(Renderer, 900,75),new Car(Renderer, 228,587),new Car(Renderer, 947,587)] let Net = new Network("ws://129.151.227.50:8080?name="+CookiePseudo(), Renderer); let playerId = null; //id of client player let players = []; let bullets = []; let player = null; Inp = new Input("canvas", Net,Renderer); playerId=Net.playerId; player=Net.clientPlayer; players=Net.getPlayersToAdd(); let dt = 1; function update() { 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); } } } let currentTime = new Date(); function game() { if(playerId==null) { if (Net.playerId!=null) { playerId=Net.playerId; player=Net.clientPlayer; players=Net.getPlayersToAdd(); Renderer.AddPlayer(player) Renderer.SetPlayerId(player.id) console.log("Connected as id ",playerId); Inp.player=player; Inp.bullets=bullets; players.forEach((p) => { Renderer.AddPlayer(p) }); LB.ReloadAff(players, player); } } else { update(); addPlayers(); remPlayers(); addBullets(); 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(); }) 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);