From 634436f8d26cf5c24593a57ddcad43ed706f4fb1 Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Thu, 14 May 2026 10:27:31 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20player=20walk=20clamp=20=E2=80=94=20use?= =?UTF-8?q?=20NPC=20position=20as=20right=20boundary=20so=20player=20can?= =?UTF-8?q?=20always=20reach=20next=20NPC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/game.js b/game.js index ca4413c..ecb42f9 100644 --- a/game.js +++ b/game.js @@ -181,7 +181,6 @@ class Game { if (!world) return; const viewW = world.parentElement.offsetWidth || 420; const viewH = world.parentElement.offsetHeight || 300; - const worldW = world.offsetWidth || viewW * 4; const SPEED = 30; /* px per tick */ let dx = 0, dy = 0, dir = ''; @@ -192,8 +191,10 @@ class Game { if (this._heldKeys.has('down')) { dy = SPEED; dir = 'down'; } if (!dir) return; - /* Clamp world X — can't walk left past origin or right past world edge */ - this.state.worldX = Math.max(0, Math.min(worldW - viewW, this.state.worldX + dx)); + /* Clamp world X — left edge is 0, right edge is npcWorldX + half screen + so the player can always walk far enough to reach the NPC */ + const maxWorldX = this.state.npcWorldX + Math.round(viewW * 0.5); + this.state.worldX = Math.max(0, Math.min(maxWorldX, this.state.worldX + dx)); /* Clamp Y within a narrow vertical band (path area) */ this.state.worldY = Math.max(-30, Math.min(30, this.state.worldY + dy)); this.state.lastDir = dir;