From 7456abf80c72860c660fac8c0874b205ff8712de Mon Sep 17 00:00:00 2001 From: 08draven Date: Wed, 6 Nov 2024 02:56:32 -0500 Subject: [PATCH] some major game changes --- common/player.js | 2 +- game.js | 21 +++++++++++++++++---- static/js/index.js | 10 ++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/common/player.js b/common/player.js index 51ed313..e028e46 100644 --- a/common/player.js +++ b/common/player.js @@ -96,7 +96,7 @@ class Player extends Entity { handleTick(game) { let { entities, width, height } = game; - this.headCount += 1 / 200; + this.headCount += 1 / 40; this.headCount = Math.round(this.headCount * 1000) / 1000; diff --git a/game.js b/game.js index 12ec3dc..673ce55 100644 --- a/game.js +++ b/game.js @@ -9,6 +9,10 @@ import { createHash } from "crypto"; let db = await initDb(); +function sround(n) { + return Math.round(n * 1000) / 1000; +} + class Game extends GameBasic { constructor() { super(); @@ -100,13 +104,22 @@ class Game extends GameBasic { let { entities } = this; let entList = []; for (let entity of entities) { - entity.pos = { x: Math.round(entity.pos.x), y: Math.round(entity.pos.y) }; - entity.vel = { x: Math.round(entity.vel.x), y: Math.round(entity.vel.y) }; - entity.camera = entity.camera ? { x: Math.round(entity.camera.x), y: Math.round(entity.camera.y) } : false; + entity.camera = entity.camera || false; let props = entity.serverProps; let basic = props.map(prop => entity[prop]); - let str = JSON.stringify(basic); + for (let posn in basic) { + let posp = basic[posn]; + if (!posp) continue; + if (posp.x && posp.y) { + posp.x = sround(posp.x); + posp.y = sround(posp.y); + } + if (typeof posp == 'number') { + basic[posn] = sround(posp); + } + } + let str = JSON.stringify(basic,null); entList.push({ entity, str, basic }); } diff --git a/static/js/index.js b/static/js/index.js index bff97e5..e742371 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -131,6 +131,9 @@ class Game extends GameBasic { textArgs = [`XY: ${-Math.round(player.camera.x)}, ${-Math.round(player.camera.y)}`, 25, 25]; ctx.strokeText(...textArgs); ctx.fillText(...textArgs); + textArgs = [`PT: ${Math.round(player.headCount)}`, 25, 75]; + ctx.strokeText(...textArgs); + ctx.fillText(...textArgs); if (player.health <= 0 || player.isMenu) { this.doMenu(); @@ -145,7 +148,10 @@ class Game extends GameBasic { ctx.textAlign = "center"; ctx.textBaseline = "middle"; ctx.font = "bold 48px sans-serif"; - if (player.health <= 0) ctx.fillText('You died! Click to respawn', cs / 2, cs / 2); + if (player.health <= 0) { + ctx.fillText(`You died! Click to respawn\n`, cs / 2, cs / 2); + return; + } if (player.isMenu) { let r = Math.floor(Math.abs(player.rot / 1.2) % emojis.length); ctx.fillText(`Click to react ${emojis[r]}`, cs / 2, cs / 2) @@ -298,7 +304,7 @@ class Game extends GameBasic { let sant = document.querySelector('.lb').innerHTML; - sant = sant.replaceAll(/\[([^\[]+)\]/g,'[$1]'); + sant = sant.replaceAll(/\[([^\[]+)\]/g, '[$1]'); document.querySelector('.lb').innerHTML = sant; }