From 8afbf00805c426d2bbf94d5c3d4cc2cee407c185 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Sun, 11 Oct 2026 22:28:10 -0400 Subject: [PATCH] feat(minigames): add procedural SFX and hit explosions to the versus duel Sound is synthesized with the Web Audio API (no new assets): a launch thump on fire, noise-burst impacts (splash for a miss, a bigger double boom for a destroyed emplacement), a chime when the turn passes to you, and victory/defeat fanfares. A mute button and volume slider live in the match header; the setting persists per browser (polaris:call-for-fire-versus-sound). Adds a one-shot explosion VFX on hit and destroyed cells on both boards (larger burst for a destroyed emplacement), suppressed under prefers-reduced-motion. Only shots that arrive while watching animate, so loading a match does not replay every past hit. --- src/app/(frontend)/styles.css | 58 +++++ .../call-for-fire-versus/VersusMatch.tsx | 92 ++++++-- .../VersusSoundToggle.tsx | 41 ++++ .../call-for-fire-versus/useVersusSounds.ts | 196 ++++++++++++++++ .../call-for-fire-versus/versusSound.ts | 217 ++++++++++++++++++ 5 files changed, 587 insertions(+), 17 deletions(-) create mode 100644 src/components/frontend/minigames/call-for-fire-versus/VersusSoundToggle.tsx create mode 100644 src/components/frontend/minigames/call-for-fire-versus/useVersusSounds.ts create mode 100644 src/components/frontend/minigames/call-for-fire-versus/versusSound.ts diff --git a/src/app/(frontend)/styles.css b/src/app/(frontend)/styles.css index dba99a23..cbabe194 100644 --- a/src/app/(frontend)/styles.css +++ b/src/app/(frontend)/styles.css @@ -1943,6 +1943,64 @@ accent-color: var(--poker-trim); } +/* Call for Fire: Versus */ +.versus-sound-toggle { + display: flex; + align-items: center; + gap: 0.4rem; +} + +.versus-sound-volume { + width: 4.5rem; + accent-color: #f59e0b; +} + +.versus-explosion { + position: absolute; + inset: -25%; + z-index: 2; + border-radius: 9999px; + pointer-events: none; + background: radial-gradient( + circle, + rgba(254, 240, 138, 0.95) 0%, + rgba(249, 115, 22, 0.85) 42%, + rgba(239, 68, 68, 0) 72% + ); + animation: versus-explosion 650ms ease-out both; +} + +.versus-explosion-destroyed { + background: radial-gradient( + circle, + #ffffff 0%, + rgba(248, 113, 113, 0.95) 38%, + rgba(185, 28, 28, 0) 74% + ); +} + +@keyframes versus-explosion { + 0% { + opacity: 0; + transform: scale(0.3); + } + 25% { + opacity: 1; + transform: scale(0.85); + } + 100% { + opacity: 0; + transform: scale(1.9); + } +} + +@media (prefers-reduced-motion: reduce) { + .versus-explosion { + animation: none; + opacity: 0; + } +} + .poker-action-console:not(.poker-action-console-complete) { grid-template-columns: minmax(0, 1.5fr) minmax(10rem, 0.8fr); } diff --git a/src/components/frontend/minigames/call-for-fire-versus/VersusMatch.tsx b/src/components/frontend/minigames/call-for-fire-versus/VersusMatch.tsx index 3e989c14..a6667a26 100644 --- a/src/components/frontend/minigames/call-for-fire-versus/VersusMatch.tsx +++ b/src/components/frontend/minigames/call-for-fire-versus/VersusMatch.tsx @@ -1,6 +1,6 @@ "use client"; -import { useCallback, useEffect, useMemo, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { Crosshair, Clock, RotateCcw, Shuffle, Target, Trophy, Users } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -21,6 +21,8 @@ import { import { cellsForFob } from "@/lib/minigames/call-for-fire-versus/engine"; import type { VersusFobView, VersusShotView } from "@/lib/minigames/call-for-fire-versus/types"; import { cn } from "@/lib/utils"; +import { VersusSoundToggle } from "./VersusSoundToggle"; +import { useVersusSounds } from "./useVersusSounds"; const BOARD = 10; const CORRECTION_STEP = 50; @@ -103,10 +105,12 @@ function PlacementPhase({ match, onMatch, waiting, + onUi, }: { match: VersusMatchView; onMatch: (next: VersusMatchView) => void; waiting: boolean; + onUi: () => void; }) { const [placements, setPlacements] = useState>(() => { const initial: Record = {}; @@ -188,10 +192,11 @@ function PlacementPhase({ ...current, [selectedId]: { assetId: selectedId, origin, orientation: placeOrientation }, })); + onUi(); const nextUnplaced = FOB_FLEET.find((f) => f.id !== selectedId && !placements[f.id]); if (nextUnplaced) setSelectedId(nextUnplaced.id); }, - [occupied, orientation, placements, selectedId], + [occupied, onUi, orientation, placements, selectedId], ); /** Double-click a placed line emplacement to flip its orientation in place. */ @@ -228,8 +233,9 @@ function PlacementPhase({ ...current, [assetId]: { ...placement, orientation: nextOrientation }, })); + onUi(); }, - [placements], + [onUi, placements], ); const allPlaced = FOB_FLEET.every((definition) => placements[definition.id]); @@ -287,6 +293,7 @@ function PlacementPhase({ onClick={() => { setPlacements(randomFleet()); setError(null); + onUi(); }} > Auto-deploy @@ -457,10 +464,10 @@ function buildBoards(you: VersusMatchView["you"]) { for (const fob of you.fleet) { for (const cell of fob.cells) myCells.set(key(cell), fob); } - const incoming = new Map(); - for (const shot of you.incoming) incoming.set(key(shot.grid), shot); - const myShots = new Map(); - for (const shot of you.shots) myShots.set(key(shot.grid), shot); + const incoming = new Map(); + you.incoming.forEach((shot, index) => incoming.set(key(shot.grid), { shot, index })); + const myShots = new Map(); + you.shots.forEach((shot, index) => myShots.set(key(shot.grid), { shot, index })); return { myCells, incoming, myShots }; } @@ -468,10 +475,12 @@ function BattlePhase({ match, currentUserId, onMatch, + onFire, }: { match: VersusMatchView; currentUserId: number | string; onMatch: (next: VersusMatchView) => void; + onFire: () => void; }) { const you = match.you; const now = useNow(); @@ -484,6 +493,12 @@ function BattlePhase({ const yourTurn = match.turnUserId !== null && String(match.turnUserId) === String(currentUserId); const boards = buildBoards(you); const firstShot = you.lastImpact === null; + // Only animate explosions for shots that arrive while watching (not those + // already on the board when the page loaded). + const initialIncomingRef = useRef(null); + if (initialIncomingRef.current === null) initialIncomingRef.current = you.incoming.length; + const initialOutgoingRef = useRef(null); + if (initialOutgoingRef.current === null) initialOutgoingRef.current = you.shots.length; const secondsLeft = match.turnDeadline === null @@ -507,6 +522,7 @@ function BattlePhase({ setBusy(false); if (result.success && result.data) { onMatch(result.data); + onFire(); setPendingGrid(null); setRangeM(0); setDeflectionM(0); @@ -517,6 +533,7 @@ function BattlePhase({ deflectionM, firstShot, match.matchId, + onFire, onMatch, pendingGrid, rangeM, @@ -576,13 +593,25 @@ function BattlePhase({ {hit && ( - {hit.outcome === "miss" ? "•" : "✕"} + {hit.shot.outcome === "miss" ? "•" : "✕"} )} + {hit && + hit.shot.outcome !== "miss" && + initialIncomingRef.current !== null && + hit.index >= initialIncomingRef.current && ( +