Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(arcade): give every cabinet game its own look, layout and scoring (#994)
Ruben Lütke3f78c5134c10
diff --git a/dodaios/ui/web/frontend/src/components/society/arcade/arcadeGames.ts b/dodaios/ui/web/frontend/src/components/society/arcade/arcadeGames.tsindex 7018c2bf3e..4cb8e8e57d 100644--- a/dodaios/ui/web/frontend/src/components/society/arcade/arcadeGames.ts+++ b/dodaios/ui/web/frontend/src/components/society/arcade/arcadeGames.ts@@ -52,17 +52,17 @@ export const ARCADE_GAMES: readonly ArcadeGameInfo[] = [{ id: "paddle-duel", title: "Paddle Duel", key: "paddle_duel", kind: "retro",look: { body: "#e8e4d8", trim: "#2a2a2e", marquee: "#151518", marqueeText: "#f5f5f0", accent: "#9aa3ff" } },{ id: "block-drop", title: "Block Drop", key: "block_drop", kind: "retro",- look: { body: "#14224a", trim: "#0a1126", marquee: "#0b1433", marqueeText: "#7cc4ff", accent: "#3fa2ff" } },+ look: { body: "#1f1d1a", trim: "#0e0d0c", marquee: "#121110", marqueeText: "#e9b949", accent: "#c9973a" } },{ id: "maze-muncher", title: "Maze Muncher", key: "maze_muncher", kind: "retro",- look: { body: "#2b1f05", trim: "#120d02", marquee: "#100c02", marqueeText: "#ffd23f", accent: "#ffb800" } },+ look: { body: "#1a1430", trim: "#0c0a18", marquee: "#0e0b1c", marqueeText: "#5ef2c2", accent: "#8f6bff" } },{ id: "desert-dash", title: "Desert Dash", key: "desert_dash", kind: "retro",look: { body: "#5a3416", trim: "#2a180a", marquee: "#2b1607", marqueeText: "#ffb36b", accent: "#ff8a3d" } },{ id: "pixel-raiders", title: "Pixel Raiders", key: "pixel_raiders", kind: "retro",look: { body: "#1a1035", trim: "#0c0719", marquee: "#0d0820", marqueeText: "#c58bff", accent: "#a855f7" } },{ id: "road-hopper", title: "Road Hopper", key: "road_hopper", kind: "retro",- look: { body: "#123a2e", trim: "#081a14", marquee: "#071b14", marqueeText: "#b6f36b", accent: "#7ed957" } },+ look: { body: "#14262a", trim: "#0a1416", marquee: "#0a1618", marqueeText: "#f0c25e", accent: "#2fd3c4" } },{ id: "city-defense", title: "City Defense", key: "city_defense", kind: "retro",- look: { body: "#3b0d0d", trim: "#1a0505", marquee: "#1c0404", marqueeText: "#ffcf5a", accent: "#ff4b2b" } },+ look: { body: "#1b1636", trim: "#0c0a1a", marquee: "#0d0b1e", marqueeText: "#e9b949", accent: "#6be3d6" } },];const BY_ID = new Map<string, ArcadeGameInfo>(ARCADE_GAMES.map((g) => [g.id, g]));diff --git a/dodaios/ui/web/frontend/src/components/society/arcade/games/blockDrop.test.ts b/dodaios/ui/web/frontend/src/components/society/arcade/games/blockDrop.test.tsindex 9390f0f2a4..dcc9eea1a1 100644--- a/dodaios/ui/web/frontend/src/components/society/arcade/games/blockDrop.test.ts+++ b/dodaios/ui/web/frontend/src/components/society/arcade/games/blockDrop.test.ts@@ -1,7 +1,7 @@import { describe, expect, it } from "vitest";import { RETRO_STEP, idleInput, seededRandom, type RetroInput } from "../retroGame";import blockDrop, {- ARR, CLEAR_TIME, COLS, DAS, HIDDEN, LINE_SCORES, LOCK_DELAY, MAX_LOCK_RESETS, PIECE_COUNT, PIECE_I, PIECE_O, PIECE_T, ROWS, SHAPES,+ ARR, CLEAR_TIME, COLS, DAS, HIDDEN, LINES_PER_LEVEL, LINE_SCORES, LOCK_DELAY, MAX_LOCK_RESETS, PIECE_COUNT, PIECE_I, PIECE_O, PIECE_T, ROWS, SHAPES,createBlockDrop, fits, gravityInterval, spawnPiece, tryRotate, type BlockDropState,} from "./blockDrop";@@ -61,6 +61,17 @@ describe("block drop", () => {expect(blockDrop.width).toBeGreaterThan(0);});+ it("has its own wide well, scoring table and level pace", () => {+ expect([COLS, ROWS - HIDDEN]).toEqual([12, 22]);+ expect(LINE_SCORES).toEqual([0, 50, 150, 350, 1000]);+ expect(LINES_PER_LEVEL).toBe(12);+ // New pieces appear centred in the wider well.+ const s = blockDrop.create(seededRandom(7));+ const xs = cellsOf(s).map(([x]) => x);+ expect(Math.min(...xs) + Math.max(...xs)).toBeGreaterThanOrEqual(COLS - 2);+ expect(Math.min(...xs) + Math.max(...xs)).toBeLessThanOrEqual(COLS);+ });+it("deals every one of the seven pieces once per bag", () => {const random = seededRandom(42);const s = createBlockDrop(random);diff --git a/dodaios/ui/web/frontend/src/components/society/arcade/games/blockDrop.ts b/dodaios/ui/web/frontend/src/components/society/arcade/games/blockDrop.tsindex e78f0926a0..33814e73e9 100644--- a/dodaios/ui/web/frontend/src/components/society/arcade/games/blockDrop.ts+++ b/dodaios/ui/web/frontend/src/components/society/arcade/games/blockDrop.ts@@ -1,35 +1,41 @@/*** "Block Drop": the falling-block puzzle cabinet.*- * Seven four-cell pieces fall into a 10 × 20 well (plus two hidden rows on- * top where pieces appear). Pieces come from a 7-bag, so every seven in a row- * hold each shape once and droughts cannot happen. Left / right shift once on+ * Seven four-cell pieces fall into a wide 12 × 22 well (plus two hidden rows+ * on top where pieces appear). Pieces come from a shuffled bag, so every seven+ * in a row hold each shape once and droughts cannot happen. Left / right shift once on* press and then auto-repeat after a short delay (DAS / ARR), `up` or `a`* rotates clockwise with a few simple wall kicks, `down` soft-drops and `b`- * hard-drops. A grounded piece locks after half a second; moving or rotating+ * hard-drops. A grounded piece locks after a short delay; moving or rotating* it buys time, but only a limited number of times, so it cannot stall* forever. Full rows clear after a short animation and score by how many went- * at once, times the level; every ten lines the level and the gravity rise.+ * at once, times the level; every twelve lines the level and the gravity rise.+ *+ * The look is the cabinet's own: every piece is cast in the same brass on a+ * charcoal well, told apart by its shade and an engraved mark, and the drop+ * hint is a faint beam down each column the piece covers.*/import { type RetroDrawInfo, type RetroGame, type RetroInput, type RetroStatus } from "../retroGame";import { drawDigits, drawSparks, emitSpark, sparkPool, stepSparks, type Spark } from "./games2Kit";-export const COLS = 10;-/** 20 visible rows plus 2 hidden ones on top where pieces spawn. */-export const ROWS = 22;+export const COLS = 12;+/** 22 visible rows plus 2 hidden ones on top where pieces spawn. */+export const ROWS = 24;export const HIDDEN = 2;/** Delayed auto shift: hold this long before a held direction starts repeating... */export const DAS = 0.17;/** ...then move one column this often. */export const ARR = 0.05;-export const LOCK_DELAY = 0.5;+export const LOCK_DELAY = 0.45;/** How often moving or rotating a grounded piece may restart its lock timer. */-export const MAX_LOCK_RESETS = 15;+export const MAX_LOCK_RESETS = 12;export const CLEAR_TIME = 0.3;const SOFT_DROP_INTERVAL = 0.035;/** Points for 1, 2, 3 or 4 lines at once, times the level. */-export const LINE_SCORES: readonly number[] = [0, 100, 300, 500, 800];+export const LINE_SCORES: readonly number[] = [0, 50, 150, 350, 1000];+/** Lines per level. */+export const LINES_PER_LEVEL = 12;/** Piece kinds, in this order: I O T S Z J L. Cells store kind + 1 (0 is empty). */export const PIECE_I = 0, PIECE_O = 1, PIECE_T = 2, PIECE_S = 3, PIECE_Z = 4, PIECE_J = 5, PIECE_L = 6;@@ -106,20 +112,26 @@ export interface BlockDropState {levelGlow: number;}-export const WIDTH = 200;+export const WIDTH = 208;export const HEIGHT = 236;-const CELL = 11;+const CELL = 10;const WELL_X = 8;const WELL_Y = 8;-const PANEL_X = 128;+const PANEL_X = 136;const PANEL_W = 64;-const COLORS = ["#4fd8ff", "#ffd84a", "#b06bff", "#5dea6a", "#ff5a6e", "#4a7dff", "#ff9a3d"];-const STACK_GREY = "#5b6177";+/** One brass family: each kind is a shade of it, never a hue of its own. */+const COLORS = ["#e9b949", "#b9862f", "#f4d27f", "#9a7432", "#d39c3a", "#7f6334", "#f0c25e"];+/** The engraved mark per kind, so shapes read apart without colour (see drawCell). */+const MARKS = [1, 0, 2, 3, 4, 5, 6];+const STACK_GREY = "#4a4740";+const GOLD = "#e9b949";+const CHARCOAL = "#141416";+/** Seconds per row of fall: a gentle geometric speed-up per level, with a floor. */export function gravityInterval(level: number): number {const l = Math.min(20, Math.max(1, level));- return Math.pow(0.8 - (l - 1) * 0.007, l - 1);+ return Math.max(0.04, 0.85 * Math.pow(0.84, l - 1));}export function fits(s: BlockDropState, kind: number, rot: number, x: number, y: number): boolean {@@ -151,7 +163,7 @@ export function spawnPiece(s: BlockDropState, random: () => number): void {refill(s, random);s.piece = kind;s.rot = 0;- s.px = kind === PIECE_O ? 4 : 3;+ s.px = kind === PIECE_O ? 5 : 4;s.py = 1;s.gravityTimer = 0;s.lockTimer = 0;@@ -216,7 +228,7 @@ export function tryRotate(s: BlockDropState): boolean {return false;}-/** How many rows the current piece can still fall (also places the ghost). */+/** How many rows the current piece can still fall (also sizes the drop beams). */export function dropDistance(s: BlockDropState): number {let d = 0;while (fits(s, s.piece, s.rot, s.px, s.py + d + 1)) d += 1;@@ -245,7 +257,7 @@ function lockPiece(s: BlockDropState, random: () => number): void {const points = LINE_SCORES[n] * s.level;s.score += points;s.lines += n;- const level = Math.max(s.level, 1 + Math.floor(s.lines / 10));+ const level = Math.max(s.level, 1 + Math.floor(s.lines / LINES_PER_LEVEL));if (level > s.level) s.levelGlow = 1;s.level = level;s.clearing = CLEAR_TIME;@@ -257,7 +269,7 @@ function lockPiece(s: BlockDropState, random: () => number): void {for (let i = 0; i < 12; i += 1) {const px = WELL_X + random() * COLS * CELL;emitSpark(s.sparks, px, py, (random() - 0.5) * 90, -30 - random() * 90, 0.4 + random() * 0.4, n === 4 ? 3 : 2,- n === 4 ? COLORS[Math.floor(random() * PIECE_COUNT)] : "#ffffff");+ n === 4 ? COLORS[Math.floor(random() * PIECE_COUNT)] : "#fff4d6");}}}@@ -341,18 +353,36 @@ export function stepBlockDrop(s: BlockDropState, input: RetroInput, dt: number,// ---------------------------------------------------------------- drawing-function drawCell(ctx: CanvasRenderingContext2D, x: number, y: number, size: number, color: string): void {+/**+ * One brass cell: a bevelled tile with a darker inset face and, at full size,+ * the kind's engraved mark (0 plain, 1 bar, 2 dot, 3 slash, 4 back-slash, 5 ring, 6 post).+ */+function drawCell(ctx: CanvasRenderingContext2D, x: number, y: number, size: number, color: string, mark = 0): void {ctx.fillStyle = color;ctx.fillRect(x, y, size, size);- ctx.fillStyle = "rgba(255,255,255,0.38)";+ ctx.fillStyle = "rgba(255,246,220,0.45)";ctx.fillRect(x, y, size, 1);ctx.fillRect(x, y, 1, size);- ctx.fillStyle = "rgba(0,0,0,0.35)";+ ctx.fillStyle = "rgba(20,14,4,0.45)";ctx.fillRect(x, y + size - 1, size, 1);ctx.fillRect(x + size - 1, y, 1, size);- if (size >= 8) {- ctx.fillStyle = "rgba(255,255,255,0.55)";- ctx.fillRect(x + 2, y + 2, 2, 2);+ if (size < 7) return;+ ctx.fillStyle = "rgba(20,14,4,0.16)";+ ctx.fillRect(x + 2, y + 2, size - 4, size - 4);+ ctx.fillStyle = "rgba(20,14,4,0.55)";+ const c = Math.floor(size / 2), m = size - 3;+ switch (mark) {+ case 1: ctx.fillRect(x + 2, y + c, size - 4, 1); break;+ case 2: ctx.fillRect(x + c - 1, y + c - 1, 2, 2); break;+ case 3: for (let i = 2; i <= m; i += 1) ctx.fillRect(x + m + 2 - i, y + i, 1, 1); break;+ case 4: for (let i = 2; i <= m; i += 1) ctx.fillRect(x + i, y + i, 1, 1); break;+ case 5:+ ctx.strokeStyle = "rgba(20,14,4,0.55)";+ ctx.lineWidth = 1;+ ctx.strokeRect(x + 2.5, y + 2.5, size - 5, size - 5);+ break;+ case 6: ctx.fillRect(x + c, y + 2, 1, size - 4); break;+ default: break;}}@@ -367,38 +397,48 @@ function drawPreview(ctx: CanvasRenderingContext2D, kind: number, cx: number, cyconst ox = Math.round(cx - ((maxX - minX + 1) * size) / 2);const oy = Math.round(cy - ((maxY - minY + 1) * size) / 2);for (let i = 0; i < 4; i += 1) {- drawCell(ctx, ox + (shape[i * 2] - minX) * size, oy + (shape[i * 2 + 1] - minY) * size, size - 1, COLORS[kind]);+ drawCell(ctx, ox + (shape[i * 2] - minX) * size, oy + (shape[i * 2 + 1] - minY) * size, size - 1, COLORS[kind], MARKS[kind]);}}function panelBox(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number): void {- ctx.fillStyle = "#0b1433";+ ctx.fillStyle = "#1b1a1d";ctx.fillRect(x, y, w, h);- ctx.strokeStyle = "#2a4a8f";+ ctx.strokeStyle = "rgba(233,185,73,0.45)";ctx.lineWidth = 1;ctx.strokeRect(x + 0.5, y + 0.5, w - 1, h - 1);}/** A decorative half-built stack for the title screen (letters are piece kinds). */const ATTRACT_ROWS = [- "J.........",- "JJJ....LOO",- "ZZTT.LLLOO",- "SZZT.ITTTS",- "SSZT.IJTSS",- "OOTT.IJJJS",+ "J...........",+ "JJJ......LOO",+ "ZZTTO.LLLLOO",+ "SZZTO.ITTTSL",+ "SSZTT.IJTSSL",+ "OOTTT.IJJJSL",];const KIND_OF: Record<string, number> = { I: 0, O: 1, T: 2, S: 3, Z: 4, J: 5, L: 6 };+/** A faint vertical beam one cell wide, with a bright foot where the cell will come to rest. */+function drawBeam(ctx: CanvasRenderingContext2D, x: number, top: number, bottom: number): void {+ const h = bottom - top;+ if (h <= 0) return;+ ctx.fillStyle = "rgba(233,185,73,0.13)";+ ctx.fillRect(x + 2, top, CELL - 5, h);+ ctx.fillStyle = "rgba(233,185,73,0.7)";+ ctx.fillRect(x + 2, bottom - 2, CELL - 5, 1);+}+function drawWell(ctx: CanvasRenderingContext2D, s: BlockDropState, info: RetroDrawInfo): void {const wellW = COLS * CELL, wellH = (ROWS - HIDDEN) * CELL;- ctx.fillStyle = "#070c1f";+ ctx.fillStyle = CHARCOAL;ctx.fillRect(WELL_X, WELL_Y, wellW, wellH);- ctx.fillStyle = "rgba(124,196,255,0.06)";- for (let x = 1; x < COLS; x += 1) ctx.fillRect(WELL_X + x * CELL, WELL_Y, 1, wellH);- for (let y = 1; y < ROWS - HIDDEN; y += 1) ctx.fillRect(WELL_X, WELL_Y + y * CELL, wellW, 1);+ // Only the grid's crossings are marked, as tiny dots.+ ctx.fillStyle = "rgba(233,185,73,0.14)";+ for (let x = 1; x < COLS; x += 1) for (let y = 1; y < ROWS - HIDDEN; y += 1) ctx.fillRect(WELL_X + x * CELL - 1, WELL_Y + y * CELL - 1, 1, 1);// The frame glows up for a moment on a level-up, fading smoothly (no blinking).- ctx.strokeStyle = s.levelGlow > 0 ? `rgba(124,196,255,${0.45 + s.levelGlow * 0.55})` : "rgba(63,162,255,0.45)";+ ctx.strokeStyle = s.levelGlow > 0 ? `rgba(244,210,127,${0.5 + s.levelGlow * 0.5})` : "rgba(233,185,73,0.5)";ctx.lineWidth = s.levelGlow > 0 ? 2 : 1;ctx.strokeRect(WELL_X - 1.5, WELL_Y - 1.5, wellW + 3, wellH + 3);@@ -409,14 +449,14 @@ function drawWell(ctx: CanvasRenderingContext2D, s: BlockDropState, info: RetroDfor (let x = 0; x < COLS; x += 1) {const ch = ATTRACT_ROWS[r][x];if (ch === ".") continue;- drawCell(ctx, WELL_X + x * CELL, WELL_Y + (top + r - HIDDEN) * CELL, CELL - 1, COLORS[KIND_OF[ch]]);+ const kind = KIND_OF[ch];+ drawCell(ctx, WELL_X + x * CELL, WELL_Y + (top + r - HIDDEN) * CELL, CELL - 1, COLORS[kind], MARKS[kind]);}}- // An upright I hovering over the gap it is about to fill.+ // An upright I hovering over the gap it is about to fill, its drop beam below it.const bob = info.reduced ? 0 : Math.round(Math.sin(info.time * 2) * 3);- for (let i = 0; i < 4; i += 1) drawCell(ctx, WELL_X + 4 * CELL, WELL_Y + (7 + i) * CELL + bob, CELL - 1, COLORS[PIECE_I]);- ctx.strokeStyle = "rgba(79,216,255,0.35)";- for (let i = 0; i < 4; i += 1) ctx.strokeRect(WELL_X + 4 * CELL + 0.5, WELL_Y + (top + 2 + i - HIDDEN) * CELL + 0.5, CELL - 2, CELL - 2);+ for (let i = 0; i < 4; i += 1) drawCell(ctx, WELL_X + 5 * CELL, WELL_Y + (7 + i) * CELL + bob, CELL - 1, COLORS[PIECE_I], MARKS[PIECE_I]);+ drawBeam(ctx, WELL_X + 5 * CELL, WELL_Y + 11 * CELL + bob, WELL_Y + (ROWS - HIDDEN) * CELL);return;}@@ -431,48 +471,51 @@ function drawWell(ctx: CanvasRenderingContext2D, s: BlockDropState, info: RetroDif (info.reduced) {// Reduced motion: the row simply fades away.ctx.globalAlpha = 1 - p;- drawCell(ctx, px, py, CELL - 1, COLORS[v - 1]);+ drawCell(ctx, px, py, CELL - 1, COLORS[v - 1], MARKS[v - 1]);ctx.globalAlpha = 1;} else {// Squeeze into a white line that wipes out from the middle.const h = Math.max(1, Math.round((CELL - 1) * (1 - p)));const reach = p * (COLS / 2 + 1);- ctx.fillStyle = Math.abs(x + 0.5 - COLS / 2) < reach ? "#ffffff" : COLORS[v - 1];+ ctx.fillStyle = Math.abs(x + 0.5 - COLS / 2) < reach ? "#fff4d6" : COLORS[v - 1];ctx.fillRect(px, py + Math.round((CELL - 1 - h) / 2), CELL - 1, h);}continue;}- drawCell(ctx, px, py, CELL - 1, s.over ? STACK_GREY : COLORS[v - 1]);+ drawCell(ctx, px, py, CELL - 1, s.over ? STACK_GREY : COLORS[v - 1], MARKS[v - 1]);}}if (s.active && !s.over) {const shape = SHAPES[s.piece][s.rot];- const ghost = s.py + dropDistance(s);- ctx.strokeStyle = COLORS[s.piece];- ctx.globalAlpha = 0.45;- ctx.lineWidth = 1;- for (let i = 0; i < 4; i += 1) {- const gy = ghost + shape[i * 2 + 1];- if (gy < HIDDEN) continue;- ctx.strokeRect(WELL_X + (s.px + shape[i * 2]) * CELL + 0.5, WELL_Y + (gy - HIDDEN) * CELL + 0.5, CELL - 2, CELL - 2);+ // Drop hint: a faint beam under each column the piece covers, from its lowest cell+ // there down to where that cell will come to rest; the piece itself is never outlined.+ const d = dropDistance(s);+ if (d > 0) {+ for (let i = 0; i < 4; i += 1) {+ const cx = shape[i * 2], cy = shape[i * 2 + 1];+ let lowest = true;+ for (let j = 0; j < 4; j += 1) if (shape[j * 2] === cx && shape[j * 2 + 1] > cy) lowest = false;+ if (!lowest) continue;+ const from = Math.max(HIDDEN, s.py + cy + 1), to = s.py + cy + d + 1;+ if (to > from) drawBeam(ctx, WELL_X + (s.px + cx) * CELL, WELL_Y + (from - HIDDEN) * CELL, WELL_Y + (to - HIDDEN) * CELL);+ }}- ctx.globalAlpha = 1;// A piece about to lock dims a little, so the lock delay can be read.const settle = grounded(s) ? Math.min(1, s.lockTimer / LOCK_DELAY) : 0;for (let i = 0; i < 4; i += 1) {const cy = s.py + shape[i * 2 + 1];if (cy < HIDDEN) continue;- drawCell(ctx, WELL_X + (s.px + shape[i * 2]) * CELL, WELL_Y + (cy - HIDDEN) * CELL, CELL - 1, COLORS[s.piece]);+ drawCell(ctx, WELL_X + (s.px + shape[i * 2]) * CELL, WELL_Y + (cy - HIDDEN) * CELL, CELL - 1, COLORS[s.piece], MARKS[s.piece]);if (settle > 0) {- ctx.fillStyle = `rgba(7,12,31,${settle * 0.35})`;+ ctx.fillStyle = `rgba(20,20,22,${settle * 0.4})`;ctx.fillRect(WELL_X + (s.px + shape[i * 2]) * CELL, WELL_Y + (cy - HIDDEN) * CELL, CELL - 1, CELL - 1);}}}if (s.over) {- ctx.fillStyle = "rgba(7,12,31,0.45)";+ ctx.fillStyle = "rgba(20,20,22,0.45)";ctx.fillRect(WELL_X, WELL_Y, wellW, wellH);}}@@ -481,7 +524,7 @@ function drawPanel(ctx: CanvasRenderingContext2D, s: BlockDropState, info: Retroconst attract = info.idle && s.ticks === 0;panelBox(ctx, PANEL_X, WELL_Y, PANEL_W, 46);// A small down-arrow marks the "next" box without words.- ctx.fillStyle = "#7cc4ff";+ ctx.fillStyle = GOLD;ctx.beginPath();ctx.moveTo(PANEL_X + 4, WELL_Y + 4); ctx.lineTo(PANEL_X + 10, WELL_Y + 4); ctx.lineTo(PANEL_X + 7, WELL_Y + 8);ctx.closePath();@@ -493,37 +536,37 @@ function drawPanel(ctx: CanvasRenderingContext2D, s: BlockDropState, info: RetrodrawPreview(ctx, attract ? PIECE_S : s.queue[2], PANEL_X + 48.5, WELL_Y + 65, 6);panelBox(ctx, PANEL_X, WELL_Y + 88, PANEL_W, 26);- drawDigits(ctx, s.score, PANEL_X + PANEL_W - 5, WELL_Y + 94, 14, "#ffffff", "right", 600);+ drawDigits(ctx, s.score, PANEL_X + PANEL_W - 5, WELL_Y + 94, 14, "#fff4d6", "right", 600);// Level: a double chevron; lines: three stacked bars.panelBox(ctx, PANEL_X, WELL_Y + 120, PANEL_W, 20);- ctx.strokeStyle = "#ffd84a";+ ctx.strokeStyle = GOLD;ctx.lineWidth = 2;ctx.beginPath();ctx.moveTo(PANEL_X + 5, WELL_Y + 131); ctx.lineTo(PANEL_X + 9, WELL_Y + 127); ctx.lineTo(PANEL_X + 13, WELL_Y + 131);ctx.moveTo(PANEL_X + 5, WELL_Y + 135); ctx.lineTo(PANEL_X + 9, WELL_Y + 131); ctx.lineTo(PANEL_X + 13, WELL_Y + 135);ctx.stroke();- drawDigits(ctx, s.level, PANEL_X + PANEL_W - 5, WELL_Y + 124, 12, "#ffd84a", "right");+ drawDigits(ctx, s.level, PANEL_X + PANEL_W - 5, WELL_Y + 124, 12, GOLD, "right");panelBox(ctx, PANEL_X, WELL_Y + 144, PANEL_W, 20);- ctx.fillStyle = "#5dea6a";+ ctx.fillStyle = "#c9c2b0";for (let i = 0; i < 3; i += 1) ctx.fillRect(PANEL_X + 5, WELL_Y + 149 + i * 4, 9, 2);- drawDigits(ctx, s.lines, PANEL_X + PANEL_W - 5, WELL_Y + 148, 12, "#5dea6a", "right");+ drawDigits(ctx, s.lines, PANEL_X + PANEL_W - 5, WELL_Y + 148, 12, "#c9c2b0", "right");// Progress to the next level as a thin bar.panelBox(ctx, PANEL_X, WELL_Y + 170, PANEL_W, 8);- ctx.fillStyle = "#3fa2ff";- ctx.fillRect(PANEL_X + 2, WELL_Y + 172, Math.round((PANEL_W - 4) * ((s.lines % 10) / 10)), 4);+ ctx.fillStyle = GOLD;+ ctx.fillRect(PANEL_X + 2, WELL_Y + 172, Math.round((PANEL_W - 4) * ((s.lines % LINES_PER_LEVEL) / LINES_PER_LEVEL)), 4);// A little decorative tower of cells at the bottom of the panel.for (let i = 0; i < 4; i += 1) {- drawCell(ctx, PANEL_X + 8 + i * 13, WELL_Y + 200, 11, COLORS[(i + 2) % PIECE_COUNT]);- if (i % 2 === 0) drawCell(ctx, PANEL_X + 8 + i * 13, WELL_Y + 188, 11, COLORS[(i + 5) % PIECE_COUNT]);+ drawCell(ctx, PANEL_X + 8 + i * 13, WELL_Y + 200, 11, COLORS[(i + 2) % PIECE_COUNT], MARKS[(i + 2) % PIECE_COUNT]);+ if (i % 2 === 0) drawCell(ctx, PANEL_X + 8 + i * 13, WELL_Y + 188, 11, COLORS[(i + 5) % PIECE_COUNT], MARKS[(i + 5) % PIECE_COUNT]);}}export function drawBlockDrop(ctx: CanvasRenderingContext2D, s: BlockDropState, info: RetroDrawInfo): void {- ctx.fillStyle = "#050916";+ ctx.fillStyle = "#0c0c0e";ctx.fillRect(0, 0, WIDTH, HEIGHT);ctx.save();if (!info.reduced && s.kick > 0) ctx.translate(0, Math.round((s.kick / 0.12) * 2));@@ -532,7 +575,7 @@ export function drawBlockDrop(ctx: CanvasRenderingContext2D, s: BlockDropState,if (s.popupTime > 0 && s.popupValue > 0 && !s.over) {const rise = info.reduced ? 0 : (1.1 - s.popupTime) * 14;ctx.globalAlpha = Math.min(1, s.popupTime * 2);- drawDigits(ctx, `+${s.popupValue}`, WELL_X + (COLS * CELL) / 2, WELL_Y + (s.popupRow - HIDDEN) * CELL - 10 - rise, 12, "#ffffff", "center", 600);+ drawDigits(ctx, `+${s.popupValue}`, WELL_X + (COLS * CELL) / 2, WELL_Y + (s.popupRow - HIDDEN) * CELL - 10 - rise, 12, "#fff4d6", "center", 600);ctx.globalAlpha = 1;}ctx.restore();diff --git a/dodaios/ui/web/frontend/src/components/society/arcade/games/cityDefense.test.ts b/dodaios/ui/web/frontend/src/components/society/arcade/games/cityDefense.test.tsindex a9d0bf952c..dc4b393119 100644--- a/dodaios/ui/web/frontend/src/components/society/arcade/games/cityDefense.test.ts+++ b/dodaios/ui/web/frontend/src/components/society/arcade/games/cityDefense.test.ts@@ -1,8 +1,9 @@import { describe, expect, it } from "vitest";import { idleInput, RETRO_STEP, seededRandom, type RetroInput } from "../retroGame";import game, {- AMMO, BATTERY_X, BATTERY_Y, BLAST_R, BLAST_S, CITY_X, GROUND_Y, WIDTH,- addWarhead, blastRadius, citiesStanding, firingBattery, multiplier, type DefenseState,+ BOLT_R, COOL_RATE, DOME_BONUS, DOME_X, FULL_COLONY_BONUS, GROUND_Y, HEAT_BOLT, HEAT_PULSE, PULSE_R, RING_S, SEEDER_POINTS,+ SHARD_POINTS, SPARE_DOME_EVERY, TOWER_X, TOWER_Y, WIDTH,+ addShard, canFire, domesStanding, multiplier, ringRadius, type DefenseState,} from "./cityDefense";const rnd = seededRandom(17);@@ -13,10 +14,10 @@ const run = (s: DefenseState, input: RetroInput, seconds: number) => {const quiet = (): DefenseState => {const s = game.create(seededRandom(4));run(s, idleInput(), 2);- for (const w of s.warheads) w.active = false;+ for (const w of s.shards) w.active = false;s.toLaunch = 5;s.salvoTimer = 999;- s.flyerTimer = 999;+ s.seederTimer = 999;return s;};const pressA = (): RetroInput => {@@ -32,8 +33,8 @@ const pressB = (): RetroInput => {return input;};const click = (x: number, y: number): RetroInput => ({ ...idleInput(), pointer: { x, y, down: true, clicked: true } });-const activeMissiles = (s: DefenseState) => s.missiles.filter((m) => m.active);-const activeWarheads = (s: DefenseState) => s.warheads.filter((w) => w.active).length;+const activeBolts = (s: DefenseState) => s.bolts.filter((m) => m.active);+const activeShards = (s: DefenseState) => s.shards.filter((w) => w.active).length;function fakeContext(): { ctx: CanvasRenderingContext2D; depth: () => number; rects: () => number } {let depth = 0, rects = 0;@@ -57,22 +58,23 @@ function fakeContext(): { ctx: CanvasRenderingContext2D; depth: () => number; re}describe("city defense", () => {- it("starts with six cities, three full batteries and a short pause", () => {+ it("starts with four domes, a cold tower and a short pause", () => {const s = game.create(seededRandom(1));expect(game.pointer).toBe(true);- expect(game.status(s)).toEqual({ score: 0, lives: 6, level: 1, over: false });- expect(s.batteries.map((b) => b.ammo)).toEqual([AMMO, AMMO, AMMO]);+ expect(DOME_X).toHaveLength(4);+ expect(game.status(s)).toEqual({ score: 0, lives: 4, level: 1, over: false });+ expect([s.heat, s.jammed]).toEqual([0, false]);expect(s.phase).toBe("ready");run(s, idleInput(), 2);expect(s.phase).toBe("play");});- it("a click aims there and fires from the nearest battery", () => {+ it("a click aims there and fires a bolt from the tower, warming it", () => {const s = quiet();game.step(s, click(290, 90), RETRO_STEP, rnd);- expect(s.batteries.map((b) => b.ammo)).toEqual([AMMO, AMMO, AMMO - 1]);- const [m] = activeMissiles(s);- expect([m.ox, m.tx, m.ty]).toEqual([BATTERY_X[2], 290, 90]);+ const [b] = activeBolts(s);+ expect([b.ox, b.oy, b.tx, b.ty, b.r]).toEqual([TOWER_X, TOWER_Y, 290, 90, BOLT_R]);+ expect(s.heat).toBeCloseTo(HEAT_BOLT, 6);});it("a resting mouse does not undo keyboard aiming", () => {@@ -82,140 +84,166 @@ describe("city defense", () => {expect(s.cx).toBeGreaterThan(160);});- it("the keyboard moves the crosshair and fires with the action button", () => {+ it("the keyboard moves the reticle and fires with the action button", () => {const s = quiet();run(s, { ...idleInput(), left: true, up: true }, 2);expect(s.cx).toBeLessThan(10);game.step(s, pressA(), RETRO_STEP, rnd);- expect(s.batteries[0].ammo).toBe(AMMO - 1);- expect(activeMissiles(s)).toHaveLength(1);+ expect(activeBolts(s)).toHaveLength(1);});- it("an empty or wrecked battery hands over to the next nearest one", () => {+ it("rapid fire overheats and jams the tower until it has fully cooled", () => {const s = quiet();- s.batteries[0].ammo = 0;- s.cx = 20;- expect(firingBattery(s)).toBe(1);- s.batteries[1].alive = false;- expect(firingBattery(s)).toBe(2);- s.batteries[2].ammo = 0;- expect(firingBattery(s)).toBe(-1);- game.step(s, pressA(), RETRO_STEP, rnd);- expect(activeMissiles(s)).toHaveLength(0);+ s.cx = 160; s.cy = 40;+ let fired = 0;+ for (let i = 0; i < 8; i += 1) {+ const before = activeBolts(s).length;+ game.step(s, pressA(), RETRO_STEP, rnd);+ if (activeBolts(s).length > before) fired += 1;+ }+ // The cooling between shots buys at most one extra bolt before the jam.+ expect(fired).toBeGreaterThanOrEqual(Math.round(1 / HEAT_BOLT));+ expect(fired).toBeLessThanOrEqual(Math.round(1 / HEAT_BOLT) + 1);+ expect(s.jammed).toBe(true);+ expect(canFire(s, false)).toBe(false);+ // Half cooled is not enough: a jam lasts until the heat is all gone.+ run(s, idleInput(), 0.5 / COOL_RATE);+ expect(s.jammed).toBe(true);+ run(s, idleInput(), 0.6 / COOL_RATE);+ expect(s.jammed).toBe(false);+ expect(canFire(s, false)).toBe(true);});- it("the secondary button forces a battery, cycling back to nearest", () => {+ it("the secondary button fires a wide pulse that costs more heat", () => {const s = quiet();- s.cx = 300;- game.step(s, pressB(), RETRO_STEP, rnd);- expect(s.selected).toBe(0);- game.step(s, pressA(), RETRO_STEP, rnd);- expect(s.batteries[0].ammo).toBe(AMMO - 1);- game.step(s, pressB(), RETRO_STEP, rnd);+ s.cx = 160; s.cy = 100;game.step(s, pressB(), RETRO_STEP, rnd);- game.step(s, pressB(), RETRO_STEP, rnd);- expect(s.selected).toBe(-1);- expect(firingBattery(s)).toBe(2);+ const [b] = activeBolts(s);+ expect(b.r).toBe(PULSE_R);+ expect(s.heat).toBeCloseTo(HEAT_PULSE, 2);+ // Too warm for a second pulse right away, but a bolt still fits.+ game.step(s, idleInput(), RETRO_STEP, rnd);+ expect(canFire(s, true)).toBe(false);+ expect(canFire(s, false)).toBe(true);});- it("a counter-missile bursts at the aim point and its blast destroys a warhead", () => {+ it("a bolt bursts at the aim point and its ring shatters a shard", () => {const s = quiet();s.cx = 160;s.cy = 120;- addWarhead(s, 160, 118, 160, GROUND_Y, 1, false);+ addShard(s, 160, 118, 160, GROUND_Y, 1);game.step(s, pressA(), RETRO_STEP, rnd);run(s, idleInput(), 0.6);- expect(activeWarheads(s)).toBe(0);- expect(s.score).toBe(25 * multiplier(1));+ expect(activeShards(s)).toBe(0);+ expect(s.score).toBe(SHARD_POINTS * multiplier(1));});- it("blasts grow, hold and fade", () => {- expect(blastRadius(0, BLAST_R)).toBe(0);- expect(blastRadius(0.5, BLAST_R)).toBe(BLAST_R);- expect(blastRadius(BLAST_S, BLAST_R)).toBeCloseTo(0, 6);+ it("rings grow, hold and fade", () => {+ expect(ringRadius(0, BOLT_R)).toBe(0);+ expect(ringRadius(0.5, BOLT_R)).toBe(BOLT_R);+ expect(ringRadius(RING_S, BOLT_R)).toBeCloseTo(0, 6);});- it("a destroyed warhead's own blast catches the next one (chain reaction)", () => {+ it("a shattered shard's own ring catches the next one (chain reaction)", () => {const s = quiet();s.cx = 100;s.cy = 100;- // The second warhead is out of reach of our blast but within the first one's.- addWarhead(s, 112, 100, 112, GROUND_Y, 0.01, false);- addWarhead(s, 124, 100, 124, GROUND_Y, 0.01, false);- expect(124 - 100).toBeGreaterThan(BLAST_R);+ // The second shard is out of reach of our ring but within the first one's.+ addShard(s, 111, 100, 111, GROUND_Y, 0.01);+ addShard(s, 122, 100, 122, GROUND_Y, 0.01);+ expect(122 - 100).toBeGreaterThan(BOLT_R);game.step(s, click(100, 100), RETRO_STEP, rnd);run(s, idleInput(), 1.5);- expect(activeWarheads(s)).toBe(0);- expect(s.score).toBe(50);+ expect(activeShards(s)).toBe(0);+ expect(s.score).toBe(2 * SHARD_POINTS);});- it("a warhead reaching a city wrecks it", () => {+ it("a shard reaching a dome breaks it", () => {const s = quiet();- addWarhead(s, CITY_X[0], GROUND_Y - 4, CITY_X[0], GROUND_Y, 60, false);+ addShard(s, DOME_X[0], GROUND_Y - 4, DOME_X[0], GROUND_Y, 60);run(s, idleInput(), 0.3);- expect(s.cities[0]).toBe(0);- expect(game.status(s).lives).toBe(5);+ expect(s.domes[0]).toBe(0);+ expect(game.status(s).lives).toBe(3);});- it("a warhead on a battery wrecks it and its ammo", () => {+ it("a shard striking the tower jams it but does not destroy it", () => {const s = quiet();- addWarhead(s, BATTERY_X[1], BATTERY_Y, BATTERY_X[1], BATTERY_Y + 4, 60, false);- run(s, idleInput(), 0.3);- expect(s.batteries[1]).toMatchObject({ alive: false, ammo: 0 });+ addShard(s, TOWER_X, TOWER_Y, TOWER_X, TOWER_Y + 4, 60);+ run(s, idleInput(), 0.2);+ expect(s.jammed).toBe(true);+ expect(domesStanding(s)).toBe(4);+ run(s, idleInput(), 1.2 / COOL_RATE);+ expect(s.jammed).toBe(false);});- it("later waves split warheads mid-air", () => {+ it("weaving shards swing side to side around their path", () => {const s = quiet();- s.wave = 5;- addWarhead(s, 160, 40, 160, GROUND_Y, 60, true, 50);- run(s, idleInput(), 0.3);- expect(activeWarheads(s)).toBeGreaterThanOrEqual(3);+ addShard(s, 160, 20, 160, GROUND_Y, 20, 14);+ let left = 160, right = 160;+ for (let t = 0; t < 2; t += RETRO_STEP) {+ game.step(s, idleInput(), RETRO_STEP, rnd);+ const w = s.shards.find((x) => x.active);+ if (!w) break;+ left = Math.min(left, w.x);+ right = Math.max(right, w.x);+ }+ expect(left).toBeLessThan(150);+ expect(right).toBeGreaterThan(170);});- it("a bomber caught in a blast is worth extra", () => {+ it("a seeder caught in a ring is worth extra", () => {const s = quiet();- s.flyer.active = true;- s.flyer.x = 150;- s.flyer.y = 60;- s.flyer.speed = 0;- s.flyer.dropTimer = 99;+ s.seeder.active = true;+ s.seeder.x = 150;+ s.seeder.y = 60;+ s.seeder.vx = 0;+ s.seeder.vy = 0;+ s.seeder.dropTimer = 99;game.step(s, click(150, 60), RETRO_STEP, rnd);run(s, idleInput(), 1);- expect(s.flyer.active).toBe(false);- expect(s.score).toBe(100);+ expect(s.seeder.active).toBe(false);+ expect(s.score).toBe(SEEDER_POINTS);});- it("the wave ends with a bonus for ammo and cities, then the next wave refills", () => {+ it("the wave ends with a bonus per dome, plus extra when the colony stayed whole", () => {const s = quiet();s.toLaunch = 0;- s.batteries[0].ammo = 4;- s.cities[5] = 0;run(s, idleInput(), 0.1);expect(s.phase).toBe("bonus");- expect(s.score).toBe((4 + AMMO * 2) * 5 + 5 * 100);+ expect(s.score).toBe(4 * DOME_BONUS + FULL_COLONY_BONUS);run(s, idleInput(), 3);expect(s.wave).toBe(2);- expect(s.batteries.map((b) => b.ammo)).toEqual([AMMO, AMMO, AMMO]);- expect(citiesStanding(s)).toBe(5);+ expect([s.heat, s.jammed]).toEqual([0, false]);++ const t = quiet();+ t.toLaunch = 0;+ t.domes[3] = 0;+ run(t, idleInput(), 0.1);+ expect(t.score).toBe(3 * DOME_BONUS);+ expect(t.bonusFull).toBe(false);});- it("a banked bonus city rebuilds a lost one", () => {+ it("a spare dome earned by points rebuilds a lost one", () => {const s = quiet();- s.score = 9990;+ s.score = SPARE_DOME_EVERY - 10;s.toLaunch = 0;- s.cities[2] = 0;+ s.domes[2] = 0;run(s, idleInput(), 0.1);- expect(s.banked).toBe(1);+ expect(s.spares).toBe(1);run(s, idleInput(), 3);- expect(citiesStanding(s)).toBe(6);- expect(s.banked).toBe(0);+ expect(domesStanding(s)).toBe(4);+ expect(s.spares).toBe(0);});- it("losing every city ends the run", () => {+ it("the multiplier steps up every three waves, up to four", () => {+ expect([1, 3, 4, 6, 7, 10, 30].map(multiplier)).toEqual([1, 1, 2, 2, 3, 4, 4]);+ });++ it("losing every dome ends the run", () => {const s = quiet();- s.cities.fill(0);- s.cities[3] = 1;- addWarhead(s, CITY_X[3], GROUND_Y - 2, CITY_X[3], GROUND_Y, 60, false);+ s.domes.fill(0);+ s.domes[3] = 1;+ addShard(s, DOME_X[3], GROUND_Y - 2, DOME_X[3], GROUND_Y, 60);run(s, idleInput(), 3);expect(game.status(s)).toMatchObject({ lives: 0, over: true });});@@ -225,7 +253,8 @@ describe("city defense", () => {s.wave = 6;for (let i = 0; i < 60 * 90 && s.phase !== "over" && s.wave === 6; i += 1) {game.step(s, idleInput(), RETRO_STEP, rnd);- expect(s.warheads.length).toBe(40);+ expect(s.shards.length).toBe(40);+ for (const w of s.shards) if (w.active) expect(w.x >= 0 && w.x <= WIDTH).toBe(true);}expect(s.wave === 7 || s.phase === "over" || s.phase === "lost").toBe(true);});@@ -243,26 +272,27 @@ describe("city defense", () => {expect(fake.rects()).toBeGreaterThan(50);}run(s, idleInput(), 2);- addWarhead(s, 100, 10, 120, GROUND_Y, 30, true, 80);+ addShard(s, 100, 10, 120, GROUND_Y, 30, 12);game.step(s, click(200, 80), RETRO_STEP, rnd);- s.flyer.active = true;- s.flyer.x = 80;- s.flyer.y = 60;+ game.step(s, pressB(), RETRO_STEP, rnd);+ s.seeder.active = true;+ s.seeder.x = 80;+ s.seeder.y = 60;run(s, idleInput(), 0.3);s.shake = 0.3;- s.selected = 1;- s.banked = 2;- for (const kind of [0, 1] as const) {- s.flyer.kind = kind;- game.draw(fakeContext().ctx, s, { time: 2, reduced: false, idle: false });- game.draw(fakeContext().ctx, s, { time: 2, reduced: true, idle: false });- }- s.cities[1] = 0;- s.batteries[2].alive = false;+ s.spares = 2;+ s.jammed = true;+ game.draw(fakeContext().ctx, s, { time: 2, reduced: false, idle: false });+ game.draw(fakeContext().ctx, s, { time: 2, reduced: true, idle: false });+ s.domes[1] = 0;+ s.phase = "ready";+ game.draw(fakeContext().ctx, s, { time: 2, reduced: false, idle: false });s.phase = "bonus";+ s.bonusFull = true;game.draw(fakeContext().ctx, s, { time: 2, reduced: false, idle: false });s.phase = "over";game.draw(fakeContext().ctx, s, { time: 2, reduced: false, idle: false });expect(WIDTH).toBe(game.width);});});+diff --git a/dodaios/ui/web/frontend/src/components/society/arcade/games/cityDefense.ts b/dodaios/ui/web/frontend/src/components/society/arcade/games/cityDefense.tsindex 4556062a10..7fe87be535 100644--- a/dodaios/ui/web/frontend/src/components/society/arcade/games/cityDefense.ts+++ b/dodaios/ui/web/frontend/src/components/society/arcade/games/cityDefense.ts@@ -1,13 +1,20 @@/**- * "City Defense": warheads rain down on six cities and three missile- * batteries. Aim the crosshair (mouse, or arrow keys) and fire: a- * counter-missile flies from the nearest battery with ammo to that point and- * bursts into a blast that grows and fades. Any warhead caught in a blast- * blows up too, and its blast can catch the next one (chain reactions).- * Later waves bring warheads that split mid-air and a fast bomber or- * satellite that drops more. Each wave ends with a bonus for unused ammo and- * surviving cities; every 10,000 points banks a city that rebuilds a lost- * one. When the last city falls and none is banked, the run is over.+ * "City Defense": crystal shards fall on four glass habitat domes. One lance+ * tower in the middle of the colony shoots them down: aim the reticle (mouse,+ * or arrow keys) and fire a bolt that bursts into a ring at that point. Any+ * shard caught in a ring shatters, and its own smaller ring can catch the+ * next one (chain reactions).+ *+ * The tower has no ammunition; it has heat. Every bolt warms it, it cools+ * down on its own, and a tower pushed past its limit jams until it has fully+ * cooled. The secondary button fires a pulse: a slower, much wider ring that+ * costs a lot of heat. A shard striking the tower jams it at once.+ *+ * Later waves bring weaving shards that swing side to side, and a drifting+ * seeder that sows more of them. Each wave ends with a bonus per dome still+ * standing (and extra for a full colony); every 7,500 points earns a spare+ * dome that rebuilds a lost one. When the last dome falls and no spare is+ * waiting, the run is over.*/import type { RetroDrawInfo, RetroGame, RetroInput, RetroStatus } from "../retroGame";import {@@ -18,52 +25,63 @@ import {export const WIDTH = 320;export const HEIGHT = 240;export const GROUND_Y = 222;-/** The crosshair stays in the sky. */+/** The reticle stays in the sky. */const AIM_TOP = 10;-const AIM_BOTTOM = 196;+const AIM_BOTTOM = 190;const AIM_SPEED = 170;-export const CITY_X: readonly number[] = [64, 92, 120, 200, 228, 256];-export const BATTERY_X: readonly number[] = [24, 160, 296];-/** Where counter-missiles leave a battery (the top of its mound). */-export const BATTERY_Y = 204;-export const AMMO = 10;-/** The centre battery fires faster missiles. */-const MISSILE_SPEED = [170, 260, 170] as const;--const BLAST_GROW = 0.45;-const BLAST_HOLD = 0.25;-const BLAST_SHRINK = 0.45;-export const BLAST_S = BLAST_GROW + BLAST_HOLD + BLAST_SHRINK;-export const BLAST_R = 16;-/** A warhead destroyed in the air bursts into a slightly smaller blast of its own. */-export const CHAIN_R = 13;-const IMPACT_R = 11;-/** How close to a city or battery an impact must be to wreck it. */-const CITY_HIT = 12;-const BATTERY_HIT = 14;--const MAX_MISSILES = 10;-const MAX_WARHEADS = 40;-const MAX_BLASTS = 48;--const WARHEAD_POINTS = 25;-const FLYER_POINTS = 100;-const AMMO_BONUS = 5;-const CITY_BONUS = 100;-export const BONUS_CITY_EVERY = 10000;+export const DOME_X: readonly number[] = [52, 116, 204, 268];+const DOME_R = 13;+export const TOWER_X = WIDTH / 2;+/** Where bolts leave the tower (the tip of its spire). */+export const TOWER_Y = 196;++/** Heat added by one bolt and by one pulse; the tower jams at 1. */+export const HEAT_BOLT = 0.2;+export const HEAT_PULSE = 0.55;+/** Heat shed per second. */+export const COOL_RATE = 0.35;+const BOLT_SPEED = 230;+const PULSE_SPEED = 150;++const RING_GROW = 0.4;+const RING_HOLD = 0.2;+const RING_FADE = 0.5;+export const RING_S = RING_GROW + RING_HOLD + RING_FADE;+export const BOLT_R = 15;+export const PULSE_R = 30;+/** A shard shattered in the air bursts into a smaller ring of its own. */+export const CHAIN_R = 12;+const IMPACT_R = 10;+/** How close to a dome or the tower an impact must be to break it. */+const DOME_HIT = 14;+const TOWER_HIT = 10;++const MAX_BOLTS = 8;+const MAX_SHARDS = 40;+const MAX_RINGS = 48;++export const SHARD_POINTS = 20;+export const SEEDER_POINTS = 150;+export const DOME_BONUS = 150;+/** Extra at the end of a wave in which no dome was lost. */+export const FULL_COLONY_BONUS = 500;+export const SPARE_DOME_EVERY = 7500;const READY_S = 1.6;const BONUS_S = 2.6;const LOST_S = 2.2;export type DefensePhase = "ready" | "play" | "bonus" | "lost" | "over";-export interface Battery { x: number; ammo: number; alive: boolean }-export interface Counter { active: boolean; ox: number; oy: number; x: number; y: number; tx: number; ty: number; vx: number; vy: number; left: number }-export interface Warhead { active: boolean; ox: number; oy: number; x: number; y: number; vx: number; vy: number; ty: number; mirv: boolean; splitY: number }-/** A blast: `friendly` ones (ours and chains) destroy what they touch in the air; impacts only wreck the ground. */-export interface Blast { active: boolean; x: number; y: number; age: number; r: number; friendly: boolean }-export interface Flyer { active: boolean; kind: 0 | 1; x: number; y: number; dir: 1 | -1; speed: number; dropTimer: number }+export interface Bolt { active: boolean; ox: number; oy: number; x: number; y: number; tx: number; ty: number; vx: number; vy: number; left: number; r: number }+/**+ * A falling shard. It travels along a straight base path (`bx`, `y`); a+ * weaving shard swings `weave` pixels either side of it.+ */+export interface Shard { active: boolean; bx: number; x: number; y: number; vx: number; vy: number; ty: number; weave: number; phase: number }+/** A ring: `friendly` ones (ours and chains) shatter what they touch in the air; impacts only break the ground. */+export interface Ring { active: boolean; x: number; y: number; age: number; r: number; friendly: boolean }+export interface Seeder { active: boolean; x: number; y: number; vx: number; vy: number; dropTimer: number; t: number }export interface DefenseState {phase: DefensePhase;@@ -72,78 +90,87 @@ export interface DefenseState {elapsed: number;score: number;wave: number;- nextCityAt: number;- /** Bonus cities waiting to rebuild a destroyed one at the next wave. */- banked: number;+ nextSpareAt: number;+ /** Spare domes waiting to rebuild a lost one at the end of the wave. */+ spares: number;cx: number;cy: number;/** Last pointer position seen, so a resting mouse does not undo keyboard aiming. */lastPx: number;lastPy: number;- /** The battery forced with `b`, or -1 for "nearest with ammo". */- selected: number;- cities: Uint8Array;- batteries: Battery[];- missiles: Counter[];- warheads: Warhead[];- blasts: Blast[];- flyer: Flyer;- /** Warheads (including the flyer's drops) still to come this wave. */+ /** Tower heat, 0 cold to 1 jammed. */+ heat: number;+ /** The tower is jammed and will not fire until it has fully cooled. */+ jammed: boolean;+ domes: Uint8Array;+ /** Domes standing when the wave began, for the full-colony bonus. */+ domesAtStart: number;+ bolts: Bolt[];+ shards: Shard[];+ rings: Ring[];+ seeder: Seeder;+ /** Shards (including the seeder's) still to come this wave. */toLaunch: number;salvoTimer: number;- flyerTimer: number;+ seederTimer: number;/** The last wave's bonus tally, for the bonus screen. */- bonusAmmo: number;- bonusCities: number;+ bonusDomes: number;+ bonusFull: boolean;particles: Particle[];shake: number;}-/** Score multiplier: ×1 for waves 1–2, ×2 for 3–4 … up to ×6. */+/** Score multiplier: ×1 for waves 1–3, ×2 for 4–6 … up to ×4. */export function multiplier(wave: number): number {- return Math.min(6, 1 + Math.floor((wave - 1) / 2));+ return Math.min(4, 1 + Math.floor((wave - 1) / 3));}-export function warheadSpeed(wave: number): number {- return Math.min(70, 16 + wave * 4);+export function shardSpeed(wave: number): number {+ return Math.min(64, 18 + wave * 3.5);}function wavePayload(wave: number): number {- return Math.min(36, 10 + wave * 2);+ return Math.min(32, 8 + wave * 2);}-/** Radius of a blast at a given age: it grows, holds and shrinks away. */-export function blastRadius(age: number, max: number): number {- if (age < BLAST_GROW) return (max * age) / BLAST_GROW;- if (age < BLAST_GROW + BLAST_HOLD) return max;- return Math.max(0, max * (1 - (age - BLAST_GROW - BLAST_HOLD) / BLAST_SHRINK));+/** Radius of a ring at a given age: it grows, holds and fades. */+export function ringRadius(age: number, max: number): number {+ if (age < RING_GROW) return (max * age) / RING_GROW;+ if (age < RING_GROW + RING_HOLD) return max;+ return Math.max(0, max * (1 - (age - RING_GROW - RING_HOLD) / RING_FADE));+}++export function domesStanding(state: DefenseState): number {+ let n = 0;+ for (const d of state.domes) n += d;+ return n;}function startWave(state: DefenseState, random: () => number): void {state.phase = "ready";state.timer = READY_S;- for (const b of state.batteries) { b.alive = true; b.ammo = AMMO; }- for (const m of state.missiles) m.active = false;- for (const w of state.warheads) w.active = false;- for (const b of state.blasts) b.active = false;- state.flyer.active = false;+ state.heat = 0;+ state.jammed = false;+ for (const b of state.bolts) b.active = false;+ for (const s of state.shards) s.active = false;+ for (const r of state.rings) r.active = false;+ state.seeder.active = false;state.toLaunch = wavePayload(state.wave);state.salvoTimer = 0.4;- state.flyerTimer = 8 + random() * 8;- state.selected = -1;+ state.seederTimer = 9 + random() * 8;+ state.domesAtStart = domesStanding(state);}function create(random: () => number): DefenseState {const state: DefenseState = {- phase: "ready", timer: 0, elapsed: 0, score: 0, wave: 1, nextCityAt: BONUS_CITY_EVERY, banked: 0,- cx: WIDTH / 2, cy: 110, lastPx: -1, lastPy: -1, selected: -1,- cities: new Uint8Array(CITY_X.length).fill(1),- batteries: BATTERY_X.map((x) => ({ x, ammo: AMMO, alive: true })),- missiles: Array.from({ length: MAX_MISSILES }, () => ({ active: false, ox: 0, oy: 0, x: 0, y: 0, tx: 0, ty: 0, vx: 0, vy: 0, left: 0 })),- warheads: Array.from({ length: MAX_WARHEADS }, () => ({ active: false, ox: 0, oy: 0, x: 0, y: 0, vx: 0, vy: 0, ty: 0, mirv: false, splitY: 0 })),- blasts: Array.from({ length: MAX_BLASTS }, () => ({ active: false, x: 0, y: 0, age: 0, r: 0, friendly: false })),- flyer: { active: false, kind: 0, x: 0, y: 0, dir: 1, speed: 0, dropTimer: 0 },- toLaunch: 0, salvoTimer: 0, flyerTimer: 0, bonusAmmo: 0, bonusCities: 0,+ phase: "ready", timer: 0, elapsed: 0, score: 0, wave: 1, nextSpareAt: SPARE_DOME_EVERY, spares: 0,+ cx: WIDTH / 2, cy: 110, lastPx: -1, lastPy: -1, heat: 0, jammed: false,+ domes: new Uint8Array(DOME_X.length).fill(1), domesAtStart: DOME_X.length,+ bolts: Array.from({ length: MAX_BOLTS }, () => ({ active: false, ox: 0, oy: 0, x: 0, y: 0, tx: 0, ty: 0, vx: 0, vy: 0, left: 0, r: 0 })),+ shards: Array.from({ length: MAX_SHARDS }, () => ({ active: false, bx: 0, x: 0, y: 0, vx: 0, vy: 0, ty: 0, weave: 0, phase: 0 })),+ rings: Array.from({ length: MAX_RINGS }, () => ({ active: false, x: 0, y: 0, age: 0, r: 0, friendly: false })),+ seeder: { active: false, x: 0, y: 0, vx: 0, vy: 0, dropTimer: 0, t: 0 },+ toLaunch: 0, salvoTimer: 0, seederTimer: 0, bonusDomes: 0, bonusFull: false,particles: makeParticles(160),shake: 0,};@@ -153,222 +180,194 @@ function create(random: () => number): DefenseState {function addScore(state: DefenseState, points: number): void {state.score += points;- while (state.score >= state.nextCityAt) {- state.banked += 1;- state.nextCityAt += BONUS_CITY_EVERY;+ while (state.score >= state.nextSpareAt) {+ state.spares += 1;+ state.nextSpareAt += SPARE_DOME_EVERY;}}-function spawnBlast(state: DefenseState, x: number, y: number, r: number, friendly: boolean): void {- let slot: Blast | undefined;- for (const b of state.blasts) if (!b.active) { slot = b; break; }+function spawnRing(state: DefenseState, x: number, y: number, r: number, friendly: boolean): void {+ let slot: Ring | undefined;+ for (const b of state.rings) if (!b.active) { slot = b; break; }if (!slot) return;slot.active = true; slot.x = x; slot.y = y; slot.age = 0; slot.r = r; slot.friendly = friendly;}/**- * Send a warhead from (x, y) to the ground at `tx` (to the battery top when it- * aims at a battery). Returns false when the sky is full.+ * Send a shard from (x, y) towards (tx, ty) on the ground; `weave` > 0 makes+ * it swing side to side. Returns false when the sky is full.*/-export function addWarhead(state: DefenseState, x: number, y: number, tx: number, ty: number, speed: number, mirv: boolean, splitY = 0): boolean {- let w: Warhead | undefined;- for (const c of state.warheads) if (!c.active) { w = c; break; }- if (!w) return false;+export function addShard(state: DefenseState, x: number, y: number, tx: number, ty: number, speed: number, weave = 0): boolean {+ let s: Shard | undefined;+ for (const c of state.shards) if (!c.active) { s = c; break; }+ if (!s) return false;const dx = tx - x, dy = ty - y;const len = Math.max(1, Math.hypot(dx, dy));- w.active = true; w.ox = x; w.oy = y; w.x = x; w.y = y;- w.vx = (dx / len) * speed; w.vy = (dy / len) * speed;- w.ty = ty; w.mirv = mirv; w.splitY = splitY;+ s.active = true; s.bx = x; s.x = x; s.y = y;+ s.vx = (dx / len) * speed; s.vy = (dy / len) * speed;+ s.ty = ty; s.weave = weave; s.phase = 0;return true;}-/** A target on the ground: a standing city or battery most of the time, sometimes open ground. */+/** A target on the ground: a standing dome most of the time, sometimes the tower or open ground. */function pickTarget(state: DefenseState, random: () => number, out: number[]): void {- let standing = 0;- for (const c of state.cities) standing += c;- for (const b of state.batteries) if (b.alive) standing += 1;- if (standing === 0 || random() < 0.15) {+ const standing = domesStanding(state);+ const roll = random();+ if (standing === 0 || roll < 0.12) {out[0] = 12 + random() * (WIDTH - 24);out[1] = GROUND_Y;return;}- let pick = Math.floor(random() * standing);- for (let i = 0; i < CITY_X.length; i += 1) {- if (state.cities[i] && pick-- === 0) { out[0] = CITY_X[i]; out[1] = GROUND_Y; return; }+ if (roll < 0.22) {+ out[0] = TOWER_X; out[1] = TOWER_Y + 4;+ return;}- for (const b of state.batteries) {- if (b.alive && pick-- === 0) { out[0] = b.x; out[1] = BATTERY_Y + 4; return; }+ let pick = Math.floor(random() * standing);+ for (let i = 0; i < DOME_X.length; i += 1) {+ if (state.domes[i] && pick-- === 0) { out[0] = DOME_X[i]; out[1] = GROUND_Y; return; }}}const target = [0, 0];function launchFromSky(state: DefenseState, random: () => number): void {pickTarget(state, random, target);- const mirvChance = state.wave >= 3 ? Math.min(0.35, 0.06 * (state.wave - 2)) : 0;- const mirv = random() < mirvChance;- if (addWarhead(state, 8 + random() * (WIDTH - 16), 0, target[0], target[1], warheadSpeed(state.wave), mirv, 50 + random() * 70)) {+ const weaveChance = state.wave >= 3 ? Math.min(0.4, 0.08 * (state.wave - 2)) : 0;+ const weave = random() < weaveChance ? 10 + random() * 10 : 0;+ // A weaver's base path is kept inside the screen so its swing never leaves it.+ const x = clamp(8 + random() * (WIDTH - 16), 8 + weave, WIDTH - 8 - weave);+ if (addShard(state, x, 0, clamp(target[0], 8 + weave, WIDTH - 8 - weave), target[1], shardSpeed(state.wave), weave)) {state.toLaunch -= 1;}}-/** Split a MIRV: two or three new warheads leave from where it is now; the original flies on. */-function split(state: DefenseState, w: Warhead, random: () => number): void {- w.mirv = false;- const count = 2 + (random() < 0.4 ? 1 : 0);- const speed = Math.hypot(w.vx, w.vy);- for (let i = 0; i < count; i += 1) {- pickTarget(state, random, target);- addWarhead(state, w.x, w.y, target[0], target[1], speed, false);- }-}--/** The battery that would fire at the crosshair now: the forced one if it can, else the nearest with ammo; -1 if none. */-export function firingBattery(state: DefenseState): number {- const forced = state.selected >= 0 ? state.batteries[state.selected] : null;- if (forced && forced.alive && forced.ammo > 0) return state.selected;- let best = -1, bestD = Infinity;- for (let i = 0; i < state.batteries.length; i += 1) {- const b = state.batteries[i];- if (!b.alive || b.ammo <= 0) continue;- // Ties go to the centre battery, whose missiles are faster.- const d = Math.abs(b.x - state.cx) - (i === 1 ? 0.5 : 0);- if (d < bestD) { bestD = d; best = i; }- }- return best;+/**+ * Whether the tower may fire now: a bolt whenever it is not jammed (the bolt+ * that pushes it past its limit jams it), a pulse only while it is cool+ * enough to take the pulse's heat.+ */+export function canFire(state: DefenseState, pulse: boolean): boolean {+ return !state.jammed && (!pulse || state.heat + HEAT_PULSE <= 1 + 1e-9);}-function fire(state: DefenseState): boolean {- const i = firingBattery(state);- if (i < 0) return false;- let m: Counter | undefined;- for (const c of state.missiles) if (!c.active) { m = c; break; }- if (!m) return false;- const b = state.batteries[i];- b.ammo -= 1;- const dx = state.cx - b.x, dy = state.cy - BATTERY_Y;+function fire(state: DefenseState, pulse: boolean): boolean {+ if (!canFire(state, pulse)) return false;+ const cost = pulse ? HEAT_PULSE : HEAT_BOLT;+ let b: Bolt | undefined;+ for (const c of state.bolts) if (!c.active) { b = c; break; }+ if (!b) return false;+ state.heat += cost;+ if (state.heat >= 1 - 1e-9) { state.heat = 1; state.jammed = true; }+ const speed = pulse ? PULSE_SPEED : BOLT_SPEED;+ const dx = state.cx - TOWER_X, dy = state.cy - TOWER_Y;const len = Math.max(1, Math.hypot(dx, dy));- m.active = true; m.ox = b.x; m.oy = BATTERY_Y; m.x = b.x; m.y = BATTERY_Y;- m.tx = state.cx; m.ty = state.cy; m.left = len;- m.vx = (dx / len) * MISSILE_SPEED[i]; m.vy = (dy / len) * MISSILE_SPEED[i];+ b.active = true; b.ox = TOWER_X; b.oy = TOWER_Y; b.x = TOWER_X; b.y = TOWER_Y;+ b.tx = state.cx; b.ty = state.cy; b.left = len; b.r = pulse ? PULSE_R : BOLT_R;+ b.vx = (dx / len) * speed; b.vy = (dy / len) * speed;return true;}-/** Cycle the forced battery: nearest → left → centre → right → nearest, skipping empty ones. */-function cycleBattery(state: DefenseState): void {- for (let n = 0; n < 4; n += 1) {- state.selected = state.selected >= 2 ? -1 : state.selected + 1;- if (state.selected < 0) return;- const b = state.batteries[state.selected];- if (b.alive && b.ammo > 0) return;- }-}--/** A warhead reached the ground: wreck what stands there. */+/** A shard reached the ground: break what stands there. */function impact(state: DefenseState, x: number, y: number, random: () => number): void {- spawnBlast(state, x, y, IMPACT_R, false);- emitBurst(state.particles, x, y, 12, 60, "#ff7a3a", random, 0.7);- for (let i = 0; i < CITY_X.length; i += 1) {- if (state.cities[i] && Math.abs(CITY_X[i] - x) <= CITY_HIT) {- state.cities[i] = 0;+ spawnRing(state, x, y, IMPACT_R, false);+ emitBurst(state.particles, x, y, 12, 60, "#ff9a4a", random, 0.7);+ for (let i = 0; i < DOME_X.length; i += 1) {+ if (state.domes[i] && Math.abs(DOME_X[i] - x) <= DOME_HIT) {+ state.domes[i] = 0;state.shake = 0.35;- emitBurst(state.particles, CITY_X[i], GROUND_Y - 4, 24, 80, "#7ff0ff", random, 1);+ emitBurst(state.particles, DOME_X[i], GROUND_Y - 6, 24, 80, "#bff6ff", random, 1);}}- for (const b of state.batteries) {- if (b.alive && Math.abs(b.x - x) <= BATTERY_HIT) {- b.alive = false;- b.ammo = 0;- state.shake = 0.35;- emitBurst(state.particles, b.x, BATTERY_Y, 20, 70, "#ffd35a", random, 0.9);- }+ if (Math.abs(TOWER_X - x) <= TOWER_HIT) {+ // The tower is armoured: a hit jams it instead of destroying it.+ state.heat = 1;+ state.jammed = true;+ state.shake = 0.3;+ emitBurst(state.particles, TOWER_X, TOWER_Y, 16, 60, "#ffd35a", random, 0.8);}}-export function citiesStanding(state: DefenseState): number {- let n = 0;- for (const c of state.cities) n += c;- return n;-}--/** Everything in the air moves; blasts grow, catch warheads and fade. */+/** Everything in the air moves; rings grow, catch shards and fade. */function stepWorld(state: DefenseState, dt: number, random: () => number): void {const mult = multiplier(state.wave);- for (const m of state.missiles) {- if (!m.active) continue;- const travel = Math.hypot(m.vx, m.vy) * dt;- if (travel >= m.left) {- m.active = false;- spawnBlast(state, m.tx, m.ty, BLAST_R, true);+ state.heat = Math.max(0, state.heat - COOL_RATE * dt);+ if (state.jammed && state.heat <= 0) state.jammed = false;+ for (const b of state.bolts) {+ if (!b.active) continue;+ const travel = Math.hypot(b.vx, b.vy) * dt;+ if (travel >= b.left) {+ b.active = false;+ spawnRing(state, b.tx, b.ty, b.r, true);continue;}- m.left -= travel;- m.x += m.vx * dt;- m.y += m.vy * dt;- }- for (const w of state.warheads) {- if (!w.active) continue;- w.x += w.vx * dt;- w.y += w.vy * dt;- if (w.mirv && w.y >= w.splitY) split(state, w, random);- if (w.y >= w.ty) {- w.active = false;- impact(state, w.x, w.ty, random);+ b.left -= travel;+ b.x += b.vx * dt;+ b.y += b.vy * dt;+ }+ for (const s of state.shards) {+ if (!s.active) continue;+ s.bx += s.vx * dt;+ s.y += s.vy * dt;+ s.phase += dt * 3;+ s.x = s.bx + Math.sin(s.phase) * s.weave;+ if (s.y >= s.ty) {+ s.active = false;+ impact(state, s.x, s.ty, random);}}- const f = state.flyer;+ const f = state.seeder;if (f.active) {- f.x += f.dir * f.speed * dt;- if (f.x < -24 || f.x > WIDTH + 24) f.active = false;- else if ((f.dropTimer -= dt) <= 0 && state.toLaunch > 0 && f.x > 16 && f.x < WIDTH - 16) {+ f.t += dt;+ f.x += f.vx * dt;+ f.y += f.vy * dt;+ if (f.x < -20 || f.x > WIDTH + 20) f.active = false;+ else if ((f.dropTimer -= dt) <= 0 && state.toLaunch > 0 && f.x > 20 && f.x < WIDTH - 20) {pickTarget(state, random, target);- if (addWarhead(state, f.x, f.y + 4, target[0], target[1], warheadSpeed(state.wave), false)) state.toLaunch -= 1;- f.dropTimer = 1.1 + random() * 1.2;+ if (addShard(state, f.x, f.y + 6, clamp(target[0], 20, WIDTH - 20), target[1], shardSpeed(state.wave) * 0.9, 12)) state.toLaunch -= 1;+ f.dropTimer = 1.4 + random() * 1.2;}}- for (const b of state.blasts) {- if (!b.active) continue;- b.age += dt;- if (b.age >= BLAST_S) { b.active = false; continue; }- if (!b.friendly) continue;- const r = blastRadius(b.age, b.r);- const r2 = r * r;- for (const w of state.warheads) {- if (!w.active) continue;- const dx = w.x - b.x, dy = w.y - b.y;+ for (const r of state.rings) {+ if (!r.active) continue;+ r.age += dt;+ if (r.age >= RING_S) { r.active = false; continue; }+ if (!r.friendly) continue;+ const rad = ringRadius(r.age, r.r);+ const r2 = rad * rad;+ for (const s of state.shards) {+ if (!s.active) continue;+ const dx = s.x - r.x, dy = s.y - r.y;if (dx * dx + dy * dy <= r2) {- w.active = false;- addScore(state, WARHEAD_POINTS * mult);- spawnBlast(state, w.x, w.y, CHAIN_R, true);- emitBurst(state.particles, w.x, w.y, 8, 50, "#ffe9a8", random, 0.5);+ s.active = false;+ addScore(state, SHARD_POINTS * mult);+ spawnRing(state, s.x, s.y, CHAIN_R, true);+ emitBurst(state.particles, s.x, s.y, 8, 50, "#ffc4f0", random, 0.5);}}if (f.active) {- const dx = f.x - b.x, dy = f.y - b.y;- if (dx * dx + dy * dy <= (r + 5) * (r + 5)) {+ const dx = f.x - r.x, dy = f.y - r.y;+ if (dx * dx + dy * dy <= (rad + 6) * (rad + 6)) {f.active = false;- addScore(state, FLYER_POINTS * mult);- spawnBlast(state, f.x, f.y, BLAST_R, true);- emitBurst(state.particles, f.x, f.y, 20, 80, "#c8f0ff", random, 0.8);+ addScore(state, SEEDER_POINTS * mult);+ spawnRing(state, f.x, f.y, BOLT_R, true);+ emitBurst(state.particles, f.x, f.y, 20, 80, "#b6fff0", random, 0.8);}}}}function airborne(state: DefenseState): boolean {- if (state.flyer.active) return true;- for (const m of state.missiles) if (m.active) return true;- for (const w of state.warheads) if (w.active) return true;- for (const b of state.blasts) if (b.active) return true;+ if (state.seeder.active) return true;+ for (const b of state.bolts) if (b.active) return true;+ for (const s of state.shards) if (s.active) return true;+ for (const r of state.rings) if (r.active) return true;return false;}function endWave(state: DefenseState): void {const mult = multiplier(state.wave);- let ammo = 0;- for (const b of state.batteries) ammo += b.ammo;- state.bonusAmmo = ammo;- state.bonusCities = citiesStanding(state);- addScore(state, (ammo * AMMO_BONUS + state.bonusCities * CITY_BONUS) * mult);+ state.bonusDomes = domesStanding(state);+ state.bonusFull = state.bonusDomes === DOME_X.length && state.domesAtStart === DOME_X.length;+ addScore(state, (state.bonusDomes * DOME_BONUS + (state.bonusFull ? FULL_COLONY_BONUS : 0)) * mult);state.phase = "bonus";state.timer = BONUS_S;}@@ -402,11 +401,11 @@ function step(state: DefenseState, input: RetroInput, dt: number, random: () =>}if (state.phase === "bonus") {if ((state.timer -= dt) <= 0) {- // Banked cities rebuild lost ones; with none standing and none banked the run is over.- for (let i = 0; i < state.cities.length && state.banked > 0; i += 1) {- if (!state.cities[i]) { state.cities[i] = 1; state.banked -= 1; }+ // Spare domes rebuild lost ones; with none standing and no spare the run is over.+ for (let i = 0; i < state.domes.length && state.spares > 0; i += 1) {+ if (!state.domes[i]) { state.domes[i] = 1; state.spares -= 1; }}- if (citiesStanding(state) === 0) {+ if (domesStanding(state) === 0) {state.phase = "over";return;}@@ -422,30 +421,31 @@ function step(state: DefenseState, input: RetroInput, dt: number, random: () =>return;}- if (input.pressed.b) cycleBattery(state);- if (input.pressed.a || input.pointer?.clicked) fire(state);+ if (input.pressed.b) fire(state, true);+ else if (input.pressed.a || input.pointer?.clicked) fire(state, false);- // The attack: salvoes from the top, and now and then a flyer.+ // The attack: salvoes from the top, and now and then a seeder.if (state.toLaunch > 0) {if ((state.salvoTimer -= dt) <= 0) {- const size = Math.min(state.toLaunch, 1 + Math.floor(random() * Math.min(4, 1 + state.wave / 2)));+ const size = Math.min(state.toLaunch, 1 + Math.floor(random() * Math.min(3, 1 + state.wave / 3)));for (let i = 0; i < size; i += 1) launchFromSky(state, random);- state.salvoTimer = Math.max(1.2, 3.4 - state.wave * 0.2) + random() * 0.8;+ state.salvoTimer = Math.max(1.1, 3 - state.wave * 0.18) + random() * 0.9;}- if (state.wave >= 2 && !state.flyer.active && (state.flyerTimer -= dt) <= 0) {- const f = state.flyer;+ if (state.wave >= 2 && !state.seeder.active && (state.seederTimer -= dt) <= 0) {+ const f = state.seeder;f.active = true;- f.kind = random() < 0.5 ? 0 : 1;- f.dir = random() < 0.5 ? 1 : -1;- f.x = f.dir > 0 ? -16 : WIDTH + 16;- f.y = 44 + random() * 50;- f.speed = f.kind === 0 ? 58 : 76;- f.dropTimer = 0.8 + random();- state.flyerTimer = 12 + random() * 10;+ const dir = random() < 0.5 ? 1 : -1;+ f.x = dir > 0 ? -16 : WIDTH + 16;+ f.y = 24 + random() * 20;+ f.vx = dir * (34 + random() * 14);+ f.vy = 6 + random() * 6;+ f.t = 0;+ f.dropTimer = 1 + random();+ state.seederTimer = 13 + random() * 9;}}- if (citiesStanding(state) === 0 && state.banked === 0) {+ if (domesStanding(state) === 0 && state.spares === 0) {state.phase = "lost";state.timer = LOST_S;return;@@ -454,208 +454,253 @@ function step(state: DefenseState, input: RetroInput, dt: number, random: () =>}function status(state: DefenseState): RetroStatus {- return { score: state.score, lives: citiesStanding(state), level: state.wave, over: state.phase === "over" };+ return { score: state.score, lives: domesStanding(state), level: state.wave, over: state.phase === "over" };}// ---- Drawing ---------------------------------------------------------------const SKY = ["#05061a", "#080a24", "#0c0d2e", "#120f36", "#1a1240", "#24154a"] as const;-const STARS = starField(60, WIDTH, 150, 23);-const CITY_SPRITES = [- sprite(["....##..............", "....##.....###......", ".####.#...####..##..", ".####.##..####.###..", "#########.########.#", "####################", "####################", "####################"]),- sprite([".........##.........", "..###....##...##....", "..###...####..##.##.", "######..####.#######", "######.#############", "####################", "####################", "####################"]),- sprite(["...##...............", "...##.......####....", "######.....######...", "######.##..######.##", "#########.##########", "####################", "####################", "####################"]),-];-const RUBBLE = sprite(["......#.......#.....", "..#..###...#.###....", ".####.####.#######..", "####################"]);-const BOMBER = sprite(["......##........", ".....####.......", "################", ".##############.", "....######......", ".....##........."]);-const SATELLITE = sprite(["###.......###", "###..###..###", "#############", "###..###..###", "###.......###"]);--function drawSky(ctx: CanvasRenderingContext2D): void {+const SKY = ["#041416", "#06191d", "#081e25", "#0c202d", "#121f35", "#1a1d3a"] as const;+const STARS = starField(50, WIDTH, 150, 41);+const SEEDER = sprite([+ "...#####...",+ ".#########.",+ "###.###.###",+ "###########",+ ".#.#.#.#.#.",+ "#..#..#..#.",+ ".#..#..#..#",+]);++function drawSky(ctx: CanvasRenderingContext2D, info: RetroDrawInfo): void {const band = Math.ceil(GROUND_Y / SKY.length);for (let i = 0; i < SKY.length; i += 1) {ctx.fillStyle = SKY[i];ctx.fillRect(0, i * band, WIDTH, band);}+ // A faint aurora ribbon high in the sky; it holds still under reduced motion.+ const t = info.reduced ? 0 : info.time;+ ctx.fillStyle = "#1f6a5c";+ ctx.globalAlpha = 0.35;+ for (let x = 0; x < WIDTH; x += 4) {+ const y = 34 + Math.sin(x * 0.03 + t * 0.4) * 8 + Math.sin(x * 0.011 - t * 0.25) * 6;+ ctx.fillRect(x, Math.round(y), 4, 3);+ }+ ctx.globalAlpha = 1;}-function drawGround(ctx: CanvasRenderingContext2D, state: DefenseState): void {- ctx.fillStyle = "#6b4a1e";+function drawGround(ctx: CanvasRenderingContext2D): void {+ ctx.fillStyle = "#1c1b22";ctx.fillRect(0, GROUND_Y, WIDTH, HEIGHT - GROUND_Y);- ctx.fillStyle = "#d4a843";+ ctx.fillStyle = "#2fd3b5";ctx.fillRect(0, GROUND_Y, WIDTH, 1);- for (const b of state.batteries) {- // A stepped mound under each battery.- for (let s = 0; s < 4; s += 1) {- const half = 22 - s * 4;- ctx.fillStyle = s === 3 ? "#d4a843" : "#8c6a2a";- ctx.fillRect(b.x - half, GROUND_Y - (s + 1) * 4, half * 2, 4);- }- }+ ctx.fillStyle = "#2a2932";+ for (let x = 6; x < WIDTH; x += 14) ctx.fillRect(x, GROUND_Y + 6 + (x % 3) * 3, 6, 2);}-function drawBatteries(ctx: CanvasRenderingContext2D, state: DefenseState, info: RetroDrawInfo): void {- for (const b of state.batteries) {- if (!b.alive) {- ctx.fillStyle = "#2a1a0c";- ctx.fillRect(b.x - 8, BATTERY_Y + 2, 16, 3);- continue;- }- // Ammo as rows of little missiles: 4, 3, 2, 1 from the bottom.- ctx.fillStyle = "#7ff0ff";- let left = b.ammo;- for (let row = 0; row < 4 && left > 0; row += 1) {- const n = 4 - row;- for (let k = 0; k < n && left > 0; k += 1, left -= 1) ctx.fillRect(b.x - n * 3 + k * 6 + 2, BATTERY_Y + 12 - row * 4 - 3, 2, 3);- }- }- const firing = firingBattery(state);- if (firing >= 0 && state.phase !== "over") {- const x = state.batteries[firing].x;- const bob = info.reduced ? 0 : Math.round(Math.sin(info.time * 5));- ctx.fillStyle = state.selected >= 0 ? "#ffd35a" : "#9aa3c7";- ctx.fillRect(x - 2, BATTERY_Y - 10 + bob, 5, 1);- ctx.fillRect(x - 1, BATTERY_Y - 9 + bob, 3, 1);- ctx.fillRect(x, BATTERY_Y - 8 + bob, 1, 1);- }+function drawTower(ctx: CanvasRenderingContext2D, state: DefenseState, info: RetroDrawInfo): void {+ // A slim stepped spire with a glowing tip.+ ctx.fillStyle = "#3a3540";+ ctx.fillRect(TOWER_X - 9, GROUND_Y - 6, 18, 6);+ ctx.fillStyle = "#c9a227";+ ctx.fillRect(TOWER_X - 5, GROUND_Y - 16, 10, 10);+ ctx.fillRect(TOWER_X - 3, TOWER_Y + 2, 6, GROUND_Y - 16 - TOWER_Y - 2);+ ctx.fillStyle = "#e0c25a";+ ctx.fillRect(TOWER_X - 1, TOWER_Y + 2, 2, GROUND_Y - 6 - TOWER_Y - 2);+ const blink = state.jammed && !info.reduced && Math.floor(info.time * 6) % 2 === 0;+ ctx.fillStyle = state.jammed ? (blink ? "#ff5a4a" : "#7a2a24") : "#fff4c8";+ ctx.fillRect(TOWER_X - 1, TOWER_Y - 1, 3, 3);+ // The heat meter beside the tower: teal when cool, through amber to red.+ const h = clamp(state.heat, 0, 1);+ const meterX = TOWER_X + 12, meterTop = GROUND_Y - 22, meterH = 20;+ ctx.fillStyle = "#0b0b10";+ ctx.fillRect(meterX, meterTop, 4, meterH);+ ctx.fillStyle = state.jammed ? "#ff5a4a" : h > 0.6 ? "#ffb347" : "#2fd3b5";+ const fill = Math.round(meterH * h);+ ctx.fillRect(meterX, meterTop + meterH - fill, 4, fill);}-function drawCities(ctx: CanvasRenderingContext2D, state: DefenseState): void {- for (let i = 0; i < CITY_X.length; i += 1) {- const x = CITY_X[i] - 10;- if (state.cities[i]) {- ctx.fillStyle = "#3fb6d9";- drawSprite(ctx, CITY_SPRITES[i % CITY_SPRITES.length], x, GROUND_Y - 8);- // Lit windows, a fixed pattern per city.- ctx.fillStyle = "#ffe08a";- for (let k = 0; k < 6; k += 1) ctx.fillRect(x + 2 + ((k * 7 + i * 3) % 16), GROUND_Y - 4 + (k % 2) * 2, 1, 1);+function drawDomes(ctx: CanvasRenderingContext2D, state: DefenseState): void {+ for (let i = 0; i < DOME_X.length; i += 1) {+ const x = DOME_X[i];+ if (state.domes[i]) {+ ctx.fillStyle = "#7fe8ff";+ ctx.globalAlpha = 0.25;+ ctx.beginPath();+ ctx.arc(x, GROUND_Y, DOME_R, Math.PI, 0);+ ctx.closePath();+ ctx.fill();+ ctx.globalAlpha = 1;+ ctx.strokeStyle = "#a8f2ff";+ ctx.lineWidth = 1;+ ctx.beginPath();+ ctx.arc(x, GROUND_Y, DOME_R, Math.PI, 0);+ ctx.stroke();+ // Ribs and a few lit gardens inside.+ ctx.fillStyle = "#a8f2ff";+ ctx.fillRect(x, GROUND_Y - DOME_R, 1, DOME_R);+ ctx.fillRect(x - DOME_R + 1, GROUND_Y - 6, DOME_R * 2 - 2, 1);+ ctx.fillStyle = "#7ed957";+ for (let k = 0; k < 4; k += 1) ctx.fillRect(x - 8 + k * 5, GROUND_Y - 3, 3, 3);} else {- ctx.fillStyle = "#5a3328";- drawSprite(ctx, RUBBLE, x, GROUND_Y - 4);+ // A broken dome: a jagged stub of glass on a dark base.+ ctx.fillStyle = "#2a2932";+ ctx.fillRect(x - DOME_R, GROUND_Y - 2, DOME_R * 2, 2);+ ctx.fillStyle = "#4a6a74";+ for (let k = 0; k < 5; k += 1) ctx.fillRect(x - DOME_R + 2 + k * 5, GROUND_Y - 3 - ((k * 3 + i) % 4), 2, 2 + ((k * 3 + i) % 4));}}}-function drawCross(ctx: CanvasRenderingContext2D, x: number, y: number, size: number): void {- ctx.fillRect(x - size, y, size - 1, 1);- ctx.fillRect(x + 2, y, size - 1, 1);- ctx.fillRect(x, y - size, 1, size - 1);- ctx.fillRect(x, y + 2, 1, size - 1);+function drawReticle(ctx: CanvasRenderingContext2D, x: number, y: number, ready: boolean): void {+ ctx.strokeStyle = ready ? "#ffffff" : "#ff8a6a";+ ctx.lineWidth = 1;+ ctx.beginPath();+ ctx.arc(x + 0.5, y + 0.5, 5, 0, Math.PI * 2);+ ctx.stroke();+ ctx.fillStyle = ready ? "#ffffff" : "#ff8a6a";+ ctx.fillRect(x, y, 1, 1);+ ctx.fillRect(x - 9, y, 3, 1);+ ctx.fillRect(x + 7, y, 3, 1);+ ctx.fillRect(x, y - 9, 1, 3);+ ctx.fillRect(x, y + 7, 1, 3);}function draw(ctx: CanvasRenderingContext2D, state: DefenseState, info: RetroDrawInfo): void {- drawSky(ctx);- drawStars(ctx, STARS, info.time, info.reduced);+ drawSky(ctx, info);+ drawStars(ctx, STARS, info.time, info.reduced, "#bfe8e0");ctx.save();if (state.shake > 0 && !info.reduced) {ctx.translate(Math.round(Math.sin(info.time * 77) * state.shake * 6), Math.round(Math.cos(info.time * 91) * state.shake * 4));}- drawGround(ctx, state);- drawCities(ctx, state);- drawBatteries(ctx, state, info);+ drawGround(ctx);+ drawDomes(ctx, state);+ drawTower(ctx, state, info);- // Trails: incoming in red, ours in blue.+ // Shards: a magenta crystal with a short fading tail.ctx.lineWidth = 1;- ctx.strokeStyle = "#ff5a4a";- ctx.globalAlpha = 0.75;+ ctx.strokeStyle = "#ff5fd2";+ ctx.globalAlpha = 0.6;ctx.beginPath();- for (const w of state.warheads) {- if (!w.active) continue;- ctx.moveTo(w.ox, w.oy);- ctx.lineTo(w.x, w.y);+ for (const s of state.shards) {+ if (!s.active) continue;+ ctx.moveTo(s.x - s.vx * 0.35, s.y - s.vy * 0.35);+ ctx.lineTo(s.x, s.y);}ctx.stroke();- ctx.strokeStyle = "#5ab8ff";+ ctx.globalAlpha = 1;+ ctx.fillStyle = "#ffd6f5";+ for (const s of state.shards) {+ if (!s.active) continue;+ const x = Math.round(s.x), y = Math.round(s.y);+ ctx.fillRect(x, y - 2, 1, 5);+ ctx.fillRect(x - 1, y - 1, 3, 3);+ }++ // Our bolts: a gold beam from the tower tip, and a diamond where each will burst.+ ctx.strokeStyle = "#e0a93b";+ ctx.globalAlpha = 0.8;ctx.beginPath();- for (const m of state.missiles) {- if (!m.active) continue;- ctx.moveTo(m.ox, m.oy);- ctx.lineTo(m.x, m.y);+ for (const b of state.bolts) {+ if (!b.active) continue;+ ctx.moveTo(b.ox, b.oy);+ ctx.lineTo(b.x, b.y);}ctx.stroke();ctx.globalAlpha = 1;- ctx.fillStyle = "#fff4d0";- for (const w of state.warheads) if (w.active) ctx.fillRect(Math.round(w.x) - 1, Math.round(w.y) - 1, 2, 2);- for (const m of state.missiles) {- if (!m.active) continue;- ctx.fillStyle = "#e6f6ff";- ctx.fillRect(Math.round(m.x) - 1, Math.round(m.y) - 1, 2, 2);- ctx.fillStyle = "#5ab8ff";- // The target mark: a small x where the missile will burst.- const tx = Math.round(m.tx), ty = Math.round(m.ty);- for (let k = -2; k <= 2; k += 1) {- ctx.fillRect(tx + k, ty + k, 1, 1);- ctx.fillRect(tx + k, ty - k, 1, 1);- }+ for (const b of state.bolts) {+ if (!b.active) continue;+ ctx.fillStyle = "#fff4c8";+ ctx.fillRect(Math.round(b.x) - 1, Math.round(b.y) - 1, b.r > BOLT_R ? 3 : 2, b.r > BOLT_R ? 3 : 2);+ ctx.fillStyle = "#e0a93b";+ const tx = Math.round(b.tx), ty = Math.round(b.ty);+ ctx.fillRect(tx, ty - 3, 1, 1);+ ctx.fillRect(tx - 3, ty, 1, 1);+ ctx.fillRect(tx + 3, ty, 1, 1);+ ctx.fillRect(tx, ty + 3, 1, 1);}- const f = state.flyer;+ const f = state.seeder;if (f.active) {- ctx.fillStyle = f.kind === 0 ? "#c8d0e0" : "#ffd35a";- if (f.kind === 0) drawSprite(ctx, BOMBER, f.x - 8, f.y - 3, 1, f.dir < 0);- else drawSprite(ctx, SATELLITE, f.x - 6, f.y - 2);- }-- // Blasts: a warm outer ball with a hot core; steady colours (no strobing).- for (const b of state.blasts) {- if (!b.active) continue;- const r = blastRadius(b.age, b.r);- if (r <= 0.5) continue;- ctx.fillStyle = b.friendly ? "#ff9f43" : "#ff5a3a";- ctx.globalAlpha = 0.85;+ ctx.fillStyle = "#9b7bff";+ const bob = info.reduced ? 0 : Math.round(Math.sin(f.t * 4) * 1.5);+ drawSprite(ctx, SEEDER, f.x - 5, f.y - 3 + bob);+ ctx.fillStyle = "#d8ccff";+ ctx.fillRect(Math.round(f.x) - 2, Math.round(f.y) - 1 + bob, 1, 1);+ ctx.fillRect(Math.round(f.x) + 2, Math.round(f.y) - 1 + bob, 1, 1);+ }++ // Rings: a bright edge around a soft tinted disc; steady colours (no strobing).+ for (const r of state.rings) {+ if (!r.active) continue;+ const rad = ringRadius(r.age, r.r);+ if (rad <= 0.5) continue;+ ctx.fillStyle = r.friendly ? "#2fd3b5" : "#ff7a3a";+ ctx.globalAlpha = 0.22;ctx.beginPath();- ctx.arc(b.x, b.y, r, 0, Math.PI * 2);+ ctx.arc(r.x, r.y, rad, 0, Math.PI * 2);ctx.fill();- ctx.fillStyle = b.friendly ? "#fff3c4" : "#ffd27a";+ ctx.globalAlpha = 0.95;+ ctx.strokeStyle = r.friendly ? "#c8fff2" : "#ffc27a";+ ctx.lineWidth = 2;ctx.beginPath();- ctx.arc(b.x, b.y, r * 0.55, 0, Math.PI * 2);- ctx.fill();+ ctx.arc(r.x, r.y, rad, 0, Math.PI * 2);+ ctx.stroke();ctx.globalAlpha = 1;}+ ctx.lineWidth = 1;drawParticles(ctx, state.particles);ctx.restore();- // Crosshair; on the attract screen it drifts lazily across the sky.+ // The reticle; on the attract screen it drifts lazily across the sky.let ax = state.cx, ay = state.cy;if (info.idle && state.elapsed === 0 && !info.reduced) {ax = WIDTH / 2 + Math.sin(info.time * 0.7) * 90;ay = 100 + Math.sin(info.time * 1.1) * 40;}- ctx.fillStyle = "#ffffff";- drawCross(ctx, Math.round(ax), Math.round(ay), 6);+ drawReticle(ctx, Math.round(ax), Math.round(ay), canFire(state, false));- // Score, wave and banked cities.- ctx.fillStyle = "#ffcf5a";+ // Score, wave and spare domes.+ ctx.fillStyle = "#e0a93b";drawNumber(ctx, state.score, 6, 5, 2);- ctx.fillStyle = "#ff8a6a";+ ctx.fillStyle = "#2fd3b5";drawNumber(ctx, state.wave, WIDTH - 6, 5, 2, "right");- ctx.fillStyle = "#3fb6d9";- for (let i = 0; i < Math.min(state.banked, 5); i += 1) ctx.fillRect(WIDTH - 10 - i * 6, 18, 4, 3);+ ctx.fillStyle = "#a8f2ff";+ for (let i = 0; i < Math.min(state.spares, 5); i += 1) {+ ctx.beginPath();+ ctx.arc(WIDTH - 9 - i * 9, 22, 3, Math.PI, 0);+ ctx.fill();+ }if (state.phase === "ready") {- ctx.fillStyle = "#ffcf5a";+ ctx.fillStyle = "#e0a93b";drawNumber(ctx, state.wave, WIDTH / 2, 80, 5, "center");+ // The multiplier as that many small diamonds under the wave number.const mult = multiplier(state.wave);- // "×n" as a pixel cross and the digit.- ctx.fillStyle = "#ff8a6a";- for (let k = 0; k < 5; k += 1) {- ctx.fillRect(WIDTH / 2 - 10 + k * 2, 112 + k * 2, 2, 2);- ctx.fillRect(WIDTH / 2 - 2 - k * 2, 112 + k * 2, 2, 2);+ ctx.fillStyle = "#2fd3b5";+ for (let k = 0; k < mult; k += 1) {+ const x = WIDTH / 2 - (mult - 1) * 6 + k * 12;+ ctx.fillRect(x - 1, 112, 3, 1);+ ctx.fillRect(x - 2, 113, 5, 1);+ ctx.fillRect(x - 1, 114, 3, 1);}- drawNumber(ctx, mult, WIDTH / 2 + 4, 112, 2);} else if (state.phase === "bonus") {- // The tally: missiles left and cities saved, each with its points.+ // The tally: domes saved with their points, and the full-colony star when earned.const mult = multiplier(state.wave);- ctx.fillStyle = "#7ff0ff";- ctx.fillRect(WIDTH / 2 - 60, 84, 2, 5);- drawNumber(ctx, state.bonusAmmo, WIDTH / 2 - 50, 84, 1);- ctx.fillStyle = "#ffcf5a";- drawNumber(ctx, state.bonusAmmo * AMMO_BONUS * mult, WIDTH / 2 + 60, 84, 1, "right");- ctx.fillStyle = "#3fb6d9";- ctx.fillRect(WIDTH / 2 - 62, 100, 6, 5);- drawNumber(ctx, state.bonusCities, WIDTH / 2 - 50, 100, 1);- ctx.fillStyle = "#ffcf5a";- drawNumber(ctx, state.bonusCities * CITY_BONUS * mult, WIDTH / 2 + 60, 100, 1, "right");+ ctx.fillStyle = "#a8f2ff";+ ctx.beginPath();+ ctx.arc(WIDTH / 2 - 56, 90, 5, Math.PI, 0);+ ctx.fill();+ drawNumber(ctx, state.bonusDomes, WIDTH / 2 - 44, 84, 1);+ ctx.fillStyle = "#e0a93b";+ drawNumber(ctx, state.bonusDomes * DOME_BONUS * mult, WIDTH / 2 + 60, 84, 1, "right");+ if (state.bonusFull) {+ ctx.fillStyle = "#2fd3b5";+ ctx.fillRect(WIDTH / 2 - 57, 100, 3, 7);+ ctx.fillRect(WIDTH / 2 - 59, 102, 7, 3);+ ctx.fillStyle = "#e0a93b";+ drawNumber(ctx, FULL_COLONY_BONUS * mult, WIDTH / 2 + 60, 100, 1, "right");+ }}}diff --git a/dodaios/ui/web/frontend/src/components/society/arcade/games/mazeMuncher.test.ts b/dodaios/ui/web/frontend/src/components/society/arcade/games/mazeMuncher.test.tsindex 39184f8d78..566fe7e1c0 100644--- a/dodaios/ui/web/frontend/src/components/society/arcade/games/mazeMuncher.test.ts+++ b/dodaios/ui/web/frontend/src/components/society/arcade/games/mazeMuncher.test.ts@@ -1,8 +1,9 @@import { describe, expect, it } from "vitest";import { RETRO_STEP, idleInput, seededRandom, type RetroInput } from "../retroGame";import mazeMuncher, {- BONUS_X, BONUS_Y, CHAIN_POINTS, CLEAR_TIME, DOT_POINTS, DOWN, DYING_TIME, EXIT_X, EXIT_Y, LEFT, MAZE, MAZE_H, MAZE_W, NONE, ORB_POINTS,- PLAYER_START_X, PLAYER_START_Y, READY_TIME, RIGHT, UP, bugTarget, createMaze, frightDuration, isOpen, type MazeState,+ BONUS_X, BONUS_Y, CHAIN_POINTS, CLEAR_TIME, DOT_POINTS, DOWN, DYING_TIME, ECHO, EXIT_X, EXIT_Y, HUNT_TIME, LEFT, MAZE, MAZE_H, MAZE_W,+ NONE, ORB_POINTS, PATROL_TIME, PEN_Y, PLAYER_START_X, PLAYER_START_Y, READY_TIME, REBOOT_TIME, RIGHT, ROAMER, TRACKER, UP, WARDEN,+ bugTarget, createMaze, frightDuration, isOpen, patrolling, type MazeState,} from "./mazeMuncher";/** A 2D context stand-in: every call is a no-op, texts are recorded, non-finite numbers are flagged. */@@ -149,7 +150,7 @@ describe("maze muncher: play", () => {expect(s.dots[1 * MAZE_W + 2]).toBe(0);});- it("an orb frightens the bugs, and eaten bugs chain their points and go home", () => {+ it("an orb shorts the bugs out, and zapped bugs chain rising points and reboot in the pen", () => {const s = quiet();const [, a, b] = s.bugs;a.mode = "active"; a.x = 9; a.y = 19; a.dir = LEFT;@@ -164,16 +165,19 @@ describe("maze muncher: play", () => {a.x = s.player.x; a.y = s.player.y;run(s, idleInput(), RETRO_STEP);- expect(a.mode).toBe("eaten");+ expect(a.mode).toBe("rebooting");+ // Straight back into the pen: no trip home through the maze.+ expect([a.x, a.y]).toEqual([10, PEN_Y]);expect(s.score).toBe(ORB_POINTS + CHAIN_POINTS[0]);run(s, idleInput(), 0.6);b.x = s.player.x; b.y = s.player.y;run(s, idleInput(), RETRO_STEP);- expect(b.mode).toBe("eaten");+ expect(b.mode).toBe("rebooting");expect(s.score - ORB_POINTS - CHAIN_POINTS[0]).toBeGreaterThanOrEqual(CHAIN_POINTS[1]);+ expect(CHAIN_POINTS).toEqual([150, 300, 450, 600]);- // The eyes find their way back into the pen and come out again as a normal bug.- run(s, idleInput(), 6);+ // After its reboot the bug comes out again as a normal bug.+ run(s, idleInput(), REBOOT_TIME + 2);expect(["leaving", "active"]).toContain(a.mode);expect(a.frightened).toBe(false);});@@ -245,33 +249,65 @@ describe("maze muncher: play", () => {expect(s.score - score).toBeGreaterThanOrEqual(100);});- it("gives the four bugs four different chase targets", () => {+ it("gives each bug its own habit while it hunts", () => {const s = quiet();- s.modeIndex = 1; // chase- place(s, 10, 15, LEFT);- s.bugs[0].x = 10; s.bugs[0].y = 7;+ s.roundTime = 0; // every bug is hunting at the start of a round+ place(s, 4, 15, LEFT);const out = { x: 0, y: 0 };- const targets = s.bugs.map((b) => {- b.x = b.index === 0 ? 10 : 18; b.y = b.index === 0 ? 7 : 3;- bugTarget(s, b, out);- return `${out.x},${out.y}`;- });- expect(targets[0]).toBe("10,15");- expect(targets[1]).toBe("6,15");- expect(new Set(targets.slice(0, 3)).size).toBe(3);- // The drifter chases from afar but backs off up close.- expect(targets[3]).toBe("10,15");- const drifter = s.bugs[3];- drifter.x = 9; drifter.y = 15;- bugTarget(s, drifter, out);- expect(`${out.x},${out.y}`).not.toBe("10,15");+ const [tracker, warden, echo, roamer] = s.bugs;+ for (const b of s.bugs) { b.x = 18; b.y = 3; }+ expect(s.bugs.some((b) => patrolling(s, b))).toBe(false);++ // The tracker goes straight for the drone.+ expect(bugTarget(s, tracker, out)).toBe(true);+ expect([out.x, out.y]).toEqual([4, 15]);+ // The warden guards the power orb left nearest the drone (bottom left), then the next one.+ expect(bugTarget(s, warden, out)).toBe(true);+ expect([out.x, out.y]).toEqual([1, 15]);+ s.dots[15 * MAZE_W + 1] = 0;+ bugTarget(s, warden, out);+ expect([out.x, out.y]).toEqual([1, 2]);+ // The echo shadows the drone's mirror image.+ bugTarget(s, echo, out);+ expect([out.x, out.y]).toEqual([MAZE_W - 1 - 4, 15]);+ // The roamer wanders while the drone is far, and pounces up close.+ expect(bugTarget(s, roamer, out)).toBe(false);+ roamer.x = 6; roamer.y = 15;+ expect(bugTarget(s, roamer, out)).toBe(true);+ expect([out.x, out.y]).toEqual([4, 15]);+ expect([TRACKER, WARDEN, ECHO, ROAMER]).toEqual([0, 1, 2, 3]);+ });++ it("each bug takes its own patrol break, never all at once", () => {+ const s = quiet();+ const cycle = HUNT_TIME + PATROL_TIME;+ for (let t = 0; t < cycle * 2; t += 0.25) {+ s.roundTime = t;+ const resting = s.bugs.filter((b) => patrolling(s, b)).length;+ expect(resting, `at ${t}s`).toBeLessThan(s.bugs.length);+ }+ // A patrolling bug heads for its own home block, not for the drone.+ s.roundTime = HUNT_TIME + 0.5;+ const tracker = s.bugs[0];+ expect(patrolling(s, tracker)).toBe(true);+ const out = { x: 0, y: 0 };+ place(s, 4, 15, LEFT);+ bugTarget(s, tracker, out);+ expect([out.x, out.y]).not.toEqual([4, 15]);+ expect(isOpen(out.x, out.y)).toBe(true);});it("the bugs leave the pen and roam without ever standing in a wall", () => {const s = createMaze();for (let t = 0; t < 30; t += RETRO_STEP) {mazeMuncher.step(s, idleInput(), RETRO_STEP, random);- if (s.phase === "dying") { s.phase = "play"; s.lives = 3; }+ if (s.phase === "dying") {+ // Keep the round going: lift the bug that made the catch off the drone, so it does not repeat every step.+ s.phase = "play"; s.lives = 3;+ for (const b of s.bugs) {+ if (b.mode === "active" && Math.abs(b.x - s.player.x) < 1 && Math.abs(b.y - s.player.y) < 1) { b.x = EXIT_X; b.y = EXIT_Y; b.dir = LEFT; }+ }+ }for (const b of s.bugs) {if (b.mode !== "active") continue;expect(isOpen(Math.round(b.x), Math.round(b.y)), `bug ${b.index} at ${b.x},${b.y}`).toBe(true);@@ -291,7 +327,8 @@ describe("maze muncher: play", () => {mazeMuncher.draw(ctx, s, { time: 3, reduced: false, idle: false });s.frightTimer = 1; for (const b of s.bugs) b.frightened = true;s.bonusTimer = 3;- s.bugs[0].mode = "eaten";+ s.bugs[0].mode = "rebooting";+ s.bugs[0].reboot = REBOOT_TIME / 2;mazeMuncher.draw(ctx, s, { time: 4, reduced: false, idle: false });mazeMuncher.draw(ctx, s, { time: 4, reduced: true, idle: false });s.phase = "dying"; s.phaseTimer = DYING_TIME / 2;diff --git a/dodaios/ui/web/frontend/src/components/society/arcade/games/mazeMuncher.ts b/dodaios/ui/web/frontend/src/components/society/arcade/games/mazeMuncher.tsindex 6fdf8ebb33..613113f3cc 100644--- a/dodaios/ui/web/frontend/src/components/society/arcade/games/mazeMuncher.ts+++ b/dodaios/ui/web/frontend/src/components/society/arcade/games/mazeMuncher.ts@@ -1,17 +1,20 @@/*** "Maze Muncher": the maze-chase cabinet.*- * A round chomper clears a symmetric maze of dots while four "glitch bugs"- * (little robot beetles) hunt it. The maze is this game's own: 21 × 21 tiles- * with a wrap tunnel through the middle row and a pen in the centre the bugs- * start in and return to. Turns are buffered: a direction pressed before a- * junction is taken at the junction, a reversal is taken at once.+ * A little mint scrubber drone vacuums a symmetric maze of data dots while+ * four violet "glitch bugs" (robot beetles) hunt it. The maze is this game's+ * own: 21 × 21 tiles with a wrap tunnel through the middle row and a pen in+ * the centre the bugs start in. Turns are buffered: a direction pressed before+ * a junction is taken at the junction, a reversal is taken at once.*- * Each bug has its own targeting personality (hunter, ambusher, flanker,- * drifter) and they alternate scatter and chase phases on a schedule. Eating- * one of the four power orbs turns them vulnerable for a while (shorter on- * later levels); eaten bugs chain 200 / 400 / 800 / 1600 and race back to the- * pen as a pair of eyes. A bonus gem shows up twice per level. Clearing every+ * Each bug has its own habit: the tracker heads straight for the drone, the+ * warden guards whichever power orb is still left nearest the drone, the echo+ * shadows the drone's mirror image across the maze, and the roamer wanders+ * until the drone comes within reach, then pounces. Every bug takes its own+ * short patrol break back to its home block now and then, staggered so they+ * never all let up at once. Eating a power orb shorts the bugs out for a while+ * (shorter on later levels); zapped bugs pay 150 more than the one before and+ * reboot inside the pen. A bonus gem shows up twice per level. Clearing every* dot starts the next, faster level; three lives.** Positions are in tile units with tile centres on integer coordinates;@@ -58,37 +61,47 @@ const DY = [-1, 0, 1, 0];const OPPOSITE = [DOWN, RIGHT, UP, LEFT];export const PLAYER_START_X = 10, PLAYER_START_Y = 15;-/** The tile just above the pen door: bugs leave from here and eyes head back to it. */+/** The tile just above the pen door: bugs leave the pen from here. */export const EXIT_X = 10, EXIT_Y = 7;-const PEN_Y = 9;+export const PEN_Y = 9;const PEN_X = [10, 10, 9, 11];export const BONUS_X = 10, BONUS_Y = 11;const TUNNEL_ROW = 9;-export const DOT_POINTS = 10;-export const ORB_POINTS = 50;-export const CHAIN_POINTS: readonly number[] = [200, 400, 800, 1600];-export const BONUS_POINTS: readonly number[] = [100, 300, 500, 700, 1000, 2000, 3000, 5000];+export const DOT_POINTS = 5;+export const ORB_POINTS = 25;+/** Bugs zapped during one power orb: each pays 150 more than the one before. */+export const CHAIN_POINTS: readonly number[] = [150, 300, 450, 600];+export const BONUS_POINTS: readonly number[] = [250, 500, 750, 1000, 1500, 2000, 2500, 3000];export const START_LIVES = 3;export const READY_TIME = 1.6;export const DYING_TIME = 1.4;export const CLEAR_TIME = 2;-const EAT_PAUSE = 0.5;+const EAT_PAUSE = 0.35;const BONUS_TIME = 9;-/** Scatter and chase alternate with these durations (seconds); the last chase lasts forever. */-const SCHEDULE: readonly number[] = [7, 20, 7, 20, 5, 20, 5, Infinity];+/** Seconds a zapped bug spends rebooting in the pen before it comes out again. */+export const REBOOT_TIME = 3;+/** Each bug hunts for HUNT_TIME, then patrols its home block for PATROL_TIME; the cycles are staggered. */+export const HUNT_TIME = 12;+export const PATROL_TIME = 4;+const CYCLE_OFFSET = [0, 3, 6, 9];const RELEASE_TIME = [0, 1, 5, 9];const RELEASE_DOTS = [0, 0, 25, 50];-/** Each bug's scatter corner (outside the maze, so they circle the nearest block). */-const CORNER_X = [19, 1, 20, 0];-const CORNER_Y = [-2, -2, 22, 22];+/** Each bug's home tile, inside the maze, that it patrols around on a break. */+const HOME_X = [17, 3, 17, 3];+const HOME_Y = [3, 3, 17, 17];+/** The roamer pounces once the drone is this close (squared tiles). */+const POUNCE_DIST2 = 25;const EPS = 1e-6;-export type BugMode = "pen" | "leaving" | "active" | "eaten" | "entering";+/** Bug indices by habit. */+export const TRACKER = 0, WARDEN = 1, ECHO = 2, ROAMER = 3;++export type BugMode = "pen" | "leaving" | "active" | "rebooting";export interface Mover { x: number; y: number; dir: number }-export interface Chomper extends Mover {+export interface Probe extends Mover {/** The buffered direction, taken at the next centre where it is open. */want: number;/** Distance travelled, for the chewing animation. */@@ -98,7 +111,10 @@ export interface Chomper extends Mover {export interface Bug extends Mover {index: number;mode: BugMode;+ /** Shorted out by a power orb: slow, aimless and safe to zap. */frightened: boolean;+ /** Seconds of reboot left while `mode` is "rebooting". */+ reboot: number;}export type MazePhase = "ready" | "play" | "dying" | "clear";@@ -110,7 +126,7 @@ export interface MazeState {dots: Uint8Array;dotsLeft: number;totalDots: number;- player: Chomper;+ player: Probe;bugs: Bug[];score: number;lives: number;@@ -118,13 +134,10 @@ export interface MazeState {over: boolean;phase: MazePhase;phaseTimer: number;- /** Index into SCHEDULE (even = scatter, odd = chase) and seconds spent in it. */- modeIndex: number;- modeTimer: number;frightTimer: number;- /** Bugs eaten during the current power orb. */+ /** Bugs zapped during the current power orb. */chain: number;- /** Freeze after eating a bug, while its points show. */+ /** Short freeze after zapping a bug, while its points show. */eatPause: number;roundTime: number;dotsThisRound: number;@@ -190,10 +203,11 @@ function resetRound(s: MazeState): void {p.x = PLAYER_START_X; p.y = PLAYER_START_Y; p.dir = NONE; p.want = LEFT; p.chew = 0;for (const b of s.bugs) {b.frightened = false;+ b.reboot = 0;if (b.index === 0) { b.x = EXIT_X; b.y = EXIT_Y; b.dir = LEFT; b.mode = "active"; }else { b.x = PEN_X[b.index]; b.y = PEN_Y; b.dir = UP; b.mode = "pen"; }}- s.modeIndex = 0; s.modeTimer = 0; s.frightTimer = 0; s.chain = 0; s.eatPause = 0;+ s.frightTimer = 0; s.chain = 0; s.eatPause = 0;s.roundTime = 0; s.dotsThisRound = 0; s.bonusTimer = 0;s.phase = "ready"; s.phaseTimer = READY_TIME;}@@ -202,9 +216,9 @@ export function createMaze(): MazeState {const s: MazeState = {dots: new Uint8Array(MAZE_W * MAZE_H), dotsLeft: 0, totalDots: 0,player: { x: 0, y: 0, dir: NONE, want: LEFT, chew: 0 },- bugs: [0, 1, 2, 3].map((index) => ({ index, x: 0, y: 0, dir: UP, mode: "pen" as BugMode, frightened: false })),+ bugs: [0, 1, 2, 3].map((index) => ({ index, x: 0, y: 0, dir: UP, mode: "pen" as BugMode, frightened: false, reboot: 0 })),score: 0, lives: START_LIVES, level: 1, over: false, phase: "ready", phaseTimer: READY_TIME,- modeIndex: 0, modeTimer: 0, frightTimer: 0, chain: 0, eatPause: 0, roundTime: 0, dotsThisRound: 0,+ frightTimer: 0, chain: 0, eatPause: 0, roundTime: 0, dotsThisRound: 0,bonusTimer: 0, bonusShown: 0,popups: [0, 1, 2].map(() => ({ x: 0, y: 0, value: 0, time: 0 })),sparks: sparkPool(48), ticks: 0,@@ -214,31 +228,43 @@ export function createMaze(): MazeState {return s;}-function scatterPhase(s: MazeState): boolean {- return s.modeIndex % 2 === 0;+/** Whether this bug is on its patrol break right now (each bug's cycle is offset from the others). */+export function patrolling(s: MazeState, b: Bug): boolean {+ const cycle = HUNT_TIME + PATROL_TIME;+ const t = (((s.roundTime + CYCLE_OFFSET[b.index]) % cycle) + cycle) % cycle;+ return t >= HUNT_TIME;}-/** Where a bug is heading right now; its personality decides in chase phases. */-export function bugTarget(s: MazeState, b: Bug, out: { x: number; y: number }): void {- if (b.mode === "eaten") { out.x = EXIT_X; out.y = EXIT_Y; return; }+/**+ * Where a bug is heading right now; its habit decides while it hunts. Returns+ * false when the bug has no target and wanders (the roamer while the drone is far).+ */+export function bugTarget(s: MazeState, b: Bug, out: { x: number; y: number }): boolean {const p = s.player;const px = Math.round(p.x), py = Math.round(p.y);- const pd = p.dir >= 0 ? p.dir : p.want >= 0 ? p.want : LEFT;- if (scatterPhase(s)) { out.x = CORNER_X[b.index]; out.y = CORNER_Y[b.index]; return; }+ if (patrolling(s, b)) { out.x = HOME_X[b.index]; out.y = HOME_Y[b.index]; return true; }switch (b.index) {- case 0: // Hunter: straight at the chomper.- out.x = px; out.y = py; return;- case 1: // Ambusher: four tiles ahead of it.- out.x = px + DX[pd] * 4; out.y = py + DY[pd] * 4; return;- case 2: { // Flanker: mirror the hunter through the point two tiles ahead, closing a pincer.- const ax = px + DX[pd] * 2, ay = py + DY[pd] * 2;- const h = s.bugs[0];- out.x = ax * 2 - Math.round(h.x); out.y = ay * 2 - Math.round(h.y); return;+ case TRACKER:+ out.x = px; out.y = py; return true;+ case WARDEN: {+ // Guard the power orb still left nearest the drone; with none left, hunt it directly.+ let best = Infinity;+ out.x = px; out.y = py;+ for (let i = 0; i < s.dots.length; i += 1) {+ if (s.dots[i] !== 2) continue;+ const ox = i % MAZE_W, oy = Math.floor(i / MAZE_W);+ const d = (ox - px) * (ox - px) + (oy - py) * (oy - py);+ if (d < best) { best = d; out.x = ox; out.y = oy; }+ }+ return true;}- default: { // Drifter: chases from afar, loses its nerve up close.+ case ECHO:+ // The drone's mirror image across the maze's centre line.+ out.x = MAZE_W - 1 - px; out.y = py; return true;+ default: {const dx = b.x - p.x, dy = b.y - p.y;- if (dx * dx + dy * dy > 64) { out.x = px; out.y = py; }- else { out.x = CORNER_X[3]; out.y = CORNER_Y[3]; }+ if (dx * dx + dy * dy > POUNCE_DIST2) return false;+ out.x = px; out.y = py; return true;}}}@@ -246,14 +272,12 @@ export function bugTarget(s: MazeState, b: Bug, out: { x: number; y: number }):const target = { x: 0, y: 0 };function chooseBugDir(s: MazeState, b: Bug, random: () => number): number {- // Eyes stop on the tile above the door; the pen script takes them in from there.- if (b.mode === "eaten" && Math.round(b.x) === EXIT_X && Math.round(b.y) === EXIT_Y) return NONE;const back = b.dir >= 0 ? OPPOSITE[b.dir] : NONE;let count = 0;for (let d = 0; d < 4; d += 1) if (d !== back && openDir(b, d)) count += 1;if (count === 0) return back >= 0 && openDir(b, back) ? back : NONE;- if (b.frightened) {- // Panicking bugs pick a random open way at every junction.+ if (b.frightened || !bugTarget(s, b, target)) {+ // Shorted-out bugs, and a roamer with nothing in reach, pick a random open way at every junction.let pick = Math.floor(random() * count);for (let d = 0; d < 4; d += 1) {if (d === back || !openDir(b, d)) continue;@@ -261,7 +285,6 @@ function chooseBugDir(s: MazeState, b: Bug, random: () => number): number {pick -= 1;}}- bugTarget(s, b, target);let best = NONE, bestDist = Infinity;const bx = Math.round(b.x), by = Math.round(b.y);for (let d = 0; d < 4; d += 1) {@@ -273,7 +296,7 @@ function chooseBugDir(s: MazeState, b: Bug, random: () => number): number {return best;}-function choosePlayerDir(p: Chomper): number {+function choosePlayerDir(p: Probe): number {if (p.want >= 0 && openDir(p, p.want)) return p.want;if (p.dir >= 0 && openDir(p, p.dir)) return p.dir;return NONE;@@ -288,7 +311,7 @@ function advance(s: MazeState, m: Mover, dist: number, bug: Bug | null, random:for (let guard = 0; dist > EPS && guard < 8; guard += 1) {if (atCentre(m)) {m.x = Math.round(m.x); m.y = Math.round(m.y);- const dir = bug ? chooseBugDir(s, bug, random) : choosePlayerDir(m as Chomper);+ const dir = bug ? chooseBugDir(s, bug, random) : choosePlayerDir(m as Probe);if (dir < 0) { if (!bug) m.dir = NONE; return moved; }m.dir = dir;}@@ -340,7 +363,7 @@ function held(input: RetroInput, dir: number): boolean {return dir === UP ? input.up : dir === LEFT ? input.left : dir === DOWN ? input.down : input.right;}-function readInput(p: Chomper, input: RetroInput): void {+function readInput(p: Probe, input: RetroInput): void {const pr = input.pressed;if (pr.up) p.want = UP;else if (pr.left) p.want = LEFT;@@ -371,7 +394,7 @@ function eatDots(s: MazeState, random: () => number): void {b.frightened = true;if (b.dir >= 0) b.dir = OPPOSITE[b.dir];}- burst(s, tx, ty, "#ffd23f", 10, random);+ burst(s, tx, ty, PROBE_COLOR, 10, random);} else {s.score += DOT_POINTS;}@@ -403,12 +426,9 @@ function moveBug(s: MazeState, b: Bug, dt: number, random: () => number): void {if (glide(b, EXIT_X, EXIT_Y, step)) { b.mode = "active"; b.dir = LEFT; b.frightened = false; }return;}- case "entering":- if (glide(b, EXIT_X, PEN_Y, 6 * dt)) b.mode = "leaving";- return;- case "eaten":- advance(s, b, 14 * dt, b, random);- if (Math.abs(b.x - EXIT_X) < 0.15 && Math.abs(b.y - EXIT_Y) < 0.15) { b.x = EXIT_X; b.y = EXIT_Y; b.mode = "entering"; }+ case "rebooting":+ b.reboot -= dt;+ if (b.reboot <= 0) { b.reboot = 0; b.mode = "leaving"; }return;default: {const speed = inTunnel(b) ? 3.6 : b.frightened ? 4.2 : 6.8 * k;@@ -426,11 +446,14 @@ function collide(s: MazeState, random: () => number): void {const points = CHAIN_POINTS[Math.min(s.chain, CHAIN_POINTS.length - 1)];s.chain += 1;s.score += points;+ popup(s, b.x, b.y, points);+ burst(s, b.x, b.y, BUG_COLORS[b.index], 14, random);+ // The zapped bug drops out of the maze and reboots in its pen slot.b.frightened = false;- b.mode = "eaten";+ b.mode = "rebooting";+ b.reboot = REBOOT_TIME;+ b.x = PEN_X[b.index]; b.y = PEN_Y; b.dir = UP;s.eatPause = EAT_PAUSE;- popup(s, b.x, b.y, points);- burst(s, b.x, b.y, "#3de8ff", 10, random);} else {s.lives -= 1;s.phase = "dying";@@ -450,7 +473,7 @@ export function stepMaze(s: MazeState, input: RetroInput, dt: number, random: ()if (s.phase !== "play") {s.phaseTimer -= dt;if (s.phase === "dying" && s.phaseTimer < DYING_TIME * 0.25 && s.phaseTimer + dt >= DYING_TIME * 0.25) {- burst(s, s.player.x, s.player.y, "#ffd23f", 16, random);+ burst(s, s.player.x, s.player.y, PROBE_COLOR, 16, random);}if (s.phaseTimer > 0) return;if (s.phase === "dying") {@@ -473,14 +496,6 @@ export function stepMaze(s: MazeState, input: RetroInput, dt: number, random: ()if (s.frightTimer > 0) {s.frightTimer -= dt;if (s.frightTimer <= 0) { s.frightTimer = 0; for (const b of s.bugs) b.frightened = false; }- } else {- s.modeTimer += dt;- if (s.modeTimer >= SCHEDULE[s.modeIndex]) {- s.modeTimer = 0;- s.modeIndex = Math.min(SCHEDULE.length - 1, s.modeIndex + 1);- // A change of phase turns every bug around, the classic tell.- for (const b of s.bugs) if (b.mode === "active" && b.dir >= 0) b.dir = OPPOSITE[b.dir];- }}const p = s.player;@@ -523,8 +538,12 @@ const WALL_SEGMENTS: number[] = (() => {return out;})();-const BUG_COLORS = ["#ff4d5e", "#ff7ad9", "#3de8ff", "#ffa13d"];-const BONUS_COLORS = ["#ff4d5e", "#ffa13d", "#ffd23f", "#5dea6a", "#3de8ff", "#4a7dff", "#b06bff", "#ffffff"];+/** One violet family for all four bugs; they differ by shade and by the shape of their crest. */+const BUG_COLORS = ["#b48cff", "#8f6bff", "#d4b2ff", "#7a5ae6"];+const SHORTED = "#59606e";+const PROBE_COLOR = "#5ef2c2";+const WALL_GOLD = "#b8933a";+const BONUS_COLORS = ["#5ef2c2", "#e9b949", "#9ad8ff", "#f08ad0", "#c7f06a", "#ffffff", "#ffb48a", "#d4b2ff"];function bonusColor(level: number): string {return BONUS_COLORS[Math.min(level - 1, BONUS_COLORS.length - 1)];@@ -543,21 +562,42 @@ function drawGem(ctx: CanvasRenderingContext2D, cx: number, cy: number, r: numbectx.fill();}-/** The chomper: a disc with a mouth wedge facing its direction. `open` is the half-angle in radians. */-function drawChomper(ctx: CanvasRenderingContext2D, cx: number, cy: number, r: number, dir: number, open: number): void {- const facing = dir === UP ? -Math.PI / 2 : dir === LEFT ? Math.PI : dir === DOWN ? Math.PI / 2 : 0;- ctx.fillStyle = "#ffd23f";+/**+ * The scrubber drone: a squat mint hexagon with a dark sensor stripe and two+ * intake prongs at the front that open and close (`open` 0..1). `scale`+ * shrinks it when it shorts out.+ */+function drawProbe(ctx: CanvasRenderingContext2D, cx: number, cy: number, r: number, dir: number, open: number, scale = 1): void {+ if (scale <= 0.02) return;+ const fx = dir >= 0 ? DX[dir] : -1, fy = dir >= 0 ? DY[dir] : 0;+ // Side axis, perpendicular to the facing.+ const sx = -fy, sy = fx;+ const R = r * scale;+ ctx.fillStyle = PROBE_COLOR;ctx.beginPath();- if (open >= Math.PI - 0.01) return;- ctx.moveTo(cx, cy);- ctx.arc(cx, cy, r, facing + open, facing + Math.PI * 2 - open);+ for (let i = 0; i < 6; i += 1) {+ const a = (Math.PI / 3) * i + Math.PI / 6;+ const x = cx + Math.cos(a) * R, y = cy + Math.sin(a) * R * 0.85;+ if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);+ }ctx.closePath();ctx.fill();- // A little eye, set back from the mouth.- const ex = cx + Math.cos(facing - Math.PI / 2 - 0.5) * r * 0.5;- const ey = cy + Math.sin(facing - Math.PI / 2 - 0.5) * r * 0.5;- ctx.fillStyle = "#2b1f05";- ctx.fillRect(Math.round(ex - 1), Math.round(ey - 1), 2, 2);+ // Intake prongs, splaying open as it vacuums.+ const spread = (0.6 + open * 1.6) * scale;+ ctx.strokeStyle = PROBE_COLOR;+ ctx.lineWidth = 1;+ ctx.beginPath();+ for (const side of [-1, 1]) {+ const bx = cx + fx * R * 0.7 + sx * side * R * 0.5, by = cy + fy * R * 0.7 + sy * side * R * 0.5;+ ctx.moveTo(bx, by);+ ctx.lineTo(bx + fx * R * 0.7 + sx * side * spread, by + fy * R * 0.7 + sy * side * spread);+ }+ ctx.stroke();+ // The sensor stripe across its face, a lit pixel on the leading side.+ ctx.fillStyle = "#0e2a24";+ ctx.fillRect(Math.round(cx - R * 0.6), Math.round(cy - 1), Math.max(1, Math.round(R * 1.2)), 2);+ ctx.fillStyle = "#eafff8";+ ctx.fillRect(Math.round(cx + fx * R * 0.35 - 0.5), Math.round(cy - 1 + fy * 0.5), 1, 1);}/** A glitch bug: domed robot beetle with antennae, a visor and scuttling legs. */@@ -565,18 +605,32 @@ function drawBug(ctx: CanvasRenderingContext2D, s: MazeState, b: Bug, info: Retrconst bob = b.mode === "pen" && !info.reduced ? Math.sin(info.time * 5 + b.index * 2) * 1.5 : 0;const cx = tileCx(b.x), cy = tileCy(b.y) + bob;const lookX = b.dir >= 0 ? DX[b.dir] : 0, lookY = b.dir >= 0 ? DY[b.dir] : 0;- if (b.mode !== "eaten" && b.mode !== "entering") {+ if (b.mode === "rebooting") {+ // Rebooting: a wireframe shell that fills in from the bottom as the reboot completes.+ const k = 1 - b.reboot / REBOOT_TIME;+ ctx.strokeStyle = BUG_COLORS[b.index];+ ctx.globalAlpha = 0.6;+ ctx.lineWidth = 1;+ ctx.strokeRect(Math.round(cx - 4.5) + 0.5, Math.round(cy - 4) + 0.5, 8, 7);+ ctx.globalAlpha = 1;+ const h = Math.round(7 * k);+ if (h > 0) {+ ctx.fillStyle = BUG_COLORS[b.index];+ ctx.fillRect(Math.round(cx - 4), Math.round(cy + 3) - h, 8, h);+ }+ return;+ }+ {let body = BUG_COLORS[b.index];if (b.frightened) {+ // Shorted out: a dull grey shell; it flickers back to its own colour as the power wears off.const left = s.frightTimer;- body = "#2a3cc8";+ body = SHORTED;if (left < 2) {if (info.reduced) {- // Fade towards pale instead of blinking.- const k = 1 - left / 2;- body = `rgb(${Math.round(42 + 180 * k)},${Math.round(60 + 160 * k)},${Math.round(200 + 40 * k)})`;+ body = left < 1 ? BUG_COLORS[b.index] : SHORTED;} else if (Math.floor(left * 5) % 2 === 0) {- body = "#e8ecff";+ body = BUG_COLORS[b.index];}}}@@ -601,41 +655,44 @@ function drawBug(ctx: CanvasRenderingContext2D, s: MazeState, b: Bug, info: Retrctx.fill();ctx.fillRect(Math.round(cx - 3.5), Math.round(cy - 7), 1, 1);ctx.fillRect(Math.round(cx + 2.5), Math.round(cy - 7), 1, 1);+ // A crest on the dome tells the four habits apart: none, a fin, twin bumps, a ridge.+ if (b.index === WARDEN) ctx.fillRect(Math.round(cx - 0.5), Math.round(cy - 6), 1, 2);+ else if (b.index === ECHO) { ctx.fillRect(Math.round(cx - 2), Math.round(cy - 5), 1, 1); ctx.fillRect(Math.round(cx + 1), Math.round(cy - 5), 1, 1); }+ else if (b.index === ROAMER) ctx.fillRect(Math.round(cx - 2), Math.round(cy - 5), 4, 1);if (b.frightened) {// A jagged glitch mouth instead of a visor.- ctx.strokeStyle = "#ffe0f0";+ ctx.strokeStyle = "#e8ecf2";ctx.beginPath();ctx.moveTo(cx - 3, cy + 1); ctx.lineTo(cx - 1.5, cy); ctx.lineTo(cx, cy + 1); ctx.lineTo(cx + 1.5, cy); ctx.lineTo(cx + 3, cy + 1);ctx.stroke();- ctx.fillStyle = "#ffe0f0";+ ctx.fillStyle = "#e8ecf2";ctx.fillRect(Math.round(cx - 2), Math.round(cy - 3), 1, 1);ctx.fillRect(Math.round(cx + 1), Math.round(cy - 3), 1, 1);return;}}- // The visor with two pupils looking where it goes (all that is left of an eaten bug).- ctx.fillStyle = "#0b0f22";+ // The visor: one lit slit that slides towards where the bug is going.+ ctx.fillStyle = "#120c22";ctx.fillRect(Math.round(cx - 3.5), Math.round(cy - 2.5), 7, 3);- ctx.fillStyle = "#e8fbff";- ctx.fillRect(Math.round(cx - 3 + lookX), Math.round(cy - 2 + lookY * 0.5), 2, 2);- ctx.fillRect(Math.round(cx + 1 + lookX), Math.round(cy - 2 + lookY * 0.5), 2, 2);+ ctx.fillStyle = "#ffe9a8";+ ctx.fillRect(Math.round(cx - 1.5 + lookX * 1.5), Math.round(cy - 1.5 + lookY * 0.5), 3, 1);}export function drawMaze(ctx: CanvasRenderingContext2D, s: MazeState, info: RetroDrawInfo): void {- ctx.fillStyle = "#03040c";+ ctx.fillStyle = "#0b0b0e";ctx.fillRect(0, 0, WIDTH, HEIGHT);- // Walls: dark fill, neon outline. A cleared level makes them glow up and down smoothly.- ctx.fillStyle = "#0a0f3a";+ // Walls: charcoal blocks with a brass edge. A cleared level makes them glow up and down smoothly.+ ctx.fillStyle = "#1c1b21";for (let y = 0; y < MAZE_H; y += 1) {for (let x = 0; x < MAZE_W; x += 1) {if (MAZE[y][x] === "#") ctx.fillRect(x * TILE, OY + y * TILE, TILE, TILE);}}- let wall = "#3b6bff";+ let wall = WALL_GOLD;if (s.phase === "clear") {const k = info.reduced ? 0.6 : 0.5 + 0.5 * Math.sin((CLEAR_TIME - s.phaseTimer) * Math.PI * 3);- wall = `rgb(${Math.round(59 + 196 * k)},${Math.round(107 + 148 * k)},255)`;+ wall = `rgb(${Math.round(184 + 71 * k)},${Math.round(147 + 98 * k)},${Math.round(58 + 150 * k)})`;}ctx.strokeStyle = wall;ctx.lineWidth = 1;@@ -645,24 +702,34 @@ export function drawMaze(ctx: CanvasRenderingContext2D, s: MazeState, info: Retrctx.lineTo(WALL_SEGMENTS[i + 2] + 0.5, WALL_SEGMENTS[i + 3] + 0.5);}ctx.stroke();- // The pen door.- ctx.fillStyle = "#ff7ad9";- ctx.fillRect(EXIT_X * TILE, OY + (EXIT_Y + 1) * TILE + 4, TILE, 2);+ // The pen door: a dashed brass grille.+ ctx.fillStyle = WALL_GOLD;+ for (let i = 0; i < TILE; i += 3) ctx.fillRect(EXIT_X * TILE + i, OY + (EXIT_Y + 1) * TILE + 4, 2, 2);- // Dots and orbs.- ctx.fillStyle = "#ffe6b0";- const orbR = info.reduced ? 3.5 : 3 + Math.sin(info.time * 6) * 0.8;+ // Data dots (tiny plus signs) and power orbs (rings around a core).+ ctx.fillStyle = "#bfeee0";+ const orbR = info.reduced ? 3.5 : 3.2 + Math.sin(info.time * 6) * 0.7;for (let y = 0; y < MAZE_H; y += 1) {for (let x = 0; x < MAZE_W; x += 1) {const v = s.dots[y * MAZE_W + x];- if (v === 1) ctx.fillRect(x * TILE + 4, OY + y * TILE + 4, 2, 2);- else if (v === 2) {- ctx.beginPath();- ctx.arc(tileCx(x), tileCy(y), orbR, 0, Math.PI * 2);- ctx.fill();+ if (v === 1) {+ ctx.fillRect(x * TILE + 4, OY + y * TILE + 5, 3, 1);+ ctx.fillRect(x * TILE + 5, OY + y * TILE + 4, 1, 3);}}}+ ctx.strokeStyle = PROBE_COLOR;+ ctx.lineWidth = 1;+ for (let y = 0; y < MAZE_H; y += 1) {+ for (let x = 0; x < MAZE_W; x += 1) {+ if (s.dots[y * MAZE_W + x] !== 2) continue;+ ctx.beginPath();+ ctx.arc(tileCx(x), tileCy(y), orbR, 0, Math.PI * 2);+ ctx.stroke();+ ctx.fillStyle = PROBE_COLOR;+ ctx.fillRect(tileCx(x) - 1, tileCy(y) - 1, 2, 2);+ }+ }if (s.bonusTimer > 0) drawGem(ctx, tileCx(BONUS_X), tileCy(BONUS_Y), 4, bonusColor(s.level));@@ -672,13 +739,13 @@ export function drawMaze(ctx: CanvasRenderingContext2D, s: MazeState, info: Retrctx.clip();const p = s.player;if (s.phase === "dying") {- // The chomper folds open and vanishes.+ // The drone shorts out and shrinks away.const k = 1 - Math.max(0, s.phaseTimer - DYING_TIME * 0.25) / (DYING_TIME * 0.75);- if (s.phaseTimer > DYING_TIME * 0.25) drawChomper(ctx, tileCx(p.x), tileCy(p.y), 4.5, UP, 0.2 + k * (Math.PI - 0.2));+ if (s.phaseTimer > DYING_TIME * 0.25) drawProbe(ctx, tileCx(p.x), tileCy(p.y), 4.5, p.dir, 0, 1 - k);} else if (!s.over) {const chew = info.idle || info.reduced ? (info.idle && !info.reduced ? info.time * 2 : 0.25) : p.chew;- const open = 0.08 + Math.abs(Math.sin(chew * Math.PI)) * 0.6;- drawChomper(ctx, tileCx(p.x), tileCy(p.y), 4.5, p.dir >= 0 ? p.dir : p.want >= 0 ? p.want : LEFT, open);+ const open = Math.abs(Math.sin(chew * Math.PI));+ drawProbe(ctx, tileCx(p.x), tileCy(p.y), 4.5, p.dir >= 0 ? p.dir : p.want >= 0 ? p.want : LEFT, open);}if (s.phase !== "dying" && s.phase !== "clear") for (const b of s.bugs) drawBug(ctx, s, b, info);ctx.restore();@@ -687,20 +754,20 @@ export function drawMaze(ctx: CanvasRenderingContext2D, s: MazeState, info: Retrfor (const pop of s.popups) {if (pop.time <= 0) continue;ctx.globalAlpha = Math.min(1, pop.time * 2);- drawDigits(ctx, pop.value, tileCx(pop.x), tileCy(pop.y) - 4 - (info.reduced ? 0 : (1 - pop.time) * 6), 8, "#3de8ff", "center", 600);+ drawDigits(ctx, pop.value, tileCx(pop.x), tileCy(pop.y) - 4 - (info.reduced ? 0 : (1 - pop.time) * 6), 8, PROBE_COLOR, "center", 600);}ctx.globalAlpha = 1;// HUD: score top left, level gem + number top right, lives bottom left, bonus gems bottom right.drawDigits(ctx, s.score, 4, 2, 10, "#ffffff", "left", 600);drawGem(ctx, WIDTH - 24, 7, 4, bonusColor(s.level));- drawDigits(ctx, s.level, WIDTH - 4, 2, 10, "#ffd23f", "right");+ drawDigits(ctx, s.level, WIDTH - 4, 2, 10, "#e9b949", "right");const spare = s.phase === "dying" ? s.lives : s.lives - 1;- for (let i = 0; i < Math.max(0, spare); i += 1) drawChomper(ctx, 8 + i * 12, HEIGHT - 7, 4, LEFT, 0.5);+ for (let i = 0; i < Math.max(0, spare); i += 1) drawProbe(ctx, 8 + i * 12, HEIGHT - 7, 4, RIGHT, 0.4);for (let i = 0; i < Math.min(s.level, 6); i += 1) drawGem(ctx, WIDTH - 8 - i * 11, HEIGHT - 7, 3.5, bonusColor(s.level - i));- // The ready pause before a round: a soft ring around the chomper (steady when motion is reduced).+ // The ready pause before a round: a soft ring around the drone (steady when motion is reduced).if (s.phase === "ready" && !info.idle) {- ctx.strokeStyle = "rgba(255,210,63,0.6)";+ ctx.strokeStyle = "rgba(94,242,194,0.6)";ctx.lineWidth = 1;ctx.beginPath();const r = info.reduced ? 8 : 7 + (s.phaseTimer % 0.8) * 4;diff --git a/dodaios/ui/web/frontend/src/components/society/arcade/games/pixelRaiders.test.ts b/dodaios/ui/web/frontend/src/components/society/arcade/games/pixelRaiders.test.tsindex 0c92c5725a..4a5837c78e 100644--- a/dodaios/ui/web/frontend/src/components/society/arcade/games/pixelRaiders.test.ts+++ b/dodaios/ui/web/frontend/src/components/society/arcade/games/pixelRaiders.test.ts@@ -1,22 +1,32 @@import { describe, expect, it } from "vitest";import { idleInput, RETRO_STEP, seededRandom, type RetroInput } from "../retroGame";import game, {- BUNKER_X, BUNKER_Y, CELL_W, COLS, DROP_Y, KIND_POINTS, MARCH_X, PLAYER_Y, ROWS, WIDTH,- alienX, alienY, bunkerCells, march, stepDelay, waveStartY, type RaidersState,+ BARRIER_Y, CELL_H, COLS, COURIER_POINTS, EDGE_MARGIN, HEIGHT, KIND_POINTS, PLAYER_Y, RAPID_S, RECHARGE_S, ROWS, SEGMENTS, SEG_HP,+ SEG_W, SINK_Y, WAVE_BONUS, WIDTH,+ alienPoints, alienX, alienY, barrierCharge, segmentX, swayRate, swaySwarm, waveStartY, type RaidersState,} from "./pixelRaiders";const rnd = seededRandom(7);const run = (s: RaidersState, input: RetroInput, seconds: number) => {for (let t = 0; t < seconds; t += RETRO_STEP) game.step(s, input, RETRO_STEP, rnd);};-/** A run with the formation and its guns held still, so one rule can be watched at a time. */+/** A run with the swarm's guns and the courier held back, so one rule can be watched at a time. */const calm = (): RaidersState => {const s = game.create(seededRandom(1));- s.stepTimer = 999;s.fireTimer = 999;- s.saucerTimer = 999;+ s.courierTimer = 999;return s;};+/** The same run; tests that pair it with `runFrozen` keep the swarm where it is. */+const frozen = calm;+/** Step the run without moving the swarm. */+const runFrozen = (s: RaidersState, input: RetroInput, seconds: number) => {+ for (let t = 0; t < seconds; t += RETRO_STEP) {+ const { fx, fy, sway, targetFy } = s;+ game.step(s, input, RETRO_STEP, rnd);+ s.fx = fx; s.fy = fy; s.sway = sway; s.targetFy = targetFy;+ }+};/** A canvas stand-in that only knows the calls a game may make, and rejects non-finite rectangles. */function fakeContext(): { ctx: CanvasRenderingContext2D; depth: () => number; rects: () => number } {@@ -40,72 +50,101 @@ function fakeContext(): { ctx: CanvasRenderingContext2D; depth: () => number; rereturn { ctx: ctx as unknown as CanvasRenderingContext2D, depth: () => depth, rects: () => rects };}+/** Left and right pixel of the living swarm. */+const extent = (s: RaidersState): [number, number] => {+ let l = Infinity, r = -Infinity;+ for (let row = 0; row < ROWS; row += 1) {+ for (let c = 0; c < COLS; c += 1) {+ if (!s.alive[row * COLS + c]) continue;+ l = Math.min(l, alienX(s, row, c));+ r = Math.max(r, alienX(s, row, c) + 9);+ }+ }+ return [l, r];+};+describe("pixel raiders", () => {- it("starts with a full formation, four whole bunkers and three lives", () => {+ it("starts with a full staggered swarm, a charged barrier and three lives", () => {const s = game.create(seededRandom(1));+ expect(game.width).toBe(256);+ expect(game.height).toBe(HEIGHT);expect(s.aliveCount).toBe(ROWS * COLS);expect(game.status(s)).toEqual({ score: 0, lives: 3, level: 1, over: false });- const whole = bunkerCells(s, 0);- expect(whole).toBeGreaterThan(60);- for (let b = 1; b < 4; b += 1) expect(bunkerCells(s, b)).toBe(whole);+ expect(barrierCharge(s)).toBe(SEGMENTS * SEG_HP);expect(s.fy).toBe(waveStartY(1));+ // Odd rows sit half a cell to the right of even rows.+ expect(alienX(s, 1, 0) - alienX(s, 0, 0)).toBeGreaterThan(5);});- it("marches sideways one step at a time", () => {+ it("sways smoothly from side to side and never leaves the screen", () => {const s = calm();- const x0 = s.fx;- s.stepTimer = 0.001;- game.step(s, idleInput(), RETRO_STEP, rnd);- expect(s.fx).toBe(x0 + MARCH_X);- expect(s.frame).toBe(1);+ let last = s.fx, biggestJump = 0, minX = Infinity, maxX = -Infinity;+ for (let t = 0; t < 20; t += RETRO_STEP) {+ swaySwarm(s, RETRO_STEP, rnd);+ biggestJump = Math.max(biggestJump, Math.abs(s.fx - last));+ last = s.fx;+ const [l, r] = extent(s);+ minX = Math.min(minX, l);+ maxX = Math.max(maxX, r);+ }+ expect(biggestJump).toBeLessThan(3);+ expect(minX).toBeGreaterThanOrEqual(EDGE_MARGIN - 1);+ expect(maxX).toBeLessThanOrEqual(WIDTH - EDGE_MARGIN + 3);+ // It really swept both ways.+ expect(maxX - minX).toBeGreaterThan(extent(game.create(seededRandom(1)))[1] - extent(game.create(seededRandom(1)))[0] + 20);});- it("drops a row and turns around at the wall", () => {+ it("sinks a little at the end of every sweep", () => {const s = calm();- s.fx = WIDTH - COLS * CELL_W - 4;const y0 = s.fy;- march(s, rnd);- expect(s.fy).toBe(y0 + DROP_Y);- expect(s.dir).toBe(-1);- const x1 = s.fx;- march(s, rnd);- expect(s.fx).toBe(x1 - MARCH_X);+ const halfTurn = Math.PI / swayRate(s.aliveCount, s.wave);+ for (let t = 0; t < halfTurn * 0.9; t += RETRO_STEP) swaySwarm(s, RETRO_STEP, rnd);+ expect(s.fy).toBe(y0);+ for (let t = 0; t < halfTurn * 0.2 + 0.5; t += RETRO_STEP) swaySwarm(s, RETRO_STEP, rnd);+ expect(s.fy).toBe(y0 + SINK_Y);});- it("ignores empty outer columns when finding the wall", () => {+ it("sweeps wider once the outer columns are gone", () => {const s = calm();- for (let r = 0; r < ROWS; r += 1) s.alive[r * COLS + COLS - 1] = 0;- s.aliveCount -= ROWS;- s.fx = WIDTH - COLS * CELL_W - 4;- const y0 = s.fy;- march(s, rnd);- expect(s.fy).toBe(y0);+ for (let r = 0; r < ROWS; r += 1) for (const c of [0, 1, COLS - 2, COLS - 1]) s.alive[r * COLS + c] = 0;+ s.aliveCount = ROWS * (COLS - 4);+ let minX = Infinity, maxX = -Infinity;+ for (let t = 0; t < 15; t += RETRO_STEP) {+ swaySwarm(s, RETRO_STEP, rnd);+ const [l, r] = extent(s);+ minX = Math.min(minX, l);+ maxX = Math.max(maxX, r);+ }+ expect(minX).toBeLessThan(EDGE_MARGIN + 4);+ expect(maxX).toBeGreaterThan(WIDTH - EDGE_MARGIN - 6);});- it("speeds up as fewer aliens remain and in later waves", () => {- expect(stepDelay(10, 1)).toBeLessThan(stepDelay(55, 1));- expect(stepDelay(1, 1)).toBeLessThan(RETRO_STEP);- expect(stepDelay(55, 4)).toBeLessThan(stepDelay(55, 1));+ it("sweeps faster as fewer raiders remain and in later waves", () => {+ expect(swayRate(8, 1)).toBeGreaterThan(swayRate(ROWS * COLS, 1));+ expect(swayRate(1, 1)).toBeGreaterThan(swayRate(ROWS * COLS, 1) * 4);+ expect(swayRate(ROWS * COLS, 4)).toBeGreaterThan(swayRate(ROWS * COLS, 1));expect(waveStartY(3)).toBeGreaterThan(waveStartY(1));});- it("a shot kills the alien it hits and scores its kind", () => {- const s = calm();- // Bottom row, middle column: clear line of fire above the cannon.- const row = ROWS - 1, col = 5;+ it("a shot kills the raider it hits and scores its kind, more in later waves", () => {+ const s = frozen();+ const row = ROWS - 1, col = 4;s.shots[0].active = true;s.shots[0].x = alienX(s, row, col) + 4;s.shots[0].y = alienY(s, row) + 12;- run(s, idleInput(), 0.1);+ runFrozen(s, idleInput(), 0.1);expect(s.alive[row * COLS + col]).toBe(0);expect(s.aliveCount).toBe(ROWS * COLS - 1);expect(s.score).toBe(KIND_POINTS[2]);expect(s.shots[0].active).toBe(false);+ expect(alienPoints(0, 1)).toBe(KIND_POINTS[0]);+ expect(alienPoints(2, 3)).toBe(KIND_POINTS[2] + 2 * WAVE_BONUS);+ expect(alienPoints(2, 50)).toBe(alienPoints(2, 20));});it("fires on the action button, at most two shots at once", () => {const s = calm();- s.px = 4; // left of the first bunker, so the shots fly free+ s.px = 4;run(s, { ...idleInput(), a: true }, 0.4);expect(s.shots.filter((x) => x.active).length).toBeGreaterThanOrEqual(1);run(s, { ...idleInput(), a: true }, 1);@@ -114,108 +153,142 @@ describe("pixel raiders", () => {it("a tap shorter than one frame still fires (the press edge alone)", () => {const s = calm();- s.px = 4;const tap = idleInput();tap.pressed.a = true;game.step(s, tap, RETRO_STEP, rnd);expect(s.shots.filter((x) => x.active).length).toBe(1);});- it("player shots and alien shots chip bunkers cell by cell", () => {- const s = calm();- const before = bunkerCells(s, 1);+ it("the barrier lets the fighter's shots through but drains under raider fire, then recharges", () => {+ const s = frozen();+ // A raider-free lane: empty the swarm except one far corner raider.+ s.alive.fill(0);+ s.alive[0] = 1;+ s.aliveCount = 1;+ const x = segmentX(10) + 3;s.shots[0].active = true;- s.shots[0].x = BUNKER_X[1] + 10;- s.shots[0].y = BUNKER_Y + 20;- run(s, idleInput(), 0.2);- const afterShot = bunkerCells(s, 1);- expect(afterShot).toBeLessThan(before);- expect(afterShot).toBeGreaterThan(before - 15);- expect(s.shots[0].active).toBe(false);+ s.shots[0].x = x;+ s.shots[0].y = BARRIER_Y + 10;+ runFrozen(s, idleInput(), 0.15);+ expect(s.shots[0].y).toBeLessThan(BARRIER_Y);+ expect(s.barrier[10]).toBe(SEG_HP);s.bombs[0].active = true;- s.bombs[0].x = BUNKER_X[2] + 4;- s.bombs[0].y = BUNKER_Y - 10;+ s.bombs[0].x = x;+ s.bombs[0].y = BARRIER_Y - 12;s.bombs[0].speed = 80;s.bombs[0].kind = 0;- run(s, idleInput(), 0.3);- expect(bunkerCells(s, 2)).toBeLessThan(before);+ runFrozen(s, idleInput(), 0.3);expect(s.bombs[0].active).toBe(false);+ expect(s.barrier[10]).toBe(SEG_HP - 1);+ runFrozen(s, idleInput(), RECHARGE_S + 0.1);+ expect(s.barrier[10]).toBe(SEG_HP);});- it("an alien shot costs a life, then the cannon comes back", () => {- const s = calm();+ it("a drained segment no longer stops raider shots", () => {+ const s = frozen();+ s.barrier[5] = 0;+ s.px = 0;+ s.bombs[0].active = true;+ s.bombs[0].x = segmentX(5) + Math.floor(SEG_W / 2);+ s.bombs[0].y = BARRIER_Y - 10;+ s.bombs[0].speed = 80;+ runFrozen(s, idleInput(), 0.25);+ expect(s.bombs[0].y).toBeGreaterThan(BARRIER_Y);+ });++ it("a raider shot costs a life, then the fighter comes back", () => {+ const s = frozen();s.px = 100;s.bombs[0].active = true;- s.bombs[0].x = 106;+ s.bombs[0].x = 105;s.bombs[0].y = PLAYER_Y - 8;s.bombs[0].speed = 80;- run(s, idleInput(), 0.2);+ runFrozen(s, idleInput(), 0.2);expect(s.lives).toBe(2);expect(s.phase).toBe("dying");- run(s, idleInput(), 2);+ runFrozen(s, idleInput(), 2);expect(s.phase).toBe("play");expect(game.status(s).over).toBe(false);});it("the last life lost ends the run", () => {- const s = calm();+ const s = frozen();s.lives = 1;s.px = 100;s.bombs[0].active = true;- s.bombs[0].x = 106;+ s.bombs[0].x = 105;s.bombs[0].y = PLAYER_Y - 4;s.bombs[0].speed = 80;- run(s, idleInput(), 2);+ runFrozen(s, idleInput(), 2);expect(game.status(s)).toMatchObject({ lives: 0, over: true });});- it("clearing the formation starts a lower, faster wave with fresh bunkers", () => {- const s = calm();+ it("clearing the swarm starts a lower, faster wave with a recharged barrier", () => {+ const s = frozen();s.alive.fill(0);- s.alive[(ROWS - 1) * COLS + 5] = 1;+ s.alive[(ROWS - 1) * COLS + 4] = 1;s.aliveCount = 1;- s.bunkers.fill(0);+ s.barrier.fill(0);s.shots[0].active = true;- s.shots[0].x = alienX(s, ROWS - 1, 5) + 4;+ s.shots[0].x = alienX(s, ROWS - 1, 4) + 4;s.shots[0].y = alienY(s, ROWS - 1) + 10;- run(s, idleInput(), 0.1);+ runFrozen(s, idleInput(), 0.1);expect(s.phase).toBe("clear");run(s, idleInput(), 2);expect(s.wave).toBe(2);expect(s.aliveCount).toBe(ROWS * COLS);expect(s.fy).toBe(waveStartY(2));- expect(bunkerCells(s, 0)).toBeGreaterThan(60);- expect(stepDelay(55, 2)).toBeLessThan(stepDelay(55, 1));+ expect(barrierCharge(s)).toBe(SEGMENTS * SEG_HP);});- it("the formation reaching the cannon ends the run", () => {+ it("the swarm burns through the barrier and, reaching the fighter, ends the run", () => {const s = calm();- s.fy = PLAYER_Y - (ROWS - 1) * 16 - 8 - 2;- s.fx = WIDTH - COLS * CELL_W - 4;- march(s, rnd);+ s.fy = BARRIER_Y - (ROWS - 1) * CELL_H - 4;+ s.targetFy = s.fy;+ swaySwarm(s, RETRO_STEP, rnd);+ expect(barrierCharge(s)).toBeLessThan(SEGMENTS * SEG_HP);+ s.fy = PLAYER_Y - (ROWS - 1) * CELL_H - 8 + 1;+ s.targetFy = s.fy;+ swaySwarm(s, RETRO_STEP, rnd);run(s, idleInput(), 2);expect(game.status(s).over).toBe(true);});- it("the saucer comes by and is worth bonus points", () => {- const s = calm();- s.saucerTimer = 0.01;- run(s, idleInput(), 0.05);- expect(s.saucer.active).toBe(true);- s.saucer.x = 100;+ it("the courier drone zigzags by; shooting it scores and drops a rapid-fire capsule", () => {+ const s = frozen();+ s.courierTimer = 0.01;+ runFrozen(s, idleInput(), 0.05);+ expect(s.courier.active).toBe(true);+ const ys = new Set<number>();+ for (let i = 0; i < 60; i += 1) { runFrozen(s, idleInput(), RETRO_STEP); ys.add(Math.round(s.courier.y)); }+ expect(ys.size).toBeGreaterThan(2);++ s.courier.x = 100;+ s.courier.y = 24;s.shots[0].active = true;- s.shots[0].x = 108;- s.shots[0].y = 40;+ s.shots[0].x = 105;+ s.shots[0].y = 36; // above the swarm's top rowconst before = s.score;- run(s, idleInput(), 0.1);- expect(s.saucer.active).toBe(false);- expect(s.score - before).toBe(s.popups.find((p) => p.active)?.value);+ runFrozen(s, idleInput(), 0.1);+ expect(s.courier.active).toBe(false);+ expect(s.score - before).toBe(COURIER_POINTS);+ expect(s.capsule.active).toBe(true);++ // Stand under the capsule and catch it: rapid fire allows a third shot in the air.+ s.px = s.capsule.x - 3;+ runFrozen(s, idleInput(), 5);+ expect(s.capsule.active).toBe(false);+ expect(s.rapid).toBeGreaterThan(RAPID_S - 2);+ s.alive.fill(0); s.alive[0] = 1; s.aliveCount = 1;+ s.px = WIDTH - 20;+ runFrozen(s, { ...idleInput(), a: true }, 0.35);+ expect(s.shots.filter((x) => x.active).length).toBe(3);});- it("aliens shoot back but never more than the cap", () => {+ it("raiders shoot back but never more than the cap", () => {const s = game.create(seededRandom(3));- s.stepTimer = 999;+ s.courierTimer = 999;let most = 0;for (let i = 0; i < 1200 && s.phase === "play"; i += 1) {game.step(s, idleInput(), RETRO_STEP, rnd);@@ -225,6 +298,19 @@ describe("pixel raiders", () => {expect(most).toBeLessThanOrEqual(2);});+ it("is deterministic for a given seed", () => {+ const play = () => {+ const random = seededRandom(99);+ const s = game.create(random);+ for (let i = 0; i < 1500; i += 1) {+ const input = { ...idleInput(), a: i % 20 < 3, left: i % 300 < 150, right: i % 300 >= 150 };+ game.step(s, input, RETRO_STEP, random);+ }+ return [s.score, s.lives, s.aliveCount, s.fx.toFixed(3), s.fy, Array.from(s.barrier).join("")].join("|");+ };+ expect(play()).toBe(play());+ });+it("draws every phase without throwing, idle and reduced included", () => {const s = game.create(seededRandom(2));for (const info of [@@ -237,14 +323,18 @@ describe("pixel raiders", () => {expect(fake.depth()).toBe(0);expect(fake.rects()).toBeGreaterThan(100);}- // A busy frame: shots, bombs, saucer, a dying cannon, then game over.run(s, { ...idleInput(), a: true, right: true }, 3);- s.saucer.active = true;- s.saucer.x = 60;+ s.courier.active = true;+ s.courier.x = 60;+ s.capsule.active = true;+ s.capsule.x = 80; s.capsule.y = 120;+ s.rapid = 3;+ s.barrier[3] = 0; s.barrier[4] = 1;s.popups[0].active = true;s.popups[0].t = 1;- s.popups[0].value = 150;+ s.popups[0].value = 80;s.shake = 0.3;+ game.draw(fakeContext().ctx, s, { time: 2, reduced: false, idle: false });s.phase = "dying";s.timer = 1;game.draw(fakeContext().ctx, s, { time: 2, reduced: false, idle: false });diff --git a/dodaios/ui/web/frontend/src/components/society/arcade/games/pixelRaiders.ts b/dodaios/ui/web/frontend/src/components/society/arcade/games/pixelRaiders.tsindex 3f0e6da226..113bef05d7 100644--- a/dodaios/ui/web/frontend/src/components/society/arcade/games/pixelRaiders.ts+++ b/dodaios/ui/web/frontend/src/components/society/arcade/games/pixelRaiders.ts@@ -1,10 +1,16 @@/**- * "Pixel Raiders": a formation of pixel aliens marches sideways, drops a row- * at each edge and speeds up as it thins out. They shoot back (some shots- * aimed at the cannon, some from a random column); the cannon hides behind- * four bunkers that crumble cell by cell. A bonus saucer crosses the top now- * and then. Clearing the formation brings the next wave, starting lower and- * marching faster; the formation reaching the cannon ends the run.+ * "Pixel Raiders": a staggered swarm of four rows sways from side to side on+ * a smooth wave, sinking a few pixels at the end of every sweep. The fewer+ * raiders are left, the wider and faster the swarm sweeps. Raiders on the+ * swarm's front line shoot back (some aimed at the fighter, some at random).+ *+ * The fighter is covered by one long energy barrier of short segments. The+ * barrier is one-way: the fighter's own shots pass through it, raider shots+ * drain a segment, and a drained segment slowly recharges. Now and then a+ * courier drone zigzags across the top; shooting it drops a capsule that+ * gives rapid fire for a while. Raider points grow with every wave. Clearing+ * the swarm brings the next one, starting lower and sweeping faster; the+ * swarm reaching the fighter ends the run.*/import type { RetroDrawInfo, RetroGame, RetroInput, RetroStatus } from "../retroGame";import {@@ -12,111 +18,117 @@ import {type Particle, type PixelSprite,} from "./games3Kit";-export const WIDTH = 224;-export const HEIGHT = 256;+export const WIDTH = 256;+export const HEIGHT = 240;-export const COLS = 11;-export const ROWS = 5;-export const CELL_W = 16;-export const CELL_H = 16;+export const COLS = 9;+export const ROWS = 4;+export const CELL_W = 22;+export const CELL_H = 18;+/** Odd rows sit half a cell to the right, so the swarm is a staggered lattice. */+export const STAGGER = CELL_W / 2;const ALIEN_H = 8;-/** Pixels the formation moves per march step, and drops at an edge. */-export const MARCH_X = 2;-export const DROP_Y = 8;-/** The formation turns when its outer column would come closer than this to a side wall. */-const EDGE_MARGIN = 6;--/** Which alien kind each row holds (top to bottom), their widths and points. */-const ROW_KIND = [0, 1, 1, 2, 2] as const;-const KIND_W = [8, 10, 12] as const;-export const KIND_POINTS = [30, 20, 10] as const;-const KIND_COLOR = ["#ff7ae0", "#7ae8ff", "#9dff7a"] as const;--export const PLAYER_Y = 216;-export const PLAYER_W = 13;-const PLAYER_H = 8;-const PLAYER_SPEED = 80;+/** Pixels the swarm sinks at the end of each sweep. */+export const SINK_Y = 6;+const SINK_SPEED = 30;+/** The swarm's living edge never comes closer than this to a side wall. */+export const EDGE_MARGIN = 6;++/** Which raider kind each row holds (top to bottom), their widths and base points. */+const ROW_KIND = [0, 1, 2, 2] as const;+const KIND_W = [11, 13, 9] as const;+export const KIND_POINTS = [40, 25, 15] as const;+/** Extra points per raider for every wave survived, up to WAVE_BONUS_CAP waves. */+export const WAVE_BONUS = 5;+const WAVE_BONUS_CAP = 6;+const KIND_COLOR = ["#ffb547", "#ff6b5a", "#9d7bff"] as const;++export const PLAYER_Y = 210;+export const PLAYER_W = 11;+const PLAYER_H = 9;+const PLAYER_SPEED = 95;const PLAYER_START_X = Math.round((WIDTH - PLAYER_W) / 2);export const MAX_SHOTS = 2;-const SHOT_SPEED = 260;-const SHOT_COOLDOWN = 0.32;-const GROUND_Y = 230;+const RAPID_SHOTS = 3;+const SHOT_SPEED = 250;+const SHOT_COOLDOWN = 0.34;+const RAPID_COOLDOWN = 0.14;+const GROUND_Y = 226;export const MAX_BOMBS = 6;-export const BUNKER_COUNT = 4;-export const BUNKER_COLS = 11;-export const BUNKER_ROWS = 8;-/** Bunker cells are 2 × 2 pixels. */-export const BUNKER_CELL = 2;-export const BUNKER_Y = 184;-export const BUNKER_X: readonly number[] = [0, 1, 2, 3].map((i) => Math.round((WIDTH * (i + 1)) / 5 - (BUNKER_COLS * BUNKER_CELL) / 2));-const BUNKER_SHAPE = [- "..#######..",- ".#########.",- "###########",- "###########",- "###########",- "###########",- "###.....###",- "##.......##",-];--const SAUCER_W = 16;-const SAUCER_Y = 26;-const SAUCER_SPEED = 48;-const SAUCER_POINTS = [50, 100, 100, 150, 150, 300] as const;+/** The energy barrier: one row of short segments with small gaps, each with a few charge points. */+export const SEGMENTS = 22;+export const SEG_W = 9;+const SEG_GAP = 2;+export const SEG_HP = 3;+export const BARRIER_Y = 182;+const BARRIER_H = 3;+export const BARRIER_X = Math.round((WIDTH - (SEGMENTS * (SEG_W + SEG_GAP) - SEG_GAP)) / 2);+/** Seconds for a drained segment to win back one charge point. */+export const RECHARGE_S = 4;++const COURIER_W = 12;+const COURIER_H = 7;+const COURIER_Y = 24;+const COURIER_SPEED = 44;+export const COURIER_POINTS = 80;+const CAPSULE_SPEED = 46;+/** Seconds of rapid fire a caught capsule gives. */+export const RAPID_S = 8;const DEATH_S = 1.4;const CLEAR_S = 1.6;-const EXTRA_LIFE_EVERY = 2000;+const EXTRA_LIFE_EVERY = 2500;const MAX_LIVES = 5;-/** Two animation frames per alien kind: our own designs, a jelly, a horned beetle and a crested trilobite. */+/** Two animation frames per raider kind: a faceted prism, a split-wing glider and a spore orb. */const ALIEN_SPRITES: readonly (readonly [PixelSprite, PixelSprite])[] = [[- sprite(["..####..", ".######.", "##.##.##", "########", ".#.##.#.", "#..##..#", ".#....#.", "..#..#.."]),- sprite(["..####..", ".######.", "##.##.##", "########", ".#.##.#.", ".#.##.#.", "#..##..#", "#......#"]),+ sprite(["....###....", "...#####...", "..##.#.##..", ".####.####.", "###.###.###", ".####.####.", "..##.#.##..", "....###...."]),+ sprite(["....###....", "...##.##...", "..#######..", ".###.#.###.", "####.#.####", ".###.#.###.", "..#######..", "....###...."]),],[- sprite(["#........#", ".#..##..#.", "..######..", ".##.##.##.", "##########", ".#.####.#.", "#.#....#.#", ".#......#."]),- sprite(["..#....#..", "..#.##.#..", "..######..", ".##.##.##.", "##########", "#.######.#", "..#....#..", ".#.#..#.#."]),+ sprite(["##.........##", ".##.......##.", "..##.###.##..", "...#######...", "..####.####..", ".##..###..##.", "##....#....##", "............."]),+ sprite(["............#", "#.........##.", ".##.###.##...", "..#########..", "..####.####..", "...#.###.#...", "..##..#..##..", ".##.......##."]),],[- sprite([".....##.....", "...######...", ".##########.", "##.##..##.##", "############", ".#.#.##.#.#.", "#.#......#.#", ".#........#."]),- sprite([".....##.....", "...######...", ".##########.", "##.##..##.##", "############", "..#.#..#.#..", ".#.#....#.#.", "#.#......#.#"]),+ sprite(["..#####..", ".##...##.", "##.###.##", "#.#####.#", "##.###.##", ".##...##.", "..#####..", "....#...."]),+ sprite(["..#####..", ".#######.", "##.....##", "#..###..#", "##.....##", ".#######.", "..#####..", "...#.#..."]),],];-const BURST_SPRITE = sprite(["#..#..#.#..", ".#..#.#..#.", "..#.....#..", "##.......##", "..#.....#..", ".#..#.#..#.", "#..#...#..#"]);+const BURST_SPRITE = sprite(["..#...#..", "#..#.#..#", ".#.....#.", "...#.#...", ".#.....#.", "#..#.#..#", "..#...#.."]);const PLAYER_SPRITE = sprite([- "......#......",- ".....###.....",- "....#####....",- ".###########.",- "#############",- "#############",- "#.#.#.#.#.#.#",- ".#.#.#.#.#.#.",+ ".....#.....",+ "....###....",+ "....#.#....",+ "...##.##...",+ "#..#####..#",+ "##.#####.##",+ "###########",+ ".##..#..##.",+ ".#.......#.",]);const WRECK_SPRITES = [- sprite(["..#.....#....", "....#.#...#..", "#..#####.....", "..#######.#..", ".##.###.###..", "#############", "#.#.#.#.#.#.#", ".#.#.#.#.#.#."]),- sprite(["#.....#....#.", "...#.....#...", "..#.##.#.....", "#.##.###.##..", ".###.###.###.", "#############", ".#.#.#.#.#.#.", "#.#.#.#.#.#.#"]),+ sprite(["..#...#....", ".....#..#..", "#..#.#.....", "...##.##.#.", "#..#.###...", "##.#.#.#.##", "#.#####.###", ".#...#..#..", ".#.......#."]),+ sprite(["#....#...#.", "...#....#..", "..#.#.#....", ".#.#..##...", "...###.#..#", "##..###.#.#", "####.######", "..#..#..#..", "#.......#.."]),];-const SAUCER_SPRITE = sprite([- ".....######.....",- "...##########...",- "..############..",- ".##.##.##.##.##.",- "################",- "..###..##..###..",- "...#........#...",+const COURIER_SPRITE = sprite([+ "..########..",+ ".#..#..#..#.",+ "############",+ "#.##.##.##.#",+ "############",+ ".#........#.",+ "#..........#",]);-const LIFE_SPRITE = sprite(["...#...", "..###..", "#######", "#######"]);+const CAPSULE_SPRITE = sprite([".##.", "####", "#..#", "####", ".##."]);+const LIFE_SPRITE = sprite(["..#..", ".###.", "#####", "#.#.#"]);export type RaidersPhase = "play" | "dying" | "clear" | "over";export interface Shot { active: boolean; x: number; y: number }-/** An alien shot. `kind` 0 straight, 1 zigzag (aimed), 2 fast dart. */+/** A raider shot. `kind` 0 straight, 1 zigzag (aimed), 2 fast dart. */export interface Bomb { active: boolean; x: number; y: number; kind: number; speed: number }interface Burst { active: boolean; x: number; y: number; t: number; color: string }interface Popup { active: boolean; x: number; y: number; t: number; value: number }@@ -133,87 +145,133 @@ export interface RaidersState {nextLifeAt: number;px: number;cooldown: number;+ /** Seconds of rapid fire left (from a caught capsule). */+ rapid: number;shots: Shot[];bombs: Bomb[];- /** One flag per alien, row-major (ROWS × COLS). */+ /** One flag per raider, row-major (ROWS × COLS). */alive: Uint8Array;aliveCount: number;- /** Top-left of the formation's grid of cells. */+ /** Top-left of the swarm's lattice (row 0, column 0), and the depth it is sinking to. */fx: number;fy: number;- dir: 1 | -1;- stepTimer: number;+ targetFy: number;+ /** The sway's angle in radians; each half turn is one sweep. */+ sway: number;frame: 0 | 1;fireTimer: number;- /** One flag per bunker cell, bunker-major (BUNKER_COUNT × BUNKER_ROWS × BUNKER_COLS). */- bunkers: Uint8Array;- saucer: { active: boolean; x: number; dir: 1 | -1; points: number };- saucerTimer: number;+ /** Charge points per barrier segment, and each segment's recharge clock. */+ barrier: Uint8Array;+ recharge: Float32Array;+ courier: { active: boolean; x: number; y: number; dir: 1 | -1 };+ courierTimer: number;+ capsule: { active: boolean; x: number; y: number };bursts: Burst[];popups: Popup[];particles: Particle[];shake: number;}-/** Seconds between march steps: slow with a full formation, every frame with one alien left, faster each wave. */-export function stepDelay(alive: number, wave: number): number {+/** How fast the swarm sweeps (radians per second): calm when full, frantic with one raider left, faster each wave. */+export function swayRate(alive: number, wave: number): number {const fill = clamp((alive - 1) / (ROWS * COLS - 1), 0, 1);- return (0.012 + 0.45 * fill) * Math.max(0.55, 1 - 0.07 * (wave - 1));+ return (0.9 + 5.2 * (1 - fill) * (1 - fill)) * Math.min(1.6, 1 + 0.08 * (wave - 1));}-/** The formation's top edge at the start of a wave: each wave starts a row lower, up to a limit. */+/** The swarm's top edge at the start of a wave: each wave starts lower, up to a limit. */export function waveStartY(wave: number): number {- return 48 + Math.min(wave - 1, 7) * 8;+ return 38 + Math.min(wave - 1, 6) * 8;+}++/** What one raider of `kind` is worth in `wave`. */+export function alienPoints(kind: number, wave: number): number {+ return KIND_POINTS[kind] + WAVE_BONUS * Math.min(wave - 1, WAVE_BONUS_CAP);}function maxBombs(wave: number): number {return Math.min(MAX_BOMBS, 2 + Math.floor(wave / 2));}-function resetBunkers(bunkers: Uint8Array): void {- for (let b = 0; b < BUNKER_COUNT; b += 1) {- for (let r = 0; r < BUNKER_ROWS; r += 1) {- for (let c = 0; c < BUNKER_COLS; c += 1) {- bunkers[(b * BUNKER_ROWS + r) * BUNKER_COLS + c] = BUNKER_SHAPE[r][c] === "#" ? 1 : 0;- }- }- }+export function segmentX(seg: number): number {+ return BARRIER_X + seg * (SEG_W + SEG_GAP);}-/** Solid cells left in one bunker (tests and balance). */-export function bunkerCells(state: RaidersState, bunker: number): number {+/** Charge points left in the whole barrier (tests and balance). */+export function barrierCharge(state: RaidersState): number {let n = 0;- const base = bunker * BUNKER_ROWS * BUNKER_COLS;- for (let i = 0; i < BUNKER_ROWS * BUNKER_COLS; i += 1) n += state.bunkers[base + i];+ for (let i = 0; i < SEGMENTS; i += 1) n += state.barrier[i];return n;}+/** Left pixel of the raider at (row, col), relative to the swarm's origin. */+function localX(row: number, col: number): number {+ return col * CELL_W + (row % 2) * STAGGER + (CELL_W - KIND_W[ROW_KIND[row]]) / 2;+}++/** Left pixel of the raider at (row, col). */+export function alienX(state: RaidersState, row: number, col: number): number {+ return state.fx + localX(row, col);+}++export function alienY(state: RaidersState, row: number): number {+ return state.fy + row * CELL_H;+}++/** Bounds of the living swarm relative to its origin: [left, right, maxRow]; false when it is empty. */+function swarmBounds(state: RaidersState, out: number[]): boolean {+ let left = Infinity, right = -Infinity, maxRow = -1;+ for (let r = 0; r < ROWS; r += 1) {+ for (let c = 0; c < COLS; c += 1) {+ if (!state.alive[r * COLS + c]) continue;+ const x = localX(r, c);+ if (x < left) left = x;+ if (x + KIND_W[ROW_KIND[r]] > right) right = x + KIND_W[ROW_KIND[r]];+ if (r > maxRow) maxRow = r;+ }+ }+ out[0] = left; out[1] = right; out[2] = maxRow;+ return maxRow >= 0;+}+const bounds = [0, 0, 0];++/** Where the swarm's origin wants to be at the current sway: centred, swinging as wide as the walls allow. */+function swayTargetX(state: RaidersState): number {+ if (!swarmBounds(state, bounds)) return state.fx;+ const [left, right] = bounds;+ const reach = Math.max(0, (WIDTH - 2 * EDGE_MARGIN - (right - left)) / 2);+ return WIDTH / 2 - (left + right) / 2 + reach * Math.sin(state.sway);+}+function startWave(state: RaidersState, random: () => number): void {state.alive.fill(1);state.aliveCount = ROWS * COLS;- state.fx = Math.round((WIDTH - COLS * CELL_W) / 2);+ state.sway = 0;+ state.fx = 0;+ state.fx = swayTargetX(state);state.fy = waveStartY(state.wave);- state.dir = 1;+ state.targetFy = state.fy;state.frame = 0;- state.stepTimer = stepDelay(state.aliveCount, state.wave);state.fireTimer = 1.2 + random();for (const s of state.shots) s.active = false;for (const b of state.bombs) b.active = false;- resetBunkers(state.bunkers);- state.saucer.active = false;- state.saucerTimer = 14 + random() * 10;+ state.barrier.fill(SEG_HP);+ state.recharge.fill(0);+ state.courier.active = false;+ state.capsule.active = false;+ state.courierTimer = 12 + random() * 10;}function create(random: () => number): RaidersState {const state: RaidersState = {phase: "play", timer: 0, elapsed: 0, score: 0, lives: 3, wave: 1, nextLifeAt: EXTRA_LIFE_EVERY,- px: PLAYER_START_X, cooldown: 0,- shots: Array.from({ length: MAX_SHOTS }, () => ({ active: false, x: 0, y: 0 })),+ px: PLAYER_START_X, cooldown: 0, rapid: 0,+ shots: Array.from({ length: RAPID_SHOTS }, () => ({ active: false, x: 0, y: 0 })),bombs: Array.from({ length: MAX_BOMBS }, () => ({ active: false, x: 0, y: 0, kind: 0, speed: 0 })),alive: new Uint8Array(ROWS * COLS), aliveCount: 0,- fx: 0, fy: 0, dir: 1, stepTimer: 0, frame: 0, fireTimer: 0,- bunkers: new Uint8Array(BUNKER_COUNT * BUNKER_ROWS * BUNKER_COLS),- saucer: { active: false, x: 0, dir: 1, points: 0 }, saucerTimer: 0,+ fx: 0, fy: 0, targetFy: 0, sway: 0, frame: 0, fireTimer: 0,+ barrier: new Uint8Array(SEGMENTS), recharge: new Float32Array(SEGMENTS),+ courier: { active: false, x: 0, y: COURIER_Y, dir: 1 }, courierTimer: 0,+ capsule: { active: false, x: 0, y: 0 },bursts: Array.from({ length: 8 }, () => ({ active: false, x: 0, y: 0, t: 0, color: "#fff" })),popups: Array.from({ length: 3 }, () => ({ active: false, x: 0, y: 0, t: 0, value: 0 })),particles: makeParticles(120),@@ -223,15 +281,6 @@ function create(random: () => number): RaidersState {return state;}-/** Left pixel of the alien at (row, col). */-export function alienX(state: RaidersState, row: number, col: number): number {- return state.fx + col * CELL_W + (CELL_W - KIND_W[ROW_KIND[row]]) / 2;-}--export function alienY(state: RaidersState, row: number): number {- return state.fy + row * CELL_H;-}-function addScore(state: RaidersState, points: number): void {state.score += points;if (state.score >= state.nextLifeAt) {@@ -245,43 +294,36 @@ function spawnBurst(state: RaidersState, x: number, y: number, color: string): vslot.active = true; slot.x = x; slot.y = y; slot.t = 0.2; slot.color = color;}-/** Erode a bunker around the cell that was hit; `down` is the shot's direction of travel. */-function erode(state: RaidersState, bunker: number, cx: number, cy: number, down: boolean, random: () => number): void {- const base = bunker * BUNKER_ROWS * BUNKER_COLS;- for (let dy = -1; dy <= 1; dy += 1) {- for (let dx = -1; dx <= 1; dx += 1) {- const x = cx + dx, y = cy + dy;- if (x < 0 || y < 0 || x >= BUNKER_COLS || y >= BUNKER_ROWS) continue;- if ((dx === 0 && dy === 0) || random() < 0.4) state.bunkers[base + y * BUNKER_COLS + x] = 0;- }- }- // Bites go a little deeper in the direction the shot was travelling.- const deeper = cy + (down ? 2 : -2);- if (deeper >= 0 && deeper < BUNKER_ROWS && random() < 0.5) state.bunkers[base + deeper * BUNKER_COLS + cx] = 0;- emitBurst(state.particles, BUNKER_X[bunker] + cx * BUNKER_CELL, BUNKER_Y + cy * BUNKER_CELL, 4, 30, "#4dff88", random, 0.3);-}--/** If (x, y) is inside a solid bunker cell, chip it and report the hit. */-function hitBunker(state: RaidersState, x: number, y: number, down: boolean, random: () => number): boolean {- if (y < BUNKER_Y || y >= BUNKER_Y + BUNKER_ROWS * BUNKER_CELL) return false;- for (let b = 0; b < BUNKER_COUNT; b += 1) {- const bx = BUNKER_X[b];- if (x < bx || x >= bx + BUNKER_COLS * BUNKER_CELL) continue;- const cx = Math.floor((x - bx) / BUNKER_CELL), cy = Math.floor((y - BUNKER_Y) / BUNKER_CELL);- if (state.bunkers[(b * BUNKER_ROWS + cy) * BUNKER_COLS + cx]) {- erode(state, b, cx, cy, down, random);- return true;- }- return false;- }- return false;+function popup(state: RaidersState, x: number, y: number, value: number): void {+ const p = state.popups.find((q) => !q.active) ?? state.popups[0];+ p.active = true; p.x = x; p.y = y; p.t = 1.2; p.value = value;+}++/** The barrier segment under x, or -1 for a gap or outside the barrier. */+function segmentAt(x: number): number {+ const rel = x - BARRIER_X;+ if (rel < 0) return -1;+ const seg = Math.floor(rel / (SEG_W + SEG_GAP));+ if (seg >= SEGMENTS || rel - seg * (SEG_W + SEG_GAP) >= SEG_W) return -1;+ return seg;+}++/** A raider shot at (x, y) hits a charged segment: drain it and report the hit. */+function hitBarrier(state: RaidersState, x: number, y: number, random: () => number): boolean {+ if (y < BARRIER_Y || y >= BARRIER_Y + BARRIER_H) return false;+ const seg = segmentAt(x);+ if (seg < 0 || state.barrier[seg] === 0) return false;+ state.barrier[seg] -= 1;+ state.recharge[seg] = 0;+ emitBurst(state.particles, x, BARRIER_Y, 5, 30, "#4fb3ff", random, 0.3);+ return true;}function killAlien(state: RaidersState, row: number, col: number, random: () => number): void {state.alive[row * COLS + col] = 0;state.aliveCount -= 1;const kind = ROW_KIND[row];- addScore(state, KIND_POINTS[kind]);+ addScore(state, alienPoints(kind, state.wave));const x = alienX(state, row, col), y = alienY(state, row);spawnBurst(state, x + KIND_W[kind] / 2, y + ALIEN_H / 2, KIND_COLOR[kind]);emitBurst(state.particles, x + KIND_W[kind] / 2, y + ALIEN_H / 2, 10, 70, KIND_COLOR[kind], random, 0.45);@@ -289,14 +331,16 @@ function killAlien(state: RaidersState, row: number, col: number, random: () =>state.phase = "clear";state.timer = CLEAR_S;for (const b of state.bombs) b.active = false;- state.saucer.active = false;+ state.courier.active = false;}}-/** The alien hit by a point, as row * COLS + col, or -1. */+/** The raider hit by a point, as row * COLS + col, or -1. */function alienAt(state: RaidersState, x: number, y: number): number {- const col = Math.floor((x - state.fx) / CELL_W), row = Math.floor((y - state.fy) / CELL_H);- if (col < 0 || col >= COLS || row < 0 || row >= ROWS || !state.alive[row * COLS + col]) return -1;+ const row = Math.floor((y - state.fy) / CELL_H);+ if (row < 0 || row >= ROWS) return -1;+ const col = Math.floor((x - state.fx - (row % 2) * STAGGER) / CELL_W);+ if (col < 0 || col >= COLS || !state.alive[row * COLS + col]) return -1;const ax = alienX(state, row, col), ay = alienY(state, row);return x >= ax && x < ax + KIND_W[ROW_KIND[row]] && y >= ay && y < ay + ALIEN_H ? row * COLS + col : -1;}@@ -306,136 +350,125 @@ function killPlayer(state: RaidersState, random: () => number): void {state.timer = DEATH_S;state.lives = Math.max(0, state.lives - 1);state.shake = 0.4;+ state.rapid = 0;for (const b of state.bombs) b.active = false;for (const s of state.shots) s.active = false;- emitBurst(state.particles, state.px + PLAYER_W / 2, PLAYER_Y + 4, 28, 90, "#63f3ff", random, 0.9);- emitBurst(state.particles, state.px + PLAYER_W / 2, PLAYER_Y + 4, 14, 60, "#fff6a8", random, 0.6);+ state.capsule.active = false;+ emitBurst(state.particles, state.px + PLAYER_W / 2, PLAYER_Y + 4, 28, 90, "#f2c14e", random, 0.9);+ emitBurst(state.particles, state.px + PLAYER_W / 2, PLAYER_Y + 4, 14, 60, "#ffffff", random, 0.6);}-/** Bounds of the living formation: [minCol, maxCol, maxRow], or null when it is empty. */-function formationBounds(state: RaidersState, out: number[]): boolean {- let minCol = COLS, maxCol = -1, maxRow = -1;- for (let r = 0; r < ROWS; r += 1) {- for (let c = 0; c < COLS; c += 1) {- if (!state.alive[r * COLS + c]) continue;- if (c < minCol) minCol = c;- if (c > maxCol) maxCol = c;- if (r > maxRow) maxRow = r;- }- }- out[0] = minCol; out[1] = maxCol; out[2] = maxRow;- return maxCol >= 0;-}-const bounds = [0, 0, 0];--/** One march step: sideways, or down and turn around at a wall. */-export function march(state: RaidersState, random: () => number): void {- if (!formationBounds(state, bounds)) return;- const [minCol, maxCol, maxRow] = bounds;- const left = state.fx + minCol * CELL_W + 1;- const right = state.fx + (maxCol + 1) * CELL_W - 1;- const atWall = state.dir > 0 ? right + MARCH_X > WIDTH - EDGE_MARGIN : left - MARCH_X < EDGE_MARGIN;- if (atWall) {- state.fy += DROP_Y;- state.dir = state.dir > 0 ? -1 : 1;- } else {- state.fx += MARCH_X * state.dir;- }- state.frame = state.frame ? 0 : 1;- const bottom = state.fy + maxRow * CELL_H + ALIEN_H;- // Aliens grind through any bunker they march into.- if (bottom > BUNKER_Y) {- for (let r = 0; r <= maxRow; r += 1) {- const ay = alienY(state, r);- if (ay + ALIEN_H <= BUNKER_Y) continue;+/**+ * Move the swarm by `dt`: advance the sway, follow it sideways, sink at the+ * end of every sweep, burn through barrier segments it reaches, and end the+ * run when it reaches the fighter.+ */+export function swaySwarm(state: RaidersState, dt: number, random: () => number): void {+ if (state.aliveCount <= 0) return;+ const rate = swayRate(state.aliveCount, state.wave);+ const before = Math.floor(state.sway / Math.PI);+ state.sway += rate * dt;+ if (Math.floor(state.sway / Math.PI) > before) state.targetFy += SINK_Y;+ state.frame = Math.floor(state.sway / (Math.PI / 4)) % 2 === 0 ? 0 : 1;+ // Follow the sway; a sudden change of reach (an outer column falls) is eased in, never jumped.+ const target = swayTargetX(state);+ const maxMove = Math.max(70, rate * WIDTH * 0.6) * dt;+ state.fx += clamp(target - state.fx, -maxMove, maxMove);+ state.fy = Math.min(state.targetFy, state.fy + SINK_SPEED * dt);++ swarmBounds(state, bounds);+ const bottom = state.fy + bounds[2] * CELL_H + ALIEN_H;+ if (bottom > BARRIER_Y) {+ // Raiders grind through every segment they sink into.+ for (let r = 0; r <= bounds[2]; r += 1) {+ if (alienY(state, r) + ALIEN_H <= BARRIER_Y) continue;for (let c = 0; c < COLS; c += 1) {if (!state.alive[r * COLS + c]) continue;const ax = alienX(state, r, c);- for (let y = ay; y < ay + ALIEN_H; y += BUNKER_CELL) {- for (let x = ax; x < ax + KIND_W[ROW_KIND[r]]; x += BUNKER_CELL) clearBunkerAt(state, x, y);+ for (let x = ax; x < ax + KIND_W[ROW_KIND[r]]; x += 2) {+ const seg = segmentAt(x);+ if (seg >= 0) { state.barrier[seg] = 0; state.recharge[seg] = 0; }}}}}if (bottom >= PLAYER_Y && state.phase === "play") {- // The formation has landed: the run is over no matter how many lives are left.+ // The swarm has landed: the run is over no matter how many lives are left.killPlayer(state, random);state.lives = 0;}}-function clearBunkerAt(state: RaidersState, x: number, y: number): void {- if (y < BUNKER_Y || y >= BUNKER_Y + BUNKER_ROWS * BUNKER_CELL) return;- for (let b = 0; b < BUNKER_COUNT; b += 1) {- const bx = BUNKER_X[b];- if (x < bx || x >= bx + BUNKER_COLS * BUNKER_CELL) continue;- state.bunkers[(b * BUNKER_ROWS + Math.floor((y - BUNKER_Y) / BUNKER_CELL)) * BUNKER_COLS + Math.floor((x - bx) / BUNKER_CELL)] = 0;+/** A raider on the swarm's front line: nothing living below it that would catch its shot. */+function frontLine(state: RaidersState, row: number, col: number): boolean {+ const cx = localX(row, col) + KIND_W[ROW_KIND[row]] / 2;+ for (let r = row + 1; r < ROWS; r += 1) {+ for (let c = 0; c < COLS; c += 1) {+ if (!state.alive[r * COLS + c]) continue;+ const x = localX(r, c);+ if (cx >= x - 1 && cx <= x + KIND_W[ROW_KIND[r]] + 1) return false;+ }}+ return true;}-/** Fire an alien shot: aimed from the column above the cannon, or from a random column. */+/** Fire a raider shot: from the front-line raider nearest the fighter, or from a random one. */function alienFire(state: RaidersState, random: () => number): void {let active = 0;for (const b of state.bombs) if (b.active) active += 1;if (active >= maxBombs(state.wave)) return;const aimed = random() < 0.45;- let col = -1;- if (aimed) {- let best = Infinity;- const target = state.px + PLAYER_W / 2;- for (let c = 0; c < COLS; c += 1) {- if (!columnAlive(state, c)) continue;- const d = Math.abs(state.fx + c * CELL_W + CELL_W / 2 - target);- if (d < best) { best = d; col = c; }+ const target = state.px + PLAYER_W / 2;+ let pick = -1, best = Infinity, count = 0;+ for (let i = 0; i < ROWS * COLS; i += 1) {+ if (!state.alive[i] || !frontLine(state, Math.floor(i / COLS), i % COLS)) continue;+ count += 1;+ if (aimed) {+ const r = Math.floor(i / COLS);+ const d = Math.abs(alienX(state, r, i % COLS) + KIND_W[ROW_KIND[r]] / 2 - target);+ if (d < best) { best = d; pick = i; }+ }+ }+ if (!aimed && count > 0) {+ let n = Math.floor(random() * count);+ for (let i = 0; i < ROWS * COLS && pick < 0; i += 1) {+ if (state.alive[i] && frontLine(state, Math.floor(i / COLS), i % COLS) && n-- === 0) pick = i;}- } else {- // Pick the n-th living column.- let living = 0;- for (let c = 0; c < COLS; c += 1) if (columnAlive(state, c)) living += 1;- let pick = Math.floor(random() * living);- for (let c = 0; c < COLS && col < 0; c += 1) if (columnAlive(state, c) && pick-- === 0) col = c;}- if (col < 0) return;- let row = ROWS - 1;- while (row >= 0 && !state.alive[row * COLS + col]) row -= 1;const bomb = state.bombs.find((b) => !b.active);- if (!bomb || row < 0) return;+ if (!bomb || pick < 0) return;+ const row = Math.floor(pick / COLS);bomb.active = true;- bomb.x = Math.round(state.fx + col * CELL_W + CELL_W / 2);+ bomb.x = Math.round(alienX(state, row, pick % COLS) + KIND_W[ROW_KIND[row]] / 2);bomb.y = alienY(state, row) + ALIEN_H;bomb.kind = aimed ? 1 : random() < 0.3 ? 2 : 0;bomb.speed = 70 + 6 * Math.min(state.wave, 8) + (bomb.kind === 2 ? 30 : 0);}-function columnAlive(state: RaidersState, col: number): boolean {- for (let r = 0; r < ROWS; r += 1) if (state.alive[r * COLS + col]) return true;- return false;-}-function stepShots(state: RaidersState, dt: number, random: () => number): void {for (const shot of state.shots) {if (!shot.active) continue;- // Move in 2-pixel steps so a fast shot never skips over a bunker cell or an alien.+ // Move in 2-pixel steps so a fast shot never skips over a raider.const steps = Math.max(1, Math.ceil((SHOT_SPEED * dt) / 2));const stepLen = (SHOT_SPEED * dt) / steps;for (let i = 0; i < steps && shot.active; i += 1) {shot.y -= stepLen;if (shot.y < 12) { shot.active = false; break; }- if (hitBunker(state, shot.x, shot.y, false, random)) { shot.active = false; break; }const hit = alienAt(state, shot.x, shot.y);if (hit >= 0) {shot.active = false;killAlien(state, Math.floor(hit / COLS), hit % COLS, random);break;}- const s = state.saucer;- if (s.active && shot.x >= s.x && shot.x < s.x + SAUCER_W && shot.y >= SAUCER_Y && shot.y < SAUCER_Y + 7) {+ const k = state.courier;+ if (k.active && shot.x >= k.x && shot.x < k.x + COURIER_W && shot.y >= k.y && shot.y < k.y + COURIER_H) {shot.active = false;- s.active = false;- addScore(state, s.points);- const popup = state.popups.find((p) => !p.active) ?? state.popups[0];- popup.active = true; popup.x = s.x + SAUCER_W / 2; popup.y = SAUCER_Y; popup.t = 1.2; popup.value = s.points;- emitBurst(state.particles, s.x + SAUCER_W / 2, SAUCER_Y + 3, 18, 80, "#ff4f6d", random, 0.6);+ k.active = false;+ addScore(state, COURIER_POINTS);+ popup(state, k.x + COURIER_W / 2, k.y, COURIER_POINTS);+ emitBurst(state.particles, k.x + COURIER_W / 2, k.y + 3, 18, 80, "#5ee0c8", random, 0.6);+ const cap = state.capsule;+ cap.active = true; cap.x = Math.round(k.x + COURIER_W / 2 - 2); cap.y = k.y + COURIER_H;break;}for (const b of state.bombs) {@@ -460,10 +493,10 @@ function stepBombs(state: RaidersState, dt: number, random: () => number): voidconst tip = b.y + 6;if (tip >= GROUND_Y) {b.active = false;- emitBurst(state.particles, b.x, GROUND_Y - 1, 4, 25, "#c58bff", random, 0.3);+ emitBurst(state.particles, b.x, GROUND_Y - 1, 4, 25, "#9d7bff", random, 0.3);break;}- if (hitBunker(state, b.x, tip, true, random)) { b.active = false; break; }+ if (hitBarrier(state, b.x, tip, random)) { b.active = false; break; }if (state.phase === "play" && b.x >= state.px && b.x < state.px + PLAYER_W && tip >= PLAYER_Y + 2 && b.y < PLAYER_Y + PLAYER_H) {b.active = false;killPlayer(state, random);@@ -473,6 +506,48 @@ function stepBombs(state: RaidersState, dt: number, random: () => number): void}}+function stepBarrier(state: RaidersState, dt: number): void {+ for (let i = 0; i < SEGMENTS; i += 1) {+ if (state.barrier[i] >= SEG_HP) continue;+ state.recharge[i] += dt;+ if (state.recharge[i] >= RECHARGE_S) {+ state.recharge[i] = 0;+ state.barrier[i] += 1;+ }+ }+}++function stepCourier(state: RaidersState, dt: number, random: () => number): void {+ const k = state.courier;+ if (k.active) {+ k.x += k.dir * COURIER_SPEED * dt;+ // A zigzag: straight diagonal legs, turning every 24 pixels.+ const leg = ((k.x % 48) + 48) % 48;+ k.y = COURIER_Y + (leg < 24 ? leg : 48 - leg) * 0.35;+ if (k.x < -COURIER_W - 2 || k.x > WIDTH + 2) k.active = false;+ } else {+ state.courierTimer -= dt;+ if (state.courierTimer <= 0 && state.aliveCount >= 6) {+ k.active = true;+ k.dir = random() < 0.5 ? 1 : -1;+ k.x = k.dir > 0 ? -COURIER_W : WIDTH;+ k.y = COURIER_Y;+ state.courierTimer = 18 + random() * 12;+ }+ }+ const cap = state.capsule;+ if (cap.active) {+ cap.y += CAPSULE_SPEED * dt;+ if (cap.y + 5 >= PLAYER_Y && cap.y < PLAYER_Y + PLAYER_H && cap.x + 4 > state.px && cap.x < state.px + PLAYER_W) {+ cap.active = false;+ state.rapid = RAPID_S;+ emitBurst(state.particles, cap.x + 2, PLAYER_Y, 12, 50, "#5ee0c8", random, 0.5);+ } else if (cap.y >= GROUND_Y) {+ cap.active = false;+ }+ }+}+function step(state: RaidersState, input: RetroInput, dt: number, random: () => number): void {if (state.phase === "over") {stepParticles(state.particles, dt, 40);@@ -509,30 +584,28 @@ function step(state: RaidersState, input: RetroInput, dt: number, random: () =>return;}- // The cannon.+ // The fighter.const move = (input.right ? 1 : 0) - (input.left ? 1 : 0);state.px = clamp(state.px + move * PLAYER_SPEED * dt, 4, WIDTH - 4 - PLAYER_W);state.cooldown -= dt;+ state.rapid = Math.max(0, state.rapid - dt);// A tap shorter than one frame still fires: the press edge counts like a held button.if ((input.a || input.pressed.a) && state.cooldown <= 0) {+ let active = 0;+ for (const s of state.shots) if (s.active) active += 1;const shot = state.shots.find((s) => !s.active);- if (shot) {+ if (shot && active < (state.rapid > 0 ? RAPID_SHOTS : MAX_SHOTS)) {shot.active = true;- shot.x = Math.round(state.px) + 6;+ shot.x = Math.round(state.px) + 5;shot.y = PLAYER_Y - 1;- state.cooldown = SHOT_COOLDOWN;+ state.cooldown = state.rapid > 0 ? RAPID_COOLDOWN : SHOT_COOLDOWN;}}stepShots(state, dt, random);if (state.phase !== "play") return;- // The formation.- state.stepTimer -= dt;- if (state.stepTimer <= 0) {- march(state, random);- state.stepTimer = stepDelay(state.aliveCount, state.wave);- if (state.phase !== "play") return;- }+ swaySwarm(state, dt, random);+ if (state.phase !== "play") return;state.fireTimer -= dt;if (state.fireTimer <= 0) {alienFire(state, random);@@ -540,41 +613,28 @@ function step(state: RaidersState, input: RetroInput, dt: number, random: () =>}stepBombs(state, dt, random);if (state.phase !== "play") return;-- // The bonus saucer.- const s = state.saucer;- if (s.active) {- s.x += s.dir * SAUCER_SPEED * dt;- if (s.x < -SAUCER_W - 2 || s.x > WIDTH + 2) s.active = false;- } else {- state.saucerTimer -= dt;- if (state.saucerTimer <= 0 && state.aliveCount >= 8) {- s.active = true;- s.dir = random() < 0.5 ? 1 : -1;- s.x = s.dir > 0 ? -SAUCER_W : WIDTH;- s.points = SAUCER_POINTS[Math.floor(random() * SAUCER_POINTS.length)];- state.saucerTimer = 16 + random() * 14;- }- }+ stepBarrier(state, dt);+ stepCourier(state, dt, random);}function status(state: RaidersState): RetroStatus {return { score: state.score, lives: state.lives, level: state.wave, over: state.phase === "over" };}-const STARS = starField(40, WIDTH, 200, 7);+const STARS = starField(46, WIDTH, 190, 11);+const SEG_COLOR = ["", "rgba(79,179,255,0.35)", "rgba(79,179,255,0.65)", "#4fb3ff"];function draw(ctx: CanvasRenderingContext2D, state: RaidersState, info: RetroDrawInfo): void {- ctx.fillStyle = "#05030f";+ ctx.fillStyle = "#070a12";ctx.fillRect(0, 0, WIDTH, HEIGHT);- drawStars(ctx, STARS, info.time, info.reduced);+ drawStars(ctx, STARS, info.time, info.reduced, "#9fb4d8");ctx.save();if (state.shake > 0 && !info.reduced) {ctx.translate(Math.round(Math.sin(info.time * 83) * state.shake * 5), Math.round(Math.cos(info.time * 71) * state.shake * 3));}- // Before the first step the formation shuffles gently on the title screen.+ // Before the first step the swarm flexes gently on the title screen.const frame = info.idle && state.elapsed === 0 ? Math.floor(info.time * 1.6) % 2 : state.frame;for (let r = 0; r < ROWS; r += 1) {const kind = ROW_KIND[r];@@ -587,79 +647,101 @@ function draw(ctx: CanvasRenderingContext2D, state: RaidersState, info: RetroDrafor (const b of state.bursts) {if (!b.active) continue;ctx.fillStyle = b.color;- drawSprite(ctx, BURST_SPRITE, b.x - 5, b.y - 3);+ drawSprite(ctx, BURST_SPRITE, b.x - 4, b.y - 3);}- const s = state.saucer;- if (s.active) {- ctx.fillStyle = "#ff4f6d";- drawSprite(ctx, SAUCER_SPRITE, s.x, SAUCER_Y);- // Running lights travel along the rim (held still under reduced motion).- ctx.fillStyle = "#fff3a8";- const lit = info.reduced ? 0 : Math.floor(info.time * 8) % 5;- for (let i = 0; i < 5; i += 1) if (i === lit || info.reduced) ctx.fillRect(Math.round(s.x) + 1 + i * 3, SAUCER_Y + 3, 1, 1);+ const k = state.courier;+ if (k.active) {+ ctx.fillStyle = "#5ee0c8";+ drawSprite(ctx, COURIER_SPRITE, k.x, k.y);+ // A beacon blinks on its belly (held lit under reduced motion).+ if (info.reduced || Math.floor(info.time * 6) % 2 === 0) {+ ctx.fillStyle = "#ffffff";+ ctx.fillRect(Math.round(k.x) + 5, Math.round(k.y) + 5, 2, 1);+ }+ }+ if (state.capsule.active) {+ ctx.fillStyle = info.reduced || Math.floor(info.time * 8) % 2 === 0 ? "#5ee0c8" : "#d8fff6";+ drawSprite(ctx, CAPSULE_SPRITE, state.capsule.x, state.capsule.y);}- ctx.fillStyle = "#ffd35a";+ ctx.fillStyle = "#ffe2a8";for (const p of state.popups) {if (p.active) drawNumber(ctx, p.value, p.x, p.y + (info.reduced ? 0 : -(1.2 - p.t) * 6), 1, "center");}- ctx.fillStyle = "#4dff88";- for (let b = 0; b < BUNKER_COUNT; b += 1) {- for (let r = 0; r < BUNKER_ROWS; r += 1) {- for (let c = 0; c < BUNKER_COLS; c += 1) {- if (state.bunkers[(b * BUNKER_ROWS + r) * BUNKER_COLS + c]) {- ctx.fillRect(BUNKER_X[b] + c * BUNKER_CELL, BUNKER_Y + r * BUNKER_CELL, BUNKER_CELL, BUNKER_CELL);- }- }+ // The barrier: brighter segments hold more charge; a drained one shows only a faint socket.+ for (let i = 0; i < SEGMENTS; i += 1) {+ const hp = state.barrier[i];+ const x = segmentX(i);+ if (hp === 0) {+ ctx.fillStyle = "rgba(79,179,255,0.12)";+ ctx.fillRect(x, BARRIER_Y + 1, SEG_W, 1);+ continue;+ }+ ctx.fillStyle = SEG_COLOR[hp];+ ctx.fillRect(x, BARRIER_Y, SEG_W, BARRIER_H);+ if (hp === SEG_HP) {+ ctx.fillStyle = "#d6efff";+ ctx.fillRect(x + 1, BARRIER_Y + 1, SEG_W - 2, 1);}}+ const shipColor = state.rapid > 0 ? "#5ee0c8" : "#f2c14e";if (state.phase === "dying") {// The wreck smoulders between two frames; under reduced motion it holds still.- ctx.fillStyle = "#63f3ff";+ ctx.fillStyle = "#f2c14e";drawSprite(ctx, WRECK_SPRITES[info.reduced ? 0 : Math.floor(info.time * 6) % 2], state.px, PLAYER_Y);} else if (state.phase !== "over") {- ctx.fillStyle = "#63f3ff";+ ctx.fillStyle = shipColor;drawSprite(ctx, PLAYER_SPRITE, state.px, PLAYER_Y);+ // Engine glow under the two nacelles.+ if (!info.reduced) {+ ctx.fillStyle = Math.floor(info.time * 12) % 2 === 0 ? "#ff8a3d" : "#ffd37a";+ ctx.fillRect(Math.round(state.px) + 1, PLAYER_Y + PLAYER_H, 1, 1);+ ctx.fillRect(Math.round(state.px) + PLAYER_W - 2, PLAYER_Y + PLAYER_H, 1, 1);+ }}- ctx.fillStyle = "#ffffff";- for (const shot of state.shots) if (shot.active) ctx.fillRect(shot.x, Math.round(shot.y), 1, 5);+ ctx.fillStyle = state.rapid > 0 ? "#5ee0c8" : "#ffe2a8";+ for (const shot of state.shots) if (shot.active) ctx.fillRect(shot.x, Math.round(shot.y), 1, 4);for (const b of state.bombs) {if (!b.active) continue;const y = Math.round(b.y);if (b.kind === 1) {- ctx.fillStyle = "#ffd35a";+ ctx.fillStyle = "#ffb547";const phase = Math.floor(y / 3) % 2;for (let i = 0; i < 7; i += 1) ctx.fillRect(b.x - 1 + ((i + phase) % 2) * 2, y + i, 1, 1);} else if (b.kind === 2) {- ctx.fillStyle = "#ff7a5a";+ ctx.fillStyle = "#ff6b5a";ctx.fillRect(b.x, y, 1, 7);- ctx.fillRect(b.x - 1, y + 4, 3, 1);+ ctx.fillRect(b.x - 1, y + 5, 3, 1);} else {- ctx.fillStyle = "#f0e6ff";- ctx.fillRect(b.x, y, 1, 6);- ctx.fillRect(b.x - 1, y + 1 + (Math.floor(y / 4) % 2) * 3, 3, 1);+ ctx.fillStyle = "#c9b8ff";+ ctx.fillRect(b.x - 1, y, 3, 2);+ ctx.fillRect(b.x, y + 2, 1, 4);}}drawParticles(ctx, state.particles);ctx.restore();- // Ground, score, wave and spare cannons.- ctx.fillStyle = "#5c3dff";+ // Ground, score, wave, rapid-fire gauge and spare fighters.+ ctx.fillStyle = "#2d3a56";ctx.fillRect(0, GROUND_Y, WIDTH, 1);- ctx.fillStyle = "#e9e4ff";+ ctx.fillStyle = "#e8edf7";drawNumber(ctx, state.score, 6, 5, 2);- ctx.fillStyle = "#c58bff";+ ctx.fillStyle = "#9d7bff";drawNumber(ctx, state.wave, WIDTH - 6, 5, 2, "right");- ctx.fillStyle = "#63f3ff";- for (let i = 0; i < Math.min(state.lives, MAX_LIVES); i += 1) drawSprite(ctx, LIFE_SPRITE, 6 + i * 10, GROUND_Y + 10);+ if (state.rapid > 0) {+ ctx.fillStyle = "#5ee0c8";+ ctx.fillRect(WIDTH - 6 - Math.round(40 * (state.rapid / RAPID_S)), GROUND_Y + 6, Math.round(40 * (state.rapid / RAPID_S)), 2);+ }+ ctx.fillStyle = "#f2c14e";+ for (let i = 0; i < Math.min(state.lives, MAX_LIVES); i += 1) drawSprite(ctx, LIFE_SPRITE, 6 + i * 9, GROUND_Y + 6);if (state.phase === "clear") {// The coming wave's number, large, while the field resets.- ctx.fillStyle = "#c58bff";- drawNumber(ctx, state.wave + 1, WIDTH / 2, 110, 5, "center");+ ctx.fillStyle = "#9d7bff";+ drawNumber(ctx, state.wave + 1, WIDTH / 2, 104, 5, "center");}}diff --git a/dodaios/ui/web/frontend/src/components/society/arcade/games/roadHopper.test.ts b/dodaios/ui/web/frontend/src/components/society/arcade/games/roadHopper.test.tsindex 37b39c9423..4a795fdca5 100644--- a/dodaios/ui/web/frontend/src/components/society/arcade/games/roadHopper.test.ts+++ b/dodaios/ui/web/frontend/src/components/society/arcade/games/roadHopper.test.ts@@ -1,8 +1,8 @@import { describe, expect, it } from "vitest";import { idleInput, RETRO_STEP, seededRandom, type RetroButtons, type RetroInput } from "../retroGame";import game, {- BAY_X, CELL, HOME_ROW, LANES, LIFE_TIME, START_ROW, START_X,- diveState, itemX, levelFactor, platformAt, vehicleAt, type HopperState,+ BATTERY_POINTS, BATTERY_TIME, CELL, HEIGHT, HOME_ROW, LANES, LEVEL_POINTS, PAD_POINTS, PAD_X, PARCEL_BONUS, QUAY_ROW, ROW_POINTS,+ START_ROW, START_X, WIDTH, carrierAt, itemX, levelFactor, sinkState, vehicleAt, type HopperState,} from "./roadHopper";const rnd = seededRandom(11);@@ -27,7 +27,7 @@ const parkItem = (s: HopperState, lane: number, x: number): number => {};const fresh = (): HopperState => {const s = game.create(seededRandom(5));- s.flyTimer = 999;+ s.parcelTimer = 999;return s;};@@ -53,11 +53,21 @@ function fakeContext(): { ctx: CanvasRenderingContext2D; depth: () => number; re}describe("road hopper", () => {- it("starts on the bottom bank with three lives and a full clock", () => {+ it("has its own field: a wide screen, four canal lanes, four road lanes, three pads", () => {+ expect([WIDTH, HEIGHT]).toEqual([game.width, game.height]);+ expect(WIDTH).toBeGreaterThan(HEIGHT);+ expect(LANES.filter((l) => l.kind === "barge" || l.kind === "floe")).toHaveLength(4);+ expect(LANES.filter((l) => l.row > QUAY_ROW)).toHaveLength(4);+ expect(PAD_X).toHaveLength(3);+ // Every pad is reachable in whole hops from the start column.+ for (const x of PAD_X) expect(Math.abs(x - START_X) % CELL).toBe(0);+ });++ it("starts on the street with three lives and a full battery", () => {const s = fresh();expect(game.status(s)).toEqual({ score: 0, lives: 3, level: 1, over: false });- expect([s.x, s.row, s.timeLeft]).toEqual([START_X, START_ROW, LIFE_TIME]);- expect(Array.from(s.bays)).toEqual([0, 0, 0, 0, 0]);+ expect([s.x, s.row, s.battery]).toEqual([START_X, START_ROW, BATTERY_TIME]);+ expect(Array.from(s.pads)).toEqual([0, 0, 0]);});it("hops one cell per press; holding the key does not keep hopping", () => {@@ -80,22 +90,22 @@ describe("road hopper", () => {expect(s.x).toBe(START_X + 2 * CELL);});- it("a vehicle squashes the frog", () => {+ it("a vehicle wrecks the bot", () => {const s = fresh();- const row = 10, lane = laneOf(row);+ const row = 9, lane = laneOf(row);parkItem(s, lane, 100);s.row = row;- s.x = 108;+ s.x = 110;expect(vehicleAt(s, row, s.x)).toBe(true);game.step(s, idleInput(), RETRO_STEP, rnd);expect(s.phase).toBe("dying");- expect(s.deathKind).toBe("splat");+ expect(s.deathKind).toBe("crash");expect(s.lives).toBe(2);run(s, idleInput(), 1.5);expect([s.phase, s.row, s.x]).toEqual(["play", START_ROW, START_X]);});- it("a log carries the frog along", () => {+ it("a hover barge carries the bot along", () => {const s = fresh();const row = 4, lane = laneOf(row);const len = parkItem(s, lane, 60);@@ -107,128 +117,136 @@ describe("road hopper", () => {expect(Math.abs(s.x - (60 + len / 2) - LANES[lane].speed * 0.5)).toBeLessThan(2);});- it("open water drowns the frog", () => {+ it("open water sinks the bot", () => {const s = fresh();const row = 2;let x = 20;- while (platformAt(s, row, x)) x += 4;+ while (carrierAt(s, row, x)) x += 4;s.row = row;s.x = x;game.step(s, idleInput(), RETRO_STEP, rnd);expect(s.phase).toBe("dying");- expect(s.deathKind).toBe("splash");+ expect(s.deathKind).toBe("sink");});- it("a diving turtle drops the frog in the water", () => {+ it("a floe that cracks and sinks drops the bot in the water", () => {const s = fresh();const row = 3, lane = laneOf(row);- // Group 1 of this lane dives; find a moment it is under.+ // Floe 1 of this lane sinks; find a moment it is gone.let clock = 0;- while (diveState(lane, 1, clock) !== 2) clock += 0.1;- s.diveClock = clock;+ while (sinkState(lane, 1, clock) !== 2) clock += 0.1;+ s.sinkClock = clock;s.row = row;- const x0 = itemX(lane, 1, s.shifts[lane]);- s.x = x0 + 16;+ s.x = itemX(lane, 1, s.shifts[lane]) + 16;game.step(s, idleInput(), RETRO_STEP, rnd);expect(s.phase).toBe("dying");+ // A cracking floe still holds.+ while (sinkState(lane, 1, clock) !== 1) clock += 0.1;+ const t = fresh();+ t.sinkClock = clock;+ t.row = row;+ t.x = itemX(lane, 1, t.shifts[lane]) + 16;+ expect(carrierAt(t, row, t.x)).toBe(true);});it("being carried off the edge costs a life", () => {const s = fresh();const row = 2, lane = laneOf(row);- parkItem(s, lane, 180);+ parkItem(s, lane, 210);s.row = row;- s.x = 214;+ s.x = WIDTH - 10;run(s, idleInput(), 1);expect(s.phase).toBe("dying");expect(s.lives).toBe(2);});- it("filling a bay scores the time left and sends a new frog", () => {+ it("lighting a pad scores the battery left and sends a new bot", () => {const s = fresh();s.row = 2;- s.x = BAY_X[0];+ s.x = PAD_X[0];game.step(s, press("up"), RETRO_STEP, rnd);run(s, idleInput(), 0.2);- expect(s.bays[0]).toBe(1);- expect(s.score).toBeGreaterThanOrEqual(50 + 10 * 29);+ expect(s.pads[0]).toBe(1);+ expect(s.score).toBeGreaterThanOrEqual(PAD_POINTS + BATTERY_POINTS * (BATTERY_TIME - 1));expect([s.row, s.x, s.phase]).toEqual([START_ROW, START_X, "play"]);});- it("the hedge between bays and a filled bay both kill", () => {+ it("the live fence between pads and a lit pad both zap", () => {const s = fresh();s.row = 2;- s.x = (BAY_X[0] + BAY_X[1]) / 2;+ s.x = (PAD_X[0] + PAD_X[1]) / 2;game.step(s, press("up"), RETRO_STEP, rnd);run(s, idleInput(), 0.2);expect(s.phase).toBe("dying");expect(s.row).toBe(HOME_ROW);const t = fresh();- t.bays[2] = 1;+ t.pads[2] = 1;t.row = 2;- t.x = BAY_X[2];+ t.x = PAD_X[2];game.step(t, press("up"), RETRO_STEP, rnd);run(t, idleInput(), 0.2);expect(t.phase).toBe("dying");});- it("a fly in a bay is worth a bonus", () => {+ it("a parcel waiting on a pad is worth a bonus", () => {const s = fresh();- s.flyBay = 1;- s.flyLeft = 5;+ s.parcelPad = 1;+ s.parcelLeft = 5;s.row = 2;- s.x = BAY_X[1];+ s.x = PAD_X[1];game.step(s, press("up"), RETRO_STEP, rnd);run(s, idleInput(), 0.2);- expect(s.score).toBeGreaterThanOrEqual(50 + 200 + 10 * 29);- expect(s.flyBay).toBe(-1);+ expect(s.score).toBeGreaterThanOrEqual(PAD_POINTS + PARCEL_BONUS + BATTERY_POINTS * (BATTERY_TIME - 1));+ expect(s.parcelPad).toBe(-1);});- it("filling all five bays starts a faster level", () => {+ it("lighting all three pads starts a faster level", () => {const s = fresh();- s.bays.set([1, 1, 1, 1, 0]);+ s.pads.set([1, 1, 0]);s.row = 2;- s.x = BAY_X[4];+ s.x = PAD_X[2];game.step(s, press("up"), RETRO_STEP, rnd);run(s, idleInput(), 0.2);expect(s.phase).toBe("levelup");- expect(s.score).toBeGreaterThanOrEqual(1000);+ expect(s.score).toBeGreaterThanOrEqual(LEVEL_POINTS);run(s, idleInput(), 2.5);expect(game.status(s).level).toBe(2);- expect(Array.from(s.bays)).toEqual([0, 0, 0, 0, 0]);+ expect(Array.from(s.pads)).toEqual([0, 0, 0]);expect(levelFactor(2)).toBeGreaterThan(levelFactor(1));});- it("the clock running out costs a life", () => {+ it("a flat battery costs a life", () => {const s = fresh();- run(s, idleInput(), LIFE_TIME - 1);+ run(s, idleInput(), BATTERY_TIME - 1);expect(s.phase).toBe("play");run(s, idleInput(), 1.5);expect(s.phase).toBe("dying");- expect(s.deathKind).toBe("time");+ expect(s.deathKind).toBe("drained");expect(s.lives).toBe(2);});it("the last life ends the run", () => {const s = fresh();s.lives = 1;- run(s, idleInput(), LIFE_TIME + 2);+ run(s, idleInput(), BATTERY_TIME + 2);expect(game.status(s)).toMatchObject({ lives: 0, over: true });});it("forward hops score once per new row", () => {const s = fresh();- s.row = 7; // the middle bank- s.bestRow = 7;+ s.row = QUAY_ROW;+ s.bestRow = QUAY_ROW;game.step(s, press("down"), RETRO_STEP, rnd);run(s, idleInput(), 0.15);expect(s.score).toBe(0);const t = fresh();+ // Park the nearest vehicle far from the start column so the hop is safe.+ parkItem(t, laneOf(START_ROW - 1), 40);game.step(t, press("up"), RETRO_STEP, rnd);run(t, idleInput(), 0.15);- expect(t.score).toBe(10);+ expect(t.score).toBe(ROW_POINTS);});it("draws every phase without throwing, idle and reduced included", () => {@@ -243,13 +261,13 @@ describe("road hopper", () => {expect(fake.depth()).toBe(0);expect(fake.rects()).toBeGreaterThan(100);}- s.bays.set([1, 0, 1, 0, 0]);- s.flyBay = 3;+ s.pads.set([1, 0, 0]);+ s.parcelPad = 2;game.step(s, press("left"), RETRO_STEP, rnd);game.draw(fakeContext().ctx, s, { time: 2, reduced: false, idle: false });- s.timeLeft = 3;+ s.battery = 3;game.draw(fakeContext().ctx, s, { time: 2, reduced: true, idle: false });- for (const kind of ["splat", "splash", "time"] as const) {+ for (const kind of ["crash", "sink", "drained"] as const) {s.phase = "dying";s.deathKind = kind;s.timer = 0.5;@@ -261,3 +279,4 @@ describe("road hopper", () => {game.draw(fakeContext().ctx, s, { time: 2, reduced: true, idle: false });});});+diff --git a/dodaios/ui/web/frontend/src/components/society/arcade/games/roadHopper.ts b/dodaios/ui/web/frontend/src/components/society/arcade/games/roadHopper.tsindex 6decb5e52f..c70ab1ec37 100644--- a/dodaios/ui/web/frontend/src/components/society/arcade/games/roadHopper.ts+++ b/dodaios/ui/web/frontend/src/components/society/arcade/games/roadHopper.ts@@ -1,10 +1,12 @@/**- * "Road Hopper": hop a little frog across five lanes of traffic and a river- * to the five home bays in the hedge at the top. One hop per press (holding a- * direction does not keep hopping). On the river only logs and turtles carry- * you; the water, a diving turtle or being carried off the edge cost a life,- * and so does the clock running out. Filling all five bays starts the next- * level with faster lanes.+ * "Road Hopper": steer a little courier bot from the street up to the three+ * delivery pads on the rooftop. It crosses four lanes of traffic, a quay and+ * a canal on the way. One hop per press (holding a direction does not keep+ * hopping). On the canal only hover barges and ice floes carry the bot; the+ * water, a floe that cracks and sinks, or being carried off the edge cost a+ * life, and so does the battery running flat. Between the pads runs a live+ * fence that zaps. Lighting all three pads starts the next level with faster+ * lanes; now and then a parcel waits on a pad for a bonus.** The lanes never store moving objects: each lane is a fixed pattern of* items plus one scrolling `shift`, so the world costs no allocations.@@ -15,35 +17,40 @@ import {type Particle, type PixelSprite,} from "./games3Kit";-export const WIDTH = 224;-export const HEIGHT = 256;+export const WIDTH = 256;+export const HEIGHT = 224;export const CELL = 16;export const HOME_ROW = 1;-export const START_ROW = 13;+export const START_ROW = 11;export const START_X = WIDTH / 2;-/** Rows 2–6 are river, row 7 the middle bank, rows 8–12 road. */-export const RIVER_TOP = 2;-export const RIVER_BOTTOM = 6;-export const ROAD_TOP = 8;-export const ROAD_BOTTOM = 12;+/** Rows 2–5 are canal, row 6 the quay, rows 7–10 road. */+export const CANAL_TOP = 2;+export const CANAL_BOTTOM = 5;+export const QUAY_ROW = 6;+export const ROAD_TOP = 7;+export const ROAD_BOTTOM = 10;export const HOP_S = 0.1;-export const LIFE_TIME = 30;+/** Seconds of battery per bot. */+export const BATTERY_TIME = 40;const DEATH_S = 1.2;const LEVEL_S = 2;-/** Half the frog's width for traffic; a river platform must hold its centre. */-const FROG_HALF = 6;-export const BAY_X: readonly number[] = [24, 68, 112, 156, 200];-/** How far off a bay's centre a landing still counts. */-const BAY_CATCH = 9;-const FLY_BONUS = 200;-const BAY_POINTS = 50;-const LEVEL_POINTS = 1000;+/** Half the bot's width for traffic; a canal carrier must hold its centre. */+const BOT_HALF = 6;+export const PAD_X: readonly number[] = [48, 128, 208];+/** How far off a pad's centre a landing still counts. */+const PAD_CATCH = 10;+export const PARCEL_BONUS = 250;+export const PAD_POINTS = 100;+/** Points per whole second of battery left when a pad lights up. */+export const BATTERY_POINTS = 5;+export const ROW_POINTS = 5;+export const LEVEL_POINTS = 750;/** Items are placed so they start fully off the left edge; any item is at most this long. */const MARGIN = 96;-export type LaneKind = "log" | "turtle" | "truck" | "car" | "racer" | "dozer";+export type LaneKind = "barge" | "floe" | "bus" | "van" | "scooter" | "sweeper";export interface LaneDef {row: number;@@ -54,33 +61,31 @@ export interface LaneDef {period: number;offsets: readonly number[];lens: readonly number[];- /** Turtle groups that dive now and then. */- dives?: readonly boolean[];+ /** Floes that crack and sink now and then. */+ sinks?: readonly boolean[];}export const LANES: readonly LaneDef[] = [- { row: 2, kind: "log", speed: 34, period: 336, offsets: [0, 112, 224], lens: [64, 64, 64] },- { row: 3, kind: "turtle", speed: -40, period: 320, offsets: [0, 80, 160, 240], lens: [32, 32, 32, 32], dives: [false, true, false, false] },- { row: 4, kind: "log", speed: 52, period: 400, offsets: [0, 200], lens: [96, 96] },- { row: 5, kind: "log", speed: 28, period: 336, offsets: [0, 112, 224], lens: [48, 48, 48] },- { row: 6, kind: "turtle", speed: -32, period: 336, offsets: [0, 112, 224], lens: [48, 48, 48], dives: [false, false, true] },- { row: 8, kind: "truck", speed: -30, period: 336, offsets: [0, 168], lens: [32, 32] },- { row: 9, kind: "racer", speed: 72, period: 336, offsets: [0, 168], lens: [16, 16] },- { row: 10, kind: "car", speed: -40, period: 336, offsets: [0, 112, 224], lens: [16, 16, 16] },- { row: 11, kind: "dozer", speed: 28, period: 336, offsets: [0, 112, 224], lens: [16, 16, 16] },- { row: 12, kind: "car", speed: -34, period: 320, offsets: [0, 80, 160, 240], lens: [16, 16, 16, 16] },+ { row: 2, kind: "barge", speed: 36, period: 384, offsets: [0, 128, 256], lens: [64, 64, 64] },+ { row: 3, kind: "floe", speed: -44, period: 352, offsets: [0, 88, 176, 264], lens: [32, 32, 32, 32], sinks: [false, true, false, false] },+ { row: 4, kind: "barge", speed: 56, period: 448, offsets: [0, 224], lens: [96, 96] },+ { row: 5, kind: "floe", speed: -30, period: 384, offsets: [0, 128, 256], lens: [48, 48, 48], sinks: [false, false, true] },+ { row: 7, kind: "bus", speed: -32, period: 384, offsets: [0, 192], lens: [40, 40] },+ { row: 8, kind: "scooter", speed: 80, period: 384, offsets: [0, 192], lens: [16, 16] },+ { row: 9, kind: "van", speed: -44, period: 384, offsets: [0, 128, 256], lens: [24, 24, 24] },+ { row: 10, kind: "sweeper", speed: 30, period: 352, offsets: [0, 117, 234], lens: [16, 16, 16] },];const LANE_OF_ROW: readonly number[] = Array.from({ length: 16 }, (_, row) => LANES.findIndex((l) => l.row === row));-/** Turtle dive cycle in seconds, and when (within it) a diving group sinks, is under, and comes back. */-const DIVE_CYCLE = 5;-const DIVE_SINK = 3;-const DIVE_UNDER = 3.6;-const DIVE_RISE = 4.8;+/** Floe sink cycle in seconds, and when (within it) a sinking floe cracks, is gone, and refreezes. */+const SINK_CYCLE = 6;+const SINK_CRACK = 3.5;+const SINK_GONE = 4.3;+const SINK_BACK = 5.4;export type HopperPhase = "play" | "dying" | "levelup" | "over";export type Direction = 0 | 1 | 2 | 3; // up, right, down, left-export type DeathKind = "splat" | "splash" | "time";+export type DeathKind = "crash" | "sink" | "drained";export interface Hop { active: boolean; t: number; fromX: number; fromRow: number; toX: number; toRow: number }interface Popup { active: boolean; x: number; y: number; t: number; value: number }@@ -93,31 +98,31 @@ export interface HopperState {score: number;lives: number;level: number;- /** The frog's centre x in pixels and its row. */+ /** The bot's centre x in pixels and its row. */x: number;row: number;facing: Direction;hop: Hop;- /** A direction pressed during a hop, taken as soon as the frog lands; -1 for none. */+ /** A direction pressed during a hop, taken as soon as the bot lands; -1 for none. */queued: number;- /** The highest row (smallest index) reached by this frog; new rows score. */+ /** The highest row (smallest index) reached by this bot; new rows score. */bestRow: number;- timeLeft: number;- bays: Uint8Array;- flyBay: number;- flyLeft: number;- flyTimer: number;+ battery: number;+ pads: Uint8Array;+ parcelPad: number;+ parcelLeft: number;+ parcelTimer: number;/** Scroll of each lane's pattern, parallel to LANES. */shifts: number[];- diveClock: number;+ sinkClock: number;deathKind: DeathKind;particles: Particle[];popups: Popup[];}-/** Lane speeds grow 20 % per level, up to a little over double. */+/** Lane speeds grow 15 % per level, up to double. */export function levelFactor(level: number): number {- return Math.min(2.2, 1 + 0.2 * (level - 1));+ return Math.min(2, 1 + 0.15 * (level - 1));}function mod(a: number, m: number): number {@@ -130,39 +135,39 @@ export function itemX(lane: number, i: number, shift: number): number {return mod(def.offsets[i] + shift, def.period) - MARGIN;}-/** 0 surfaced, 1 sinking or rising (still rideable), 2 under water. */-export function diveState(lane: number, i: number, clock: number): 0 | 1 | 2 {- if (!LANES[lane].dives?.[i]) return 0;- const t = mod(clock + i * 1.3, DIVE_CYCLE);- return t < DIVE_SINK ? 0 : t < DIVE_UNDER ? 1 : t < DIVE_RISE ? 2 : 1;+/** 0 solid, 1 cracking (still rideable), 2 sunk. */+export function sinkState(lane: number, i: number, clock: number): 0 | 1 | 2 {+ if (!LANES[lane].sinks?.[i]) return 0;+ const t = mod(clock + i * 1.7, SINK_CYCLE);+ return t < SINK_CRACK ? 0 : t < SINK_GONE ? 1 : t < SINK_BACK ? 2 : 1;}-/** Whether a frog centred at x on a river row stands on something that floats. */-export function platformAt(state: HopperState, row: number, x: number): boolean {+/** Whether a bot centred at x on a canal row stands on something that floats. */+export function carrierAt(state: HopperState, row: number, x: number): boolean {const lane = LANE_OF_ROW[row];if (lane < 0) return false;const def = LANES[lane];for (let i = 0; i < def.offsets.length; i += 1) {const x0 = itemX(lane, i, state.shifts[lane]);- if (x >= x0 + 1 && x <= x0 + def.lens[i] - 1 && diveState(lane, i, state.diveClock) !== 2) return true;+ if (x >= x0 + 1 && x <= x0 + def.lens[i] - 1 && sinkState(lane, i, state.sinkClock) !== 2) return true;}return false;}-/** Whether a frog centred at x on a road row touches a vehicle. */+/** Whether a bot centred at x on a road row touches a vehicle. */export function vehicleAt(state: HopperState, row: number, x: number): boolean {const lane = LANE_OF_ROW[row];if (lane < 0) return false;const def = LANES[lane];for (let i = 0; i < def.offsets.length; i += 1) {const x0 = itemX(lane, i, state.shifts[lane]);- if (x + FROG_HALF > x0 + 1 && x - FROG_HALF < x0 + def.lens[i] - 1) return true;+ if (x + BOT_HALF > x0 + 1 && x - BOT_HALF < x0 + def.lens[i] - 1) return true;}return false;}-export function isRiver(row: number): boolean {- return row >= RIVER_TOP && row <= RIVER_BOTTOM;+export function isCanal(row: number): boolean {+ return row >= CANAL_TOP && row <= CANAL_BOTTOM;}function isRoad(row: number): boolean {@@ -177,7 +182,7 @@ function respawn(state: HopperState): void {state.hop.active = false;state.queued = -1;state.bestRow = START_ROW;- state.timeLeft = LIFE_TIME;+ state.battery = BATTERY_TIME;}function create(random: () => number): HopperState {@@ -185,10 +190,10 @@ function create(random: () => number): HopperState {phase: "play", timer: 0, elapsed: 0, score: 0, lives: 3, level: 1,x: START_X, row: START_ROW, facing: 0,hop: { active: false, t: 0, fromX: 0, fromRow: 0, toX: 0, toRow: 0 },- queued: -1, bestRow: START_ROW, timeLeft: LIFE_TIME,- bays: new Uint8Array(5), flyBay: -1, flyLeft: 0, flyTimer: 6 + random() * 5,+ queued: -1, bestRow: START_ROW, battery: BATTERY_TIME,+ pads: new Uint8Array(PAD_X.length), parcelPad: -1, parcelLeft: 0, parcelTimer: 7 + random() * 5,shifts: LANES.map((l) => Math.floor(random() * l.period)),- diveClock: 0, deathKind: "splat",+ sinkClock: 0, deathKind: "crash",particles: makeParticles(80),popups: Array.from({ length: 3 }, () => ({ active: false, x: 0, y: 0, t: 0, value: 0 })),};@@ -209,8 +214,8 @@ function die(state: HopperState, kind: DeathKind, random: () => number): void {state.hop.active = false;state.queued = -1;const cy = state.row * CELL + CELL / 2;- if (kind === "splash") emitBurst(state.particles, state.x, cy, 16, 50, "#9fd8ff", random, 0.7);- else emitBurst(state.particles, state.x, cy, 14, 45, "#7ed957", random, 0.6);+ if (kind === "sink") emitBurst(state.particles, state.x, cy, 16, 50, "#8ff5e8", random, 0.7);+ else emitBurst(state.particles, state.x, cy, 14, 45, "#ffc64a", random, 0.6);}function startHop(state: HopperState, dir: Direction): void {@@ -219,8 +224,8 @@ function startHop(state: HopperState, dir: Direction): void {if (dir === 0) toRow = Math.max(HOME_ROW, state.row - 1);else if (dir === 2) toRow = Math.min(START_ROW, state.row + 1);else toX = state.x + (dir === 1 ? CELL : -CELL);- // On land the frog stays on screen; on the river the current may carry it off.- if (!isRiver(state.row)) toX = clamp(toX, CELL / 2, WIDTH - CELL / 2);+ // On land the bot stays on screen; on the canal the current may carry it off.+ if (!isCanal(state.row)) toX = clamp(toX, CELL / 2, WIDTH - CELL / 2);if (toRow === state.row && toX === state.x) return;const h = state.hop;h.active = true; h.t = 0; h.fromX = state.x; h.fromRow = state.row; h.toX = toX; h.toRow = toRow;@@ -231,47 +236,43 @@ function pressedDirection(input: RetroInput): number {return p.up ? 0 : p.right ? 1 : p.down ? 2 : p.left ? 3 : -1;}-/** Arrive in a bay: fill it (with any fly bonus), or die against the hedge or a full bay. */-function reachHome(state: HopperState, random: () => number): void {- const bay = BAY_X.findIndex((bx) => Math.abs(state.x - bx) <= BAY_CATCH);- if (bay < 0 || state.bays[bay]) {- die(state, "splat", random);+/** Arrive on the rooftop: light a pad (with any parcel bonus), or get zapped by the fence or a lit pad. */+function reachRoof(state: HopperState, random: () => number): void {+ const pad = PAD_X.findIndex((px) => Math.abs(state.x - px) <= PAD_CATCH);+ if (pad < 0 || state.pads[pad]) {+ die(state, "crash", random);return;}- state.bays[bay] = 1;- let points = BAY_POINTS + 10 * Math.floor(state.timeLeft);- if (state.flyBay === bay) {- points += FLY_BONUS;- state.flyBay = -1;- state.flyTimer = 6 + random() * 6;+ state.pads[pad] = 1;+ let points = PAD_POINTS + BATTERY_POINTS * Math.floor(state.battery);+ if (state.parcelPad === pad) {+ points += PARCEL_BONUS;+ state.parcelPad = -1;+ state.parcelTimer = 7 + random() * 6;}state.score += points;- popup(state, BAY_X[bay], HOME_ROW * CELL + 2, points);- emitBurst(state.particles, BAY_X[bay], HOME_ROW * CELL + 8, 12, 40, "#ffe66b", random, 0.6);- if (state.bays.every((b) => b === 1)) {+ popup(state, PAD_X[pad], HOME_ROW * CELL + 2, points);+ emitBurst(state.particles, PAD_X[pad], HOME_ROW * CELL + 8, 12, 40, "#5ff0d0", random, 0.6);+ if (state.pads.every((b) => b === 1)) {state.score += LEVEL_POINTS;state.phase = "levelup";state.timer = LEVEL_S;state.hop.active = false;- state.flyBay = -1;+ state.parcelPad = -1;} else {respawn(state);}}-/** The frog sits on `row` at `x`: is it alive? Returns false after killing it. */+/** The bot sits on `row` at `x`: is it still running? Returns false after wrecking it. */function survives(state: HopperState, random: () => number): boolean {if (isRoad(state.row) && vehicleAt(state, state.row, state.x)) {- die(state, "splat", random);+ die(state, "crash", random);return false;}- if (isRiver(state.row)) {- if (state.x < 2 || state.x > WIDTH - 2) {- die(state, "splash", random);- return false;- }- if (!platformAt(state, state.row, state.x)) {- die(state, "splash", random);+ if (isCanal(state.row)) {+ if (state.x < 2 || state.x > WIDTH - 2 || !carrierAt(state, state.row, state.x)) {+ die(state, "sink", random);return false;}}@@ -284,11 +285,11 @@ function land(state: HopperState, random: () => number): void {state.x = h.toX;state.row = h.toRow;if (state.row < state.bestRow) {- state.score += 10 * (state.bestRow - state.row);+ state.score += ROW_POINTS * (state.bestRow - state.row);state.bestRow = state.row;}if (state.row === HOME_ROW) {- reachHome(state, random);+ reachRoof(state, random);return;}if (!survives(state, random)) return;@@ -307,7 +308,7 @@ function step(state: HopperState, input: RetroInput, dt: number, random: () => nstepParticles(state.particles, dt, 30);if (state.phase === "over") return;state.elapsed += dt;- state.diveClock += dt;+ state.sinkClock += dt;for (let i = 0; i < LANES.length; i += 1) state.shifts[i] = mod(state.shifts[i] + laneSpeed(i, state.level) * dt, LANES[i].period);for (const p of state.popups) if (p.active && (p.t -= dt) <= 0) p.active = false;@@ -323,34 +324,34 @@ function step(state: HopperState, input: RetroInput, dt: number, random: () => nstate.timer -= dt;if (state.timer <= 0) {state.level += 1;- state.bays.fill(0);- state.flyTimer = 6 + random() * 5;+ state.pads.fill(0);+ state.parcelTimer = 7 + random() * 5;respawn(state);}return;}- // The fly visits empty bays now and then.- if (state.flyBay >= 0) {- state.flyLeft -= dt;- if (state.flyLeft <= 0) {- state.flyBay = -1;- state.flyTimer = 6 + random() * 6;+ // A parcel waits on a dark pad now and then.+ if (state.parcelPad >= 0) {+ state.parcelLeft -= dt;+ if (state.parcelLeft <= 0) {+ state.parcelPad = -1;+ state.parcelTimer = 7 + random() * 6;}- } else if ((state.flyTimer -= dt) <= 0) {- let empty = 0;- for (const b of state.bays) if (!b) empty += 1;- let pick = Math.floor(random() * empty);- for (let i = 0; i < 5 && empty > 0; i += 1) {- if (!state.bays[i] && pick-- === 0) { state.flyBay = i; state.flyLeft = 4.5; }+ } else if ((state.parcelTimer -= dt) <= 0) {+ let dark = 0;+ for (const b of state.pads) if (!b) dark += 1;+ let pick = Math.floor(random() * dark);+ for (let i = 0; i < state.pads.length && dark > 0; i += 1) {+ if (!state.pads[i] && pick-- === 0) { state.parcelPad = i; state.parcelLeft = 5; }}- state.flyTimer = 6 + random() * 6;+ state.parcelTimer = 7 + random() * 6;}- state.timeLeft -= dt;- if (state.timeLeft <= 0) {- state.timeLeft = 0;- die(state, "time", random);+ state.battery -= dt;+ if (state.battery <= 0) {+ state.battery = 0;+ die(state, "drained", random);return;}@@ -358,8 +359,8 @@ function step(state: HopperState, input: RetroInput, dt: number, random: () => nconst h = state.hop;if (h.active) {if (dir >= 0) state.queued = dir;- // A hop that starts on the river keeps drifting with what it left.- if (isRiver(h.fromRow)) {+ // A hop that starts on the canal keeps drifting with what it left.+ if (isCanal(h.fromRow)) {const drift = laneSpeed(LANE_OF_ROW[h.fromRow], state.level) * dt;h.fromX += drift;h.toX += drift;@@ -372,8 +373,8 @@ function step(state: HopperState, input: RetroInput, dt: number, random: () => nstartHop(state, dir as Direction);if (h.active) return;}- // Sitting still: the river carries the frog; traffic or water may end it.- if (isRiver(state.row)) state.x += laneSpeed(LANE_OF_ROW[state.row], state.level) * dt;+ // Standing still: the canal carries the bot; traffic or water may end it.+ if (isCanal(state.row)) state.x += laneSpeed(LANE_OF_ROW[state.row], state.level) * dt;survives(state, random);}@@ -399,47 +400,55 @@ function rotateRows(rows: readonly string[], turns: number): string[] {return out;}-const FROG_SIT = [- ".###....###.",- ".#.#....#.#.",- "..########..",- ".##########.",- "#.########.#",- "#.########.#",+/** The courier bot seen from above, facing up: two treads, a sensor bar at the front, a parcel bay. */+const BOT_BODY = [+ "....#..#....",+ "...######...",+ "..#......#..",+ "##.######.##",+ "##.######.##",+ "##.##..##.##",+ "##.##..##.##",+ "##.######.##",+ "##.######.##","##.######.##",- "..########..",- ".##.####.##.",- "##........##",- "#..........#",+ "...######...","............",];-const FROG_LEAP = [- "#.###..###.#",- "#.#.#..#.#.#",- ".#.######.#.",- "..########..",- "..########..",+/** The same with the treads mid-roll, for a hop. */+const BOT_ROLL = [+ "....#..#....","...######...",+ "#.#......#.#",+ ".#.######.#.",+ "#..######..#",+ ".#.##..##.#.",+ "#..##..##..#",+ ".#.######.#.",+ "#..######..#",+ ".#.######.#.","...######...",- "..########..",- "..##.##.##..",- ".##......##.",- ".#........#.",- "#..........#",+ "............",+];+const BOT_VISOR = [+ "............", "............", "...######...", "............", "............", "............",+ "............", "............", "............", "............", "............", "............",];-/** [direction][0 sitting, 1 leaping]. */-const FROG: readonly (readonly [PixelSprite, PixelSprite])[] = [0, 1, 2, 3].map(- (turns) => [sprite(rotateRows(FROG_SIT, turns)), sprite(rotateRows(FROG_LEAP, turns))] as const,-);-const SPLAT = sprite(["#...#..#...#", ".#..####..#.", "..########..", ".##.####.##.", "#.########.#", "..##.##.##..", ".#..#..#..#.", "#..........#"]);-const FLY = sprite([".#.#.", "#####", ".###.", "..#.."]);-const CAR = sprite(["..########......", ".##########.....", "################", "################", ".##########.....", "..########......"]);-const RACER = sprite(["....######......", "..##########....", "################", "################", "..##########....", "....######......"]);-const DOZER = sprite(["#..#########....", "#.###########...", "#.############..", "#.############..", "#.###########...", "#..#########...."]);-const LIFE_ICON = sprite([".#..#.", "######", "######", "#....#"]);--const BANK_ROWS = [7, START_ROW] as const;-const LANE_COLOR: Partial<Record<LaneKind, string>> = { car: "#4fc3ff", racer: "#ff5fb8", dozer: "#ffcc33" };+const BOT_PARCEL = [+ "............", "............", "............", "............", "............", ".....##.....",+ ".....##.....", "............", "............", "............", "............", "............",+];+const turned = (rows: readonly string[]) => [0, 1, 2, 3].map((t) => sprite(rotateRows(rows, t)));+/** [direction] for each layer. */+const BOT: readonly PixelSprite[] = turned(BOT_BODY);+const BOT_HOP: readonly PixelSprite[] = turned(BOT_ROLL);+const VISOR: readonly PixelSprite[] = turned(BOT_VISOR);+const PARCEL: readonly PixelSprite[] = turned(BOT_PARCEL);+const WRECK = sprite(["#..#....#..#", ".##..##..##.", "..#.####.#..", "#.##....##.#", "..#.####.#..", ".##..##..##.", "#..#....#..#"]);+const PARCEL_BOX = sprite(["######", "#.##.#", "######", "######"]);+const LIFE_ICON = sprite([".####.", "#....#", "######", "#.##.#"]);++const BANK_ROWS = [QUAY_ROW, START_ROW] as const;/** Lane scroll used for drawing: on the attract screen the world drifts on its own. */function drawShift(state: HopperState, lane: number, attract: boolean, time: number): number {@@ -447,79 +456,135 @@ function drawShift(state: HopperState, lane: number, attract: boolean, time: num}function drawVehicle(ctx: CanvasRenderingContext2D, kind: LaneKind, x: number, y: number, len: number, flip: boolean): void {- if (kind === "truck") {- ctx.fillStyle = "#d9d4c7";- ctx.fillRect(x + (flip ? 0 : 8), y + 2, len - 8, 12);- ctx.fillStyle = "#e0523d";- ctx.fillRect(x + (flip ? len - 8 : 0), y + 3, 8, 10);- ctx.fillStyle = "#0b0b12";- ctx.fillRect(x + (flip ? len - 5 : 1), y + 4, 3, 8);- ctx.fillRect(x + 4, y + 1, 4, 1);- ctx.fillRect(x + len - 8, y + 1, 4, 1);- ctx.fillRect(x + 4, y + 14, 4, 1);- ctx.fillRect(x + len - 8, y + 14, 4, 1);+ const front = flip ? x : x + len - 3;+ if (kind === "bus") {+ ctx.fillStyle = "#3a3f52";+ ctx.fillRect(x + 1, y + 2, len - 2, 12);+ ctx.fillStyle = "#e0a93b";+ ctx.fillRect(x + 1, y + 7, len - 2, 2);+ ctx.fillStyle = "#9fd7e8";+ for (let w = x + 4; w < x + len - 6; w += 7) ctx.fillRect(w, y + 4, 4, 2);+ } else if (kind === "van") {+ ctx.fillStyle = "#c7c2b4";+ ctx.fillRect(x + 1, y + 3, len - 2, 10);+ ctx.fillStyle = "#2f6f73";+ ctx.fillRect(flip ? x + 1 : x + len - 8, y + 3, 7, 10);+ } else if (kind === "scooter") {+ ctx.fillStyle = "#e85d9a";+ ctx.fillRect(x + 2, y + 6, len - 4, 4);+ ctx.fillStyle = "#f2efe6";+ ctx.fillRect(x + 6, y + 4, 4, 8);+ } else {+ ctx.fillStyle = "#7d8a3a";+ ctx.fillRect(x + 2, y + 3, len - 4, 10);+ ctx.fillStyle = "#c9d46a";+ // The spinning brush underneath.+ ctx.fillRect(flip ? x + len - 3 : x, y + 2, 3, 12);+ }+ ctx.fillStyle = "#fff4c8";+ ctx.fillRect(front, y + 4, 3, 1);+ ctx.fillRect(front, y + 11, 3, 1);+}++function drawCarrier(ctx: CanvasRenderingContext2D, def: LaneDef, lane: number, i: number, x: number, y: number, len: number, clock: number): void {+ if (def.kind === "barge") {+ ctx.fillStyle = "#4a4d5a";+ ctx.fillRect(x + 2, y + 2, len - 4, 12);+ ctx.fillStyle = "#6c7082";+ ctx.fillRect(x + 2, y + 2, len - 4, 2);+ ctx.fillStyle = "#c9a227";+ ctx.fillRect(x + 6, y + 8, len - 12, 1);+ // Hover glow under the hull and running lights at both ends.+ ctx.fillStyle = "#5ff0d0";+ ctx.fillRect(x + 4, y + 14, len - 8, 1);+ ctx.fillRect(x + 2, y + 6, 1, 4);+ ctx.fillRect(x + len - 3, y + 6, 1, 4);return;}- ctx.fillStyle = "#0b0b12";- ctx.fillRect(x + 3, y + 1, 3, 14);- ctx.fillRect(x + 10, y + 1, 3, 14);- ctx.fillStyle = LANE_COLOR[kind] ?? "#fff";- drawSprite(ctx, kind === "racer" ? RACER : kind === "dozer" ? DOZER : CAR, x, y + 5, 1, flip);- ctx.fillStyle = "#fff8d0";- ctx.fillRect(flip ? x : x + len - 1, y + 7, 1, 2);+ const sink = sinkState(lane, i, clock);+ for (let t = 0; t < len; t += CELL) {+ const tx = x + t;+ if (sink === 2) {+ ctx.fillStyle = "#2c8a86";+ ctx.fillRect(tx + 3, y + 4, 10, 1);+ ctx.fillRect(tx + 3, y + 11, 10, 1);+ continue;+ }+ ctx.fillStyle = sink === 1 ? "#8fb8c2" : "#dff5fa";+ ctx.fillRect(tx + 1, y + 2, 14, 12);+ ctx.fillStyle = sink === 1 ? "#5c8590" : "#b4dbe6";+ ctx.fillRect(tx + 1, y + 11, 14, 3);+ if (sink === 1) {+ ctx.fillStyle = "#2f5560";+ ctx.fillRect(tx + 4, y + 3, 1, 4);+ ctx.fillRect(tx + 5, y + 7, 4, 1);+ ctx.fillRect(tx + 9, y + 7, 1, 5);+ }+ }+}++function drawRoof(ctx: CanvasRenderingContext2D, state: HopperState, info: RetroDrawInfo): void {+ const y = HOME_ROW * CELL;+ ctx.fillStyle = "#232329";+ ctx.fillRect(0, y - 2, WIDTH, CELL + 2);+ // The live fence: a dashed gold line that hums between the pads.+ const hum = info.reduced ? 0 : Math.floor(info.time * 8) % 2;+ ctx.fillStyle = "#8a6d1e";+ for (let x = hum; x < WIDTH; x += 3) ctx.fillRect(x, y + 7, 2, 1);+ for (let i = 0; i < PAD_X.length; i += 1) {+ const cx = PAD_X[i];+ ctx.fillStyle = "#232329";+ ctx.fillRect(cx - 11, y, 22, CELL);+ ctx.strokeStyle = state.pads[i] ? "#5ff0d0" : "#c9a227";+ ctx.lineWidth = 1;+ ctx.beginPath();+ ctx.arc(cx, y + 8, 7, 0, Math.PI * 2);+ ctx.stroke();+ if (state.pads[i]) {+ ctx.fillStyle = "#5ff0d0";+ ctx.fillRect(cx - 3, y + 5, 6, 6);+ } else if (state.parcelPad === i) {+ ctx.fillStyle = "#e0a93b";+ const bob = info.reduced ? 0 : Math.floor(info.time * 4) % 2;+ drawSprite(ctx, PARCEL_BOX, cx - 3, y + 6 - bob);+ }+ }}function draw(ctx: CanvasRenderingContext2D, state: HopperState, info: RetroDrawInfo): void {const attract = info.idle && state.elapsed === 0;- const clock = attract ? info.time : state.diveClock;+ const clock = attract ? info.time : state.sinkClock;const motion = info.reduced ? 0 : info.time;- ctx.fillStyle = "#06070d";+ ctx.fillStyle = "#0d0d12";ctx.fillRect(0, 0, WIDTH, HEIGHT);- // River with drifting ripples.- ctx.fillStyle = "#0b2a5c";- ctx.fillRect(0, RIVER_TOP * CELL, WIDTH, (RIVER_BOTTOM - RIVER_TOP + 1) * CELL);- ctx.fillStyle = "#1d4f96";- for (let row = RIVER_TOP; row <= RIVER_BOTTOM; row += 1) {- const drift = Math.floor(mod(motion * 6 + row * 13, 32));- for (let x = -32 + drift; x < WIDTH; x += 32) ctx.fillRect(x, row * CELL + 5 + (row % 2) * 6, 6, 1);+ // The canal with drifting ripples.+ ctx.fillStyle = "#0b3a40";+ ctx.fillRect(0, CANAL_TOP * CELL, WIDTH, (CANAL_BOTTOM - CANAL_TOP + 1) * CELL);+ ctx.fillStyle = "#1f6f73";+ for (let row = CANAL_TOP; row <= CANAL_BOTTOM; row += 1) {+ const drift = Math.floor(mod(motion * 5 + row * 11, 24));+ for (let x = -24 + drift; x < WIDTH; x += 24) ctx.fillRect(x, row * CELL + 4 + (row % 2) * 7, 4, 1);}- // Hedge and bays.- ctx.fillStyle = "#1f5e2b";- ctx.fillRect(0, HOME_ROW * CELL - 2, WIDTH, CELL + 2);- ctx.fillStyle = "#2f8a3e";- for (let x = 0; x < WIDTH; x += 4) ctx.fillRect(x, HOME_ROW * CELL - 2 + (x % 8 === 0 ? 0 : 1), 2, 1);- for (let i = 0; i < 5; i += 1) {- const bx = BAY_X[i] - 10;- ctx.fillStyle = "#0b2a5c";- ctx.fillRect(bx, HOME_ROW * CELL, 20, CELL);- if (state.bays[i]) {- ctx.fillStyle = "#b6f36b";- drawSprite(ctx, FROG[2][0], BAY_X[i] - 6, HOME_ROW * CELL + 2);- } else if (state.flyBay === i) {- ctx.fillStyle = "#ffe66b";- const flap = info.reduced ? 0 : Math.floor(info.time * 10) % 2;- drawSprite(ctx, FLY, BAY_X[i] - 2, HOME_ROW * CELL + 6 - flap);- }- }+ drawRoof(ctx, state, info);- // Banks.+ // The quay and the street pavement: warm paving slabs.for (const row of BANK_ROWS) {- ctx.fillStyle = "#3d2f6e";+ ctx.fillStyle = "#3a2f22";ctx.fillRect(0, row * CELL, WIDTH, CELL);- ctx.fillStyle = "#56449a";- for (let x = 2; x < WIDTH; x += 8) ctx.fillRect(x + (row % 2) * 4, row * CELL + 4, 2, 2);- for (let x = 6; x < WIDTH; x += 8) ctx.fillRect(x - (row % 2) * 4, row * CELL + 11, 2, 2);+ ctx.fillStyle = "#4f402c";+ for (let x = 0; x < WIDTH; x += 16) ctx.fillRect(x + (row % 2) * 8, row * CELL + 1, 7, 6);+ for (let x = 0; x < WIDTH; x += 16) ctx.fillRect(x + 8 - (row % 2) * 8, row * CELL + 9, 7, 6);}- // Road with lane markings.- ctx.fillStyle = "#14141c";+ // The road with gold lane markings.+ ctx.fillStyle = "#16161a";ctx.fillRect(0, ROAD_TOP * CELL, WIDTH, (ROAD_BOTTOM - ROAD_TOP + 1) * CELL);- ctx.fillStyle = "#4b4b5c";+ ctx.fillStyle = "#6e5a1c";for (let row = ROAD_TOP + 1; row <= ROAD_BOTTOM; row += 1) {- for (let x = 4; x < WIDTH; x += 16) ctx.fillRect(x, row * CELL, 8, 1);+ for (let x = 2; x < WIDTH; x += 12) ctx.fillRect(x, row * CELL, 4, 1);}// Lane contents.@@ -531,98 +596,75 @@ function draw(ctx: CanvasRenderingContext2D, state: HopperState, info: RetroDrawconst x = Math.round(itemX(lane, i, shift));const len = def.lens[i];if (x >= WIDTH || x + len <= 0) continue;- if (def.kind === "log") {- ctx.fillStyle = "#8a5a2b";- ctx.fillRect(x + 1, y + 2, len - 2, 12);- ctx.fillStyle = "#b07a40";- ctx.fillRect(x + 1, y + 3, len - 2, 2);- ctx.fillStyle = "#5c3a1a";- for (let g = x + 6; g < x + len - 6; g += 11) ctx.fillRect(g, y + 8, 5, 1);- ctx.fillRect(x + 1, y + 2, 2, 12);- ctx.fillStyle = "#d9a86a";- ctx.fillRect(x + len - 3, y + 3, 2, 10);- } else if (def.kind === "turtle") {- const dive = diveState(lane, i, clock);- for (let t = 0; t < len; t += CELL) {- const tx = x + t;- if (dive === 2) {- ctx.fillStyle = "#1d4f96";- ctx.fillRect(tx + 4, y + 7, 8, 1);- continue;- }- ctx.fillStyle = dive === 1 ? "#6e3a2c" : "#c0463a";- ctx.fillRect(tx + 3, y + 3, 10, 10);- ctx.fillRect(tx + 2, y + 5, 12, 6);- ctx.fillStyle = dive === 1 ? "#4a6a3a" : "#7ed957";- ctx.fillRect(def.speed < 0 ? tx : tx + 14, y + 6, 2, 4);- ctx.fillStyle = "#e8b04a";- ctx.fillRect(tx + 6, y + 6, 4, 4);- }- } else {- drawVehicle(ctx, def.kind, x, y, len, def.speed < 0);- }+ if (isCanal(def.row)) drawCarrier(ctx, def, lane, i, x, y, len, clock);+ else drawVehicle(ctx, def.kind, x, y, len, def.speed < 0);}}- // The frog, or what is left of it.+ // The bot, or what is left of it.if (state.phase === "dying") {const cy = state.row * CELL;- if (state.deathKind === "splash") {- ctx.strokeStyle = "#9fd8ff";+ if (state.deathKind === "sink") {+ ctx.strokeStyle = "#8ff5e8";ctx.lineWidth = 1;const grow = clamp(1 - state.timer / DEATH_S, 0, 1);- for (let ring = 0; ring < 2; ring += 1) {- ctx.beginPath();- ctx.arc(state.x, cy + CELL / 2, 2 + grow * 8 + ring * 4, 0, Math.PI * 2);- ctx.stroke();- }+ ctx.strokeRect(Math.round(state.x - 3 - grow * 6) + 0.5, Math.round(cy + 5 - grow * 3) + 0.5, Math.round(6 + grow * 12), Math.round(6 + grow * 6));} else {- ctx.fillStyle = "#7ed957";- drawSprite(ctx, SPLAT, state.x - 6, cy + 4);+ ctx.fillStyle = state.deathKind === "drained" ? "#6b6b78" : "#ffc64a";+ drawSprite(ctx, WRECK, state.x - 6, cy + 4);}} else if (state.phase === "play") {const h = state.hop;- let fx = state.x, fy = state.row * CELL, leap = 0;+ let bx = state.x, by = state.row * CELL, rolling = false;if (h.active) {const k = clamp(h.t / HOP_S, 0, 1);- fx = h.fromX + (h.toX - h.fromX) * k;- fy = (h.fromRow + (h.toRow - h.fromRow) * k) * CELL - (info.reduced ? 0 : Math.sin(k * Math.PI) * 3);- leap = 1;+ bx = h.fromX + (h.toX - h.fromX) * k;+ by = (h.fromRow + (h.toRow - h.fromRow) * k) * CELL - (info.reduced ? 0 : Math.sin(k * Math.PI) * 3);+ rolling = true;}- ctx.fillStyle = "#0a1a0a";- ctx.fillRect(Math.round(fx) - 4, state.row * CELL + 13, 8, 1);- ctx.fillStyle = "#7ed957";- drawSprite(ctx, FROG[state.facing][leap], fx - 6, fy + 2);+ ctx.fillStyle = "#050507";+ ctx.fillRect(Math.round(bx) - 4, state.row * CELL + 13, 8, 1);+ ctx.fillStyle = "#d8dce6";+ drawSprite(ctx, (rolling ? BOT_HOP : BOT)[state.facing], bx - 6, by + 2);+ ctx.fillStyle = "#5ff0d0";+ drawSprite(ctx, VISOR[state.facing], bx - 6, by + 2);+ ctx.fillStyle = "#e0a93b";+ drawSprite(ctx, PARCEL[state.facing], bx - 6, by + 2);}drawParticles(ctx, state.particles);- ctx.fillStyle = "#ffe66b";+ ctx.fillStyle = "#5ff0d0";for (const p of state.popups) {if (p.active) drawNumber(ctx, p.value, p.x, p.y - (info.reduced ? 0 : (1.2 - p.t) * 6), 1, "center");}- // Top: score and level. Bottom: lives and the clock.- ctx.fillStyle = "#e9ffe0";+ // Top: score and level. Bottom: spare bots and the battery.+ ctx.fillStyle = "#f2efe6";drawNumber(ctx, state.score, 6, 4, 2);- ctx.fillStyle = "#b6f36b";+ ctx.fillStyle = "#e0a93b";drawNumber(ctx, state.level, WIDTH - 6, 4, 2, "right");- ctx.fillStyle = "#7ed957";- for (let i = 0; i < Math.min(state.lives, 6); i += 1) drawSprite(ctx, LIFE_ICON, 6 + i * 9, 14 * CELL + 6);- const frac = clamp(state.timeLeft / LIFE_TIME, 0, 1);- const low = state.timeLeft < 8;- ctx.fillStyle = "#1c2a1c";- ctx.fillRect(40, 15 * CELL + 5, WIDTH - 46, 6);- // The bar turns red when time runs low; it pulses only without reduced motion.+ ctx.fillStyle = "#d8dce6";+ for (let i = 0; i < Math.min(state.lives, 6); i += 1) drawSprite(ctx, LIFE_ICON, 6 + i * 9, 12 * CELL + 6);+ const frac = clamp(state.battery / BATTERY_TIME, 0, 1);+ const low = state.battery < 10;+ const barX = 40, barW = WIDTH - 52, barY = 13 * CELL + 3;+ // A battery outline with a nub; the charge drains from the right.+ ctx.fillStyle = "#3a3a44";+ ctx.fillRect(barX - 1, barY - 1, barW + 2, 9);+ ctx.fillRect(barX + barW + 1, barY + 2, 2, 3);+ ctx.fillStyle = "#0d0d12";+ ctx.fillRect(barX, barY, barW, 7);+ // The charge turns red when it runs low; it pulses only without reduced motion.ctx.globalAlpha = low && !info.reduced && state.phase === "play" ? 0.65 + 0.35 * Math.sin(info.time * 6) : 1;- ctx.fillStyle = low ? "#ff5a4a" : "#7ed957";- ctx.fillRect(WIDTH - 6 - Math.round((WIDTH - 46) * frac), 15 * CELL + 5, Math.round((WIDTH - 46) * frac), 6);+ ctx.fillStyle = low ? "#ff5a4a" : "#5ff0d0";+ for (let x = 0; x < Math.round(barW * frac); x += 4) ctx.fillRect(barX + 1 + x, barY + 1, Math.min(3, Math.round(barW * frac) - x), 5);ctx.globalAlpha = 1;- ctx.fillStyle = low ? "#ff5a4a" : "#b6f36b";- drawNumber(ctx, Math.ceil(state.timeLeft), 6, 15 * CELL + 4, 2);+ ctx.fillStyle = low ? "#ff5a4a" : "#e0a93b";+ drawNumber(ctx, Math.ceil(state.battery), 6, barY - 1, 2);if (state.phase === "levelup") {- ctx.fillStyle = "#ffe66b";- drawNumber(ctx, state.level + 1, WIDTH / 2, 7 * CELL + 1, 3, "center");+ ctx.fillStyle = "#e0a93b";+ drawNumber(ctx, state.level + 1, WIDTH / 2, QUAY_ROW * CELL + 1, 3, "center");}}diff --git a/dodaios/ui/web/frontend/src/i18n/locales/society/de.json b/dodaios/ui/web/frontend/src/i18n/locales/society/de.jsonindex d43866cfa6..ad7b15cc09 100644--- a/dodaios/ui/web/frontend/src/i18n/locales/society/de.json+++ b/dodaios/ui/web/frontend/src/i18n/locales/society/de.json@@ -1805,8 +1805,8 @@"how": "←/→ bewegen · ↑/Leertaste drehen · ↓ schneller fallen · Shift sofort ablegen · P Pause · Esc verlassen"},"maze_muncher": {- "tagline": "Futtere jeden Punkt und überliste vier Glitch-Käfer.",- "how": "Pfeiltasten lenken (Abbiegen wird vorgemerkt) · Kraftkugeln machen die Käfer essbar · P Pause · Esc verlassen"+ "tagline": "Sauge jeden Punkt auf und überliste vier Glitch-Käfer.",+ "how": "Pfeiltasten lenken (Abbiegen wird vorgemerkt) · Kraftkugeln legen die Käfer lahm, dann kannst du sie zappen · P Pause · Esc verlassen"},"desert_dash": {"tagline": "Sprinte über die Dünen: spring über Kakteen, duck dich vor Vögeln.",@@ -1817,12 +1817,12 @@"how": "←/→ bewegen · Leertaste feuern · P Pause · Esc verlassen"},"road_hopper": {- "tagline": "Hüpf über Straße und Fluss nach Hause.",+ "tagline": "Steuere den Kurier-Bot über Straße und Kanal zu den Landeplätzen auf dem Dach.","how": "Pfeiltasten hüpfen · P Pause · Esc verlassen"},"city_defense": {- "tagline": "Schieß die Sprengköpfe ab, bevor sie deine Städte treffen.",- "how": "Maus zielen + Klick feuern · Pfeiltasten zielen · Leertaste feuern · Shift Batterie wählen · P Pause · Esc verlassen"+ "tagline": "Zerschlage die fallenden Splitter, bevor sie deine Kuppeln zerbrechen.",+ "how": "Maus zielen + Klick feuern · Pfeiltasten zielen · Leertaste feuern · Shift Impuls (breit, mehr Hitze) · P Pause · Esc verlassen"}}},diff --git a/dodaios/ui/web/frontend/src/i18n/locales/society/en.json b/dodaios/ui/web/frontend/src/i18n/locales/society/en.jsonindex 37377cdcdd..6c8ddff63d 100644--- a/dodaios/ui/web/frontend/src/i18n/locales/society/en.json+++ b/dodaios/ui/web/frontend/src/i18n/locales/society/en.json@@ -1805,8 +1805,8 @@"how": "←/→ move · ↑/Space rotate · ↓ soft drop · Shift hard drop · P pause · Esc leave"},"maze_muncher": {- "tagline": "Munch every dot and outsmart four glitch bugs.",- "how": "Arrows steer (turns are buffered) · power orbs make the bugs edible · P pause · Esc leave"+ "tagline": "Vacuum up every dot and outsmart four glitch bugs.",+ "how": "Arrows steer (turns are buffered) · power orbs short the bugs out so you can zap them · P pause · Esc leave"},"desert_dash": {"tagline": "Dash across the dunes: jump the cacti, duck the birds.",@@ -1817,12 +1817,12 @@"how": "←/→ move · Space fire · P pause · Esc leave"},"road_hopper": {- "tagline": "Hop across the traffic and the river to get home.",+ "tagline": "Steer the courier bot across the traffic and the canal to the rooftop pads.","how": "Arrows hop · P pause · Esc leave"},"city_defense": {- "tagline": "Shoot down the warheads before they reach your cities.",- "how": "Mouse aim + click fire · Arrows aim · Space fire · Shift pick battery · P pause · Esc leave"+ "tagline": "Shatter the falling shards before they break your domes.",+ "how": "Mouse aim + click fire · Arrows aim · Space fire · Shift pulse (wide, more heat) · P pause · Esc leave"}}},diff --git a/dodaios/ui/web/frontend/src/i18n/locales/society/es.json b/dodaios/ui/web/frontend/src/i18n/locales/society/es.jsonindex 70ad7cd3d5..5a81d0e9f0 100644--- a/dodaios/ui/web/frontend/src/i18n/locales/society/es.json+++ b/dodaios/ui/web/frontend/src/i18n/locales/society/es.json@@ -1805,8 +1805,8 @@"how": "←/→ mover · ↑/Espacio girar · ↓ bajar rápido · Shift caída directa · P pausa · Esc salir"},"maze_muncher": {- "tagline": "Come todos los puntos y burla a cuatro bichos glitch.",- "how": "Flechas para girar (los giros se guardan) · los orbes de poder vuelven comestibles a los bichos · P pausa · Esc salir"+ "tagline": "Aspira todos los puntos y burla a cuatro bichos glitch.",+ "how": "Flechas para girar (los giros se guardan) · los orbes de poder dejan fuera de combate a los bichos para que puedas eliminarlos · P pausa · Esc salir"},"desert_dash": {"tagline": "Corre por las dunas: salta los cactus y agáchate ante los pájaros.",@@ -1817,12 +1817,12 @@"how": "←/→ mover · Espacio disparar · P pausa · Esc salir"},"road_hopper": {- "tagline": "Salta entre el tráfico y el río para llegar a casa.",+ "tagline": "Guía al robot mensajero entre el tráfico y el canal hasta las plataformas de la azotea.","how": "Flechas saltar · P pausa · Esc salir"},"city_defense": {- "tagline": "Derriba las cabezas nucleares antes de que alcancen tus ciudades.",- "how": "Ratón apuntar + clic disparar · Flechas apuntar · Espacio disparar · Shift elegir batería · P pausa · Esc salir"+ "tagline": "Destroza los fragmentos que caen antes de que rompan tus cúpulas.",+ "how": "Ratón apuntar + clic disparar · Flechas apuntar · Espacio disparar · Shift pulso (amplio, más calor) · P pausa · Esc salir"}}},diff --git a/dodaios/ui/web/frontend/src/i18n/locales/society/pt.json b/dodaios/ui/web/frontend/src/i18n/locales/society/pt.jsonindex 057344797e..7bba6a0c41 100644--- a/dodaios/ui/web/frontend/src/i18n/locales/society/pt.json+++ b/dodaios/ui/web/frontend/src/i18n/locales/society/pt.json@@ -1805,8 +1805,8 @@"how": "←/→ mover · ↑/Espaço rodar · ↓ descida suave · Shift descida rápida · P pausa · Esc sair"},"maze_muncher": {- "tagline": "Come todos os pontos e engana quatro bugs com falhas.",- "how": "Setas dirigem (as curvas ficam em memória) · as orbes de energia tornam os bugs comestíveis · P pausa · Esc sair"+ "tagline": "Aspira todos os pontos e engana quatro bugs com falhas.",+ "how": "Setas dirigem (as curvas ficam em memória) · as orbes de energia deixam os bugs em curto-circuito para os poderes eliminar · P pausa · Esc sair"},"desert_dash": {"tagline": "Corre pelas dunas: salta os catos, baixa-te para fugir aos pássaros.",@@ -1817,12 +1817,12 @@"how": "←/→ mover · Espaço disparar · P pausa · Esc sair"},"road_hopper": {- "tagline": "Salta por entre o trânsito e atravessa o rio para chegar a casa.",+ "tagline": "Leva o robô estafeta por entre o trânsito e o canal até às plataformas do telhado.","how": "Setas saltam · P pausa · Esc sair"},"city_defense": {- "tagline": "Abate as ogivas antes que cheguem às tuas cidades.",- "how": "Rato apontar + clique disparar · Setas apontar · Espaço disparar · Shift escolher bateria · P pausa · Esc sair"+ "tagline": "Desfaz os fragmentos que caem antes que partam as tuas cúpulas.",+ "how": "Rato apontar + clique disparar · Setas apontar · Espaço disparar · Shift pulso (largo, mais calor) · P pausa · Esc sair"}}},diff --git a/dodaios/ui/web/frontend/src/i18n/locales/society/zh.json b/dodaios/ui/web/frontend/src/i18n/locales/society/zh.jsonindex b054fa6468..073afe348f 100644--- a/dodaios/ui/web/frontend/src/i18n/locales/society/zh.json+++ b/dodaios/ui/web/frontend/src/i18n/locales/society/zh.json@@ -1805,8 +1805,8 @@"how": "←/→ 移动 · ↑/空格旋转 · ↓ 软降 · Shift 硬降 · P 暂停 · Esc 离开"},"maze_muncher": {- "tagline": "吃光每一颗豆子,智胜四只故障虫。",- "how": "方向键转向(转弯会预输入)· 能量球让虫子变得可以吃 · P 暂停 · Esc 离开"+ "tagline": "吸光每一个光点,智胜四只故障虫。",+ "how": "方向键转向(转弯会预输入)· 能量球让虫子短路,趁机消灭它们 · P 暂停 · Esc 离开"},"desert_dash": {"tagline": "冲过沙丘:跳过仙人掌,躲开飞鸟。",@@ -1817,12 +1817,12 @@"how": "←/→ 移动 · 空格开火 · P 暂停 · Esc 离开"},"road_hopper": {- "tagline": "跳过车流和河流,回到家。",+ "tagline": "驾驶快递机器人穿过车流和运河,抵达屋顶停机坪。","how": "方向键跳跃 · P 暂停 · Esc 离开"},"city_defense": {- "tagline": "在弹头击中城市之前将其击落。",- "how": "鼠标瞄准 + 点击开火 · 方向键瞄准 · 空格开火 · Shift 选择炮台 · P 暂停 · Esc 离开"+ "tagline": "在坠落的碎晶击碎穹顶之前将其粉碎。",+ "how": "鼠标瞄准 + 点击开火 · 方向键瞄准 · 空格开火 · Shift 脉冲(范围大、发热多) · P 暂停 · Esc 离开"}}},