diff --git a/common/player.js b/common/player.js index ff0b38b..1722f4f 100644 --- a/common/player.js +++ b/common/player.js @@ -27,8 +27,10 @@ class Player { this.r = 1; + this.isYou = false; + this.serverProps = [ - 'type', 'camera','pos','vel','rot','dir','ticks','health','you','isPlayer','headCount','isMenu','r' + 'type', 'camera','pos','vel','rot','dir','ticks','health','you','isPlayer','headCount','isMenu','r','isYou' ]; this.legalProps = [ diff --git a/game.js b/game.js index 979367e..296545a 100644 --- a/game.js +++ b/game.js @@ -21,6 +21,7 @@ class Game extends GameBasic { if (!client.active) continue; let wsEnt = client.ent; + wsEnt.isYou = true; if (!wsEnt) continue; let filtered; @@ -40,6 +41,8 @@ class Game extends GameBasic { }); client.send(JSON.stringify(filtered)); + + wsEnt.isYou = false; } for (let entity of entities) { diff --git a/static/js/index.js b/static/js/index.js index e47480c..00b11eb 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -126,8 +126,6 @@ class Game extends GameBasic { this.ws.close(); this.ws = new WebSocket(origin); this.ws.addEventListener('message', function (e) { that.recv(e) }); - this.player = new Player(false, true); - this.entities.push(this.player); } else if (player.isMenu) { player.r = Math.floor(Math.abs(player.rot / 1.2) % emojis.length); player.isMenu = false; @@ -180,7 +178,10 @@ class Game extends GameBasic { let matchingPlayer = entList.filter(x => x.you == you) - if (matchingPlayer.length == 0) matchingPlayer = entList.filter(x => x.type == 'Player'); + + if (matchingPlayer.length == 0) { + matchingPlayer = entList.filter(x => x.isYou); + } this.player = Object.assign(this.player || new Player(false, false), matchingPlayer[0]);