Skip to content

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.

feat(office): Asteroid Run replaces the arcade invaders game

rubenluetke10-beep2699681d1e8a
diff --git a/jarvis/ui/web/frontend/src/components/society/office/ArcadeCabinet.tsx b/jarvis/ui/web/frontend/src/components/society/office/ArcadeCabinet.tsx
index 138f99a1f6..6a608e0646 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/ArcadeCabinet.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/ArcadeCabinet.tsx
@@ -1,40 +1,25 @@
/**
* The break-room arcade, playable: walking up to the cabinet and pressing E
- * opens this overlay. The rules live in arcadeGame.ts; this component feeds
- * the keyboard in, runs a fixed-step loop and paints the playfield. It is a
- * modal dialog, so the office character stands still while you play.
+ * opens this overlay with "Asteroid Run". The rules live in arcadeGame.ts;
+ * this component feeds the keyboard in, runs a fixed-step loop and paints
+ * the playfield. It is a modal dialog, so the office character stands still
+ * while you play.
*/
import { useCallback, useEffect, useRef, useState } from "react";
import { useT } from "@/i18n";
import {
- ARCADE_H, ARCADE_SHIP_Y, ARCADE_W, invaderPos, newArcade, stepArcade,
- type ArcadeInput, type ArcadePhase, type ArcadeState,
+ ARCADE_H, ARCADE_W, RAPID_S, ROCK_RADIUS, SHIP_RADIUS, arcadeLevel, newArcade, stepArcade,
+ type ArcadeInput, type ArcadePhase, type ArcadeState, type PickupKind,
} from "./arcadeGame";
import "./arcade.css";
-const BEST_KEY = "jarvis.office.arcade.best";
+const BEST_KEY = "jarvis.office.arcade.asteroids.best";
const STEP = 1 / 120;
-/** Canvas pixels per playfield pixel; CSS scales the canvas to fit. */
+/** Canvas pixels per playfield unit; CSS scales the canvas to fit. */
const SCALE = 3;
-// Pixel sprites, two marching frames per invader row style ("X" = lit).
-const SPRITES: Record<"squid" | "crab" | "octo", [string[], string[]]> = {
- squid: [
- ["....XXX....", "...XXXXX...", "..XXXXXXX..", ".XX.XXX.XX.", ".XXXXXXXXX.", "...X...X...", "..X.XXX.X..", ".X.X...X.X."],
- ["....XXX....", "...XXXXX...", "..XXXXXXX..", ".XX.XXX.XX.", ".XXXXXXXXX.", "..X.X.X.X..", ".X.......X.", "..X.....X.."],
- ],
- crab: [
- ["..X.....X..", "...X...X...", "..XXXXXXX..", ".XX.XXX.XX.", "XXXXXXXXXXX", "X.XXXXXXX.X", "X.X.....X.X", "...XX.XX..."],
- ["..X.....X..", "X..X...X..X", "X.XXXXXXX.X", "XXX.XXX.XXX", "XXXXXXXXXXX", ".XXXXXXXXX.", "..X.....X..", ".X.......X."],
- ],
- octo: [
- ["...XXXXX...", ".XXXXXXXXX.", "XXXXXXXXXXX", "XXX..X..XXX", "XXXXXXXXXXX", "..XX...XX..", ".XX.XXX.XX.", "XX.......XX"],
- ["...XXXXX...", ".XXXXXXXXX.", "XXXXXXXXXXX", "XXX..X..XXX", "XXXXXXXXXXX", "...XX.XX...", "..XX.X.XX..", "...XX.XX..."],
- ],
-};
-const ROW_SPRITE = ["squid", "crab", "crab", "octo", "octo"] as const;
-const ROW_COLOUR = ["#ff7ab8", "#c792ff", "#c792ff", "#7cfc9a", "#7cfc9a"];
-const SHIP = ["......X......", ".....XXX.....", ".XXXXXXXXXXX.", "XXXXXXXXXXXXX", "XXXXXXXXXXXXX"];
+const PICKUP_COLOUR: Record<PickupKind, string> = { shield: "#7dd3fc", rapid: "#fde68a", life: "#ff7ab8" };
+const ROCK_FILL = ["#8f7b66", "#7d6a57", "#6b5a4a"];
function readBest(): number {
try { return Number(window.localStorage.getItem(BEST_KEY)) || 0; } catch { return 0; }
@@ -44,68 +29,141 @@ function writeBest(score: number): void {
try { window.localStorage.setItem(BEST_KEY, String(score)); } catch { /* not persisted this session */ }
}
-function sprite(ctx: CanvasRenderingContext2D, rows: readonly string[], x: number, y: number): void {
- rows.forEach((line, dy) => {
- for (let dx = 0; dx < line.length; dx += 1) if (line[dx] === "X") ctx.fillRect(x + dx, y + dy, 1, 1);
- });
+function drawShip(ctx: CanvasRenderingContext2D, s: ArcadeState, now: number): void {
+ const { shipX: x, shipY: y } = s;
+ const tilt = Math.max(-0.35, Math.min(0.35, s.vx / 400));
+ ctx.save();
+ ctx.translate(x, y);
+ ctx.rotate(tilt);
+ // Flame, flickering, longer while thrusting forward.
+ const flame = 7 + Math.sin(now / 30) * 2 + (s.vy < 0 ? 4 : 0);
+ ctx.fillStyle = "#ff7a59";
+ ctx.beginPath(); ctx.moveTo(-3, 7); ctx.lineTo(0, 7 + flame); ctx.lineTo(3, 7); ctx.closePath(); ctx.fill();
+ ctx.fillStyle = "#ffd166";
+ ctx.beginPath(); ctx.moveTo(-1.6, 7); ctx.lineTo(0, 7 + flame * 0.6); ctx.lineTo(1.6, 7); ctx.closePath(); ctx.fill();
+ // Fins.
+ ctx.fillStyle = "#e0526b";
+ ctx.beginPath(); ctx.moveTo(-4, 2); ctx.lineTo(-8, 9); ctx.lineTo(-3, 7); ctx.closePath(); ctx.fill();
+ ctx.beginPath(); ctx.moveTo(4, 2); ctx.lineTo(8, 9); ctx.lineTo(3, 7); ctx.closePath(); ctx.fill();
+ // Body.
+ ctx.fillStyle = "#eef2f7";
+ ctx.beginPath();
+ ctx.moveTo(0, -11);
+ ctx.quadraticCurveTo(5, -5, 4, 7);
+ ctx.lineTo(-4, 7);
+ ctx.quadraticCurveTo(-5, -5, 0, -11);
+ ctx.fill();
+ // Nose cone and window.
+ ctx.fillStyle = "#e0526b";
+ ctx.beginPath(); ctx.moveTo(0, -11); ctx.quadraticCurveTo(3.2, -7.5, 3.4, -5); ctx.lineTo(-3.4, -5); ctx.quadraticCurveTo(-3.2, -7.5, 0, -11); ctx.fill();
+ ctx.fillStyle = "#38bdf8";
+ ctx.beginPath(); ctx.arc(0, -1, 1.9, 0, Math.PI * 2); ctx.fill();
+ ctx.restore();
+ if (s.shield) {
+ ctx.strokeStyle = `rgba(125, 211, 252, ${0.55 + Math.sin(now / 150) * 0.25})`;
+ ctx.lineWidth = 1.2;
+ ctx.beginPath(); ctx.arc(x, y, SHIP_RADIUS + 7, 0, Math.PI * 2); ctx.stroke();
+ }
+}
+
+function drawPickup(ctx: CanvasRenderingContext2D, kind: PickupKind, x: number, y: number, t: number): void {
+ const pulse = 1 + Math.sin(t * 6) * 0.12;
+ ctx.save();
+ ctx.translate(x, y);
+ ctx.scale(pulse, pulse);
+ ctx.strokeStyle = PICKUP_COLOUR[kind];
+ ctx.fillStyle = PICKUP_COLOUR[kind];
+ ctx.lineWidth = 1.2;
+ ctx.beginPath(); ctx.arc(0, 0, 6, 0, Math.PI * 2); ctx.stroke();
+ ctx.beginPath();
+ if (kind === "shield") { ctx.moveTo(0, -3.5); ctx.lineTo(3, -2); ctx.lineTo(2.4, 1.8); ctx.lineTo(0, 3.6); ctx.lineTo(-2.4, 1.8); ctx.lineTo(-3, -2); }
+ else if (kind === "rapid") { ctx.moveTo(0.8, -4); ctx.lineTo(-2.4, 0.6); ctx.lineTo(0, 0.6); ctx.lineTo(-0.8, 4); ctx.lineTo(2.4, -0.6); ctx.lineTo(0, -0.6); }
+ else { ctx.moveTo(0, 3.4); ctx.bezierCurveTo(-5, -0.5, -2.2, -4.5, 0, -1.6); ctx.bezierCurveTo(2.2, -4.5, 5, -0.5, 0, 3.4); }
+ ctx.closePath(); ctx.fill();
+ ctx.restore();
}
function paint(ctx: CanvasRenderingContext2D, s: ArcadeState, now: number): void {
- ctx.setTransform(SCALE, 0, 0, SCALE, 0, 0);
- ctx.fillStyle = "#07060f";
- ctx.fillRect(0, 0, ARCADE_W, ARCADE_H);
- // A few fixed stars, for depth.
- ctx.fillStyle = "#2a2645";
- for (let i = 0; i < 40; i += 1) ctx.fillRect((i * 97) % ARCADE_W, (i * 53 + 17) % (ARCADE_H - 40), 1, 1);
- for (const inv of s.invaders) {
- if (!inv.alive) continue;
- const { x, y } = invaderPos(s, inv);
- ctx.fillStyle = ROW_COLOUR[inv.row];
- sprite(ctx, SPRITES[ROW_SPRITE[inv.row]][s.frame], Math.round(x), Math.round(y));
+ const shake = s.shake * 10;
+ const ox = shake > 0 ? (Math.random() - 0.5) * shake : 0, oy = shake > 0 ? (Math.random() - 0.5) * shake : 0;
+ ctx.setTransform(SCALE, 0, 0, SCALE, ox * SCALE, oy * SCALE);
+ const sky = ctx.createLinearGradient(0, 0, 0, ARCADE_H);
+ sky.addColorStop(0, "#05040d");
+ sky.addColorStop(1, "#120b2a");
+ ctx.fillStyle = sky;
+ ctx.fillRect(-10, -10, ARCADE_W + 20, ARCADE_H + 20);
+ // Stars stretch into streaks as the run speeds up.
+ const streak = 1 + Math.min(6, s.time / 20);
+ for (const star of s.stars) {
+ ctx.fillStyle = `rgba(220, 225, 255, ${0.25 + star.depth * 0.6})`;
+ ctx.fillRect(star.x, star.y, star.depth > 0.7 ? 1.2 : 0.8, streak * star.depth);
+ }
+ for (const p of s.pickups) drawPickup(ctx, p.kind, p.x, p.y, p.t);
+ for (const rock of s.rocks) {
+ const r = ROCK_RADIUS[rock.size];
+ ctx.save();
+ ctx.translate(rock.x, rock.y);
+ ctx.rotate(rock.angle);
+ ctx.beginPath();
+ rock.shape.forEach((k, i) => {
+ const a = (i / rock.shape.length) * Math.PI * 2;
+ if (i === 0) ctx.moveTo(Math.cos(a) * r * k, Math.sin(a) * r * k); else ctx.lineTo(Math.cos(a) * r * k, Math.sin(a) * r * k);
+ });
+ ctx.closePath();
+ ctx.fillStyle = rock.flash > 0 ? "#ffffff" : ROCK_FILL[rock.size];
+ ctx.fill();
+ ctx.strokeStyle = "#b8a38a";
+ ctx.lineWidth = 1;
+ ctx.stroke();
+ // A couple of craters.
+ ctx.fillStyle = "rgba(0, 0, 0, 0.22)";
+ ctx.beginPath(); ctx.arc(r * 0.3, -r * 0.2, r * 0.22, 0, Math.PI * 2); ctx.fill();
+ ctx.beginPath(); ctx.arc(-r * 0.35, r * 0.3, r * 0.15, 0, Math.PI * 2); ctx.fill();
+ ctx.restore();
}
ctx.fillStyle = "#fde68a";
- if (s.shot) ctx.fillRect(Math.round(s.shot.x), Math.round(s.shot.y), 1, 5);
- ctx.fillStyle = "#ff9e6b";
- for (const b of s.bombs) {
- const zig = Math.floor(b.y / 3) % 2;
- ctx.fillRect(Math.round(b.x) + zig, Math.round(b.y), 1, 2);
- ctx.fillRect(Math.round(b.x) - zig + 1, Math.round(b.y) + 2, 1, 2);
+ for (const shot of s.shots) ctx.fillRect(shot.x - 0.7, shot.y - 3, 1.4, 6);
+ for (const p of s.particles) {
+ ctx.globalAlpha = Math.max(0, p.life / p.max);
+ ctx.fillStyle = p.colour;
+ ctx.fillRect(p.x - 0.8, p.y - 0.8, 1.6, 1.6);
}
- // The ship blinks while it recovers from a hit.
- if (s.phase !== "over" && (s.hitTimer <= 0 || Math.floor(now / 120) % 2 === 0)) {
- ctx.fillStyle = s.hitTimer > 0 ? "#ff6b6b" : "#7dd3fc";
- sprite(ctx, SHIP, Math.round(s.shipX) - 6, ARCADE_SHIP_Y - 2);
+ ctx.globalAlpha = 1;
+ // The ship blinks while it is invulnerable after a hit.
+ if (s.phase !== "over" && (s.invulnerable <= 0 || Math.floor(now / 100) % 2 === 0)) drawShip(ctx, s, now);
+ // Rapid-fire time left, as a bar along the bottom.
+ if (s.rapid > 0) {
+ ctx.fillStyle = "#fde68a";
+ ctx.fillRect(4, ARCADE_H - 4, (ARCADE_W - 8) * (s.rapid / RAPID_S), 1.5);
}
- ctx.fillStyle = "#3b3470";
- ctx.fillRect(0, ARCADE_SHIP_Y + 6, ARCADE_W, 1);
- // Reserve lives, bottom left.
- ctx.fillStyle = "#7dd3fc";
- for (let i = 0; i < s.lives - 1; i += 1) sprite(ctx, SHIP, 6 + i * 16, ARCADE_H - 12);
}
const KEY_LEFT = new Set(["ArrowLeft", "KeyA"]);
const KEY_RIGHT = new Set(["ArrowRight", "KeyD"]);
-const KEY_FIRE = new Set(["Space", "ArrowUp", "KeyW"]);
+const KEY_UP = new Set(["ArrowUp", "KeyW"]);
+const KEY_DOWN = new Set(["ArrowDown", "KeyS"]);
+const idleInput = (): ArcadeInput => ({ left: false, right: false, up: false, down: false, fire: false });
export function ArcadeCabinet({ onClose }: { onClose: () => void }) {
const t = useT();
const canvas = useRef<HTMLCanvasElement>(null);
const dialog = useRef<HTMLDivElement>(null);
const game = useRef<ArcadeState>(newArcade());
- const input = useRef<ArcadeInput>({ left: false, right: false, fire: false });
- const [hud, setHud] = useState({ score: 0, lives: 3, wave: 1, phase: "ready" as ArcadePhase });
+ const input = useRef<ArcadeInput>(idleInput());
+ const [hud, setHud] = useState({ score: 0, lives: 3, level: 1, phase: "ready" as ArcadePhase });
const [best, setBest] = useState(readBest);
const bestRef = useRef(best);
+ const lastPhase = useRef<ArcadePhase>("ready");
const sync = useCallback(() => {
const s = game.current;
- setHud((h) => (h.score === s.score && h.lives === s.lives && h.wave === s.wave && h.phase === s.phase
- ? h : { score: s.score, lives: s.lives, wave: s.wave, phase: s.phase }));
- if (s.score > bestRef.current) {
- bestRef.current = s.score;
- setBest(s.score);
- writeBest(s.score);
- }
+ const score = Math.floor(s.score), level = arcadeLevel(s);
+ setHud((h) => (h.score === score && h.lives === s.lives && h.level === level && h.phase === s.phase
+ ? h : { score, lives: s.lives, level, phase: s.phase }));
+ if (score > bestRef.current) { bestRef.current = score; setBest(score); }
+ // Store a new best once, when a run stops (game over or pause), not every frame.
+ if (lastPhase.current === "playing" && s.phase !== "playing" && bestRef.current > readBest()) writeBest(bestRef.current);
+ lastPhase.current = s.phase;
}, []);
const startOrResume = useCallback(() => {
@@ -116,6 +174,9 @@ export function ArcadeCabinet({ onClose }: { onClose: () => void }) {
sync();
}, [sync]);
+ // Closing mid-run still keeps a new best score.
+ useEffect(() => () => { if (bestRef.current > readBest()) writeBest(bestRef.current); }, []);
+
// Keyboard: the dialog owns every key while it is open (capture phase, so
// the office's own Escape and E handlers never see them).
useEffect(() => {
@@ -134,20 +195,25 @@ export function ArcadeCabinet({ onClose }: { onClose: () => void }) {
}
if (KEY_LEFT.has(code)) input.current.left = true;
else if (KEY_RIGHT.has(code)) input.current.right = true;
- else if (KEY_FIRE.has(code) || code === "Enter") {
- if (s.phase === "playing") input.current.fire = KEY_FIRE.has(code) || input.current.fire;
+ else if (KEY_UP.has(code)) input.current.up = true;
+ else if (KEY_DOWN.has(code)) input.current.down = true;
+ else if (code === "Space" || code === "Enter") {
+ if (s.phase === "playing") input.current.fire = code === "Space" || input.current.fire;
else if (!event.repeat) startOrResume();
} else return;
event.preventDefault(); event.stopPropagation();
};
const up = (event: KeyboardEvent) => {
- if (KEY_LEFT.has(event.code)) input.current.left = false;
- else if (KEY_RIGHT.has(event.code)) input.current.right = false;
- else if (KEY_FIRE.has(event.code)) input.current.fire = false;
+ const code = event.code;
+ if (KEY_LEFT.has(code)) input.current.left = false;
+ else if (KEY_RIGHT.has(code)) input.current.right = false;
+ else if (KEY_UP.has(code)) input.current.up = false;
+ else if (KEY_DOWN.has(code)) input.current.down = false;
+ else if (code === "Space") input.current.fire = false;
};
// Losing window focus pauses the game and forgets held keys.
const blur = () => {
- input.current = { left: false, right: false, fire: false };
+ input.current = idleInput();
if (game.current.phase === "playing") { game.current.phase = "paused"; sync(); }
};
document.addEventListener("keydown", down, true);
@@ -164,7 +230,6 @@ export function ArcadeCabinet({ onClose }: { onClose: () => void }) {
useEffect(() => {
const ctx = canvas.current?.getContext("2d") ?? null;
if (!ctx) return;
- ctx.imageSmoothingEnabled = false;
let raf = 0;
let last = performance.now();
let acc = 0;
@@ -197,7 +262,7 @@ export function ArcadeCabinet({ onClose }: { onClose: () => void }) {
</header>
<div className="office-arcade-score" aria-live="polite">
<span>{t("society.office.arcade_score")} <b>{hud.score}</b></span>
- <span>{t("society.office.arcade_wave")} <b>{hud.wave}</b></span>
+ <span>{t("society.office.arcade_level")} <b>{hud.level}</b></span>
<span>{t("society.office.arcade_lives")} <b>{hud.lives}</b></span>
<span>{t("society.office.arcade_best")} <b>{best}</b></span>
</div>
diff --git a/jarvis/ui/web/frontend/src/components/society/office/arcade.css b/jarvis/ui/web/frontend/src/components/society/office/arcade.css
index 1060a3b082..de0d69a395 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/arcade.css
+++ b/jarvis/ui/web/frontend/src/components/society/office/arcade.css
@@ -7,8 +7,8 @@
.office-arcade-head h2 { margin:0; font-size:14px; font-weight:700; }
.office-arcade-score { display:flex; flex-wrap:wrap; justify-content:space-between; gap:4px 12px; font-size:12px; color:hsl(var(--muted-foreground)); font-variant-numeric:tabular-nums; }
.office-arcade-score b { color:hsl(var(--foreground)); }
-.office-arcade-screen { position:relative; align-self:center; width:min(100%, calc((100vh - 170px) * 224 / 256)); aspect-ratio:224 / 256; border-radius:10px; overflow:hidden; border:6px solid hsl(var(--border)); background:#07060f; }
-.office-arcade-screen canvas { display:block; width:100%; height:100%; image-rendering:pixelated; }
+.office-arcade-screen { position:relative; align-self:center; width:min(100%, calc((100vh - 170px) * 240 / 320)); aspect-ratio:240 / 320; border-radius:10px; overflow:hidden; border:6px solid hsl(var(--border)); background:#07060f; }
+.office-arcade-screen canvas { display:block; width:100%; height:100%; }
.office-arcade-message { position:absolute; left:50%; top:58%; transform:translate(-50%, -50%); max-width:86%; border:1px solid #fde68a; border-radius:8px; padding:8px 14px; background:rgb(7 6 15 / .85); color:#fde68a; font-size:13px; font-weight:600; letter-spacing:.02em; cursor:pointer; text-align:center; }
.office-arcade-message:focus-visible { outline:2px solid hsl(var(--ring)); outline-offset:2px; }
.office-arcade-keys { text-align:center; }
diff --git a/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.test.ts b/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.test.ts
index 3799ec9c41..03267f05df 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.test.ts
+++ b/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.test.ts
@@ -1,71 +1,139 @@
import { describe, expect, it } from "vitest";
-import { ARCADE_SHIP_Y, ARCADE_W, invaderPos, newArcade, stepArcade, swarmInterval, type ArcadeInput } from "./arcadeGame";
+import {
+ ARCADE_H, ARCADE_W, ROCK_RADIUS, arcadeLevel, newArcade, spawnInterval, speedFactor, stepArcade,
+ type ArcadeInput, type ArcadeState, type Rock,
+} from "./arcadeGame";
-const idle: ArcadeInput = { left: false, right: false, fire: false };
-const run = (s: ReturnType<typeof newArcade>, input: ArcadeInput, seconds: number) => {
- for (let t = 0; t < seconds; t += 1 / 120) stepArcade(s, input, 1 / 120, () => 0.5);
+const idle: ArcadeInput = { left: false, right: false, up: false, down: false, fire: false };
+const DT = 1 / 120;
+const run = (s: ArcadeState, input: ArcadeInput, seconds: number, random: () => number = () => 0.5) => {
+ for (let t = 0; t < seconds; t += DT) stepArcade(s, input, DT, random);
};
+const rock = (over: Partial<Rock>): Rock => ({
+ x: 0, y: 0, vx: 0, vy: 0, size: 0, hp: 1, angle: 0, spin: 0, shape: [1, 1, 1, 1, 1, 1], flash: 0, ...over,
+});
+const playing = (): ArcadeState => {
+ const s = newArcade(() => 0.5);
+ s.phase = "playing";
+ s.spawnTimer = 999;
+ return s;
+};
+
+/** Deterministic pseudo-random numbers for the balance runs. */
+function seeded(seed: number): () => number {
+ let x = seed;
+ return () => { x = (x * 1664525 + 1013904223) % 4294967296; return x / 4294967296; };
+}
-describe("arcade game", () => {
- it("does nothing until started", () => {
+describe("asteroid run", () => {
+ it("does nothing until launched", () => {
const s = newArcade();
- run(s, { ...idle, right: true }, 1);
- expect(s.shipX).toBe(ARCADE_W / 2);
+ run(s, { ...idle, up: true }, 1);
+ expect(s.time).toBe(0);
+ expect(s.rocks).toHaveLength(0);
});
- it("moves the ship and keeps it on screen", () => {
- const s = newArcade();
- s.phase = "playing";
+ it("flies the rocket in every direction and keeps it on screen", () => {
+ const s = playing();
+ const y0 = s.shipY;
+ run(s, { ...idle, up: true }, 0.3);
+ expect(s.shipY).toBeLessThan(y0);
run(s, { ...idle, left: true }, 5);
- expect(s.shipX).toBe(10);
+ expect(s.shipX).toBeGreaterThan(0);
+ expect(s.shipX).toBeLessThan(15);
+ run(s, { ...idle, right: true, down: true }, 5);
+ expect(s.shipX).toBeLessThan(ARCADE_W);
+ expect(s.shipY).toBeLessThan(ARCADE_H);
});
- it("scores when a shot hits an invader", () => {
- const s = newArcade();
- s.phase = "playing";
- s.bombTimer = 99;
- const target = s.invaders.find((inv) => inv.row === 4 && inv.col === 0)!;
- const { x, y } = invaderPos(s, target);
- s.shot = { x: x + 5, y: y + 4 };
- stepArcade(s, idle, 0.001);
- expect(target.alive).toBe(false);
- expect(s.score).toBe(10);
- expect(s.shot).toBeNull();
+ it("drifts to a stop when no key is held", () => {
+ const s = playing();
+ run(s, { ...idle, right: true }, 0.3);
+ run(s, idle, 2);
+ expect(Math.abs(s.vx)).toBeLessThan(1);
});
- it("loses a life to a bomb and ends the game on the last one", () => {
- const s = newArcade();
- s.phase = "playing";
- s.bombTimer = 99;
- s.bombs = [{ x: s.shipX, y: ARCADE_SHIP_Y }];
+ it("breaks a big rock into two smaller ones and scores it", () => {
+ const s = playing();
+ s.rocks = [rock({ x: 120, y: 100, size: 2, hp: 1 })];
+ s.shots = [{ x: 120, y: 100 }];
+ stepArcade(s, idle, 0.001, () => 0.5);
+ expect(s.rocks.map((r) => r.size)).toEqual([1, 1]);
+ expect(s.score).toBeGreaterThanOrEqual(25);
+ });
+
+ it("needs several hits for a large rock", () => {
+ const s = playing();
+ s.rocks = [rock({ x: 120, y: 100, size: 2, hp: 4 })];
+ s.shots = [{ x: 120, y: 100 }];
+ stepArcade(s, idle, 0.001, () => 0.5);
+ expect(s.rocks).toHaveLength(1);
+ expect(s.rocks[0].hp).toBe(3);
+ });
+
+ it("loses a life on a crash, blinks, and ends on the last life", () => {
+ const s = playing();
+ s.rocks = [rock({ x: s.shipX, y: s.shipY })];
stepArcade(s, idle, 0.001);
expect(s.lives).toBe(2);
- expect(s.hitTimer).toBeGreaterThan(0);
+ expect(s.invulnerable).toBeGreaterThan(0);
+ s.rocks = [rock({ x: s.shipX, y: s.shipY })];
+ stepArcade(s, idle, 0.001);
+ expect(s.lives).toBe(2);
+ s.invulnerable = 0;
s.lives = 1;
- s.hitTimer = 0;
- s.bombs = [{ x: s.shipX, y: ARCADE_SHIP_Y }];
+ s.rocks = [rock({ x: s.shipX, y: s.shipY })];
stepArcade(s, idle, 0.001);
expect(s.phase).toBe("over");
});
- it("marches faster as invaders fall, and starts the next wave when all are gone", () => {
- const s = newArcade();
- s.phase = "playing";
- const full = swarmInterval(s);
- s.invaders.forEach((inv, i) => { inv.alive = i === 0; });
- expect(swarmInterval(s)).toBeLessThan(full);
- s.invaders[0].alive = false;
- s.bombTimer = 99;
+ it("a shield absorbs one crash", () => {
+ const s = playing();
+ s.shield = true;
+ s.rocks = [rock({ x: s.shipX, y: s.shipY })];
stepArcade(s, idle, 0.001);
- expect(s.wave).toBe(2);
- expect(s.invaders.every((inv) => inv.alive)).toBe(true);
+ expect(s.lives).toBe(3);
+ expect(s.shield).toBe(false);
});
- it("ends the game when the swarm reaches the ship", () => {
- const s = newArcade();
- s.phase = "playing";
- s.swarmY = ARCADE_SHIP_Y;
+ it("collects pickups by touching them", () => {
+ const s = playing();
+ s.pickups = [{ x: s.shipX, y: s.shipY, kind: "rapid", t: 0 }, { x: s.shipX, y: s.shipY, kind: "life", t: 0 }];
stepArcade(s, idle, 0.001);
- expect(s.phase).toBe("over");
+ expect(s.rapid).toBeGreaterThan(0);
+ expect(s.lives).toBe(4);
+ });
+
+ it("gets harder the longer you survive", () => {
+ expect(spawnInterval(0)).toBeGreaterThan(1);
+ expect(spawnInterval(120)).toBeLessThan(spawnInterval(30));
+ expect(speedFactor(100)).toBeGreaterThan(2.5);
+ const s = playing();
+ s.time = 45;
+ expect(arcadeLevel(s)).toBe(3);
+ });
+
+ it("starts gentle: an idle rocket survives the first seconds, a long idle run does not", () => {
+ // Averaged over seeds so the check is about the curve, not one lucky field.
+ let early = 0, late = 0;
+ for (let seed = 1; seed <= 20; seed += 1) {
+ const random = seeded(seed);
+ const s = newArcade(random);
+ s.phase = "playing";
+ run(s, idle, 8, random);
+ if (s.lives === 3) early += 1;
+ run(s, idle, 170, random);
+ if ((s.phase as string) === "over") late += 1;
+ }
+ expect(early).toBeGreaterThanOrEqual(12);
+ expect(late).toBe(20);
+ });
+
+ it("keeps rocks inside the side walls", () => {
+ const s = playing();
+ s.rocks = [rock({ x: 3, y: 100, vx: -50, size: 1 })];
+ stepArcade(s, idle, 0.05);
+ expect(s.rocks[0].x).toBeGreaterThanOrEqual(ROCK_RADIUS[1]);
+ expect(s.rocks[0].vx).toBeGreaterThan(0);
});
});
diff --git a/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.ts b/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.ts
index 7d328805f4..5046118ddb 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.ts
+++ b/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.ts
@@ -1,200 +1,272 @@
/**
- * The break-room arcade game: a small invaders shooter. Pure state and a
- * fixed-rate `stepArcade`, so the rules are testable without a canvas; the
- * cabinet overlay (ArcadeCabinet) only feeds input and draws the state.
+ * The break-room arcade game: "Asteroid Run". A rocket flies up through an
+ * endless asteroid field; dodge or shoot the rocks. It starts gentle and gets
+ * harder the longer you survive: rocks come faster, denser and bigger.
+ *
+ * Pure state and a fixed-rate `stepArcade`, so the rules are testable without
+ * a canvas; the cabinet overlay (ArcadeCabinet) only feeds input and draws.
*/
-/** Playfield size in logical pixels; the canvas scales it up crisply. */
-export const ARCADE_W = 224;
-export const ARCADE_H = 256;
-
-const SHIP_Y = ARCADE_H - 24;
-const SHIP_HALF = 7;
-const SHIP_SPEED = 110;
-const SHOT_SPEED = 260;
-const BOMB_SPEED = 95;
-const COLS = 9;
-const ROWS = 5;
-const CELL_X = 18;
-const CELL_Y = 15;
-export const INVADER_W = 11;
-export const INVADER_H = 8;
-/** Points per invader by row, top row worth most. */
-const ROW_POINTS = [30, 20, 20, 10, 10];
-/** How long the ship blinks after a hit before play resumes (s). */
-const RESPAWN_S = 1.2;
+/** Playfield size in logical units; the canvas scales it up. */
+export const ARCADE_W = 240;
+export const ARCADE_H = 320;
+
+export const SHIP_RADIUS = 6;
+const SHIP_ACCEL = 900;
+const SHIP_MAX_SPEED = 150;
+/** Fraction of velocity kept per second when no key is held (gentle drift). */
+const SHIP_DRAG = 0.02;
+const SHOT_SPEED = 330;
+const SHOT_COOLDOWN = 0.2;
+const RAPID_COOLDOWN = 0.08;
+/** Seconds of blinking invulnerability after losing a life. */
+const INVULNERABLE_S = 2;
+export const RAPID_S = 8;
+const MAX_LIVES = 5;
export type ArcadePhase = "ready" | "playing" | "paused" | "over";
+export type RockSize = 0 | 1 | 2;
+export type PickupKind = "shield" | "rapid" | "life";
+
+/** Radius, hit points and score per rock size (small, medium, large). */
+export const ROCK_RADIUS: Record<RockSize, number> = { 0: 6, 1: 11, 2: 17 };
+const ROCK_HP: Record<RockSize, number> = { 0: 1, 1: 2, 2: 4 };
+const ROCK_POINTS: Record<RockSize, number> = { 0: 100, 1: 50, 2: 25 };
-export interface Invader { col: number; row: number; alive: boolean }
+export interface Rock {
+ x: number; y: number; vx: number; vy: number; size: RockSize; hp: number;
+ angle: number; spin: number;
+ /** Per-vertex radius factors: the jagged outline. */
+ shape: number[];
+ /** Seconds of white flash after a hit that did not break it. */
+ flash: number;
+}
export interface Shot { x: number; y: number }
+export interface Pickup { x: number; y: number; kind: PickupKind; t: number }
+export interface Particle { x: number; y: number; vx: number; vy: number; life: number; max: number; colour: string }
+export interface Star { x: number; y: number; depth: number }
export interface ArcadeState {
phase: ArcadePhase;
+ /** Seconds survived in this run; drives the difficulty. */
+ time: number;
score: number;
lives: number;
- wave: number;
- shipX: number;
- /** Seconds of post-hit grace left; the ship neither moves nor dies meanwhile. */
- hitTimer: number;
- shot: Shot | null;
- bombs: Shot[];
- invaders: Invader[];
- /** Top-left corner of the invader block. */
- swarmX: number;
- swarmY: number;
- swarmDir: 1 | -1;
- /** Seconds until the next bomb drops. */
- bombTimer: number;
- /** Animation frame of the marching invaders (0/1), flips per swarm step. */
- frame: 0 | 1;
- stepTimer: number;
+ shipX: number; shipY: number; vx: number; vy: number;
+ invulnerable: number;
+ shield: boolean;
+ rapid: number;
+ cooldown: number;
+ shots: Shot[];
+ rocks: Rock[];
+ pickups: Pickup[];
+ particles: Particle[];
+ stars: Star[];
+ spawnTimer: number;
+ /** Screen shake left, in seconds. */
+ shake: number;
}
-export interface ArcadeInput { left: boolean; right: boolean; fire: boolean }
+export interface ArcadeInput { left: boolean; right: boolean; up: boolean; down: boolean; fire: boolean }
-function spawnWave(state: ArcadeState, wave: number): void {
- state.wave = wave;
- state.invaders = [];
- for (let row = 0; row < ROWS; row += 1) {
- for (let col = 0; col < COLS; col += 1) state.invaders.push({ col, row, alive: true });
- }
- state.swarmX = 20;
- // Each wave starts a little lower, capped so there is always room to react.
- state.swarmY = 34 + Math.min(wave - 1, 5) * 8;
- state.swarmDir = 1;
- state.shot = null;
- state.bombs = [];
- state.bombTimer = 1.5;
- state.stepTimer = 0;
+/** 1, 2, 3 … one level per 20 seconds survived. */
+export function arcadeLevel(state: ArcadeState): number {
+ return 1 + Math.floor(state.time / 20);
+}
+
+/** Seconds between new rocks: 1.3 s at the start, down towards 0.2 s. */
+export function spawnInterval(time: number): number {
+ return Math.max(0.2, 1.3 / (1 + time / 25));
}
-export function newArcade(): ArcadeState {
- const state: ArcadeState = {
- phase: "ready", score: 0, lives: 3, wave: 1, shipX: ARCADE_W / 2, hitTimer: 0,
- shot: null, bombs: [], invaders: [], swarmX: 0, swarmY: 0, swarmDir: 1, bombTimer: 0, frame: 0, stepTimer: 0,
+/** How fast rocks fall relative to the start: doubles after about 50 s. */
+export function speedFactor(time: number): number {
+ return 1 + time / 50;
+}
+
+export function newArcade(random: () => number = Math.random): ArcadeState {
+ const stars: Star[] = [];
+ for (let i = 0; i < 70; i += 1) stars.push({ x: random() * ARCADE_W, y: random() * ARCADE_H, depth: 0.2 + random() * 0.8 });
+ return {
+ phase: "ready", time: 0, score: 0, lives: 3,
+ shipX: ARCADE_W / 2, shipY: ARCADE_H - 40, vx: 0, vy: 0,
+ invulnerable: 0, shield: false, rapid: 0, cooldown: 0,
+ shots: [], rocks: [], pickups: [], particles: [], stars, spawnTimer: 0.8, shake: 0,
};
- spawnWave(state, 1);
- return state;
}
-/** Where an invader's top-left corner currently is. */
-export function invaderPos(state: ArcadeState, inv: Invader): { x: number; y: number } {
- return { x: state.swarmX + inv.col * CELL_X, y: state.swarmY + inv.row * CELL_Y };
+function makeRock(size: RockSize, x: number, y: number, vx: number, vy: number, random: () => number): Rock {
+ const points = 9 + size * 2;
+ const shape = Array.from({ length: points }, () => 0.72 + random() * 0.4);
+ return { x, y, vx, vy, size, hp: ROCK_HP[size], angle: random() * Math.PI * 2, spin: (random() - 0.5) * 2.4, shape, flash: 0 };
}
-function aliveCount(state: ArcadeState): number {
- let n = 0;
- for (const inv of state.invaders) if (inv.alive) n += 1;
- return n;
+function spawnRock(state: ArcadeState, random: () => number): void {
+ // Bigger rocks become more common as the run goes on.
+ const bigChance = Math.min(0.45, 0.12 + state.time / 250);
+ const roll = random();
+ const size: RockSize = roll < bigChance ? 2 : roll < bigChance + 0.4 ? 1 : 0;
+ const r = ROCK_RADIUS[size];
+ const speed = (40 + random() * 35) * speedFactor(state.time) * (size === 0 ? 1.25 : 1);
+ const x = r + random() * (ARCADE_W - 2 * r);
+ state.rocks.push(makeRock(size, x, -r - 2, (random() - 0.5) * 40, speed, random));
}
-/** Seconds between swarm steps: the fewer left, the faster they march. */
-export function swarmInterval(state: ArcadeState): number {
- const left = aliveCount(state) / (ROWS * COLS);
- return Math.max(0.05, (0.08 + 0.55 * left) * Math.pow(0.9, state.wave - 1));
+function burst(state: ArcadeState, x: number, y: number, count: number, colour: string, speed: number, random: () => number): void {
+ for (let i = 0; i < count; i += 1) {
+ const a = random() * Math.PI * 2, v = speed * (0.3 + random() * 0.7), life = 0.35 + random() * 0.5;
+ state.particles.push({ x, y, vx: Math.cos(a) * v, vy: Math.sin(a) * v, life, max: life, colour });
+ }
}
-/** Advance the game by `dt` seconds. `random` returns [0, 1) and is injectable for tests. */
-export function stepArcade(state: ArcadeState, input: ArcadeInput, dt: number, random: () => number = Math.random): void {
- if (state.phase !== "playing") return;
+function breakRock(state: ArcadeState, rock: Rock, random: () => number): void {
+ state.score += ROCK_POINTS[rock.size];
+ burst(state, rock.x, rock.y, 8 + rock.size * 8, "#c9b79c", 60 + rock.size * 20, random);
+ burst(state, rock.x, rock.y, 5 + rock.size * 3, "#ffb454", 90, random);
+ if (rock.size > 0) {
+ const child = (rock.size - 1) as RockSize;
+ for (const side of [-1, 1]) {
+ state.rocks.push(makeRock(child, rock.x + side * ROCK_RADIUS[child] * 0.6, rock.y,
+ rock.vx + side * (25 + random() * 25), rock.vy * (0.85 + random() * 0.3), random));
+ }
+ }
+ // Now and then a rock leaves something useful behind.
+ const roll = random();
+ if (roll < 0.03) state.pickups.push({ x: rock.x, y: rock.y, kind: "life", t: 0 });
+ else if (roll < 0.09) state.pickups.push({ x: rock.x, y: rock.y, kind: "shield", t: 0 });
+ else if (roll < 0.15) state.pickups.push({ x: rock.x, y: rock.y, kind: "rapid", t: 0 });
+}
- if (state.hitTimer > 0) {
- state.hitTimer = Math.max(0, state.hitTimer - dt);
+function hitShip(state: ArcadeState, random: () => number): void {
+ state.shake = 0.35;
+ if (state.shield) {
+ state.shield = false;
+ state.invulnerable = 1;
+ burst(state, state.shipX, state.shipY, 18, "#7dd3fc", 120, random);
return;
}
+ state.lives -= 1;
+ burst(state, state.shipX, state.shipY, 30, "#ff7a59", 140, random);
+ if (state.lives <= 0) {
+ state.lives = 0;
+ state.phase = "over";
+ } else {
+ state.invulnerable = INVULNERABLE_S;
+ state.rapid = 0;
+ }
+}
- // Ship and shot.
- const dir = (input.right ? 1 : 0) - (input.left ? 1 : 0);
- state.shipX = Math.min(ARCADE_W - 10, Math.max(10, state.shipX + dir * SHIP_SPEED * dt));
- if (input.fire && !state.shot) state.shot = { x: state.shipX, y: SHIP_Y - 6 };
- if (state.shot) {
- state.shot.y -= SHOT_SPEED * dt;
- if (state.shot.y < 12) state.shot = null;
+/** Advance the game by `dt` seconds. `random` returns [0, 1) and is injectable for tests. */
+export function stepArcade(state: ArcadeState, input: ArcadeInput, dt: number, random: () => number = Math.random): void {
+ // Particles and stars keep drifting on the game-over screen; everything else stops.
+ for (const p of state.particles) { p.x += p.vx * dt; p.y += p.vy * dt; p.life -= dt; }
+ state.particles = state.particles.filter((p) => p.life > 0);
+ state.shake = Math.max(0, state.shake - dt);
+ if (state.phase !== "playing" && state.phase !== "over") return;
+ const starSpeed = 30 * speedFactor(state.time);
+ for (const s of state.stars) {
+ s.y += starSpeed * s.depth * dt;
+ if (s.y > ARCADE_H) { s.y -= ARCADE_H; s.x = random() * ARCADE_W; }
}
+ if (state.phase !== "playing") return;
- // Swarm march: a sideways step, or down and turn at an edge.
- state.stepTimer += dt;
- const interval = swarmInterval(state);
- while (state.stepTimer >= interval) {
- state.stepTimer -= interval;
- state.frame = state.frame === 0 ? 1 : 0;
- let minX = Infinity, maxX = -Infinity;
- for (const inv of state.invaders) {
- if (!inv.alive) continue;
- const { x } = invaderPos(state, inv);
- minX = Math.min(minX, x);
- maxX = Math.max(maxX, x + INVADER_W);
- }
- const next = state.swarmDir * 3;
- if (maxX + next > ARCADE_W - 4 || minX + next < 4) {
- state.swarmY += 8;
- state.swarmDir = state.swarmDir === 1 ? -1 : 1;
- } else {
- state.swarmX += next;
- }
+ state.time += dt;
+ state.score += dt * 10 * arcadeLevel(state);
+ state.invulnerable = Math.max(0, state.invulnerable - dt);
+ state.rapid = Math.max(0, state.rapid - dt);
+ state.cooldown = Math.max(0, state.cooldown - dt);
+
+ // Ship: accelerate towards the held direction, drift to a stop otherwise.
+ const ax = (input.right ? 1 : 0) - (input.left ? 1 : 0);
+ const ay = (input.down ? 1 : 0) - (input.up ? 1 : 0);
+ state.vx += ax * SHIP_ACCEL * dt;
+ state.vy += ay * SHIP_ACCEL * dt;
+ const drag = Math.pow(SHIP_DRAG, dt);
+ if (ax === 0) state.vx *= drag;
+ if (ay === 0) state.vy *= drag;
+ const speed = Math.hypot(state.vx, state.vy);
+ if (speed > SHIP_MAX_SPEED) { state.vx *= SHIP_MAX_SPEED / speed; state.vy *= SHIP_MAX_SPEED / speed; }
+ state.shipX += state.vx * dt;
+ state.shipY += state.vy * dt;
+ const minX = SHIP_RADIUS + 2, maxX = ARCADE_W - SHIP_RADIUS - 2, minY = 40, maxY = ARCADE_H - SHIP_RADIUS - 8;
+ if (state.shipX < minX || state.shipX > maxX) { state.shipX = Math.min(maxX, Math.max(minX, state.shipX)); state.vx = 0; }
+ if (state.shipY < minY || state.shipY > maxY) { state.shipY = Math.min(maxY, Math.max(minY, state.shipY)); state.vy = 0; }
+ // Engine exhaust.
+ if (random() < 0.7) {
+ const life = 0.2 + random() * 0.2;
+ state.particles.push({ x: state.shipX + (random() - 0.5) * 3, y: state.shipY + 9, vx: (random() - 0.5) * 20, vy: 60 + random() * 40, life, max: life, colour: random() < 0.5 ? "#ffd166" : "#ff7a59" });
}
- // Shot hits an invader.
- if (state.shot) {
- for (const inv of state.invaders) {
- if (!inv.alive) continue;
- const { x, y } = invaderPos(state, inv);
- if (state.shot.x >= x - 1 && state.shot.x <= x + INVADER_W + 1 && state.shot.y >= y && state.shot.y <= y + INVADER_H) {
- inv.alive = false;
- state.score += ROW_POINTS[inv.row];
- state.shot = null;
- break;
- }
- }
+ // Shooting: twin shots while rapid fire lasts.
+ if (input.fire && state.cooldown <= 0) {
+ if (state.rapid > 0) state.shots.push({ x: state.shipX - 4, y: state.shipY - 6 }, { x: state.shipX + 4, y: state.shipY - 6 });
+ else state.shots.push({ x: state.shipX, y: state.shipY - 9 });
+ state.cooldown = state.rapid > 0 ? RAPID_COOLDOWN : SHOT_COOLDOWN;
}
+ for (const s of state.shots) s.y -= SHOT_SPEED * dt;
+ state.shots = state.shots.filter((s) => s.y > -6);
- // Bombs drop from a random column's lowest invader.
- state.bombTimer -= dt;
- if (state.bombTimer <= 0) {
- const lowest = new Map<number, Invader>();
- for (const inv of state.invaders) {
- if (inv.alive && (lowest.get(inv.col)?.row ?? -1) < inv.row) lowest.set(inv.col, inv);
- }
- const shooters = [...lowest.values()];
- if (shooters.length > 0) {
- const inv = shooters[Math.floor(random() * shooters.length)];
- const { x, y } = invaderPos(state, inv);
- state.bombs.push({ x: x + INVADER_W / 2, y: y + INVADER_H });
- }
- state.bombTimer = Math.max(0.35, 1.3 - state.wave * 0.12) * (0.6 + random() * 0.8);
+ // New rocks.
+ state.spawnTimer -= dt;
+ while (state.spawnTimer <= 0) {
+ spawnRock(state, random);
+ state.spawnTimer += spawnInterval(state.time) * (0.7 + random() * 0.6);
}
- for (const bomb of state.bombs) bomb.y += BOMB_SPEED * dt;
- state.bombs = state.bombs.filter((b) => b.y < ARCADE_H);
- // A bomb hits the ship.
- if (state.bombs.some((b) => Math.abs(b.x - state.shipX) <= SHIP_HALF && b.y >= SHIP_Y - 4 && b.y <= SHIP_Y + 6)) {
- loseLife(state);
- return;
+ // Rocks move, bounce off the side walls, and leave at the bottom.
+ for (const rock of state.rocks) {
+ rock.x += rock.vx * dt;
+ rock.y += rock.vy * dt;
+ rock.angle += rock.spin * dt;
+ rock.flash = Math.max(0, rock.flash - dt);
+ const r = ROCK_RADIUS[rock.size];
+ if (rock.x < r) { rock.x = r; rock.vx = Math.abs(rock.vx); }
+ if (rock.x > ARCADE_W - r) { rock.x = ARCADE_W - r; rock.vx = -Math.abs(rock.vx); }
}
- // The swarm reaches the ship's row: game over, whatever lives remain.
- for (const inv of state.invaders) {
- if (inv.alive && invaderPos(state, inv).y + INVADER_H >= SHIP_Y - 4) {
- state.lives = 0;
- state.phase = "over";
- return;
+ // Shots against rocks.
+ const broken = new Set<Rock>();
+ state.shots = state.shots.filter((shot) => {
+ for (const rock of state.rocks) {
+ if (broken.has(rock)) continue;
+ const r = ROCK_RADIUS[rock.size];
+ if ((shot.x - rock.x) ** 2 + (shot.y - rock.y) ** 2 <= (r + 1.5) ** 2) {
+ rock.hp -= 1;
+ rock.flash = 0.08;
+ burst(state, shot.x, shot.y, 3, "#fde68a", 50, random);
+ if (rock.hp <= 0) broken.add(rock);
+ return false;
+ }
}
+ return true;
+ });
+ if (broken.size > 0) {
+ state.rocks = state.rocks.filter((rock) => !broken.has(rock));
+ for (const rock of broken) breakRock(state, rock, random);
}
+ state.rocks = state.rocks.filter((rock) => rock.y - ROCK_RADIUS[rock.size] < ARCADE_H + 4);
- if (aliveCount(state) === 0) spawnWave(state, state.wave + 1);
-}
+ // Pickups fall slowly and are collected by touch.
+ for (const p of state.pickups) { p.y += 45 * dt; p.t += dt; }
+ state.pickups = state.pickups.filter((p) => {
+ if (Math.hypot(p.x - state.shipX, p.y - state.shipY) <= SHIP_RADIUS + 7) {
+ if (p.kind === "shield") state.shield = true;
+ else if (p.kind === "rapid") state.rapid = RAPID_S;
+ else state.lives = Math.min(MAX_LIVES, state.lives + 1);
+ state.score += 50;
+ burst(state, p.x, p.y, 12, "#a7f3d0", 70, random);
+ return false;
+ }
+ return p.y < ARCADE_H + 8;
+ });
-function loseLife(state: ArcadeState): void {
- state.lives -= 1;
- state.bombs = [];
- state.shot = null;
- if (state.lives <= 0) {
- state.lives = 0;
- state.phase = "over";
- } else {
- state.hitTimer = RESPAWN_S;
+ // A rock hits the ship (slightly forgiving hitbox).
+ if (state.invulnerable <= 0) {
+ const hit = state.rocks.find((rock) => Math.hypot(rock.x - state.shipX, rock.y - state.shipY) < ROCK_RADIUS[rock.size] * 0.85 + SHIP_RADIUS - 1);
+ if (hit) {
+ state.rocks = state.rocks.filter((rock) => rock !== hit);
+ burst(state, hit.x, hit.y, 12, "#c9b79c", 80, random);
+ hitShip(state, random);
+ }
}
}
-
-export const ARCADE_SHIP_Y = SHIP_Y;
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/society/de.json b/jarvis/ui/web/frontend/src/i18n/locales/society/de.json
index d22b928ace..9285dce475 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/de.json
@@ -816,16 +816,16 @@
"elevator_down_count": "Gerade unten: {0}",
"elevator_up": "Hoch zur Coding-Etage",
"elevator_down": "Runter ins Agenten-Büro",
- "arcade_prompt": "Am Automaten zocken",
- "arcade_title": "Automat im Pausenraum",
+ "arcade_prompt": "Asteroid Run spielen",
+ "arcade_title": "Asteroid Run",
"arcade_score": "Punkte",
- "arcade_wave": "Welle",
+ "arcade_level": "Level",
"arcade_lives": "Leben",
"arcade_best": "Rekord",
- "arcade_start": "Leertaste drücken zum Spielen",
- "arcade_paused": "Pause: Leertaste zum Weiterspielen",
- "arcade_over": "Game over: {0} Punkte. Leertaste für eine neue Runde",
- "arcade_keys": "A/D oder Pfeile bewegen · Leertaste schießt · P pausiert · E oder Esc verlässt",
+ "arcade_start": "Leertaste drücken zum Starten",
+ "arcade_paused": "Pause: Leertaste zum Weiterfliegen",
+ "arcade_over": "Abgestürzt mit {0} Punkten. Leertaste für einen neuen Flug",
+ "arcade_keys": "WASD oder Pfeile fliegen · Leertaste schießt · P pausiert · E oder Esc verlässt · Schild, Blitz und Herz einsammeln",
"room_lead": "Chefbüro",
"room_team": "Teamraum",
"room_wardrobe": "Garderobe",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/society/en.json b/jarvis/ui/web/frontend/src/i18n/locales/society/en.json
index 5c5fc23c15..75783eac4a 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/en.json
@@ -816,16 +816,16 @@
"elevator_down_count": "Downstairs right now: {0}",
"elevator_up": "Up to the coding floor",
"elevator_down": "Down to the agents office",
- "arcade_prompt": "Play the arcade",
- "arcade_title": "Break-room arcade",
+ "arcade_prompt": "Play Asteroid Run",
+ "arcade_title": "Asteroid Run",
"arcade_score": "Score",
- "arcade_wave": "Wave",
+ "arcade_level": "Level",
"arcade_lives": "Lives",
"arcade_best": "Best",
- "arcade_start": "Press Space to play",
- "arcade_paused": "Paused: press Space to go on",
- "arcade_over": "Game over: {0} points. Space plays again",
- "arcade_keys": "A/D or arrows move · Space shoots · P pauses · E or Esc leaves",
+ "arcade_start": "Press Space to launch",
+ "arcade_paused": "Paused: press Space to fly on",
+ "arcade_over": "Crashed with {0} points. Space flies again",
+ "arcade_keys": "WASD or arrows fly · Space shoots · P pauses · E or Esc leaves · Grab shield, lightning and heart drops",
"room_lead": "Lead office",
"room_team": "Team room",
"room_wardrobe": "Wardrobe",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/society/es.json b/jarvis/ui/web/frontend/src/i18n/locales/society/es.json
index a5059565cd..988be48673 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/es.json
@@ -816,16 +816,16 @@
"elevator_down_count": "Abajo ahora mismo: {0}",
"elevator_up": "Subir a la planta de código",
"elevator_down": "Bajar a la oficina de agentes",
- "arcade_prompt": "Jugar a la máquina",
- "arcade_title": "Máquina recreativa",
+ "arcade_prompt": "Jugar a Asteroid Run",
+ "arcade_title": "Asteroid Run",
"arcade_score": "Puntos",
- "arcade_wave": "Oleada",
+ "arcade_level": "Nivel",
"arcade_lives": "Vidas",
"arcade_best": "Récord",
- "arcade_start": "Pulsa Espacio para jugar",
- "arcade_paused": "Pausa: pulsa Espacio para seguir",
- "arcade_over": "Fin de la partida: {0} puntos. Espacio para otra",
- "arcade_keys": "A/D o flechas para moverte · Espacio dispara · P pausa · E o Esc para salir",
+ "arcade_start": "Pulsa Espacio para despegar",
+ "arcade_paused": "Pausa: pulsa Espacio para seguir volando",
+ "arcade_over": "Te estrellaste con {0} puntos. Espacio para volar otra vez",
+ "arcade_keys": "WASD o flechas para volar · Espacio dispara · P pausa · E o Esc para salir · Recoge escudo, rayo y corazón",
"room_lead": "Despacho del líder",
"room_team": "Sala de equipos",
"room_wardrobe": "Vestuario",