diff --git a/js/class.js b/js/class.js index 8e3b846..1ee23d9 100644 --- a/js/class.js +++ b/js/class.js @@ -52,6 +52,7 @@ class Player if(this.dir!=0){ this.visibleDir = newDirection; } + console.log("Should send: {type='update', dir=",this.dir,", x=",this.x,", y=",this.y,"}"); } update(squares,circles)//update position diff --git a/js/game.js b/js/game.js index 93f018b..07e8009 100644 --- a/js/game.js +++ b/js/game.js @@ -29,6 +29,7 @@ function game() { } else { + player.update([],[]); for (var i = players.length - 1; i >= 0; i--) { players[i].update([],[]);//squares, circles } diff --git a/js/input.js b/js/input.js index 7591880..bca7acd 100644 --- a/js/input.js +++ b/js/input.js @@ -2,7 +2,7 @@ class Input { constructor(id) { this.keysDown = new Set() this.dir = 0; - + this.player=null; this.canvas = document.getElementById(id); this.mouseX = 0 @@ -15,7 +15,7 @@ class Input { console.log("Clic de la souris"); }); - window.addEventListener("keydown", function(event) { + /*window.addEventListener("keydown", function(event) { switch(event.key) { case "ArrowUp": console.log("Flèche du haut"); @@ -30,7 +30,7 @@ class Input { console.log("Flèche de droite pressée"); break; } - }); + });*/ window.addEventListener("keydown", (e)=>{ this.keysDown.add(e.key.toLowerCase()) @@ -44,6 +44,8 @@ class Input { } updateDir(){ + if(this.player==null) + return; if(this.keysDown.has('z')){ if(this.keysDown.has('d')){ this.dir = 2; @@ -71,6 +73,7 @@ class Input { }else if(this.keysDown.has('q')){ this.dir = 7; } + this.player.updateDir(this.dir) } get getDirection() { diff --git a/js/network.js b/js/network.js index 15bcead..260a803 100644 --- a/js/network.js +++ b/js/network.js @@ -16,7 +16,7 @@ class Network{ this.playerId = data.data.playerId; for (var i = data.data.players.length - 1; i >= 0; i--) { if(data.data.players[i].id==this.playerId) - this.clientPlayer=data.data.players[i]; + this.clientPlayer=new Player(data.data.players[i].id, data.data.players[i].x, data.data.players[i].y, data.data.players[i].name, data.data.players[i].dir); else this.playersToAdd.push(new Player(data.data.players[i].id, data.data.players[i].x, data.data.players[i].y, data.data.players[i].name, data.data.players[i].dir)) }