diff --git a/config.js b/config.js index accc7e7..591ee4e 100644 --- a/config.js +++ b/config.js @@ -27,6 +27,9 @@ export const TUNE = { bombEvery: 8, // splatter kills between bomb-ball rewards bombMax: 3, // bomb balls you can stock at once bombRadius: 2.5, // m blast radius of a bomb ball + hordeLen: 12, // s a horde wave lasts + hordeRate: 2.5, // zombies spawned per second during a horde + mgRate: 6, // machine-gun pellets fired per second during a horde missHud: 1, // show the last miss reason on screen (full log: T.G.missLog) }; diff --git a/gameplay.js b/gameplay.js index fc7a53c..7a7f36e 100644 --- a/gameplay.js +++ b/gameplay.js @@ -178,20 +178,32 @@ function pointTo(side, reason) { G.serveNum = 1; } -// splatter-mode scoring: points land mid-flight without interrupting play -export function splatPoint(side) { +// splatter-mode scoring: points land mid-flight without interrupting play. +// quiet (during a horde) rate-limits the umpire so he doesn't call every rapid-fire point. +export function splatPoint(side, quiet = false) { const gameOver = advancePoint(side); if (gameOver) { - voice(side === 'P' ? 'game_set_massacre' : 'game_opponent', 0.5); + voice(side === 'P' ? 'game_set_massacre' : 'game_opponent', 0.5); // game-win lines always speak cheer(2.2, 0.5); - } else { - voice(scoreKey(), 0.45); - if (side === 'P') cheer(0.7, 0.25); + if (side === 'P' && ++G.splatGames >= 2) startHorde(); // 2nd splatter game (and every one after): the horde + } else if (!quiet || G.idleT - G.lastScoreT > 2) { + voice(scoreKey(), 0.45); G.lastScoreT = G.idleT; + if (side === 'P' && !quiet) cheer(0.7, 0.25); } } -// hidden shortcut: tapping the umpire three times summons them early +// the swarm keeps coming: no serving, the racket auto-fires, the thumb drag steers you +function startHorde() { + if (G.horde) return; + G.horde = { t: TUNE.hordeLen, spawnT: 0, mgT: 0 }; + ball.active = false; G.phase = 'rally'; // ball gone; 'rally' lets the movement block steer P + voice('remain_seated', 0.3); + G.flash = { text: 'THEY KEEP COMING', t: 1.2 }; +} + +// hidden shortcut: tapping the umpire three times summons the horror early export function forceZombies() { + if (G.mode === 'splatter') { startHorde(); return; } // in splatter the cheat forces a horde wave if (G.mode !== 'tennis') return; ball.active = false; startTransition(); @@ -363,6 +375,7 @@ function trySwing(ch, isAI) { export function keyPressed(code) { if (code !== 'Space') return; audio(); // unlock on first gesture + if (G.horde) return; // horde: the racket auto-fires, taps do nothing — the thumb drag steers you // splatter: a tap/flick during the brief 'over' beat arms the next serve immediately — // reset inline, then fall through to pretoss so the finger is the only cadence limit if (G.mode === 'splatter' && G.phase === 'over') { ball.active = false; setupPoint(); } @@ -421,7 +434,7 @@ export function update(dt) { P.x += mx * TUNE.playerSpeed * slow * dt; P.z += mz * TUNE.playerSpeed * slow * dt; let assist = 0; - if (!mx && !mz && TUNE.autoAssist > 0 && ball.active) { + if (!mx && !mz && TUNE.autoAssist > 0 && ball.active && !G.horde) { // horde: you aim by hand, no assist const chasing = ball.lastHit === 'O'; // no `slow` here: tapping must not freeze your legs, or anticipating a shot loses it const rate = TUNE.playerSpeed * TUNE.autoAssist * dt * (chasing ? 1 : 0.55); diff --git a/main.js b/main.js index cc9983e..d35d239 100644 --- a/main.js +++ b/main.js @@ -8,7 +8,7 @@ import { P, O, ball, score, G, setupPoint } from './state.js'; import { update, keyPressed, solveShot, inServeBox, inCourt, forceZombies } from './gameplay.js'; import { fitViewport, render, proj } from './render.js'; import { voice } from './audio.js'; -import { zombies, spawnZombie, piles, gore, parts } from './zombies.js'; +import { zombies, spawnZombie, piles, gore, parts, pellets } from './zombies.js'; import { cv } from './dom.js'; import './input.js'; @@ -54,6 +54,6 @@ cv.addEventListener('pointerdown', e => { requestAnimationFrame(frame); // exposed for in-browser sanity checks and simulated playtests -window.T = { TUNE, ball, P, O, score, G, zombies, spawnZombie, piles, gore, parts, solveShot, inServeBox, inCourt, proj, setupPoint, +window.T = { TUNE, ball, P, O, score, G, zombies, spawnZombie, piles, gore, parts, pellets, solveShot, inServeBox, inCourt, proj, setupPoint, forceZombies, step: dt => update(dt), render, press: keyPressed, get phase() { return G.phase; }, set phase(v) { G.phase = v; } }; diff --git a/render.js b/render.js index 6397870..c2f1777 100644 --- a/render.js +++ b/render.js @@ -4,7 +4,7 @@ import { cv, ctx } from './dom.js'; import { TUNE, COURT, PLAYER_H, BOY_H, UMP_H, BOUNCE_IDLE, SPRITE_H } from './config.js'; import { P, O, ball, score, crowd, G } from './state.js'; import { predictLanding } from './gameplay.js'; -import { zombies, gore, piles, parts } from './zombies.js'; +import { zombies, gore, piles, parts, pellets } from './zombies.js'; // ---------------------------------------------------------------- palette ---- // tennis palette -> drained splatter palette; the transition lerps between them @@ -301,6 +301,12 @@ export function render() { ctx.fillStyle = pt.dark ? 'rgba(96,14,14,0.9)' : 'rgba(170,22,22,0.9)'; ctx.fillRect(pp.x | 0, pp.y | 0, 2, 2); } + // machine-gun pellets: flat tracers with a tiny ground shadow + for (const pe of pellets) { + const sh = proj(pe.x, 0, pe.z); drawShadow(sh.x, sh.y, Math.max(1, sh.s * 0.04), Math.max(1, sh.s * 0.02), 0.25); + const pp = proj(pe.x, pe.y, pe.z); + ctx.fillStyle = '#f8e048'; ctx.fillRect((pp.x | 0) - 1, (pp.y | 0) - 1, 2, 2); + } if (G.mode !== 'eaten') drawChar(P); // there is no P anymore // HUD — scoreboard @@ -327,7 +333,7 @@ export function render() { ctx.fillText('GAMES YOU ' + score.games[0] + ' — THEM ' + score.games[1], W / 2, H / 2); if (G.eatenT > 0.7) { ctx.fillStyle = '#f8e048'; ctx.font = 'bold 8px monospace'; ctx.fillText('TAP TO PLAY AGAIN', W / 2, H / 2 + 20); } } - if (G.phase === 'pretoss' && score.server === 'P' && G.mode !== 'eaten') { + if (G.phase === 'pretoss' && score.server === 'P' && G.mode !== 'eaten' && !G.horde) { ctx.fillStyle = '#f8e048'; ctx.font = 'bold 8px monospace'; const touch = matchMedia('(pointer: coarse)').matches; ctx.fillText(G.serveNum === 2 ? (touch ? 'SECOND SERVE — TAP' : 'SECOND SERVE — SPACE') diff --git a/state.js b/state.js index 406d5a5..f1d57c0 100644 --- a/state.js +++ b/state.js @@ -31,6 +31,9 @@ export const G = { splatT: 0, // time survived in splatter mode — drives the difficulty ramp bombs: 0, // bomb-ball stock (max TUNE.bombMax); the next serve auto-consumes one killMeter: 0, // splatter kills toward the next bomb reward (every TUNE.bombEvery) + horde: null, // active horde wave {t, spawnT, mgT} — machine-gun racket, no serving + splatGames: 0, // splatter games you've won; the 2nd (and every one after) launches a horde + 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 diff --git a/zombies.js b/zombies.js index 0b500c8..9c2fd30 100644 --- a/zombies.js +++ b/zombies.js @@ -4,7 +4,7 @@ // (zombies <-> gameplay is a runtime-only import cycle, same pattern as input.) import { TUNE, COURT } from './config.js'; -import { G, P, ball, sendBoy } from './state.js'; +import { G, P, ball, sendBoy, setupPoint } from './state.js'; import { splat, moan, pock, voice, boom } from './audio.js'; import { splatPoint, cheer } from './gameplay.js'; @@ -12,6 +12,7 @@ export const zombies = []; // {x, z, v, walkT, variant: 'a'|'b'|'c'} export const gore = []; // lawn decals {x, z, r, a} — the flat ground layer export const piles = []; // 3D-ish gore mounds {x, z, size 1..4, seed} — grow where kills cluster export const parts = []; // splatter particles {x, y, z, vx, vy, vz, t, dark} +export const pellets = []; // machine-gun rounds during a horde {x, y, z, vx, vz, t} let spawnT = 1.5, moanT = 3; @@ -20,10 +21,9 @@ export function spawnZombie(x, z, variant) { zombies.push({ x, z, v: TUNE.zSpeed * ramp * (0.8 + Math.random() * 0.4), walkT: Math.random() * 9, variant }); } -function splatter(i) { +function splatter(i, fanfare = true) { const zb = zombies[i]; zombies.splice(i, 1); - ball.kills++; // this shot's running streak gore.push({ x: zb.x, z: zb.z, r: 0.45 + Math.random() * 0.35, a: 0.85 }); if (gore.length > 40) gore.shift(); const pl = piles.find(p => Math.hypot(p.x - zb.x, p.z - zb.z) < 0.6); // stack up where kills cluster @@ -38,7 +38,9 @@ function splatter(i) { splat(); ball.vx *= TUNE.zPierce; ball.vz *= TUNE.zPierce; // keep enough pace to plow through the next sendBoy(zb.x, zb.z); // a boy sprints out to mop - splatPoint('P'); + splatPoint('P', !!G.horde); // horde kills rate-limit the umpire so he doesn't machine-gun scores + if (!fanfare) return; // machine-gun pellets splatter but skip the streak fanfare / bomb meter + ball.kills++; // this shot's running streak // escalating multi-kill fanfare — one shot, ≥2 zombies if (ball.kills === 2) { G.flash = { text: 'DOUBLE KILL', t: 0.9 }; cheer(1.6, 0.45); voice('double_kill', 0.4); } else if (ball.kills === 3) { G.flash = { text: 'TRIPLE KILL', t: 0.9 }; cheer(2.2, 0.6); voice('triple_kill', 0.4); } @@ -50,6 +52,29 @@ function splatter(i) { } } +// ---- horde wave: dense spawns + an auto-firing machine-gun racket (pellets, not the match ball) +function spawnHordeZombie() { + if (Math.random() < 0.5) spawnZombie((Math.random() * 2 - 1) * 5, -1.5 - Math.random(), Math.random() < 0.5 ? 'a' : 'b'); // far baseline + else spawnZombie(Math.random() < 0.5 ? -6 : 6, Math.random() * 8, Math.random() < 0.5 ? 'a' : 'b'); // in from the sides +} +function firePellet() { + const a = (Math.random() * 2 - 1) * 4 * Math.PI / 180, s = 26; // ±4° spread, straight up-court (-z) + pellets.push({ x: P.x, y: 0.9, z: P.z, vx: Math.sin(a) * s, vz: -Math.cos(a) * s, t: 1.2 }); + pock(0.25, 1400); // rapid fire tick; if it clips on device, gate to every 2nd pellet +} +function endHorde() { + G.horde = null; pellets.length = 0; + setupPoint(); // serve loop resumes; any zombies still standing are yours to mop up + voice('quiet_dark', 0.5, 0.85); +} +function tickHorde(dt) { + const h = G.horde; + h.t -= dt; + if ((h.spawnT -= dt) <= 0) { spawnHordeZombie(); h.spawnT = 1 / TUNE.hordeRate; } + if ((h.mgT -= dt) <= 0) { firePellet(); h.mgT = 1 / TUNE.mgRate; } + if (h.t <= 0) endHorde(); +} + // bomb ball: everything inside bombRadius splatters at once (each kill still ++ball.kills so // the Phase-2 fanfare escalates), plus a crater — big stain, size-3 pile, extra particles, boom. export function explode(x, z) { @@ -72,10 +97,13 @@ export function updateZombies(dt) { if (G.mode === 'splatter') { // transition spawns are scripted, not timed G.splatT += dt; - spawnT -= dt; - if (spawnT <= 0 && zombies.length < TUNE.zMax) { - spawnZombie((Math.random() * 2 - 1) * 4.8, -1.5 - Math.random(), Math.random() < 0.5 ? 'a' : 'b'); - spawnT = TUNE.zSpawnEvery; + if (G.horde) tickHorde(dt); // horde: dense spawns + machine gun, ignores zMax + else { + spawnT -= dt; + if (spawnT <= 0 && zombies.length < TUNE.zMax) { + spawnZombie((Math.random() * 2 - 1) * 4.8, -1.5 - Math.random(), Math.random() < 0.5 ? 'a' : 'b'); + spawnT = TUNE.zSpawnEvery; + } } } @@ -94,6 +122,7 @@ export function updateZombies(dt) { splat(1); voice('game_set_massacre', 0.8); G.mode = 'eaten'; ball.active = false; G.flash = null; // zombies keep shambling for ambience + G.horde = null; pellets.length = 0; // the swarm stops; the eaten screen takes over } if (ball.active && ball.lastHit === 'P' && ball.y < 1.9) { const d = Math.hypot(ball.x - zb.x, ball.z - zb.z); @@ -108,7 +137,16 @@ export function updateZombies(dt) { ball.vx *= 0.6; ball.vz *= 0.6; ball.lastHit = 'X'; // spent — one stagger per ball } } - if (zb.z >= COURT.L + 0.7) { zombies.splice(i, 1); if (G.mode !== 'eaten') splatPoint('O'); } // it reached your baseline + if (zb.z >= COURT.L + 0.7) { zombies.splice(i, 1); if (G.mode !== 'eaten') splatPoint('O', !!G.horde); } // it reached your baseline + } + + for (let i = pellets.length - 1; i >= 0; i--) { // machine-gun rounds: flat, fast, one-shot kills + const pe = pellets[i]; + pe.t -= dt; pe.x += pe.vx * dt; pe.z += pe.vz * dt; + let hit = false; + for (let j = zombies.length - 1; j >= 0; j--) + if (Math.hypot(zombies[j].x - pe.x, zombies[j].z - pe.z) < 0.55) { splatter(j, false); hit = true; break; } + if (hit || pe.t <= 0) pellets.splice(i, 1); } for (let i = parts.length - 1; i >= 0; i--) {