diff --git a/common/player.js b/common/player.js index dd2b016..8e6825b 100644 --- a/common/player.js +++ b/common/player.js @@ -28,7 +28,7 @@ class Player extends Entity { this.isYou = false; this.serverProps = [ - 'type', 'camera', 'pos', 'vel', 'rot', 'dir', 'ticks', 'health', 'you', 'isPlayer', 'headCount', 'isMenu', 'r', 'isYou' + 'type', 'camera', 'pos', 'vel', 'rot', 'dir', 'ticks', 'health', 'you', 'isPlayer', 'headCount', 'isMenu', 'r', 'isYou', 'username' ]; this.legalProps = [ diff --git a/index.js b/index.js index c839fa1..4aea6d5 100644 --- a/index.js +++ b/index.js @@ -66,7 +66,7 @@ app.ws('/', function (ws, req) { console.log(`Player ${player.you} uses username ${x.username} illegally`) return; } - ws.username = j.username; + ws.ent.username = ws.username = j.username; console.log(`Player ${player.you} uses username ${ws.username}`) })() diff --git a/static/js/index.js b/static/js/index.js index 89543e3..cc06d05 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -56,12 +56,22 @@ class Game extends GameBasic { ctx.clearRect(0, 0, cs, cs); + ctx.strokeStyle = "rgb(255,255,255)"; + ctx.lineWidth = "8"; + ctx.textAlign = "center"; + ctx.textBaseline = "bottom"; + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + ctx.font = "bold 16px sans-serif"; + ctx.save(); ctx.translate(player.camera.x + cs / 2, player.camera.y + cs / 2); ctx.drawImage(assetsIn[2], -width / 2, -height / 2, width, height); + let textArgs = []; + for (let ent of entities) { if (ent.health <= 0) continue; @@ -94,20 +104,28 @@ class Game extends GameBasic { if (ent.type != 'Player') continue; - ctx.strokeStyle = "rgb(255,255,255)"; - ctx.lineWidth = "8"; - ctx.textAlign = "center"; - ctx.textBaseline = "bottom"; - ctx.font = "bold 16px sans-serif"; + textArgs = [`HP: ${ent.health} PT: ${ent.headCount}`, ent.pos.x, ent.pos.y - 64 / 2]; - let args = [`HP: ${ent.health} PT: ${ent.headCount} XY: ${Math.round(ent.pos.x)}, ${Math.round(ent.pos.y)}`, ent.pos.x, ent.pos.y - 64 / 2]; + ctx.strokeText(...textArgs); + ctx.fillText(...textArgs); - ctx.strokeText(...args); - ctx.fillText(...args); + ctx.textBaseline = "top"; + textArgs = [`${ent.username || 'Guest'}`, ent.pos.x, ent.pos.y + 64 / 2]; + + ctx.strokeText(...textArgs); + ctx.fillText(...textArgs); } ctx.restore(); + ctx.textAlign = "start"; + ctx.textBaseline = "top"; + ctx.font = "bold 32px sans-serif"; + + textArgs = [`XY: ${-Math.round(player.camera.x)}, ${-Math.round(player.camera.y)}`,25,25]; + ctx.strokeText(...textArgs); + ctx.fillText(...textArgs); + if (player.health <= 0 || player.isMenu) { this.doMenu(); }