// All mutable game state in one place, plus the point-reset that re-arms it. import { HOME } from './config.js'; export const P = { x: 1.3, z: 22.8, side: 'P', pose: 'idle', poseT: 0, swingT: -1, facing: 1, runT: 0 }; export const O = { x: -1.3, z: 1.0, side: 'O', pose: 'idle', poseT: 0, swingT: -1, facing: 1, runT: 0 }; export const ball = { x: 0, y: 1, z: 20, vx: 0, vy: 0, vz: 0, g: 9.2, active: false, lastHit: 'P', bounces: 0, firstLand: null, collected: false, kills: 0, bomb: false, flame: false }; export const score = { pts: [0, 0], games: [0, 0], server: 'P' }; // pts index 0=P 1=O export const crowd = { cheer: 0, dots: [] }; // dots are (re)built by render.buildCrowd // everything that used to be loose top-level lets export const G = { mode: 'tennis', // tennis | transition | splatter transT: 0, // transition timeline clock tFlags: null, // one-shot markers within the transition hideO: false, // the opponent has... left the match everTransitioned: false, phase: 'pretoss', // pretoss | toss | rally | over serveNum: 1, overT: 0, hitstop: 0, flash: null, // {text, t} shake: null, // {t, mag} — camera shake, decays like flash (bomb impact) boomFlash: 0, // s of white flash frame left (bomb impact) lastOrderT: -9, // idleT of the last 'Order' call — bomb chains mustn't spam the umpire idleT: 0, outMarker: null, // {x, z, out, t} — where your last shot lands boy: null, // ball boy sprinting across: {x, z, dir, runT} aiServeT: 0, aiSwingCool: 0, aiReactT: 9, // time since the player's last hit; CPU reads the shot after TUNE.aiReaction wasServe: false, // the ball in flight is a serve (first bounce must hit the box) splatT: 0, // time survived in splatter mode — drives the difficulty ramp bombs: 0, // bomb-ball stock; the next serve auto-consumes one (delivery 1 of the ladder) triples: 0, // triple-serve stock — a serve fans into three balls (delivery 2) flames: 0, // flame-ball stock — kills on any touch, full pierce (delivery 3) mgT: 0, // s of machine-gun time left (delivery 4) — auto-fire, no serving mgCool: 0, // s until the next pickup-mode pellet deliveries: 0, // tins delivered this run — indexes the weapon ladder tinDue: false, // the rules called for new balls — deliver at the next changeover pendingGame: false, // a game just ended — flash 'GAME N' when the next one arms aim: null, // live two-stage serve aim {fx, fy, mag} while the thumb is down (splatter pretoss) interlude: false, // sudden-death duel vs the racket zombie: falsy, or {introT} while announcing duelLerp: 0, // 0..1 — how far the court has returned to tennis colors for the duel horde: null, // active horde wave {t, spawnT, mgT} — machine-gun racket, no serving runGames: 0, // games finished this run (either side) — the difficulty director sets: [0, 0], // splatter sets won [you, them]; 6 games = a set = a horde changeover: false, // the odd-game breather: no spawns, no serving, the boys mop shameGame: false, // they took a game — the next new-balls delivery is withheld best: null, // best run {games, sets}, loaded from localStorage when you get eaten lastScoreT: -9, // idleT of the last score voice — rate-limits umpire during a horde eatenT: 0, // time since you were eaten — gates the restart tap missLog: [], // swing diagnostics ring buffer (tennis mode) — inspect via T.G.missLog swingSnaps: null, // ball-approach samples during the live swing, feeds the miss log rallyNear: null, // closest the incoming ball got this rally (for never-swung passes) swung: false, // player swung at least once this rally — whiff log supersedes PASSED lastMiss: null, // {text, at} — most recent miss reason, drawn on the HUD briefly logShow: false, // tap the scoreboard to toggle the on-screen miss-log dump }; export const other = s => s === 'P' ? 'O' : 'P'; export const deuceSide = () => (score.pts[0] + score.pts[1]) % 2 === 0; // even points → deuce (right) side export function setupPoint() { G.phase = 'pretoss'; ball.active = false; ball.bounces = 0; ball.firstLand = null; G.swingSnaps = null; G.rallyNear = null; G.swung = false; if (G.mode === 'splatter') { // always your serve, from wherever you're standing score.server = 'P'; P.pose = 'idle'; P.swingT = -1; P.facing = 1; return; } const sv = score.server === 'P' ? P : O, rc = score.server === 'P' ? O : P; const sx = deuceSide() ? 1.3 : -1.3; sv.x = sv.side === 'P' ? sx : -sx; // deuce side mirrors across the net sv.z = sv.side === 'P' ? 24.3 : -0.5; rc.x = -sv.x; rc.z = rc.side === 'P' ? 22.5 : HOME.O.z - 1.3; P.pose = O.pose = 'idle'; P.swingT = O.swingT = -1; P.facing = O.facing = 1; // canonical righty stance — bounce/serve sprites must not render mirrored G.aiServeT = score.server === 'O' ? 1.4 : 0; } export function sendBoy(tx = ball.x, tz = ball.z) { // fetch a dead ball — or mop a splat if (tz < -3 || tz > 27) return; // target left the field lengthwise, let it go const dir = tx > 0 ? 1 : -1; // enter from the opposite side so the pickup is mid-run G.boy = { x: dir > 0 ? -13 : 13, z: tz, dir, runT: 0 }; }