diff --git a/js/game.js b/js/game.js index 8362430..19754ce 100644 --- a/js/game.js +++ b/js/game.js @@ -2,22 +2,27 @@ Renderer = new Render("canvas", "./assets/map/map7_recadr.png"); let Net = new Network("ws://129.151.227.50:8080/", Renderer); //let ClientKeyboard = new Keyboard() - -let playerId; //id of client player -let players = []; - Inp = new Input("canvas"); -Net.connect(); //connect to server, create a player, and retrieve all players info -//ClientKeyboard.init(); +let playerId; +let players = [] function game() { for (var i = players.length - 1; i >= 0; i--) { players[i].update([],[]); } + //console.log(Inp.calculateAngle(500,500)) Renderer.ReloadAff(); } -setInterval(game); \ No newline at end of file +function Start() { + playerId = Net.getPlayerId(); //id of client player + //Net.getPlayersToAdd.forEach((Player) => players[Player[id]] = Player) + setInterval(game) +} + +Net.onready = Start(); + +Net.connect(); //connect to server, create a player, and retrieve all players info \ No newline at end of file diff --git a/js/network.js b/js/network.js index 0ff980e..620295a 100644 --- a/js/network.js +++ b/js/network.js @@ -37,7 +37,7 @@ class Network{ }) } - get getPlayerId(){ + getPlayerId(){ while(this.playerId==null){ //waiting for connection }; @@ -51,19 +51,19 @@ class Network{ })) } - get getPlayersToAdd(){ + getPlayersToAdd(){ let tmp = this.playersToAdd; this.playersToAdd = []; return tmp; } - get getPlayersToRemove(){ + getPlayersToRemove(){ let tmp = this.playersToRemove; this.playersToRemove = []; return tmp; } - get getPlayersToUpdate(){ + getPlayersToUpdate(){ let tmp = this.playersToUpdate; this.playersToUpdate = []; return tmp;