commit 5cd1a313cc114847f206db35eb7c5a2c503c42ac
parent ef51f2228ec65e52f4ef824080d9262990310913
Author: Kyle Barlow <kb@kylebarlow.com>
Date: Sat, 2 May 2026 11:29:51 -0700
fire-truck: fix repeated fire spawning, scale flames to fill block
_extinguishFire stayed in firefighting state for 600ms, causing step()
to call it every frame — queuing dozens of delayedCalls, each orphaning
a fireGraphics object in the Phaser scene as frozen sprites. Guard with
early return if fireBuildingCell is already null. Also destroy any
existing fireGraphics in _createFireGraphics before allocating a new one.
Scale flame triangles from fixed pixel values (~3px on screen) to
CELL_SIZE-relative values (~90% of cell height) with 7 overlapping
triangles to fill the building block visually.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat:
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/games/fire-truck/game.js b/games/fire-truck/game.js
@@ -634,6 +634,7 @@ class FireTruckScene extends Phaser.Scene {
}
_createFireGraphics() {
+ if (this.fireGraphics) { this.fireGraphics.destroy(); }
this.fireGraphics = this.add.graphics();
this.fireGraphics.setDepth(10);
this.uiCamera.ignore(this.fireGraphics);
@@ -645,15 +646,17 @@ class FireTruckScene extends Phaser.Scene {
gfx.clear();
const cx = this.fireBuildingCell.x * CELL_SIZE;
const cy = this.fireBuildingCell.y * CELL_SIZE;
+ const baseY = cy + CELL_SIZE * 0.40;
+ const half = CELL_SIZE * 0.22;
const colors = [0xff6600, 0xff2200, 0xffcc00, 0xff8800];
- for (let i = 0; i < 5; i++) {
- const offset = Math.sin(t * 0.003 + i * 1.3) * 10;
- const h = 20 + Math.sin(t * 0.005 + i * 2.1) * 10;
+ for (let i = 0; i < 7; i++) {
+ const offset = Math.sin(t * 0.003 + i * 1.3) * CELL_SIZE * 0.16;
+ const h = CELL_SIZE * 0.70 + Math.sin(t * 0.005 + i * 2.1) * CELL_SIZE * 0.22;
gfx.fillStyle(colors[i % colors.length], 0.7 + Math.sin(t * 0.004 + i) * 0.3);
gfx.fillTriangle(
- cx + offset - 8, cy + 20,
- cx + offset + 8, cy + 20,
- cx + offset, cy + 20 - h
+ cx + offset - half, baseY,
+ cx + offset + half, baseY,
+ cx + offset, baseY - h
);
}
}
@@ -698,6 +701,9 @@ class FireTruckScene extends Phaser.Scene {
}
_extinguishFire() {
+ // Guard against re-entrant calls: step() stays in firefighting state for 600ms
+ // while the delayedCall is pending, so this can fire every frame otherwise.
+ if (!this.fireBuildingCell) return;
this.successOverlay.setAlpha(0.12);
this.successUntil = this.time.now + 200;
this.playSuccessSound();