diff --git a/js/class.js b/js/class.js index cde3256..b9e0adc 100644 --- a/js/class.js +++ b/js/class.js @@ -47,6 +47,14 @@ class Player } } + changeDirection(newDirection){ + this.dir = newDirection; + if(this.dir!=0){ + this.visibleDir = newDirection; + } + Net.update(this); + } + update(squares,circles)//update position { if(this.dir==0) diff --git a/js/keyboard.js b/js/keyboard.js index a69387b..c6b357c 100644 --- a/js/keyboard.js +++ b/js/keyboard.js @@ -32,10 +32,10 @@ class Keyboard{ }else if(this.keysDown.has('q')){ newDir = 7; } - console.log(newDir) + for (var i = players.length - 1; i >= 0; i--) { if(players[i].id==playerId){ - players[i].dir = newDir; + players[i].changeDirection(newDir); } } } diff --git a/js/network.js b/js/network.js index fe8d646..0254e21 100644 --- a/js/network.js +++ b/js/network.js @@ -17,7 +17,7 @@ class Network{ case 'update': for (var i = players.length - 1; i >= 0; i--) { if(players[i].id==data.data.id){ - players[i]=data.data; + players[i].retrieveServerInfo(data.data.id, data.data.x, data.data.y, data.data.dir); break; } } @@ -40,4 +40,11 @@ class Network{ this.message(JSON.parse(e.data)); }) } + + update(obj){ + this.socket.send(JSON.stringify({ + type: "update", + data: obj + })) + } } \ No newline at end of file