Fix missing trees at game start by generating them after npcWorldX is set

This commit is contained in:
Justin Oros
2026-05-20 21:02:42 -07:00
parent 446d56bf38
commit ddf0a9cb08
+2 -4
View File
@@ -1036,9 +1036,7 @@ class Game {
this.show('map'); this.show('map');
this._showController(true); this._showController(true);
/* We need the viewport size — defer a tick so the DOM is laid out */
requestAnimationFrame(() => { requestAnimationFrame(() => {
this._generateTrees();
const world = document.getElementById('map-inner'); const world = document.getElementById('map-inner');
const viewW = world ? world.parentElement.offsetWidth : 420; const viewW = world ? world.parentElement.offsetWidth : 420;
@@ -1048,14 +1046,14 @@ class Game {
this.state.npcWorldX = Math.round(viewW * 3.5); this.state.npcWorldX = Math.round(viewW * 3.5);
this.state.npcWorldY = 0; this.state.npcWorldY = 0;
} else { } else {
/* Always reset camera to 0 each question — keeps trees in view.
NPC spawns off-screen right relative to fresh origin. */
this.state.worldX = 0; this.state.worldX = 0;
this.state.worldY = 0; this.state.worldY = 0;
this.state.npcWorldX = Math.round(viewW * 3.0 + Math.random() * viewW * 0.8); this.state.npcWorldX = Math.round(viewW * 3.0 + Math.random() * viewW * 0.8);
this.state.npcWorldY = 0; this.state.npcWorldY = 0;
} }
this._generateTrees();
document.getElementById('hud-name').textContent = this.state.playerName||'ASH'; document.getElementById('hud-name').textContent = this.state.playerName||'ASH';
this.updateHUD(); this.updateHUD();