diff --git a/src/components/frontend/minigames/bomperator/BomperatorGame.tsx b/src/components/frontend/minigames/bomperator/BomperatorGame.tsx index 25efa843..ae5b44b5 100644 --- a/src/components/frontend/minigames/bomperator/BomperatorGame.tsx +++ b/src/components/frontend/minigames/bomperator/BomperatorGame.tsx @@ -5,7 +5,7 @@ import { Eye, Flag, Play, Radio, Users } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import type { BomperatorView, Dir, PlayerView } from "@/lib/minigames/bomperator/types"; -import { BOMB_FUSE_TICKS, GRID_H, GRID_W, MAX_SEATS, MIN_TO_START, TICK_MS, TICKS_PER_SECOND } from "@/lib/minigames/bomperator/constants"; +import { BOMB_FUSE_TICKS, FLAME_LIFETIME_TICKS, GRID_H, GRID_W, MAX_SEATS, MIN_TO_START, TICK_MS, TICKS_PER_SECOND } from "@/lib/minigames/bomperator/constants"; import { sendBomperatorInput } from "@/app/(frontend)/minigames/bomperator/actions"; import { BomperatorHud, seatColor } from "./BomperatorHud"; import { useBomperatorSounds } from "./sounds"; @@ -269,8 +269,8 @@ function drawBomb(ctx: CanvasRenderingContext2D, x: number, y: number, fuseTicks ctx.strokeStyle = "#475569"; ctx.lineWidth = 1.5; ctx.stroke(); - // Blinking spark: faster as the fuse burns down. - const blink = fuseTicks <= 6 ? Math.floor(t / 90) % 2 === 0 : Math.floor(t / 260) % 2 === 0; + // Blinking spark: faster over the last quarter of the fuse. + const blink = fuseTicks <= BOMB_FUSE_TICKS / 4 ? Math.floor(t / 90) % 2 === 0 : Math.floor(t / 260) % 2 === 0; if (blink) { ctx.fillStyle = "#fbbf24"; ctx.beginPath(); @@ -283,7 +283,7 @@ function drawFlame(ctx: CanvasRenderingContext2D, x: number, y: number, ticksLef const px = x * CELL; const py = y * CELL; const flicker = 0.55 + 0.35 * Math.abs(Math.sin(t / 80 + x * 2 + y)); - ctx.globalAlpha = Math.min(1, ticksLeft / 3 + 0.2) * flicker; + ctx.globalAlpha = Math.min(1, ticksLeft / FLAME_LIFETIME_TICKS + 0.2) * flicker; const grad = ctx.createRadialGradient(px + CELL / 2, py + CELL / 2, 2, px + CELL / 2, py + CELL / 2, CELL * 0.7); grad.addColorStop(0, "#fde68a"); grad.addColorStop(0.5, "#fb923c"); diff --git a/src/lib/minigames/AGENTS.md b/src/lib/minigames/AGENTS.md index 75a0fbae..515f8a62 100644 --- a/src/lib/minigames/AGENTS.md +++ b/src/lib/minigames/AGENTS.md @@ -10,7 +10,7 @@ Five XP-earning minigames under one parent: routes live at `/minigames/*` (moved - **Flight Simulator**: `/minigames/flappy` (canvas game + leaderboard). **Minefield Clearance (EOD)**: `/minigames/eod`. **OPORD Recall**: `/minigames/opord` (`src/lib/minigames/opord-recall.ts`). - **Call for Fire (artillery observer)**: `/minigames/call-for-fire`, game rules in `src/lib/minigames/call-for-fire.ts` (patrol/checkpoint/compound difficulties, compass bearing observer reports, ADD/DROP + RIGHT/LEFT corrections, scoring/accuracy/XP, injected rng, pure). Components: `src/components/frontend/minigames/call-for-fire/` (`CallForFireArena`, `FireMissionBoard`, `CallForFireLeaderboard`). Action `submitCallForFireResult` validates result bounds, updates profile stats, awards XP + chips, emits `minigame:call-for-fire`, and records the ledger entry (accuracy is distance-to-target on a win, null on a loss). - **Call for Fire: Versus (multiplayer)**: `/minigames/call-for-fire-versus`, category `multiplayer` (out of periods). Pure engine in `src/lib/minigames/call-for-fire-versus/` (`engine.ts`, `views.ts`, `types.ts`, `constants.ts`; client-safe) plus a server-only in-memory match registry in `registry.ts` (mirrors `blackjack/tables.ts`: `globalThis`-anchored Map, lobby, per-turn timeout, expiry sweep, SINGLE-INSTANCE ONLY). Each player hides a FOB fleet, then alternates fire corrections (first shot is a grid designation, later shots adjust from the last impact). `views.ts` builds per-viewer snapshots that never serialize the opponent's fleet. Client polls `fetchVersusMatch` (the in-memory SSE bus is unreliable across dev module copies, same as blackjack). Rewards on completion via `stats.ts` (`minigame:call-for-fire-versus`, profile group `callForFireVersus`). -- **Ordnance Disposal (multiplayer, real-time)**: `/minigames/bomperator` (internal key `bomperator`, label "Ordnance Disposal"), category `multiplayer` (out of periods), a 2-8 player free-for-all Bomberman-style charge-clearing drill. Same pure-engine + in-memory-registry split as CFF versus, but upgraded from turn-based to a **fixed ~10 Hz tick loop**: `src/lib/minigames/bomperator/{constants,types,engine,views}.ts` are pure/client-safe (seeded RNG via `state.rngState`/`gridSeed`; `generateGrid`, `createMatchState`, `startRound`, `applyInput`, `tick`), and `registry.ts` runs one `setInterval(TICK_MS)` per live match (started on `startMatch`, cleared on complete/dissolve; `globalThis.__bomperatorMatches`; SINGLE-INSTANCE ONLY: a restart/redeploy kills live matches). Grid is 15x13 (border + even/even pillars + seeded crates with one hidden power-up each; four classic pickups bomb/range/speed/kick). Movement is grid-locked with sub-cell interpolation; charges fuse ~2.5s, cross-flames stop at walls, destroy crates, chain-detonate, and kick-push; round ends at <=1 alive; sudden death spawns random-cell explosions after the 150s timer, with a draw guard. FFA has no hidden info so `buildBomperatorView` serves every viewer the same board (`yourSeat: null` = spectator). Clients POST inputs (`sendBomperatorInput`, rate-limited 20/s) and poll `fetchBomperatorMatch` (~150ms); a rolling event buffer (monotonic ids) drives client SFX without diffing. Disconnects hold the seat for `RECONNECT_WINDOW_MS` then eliminate; below two active seats the match dissolves. Rewards on completion via `stats.ts` (`minigame:bomperator`, profile group `bomperator`: matchesPlayed/matchWins/roundsWon/kills/xpEarned; XP win/loss base + per-kill bounty, chips auto-derived). Registry row ships `status: "upcoming"` (page renders `MinigameComingSoon` until an admin flips it active). +- **Ordnance Disposal (multiplayer, real-time)**: `/minigames/bomperator` (internal key `bomperator`, label "Ordnance Disposal"), category `multiplayer` (out of periods), a 2-8 player free-for-all Bomberman-style charge-clearing drill. Same pure-engine + in-memory-registry split as CFF versus, but upgraded from turn-based to a **fixed ~20 Hz tick loop** (was ~10 Hz until v0.12.3; every tick-denominated constant doubles with the rate so real-world durations stay identical): `src/lib/minigames/bomperator/{constants,types,engine,views}.ts` are pure/client-safe (seeded RNG via `state.rngState`/`gridSeed`; `generateGrid`, `createMatchState`, `startRound`, `applyInput`, `tick`), and `registry.ts` runs one `setInterval(TICK_MS)` per live match (started on `startMatch`, cleared on complete/dissolve; `globalThis.__bomperatorMatches`; SINGLE-INSTANCE ONLY: a restart/redeploy kills live matches). Grid is 15x13 (border + even/even pillars + seeded crates with one hidden power-up each; four classic pickups bomb/range/speed/kick). Movement is grid-locked with sub-cell interpolation; charges fuse ~2.5s, cross-flames stop at walls, destroy crates, chain-detonate, and kick-push; round ends at <=1 alive; sudden death spawns random-cell explosions after the 150s timer, with a draw guard. FFA has no hidden info so `buildBomperatorView` serves every viewer the same board (`yourSeat: null` = spectator). Clients POST inputs (`sendBomperatorInput`, rate-limited 40/s) and poll `fetchBomperatorMatch` (~500ms fallback behind the SSE stream); a rolling event buffer (monotonic ids) drives client SFX without diffing. Disconnects hold the seat for `RECONNECT_WINDOW_MS` then eliminate; below two active seats the match dissolves. Rewards on completion via `stats.ts` (`minigame:bomperator`, profile group `bomperator`: matchesPlayed/matchWins/roundsWon/kills/xpEarned; XP win/loss base + per-kill bounty, chips auto-derived). Registry row ships `status: "upcoming"` (page renders `MinigameComingSoon` until an admin flips it active). - Leaderboards match active players by user id (not display name) — see commit 72715c4 if leaderboard queries look wrong. ## Periods, achievements & the game registry diff --git a/src/lib/minigames/bomperator/constants.ts b/src/lib/minigames/bomperator/constants.ts index fbf484f6..c17c126e 100644 --- a/src/lib/minigames/bomperator/constants.ts +++ b/src/lib/minigames/bomperator/constants.ts @@ -9,8 +9,9 @@ /* ------------------------------------------------------------------ timing */ -/** Fixed simulation tick. ~10 Hz server-authoritative loop. */ -export const TICK_MS = 100; +/** Fixed simulation tick. ~20 Hz server-authoritative loop (100ms pre-v0.12.3; + * halved to freshen every snapshot-bound surface: opponents, explosions, drops). */ +export const TICK_MS = 50; /** Ticks per second, derived from TICK_MS. */ export const TICKS_PER_SECOND = Math.round(1000 / TICK_MS); @@ -26,10 +27,10 @@ export const CRATE_DENSITY = 0.4; /* ------------------------------------------------------------------- bombs */ -/** Fuse length in ticks (~2.5s at 10 Hz). */ -export const BOMB_FUSE_TICKS = 25; -/** How long a flame cell lingers after an explosion (ticks). */ -export const FLAME_LIFETIME_TICKS = 3; +/** Fuse length in ticks (~2.5s at 20 Hz). */ +export const BOMB_FUSE_TICKS = 50; +/** How long a flame cell lingers after an explosion (ticks, ~0.3s at 20 Hz). */ +export const FLAME_LIFETIME_TICKS = 6; /** Starting loadout every technician begins each round with. */ export const START_BOMBS = 1; @@ -59,14 +60,14 @@ export const POWERUP_WEIGHTS: Record<"bomb" | "range" | "speed" | "kick", number export const ROUND_TIMER_S = 150; export const ROUND_TIMER_TICKS = ROUND_TIMER_S * TICKS_PER_SECOND; /** In sudden death, spawn a random-cell explosion every N ticks (~4s). */ -export const SUDDEN_DEATH_INTERVAL_TICKS = 40; +export const SUDDEN_DEATH_INTERVAL_TICKS = 80; /** Countdown between rounds (seconds). */ export const INTER_ROUND_COUNTDOWN_S = 3; export const INTER_ROUND_COUNTDOWN_TICKS = INTER_ROUND_COUNTDOWN_S * TICKS_PER_SECOND; /** Brief result hold at the end of a round before the next countdown. */ export const ROUND_END_HOLD_TICKS = 3 * TICKS_PER_SECOND; -/** Spawn protection so nobody dies the instant a round opens (ticks). */ -export const SPAWN_INVULNERABLE_TICKS = 10; +/** Spawn protection so nobody dies the instant a round opens (ticks, ~1s at 20 Hz). */ +export const SPAWN_INVULNERABLE_TICKS = 20; /** * Draw guard: if sudden death runs this many explosions without reducing the * field to one technician, the round is called a draw rather than looping. diff --git a/src/lib/minigames/bomperator/engine.ts b/src/lib/minigames/bomperator/engine.ts index 76420480..aa35bc66 100644 --- a/src/lib/minigames/bomperator/engine.ts +++ b/src/lib/minigames/bomperator/engine.ts @@ -435,7 +435,11 @@ function advancePlayer( function approach(current: number, target: number, step: number): number { const delta = target - current; - if (Math.abs(delta) <= step) return target; + // EPS tolerance: multi-tick glides accrue float dust (e.g. 5.3 + 0.35 = + // 5.6499999999999995), so the final step can land a hair past `step` from the + // target; without this the player stops within 1e-15 of the center without + // ever reaching it exactly. + if (Math.abs(delta) <= step + 1e-6) return target; return current + Math.sign(delta) * step; } @@ -633,8 +637,15 @@ function tickBattle(state: BomperatorState): BomperatorState { if (!dir) continue; const cellsPerTick = (p.speed * TICK_MS) / 1000; const res = advancePlayer(state, { ...p, inputDir: dir }, ctx.bombs, cellsPerTick); - p.x = res.x; - p.y = res.y; + if (isCellCentered(res.x, res.y)) { + // Resting on a whole cell keeps bomb/flame rounding exact: snap away any + // sub-EPS float residue accumulated over a multi-tick glide. + p.x = Math.round(res.x); + p.y = Math.round(res.y); + } else { + p.x = res.x; + p.y = res.y; + } if (p.inputDir) p.dir = p.inputDir; if (res.pushedBombId && res.pushedTo) { ctx.bombs = ctx.bombs.map((b) => diff --git a/src/lib/minigames/bomperator/registry.ts b/src/lib/minigames/bomperator/registry.ts index e00e7197..736fe098 100644 --- a/src/lib/minigames/bomperator/registry.ts +++ b/src/lib/minigames/bomperator/registry.ts @@ -8,7 +8,7 @@ * and a server restart or redeploy ends any live match. * * The pure engine (./engine, ./views) never touches timers or I/O. This wrapper - * owns the fixed ~10 Hz tick loop, lobby membership, the disconnect/reconnect + * owns the fixed ~20 Hz tick loop, lobby membership, the disconnect/reconnect * window, completion rewards, and the idle-expiry sweep. Clients POST inputs and * poll snapshots; the in-memory SSE bus is used only for the profile-update nudge * after awards (it is unreliable across dev module copies, same as blackjack).