better UI

This commit is contained in:
biglyderv 2024-11-25 14:14:21 -05:00
parent c92ec69523
commit 6a0863bd56
3 changed files with 28 additions and 10 deletions

View file

@ -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 = [

View file

@ -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}`)
})()

View file

@ -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();
}