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): playable arcade cabinet in the break room

rubenluetke10-beepa322f0982f15
diff --git a/jarvis/ui/web/frontend/src/components/society/office/ArcadeCabinet.tsx b/jarvis/ui/web/frontend/src/components/society/office/ArcadeCabinet.tsx
new file mode 100644
index 0000000000..138f99a1f6
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/office/ArcadeCabinet.tsx
@@ -0,0 +1,214 @@
+/**
+ * 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.
+ */
+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,
+} from "./arcadeGame";
+import "./arcade.css";
+
+const BEST_KEY = "jarvis.office.arcade.best";
+const STEP = 1 / 120;
+/** Canvas pixels per playfield pixel; 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"];
+
+function readBest(): number {
+ try { return Number(window.localStorage.getItem(BEST_KEY)) || 0; } catch { return 0; }
+}
+function writeBest(score: number): void {
+ // Private windows and blocked site data throw here; the best score is only a nicety.
+ 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 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));
+ }
+ 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);
+ }
+ // 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.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"]);
+
+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 [best, setBest] = useState(readBest);
+ const bestRef = useRef(best);
+
+ 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 startOrResume = useCallback(() => {
+ const s = game.current;
+ if (s.phase === "over") game.current = { ...newArcade(), phase: "playing" };
+ else s.phase = "playing";
+ input.current.fire = false;
+ sync();
+ }, [sync]);
+
+ // 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(() => {
+ const down = (event: KeyboardEvent) => {
+ const s = game.current;
+ const code = event.code;
+ if (event.key === "Escape" || code === "KeyE") {
+ event.preventDefault(); event.stopPropagation();
+ if (!event.repeat) onClose();
+ return;
+ }
+ if (code === "KeyP") {
+ event.preventDefault(); event.stopPropagation();
+ if (!event.repeat && (s.phase === "playing" || s.phase === "paused")) { s.phase = s.phase === "playing" ? "paused" : "playing"; sync(); }
+ return;
+ }
+ 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 (!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;
+ };
+ // Losing window focus pauses the game and forgets held keys.
+ const blur = () => {
+ input.current = { left: false, right: false, fire: false };
+ if (game.current.phase === "playing") { game.current.phase = "paused"; sync(); }
+ };
+ document.addEventListener("keydown", down, true);
+ document.addEventListener("keyup", up, true);
+ window.addEventListener("blur", blur);
+ return () => {
+ document.removeEventListener("keydown", down, true);
+ document.removeEventListener("keyup", up, true);
+ window.removeEventListener("blur", blur);
+ };
+ }, [onClose, startOrResume, sync]);
+
+ // Fixed-step simulation, painted once per animation frame.
+ useEffect(() => {
+ const ctx = canvas.current?.getContext("2d") ?? null;
+ if (!ctx) return;
+ ctx.imageSmoothingEnabled = false;
+ let raf = 0;
+ let last = performance.now();
+ let acc = 0;
+ const tick = (now: number) => {
+ acc += Math.min(0.1, (now - last) / 1000);
+ last = now;
+ while (acc >= STEP) { stepArcade(game.current, input.current, STEP); acc -= STEP; }
+ paint(ctx, game.current, now);
+ sync();
+ raf = requestAnimationFrame(tick);
+ };
+ raf = requestAnimationFrame(tick);
+ return () => cancelAnimationFrame(raf);
+ }, [sync]);
+
+ useEffect(() => { dialog.current?.focus({ preventScroll: true }); }, []);
+
+ const message = hud.phase === "ready" ? t("society.office.arcade_start")
+ : hud.phase === "paused" ? t("society.office.arcade_paused")
+ : hud.phase === "over" ? t("society.office.arcade_over").replace("{0}", String(hud.score))
+ : null;
+
+ return (
+ <div className="office-arcade-backdrop" data-office-ui onPointerDown={(event) => { if (event.target === event.currentTarget) onClose(); }}>
+ <div ref={dialog} className="office-card office-arcade" role="dialog" data-state="open" aria-modal="true"
+ aria-label={t("society.office.arcade_title")} tabIndex={-1}>
+ <header className="office-arcade-head">
+ <h2>{t("society.office.arcade_title")}</h2>
+ <button type="button" className="office-icon-button" onClick={onClose} aria-label={t("society.office.close")}>×</button>
+ </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_lives")} <b>{hud.lives}</b></span>
+ <span>{t("society.office.arcade_best")} <b>{best}</b></span>
+ </div>
+ <div className="office-arcade-screen">
+ <canvas ref={canvas} width={ARCADE_W * SCALE} height={ARCADE_H * SCALE} aria-hidden />
+ {message && (
+ <button type="button" className="office-arcade-message" onClick={startOrResume}>{message}</button>
+ )}
+ </div>
+ <p className="office-hint office-arcade-keys">{t("society.office.arcade_keys")}</p>
+ </div>
+ </div>
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx b/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx
index 86d10b1e1e..48fd3bedb4 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx
@@ -24,6 +24,9 @@ export const PLAYER_SPRINT_SPEED = 4.4;
/** Talk range to an agent, in metres. */
export const AGENT_TALK_RANGE = 1.8;
+/** Play range around the spot in front of an arcade screen, in metres. */
+export const ARCADE_PLAY_RANGE = 0.9;
+
const MOVE_KEYS: Record<string, [number, number]> = {
KeyW: [0, 1], ArrowUp: [0, 1], KeyS: [0, -1], ArrowDown: [0, -1],
KeyA: [-1, 0], ArrowLeft: [-1, 0], KeyD: [1, 0], ArrowRight: [1, 0],
@@ -88,6 +91,13 @@ function nearestInteractable(layout: OfficeLayout): Selection | null {
const d = Math.hypot(p.x - player.x, p.z - player.z);
if (d <= AGENT_TALK_RANGE && d < bestDistance) { best = { kind: "agent", id }; bestDistance = d; }
}
+ for (const item of layout.furniture) {
+ if (item.kind !== "arcade") continue;
+ // The cabinet's screen faces its local +z; you play standing in front of it.
+ const fx = item.x + Math.sin(item.rotationY) * 0.85, fz = item.z + Math.cos(item.rotationY) * 0.85;
+ const d = Math.hypot(fx - player.x, fz - player.z);
+ if (d <= ARCADE_PLAY_RANGE && d < bestDistance) { best = { kind: "arcade", id: item.id }; bestDistance = d; }
+ }
return best;
}
diff --git a/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx b/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx
index 0583aa0d49..09672216c2 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx
@@ -27,6 +27,7 @@ import { loadProfile, playerLook, saveProfile, type PlayerProfile } from "./play
import { AgentPanel, CheckpointPanel, type OfficeActions } from "./OfficePanels";
import type { WalkerContext } from "./OfficeAgents";
import { ownsKeyboard } from "./OfficePlayer";
+import { ArcadeCabinet } from "./ArcadeCabinet";
import "./office.css";
import "./officeHud.css";
import "./officeMinimap.css";
@@ -187,7 +188,9 @@ export function OfficeStage({ onOpenLedger, onSelectAgent, onCreateAgent, onOpen
const nearbyLabel = nearby
? nearby.kind === "agent"
? t("society.office.prompt_agent").replace("{0}", agents.get(nearby.id)?.name ?? "")
- : t(`society.office.cp_${nearby.id}_hint`)
+ : nearby.kind === "arcade"
+ ? t("society.office.arcade_prompt")
+ : t(`society.office.cp_${nearby.id}_hint`)
: null;
const playerName = profile.name.trim() || t("society.office.you");
@@ -232,7 +235,8 @@ export function OfficeStage({ onOpenLedger, onSelectAgent, onCreateAgent, onOpen
<button type="button" className="office-button" onClick={onOpenLedger}>{t("society.office.ledger")}</button>
</div>
- {selection && (
+ {selection?.kind === "arcade" && <ArcadeCabinet onClose={() => select(null)} />}
+ {selection && selection.kind !== "arcade" && (
<div className="office-panel-slot">
{selection.kind === "agent" && selectedAgent && (
<AgentPanel agent={selectedAgent} actions={actions} onClose={() => select(null)} />
diff --git a/jarvis/ui/web/frontend/src/components/society/office/arcade.css b/jarvis/ui/web/frontend/src/components/society/office/arcade.css
new file mode 100644
index 0000000000..1060a3b082
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/office/arcade.css
@@ -0,0 +1,14 @@
+/* The playable break-room arcade (ArcadeCabinet). The playfield is a lit
+ screen and stays dark in both themes; the frame around it follows the theme. */
+.office-arcade-backdrop { position:absolute; inset:0; z-index:70; display:flex; align-items:center; justify-content:center; padding:16px; background:hsl(var(--background) / .55); }
+.office-arcade { display:flex; flex-direction:column; gap:8px; width:min(520px, 100%); max-height:100%; padding:10px 14px 12px; overflow:auto; }
+.office-arcade:focus { outline:none; }
+.office-arcade-head { display:flex; align-items:center; justify-content:space-between; gap:8px; }
+.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-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
new file mode 100644
index 0000000000..3799ec9c41
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.test.ts
@@ -0,0 +1,71 @@
+import { describe, expect, it } from "vitest";
+import { ARCADE_SHIP_Y, ARCADE_W, invaderPos, newArcade, stepArcade, swarmInterval, type ArcadeInput } 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);
+};
+
+describe("arcade game", () => {
+ it("does nothing until started", () => {
+ const s = newArcade();
+ run(s, { ...idle, right: true }, 1);
+ expect(s.shipX).toBe(ARCADE_W / 2);
+ });
+
+ it("moves the ship and keeps it on screen", () => {
+ const s = newArcade();
+ s.phase = "playing";
+ run(s, { ...idle, left: true }, 5);
+ expect(s.shipX).toBe(10);
+ });
+
+ 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("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 }];
+ stepArcade(s, idle, 0.001);
+ expect(s.lives).toBe(2);
+ expect(s.hitTimer).toBeGreaterThan(0);
+ s.lives = 1;
+ s.hitTimer = 0;
+ s.bombs = [{ x: s.shipX, y: ARCADE_SHIP_Y }];
+ 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;
+ stepArcade(s, idle, 0.001);
+ expect(s.wave).toBe(2);
+ expect(s.invaders.every((inv) => inv.alive)).toBe(true);
+ });
+
+ it("ends the game when the swarm reaches the ship", () => {
+ const s = newArcade();
+ s.phase = "playing";
+ s.swarmY = ARCADE_SHIP_Y;
+ stepArcade(s, idle, 0.001);
+ expect(s.phase).toBe("over");
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.ts b/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.ts
new file mode 100644
index 0000000000..7d328805f4
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/office/arcadeGame.ts
@@ -0,0 +1,200 @@
+/**
+ * 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.
+ */
+
+/** 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;
+
+export type ArcadePhase = "ready" | "playing" | "paused" | "over";
+
+export interface Invader { col: number; row: number; alive: boolean }
+export interface Shot { x: number; y: number }
+
+export interface ArcadeState {
+ phase: ArcadePhase;
+ 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;
+}
+
+export interface ArcadeInput { left: boolean; right: 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;
+}
+
+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,
+ };
+ 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 aliveCount(state: ArcadeState): number {
+ let n = 0;
+ for (const inv of state.invaders) if (inv.alive) n += 1;
+ return n;
+}
+
+/** 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));
+}
+
+/** 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;
+
+ if (state.hitTimer > 0) {
+ state.hitTimer = Math.max(0, state.hitTimer - dt);
+ return;
+ }
+
+ // 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;
+ }
+
+ // 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;
+ }
+ }
+
+ // 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;
+ }
+ }
+ }
+
+ // 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);
+ }
+ 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;
+ }
+
+ // 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;
+ }
+ }
+
+ if (aliveCount(state) === 0) spawnWave(state, state.wave + 1);
+}
+
+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;
+ }
+}
+
+export const ARCADE_SHIP_Y = SHIP_Y;
diff --git a/jarvis/ui/web/frontend/src/components/society/office/officeStore.ts b/jarvis/ui/web/frontend/src/components/society/office/officeStore.ts
index e0ff22c740..5afc2ed4e2 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/officeStore.ts
+++ b/jarvis/ui/web/frontend/src/components/society/office/officeStore.ts
@@ -8,7 +8,8 @@
import { create } from "zustand";
import type { CheckpointKind, Point } from "./officeLayout";
-export type Selection = { kind: "agent"; id: string } | { kind: "checkpoint"; id: CheckpointKind };
+/** `arcade` is a playable arcade cabinet, by furniture id. */
+export type Selection = { kind: "agent"; id: string } | { kind: "checkpoint"; id: CheckpointKind } | { kind: "arcade"; id: string };
export interface PlayerBody { x: number; z: number; heading: number; path: Point[]; moving: boolean }
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 ba77e88e5f..2f37a30a8a 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/de.json
@@ -781,6 +781,16 @@
"cp_lead_hint": "Mit deinem Chef-Agenten sprechen",
"cp_break": "Pausenraum",
"cp_break_hint": "Kaffeepause ausrufen",
+ "arcade_prompt": "Am Automaten zocken",
+ "arcade_title": "Automat im Pausenraum",
+ "arcade_score": "Punkte",
+ "arcade_wave": "Welle",
+ "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",
"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 02aa42b039..1d0d440a34 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/en.json
@@ -781,6 +781,16 @@
"cp_lead_hint": "Talk to your lead agent",
"cp_break": "Break room",
"cp_break_hint": "Call a coffee break",
+ "arcade_prompt": "Play the arcade",
+ "arcade_title": "Break-room arcade",
+ "arcade_score": "Score",
+ "arcade_wave": "Wave",
+ "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",
"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 d59f0012e7..809f70b41c 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/es.json
@@ -781,6 +781,16 @@
"cp_lead_hint": "Hablar con tu agente líder",
"cp_break": "Sala de descanso",
"cp_break_hint": "Hacer una pausa de café",
+ "arcade_prompt": "Jugar a la máquina",
+ "arcade_title": "Máquina recreativa",
+ "arcade_score": "Puntos",
+ "arcade_wave": "Oleada",
+ "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",
"room_lead": "Despacho del líder",
"room_team": "Sala de equipos",
"room_wardrobe": "Vestuario",