From d016ba862ace10296c61ca49550ac385c6889975 Mon Sep 17 00:00:00 2001 From: Justin Parker Date: Tue, 3 Nov 2026 04:08:02 -0800 Subject: [PATCH] Add Ghoul Rush's new stages (bog, hearse, pew, wagon and more) with their intros and suites AI Assisted --- scripts/ghoul-test-helpers.mjs | 9 + ...test-web-console-activities-ghoul-arms.mjs | 31 +- ...-web-console-activities-ghoul-banister.mjs | 1186 +++++++++++++++ .../test-web-console-activities-ghoul-bog.mjs | 990 ++++++++++++ ...t-web-console-activities-ghoul-bogboat.mjs | 945 ++++++++++++ ...web-console-activities-ghoul-bossintro.mjs | 303 ++++ ...-web-console-activities-ghoul-carnival.mjs | 4 +- ...test-web-console-activities-ghoul-cart.mjs | 3 + ...st-web-console-activities-ghoul-chapel.mjs | 229 ++- ...test-web-console-activities-ghoul-dice.mjs | 12 +- ...st-web-console-activities-ghoul-frozen.mjs | 31 +- ...-web-console-activities-ghoul-gameover.mjs | 2 + ...web-console-activities-ghoul-graveyard.mjs | 4 +- ...t-web-console-activities-ghoul-grounds.mjs | 9 +- ...st-web-console-activities-ghoul-gurney.mjs | 1063 +++++++++++++ ...st-web-console-activities-ghoul-hearse.mjs | 1161 +++++++++++++++ ...est-web-console-activities-ghoul-intro.mjs | 226 +++ ...test-web-console-activities-ghoul-mine.mjs | 4 +- ...est-web-console-activities-ghoul-mower.mjs | 945 ++++++++++++ .../test-web-console-activities-ghoul-pew.mjs | 1087 ++++++++++++++ ...est-web-console-activities-ghoul-retry.mjs | 9 + ...eb-console-activities-ghoul-sanatorium.mjs | 5 +- ...test-web-console-activities-ghoul-sled.mjs | 5 +- ...est-web-console-activities-ghoul-story.mjs | 455 ++++++ ...test-web-console-activities-ghoul-tray.mjs | 894 +++++++++++ ...t-web-console-activities-ghoul-village.mjs | 4 +- ...est-web-console-activities-ghoul-wagon.mjs | 1157 +++++++++++++++ scripts/test-web-console-activities-ghoul.mjs | 116 +- .../public/activities/ghoul-arms.js | 15 +- .../public/activities/ghoul-banister-draw.js | 1044 +++++++++++++ .../public/activities/ghoul-banister.js | 520 +++++++ .../public/activities/ghoul-bog-draw.js | 1321 +++++++++++++++++ .../public/activities/ghoul-bog.js | 496 +++++++ .../public/activities/ghoul-bogboat-draw.js | 949 ++++++++++++ .../public/activities/ghoul-bogboat.js | 420 ++++++ .../public/activities/ghoul-boss-intros.js | 31 + .../public/activities/ghoul-bossintro-draw.js | 256 ++++ .../public/activities/ghoul-cart.js | 2 +- .../public/activities/ghoul-chapel-draw.js | 48 +- .../public/activities/ghoul-chapel.js | 109 +- .../public/activities/ghoul-dice-draw.js | 73 +- .../public/activities/ghoul-dice.js | 10 +- .../public/activities/ghoul-draw.js | 132 +- .../public/activities/ghoul-frozen-draw.js | 5 + .../public/activities/ghoul-frozen.js | 22 +- .../public/activities/ghoul-gurney-draw.js | 1067 +++++++++++++ .../public/activities/ghoul-gurney.js | 586 ++++++++ .../public/activities/ghoul-hearse-draw.js | 1308 ++++++++++++++++ .../public/activities/ghoul-hearse.js | 503 +++++++ .../public/activities/ghoul-intro-draw.js | 336 +++++ .../public/activities/ghoul-intros.js | 85 ++ .../public/activities/ghoul-mower-draw.js | 1210 +++++++++++++++ .../public/activities/ghoul-mower.js | 547 +++++++ .../public/activities/ghoul-pew-course.js | 140 ++ .../public/activities/ghoul-pew-draw.js | 249 ++++ .../public/activities/ghoul-pew-world.js | 947 ++++++++++++ .../public/activities/ghoul-pew.js | 475 ++++++ .../public/activities/ghoul-picker-draw.js | 2 +- .../public/activities/ghoul-powers.js | 13 +- .../public/activities/ghoul-rooms.js | 599 +++++++- .../public/activities/ghoul-run.js | 61 + .../public/activities/ghoul-sfx-banister.js | 241 +++ .../public/activities/ghoul-sfx-bog.js | 339 +++++ .../public/activities/ghoul-sfx-bogboat.js | 203 +++ .../public/activities/ghoul-sfx-gurney.js | 223 +++ .../public/activities/ghoul-sfx-hearse.js | 247 +++ .../public/activities/ghoul-sfx-mower.js | 221 +++ .../public/activities/ghoul-sfx-pew.js | 220 +++ .../public/activities/ghoul-sfx-story.js | 116 ++ .../public/activities/ghoul-sfx-tray.js | 225 +++ .../public/activities/ghoul-sfx-wagon.js | 230 +++ .../public/activities/ghoul-sfx.js | 41 +- .../public/activities/ghoul-story-draw.js | 811 ++++++++++ .../public/activities/ghoul-story.js | 216 +++ .../public/activities/ghoul-tray-draw.js | 930 ++++++++++++ .../public/activities/ghoul-tray.js | 496 +++++++ .../public/activities/ghoul-wagon-draw.js | 1297 ++++++++++++++++ .../public/activities/ghoul-wagon.js | 601 ++++++++ 78 files changed, 30982 insertions(+), 145 deletions(-) create mode 100644 scripts/ghoul-test-helpers.mjs create mode 100644 scripts/test-web-console-activities-ghoul-banister.mjs create mode 100644 scripts/test-web-console-activities-ghoul-bog.mjs create mode 100644 scripts/test-web-console-activities-ghoul-bogboat.mjs create mode 100644 scripts/test-web-console-activities-ghoul-bossintro.mjs create mode 100644 scripts/test-web-console-activities-ghoul-gurney.mjs create mode 100644 scripts/test-web-console-activities-ghoul-hearse.mjs create mode 100644 scripts/test-web-console-activities-ghoul-intro.mjs create mode 100644 scripts/test-web-console-activities-ghoul-mower.mjs create mode 100644 scripts/test-web-console-activities-ghoul-pew.mjs create mode 100644 scripts/test-web-console-activities-ghoul-story.mjs create mode 100644 scripts/test-web-console-activities-ghoul-tray.mjs create mode 100644 scripts/test-web-console-activities-ghoul-wagon.mjs create mode 100644 src/web-console/public/activities/ghoul-banister-draw.js create mode 100644 src/web-console/public/activities/ghoul-banister.js create mode 100644 src/web-console/public/activities/ghoul-bog-draw.js create mode 100644 src/web-console/public/activities/ghoul-bog.js create mode 100644 src/web-console/public/activities/ghoul-bogboat-draw.js create mode 100644 src/web-console/public/activities/ghoul-bogboat.js create mode 100644 src/web-console/public/activities/ghoul-boss-intros.js create mode 100644 src/web-console/public/activities/ghoul-bossintro-draw.js create mode 100644 src/web-console/public/activities/ghoul-gurney-draw.js create mode 100644 src/web-console/public/activities/ghoul-gurney.js create mode 100644 src/web-console/public/activities/ghoul-hearse-draw.js create mode 100644 src/web-console/public/activities/ghoul-hearse.js create mode 100644 src/web-console/public/activities/ghoul-intro-draw.js create mode 100644 src/web-console/public/activities/ghoul-intros.js create mode 100644 src/web-console/public/activities/ghoul-mower-draw.js create mode 100644 src/web-console/public/activities/ghoul-mower.js create mode 100644 src/web-console/public/activities/ghoul-pew-course.js create mode 100644 src/web-console/public/activities/ghoul-pew-draw.js create mode 100644 src/web-console/public/activities/ghoul-pew-world.js create mode 100644 src/web-console/public/activities/ghoul-pew.js create mode 100644 src/web-console/public/activities/ghoul-sfx-banister.js create mode 100644 src/web-console/public/activities/ghoul-sfx-bog.js create mode 100644 src/web-console/public/activities/ghoul-sfx-bogboat.js create mode 100644 src/web-console/public/activities/ghoul-sfx-gurney.js create mode 100644 src/web-console/public/activities/ghoul-sfx-hearse.js create mode 100644 src/web-console/public/activities/ghoul-sfx-mower.js create mode 100644 src/web-console/public/activities/ghoul-sfx-pew.js create mode 100644 src/web-console/public/activities/ghoul-sfx-story.js create mode 100644 src/web-console/public/activities/ghoul-sfx-tray.js create mode 100644 src/web-console/public/activities/ghoul-sfx-wagon.js create mode 100644 src/web-console/public/activities/ghoul-story-draw.js create mode 100644 src/web-console/public/activities/ghoul-story.js create mode 100644 src/web-console/public/activities/ghoul-tray-draw.js create mode 100644 src/web-console/public/activities/ghoul-tray.js create mode 100644 src/web-console/public/activities/ghoul-wagon-draw.js create mode 100644 src/web-console/public/activities/ghoul-wagon.js diff --git a/scripts/ghoul-test-helpers.mjs b/scripts/ghoul-test-helpers.mjs new file mode 100644 index 0000000..f3e3ae6 --- /dev/null +++ b/scripts/ghoul-test-helpers.mjs @@ -0,0 +1,9 @@ +// Shared helpers for the Ghoul Rush tests (not a test itself). + +// Leaves a boss room's intro card (phase "bossintro", ghoul-bossintro-draw.js) the way a player does: after the lockout, a fresh press. +// A round in any other phase is left alone. Returns true when it left a card. +export function skipBossIntro(ghoul, round) { + if (round.phase !== "bossintro") return false; + round.introMs = Math.max(round.introMs || 0, ghoul.INTRO_MIN_MS); + return ghoul.takeIntro(round); +} diff --git a/scripts/test-web-console-activities-ghoul-arms.mjs b/scripts/test-web-console-activities-ghoul-arms.mjs index db647e2..71792fd 100644 --- a/scripts/test-web-console-activities-ghoul-arms.mjs +++ b/scripts/test-web-console-activities-ghoul-arms.mjs @@ -521,7 +521,8 @@ test("Ghoul Rush's Silver Bear Trap sets at his feet, snaps on the first thing t }); test("Ghoul Rush's ride rooms keep what needs a floor in the bag, use the next kind down, and a stick or a flash goes off in the air rather than being lost", () => { - const room = ghoul.ROOMS.find((r) => r.ride); + // The Mine's Runaway Cart, whichever rides other stages have in the room list before it. + const room = ghoul.ROOMS.find((r) => r.ride && r.id === "cart"); if (!room) return; const round = ghoul.newRound(5); round.dice = 0; @@ -1635,3 +1636,31 @@ test("Ghoul Rush's Dynamite, Road Flare, Salt and Flash Powder are aimed: they l const lob = pie.hazards.find((h) => h.kind === "armPie"); assert.ok(lob && Math.abs(lob.vx - arm.PIE_VX) < 1e-9, "the pie is not aimed"); }); + +test("Ghoul Rush's Dynamite keeps its fuse but also goes off at once when a monster stands within a unit of it after it lands", () => { + const blasts = (round) => events(round, "dynBlast").length; + // A monster that walks up to a landed stick sets it off before the fuse. + const near = roomOf("village", "inn"); + standAt(near, 40); + give(near, "dyn", 2); + tapTap(near); + const stick = near.hazards.find((h) => h.kind === "stick"); + for (let i = 0; i < 200 && !stick.rest; i++) run(near, 16); + assert.ok(stick.rest && stick.fuse > 200, "landed with fuse left"); + assert.equal(blasts(near), 0); + put(near, "zombie", stick.x + 0.5, { stunMs: 1e9 }); + run(near, 40); + assert.equal(blasts(near), 1, "went off at once on the neighbor"); + // A monster further off than a unit does not set it off; the fuse still does. + const far = roomOf("village", "inn"); + standAt(far, 40); + give(far, "dyn", 2); + tapTap(far); + const s2 = far.hazards.find((h) => h.kind === "stick"); + for (let i = 0; i < 200 && !s2.rest; i++) run(far, 16); + put(far, "zombie", s2.x + 6, { stunMs: 1e9 }); + run(far, 40); + assert.equal(blasts(far), 0, "too far"); + run(far, arm.DYN_FUSE_MS + 40); + assert.equal(blasts(far), 1, "the fuse still blows it"); +}); diff --git a/scripts/test-web-console-activities-ghoul-banister.mjs b/scripts/test-web-console-activities-ghoul-banister.mjs new file mode 100644 index 0000000..0fe2c0f --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-banister.mjs @@ -0,0 +1,1186 @@ +// Web console tests, Ghoul Rush's Grand Banister (the Manor's bonus round, between the Library and the Ballroom): its shape (every break clears with a jump and swallows a rider that does not jump, the brass under-rails, every low can be ducked, spacing, checkpoints, the clock), the ride's speed on slopes and its lean and brake, its jump, ducking and diving, a vase, a candlestick, a hanging frame, a chandelier on its pendulum, a ghostly butler, the cobwebs, a fall off the rail, the checkpoint, the jump off the end and the door, the bonus round's hearts and dice (3 to 9), endless lives for every new cause, a voice for every event, the drawing, and bots that ride the whole stair (one that rides well, one that never dodges). +// Run with: node --test scripts/test-web-console-activities-ghoul-banister.mjs +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { skipBossIntro } from "./ghoul-test-helpers.mjs"; +import * as bn from "../src/web-console/public/activities/ghoul-banister.js"; +import * as ct from "../src/web-console/public/activities/ghoul-cart.js"; +import { EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as BAN_LOOKS, VOICES as BAN_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-banister-draw.js"; +import { BANISTER_SFX } from "../src/web-console/public/activities/ghoul-sfx-banister.js"; +import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js"; +import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-draw.js"; +import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-bonus.js"; + +const steady = () => 0.5; +// The pack draws no random number: a run on this fails on the first draw. +const never = () => { + throw new Error("the banister drew a random number"); +}; +const events = (round, type) => round.events.filter((e) => e.type === type); + +function through(round) { + round.phase = "clear"; + round.phaseMs = 1; + ghoul.advance(round, 4, steady); +} + +// A round in the Grand Banister reached the way play reaches it, nothing woken, the clocks long, +// the bonus round on (five hearts). +function banRound(seed = 5) { + const round = ghoul.newRound(seed); + round.lives = 3; + round.dice = 0; + through(round); + round.offer = ["manor"]; + round.phaseMs = 0; + ghoul.pickStage(round, 0); + while (round.spec.id !== "banister") through(round); + round.phase = "play"; + for (const st of round.spawns) st.over = true; + round.monsters.length = 0; + round.hordeMs = Infinity; + round.timeMs = 1e9; + round.bonus = 1e9; + round.events.length = 0; + return round; +} + +const NONE = { runner: "banister", rails: 0, time: 1e9, finish: 1e6, track: [], props: [], lows: [], swings: [], butlers: [], webs: [], checks: [] }; +// The same round over a ride of its own (a plain track to measure the rider on). +function synth(ride) { + const round = banRound(); + round.spec = { ...round.spec, start: 10, ground: [[0, 5, 0]], ride: { ...NONE, rails: (ride.track || []).length, ...ride } }; + bn.BANISTER.place[0](round, {}); + return round; +} +const FLAT = [[[0, 20], [4000, 20]]]; +const DOWN = [[[0, 40], [4000, 40 - 0.15 * 4000]]]; +const UP = [[[0, 0], [4000, 0.3 * 4000]]]; + +// The rider on line `line` of the ride at `x`, at speed `v`. +function rideAt(round, x, line, { v = bn.BAN_V, safe = false } = {}) { + const y = ct.trackY(round.spec.ride, line, x); + assert.ok(y !== null, `line ${line} runs under ${x}`); + Object.assign(round.you, { x, y, vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false }); + Object.assign(round.runner, { line, v, coyote: 0 }); + round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24)); +} + +function run(round, ms, keys = {}, random = steady) { + Object.assign(round.input, keys); + for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random); + for (const k of Object.keys(keys)) round.input[k] = typeof keys[k] === "number" ? 0 : false; +} + +function until(round, done, ms = 6000, random = steady) { + let t = 0; + for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random); + return t; +} + +const press = (round) => { + round.input.jump = ghoul.JUMP_BUFFER_MS; + round.input.up = true; +}; + +const heard = (e, extra = {}) => { + const played = []; + const noop = () => {}; + const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra }; + react({ x: 10, y: 6, tx: 20, ty: 6, ...e }, kit); + return { played }; +}; + +const ROOM = ghoul.roomById("banister"); +const R = ROOM.ride; +const lines = ct.linesOf(R); +const floorOf = (x) => ghoul.groundAt(ROOM, x); +const slopeAtLine = (L, i) => (L.pts[i + 1][1] - L.pts[i][1]) / (L.pts[i + 1][0] - L.pts[i][0]); +const uppers = lines.slice(0, R.rails); +const unders = lines.slice(R.rails); + +// The kit's numbers the room is built to. +const K = { HIT_W: ghoul.HIT_W, HIT_H: ghoul.HIT_H, DUCK_H: ghoul.DUCK_H }; + +/* -------------------------------------------------------------- the room */ + +test("Ghoul Rush's Grand Banister is the Manor's fourth room, between the Library and the Ballroom: lit, no key, no boss, a ride about 60 to 70 seconds long, a bonus round that plays its own track", () => { + const st = ghoul.stageById("manor"); + assert.deepEqual(st.rooms, ["foyer", "gallery", "library", "banister", "ballroom"]); + assert.equal(st.boss, "gourd"); + assert.deepEqual([ROOM.title, ROOM.sub], ["The Grand Banister", "Please keep your hands and ghosts inside the rail"]); + assert.equal(ROOM.dark, false, "always lit"); + assert.equal(ROOM.key, null); + assert.equal(ROOM.boss, null); + assert.equal(ROOM.bonus, true, "a bonus round"); + assert.equal(R.runner, "banister"); + assert.ok(ROOM.length >= 2400 && ROOM.length <= 3100, `${ROOM.length} units long`); + assert.equal(ghoul.ROOM_MUSIC.banister, "ghoulBanister"); + assert.ok(ghoulSfx.default.music.ghoulBanister, "its own track"); + assert.deepEqual(Object.keys(bn.BANISTER.monsters), [], "no new monster kinds"); + assert.equal(LOOKS.banister, BAN_LOOKS.banister); + assert.equal(LOOKS.banister.pack, "banister"); + assert.ok(Object.isFrozen(R) && Object.isFrozen(R.track) && Object.isFrozen(R.track[0][0]), "frozen all the way down"); + assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0 && ROOM.items.length === 0, "no monsters and no pickups: the things on the stairs are the pack's own"); + assert.match(R.how, /UP jump, DOWN duck/); + // The ground is the attic landing at the start and the foyer floor at the end only. + assert.equal(ROOM.ground.length, 2); + assert.ok(ROOM.ground[0][1] < 60 && ROOM.ground[1][0] > ROOM.length - 100, "floor only at the ends"); + assert.equal(ROOM.ground[1][0], R.finish); + assert.ok(ROOM.door > R.finish && ROOM.door > ROOM.length - 14, "the door at the room's end, past the foyer's start"); + assert.ok(floorOf(ROOM.door - 2) > -Infinity, "floor to walk out on"); + for (const L of lines) for (let i = 0; i + 1 < L.pts.length; i++) assert.ok(L.pts[i + 1][0] > L.pts[i][0], "x rises"); + assert.ok(ct.trackY(R, 0, ROOM.start) > floorOf(ROOM.start), "the rider starts on the rail over the attic landing"); + // The ride, at the rider's speed, takes 60 to 70 seconds. + const secs = (uppers.at(-1).x1 - ROOM.start) / bn.BAN_V; + assert.ok(secs >= 58 && secs <= 72, `${secs.toFixed(1)} s at BAN_V`); + // The stairs: descents that fall about 0.10 to 0.11 and short climbs at about 0.3, never steeper. + let down = 0; + let total = 0; + for (const L of uppers) { + for (let i = 0; i + 1 < L.pts.length; i++) { + const s = slopeAtLine(L, i); + const len = L.pts[i + 1][0] - L.pts[i][0]; + assert.ok(s >= -0.2 && s <= 0.32, `a slope of ${s.toFixed(3)}`); + total += len; + if (s < 0) down += len; + } + } + assert.ok(down / total > 0.6, `${((100 * down) / total).toFixed(0)}% of the stairs go down`); + for (const L of lines) for (const [, y] of L.pts) assert.ok(y > bn.DERAIL_Y + 4 && y < 40, `a rail height of ${y}`); + assert.equal(ghoul.timeFor(ghoul.roomFor("banister")), R.time); + assert.ok(R.time >= 1.5 * secs * 1000, `a ${R.time} ms clock for a ${secs.toFixed(0)} s ride`); + // The lip ends the stairs rising, so it launches by itself. + const last = R.rails - 1; + assert.ok(ct.slopeOf(R, last, uppers.at(-1).x1) >= bn.RAMP_SLOPE, "the lip launches"); +}); + +test("Ghoul Rush's Grand Banister: the lip's launch alone carries the rider onto the foyer floor at any speed it can have there, landing 10 to 40 past its start", () => { + const lip = uppers.at(-1); + const end = lip.pts.at(-1); + const rise = ct.slopeOf(R, R.rails - 1, lip.x1); + const floor = floorOf(R.finish + 1); + for (const v of [bn.BAN_MIN, 34, bn.BAN_V, 55, bn.BAN_MAX]) { + let vy = rise * v + bn.RAMP_POP; + let x = end[0]; + let y = end[1]; + for (let t = 0; t < 3; t += 0.002) { + vy -= bn.BAN_G * 0.002; + x += v * 0.002; + y += vy * 0.002; + if (vy < 0 && y <= floor) break; + } + assert.ok(x >= R.finish + 2, `at ${v} it lands ${x - R.finish} past the floor's start`); + assert.ok(x <= R.finish + 40, `at ${v} it lands ${x - R.finish} past the floor's start`); + } +}); + +test("Ghoul Rush's Grand Banister: every break in the rail clears with a jump at the edge or a few units early, and a rider that never jumps drops into it", () => { + assert.equal(R.rails - 1, 7, "seven breaks"); + for (let i = 0; i + 1 < R.rails - 1; i++) { + const a = lines[i]; + const b = lines[i + 1]; + const gap = b.x0 - a.x1; + assert.ok(gap >= 9 && gap <= 18, `break ${i} is ${gap} wide`); + const end = a.pts.at(-1); + const slope = ct.slopeOf(R, i, a.x1); + assert.ok(slope < 0, "breaks lie on descents (no ramp launch)"); + for (const v of [40, 45, 50, 55]) { + assert.equal(bn.flight(R, a.x1, end[1], slope * v, v), null, `break ${i}, no jump, at ${v}`); + for (const early of [0, 4]) { + const x = a.x1 - early; + const y = ct.trackY(R, i, x); + const s = bn.flight(R, x, y, bn.BAN_JUMP_V + ct.slopeOf(R, i, x) * v, v); + assert.ok(s, `break ${i}: a jump ${early} early at ${v} lands`); + assert.equal(s.line, i + 1, `break ${i} cleared, at ${v}, ${early} early`); + } + } + } +}); + +test("Ghoul Rush's Grand Banister: the brass under-rails run RAIL_SEP under the handrail along one descent each, a jump with DOWN held lands on one and a plain jump on the handrail, and a jump off its end lands back on the handrail", () => { + assert.equal(unders.length, 8, "eight places where the track splits"); + for (let n = 0; n < unders.length; n++) { + const line = R.rails + n; + const L = unders[n]; + // It lies under one handrail line, on a descent, RAIL_SEP below it all along. + const up = uppers.findIndex((u) => u.x0 <= L.x0 && u.x1 >= L.x1); + assert.ok(up >= 0, `under-rail ${n} lies under a handrail line`); + for (let x = L.x0; x <= L.x1; x += 2) assert.ok(Math.abs(ct.trackY(R, up, x) - ct.trackY(R, line, x) - bn.RAIL_SEP) < 0.15, `${bn.RAIL_SEP} under at ${x}`); + for (let i = 0; i + 1 < L.pts.length; i++) assert.ok(slopeAtLine(L, i) < -0.05, "on a descent only"); + assert.ok(L.x1 - L.x0 > 90, "a long flight"); + assert.ok(bn.lowerLine(R, line) && !bn.lowerLine(R, up)); + // A dive from the climb before it lands on it; a plain jump from the same place on the handrail. + const x = L.x0 - 12; + const y = ct.trackY(R, up, x); + const v = bn.BAN_V; + const dive = bn.flight(R, x, y, bn.BAN_JUMP_V + ct.slopeOf(R, up, x) * v, v, true); + const plain = bn.flight(R, x, y, bn.BAN_JUMP_V + ct.slopeOf(R, up, x) * v, v, false); + assert.ok(dive && dive.line === line, `a dive lands on under-rail ${n}`); + assert.ok(plain && plain.line === up, `a plain jump lands on the handrail at ${n}`); + // Off its end the rider falls (a plunge) unless he jumps; a jump lands on the handrail. + const end = L.pts.at(-1); + const slope = ct.slopeOf(R, line, L.x1); + assert.equal(bn.flight(R, L.x1, end[1], slope * v, v), null, `under-rail ${n}: no jump, a plunge`); + for (const early of [0, 3]) { + const ex = L.x1 - early; + const f = bn.flight(R, ex, ct.trackY(R, line, ex), bn.BAN_JUMP_V + ct.slopeOf(R, line, ex) * v, v); + assert.ok(f && f.line < R.rails, `under-rail ${n}: a jump ${early} early lands on the handrail`); + } + } +}); + +test("Ghoul Rush's Grand Banister: every thing is on a line, off its ends, spaced for a player (22 between jumps and 38 between a jump and a duck), a frame's underside between a ducked box and a standing one, a chandelier's swing inside its line", () => { + const jumps = []; + for (const [x, line] of R.props) { + assert.ok(ct.trackY(R, line, x) !== null, `a prop at ${x} stands on line ${line}`); + jumps.push([x - 2, x + 2, line]); + } + for (const [x, line] of R.butlers) { + assert.ok(ct.trackY(R, line, x) !== null); + assert.ok(x - lines[line].x0 > 20 && lines[line].x1 - x > 14, `a butler at ${x} has room to lunge`); + jumps.push([x - 12, x + 2, line]); + } + for (let i = 0; i + 1 < R.rails; i++) jumps.push([lines[i].x1, lines[i + 1].x0, -1]); + for (const [x, line] of [...R.webs]) assert.ok(x - lines[line].x0 > 8 && lines[line].x1 - x > 14, `a web at ${x} well inside its line`); + for (const [x, line] of R.props) assert.ok(x - lines[line].x0 > 8 && lines[line].x1 - x > 14, `a prop at ${x} well inside its line`); + const ducks = []; + for (const [x0, x1] of R.lows) ducks.push([x0, x1]); + for (const [cx, line, amp] of R.swings) { + assert.ok(line < R.rails, "chandeliers hang over the handrail"); + assert.ok(cx - amp - 6 > lines[line].x0 && cx + amp + 6 < lines[line].x1, `the swing at ${cx} stays inside its line`); + ducks.push([cx - amp - 3, cx + amp + 3]); + } + // The routes: the handrail's and each under-rail's own; the breaks belong to both (line -1). + const checkSpacing = (set, label) => { + set.sort((p, q) => p[0] - q[0]); + for (let i = 0; i + 1 < set.length; i++) assert.ok(set[i + 1][0] - set[i][1] >= 22, `${label}: jumps at ${set[i][1]} and ${set[i + 1][0]}`); + }; + const handrail = jumps.filter((j) => j[2] < R.rails); + checkSpacing([...handrail], "handrail"); + for (let n = 0; n < unders.length; n++) { + const line = R.rails + n; + const own = jumps.filter((j) => j[2] === line || j[2] === -1); + own.push([unders[n].x1 - 2, unders[n].x1 + 4, line]); + // The dive in from the climb before it: a jump from 14 short of its start, landing about 26 in. + own.push([unders[n].x0 - 14, unders[n].x0 + 26, line]); + checkSpacing(own, `under-rail ${n}`); + } + for (const [d0, d1] of ducks) { + for (const [j0, j1, l] of handrail) assert.ok(j0 - d1 >= 38 || d0 - j1 >= 38, `a jump at ${j0} and a duck at ${d0} (line ${l})`); + } + for (let i = 0; i < R.lows.length; i++) { + const [x0, x1, y] = R.lows[i]; + let hi = 0; + let lo = 99; + for (let x = x0 - K.HIT_W / 2; x <= x1 + K.HIT_W / 2; x += 0.25) { + const g = ct.linesAt(R, x)[0]; + assert.ok(g, "rail under a frame"); + hi = Math.max(hi, g[1]); + lo = Math.min(lo, g[1]); + } + assert.ok(hi + K.DUCK_H < y, `a ducked box clears the frame at ${x0}`); + assert.ok(lo + K.HIT_H > y, `a standing box hits the frame at ${x0}`); + } + assert.deepEqual([R.props.length, R.lows.length, R.swings.length, R.butlers.length, R.webs.length], [12, 6, 7, 8, 8]); + // Checkpoints every 300 to 400 units, each on the handrail and clear of a jump coming up. + const cs = R.checks; + for (let i = 0; i < cs.length; i++) { + assert.ok(ct.linesAt(R, cs[i]).length, `checkpoint ${i} on the rail`); + if (i) assert.ok(cs[i] - cs[i - 1] >= 300 && cs[i] - cs[i - 1] <= 400, `${cs[i] - cs[i - 1]} between checkpoints`); + for (const [j0, j1, l] of handrail) assert.ok(j0 - cs[i] > 20 || cs[i] - j1 > 4, `a jump at ${j0} near checkpoint ${i} (line ${l})`); + } + assert.ok(cs[0] < 450 && R.finish - cs.at(-1) > 300); +}); + +/* ---------------------------------------------------------- the pendulum */ + +test("Ghoul Rush's Grand Banister's chandeliers swing on a pendulum: a sine in time, lowest in the middle of the swing and rising at the ends, over the handrail under them", () => { + const round = synth({ track: FLAT, swings: [[100, 0, 9, 2400, 300]] }); + const sw = (t) => bn.swingAt(round.spec.ride, 0, t); + // At the phase's zero it is in the middle, going right; a quarter period later at the far end. + const mid = sw(2400 - 300); + assert.ok(Math.abs(mid.x - 100) < 1e-6 && Math.abs(mid.u) < 1e-6); + assert.ok(Math.abs(mid.bottom - (20 + bn.SWING_LOW)) < 1e-6, "lowest in the middle"); + const end = sw(2400 - 300 + 600); + assert.ok(Math.abs(end.x - 109) < 1e-6 && Math.abs(end.u - 1) < 1e-6); + assert.ok(Math.abs(end.bottom - (20 + bn.SWING_LOW + bn.SWING_RISE)) < 1e-6, "highest at the ends"); + const back = sw(2400 - 300 + 1800); + assert.ok(Math.abs(back.x - 91) < 1e-6); + // Periodic, and the same every time. + const p1 = sw(777); + const p2 = sw(777 + 2400); + assert.ok(Math.abs(p1.x - p2.x) < 1e-6 && Math.abs(p1.bottom - p2.bottom) < 1e-6); + // Over a slope, the bob hangs over the rail under it. + const slope = synth({ track: DOWN, swings: [[100, 0, 9, 2400, 0]] }); + const a = bn.swingAt(slope.spec.ride, 0, 600); + assert.ok(Math.abs(a.bottom - (ct.trackY(slope.spec.ride, 0, a.x) + bn.SWING_LOW + bn.SWING_RISE)) < 1e-6); + // The clock only runs while the rider rides. + assert.equal(round.runner.clock, 0); + run(round, 1000); + assert.equal(round.runner.clock, 1000); +}); + +test("Ghoul Rush's Grand Banister: a chandelier hits a standing rider while its bob hangs low, a ducked one while it hangs lower than a ducked head (the middle of its swing) and nobody while it is out at the end of its arc; a rider on the under-rail passes beneath it", () => { + const ride = { track: [[[0, 20], [400, 20]]], swings: [[100, 0, 9, 2400, 0]] }; + // Where the rider and the bob meet: the rider placed at the bob at time t (a clock to the nearest slice). + const meet = (t, { duck = false, line = 0, track = ride.track } = {}) => { + const r = synth({ ...ride, track }); + const b = bn.swingAt(r.spec.ride, 0, t + 4); + rideAt(r, b.x - 0.2, line); + r.runner.clock = t; + r.input.down = duck; + r.you.safeMs = 0; + run(r, 4); + r.input.down = false; + return r; + }; + // The middle of the swing (u 0, at t 0): the bob is lower than a ducked head, 22.2 over the rail. + const mid = meet(2400 - 4, { duck: true }); + assert.equal(mid.bonusRound.hearts, 4, "ducking does not help at the middle"); + assert.equal(events(mid, "lose")[0].cause, "swing"); + assert.equal(events(mid, "banCrash")[0].what, "swing"); + assert.deepEqual(mid.bonusRound.perf.hits, ["w0"]); + assert.equal(mid.lives, 3, "not a life"); + assert.ok(mid.you.safeMs > 0); + // Out at the end (u 1, t 600): the bob is over a standing head. + assert.equal(meet(600 - 4).bonusRound.hearts, 5, "high at the end of its arc"); + // In between (u 0.6): low enough to hit a standing rider, high enough to duck under. + const t06 = Math.round((Math.asin(0.6) / (2 * Math.PI)) * 2400); + assert.equal(meet(t06 - 4).bonusRound.hearts, 4, "standing: hit"); + assert.equal(meet(t06 - 4, { duck: true }).bonusRound.hearts, 5, "ducked: under"); + // The chain makes it a wall to the roof: a jump into it hits too. + const jump = synth(ride); + const b = bn.swingAt(jump.spec.ride, 0, 604); + rideAt(jump, b.x - 0.2, 0); + jump.runner.clock = 600 - 4 + 0; + Object.assign(jump.you, { state: "air", y: 28, vy: 5 }); + jump.runner.line = -1; + jump.runner.left = 0; + run(jump, 4); + assert.equal(jump.bonusRound.hearts, 4, "a jumper is hit above the bob"); + // On the under-rail 7 below, the same bob at its lowest passes overhead. + const under = meet(2400 - 4, { line: 1, track: [[[0, 20], [400, 20]], [[0, 13], [400, 13]]] }); + assert.equal(under.bonusRound.hearts, 5); + // The bob is a box: well clear of it in x, nothing hits. + const far = synth(ride); + rideAt(far, 60, 0); + far.runner.clock = 2400 - 4; + run(far, 4); + assert.equal(far.bonusRound.hearts, 5); +}); + +/* ------------------------------------------------------------ the rider */ + +test("Ghoul Rush's Grand Banister rolls at BAN_V on the flat, faster down a slope and slower up one, never past BAN_MIN or BAN_MAX; RIGHT leans and LEFT brakes", () => { + const flat = synth({ track: FLAT }); + assert.equal(flat.runner.v, bn.BAN_V); + run(flat, 2000); + assert.ok(Math.abs(flat.runner.v - bn.BAN_V) < 0.01); + run(flat, 300, { right: true }); + assert.ok(flat.runner.v > bn.BAN_V + 2, `a lean: ${flat.runner.v}`); + run(flat, 3000); + assert.ok(Math.abs(flat.runner.v - bn.BAN_V) < 0.5, "it settles back"); + run(flat, 300, { left: true }); + assert.ok(flat.runner.v < bn.BAN_V - 5, `a brake: ${flat.runner.v}`); + const down = synth({ track: DOWN }); + run(down, 3000); + assert.ok(Math.abs(down.runner.v - (bn.BAN_V + (bn.SLOPE_G * 0.15) / bn.RELAX)) < 0.2, `${down.runner.v} down a 0.15 slope`); + assert.ok(down.runner.v <= bn.BAN_MAX); + const up = synth({ track: UP }); + run(up, 3000); + assert.ok(Math.abs(up.runner.v - (bn.BAN_V - (bn.SLOPE_G * 0.3) / bn.RELAX)) < 0.2, `${up.runner.v} up a 0.3 slope`); + const steep = synth({ track: [[[0, 10000], [4000, 6000]]] }); + run(steep, 3000); + assert.equal(steep.runner.v, bn.BAN_MAX); + const wall = synth({ track: [[[0, 0], [4000, 4000]]] }); + run(wall, 3000); + assert.equal(wall.runner.v, bn.BAN_MIN); + const long = synth({ track: FLAT }); + run(long, 3000, { left: true }); + assert.equal(long.runner.v, bn.BAN_MIN); + // The rider faces right, on the rail, never walking. + assert.equal(flat.you.face, 1); + assert.equal(flat.you.state, "run"); + assert.equal(flat.you.y, 20); +}); + +test("Ghoul Rush's Grand Banister jumps about 13 high for about three quarters of a second, a press saved for a landing jumps on it, one just after a line's end still jumps", () => { + const round = synth({ track: FLAT }); + let top = 0; + press(round); + const t = until(round, () => { + top = Math.max(top, round.you.y - 20); + return round.you.state === "run" && round.you.y === 20 && round.you.vy === 0 && top > 1; + }, 3000); + assert.ok(Math.abs(top - (bn.BAN_JUMP_V * bn.BAN_JUMP_V) / (2 * bn.BAN_G)) < 0.4, `${top.toFixed(1)} high`); + assert.ok(t > 650 && t < 850, `${t} ms in the air`); + assert.equal(events(round, "banJump").length, 1); + assert.equal(events(round, "banLand").length, 1); + const across = round.you.x - 10; + assert.ok(across > 31 && across < 37, `${across.toFixed(1)} across`); + const buf = synth({ track: FLAT }); + press(buf); + run(buf, 640); + press(buf); + until(buf, () => events(buf, "banJump").length >= 2, 1500); + assert.equal(events(buf, "banJump").length, 2, "the saved press jumped again at the landing"); + const edge = synth({ track: [[[0, 20], [60, 20]], [[100, 20], [300, 20]]] }); + rideAt(edge, 58.5, 0); + run(edge, 80); + assert.equal(edge.runner.line, -1, "off the end"); + press(edge); + run(edge, 4); + assert.equal(events(edge, "banJump").length, 1, "coyote"); + const late = synth({ track: [[[0, 20], [60, 20]], [[100, 20], [300, 20]]] }); + rideAt(late, 58.5, 0); + run(late, 80 + bn.COYOTE_MS); + press(late); + run(late, 4); + assert.equal(events(late, "banJump").length, 0); +}); + +test("Ghoul Rush's Grand Banister: DOWN ducks (and a press of up jumps instead of ducking); a ducked rider passes under a frame and a standing one hits it (cause frame), at the cost of a heart", () => { + const round = synth({ track: FLAT, lows: [[60, 66, 23.0]] }); + const you = round.you; + assert.equal(you.ducking, false); + run(round, 20, { down: true }); + assert.equal(events(round, "banDuck").length, 1); + round.input.down = true; + until(round, () => you.x > 75, 3000); + round.input.down = false; + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.lives, 3); + const hit = synth({ track: FLAT, lows: [[60, 66, 23.0]] }); + until(hit, () => hit.bonusRound.hearts < 5, 3000); + assert.equal(hit.bonusRound.hearts, 4); + assert.equal(hit.lives, 3, "not a life"); + assert.equal(events(hit, "lose")[0].cause, "frame"); + assert.equal(events(hit, "banCrash")[0].what, "frame"); + assert.equal(hit.phase, "play", "the ride plays on"); + assert.ok(hit.you.safeMs > 0, "blinking safe"); + assert.deepEqual(hit.bonusRound.perf.hits, ["f0"]); + run(hit, 1000); + assert.equal(hit.bonusRound.hearts, 4, "the same frame costs nothing twice"); + const jump = synth({ track: FLAT, lows: [[60, 66, 23.0]] }); + rideAt(jump, 40, 0); + press(jump); + until(jump, () => jump.bonusRound.hearts < 5 || jump.you.x > 80, 3000); + assert.equal(jump.bonusRound.hearts, 4, "a jump does not clear a hanging frame"); + const both = synth({ track: FLAT }); + both.input.down = true; + press(both); + run(both, 20); + assert.equal(both.you.ducking, false); + assert.equal(events(both, "banJump").length, 1); +}); + +test("Ghoul Rush's Grand Banister: a vase and a candlestick are cleared by a jump and cost a heart otherwise (causes vase and candle), each only once", () => { + for (const [kind, cause, what] of [[0, "vase", "vase"], [1, "candle", "candle"]]) { + const hit = synth({ track: FLAT, props: [[60, 0, kind]] }); + until(hit, () => hit.bonusRound.hearts < 5, 3000); + assert.equal(hit.bonusRound.hearts, 4, `${cause} costs a heart`); + assert.equal(events(hit, "lose")[0].cause, cause); + assert.equal(events(hit, "banCrash")[0].what, what); + assert.equal(hit.lives, 3); + assert.deepEqual(hit.bonusRound.perf.hits, ["p0"]); + run(hit, 500); + assert.equal(hit.bonusRound.hearts, 4); + for (const from of [60 - 26, 60 - 14, 60 - 9]) { + const clear = synth({ track: FLAT, props: [[60, 0, kind]] }); + rideAt(clear, from, 0); + press(clear); + until(clear, () => clear.you.x > 80, 3000); + assert.equal(clear.bonusRound.hearts, 5, `${cause} jumped from ${from}`); + } + } +}); + +test("Ghoul Rush's Grand Banister: a ghostly butler waits until BUTLER_NEAR short of it, bows BUTLER_WARN_MS, lunges up the rail with its tray and hits (cause butler) if you meet it; a jump clears it", () => { + const hit = synth({ track: FLAT, butlers: [[200, 0]] }); + rideAt(hit, 150, 0); + assert.equal(hit.runner.butlers[0].state, "wait"); + run(hit, 100); + assert.equal(hit.runner.butlers[0].state, "wait", "far off: waiting"); + until(hit, () => hit.runner.butlers[0].state === "warn", 2000); + assert.ok(200 - hit.you.x <= bn.BUTLER_NEAR + 0.5 && 200 - hit.you.x > bn.BUTLER_NEAR - 1, "wakes at BUTLER_NEAR"); + assert.equal(events(hit, "banButlerWarn").length, 1); + assert.equal(hit.bonusRound.hearts, 5, "a bow hurts nothing"); + const warnMs = until(hit, () => hit.runner.butlers[0].state === "lunge", 2000); + assert.ok(Math.abs(warnMs - bn.BUTLER_WARN_MS) < 20, `bowed ${warnMs} ms`); + assert.equal(events(hit, "banButlerLunge").length, 1); + assert.ok(200 - hit.you.x > 12 && 200 - hit.you.x < 30, `lunges ${200 - hit.you.x} ahead: time to see it`); + const x0 = hit.runner.butlers[0].x; + run(hit, 100); + assert.ok(x0 - hit.runner.butlers[0].x > bn.BUTLER_V * 0.09, "it comes at you"); + until(hit, () => hit.bonusRound.hearts < 5, 2000); + assert.equal(events(hit, "lose")[0].cause, "butler"); + assert.equal(events(hit, "banCrash")[0].what, "butler"); + assert.equal(hit.runner.butlers[0].state, "spent"); + assert.deepEqual(hit.bonusRound.perf.hits, ["b0"]); + // A jump over it, any time from about 10 to 18 short of it while it lunges. + const jump = synth({ track: FLAT, butlers: [[200, 0]] }); + rideAt(jump, 150, 0); + until(jump, () => jump.runner.butlers[0].state === "lunge" && jump.runner.butlers[0].x - jump.you.x < 20, 3000); + press(jump); + until(jump, () => jump.you.x > 240, 3000); + assert.equal(jump.bonusRound.hearts, 5); + assert.equal(events(jump, "lose").length, 0); + // It gives up after its lunge. + const left = synth({ track: FLAT, butlers: [[600, 0]] }); + rideAt(left, 580, 0, { safe: true }); + left.runner.butlers[0] = { state: "lunge", t: bn.BUTLER_LUNGE_MS, x: 600, hp: 2 }; + run(left, bn.BUTLER_LUNGE_MS + 50); + assert.equal(left.runner.butlers[0].state, "spent"); +}); + +test("Ghoul Rush's Grand Banister: bolts follow the stairs, so two bolts break a butler (150 points) and one shoots down a cobweb (50 points), each for the grade's acts; riding through a web only tears it", () => { + const round = synth({ track: DOWN, butlers: [[220, 0]], webs: [[90, 0]] }); + rideAt(round, 20, 0); + round.you.safeMs = 1e9; + const start = round.score; + round.input.fire = true; + until(round, () => round.runner.webs[0] === "shot", 2000); + assert.equal(round.runner.webs[0], "shot"); + assert.equal(events(round, "banWebShot")[0].points, bn.WEB_POINTS); + assert.equal(round.bonusRound.perf.acts, 1); + until(round, () => round.runner.butlers[0].state === "broken", 4000); + assert.equal(round.runner.butlers[0].state, "broken"); + assert.equal(events(round, "banButlerHit").length, bn.BUTLER_HP - 1); + assert.equal(events(round, "banButlerBreak")[0].points, bn.BUTLER_POINTS); + round.input.fire = false; + assert.equal(round.bonusRound.perf.acts, 2); + assert.ok(round.score - start >= bn.WEB_POINTS + bn.BUTLER_POINTS); + assert.equal(round.bonusRound.hearts, 5, "a butler shot dead never hits"); + // A bolt flies along the slope, not level. + const probe = synth({ track: DOWN }); + probe.input.fire = true; + run(probe, 300); + probe.input.fire = false; + assert.ok(probe.shots.length > 0); + for (const s of probe.shots) { + const above = s.y - (40 - 0.15 * s.x); + assert.ok(Math.abs(above - ghoul.SHOT_Y) < 0.5, `a bolt ${above.toFixed(2)} over the rail`); + } + assert.equal(probe.bonusRound.perf.acts, 0); + // A web ridden through tears, costs nothing, and cannot be shot after. + const through = synth({ track: FLAT, webs: [[60, 0]] }); + until(through, () => through.runner.webs[0] === "torn", 3000); + assert.equal(through.runner.webs[0], "torn"); + assert.equal(events(through, "banWebTear").length, 1); + assert.equal(through.bonusRound.hearts, 5); + run(through, 400); + assert.equal(through.bonusRound.hearts, 5); + assert.equal(bn.BANISTER.target(through, { x: 60, y: 22.4 }), false, "a torn web is no target"); + // What was shot stays shot after a restart. + const again = synth({ track: FLAT, butlers: [[300, 0]], webs: [[200, 0]] }); + again.runner.butlers[0].state = "broken"; + again.runner.webs[0] = "shot"; + bn.BANISTER.place[0](again, {}); + assert.equal(again.runner.butlers[0].state, "broken"); + assert.equal(again.runner.webs[0], "shot"); +}); + +/* ------------------------------------------------- breaks, rails and hearts */ + +test("Ghoul Rush's Grand Banister: a break with no jump is a heart (cause plunge), the rider goes back on the handrail ahead at BAN_V and rolls on; a jump over it costs nothing", () => { + const ride = { track: [[[0, 20], [60, 20]], [[75, 20], [400, 20]]] }; + const fall = synth(ride); + rideAt(fall, 30, 0); + until(fall, () => fall.bonusRound.hearts < 5, 3000); + assert.equal(fall.bonusRound.hearts, 4); + assert.equal(fall.lives, 3, "not a life"); + assert.equal(events(fall, "lose")[0].cause, "plunge"); + assert.equal(fall.phase, "play"); + assert.equal(fall.runner.line, 1, "on the rail beyond the break"); + assert.ok(fall.you.x >= 75 && fall.you.x < 80); + assert.equal(fall.you.y, 20); + assert.equal(fall.runner.v, bn.BAN_V); + assert.ok(fall.you.safeMs > 0); + assert.deepEqual(fall.bonusRound.perf.hits, ["g0"]); + run(fall, 600); + assert.equal(fall.runner.line, 1); + assert.equal(fall.bonusRound.hearts, 4); + const hop = synth(ride); + rideAt(hop, 54, 0); + press(hop); + until(hop, () => hop.you.x > 100, 3000); + assert.equal(hop.bonusRound.hearts, 5); + assert.equal(hop.runner.line, 1); +}); + +test("Ghoul Rush's Grand Banister: a jump with DOWN held dives onto the under-rail (an event banSwitch), a plain jump lands back on the handrail, and off the under-rail's end a rider who does not jump plunges", () => { + // Two rails over 300 units: the handrail at 20, the brass under-rail 7 below. + const ride = { track: [[[0, 20], [400, 20]], [[100, 13], [300, 13]]], rails: 1 }; + const plain = synth(ride); + rideAt(plain, 80, 0); + press(plain); + until(plain, () => plain.you.x > 150, 3000); + assert.equal(plain.runner.line, 0, "a plain jump lands on the handrail"); + assert.equal(events(plain, "banSwitch").length, 0); + const dive = synth(ride); + rideAt(dive, 80, 0); + press(dive); + run(dive, 100, { down: true }); + dive.input.down = true; + until(dive, () => dive.runner.line >= 0, 3000); + dive.input.down = false; + assert.equal(dive.runner.line, 1, "a dive lands on the under-rail"); + assert.equal(dive.you.y, 13); + assert.equal(events(dive, "banSwitch").length, 1); + assert.equal(events(dive, "banSwitch")[0].lower, true); + assert.equal(dive.bonusRound.hearts, 5); + // Up from the under-rail: a jump rises through the handrail and lands on it (a switch back). + press(dive); + until(dive, () => dive.runner.line === 0, 2000); + assert.equal(dive.runner.line, 0); + assert.equal(events(dive, "banSwitch")[1].lower, false); + // Held DOWN with nothing below, a dive lands on the handrail all the same. + const only = synth({ track: FLAT }); + press(only); + run(only, 100, { down: true }); + only.input.down = true; + until(only, () => only.runner.line >= 0 && only.you.state === "run", 3000); + only.input.down = false; + assert.equal(only.runner.line, 0); + // The under-rail's end is a plunge unless the rider jumps. + const fall = synth(ride); + rideAt(fall, 250, 1); + until(fall, () => fall.bonusRound.hearts < 5, 3000); + assert.equal(fall.bonusRound.hearts, 4); + assert.equal(events(fall, "lose")[0].cause, "plunge"); + assert.deepEqual(fall.bonusRound.perf.hits, [], "an under-rail's end is not one of the graded obstacles"); + assert.equal(fall.runner.line, 0, "caught back on the handrail"); + const hop = synth(ride); + rideAt(hop, 298, 1); + press(hop); + until(hop, () => hop.you.x > 340, 3000); + assert.equal(hop.bonusRound.hearts, 5); + assert.equal(hop.runner.line, 0, "a jump at the end lands on the handrail"); +}); + +test("Ghoul Rush's Grand Banister: the last heart gone ends the round with nothing at once (no life lost, the dice in hand kept) and the run goes on to the Ballroom", () => { + const round = banRound(); + round.dice = 2; + const score = round.score; + round.bonusRound.hearts = 1; + rideAt(round, lines[0].x1 - 6, 0); + round.you.safeMs = 0; + until(round, () => round.phase === "clear", 6000); + assert.equal(round.bonusRound.hearts, 0); + assert.equal(round.bonusRound.over, true); + assert.equal(round.bonusRound.won, false); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, false); + assert.equal(end[0].dice, 0); + assert.equal(round.over, false, "no game over"); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + assert.ok(round.score >= score); + run(round, ghoul.CARD_LOST_MS + 100); + assert.equal(round.spec.id, "ballroom"); + assert.equal(round.bonusRound, null); + assert.equal(round.runner ?? null, null); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + assert.equal(round.phase, "bossintro", "the boss room opens on its card"); + skipBossIntro(ghoul, round); + assert.equal(round.phase, "ready"); +}); + +test("Ghoul Rush's Grand Banister: the checkpoints are passed in order (an event each) and the ride goes back to the last one after the last heart", () => { + const round = banRound(); + rideAt(round, R.checks[0] - 6, ct.linesAt(R, R.checks[0] - 6)[0][0]); + round.you.safeMs = 1e9; + until(round, () => round.runner.check >= 1, 4000); + const seen = events(round, "banCheck").map((e) => e.n); + assert.deepEqual(seen.slice(0, 1), [1]); + assert.ok(round.runner.check >= 0); + const c0 = round.runner.check; + round.you.x = 1; + bn.BANISTER.place[0](round, {}); + assert.equal(round.you.x, R.checks[c0]); + assert.equal(round.runner.v, bn.BAN_V); + assert.equal(round.runner.check, c0); + assert.equal(round.camLead, bn.CAM_AHEAD); + const fresh = banRound(); + assert.equal(fresh.you.x, ROOM.start); + assert.equal(fresh.runner.check, -1); + assert.equal(fresh.runner.id, "banister"); + // Another room's rider slot is not ours to take: the slot is ours only in our room. + const other = banRound(); + other.runner = { id: "tray" }; + other.spec = { ...other.spec, ride: { ...other.spec.ride, runner: "tray" } }; + bn.BANISTER.place[0](other, {}); + assert.deepEqual(other.runner, { id: "tray" }); + other.runner = { id: "banister" }; + bn.BANISTER.place[0](other, {}); + assert.equal(other.runner, null); +}); + +test("Ghoul Rush's Grand Banister: off the lip the rider launches, lands on the foyer floor and stops (banFinish), the door opens, and walking out ends the round with 3 to 9 Lucky dice", () => { + const round = banRound(); + round.dice = 1; + const last = R.rails - 1; + rideAt(round, lines[last].x1 - 12, last, { safe: true }); + until(round, () => round.runner.done, 4000); + assert.equal(round.runner.done, true); + assert.equal(events(round, "banLaunch").length, 1); + assert.equal(events(round, "banLaunch")[0].last, true); + assert.equal(events(round, "banFinish").length, 1); + assert.ok(round.you.x > R.finish + 4 && round.you.x < R.finish + 40, `${round.you.x} landed`); + assert.equal(round.you.y, floorOf(round.you.x)); + assert.equal(round.hasKey, true, "the door opens"); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.phase, "play"); + round.input.right = true; + until(round, () => round.phase === "clear", 20000); + round.input.right = false; + assert.equal(round.phase, "clear"); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, true); + assert.ok(end[0].dice >= BONUS_FLOOR && end[0].dice <= ghoul.MAX_DICE, `${end[0].dice} dice`); + assert.equal(round.dice, Math.min(ghoul.MAX_DICE, 1 + end[0].dice)); + assert.equal(round.lives, 3); + run(round, ghoul.CARD_MS + 100); + assert.equal(round.spec.id, "ballroom"); + assert.equal(round.runner ?? null, null); +}); + +test("Ghoul Rush's Grand Banister: no random number is drawn in the room (a ride of 20 seconds, jumping and shooting, on a draw that throws)", () => { + const round = banRound(); + rideAt(round, 120, 0, { safe: true }); + round.input.fire = true; + for (let t = 0; t < 20000; t += 4) { + if (t % 1500 === 0) press(round); + ghoul.advance(round, 4, never); + round.events.length = 0; + round.you.safeMs = 1e9; + if (round.phase !== "play") break; + } + assert.ok(round.you.x > 600); +}); + +/* ----------------------------------------------------------- the grade */ + +test("Ghoul Rush's Grand Banister's grade: the dice formula, shooting 8 things for the die, and the smooth slide die (braking for no more than 3 seconds in all)", () => { + const round = banRound(); + const b = round.bonusRound; + assert.equal(b.perf.goal, bn.ACTS_GOAL); + assert.equal(b.perf.total, R.props.length + R.lows.length + R.swings.length + R.butlers.length + R.rails - 1); + assert.equal(b.perf.steady, true, "a smooth slide so far"); + const mk = (perf) => { + const x = makeBonus({ stats: { kills: 0 } }); + Object.assign(x.perf, { total: b.perf.total, goal: bn.ACTS_GOAL }, perf); + return x; + }; + assert.equal(diceFor(mk({ hits: [], acts: 8, steady: true })), 9, "a perfect ride"); + assert.equal(diceFor(mk({ hits: [], acts: 7, steady: true })), 8); + assert.equal(diceFor(mk({ hits: [], acts: 8, steady: false })), 8); + const slide = synth({ track: FLAT }); + run(slide, bn.STEADY_BRAKE_MS - 200, { left: true }); + assert.equal(slide.bonusRound.perf.steady, true, "just under the limit"); + run(slide, 400, { left: true }); + assert.equal(slide.bonusRound.perf.steady, false, "too much braking"); + const lean = synth({ track: FLAT }); + run(lean, 5000, { right: true }); + assert.equal(lean.bonusRound.perf.steady, true, "leaning is no sin"); +}); + +test("Ghoul Rush's Grand Banister: endless lives (round.infinite) spare the hearts for every cause, through the same lose path", () => { + const tries = [ + { props: [[60, 0, 0]] }, { props: [[60, 0, 1]] }, { lows: [[56, 62, 23.0]] }, { butlers: [[300, 0]] }, + ]; + for (const t of tries) { + const r = synth({ track: FLAT, ...t }); + r.infinite = true; + if (t.butlers) rideAt(r, 260, 0); + until(r, () => events(r, "lose").length > 0, 3000); + assert.equal(r.bonusRound.hearts, 5, JSON.stringify(Object.keys(t))); + assert.equal(r.lives, 3); + } + const sw = synth({ track: FLAT, swings: [[100, 0, 9, 2400, 0]] }); + sw.infinite = true; + const b = bn.swingAt(sw.spec.ride, 0, 2400); + rideAt(sw, b.x - 0.2, 0); + sw.runner.clock = 2400 - 4; + run(sw, 4); + assert.equal(events(sw, "lose").length, 1); + assert.equal(sw.bonusRound.hearts, 5); + const crack = synth({ track: [[[0, 20], [60, 20]], [[75, 20], [400, 20]]] }); + crack.infinite = true; + rideAt(crack, 30, 0); + until(crack, () => events(crack, "lose").length > 0, 3000); + assert.equal(crack.bonusRound.hearts, 5); + assert.equal(crack.lives, 3); +}); + +test("Ghoul Rush's Grand Banister: the Garlic shield takes a hit instead of a heart", () => { + const round = synth({ track: FLAT, props: [[60, 0, 0]] }); + round.you.garlic = true; + until(round, () => round.you.x > 70, 3000); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.you.garlic, false, "spent"); +}); + +/* ------------------------------------------------------ sounds and words */ + +test("Ghoul Rush's Grand Banister: every event has a voice that plays, every cause has words and a sound, and the voices are tones that exist (none longer than 1.2 s)", () => { + assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...bn.EVENTS].sort(), "a voice for every event and no more"); + const tones = ghoulSfx.default.tones; + for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) { + const name = BAN_VOICES[kind] && BAN_VOICES[kind][act]; + assert.ok(name, `${event} has a ${kind}.${act} voice`); + assert.ok(tones[name], `${name} exists`); + assert.equal(VOICES[kind][act], name, "joined to the game's voices"); + const played = heard({ type: event, what: "vase", points: 50 }).played; + assert.ok(played.includes(name), `${event} plays ${name}`); + } + for (const [name, tone] of Object.entries(BANISTER_SFX.tones)) { + assert.ok(tones[name], `${name} is merged into the game`); + const length = Math.max(...tone.layers.map((l) => (l.delay || 0) + l.seconds)); + assert.ok(length <= 1.2, `${name} is ${length.toFixed(2)} s`); + } + for (const cause of ["vase", "candle", "frame", "swing", "butler", "plunge"]) { + assert.ok(LOSE_WORDS[cause], `${cause} has words`); + assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`); + assert.ok(heard({ type: "lose", cause, hearts: 3 }).played.length > 0, `${cause} sounds`); + } + assert.equal(heard({ type: "banJump" }).played.length, 1); + assert.equal(heard({ type: "banWebShot", points: 50 }).played.length, 1); +}); + +test("Ghoul Rush's Grand Banister's music is a loop of parts whose voices all run the same number of steps", () => { + const music = BANISTER_SFX.music.ghoulBanister; + assert.ok(ghoulSfx.default.music.ghoulBanister === music, "merged into the game"); + for (const [key, p] of Object.entries(music.patterns)) { + let steps = null; + for (const [voice, line] of Object.entries(p)) { + assert.ok(music.voices[voice], `${key}.${voice} is a voice`); + const n = line.split("|").join(" ").split(/\s+/).filter(Boolean).length; + if (steps === null) steps = n; + assert.equal(n, steps, `${key}.${voice} has ${n} steps, the others ${steps}`); + } + assert.equal(steps % 16, 0, "whole bars"); + } + for (const key of music.order) assert.ok(music.patterns[key]); + assert.ok(music.order.length >= 6, "a loop long enough not to grate"); +}); + +test("Ghoul Rush's Grand Banister: the room's own names do not collide with the game's (events, kinds, the shared rider slot)", () => { + for (const e of bn.EVENTS) assert.ok(e.startsWith("ban"), e); + const other = new Set(ct.EVENTS || []); + for (const e of bn.EVENTS) assert.ok(!other.has(e), `${e} is the banister's alone`); + assert.deepEqual(Object.keys(bn.BANISTER).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []); + assert.equal(typeof ghoul.ROOM_MUSIC.banister, "string"); + assert.equal(banRound().runner.id, "banister"); + assert.equal(banRound().cart, null); +}); + +/* --------------------------------------------------------------- drawing */ + +test("Ghoul Rush's Grand Banister draws: the room in a lit and a dark one, the rider on the rail, in the air and ducking, each thing (vases, candlesticks, frames, chandeliers at every point of their swing, butlers in each state, webs whole, torn and shot), a crash, the finish and the cards", () => { + const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) }); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + g.resize(900, 900); + g.key("action"); + g.tick(16); + const r = g.round; + through(r); + r.offer = ["manor"]; + r.phaseMs = 0; + ghoul.pickStage(r, 0); + while (r.spec.id !== "banister") through(r); + r.lives = 99; + const spots = [ROOM.start + 40, R.props[0][0] - 10, R.lows[0][0] - 5, R.swings[0][0] - 8, R.butlers[0][0] - 20, R.webs[0][0] - 6, R.checks[0], lines[0].x1 - 10, unders[0].x0 + 20, R.finish - 40]; + for (const dark of [true, false]) { + for (const x of spots) { + r.dark = dark; + r.phase = "play"; + for (const st of r.spawns) st.over = true; + r.hordeMs = Infinity; + r.monsters.length = 0; + const top = ct.linesAt(R, x)[0] || [R.rails - 1, 20]; + rideAt(r, x, top[0], { safe: true }); + r.runner.butlers = r.runner.butlers.map((b, i) => ({ ...b, state: ["wait", "warn", "lunge", "broken", "spent"][i % 5], t: 300 })); + r.runner.webs = r.runner.webs.map((_, i) => ["up", "torn", "shot"][i % 3]); + r.runner.clock = x * 37; + for (const air of [false, true]) { + if (air) Object.assign(r.you, { state: "air", vy: 20, y: r.you.y + 4 }); + if (air) r.runner.line = -1; + r.you.ducking = x === R.lows[0][0] - 5 && !air; + r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: -10, gone: 0 }); + for (let k = 0; k < 4; k++) g.tick(16); + r.monsters.length = 0; + r.you.safeMs = 1e9; + rideAt(r, x, top[0], { safe: true }); + } + } + } + assert.equal(r.spec.id, "banister"); + // A crash, the lip and the stop, the lost and won cards. + r.you.safeMs = 0; + rideAt(r, R.props[0][0] - 3, R.props[0][1]); + for (let k = 0; k < 30; k++) g.tick(16); + assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too"); + const done = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + done.resize(900, 900); + done.key("action"); + done.tick(16); + const d = done.round; + through(d); + d.offer = ["manor"]; + d.phaseMs = 0; + ghoul.pickStage(d, 0); + while (d.spec.id !== "banister") through(d); + d.phase = "play"; + d.runner.done = true; + d.runner.restX = R.finish + 20; + Object.assign(d.you, { x: R.finish + 30, y: 10, state: "run" }); + d.camX = R.finish - 40; + for (let k = 0; k < 10; k++) done.tick(16); + for (const won of [true, false]) { + endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) }); + d.bonusRound.over = true; + for (let k = 0; k < 10; k++) { + done.tick(16); + bonusTick(d, { tone() {}, fx: {} }); + } + d.bonusRound.over = false; + } + // The stage select goes straight into it. + const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + pick.resize(900, 900); + pick.stageSelect(); + const p = pick.round; + const at = ghoul.STAGES.findIndex((s) => s.id === "manor"); + for (let i = 0; i < at; i++) ghoul.steerSelect(p, 1, 0); + for (let i = 0; i < 3; i++) ghoul.steerSelect(p, 0, 1); + assert.equal(p.select.room, 3); + pick.tick(16); + ghoul.takeSelect(p); + assert.equal(p.spec.id, "banister"); + assert.equal(p.runner.line, 0); + assert.equal(p.you.y, ct.trackY(R, 0, ROOM.start)); + pick.tick(16); +}); + +/* ----------------------------------------------------------- the bots */ + +// A bot that rides well: it jumps at the end of a line (not the lip), 9 to 15 short of a vase or a +// candlestick on its rail, when a butler is 6 to 17 short of it and moving, ducks under every frame +// and every chandelier's swing, watches the pendulums and brakes or leans to arrive when one is +// out of the way, takes the brass under-rail where a chandelier hangs lethal over the handrail, and +// holds the blaster. `miss` is the share of things it fails to dodge (by a hash). +const mix = (a, b) => { + let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +// Whether a rider on the handrail doing `act` (-1 brake, 0 nothing, 1 lean) for the next second and a +// half and ducking meets no chandelier: the pendulums run ahead on the rider's own clock. +function swingSafe(round, act) { + const c = round.runner; + let x = round.you.x; + let v = c.v; + let t = c.clock; + for (let i = 0; i < 90; i++) { + v = Math.min(bn.BAN_MAX, Math.max(bn.BAN_MIN, v + ((bn.BAN_V - v) * bn.RELAX + (act < 0 ? -bn.BRAKE_ACC : act > 0 ? bn.LEAN_ACC : 0)) * 0.016)); + x += v * 0.016; + t += 16; + const rail = ct.trackY(R, c.line, x); + if (rail === null) return true; + for (let j = 0; j < R.swings.length; j++) { + const [cx, , amp] = R.swings[j]; + if (Math.abs(x - cx) > amp + 6) continue; + const bob = bn.swingAt(R, j, t); + if (Math.abs(x - bob.x) < (bn.SWING_BOB_W + K.HIT_W) / 2 && rail + K.DUCK_H > bob.bottom) return false; + } + } + return true; +} +function goodBot(round, seed, miss = 0.04, { lower = true, timing = true } = {}) { + const { you, runner: c, input: inp } = round; + inp.left = inp.right = inp.down = false; + inp.fire = true; + if (round.phase !== "play" || !c || c.done) { + inp.up = false; + return; + } + const ok = (x) => mix(seed, Math.round(x)) >= miss; + const look = 9 + (seed % 7); + let jump = false; + if (c.line >= 0) { + round.__dive = false; + const line = c.line; + const L = lines[line]; + const isLower = line >= R.rails; + if (!isLower && line < R.rails - 1 && L.x1 - you.x < 2.2 && ok(L.x1)) jump = true; + if (isLower && L.x1 - you.x < 2.2) jump = true; + const ahead = (x) => x - you.x > 6 && x - you.x < look; + for (const [x, ln] of R.props) if (ln === line && ahead(x) && ok(x)) jump = true; + R.butlers.forEach(([, ln], i) => { + const b = c.butlers[i]; + if (ln === line && (b.state === "warn" || b.state === "lunge") && b.x - you.x > 6 && b.x - you.x < 17 && ok(b.x)) jump = true; + }); + for (const [x0, x1] of R.lows) if (!isLower && you.x > x0 - 10 && you.x < x1 + 3 && ok(x0)) inp.down = true; + R.swings.forEach(([cx, , amp]) => { + if (!isLower && you.x > cx - amp - 12 && you.x < cx + amp + 8 && ok(cx)) inp.down = true; + }); + if (timing && !isLower && !swingSafe(round, 0)) { + if (swingSafe(round, -1)) inp.left = true; + else if (swingSafe(round, 1)) inp.right = true; + } + // The fork: where a chandelier hangs lethal over a split, jump from before its start and dive onto the brass. + if (lower && !isLower) { + for (const U of unders) { + const under = R.swings.some(([cx], i) => cx > U.x0 && cx < U.x1 && nominal()[i]); + if (under && U.x0 - you.x > 6 && U.x0 - you.x < 13) { + jump = true; + round.__dive = true; + } + } + } + if (round.__dive) inp.down = true; + } else if (round.__dive) inp.down = true; + if (jump && (!inp.down || round.__dive)) press(round); + else inp.up = false; +} +// The chandeliers that hang lethal to a ducking rider at the time the stairs bring him to them (the +// ones the room has phased to the middle of the swing at the arrival of a rider on the handrail who +// jumps everything and times nothing, nothing able to hurt him): found by that ride, once. +let NOMINAL = null; +function nominal() { + if (NOMINAL) return NOMINAL; + const round = banRound(); + const out = R.swings.map(() => null); + for (let t = 0; t < 120000 && !round.runner.done; t += 16) { + round.you.safeMs = 1e9; + goodBot(round, 1, 0, { lower: false, timing: false }); + ghoul.advance(round, 16, steady); + R.swings.forEach(([cx], i) => { + if (out[i] === null && round.you.x >= cx) out[i] = round.runner.clock; + }); + } + NOMINAL = out.map((T, i) => Math.abs(bn.swingAt(R, i, T).u) < 0.2); + return NOMINAL; +} +function idleBot(round) { + const inp = round.input; + inp.left = inp.right = inp.down = false; + inp.up = false; + inp.fire = true; +} +function rideWith(seed, bot, limit = 100000) { + const round = banRound(seed); + const lost = []; + let t = 0; + for (; t < limit && round.phase !== "clear" && !round.over; t += 16) { + bot(round); + if (round.runner && round.runner.done && round.phase === "play") round.input.right = true; + ghoul.advance(round, 16, steady); + for (const e of round.events) if (e.type === "lose") lost.push(e.cause); + if (round.runner && !round.runner.done) { + const off = round.you.x - round.camX; + assert.ok(off > 4 && off < 70, `the rider stays in view (${off.toFixed(1)} from the left edge at ${round.you.x.toFixed(0)})`); + } + round.events.length = 0; + } + return { round, lost, ms: t }; +} + +test("Ghoul Rush's Grand Banister: the chandeliers hang lethal to a ducking rider on the handrail where the room says so (two of them, each over a split with an under-rail beneath), and the rest pass a rider who ducks", () => { + const lethal = nominal(); + assert.equal(lethal.filter(Boolean).length, 2, `lethal at the nominal time: ${lethal.join(",")}`); + lethal.forEach((is, i) => { + if (!is) return; + const [cx] = R.swings[i]; + assert.ok(unders.some((U) => cx > U.x0 && cx < U.x1), `chandelier ${i} hangs over an under-rail`); + }); + assert.equal(lethal[0], false, "the first one is kind"); +}); + +test("Ghoul Rush's Grand Banister: a bot that rides well finishes the whole stair in 60 to 75 seconds, 7 to 9 dice, a few hearts lost at most, past every checkpoint", () => { + const dice = []; + for (let seed = 1; seed <= 12; seed++) { + const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed)); + const b = round.bonusRound; + assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")})`); + assert.ok(ms > 60000 && ms < 76000, `${ms} ms`); + assert.ok(b.dice >= 6 && b.dice <= ghoul.MAX_DICE, `${b.dice} dice`); + assert.equal(round.lives, 3, "never a run life"); + assert.equal(round.runner.check, R.checks.length - 1, "past every checkpoint"); + dice.push(b.dice); + } + assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 6.5, `${dice.join(",")}`); +}); + +test("Ghoul Rush's Grand Banister: a rider who stays on the handrail and ignores the pendulums is hit by the two lethal chandeliers, while the same rider braking or leaning to time them passes both (and one on the under-rail never meets them)", () => { + const swings = (r) => r.lost.filter((c) => c === "swing").length; + const blind = rideWith(3, (r) => goodBot(r, 3, 0, { lower: false, timing: false })); + assert.ok(swings(blind) >= 1, `lost ${blind.lost.join(",")}`); + const timed = rideWith(3, (r) => goodBot(r, 3, 0, { lower: false, timing: true })); + assert.equal(swings(timed), 0, `lost ${timed.lost.join(",")}`); + assert.equal(timed.round.bonusRound.won, true); + const under = rideWith(3, (r) => goodBot(r, 3, 0, { lower: true, timing: false })); + assert.equal(swings(under), 0, `lost ${under.lost.join(",")}`); + assert.equal(under.round.bonusRound.won, true); +}); + +test("Ghoul Rush's Grand Banister: a bot that never dodges (holding fire) loses all five hearts before the first third, ends with 0 dice and the run goes on", () => { + for (let seed = 1; seed <= 6; seed++) { + const { round, lost } = rideWith(seed, idleBot); + const b = round.bonusRound; + assert.equal(b.won, false, "never finishes"); + assert.equal(b.dice, 0); + assert.equal(b.hearts, 0); + assert.equal(lost.length, 5); + assert.ok(round.you.x < ROOM.length * 0.45, `out at ${round.you.x}`); + assert.equal(round.lives, 3); + assert.equal(round.over, false); + } +}); + +/* ------------------------------------------------------------ telegraphs */ + +test("Ghoul Rush's Grand Banister telegraphs: DUCK over frames and chandeliers, JUMP over breaks, vases, candlesticks and the end of an under-rail, DIVE at the start of one, none for butlers or webs, words only on the first three of each kind, the same every time", () => { + const marks = telegraphMarks(R); + const answers = { gap: "JUMP", vase: "JUMP", candle: "JUMP", frame: "DUCK", swing: "DUCK", end: "JUMP", dive: "DIVE" }; + const vases = R.props.filter((p) => !p[2]).length; + assert.equal(marks.length, (R.rails - 1) + R.props.length + R.lows.length + R.swings.length + 2 * unders.length, "no mark for butlers or webs"); + for (const m of marks) assert.equal(m.answer, answers[m.kind], m.kind); + assert.equal(marks.filter((m) => m.kind === "vase").length, vases); + assert.equal(marks.filter((m) => m.kind === "dive").length, unders.length); + const m = marks.find((q) => q.kind === "frame"); + const xs = [m.lead - 45, m.lead - 41, m.lead - 36, m.lead - 30, m.lead - 10, m.lead, m.lead + 3, m.lead + 7]; + const alphaOf = (x) => (telegraphs(R, x).find((t) => t.kind === "frame" && t.lead === m.lead) || { alpha: 0 }).alpha; + const a = xs.map(alphaOf); + assert.equal(a[0], 0, "not yet in view"); + assert.ok(a[2] > 0 && a[2] < 1, "fading in 40 to 30 ahead"); + assert.equal(a[3], 1); + assert.equal(a[4], 1); + assert.ok(a[6] > 0 && a[6] < 1, "fading as it passes"); + assert.equal(a[7], 0, "gone once passed"); + assert.deepEqual(telegraphs(R, m.lead - 33), telegraphs(R, m.lead - 33), "deterministic"); + for (const kind of ["gap", "frame", "swing", "dive", "end"]) { + const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead); + assert.ok(of.length >= 5, kind); + of.forEach((q, i) => { + assert.equal(q.n, i); + const shown = telegraphs(R, q.lead - 32).find((t) => t.lead === q.lead && t.kind === kind); + assert.equal(shown.words, i < 3, `${kind} ${i}`); + }); + } +}); + +test("Ghoul Rush's Grand Banister's intro banner says the controls plainly", () => { + assert.match(R.how, /UP jump, DOWN duck/); + assert.match(R.how, /dive/); + assert.match(R.how, /LEFT brake/); +}); + diff --git a/scripts/test-web-console-activities-ghoul-bog.mjs b/scripts/test-web-console-activities-ghoul-bog.mjs new file mode 100644 index 0000000..88ec3b5 --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-bog.mjs @@ -0,0 +1,990 @@ +// Web console tests, Ghoul Rush's Gallows Bog stage: the pack skeleton (the +// lurker, the leech swarm, the will-o'-wisp, the bog body and Old Mother Bog +// joined to the game's tables), the stage row and its five rooms' shapes, the +// mud spans that slow and sink you, the Bog Runner's stub and the Drowning +// Pool's boss spec. The monsters' rules, the fight and the ride land in +// later phases. +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import * as bog from "../src/web-console/public/activities/ghoul-bog.js"; +import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js"; +import { LOSE_SOUNDS, LOSE_WORDS, VOICES } from "../src/web-console/public/activities/ghoul-bog-draw.js"; +import { BOG_SFX } from "../src/web-console/public/activities/ghoul-sfx-bog.js"; +import { BOSS_INTROS, bossIntroFor } from "../src/web-console/public/activities/ghoul-boss-intros.js"; +import { INTROS, introFor } from "../src/web-console/public/activities/ghoul-intros.js"; +import { react } from "../src/web-console/public/activities/ghoul-draw.js"; + +const steady = () => 0.5; +const events = (round, type) => round.events.filter((e) => e.type === type); +const ROOM_IDS = ["boardwalk", "hollow", "stilts", "bogboat", "drowning"]; + +function through(round) { + round.phase = "clear"; + round.phaseMs = 1; + ghoul.advance(round, 4, steady); +} + +// A round in the Gallows Bog room `id`, reached the way play reaches it (out +// of the hall, the stage picked, the rooms before it gone through), nothing +// woken. +function bogRound(id) { + const round = ghoul.newRound(5); + round.dice = 0; + through(round); + assert.equal(round.phase, "pick"); + round.offer = ["bog"]; + round.phaseMs = 0; + ghoul.pickStage(round, 0); + while (round.spec.id !== id) through(round); + round.phase = "play"; + for (const st of round.spawns) st.over = true; + round.monsters.length = 0; + round.hordeMs = Infinity; + round.items.fill(true); + round.candy.fill(true); + round.sky.fill(true); + round.events.length = 0; + return round; +} + +function standAt(round, x, shelf = -1) { + const y = shelf >= 0 ? round.spec.shelves[shelf][2] : ghoul.groundAt(round.spec, x); + Object.assign(round.you, { x, y, vx: 0, vy: 0, state: "run", shelf, coyote: 0, drop: -1, cuttable: false, out: 0, safeMs: 0 }); + round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 36)); +} + +function run(round, ms, keys = {}, random = steady) { + Object.assign(round.input, keys); + for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random); + for (const k of Object.keys(keys)) round.input[k] = false; +} + +/* ------------------------------------------------------------ the stage */ + +test("Ghoul Rush's Gallows Bog is a stage of five rooms ending on the Drowning Pool, its kinds and boss joined to the game's, last in the list", () => { + const st = ghoul.stageById("bog"); + assert.deepEqual(st.rooms, ROOM_IDS); + assert.equal(st.boss, "motherbog"); + assert.equal(st.title, "Gallows Bog"); + assert.equal(st.sub, "The mud does not like to let go"); + assert.equal(ghoul.STAGES.at(-1), st, "the last stage in the list"); + for (const kind of Object.keys(bog.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], bog.MONSTERS[kind], `${kind} is a monster`); + assert.deepEqual(Object.keys(bog.MONSTERS).sort(), ["bogbody", "leech", "lurker", "wisp"]); + assert.equal(ghoul.BOSSES.motherbog, bog.BOSSES.motherbog); + assert.equal(bog.BOSSES.motherbog.name, "Old Mother Bog"); + assert.equal(bog.BOSSES.motherbog.sub, "Keep to the planks, she owns the water"); + assert.equal(bog.BOG.id, "bog"); + for (const key of ["walkers", "zombies", "act", "swoops", "solid", "unseen", "move", "kill", "horde", "tick", "bosses", "boss", "weak", "cause", "hazards"]) assert.ok(key in bog.BOG, `the pack carries ${key}`); + assert.deepEqual(bog.BOG.zombies, ["bogbody"], "the bog body counts as a zombie"); + for (const id of ROOM_IDS) { + assert.ok(ghoul.roomById(id), `${id} resolves`); + assert.ok(ghoul.ROOM_MUSIC[id], `${id} has music`); + assert.ok(Object.hasOwn(ghoulSfx.default.music, ghoul.ROOM_MUSIC[id]), `${id}'s track exists`); + } +}); + +test("Ghoul Rush's bog rooms carry the usual pieces: a key, sky treasures, candy, items and a horde in each walked room, mud spans frozen, the ride its own course, the arena the hag's", () => { + const [boardwalk, hollow, stilts, bogboat, drowning] = ROOM_IDS.map((id) => ghoul.roomById(id)); + assert.deepEqual([boardwalk.title, hollow.title, stilts.title, bogboat.title, drowning.title], ["Sunken Boardwalk", "Cypress Hollow", "Stilt House", "The Bog Runner", "The Drowning Pool"]); + assert.deepEqual([boardwalk.sub, hollow.sub, stilts.sub, drowning.sub], ["Mind the gaps. Something lives in them", "The moss is breathing", "She has been expecting you", "Keep to the planks, she owns the water"]); + for (const room of [boardwalk, hollow, stilts]) { + assert.ok(room.key, `${room.id}: a key`); + assert.ok(room.door > room.length - 14, `${room.id}: the door at the end`); + assert.ok(room.sky.length && room.candy.length && room.items.length && room.horde.length, `${room.id}: sky treasures, candy, items and a horde`); + const wings = room.items.find((i) => i[0] === "wings"); + assert.ok(wings && wings[1] < Math.min(...room.sky.map(([, x]) => x)), `${room.id}: wings on the way to the sky`); + assert.ok(room.mud.length >= 1, `${room.id}: mud spans`); + for (const span of room.mud) assert.ok(Object.isFrozen(span), `${room.id}: a mud span is frozen`); + for (const kind of room.horde) assert.ok(ghoul.MONSTERS[kind], `${room.id}: ${kind} is a monster`); + assert.equal(room.boss, null, `${room.id}: no boss`); + assert.equal(room.dark, null, `${room.id}: dark or lit by the roll`); + } + assert.ok(hollow.water.length && stilts.water.length, "the hollow and the stilts keep pools beside the mud"); + assert.ok(boardwalk.shelves.some((s) => s[3] === "crumble") && hollow.shelves.some((s) => s[3] === "crumble") && stilts.shelves.some((s) => s[3] === "crumble"), "rotting boards that give way"); + // The Bog Runner is a stub: a bonus ride with empty obstacle arrays that + // Phase 4's deterministic generator fills in. + assert.equal(bogboat.bonus, true); + assert.equal(bogboat.dark, false); + assert.equal(bogboat.key, null); + assert.equal(bogboat.boss, null); + assert.equal(bogboat.horde.length, 0); + assert.equal(bogboat.ride.runner, "bogboat"); + assert.equal(bogboat.ride.how, "LEFT or RIGHT at a bank: switch lane. UP jump, DOWN duck, SPACE shoot"); + assert.ok(bogboat.ride.time >= 70000 && bogboat.ride.time <= 120000); + assert.ok(bogboat.ride.finish > 0 && bogboat.ride.finish < bogboat.length); + assert.ok(bogboat.ride.checks.length >= 1 && bogboat.ride.checks.every((x) => x > 0 && x < bogboat.ride.finish), "checkpoints inside the run"); + assert.ok(Object.isFrozen(bogboat.ride), "the ride is frozen"); + assert.equal(drowning.boss, "motherbog"); + assert.equal(drowning.key, null); + assert.equal(drowning.horde.length, 0); + assert.equal(drowning.dark, null, "the arena rolls dark or lit"); + assert.ok(drowning.length - ghoul.FIELD_W > 30, "room to walk into the arena"); +}); + +/* ---------------------------------------------------------- the mud */ + +test("Ghoul Rush's mud slows a run the longer you stand in it, down to a crawl, and lets go on dry floor", () => { + const round = bogRound("boardwalk"); + const inMud = round.spec.mud[0][0] + 2; + standAt(round, inMud); + round.you.safeMs = 1e9; + run(round, 200, { right: true }); + assert.equal(round.you.mud, true, "in the span you are muddy"); + // Fresh mud drags like water; the run crawls as the sink deepens. + standAt(round, inMud); + const x0 = round.you.x; + run(round, 1000, { right: true }); + const early = round.you.x - x0; + assert.ok(round.you.mudMs > 900, `sunk a second (${round.you.mudMs} ms)`); + run(round, 1800, { right: true }); + const x1 = round.you.x; + run(round, 1000, { right: true }); + const late = round.you.x - x1; + assert.ok(late < early * 0.6, `deeper is slower (${early.toFixed(1)} then ${late.toFixed(1)})`); + // Out of the mud it drains away. + round.you.mudMs = 2000; + standAt(round, 290); + run(round, 500, { right: true }); + assert.equal(round.you.mud, false); + assert.ok(round.you.mudMs < 2000, `it lets go (${round.you.mudMs} ms)`); +}); + +test("Ghoul Rush's mud cuts a jump lower the deeper you sink, and a shelf keeps you out of it", () => { + const round = bogRound("boardwalk"); + const inMud = round.spec.mud[0][0] + 2; + // A fresh jump in mud leaves near WATER_JUMP of full speed; a sunk one nears MUD_JUMP_MIN. + const jumpV = (ms) => { + standAt(round, inMud); + round.you.mudMs = ms; + run(round, 4, {}); + round.input.jump = ghoul.JUMP_BUFFER_MS; + ghoul.advance(round, 4, steady); + return round.you.vy; + }; + const fresh = jumpV(0); + const sunk = jumpV(ghoul.MUD_MS); + // The vy read is one gravity slice after the jump itself. + assert.ok(Math.abs(fresh - ghoul.JUMP_V * ghoul.WATER_JUMP) < 2, `fresh mud jumps near water height (${fresh.toFixed(1)})`); + assert.ok(Math.abs(sunk - ghoul.JUMP_V * ghoul.MUD_JUMP_MIN) < 2, `sunk jumps near the floor of it (${sunk.toFixed(1)})`); + assert.ok(sunk < fresh, "the deeper the sink, the lower the jump"); + // On a shelf over the mud there is no sinking. + const shelf = round.spec.shelves.findIndex(([a, b]) => round.spec.mud.some(([m0, m1]) => a < m1 && b > m0)); + assert.ok(shelf >= 0, "a board over the mud to stand on"); + const [a, b] = round.spec.shelves[shelf]; + standAt(round, (a + b) / 2, shelf); + run(round, 300, {}); + assert.equal(round.you.mud, false, "a board over the mud is dry"); +}); + +test("Ghoul Rush's wisp lure pulls the dead inside a bright wisp's light and lets go when it dims, and never touches another stage's lure", () => { + const round = bogRound("boardwalk"); + standAt(round, 20); + round.you.safeMs = 60000; + const wisp = ghoul.spawnMonster(round, "wisp", 24, 10); + const risen = ghoul.spawnMonster(round, "bogbody", 28, ghoul.groundAt(round.spec, 28)); + run(round, 40, {}); + assert.ok(risen.lure > 0 && risen.hasteMs > 0 && risen.haste === bog.WISP_HASTE, "in the light it is pulled, a step quicker"); + wisp.act = "dim"; + run(round, 8, {}); + assert.equal(risen.lure, 0, "a shot-out wisp lets it go"); + // In any other stage the same fields belong to another pack (the moth's call). + const hall = ghoul.newRound(5); + const moth = ghoul.spawnMonster(hall, "zombie", 20, 6); + moth.lure = 500; + moth.hasteMs = 500; + ghoul.advance(hall, 4, steady); + assert.equal(moth.lure, 500, "the hall's lure is not the wisp's to clear"); +}); + +/* ------------------------------------------------------ monsters */ + +const put = (round, kind, x, over = {}) => ghoul.spawnMonster(round, kind, x, over.y ?? ghoul.groundAt(round.spec, x), over); + +// Runs until `done()` (or `ms` have passed), 4 ms at a time. +function until(round, done, ms = 4000) { + for (let t = 0; t < ms && !done(); t += 4) ghoul.advance(round, 4, steady); +} + +const tx2 = (e) => e.tx2; + +// A bolt arriving from the left at height `y` on the monster `m`. +const bolt = (round, m, y, extra = {}) => round.shots.push({ x: m.x - m.w / 2 - 0.3, y, vx: 80, vy: 0, gone: 0, ...extra }); + +// A hollow x on dry floor with open floor to either side. +const dry = (round, x) => { + assert.ok(Number.isFinite(ghoul.groundAt(round.spec, x)), `floor at ${x}`); + return x; +}; + +test("Ghoul Rush's lurker is eyes you cannot touch or shoot until you cross it, then snaps out of the water solid and sinks back", () => { + const round = bogRound("hollow"); + standAt(round, dry(round, 20)); + round.you.safeMs = 1e9; + const m = put(round, "lurker", 60); + assert.equal(m.act, "eyes"); + run(round, 8); + assert.equal(m.unseen, true, "eyes are unseen"); + assert.equal(ghoul.solid(m), false, "nothing to stomp or hit"); + bolt(round, m, m.y + 1); + run(round, 40); + assert.equal(m.hp, m.max, "a bolt goes through the eyes"); + assert.equal(events(round, "lurkerSnap").length, 0, "far away it stays down"); + // Cross into its range: it snaps, solid and lunging at you. + standAt(round, m.x - bog.SNAP_RANGE + 2); + round.you.safeMs = 1e9; + run(round, 8); + assert.equal(m.act, "snap"); + assert.equal(events(round, "lurkerSnap").length, 1); + assert.equal(ghoul.solid(m), true, "snapping it is solid"); + const x0 = m.x; + run(round, 200); + assert.ok(Math.abs(m.x - x0) > 1, "it lunges"); + // The snap ends in a sink, then eyes again. + run(round, bog.SNAP_MS); + assert.equal(events(round, "lurkerSink").length, 1); + assert.ok(m.act === "sink" || m.act === "eyes"); + run(round, bog.LURKER_SINK_MS + 40); + assert.ok(m.act === "eyes" || m.act === "snap", "back to eyes (or snapping again if you are still near)"); + // Eyes at the waterline do no harm when you walk through them with the shield down. + const calm = bogRound("hollow"); + standAt(calm, 20); + calm.you.safeMs = 0; + const e = put(calm, "lurker", 20, { act: "eyes" }); + calm.you.out = 1000; + run(calm, 30); + assert.equal(events(calm, "lose").length, 0); + assert.equal(e.act, "eyes", "a player who is out never wakes it"); +}); + +test("Ghoul Rush's leech swarm latches for one heart on touch, drops off and cannot latch again at once, and a hit disperses it", () => { + const round = bogRound("hollow"); + standAt(round, dry(round, 30)); + round.you.safeMs = 0; + const hearts = round.lives; + const m = put(round, "leech", 30); + run(round, 8); + assert.equal(events(round, "leechLatch").length, 1, "one latch"); + assert.equal(events(round, "lose")[0]?.cause, "leeches", "it costs a heart, named for the leeches"); + assert.equal(m.act, "drop"); + assert.equal(round.lives, hearts - 1, "exactly one heart"); + // It drops off for LEECH_DROP_MS, then drifts again; a second latch waits LEECH_AGAIN_MS. + const lives = round.lives; + round.you.safeMs = 0; + run(round, bog.LEECH_DROP_MS + 20); + assert.equal(m.act === "drift" || m.act === "drop", true); + assert.ok(m.latchIn > 0, "cannot latch again yet"); + assert.equal(events(round, "leechLatch").length, 1, "still the one latch"); + assert.equal(round.lives, lives); + // Stomp-free dispersal: a bolt takes LEECH hp, the swarm comes apart. + const swarm = put(round, "leech", 60); + standAt(round, 30); + round.you.safeMs = 1e9; + ghoul.hurt(round, swarm, 99, "shot"); + assert.equal(events(round, "leechDie").length, 1, "the swarm comes apart"); +}); + +test("Ghoul Rush's will-o'-wisp is hit only while bright: a bolt puts it out, it stays dim, glows where it will return, then burns again", () => { + const round = bogRound("boardwalk"); + standAt(round, 20); + round.you.safeMs = 1e9; + const m = put(round, "wisp", 40, { y: 10 }); + assert.equal(m.act, "bright"); + assert.equal(ghoul.solid(m), true); + bolt(round, m, m.y + m.h / 2); + run(round, 4); + assert.equal(m.act, "dim", "a bolt puts it out"); + assert.equal(events(round, "wispOut").length, 1); + assert.equal(ghoul.solid(m), false, "a dim wisp is no target and no threat"); + assert.ok(m.relight && Number.isFinite(m.relight.x), "the spot it returns to is seeded"); + run(round, bog.WISP_RELIGHT_MS - 100); + assert.equal(m.act, "dim", "stays dim for the relight time"); + run(round, 200); + assert.equal(m.act, "rekindle"); + assert.equal(events(round, "wispRelight").length, 1); + assert.equal(ghoul.solid(m), false, "glowing is not yet burning"); + run(round, bog.WISP_REKINDLE_MS + 20); + assert.equal(m.act, "bright"); + assert.equal(events(round, "wispOn").length, 1); + // A dim wisp is a dip you can pass through: touching it costs nothing. + const pass = bogRound("boardwalk"); + standAt(pass, 20); + pass.you.safeMs = 0; + put(pass, "wisp", 20, { y: pass.you.y + 1, act: "dim", wait: 5000 }); + run(pass, 40); + assert.equal(events(pass, "lose").length, 0); +}); + +test("Ghoul Rush's bog body climbs out of the mud harmless, then shambles toward you", () => { + const round = bogRound("boardwalk"); + standAt(round, 20); + round.you.safeMs = 1e9; + const m = put(round, "bogbody", 50); + assert.equal(m.act, "rise"); + run(round, 8); + assert.ok(m.rise > 0, "climbing out"); + assert.equal(ghoul.solid(m), false, "harmless while it rises"); + assert.equal(events(round, "bogRise").length, 1); + const x0 = m.x; + run(round, 300); + assert.equal(m.x, x0, "it does not walk while it climbs"); + run(round, bog.BOG_RISE_MS); + assert.equal(m.act, "walk"); + assert.equal(ghoul.solid(m), true); + const x1 = m.x; + run(round, 400); + assert.ok(m.x < x1 - 1, "it walks toward you"); + // One that comes in with the horde is already up. + const up = put(round, "bogbody", 80, { horde: true }); + run(round, 8); + assert.equal(up.act, "walk"); + assert.equal(events(round, "bogRise").length, 1, "no second climb"); +}); + +/* ------------------------------------------------------ the lure */ + +test("Ghoul Rush's bright wisp lures monsters inside WISP_LURE toward you at WISP_HASTE times their speed, and shot out the pull ends", () => { + const walked = (withWisp) => { + const round = bogRound("boardwalk"); + standAt(round, 20); + round.you.safeMs = 1e9; + const m = put(round, "bogbody", 70, { rise: 0, act: "walk" }); + if (withWisp) put(round, "wisp", 70, { y: 10 }); + const x0 = m.x; + run(round, 1000); + return { m, round, dx: x0 - m.x }; + }; + const plain = walked(false); + const lured = walked(true); + assert.equal(plain.m.lure || 0, 0); + assert.ok(lured.m.lure > 0, "pulled"); + assert.ok(lured.m.haste <= bog.WISP_HASTE, "never past the cap"); + const ratio = lured.dx / plain.dx; + assert.ok(ratio > 1.1 && ratio < bog.WISP_HASTE + 0.05, `about ${bog.WISP_HASTE}x, not more (${ratio.toFixed(2)})`); + assert.equal(events(lured.round, "wispLure").length, 1, "the pull is announced once"); + // Out of reach of a bright light it is no quicker. + const round = bogRound("boardwalk"); + standAt(round, 20); + round.you.safeMs = 1e9; + const far = put(round, "bogbody", 75, { rise: 0, act: "walk" }); + const w = put(round, "wisp", 75 - bog.WISP_LURE - 6, { y: 10 }); + run(round, 100); + assert.equal(w.act, "bright", "the wisp is burning"); + assert.equal(far.lure || 0, 0, "a bright wisp out of reach lures nobody"); + assert.equal(far.haste || 1, 1); + // Shot out, the pull ends at once; a monster beyond the radius is not drawn. + const shot = bogRound("boardwalk"); + standAt(shot, 20); + shot.you.safeMs = 1e9; + const walker = put(shot, "bogbody", 70, { rise: 0, act: "walk" }); + const light = put(shot, "wisp", 72, { y: 10 }); + run(shot, 60); + assert.ok(walker.lure > 0); + light.act = "dim"; + light.wait = 1e9; + run(shot, 8); + assert.equal(walker.lure, 0); + assert.equal(walker.hasteMs, 0); + assert.equal(walker.haste, 1); +}); + +test("Ghoul Rush's wisp lure stays fair in a horde: every monster in the light is capped at WISP_HASTE, a wisp never lures another wisp, and shooting the wisp out frees the lot", () => { + const round = bogRound("boardwalk"); + standAt(round, 20); + round.you.safeMs = 1e9; + const pack = [put(round, "bogbody", 70, { rise: 0, act: "walk" }), put(round, "bogbody", 75, { rise: 0, act: "walk" }), put(round, "leech", 72), put(round, "bogbody", 78, { rise: 0, act: "walk" })]; + const lights = [put(round, "wisp", 74, { y: 10 }), put(round, "wisp", 76, { y: 11 })]; + run(round, 120); + for (const m of pack) { + assert.ok(m.lure > 0, `${m.kind} is lured`); + assert.ok(m.haste <= bog.WISP_HASTE + 1e-9, `${m.kind} at ${m.haste}x`); + } + for (const w of lights) assert.equal(w.lure || 0, 0, "a wisp is never lured by a wisp"); + // Two lights do not stack: the cap is the cap. + assert.equal(new Set(pack.map((m) => m.haste)).size, 1); + for (const w of lights) { + bolt(round, w, w.y + w.h / 2); + run(round, 8); + } + run(round, 20); + for (const m of pack) assert.equal(m.lure, 0, `${m.kind} is let go`); +}); + +/* ---------------------------------------------------------- mud, boots, harpoon */ + +test("Ghoul Rush's mud holds you only on its spans and on the ground: a jump lets go of the sink, mudMs builds and drains, and the speed bottoms out at MUD_SPEED_MIN", () => { + const round = bogRound("boardwalk"); + const [a, b] = round.spec.mud[0]; + standAt(round, a + 3); + round.you.safeMs = 1e9; + run(round, 4); + assert.equal(round.you.mud, true, "on the span"); + standAt(round, a - 3); + run(round, 4); + assert.equal(round.you.mud, false, "just off it"); + standAt(round, b + 3); + run(round, 4); + assert.equal(round.you.mud, false, "past it"); + // In the air over the mud nothing sinks. + standAt(round, a + 3); + round.you.y += 4; + round.you.vy = 0; + round.you.state = "fall"; + run(round, 4); + assert.equal(round.you.mud, false, "airborne is dry"); + // mudMs builds one-for-one and drains the same way, never below zero. + standAt(round, a + 3); + round.you.mudMs = 0; + run(round, 400); + assert.ok(round.you.mudMs >= 380 && round.you.mudMs <= 440, `built (${round.you.mudMs})`); + standAt(round, a - 20); + run(round, 10000); + assert.equal(round.you.mudMs, 0, "never below zero"); + // At full sink the run is a crawl: MUD_SPEED_MIN of a dry run's reach over the same time. + const reach = (mudMs, x) => { + standAt(round, x); + round.you.mudMs = mudMs; + const x0 = round.you.x; + run(round, 160, { right: true }); + return round.you.x - x0; + }; + const dryReach = reach(0, 270); + const fresh = reach(0, a + 3); + const sunk = reach(ghoul.MUD_MS, a + 3); + assert.ok(sunk < fresh && fresh < dryReach, `dry ${dryReach.toFixed(1)} > fresh ${fresh.toFixed(1)} > sunk ${sunk.toFixed(1)}`); + assert.ok(sunk / dryReach < ghoul.MUD_SPEED_MIN + 0.12, `crawls (${(sunk / dryReach).toFixed(2)} of dry)`); + assert.ok(ghoul.MUD_SPEED_MIN < ghoul.WATER_SPEED && ghoul.MUD_JUMP_MIN < ghoul.WATER_JUMP, "mud is always worse than water"); +}); + +test("Ghoul Rush's Stilt Boots let the mud go while they last, and the mud takes hold again after", () => { + const round = bogRound("boardwalk"); + const [a] = round.spec.mud[0]; + standAt(round, a + 3); + round.you.safeMs = 1e9; + round.effects.boots = 300; + run(round, 100); + assert.equal(round.you.mud, false, "boots neutralize it"); + assert.equal(round.you.mudMs, 0); + const x0 = round.you.x; + run(round, 100, { right: true }); + const booted = round.you.x - x0; + assert.ok(booted > 0); + round.effects.boots = 0; + standAt(round, a + 3); + run(round, 8); + assert.equal(round.you.mud, true, "the mud takes hold again"); + assert.equal(ghoul.POWERS.boots.stage, "bog"); +}); + +test("Ghoul Rush's harpoon pierces everything in its line, reaches a lurker's eyes under the water that any other bolt passes through, and a plain bolt does not", () => { + const round = bogRound("hollow"); + standAt(round, dry(round, 20)); + round.you.safeMs = 1e9; + const near = put(round, "lurker", 50); + const far = put(round, "lurker", 70); + run(round, 8); + assert.equal(near.unseen && far.unseen, true); + const harpoon = () => ({ arm: "harpoon", x: 30, y: near.y + 1, vx: 84, vy: 0, gone: 0, t: 0, spin: 0, dmg: 14, bossDmg: 8, pierce: true }); + // A plain bolt flies through both pairs of eyes. + round.shots.push({ x: 30, y: near.y + 1, vx: 80, vy: 0, gone: 0 }); + run(round, 600); + assert.equal(near.hp, near.max); + assert.equal(far.hp, far.max); + assert.equal(events(round, "harpoonHit").length, 0); + // A harpoon finds the first, goes on through it and finds the second. + round.shots.push(harpoon()); + run(round, 800); + assert.equal(events(round, "harpoonHit").length, 2, "one hit for each, none twice"); + assert.ok(near.dead || near.hp < near.max, "the near lurker is hurt"); + assert.ok(far.dead || far.hp < far.max, "the far one too"); + assert.equal(events(round, "kill").length, 2, "14 damage is enough for a lurker"); +}); + +/* ------------------------------------------------------ Old Mother Bog */ + +// The Drowning Pool with the hag awake and fighting, nothing else on the field. +function motherFight() { + const round = bogRound("drowning"); + standAt(round, round.spec.arena + ghoul.BOSS_LOCK + 2); + ghoul.advance(round, 4, steady); + ghoul.advance(round, ghoul.BOSS_INTRO_MS + 8, steady); + assert.equal(round.boss.state, "fight"); + round.you.safeMs = 0; + round.events.length = 0; + return round; +} + +// Straight to her next move, as if her wait had run out. +const hurry = (b) => (b.wait = 0); + +test("Old Mother Bog's mud wave winds up, rolls down the planks at you, and is jumped: standing in it costs a heart (swamped), a jump clears it", () => { + const round = motherFight(); + const b = round.boss; + assert.equal(b.kind, "motherbog"); + assert.equal(b.hp, bog.BOSSES.motherbog.hp); + standAt(round, 150); + b.act = "idle"; + hurry(b); + run(round, 8); + assert.equal(b.act, "wind", "the first move is the wave"); + assert.equal(events(round, "motherWind").length, 1, "a wind-up to read"); + assert.equal(round.waves.length, 0, "nothing rolls during the wind-up"); + run(round, bog.MOTHER_WIND_MS + 20); + assert.equal(events(round, "mudWave").length, 1); + assert.equal(round.waves[0]?.cause, "mudwave"); + assert.equal(b.act, "rest"); + // Stand still: it arrives and swamps you. + const stand = round.you.x; + until(round, () => events(round, "lose").length > 0, 3000); + assert.equal(events(round, "lose")[0]?.cause, "mudwave"); + assert.equal(round.you.x, stand); + // The same wave, jumped at the edge, goes by. + const jumper = motherFight(); + standAt(jumper, 150); + jumper.boss.act = "rest"; + jumper.boss.wait = 1e9; + jumper.waves.push({ x: 170, y: 6, dir: -1, life: 6000, kind: "mudwave", cause: "mudwave" }); + let jumped = false; + until(jumper, () => { + const w = jumper.waves[0]; + if (!jumped && w && w.x - jumper.you.x < 9) { + jumper.input.jump = ghoul.JUMP_BUFFER_MS; + jumped = true; + } + return !jumper.waves.length || jumper.waves[0].x < jumper.you.x - 3; + }, 3000); + assert.ok(jumped, "it came at me"); + assert.equal(events(jumper, "lose").length, 0, "a jump clears the wave"); +}); + +test("Old Mother Bog's cauldron opens late in each rest, and a shot into her then counts triple, any other time one", () => { + const round = motherFight(); + const b = round.boss; + const hit = (act, wait) => { + Object.assign(b, { act, wait }); + round.shots.push({ x: b.x - b.w / 2 - 0.2, y: b.y + b.h * 0.35, vx: 80, vy: 0, gone: 0 }); + const hp = b.hp; + ghoul.advance(round, 4, steady); + return hp - b.hp; + }; + assert.equal(hit("idle", 1e9), 1, "shut: one"); + assert.equal(hit("rest", bog.MOTHER_REST_MS), 1, "early in the rest: one"); + assert.equal(b.lit, false); + round.events.length = 0; + assert.equal(hit("rest", bog.MOTHER_OPEN_MS - 100), 3, "open: triple"); + assert.equal(b.lit, true); + assert.equal(events(round, "cauldronOpen").length, 1, "the opening is announced"); + assert.equal(round.events.filter((e) => e.type === "bossHit").at(-1).weak, true, "and the hit says it was a weak spot"); + assert.equal(hit("wind", 400), 1, "mid-wind-up: one"); + assert.equal(b.lit, false, "closed again"); +}); + +test("Old Mother Bog's cauldron spit lands a muck patch where you stand after a wind-up, warns before it burns, burns for MUCK_MS and hurts only while live", () => { + const round = motherFight(); + const b = round.boss; + standAt(round, 150); + round.you.safeMs = 1e9; + b.act = "idle"; + b.attacks = 1; + hurry(b); + run(round, 8); + assert.equal(b.act, "throwWind"); + assert.equal(events(round, "spitWind").length, 1); + assert.equal(round.hazards.length, 0, "the glob is not thrown during the wind-up"); + run(round, bog.SPIT_WIND_MS + 20); + const spit = events(round, "cauldronSpit"); + assert.equal(spit.length, 1); + assert.equal(round.hazards.length, 1, "one patch before she is angry"); + const patch = round.hazards[0]; + assert.equal(patch.kind, "muck"); + assert.equal(patch.cause, "muck"); + assert.ok(Math.abs(patch.x - 150) <= 6, "where you stood"); + assert.equal(spit[0].tx, patch.x); + assert.equal(tx2(spit[0]), undefined, "no second patch yet"); + // It warns first: standing in the glob's shadow is safe. + round.you.safeMs = 0; + standAt(round, patch.x); + run(round, bog.MUCK_LAND_MS - 100); + assert.equal(events(round, "lose").length, 0, "still in the air"); + run(round, 200); + assert.equal(events(round, "muckLand").length, 1); + assert.equal(events(round, "lose")[0]?.cause, "muck", "burning, it hurts"); + // It burns out MUCK_MS after it lands. + const out = motherFight(); + out.boss.act = "rest"; + out.boss.wait = 1e9; + out.hazards.push({ kind: "muck", x: 150, y: 6, w: bog.MUCK_W, h: bog.MUCK_H, warn: 0, live: bog.MUCK_MS, cause: "muck" }); + standAt(out, 100); + out.you.safeMs = 1e9; + run(out, bog.MUCK_MS - 100); + assert.equal(out.hazards.length, 1); + run(out, 200); + assert.equal(out.hazards.length, 0, "burnt out"); +}); + +test("Old Mother Bog goes meaner at half her hp: waits shrink to MOTHER_QUICK of themselves and the spit leaves a second patch ahead of your feet", () => { + const round = motherFight(); + const b = round.boss; + standAt(round, 150); + round.you.safeMs = 1e9; + Object.assign(b, { raged: true, sank: true, act: "idle", attacks: 1, y: 6, x: 176 }); + b.wait = 0; + round.you.vx = 20; + run(round, 8); + assert.equal(b.act, "throwWind"); + assert.ok(b.wait <= bog.SPIT_WIND_MS * bog.MOTHER_QUICK + 1, `quicker wind-up (${b.wait})`); + run(round, bog.SPIT_WIND_MS); + const spit = events(round, "cauldronSpit")[0]; + assert.ok(spit, "spat"); + assert.equal(round.hazards.length, 2, "two patches"); + assert.ok(tx2(spit) !== undefined && Math.abs(tx2(spit) - spit.tx) >= bog.MUCK_W, "the second is a patch away from the first"); + assert.ok(b.wait <= bog.MOTHER_REST_MS * bog.MOTHER_QUICK + 1, "and her rest is shorter"); + // Calm, the same spit is one patch. + const calm = motherFight(); + standAt(calm, 150); + calm.you.safeMs = 1e9; + Object.assign(calm.boss, { act: "throwWind", wait: 0 }); + run(calm, 8); + assert.equal(calm.hazards.length, 1); +}); + +test("Old Mother Bog sinks at half her hp, bubbles where she will rise, rises near you on a plank and is hittable the instant she does", () => { + const calm = motherFight(); + assert.equal(calm.boss.sank || false, false); + calm.boss.act = "idle"; + calm.boss.wait = 1e9; + calm.boss.hp = calm.boss.max * bog.MOTHER_RAGE + 1; + run(calm, 40); + assert.equal(calm.boss.sank || false, false, "above half she stays up"); + standAt(calm, 150); + calm.you.safeMs = 1e9; + calm.boss.hp = calm.boss.max * bog.MOTHER_RAGE; + run(calm, 8); + const h = calm.boss; + assert.equal(h.sank, true); + assert.equal(h.act, "sink"); + assert.equal(h.raged, true); + assert.equal(h.hidden, true, "gone at once"); + assert.equal(events(calm, "motherSink").length, 1); + // Under the water nothing she is hurts and nothing hurts her: a bolt meets water. + const hp = h.hp; + calm.shots.push({ x: h.x - 2, y: 6.5, vx: 80, vy: 0, gone: 0 }); + Object.assign(calm.you, { x: h.x - 1 }); + calm.you.safeMs = 0; + run(calm, 40); + assert.equal(h.hp, hp, "no damage while she is under"); + assert.equal(events(calm, "lose").length, 0, "and she cannot hurt you from the water"); + // She bubbles where she will come up: a plank near you, never on top of you. + standAt(calm, 150); + calm.you.safeMs = 1e9; + until(calm, () => h.act === "under", 2000); + const bubble = events(calm, "motherBubble")[0]; + assert.ok(bubble, "bubbles show"); + assert.equal(h.act, "under"); + assert.equal(bubble.x, h.sinkX); + assert.ok(Number.isFinite(ghoul.groundAt(calm.spec, h.sinkX)), "on a plank"); + assert.ok(Math.abs(h.sinkX - calm.you.x) >= 6, "never on top of you"); + // She rises exactly there, touchable and hittable at once. + until(calm, () => h.act === "resurface", 2000); + assert.equal(h.x, bubble.x); + assert.equal(h.hidden, false); + assert.equal(h.y, h.home); + assert.equal(events(calm, "motherRise").length, 1); + const before = h.hp; + calm.shots.push({ x: h.x - h.w / 2 - 0.2, y: h.y + h.h * 0.35, vx: 80, vy: 0, gone: 0 }); + ghoul.advance(calm, 4, steady); + assert.ok(before - h.hp >= 1, "never unhittable once she is up"); + until(calm, () => h.act === "rest", 2000); + assert.ok(h.wait <= bog.MOTHER_REST_MS * bog.MOTHER_QUICK + 1, "and her next wait is the quick one"); +}); + +test("Old Mother Bog: her guard and weak spot are what the pack says, her touch is the motherbog cause, and her fall clears the field", () => { + assert.equal(bog.BOG.guard.motherbog({ hidden: true }), true); + assert.equal(bog.BOG.guard.motherbog({ hidden: false }), false); + assert.equal(bog.BOG.weak.motherbog({ lit: true }), 3); + assert.equal(bog.BOG.weak.motherbog({ lit: false }), 1); + assert.equal(bog.BOG.cause.motherbog(), "motherbog"); + const touch = motherFight(); + touch.boss.act = "idle"; + touch.boss.wait = 1e9; + Object.assign(touch.you, { x: touch.boss.x - 3 }); + run(touch, 20); + assert.equal(events(touch, "lose")[0]?.cause, "motherbog"); + const round = motherFight(); + const b = round.boss; + b.hp = 1; + b.sank = true; + round.hazards.push({ kind: "muck", x: 150, y: 6, w: bog.MUCK_W, h: bog.MUCK_H, warn: 0, live: 2000, cause: "muck" }); + round.waves.push({ x: 140, y: 6, dir: -1, life: 6000, kind: "mudwave", cause: "mudwave" }); + Object.assign(b, { act: "rest", wait: bog.MOTHER_OPEN_MS - 100 }); + standAt(round, 120); + round.you.safeMs = 1e9; + round.shots.push({ x: b.x - b.w / 2 - 0.2, y: b.y + b.h * 0.35, vx: 80, vy: 0, gone: 0 }); + ghoul.advance(round, 4, steady); + assert.equal(b.state, "down"); + assert.equal(round.hasKey, true); + assert.equal(round.hazards.length, 0); + assert.equal(round.waves.length, 0); +}); + +/* ------------------------------------------------------ voices, words, cards */ + +const heard = (e, extra = {}) => { + const played = []; + const noop = () => {}; + const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra }; + react(e, kit); + return played; +}; + +test("Ghoul Rush's bog: every new kind has a voice for every act, every new event plays exactly one picked sound, and the tones are the stage's own", () => { + const own = { lurker: ["appear", "snap", "sink", "hurt", "die"], leech: ["appear", "latch", "hurt", "die"], wisp: ["appear", "out", "relight", "on", "hurt", "die"], bogbody: ["appear", "rise", "hurt", "die"], motherbog: ["wake", "wind", "wave", "spitWind", "spit", "open", "sink", "bubble", "rise", "muck", "hurt", "weak", "die"] }; + assert.deepEqual(Object.keys(VOICES).sort(), Object.keys(own).sort(), "a voice table for each new kind and the boss"); + for (const [kind, acts] of Object.entries(own)) assert.deepEqual(Object.keys(VOICES[kind]).sort(), [...acts].sort(), `${kind}: every act`); + const names = Object.values(VOICES).flatMap((v) => Object.values(v)); + const at = { x: 10, y: 6, tx: 20, ty: 6 }; + const cases = [ + [{ type: "lurkerSnap", kind: "lurker" }, "lurker", "snap"], + [{ type: "lurkerSink", kind: "lurker" }, "lurker", "sink"], + [{ type: "leechLatch", kind: "leech" }, "leech", "latch"], + [{ type: "bogRise", kind: "bogbody" }, "bogbody", "rise"], + [{ type: "wispOut", kind: "wisp" }, "wisp", "out"], + [{ type: "wispRelight", kind: "wisp" }, "wisp", "relight"], + [{ type: "wispOn", kind: "wisp" }, "wisp", "on"], + [{ type: "motherWind", kind: "motherbog" }, "motherbog", "wind"], + [{ type: "mudWave", kind: "motherbog" }, "motherbog", "wave"], + [{ type: "spitWind", kind: "motherbog" }, "motherbog", "spitWind"], + [{ type: "cauldronSpit", kind: "motherbog" }, "motherbog", "spit"], + [{ type: "cauldronOpen", kind: "motherbog" }, "motherbog", "open"], + [{ type: "muckLand" }, "motherbog", "muck"], + [{ type: "motherSink", kind: "motherbog" }, "motherbog", "sink"], + [{ type: "motherBubble", kind: "motherbog" }, "motherbog", "bubble"], + [{ type: "motherRise", kind: "motherbog" }, "motherbog", "rise"], + [{ type: "bossWake", kind: "motherbog" }, "motherbog", "wake"], + [{ type: "bossHit", kind: "motherbog", how: "shot" }, "motherbog", "hurt"], + [{ type: "bossHit", kind: "motherbog", how: "weak", weak: true }, "motherbog", "weak"], + [{ type: "bossDown", kind: "motherbog", points: 1 }, "motherbog", "die"], + [{ type: "hit", kind: "lurker" }, "lurker", "hurt"], + [{ type: "hit", kind: "leech" }, "leech", "hurt"], + [{ type: "hit", kind: "wisp" }, "wisp", "hurt"], + [{ type: "hit", kind: "bogbody" }, "bogbody", "hurt"], + [{ type: "kill", kind: "lurker", mult: 1, how: "shot", points: 1 }, "lurker", "die"], + [{ type: "kill", kind: "leech", mult: 1, how: "shot", points: 1 }, "leech", "die"], + [{ type: "kill", kind: "wisp", mult: 1, how: "shot", points: 1 }, "wisp", "die"], + [{ type: "kill", kind: "bogbody", mult: 1, how: "shot", points: 1 }, "bogbody", "die"], + [{ type: "spawn", kind: "lurker" }, "lurker", "appear"], + [{ type: "spawn", kind: "leech" }, "leech", "appear"], + [{ type: "spawn", kind: "wisp" }, "wisp", "appear"], + [{ type: "spawn", kind: "bogbody" }, "bogbody", "appear"], + ]; + for (const [e, kind, act] of cases) assert.ok(heard({ ...at, ...e }).includes(VOICES[kind][act]), `${e.type}: ${kind} ${act}`); + const reached = new Set(cases.map(([, kind, act]) => `${kind}.${act}`)); + for (const [kind, acts] of Object.entries(own)) for (const act of acts) assert.ok(reached.has(`${kind}.${act}`), `${kind}.${act} is reached by an event`); + for (const e of cases.map((c) => c[0])) { + const picked = heard({ ...at, ...e }).filter((n) => names.includes(n)); + assert.equal(picked.length, 1, `${e.type}${e.kind ? ` (${e.kind})` : ""} plays exactly one picked sound`); + } + const weakHit = heard({ ...at, type: "bossHit", kind: "motherbog", how: "weak", weak: true }); + assert.equal(weakHit.includes(VOICES.motherbog.hurt), false, "weak replaces hurt"); + assert.equal(heard({ ...at, type: "bossHit", kind: "motherbog", how: "shot" }).includes(VOICES.motherbog.weak), false, "a plain shot is not weak"); + // Events that are only looks (the pull of the lure, a swarm coming apart) say nothing the voices own. + for (const type of ["wispLure", "leechDie"]) assert.equal(heard({ ...at, type, kind: "leech" }).filter((n) => names.includes(n)).length, 0, `${type} is visual`); + // Every picked tone exists in the merged tones, lives in the stage's file and is named by kind and act. + const merged = ghoulSfx.default.tones; + for (const [kind, acts] of Object.entries(VOICES)) { + for (const [act, name] of Object.entries(acts)) { + assert.ok(merged[name]?.layers?.length, `${kind}.${act}: ${name} is in the merged tones`); + assert.ok(BOG_SFX.tones[name], `${name} lives in ghoul-sfx-bog.js`); + assert.equal(name, `ghoul${kind === "motherbog" ? "Mother" : kind[0].toUpperCase() + kind.slice(1)}${act[0].toUpperCase()}${act.slice(1)}`, "named by kind and act"); + } + } +}); + +test("Ghoul Rush's bog: every new way to die has its words and its own sound, and endless lives spare the heart for each", () => { + const causes = ["lurker", "leeches", "wisp", "bogbody", "mudwave", "muck", "motherbog"]; + assert.deepEqual(Object.keys(LOSE_WORDS).sort(), [...causes].sort(), "words for exactly these"); + assert.deepEqual(Object.keys(LOSE_SOUNDS).sort(), [...causes].sort(), "a sound for exactly these"); + for (const cause of causes) { + assert.ok(LOSE_WORDS[cause] && LOSE_SOUNDS[cause], `${cause} has its words and its sound`); + assert.ok(heard({ x: 10, y: 6, type: "lose", cause, lives: 2 }).includes(LOSE_SOUNDS[cause][0]), `${cause} plays its own sound`); + const round = motherFight(); + round.infinite = true; + const lives = round.lives; + ghoul.lose(round, cause); + assert.equal(round.lives, lives, `${cause} costs none`); + const normal = motherFight(); + const had = normal.lives; + ghoul.lose(normal, cause); + assert.equal(normal.lives, had - 1, `${cause} costs a heart otherwise`); + } + // The real causes the stage raises are all among them. + for (const cause of ["leeches", "mudwave", "muck", "motherbog"]) assert.ok(LOSE_WORDS[cause]); + assert.equal(bog.BOG.cause.motherbog(), "motherbog"); +}); + +test("Ghoul Rush's bog cards: the stage card names the stage, boss and no em dash, the boss card names Old Mother Bog, and both agree", () => { + const card = INTROS.bog; + assert.equal(card.title, "Gallows Bog"); + assert.equal(card.boss, "Old Mother Bog"); + assert.ok(card.lines.length >= 3 && card.lines.length <= 4); + assert.equal(card.kicker, ghoul.stageById("bog").sub, "the card's kicker is the stage's subtitle"); + assert.ok(card.lines.some((l) => /YOU/.test(l)) && !card.lines.some((l) => /Planny/.test(l)), "addressed to YOU, never the hero's name"); + assert.ok(![card.title, card.kicker, card.boss, ...card.lines].some((t) => t.includes("\u2014")), "no em dash"); + const boss = BOSS_INTROS.motherbog; + assert.equal(boss.name, "Old Mother Bog"); + assert.equal(boss.name, card.boss, "the two cards agree on the name"); + assert.ok(boss.epithet && !boss.epithet.includes("\u2014") && !/Planny/.test(boss.epithet)); + assert.equal(bossIntroFor("motherbog"), boss); + assert.equal(introFor("bog"), card); +}); + +/* ------------------------------------------------------ round flow */ + +test("Ghoul Rush's bog round flow: the stage card opens before the Sunken Boardwalk, the hag's card before the Drowning Pool (after the ride), and neither shows on a retry", () => { + const r = ghoul.newRound(5); + r.dice = 0; + through(r); + r.offer = ["bog"]; + r.phaseMs = 0; + assert.equal(ghoul.pickStage(r, 0), true); + assert.equal(r.stage, "bog"); + assert.equal(r.spec.id, "boardwalk"); + assert.equal(r.phase, "intro", "the stage card first"); + assert.deepEqual(r.events.filter((e) => e.type === "intro").map((e) => e.stage), ["bog"]); + assert.equal(r.events.some((e) => e.type === "room"), false, "the room waits for the card"); + r.introMs = ghoul.INTRO_MIN_MS; + assert.equal(ghoul.takeIntro(r), true); + assert.equal(r.phase, "ready"); + ghoul.advance(r, ghoul.READY_MS + 20, steady); + assert.equal(r.phase, "play"); + for (const id of ["hollow", "stilts", "bogboat"]) { + r.events.length = 0; + through(r); + assert.equal(r.spec.id, id); + assert.notEqual(r.phase, "bossintro", `${id}: no boss card`); + assert.equal(r.events.some((e) => e.type === "bossIntro"), false); + } + assert.ok(ghoul.roomById("bogboat").bonus, "the ride comes right before the boss"); + r.events.length = 0; + through(r); + assert.equal(r.spec.id, "drowning"); + assert.equal(r.phase, "bossintro", "the boss card"); + assert.deepEqual(r.events.filter((e) => e.type === "bossIntro").map((e) => [e.boss, e.stage]), [["motherbog", "bog"]]); + assert.equal(r.boss.kind, "motherbog"); + assert.equal(r.boss.state, "sleep", "she sleeps behind the card"); + r.introMs = ghoul.INTRO_MIN_MS; + assert.equal(ghoul.takeIntro(r), true); + assert.equal(r.phase, "ready"); + ghoul.advance(r, ghoul.READY_MS + 20, steady); + assert.equal(r.phase, "play"); + // Into the pool, the fight starts; a life lost there goes back without the card. + r.events.length = 0; + standAt(r, r.spec.arena + ghoul.BOSS_LOCK + 2); + ghoul.advance(r, 4, steady); + ghoul.advance(r, ghoul.BOSS_INTRO_MS + 8, steady); + assert.equal(r.boss.state, "fight"); + ghoul.lose(r, "motherbog"); + for (let t = 0; t < 6000 && r.phase !== "play" && !r.over; t += 4) ghoul.advance(r, 4, steady); + assert.notEqual(r.phase, "bossintro", "no card on a retry"); + assert.equal(r.events.some((e) => e.type === "bossIntro"), false, "no card event on a retry"); +}); + +test("Ghoul Rush's bog draws: every walked room and the arena, every monster in every act, the hag in each move above and under the water, the mud wave and the muck, in a lit room and a dark one", () => { + const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) }); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + g.resize(900, 900); + g.key("action"); + g.tick(16); + const r = g.round; + through(r); + r.offer = ["bog"]; + r.phaseMs = 0; + ghoul.pickStage(r, 0); + const acts = { lurker: ["eyes", "snap", "sink"], leech: ["drift", "drop"], wisp: ["bright", "dim", "rekindle"], bogbody: ["rise", "walk"] }; + let drew = 0; + for (const id of ["boardwalk", "hollow", "stilts", "drowning"]) { + while (r.spec.id !== id) through(r); + for (const dark of [true, false]) { + r.dark = dark; + r.phase = "play"; + r.lives = 99; + for (const st of r.spawns) st.over = true; + r.hordeMs = Infinity; + r.monsters.length = 0; + standAt(r, id === "drowning" ? r.spec.arena + ghoul.BOSS_LOCK + 2 : 40); + r.you.safeMs = 1e9; + for (const [kind, list] of Object.entries(acts)) list.forEach((act, i) => put(r, kind, r.you.x + 6 + i * 5, { act, wait: 300, rise: act === "rise" ? 300 : 0, y: kind === "wisp" ? 12 : undefined })); + r.monsters.at(-1).lurching = true; + if (r.boss) { + ghoul.advance(r, ghoul.BOSS_INTRO_MS + 16, steady); + for (const hidden of [false, true]) { + for (const act of ["idle", "wind", "rest", "throwWind", "sink", "under", "resurface"]) { + Object.assign(r.boss, { act, wait: 400, dir: -1, lit: act === "rest", hidden: hidden && (act === "sink" || act === "under"), sinkX: r.boss.x - 10, home: 6 }); + g.tick(16); + drew++; + } + } + Object.assign(r.boss, { hidden: false, act: "rest", wait: 1e9 }); + r.hazards.push({ kind: "muck", x: r.you.x + 10, y: 6, w: bog.MUCK_W, h: bog.MUCK_H, warn: 400, live: 0, cause: "muck", sx: r.boss.x, sy: 9 }, { kind: "muck", x: r.you.x + 20, y: 6, w: bog.MUCK_W, h: bog.MUCK_H, warn: 0, live: 1500, cause: "muck" }); + r.waves.push({ x: r.you.x + 8, y: 6, dir: -1, life: 6000, kind: "mudwave", cause: "mudwave" }); + } + for (let k = 0; k < 20; k++) g.tick(16); + r.you.safeMs = 1e9; + drew++; + } + } + assert.ok(drew >= 8 + 14, "drew a lot"); + assert.equal(r.spec.id, "drowning", "got to the pool and drew it"); +}); + +test("Ghoul Rush's bog: a seeded bot, shielded and with endless lives, plays the Sunken Boardwalk on a draw that throws if the bog's own rules ask for a random number, and any life it loses is for a cause the stage names", () => { + // The engine rolls dice of its own (power-up drops, horde edges, variants), so the draw is a steady one that throws only when the call came out of the bog's pack file. + const boom = () => { + Error.stackTraceLimit = 20; + const stack = new Error().stack; + if (stack.includes("ghoul-bog.js")) throw new Error(`the bog pack drew a random number: ${stack}`); + return 0.5; + }; + let seed = 7; + const next = () => ((seed = (seed * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff); + const causes = new Set(); + const round = ghoul.newRound(5); + round.dice = 0; + round.infinite = true; + through(round); + round.offer = ["bog"]; + round.phaseMs = 0; + ghoul.pickStage(round, 0); + round.introMs = ghoul.INTRO_MIN_MS; + ghoul.takeIntro(round); + ghoul.advance(round, ghoul.READY_MS + 20, steady); + assert.equal(round.phase, "play"); + assert.equal(round.spec.id, "boardwalk"); + round.hasKey = true; + round.effects.boots = 1e9; + let far = 0; + let wake = 0; + // Walking right, firing, jumping at a gap or a step and now and then at nothing: a bot with no sense of the lurkers, the leeches or the lights. + for (let t = 0; t < 90000 && !round.over; t += 4) { + const you = round.you; + you.safeMs = 1e9; + const ahead = ghoul.groundAt(round.spec, you.x + 3); + round.input.right = true; + round.input.fire = true; + if (!Number.isFinite(ahead) || ahead > you.y + 0.4 || next() < 0.02) round.input.jump = ghoul.JUMP_BUFFER_MS; + ghoul.advance(round, 4, boom); + for (const e of round.events) { + if (e.type === "lose") causes.add(e.cause); + if (/^(lurkerSnap|leechLatch|wispLure|wispOut|bogRise)$/.test(e.type)) wake++; + } + round.events.length = 0; + far = Math.max(far, you.x); + assert.ok(Number.isFinite(you.x), "the player stays on the map"); + if (round.phase === "clear") break; + } + assert.ok(far > 150, `the bot got well into the room (${far.toFixed(0)} of ${round.spec.length})`); + assert.ok(wake > 0, "the stage's monsters woke and acted around it"); + assert.equal(round.lives, ghoul.newRound(5).lives, "endless lives: not one heart spent"); + const known = new Set([...Object.keys(LOSE_WORDS), "pit"]); + for (const cause of causes) assert.ok(known.has(cause), `${cause} has words`); +}); diff --git a/scripts/test-web-console-activities-ghoul-bogboat.mjs b/scripts/test-web-console-activities-ghoul-bogboat.mjs new file mode 100644 index 0000000..f0b2337 --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-bogboat.mjs @@ -0,0 +1,945 @@ +// Web console tests, Ghoul Rush's Bog Runner (Gallows Bog's bonus round, between the Stilt House and the Drowning Pool): its shape (two lanes, the banks, every thing spaced for a player), the boat's motion (a steady speed on the channel, slower on the flats, a jump, a duck, a hop between lanes only at a bank), each obstacle and its cost (snag, knee, veil, limb), the fan's clog and stall, the swarm in the wake and its catch, the charms and gas pockets shot for points and a cover burst, the hearts and the grade and the dice, endless lives, the drawing and the sounds, and bots that play it. +// Run with: node --test scripts/test-web-console-activities-ghoul-bogboat.mjs +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { skipBossIntro } from "./ghoul-test-helpers.mjs"; +import * as bz from "../src/web-console/public/activities/ghoul-bogboat.js"; +import { ANSWERS, EVENT_VOICE, LOOKS as BOAT_LOOKS, LOSE_SOUNDS, LOSE_WORDS, TELEGRAPH_WORDS, VOICES as BOAT_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-bogboat-draw.js"; +import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js"; +import { BOGBOAT_SFX } from "../src/web-console/public/activities/ghoul-sfx-bogboat.js"; +import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-draw.js"; +import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-bonus.js"; + +const steady = () => 0.5; +// The pack draws no random number: a run on this fails on the first draw. +const never = () => { + throw new Error("the bog runner drew a random number"); +}; +const events = (round, type) => round.events.filter((e) => e.type === type); + +function through(round) { + round.phase = "clear"; + round.phaseMs = 1; + ghoul.advance(round, 4, steady); +} + +// A round in the Bog Runner reached the way play reaches it, nothing woken, the clocks long, +// the bonus round on (five hearts). +function boatRound(seed = 5) { + const round = ghoul.newRound(seed); + round.lives = 3; + round.dice = 0; + through(round); + round.offer = ["bog"]; + round.phaseMs = 0; + ghoul.pickStage(round, 0); + while (round.spec.id !== "bogboat") through(round); + round.phase = "play"; + for (const st of round.spawns) st.over = true; + round.monsters.length = 0; + round.hordeMs = Infinity; + round.timeMs = 1e9; + round.bonus = 1e9; + round.events.length = 0; + return round; +} + +const NONE = { runner: "bogboat", time: 1e9, finish: 1e6, banks: [], snags: [], knees: [], veils: [], limbs: [], props: [], gas: [], checks: [] }; +// The same round over a ride of its own (a plain channel to measure the boat on). +function synth(ride) { + const round = boatRound(); + round.spec = { ...round.spec, start: 10, ground: [[0, 1e6, 9]], ride: { ...NONE, ...ride } }; + round.runner = null; + bz.BOGBOAT.place[0](round, {}); + return round; +} + +// The boat at `x` in `lane`, on the water. +function at(round, x, lane = 0, { safe = false } = {}) { + Object.assign(round.runner, { lane, from: lane, swMs: 0, h: 0, vy: 0, air: false, v: lane ? bz.FLATS_V : bz.BOGBOAT_V, stall: 0, clog: 0 }); + Object.assign(round.you, { x, y: bz.LANE_Y[lane], vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false }); + round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24)); +} + +function run(round, ms, keys = {}, random = steady) { + Object.assign(round.input, keys); + for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random); + for (const k of Object.keys(keys)) round.input[k] = typeof keys[k] === "number" ? 0 : false; +} + +function until(round, done, ms = 6000, random = steady) { + let t = 0; + for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random); + return t; +} + +const press = (round) => { + round.input.jump = ghoul.JUMP_BUFFER_MS; + round.input.up = true; +}; + +const heard = (e, extra = {}) => { + const played = []; + const noop = () => {}; + const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra }; + react({ x: 10, y: 9, tx: 20, ty: 9, ...e }, kit); + return { played }; +}; + +const ROOM = ghoul.roomById("bogboat"); +const R = ROOM.ride; +const V = bz.BOGBOAT_V; +const things = () => [ + ...R.snags.map(([x, lane], i) => ({ id: `s${i}`, kind: "snag", lane, x })), + ...R.knees.map(([x, lane], i) => ({ id: `k${i}`, kind: "knee", lane, x })), + ...R.veils.map(([x0, x1, lane], i) => ({ id: `v${i}`, kind: "veil", lane, x: (x0 + x1) / 2 })), + ...R.limbs.map(([x0, x1, lane], i) => ({ id: `l${i}`, kind: "limb", lane, x: (x0 + x1) / 2 })), + ...R.props.map(([x, lane], i) => ({ id: `p${i}`, kind: "prop", lane, x })), + ...R.gas.map(([x, lane], i) => ({ id: `g${i}`, kind: "gas", lane, x })), +]; +const HARMFUL = new Set(["snag", "knee", "veil", "limb"]); + +/* -------------------------------------------------------------- the room */ + +test("Ghoul Rush's Bog Runner is Gallows Bog's fourth room, between the Stilt House and the Drowning Pool: lit, no key, no boss, a ride about a minute long, a bonus round that plays its own track", () => { + const st = ghoul.stageById("bog"); + assert.deepEqual(st.rooms, ["boardwalk", "hollow", "stilts", "bogboat", "drowning"]); + assert.deepEqual([ROOM.title, ROOM.sub], ["The Bog Runner", "Something swims in your wake"]); + assert.equal(ROOM.dark, false, "a moonlit night, always lit"); + assert.equal(ROOM.key, null); + assert.equal(ROOM.boss, null); + assert.equal(ROOM.bonus, true, "a bonus round"); + assert.equal(R.runner, "bogboat"); + assert.ok(ROOM.length >= 2400 && ROOM.length <= 3000, `${ROOM.length} units long`); + assert.equal(ghoul.ROOM_MUSIC.bogboat, "ghoulBoatRide"); + assert.ok(ghoulSfx.default.music.ghoulBoatRide, "its own track"); + assert.deepEqual(Object.keys(bz.BOGBOAT.monsters), [], "no new monster kinds"); + assert.equal(LOOKS.bogboat, BOAT_LOOKS.bogboat); + assert.equal(LOOKS.bogboat.pack, "bogboat"); + assert.ok(Object.isFrozen(R) && Object.isFrozen(R.snags) && Object.isFrozen(R.snags[0]), "frozen all the way down"); + assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0 && ROOM.items.length === 0, "no monsters or pickups: the things on the water are the pack's own"); + assert.deepEqual(ROOM.ground.map((g) => g.slice()), [[0, ROOM.length, bz.LANE_Y[0]]], "one flat floor under the water"); + assert.ok(R.finish < ROOM.door && ROOM.door > ROOM.length - 20, "the door at the room's end, past the finish"); + assert.ok(ghoul.groundAt(ROOM, ROOM.door - 2) > -Infinity, "floor to walk out on"); + const secs = (R.finish - ROOM.start) / V; + assert.ok(secs >= 56 && secs <= 80, `${secs.toFixed(1)} s at BOGBOAT_V`); + assert.equal(ghoul.timeFor(ROOM), R.time, "its own clock"); + assert.ok(R.time / 1000 > secs * 1.4, "a clock with room to spare"); + assert.equal(ghoul.STAGES.find((s) => s.id === "bog").rooms.length, 5); + assert.equal(R.banks.length, 11); + assert.equal(R.checks.length, 4); + assert.ok(R.props.length >= 16 && R.gas.length >= 14, "enough to shoot"); + assert.ok(R.snags.length && R.knees.length && R.veils.length && R.limbs.length, "one of each thing to dodge"); +}); + +test("Ghoul Rush's Bog Runner: every thing is in lane 0 or 1, off the ends, spaced for a player, and clear of the banks", () => { + const all = things(); + assert.ok(all.length >= 70 && all.length <= 130, `${all.length} things`); + for (const t of all) { + assert.ok(t.lane === 0 || t.lane === 1, `${t.id} lane`); + assert.ok(t.x >= 120 && t.x < R.finish - 40, `${t.id} at ${t.x}`); + } + for (const lane of [0, 1]) assert.ok(all.filter((t) => t.lane === lane && HARMFUL.has(t.kind)).length >= 12, `plenty to dodge in lane ${lane}`); + // The same lane: 36 between any two (a jump and a duck need 38 at the full speed, so the slots never share). + for (const lane of [0, 1]) { + const xs = all.filter((t) => t.lane === lane).map((t) => t.x).sort((a, b) => a - b); + for (let i = 1; i < xs.length; i++) assert.ok(xs[i] - xs[i - 1] >= 36, `lane ${lane}: ${xs[i - 1]} and ${xs[i]}`); + } + // Banks: 16 wide, 200 apart, in order, and nothing within the hop of one. + R.banks.forEach(([a, b], i) => { + assert.equal(b - a, 16); + if (i) assert.equal(a - R.banks[i - 1][0], 200, "banks are spaced out"); + for (const t of all) assert.ok(t.x < a - 6 || t.x > b + 22, `${t.id} at ${t.x} is near the bank ${a}`); + }); + for (const [x0, x1] of R.veils) assert.equal(x1 - x0, 8); + for (const [x0, x1] of R.limbs) assert.equal(x1 - x0, 6); + // The channel is the thicker lane and the flats hold most of the gas. + const dense = (lane) => all.filter((t) => t.lane === lane && HARMFUL.has(t.kind)).length; + assert.ok(dense(0) > dense(1) * 1.5, `${dense(0)} to dodge in the channel, ${dense(1)} on the flats`); +}); + +test("Ghoul Rush's Bog Runner: every jump is clearable and every duck passable, at the speed of either lane, and the checkpoints sit clear of the banks", () => { + const clearFor = (h, speed) => (2 * Math.sqrt(bz.JUMP_V ** 2 - 2 * bz.GRAVITY * h) / bz.GRAVITY) * speed; + for (const speed of [bz.BOGBOAT_V, bz.FLATS_V]) { + assert.ok(clearFor(bz.SNAG_H, speed) >= bz.SNAG_W + ghoul.HIT_W + 8, `a snag at ${speed}`); + assert.ok(clearFor(bz.KNEE_H, speed) >= bz.KNEE_W + ghoul.HIT_W + 8, `knees at ${speed}`); + } + assert.ok(bz.SNAG_H < (bz.JUMP_V ** 2) / (2 * bz.GRAVITY) - 4, "a snag is well under the jump's peak"); + assert.ok(ghoul.DUCK_H < bz.LOW_Y && ghoul.HIT_H > bz.LOW_Y, "a ducked Planny fits under a low and a standing one does not"); + R.checks.forEach((x, i) => { + if (i) assert.ok(x - R.checks[i - 1] >= 400); + assert.ok(R.banks.every(([a, b]) => x < a - 4 || x > b + 4)); + }); +}); + +/* ---------------------------------------------------------------- the boat */ + +test("Ghoul Rush's Bog Runner rolls at BOGBOAT_V on the channel whatever is pressed, slower on the flats, and DOWN eases the throttle in either; the camera leads it", () => { + const round = synth({}); + assert.equal(round.runner.id, "bogboat"); + assert.equal(round.camLead, bz.CAM_AHEAD); + assert.equal(round.you.y, bz.LANE_Y[0]); + const x0 = round.you.x; + run(round, 1000); + assert.ok(Math.abs(round.you.x - x0 - V) < 0.5, `${round.you.x - x0} in a second`); + for (const keys of [{ left: true }, { fire: true }]) { + const a = round.you.x; + run(round, 500, keys); + assert.ok(Math.abs(round.you.x - a - V / 2) < 0.5, JSON.stringify(keys)); + } + assert.equal(round.you.face, 1); + // Left and right do nothing off a bank. + run(round, 400, { right: true }); + assert.equal(round.runner.lane, 0); + assert.equal(round.you.y, bz.LANE_Y[0]); + const speedOf = (lane, keys) => { + const r = synth({}); + at(r, 100, lane); + run(r, 1500, keys); + return r.runner.v; + }; + assert.ok(Math.abs(speedOf(0, {}) - bz.BOGBOAT_V) < 0.3); + assert.ok(Math.abs(speedOf(0, { down: true }) - bz.EASE_V) < 0.3); + assert.ok(Math.abs(speedOf(1, {}) - bz.FLATS_V) < 0.3); + assert.ok(Math.abs(speedOf(1, { down: true }) - bz.FLATS_EASE_V) < 0.3); +}); + +test("Ghoul Rush's Bog Runner jumps about 13 high for about three quarters of a second, a press saved for a landing jumps on it, and it cannot jump in the air", () => { + const round = synth({}); + at(round, 100, 0, { safe: true }); + let peak = 0; + let ms = 0; + press(round); + ghoul.advance(round, 4, steady); + round.input.up = false; + assert.equal(round.runner.air, true); + while (round.runner.air && ms < 2000) { + ghoul.advance(round, 4, steady); + peak = Math.max(peak, round.you.y - bz.LANE_Y[0]); + ms += 4; + } + assert.ok(peak > 12 && peak < 15, `${peak} high`); + assert.ok(ms > 650 && ms < 850, `${ms} ms`); + assert.equal(round.you.y, bz.LANE_Y[0]); + assert.equal(events(round, "bogboatJump").length, 1); + assert.equal(events(round, "bogboatLand").length, 1); + // A press in the air does not double jump, but waits for the landing. + const again = synth({}); + at(again, 100, 0, { safe: true }); + press(again); + ghoul.advance(again, 4, steady); + run(again, 400); + press(again); + run(again, 100); + assert.ok(again.runner.vy <= 0 || again.runner.air, "no second jump in mid-air"); + until(again, () => !again.runner.air, 1000); + press(again); + ghoul.advance(again, 4, steady); + assert.equal(again.runner.air, true, "a press saved for the landing jumps on it"); +}); + +test("Ghoul Rush's Bog Runner: DOWN ducks, a ducked Planny passes under a veil or a limb and a standing one hits it (causes veil and limb), at the cost of a heart", () => { + for (const [key, cause, ride] of [["veils", "veil", { veils: [[300, 308, 0]] }], ["limbs", "limb", { limbs: [[300, 306, 0]] }]]) { + const standing = synth(ride); + at(standing, 270, 0); + run(standing, 1500); + assert.equal(standing.bonusRound.hearts, 4, `${key}: a standing boat is hit`); + assert.equal(events(standing, "lose").map((e) => e.cause).join(), cause); + const ducked = synth(ride); + at(ducked, 270, 0); + run(ducked, 1500, { down: true }); + assert.equal(ducked.bonusRound.hearts, 5, `${key}: a ducked boat passes`); + assert.equal(events(ducked, "bogboatDuck").length, 1); + assert.equal(events(ducked, "lose").length, 0); + } +}); + +test("Ghoul Rush's Bog Runner: a snag or cypress knees stop a boat that does not jump (causes snag and knee); a jump clears each; each costs only once", () => { + for (const [cause, ride] of [["snag", { snags: [[300, 0]] }], ["knee", { knees: [[300, 0]] }]]) { + const hit = synth(ride); + at(hit, 270, 0); + run(hit, 1500); + assert.equal(hit.bonusRound.hearts, 4, cause); + assert.equal(events(hit, "lose").map((e) => e.cause).join(), cause, "one heart, once"); + assert.equal(events(hit, "bogboatCrash").length, 1); + const jumped = synth(ride); + at(jumped, 270, 0); + let pressed = false; + until(jumped, () => { + if (!pressed && jumped.you.x >= 300 - 14) { + press(jumped); + pressed = true; + } + return jumped.you.x > 340; + }, 3000); + assert.equal(jumped.bonusRound.hearts, 5, `${cause}: a jump clears it`); + assert.equal(jumped.bonusRound.perf.hits.length, 0); + } + // The things in the other lane do not touch a boat. + const other = synth({ snags: [[300, 1]], knees: [[300, 1]], veils: [[330, 338, 1]], limbs: [[360, 366, 1]] }); + at(other, 270, 0); + run(other, 2400); + assert.equal(other.bonusRound.hearts, 5); +}); + +test("Ghoul Rush's Bog Runner switches lanes only inside a bank: LEFT is the channel, RIGHT the flats, in SWITCH_MS, with no jump or duck in the hop; the boat slows to the flats' speed and comes back up to the channel's", () => { + const round = synth({ banks: [[300, 316], [500, 516]] }); + at(round, 301, 0, { safe: true }); + run(round, 200, { right: true }); + assert.equal(round.runner.lane, 1); + assert.equal(events(round, "bogboatSwitch").length, 1); + assert.equal(events(round, "bogboatSwitch")[0].to, 1); + assert.ok(round.runner.swMs > 0, "mid-hop"); + assert.equal(round.you.state, "run"); + // No jump or duck in the hop. + press(round); + ghoul.advance(round, 4, steady); + assert.equal(round.runner.air, false); + round.input.up = false; + run(round, bz.SWITCH_MS); + assert.equal(round.runner.swMs, 0); + assert.equal(round.you.y, bz.LANE_Y[1], "up on the flats"); + assert.ok(round.runner.v < bz.BOGBOAT_V - 5, "slowed"); + // Not outside a bank. + run(round, 400, { left: true }); + assert.equal(round.runner.lane, 1, "off a bank nothing changes"); + // Back down at the next one. + at(round, 496, 1, { safe: true }); + run(round, 600, { left: true }); + assert.equal(round.runner.lane, 0); + assert.equal(round.you.y, bz.LANE_Y[0]); + // Not in the air. + const air = synth({ banks: [[300, 316]] }); + at(air, 304, 0, { safe: true }); + press(air); + run(air, 40); + run(air, 40, { right: true }); + assert.equal(air.runner.lane, 0, "no switch in the air"); +}); + +test("Ghoul Rush's Bog Runner: the fan clogs on the flats at full throttle (a warning at CLOG_WARN, a stall at CLOG_MAX that stops the boat for STALL_MS), an ease or the channel clears it", () => { + const round = synth({}); + at(round, 100, 1, { safe: true }); + run(round, 1000); + assert.ok(Math.abs(round.runner.clog - bz.CLOG_RISE) < 2, `${round.runner.clog} after a second`); + until(round, () => events(round, "bogboatClog").length > 0, 4000); + assert.ok(round.runner.clog >= bz.CLOG_WARN - 1); + until(round, () => round.runner.stall > 0, 4000); + assert.equal(events(round, "bogboatStall").length, 1); + run(round, 800); + assert.ok(round.runner.v < 3, `coasting to a stop (${round.runner.v})`); + const x = round.you.x; + until(round, () => round.runner.stall === 0, 2000); + assert.equal(round.runner.stall, 0); + assert.ok(round.runner.clog >= bz.CLOG_RESTART && round.runner.clog < bz.CLOG_WARN, `restarted at ${round.runner.clog}`); + assert.ok(round.you.x - x < 6, "hardly moved while stalled"); + // Eased, the flats cool the fan. + const eased = synth({}); + at(eased, 100, 1, { safe: true }); + run(eased, 1200); + const hot = eased.runner.clog; + run(eased, 1000, { down: true }); + assert.ok(eased.runner.clog < hot, "an ease cools it"); + // And the channel does. + const channel = synth({}); + at(channel, 100, 0, { safe: true }); + channel.runner.clog = 80; + run(channel, 1000); + assert.ok(Math.abs(channel.runner.clog - (80 - bz.CLOG_COOL)) < 0.5, `${channel.runner.clog}`); + // A stalled fan stops the boat, so the swarm gains on it. + const lost = synth({}); + at(lost, 100, 1, { safe: true }); + Object.assign(lost.runner, { clog: bz.CLOG_MAX - 0.1, gap: bz.GAP_MAX }); + until(lost, () => lost.runner.stall > 0, 1000); + const gap = lost.runner.gap; + run(lost, 1000); + assert.ok(lost.runner.gap < gap - 10, `${gap} to ${lost.runner.gap}`); +}); + +test("Ghoul Rush's Bog Runner's wake: it opens on clean riding, closes when the boat is eased or on the flats, a hit shoves it HIT_CLOSE closer, and PANIC_ON boils it until PANIC_OFF", () => { + const round = synth({}); + at(round, 100, 0, { safe: true }); + run(round, 500); + assert.ok(round.runner.gap > bz.GAP_START, "opening"); + run(round, 2000); + assert.equal(round.runner.gap, bz.GAP_MAX, "never over GAP_MAX"); + const eased = synth({}); + at(eased, 100, 0, { safe: true }); + eased.runner.gap = 30; + run(eased, 2000, { down: true }); + assert.ok(eased.runner.gap < 30, "the ease loses ground"); + const flats = synth({}); + at(flats, 100, 1, { safe: true }); + flats.runner.gap = 30; + run(flats, 500, { down: true }); + assert.ok(flats.runner.gap < 30, "the eased flats lose ground"); + // A hit shoves it closer. + const hit = synth({ snags: [[300, 0]] }); + at(hit, 280, 0); + hit.runner.gap = 30; + run(hit, 500); + assert.ok(hit.runner.gap <= 30 - bz.HIT_CLOSE + (V - bz.WAKE_V) * 0.5 + 1, `${hit.runner.gap}`); + assert.equal(hit.bonusRound.hearts, 4); + // PANIC_ON: the swarm boils (an event, once), PANIC_OFF puts it out and it can boil again. + const panic = synth({}); + at(panic, 100, 0, { safe: true }); + panic.runner.gap = bz.PANIC_ON + 0.5; + panic.runner.v = 20; + run(panic, 200, { down: true }); + assert.equal(panic.runner.panic, true); + assert.equal(events(panic, "bogboatPanic").length, 1); + run(panic, 4000); + assert.equal(panic.runner.panic, false); + assert.equal(panic.bonusRound.perf.steady, false, "a swarm that boiled loses the steady die"); + assert.equal(panic.runner.panicked, true); + const clean = synth({}); + at(clean, 100, 0, { safe: true }); + run(clean, 3000); + assert.equal(clean.bonusRound.perf.steady, true); +}); + +test("Ghoul Rush's Bog Runner: at WAKE_CATCH the swarm has you, a heart (cause wake), and it falls back to WAKE_FALLBACK, once; a blinking boat is caught for free; the catch is counted for the grade", () => { + const round = synth({}); + at(round, 100, 0); + round.runner.v = 20; + round.runner.gap = bz.WAKE_CATCH + 0.2; + run(round, 200, { down: true }); + assert.equal(round.bonusRound.hearts, 4); + assert.equal(events(round, "lose").map((e) => e.cause).join(), "wake"); + assert.equal(events(round, "bogboatCatch").length, 1); + assert.ok(round.runner.gap > bz.WAKE_FALLBACK - 3 && round.runner.gap <= bz.WAKE_FALLBACK + 2, `${round.runner.gap}`); + assert.equal(round.runner.catches, 1); + assert.equal(round.bonusRound.perf.total, 1); + assert.deepEqual(round.bonusRound.perf.hits, ["w1"]); + assert.equal(round.phase, "play", "the ride goes on"); + const free = synth({}); + at(free, 100, 0, { safe: true }); + free.runner.v = 20; + free.runner.gap = bz.WAKE_CATCH + 0.2; + run(free, 200, { down: true }); + assert.equal(free.bonusRound.hearts, 5); + assert.equal(events(free, "bogboatCatch").length, 1); + assert.equal(free.runner.gap > bz.WAKE_CATCH + 10, true, "still falls back"); +}); + +/* ------------------------------------------------------------ shooting */ + +test("Ghoul Rush's Bog Runner: one bolt breaks a charm (60 points) and one bursts a gas pocket (90 points, the wake pushed back GAS_PUSH), each an act for the grade; a bolt at another height flies on; a pocket stays burst across a re-seat", () => { + const round = synth({ props: [[330, 0, 0], [380, 1, 1]], gas: [[420, 0], [470, 1]] }); + at(round, 300, 0, { safe: true }); + round.runner.gap = 20; + const score = round.score; + round.shots.push({ x: 328, y: bz.LANE_Y[0] + 2.4, vx: 130, vy: 0, gone: 0 }); + ghoul.advance(round, 4, steady); + assert.equal(round.runner.props[0].state, "broken"); + assert.equal(round.score - score, bz.PROP_POINTS); + assert.equal(round.bonusRound.perf.acts, 1); + assert.equal(events(round, "bogboatProp").length, 1); + assert.equal(events(round, "bogboatProp")[0].points, bz.PROP_POINTS); + // A bolt too high flies on, one in the wrong lane too. + round.shots.push({ x: 418, y: bz.LANE_Y[0] + 9, vx: 130, vy: 0, gone: 0 }); + round.shots.push({ x: 468, y: bz.LANE_Y[0] + 2.4, vx: 130, vy: 0, gone: 0 }); + ghoul.advance(round, 4, steady); + assert.equal(round.runner.gas[0].state, "up"); + assert.equal(round.runner.gas[1].state, "up", "the flats' pocket needs a bolt at the flats' height"); + const gap = round.runner.gap; + round.shots.push({ x: 418, y: bz.LANE_Y[0] + 2.4, vx: 130, vy: 0, gone: 0 }); + ghoul.advance(round, 4, steady); + assert.equal(round.runner.gas[0].state, "burst"); + assert.ok(round.runner.gap - gap >= bz.GAS_PUSH - 0.5, `pushed back ${round.runner.gap - gap}`); + assert.equal(round.bonusRound.perf.acts, 2); + assert.equal(events(round, "bogboatGas")[0].points, bz.GAS_POINTS); + // Burst, then spent; a second bolt through the cloud does nothing. + run(round, bz.GAS_BURST_MS + 20); + assert.equal(round.runner.gas[0].state, "spent"); + const acts = round.bonusRound.perf.acts; + round.shots.push({ x: 418, y: bz.LANE_Y[0] + 2.4, vx: 130, vy: 0, gone: 0 }); + ghoul.advance(round, 4, steady); + assert.equal(round.bonusRound.perf.acts, acts); + // A charm hit in the flats' height. + at(round, 340, 1, { safe: true }); + round.shots.push({ x: 378, y: bz.LANE_Y[1] + 2.4, vx: 130, vy: 0, gone: 0 }); + ghoul.advance(round, 4, steady); + assert.equal(round.runner.props[1].state, "broken"); + // What was shot stays shot when the boat is put back (a re-seat in the same room), a pocket still bursting too. + Object.assign(round.runner.gas[1], { state: "burst", t: 300 }); + bz.BOGBOAT.place[0](round, {}); + assert.equal(round.runner.gas[0].state, "spent"); + assert.equal(round.runner.props[0].state, "broken"); + assert.equal(round.runner.props[1].state, "broken"); + assert.equal(round.runner.gas[1].state, "spent", "a burst pocket is not revived"); + const fresh = synth({ gas: [[420, 0]] }); + assert.equal(fresh.runner.gas[0].state, "up"); +}); + +/* --------------------------------------------------------------- the round */ + +test("Ghoul Rush's Bog Runner: the last heart gone ends the round with nothing at once (no life lost, the dice in hand kept) and the run goes on to the Drowning Pool", () => { + const round = boatRound(); + round.dice = 2; + round.bonusRound.hearts = 1; + const first = things().filter((t) => t.lane === 0 && HARMFUL.has(t.kind)).sort((a, b) => a.x - b.x)[0]; + at(round, first.x - 12, 0); + until(round, () => round.phase === "clear", 8000); + assert.equal(round.bonusRound.hearts, 0); + assert.equal(round.bonusRound.over, true); + assert.equal(round.bonusRound.won, false); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, false); + assert.equal(end[0].dice, 0); + assert.equal(round.over, false, "no game over"); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + run(round, ghoul.CARD_LOST_MS + 100); + assert.equal(round.spec.id, "drowning"); + assert.equal(round.bonusRound, null); + assert.equal(round.runner, null); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + skipBossIntro(ghoul, round); + assert.equal(round.phase, "ready"); +}); + +test("Ghoul Rush's Bog Runner: the checkpoints are passed in order (an event each) and the ride goes back to the last one after the last heart", () => { + const round = boatRound(); + at(round, R.checks[0] - 6, 0, { safe: true }); + until(round, () => round.runner.check >= 0, 3000); + assert.deepEqual(events(round, "bogboatCheck").map((e) => e.n).slice(0, 1), [1]); + const c0 = round.runner.check; + round.you.x = 1; + bz.BOGBOAT.place[0](round, {}); + assert.equal(round.you.x, R.checks[c0]); + assert.equal(round.runner.check, c0); + assert.equal(round.runner.lane, 0); + assert.equal(round.camLead, bz.CAM_AHEAD); + const fresh = boatRound(); + assert.equal(fresh.you.x, ROOM.start); + assert.equal(fresh.runner.check, -1); + // Past all four on a long ride. + const long = synth({ checks: R.checks }); + long.you.safeMs = 1e9; + long.timeMs = 1e9; + run(long, 62000); + assert.equal(long.runner.check, R.checks.length - 1); +}); + +test("Ghoul Rush's Bog Runner: at the finish the fan is cut, the door opens, and walking out ends the round with 3 to 9 Lucky dice", () => { + const round = boatRound(); + round.dice = 1; + at(round, R.finish - 8, 1, { safe: true }); + until(round, () => round.runner.done, 3000); + assert.equal(round.runner.done, true); + assert.equal(events(round, "bogboatFinish").length, 1); + assert.equal(round.you.y, ghoul.groundAt(ROOM, round.you.x), "back down on the water's floor, from either lane"); + assert.equal(round.hasKey, true, "the door opens"); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.phase, "play"); + round.input.right = true; + until(round, () => round.phase === "clear", 20000); + round.input.right = false; + assert.equal(round.phase, "clear"); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, true); + assert.ok(end[0].dice >= BONUS_FLOOR && end[0].dice <= ghoul.MAX_DICE, `${end[0].dice} dice`); + assert.equal(round.dice, Math.min(ghoul.MAX_DICE, 1 + end[0].dice)); + assert.equal(round.lives, 3); + run(round, ghoul.CARD_MS + 100); + assert.equal(round.spec.id, "drowning"); + assert.equal(round.runner, null); +}); + +test("Ghoul Rush's Bog Runner: no random number is drawn in the room (a ride of 20 seconds, jumping, switching and shooting, on a draw that throws)", () => { + const round = boatRound(); + round.you.safeMs = 1e9; + for (let t = 0; t < 20000; t += 16) { + round.input.fire = true; + round.input.right = t % 6000 < 3000; + round.input.left = !round.input.right; + round.input.down = t % 2500 < 400; + if (t % 1500 === 0) press(round); + ghoul.advance(round, 16, never); + round.input.up = false; + round.events.length = 0; + } + assert.ok(round.you.x > 300); +}); + +/* ----------------------------------------------------------- grade and dice */ + +test("Ghoul Rush's Bog Runner's grade: the obstacles the boat faced are the total, one passed in its lane counts and one dodged by a lane does not, shooting 8 things is the die, a swarm that never boiled is the die", () => { + const ride = { banks: [[300, 316]], snags: [[400, 0]], knees: [[460, 0], [460, 1]], gas: [[600, 1]] }; + const round = synth(ride); + at(round, 250, 0, { safe: true }); + assert.equal(round.bonusRound.perf.total, 0); + assert.equal(round.bonusRound.perf.goal, bz.ACTS_GOAL); + // Stay in the channel: the snag and the channel's knees are faced, not the flats' knees. + until(round, () => round.you.x > 480, 6000); + assert.equal(round.bonusRound.perf.total, 2); + // Switch away at the bank: the channel's things are dodged by the lane and not counted; the flats' are. + const away = synth(ride); + at(away, 296, 0, { safe: true }); + away.input.right = true; + run(away, 500); + away.input.right = false; + assert.equal(away.runner.lane, 1); + until(away, () => away.you.x > 480, 8000); + const faced = Object.keys(away.runner.faced).filter((id) => id[0] !== "w"); + assert.deepEqual(faced, ["k1"], "the flats' knees only: the channel's things were dodged by a lane"); + assert.equal(away.bonusRound.perf.hits.filter((id) => id[0] !== "w").length, 0); + // A faced thing that cost a heart is a hit, counted once. + const hit = synth(ride); + at(hit, 385, 0); + run(hit, 800); + assert.deepEqual(hit.bonusRound.perf.hits, ["s0"]); + assert.equal(hit.bonusRound.perf.total, 1); + // The dice: the floor, hearts, clean passes, acts, a swarm that never boiled. + const b = makeBonus({ stats: { kills: 0 } }); + b.perf = { total: 20, hits: [], acts: 0, goal: bz.ACTS_GOAL, steady: false, kills0: 0 }; + assert.equal(diceFor(b), BONUS_FLOOR + 2 + 2); + b.perf.steady = true; + assert.equal(diceFor(b), 9 - 1); + b.perf.acts = bz.ACTS_GOAL; + assert.equal(diceFor(b), 9); + b.perf.acts = bz.ACTS_GOAL - 1; + assert.equal(diceFor(b), 8); + b.hearts = 1; + assert.equal(diceFor(b), 6); + b.perf.hits = Array.from({ length: 20 }, (_, i) => `x${i}`); + assert.equal(diceFor(b), BONUS_FLOOR + 0 + 0 + 0 + 1); + b.perf.steady = false; + assert.equal(diceFor(b), BONUS_FLOOR); +}); + +const CAUSES = { + snag: { snags: [[300, 0]] }, + knee: { knees: [[300, 0]] }, + veil: { veils: [[300, 308, 0]] }, + limb: { limbs: [[300, 306, 0]] }, +}; + +test("Ghoul Rush's Bog Runner: endless lives (round.infinite) spare the hearts for every cause, through the same lose path", () => { + for (const [cause, ride] of Object.entries(CAUSES)) { + const round = synth(ride); + round.infinite = true; + at(round, 270, 0); + run(round, 1800); + assert.ok(events(round, "lose").some((e) => e.cause === cause), `${cause} was lost to`); + assert.equal(round.bonusRound.hearts, 5, `${cause} cost nothing`); + assert.equal(round.lives, 3); + assert.equal(round.phase, "play"); + } + const wake = synth({}); + wake.infinite = true; + at(wake, 100, 0); + wake.runner.v = 20; + wake.runner.gap = bz.WAKE_CATCH + 0.2; + run(wake, 200, { down: true }); + assert.ok(events(wake, "lose").some((e) => e.cause === "wake"), "the wake was lost to"); + assert.equal(wake.bonusRound.hearts, 5); +}); + +test("Ghoul Rush's Bog Runner: every cause costs exactly one heart", () => { + for (const [cause, ride] of Object.entries(CAUSES)) { + const round = synth(ride); + at(round, 270, 0); + run(round, 1800); + assert.equal(round.bonusRound.hearts, 4, cause); + assert.equal(events(round, "lose").map((e) => e.cause).join(), cause); + assert.equal(round.lives, 3); + } +}); + +test("Ghoul Rush's Bog Runner: the Garlic shield takes a hit instead of a heart", () => { + const round = synth({ snags: [[300, 0]] }); + round.you.garlic = true; + at(round, 285, 0); + round.you.garlic = true; + run(round, 800); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.you.garlic, false); +}); + +/* ---------------------------------------------------------------- voices */ + +test("Ghoul Rush's Bog Runner: every event has a voice that plays, every cause has words and a sound, and the voices are tones that exist (none over 1.2 s)", () => { + assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...bz.EVENTS].sort(), "a voice for every event and no more"); + const tones = ghoulSfx.default.tones; + for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) { + const name = BOAT_VOICES[kind] && BOAT_VOICES[kind][act]; + assert.ok(name, `${event} has a ${kind}.${act} voice`); + assert.ok(tones[name], `${name} exists`); + assert.equal(VOICES[kind][act], name, "joined to the game's voices"); + const played = heard({ type: event, what: "snag", kind: 0, points: 50, to: 1 }).played; + assert.ok(played.includes(name), `${event} plays ${name}`); + } + for (const [name, def] of Object.entries(BOGBOAT_SFX.tones)) { + assert.ok(tones[name], name); + for (const l of def.layers) assert.ok(l.seconds > 0 && l.seconds + (l.delay || 0) <= 1.2, `${name} is short`); + } + for (const cause of ["snag", "knee", "veil", "limb", "wake"]) { + assert.ok(LOSE_WORDS[cause], `${cause} has words`); + assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`); + assert.ok(heard({ type: "lose", cause, hearts: 3 }).played.length > 0, `${cause} sounds`); + } + assert.equal(heard({ type: "bogboatJump" }).played.length, 1); + assert.equal(heard({ type: "bogboatGas", points: 90 }).played.length, 1); +}); + +test("Ghoul Rush's Bog Runner: its music has the room's level of voices, bars of sixteen steps, and a track for the room", () => { + const track = ghoulSfx.default.music.ghoulBoatRide; + assert.equal(track, BOGBOAT_SFX.music.ghoulBoatRide); + const playing = Object.entries(track.voices).filter(([, v]) => (v.from ?? 0) <= 0.7); + assert.ok(playing.length >= 4); + for (const [name, p] of Object.entries(track.patterns)) { + for (const [voice, line] of Object.entries(p)) { + assert.ok(track.voices[voice], `${name}.${voice} is a voice`); + for (const bar of line.split("|")) assert.equal(bar.trim().split(/\s+/).length, 16, `${name}.${voice}`); + } + } + for (const name of track.order) assert.ok(track.patterns[name]); +}); + +test("Ghoul Rush's Bog Runner: the room's own names do not collide with the game's (hazards, events, kinds)", () => { + for (const e of bz.EVENTS) assert.ok(e.startsWith("bogboat"), e); + assert.ok(!bz.EVENTS.some((e) => e.startsWith("bogboatboat")), "no bogboatboat names"); + assert.deepEqual(Object.keys(bz.BOGBOAT).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []); + assert.equal(typeof ghoul.ROOM_MUSIC.bogboat, "string"); + assert.equal(ghoul.roomById("bogboat").ride.runner, "bogboat"); + for (const kind of Object.keys(BOAT_VOICES)) assert.ok(kind.startsWith("bogboat"), kind); +}); + +/* --------------------------------------------------------------- drawing */ + +test("Ghoul Rush's Bog Runner draws: the room in a lit and a dark one, the boat on each lane, in the air, ducking and switching, each thing in each state, the swarm far and close, the clog and the stall, a crash, the finish and the cards", () => { + const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) }); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + g.resize(900, 900); + g.key("action"); + g.tick(16); + const r = g.round; + through(r); + r.offer = ["bog"]; + r.phaseMs = 0; + ghoul.pickStage(r, 0); + while (r.spec.id !== "bogboat") through(r); + r.lives = 99; + const spots = [ROOM.start + 40, R.snags[0][0] - 10, R.limbs[0][0] - 5, R.veils[0][0] - 5, R.gas[0][0] - 10, R.checks[0], R.banks[0][0] + 2, R.finish - 40]; + for (const dark of [true, false]) { + for (const x of spots) { + r.dark = dark; + r.phase = "play"; + for (const st of r.spawns) st.over = true; + r.hordeMs = Infinity; + r.monsters.length = 0; + for (const lane of [0, 1]) { + at(r, x, lane, { safe: true }); + r.runner.props = r.runner.props.map((p, i) => ({ ...p, state: i % 3 ? "up" : "broken" })); + r.runner.gas = r.runner.gas.map((p, i) => ({ ...p, state: ["up", "burst", "spent"][i % 3], t: 300 })); + for (const air of [false, true]) { + if (air) Object.assign(r.runner, { air: true, h: 5, vy: 20, gap: 12, panic: true, clog: 90 }); + if (air) Object.assign(r.you, { state: "air", vy: 20, y: r.you.y + 5 }); + if (!air) Object.assign(r.runner, { gap: 30, panic: false, clog: 20 }); + r.you.ducking = !air && lane === 0; + r.runner.stall = air ? 800 : 0; + r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: 0, gone: 0 }); + for (let k = 0; k < 4; k++) g.tick(16); + r.monsters.length = 0; + r.you.safeMs = 1e9; + at(r, x, lane, { safe: true }); + } + } + } + } + // A switch in progress, mid-hop. + at(r, R.banks[0][0] + 2, 0, { safe: true }); + r.input.right = true; + for (let k = 0; k < 12; k++) g.tick(16); + r.input.right = false; + assert.equal(r.spec.id, "bogboat"); + // Crashes: a snag. + r.you.safeMs = 0; + at(r, R.snags[0][0] - 3, R.snags[0][1]); + for (let k = 0; k < 30; k++) g.tick(16); + assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too"); + const done = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + done.resize(900, 900); + done.key("action"); + done.tick(16); + const d = done.round; + through(d); + d.offer = ["bog"]; + d.phaseMs = 0; + ghoul.pickStage(d, 0); + while (d.spec.id !== "bogboat") through(d); + d.phase = "play"; + d.runner.done = true; + d.runner.restX = R.finish + 10; + Object.assign(d.you, { x: R.finish + 20, y: 9, state: "run" }); + d.camX = R.finish - 40; + for (let k = 0; k < 10; k++) done.tick(16); + for (const won of [true, false]) { + endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) }); + d.bonusRound.over = true; + for (let k = 0; k < 10; k++) { + done.tick(16); + bonusTick(d, { tone() {}, fx: {} }); + } + d.bonusRound.over = false; + } + // The stage select goes straight into it. + const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + pick.resize(900, 900); + pick.stageSelect(); + const p = pick.round; + const at2 = ghoul.STAGES.findIndex((s) => s.id === "bog"); + for (let i = 0; i < at2; i++) ghoul.steerSelect(p, 1, 0); + for (let i = 0; i < 3; i++) ghoul.steerSelect(p, 0, 1); + assert.equal(p.select.room, 3); + pick.tick(16); + ghoul.takeSelect(p); + assert.equal(p.spec.id, "bogboat"); + assert.equal(p.runner.lane, 0); + assert.equal(p.you.y, bz.LANE_Y[0]); + pick.tick(16); +}); + +/* ----------------------------------------------------------- the bots */ + +// A bot that rides well: it keeps to the channel, jumps 9 to 15 short of a snag or cypress knees, ducks under +// every veil and limb, and holds the blaster. `miss` is the share of things it fails to dodge (by a hash). +const mix = (a, b) => { + let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +function goodBot(round, seed, miss = 0.04, shoot = true) { + const { you, runner: c, input: inp } = round; + inp.left = inp.right = inp.down = false; + inp.fire = shoot; + if (round.phase !== "play" || !c || c.done) { + inp.up = false; + return; + } + const ok = (x) => mix(seed, Math.round(x)) >= miss; + const look = 9 + (seed % 7); + const lane = c.lane; + const bank = R.banks.find(([a, b]) => you.x >= a && you.x <= b); + if (bank) inp.left = true; + let jump = false; + const ahead = (x) => x - you.x > 6 && x - you.x < look; + for (const [x, l] of R.snags) if (l === lane && ahead(x) && ok(x)) jump = true; + for (const [x, l] of R.knees) if (l === lane && ahead(x) && ok(x)) jump = true; + for (const [x0, x1, l] of [...R.veils, ...R.limbs]) if (l === lane && you.x > x0 - 10 && you.x < x1 + 3 && ok(x0)) inp.down = true; + if (jump && !inp.down && !c.air) press(round); + else inp.up = false; +} +function idleBot(round) { + const inp = round.input; + inp.left = inp.right = inp.down = false; + inp.up = false; + inp.fire = true; +} +function rideWith(seed, bot, limit = 100000) { + const round = boatRound(seed); + const lost = []; + let t = 0; + for (; t < limit && round.phase !== "clear" && !round.over; t += 16) { + bot(round); + if (round.runner && round.runner.done && round.phase === "play") round.input.right = true; + ghoul.advance(round, 16, steady); + for (const e of round.events) if (e.type === "lose") lost.push(e.cause); + if (round.runner && !round.runner.done) { + const off = round.you.x - round.camX; + assert.ok(off > 4 && off < 70, `the boat stays in view (${off.toFixed(1)} from the left edge at ${round.you.x.toFixed(0)})`); + } + round.events.length = 0; + } + return { round, lost, ms: t }; +} + +test("Ghoul Rush's Bog Runner: a bot that rides well finishes the whole channel in 57 to 75 seconds, with 5 to 9 dice, a few hearts lost at most, past every checkpoint", () => { + const dice = []; + const gone = []; + for (let seed = 1; seed <= 12; seed++) { + const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed)); + const b = round.bonusRound; + assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")})`); + assert.ok(ms > 57000 && ms < 76000, `${ms} ms`); + assert.ok(b.dice >= 5 && b.dice <= ghoul.MAX_DICE, `${b.dice} dice`); + assert.equal(round.lives, 3, "never a run life"); + dice.push(b.dice); + gone.push(lost.length); + } + assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 5.5, `${dice.join(",")}`); + assert.ok(gone.every((n) => n <= 4), `${gone.join(",")}`); +}); + +test("Ghoul Rush's Bog Runner: a bot that misses a quarter of the things loses, and a bot that never dodges (holding fire) loses all five hearts before 40% of the room, ends with 0 dice and the run goes on", () => { + let finished = 0; + for (let seed = 1; seed <= 6; seed++) if (rideWith(seed, (r) => goodBot(r, seed, 0.25)).round.bonusRound.won) finished++; + assert.ok(finished <= 3, `${finished} of 6 finished missing a quarter`); + for (let seed = 1; seed <= 6; seed++) { + const { round, lost } = rideWith(seed, idleBot); + const b = round.bonusRound; + assert.equal(b.won, false, "never finishes"); + assert.equal(b.dice, 0); + assert.equal(b.hearts, 0); + assert.equal(lost.length, 5); + assert.ok(round.you.x < ROOM.length * 0.4, `out at ${round.you.x}`); + assert.equal(round.lives, 3); + assert.equal(round.over, false); + } +}); + +/* ------------------------------------------------------------ telegraphs */ + +test("Ghoul Rush's Bog Runner telegraphs: JUMP over snags and knees, DUCK under veils and limbs, SHOOT at the first gas pockets, for the boat's lane only, words on the first three of each kind, the same every time", () => { + const marks = telegraphMarks(R); + const gasMarks = marks.filter((m) => m.kind === "gas"); + assert.ok(gasMarks.length >= 1 && gasMarks.length < R.gas.length, "only the first pockets are marked"); + assert.equal(marks.length, R.snags.length + R.knees.length + R.veils.length + R.limbs.length + gasMarks.length); + for (const m of marks) assert.equal(m.answer, ANSWERS[m.kind], m.kind); + assert.equal(ANSWERS.snag, "JUMP"); + assert.equal(ANSWERS.knee, "JUMP"); + assert.equal(ANSWERS.veil, "DUCK"); + assert.equal(ANSWERS.limb, "DUCK"); + assert.equal(ANSWERS.gas, "SHOOT"); + const first = R.limbs[0]; + const m = marks.find((q) => q.kind === "limb" && q.x === (first[0] + first[1]) / 2); + const lane = first[2]; + const xs = [m.lead - 45, m.lead - 41, m.lead - 36, m.lead - 30, m.lead - 10, m.lead, m.lead + 3, m.lead + 7]; + const alphaOf = (x) => (telegraphs(R, x, lane).find((t) => t.kind === "limb" && t.lead === m.lead) || { alpha: 0 }).alpha; + const a = xs.map(alphaOf); + assert.equal(a[0], 0, "not yet in view"); + assert.ok(a[2] > 0 && a[2] < 1, "fading in 40 to 30 ahead"); + assert.equal(a[3], 1); + assert.equal(a[4], 1); + assert.ok(a[6] > 0 && a[6] < 1, "fading as it passes"); + assert.equal(a[7], 0, "gone once passed"); + assert.deepEqual(telegraphs(R, m.lead - 33, lane), telegraphs(R, m.lead - 33, lane), "deterministic"); + for (const kind of ["snag", "knee", "veil", "limb", "gas"]) { + const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead); + assert.ok(of.length >= 1, kind); + of.forEach((q, i) => { + assert.equal(q.n, kind === "gas" ? q.n : i); + const shown = telegraphs(R, q.lead - 32, q.lane).find((t) => t.lead === q.lead && t.kind === kind); + assert.ok(shown, `${kind} ${i} shows`); + assert.equal(shown.words, q.n < TELEGRAPH_WORDS, `${kind} ${i}`); + }); + } + // In the other lane a thing shows nothing. + const s = marks.find((q) => q.kind === "snag"); + assert.ok(!telegraphs(R, s.lead - 32, 1 - s.lane).some((t) => t.lead === s.lead && t.kind === "snag")); +}); + +test("Ghoul Rush's Bog Runner's intro banner says the controls plainly", () => { + assert.match(R.how, /LEFT or RIGHT at a bank/); + assert.match(R.how, /UP jump, DOWN duck/); + assert.match(R.how, /SPACE shoot/); + assert.ok(R.how.length <= 72); +}); diff --git a/scripts/test-web-console-activities-ghoul-bossintro.mjs b/scripts/test-web-console-activities-ghoul-bossintro.mjs new file mode 100644 index 0000000..c9080f3 --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-bossintro.mjs @@ -0,0 +1,303 @@ +// Web console tests, Ghoul Rush's boss intro cards: every boss room has an entry (the boss's exact name, an epithet, no em dash, never the hero's name), the card shows when a boss room is entered (after the bonus ride too) and in no other room, not again on a retry, any fresh move key, fire or click moves it on after the lockout (repeats and early presses never do), it never moves on by itself, a pause holds it, and it draws for every boss on a fake canvas (through the boss's own art, with a fallback when the art throws or is missing). +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { BOSS_INTROS, MAX_EPITHET, bossIntroFor } from "../src/web-console/public/activities/ghoul-boss-intros.js"; +import { BOSS_HINT, BOSS_TITLE, beatAt, landAt, shakeAt, bossIntroArt } from "../src/web-console/public/activities/ghoul-bossintro-draw.js"; +import { INTROS } from "../src/web-console/public/activities/ghoul-intros.js"; +import { toneNames } from "../src/web-console/public/tones.js"; +import { skipBossIntro } from "./ghoul-test-helpers.mjs"; + +const steady = () => 0.5; +const DASH = String.fromCharCode(0x2014); + +function fakeCtx(texts) { + return new Proxy({}, { + get: (t, name) => (name in t ? t[name] : name === "fillText" ? (s) => texts.push(s) : () => {}), + set: (t, name, value) => ((t[name] = value), true), + }); +} + +function newGame(texts = [], opts = {}) { + const ctx = fakeCtx(texts); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, ...opts }); + g.resize(900, 900); + g.key("action"); + g.round.dice = 0; + return g; +} + +// A game on the stage select, straight into room `room` of the stage at `at` (a boss room is the last). +function selectInto(at, room, texts = [], opts = {}) { + const g = newGame(texts, opts); + g.round.phase = "select"; + g.round.select = { at, room }; + g.round.practice = true; + g.key("action"); + return g; +} + +const bossRooms = ghoul.ROOMS.filter((r) => r.boss); + +// A round at the stage pick, the offer settled, then into `id`'s first room (the stage's intro card skipped). +function inStage(id) { + const r = ghoul.newRound(3); + r.dice = 0; + r.phase = "clear"; + r.phaseMs = 1; + ghoul.advance(r, 4, steady); + r.offer = [id]; + r.phaseMs = 0; + assert.equal(ghoul.pickStage(r, 0), true); + r.introMs = ghoul.INTRO_MIN_MS; + assert.equal(ghoul.takeIntro(r), true); + return r; +} + +const through = (round) => { + round.phase = "clear"; + round.phaseMs = 1; + ghoul.advance(round, 4, steady); +}; + +test("Ghoul Rush boss intros: every boss room has an entry with the boss's exact name and a short epithet, no em dash, never the hero's name", () => { + assert.ok(bossRooms.length >= 10, "the boss rooms are found"); + const ids = new Set(bossRooms.map((r) => r.boss)); + for (const id of ids) { + const info = bossIntroFor(id); + assert.ok(info, `the boss "${id}" needs an entry in ghoul-boss-intros.js (BOSS_INTROS)`); + assert.equal(info.name, ghoul.BOSSES[id].name, `${id}: the name is the boss's own`); + assert.ok(typeof info.epithet === "string" && info.epithet.length >= 8 && info.epithet.length <= MAX_EPITHET, `${id}: an epithet of 8 to ${MAX_EPITHET} characters`); + for (const text of [info.name, info.epithet]) { + assert.ok(!text.includes(DASH), `${id}: no em dash`); + assert.ok(!/planny/i.test(text), `${id}: never the hero's name`); + } + if (info.accent) assert.match(info.accent, /^#[0-9a-f]{6}$/i); + } + for (const id of Object.keys(BOSS_INTROS)) assert.ok(ids.has(id), `${id} is no boss of any room`); + for (const st of ghoul.STAGES) { + assert.ok(INTROS[st.id], st.id); + assert.equal(INTROS[st.id].boss, bossIntroFor(st.boss).name, `${st.id}: the stage card and the boss card agree on the name`); + assert.equal(ghoul.roomById(st.rooms.at(-1)).boss, st.boss, `${st.id}: its last room holds its boss`); + } + assert.equal(bossIntroFor("nobody"), null); + assert.ok(toneNames().includes("ghoulBossIntro"), "the sting is a real tone"); +}); + +test("Ghoul Rush boss intros: a new boss room added without an entry would fail (the check reads every room)", () => { + const missing = [...ghoul.ROOMS, { id: "fake", boss: "newfiend" }].filter((r) => r.boss && !bossIntroFor(r.boss)).map((r) => r.boss); + assert.deepEqual(missing, ["newfiend"]); +}); + +test("Ghoul Rush boss intros: every stage's boss room opens on the card, after the bonus ride too, and no other room does", () => { + for (const st of ghoul.STAGES) { + const r = inStage(st.id); + for (let i = 0; i < st.rooms.length; i++) { + const id = st.rooms[i]; + assert.equal(r.spec.id, id); + const boss = Boolean(ghoul.roomById(id).boss); + if (i === st.rooms.length - 1) { + assert.ok(boss, `${st.id}: the last room is the boss room`); + assert.ok(ghoul.roomById(st.rooms[i - 1]).bonus, `${st.id}: the bonus ride comes right before the boss`); + } + if (!boss) { + assert.notEqual(r.phase, "bossintro", `${st.id}/${id}: no card here`); + assert.equal(r.phase, "ready", `${st.id}/${id}`); + assert.equal(r.events.some((e) => e.type === "bossIntro"), false); + r.events.length = 0; + through(r); + continue; + } + assert.equal(r.phase, "bossintro", `${st.id}: the boss room opens on its card`); + assert.deepEqual(r.events.filter((e) => e.type === "bossIntro").map((e) => [e.boss, e.stage]), [[st.boss, st.id]]); + assert.equal(r.events.some((e) => e.type === "room" && e.room === r.room), false, "the room's announcement waits for the card"); + assert.ok(r.boss && r.boss.kind === st.boss, "the boss room is set up behind the card"); + assert.equal(r.boss.state, "sleep"); + // Nothing moves while the card is up. + const at = r.you.x; + r.input.right = true; + ghoul.advance(r, 600, steady); + assert.equal(r.you.x, at); + assert.equal(r.phase, "bossintro"); + r.input.right = false; + // The lockout, then a press. + ghoul.advance(r, ghoul.INTRO_MIN_MS - 650, steady); + assert.equal(ghoul.takeIntro(r), false, "not before the lockout"); + ghoul.advance(r, 100, steady); + r.events.length = 0; + assert.equal(ghoul.takeIntro(r), true); + assert.equal(r.phase, "ready"); + assert.equal(r.phaseMs, ghoul.READY_MS); + assert.equal(r.events.filter((e) => e.type === "room").length, 1, "the boss room is announced now"); + assert.equal(ghoul.takeIntro(r), false, "taken once"); + ghoul.advance(r, ghoul.READY_MS + 20, steady); + assert.equal(r.phase, "play"); + } + } +}); + +test("Ghoul Rush boss intros: the last room's door shows the card, a retry inside the boss room never does", () => { + const r = inStage("manor"); + while (!ghoul.roomById(r.spec.id).boss) through(r); + assert.equal(r.phase, "bossintro"); + skipBossIntro(ghoul, r); + ghoul.advance(r, ghoul.READY_MS + 20, steady); + assert.equal(r.phase, "play"); + r.lives = 9; + r.you.safeMs = 0; + for (let n = 0; n < 3; n++) { + r.events.length = 0; + ghoul.lose(r, "zombie"); + for (let ms = 0; ms < ghoul.CRASH_MS + 400 && r.phase !== "ready" && r.phase !== "over"; ms += 16) { + ghoul.advance(r, 16, steady); + assert.notEqual(r.phase, "bossintro", "no card on a retry"); + } + assert.equal(r.phase, "ready", `retry ${n + 1} restarts the room`); + assert.equal(r.events.some((e) => e.type === "bossIntro"), false, "no card event on a retry"); + ghoul.advance(r, ghoul.READY_MS + 20, steady); + r.you.safeMs = 0; + } +}); + +test("Ghoul Rush boss intros: the stage select shows the card for a boss room only, like the stage's card on its first room", () => { + ghoul.STAGES.forEach((st, at) => { + const g = selectInto(at, st.rooms.length - 1); + assert.equal(g.round.phase, "bossintro", `${st.id}: straight into the boss room`); + assert.equal(g.round.stage, st.id); + const mid = selectInto(at, 2); + assert.equal(mid.round.phase, "ready", `${st.id}: a mid-stage room has no card`); + const bonus = selectInto(at, st.rooms.length - 2); + assert.equal(bonus.round.phase, "ready", `${st.id}: the bonus ride has none`); + }); +}); + +test("Ghoul Rush boss intros: with the window's keys, a held fire never skips it, a fresh press does after the lockout, a click works, and a pause holds it", () => { + const sounds = []; + const texts = []; + const g = selectInto(0, ghoul.STAGES[0].rooms.length - 1, texts, { tone: (name) => sounds.push(name) }); + assert.equal(g.round.phase, "bossintro"); + for (let k = 0; k < 5; k++) g.key("action", true); + g.key("action"); + assert.equal(g.round.phase, "bossintro", "too soon, and repeats never count"); + assert.equal(g.round.input.fire, false, "no shot fired at the card"); + g.tick(16); + assert.ok(sounds.includes("ghoulBossIntro"), "the sting plays when the card opens"); + for (let ms = 0; ms < 3000; ms += 16) g.tick(16); + texts.length = 0; + g.tick(16); + const info = bossIntroFor(ghoul.STAGES[0].boss); + assert.ok(texts.includes(BOSS_HINT), "the hint shows"); + assert.match(BOSS_HINT, /any move key or fire to start the fight/); + assert.ok(BOSS_TITLE.split("").every((ch) => ch === " " || texts.includes(ch)), "every letter of BOSS FIGHT is drawn"); + assert.ok(texts.includes(info.name.toUpperCase()), "the boss's name is drawn"); + assert.ok(texts.includes(info.epithet), "the epithet is drawn"); + g.pause(); + const held = g.round.introMs; + for (let k = 0; k < 20; k++) g.tick(16); + assert.equal(g.round.introMs, held, "a pause holds the card"); + texts.length = 0; + g.tick(16); + g.resume(); + g.key("action", true); + assert.equal(g.round.phase, "bossintro", "a repeat still does nothing"); + g.release("action"); + g.key("action"); + assert.equal(g.round.phase, "ready", "a fresh press starts the fight"); + assert.equal(g.round.input.fire, false); + // Each of the other keys, and a click. + for (const name of ["left", "right", "up", "down", "action"]) { + const k = selectInto(3, ghoul.STAGES[3].rooms.length - 1); + k.key(name); + assert.equal(k.round.phase, "bossintro", `${name}: an early press is ignored`); + for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 100; ms += 16) k.tick(16); + k.key(name, true); + assert.equal(k.round.phase, "bossintro", `${name}: a repeat is ignored`); + k.release(name); + k.key(name); + assert.equal(k.round.phase, "ready", `${name}: a fresh press moves on`); + assert.equal(k.round.input.fire, false, "no shot fired at the card"); + } + const h = selectInto(5, ghoul.STAGES[5].rooms.length - 1); + h.pointer("down", 10, 10); + assert.equal(h.round.phase, "bossintro", "a click before the lockout is ignored"); + for (let ms = 0; ms < 1300; ms += 16) h.tick(16); + h.pointer("down", 10, 10); + assert.equal(h.round.phase, "ready", "a click moves on"); +}); + +test("Ghoul Rush boss intros: it never moves on by itself, not after a minute and not after an hour", () => { + const q = inStage("manor"); + while (!ghoul.roomById(q.spec.id).boss) through(q); + assert.equal(q.phase, "bossintro"); + for (const ms of [15000, 60000, 3600000]) { + ghoul.advance(q, ms, steady); + assert.equal(q.phase, "bossintro", `still waiting after ${ms} ms more`); + } + assert.equal(q.boss.state, "sleep", "the boss has not woken"); + assert.equal(ghoul.takeIntro(q), true, "a press still works after any wait"); + const g = selectInto(2, ghoul.STAGES[2].rooms.length - 1); + for (let ms = 0; ms < 120000; ms += 100) g.tick(100); + assert.equal(g.round.phase, "bossintro"); +}); + +test("Ghoul Rush boss intros: the card draws for every boss at many moments, through that boss's own art", () => { + const sizes = { W: 96, H: 54 }; + for (const room of bossRooms) { + const id = room.boss; + const st = ghoul.STAGES.find((s) => s.boss === id); + const calls = []; + const BOSS_ART = new Proxy({}, { get: (t, k) => (k === id ? (ctx, pic, b) => calls.push([pic, b]) : undefined) }); + const texts = []; + const ctx = fakeCtx(texts); + const draw = bossIntroArt({ label: (c, text) => c.fillText(text), circle: () => {}, BOSS_ART, drawGourdFire: () => {}, GOLD: "#fc0", BONE: "#eee" }); + const v = { g: { FIELD_W: sizes.W, FIELD_H: sizes.H }, round: { spec: { boss: id }, stage: st ? st.id : null, introMs: 0 }, bosses: ghoul.BOSSES }; + for (let t = 0; t <= 6000; t += 37) { + v.round.introMs = t; + draw(ctx, v); + } + assert.ok(calls.length > 50, `${id}: the boss's art was called`); + assert.ok(calls.every(([pic, b]) => b.kind === id && b.w === ghoul.BOSSES[id].w && b.h === ghoul.BOSSES[id].h), `${id}: drawn as itself`); + assert.ok(texts.includes(bossIntroFor(id).name.toUpperCase()), `${id}: the name`); + assert.ok(texts.includes(bossIntroFor(id).epithet), `${id}: the epithet`); + // The same through the game's own drawing, with the real art. + const g2texts = []; + const g = selectInto(ghoul.STAGES.findIndex((s) => s.boss === id), ghoul.STAGES.find((s) => s.boss === id).rooms.length - 1, g2texts); + assert.equal(g.round.phase, "bossintro", id); + for (let ms = 0; ms < 5000; ms += 80) { + g.round.introMs = ms; + g.tick(1); + } + assert.ok(g2texts.includes(bossIntroFor(id).name.toUpperCase()), `${id}: the game draws the card`); + } +}); + +test("Ghoul Rush boss intros: a boss whose art throws or is missing still gets its card, with a silhouette and its name", () => { + const v = { g: { FIELD_W: 96, FIELD_H: 54 }, round: { spec: { boss: "bones" }, stage: "wing", introMs: 3000 }, bosses: ghoul.BOSSES }; + for (const BOSS_ART of [{ bones: () => { throw new Error("broken art"); } }, {}, { bones: "not a function" }]) { + const texts = []; + let shapes = 0; + const ctx = new Proxy({}, { + get: (t, name) => (name in t ? t[name] : name === "fillText" ? (s) => texts.push(s) : name === "ellipse" ? () => shapes++ : () => {}), + set: (t, name, value) => ((t[name] = value), true), + }); + const draw = bossIntroArt({ label: (c, text) => c.fillText(text), circle: () => {}, BOSS_ART, drawGourdFire: () => {}, GOLD: "#fc0", BONE: "#eee" }); + assert.doesNotThrow(() => draw(ctx, v)); + assert.ok(shapes > 0, "a silhouette is drawn"); + assert.ok(texts.includes("OLD RATTLEBONES")); + } + // A card for a room that holds no boss (or one with no entry) draws nothing and does not throw. + const draw = bossIntroArt({ label: () => {}, circle: () => {}, BOSS_ART: {}, drawGourdFire: () => {}, GOLD: "#fc0", BONE: "#eee" }); + assert.doesNotThrow(() => draw(fakeCtx([]), { g: { FIELD_W: 96, FIELD_H: 54 }, round: { spec: { boss: null }, introMs: 10 }, bosses: ghoul.BOSSES })); + assert.doesNotThrow(() => draw(fakeCtx([]), { g: { FIELD_W: 96, FIELD_H: 54 }, round: { spec: { boss: "newfiend" }, introMs: 10 }, bosses: ghoul.BOSSES })); +}); + +test("Ghoul Rush boss intros: the letters land one after another, each jolting the card, and the heartbeat thumps twice a second apart", () => { + const lands = [...BOSS_TITLE].map((ch, i) => (ch === " " ? null : landAt(i))).filter((x) => x !== null); + assert.deepEqual(lands, [...lands].sort((a, b) => a - b)); + assert.ok(lands.at(-1) < 1800, "the title is in before the name"); + assert.equal(shakeAt(0), 0); + assert.ok(shakeAt(lands[0] + 10) > 0.5, "a jolt on a landing"); + assert.ok(shakeAt(lands[0] + 400) < shakeAt(lands[0] + 10), "which dies away"); + assert.ok(beatAt(0) > 0.9 && beatAt(120) < beatAt(0) && beatAt(200) > beatAt(120), "a thump, then a softer one"); + for (let t = 0; t < 5000; t += 17) assert.ok(beatAt(t) >= 0 && beatAt(t) <= 1.0001 && shakeAt(t) < 6); +}); diff --git a/scripts/test-web-console-activities-ghoul-carnival.mjs b/scripts/test-web-console-activities-ghoul-carnival.mjs index a120274..ee4cdac 100644 --- a/scripts/test-web-console-activities-ghoul-carnival.mjs +++ b/scripts/test-web-console-activities-ghoul-carnival.mjs @@ -157,7 +157,7 @@ test("Ghoul Rush's Midnight Carnival is a stage of three rooms, the dark ride (a assert.equal(st.boss, "ringmaster"); assert.equal(st.title, "The Midnight Carnival"); assert.equal(st.sub, "Every game is rigged in its favor"); - assert.equal(ghoul.STAGES.at(-2), st, "the last stage in the list but the Frozen Lake"); + assert.equal(ghoul.STAGES.at(-3), st, "the last stage in the list but the Frozen Lake and Gallows Bog"); for (const kind of Object.keys(cv.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], cv.MONSTERS[kind], `${kind} is a monster`); assert.deepEqual(Object.keys(cv.MONSTERS).sort(), ["balloon", "circushound", "grinner", "marionette", "mirror", "strongman"]); assert.equal(ghoul.BOSSES.ringmaster, cv.BOSSES.ringmaster); @@ -2002,7 +2002,7 @@ test("Ghoul Rush's stage select lists the Carnival and takes you straight into e const r = g.round; assert.equal(r.phase, "select"); const at = ghoul.STAGES.findIndex((s) => s.id === "carnival"); - assert.equal(at, ghoul.STAGES.length - 2); + assert.equal(at, ghoul.STAGES.length - 3); for (let i = 0; i < at; i++) ghoul.steerSelect(r, 1, 0); for (let i = 0; i < 4; i++) ghoul.steerSelect(r, 0, 1); assert.equal(r.select.at, at); diff --git a/scripts/test-web-console-activities-ghoul-cart.mjs b/scripts/test-web-console-activities-ghoul-cart.mjs index fbb83f4..b206e9f 100644 --- a/scripts/test-web-console-activities-ghoul-cart.mjs +++ b/scripts/test-web-console-activities-ghoul-cart.mjs @@ -3,6 +3,7 @@ import { test } from "node:test"; import assert from "node:assert/strict"; import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { skipBossIntro } from "./ghoul-test-helpers.mjs"; import * as ct from "../src/web-console/public/activities/ghoul-cart.js"; import { EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as CART_LOOKS, VOICES as CART_VOICES } from "../src/web-console/public/activities/ghoul-cart-draw.js"; import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js"; @@ -1118,6 +1119,8 @@ test("Ghoul Rush's bonus round: the fifth lost heart ends it with no dice and no assert.equal(round.cart, null); assert.equal(round.lives, 3); assert.equal(round.dice, 2); + assert.equal(round.phase, "bossintro", "the boss room opens on its card"); + skipBossIntro(ghoul, round); assert.equal(round.phase, "ready"); // A life lost there is a run life as always, and the dice roll for it. round.phase = "play"; diff --git a/scripts/test-web-console-activities-ghoul-chapel.mjs b/scripts/test-web-console-activities-ghoul-chapel.mjs index 1c2d018..1b0128d 100644 --- a/scripts/test-web-console-activities-ghoul-chapel.mjs +++ b/scripts/test-web-console-activities-ghoul-chapel.mjs @@ -82,7 +82,7 @@ const heard = (e, extra = {}) => { test("Ghoul Rush's Chapel is a stage of three rooms and the Choir's, its monsters and boss joined to the game's, with Holy Water and a place for each kind", () => { const st = ghoul.stageById("chapel"); - assert.deepEqual(st.rooms, ["nave", "tower", "loft", "choir"]); + assert.deepEqual(st.rooms, ["nave", "tower", "loft", "pew", "choir"], "the bonus ride (Holy Roller) sits before the Choir"); assert.equal(st.boss, "choirmaster"); assert.equal(st.title, "The Chapel"); assert.equal(st.sub, "Service is still in session"); @@ -90,7 +90,7 @@ test("Ghoul Rush's Chapel is a stage of three rooms and the Choir's, its monster assert.equal(ghoul.BOSSES.choirmaster, ch.BOSSES.choirmaster); assert.equal(ch.BOSSES.choirmaster.sub, "Silence the pipes one by one"); for (const id of st.rooms) assert.ok(ghoul.ROOM_MUSIC[id], `${id} has music`); - const [nave, tower, loft, choir] = st.rooms.map((id) => ghoul.roomById(id)); + const [nave, tower, loft, choir] = st.rooms.filter((id) => id !== "pew").map((id) => ghoul.roomById(id)); for (const room of [nave, tower, loft]) { assert.ok(room.key, `${room.id}: a key`); assert.ok(room.sky.length && room.candy.length && room.items.length && room.horde.length, `${room.id}: sky treasures, candy, items and a horde`); @@ -785,7 +785,7 @@ test("Every column of notes can be passed: for each gap a surface in the arena ( test("Every column can be reached from the one before: the next gap is the same height or one step either side, over a long fight", () => { const round = choirFight(); const gaps = []; - const rand = ghoul.seeded(11); + const rand = ghoul.seeded(2); round.boss.act = "idle"; round.boss.wait = 0; for (let t = 0; t < 70000; t += 4) { @@ -832,7 +832,7 @@ test("A jump from the floor clears the third gap too, with a window of about a f /* ----------------------------------------------------------- the rage */ -test("The Choirmaster at half his hp: a rage that is told, silenced pipes sounding again one at a time every 6 s (guarding him again), faster notes, and now and then two columns close together", () => { +test("The Choirmaster at half his hp: a rage that is told, and no pipe comes back for it alone", () => { const round = choirFight(); const b = round.boss; b.pipes.forEach((p) => { @@ -846,17 +846,202 @@ test("The Choirmaster at half his hp: a rage that is told, silenced pipes soundi assert.equal(events(round, "choirRage").length, 1, "the rage is told"); assert.equal(b.raged, true); assert.deepEqual(b.pipes.map((p) => p.on), [false, false, false, false], "none yet"); - // One every 6 s, one at a time. - const sounds = log(round, ch.RESOUND_MS * 4 + 200, "pipeSound"); - assert.equal(sounds.length, 4, "all four, one by one"); - for (let i = 1; i < sounds.length; i++) assert.ok(Math.abs(sounds[i][0] - sounds[i - 1][0] - ch.RESOUND_MS) < 60, `${sounds[i][0] - sounds[i - 1][0]} apart`); - assert.equal(new Set(sounds.map((s) => s[1].pipe)).size, 4, "a different pipe each time"); - assert.ok(b.pipes.every((p) => p.on && p.hp === p.max), "each at full hp"); - // While any sounds, he is guarded again. + // He is held to no columns, so the pipes stay down however long it takes. + run(round, 30000); + assert.equal(events(round, "pipeSound").length, 0); + assert.ok(b.pipes.every((p) => !p.on)); +}); + +/* ------------------------------------------- the pipes drop back in */ + +// A fight with all four pipes shot silent, his next cue due now. +function openFight() { + const round = choirFight(); + const b = round.boss; + until(round, () => b.x === round.spec.length - ch.HOME_FROM_END, 4000); + hold(round); + for (const p of b.pipes) { + p.hp = 1; + round.shots.push({ x: p.x - 3, y: p.y + 4, vx: 80, vy: 0, gone: 0 }); + run(round, 60); + } + assert.ok(b.pipes.every((p) => !p.on)); + Object.assign(b, { act: "idle", wait: 0 }); + round.events.length = 0; + return round; +} + +// Runs a fight until `n` columns are away, you kept safe and the bell off. +function columns(round, n, random = steady) { + const flownSoFar = () => events(round, "notes").filter((e) => !e.pair).length; + const want = flownSoFar() + n; + for (let t = 0; t < 60000 && (flownSoFar() < want || round.boss.act !== "idle"); t += 4) { + ghoul.advance(round, 4, random); + round.you.safeMs = 1e9; + round.twist.next = 1e9; + round.monsters.length = 0; + } +} + +test("The Choirmaster's pipes drop back in: with all four silent he stays open for four columns, warns on the third, and the fourth brings all of them back at full hp", () => { + const round = openFight(); + const b = round.boss; + assert.equal(ch.PIPES_BACK, 4); + columns(round, 2); + assert.ok(b.pipes.every((p) => !p.on), "still open after two"); + assert.equal(events(round, "pipesStir").length, 0); + columns(round, 1); + assert.ok(b.pipes.every((p) => !p.on), "still open after three"); + assert.equal(b.quiet, 1, "one column left"); + assert.equal(events(round, "pipesStir").length, 1, "and it warns you"); const hp = b.hp; round.shots.push({ x: b.x - b.w / 2 - 0.2, y: b.y + 5, vx: 80, vy: 0, gone: 0 }); - run(round, 20); - assert.equal(b.hp, hp); + ghoul.advance(round, 4, steady); + assert.equal(b.hp, hp - 1, "and still to be hurt"); + columns(round, 1); + assert.ok(b.pipes.every((p) => p.on && p.hp === p.max), "all four, at full hp"); + assert.ok(b.pipes.every((p) => p.dropMs > 0), "falling"); + // Guarded from the moment they start to fall. + const now = b.hp; + round.shots.push({ x: b.x - b.w / 2 - 0.2, y: b.y + 5, vx: 80, vy: 0, gone: 0 }); + ghoul.advance(round, 4, steady); + assert.equal(b.hp, now, "guarded again"); +}); + +test("A falling pipe cannot be shot and spews nothing; each lands in turn with its sound, and then has to be silenced all over again, which starts the count anew", () => { + const round = openFight(); + const b = round.boss; + columns(round, ch.PIPES_BACK); + const [first, , , last] = b.pipes; + assert.equal(last.dropMs - first.dropMs, 3 * ch.PIPE_DROP_STAGGER_MS, "one after another"); + hold(round); + // A bolt passes through a pipe still in the air. + round.events.length = 0; + round.shots.push({ x: first.x - 3, y: first.y + 4, vx: 80, vy: 0, gone: 0 }); + run(round, 60); + assert.equal(first.hp, first.max); + assert.equal(events(round, "pipeHit").length, 0); + assert.equal(events(round, "pipeSpew").length, 0); + // They land one at a time. + const lands = log(round, ch.PIPE_DROP_MS + 4 * ch.PIPE_DROP_STAGGER_MS, "pipeSound"); + assert.deepEqual(lands.map(([, e]) => e.pipe), [0, 1, 2, 3]); + assert.ok(b.pipes.every((p) => !(p.dropMs > 0))); + // Landed: shots count again, and silencing all four opens him and starts over. + for (const p of b.pipes) { + p.hp = 1; + p.spewIn = 1e9; + round.shots.push({ x: p.x - 3, y: p.y + 4, vx: 80, vy: 0, gone: 0 }); + run(round, 60); + } + assert.ok(b.pipes.every((p) => !p.on), "silenced again"); + assert.ok(events(round, "choirOpen").length >= 1); + run(round, 8); + assert.equal(b.quiet, ch.PIPES_BACK, "the count starts over"); +}); + +test("The pipes only come back once all four are silent: columns flown with one still sounding count for nothing, and the rage changes none of it", () => { + const round = choirFight(); + const b = round.boss; + b.pipes.forEach((p, i) => (p.on = i === 0)); + Object.assign(b, { act: "idle", wait: 0 }); + columns(round, ch.PIPES_BACK + 2); + assert.deepEqual(b.pipes.map((p) => p.on), [true, false, false, false]); + assert.equal(b.quiet, null); + const mad = openFight(); + mad.boss.hp = mad.boss.max * 0.4; + columns(mad, ch.PIPES_BACK - 1, ghoul.seeded(3)); + assert.ok(mad.boss.pipes.every((p) => !p.on), "not yet"); + columns(mad, 1, ghoul.seeded(4)); + assert.ok(mad.boss.pipes.every((p) => p.on), "back in the rage too"); +}); + +/* --------------------------------------- each column at its own speed */ + +// A long fight from a seed, every column as { at, v, pair, end }: `end` when it +// reaches the arena's far end. Bolts, ghosts and the bell kept out of it. +function flown(seed, raged) { + const round = choirFight(); + const b = round.boss; + until(round, () => b.x === round.spec.length - ch.HOME_FROM_END, 4000); + hold(round); + if (raged) { + b.hp = b.max * 0.4; + b.raged = true; + } + Object.assign(b, { act: "idle", wait: 0, gap: 1 }); + const random = ghoul.seeded(seed); + const end = round.spec.arena - 6; + const got = []; + for (let t = 0; t < 120000; t += 4) { + ghoul.advance(round, 4, random); + round.you.safeMs = 1e9; + round.twist.next = 1e9; + b.pipes.forEach((p) => (p.spewIn = 1e9)); + round.monsters.length = 0; + for (const e of round.events) if (e.type === "notes") got.push({ at: round.clock, v: e.v, pair: e.pair, gap: e.gap, end: round.clock + ((e.x - end) / e.v) * 1000 }); + round.events.length = 0; + } + return { round, got }; +} + +test("Every column of notes flies at its own speed: the whole column together, some far faster than usual and some far slower, in no fixed order", () => { + const { got } = flown(7, false); + assert.ok(got.length >= 25, `${got.length} columns`); + const vs = got.map((c) => c.v); + assert.ok(Math.min(...vs) <= ch.NOTE_V * 0.6, `some slow (${Math.min(...vs).toFixed(1)})`); + assert.ok(Math.max(...vs) >= ch.NOTE_V * 1.3, `some fast (${Math.max(...vs).toFixed(1)})`); + assert.ok(new Set(vs.map((v) => v.toFixed(1))).size >= 5, "many speeds"); + // One launch: every note in it alike, with the edge the art draws from. + const round = choirFight(); + Object.assign(round.boss, { act: "idle", wait: 0 }); + run(round, ch.CUE_MS + 20); + const notes = round.hazards.filter((h) => h.kind === "note"); + assert.equal(notes.length, 4); + assert.equal(new Set(notes.map((n) => n.v)).size, 1, "a column flies together"); + assert.ok(notes.every((n) => n.pace === 1), "the middle draw is the usual speed"); + // Different draws, different speeds: the table's ends are real. + for (const [draw, pace] of [[0, ch.NOTE_PACE[0]], [0.999, ch.NOTE_PACE.at(-1)]]) { + const r = choirFight(); + Object.assign(r.boss, { act: "cue", wait: 0, gap: 1, second: null }); + ghoul.advance(r, 4, () => draw); + const n = r.hazards.find((h) => h.kind === "note"); + assert.ok(Math.abs(n.v - ch.NOTE_V * pace) < 1e-9, `draw ${draw}`); + } +}); + +test("No column ever catches the one ahead: wherever you stand you get time between two gaps, a pair keeps its spacing, and even the slowest crosses the arena", () => { + for (const raged of [false, true]) { + for (const seed of [1, 2, 3, 4]) { + const { got } = flown(seed, raged); + assert.ok(got.length >= 20); + for (let i = 1; i < got.length; i++) { + const gap = got[i].end - got[i - 1].end; + const least = got[i].pair ? ch.PAIR_MS : ch.NOTE_SEP_MS; + assert.ok(gap >= least - 20, `seed ${seed}, column ${i}: ${gap.toFixed(0)} ms behind at the far end`); + // Launched later and arriving later, so it is behind at every spot between. + assert.ok(got[i].at > got[i - 1].at); + } + if (raged) assert.ok(got.some((c) => c.pair), "pairs in the rage"); + for (let i = 1; i < got.length; i++) if (got[i].pair) assert.equal(got[i].v, got[i - 1].v, "a pair flies as one"); + } + } + // The slowest note lives long enough to leave by the far end. + const round = choirFight(); + const b = round.boss; + until(round, () => b.x === round.spec.length - ch.HOME_FROM_END, 4000); + hold(round); + Object.assign(b, { act: "cue", wait: 0, gap: 1, second: null }); + ghoul.advance(round, 4, () => 0); + hold(round); + const note = round.hazards.find((h) => h.kind === "note"); + let lowest = note.x; + for (let t = 0; t < 12000 && round.hazards.includes(note); t += 4) { + ghoul.advance(round, 4, steady); + round.you.safeMs = 1e9; + round.twist.next = 1e9; + lowest = Math.min(lowest, note.x); + } + assert.ok(lowest <= round.spec.arena - 5.5, `reached ${lowest.toFixed(1)}`); }); test("The Choirmaster in his rage conducts faster: notes at NOTE_V_RAGE, a column every 2.3 s, and sometimes a second column 1.1 s behind the first, its gap next to the first's", () => { @@ -865,7 +1050,6 @@ test("The Choirmaster in his rage conducts faster: notes at NOTE_V_RAGE, a colum b.pipes.forEach((p) => (p.on = false)); b.hp = b.max * 0.5 - 1; b.raged = true; - b.resoundIn = 1e9; const random = ghoul.seeded(5); Object.assign(b, { act: "idle", wait: 0, gap: 1 }); const pairs = []; @@ -894,9 +1078,13 @@ test("The Choirmaster in his rage conducts faster: notes at NOTE_V_RAGE, a colum spaced++; } assert.ok(spaced >= 5); - // Faster notes. - assert.equal(speed, ch.NOTE_V_RAGE * round.spec.pace); + // Faster notes: the same draw flies faster in the rage. + assert.ok(speed > 0); assert.ok(ch.NOTE_V_RAGE > ch.NOTE_V && ch.COLUMN_RAGE_MS < ch.COLUMN_MS); + const mad = choirFight(); + Object.assign(mad.boss, { hp: mad.boss.max * 0.4, raged: true, act: "cue", wait: 0, gap: 1, second: null }); + ghoul.advance(mad, 4, steady); + assert.equal(mad.hazards.find((h) => h.kind === "note").v, ch.NOTE_V_RAGE * mad.spec.pace); // Without the rage, the same draws give no pairs. const calm = choirFight(); Object.assign(calm.boss, { act: "idle", wait: 0, gap: 1 }); @@ -1039,6 +1227,7 @@ test("Ghoul Rush's Chapel: every new kind has a voice for every act and every ne // Every new event says something (a float, a banner or a sound). assert.deepEqual(heard({ type: "toll", ms: 1000 }).floats, ["Frozen!"]); assert.deepEqual(heard({ type: "pipeSilence", kind: "choirmaster", left: 0 }).floats, ["Silent!"]); + assert.deepEqual(heard({ type: "pipesStir", kind: "choirmaster" }).floats, ["The pipes stir!"]); }); test("Ghoul Rush's Chapel: every new way to die has its words and its own sound", () => { @@ -1088,6 +1277,14 @@ test("Ghoul Rush's Chapel draws: every room, every monster in every act, the Cho r.stunMs = 500; g.tick(16); r.stunMs = 0; + // The pipes rattling, then falling back in; notes of every speed. + if (r.boss.pipes) { + Object.assign(r.boss, { act: "idle", wait: 1e9, quiet: 1 }); + g.tick(16); + r.boss.pipes.forEach((p, i) => Object.assign(p, { on: true, dropMs: 300 + i * 100 })); + r.hazards.push({ kind: "note", x: r.you.x + 24, y: 10, w: 1.6, h: 1.6, v: 0, pace: 1.75, live: 1, life: 5000, row: 1, cause: "note" }, { kind: "note", x: r.you.x + 28, y: 10, w: 1.6, h: 1.6, v: 0, pace: 0.55, live: 1, life: 5000, row: 1, cause: "note" }); + g.tick(16); + } } for (let k = 0; k < 20; k++) g.tick(16); r.you.safeMs = 1e9; diff --git a/scripts/test-web-console-activities-ghoul-dice.mjs b/scripts/test-web-console-activities-ghoul-dice.mjs index a125f15..dd21343 100644 --- a/scripts/test-web-console-activities-ghoul-dice.mjs +++ b/scripts/test-web-console-activities-ghoul-dice.mjs @@ -164,18 +164,22 @@ test("Ghoul Rush: a death with dice holds and rolls just one; a six saves Planny assert.equal(round.lives, 3, "no life lost yet"); assert.equal(round.dice, 2, "the die is in hand"); assert.equal(events(round, "diceStart").length, 1); - assert.equal(events(round, "diceRoll").length, 1); + assert.equal(events(round, "diceRoll").length, 0, "the die is still flying in from the HUD"); assert.equal(events(round, "lose").length, 0, "not lost"); const random = rolls(SIX); + // The lead-in: the die flies in, then the rattle starts. + ghoul.advance(round, ghoul.LEAD_MS + 8, random); + assert.equal(events(round, "diceRoll").length, 1); + assert.equal(events(round, "diceFace").length, 0); // Half way through: tumbling, no face yet. - ghoul.advance(round, ghoul.TUMBLE_MS / 2, random); + ghoul.advance(round, (ghoul.TUMBLE_MS - ghoul.LEAD_MS) / 2, random); assert.equal(round.phase, "roll"); assert.equal(events(round, "diceFace").length, 0); // It lands, and holds its beat. - ghoul.advance(round, ghoul.TUMBLE_MS / 2 + 8, random); + ghoul.advance(round, (ghoul.TUMBLE_MS - ghoul.LEAD_MS) / 2, random); assert.deepEqual(events(round, "diceFace").map((e) => e.face), [6]); assert.equal(round.phase, "roll"); - ghoul.advance(round, ghoul.ROLL_MS - ghoul.TUMBLE_MS, random); + ghoul.advance(round, ghoul.ROLL_MS - ghoul.TUMBLE_MS + 8, random); assert.equal(events(round, "diceRoll").length, 1, "no second die"); assert.equal(events(round, "diceSaved").length, 1); assert.equal(events(round, "diceFail").length, 0); diff --git a/scripts/test-web-console-activities-ghoul-frozen.mjs b/scripts/test-web-console-activities-ghoul-frozen.mjs index 26e56c5..be01297 100644 --- a/scripts/test-web-console-activities-ghoul-frozen.mjs +++ b/scripts/test-web-console-activities-ghoul-frozen.mjs @@ -125,7 +125,7 @@ test("Ghoul Rush's Frozen Lake is a stage of three rooms and the Widow's Web, it assert.equal(st.boss, "frostwidow"); assert.equal(st.title, "The Frozen Lake"); assert.equal(st.sub, "The ice remembers who fell through"); - assert.equal(ghoul.STAGES.at(-1), st, "the last stage in the list"); + assert.equal(ghoul.STAGES.at(-2), st, "the last stage in the list but Gallows Bog"); for (const kind of Object.keys(fz.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], fz.MONSTERS[kind], `${kind} is a monster`); assert.deepEqual(Object.keys(fz.MONSTERS).sort(), ["frozen", "hand", "icewraith", "shade"]); assert.equal(ghoul.BOSSES.frostwidow, fz.BOSSES.frostwidow); @@ -848,6 +848,13 @@ test("Ghoul Rush's barrels: a bolt kicks a standing one the way it flew, it roll const round = widowFight({ x: 120 }); const barrel = round.hazards.find((h) => h.kind === "barrel" && h.x === round.spec.arena + 30); // From the left: it rolls right. + // A stray bolt does not topple it: it takes BARREL_HITS of them. + for (let i = 0; i < fz.BARREL_HITS - 1; i++) { + round.shots.push({ x: barrel.x - 4, y: 7.5, vx: 130, vy: 0, gone: 0 }); + run(round, 60); + assert.equal(barrel.state, "still", `bolt ${i + 1} only knocks it`); + } + assert.equal(events(round, "barrelKnock").length, fz.BARREL_HITS - 1); round.shots.push({ x: barrel.x - 4, y: 7.5, vx: 130, vy: 0, gone: 0 }); run(round, 60); assert.equal(barrel.state, "roll"); @@ -860,14 +867,14 @@ test("Ghoul Rush's barrels: a bolt kicks a standing one the way it flew, it roll // From the right: it rolls left. const left = widowFight({ x: 190 }); const b2 = left.hazards.find((h) => h.kind === "barrel" && h.x === left.spec.arena + 66); - left.shots.push({ x: b2.x + 4, y: 7.5, vx: -130, vy: 0, gone: 0 }); + left.shots.push({ x: b2.x + 4, y: 7.5, vx: -130, vy: 0, gone: 0, arm: "stake", t: 0, spin: 0, dmg: 4, bossDmg: 4, pierce: true }); run(left, 40); assert.equal(b2.vx, -fz.BARREL_V); // It hurts what it rolls through, once each. const hit = widowFight({ x: 120 }); const b3 = hit.hazards.find((h) => h.kind === "barrel" && h.x === hit.spec.arena + 30); const z = put(hit, "zombie", b3.x + 8); - hit.shots.push({ x: b3.x - 4, y: 7.5, vx: 130, vy: 0, gone: 0 }); + Object.assign(b3, { state: "roll", vx: fz.BARREL_V, life: fz.BARREL_LIFE_MS }); run(hit, 600); assert.equal(z.hp, z.max - fz.BARREL_DMG >= 0 ? z.max - fz.BARREL_DMG : z.hp); assert.ok(z.dead || z.hp < z.max, "burned by the barrel"); @@ -875,7 +882,7 @@ test("Ghoul Rush's barrels: a bolt kicks a standing one the way it flew, it roll const wall = widowFight({ x: 120 }); const b4 = wall.hazards.find((h) => h.kind === "barrel" && h.x === wall.spec.arena + 66); wall.boss.x = 120; - wall.shots.push({ x: b4.x - 4, y: 7.5, vx: 130, vy: 0, gone: 0 }); + wall.shots.push({ x: b4.x - 4, y: 7.5, vx: 130, vy: 0, gone: 0, arm: "stake", t: 0, spin: 0, dmg: 4, bossDmg: 4, pierce: true }); run(wall, 1500); assert.ok(!wall.hazards.includes(b4)); assert.ok(events(wall, "barrelBurst").length >= 1); @@ -901,7 +908,7 @@ test("Ghoul Rush's veil melts to a rolling barrel (or a flare's fire) when she i const barrel = round.hazards.find((h) => h.kind === "barrel" && h.x === round.spec.arena + 48); // Shot from the left, 4 away from her: it rolls into her. barrel.x = 150; - round.shots.push({ x: 146, y: 7.5, vx: 130, vy: 0, gone: 0 }); + round.shots.push({ x: 146, y: 7.5, vx: 130, vy: 0, gone: 0, arm: "stake", t: 0, spin: 0, dmg: 4, bossDmg: 4, pierce: true }); until(round, () => !b.veil, 1500); assert.equal(b.veil, false, "melted"); const melt = events(round, "veilMelt")[0]; @@ -1209,7 +1216,7 @@ test("Ghoul Rush's web spit: a slow glob that lands as a patch 5 wide for 6 s, s assert.ok(!shot.hazards.some((h) => h.kind === "webGlob" || h.kind === "webPatch"), "shot down"); }); -test("Ghoul Rush's Frost Widow's rage at half her hp: the veil grows back sooner, the barrels are set out new, two ice wraiths come (never more than two alive) and she is quicker; endless lives spare her touch", () => { +test("Ghoul Rush's Frost Widow's rage at half her hp: the veil grows back sooner, the barrels are set out new, an ice wraith comes (never more than WRAITH_CAP alive, and not again for a while) and she is quicker; endless lives spare her touch", () => { const round = widowFight({ x: 125 }); const b = round.boss; round.hazards = round.hazards.filter((h) => h.kind !== "barrel").concat([{ kind: "barrel", x: 140, y: 6, spot: 99, state: "roll", vx: 5, roll: 0, life: 9999, hit: [], w: 3, h: 3.4, live: 0, cause: "" }]); @@ -1222,19 +1229,19 @@ test("Ghoul Rush's Frost Widow's rage at half her hp: the veil grows back sooner assert.equal(barrels.length, 3, "a new set of three"); assert.ok(barrels.every((h) => h.state === "still")); const wraiths = round.monsters.filter((m) => m.kind === "icewraith"); - assert.equal(wraiths.length, 2); - assert.equal(events(round, "wraithCall").length, 2); - // Never more than two alive, a drop or not. + assert.equal(wraiths.length, fz.WRAITH_CAP); + assert.equal(events(round, "wraithCall").length, fz.WRAITH_CAP); + // Never more than the cap alive, a drop or not. b.act = "hang"; b.wait = 1; b.spikeIn = 1e9; b.spitIn = 1e9; run(round, 16); - assert.equal(round.monsters.filter((m) => m.kind === "icewraith").length, 2); + assert.equal(round.monsters.filter((m) => m.kind === "icewraith").length, fz.WRAITH_CAP); // The veil grows back in VEIL_DOWN_RAGE_MS. Object.assign(b, { act: "low", y: 6, x: 160, lowMs: 1e9, wait: 0 }); round.hazards.find((h) => h.kind === "barrel").x = 150; - round.shots.push({ x: 146, y: 7.5, vx: 130, vy: 0, gone: 0 }); + round.shots.push({ x: 146, y: 7.5, vx: 130, vy: 0, gone: 0, arm: "stake", t: 0, spin: 0, dmg: 4, bossDmg: 4, pierce: true }); until(round, () => !b.veil, 1500); assert.equal(events(round, "veilDown").at(-1).ms, fz.VEIL_DOWN_RAGE_MS); // Quicker waits: a fight at half hp has shorter hangs. @@ -1472,7 +1479,7 @@ test("Ghoul Rush's stage select lists the Frozen Lake and takes you straight int const r = g.round; assert.equal(r.phase, "select"); const at = ghoul.STAGES.findIndex((s) => s.id === "frozen"); - assert.equal(at, ghoul.STAGES.length - 1); + assert.equal(at, ghoul.STAGES.length - 2); for (let i = 0; i < at; i++) ghoul.steerSelect(r, 1, 0); for (let i = 0; i < 4; i++) ghoul.steerSelect(r, 0, 1); assert.equal(r.select.at, at); diff --git a/scripts/test-web-console-activities-ghoul-gameover.mjs b/scripts/test-web-console-activities-ghoul-gameover.mjs index 7bcd77d..a64e6f0 100644 --- a/scripts/test-web-console-activities-ghoul-gameover.mjs +++ b/scripts/test-web-console-activities-ghoul-gameover.mjs @@ -2,6 +2,7 @@ import { test } from "node:test"; import assert from "node:assert/strict"; import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { skipStory } from "../src/web-console/public/activities/ghoul-story.js"; import { dropAt, gameOverBanner, OVER_WORD } from "../src/web-console/public/activities/ghoul-gameover-draw.js"; import { toneNames } from "../src/web-console/public/tones.js"; @@ -35,6 +36,7 @@ function playTo(end) { const h = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, tone: (name) => sounds.push(name) }); h.resize(900, 900); h.key("action"); + skipStory(h.round); for (let k = 0; k < 40; k++) h.tick(16); end(h); for (let k = 0; k < 300 && h.state === "running"; k++) h.tick(16); diff --git a/scripts/test-web-console-activities-ghoul-graveyard.mjs b/scripts/test-web-console-activities-ghoul-graveyard.mjs index 35b40c0..db74035 100644 --- a/scripts/test-web-console-activities-ghoul-graveyard.mjs +++ b/scripts/test-web-console-activities-ghoul-graveyard.mjs @@ -45,9 +45,9 @@ function run(round, ms, keys = {}) { for (const k of Object.keys(keys)) round.input[k] = false; } -test("Ghoul Rush's Graveyard is a stage of three rooms and Mother Mourning's, its monsters and boss joined to the game's", () => { +test("Ghoul Rush's Graveyard is a stage of three rooms, the Midnight Hearse bonus ride (its own suite: ghoul-hearse) and Mother Mourning's, its monsters and boss joined to the game's", () => { const st = ghoul.stageById("graveyard"); - assert.deepEqual(st.rooms, ["lychgate", "graves", "mausoleums", "angel"]); + assert.deepEqual(st.rooms, ["lychgate", "graves", "mausoleums", "hearse", "angel"]); assert.equal(st.boss, "angel"); for (const kind of Object.keys(gy.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], gy.MONSTERS[kind], `${kind} is a monster`); assert.equal(ghoul.BOSSES.angel, gy.BOSSES.angel); diff --git a/scripts/test-web-console-activities-ghoul-grounds.mjs b/scripts/test-web-console-activities-ghoul-grounds.mjs index 9d55046..75426f5 100644 --- a/scripts/test-web-console-activities-ghoul-grounds.mjs +++ b/scripts/test-web-console-activities-ghoul-grounds.mjs @@ -61,14 +61,17 @@ function until(round, done, ms = 4000) { // A bolt arriving from the left at height `y` on the monster `m`. const bolt = (round, m, y) => round.shots.push({ x: m.x - m.w / 2 - 0.3, y, vx: 80, vy: 0, gone: 0 }); -test("Ghoul Rush's Grounds is a stage of three rooms and the Groundskeeper's, its monsters and boss joined to the game's, with shears and a place for each kind", () => { +test("Ghoul Rush's Grounds is a stage of three rooms, a bonus ride and the Groundskeeper's, its monsters and boss joined to the game's, with shears and a place for each kind", () => { const st = ghoul.stageById("grounds"); - assert.deepEqual(st.rooms, ["maze", "topiary", "gazebo", "yard"]); + assert.deepEqual(st.rooms, ["maze", "topiary", "gazebo", "mower", "yard"]); assert.equal(st.boss, "keeper"); for (const kind of Object.keys(gr.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], gr.MONSTERS[kind], `${kind} is a monster`); assert.equal(ghoul.BOSSES.keeper, gr.BOSSES.keeper); for (const id of st.rooms) assert.ok(ghoul.ROOM_MUSIC[id], `${id} has music`); - const [maze, garden, gazebo, yard] = st.rooms.map((id) => ghoul.roomById(id)); + const [maze, garden, gazebo, mower, yard] = st.rooms.map((id) => ghoul.roomById(id)); + // The Gardener's Revenge, the bonus ride before the boss, has its own suite (ghoul-mower). + assert.equal(mower.bonus, true); + assert.equal(mower.id, "mower"); for (const room of [maze, garden, gazebo]) { assert.ok(room.key, `${room.id}: a key`); assert.ok(room.sky.length && room.candy.length && room.items.length && room.horde.length, `${room.id}: sky treasures, candy, items and a horde`); diff --git a/scripts/test-web-console-activities-ghoul-gurney.mjs b/scripts/test-web-console-activities-ghoul-gurney.mjs new file mode 100644 index 0000000..94ff400 --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-gurney.mjs @@ -0,0 +1,1063 @@ +// Web console tests, Ghoul Rush's Code Blue (Blackmoor Sanatorium's bonus round, between the Surgical Theater and the Night Ward): its shape (every elevator shaft clears with a jump and swallows a gurney that does not jump, every low can be ducked, spacing, the surge lamps and the blackout waves, checkpoints, the clock), the gurney's speed on slopes, its jump, ducking, a wheelchair that rolls, an IV stand, a lamp or a door overhead, an orderly in a doorway, the surge lamp shot from the air, the lights-out rhythm (the countdown, the dark, the lights back), the heartbeat monitor, a fall down a shaft, the checkpoint, the jump off the end and the door, the bonus round's hearts and dice (3 to 9) and the clean-dark-stretches die, endless lives for every cause, a voice for every event, the drawing, and bots that ride the whole way (one that dodges well, one that never does). +// Run with: node --test scripts/test-web-console-activities-ghoul-gurney.mjs +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { skipBossIntro } from "./ghoul-test-helpers.mjs"; +import * as gn from "../src/web-console/public/activities/ghoul-gurney.js"; +import * as ct from "../src/web-console/public/activities/ghoul-cart.js"; +import { EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as GURNEY_LOOKS, VOICES as GURNEY_VOICES, gurneyArt, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-gurney-draw.js"; +import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js"; +import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-draw.js"; +import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-bonus.js"; + +const steady = () => 0.5; +// The pack draws no random number: a run on this fails on the first draw. +const never = () => { + throw new Error("Code Blue drew a random number"); +}; +const events = (round, type) => round.events.filter((e) => e.type === type); + +function through(round) { + round.phase = "clear"; + round.phaseMs = 1; + ghoul.advance(round, 4, steady); +} + +// A round in Code Blue reached the way play reaches it, nothing woken, the clocks long, the bonus round on (five hearts). +function gurneyRound(seed = 5) { + const round = ghoul.newRound(seed); + round.lives = 3; + round.dice = 0; + through(round); + round.offer = ["sanatorium"]; + round.phaseMs = 0; + ghoul.pickStage(round, 0); + while (round.spec.id !== "codeblue") through(round); + round.phase = "play"; + for (const st of round.spawns) st.over = true; + round.monsters.length = 0; + round.hordeMs = Infinity; + round.timeMs = 1e9; + round.bonus = 1e9; + round.events.length = 0; + return round; +} + +const NONE = { runner: "codeblue", time: 1e9, finish: 1e6, track: [], chairs: [], stands: [], lows: [], orderlies: [], lamps: [], waves: [], checks: [] }; +// The same round over a ride of its own (a plain track to measure the gurney on). +function synth(ride) { + const round = gurneyRound(); + round.spec = { ...round.spec, start: 10, ground: [[0, 5, 0]], ride: { ...NONE, ...ride } }; + gn.GURNEY.place[0](round, {}); + return round; +} +const FLAT = [[[0, 20], [4000, 20]]]; +const DOWN = [[[0, 40], [4000, 40 - 0.15 * 4000]]]; +const UP = [[[0, 0], [4000, 0.3 * 4000]]]; + +// The gurney on line `line` of the ride at `x`, at speed `v`. +function gurneyAt(round, x, line, { v = gn.GURNEY_V, safe = false } = {}) { + const y = ct.trackY(round.spec.ride, line, x); + assert.ok(y !== null, `line ${line} runs under ${x}`); + Object.assign(round.you, { x, y, vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false }); + Object.assign(round.runner, { line, v, coyote: 0 }); + round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24)); +} + +function run(round, ms, keys = {}, random = steady) { + Object.assign(round.input, keys); + for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random); + for (const k of Object.keys(keys)) round.input[k] = typeof keys[k] === "number" ? 0 : false; +} + +function until(round, done, ms = 6000, random = steady) { + let t = 0; + for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random); + return t; +} + +const press = (round) => { + round.input.jump = ghoul.JUMP_BUFFER_MS; + round.input.up = true; +}; + +const heard = (e, extra = {}) => { + const played = []; + const noop = () => {}; + const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra }; + react({ x: 10, y: 6, tx: 20, ty: 6, ...e }, kit); + return { played }; +}; + +const ROOM = ghoul.roomById("codeblue"); +const R = ROOM.ride; +const lines = ct.linesOf(R); +const floorOf = (x) => ghoul.groundAt(ROOM, x); +const slopeAtLine = (L, i) => (L.pts[i + 1][1] - L.pts[i][1]) / (L.pts[i + 1][0] - L.pts[i][0]); +const lineOfX = (x) => lines.findIndex((L) => x >= L.x0 && x <= L.x1); + +/* -------------------------------------------------------------- the room */ + +test("Ghoul Rush's Code Blue is Blackmoor Sanatorium's fourth room, between the Surgical Theater and the Night Ward: lit, no key, no boss, a ride about 60 to 70 seconds long, a bonus round that plays its own track", () => { + const st = ghoul.stageById("sanatorium"); + assert.deepEqual(st.rooms, ["admissions", "baths", "theater", "codeblue", "ward"]); + assert.equal(st.boss, ghoul.roomById("ward").boss); + assert.deepEqual([ROOM.title, ROOM.sub], ["Code Blue", "Please remain calm. The gurney will not"]); + assert.equal(ROOM.dark, false, "its own darkness comes from the waves"); + assert.equal(ROOM.key, null); + assert.equal(ROOM.boss, null); + assert.equal(ROOM.bonus, true, "a bonus round"); + assert.equal(R.runner, "codeblue"); + assert.ok(!R.sled && !R.gallery, "not another ride's room"); + assert.ok(ROOM.length >= 2400 && ROOM.length <= 3400, `${ROOM.length} units long`); + assert.equal(ghoul.ROOM_MUSIC.codeblue, "ghoulBlueRide"); + assert.ok(ghoulSfx.default.music.ghoulBlueRide, "its own track"); + assert.deepEqual(Object.keys(gn.GURNEY.monsters), [], "no new monster kinds"); + assert.equal(LOOKS.codeblue, GURNEY_LOOKS.codeblue); + assert.equal(LOOKS.codeblue.pack, "codeblue"); + assert.ok(Object.isFrozen(R) && Object.isFrozen(R.track) && Object.isFrozen(R.track[0][0]) && Object.isFrozen(R.waves[0]), "frozen all the way down"); + assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0, "no monsters: the things in the corridors are the pack's own"); + assert.ok(ROOM.candy.length === 0 && ROOM.items.length === 0, "no pickups"); + assert.equal(ROOM.ground.length, 2); + assert.ok(ROOM.ground[0][1] < 60 && ROOM.ground[1][0] > ROOM.length - 100, "floor only at the ends"); + assert.equal(ROOM.ground[1][0], R.finish); + assert.ok(ROOM.door > R.finish && ROOM.door > ROOM.length - 14, "the door at the room's end, past the bay's start"); + assert.ok(floorOf(ROOM.door - 2) > -Infinity, "floor to walk out on"); + for (const L of lines) for (let i = 0; i + 1 < L.pts.length; i++) assert.ok(L.pts[i + 1][0] > L.pts[i][0], "x rises"); + assert.ok(ct.trackY(R, 0, ROOM.start) > floorOf(ROOM.start), "the gurney starts on the floor over the start's ground"); + const secs = (lines.at(-1).x1 - ROOM.start) / gn.GURNEY_V; + assert.ok(secs >= 58 && secs <= 72, `${secs.toFixed(1)} s at GURNEY_V`); + let steepest = 0; + for (const L of lines) { + for (let i = 0; i + 1 < L.pts.length; i++) { + const s = slopeAtLine(L, i); + const lip = L === lines.at(-1) && i === L.pts.length - 2; + steepest = Math.max(steepest, Math.abs(s)); + assert.ok(lip ? s >= gn.RAMP_SLOPE && s <= 0.32 : Math.abs(s) <= 0.22, `a slope of ${s.toFixed(3)}`); + } + for (const [, y] of L.pts) assert.ok(y > gn.DERAIL_Y + 5 && y < 36, `a floor height of ${y}`); + } + assert.equal(ghoul.timeFor(ghoul.roomFor("codeblue")), R.time); + assert.ok(R.time >= 1.5 * secs * 1000, `a ${R.time} ms clock for a ${secs.toFixed(0)} s ride`); + assert.equal(R.lamps.length, R.waves.length, "a surge lamp for every wave"); + assert.equal(R.checks.length, lines.length - 1); +}); + +test("Ghoul Rush's Code Blue: the loading ramp's launch alone carries the gurney onto the ambulance bay at any speed it can have there, landing 10 to 40 past its start", () => { + const lip = lines.at(-1); + const end = lip.pts.at(-1); + const rise = ct.slopeOf(R, lines.length - 1, lip.x1); + assert.ok(rise >= gn.RAMP_SLOPE, "the lip launches"); + const bank = floorOf(R.finish + 1); + for (const v of [gn.GURNEY_MIN, 42, gn.GURNEY_V, 54, gn.GURNEY_MAX]) { + let vy = rise * v + gn.RAMP_POP; + let x = end[0]; + let y = end[1]; + for (let t = 0; t < 3; t += 0.002) { + vy -= gn.GRAV * 0.002; + x += v * 0.002; + y += vy * 0.002; + if (vy < 0 && y <= bank) break; + } + assert.ok(x >= R.finish + 2 && x <= R.finish + 40, `at ${v} it lands ${x - R.finish} past the bay's start`); + } +}); + +test("Ghoul Rush's Code Blue: every elevator shaft clears with a jump at the edge or a few units early, and a gurney that never jumps drops into it", () => { + assert.equal(lines.length - 1, 7, "seven shafts"); + for (let i = 0; i + 1 < lines.length - 1; i++) { + const a = lines[i]; + const b = lines[i + 1]; + const gap = b.x0 - a.x1; + assert.ok(gap >= 9 && gap <= 18, `shaft ${i} is ${gap} wide`); + const end = a.pts.at(-1); + const slope = ct.slopeOf(R, i, a.x1); + assert.ok(slope < gn.RAMP_SLOPE, "shafts lie on floors that do not launch"); + for (const v of [40, 45, 50, 55]) { + assert.equal(gn.flight(R, a.x1, end[1], slope * v, v), null, `shaft ${i}, no jump, at ${v}`); + for (const early of [0, 4]) { + const x = a.x1 - early; + const y = ct.trackY(R, i, x); + const s = gn.flight(R, x, y, gn.JUMP_V + ct.slopeOf(R, i, x) * v, v); + assert.ok(s, `shaft ${i}: a jump ${early} early at ${v} lands`); + assert.equal(s.line, i + 1, `shaft ${i} cleared, at ${v}, ${early} early`); + } + } + } +}); + +test("Ghoul Rush's Code Blue: every thing is on a line, off its ends, level where it needs to be, spaced for a player (22 between jumps and 38 between a jump and a duck, a wheelchair's roll counted), a low's underside between a ducked box and a standing one", () => { + const jumps = []; + const ducks = []; + const at = (x, w, what) => { + const i = lineOfX(x); + assert.ok(i >= 0, `${what} at ${x} is on a line`); + assert.ok(x - lines[i].x0 >= 30 && lines[i].x1 - x >= 30, `${what} at ${x} is clear of its line's ends`); + return i; + }; + const levelAround = (i, a, b) => { + let lo = 1e9; + let hi = -1e9; + for (let x = a; x <= b; x += 0.5) { + const y = ct.trackY(R, i, x); + lo = Math.min(lo, y); + hi = Math.max(hi, y); + } + return hi - lo; + }; + for (const [x, line] of R.chairs) { + assert.equal(at(x, gn.CHAIR_W, "chair"), line); + assert.ok(levelAround(line, x - gn.CHAIR_MAX - 2, x + 2) < 0.3, "a chair rolls on level floor"); + jumps.push([x - gn.CHAIR_MAX, x + gn.CHAIR_W / 2]); + } + for (const [x, line] of R.stands) { + assert.equal(at(x, gn.STAND_W, "stand"), line); + jumps.push([x - gn.STAND_W / 2, x + gn.STAND_W / 2]); + } + for (const [x, line] of R.orderlies) { + assert.equal(at(x, gn.ORDERLY_W, "orderly"), line); + jumps.push([x - gn.ORDERLY_W / 2, x + gn.ORDERLY_W / 2]); + } + R.lows.forEach(([x0, x1, y, kind]) => { + const i = at((x0 + x1) / 2, x1 - x0, "low"); + assert.ok(kind === 0 || kind === 1); + const flat = levelAround(i, x0 - 3, x1 + 3); + assert.ok(flat < 0.3, "a low hangs over level floor"); + const floor = ct.trackY(R, i, (x0 + x1) / 2); + assert.ok(Math.abs(y - (floor + 3)) < 0.3, `a low's underside is 3.0 over the floor (${y - floor})`); + assert.ok(floor + 2.4 < y && y < floor + 4.4, "between a ducked box and a standing one"); + ducks.push([x0, x1]); + }); + const all = [...jumps.map((r) => ({ r, jump: true })), ...ducks.map((r) => ({ r, jump: false }))].sort((p, q) => p.r[0] - q.r[0]); + for (let k = 1; k < all.length; k++) { + const gap = all[k].r[0] - all[k - 1].r[1]; + const need = all[k].jump && all[k - 1].jump ? 22 : all[k].jump !== all[k - 1].jump ? 38 : 16; + assert.ok(gap >= need, `${all[k - 1].jump ? "a jump" : "a duck"} to ${all[k].jump ? "a jump" : "a duck"} is ${gap.toFixed(0)} apart at ${all[k].r[0]}`); + } + // A shaft's two edges keep clear of the nearest things as well (the first thing is 50 into a line). + assert.ok(R.chairs.length >= 6 && R.stands.length >= 6 && R.lows.length >= 10 && R.orderlies.length >= 8, "a good many of each"); + const total = R.chairs.length + R.stands.length + R.lows.length + R.orderlies.length + (lines.length - 1); + assert.ok(total >= 40, `${total} things to get past`); +}); + +test("Ghoul Rush's Code Blue: the blackout waves are in order with room between them, each surge lamp hangs SURGE_BACK before its wave on a line, the countdown fits in lit floor, the checkpoints are on lines", () => { + let prev = 0; + R.waves.forEach(([x0, x1], i) => { + assert.ok(x1 - x0 >= 150 && x1 - x0 <= 240, `wave ${i} is ${x1 - x0} long`); + assert.ok(x0 - gn.WARN_UNITS - prev >= 150, `${x0 - gn.WARN_UNITS - prev} lit units before wave ${i}`); + prev = x1; + const [lx, line] = R.lamps[i]; + assert.equal(lx, x0 - gn.SURGE_BACK); + assert.equal(lineOfX(lx), line); + assert.ok(lx - lines[line].x0 >= 10 && lines[line].x1 - lx >= 10, "a lamp hangs over floor"); + }); + assert.ok(R.waves.at(-1)[1] <= R.finish - 150, "lit again well before the ramp"); + assert.ok(R.waves[0][0] >= 300, "the first blackout is not at the start"); + R.checks.forEach((x, i) => { + assert.equal(lineOfX(x), i + 1, `checkpoint ${i} is at the start of line ${i + 1}`); + }); +}); + +/* ------------------------------------------------------------ the gurney */ + +test("Ghoul Rush's Code Blue rolls at GURNEY_V on the flat, faster down a slope and slower up one, never past GURNEY_MIN or GURNEY_MAX, and no key changes it", () => { + const flat = synth({ track: FLAT }); + assert.equal(flat.runner.v, gn.GURNEY_V); + run(flat, 2000); + assert.ok(Math.abs(flat.runner.v - gn.GURNEY_V) < 0.01); + run(flat, 1500, { right: true }); + run(flat, 1500, { left: true }); + assert.ok(Math.abs(flat.runner.v - gn.GURNEY_V) < 0.01, "right and left do nothing"); + assert.ok(Math.abs(flat.you.x - (10 + ((2000 + 1500 + 1500) / 1000) * gn.GURNEY_V)) < 1); + const down = synth({ track: DOWN }); + run(down, 3000); + assert.ok(Math.abs(down.runner.v - (gn.GURNEY_V + (gn.SLOPE_G * 0.15) / gn.RELAX)) < 0.2, `${down.runner.v} down a 0.15 slope`); + assert.ok(down.runner.v <= gn.GURNEY_MAX); + const up = synth({ track: UP }); + run(up, 3000); + assert.ok(up.runner.v >= gn.GURNEY_MIN && up.runner.v < gn.GURNEY_V); + const steep = synth({ track: [[[0, 10000], [4000, 6000]]] }); + run(steep, 3000); + assert.equal(steep.runner.v, gn.GURNEY_MAX); + assert.equal(flat.you.face, 1); + assert.equal(flat.you.state, "run"); + assert.equal(flat.you.y, 20); + assert.equal(flat.runner.pack, "codeblue"); +}); + +test("Ghoul Rush's Code Blue jumps about 13 high for about three quarters of a second, a press saved for a landing jumps on it, one just after a line's end still jumps", () => { + const round = synth({ track: FLAT }); + let top = 0; + press(round); + const t = until(round, () => { + top = Math.max(top, round.you.y - 20); + return round.you.state === "run" && round.you.y === 20 && round.you.vy === 0 && top > 1; + }, 3000); + assert.ok(Math.abs(top - (gn.JUMP_V * gn.JUMP_V) / (2 * gn.GRAV)) < 0.4, `${top.toFixed(1)} high`); + assert.ok(t > 650 && t < 850, `${t} ms in the air`); + assert.equal(events(round, "blueJump").length, 1); + assert.equal(events(round, "blueLand").length, 1); + const buf = synth({ track: FLAT }); + press(buf); + run(buf, 640); + press(buf); + until(buf, () => events(buf, "blueJump").length >= 2, 1500); + assert.equal(events(buf, "blueJump").length, 2, "the saved press jumped again at the landing"); + const edge = synth({ track: [[[0, 20], [60, 20]], [[100, 20], [300, 20]]] }); + gurneyAt(edge, 58.5, 0); + run(edge, 80); + assert.equal(edge.runner.line, -1, "off the end"); + press(edge); + run(edge, 4); + assert.equal(events(edge, "blueJump").length, 1, "coyote"); + const late = synth({ track: [[[0, 20], [60, 20]], [[100, 20], [300, 20]]] }); + gurneyAt(late, 58.5, 0); + run(late, 80 + gn.COYOTE_MS); + press(late); + run(late, 4); + assert.equal(events(late, "blueJump").length, 0); +}); + +test("Ghoul Rush's Code Blue: down ducks (and a press of up jumps instead), a ducked Planny passes under a hanging lamp or a swinging door and a standing one hits it (cause overhead), at the cost of a heart", () => { + for (const kind of [0, 1]) { + const round = synth({ track: FLAT, lows: [[60, 66, 23.0, kind]] }); + const you = round.you; + run(round, 20, { down: true }); + assert.equal(events(round, "blueDuck").length, 1); + round.input.down = true; + until(round, () => you.x > 75, 3000); + round.input.down = false; + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.lives, 3); + const hit = synth({ track: FLAT, lows: [[60, 66, 23.0, kind]] }); + until(hit, () => hit.bonusRound.hearts < 5, 3000); + assert.equal(hit.bonusRound.hearts, 4, "a heart"); + assert.equal(hit.lives, 3, "never a life"); + assert.equal(events(hit, "lose")[0].cause, "overhead"); + assert.equal(events(hit, "blueCrash")[0].what, "low"); + assert.ok(hit.you.safeMs > 0, "blinking safe"); + assert.equal(hit.phase, "play", "rolls on"); + assert.deepEqual(hit.bonusRound.perf.hits, ["l0"]); + until(hit, () => hit.you.x > 80, 2000); + assert.equal(hit.bonusRound.hearts, 4, "only once"); + } + const both = synth({ track: FLAT }); + both.input.down = true; + press(both); + run(both, 20); + assert.equal(both.you.ducking, false); + assert.equal(events(both, "blueJump").length, 1); +}); + +test("Ghoul Rush's Code Blue: a wheelchair starts rolling at the gurney CHAIR_NEAR short of it (at most CHAIR_MAX), a jump clears it and standing in its way is a heart (cause wheelchair); an IV stand likewise (cause ivstand)", () => { + const hit = synth({ track: FLAT, chairs: [[300, 0]] }); + gurneyAt(hit, 200, 0); + run(hit, 100); + assert.equal(hit.runner.chairs[0].rolling, false, "far off: parked"); + until(hit, () => hit.runner.chairs[0].rolling, 2000); + assert.ok(300 - hit.you.x <= gn.CHAIR_NEAR + 0.5 && 300 - hit.you.x > gn.CHAIR_NEAR - 1, "starts at CHAIR_NEAR"); + assert.equal(events(hit, "blueChair").length, 1); + until(hit, () => hit.bonusRound.hearts < 5, 3000); + assert.equal(events(hit, "lose")[0].cause, "wheelchair"); + assert.equal(events(hit, "blueCrash")[0].what, "chair"); + assert.ok(hit.runner.chairs[0].x < 300 && hit.runner.chairs[0].x >= 300 - gn.CHAIR_MAX, "it rolled toward the gurney"); + assert.deepEqual(hit.bonusRound.perf.hits, ["c0"]); + // It stops rolling at CHAIR_MAX. + const far = synth({ track: FLAT, chairs: [[300, 0]] }); + gurneyAt(far, 240, 0, { safe: true }); + run(far, 3000); + assert.equal(far.runner.chairs[0].x, 300 - gn.CHAIR_MAX); + // A jump 9 to 15 short clears it. + const jump = synth({ track: FLAT, chairs: [[300, 0]] }); + gurneyAt(jump, 200, 0); + until(jump, () => 300 - jump.runner.chairs[0].x > 6 && 300 - jump.runner.chairs[0].x - jump.you.x > -1e9 && jump.runner.chairs[0].x - jump.you.x < 14, 3000); + press(jump); + until(jump, () => jump.you.x > 340, 3000); + assert.equal(jump.bonusRound.hearts, 5); + // The stand. + const stand = synth({ track: FLAT, stands: [[100, 0]] }); + until(stand, () => stand.bonusRound.hearts < 5, 3000); + assert.equal(events(stand, "lose")[0].cause, "ivstand"); + assert.deepEqual(stand.bonusRound.perf.hits, ["s0"]); + const over = synth({ track: FLAT, stands: [[100, 0]] }); + until(over, () => over.you.x > 88, 3000); + press(over); + until(over, () => over.you.x > 125, 3000); + assert.equal(over.bonusRound.hearts, 5); +}); + +test("Ghoul Rush's Code Blue: an orderly's door shivers when the gurney is ORDERLY_NEAR short, he lunges for ORDERLY_UP_MS, grabs (cause lunged) if you meet him, and steps back; a jump clears him; two bolts drop him for 100 points", () => { + const hit = synth({ track: FLAT, orderlies: [[200, 0]] }); + gurneyAt(hit, 150, 0); + assert.equal(hit.runner.orderlies[0].state, "door"); + run(hit, 100); + assert.equal(hit.runner.orderlies[0].state, "door", "far off: shut"); + until(hit, () => hit.runner.orderlies[0].state === "warn", 2000); + assert.ok(200 - hit.you.x <= gn.ORDERLY_NEAR + 0.5 && 200 - hit.you.x > gn.ORDERLY_NEAR - 1, "wakes at ORDERLY_NEAR"); + assert.equal(events(hit, "blueOrderlyWarn").length, 1); + assert.equal(hit.bonusRound.hearts, 5, "a shiver hurts nothing"); + until(hit, () => hit.runner.orderlies[0].state === "up", 2000); + assert.equal(events(hit, "blueOrderlyUp").length, 1); + assert.ok(200 - hit.you.x > 8 && 200 - hit.you.x < 24, `up ${200 - hit.you.x} ahead: time to see him`); + until(hit, () => hit.bonusRound.hearts < 5, 2000); + assert.equal(events(hit, "lose")[0].cause, "lunged"); + assert.equal(events(hit, "blueCrash")[0].what, "orderly"); + assert.equal(hit.runner.orderlies[0].state, "sink"); + until(hit, () => hit.runner.orderlies[0].state === "spent", 1000); + assert.deepEqual(hit.bonusRound.perf.hits, ["o0"]); + const jump = synth({ track: FLAT, orderlies: [[200, 0]] }); + gurneyAt(jump, 150, 0); + until(jump, () => jump.runner.orderlies[0].state === "up", 2000); + press(jump); + until(jump, () => jump.you.x > 230, 3000); + assert.equal(jump.bonusRound.hearts, 5); + const shot = synth({ track: FLAT, orderlies: [[200, 0]] }); + gurneyAt(shot, 130, 0, { safe: true }); + const start = shot.score; + shot.input.fire = true; + until(shot, () => shot.runner.orderlies[0].state === "broken", 3000); + shot.input.fire = false; + assert.equal(shot.runner.orderlies[0].state, "broken"); + assert.equal(events(shot, "blueOrderlyHit").length, gn.ORDERLY_HP - 1); + assert.equal(events(shot, "blueOrderlyBreak")[0].points, gn.ORDERLY_POINTS); + assert.equal(shot.bonusRound.perf.acts, 1); + assert.ok(shot.score - start >= gn.ORDERLY_POINTS); + assert.equal(shot.bonusRound.hearts, 5, "a dead orderly never grabs"); + // A restart keeps him shot. + const next = synth({ track: FLAT, orderlies: [[200, 0]] }); + next.runner.orderlies[0].state = "broken"; + next.runner.check = 0; + next.spec = { ...next.spec, ride: { ...next.spec.ride, checks: [20] } }; + gn.GURNEY.place[0](next, {}); + assert.equal(next.runner.orderlies[0].state, "broken"); +}); + +/* ----------------------------------------------------- the lights, the lamps */ + +test("Ghoul Rush's Code Blue: the lights go 3, 2, 1 over WARN_UNITS, then dark from x0 to x1 (fading in and out), and come back; each step is an event", () => { + const ride = { track: FLAT, waves: [[400, 600]], lamps: [[330, 0]] }; + assert.deepEqual(gn.lightsAt({ ...NONE, ...ride }, 100, null), { i: -1, phase: "lit", n: 0, dark: 0 }); + const w = { ...NONE, ...ride }; + assert.equal(gn.lightsAt(w, 400 - gn.WARN_UNITS - 1, null).phase, "lit"); + assert.deepEqual([400 - 84, 400 - 57, 400 - 56, 400 - 29, 400 - 28, 400 - 0.5].map((x) => gn.lightsAt(w, x, null).n), [3, 3, 2, 2, 1, 1]); + assert.equal(gn.lightsAt(w, 399.9, null).phase, "warn"); + assert.equal(gn.lightsAt(w, 400, null).phase, "dark"); + const fade = gn.lightsAt(w, 402, null).dark; + assert.ok(fade > 0 && fade < 1, "falling"); + assert.equal(gn.lightsAt(w, 500, null).dark, 1); + const lift = gn.lightsAt(w, 595, null).dark; + assert.ok(lift > 0 && lift < 1, "lifting"); + assert.equal(gn.lightsAt(w, 600, null).phase, "lit"); + assert.equal(gn.lightsAt(w, 500, [{ off: true }]).phase, "lit", "a wave called off is skipped"); + // Through a ride at the gurney's pace. + const round = synth(ride); + gurneyAt(round, 300, 0, { safe: true }); + const seen = []; + const log = (type) => events(round, type).forEach((e) => seen.push(type + (e.n || ""))); + for (let t = 0; t < 8000 && round.you.x < 640; t += 4) { + ghoul.advance(round, 4, steady); + for (const k of ["blueWarn", "blueDark", "blueLit"]) log(k); + round.events.length = 0; + } + assert.deepEqual(seen, ["blueWarn3", "blueWarn2", "blueWarn1", "blueDark", "blueLit"]); + assert.equal(round.runner.phase, "lit"); + assert.equal(round.runner.dark, 0); +}); + +test("Ghoul Rush's Code Blue: a surge lamp shot from the air (a hop while holding fire) calls its blackout off, for 150 points and one act; a level shot passes under it", () => { + const ride = { track: FLAT, waves: [[400, 600]], lamps: [[330, 0]] }; + const level = synth(ride); + gurneyAt(level, 260, 0, { safe: true }); + level.input.fire = true; + until(level, () => level.you.x > 336, 3000); + level.input.fire = false; + assert.equal(level.runner.lamps[0], false, "a level shot passes under the lamp"); + assert.equal(level.runner.waves[0].off, false); + const duck = synth(ride); + gurneyAt(duck, 260, 0, { safe: true }); + duck.input.fire = true; + duck.input.down = true; + until(duck, () => duck.you.x > 336, 3000); + assert.equal(duck.runner.lamps[0], false, "nor a ducked one"); + // A hop with the blaster held. + const hop = synth(ride); + gurneyAt(hop, 270, 0, { safe: true }); + const start = hop.score; + hop.input.fire = true; + press(hop); + until(hop, () => hop.runner.lamps[0], 1500); + hop.input.fire = false; + assert.equal(hop.runner.lamps[0], true, "the lamp shorts out"); + assert.equal(hop.runner.waves[0].off, true); + const e = events(hop, "blueLamp")[0]; + assert.equal(e.points, gn.LAMP_POINTS); + assert.equal(e.wave, 0); + assert.equal(hop.bonusRound.perf.acts, 1); + assert.ok(hop.score - start >= gn.LAMP_POINTS); + // The section stays lit: the countdown never runs and it never goes dark. + const seen = []; + for (let t = 0; t < 8000 && hop.you.x < 640; t += 4) { + ghoul.advance(hop, 4, steady); + for (const k of ["blueWarn", "blueDark", "blueLit"]) if (events(hop, k).length) seen.push(k); + hop.events.length = 0; + assert.equal(hop.runner.dark, 0); + } + assert.deepEqual(seen, [], "no countdown, no dark"); + // A shot lamp stays shot after a restart. + hop.runner.check = -1; + gn.GURNEY.place[0](hop, {}); + assert.equal(hop.runner.lamps[0], true); + assert.equal(hop.runner.waves[0].off, true); +}); + +test("Ghoul Rush's Code Blue: the heartbeat monitor beeps every BEAT_MS by hearts left, faster with each hit, and flatlines at the last heart (a long flat tone)", () => { + const rates = []; + for (const hearts of [5, 4, 3, 2, 1]) { + const round = synth({ track: FLAT }); + round.bonusRound.hearts = hearts; + round.you.safeMs = 1e9; + round.events.length = 0; + let beats = 0; + let flat = 0; + for (let t = 0; t < 4800; t += 4) { + ghoul.advance(round, 4, steady); + for (const e of events(round, "blueBeat")) { + beats++; + if (e.flat) flat++; + } + round.events.length = 0; + } + rates.push(beats); + if (hearts > 1) { + assert.equal(flat, 0); + assert.equal(beats, Math.floor(4800 / gn.BEAT_MS[hearts]), `${hearts} hearts`); + } else { + assert.equal(flat, beats, "flat"); + assert.equal(beats, Math.floor(4800 / gn.FLAT_MS)); + assert.equal(round.runner.flat, true); + } + } + assert.ok(rates[0] < rates[1] && rates[1] < rates[2] && rates[2] < rates[3], `${rates.join(",")}: faster with every hit`); + // The flat tone is a tone of its own and fits in 1.2 s. + assert.ok(heard({ type: "blueBeat", flat: true }).played.includes("ghoulBlueFlat")); + assert.ok(heard({ type: "blueBeat", flat: false }).played.includes("ghoulBlueBeat")); + for (const layer of ghoulSfx.default.tones.ghoulBlueFlat.layers) assert.ok(layer.seconds <= 1.2); +}); + +/* ------------------------------------------------------- shaft, hearts, door */ + +test("Ghoul Rush's Code Blue: a shaft with no jump is a heart (cause elevator), the gurney goes back on the floor ahead at GURNEY_V and rolls on; a jump over it costs nothing", () => { + const ride = { track: [[[0, 20], [60, 20]], [[75, 20], [400, 20]]] }; + const fall = synth(ride); + gurneyAt(fall, 30, 0); + until(fall, () => events(fall, "lose").length > 0, 3000); + assert.equal(events(fall, "lose")[0].cause, "elevator"); + assert.equal(fall.bonusRound.hearts, 4); + assert.equal(fall.lives, 3); + assert.equal(fall.phase, "play"); + assert.ok(fall.you.x > 75 && fall.runner.line === 1, "back on the floor ahead"); + assert.equal(fall.runner.v, gn.GURNEY_V); + assert.ok(fall.you.safeMs > 0); + assert.deepEqual(fall.bonusRound.perf.hits, ["k0"]); + const jump = synth(ride); + gurneyAt(jump, 30, 0); + until(jump, () => jump.you.x > 52, 2000); + press(jump); + until(jump, () => jump.you.x > 120, 3000); + assert.equal(jump.bonusRound.hearts, 5); + assert.equal(jump.runner.line, 1); +}); + +test("Ghoul Rush's Code Blue: the last heart gone ends the round with nothing at once (no life lost, the dice in hand kept) and the run goes on to the Night Ward", () => { + const round = gurneyRound(); + round.dice = 2; + round.bonusRound.hearts = 1; + gurneyAt(round, lines[0].x1 - 6, 0); + round.you.safeMs = 0; + until(round, () => round.phase === "clear", 6000); + assert.equal(round.bonusRound.hearts, 0); + assert.equal(round.bonusRound.over, true); + assert.equal(round.bonusRound.won, false); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, false); + assert.equal(end[0].dice, 0); + assert.equal(round.over, false, "no game over"); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + run(round, ghoul.CARD_LOST_MS + 100); + assert.equal(round.spec.id, "ward"); + assert.equal(round.bonusRound, null); + assert.equal(round.runner, null, "the slot is empty in any other room"); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + assert.equal(round.phase, "bossintro", "the boss room opens on its card"); + skipBossIntro(ghoul, round); + assert.equal(round.phase, "ready"); +}); + +test("Ghoul Rush's Code Blue: the checkpoints are passed in order (an event each) and the ride goes back to the last one after the last heart", () => { + const round = gurneyRound(); + for (let i = 0; i < 3; i++) { + gurneyAt(round, R.checks[i] - 4, lineOfX(R.checks[i] - 4) < 0 ? i : lineOfX(R.checks[i] - 4), { safe: true }); + until(round, () => round.runner.check >= i, 2000); + } + assert.equal(round.runner.check, 2); + assert.deepEqual(events(round, "blueCheck").map((e) => e.n), [1, 2, 3]); + const x = R.checks[2]; + gn.GURNEY.place[0](round, {}); + assert.equal(round.you.x, x, "back at the last checkpoint passed"); + assert.equal(round.runner.check, 2); +}); + +test("Ghoul Rush's Code Blue: off the ramp the gurney launches, lands on the bay and stops (blueFinish), the door opens, and walking out ends the round with 3 to 9 Lucky dice", () => { + const round = gurneyRound(); + round.dice = 1; + const last = lines.length - 1; + gurneyAt(round, lines[last].x1 - 12, last, { safe: true }); + until(round, () => round.runner.done, 4000); + assert.equal(round.runner.done, true); + assert.equal(events(round, "blueLaunch").length, 1); + assert.equal(events(round, "blueLaunch")[0].last, true); + assert.equal(events(round, "blueFinish").length, 1); + assert.ok(round.you.x > R.finish + 4 && round.you.x < R.finish + 40, `${round.you.x} landed`); + assert.equal(round.you.y, floorOf(round.you.x)); + assert.equal(round.hasKey, true, "the door opens"); + assert.equal(round.runner.phase, "lit"); + round.input.right = true; + until(round, () => round.phase === "clear", 20000); + round.input.right = false; + assert.equal(round.phase, "clear"); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, true); + assert.ok(end[0].dice >= BONUS_FLOOR && end[0].dice <= ghoul.MAX_DICE, `${end[0].dice} dice`); + assert.equal(round.dice, Math.min(ghoul.MAX_DICE, 1 + end[0].dice)); + assert.equal(round.lives, 3); + run(round, ghoul.CARD_MS + 100); + assert.equal(round.spec.id, "ward"); + assert.equal(round.runner, null); +}); + +test("Ghoul Rush's Code Blue: no random number is drawn in the room (a ride of 20 seconds, jumping and shooting, on a draw that throws)", () => { + const round = gurneyRound(); + round.input.fire = true; + for (let t = 0; t < 20000; t += 4) { + if (t % 700 === 0) press(round); + round.input.down = t % 1900 < 400; + ghoul.advance(round, 4, never); + round.events.length = 0; + if (round.phase !== "play") break; + } + assert.ok(round.you.x > 100); +}); + +test("Ghoul Rush's Code Blue's grade: the dice formula, shooting 8 things for the die, and the clean dark stretches die (at most one blackout may cost a heart)", () => { + const b = makeBonus({ stats: { kills: 0 } }); + b.perf.total = 40; + b.perf.goal = gn.ACTS_GOAL; + assert.equal(diceFor(b), 3 + 2 + 2 + 0 + 1, "five hearts, nothing hit, steady, no shots: 8"); + b.perf.acts = gn.ACTS_GOAL; + assert.equal(diceFor(b), 9); + b.perf.steady = false; + assert.equal(diceFor(b), 8); + b.perf.hits = Array.from({ length: 40 }, (_, i) => i); + b.hearts = 1; + assert.equal(diceFor(b), 3 + 0 + 0 + 1 + 0); + // A hit in a blackout marks that wave, once; two waves hit take the die. + const round = synth({ track: FLAT, waves: [[300, 480], [700, 880]], lamps: [[230, 0], [630, 0]], stands: [[330, 0], [350, 0], [750, 0]] }); + assert.equal(round.bonusRound.perf.steady, true); + gurneyAt(round, 310, 0); + until(round, () => round.bonusRound.hearts < 5, 2000); + assert.equal(round.runner.waves[0].hit, true); + assert.equal(round.runner.hitWaves, 1); + assert.equal(round.bonusRound.perf.steady, true, "one blackout may cost a heart"); + gurneyAt(round, 720, 0); + until(round, () => round.bonusRound.hearts < 4, 2000); + assert.equal(round.runner.hitWaves, 2); + assert.equal(round.bonusRound.perf.steady, false, "two take the die"); + // A hit in the lit does not count. + const lit = synth({ track: FLAT, waves: [[600, 800]], lamps: [[530, 0]], stands: [[100, 0]] }); + until(lit, () => lit.bonusRound.hearts < 5, 2000); + assert.equal(lit.runner.hitWaves, 0); + // The total counts every obstacle. + const real = gurneyRound(); + assert.equal(real.bonusRound.perf.total, R.chairs.length + R.stands.length + R.lows.length + R.orderlies.length + (lines.length - 1)); + assert.equal(real.bonusRound.perf.goal, gn.ACTS_GOAL); + assert.equal(real.bonusRound.perf.steady, true); +}); + +test("Ghoul Rush's Code Blue: endless lives (round.infinite) spare the hearts for every cause, through the same lose path", () => { + const tries = [ + { chairs: [[100, 0]] }, { stands: [[60, 0]] }, { lows: [[56, 62, 23.0, 0]] }, { orderlies: [[60, 0]] }, + ]; + for (const t of tries) { + const r = synth({ track: FLAT, ...t }); + r.infinite = true; + if (t.orderlies || t.chairs) gurneyAt(r, 20, 0); + until(r, () => events(r, "lose").length > 0, 3000); + assert.equal(r.bonusRound.hearts, 5, JSON.stringify(Object.keys(t))); + assert.equal(r.lives, 3); + } + const shaft = synth({ track: [[[0, 20], [60, 20]], [[75, 20], [400, 20]]] }); + shaft.infinite = true; + gurneyAt(shaft, 30, 0); + until(shaft, () => events(shaft, "lose").length > 0, 3000); + assert.equal(shaft.bonusRound.hearts, 5); + assert.equal(shaft.lives, 3); +}); + +test("Ghoul Rush's Code Blue: the Garlic shield takes a hit instead of a heart", () => { + const round = synth({ track: FLAT, stands: [[60, 0]] }); + round.you.garlic = true; + until(round, () => round.you.x > 75, 3000); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.you.garlic, false, "the garlic is spent"); +}); + +test("Ghoul Rush's Code Blue keeps its state in the shared slot and puts it back if another pack's place clears it", () => { + const round = gurneyRound(); + const c = round.runner; + assert.equal(c.pack, "codeblue"); + round.runner = null; + run(round, 40); + assert.equal(round.runner, c, "put back"); + // Another ride's state is left alone. + round.runner = { pack: "other", done: false }; + gn.GURNEY.place[0]({ ...round, spec: { ...round.spec, ride: null } }, {}); + assert.equal(round.runner.pack, "other"); +}); + +/* ------------------------------------------------------ voices and names */ + +test("Ghoul Rush's Code Blue: every event has a voice that plays, every cause has words and a sound, and every tone exists and is at most 1.2 s", () => { + assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...gn.EVENTS].sort(), "a voice for every event and no more"); + const tones = ghoulSfx.default.tones; + for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) { + const name = GURNEY_VOICES[kind] && GURNEY_VOICES[kind][act]; + assert.ok(name && tones[name], `${event} has a ${kind}.${act} voice that exists`); + assert.equal(VOICES[kind][act], name, "joined to the game's voices"); + const played = heard({ type: event, what: "stand", points: 50, flat: false }).played; + assert.ok(played.includes(name), `${event} plays ${name}`); + } + for (const name of Object.values(GURNEY_VOICES).flatMap((v) => Object.values(v))) { + for (const layer of tones[name].layers) assert.ok((layer.delay || 0) + layer.seconds <= 1.2, `${name} fits in 1.2 s`); + } + for (const cause of ["wheelchair", "ivstand", "overhead", "lunged", "elevator"]) { + assert.ok(LOSE_WORDS[cause], `${cause} has words`); + assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`); + assert.ok(heard({ type: "lose", cause, hearts: 3 }).played.length > 0, `${cause} sounds`); + } + assert.equal(heard({ type: "blueJump" }).played.length, 1); + assert.equal(heard({ type: "blueLamp", points: 150 }).played.length, 1); +}); + +test("Ghoul Rush's Code Blue: the room's own names do not collide with the game's (events, kinds, tones, causes)", () => { + for (const e of gn.EVENTS) assert.ok(e.startsWith("blue"), e); + const other = new Set([...ct.EVENTS]); + for (const e of gn.EVENTS) assert.ok(!other.has(e), `${e} is Code Blue's alone`); + assert.deepEqual(Object.keys(gn.GURNEY).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []); + for (const kind of Object.keys(GURNEY_VOICES)) assert.ok(!(kind in ghoul.MONSTERS), `${kind} is no monster kind`); + for (const cause of Object.keys(LOSE_WORDS)) assert.ok(!(cause in ghoul.MONSTERS), `${cause} is no monster kind`); +}); + +/* --------------------------------------------------------------- drawing */ + +test("Ghoul Rush's Code Blue draws: the corridors in the lit, the countdown and the dark, each thing (wheelchairs parked and rolling, IV stands, lamps and doors overhead, doorways in each state, surge lamps whole and shot), the monitor at every heart count, a crash, the finish and the cards", () => { + const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) }); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + g.resize(900, 900); + g.key("action"); + g.tick(16); + const r = g.round; + through(r); + r.offer = ["sanatorium"]; + r.phaseMs = 0; + ghoul.pickStage(r, 0); + while (r.spec.id !== "codeblue") through(r); + r.lives = 99; + const w0 = R.waves[0][0]; + const spots = [ROOM.start + 40, R.stands[0][0] - 10, R.lows[0][0] - 5, R.lows[1][0] - 5, R.orderlies[0][0] - 20, R.chairs[0][0] - 30, R.checks[0], lines[0].x1 - 10, w0 - 60, w0 - 20, w0 + 30, R.waves[0][1] - 5, R.finish - 40]; + for (const dark of [true, false]) { + for (const x of spots) { + r.dark = dark; + r.phase = "play"; + for (const st of r.spawns) st.over = true; + r.hordeMs = Infinity; + r.monsters.length = 0; + const top = ct.linesAt(R, x)[0] || [lines.length - 1, 20]; + gurneyAt(r, x, top[0], { safe: true }); + r.runner.orderlies = r.runner.orderlies.map((o, i) => ({ ...o, state: ["door", "warn", "up", "sink", "broken", "spent"][i % 6], t: 600 })); + r.runner.chairs = r.runner.chairs.map((c, i) => ({ ...c, rolling: i % 2 === 0, x: c.x - (i % 2 === 0 ? 7 : 0) })); + r.runner.lamps = r.runner.lamps.map((_, i) => i % 3 === 0); + r.runner.phase = ["lit", "warn", "dark"][spots.indexOf(x) % 3]; + r.runner.n = 1 + (spots.indexOf(x) % 3); + r.runner.dark = 1; + for (const air of [false, true]) { + for (const hearts of [5, 3, 1]) { + r.bonusRound.hearts = hearts; + if (air) Object.assign(r.you, { state: "air", vy: 20, y: r.you.y + 4 }); + if (air) r.runner.line = -1; + r.you.ducking = x === R.lows[0][0] - 5 && !air; + r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: -10, gone: 0 }); + for (let k = 0; k < 3; k++) g.tick(16); + r.monsters.length = 0; + r.you.safeMs = 1e9; + gurneyAt(r, x, top[0], { safe: true }); + } + } + } + } + assert.equal(r.spec.id, "codeblue"); + r.bonusRound.hearts = 5; + // A crash, then the finish and the won and lost cards. + r.you.safeMs = 0; + gurneyAt(r, R.stands[0][0] - 3, R.stands[0][1]); + for (let k = 0; k < 30; k++) g.tick(16); + assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too"); + const done = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + done.resize(900, 900); + done.key("action"); + done.tick(16); + const d = done.round; + through(d); + d.offer = ["sanatorium"]; + d.phaseMs = 0; + ghoul.pickStage(d, 0); + while (d.spec.id !== "codeblue") through(d); + d.phase = "play"; + d.runner.done = true; + d.runner.restX = R.finish + 20; + Object.assign(d.you, { x: R.finish + 30, y: 10, state: "run" }); + d.camX = R.finish - 40; + for (let k = 0; k < 10; k++) done.tick(16); + for (const won of [true, false]) { + endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) }); + d.bonusRound.over = true; + for (let k = 0; k < 10; k++) { + done.tick(16); + bonusTick(d, { tone() {}, fx: {} }); + } + d.bonusRound.over = false; + } + // The stage select goes straight into it. + const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + pick.resize(900, 900); + pick.stageSelect(); + const p = pick.round; + const at = ghoul.STAGES.findIndex((s) => s.id === "sanatorium"); + for (let i = 0; i < at; i++) ghoul.steerSelect(p, 1, 0); + for (let i = 0; i < 3; i++) ghoul.steerSelect(p, 0, 1); + assert.equal(p.select.room, 3); + pick.tick(16); + ghoul.takeSelect(p); + assert.equal(p.spec.id, "codeblue"); + assert.equal(p.runner.line, 0); + assert.equal(p.you.y, ct.trackY(R, 0, ROOM.start)); + pick.tick(16); +}); + +test("Ghoul Rush's Code Blue is dark where the rules say: dim follows the phase (none lit, a flicker in the countdown, the dark's fade), and the lights keep the monitor's band, the lamps and the checkpoints lit", () => { + const art = gurneyArt({ say() {}, label() {}, ellipse() {}, GOLD: "#fff", EYE_PALE: "#fff" }); + const round = gurneyRound(); + const c = round.runner; + const view = (clock = 1000) => ({ round, spec: round.spec, clock, fx: { clock }, g: { FIELD_W: 96, FIELD_H: 54 } }); + const sweep = (phase, n, dark) => { + Object.assign(c, { phase, n, dark }); + const out = []; + for (let clock = 0; clock < 3000; clock += 35) out.push(art.dim(view(clock))); + return out; + }; + assert.ok(sweep("lit", 0, 0).every((d) => d === 0), "no dim in the lit"); + for (const n of [3, 2, 1]) { + const f = sweep("warn", n, 0); + assert.ok(f.some((d) => d === 0) && f.some((d) => d > 0.5), `a flicker at ${n}`); + assert.ok(f.every((d) => d === 0 || d <= 0.9), "never full dark in the countdown"); + } + const flickers = [3, 2, 1].map((n) => sweep("warn", n, 0).filter((d) => d > 0).length); + assert.ok(flickers[0] < flickers[2], `the flicker thickens as the count falls: ${flickers.join(",")}`); + assert.equal(art.dim(view()) >= 0, true); + Object.assign(c, { phase: "dark", n: 0, dark: 1 }); + assert.ok(art.dim(view()) > 0.9, "pitch black"); + c.dark = 0.5; + assert.ok(art.dim(view()) > 0.4 && art.dim(view()) < 0.6, "fading"); + // In another room there is no dim and no lights. + const other = { round: { ...round, runner: null }, spec: { ...round.spec, ride: null }, clock: 0, fx: { clock: 0 } }; + assert.equal(art.dim(other), 0); + const none = []; + art.lights(other, (...p) => none.push(p)); + assert.equal(none.length, 0); + // In the dark: the monitor's band, a pool on every near thing, the strips; a surge lamp is lit always. + Object.assign(c, { phase: "dark", n: 0, dark: 1, wave: 0 }); + round.camX = R.waves[0][0] - 20; + Object.assign(round.you, { x: R.waves[0][0] + 10, y: 15 }); + const darkLights = []; + art.lights(view(), (x, y, r, a) => darkLights.push({ x, y, r, a })); + assert.ok(darkLights.filter((l) => l.y > 40 && l.r >= 20).length >= 3, "the monitor's band stays lit"); + assert.ok(darkLights.length > 8, "strips and pools"); + Object.assign(c, { phase: "lit", n: 0, dark: 0, wave: -1 }); + const litLights = []; + art.lights(view(), (x, y, r, a) => litLights.push({ x, y, r, a })); + assert.ok(litLights.length < darkLights.length, "fewer pools when lit"); + assert.ok(darkLights.every((l) => l.a > 0 && l.a <= 1 && l.r > 0)); +}); + +/* ----------------------------------------------------------- the bots */ + +// A bot that dodges well: it jumps at the end of a line (not the ramp), 9 to 15 short of a wheelchair, a stand or an orderly, +// ducks under every low, and fires only at targets (the blaster overheats if held). `miss` is the share of things it fails to dodge (by a hash). With `lamps` it +// also hops when a surge lamp is 20 to 60 ahead, to shoot it out. +const mix = (a, b) => { + let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +function goodBot(round, seed, { miss = 0.04, lamps = false } = {}) { + const { you, runner: c, input: inp } = round; + inp.left = inp.right = inp.down = false; + inp.fire = false; + if (round.phase !== "play" || !c || c.done) { + inp.up = false; + return; + } + const ok = (x) => mix(seed, Math.round(x)) >= miss; + const look = 9 + (seed % 7); + let jump = false; + if (c.line >= 0) { + const last = c.line === lines.length - 1; + if (!last && lines[c.line].x1 - you.x < 2.2 && ok(lines[c.line].x1)) jump = true; + const ahead = (x) => x - you.x > 6 && x - you.x < look; + R.chairs.forEach(([x0], i) => { + if (ahead(c.chairs[i].x) && ok(x0)) jump = true; + }); + for (const [x] of R.stands) if (ahead(x) && ok(x)) jump = true; + R.orderlies.forEach(([x], i) => { + if (c.orderlies[i].state !== "broken" && ahead(x) && ok(x)) jump = true; + }); + for (const [x0, x1] of R.lows) if (you.x > x0 - 10 && you.x < x1 + 3 && ok(x0)) inp.down = true; + // The blaster overheats if held, so it fires only at a target: an orderly stirring, a surge lamp to shoot out. + R.orderlies.forEach(([x], i) => { + if ((c.orderlies[i].state === "warn" || c.orderlies[i].state === "up") && x - you.x > 0 && x - you.x < 50) inp.fire = true; + }); + if (lamps) { + R.lamps.forEach(([x], i) => { + if (c.lamps[i] || x - you.x < 0 || x - you.x > 60) return; + inp.fire = true; + if (x - you.x > 42 && x - you.x < 46 && !inp.down) jump = true; + }); + } + } + if (jump && !inp.down) press(round); + else inp.up = false; +} +function idleBot(round) { + const inp = round.input; + inp.left = inp.right = inp.down = false; + inp.up = false; + inp.fire = true; +} +function rideWith(seed, bot, limit = 100000) { + const round = gurneyRound(seed); + const lost = []; + let t = 0; + for (; t < limit && round.phase !== "clear" && !round.over; t += 16) { + bot(round); + if (round.runner && round.runner.done && round.phase === "play") round.input.right = true; + ghoul.advance(round, 16, steady); + for (const e of round.events) if (e.type === "lose") lost.push(e.cause); + if (round.runner && !round.runner.done) { + const off = round.you.x - round.camX; + assert.ok(off > 4 && off < 70, `the gurney stays in view (${off.toFixed(1)} from the left edge at ${round.you.x.toFixed(0)})`); + } + round.events.length = 0; + } + return { round, lost, ms: t }; +} + +test("Ghoul Rush's Code Blue: a bot that dodges well finishes the whole way in 60 to 75 seconds, 6 to 9 dice, a few hearts lost at most, past every checkpoint", () => { + const dice = []; + for (let seed = 1; seed <= 12; seed++) { + const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed, { lamps: seed % 2 === 0 })); + const b = round.bonusRound; + assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")})`); + assert.ok(ms > 60000 && ms < 78000, `${ms} ms`); + assert.ok(b.dice >= 5 && b.dice <= ghoul.MAX_DICE, `${b.dice} dice`); + assert.equal(round.lives, 3, "never a run life"); + dice.push(b.dice); + } + assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 6, `${dice.join(",")}`); +}); + +test("Ghoul Rush's Code Blue: a bot that hops to shoot the surge lamps keeps the corridors lit (waves called off) and a bot that does not rides through every blackout", () => { + const lit = rideWith(2, (r) => goodBot(r, 2, { miss: 0, lamps: true })); + assert.equal(lit.round.bonusRound.won, true); + const lampsShot = lit.round.bonusRound.perf.acts; + assert.ok(lampsShot >= 4, `${lampsShot} acts`); + // The blind way: it never shoots a lamp, the lights go out six times, and it still gets through. + const seen = { dark: 0, warn: 0 }; + const round = gurneyRound(3); + for (let t = 0; t < 100000 && round.phase !== "clear"; t += 16) { + goodBot(round, 3, { miss: 0 }); + round.input.fire = false; + if (round.runner && round.runner.done) round.input.right = true; + ghoul.advance(round, 16, steady); + seen.dark += events(round, "blueDark").length; + seen.warn += events(round, "blueWarn").length; + round.events.length = 0; + } + assert.equal(seen.dark, R.waves.length, "six blackouts"); + assert.equal(seen.warn, R.waves.length * 3, "a 3, 2, 1 each"); + assert.equal(round.bonusRound.won, true); +}); + +test("Ghoul Rush's Code Blue: a bot that never dodges (holding fire) loses all five hearts before the first third, ends with 0 dice and the run goes on", () => { + for (let seed = 1; seed <= 6; seed++) { + const { round, lost } = rideWith(seed, idleBot); + const b = round.bonusRound; + assert.equal(b.won, false, "never finishes"); + assert.equal(b.dice, 0); + assert.equal(b.hearts, 0); + assert.equal(lost.length, 5); + assert.ok(round.you.x < ROOM.length * 0.4, `out at ${round.you.x}`); + assert.equal(round.lives, 3); + assert.equal(round.over, false); + } +}); + +/* ------------------------------------------------------------ telegraphs */ + +test("Ghoul Rush's Code Blue telegraphs: DUCK over lamps and doors, JUMP over shafts, wheelchairs and stands, SHOOT over the surge lamps, none for orderlies, words only on the first of each kind, the same every time", () => { + const marks = telegraphMarks(R); + const answers = { shaft: "JUMP", chair: "JUMP", stand: "JUMP", lamp: "DUCK", door: "DUCK", surge: "SHOOT" }; + assert.equal(marks.length, (lines.length - 1) + R.chairs.length + R.stands.length + R.lows.length + R.lamps.length, "one per jumped, ducked or shot-for-light thing, none for orderlies"); + for (const m of marks) assert.equal(m.answer, answers[m.kind], m.kind); + const first = R.lows.find((l) => !l[3]); + const m = marks.find((q) => q.x === (first[0] + first[1]) / 2); + const alphaOf = (x) => (telegraphs(R, x).find((t) => t.kind === "lamp" && t.lead === m.lead) || { alpha: 0 }).alpha; + const a = [m.lead - 45, m.lead - 36, m.lead - 30, m.lead - 10, m.lead + 3, m.lead + 7].map(alphaOf); + assert.equal(a[0], 0, "not yet in view"); + assert.ok(a[1] > 0 && a[1] < 1, "fading in 40 to 30 ahead"); + assert.equal(a[2], 1); + assert.equal(a[3], 1); + assert.ok(a[4] > 0 && a[4] < 1, "fading as it passes"); + assert.equal(a[5], 0, "gone once passed"); + assert.deepEqual(JSON.parse(JSON.stringify(telegraphs(R, 100))), JSON.parse(JSON.stringify(telegraphs(R, 100)))); + for (const kind of ["shaft", "chair", "stand", "lamp", "door"]) { + const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead); + assert.ok(of.length >= 3, kind); + of.forEach((q, i) => { + assert.equal(q.n, i); + const shown = telegraphs(R, q.lead - 32).find((t) => t.lead === q.lead); + assert.equal(shown.words, i < 3, `${kind} ${i}`); + }); + } + const surge = telegraphs(R, R.lamps[0][0] - 24 - 32).find((t) => t.kind === "surge"); + assert.equal(surge.answer, "SHOOT"); +}); + +test("Ghoul Rush's Code Blue's intro banner says the controls plainly", () => { + assert.match(R.how, /UP to jump, DOWN to duck/); +}); diff --git a/scripts/test-web-console-activities-ghoul-hearse.mjs b/scripts/test-web-console-activities-ghoul-hearse.mjs new file mode 100644 index 0000000..41b046c --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-hearse.mjs @@ -0,0 +1,1161 @@ +// Web console tests, Ghoul Rush's Midnight Hearse (the Graveyard's bonus round, between the Mausoleum Row and Angel's Rest): its shape (two lanes, the gates, every thing spaced for a player, the closed stretches with a gate before each), the hearse's motion (a steady speed, a jump, a duck, a hop between lanes only at a gate), each obstacle and its cost (grave, headstone, cross, branch, hand, crow, wreck), the lamp and its lanterns, the coffins thrown out and the ghouls that sit up in them, the hearts and the grade and the dice, endless lives, the drawing and the sounds, and bots that play it. +// Run with: node --test scripts/test-web-console-activities-ghoul-hearse.mjs +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { skipBossIntro } from "./ghoul-test-helpers.mjs"; +import * as hz from "../src/web-console/public/activities/ghoul-hearse.js"; +import { ANSWERS, EVENT_VOICE, LOOKS as HEARSE_LOOKS, LOSE_SOUNDS, LOSE_WORDS, VOICES as HEARSE_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-hearse-draw.js"; +import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js"; +import { HEARSE_SFX } from "../src/web-console/public/activities/ghoul-sfx-hearse.js"; +import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-draw.js"; +import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-bonus.js"; + +const steady = () => 0.5; +// The pack draws no random number: a run on this fails on the first draw. +const never = () => { + throw new Error("the hearse drew a random number"); +}; +const events = (round, type) => round.events.filter((e) => e.type === type); + +function through(round) { + round.phase = "clear"; + round.phaseMs = 1; + ghoul.advance(round, 4, steady); +} + +// A round in the Midnight Hearse reached the way play reaches it, nothing woken, the clocks long, +// the bonus round on (five hearts). +function hearseRound(seed = 5) { + const round = ghoul.newRound(seed); + round.lives = 3; + round.dice = 0; + through(round); + round.offer = ["graveyard"]; + round.phaseMs = 0; + ghoul.pickStage(round, 0); + while (round.spec.id !== "hearse") through(round); + round.phase = "play"; + for (const st of round.spawns) st.over = true; + round.monsters.length = 0; + round.hordeMs = Infinity; + round.timeMs = 1e9; + round.bonus = 1e9; + round.events.length = 0; + return round; +} + +const NONE = { runner: "hearse", time: 1e9, finish: 1e6, gates: [], graves: [], stones: [], lows: [], hands: [], crows: [], blocks: [], lanterns: [], fog: [], checks: [] }; +// The same round over a ride of its own (a plain road to measure the hearse on). +function synth(ride) { + const round = hearseRound(); + round.spec = { ...round.spec, start: 10, ground: [[0, 1e6, 9]], ride: { ...NONE, ...ride } }; + round.runner = null; + hz.HEARSE.place[0](round, {}); + return round; +} + +// The hearse at `x` in `lane`, on the road. +function at(round, x, lane = 0, { safe = false } = {}) { + Object.assign(round.runner, { lane, from: lane, swMs: 0, h: 0, vy: 0, air: false }); + Object.assign(round.you, { x, y: hz.LANE_Y[lane], vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false }); + round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24)); +} + +function run(round, ms, keys = {}, random = steady) { + Object.assign(round.input, keys); + for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random); + for (const k of Object.keys(keys)) round.input[k] = typeof keys[k] === "number" ? 0 : false; +} + +function until(round, done, ms = 6000, random = steady) { + let t = 0; + for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random); + return t; +} + +const press = (round) => { + round.input.jump = ghoul.JUMP_BUFFER_MS; + round.input.up = true; +}; + +const heard = (e, extra = {}) => { + const played = []; + const noop = () => {}; + const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra }; + react({ x: 10, y: 9, tx: 20, ty: 9, ...e }, kit); + return { played }; +}; + +const ROOM = ghoul.roomById("hearse"); +const R = ROOM.ride; +const V = hz.HEARSE_V; +// Where each kind of thing is met by a hearse in its lane: a crow meets it before the perch it flies from. +const CROW_MEET = hz.CROW_NEAR - (hz.CROW_NEAR * V) / (V + hz.CROW_V); +const things = () => [ + ...R.graves.map(([x, lane], i) => ({ id: `g${i}`, kind: "grave", lane, x })), + ...R.stones.map(([x, lane, kind], i) => ({ id: `s${i}`, kind: kind ? "cross" : "stone", lane, x })), + ...R.lows.map(([x0, x1, lane], i) => ({ id: `l${i}`, kind: "low", lane, x: (x0 + x1) / 2 })), + ...R.hands.map(([x, lane], i) => ({ id: `h${i}`, kind: "hand", lane, x: x - 6 })), + ...R.crows.map(([x, lane], i) => ({ id: `c${i}`, kind: "crow", lane, x: x - CROW_MEET })), +]; + +/* -------------------------------------------------------------- the room */ + +test("Ghoul Rush's Midnight Hearse is the Graveyard's fourth room, between the Mausoleum Row and Angel's Rest: lit, no key, no boss, a ride about 60 to 70 seconds long, a bonus round that plays its own track", () => { + const st = ghoul.stageById("graveyard"); + assert.deepEqual(st.rooms, ["lychgate", "graves", "mausoleums", "hearse", "angel"]); + assert.equal(st.boss, "angel"); + assert.deepEqual([ROOM.title, ROOM.sub], ["The Midnight Hearse", "Everyone else is already dead on time"]); + assert.equal(ROOM.dark, false, "a moonlit night, always lit"); + assert.equal(ROOM.key, null); + assert.equal(ROOM.boss, null); + assert.equal(ROOM.bonus, true, "a bonus round"); + assert.equal(R.runner, "hearse"); + assert.ok(ROOM.length >= 2400 && ROOM.length <= 3000, `${ROOM.length} units long`); + assert.equal(ghoul.ROOM_MUSIC.hearse, "ghoulHearseRide"); + assert.ok(ghoulSfx.default.music.ghoulHearseRide, "its own track"); + assert.deepEqual(Object.keys(hz.HEARSE.monsters), [], "no new monster kinds"); + assert.equal(LOOKS.hearse, HEARSE_LOOKS.hearse); + assert.equal(LOOKS.hearse.pack, "hearse"); + assert.ok(Object.isFrozen(R) && Object.isFrozen(R.graves) && Object.isFrozen(R.graves[0]), "frozen all the way down"); + assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0 && ROOM.items.length === 0, "no monsters or pickups: the things on the road are the pack's own"); + // One flat road; the door past the finish. + assert.deepEqual(ROOM.ground.map((g) => g.slice()), [[0, ROOM.length, hz.LANE_Y[0]]]); + assert.ok(R.finish < ROOM.door && ROOM.door > ROOM.length - 20, "the door at the room's end, past the finish"); + assert.ok(ghoul.groundAt(ROOM, ROOM.door - 2) > -Infinity, "floor to walk out on"); + const secs = (R.finish - ROOM.start) / V; + assert.ok(secs >= 58 && secs <= 72, `${secs.toFixed(1)} s at HEARSE_V`); + assert.equal(ghoul.timeFor(ROOM), R.time, "its own clock"); + assert.ok(R.time / 1000 > secs * 1.4, "a clock with room to spare"); + assert.deepEqual(ghoul.STAGES.find((s) => s.id === "graveyard").rooms.length, 5); + // The numbers of the course. + assert.equal(R.gates.length, 13); + assert.equal(R.blocks.length, 5); + assert.equal(R.checks.length, 6); + assert.ok(R.fog.length >= 3); + assert.ok(R.hands.length >= 6 && R.crows.length >= 6, "enough to shoot"); +}); + +test("Ghoul Rush's Midnight Hearse: every thing is in lane 0 or 1, off the ends, spaced for a player, and clear of the lane gates", () => { + const all = things(); + assert.ok(all.length >= 36 && all.length <= 56, `${all.length} things`); + for (const t of all) { + assert.ok(t.lane === 0 || t.lane === 1, `${t.id} lane`); + assert.ok(t.x >= 120 && t.x < R.finish - 40, `${t.id} at ${t.x}`); + } + for (const kind of ["grave", "stone", "cross", "low", "hand", "crow"]) assert.ok(all.some((t) => t.kind === kind), `a ${kind}`); + for (const lane of [0, 1]) assert.ok(all.filter((t) => t.lane === lane).length >= 18, `plenty in lane ${lane}`); + // The same lane: 36 between any two (a jump and a duck need 38, a jump and a jump 22). + for (const lane of [0, 1]) { + const xs = all.filter((t) => t.lane === lane).map((t) => t.x).sort((a, b) => a - b); + for (let i = 1; i < xs.length; i++) assert.ok(xs[i] - xs[i - 1] >= 36, `lane ${lane}: ${xs[i - 1]} and ${xs[i]}`); + } + // Gates: 16 wide, in order, and nothing within the hop of one. + R.gates.forEach(([a, b], i) => { + assert.equal(b - a, 16); + if (i) assert.ok(a - R.gates[i - 1][1] >= 150, "gates are spaced out"); + for (const t of all) assert.ok(t.x < a - 6 || t.x > b + 22, `${t.id} at ${t.x} is near the gate ${a}`); + }); + // A low's width and its mouth: 6 wide. + for (const [x0, x1] of R.lows) assert.equal(x1 - x0, 6); + // Hands and crows sit clear of every kind of block too. + assert.ok(R.hands.every(([x]) => x > R.gates[0][1]) && R.crows.every(([x]) => x > R.gates[0][1])); +}); + +test("Ghoul Rush's Midnight Hearse: each closed stretch has a lane gate well before it, nothing else stands in its lane near it, and the road is open in the other lane", () => { + const all = things(); + for (const [x0, x1, lane] of R.blocks) { + assert.ok(x1 - x0 >= 24 && x1 - x0 <= 40, `a block ${x1 - x0} long (the safe blink must outlast it)`); + assert.ok((x1 - x0 + 2.4) / V * 1000 < 1800, "the blink after a wreck covers the stretch"); + const gate = R.gates.filter(([, b]) => b + 22 <= x0).at(-1); + assert.ok(gate, "a gate ends 22 or more short of it"); + assert.ok(x0 - gate[1] <= 70, "the gate is close enough to see the stretch from"); + for (const t of all.filter((q) => q.lane === lane)) assert.ok(t.x < x0 - 18 || t.x > x1 + 18, `${t.id} at ${t.x} is in the way of the block at ${x0}`); + assert.ok(!R.checks.some((x) => x > x0 - 4 && x < x1 + 4), "no checkpoint inside it"); + } + // They alternate lanes, so a hearse that goes round each is switched back and forth. + assert.deepEqual(R.blocks.map(([, , lane]) => lane), [0, 1, 0, 1, 0]); +}); + +test("Ghoul Rush's Midnight Hearse: the lanterns, the fog and the checkpoints are set where they can be used", () => { + const all = things(); + assert.ok(R.lanterns.length >= 24); + assert.ok(R.lanterns.filter(([, l]) => l === 0).length > R.lanterns.filter(([, l]) => l === 1).length * 2, "mostly on the road"); + assert.ok(R.lanterns.some(([, l]) => l === 1), "a few on the verge"); + for (const [x, lane] of R.lanterns) { + assert.ok(all.filter((t) => t.lane === lane).every((t) => Math.abs(t.x - x) >= 12), `the lantern at ${x} is clear of the things`); + assert.ok(R.blocks.every(([x0, x1, l]) => l !== lane || x < x0 - 10 || x > x1 + 10), "and of the blocks"); + } + R.checks.forEach((x, i) => { + if (i) assert.ok(x - R.checks[i - 1] >= 350); + assert.ok(R.gates.every(([a, b]) => x < a - 4 || x > b + 4)); + }); + for (const [a, b] of R.fog) assert.ok(b - a >= 100 && b - a <= 200); + // Souls along both lanes, and over the things. + const rows = ROOM.candy; + assert.ok(rows.length * 3 >= 200, `${rows.length * 3} souls`); + assert.ok(rows.some(([, y]) => y < 12) && rows.some(([, y]) => y > 15 && y < 20), "souls in both lanes"); +}); + +/* -------------------------------------------------------------- the hearse */ + +function k() { + return { HIT_W: ghoul.HIT_W, HIT_H: ghoul.HIT_H, DUCK_H: ghoul.DUCK_H }; +} + +test("Ghoul Rush's Midnight Hearse rolls at HEARSE_V whatever is pressed, on a road with nothing on it, and the camera leads it", () => { + const round = synth({}); + assert.equal(round.runner.id, "hearse"); + assert.equal(round.camLead, hz.CAM_AHEAD); + assert.equal(round.you.y, hz.LANE_Y[0]); + const x0 = round.you.x; + run(round, 1000); + assert.ok(Math.abs(round.you.x - x0 - V) < 0.5, `${round.you.x - x0} in a second`); + for (const keys of [{ left: true }, { down: true }, { fire: true }]) { + const a = round.you.x; + run(round, 500, keys); + assert.ok(Math.abs(round.you.x - a - V / 2) < 0.5, `${JSON.stringify(keys)}`); + } + assert.equal(round.you.face, 1); + // Left and right do nothing off a gate. + run(round, 400, { right: true }); + assert.equal(round.runner.lane, 0); + assert.equal(round.you.y, hz.LANE_Y[0]); +}); + +test("Ghoul Rush's Midnight Hearse jumps about 13 high for about three quarters of a second, a press saved for a landing jumps on it, and it cannot jump in the air", () => { + const round = synth({}); + let peak = 0; + let ms = 0; + press(round); + for (let t = 0; t < 1200; t += 4) { + ghoul.advance(round, 4, steady); + round.input.up = false; + if (round.runner.air) { + peak = Math.max(peak, round.you.y - hz.LANE_Y[0]); + ms += 4; + } else if (ms) break; + } + assert.ok(peak > 12 && peak < 15, `${peak} high`); + assert.ok(ms > 650 && ms < 850, `${ms} ms in the air`); + assert.equal(events(round, "hearseJump").length, 1); + assert.equal(events(round, "hearseLand").length, 1); + assert.equal(round.you.y, hz.LANE_Y[0]); + assert.equal(round.you.state, "run"); + // The reach: about 31 units across. + const fresh = synth({}); + const x0 = fresh.you.x; + press(fresh); + ghoul.advance(fresh, 4, steady); + fresh.input.up = false; + until(fresh, () => fresh.runner.air === false, 2000); + assert.ok(fresh.you.x - x0 > 28 && fresh.you.x - x0 < 34, `${fresh.you.x - x0} across`); + // A press in the air waits for the landing and jumps then. + const late = synth({}); + press(late); + ghoul.advance(late, 4, steady); + until(late, () => late.you.vy < -60, 2000); + press(late); + late.events.length = 0; + until(late, () => events(late, "hearseJump").length > 0, 2000); + assert.equal(events(late, "hearseLand").length, 1, "landed first"); + assert.equal(events(late, "hearseJump").length, 1); +}); + +test("Ghoul Rush's Midnight Hearse: down ducks (up jumps instead of ducking), a ducked Planny passes under a low and a standing one hits it (cause branch), at the cost of a heart", () => { + const ride = { lows: [[300, 306, 0, 0], [500, 506, 0, 1]] }; + const stand = synth(ride); + at(stand, 285, 0); + const lose = []; + until(stand, () => stand.events.some((e) => e.type === "lose"), 1500); + for (const e of stand.events) if (e.type === "lose") lose.push(e.cause); + assert.deepEqual(lose, ["branch"]); + assert.equal(stand.bonusRound.hearts, 4); + assert.equal(stand.lives, 3, "a heart, not a life"); + assert.equal(events(stand, "hearseCrash")[0].what, "low"); + const duck = synth(ride); + at(duck, 285, 0); + run(duck, 1000, { down: true }); + assert.equal(duck.bonusRound.hearts, 5, "ducked under it"); + assert.ok(events(duck, "hearseDuck").length >= 1); + assert.equal(duck.you.ducking, true, "still ducking"); + // The arch is the same. + const arch = synth(ride); + at(arch, 485, 0); + run(arch, 1000, { down: true }); + assert.equal(arch.bonusRound.hearts, 5); + // The underside is between a ducked box and a standing one. + assert.ok(hz.LOW_Y > ghoul.DUCK_H && hz.LOW_Y < ghoul.HIT_H); + // A jump over a low hits it too (the box rises into it). + const hop = synth(ride); + at(hop, 288, 0); + press(hop); + run(hop, 600); + assert.ok(hop.bonusRound.hearts < 5); + // On the verge a low is on the verge: the same underside over its lane. + const verge = synth({ lows: [[300, 306, 1, 0]] }); + at(verge, 285, 1); + run(verge, 800); + assert.equal(verge.bonusRound.hearts, 4); + const vduck = synth({ lows: [[300, 306, 1, 0]] }); + at(vduck, 285, 1); + run(vduck, 800, { down: true }); + assert.equal(vduck.bonusRound.hearts, 5); +}); + +test("Ghoul Rush's Midnight Hearse: an open grave swallows a hearse that does not jump (cause grave), a headstone and a fallen cross likewise (tomb and cross); a jump clears each; each costs only once", () => { + const ride = { graves: [[300, 0]], stones: [[400, 0, 0], [500, 0, 1]] }; + for (const [x, cause, what] of [[285, "grave", "grave"], [385, "tomb", "stone"], [485, "cross", "cross"]]) { + const round = synth(ride); + at(round, x, 0); + run(round, 1000); + assert.equal(round.bonusRound.hearts, 4, cause); + assert.deepEqual(round.bonusRound.perf.hits.length, 1); + assert.equal(events(round, "hearseCrash").length, 1, "once: the blink after a hit covers the rest of it"); + assert.equal(events(round, "hearseCrash")[0].what, what); + assert.equal(round.lives, 3); + const jumped = synth(ride); + at(jumped, x, 0); + // Jump 10 short, the way a player does. + run(jumped, 40); + press(jumped); + run(jumped, 40); + jumped.input.up = false; + run(jumped, 1400); + assert.equal(jumped.bonusRound.hearts, 5, `${cause} cleared`); + } + // The causes reach the lose event. + const g = synth(ride); + at(g, 285, 0); + run(g, 800); + assert.equal(events(g, "lose")[0].cause, "grave"); + // A grave in the other lane, or one the hearse has passed over by a jump from the verge, does nothing. + const other = synth({ graves: [[300, 1]] }); + at(other, 285, 0); + run(other, 1000); + assert.equal(other.bonusRound.hearts, 5); + // An obstacle cleared at every jump distance in its window: 7 to 24 short for a grave, 6 to 25 for a headstone. + for (const d of [8, 12, 16, 20, 24]) { + const w = synth({ graves: [[300, 0]], stones: [[400, 0, 0]] }); + at(w, 300 - d, 0); + press(w); + run(w, 20); + w.input.up = false; + run(w, 1000); + assert.equal(w.bonusRound.hearts, 5, `jumped ${d} short of the grave`); + } + for (const d of [8, 12, 16, 20, 24]) { + const w = synth({ stones: [[400, 0, 0]] }); + at(w, 400 - d, 0); + press(w); + run(w, 20); + w.input.up = false; + run(w, 1000); + assert.equal(w.bonusRound.hearts, 5, `jumped ${d} short of the headstone`); + } +}); + +test("Ghoul Rush's Midnight Hearse switches lanes only inside a gate: LEFT is the road, RIGHT the verge, in SWITCH_MS, with no jump or duck in the hop; things in the other lane do not touch it", () => { + const ride = { gates: [[300, 316]], graves: [[330, 0]], stones: [[330, 1, 0]] }; + const round = synth(ride); + at(round, 280, 0); + run(round, 200, { right: true }); + assert.equal(round.runner.lane, 0, "not yet at the gate"); + assert.equal(round.you.y, hz.LANE_Y[0]); + run(round, 400, { right: true }); + assert.ok(round.you.x > 300); + assert.equal(round.runner.lane, 1); + assert.equal(events(round, "hearseSwitch").length, 1); + assert.equal(events(round, "hearseSwitch")[0].to, 1); + // It climbs across the switch time, with a small hop, and ends on the verge. + const ys = []; + const switching = synth(ride); + at(switching, 301, 0); + switching.input.right = true; + for (let t = 0; t < hz.SWITCH_MS + 40; t += 4) { + ghoul.advance(switching, 4, steady); + ys.push(switching.you.y); + } + switching.input.right = false; + assert.ok(ys.every((y, i) => !i || y >= ys[i - 1] - 0.5), "rising"); + assert.ok(Math.max(...ys) > hz.LANE_Y[1] - 0.2, "up on the verge"); + assert.equal(switching.you.y, hz.LANE_Y[1]); + assert.equal(switching.runner.swMs, 0); + // And back with LEFT, in a gate again. + const back = synth({ gates: [[300, 316]] }); + at(back, 301, 1); + run(back, hz.SWITCH_MS + 40, { left: true }); + assert.equal(back.runner.lane, 0); + assert.equal(back.you.y, hz.LANE_Y[0]); + // Pressing the lane it is in does nothing; both at once do nothing. + const same = synth({ gates: [[300, 316]] }); + at(same, 301, 0); + run(same, 300, { left: true }); + assert.equal(events(same, "hearseSwitch").length, 0); + run(same, 200, { left: true, right: true }); + assert.equal(events(same, "hearseSwitch").length, 0); + // Not in the air. + const air = synth({ gates: [[300, 400]] }); + at(air, 301, 0); + press(air); + run(air, 40); + run(air, 100, { right: true }); + assert.equal(air.runner.lane, 0, "in the air"); + run(air, 900, { right: true }); + assert.equal(air.runner.lane, 1, "once down"); + // In the hop no jump, and the hearse stays down. + const hop = synth({ gates: [[300, 316]] }); + at(hop, 301, 0); + hop.input.right = true; + press(hop); + run(hop, 100); + assert.equal(events(hop, "hearseJump").length, 0); + // A lane's own things only touch the hearse in that lane: the grave in lane 0 is nothing to a hearse on the verge. + const verge = synth(ride); + at(verge, 301, 0); + verge.input.right = true; + run(verge, 1400); + verge.input.right = false; + assert.equal(verge.runner.lane, 1); + assert.ok(verge.bonusRound.hearts >= 4); + assert.equal(verge.bonusRound.perf.hits.includes("g0"), false, "the grave in the road did not hit the hearse on the verge"); +}); + +test("Ghoul Rush's Midnight Hearse: a closed stretch throws the hearse across into the other lane (cause wreck), a heart lighter, once; going round by the gate costs nothing; a blinking hearse is thrown for free", () => { + const ride = { gates: [[100, 116]], blocks: [[200, 232, 0]] }; + const smash = synth(ride); + at(smash, 180, 0); + run(smash, 1200); + assert.equal(smash.bonusRound.hearts, 4); + assert.equal(events(smash, "lose")[0].cause, "wreck"); + assert.equal(smash.runner.lane, 1, "thrown across"); + assert.equal(smash.you.y, hz.LANE_Y[1]); + assert.equal(events(smash, "hearseCrash").length, 1); + assert.equal(events(smash, "hearseCrash")[0].what, "wreck"); + assert.equal(smash.bonusRound.perf.hits.join(), "b0"); + // Round by the gate: nothing. + const round = synth(ride); + at(round, 96, 0); + round.input.right = true; + until(round, () => round.you.x > 117, 1000); + round.input.right = false; + until(round, () => round.you.x > 240, 4000); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.runner.lane, 1); + assert.ok(round.you.x > 240, "through the stretch"); + // On the verge the stretch is in the road's lane, so nothing happens either; and a verge block is the verge's. + const verge = synth({ blocks: [[200, 232, 1]] }); + at(verge, 180, 1); + run(verge, 1200); + assert.equal(verge.runner.lane, 0); + assert.equal(verge.bonusRound.hearts, 4); + // Blinking safe: thrown, no heart. + const safe = synth(ride); + at(safe, 180, 0, { safe: true }); + run(safe, 1200); + assert.equal(safe.runner.lane, 1); + assert.equal(safe.bonusRound.hearts, 5); + assert.equal(safe.runner.coffins, hz.COFFINS, "no heart, no coffin"); +}); + +test("Ghoul Rush's Midnight Hearse: a hand in a mound stirs when the hearse is HAND_NEAR short, shivers, reaches up for HAND_UP_MS, grabs (cause grasp) if you meet it, and sinks; a jump clears it", () => { + const ride = { hands: [[300, 0]] }; + const round = synth(ride); + at(round, 300 - hz.HAND_NEAR - 2, 0, { safe: true }); + run(round, 40); + assert.equal(round.runner.hands[0].state, "mound"); + run(round, 100); + assert.equal(round.runner.hands[0].state, "warn"); + assert.equal(events(round, "hearseHandWarn").length, 1); + run(round, hz.HAND_WARN_MS); + assert.equal(round.runner.hands[0].state, "up"); + assert.equal(events(round, "hearseHandUp").length, 1); + // It grabs a hearse that meets it, and sinks. + const grab = synth(ride); + at(grab, 270, 0); + run(grab, 1500); + assert.equal(grab.bonusRound.hearts, 4); + assert.equal(events(grab, "lose")[0].cause, "grasp"); + assert.equal(grab.runner.hands[0].state === "sink" || grab.runner.hands[0].state === "spent", true); + // A jump over it. + const hop = synth(ride); + at(hop, 300 - 24, 0); + run(hop, 100); + press(hop); + run(hop, 40); + hop.input.up = false; + run(hop, 1500); + assert.equal(hop.bonusRound.hearts, 5, "jumped it"); + // It rises and sinks on a timer when nothing is near: HAND_UP_MS up, then HAND_SINK_MS. + const timed = synth(ride); + at(timed, 300 - hz.HAND_NEAR + 1, 0, { safe: true }); + timed.you.x = 300 - hz.HAND_NEAR + 1; + run(timed, 50); + run(timed, hz.HAND_WARN_MS + hz.HAND_UP_MS + hz.HAND_SINK_MS + 100); + assert.equal(timed.runner.hands[0].state, "spent"); +}); + +test("Ghoul Rush's Midnight Hearse: one bolt breaks a flying crow (80 points), a perched one too, HAND_HP bolts a hand (100 points), each for the grade's acts; a crow hits a standing hearse (cause crow), a ducked one passes under it", () => { + const ride = { crows: [[320, 0, 2.6]], hands: [[500, 0]] }; + // A crow wakes CROW_NEAR short of its perch and flies back at CROW_V. + const round = synth(ride); + at(round, 320 - hz.CROW_NEAR + 2, 0, { safe: true }); + run(round, 100); + assert.equal(round.runner.crows[0].state, "fly"); + assert.equal(events(round, "hearseCrowWake").length, 1); + const x1 = round.runner.crows[0].x; + run(round, 500); + assert.ok(Math.abs(x1 - round.runner.crows[0].x - hz.CROW_V * 0.5) < 0.3, "flying back at CROW_V"); + // It hits a hearse that stands, and misses one that ducks. + const hit = synth(ride); + at(hit, 320 - 50, 0); + run(hit, 1600); + assert.equal(hit.bonusRound.hearts, 4); + assert.equal(events(hit, "lose")[0].cause, "crow"); + const duck = synth(ride); + at(duck, 320 - 50, 0); + run(duck, 1600, { down: true }); + assert.equal(duck.bonusRound.hearts, 5, "ducked under it"); + // Shot: one bolt, the points, the grade's act. + const shot = synth(ride); + at(shot, 320 - 50, 0); + const score = shot.score; + run(shot, 1600, { fire: true }); + assert.equal(shot.bonusRound.hearts, 5, "shot before it arrived"); + assert.equal(shot.runner.crows[0].state, "broken"); + assert.equal(shot.score - score >= hz.CROW_POINTS, true); + assert.equal(shot.bonusRound.perf.acts, 1); + assert.equal(events(shot, "hearseCrowHit")[0].points, hz.CROW_POINTS); + // A hand takes two bolts. + const hand = synth(ride); + at(hand, 500 - 30, 0, { safe: true }); + const before = hand.score; + run(hand, 700, { fire: true }); + assert.equal(events(hand, "hearseHandHit").length, 1); + assert.equal(events(hand, "hearseHandBreak").length, 1); + assert.equal(hand.runner.hands[0].state === "broken", true); + assert.equal(hand.score - before >= hz.HAND_POINTS, true); + assert.equal(hand.bonusRound.perf.acts, 1); + // A bolt in the other lane misses. + const lane = synth({ crows: [[320, 1, 2.6]] }); + at(lane, 320 - 50, 0, { safe: true }); + run(lane, 1200, { fire: true }); + assert.notEqual(lane.runner.crows[0].state, "broken"); +}); + +test("Ghoul Rush's Midnight Hearse: the lamp burns down LAMP_DRAIN a second (more in the fog), a lantern gives LANTERN_GAIN back, and a lamp that goes out is the one the steady die loses", () => { + const round = synth({}); + assert.equal(round.runner.lamp, hz.LAMP_MAX); + run(round, 1000); + assert.ok(Math.abs(round.runner.lamp - (hz.LAMP_MAX - hz.LAMP_DRAIN)) < 0.1, `${round.runner.lamp}`); + const fog = synth({ fog: [[0, 1e6]] }); + run(fog, 1000); + assert.ok(Math.abs(fog.runner.lamp - (hz.LAMP_MAX - hz.LAMP_DRAIN - hz.LAMP_FOG)) < 0.1); + assert.equal(fog.runner.fog, true); + // A lantern in the lane gives LANTERN_GAIN (once, capped), in points too. + const lit = synth({ lanterns: [[200, 0]] }); + at(lit, 190, 0); + lit.runner.lamp = 40; + const score = lit.score; + run(lit, 500); + assert.ok(lit.runner.lamp > 40 + hz.LANTERN_GAIN - hz.LAMP_DRAIN, `${lit.runner.lamp}`); + assert.equal(lit.runner.lit[0], true); + assert.equal(lit.score - score >= hz.LANTERN_POINTS, true); + assert.equal(events(lit, "hearseLantern").length, 1); + const cap = synth({ lanterns: [[200, 0]] }); + at(cap, 190, 0); + run(cap, 500); + assert.ok(cap.runner.lamp <= hz.LAMP_MAX); + // A lantern in the other lane is not taken, nor one the hearse jumps high over. + const other = synth({ lanterns: [[200, 1]] }); + at(other, 190, 0); + run(other, 500); + assert.equal(other.runner.lit[0], false); + const high = synth({ lanterns: [[200, 0]] }); + at(high, 182, 0); + press(high); + run(high, 20); + high.input.up = false; + run(high, 1000); + assert.equal(high.runner.lit[0], false, "jumped over it"); + // The lamp going out: the event, the grade, the night closing in; a lantern relights it. + const out = synth({ lanterns: [[400, 0]] }); + out.runner.lamp = 1; + assert.equal(out.bonusRound.perf.steady, true); + run(out, 800); + assert.equal(out.runner.out, true); + assert.equal(out.runner.lamp, 0); + assert.equal(out.runner.broken, true); + assert.equal(out.bonusRound.perf.steady, false); + assert.equal(events(out, "hearseLampOut").length, 1); + at(out, 390, 0); + out.runner.lamp = 0; + run(out, 500); + assert.equal(out.runner.out, false); + assert.equal(events(out, "hearseLampLit").length, 1); + assert.equal(out.bonusRound.perf.steady, false, "a lamp that went out stays a broken lamp"); +}); + +test("Ghoul Rush's Midnight Hearse: a hit throws a coffin out ahead, the lid pops and a ghoul sits up in the lane to shoot for SIT_POINTS; it ducks back as the hearse reaches it; the five coffins run out", () => { + const ride = { stones: [[300, 0, 0], [900, 0, 0]] }; + const round = synth(ride); + at(round, 285, 0); + assert.equal(round.runner.coffins, hz.COFFINS); + run(round, 400); + assert.equal(round.runner.coffins, hz.COFFINS - 1); + assert.equal(round.runner.sitters.length, 1); + const s = round.runner.sitters[0]; + assert.equal(s.lane, 0); + assert.ok(s.x > 285 + hz.SIT_AHEAD - 20 && s.x < 300 + hz.SIT_AHEAD + 5, `${s.x}`); + assert.equal(events(round, "hearseCoffin").length, 1); + assert.equal(events(round, "hearseCoffin")[0].left, hz.COFFINS - 1); + assert.equal(s.state, "fly"); + until(round, () => s.state === "sit", 1500); + assert.equal(s.state, "sit"); + assert.equal(events(round, "hearseSitUp").length, 1); + // Shot: points and an act. Not before it has risen. + round.you.safeMs = 1e9; + const score = round.score; + run(round, 600, { fire: true }); + assert.equal(s.state, "broken"); + assert.equal(round.score - score >= hz.SIT_POINTS, true); + assert.equal(round.bonusRound.perf.acts, 1); + assert.equal(events(round, "hearseSitHit")[0].points, hz.SIT_POINTS); + // A ghoul not shot ducks back down as the hearse reaches it (it never hurts). + const miss = synth(ride); + at(miss, 285, 0); + run(miss, 400); + const m = miss.runner.sitters[0]; + until(miss, () => m.state === "sit", 1500); + miss.you.safeMs = 1e9; + const hearts = miss.bonusRound.hearts; + until(miss, () => miss.you.x > m.x + 8, 3000); + assert.equal(m.state, "hid"); + assert.equal(miss.bonusRound.hearts, hearts, "harmless"); + // The sat-up ghoul can be shot only after it has risen. + const early = synth(ride); + at(early, 285, 0); + run(early, 400); + const e = early.runner.sitters[0]; + until(early, () => e.state === "sit", 1500); + early.shots.push({ x: e.x - 2, y: hz.LANE_Y[0] + 2.4, vx: 130, vy: 0, gone: 0 }); + e.t = hz.SIT_MS - 10; + ghoul.advance(early, 4, steady); + assert.equal(e.state, "sit", "still rising"); + // Five coffins and no more. + const many = synth({}); + many.runner.coffins = 1; + at(many, 285, 0); + many.spec = { ...many.spec, ride: { ...many.spec.ride, stones: [[300, 0, 0], [400, 0, 0]] } }; + run(many, 400); + assert.equal(many.runner.coffins, 0); + assert.equal(many.runner.sitters.length, 1); + many.you.safeMs = 0; + at(many, 385, 0); + run(many, 400); + assert.equal(many.runner.sitters.length, 1, "none left to throw"); + assert.equal(many.bonusRound.hearts, 3); +}); + +test("Ghoul Rush's Midnight Hearse: the last heart gone ends the round with nothing at once (no life lost, the dice in hand kept) and the run goes on to Angel's Rest", () => { + const round = hearseRound(); + round.dice = 2; + round.bonusRound.hearts = 1; + at(round, R.gates[0][1] + 20, 0); + // Find the first thing in the road's lane and drive at it. + const first = things().filter((t) => t.lane === 0).sort((a, b) => a.x - b.x)[0]; + at(round, first.x - 12, 0); + until(round, () => round.phase === "clear", 8000); + assert.equal(round.bonusRound.hearts, 0); + assert.equal(round.bonusRound.over, true); + assert.equal(round.bonusRound.won, false); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, false); + assert.equal(end[0].dice, 0); + assert.equal(round.over, false, "no game over"); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + run(round, ghoul.CARD_LOST_MS + 100); + assert.equal(round.spec.id, "angel"); + assert.equal(round.bonusRound, null); + assert.equal(round.runner, null); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + assert.equal(round.phase, "bossintro", "the boss room opens on its card"); + skipBossIntro(ghoul, round); + assert.equal(round.phase, "ready"); +}); + +test("Ghoul Rush's Midnight Hearse: the checkpoints are passed in order (an event each) and the ride goes back to the last one after the last heart", () => { + const round = hearseRound(); + at(round, R.checks[0] - 6, 0, { safe: true }); + until(round, () => round.runner.check >= 0, 3000); + const seen = events(round, "hearseCheck").map((e) => e.n); + assert.deepEqual(seen.slice(0, 1), [1]); + const c0 = round.runner.check; + round.you.x = 1; + hz.HEARSE.place[0](round, {}); + assert.equal(round.you.x, R.checks[c0]); + assert.equal(round.runner.check, c0); + assert.equal(round.runner.lane, 0); + assert.equal(round.camLead, hz.CAM_AHEAD); + const fresh = hearseRound(); + assert.equal(fresh.you.x, ROOM.start); + assert.equal(fresh.runner.check, -1); + // Past all six on a long drive. + const long = synth({ checks: R.checks }); + long.you.safeMs = 1e9; + long.timeMs = 1e9; + run(long, 62000); + assert.equal(long.runner.check, R.checks.length - 1); +}); + +test("Ghoul Rush's Midnight Hearse: at the finish the hearse brakes, the door opens, and walking out ends the round with 3 to 9 Lucky dice", () => { + const round = hearseRound(); + round.dice = 1; + at(round, R.finish - 8, 1, { safe: true }); + until(round, () => round.runner.done, 3000); + assert.equal(round.runner.done, true); + const fin = events(round, "hearseFinish"); + assert.equal(fin.length, 1); + assert.equal(round.you.y, ghoul.groundAt(ROOM, round.you.x), "back down on the road, from either lane"); + assert.equal(round.hasKey, true, "the door opens"); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.phase, "play"); + round.input.right = true; + until(round, () => round.phase === "clear", 20000); + round.input.right = false; + assert.equal(round.phase, "clear"); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, true); + assert.ok(end[0].dice >= BONUS_FLOOR && end[0].dice <= ghoul.MAX_DICE, `${end[0].dice} dice`); + assert.equal(round.dice, Math.min(ghoul.MAX_DICE, 1 + end[0].dice)); + assert.equal(round.lives, 3); + run(round, ghoul.CARD_MS + 100); + assert.equal(round.spec.id, "angel"); + assert.equal(round.runner, null); +}); + +test("Ghoul Rush's Midnight Hearse: no random number is drawn in the room (a ride of 20 seconds, jumping, switching and shooting, on a draw that throws)", () => { + const round = hearseRound(); + round.you.safeMs = 1e9; + for (let t = 0; t < 20000; t += 16) { + round.input.fire = true; + round.input.right = t % 6000 < 3000; + round.input.left = !round.input.right; + if (t % 1500 === 0) press(round); + ghoul.advance(round, 16, never); + round.input.up = false; + round.events.length = 0; + } + assert.ok(round.you.x > 600); +}); + +/* ----------------------------------------------------------- grade and dice */ + +test("Ghoul Rush's Midnight Hearse's grade: the obstacles the hearse faced are the total, one passed in its lane counts and one dodged by a lane does not, shooting 8 things is the die, an unbroken lamp is the die", () => { + const ride = { gates: [[300, 316]], graves: [[400, 0]], stones: [[460, 0, 0], [460, 1, 0]], hands: [[600, 1]] }; + const round = synth(ride); + at(round, 250, 0, { safe: true }); + assert.equal(round.bonusRound.perf.total, 0); + assert.equal(round.bonusRound.perf.goal, hz.ACTS_GOAL); + // Stay in the road: the grave and the road's headstone are faced, not the verge's stone or hand. + until(round, () => round.you.x > 480, 6000); + assert.equal(round.bonusRound.perf.total, 2); + // Switch away at the gate: the road's stone is dodged by the lane and not counted; the verge's is. + const away = synth(ride); + at(away, 296, 0, { safe: true }); + away.input.right = true; + run(away, 500); + away.input.right = false; + assert.equal(away.runner.lane, 1); + until(away, () => away.you.x > 480, 6000); + assert.ok(away.bonusRound.perf.total >= 1 && away.bonusRound.perf.total <= 2, `${away.bonusRound.perf.total}`); + assert.equal(away.bonusRound.perf.hits.length, 0); + // A faced thing that cost a heart is a hit, counted once. + const hit = synth(ride); + at(hit, 385, 0); + run(hit, 800); + assert.deepEqual(hit.bonusRound.perf.hits, ["g0"]); + assert.equal(hit.bonusRound.perf.total, 1); + // The dice: the floor, hearts, clean passes, acts, an unbroken lamp. + const b = makeBonus({ stats: { kills: 0 } }); + b.perf = { total: 20, hits: [], acts: 0, goal: hz.ACTS_GOAL, steady: false, kills0: 0 }; + assert.equal(diceFor(b), BONUS_FLOOR + 2 + 2); + b.perf.steady = true; + assert.equal(diceFor(b), 9 - 1); + b.perf.acts = hz.ACTS_GOAL; + assert.equal(diceFor(b), 9); + b.perf.acts = hz.ACTS_GOAL - 1; + assert.equal(diceFor(b), 8); + b.hearts = 1; + assert.equal(diceFor(b), 6); + b.perf.hits = Array.from({ length: 20 }, (_, i) => `x${i}`); + assert.equal(diceFor(b), BONUS_FLOOR + 0 + 0 + 0 + 1); + b.perf.steady = false; + assert.equal(diceFor(b), BONUS_FLOOR); +}); + +test("Ghoul Rush's Midnight Hearse: endless lives (round.infinite) spare the hearts for every cause, through the same lose path", () => { + const causes = { + grave: { graves: [[300, 0]] }, + tomb: { stones: [[300, 0, 0]] }, + cross: { stones: [[300, 0, 1]] }, + branch: { lows: [[300, 306, 0, 0]] }, + grasp: { hands: [[300, 0]] }, + crow: { crows: [[330, 0, 2.6]] }, + wreck: { blocks: [[300, 330, 0]] }, + }; + for (const [cause, ride] of Object.entries(causes)) { + const round = synth(ride); + round.infinite = true; + at(round, cause === "crow" ? 250 : 270, 0); + run(round, 1800); + assert.ok(events(round, "lose").some((e) => e.cause === cause), `${cause} was lost to`); + assert.equal(round.bonusRound.hearts, 5, `${cause} cost nothing`); + assert.equal(round.lives, 3); + assert.equal(round.phase, "play"); + } +}); + +test("Ghoul Rush's Midnight Hearse: every cause costs exactly one heart", () => { + const causes = { + grave: { graves: [[300, 0]] }, + tomb: { stones: [[300, 0, 0]] }, + cross: { stones: [[300, 0, 1]] }, + branch: { lows: [[300, 306, 0, 0]] }, + grasp: { hands: [[300, 0]] }, + crow: { crows: [[330, 0, 2.6]] }, + wreck: { blocks: [[300, 330, 0]] }, + }; + for (const [cause, ride] of Object.entries(causes)) { + const round = synth(ride); + at(round, cause === "crow" ? 250 : 270, 0); + run(round, 1800); + assert.equal(round.bonusRound.hearts, 4, cause); + assert.equal(events(round, "lose").map((e) => e.cause).join(), cause); + assert.equal(round.lives, 3); + } +}); + +test("Ghoul Rush's Midnight Hearse: the Garlic shield takes a hit instead of a heart", () => { + const round = synth({ stones: [[300, 0, 0]] }); + round.you.garlic = true; + at(round, 285, 0); + round.you.garlic = true; + run(round, 800); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.you.garlic, false); + assert.equal(round.runner.coffins, hz.COFFINS, "a coffin goes only with a heart"); +}); + +/* ---------------------------------------------------------------- voices */ + +test("Ghoul Rush's Midnight Hearse: every event has a voice that plays, every cause has words and a sound, and the voices are tones that exist (none over 1.2 s)", () => { + assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...hz.EVENTS].sort(), "a voice for every event and no more"); + const tones = ghoulSfx.default.tones; + for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) { + const name = HEARSE_VOICES[kind] && HEARSE_VOICES[kind][act]; + assert.ok(name, `${event} has a ${kind}.${act} voice`); + assert.ok(tones[name], `${name} exists`); + assert.equal(VOICES[kind][act], name, "joined to the game's voices"); + const played = heard({ type: event, what: "stone", points: 50, left: 2, to: 1 }).played; + assert.ok(played.includes(name), `${event} plays ${name}`); + } + for (const [name, def] of Object.entries(HEARSE_SFX.tones)) { + assert.ok(tones[name], name); + for (const l of def.layers) assert.ok(l.seconds > 0 && l.seconds + (l.delay || 0) <= 1.2, `${name} is short`); + } + for (const cause of ["grave", "tomb", "cross", "branch", "grasp", "crow", "wreck"]) { + assert.ok(LOSE_WORDS[cause], `${cause} has words`); + assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`); + assert.ok(heard({ type: "lose", cause, hearts: 3 }).played.length > 0, `${cause} sounds`); + } + assert.equal(heard({ type: "hearseJump" }).played.length, 1); + assert.equal(heard({ type: "hearseCrowHit", points: 80 }).played.length, 1); +}); + +test("Ghoul Rush's Midnight Hearse: its music has the room's level of voices, bars of sixteen steps, and a track for the room", () => { + const track = ghoulSfx.default.music.ghoulHearseRide; + assert.equal(track, HEARSE_SFX.music.ghoulHearseRide); + const playing = Object.entries(track.voices).filter(([, v]) => (v.from ?? 0) <= 0.7); + assert.ok(playing.length >= 4); + for (const [name, p] of Object.entries(track.patterns)) { + for (const [voice, line] of Object.entries(p)) { + assert.ok(track.voices[voice], `${name}.${voice} is a voice`); + for (const bar of line.split("|")) assert.equal(bar.trim().split(/\s+/).length, 16, `${name}.${voice}`); + } + } + for (const name of track.order) assert.ok(track.patterns[name]); +}); + +test("Ghoul Rush's Midnight Hearse: the room's own names do not collide with the game's (hazards, events, kinds)", () => { + for (const e of hz.EVENTS) assert.ok(e.startsWith("hearse"), e); + assert.deepEqual(Object.keys(hz.HEARSE).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []); + assert.equal(typeof ghoul.ROOM_MUSIC.hearse, "string"); + assert.equal(ghoul.roomById("hearse").ride.runner, "hearse"); +}); + +/* --------------------------------------------------------------- drawing */ + +test("Ghoul Rush's Midnight Hearse draws: the room in a lit and a dark one, the hearse on each lane, in the air, ducking and switching, each thing in each state, the fog, the lamp out, a crash, the finish and the cards", () => { + const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) }); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + g.resize(900, 900); + g.key("action"); + g.tick(16); + const r = g.round; + through(r); + r.offer = ["graveyard"]; + r.phaseMs = 0; + ghoul.pickStage(r, 0); + while (r.spec.id !== "hearse") through(r); + r.lives = 99; + const spots = [ROOM.start + 40, R.graves[0][0] - 10, R.lows[0][0] - 5, R.hands[0][0] - 10, R.crows[0][0] - 30, R.checks[0], R.blocks[0][0] - 20, R.blocks[0][0] + 10, R.fog[0][0] + 50, R.finish - 40]; + for (const dark of [true, false]) { + for (const x of spots) { + r.dark = dark; + r.phase = "play"; + for (const st of r.spawns) st.over = true; + r.hordeMs = Infinity; + r.monsters.length = 0; + for (const lane of [0, 1]) { + at(r, x, lane, { safe: true }); + r.runner.hands = r.runner.hands.map((h, i) => ({ ...h, state: ["mound", "warn", "up", "sink", "broken", "spent"][i % 6], t: 600 })); + r.runner.crows = r.runner.crows.map((w, i) => ({ ...w, state: ["perch", "fly", "gone", "broken"][i % 4] })); + r.runner.lit = r.runner.lit.map((_, i) => i % 3 === 0); + r.runner.sitters = [{ x: x + 30, ox: x, lane: 0, state: "sit", t: 1500 }, { x: x + 40, ox: x, lane: 1, state: "fly", t: 300 }, { x: x + 20, ox: x, lane: 1, state: "hid", t: 0 }, { x: x + 10, ox: x, lane: 0, state: "broken", t: 0 }]; + for (const air of [false, true]) { + if (air) Object.assign(r.runner, { air: true, h: 5, vy: 20 }); + if (air) Object.assign(r.you, { state: "air", vy: 20, y: r.you.y + 5 }); + r.you.ducking = !air && lane === 0; + r.runner.lamp = air ? 0 : 60; + r.runner.out = air; + r.runner.coffins = air ? 0 : 5; + r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: 0, gone: 0 }); + for (let k = 0; k < 4; k++) g.tick(16); + r.monsters.length = 0; + r.you.safeMs = 1e9; + at(r, x, lane, { safe: true }); + } + } + } + } + // A switch in progress, mid-hop. + at(r, R.gates[0][0] + 2, 0, { safe: true }); + r.input.right = true; + for (let k = 0; k < 12; k++) g.tick(16); + r.input.right = false; + assert.equal(r.spec.id, "hearse"); + // Crashes: a grave, a headstone, a wreck. + r.you.safeMs = 0; + at(r, R.graves[0][0] - 3, R.graves[0][1]); + for (let k = 0; k < 30; k++) g.tick(16); + assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too"); + const done = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + done.resize(900, 900); + done.key("action"); + done.tick(16); + const d = done.round; + through(d); + d.offer = ["graveyard"]; + d.phaseMs = 0; + ghoul.pickStage(d, 0); + while (d.spec.id !== "hearse") through(d); + d.phase = "play"; + d.runner.done = true; + d.runner.restX = R.finish + 10; + Object.assign(d.you, { x: R.finish + 20, y: 9, state: "run" }); + d.camX = R.finish - 40; + for (let k = 0; k < 10; k++) done.tick(16); + for (const won of [true, false]) { + endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) }); + d.bonusRound.over = true; + for (let k = 0; k < 10; k++) { + done.tick(16); + bonusTick(d, { tone() {}, fx: {} }); + } + d.bonusRound.over = false; + } + // The stage select goes straight into it. + const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + pick.resize(900, 900); + pick.stageSelect(); + const p = pick.round; + const at2 = ghoul.STAGES.findIndex((s) => s.id === "graveyard"); + for (let i = 0; i < at2; i++) ghoul.steerSelect(p, 1, 0); + for (let i = 0; i < 3; i++) ghoul.steerSelect(p, 0, 1); + assert.equal(p.select.room, 3); + pick.tick(16); + ghoul.takeSelect(p); + assert.equal(p.spec.id, "hearse"); + assert.equal(p.runner.lane, 0); + assert.equal(p.you.y, hz.LANE_Y[0]); + pick.tick(16); +}); + +/* ----------------------------------------------------------- the bots */ + +// A bot that drives well: it takes the road (the lanterns) unless a closed stretch is coming there, jumps 6 to 15 +// short of a grave, headstone, cross or hand, ducks under every low and every crow in flight, and holds the +// blaster. `miss` is the share of things it fails to dodge (by a hash). +const mix = (a, b) => { + let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +function goodBot(round, seed, miss = 0.04, shoot = true) { + const { you, runner: c, input: inp } = round; + inp.left = inp.right = inp.down = false; + inp.fire = shoot; + if (round.phase !== "play" || !c || c.done) { + inp.up = false; + return; + } + const ok = (x) => mix(seed, Math.round(x)) >= miss; + const look = 9 + (seed % 7); + const lane = c.lane; + const gate = R.gates.find(([a, b]) => you.x >= a && you.x <= b); + if (gate) { + const closed = (l) => R.blocks.some(([x0, , bl]) => bl === l && x0 > you.x && x0 - you.x < 150 && ok(x0)); + const want = closed(0) ? 1 : 0; + inp.left = want === 0; + inp.right = want === 1; + } + let jump = false; + const ahead = (x) => x - you.x > 6 && x - you.x < look; + for (const [x, l] of R.graves) if (l === lane && ahead(x) && ok(x)) jump = true; + for (const [x, l] of R.stones) if (l === lane && ahead(x) && ok(x)) jump = true; + R.hands.forEach(([x, l], i) => { + if (l === lane && c.hands[i].state !== "broken" && ahead(x) && ok(x)) jump = true; + }); + for (const [x0, x1, l] of R.lows) if (l === lane && you.x > x0 - 10 && you.x < x1 + 3 && ok(x0)) inp.down = true; + R.crows.forEach(([x, l], i) => { + const w = c.crows[i]; + if (l === lane && w.state === "fly" && Math.abs(w.x - you.x) < 16 && ok(x)) inp.down = true; + }); + if (jump && !inp.down && !c.air) press(round); + else inp.up = false; +} +function idleBot(round) { + const inp = round.input; + inp.left = inp.right = inp.down = false; + inp.up = false; + inp.fire = true; +} +function rideWith(seed, bot, limit = 100000) { + const round = hearseRound(seed); + const lost = []; + let t = 0; + for (; t < limit && round.phase !== "clear" && !round.over; t += 16) { + bot(round); + if (round.runner && round.runner.done && round.phase === "play") round.input.right = true; + ghoul.advance(round, 16, steady); + for (const e of round.events) if (e.type === "lose") lost.push(e.cause); + if (round.runner && !round.runner.done) { + const off = round.you.x - round.camX; + assert.ok(off > 4 && off < 70, `the hearse stays in view (${off.toFixed(1)} from the left edge at ${round.you.x.toFixed(0)})`); + } + round.events.length = 0; + } + return { round, lost, ms: t }; +} + +test("Ghoul Rush's Midnight Hearse: a bot that drives well finishes the whole road in 60 to 75 seconds, with 6 to 9 dice, a few hearts lost at most, past every checkpoint", () => { + const dice = []; + const gone = []; + for (let seed = 1; seed <= 12; seed++) { + const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed)); + const b = round.bonusRound; + assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")})`); + assert.ok(ms > 60000 && ms < 76000, `${ms} ms`); + assert.ok(b.dice >= 5 && b.dice <= ghoul.MAX_DICE, `${b.dice} dice`); + assert.equal(round.lives, 3, "never a run life"); + dice.push(b.dice); + gone.push(lost.length); + } + assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 6.5, `${dice.join(",")}`); + assert.ok(gone.every((n) => n <= 4), `${gone.join(",")}`); +}); + +test("Ghoul Rush's Midnight Hearse: a bot that misses a quarter of the things loses, one that never switches lanes is thrown by the closed stretches, and a bot that never dodges (holding fire) loses all five hearts before the first third, ends with 0 dice and the run goes on", () => { + let finished = 0; + for (let seed = 1; seed <= 6; seed++) if (rideWith(seed, (r) => goodBot(r, seed, 0.25)).round.bonusRound.won) finished++; + assert.ok(finished <= 3, `${finished} of 6 finished missing a quarter`); + for (let seed = 1; seed <= 6; seed++) { + const { round, lost } = rideWith(seed, idleBot); + const b = round.bonusRound; + assert.equal(b.won, false, "never finishes"); + assert.equal(b.dice, 0); + assert.equal(b.hearts, 0); + assert.equal(lost.length, 5); + assert.ok(round.you.x < ROOM.length * 0.4, `out at ${round.you.x}`); + assert.equal(round.lives, 3); + assert.equal(round.over, false); + } + // A driver who dodges everything but never changes lane meets the first closed stretch in the road. + const { lost } = rideWith(3, (r) => { + goodBot(r, 3, 0); + r.input.left = r.input.right = false; + }); + assert.ok(lost.includes("wreck"), "thrown by a closed stretch"); +}); + +/* ------------------------------------------------------------ telegraphs */ + +test("Ghoul Rush's Midnight Hearse telegraphs: JUMP over graves, headstones and crosses, DUCK under branches and the arch, SHOOT at hands and crows, SWITCH at the gate before a closed stretch, for the hearse's lane only, words on the first three of each kind, the same every time", () => { + const marks = telegraphMarks(R); + assert.equal(marks.length, R.graves.length + R.stones.length + R.lows.length + R.hands.length + R.crows.length + R.blocks.length); + for (const m of marks) assert.equal(m.answer, ANSWERS[m.kind], m.kind); + assert.equal(ANSWERS.grave, "JUMP"); + assert.equal(ANSWERS.branch, "DUCK"); + assert.equal(ANSWERS.arch, "DUCK"); + assert.equal(ANSWERS.crow, "SHOOT"); + assert.equal(ANSWERS.block, "SWITCH"); + // Each closed stretch's sign stands at a gate and shows to the lane that is shut. + for (const [x0, , lane] of R.blocks) { + const m = marks.find((q) => q.kind === "block" && q.lane === lane && q.lead < x0 && x0 - q.lead < 90); + assert.ok(m, `a sign for the block at ${x0}`); + assert.ok(R.gates.some(([a, b]) => b === m.lead && a < m.lead), "at a gate"); + assert.ok(telegraphs(R, m.lead - 30, lane).some((t) => t === t && t.kind === "block")); + assert.ok(!telegraphs(R, m.lead - 30, 1 - lane).some((t) => t.kind === "block"), "not for the other lane"); + } + const first = R.lows.find((l) => !l[3]); + const m = marks.find((q) => q.kind === "branch" && q.x === (first[0] + first[1]) / 2); + const lane = first[2]; + const xs = [m.lead - 45, m.lead - 41, m.lead - 36, m.lead - 30, m.lead - 10, m.lead, m.lead + 3, m.lead + 7]; + const alphaOf = (x) => (telegraphs(R, x, lane).find((t) => t.kind === "branch" && t.lead === m.lead) || { alpha: 0 }).alpha; + const a = xs.map(alphaOf); + assert.equal(a[0], 0, "not yet in view"); + assert.ok(a[2] > 0 && a[2] < 1, "fading in 40 to 30 ahead"); + assert.equal(a[3], 1); + assert.equal(a[4], 1); + assert.ok(a[6] > 0 && a[6] < 1, "fading as it passes"); + assert.equal(a[7], 0, "gone once passed"); + assert.deepEqual(telegraphs(R, m.lead - 33, lane), telegraphs(R, m.lead - 33, lane), "deterministic"); + for (const kind of ["grave", "stone", "branch", "hand", "crow"]) { + const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead); + assert.ok(of.length >= 3, kind); + of.forEach((q, i) => { + assert.equal(q.n, i); + const shown = telegraphs(R, q.lead - 32, q.lane).find((t) => t.lead === q.lead && t.kind === kind); + assert.ok(shown, `${kind} ${i} shows`); + assert.equal(shown.words, i < 3, `${kind} ${i}`); + }); + } + // In the other lane a thing shows nothing. + const g = marks.find((q) => q.kind === "grave"); + assert.ok(!telegraphs(R, g.lead - 32, 1 - g.lane).some((t) => t.lead === g.lead && t.kind === "grave")); +}); + +test("Ghoul Rush's Midnight Hearse's intro banner says the controls plainly", () => { + assert.match(R.how, /LEFT or RIGHT at a gate/); + assert.match(R.how, /UP jump, DOWN duck/); + assert.match(R.how, /SPACE shoot/); + assert.ok(R.how.length <= 72); +}); diff --git a/scripts/test-web-console-activities-ghoul-intro.mjs b/scripts/test-web-console-activities-ghoul-intro.mjs new file mode 100644 index 0000000..932ca02 --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-intro.mjs @@ -0,0 +1,226 @@ +// Web console tests, Ghoul Rush's stage intro cards: every stage has one (3 or 4 lines, short, no em dash, never the hero's name), the card shows when a stage is entered and not before the pick, any move key or fire moves it on after the minimum (repeats and early presses never do) and it never moves on by itself, and it draws on a fake canvas. +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { INTROS, MAX_LINE, introFor } from "../src/web-console/public/activities/ghoul-intros.js"; +import { INTRO_HINT, LINE_SIZE, TITLE_SIZE, dropAt, titleLayout } from "../src/web-console/public/activities/ghoul-intro-draw.js"; +import { toneNames } from "../src/web-console/public/tones.js"; + +const steady = () => 0.5; +const DASH = String.fromCharCode(0x2014); + +function fakeCtx(texts) { + return new Proxy({}, { + get: (t, name) => (name in t ? t[name] : name === "fillText" ? (s) => texts.push(s) : () => {}), + set: (t, name, value) => ((t[name] = value), true), + }); +} + +// A round at the stage pick, the offer settled. +function atPick(seed = 3) { + const r = ghoul.newRound(seed); + r.dice = 0; + r.phase = "clear"; + r.phaseMs = 1; + ghoul.advance(r, 4, steady); + ghoul.advance(r, ghoul.PICK_HOLD_MS, steady); + return r; +} + +test("Ghoul Rush intros: every stage has a card of 3 or 4 short lines, no em dash, YOU and never Planny", () => { + const field = ghoul.FIELD_W; + for (const st of ghoul.STAGES) { + const info = introFor(st.id); + assert.ok(info, `${st.id} has an intro`); + assert.ok(info.title && info.kicker && info.boss, `${st.id} has a title, a kicker and a boss`); + assert.ok(info.lines.length >= 3 && info.lines.length <= 4, `${st.id} has 3 or 4 lines`); + assert.ok(/^#[0-9a-f]{6}$/i.test(info.palette.a) && /^#[0-9a-f]{6}$/i.test(info.palette.b) && /^#[0-9a-f]{6}$/i.test(info.palette.glow), `${st.id} has a palette`); + assert.equal(info.title, st.title, `${st.id} keeps the stage's title`); + assert.equal(info.kicker, st.sub, `${st.id} keeps the stage's tagline`); + assert.equal(info.boss, ghoul.BOSSES[st.boss].name, `${st.id} names its boss`); + const text = [info.title, info.kicker, info.boss, ...info.lines].join("\n"); + assert.ok(!text.includes(DASH), `${st.id} has no em dash`); + assert.ok(!/planny|the player/i.test(text), `${st.id} never names the hero`); + assert.ok(info.lines.some((l) => l.includes("YOU")), `${st.id} speaks to YOU`); + for (const line of info.lines) { + assert.ok(line.length <= MAX_LINE, `${st.id}: "${line}" is ${line.length} characters`); + // The same width guess the field's label helper uses (0.62 em a letter). + assert.ok(line.length * LINE_SIZE * 0.62 <= field - 1, `${st.id}: "${line}" fits the field`); + } + const { size, xs } = titleLayout(info.title); + assert.ok(size > 0 && size <= TITLE_SIZE, `${st.id}'s title has a size`); + assert.ok(Math.abs(xs[0]) < field / 2 && Math.abs(xs[xs.length - 1]) < field / 2, `${st.id}'s title fits the field`); + } + assert.deepEqual(Object.keys(INTROS).sort(), ghoul.STAGES.map((st) => st.id).sort(), "no intro for a stage that does not exist"); + assert.equal(new Set(ghoul.STAGES.flatMap((st) => introFor(st.id).lines)).size, ghoul.STAGES.reduce((n, st) => n + introFor(st.id).lines.length, 0), "no line used twice"); + assert.ok(toneNames().includes("ghoulStageIntro")); +}); + +test("Ghoul Rush intros: the card shows when a stage is entered and not before the pick, and holds the room back", () => { + const r = ghoul.newRound(3); + assert.equal(r.phase, "play", "the hall has no card"); + const p = atPick(); + assert.equal(p.phase, "pick"); + assert.equal(p.events.some((e) => e.type === "intro"), false, "no card before the pick"); + const want = p.offer[p.pick]; + p.events.length = 0; + assert.equal(ghoul.pickStage(p), true); + assert.equal(p.phase, "intro"); + assert.deepEqual(p.events.filter((e) => e.type === "intro").map((e) => e.stage), [want]); + assert.equal(p.events.some((e) => e.type === "room"), false, "the room's announcement waits for the card"); + assert.equal(p.spec.id, ghoul.stageById(want).rooms[0], "the first room is set up behind it"); + // Nothing in the room moves while the card is up. + const at = p.you.x; + p.input.right = true; + ghoul.advance(p, 600, steady); + assert.equal(p.you.x, at); + assert.equal(p.phase, "intro"); +}); + +test("Ghoul Rush intros: fire, jump or a click moves on after the minimum, and nothing moves it on alone", () => { + const p = atPick(); + ghoul.pickStage(p); + assert.equal(ghoul.takeIntro(p), false, "not at once"); + ghoul.advance(p, ghoul.INTRO_MIN_MS - 50, steady); + assert.equal(ghoul.takeIntro(p), false, "not before the minimum"); + assert.equal(p.phase, "intro"); + ghoul.advance(p, 60, steady); + p.events.length = 0; + assert.equal(ghoul.takeIntro(p), true); + assert.equal(p.phase, "ready"); + assert.equal(p.phaseMs, ghoul.READY_MS); + assert.equal(p.events.filter((e) => e.type === "room").length, 1, "the room is announced now"); + ghoul.advance(p, ghoul.READY_MS + 20, steady); + assert.equal(p.phase, "play"); + // It never advances on its own: not after a minute, not after an hour. + const q = atPick(5); + ghoul.pickStage(q); + for (const ms of [15000, 60000, 3600000]) { + ghoul.advance(q, ms, steady); + assert.equal(q.phase, "intro", `still waiting after ${ms} ms more`); + } + assert.equal(ghoul.INTRO_MAX_MS, undefined, "the auto-advance timeout is gone"); + assert.ok(ghoul.INTRO_MIN_MS >= 1000 && ghoul.INTRO_MIN_MS <= 2000); + assert.equal(ghoul.takeIntro(q), true, "a press still works after any wait"); +}); + +test("Ghoul Rush intros: with the window's keys, a held fire never skips it, a fresh press does, and a pause holds it", () => { + const texts = []; + const sounds = []; + const ctx = fakeCtx(texts); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, tone: (name) => sounds.push(name) }); + g.resize(900, 900); + g.key("action"); + g.round.dice = 0; + g.round.phase = "clear"; + g.round.phaseMs = 1; + for (let ms = 0; ms < ghoul.PICK_HOLD_MS + 200; ms += 16) g.tick(16); + assert.equal(g.round.phase, "pick"); + g.key("action"); + assert.equal(g.round.phase, "intro"); + for (let k = 0; k < 5; k++) g.key("action", true); + g.key("action"); + assert.equal(g.round.phase, "intro", "too soon, and repeats never count"); + assert.equal(g.round.input.fire, false, "no shot fired at the card"); + g.tick(16); + assert.ok(sounds.includes("ghoulStageIntro"), "the stinger plays when the card opens"); + const title = introFor(g.round.stage).title; + // The card is on screen, paused too. + for (let ms = 0; ms < 3000; ms += 16) g.tick(16); + texts.length = 0; + g.tick(16); + assert.ok(texts.includes(INTRO_HINT), "the hint shows"); + assert.match(INTRO_HINT, /any move key or fire/); + assert.ok(title.split("").every((ch) => ch === " " || texts.includes(ch)), "every letter of the title is drawn"); + const line = introFor(g.round.stage).lines[0]; + assert.ok(texts.includes(line), "the flavor text is drawn"); + g.pause(); + const held = g.round.introMs; + for (let k = 0; k < 20; k++) g.tick(16); + assert.equal(g.round.introMs, held, "a pause holds the card"); + g.resume(); + g.key("up"); + assert.equal(g.round.phase, "ready", "jump moves on too"); + // Each of the other keys, and fire, moves a card on once the lockout has passed; a repeat or an early press never does. + for (const name of ["left", "right", "up", "down", "action"]) { + const k = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + k.resize(900, 900); + k.key("action"); + k.round.dice = 0; + k.round.phase = "clear"; + k.round.phaseMs = 1; + for (let ms = 0; ms < ghoul.PICK_HOLD_MS + 200; ms += 16) k.tick(16); + k.key("action"); + assert.equal(k.round.phase, "intro", name); + k.key(name); + assert.equal(k.round.phase, "intro", `${name}: an early press is ignored`); + for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 100; ms += 16) k.tick(16); + k.key(name, true); + assert.equal(k.round.phase, "intro", `${name}: a repeat is ignored`); + k.release(name); + k.key(name); + assert.equal(k.round.phase, "ready", `${name}: a fresh press moves on`); + assert.equal(k.round.input.fire, false, "no shot fired at the card"); + } + // A click works as well. + const h = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + h.resize(900, 900); + h.key("action"); + h.round.dice = 0; + h.round.phase = "clear"; + h.round.phaseMs = 1; + for (let ms = 0; ms < ghoul.PICK_HOLD_MS + 200; ms += 16) h.tick(16); + h.key("action"); + for (let ms = 0; ms < 1300; ms += 16) h.tick(16); + h.pointer("down", 10, 10); + assert.equal(h.round.phase, "ready", "a click moves on"); +}); + +test("Ghoul Rush intros: the stage select shows the card on a stage's first room only", () => { + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => fakeCtx([]) } }); + g.resize(900, 900); + g.key("action"); + const r = g.round; + r.phase = "select"; + r.select = { at: 3, room: 0 }; + r.practice = true; + g.key("action"); + assert.equal(r.phase, "intro", "the first room opens on the card"); + assert.equal(r.stage, ghoul.STAGES[3].id); + const s = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => fakeCtx([]) } }); + s.resize(900, 900); + s.key("action"); + s.round.phase = "select"; + s.round.select = { at: 3, room: 2 }; + s.round.practice = true; + s.key("action"); + assert.equal(s.round.phase, "ready", "a room mid-stage has no card"); +}); + +test("Ghoul Rush intros: every card draws on a fake canvas at every moment without throwing", () => { + for (const st of ghoul.STAGES) { + const texts = []; + const ctx = fakeCtx(texts); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + g.resize(900, 900); + g.key("action"); + g.round.phase = "select"; + g.round.select = { at: ghoul.STAGES.indexOf(st), room: 0 }; + g.key("action"); + assert.equal(g.round.phase, "intro", st.id); + for (let ms = 0; ms < 5000; ms += 80) { + g.round.introMs = ms; + g.tick(1); + } + assert.ok(texts.includes(`BOSS: ${introFor(st.id).boss.toUpperCase()}`), `${st.id} names its boss`); + } +}); + +test("Ghoul Rush intros: the title's letters fall once and bounce", () => { + assert.equal(dropAt(-1), 1); + assert.equal(dropAt(10000), 0); + assert.ok(dropAt(100) < 1 && dropAt(100) > 0.5); + let peak = 0; + for (let t = 330; t < 520; t += 10) peak = Math.max(peak, dropAt(t)); + assert.ok(peak > 0 && peak < 0.2, "one small bounce"); +}); diff --git a/scripts/test-web-console-activities-ghoul-mine.mjs b/scripts/test-web-console-activities-ghoul-mine.mjs index 766c10b..039f38c 100644 --- a/scripts/test-web-console-activities-ghoul-mine.mjs +++ b/scripts/test-web-console-activities-ghoul-mine.mjs @@ -135,7 +135,7 @@ test("Ghoul Rush's Deep Seam Mine is a stage of three rooms and the Seam, always assert.equal(st.boss, "tommy"); assert.equal(st.title, "The Deep Seam Mine"); assert.equal(st.sub, "They are still knocking"); - assert.equal(ghoul.STAGES.at(-3), st, "the last stage in the list but the Carnival and the Frozen Lake"); + assert.equal(ghoul.STAGES.at(-4), st, "the last stage in the list but the Carnival, the Frozen Lake and Gallows Bog"); for (const kind of Object.keys(mn.MONSTERS)) assert.equal(ghoul.MONSTERS[kind], mn.MONSTERS[kind], `${kind} is a monster`); assert.equal(ghoul.BOSSES.tommy, mn.BOSSES.tommy); assert.equal(mn.BOSSES.tommy.sub, "Follow the knocking, not the light"); @@ -1556,7 +1556,7 @@ test("Ghoul Rush's stage select lists the Mine and takes you straight into each const r = g.round; assert.equal(r.phase, "select"); const at = ghoul.STAGES.findIndex((s) => s.id === "mine"); - assert.equal(at, ghoul.STAGES.length - 3); + assert.equal(at, ghoul.STAGES.length - 4); for (let i = 0; i < at; i++) ghoul.steerSelect(r, 1, 0); for (let i = 0; i < 4; i++) ghoul.steerSelect(r, 0, 1); assert.equal(r.select.at, at); diff --git a/scripts/test-web-console-activities-ghoul-mower.mjs b/scripts/test-web-console-activities-ghoul-mower.mjs new file mode 100644 index 0000000..518df4f --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-mower.mjs @@ -0,0 +1,945 @@ +// Web console tests, Ghoul Rush's Gardener's Revenge (the Grounds' bonus round, between the Gazebo and the Groundskeeper's Yard): its shape (every pond and ditch clears with a jump and swallows a mower that does not jump, every low can be ducked), the mower's motion, each obstacle's cost and cause, the blades (cutting, the heat, the jam, the lawn cut), the topiary beasts, the hearts, the checkpoints, the finish and the dice, endless lives, the art on a fake canvas, and the two bots (one that plays well finishes in time, one that never dodges loses). +// Run with: node --test scripts/test-web-console-activities-ghoul-mower.mjs +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { skipBossIntro } from "./ghoul-test-helpers.mjs"; +import * as mw from "../src/web-console/public/activities/ghoul-mower.js"; +import * as ct from "../src/web-console/public/activities/ghoul-cart.js"; +import { ANSWERS, EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as MOWER_LOOKS, VOICES as MOWER_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-mower-draw.js"; +import { MOWER_SFX } from "../src/web-console/public/activities/ghoul-sfx-mower.js"; +import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js"; +import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-draw.js"; +import { BONUS_FLOOR, diceFor, endBonus } from "../src/web-console/public/activities/ghoul-bonus.js"; + +const steady = () => 0.5; +// The pack draws no random number: a run on this fails on the first draw. +const never = () => { + throw new Error("the mower drew a random number"); +}; +const events = (round, type) => round.events.filter((e) => e.type === type); + +function through(round) { + round.phase = "clear"; + round.phaseMs = 1; + ghoul.advance(round, 4, steady); +} + +// A round in the Gardener's Revenge reached the way play reaches it, nothing woken, the clocks long, +// the bonus round on (five hearts). +function mowerRound(seed = 5) { + const round = ghoul.newRound(seed); + round.lives = 3; + round.dice = 0; + through(round); + round.offer = ["grounds"]; + round.phaseMs = 0; + ghoul.pickStage(round, 0); + while (round.spec.id !== "mower") through(round); + round.phase = "play"; + for (const st of round.spawns) st.over = true; + round.monsters.length = 0; + round.hordeMs = Infinity; + round.timeMs = 1e9; + round.bonus = 1e9; + round.events.length = 0; + return round; +} + +const NONE = { runner: "mower", time: 1e9, finish: 1e6, track: [], gaps: [], junk: [], lows: [], hedges: [], beasts: [], grass: [], weeds: [], checks: [] }; +// The same round over a ride of its own (a plain lawn to measure the mower on). +function synth(ride) { + const round = mowerRound(); + round.spec = { ...round.spec, start: 10, ground: [[0, 5, 0]], ride: { ...NONE, ...ride } }; + round.runner = null; + mw.MOWER.place[0](round, {}); + return round; +} +const FLAT = [[[0, 20], [4000, 20]]]; + +// The mower on line `line` of the ride at `x`, at speed `v`. +function mowerAt(round, x, line, { v = mw.MOWER_V, safe = false } = {}) { + const y = ct.trackY(round.spec.ride, line, x); + assert.ok(y !== null, `line ${line} runs under ${x}`); + Object.assign(round.you, { x, y, vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false }); + Object.assign(round.runner, { line, v, coyote: 0 }); + round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24)); +} + +function run(round, ms, keys = {}, random = steady) { + Object.assign(round.input, keys); + for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random); + for (const k of Object.keys(keys)) round.input[k] = typeof keys[k] === "number" ? 0 : false; +} + +function until(round, done, ms = 6000, random = steady) { + let t = 0; + for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random); + return t; +} + +const press = (round) => { + round.input.jump = ghoul.JUMP_BUFFER_MS; + round.input.up = true; +}; + +const heard = (e, extra = {}) => { + const played = []; + const noop = () => {}; + const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra }; + react({ x: 10, y: 6, tx: 20, ty: 6, ...e }, kit); + return { played }; +}; + +const ROOM = ghoul.roomById("mower"); +const R = ROOM.ride; +const lines = ct.linesOf(R); +const floorOf = (x) => ghoul.groundAt(ROOM, x); +const LANE = R.track[0][0][1]; + +/* -------------------------------------------------------------- the room */ + +test("Ghoul Rush's Gardener's Revenge is the Grounds' fourth room, between the Gazebo and the Groundskeeper's Yard: lit, no key, no boss, a ride about 60 to 70 seconds long, a bonus round that plays its own track", () => { + const st = ghoul.stageById("grounds"); + assert.deepEqual(st.rooms, ["maze", "topiary", "gazebo", "mower", "yard"]); + assert.equal(st.boss, "keeper"); + assert.deepEqual([ROOM.title, ROOM.sub], ["The Gardener's Revenge", "The lawn has not been mowed since 1893"]); + assert.equal(ROOM.dark, false); + assert.equal(ROOM.key, null); + assert.equal(ROOM.boss, null); + assert.equal(ROOM.bonus, true); + assert.equal(R.runner, "mower", "the shared ride slot, which the cart's place leaves alone"); + assert.ok(ROOM.length >= 1800 && ROOM.length <= 3000, `${ROOM.length} units long`); + assert.equal(ghoul.ROOM_MUSIC.mower, "ghoulMowerRide"); + assert.ok(ghoulSfx.default.music.ghoulMowerRide, "its own track"); + assert.deepEqual(Object.keys(mw.MOWER.monsters), [], "no new monster kinds"); + assert.equal(LOOKS.mower, MOWER_LOOKS.mower); + assert.equal(LOOKS.mower.pack, "mower"); + assert.ok(Object.isFrozen(R) && Object.isFrozen(R.track) && Object.isFrozen(R.track[0][0]), "frozen all the way down"); + assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0, "no monsters: the things on the lawn are the pack's own"); + assert.equal(ROOM.ground.length, 2); + assert.equal(ROOM.ground[1][0], R.finish, "the lawn's end begins at the finish"); + assert.ok(ROOM.door > R.finish && ROOM.door > ROOM.length - 14); + assert.ok(floorOf(ROOM.door - 2) > -Infinity, "floor to walk out on"); + assert.equal(ct.trackY(R, 0, ROOM.start), floorOf(ROOM.start), "the mower starts on the lawn"); + assert.equal(floorOf(R.finish + 1), LANE, "the lawn's end is level with the lawn"); + // Every line is flat at one height, running left to right. + for (const L of lines) for (const [x, y] of L.pts) assert.equal(y, LANE, `a flat lawn at ${x}`); + const secs = (lines.at(-1).x1 - ROOM.start) / mw.MOWER_V; + assert.ok(secs >= 58 && secs <= 72, `${secs.toFixed(1)} s at MOWER_V`); + assert.equal(ghoul.timeFor(ghoul.roomFor("mower")), R.time); + assert.ok(R.time >= 1.5 * secs * 1000 && R.time <= 120000, `a ${R.time} ms clock for a ${secs.toFixed(0)} s ride`); + assert.equal(lines.at(-1).x1, R.finish); + assert.match(R.how, /UP to jump, DOWN to duck, hold space to shoot and mow/); +}); + +test("Ghoul Rush's Gardener's Revenge: every pond and ditch clears with a jump at the edge or a few units early, and a mower that never jumps drops into it", () => { + assert.equal(R.gaps.length, lines.length - 1); + assert.ok(R.gaps.includes(0) && R.gaps.includes(1), "ponds and ditches both"); + for (let i = 0; i + 1 < lines.length; i++) { + const a = lines[i]; + const b = lines[i + 1]; + const gap = b.x0 - a.x1; + assert.ok(gap >= 7 && gap <= 12, `gap ${i} is ${gap} wide`); + for (const v of [mw.MOWER_V - mw.BOG, mw.MOWER_V]) { + assert.equal(mw.flight(R, a.x1, LANE, 0, v), null, `gap ${i}, no jump, at ${v}`); + for (const early of v === mw.MOWER_V ? [0, 4, 8] : [0, 4]) { + const x = a.x1 - early; + const s = mw.flight(R, x, LANE, mw.MOWER_JUMP_V, v); + assert.ok(s, `gap ${i}: a jump ${early} early at ${v} lands`); + assert.equal(s.line, i + 1, `gap ${i} cleared, at ${v}, ${early} early`); + } + } + } +}); + +test("Ghoul Rush's Gardener's Revenge: every thing is on the lawn, off the ends and off the gaps, spaced for a player (30 between jumps and 38 between a jump and a duck), a low's underside between a ducked box and a standing one", () => { + const onLawn = (x) => lines.some((L) => x > L.x0 + 3 && x < L.x1 - 3); + const hits = []; + for (const [x] of R.junk) hits.push({ x, kind: "jump" }); + for (const x of R.hedges) hits.push({ x, kind: "jump" }); + for (const x of R.beasts) hits.push({ x, kind: "jump" }); + for (let i = 0; i + 1 < lines.length; i++) hits.push({ x: lines[i].x1, kind: "jump" }); + for (const [x0, x1, y, kind] of R.lows) { + assert.ok(kind === 0 || kind === 1); + assert.equal(y, LANE + 3, "a low's underside 3.0 over the lawn"); + assert.ok(y > LANE + ghoul.DUCK_H && y < LANE + ghoul.HIT_H, "between a ducked box and a standing one"); + assert.ok(x0 < x1); + hits.push({ x: x0, x1, kind: "duck" }); + } + for (const h of hits) if (h.kind === "jump" && h.x < lines.at(-1).x1) assert.ok(h.x > ROOM.start + 30, `${h.x} is past the start`); + for (const [x] of R.junk) assert.ok(onLawn(x), `junk at ${x}`); + for (const x of [...R.hedges, ...R.beasts]) assert.ok(onLawn(x), `a hedge or beast at ${x}`); + hits.sort((p, q) => p.x - q.x); + for (let i = 0; i + 1 < hits.length; i++) { + const a = hits[i]; + const b = hits[i + 1]; + const need = a.kind === "jump" && b.kind === "jump" ? 30 : a.kind === "duck" && b.kind === "duck" ? 20 : a.kind === "jump" ? 38 : 24; + const gap = b.x - (a.x1 ?? a.x); + assert.ok(gap >= need, `${a.kind} at ${a.x} then ${b.kind} at ${b.x}: ${gap} between (${need} wanted)`); + } + // Counts: the room's graded obstacles and the mow targets. + assert.equal(R.junk.length + R.lows.length + R.hedges.length + R.beasts.length + R.gaps.length, 36); + assert.equal(R.checks.length, 5); + for (const x of R.checks) assert.ok(onLawn(x), `checkpoint ${x}`); + for (const [x0, x1] of R.grass) assert.ok(x1 > x0 && x0 >= 0 && x1 <= R.finish); + assert.ok(mw.totalCells(R) > 600, `${mw.totalCells(R)} cells`); + // Candy and items are on the lawn. + assert.ok(ROOM.candy.length > 50); + for (const [x, y] of ROOM.candy) assert.ok(y > LANE, `candy ${x} over the lawn`); +}); + +/* ------------------------------------------------------------ the mower */ + +test("Ghoul Rush's Gardener's Revenge rolls at MOWER_V, no key changes it, and it bogs down a little after a cut", () => { + const flat = synth({ track: FLAT }); + assert.equal(flat.runner.v, mw.MOWER_V); + assert.equal(flat.runner.id, "mower"); + run(flat, 2000); + assert.ok(Math.abs(flat.runner.v - mw.MOWER_V) < 0.01); + run(flat, 1500, { right: true }); + run(flat, 1500, { left: true }); + assert.ok(Math.abs(flat.runner.v - mw.MOWER_V) < 0.01, "right and left do nothing"); + assert.ok(Math.abs(flat.you.x - (10 + (2000 + 1500 + 1500) / 1000 * mw.MOWER_V)) < 1, "rides on at MOWER_V"); + assert.equal(flat.you.face, 1); + assert.equal(flat.you.state, "run"); + assert.equal(flat.you.y, 20); + const grass = synth({ track: FLAT, grass: [[40, 80]] }); + grass.input.fire = true; + let low = mw.MOWER_V; + until(grass, () => (low = Math.min(low, grass.runner.v)) < 0 || grass.you.x > 90, 4000); + assert.ok(low < mw.MOWER_V - 2 && low >= mw.MOWER_V - mw.BOG - 0.01, `${low} while cutting`); +}); + +test("Ghoul Rush's Gardener's Revenge jumps about 11 high for about 0.7 s (22 across), a press saved for a landing jumps on it, one just after a line's end still jumps", () => { + const round = synth({ track: FLAT }); + let top = 0; + press(round); + const t = until(round, () => { + top = Math.max(top, round.you.y - 20); + return round.you.state === "run" && round.you.y === 20 && round.you.vy === 0 && top > 1; + }, 3000); + assert.ok(Math.abs(top - (mw.MOWER_JUMP_V * mw.MOWER_JUMP_V) / (2 * mw.MOWER_G)) < 0.4, `${top.toFixed(1)} high`); + assert.ok(t > 600 && t < 800, `${t} ms in the air`); + assert.equal(events(round, "mowerJump").length, 1); + assert.equal(events(round, "mowerLand").length, 1); + const across = round.you.x - 10; + assert.ok(across > 20 && across < 25, `${across.toFixed(1)} across`); + const buf = synth({ track: FLAT }); + press(buf); + run(buf, 600); + press(buf); + until(buf, () => events(buf, "mowerJump").length >= 2, 1500); + assert.equal(events(buf, "mowerJump").length, 2, "the saved press jumped again at the landing"); + const edge = synth({ track: [[[0, 20], [60, 20]], [[100, 20], [300, 20]]] }); + mowerAt(edge, 58.5, 0); + run(edge, 60); + assert.equal(edge.runner.line, -1, "off the end"); + press(edge); + run(edge, 4); + assert.equal(events(edge, "mowerJump").length, 1, "coyote"); + const late = synth({ track: [[[0, 20], [60, 20]], [[100, 20], [300, 20]]] }); + mowerAt(late, 58.5, 0); + run(late, 60 + mw.COYOTE_MS); + press(late); + run(late, 4); + assert.equal(events(late, "mowerJump").length, 0); +}); + +test("Ghoul Rush's Gardener's Revenge: down ducks (and a press of up jumps instead of ducking), a ducked Planny passes under a hedge arch or a line of gloves and a standing one hits it (causes arch and line), at the cost of a heart", () => { + const round = synth({ track: FLAT, lows: [[60, 66, 23, 0]] }); + const you = round.you; + assert.equal(you.ducking, false); + run(round, 20, { down: true }); + assert.equal(events(round, "mowerDuck").length, 1); + round.input.down = true; + until(round, () => you.x > 75, 3000); + round.input.down = false; + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.lives, 3); + for (const [kind, cause] of [[0, "arch"], [1, "line"]]) { + const hit = synth({ track: FLAT, lows: [[60, 66, 23, kind]] }); + until(hit, () => hit.bonusRound.hearts < 5, 3000); + assert.equal(hit.bonusRound.hearts, 4, `${cause} costs a heart`); + assert.equal(events(hit, "lose")[0].cause, cause); + assert.equal(hit.lives, 3); + assert.ok(hit.you.safeMs > 0, "Planny blinks safe"); + assert.deepEqual(hit.bonusRound.perf.hits, ["l0"]); + run(hit, 800); + assert.equal(hit.bonusRound.hearts, 4, "the safe moment spares the rest of it"); + assert.equal(hit.runner.done, false, "the mower rolls on"); + } + const jump = synth({ track: FLAT, lows: [[60, 66, 23, 0]] }); + mowerAt(jump, 52, 0); + press(jump); + run(jump, 8); + assert.equal(jump.you.ducking, false); + assert.equal(events(jump, "mowerJump").length, 1); +}); + +test("Ghoul Rush's Gardener's Revenge: a gnome, a wheelbarrow and a flowerpot are cleared by a jump and cost a heart otherwise (causes gnome, barrow and pot), each only once", () => { + for (const [kind, cause] of [[0, "gnome"], [1, "barrow"], [2, "pot"]]) { + const hit = synth({ track: FLAT, junk: [[60, kind]] }); + until(hit, () => hit.bonusRound.hearts < 5, 3000); + assert.equal(hit.bonusRound.hearts, 4, `${cause} costs a heart`); + assert.equal(events(hit, "lose")[0].cause, cause); + assert.equal(events(hit, "mowerCrash")[0].what, cause); + assert.deepEqual(hit.bonusRound.perf.hits, ["j0"]); + run(hit, 500); + assert.equal(hit.bonusRound.hearts, 4); + for (const from of [60 - 16, 60 - 12, 60 - 9, 60 - 6]) { + const clear = synth({ track: FLAT, junk: [[60, kind]] }); + mowerAt(clear, from, 0); + press(clear); + until(clear, () => clear.you.x > 80, 3000); + assert.equal(clear.bonusRound.hearts, 5, `${cause} jumped from ${from}`); + } + } + assert.equal(mw.JUNK.length, 3); +}); + +test("Ghoul Rush's Gardener's Revenge: a pond or a ditch with no jump is a heart (causes pond and ditch), the mower goes back on the lawn ahead at MOWER_V and rolls on; a jump over it costs nothing", () => { + for (const [kind, cause] of [[0, "pond"], [1, "ditch"]]) { + const gap = synth({ track: [[[0, 20], [60, 20]], [[72, 20], [400, 20]]], gaps: [kind] }); + mowerAt(gap, 30, 0); + until(gap, () => events(gap, "lose").length > 0, 3000); + assert.equal(events(gap, "lose")[0].cause, cause); + assert.equal(events(gap, "mowerCrash")[0].what, cause); + assert.equal(gap.bonusRound.hearts, 4); + assert.deepEqual(gap.bonusRound.perf.hits, ["g0"]); + assert.equal(gap.runner.line, 1, "back on the next lawn"); + assert.equal(gap.you.y, 20); + assert.equal(gap.runner.v, mw.MOWER_V); + run(gap, 600); + assert.equal(gap.bonusRound.hearts, 4); + const over = synth({ track: [[[0, 20], [60, 20]], [[72, 20], [400, 20]]], gaps: [kind] }); + mowerAt(over, 56, 0); + press(over); + until(over, () => over.you.x > 100, 3000); + assert.equal(over.bonusRound.hearts, 5, `${cause} jumped`); + } +}); + +/* ------------------------------------------------------------- the blades */ + +test("Ghoul Rush's Gardener's Revenge: holding fire lowers the blades, which cut every grass cell within BLADE_REACH ahead (GRASS_POINTS each) and nothing behind or out of reach; let go, nothing is cut", () => { + const dry = synth({ track: FLAT, grass: [[30, 60]] }); + run(dry, 1500); + assert.equal(dry.runner.cut, 0, "no fire, no cut"); + assert.equal(dry.runner.blade, false); + const round = synth({ track: FLAT, grass: [[40, 70]] }); + mowerAt(round, 29, 0); + const score = round.score; + round.input.fire = true; + run(round, 24); + assert.equal(round.runner.blade, true); + assert.equal(round.runner.cut, 0, "nothing in reach yet"); + until(round, () => round.runner.cut > 0, 1000); + const cells = round.runner.cut; + assert.ok(cells >= 1); + const row = round.runner.grass[0]; + assert.ok(row[0] && !row[mw.BLADE_REACH + 3], "the nearest cells first, none beyond the zone"); + assert.ok(round.you.x + mw.BLADE_REACH >= 40); + assert.equal(round.score - score >= cells * mw.GRASS_POINTS, true); + const ev = events(round, "mowerGrass"); + assert.ok(ev.length >= 1 && ev[0].points === ev[0].n * mw.GRASS_POINTS); + until(round, () => round.you.x > 62, 2000); + assert.equal(round.runner.cut, 30, "the whole strip, 30 cells"); + assert.equal(round.runner.cells, 30); + assert.ok(Math.abs(round.runner.lawn - 1) < 1e-9); +}); + +test("Ghoul Rush's Gardener's Revenge: a thorn hedge is cut by the blades (HEDGE_POINTS, an act) before it can hurt, or jumped; uncut it costs a heart (cause thorns); a weed patch is cut for WEED_POINTS and counts WEED_CELLS", () => { + const cut = synth({ track: FLAT, hedges: [80] }); + mowerAt(cut, 60, 0); + cut.input.fire = true; + const score = cut.score; + until(cut, () => cut.you.x > 95, 3000); + assert.equal(cut.bonusRound.hearts, 5, "cut, not hit"); + assert.equal(cut.runner.hedges[0], true); + assert.equal(events(cut, "mowerHedge").length, 1); + assert.ok(cut.score - score >= mw.HEDGE_POINTS, "the points (and any souls on the way)"); + assert.equal(events(cut, "mowerHedge")[0].points, mw.HEDGE_POINTS); + assert.equal(cut.bonusRound.perf.acts, 1); + const hit = synth({ track: FLAT, hedges: [80] }); + until(hit, () => hit.bonusRound.hearts < 5, 4000); + assert.equal(hit.bonusRound.hearts, 4); + assert.equal(events(hit, "lose")[0].cause, "thorns"); + assert.deepEqual(hit.bonusRound.perf.hits, ["h0"]); + for (const from of [80 - 16, 80 - 10, 80 - 6]) { + const jump = synth({ track: FLAT, hedges: [80] }); + mowerAt(jump, from, 0); + press(jump); + until(jump, () => jump.you.x > 100, 3000); + assert.equal(jump.bonusRound.hearts, 5, `jumped from ${from}`); + assert.equal(jump.runner.hedges[0], false, "left standing"); + } + const weeds = synth({ track: FLAT, weeds: [60, 90], grass: [[120, 130]] }); + assert.equal(weeds.runner.cells, 2 * mw.WEED_CELLS + 10); + mowerAt(weeds, 40, 0); + weeds.input.fire = true; + const s0 = weeds.score; + until(weeds, () => weeds.you.x > 100, 4000); + assert.deepEqual(weeds.runner.weeds, [true, true]); + assert.ok(weeds.score - s0 >= 2 * mw.WEED_POINTS); + assert.equal(weeds.bonusRound.perf.acts, 2); + assert.equal(weeds.runner.cut, 2 * mw.WEED_CELLS); + assert.equal(events(weeds, "mowerWeed").length, 2); +}); + +test("Ghoul Rush's Gardener's Revenge: the blades heat while fire is held (HEAT_UP a second), cool when let go (COOL), and at full heat jam for JAM_MS, cutting nothing, then restart at JAM_RESUME", () => { + const round = synth({ track: FLAT }); + round.input.fire = true; + run(round, 1000); + assert.ok(Math.abs(round.runner.heat - mw.HEAT_UP) < 0.02, `${round.runner.heat} after a second`); + round.input.fire = false; + run(round, 500); + assert.ok(Math.abs(round.runner.heat - (mw.HEAT_UP - mw.COOL * 0.5)) < 0.03, `${round.runner.heat} after cooling`); + run(round, 2000); + assert.equal(round.runner.heat, 0); + // Held to the end: a jam. + const jam = synth({ track: FLAT, grass: [[40, 900]], hedges: [] }); + jam.input.fire = true; + const t = until(jam, () => jam.runner.jam > 0, 4000); + assert.ok(Math.abs(t - 1000 / mw.HEAT_UP) < 60, `jammed after ${t} ms`); + assert.equal(events(jam, "mowerJam").length, 1); + assert.equal(jam.runner.blade, false); + const cut = jam.runner.cut; + run(jam, mw.JAM_MS / 2); + assert.equal(jam.runner.cut, cut, "nothing is cut while jammed, though fire is held"); + assert.ok(jam.runner.heat < 1 && jam.runner.heat > mw.JAM_RESUME); + until(jam, () => jam.runner.jam === 0, 2000); + assert.ok(Math.abs(jam.runner.heat - mw.JAM_RESUME) < 0.02 || jam.runner.heat > mw.JAM_RESUME); + run(jam, 100); + assert.equal(jam.runner.blade, true, "the blades come down again"); + assert.ok(jam.runner.cut > cut); + // A thorn hedge met while jammed is not cut. + const hedge = synth({ track: FLAT, hedges: [100] }); + hedge.runner.jam = 5000; + hedge.input.fire = true; + until(hedge, () => hedge.bonusRound.hearts < 5 || hedge.you.x > 120, 5000); + assert.equal(events(hedge, "lose")[0].cause, "thorns"); +}); + +test("Ghoul Rush's Gardener's Revenge: the lawn cut is the grade's steady die (LAWN_GOAL), the cut stays cut after a restart, and ACTS_GOAL cuts and shots are the acts die", () => { + const round = synth({ track: FLAT, grass: [[40, 80]] }); + mowerAt(round, 28, 0); + const b = round.bonusRound; + assert.equal(b.perf.steady, false); + assert.equal(b.perf.goal, mw.ACTS_GOAL); + round.input.fire = true; + until(round, () => round.runner.lawn >= mw.LAWN_GOAL - 0.0001 && round.runner.lawn < 1, 3000); + assert.equal(b.perf.steady, true, "60% is the die"); + // Below the goal, no die. + const low = synth({ track: FLAT, grass: [[40, 80]] }); + mowerAt(low, 28, 0); + low.input.fire = true; + until(low, () => low.runner.lawn > 0.4, 3000); + low.input.fire = false; + run(low, 200); + assert.ok(low.runner.lawn < mw.LAWN_GOAL); + assert.equal(low.bonusRound.perf.steady, false); + // The lawn cut survives the same room's restart. + const cutBefore = round.runner.grass[0].slice(); + mw.MOWER.place[0](round, {}); + assert.deepEqual(round.runner.grass[0], cutBefore); + assert.equal(round.runner.cut, cutBefore.filter(Boolean).length); + // The dice formula with and without the die. + const make = (steadyDie, acts) => ({ hearts: 5, max: 5, perf: { total: 36, hits: [], acts, goal: mw.ACTS_GOAL, steady: steadyDie, kills0: 0 } }); + assert.equal(diceFor(make(true, mw.ACTS_GOAL)), 9); + assert.equal(diceFor(make(false, mw.ACTS_GOAL)), 8); + assert.equal(diceFor(make(true, 0)), 8); + assert.equal(diceFor(make(false, 0)), 7); + const bad = make(false, 0); + bad.hearts = 1; + bad.perf.hits = Array.from({ length: 36 }, (_, i) => `x${i}`); + assert.equal(diceFor(bad), BONUS_FLOOR); +}); + +/* -------------------------------------------------------- topiary beasts */ + +test("Ghoul Rush's Gardener's Revenge: a topiary beast shivers when the mower is BEAST_NEAR short, lunges into the lane for BEAST_UP_MS, snaps (cause snap) if you meet it, and a jump clears it", () => { + const round = synth({ track: FLAT, beasts: [120] }); + const b = round.runner.beasts[0]; + assert.equal(b.state, "idle"); + until(round, () => b.state === "warn", 3000); + assert.ok(Math.abs(120 - round.you.x - mw.BEAST_NEAR) < 2, `woke ${120 - round.you.x} short`); + assert.equal(events(round, "mowerBeastWarn").length, 1); + until(round, () => b.state === "snap", 1000); + assert.equal(events(round, "mowerBeastSnap").length, 1); + until(round, () => round.bonusRound.hearts < 5, 3000); + assert.equal(round.bonusRound.hearts, 4); + assert.equal(events(round, "lose")[0].cause, "snap"); + assert.equal(events(round, "mowerCrash")[0].what, "snap"); + assert.deepEqual(round.bonusRound.perf.hits, ["b0"]); + for (const from of [120 - 16, 120 - 10, 120 - 6]) { + const jump = synth({ track: FLAT, beasts: [120] }); + mowerAt(jump, from, 0); + jump.runner.beasts[0].state = "snap"; + jump.runner.beasts[0].t = mw.BEAST_UP_MS; + press(jump); + until(jump, () => jump.you.x > 140, 3000); + assert.equal(jump.bonusRound.hearts, 5, `jumped from ${from}`); + } + // It goes back to being a bush if it is not met. + const away = synth({ track: FLAT, beasts: [120] }); + mowerAt(away, 100, 0, { safe: true }); + until(away, () => away.runner.beasts[0].state === "spent", 6000); + assert.equal(away.runner.beasts[0].state, "spent"); +}); + +test("Ghoul Rush's Gardener's Revenge: BEAST_HP bolts break a lunging beast (150 points, an act, mowerBeastHit then mowerBeastBreak); a sleeping one is not hit, and what was shot stays shot after a restart", () => { + const round = synth({ track: FLAT, beasts: [120] }); + const b = round.runner.beasts[0]; + const shoot = () => { + const y = 20 + 2.4; + round.shots.push({ x: 119, y, vx: 130, vy: 0, gone: 0 }); + run(round, 12); + }; + shoot(); + assert.equal(b.hp, mw.BEAST_HP, "a sleeping beast takes no bolt"); + b.state = "snap"; + b.t = mw.BEAST_UP_MS; + round.you.safeMs = 1e9; + const score = round.score; + shoot(); + assert.equal(b.hp, mw.BEAST_HP - 1); + assert.equal(events(round, "mowerBeastHit").length, 1); + assert.equal(b.state, "snap"); + shoot(); + assert.equal(b.state, "broken"); + assert.equal(events(round, "mowerBeastBreak").length, 1); + assert.equal(round.score - score, mw.BEAST_POINTS); + assert.equal(round.bonusRound.perf.acts, 1); + mw.MOWER.place[0](round, {}); + assert.equal(round.runner.beasts[0].state, "broken"); +}); + +/* ------------------------------------------------------------ the rounds */ + +test("Ghoul Rush's Gardener's Revenge: the last heart gone ends the round with nothing at once (no life lost, the dice in hand kept) and the run goes on to the Groundskeeper's Yard", () => { + const round = mowerRound(); + round.dice = 2; + round.bonusRound.hearts = 1; + mowerAt(round, lines[0].x1 - 6, 0); + round.you.safeMs = 0; + until(round, () => round.phase === "clear", 6000); + assert.equal(round.bonusRound.hearts, 0); + assert.equal(round.bonusRound.over, true); + assert.equal(round.bonusRound.won, false); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, false); + assert.equal(end[0].dice, 0); + assert.equal(round.over, false, "no game over"); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + run(round, ghoul.CARD_LOST_MS + 100); + assert.equal(round.spec.id, "yard"); + assert.equal(round.bonusRound, null); + assert.equal(round.runner, null, "the slot is empty in any other room"); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + assert.equal(round.phase, "bossintro", "the boss room opens on its card"); + skipBossIntro(ghoul, round); + assert.equal(round.phase, "ready"); +}); + +test("Ghoul Rush's Gardener's Revenge: the checkpoints are passed in order (an event each) and the ride goes back to the last one after a restart", () => { + const round = mowerRound(); + round.you.safeMs = 1e9; + mowerAt(round, R.checks[0] - 3, lines.findIndex((L) => L.x1 > R.checks[0] - 3 && L.x0 < R.checks[0] - 3), { safe: true }); + until(round, () => round.runner.check >= 0, 1000); + assert.equal(round.runner.check, 0); + const ev = events(round, "mowerCheck"); + assert.equal(ev.length, 1); + assert.equal(ev[0].n, 1); + round.you.x = R.checks[2] + 1; + round.you.y = LANE; + round.runner.line = lines.findIndex((L) => L.x1 > R.checks[2] + 1 && L.x0 < R.checks[2] + 1); + until(round, () => round.runner.check >= 2, 1000); + assert.equal(round.runner.check, 2, "all passed on the way"); + mw.MOWER.place[0](round, {}); + assert.equal(round.you.x, R.checks[2], "back at the last one"); + assert.equal(round.runner.check, 2); +}); + +test("Ghoul Rush's Gardener's Revenge: rolling onto the lawn's end stops the mower (mowerFinish), the door opens, and walking out ends the round with 3 to 9 Lucky dice", () => { + const round = mowerRound(); + round.dice = 1; + const last = lines.length - 1; + mowerAt(round, lines[last].x1 - 12, last, { safe: true }); + until(round, () => round.runner.done, 4000); + assert.equal(round.runner.done, true); + const fin = events(round, "mowerFinish"); + assert.equal(fin.length, 1); + assert.ok(round.you.x >= R.finish && round.you.x < R.finish + 2, `${round.you.x} stopped`); + assert.equal(round.you.y, floorOf(round.you.x)); + assert.equal(round.hasKey, true, "the door opens"); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.phase, "play"); + round.input.right = true; + until(round, () => round.phase === "clear", 20000); + round.input.right = false; + assert.equal(round.phase, "clear"); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, true); + assert.ok(end[0].dice >= BONUS_FLOOR && end[0].dice <= ghoul.MAX_DICE, `${end[0].dice} dice`); + assert.equal(round.dice, Math.min(ghoul.MAX_DICE, 1 + end[0].dice)); + assert.equal(round.lives, 3); + run(round, ghoul.CARD_MS + 100); + assert.equal(round.spec.id, "yard"); + assert.equal(round.runner, null); +}); + +test("Ghoul Rush's Gardener's Revenge: no random number is drawn in the room (a ride of 20 seconds, jumping, mowing and shooting, on a draw that throws)", () => { + const round = mowerRound(); + mowerAt(round, 120, 0, { safe: true }); + round.input.fire = true; + for (let t = 0; t < 20000; t += 4) { + if (t % 1500 === 0) press(round); + ghoul.advance(round, 4, never); + round.events.length = 0; + round.you.safeMs = 1e9; + if (round.phase !== "play") break; + } + assert.ok(round.you.x > 500); +}); + +test("Ghoul Rush's Gardener's Revenge: endless lives (round.infinite) spare the hearts for every cause, through the same lose path", () => { + const tries = [ + { junk: [[60, 0]] }, { junk: [[60, 1]] }, { junk: [[60, 2]] }, { lows: [[56, 62, 23, 0]] }, { lows: [[56, 66, 23, 1]] }, { hedges: [[60]].map((r) => r[0]) }, { beasts: [60] }, + ]; + for (const t of tries) { + const r = synth({ track: FLAT, ...t }); + r.infinite = true; + if (t.beasts) mowerAt(r, 20, 0); + until(r, () => events(r, "lose").length > 0, 4000); + assert.ok(events(r, "lose").length > 0, JSON.stringify(Object.keys(t))); + assert.equal(r.bonusRound.hearts, 5, JSON.stringify(Object.keys(t))); + assert.equal(r.lives, 3); + } + for (const kind of [0, 1]) { + const gap = synth({ track: [[[0, 20], [60, 20]], [[72, 20], [400, 20]]], gaps: [kind] }); + gap.infinite = true; + mowerAt(gap, 30, 0); + until(gap, () => events(gap, "lose").length > 0, 3000); + assert.equal(gap.bonusRound.hearts, 5); + assert.equal(gap.lives, 3); + } +}); + +test("Ghoul Rush's Gardener's Revenge: the Garlic shield takes a hit instead of a heart", () => { + const round = synth({ track: FLAT, junk: [[60, 0]] }); + round.you.garlic = true; + until(round, () => round.you.x > 70, 3000); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.you.garlic, false, "spent"); +}); + +/* ------------------------------------------------------ sounds and words */ + +test("Ghoul Rush's Gardener's Revenge: every event has a voice that plays, every cause has words and a sound, the voices borrow tones that exist, and the tones are short", () => { + assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...mw.EVENTS].sort(), "a voice for every event and no more"); + const tones = ghoulSfx.default.tones; + for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) { + const name = MOWER_VOICES[kind] && MOWER_VOICES[kind][act]; + assert.ok(name, `${event} has a ${kind}.${act} voice`); + assert.ok(tones[name], `${name} exists`); + assert.equal(VOICES[kind][act], name, "joined to the game's voices"); + assert.ok(heard({ type: event, what: "pond", points: 50 }).played.includes(name), `${event} plays ${name}`); + } + for (const cause of ["gnome", "barrow", "pot", "arch", "line", "thorns", "snap", "pond", "ditch"]) { + assert.ok(LOSE_WORDS[cause], `${cause} has words`); + assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`); + assert.ok(heard({ type: "lose", cause, hearts: 3 }).played.length > 0, `${cause} sounds`); + } + assert.equal(heard({ type: "mowerJump" }).played.length, 1); + assert.equal(heard({ type: "mowerHedge", points: 80 }).played.length, 1); + for (const [name, tone] of Object.entries(MOWER_SFX.tones)) { + for (const layer of tone.layers) assert.ok((layer.delay || 0) + layer.seconds <= 1.2, `${name} is under 1.2 s`); + } + const music = MOWER_SFX.music.ghoulMowerRide; + for (const [key, p] of Object.entries(music.patterns)) { + for (const [voice, text] of Object.entries(p)) { + assert.ok(music.voices[voice], `${key}.${voice} is a voice`); + const bars = text.split("|").map((s) => s.trim().split(/\s+/).length); + assert.deepEqual(bars, [16, 16, 16, 16], `${key}.${voice}: four bars of 16 steps`); + } + } + for (const key of music.order) assert.ok(music.patterns[key]); +}); + +test("Ghoul Rush's Gardener's Revenge: the room's own names do not collide with the game's (events, kinds)", () => { + for (const e of mw.EVENTS) assert.ok(e.startsWith("mower"), e); + const other = new Set(ct.EVENTS || []); + for (const e of mw.EVENTS) assert.ok(!other.has(e), `${e} is the mower's alone`); + assert.deepEqual(Object.keys(mw.MOWER).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []); + for (const name of Object.keys(MOWER_SFX.tones)) assert.ok(name.startsWith("ghoulMower"), name); +}); + +/* --------------------------------------------------------------- drawing */ + +test("Ghoul Rush's Gardener's Revenge draws: the room in a lit and a dark one, the mower on the lawn, in the air and ducking, with the blades up, down and jammed, each thing (grass cut and uncut, weeds, hedges, junk, arches, lines, beasts in each state, ponds, ditches), a crash, the finish and the cards", () => { + const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) }); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + g.resize(900, 900); + g.key("action"); + g.tick(16); + const r = g.round; + through(r); + r.offer = ["grounds"]; + r.phaseMs = 0; + ghoul.pickStage(r, 0); + while (r.spec.id !== "mower") through(r); + r.lives = 99; + const spots = [ROOM.start + 40, R.junk[0][0] - 10, R.lows[0][0] - 5, R.lows[1][0] - 5, R.hedges[0] - 10, R.beasts[0] - 20, R.checks[0], lines[0].x1 - 10, R.finish - 40]; + for (const dark of [true, false]) { + for (const x of spots) { + r.dark = dark; + r.phase = "play"; + for (const st of r.spawns) st.over = true; + r.hordeMs = Infinity; + r.monsters.length = 0; + const line = Math.max(0, lines.findIndex((L) => x >= L.x0 && x <= L.x1)); + mowerAt(r, x, line, { safe: true }); + r.runner.beasts = r.runner.beasts.map((b, i) => ({ ...b, state: ["idle", "warn", "snap", "sink", "spent", "broken"][i % 6], t: 600 })); + r.runner.grass = r.runner.grass.map((row, i) => row.map((_, j) => (i + j) % 3 === 0)); + r.runner.hedges = r.runner.hedges.map((_, i) => i % 2 === 0); + r.runner.weeds = r.runner.weeds.map((_, i) => i % 2 === 0); + for (const mode of ["up", "down", "jam"]) { + r.input.fire = mode === "down"; + r.runner.jam = mode === "jam" ? 900 : 0; + r.runner.heat = mode === "jam" ? 0.7 : 0.4; + for (const air of [false, true]) { + if (air) Object.assign(r.you, { state: "air", vy: 20, y: r.you.y + 4 }); + if (air) r.runner.line = -1; + r.you.ducking = x === R.lows[0][0] - 5 && !air; + r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: 0, gone: 0 }); + for (let k = 0; k < 3; k++) g.tick(16); + r.monsters.length = 0; + r.you.safeMs = 1e9; + mowerAt(r, x, line, { safe: true }); + } + } + } + } + r.input.fire = false; + assert.equal(r.spec.id, "mower"); + // A crash, then the stop and the lost and won cards. + r.you.safeMs = 0; + mowerAt(r, R.junk[0][0] - 3, 0); + for (let k = 0; k < 30; k++) g.tick(16); + assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too"); + const done = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + done.resize(900, 900); + done.key("action"); + done.tick(16); + const d = done.round; + through(d); + d.offer = ["grounds"]; + d.phaseMs = 0; + ghoul.pickStage(d, 0); + while (d.spec.id !== "mower") through(d); + d.phase = "play"; + d.runner.done = true; + d.runner.restX = R.finish + 1; + Object.assign(d.you, { x: R.finish + 30, y: LANE, state: "run" }); + d.camX = R.finish - 40; + for (let k = 0; k < 10; k++) done.tick(16); + for (const won of [true, false]) { + endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) }); + d.bonusRound.over = true; + for (let k = 0; k < 10; k++) { + done.tick(16); + bonusTick(d, { tone() {}, fx: {} }); + } + d.bonusRound.over = false; + } + // The stage select goes straight into it. + const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + pick.resize(900, 900); + pick.stageSelect(); + const p = pick.round; + const at = ghoul.STAGES.findIndex((s) => s.id === "grounds"); + for (let i = 0; i < at; i++) ghoul.steerSelect(p, 1, 0); + for (let i = 0; i < 3; i++) ghoul.steerSelect(p, 0, 1); + assert.equal(p.select.room, 3); + pick.tick(16); + ghoul.takeSelect(p); + assert.equal(p.spec.id, "mower"); + assert.equal(p.runner.line, 0); + assert.equal(p.you.y, LANE); + pick.tick(16); +}); + +/* ----------------------------------------------------------- the bots */ + +// A bot that plays well: it jumps at the end of a line, 6 to 15 short of junk or a snapping beast, ducks under +// every low, and works the blades: fire while there is grass, a weed or a thorn hedge in reach (and cool), a +// jump over a hedge when the blades are jammed. `miss` is the share of things it fails to dodge (by a hash). +const mix = (a, b) => { + let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +function goodBot(round, seed, miss = 0.04) { + const { you, runner: c, input: inp } = round; + inp.left = inp.right = inp.down = false; + if (round.phase !== "play" || !c || c.done) { + inp.up = false; + inp.fire = false; + return; + } + const ok = (x) => mix(seed, Math.round(x)) >= miss; + const look = 9 + (seed % 7); + let jump = false; + let fire = false; + if (c.line >= 0) { + if (lines[c.line].x1 - you.x < 2.2 && c.line < lines.length - 1 && ok(lines[c.line].x1)) jump = true; + const ahead = (x) => x - you.x > 6 && x - you.x < look; + for (const [x] of R.junk) if (ahead(x) && ok(x)) jump = true; + R.hedges.forEach((x, i) => { + if (c.hedges[i]) return; + const away = x - you.x; + if (away > -2 && away < mw.BLADE_REACH + 4) fire = true; + if (ahead(x) && (c.jam > 0 || c.heat > 0.85) && ok(x)) jump = true; + }); + R.beasts.forEach((x, i) => { + const b = c.beasts[i]; + if (b.state === "broken" || b.state === "spent" || b.state === "sink") return; + if (x - you.x > 0 && x - you.x < 36) fire = true; + if (b.state === "snap" && ahead(x) && x - you.x < 11 && ok(x)) jump = true; + }); + for (const [x0, x1] of R.lows) if (you.x > x0 - 10 && you.x < x1 + 3 && ok(x0)) inp.down = true; + // Grass and weeds in reach. + R.grass.forEach((gr, i) => { + if (gr[1] > you.x && gr[0] < you.x + mw.BLADE_REACH && c.grass[i].some((cell) => !cell)) fire = true; + }); + R.weeds.forEach((x, i) => { + if (!c.weeds[i] && x > you.x - 1 && x < you.x + mw.BLADE_REACH + 3) fire = true; + }); + } + inp.fire = fire && c.heat < 0.93; + if (jump && !inp.down) press(round); + else inp.up = false; +} +function idleBot(round) { + const inp = round.input; + inp.left = inp.right = inp.down = false; + inp.up = false; + inp.fire = true; +} +function rideWith(seed, bot, limit = 100000) { + const round = mowerRound(seed); + const lost = []; + let t = 0; + for (; t < limit && round.phase !== "clear" && !round.over; t += 16) { + bot(round); + if (round.runner && round.runner.done && round.phase === "play") round.input.right = true; + ghoul.advance(round, 16, steady); + for (const e of round.events) if (e.type === "lose") lost.push(e.cause); + if (round.runner && !round.runner.done) { + const off = round.you.x - round.camX; + assert.ok(off > 4 && off < 70, `the mower stays in view (${off.toFixed(1)} from the left edge at ${round.you.x.toFixed(0)})`); + } + round.events.length = 0; + } + return { round, lost, ms: t }; +} + +test("Ghoul Rush's Gardener's Revenge: a bot that plays well finishes the whole lawn in 60 to 78 seconds, 7 to 9 dice, past every checkpoint, most of the lawn cut", () => { + const dice = []; + for (let seed = 1; seed <= 12; seed++) { + const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed)); + const b = round.bonusRound; + assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")}, lawn ${(round.runner.lawn * 100).toFixed(0)}%)`); + assert.ok(ms > 60000 && ms < 78000, `${ms} ms`); + assert.ok(b.dice >= 6 && b.dice <= ghoul.MAX_DICE, `${b.dice} dice (lawn ${(round.runner.lawn * 100).toFixed(0)}%, acts ${b.perf.acts}, lost ${lost.join(",")})`); + assert.equal(round.lives, 3, "never a run life"); + assert.equal(round.runner.check, R.checks.length - 1, "past every checkpoint"); + assert.ok(round.runner.lawn >= mw.LAWN_GOAL, `lawn ${(round.runner.lawn * 100).toFixed(0)}%`); + dice.push(b.dice); + } + assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 7, `${dice.join(",")}`); +}); + +test("Ghoul Rush's Gardener's Revenge: a bot that dodges well but holds fire the whole way jams the blades again and again, cuts under the lawn goal (no steady die) and earns fewer dice than one that pulses them", () => { + for (let seed = 1; seed <= 4; seed++) { + let jams = 0; + let was = 0; + const holder = rideWith(seed, (r) => { + goodBot(r, seed); + r.input.fire = true; + if (r.runner) { + if (r.runner.jam > 0 && !was) jams++; + was = r.runner.jam > 0 ? 1 : 0; + // It jumps a thorn hedge it cannot cut while the blades are jammed. + if (r.runner.line >= 0) R.hedges.forEach((x, i) => (!r.runner.hedges[i] && x - r.you.x > 6 && x - r.you.x < 12 && r.runner.jam > 0 ? press(r) : null)); + } + }); + const pulser = rideWith(seed, (r) => goodBot(r, seed)); + assert.ok(jams >= 8, `jammed ${jams} times`); + assert.equal(holder.round.bonusRound.won, true, `seed ${seed} finished`); + assert.ok(holder.round.runner.lawn < mw.LAWN_GOAL, `lawn ${holder.round.runner.lawn}`); + assert.equal(holder.round.bonusRound.perf.steady, false); + assert.ok(holder.round.bonusRound.dice < pulser.round.bonusRound.dice, `${holder.round.bonusRound.dice} dice to ${pulser.round.bonusRound.dice}`); + } +}); + +test("Ghoul Rush's Gardener's Revenge: a bot that never dodges (holding fire) loses all five hearts before the first third, ends with 0 dice and the run goes on", () => { + for (let seed = 1; seed <= 6; seed++) { + const { round, lost } = rideWith(seed, idleBot); + const b = round.bonusRound; + assert.equal(b.won, false, "never finishes"); + assert.equal(b.dice, 0); + assert.equal(b.hearts, 0); + assert.equal(lost.length, 5); + assert.ok(round.you.x < ROOM.length * 0.4, `out at ${round.you.x}`); + assert.equal(round.lives, 3); + assert.equal(round.over, false); + } +}); + +/* ------------------------------------------------------------ telegraphs */ + +test("Ghoul Rush's Gardener's Revenge telegraphs: DUCK over arches and lines, JUMP over ponds, ditches and junk, CUT over thorn hedges, none for beasts, weeds or grass, words only on the first three of each kind, the same every time", () => { + const marks = telegraphMarks(R); + assert.equal(marks.length, R.gaps.length + R.junk.length + R.hedges.length + R.lows.length); + for (const m of marks) assert.equal(m.answer, ANSWERS[m.kind], m.kind); + assert.deepEqual(new Set(marks.map((m) => m.kind)), new Set(["pond", "ditch", "junk", "hedge", "arch", "line"])); + R.lows.forEach(([x0, x1, y, kind]) => { + const m = marks.find((q) => q.x === (x0 + x1) / 2); + assert.equal(m.kind, kind ? "line" : "arch"); + assert.equal(m.answer, "DUCK"); + }); + for (const x of R.hedges) assert.equal(marks.find((q) => q.kind === "hedge" && q.x === x).answer, "CUT"); + const m = marks.find((q) => q.kind === "junk"); + const xs = [m.lead - 45, m.lead - 41, m.lead - 36, m.lead - 30, m.lead - 10, m.lead, m.lead + 3, m.lead + 7]; + const alphaOf = (x) => (telegraphs(R, x).find((t) => t.kind === "junk" && t.lead === m.lead) || { alpha: 0 }).alpha; + const a = xs.map(alphaOf); + assert.equal(a[0], 0, "not yet in view"); + assert.ok(a[2] > 0 && a[2] < 1, "fading in 40 to 30 ahead"); + assert.equal(a[3], 1); + assert.equal(a[4], 1); + assert.ok(a[6] > 0 && a[6] < 1, "fading as it passes"); + assert.equal(a[7], 0, "gone once passed"); + assert.deepEqual(telegraphs(R, m.lead - 33), telegraphs(R, m.lead - 33), "deterministic"); + for (const kind of ["pond", "ditch", "junk", "hedge", "arch", "line"]) { + const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead); + assert.ok(of.length >= 3, kind); + of.forEach((q, i) => { + assert.equal(q.n, i); + const shown = telegraphs(R, q.lead - 32).find((t) => t.lead === q.lead); + assert.equal(shown.words, i < 3, `${kind} ${i}`); + }); + } +}); + +test("Ghoul Rush's Gardener's Revenge's intro banner says the controls plainly", () => { + assert.match(R.how, /UP to jump, DOWN to duck/); + assert.match(R.how, /mow/); +}); diff --git a/scripts/test-web-console-activities-ghoul-pew.mjs b/scripts/test-web-console-activities-ghoul-pew.mjs new file mode 100644 index 0000000..8d2c040 --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-pew.mjs @@ -0,0 +1,1087 @@ +// Web console tests, Ghoul Rush's Holy Roller (the Chapel's bonus round, between the Organ Loft and the Choir): an endless-runner seen from behind, in three lanes. Its room and its seeded course (every thing in the way has a safe answer, a safe path exists at every moment), the speed ramp, the lanes and the wall bump, the jump and the slide, each kind of obstacle's cost and cause, the gargoyles and the bell ropes, the wax souls, the combo and the halo's magnet, the grade, the last heart ending the round with the run going on, endless lives, the Garlic shield, the sounds and words, the drawing on a fake canvas, and bots that play it well and badly. +// Run with: node --test scripts/test-web-console-activities-ghoul-pew.mjs +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import * as pew from "../src/web-console/public/activities/ghoul-pew.js"; +import { EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as PEW_LOOKS, VOICES as PEW_VOICES } from "../src/web-console/public/activities/ghoul-pew-draw.js"; +import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js"; +import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-draw.js"; +import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-bonus.js"; +import { BPM, pulse } from "../src/web-console/public/activities/ghoul-pew-world.js"; + +const steady = () => 0.5; +// The pack draws no random number: a run on this fails on the first draw. +const never = () => { + throw new Error("the pew drew a random number"); +}; +const events = (round, type) => round.events.filter((e) => e.type === type); + +function through(round) { + round.phase = "clear"; + round.phaseMs = 1; + ghoul.advance(round, 4, steady); +} + +// A round in Holy Roller reached the way play reaches it, nothing woken, the clocks long, the bonus round on (five hearts). +function pewRound(seed = 5) { + const round = ghoul.newRound(seed); + round.lives = 3; + round.dice = 0; + through(round); + round.offer = ["chapel"]; + round.phaseMs = 0; + ghoul.pickStage(round, 0); + while (round.spec.id !== "pew") through(round); + round.phase = "play"; + for (const st of round.spawns) st.over = true; + round.monsters.length = 0; + round.hordeMs = Infinity; + round.timeMs = 1e9; + round.bonus = 1e9; + round.events.length = 0; + return round; +} + +const ROOM = ghoul.roomById("pew"); +const R = ROOM.ride; +const cues = pew.cuesOf(R); +const counted = pew.countedOf(R); +const floorOf = (x) => ghoul.groundAt(ROOM, x); + +// A round over a ride of its own (a plain stretch to measure the pew on): `ride` adds things. +function synth(ride = {}) { + const round = pewRound(); + round.spec = { ...round.spec, start: 10, length: 1e6 + 100, door: 1e6 + 30, ground: [[0, 1e6 + 100, 12]], ride: { runner: "pew", time: 1e9, finish: 1e6, items: [], souls: [], checks: [], ...ride } }; + round.runner = null; + pew.PEW.place[0](round, { groundAt: ghoul.groundAt }); + return round; +} + +// The pew at distance `x` in `lane` (and the things behind it passed). +function pewAt(round, x, lane = 1, { safe = false } = {}) { + const ride = round.spec.ride; + const c = round.runner; + Object.assign(round.you, { x, y: 12, vy: 0, state: "run", out: 0, safeMs: safe ? 1e9 : 0, ducking: false }); + Object.assign(c, { lane, laneTo: lane, h: 0, vh: 0, slide: 0, v: pew.speedAt(x), hl: false, hr: false, hd: false }); + c.sNext = ride.souls.findIndex((s) => s[0] >= x - 1); + if (c.sNext < 0) c.sNext = ride.souls.length; +} + +function run(round, ms, keys = {}, random = steady) { + Object.assign(round.input, keys); + for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random); + for (const k of Object.keys(keys)) round.input[k] = typeof keys[k] === "number" ? 0 : false; +} + +function until(round, done, ms = 6000, random = steady) { + let t = 0; + for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random); + return t; +} + +// One tick with a key down, then one with it up: a press. +const tap = (round, key) => { + run(round, 4, { [key]: true }); + run(round, 4); +}; +const jump = (round) => { + round.input.jump = ghoul.JUMP_BUFFER_MS; + round.input.up = true; + run(round, 4); + round.input.up = false; +}; + +const heard = (e, extra = {}) => { + const played = []; + const pitches = []; + const noop = () => {}; + const kit = { tone: (name, level, pitch) => (played.push(name), pitches.push(pitch)), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra }; + react({ x: 10, y: 6, tx: 20, ty: 6, lane: 1, h: 0, ...e }, kit); + return { played, pitches }; +}; + +// Seconds the pew is over `h` high in one jump, and what that is in distance at speed v. +const airOver = (h) => (2 * Math.sqrt(pew.JUMP_V ** 2 - 2 * pew.JUMP_G * h)) / pew.JUMP_G; + +/* ------------------------------------------------------------ the room */ + +test("Ghoul Rush's Holy Roller is the Chapel's fourth room, between the Organ Loft and the Choir: lit, no key, no boss, a bonus round with its own track, about 66 seconds of ride", () => { + const st = ghoul.stageById("chapel"); + assert.deepEqual(st.rooms, ["nave", "tower", "loft", "pew", "choir"]); + assert.deepEqual([ROOM.title, ROOM.sub], ["Holy Roller", "The organist has been waiting for YOU"]); + assert.equal(ROOM.dark, false); + assert.equal(ROOM.key, null); + assert.equal(ROOM.boss, null); + assert.equal(ROOM.bonus, true, "a bonus round"); + assert.equal(R.runner, "pew"); + assert.ok(!R.sled && !R.gallery && !R.track, "not another ride's room, and no side-view track"); + assert.equal(ghoul.ROOM_MUSIC.pew, "ghoulPewDirge"); + assert.ok(ghoulSfx.default.music.ghoulPewDirge, "its own track"); + assert.deepEqual(Object.keys(pew.PEW.monsters), [], "no new monster kinds"); + assert.equal(LOOKS.pew, PEW_LOOKS.pew); + assert.equal(LOOKS.pew.pack, "pew"); + assert.ok(Object.isFrozen(R) && Object.isFrozen(R.items) && Object.isFrozen(R.items[0]) && Object.isFrozen(R.souls), "frozen all the way down"); + assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0, "no monsters: the things in the nave are the pack's own"); + assert.ok(ROOM.candy.length === 0 && ROOM.items.length === 0, "no pickups of the game's own"); + assert.ok(ROOM.door > R.finish && floorOf(ROOM.door) > -Infinity, "a door past the finish to walk out of"); + assert.ok(R.finish > pew.PEW_START, "a ride"); + assert.equal(ghoul.timeFor(ghoul.roomFor("pew")), R.time); + assert.ok(R.time >= 1.4 * pew.RIDE_S * 1000, `a ${R.time} ms clock for a ${pew.RIDE_S} s ride`); + assert.match(R.how, /LEFT\/RIGHT change lane, UP jump, DOWN slide, hold space to shoot/); + assert.equal(R.checks.length, 4); + for (let i = 0; i < 4; i++) assert.ok(R.checks[i] > ROOM.start && R.checks[i] < R.finish && (i === 0 || R.checks[i] > R.checks[i - 1]), "checkpoints rise"); + assert.equal(ghoul.roomFor("pew").bonus, true); +}); + +test("Ghoul Rush's Holy Roller: no em dashes or Planny in what the player reads", () => { + const text = JSON.stringify([ROOM.title, ROOM.sub, R.how, LOSE_WORDS]); + assert.ok(!text.includes(String.fromCharCode(0x2014))); + assert.ok(!/planny/i.test(text)); +}); + +/* ---------------------------------------------------------- the course */ + +test("Ghoul Rush's Holy Roller's course: seeded and fixed, every thing a known kind in one of three lanes, sorted, with the grade's numbers (a ride of 60 to 75 seconds at the speed ramp)", () => { + const again = ghoul.roomById("pew").ride; + assert.equal(again, R, "the same data every time"); + const xs = R.items.map((i) => i[0]); + assert.deepEqual([...xs].sort((a, b) => a - b), xs, "sorted"); + for (const [x, lane, kind, len] of R.items) { + assert.ok(pew.KINDS[kind], kind); + assert.ok([0, 1, 2].includes(lane), `lane ${lane}`); + assert.ok(x > ROOM.start + 20 && x < R.finish - 20, `${kind} at ${x}`); + assert.ok(len >= 0); + } + const kinds = new Set(R.items.map((i) => i[2])); + for (const k of Object.keys(pew.KINDS)) assert.ok(kinds.has(k), `the course has a ${k}`); + assert.equal(counted.length, R.items.filter((i) => i[2] !== "bell").length); + assert.ok(counted.length >= 60 && counted.length <= 140, `${counted.length} obstacles`); + assert.ok(pew.soulTotal(R) >= 200 && pew.soulTotal(R) <= 500, `${pew.soulTotal(R)} souls`); + assert.ok(R.souls.filter((s) => s[3] === 1).length >= 3, "halos"); + for (const [x, lane, h, type] of R.souls) assert.ok(x > 0 && [0, 1, 2].includes(lane) && h >= 0.5 && h <= 6.5 && (type === 0 || type === 1), "a soul"); + assert.ok(pew.gargsOf(R).length >= 6 && pew.bellsOf(R).length >= 2, "gargoyles and bell ropes"); + // The ride: about 66 seconds, and the speed climbs the whole way. + const secs = (Math.sqrt(pew.V0 ** 2 + 2 * pew.ACC * (R.finish - pew.PEW_START)) - pew.V0) / pew.ACC; + assert.ok(secs >= 60 && secs <= 75, `${secs.toFixed(1)} s`); + assert.ok(Math.abs(secs - pew.RIDE_S) < 0.5); + let last = 0; + for (let x = pew.PEW_START; x <= R.finish; x += 25) { + const v = pew.speedAt(x); + assert.ok(v >= last, "never slows"); + last = v; + } + assert.ok(pew.speedAt(R.finish) >= 2.2 * pew.speedAt(pew.PEW_START), "the ride more than doubles its speed"); + assert.equal(pew.speedAt(pew.PEW_START), pew.V0); + assert.ok(pew.speedAt(R.finish) <= pew.V_MAX); + assert.ok(Math.abs(pew.xAt(5) - (pew.PEW_START + pew.V0 * 5 + (pew.ACC * 25) / 2)) < 1e-9); +}); + +test("Ghoul Rush's Holy Roller's course is fair: every jumped thing leaves a window to jump, every slide covers its depth, at the speed it is met", () => { + const margin = 0.12; + for (const q of cues) { + const k = pew.KINDS[q.kind]; + const v = pew.speedAt(q.x); + if (k.answer === "JUMP") { + const window = airOver(k.h) * v; + assert.ok(window >= q.len + 2 * pew.HIT_Z + margin * v, `${q.id} at ${q.x}: a window of ${window.toFixed(1)} for ${q.len} deep`); + } + if (k.answer === "SLIDE") assert.ok((pew.SLIDE_MS / 1000) * v >= q.len + 2 * pew.HIT_Z + margin * v, `${q.id} slide`); + } + // A jump clears the highest low thing, and a slide goes under every high one. + const top = Math.max(...Object.values(pew.KINDS).map((k) => k.h || 0).filter((h, i, a) => h < 5)); + assert.ok(pew.JUMP_V ** 2 / (2 * pew.JUMP_G) > top + 1.5, "the jump is higher than the highest low thing"); + assert.ok(pew.SLIDE_H < pew.LOW_Y && pew.STAND_H > pew.LOW_Y, "a standing pew hits a high thing and a slid one passes"); +}); + +// Whether a cue stops the pew in its lane (a block, a gargoyle that has not been dealt with). +const stops = (q) => pew.KINDS[q.kind].answer === "SWITCH" || q.kind === "garg"; + +test("Ghoul Rush's Holy Roller's course always has a safe path: at every depth a lane is clear of blocks (some action answers the rest), and a player who changes lane no faster than one lane in 0.4 s can ride it start to finish", () => { + // At every depth at least one lane has nothing that only a lane change answers, and no lane asks for jump and slide at once. + for (let x = pew.PEW_START; x < R.finish; x += 0.5) { + const blocked = [0, 1, 2].map((l) => cues.some((q) => q.lane === l && stops(q) && x >= q.x - pew.HIT_Z && x <= q.end + pew.HIT_Z)); + assert.ok(blocked.some((b) => !b), `a lane is open at ${x}`); + for (let l = 0; l < 3; l++) { + const acts = new Set(cues.filter((q) => q.lane === l && ["JUMP", "SLIDE"].includes(q.answer) && x >= q.x - pew.HIT_Z && x <= q.end + pew.HIT_Z).map((q) => q.answer)); + assert.ok(acts.size <= 1, `lane ${l} at ${x} asks for one action`); + } + } + // The path: sample the ride every 0.05 s; a lane is out when a stopper (or two different actions too close together) is on it. + const dt = 0.05; + const step = 0.4 / dt; + const n = Math.floor(pew.RIDE_S / dt); + const out = (lane, i) => { + const t = i * dt; + const x = pew.xAt(t); + const here = cues.filter((q) => q.lane === lane); + if (here.some((q) => stops(q) && x >= q.x - pew.HIT_Z && x <= q.end + pew.HIT_Z)) return true; + // Two different answers in one lane closer than 0.9 s apart: the first one's lane is out through the second. + const acts = here.filter((q) => q.answer === "JUMP" || q.answer === "SLIDE"); + for (let a = 0; a < acts.length; a++) { + for (let b = a + 1; b < acts.length; b++) { + if (acts[a].answer === acts[b].answer) continue; + const gap = (acts[b].x - acts[a].end) / pew.speedAt(acts[a].end); + if (gap < 0.9 && x >= acts[a].x - pew.HIT_Z && x <= acts[b].end + pew.HIT_Z) return true; + } + } + return false; + }; + // reach[i][lane]: the pew can be in `lane` at step i. A move to the next lane takes `step` steps, the lane it ends in free at its end. + let reach = new Array(n + 1).fill(0).map(() => [false, false, false]); + reach[0][1] = true; + for (let i = 0; i < n; i++) { + for (let l = 0; l < 3; l++) { + if (!reach[i][l]) continue; + if (!out(l, i + 1)) reach[i + 1][l] = true; + for (const m of [l - 1, l + 1]) { + if (m < 0 || m > 2 || i + step > n) continue; + if (!out(m, i + step) && !out(l, i + 1)) reach[i + step][m] = true; + } + } + } + assert.ok(reach[n].some(Boolean), "a path to the finish"); + // And no moment strands it: every step has some reachable lane. + for (let i = 0; i <= n; i++) assert.ok(reach[i].some(Boolean), `reachable at ${(i * dt).toFixed(2)} s`); +}); + +test("Ghoul Rush's Holy Roller's rows telegraph by kind: the answers are JUMP, SLIDE, SWITCH or SHOOT and each thing has its own cause", () => { + const causes = Object.values(pew.KINDS).map((k) => k.cause).filter(Boolean); + assert.equal(new Set(causes).size, causes.length, "a cause each"); + assert.equal(causes.length, 11); + for (const [name, k] of Object.entries(pew.KINDS)) { + assert.ok(["JUMP", "SLIDE", "SWITCH", "SHOOT"].includes(k.answer), name); + if (k.cause) assert.ok(k.cause.startsWith("pew"), k.cause); + } +}); + +/* ------------------------------------------------------- lanes and wall */ + +test("Ghoul Rush's Holy Roller: a press of left or right moves one lane in a quick smooth slide with a lean, a press at the edge bumps the wall harmlessly, holding a key moves only once", () => { + const round = synth(); + const c = round.runner; + assert.equal(c.lane, 1); + tap(round, "left"); + assert.equal(c.laneTo, 0); + assert.ok(c.lane < 1 && c.lane > 0.9, "it has begun to slide"); + run(round, 60); + assert.ok(c.lane > 0 && c.lane < 0.8, `mid-slide ${c.lane}`); + assert.ok(c.lean < -0.2, "leaning into it"); + run(round, 140); + assert.equal(c.lane, 0); + run(round, 300); + assert.ok(Math.abs(c.lean) < 0.1, "upright again"); + assert.equal(events(round, "pewLane").length, 1); + round.events.length = 0; + // At the edge: a bump (and a tiny shake), no lane, no heart. + tap(round, "left"); + assert.equal(c.laneTo, 0); + assert.ok(c.bump > 0); + assert.equal(events(round, "pewBump").length, 1); + assert.equal(events(round, "pewBump")[0].dir, -1); + assert.equal(round.bonusRound.hearts, 5); + run(round, 300); + assert.equal(c.bump, 0); + // To the other edge by two presses, and a bump on the right. + tap(round, "right"); + tap(round, "right"); + run(round, 300); + assert.equal(c.lane, 2); + round.events.length = 0; + tap(round, "right"); + assert.equal(events(round, "pewBump")[0].dir, 1); + // A key held down is one press. + pewAt(round, 400, 1); + run(round, 800, { left: true }); + assert.equal(c.laneTo, 0, "held left is one lane"); + assert.equal(events(round, "pewBump").length, 1, "only the first bump"); + // The slide takes about 0.15 s a lane. + pewAt(round, 450, 0); + tap(round, "right"); + const ms = until(round, () => c.lane >= 1, 600) + 4; + assert.ok(ms >= 120 && ms <= 220, `${ms} ms a lane`); +}); + +test("Ghoul Rush's Holy Roller: UP jumps about 6 high for two thirds of a second, DOWN slides (it ducks under the high things), and DOWN in the air fast-falls and slides on landing", () => { + const round = synth(); + const c = round.runner; + const peaks = []; + jump(round); + assert.ok(c.h > 0 && round.you.state === "air"); + let t = 4; + let peak = 0; + for (; c.h > 0 && t < 2000; t += 4) { + ghoul.advance(round, 4, steady); + peak = Math.max(peak, c.h); + } + peaks.push(peak); + assert.ok(peak > 5.5 && peak < 6.3, `${peak}`); + assert.ok(t > 600 && t < 720, `${t} ms in the air`); + assert.equal(events(round, "pewJump").length, 1); + assert.equal(events(round, "pewLand").length, 1); + assert.equal(round.you.state, "run"); + // A press early in a jump is forgotten; one just before the landing jumps on it. + round.events.length = 0; + jump(round); + run(round, 150); + round.input.jump = ghoul.JUMP_BUFFER_MS; + until(round, () => c.h <= 0, 2000); + run(round, 100); + assert.equal(events(round, "pewJump").length, 1, "a press at the top is forgotten by the landing"); + assert.equal(c.h, 0); + jump(round); + until(round, () => c.vh < 0 && c.h < 1.2, 2000); + round.input.jump = ghoul.JUMP_BUFFER_MS; + run(round, 120); + assert.equal(events(round, "pewJump").length, 3, "a press just before the landing jumps on it"); + assert.ok(c.h > 0); + run(round, 800); + // Slide. + const slider = synth(); + tap(slider, "down"); + assert.ok(slider.runner.slide > 0 && slider.you.ducking); + assert.equal(events(slider, "pewSlide").length, 1); + run(slider, pew.SLIDE_MS - 100); + assert.ok(slider.you.ducking, "still low"); + run(slider, 200); + assert.equal(slider.you.ducking, false, "up again after SLIDE_MS"); + // UP breaks a slide into a jump. + tap(slider, "down"); + jump(slider); + assert.equal(slider.runner.slide, 0); + assert.ok(slider.runner.h > 0); + // In the air DOWN fast-falls: down sooner than a plain jump, and a slide on landing. + const dive = synth(); + jump(dive); + run(dive, 100); + tap(dive, "down"); + assert.equal(events(dive, "pewDive").length, 1); + const fall = until(dive, () => dive.runner.h <= 0, 1500); + assert.ok(fall < 250, `fast-fell in ${fall} ms`); + assert.ok(dive.runner.slide > 0, "slides on landing"); +}); + +/* --------------------------------------------------- each kind of thing */ + +// Plays the right answer to the thing at `q` (the cue) with the real rules: returns the round after the pass. +function pass(kind, answer, { len = 0, lane = 1, x = 160 } = {}) { + const round = synth({ items: [[x, lane, kind, len]] }); + round.input.fire = false; + pewAt(round, 20, lane); + const q = pew.cuesOf(round.spec.ride)[0]; + let did = false; + const stop = x + 60; + while (round.you.x < stop && round.phase === "play") { + const c = round.runner; + const toNear = (q.x - round.you.x) / c.v; + const toMid = ((q.x + q.end) / 2 - round.you.x) / c.v; + if (!did && answer === "JUMP" && toMid <= 0.33) (jump(round), (did = true)); + else if (!did && answer === "SLIDE" && toNear <= 0.16) (tap(round, "down"), (did = true)); + else if (!did && answer === "SWITCH" && toNear <= 1) (tap(round, lane === 0 ? "right" : "left"), (did = true)); + else ghoul.advance(round, 4, steady); + } + return round; +} + +test("Ghoul Rush's Holy Roller: a block (a pillar, a confessional, a crosswise pew) is answered by changing lane and costs a heart (its cause) if met", () => { + for (const kind of ["pillar", "confessional", "pewx"]) { + const ok = pass(kind, "SWITCH"); + assert.equal(ok.bonusRound.hearts, 5, `${kind}: switching clears it`); + assert.equal(events(ok, "lose").length, 0); + const bad = pass(kind, "NONE"); + assert.equal(bad.bonusRound.hearts, 4, `${kind}: met`); + assert.equal(events(bad, "lose")[0].cause, pew.KINDS[kind].cause); + // Neither a jump nor a slide gets over a block. + assert.equal(pass(kind, "JUMP").bonusRound.hearts, 4, `${kind}: no jumping a block`); + assert.equal(pass(kind, "SLIDE").bonusRound.hearts, 4, `${kind}: no sliding under a block`); + } +}); + +test("Ghoul Rush's Holy Roller: a low thing (kneeler, candle stand, flagstone cracks, crypt hatch) is cleared by a jump and costs a heart otherwise, a slide does not clear it", () => { + for (const kind of ["kneeler", "stand", "cracks", "hatch"]) { + const len = kind === "cracks" ? 7 : 0; + const ok = pass(kind, "JUMP", { len }); + assert.equal(ok.bonusRound.hearts, 5, `${kind}: a jump clears it`); + const bad = pass(kind, "NONE", { len }); + assert.equal(bad.bonusRound.hearts, 4, `${kind}: met`); + assert.equal(events(bad, "lose")[0].cause, pew.KINDS[kind].cause); + assert.equal(pass(kind, "SLIDE", { len }).bonusRound.hearts, 4, `${kind}: a slide is no jump`); + // A lane change clears it too. + assert.equal(pass(kind, "SWITCH", { len }).bonusRound.hearts, 5, `${kind}: or a lane change`); + } +}); + +test("Ghoul Rush's Holy Roller: a high thing (censer, banner, fallen beam) is cleared by a slide and costs a heart standing or jumping", () => { + for (const kind of ["censer", "banner", "beam"]) { + assert.equal(pass(kind, "SLIDE").bonusRound.hearts, 5, `${kind}: a slide goes under`); + const bad = pass(kind, "NONE"); + assert.equal(bad.bonusRound.hearts, 4, `${kind}: met standing`); + assert.equal(events(bad, "lose")[0].cause, pew.KINDS[kind].cause); + assert.equal(pass(kind, "JUMP").bonusRound.hearts, 4, `${kind}: a jump goes into it`); + assert.equal(pass(kind, "SWITCH").bonusRound.hearts, 5, `${kind}: or a lane change`); + } +}); + +test("Ghoul Rush's Holy Roller: a thing in another lane is no danger, and a hit in the lane it is in is only in that lane", () => { + for (const lane of [0, 2]) { + const round = synth({ items: [[100, lane, "pillar", 0]] }); + round.input.fire = false; + pewAt(round, 20, 1); + until(round, () => round.you.x > 140, 5000); + assert.equal(round.bonusRound.hearts, 5, `lane ${lane} thing, pew in 1`); + } + // Half way between two lanes is in neither (the slide takes it past a thing at once). + const mid = synth({ items: [[60, 0, "pillar", 0]] }); + pewAt(mid, 30, 1); + mid.runner.lane = 0.5; + mid.runner.laneTo = 0.5; + until(mid, () => mid.you.x > 90, 3000); + assert.equal(mid.bonusRound.hearts, 5, "0.5 lanes over is clear of lane 0"); +}); + +/* -------------------------------------------------------------- a hit */ + +test("Ghoul Rush's Holy Roller: a hit costs one of the five hearts (never a life or a die), blinks the pew safe for BONUS_SAFE_MS, breaks the combo and shoves the pew into the nearest calm lane", () => { + const round = synth({ items: [[100, 1, "pillar", 0], [100, 0, "pillar", 0], [120, 1, "kneeler", 0], [122, 0, "kneeler", 0]], souls: [] }); + round.dice = 2; + round.input.fire = false; + pewAt(round, 60, 1); + round.runner.combo = 12; + round.runner.mult = 2; + round.runner.comboMs = 1500; + until(round, () => events(round, "lose").length > 0, 3000); + const lose = events(round, "lose"); + assert.equal(lose.length, 1); + assert.equal(lose[0].cause, "pewPillar"); + assert.equal(round.bonusRound.hearts, 4); + assert.equal(round.lives, 3, "no run life"); + assert.equal(round.dice, 2, "no die"); + assert.equal(round.phase, "play", "the ride rolls on"); + assert.equal(round.runner.combo, 0, "the combo is broken"); + assert.equal(round.runner.mult, 1); + assert.equal(round.runner.laneTo, 2, "shoved to the nearest calm lane (the one beside the blocked pair)"); + assert.ok(round.you.safeMs > 0 && round.you.safeMs <= ghoul.BONUS_SAFE_MS, "blinking safe"); + assert.deepEqual(round.bonusRound.perf.hits.length, 1); + const crash = events(round, "pewCrash"); + assert.equal(crash.length, 1); + assert.equal(crash[0].what, "pillar"); + // While safe a second touch costs nothing; once safe has passed it costs again. + pewAt(round, 115, 1); + round.you.safeMs = 500; + until(round, () => round.you.x > 140, 3000); + assert.equal(round.bonusRound.hearts, 4, "safe: the kneeler costs nothing"); + pewAt(round, 115, 1); + round.you.safeMs = 0; + round.runner.hit = {}; + until(round, () => events(round, "lose").length > 1 || round.you.x > 140, 3000); + assert.equal(round.bonusRound.hearts, 3, "unsafe: it costs a heart"); + assert.equal(events(round, "lose")[1].cause, "pewKneeler"); +}); + +test("Ghoul Rush's Holy Roller: the same thing never costs twice, and the Garlic shield takes a hit instead of a heart", () => { + const round = synth({ items: [[80, 1, "confessional", 0]] }); + round.input.fire = false; + pewAt(round, 40, 1); + round.runner.laneTo = 1; + // A long block met head on, with the shove disabled by holding the lane: only one heart goes. + until(round, () => round.you.x > 140, 5000); + assert.equal(round.bonusRound.hearts, 4, "one heart for one thing"); + const g = synth({ items: [[80, 1, "pillar", 0]] }); + g.input.fire = false; + pewAt(g, 40, 1); + g.you.garlic = true; + until(g, () => g.you.x > 120, 4000); + assert.equal(g.bonusRound.hearts, 5); + assert.equal(g.you.garlic, false, "spent"); +}); + +/* ------------------------------------------------- gargoyles and bells */ + +test("Ghoul Rush's Holy Roller: a gargoyle perched in the arches wakes GARG_LEAD_S short of it, shudders, drops into its lane and stands there; met standing it costs a heart (pewGargoyle), a lane change passes it", () => { + const round = synth({ items: [[300, 1, "garg", 0]] }); + round.input.fire = false; + pewAt(round, 20, 1); + const g = round.runner.gargs[0]; + assert.equal(g.state, "perch"); + until(round, () => g.state !== "perch", 12000); + const lead = (300 - round.you.x) / round.runner.v; + assert.equal(g.state, "warn"); + assert.ok(lead <= pew.GARG_LEAD_S + 0.05 && lead > pew.GARG_LEAD_S - 0.2, `woke ${lead.toFixed(2)} s short`); + assert.equal(events(round, "pewGargWarn").length, 1); + until(round, () => g.state === "drop", 1000); + assert.equal(g.state, "drop"); + assert.ok(pew.gargRise(g) > 0, "still falling"); + until(round, () => g.state === "stand", 1000); + assert.equal(events(round, "pewGargDrop").length, 1); + assert.equal(pew.gargRise(g), 0); + const left = (300 - round.you.x) / round.runner.v; + assert.ok(left >= 0.4, `${left.toFixed(2)} s of warning between its landing and the pew`); + until(round, () => events(round, "lose").length > 0 || round.you.x > 330, 3000); + assert.equal(events(round, "lose")[0].cause, "pewGargoyle"); + // A lane change past it costs nothing. + const dodge = synth({ items: [[300, 1, "garg", 0]] }); + dodge.input.fire = false; + pewAt(dodge, 20, 1); + until(dodge, () => dodge.runner.gargs[0].state === "stand", 12000); + tap(dodge, "right"); + until(dodge, () => dodge.you.x > 330, 3000); + assert.equal(dodge.bonusRound.hearts, 5); +}); + +test("Ghoul Rush's Holy Roller: two bolts shoot a gargoyle (150 points, an act), one only chips it, a bolt in another lane misses, and what is shot stays shot after a restart", () => { + const round = synth({ items: [[300, 1, "garg", 0]] }); + round.input.fire = false; + pewAt(round, 20, 1); + const g = round.runner.gargs[0]; + until(round, () => g.state === "stand", 12000); + const score = round.score; + run(round, 4, { fire: true }); + until(round, () => events(round, "pewGargChip").length > 0 || g.state === "broken", 1000, steady); + assert.equal(events(round, "pewGargChip").length, 1, "the first bolt chips"); + assert.equal(g.hp, 1); + assert.notEqual(g.state, "broken"); + run(round, 300, { fire: true }); + assert.equal(g.state, "broken", "the second breaks it"); + assert.equal(events(round, "pewGargHit").length, 1); + assert.equal(round.score - score >= pew.GARG_POINTS, true, "150 points"); + assert.equal(round.bonusRound.perf.acts, 1); + run(round, 2500); + assert.equal(round.bonusRound.hearts, 5, "a broken gargoyle hurts nothing"); + // Another lane: the bolts miss. + const side = synth({ items: [[300, 1, "garg", 0]] }); + side.input.fire = false; + pewAt(side, 20, 1); + until(side, () => side.runner.gargs[0].state === "stand", 12000); + tap(side, "left"); + run(side, 300); + run(side, 600, { fire: true }); + assert.equal(side.runner.gargs[0].state, "stand"); + assert.equal(side.runner.gargs[0].hp, 2); + // What was shot stays shot after a restart in the room. + pew.PEW.place[0](round, { groundAt: ghoul.groundAt }); + assert.equal(round.runner.gargs[0].state, "broken"); +}); + +test("Ghoul Rush's Holy Roller: shooting a bell rope rings the bell (100 points, an act) and stuns every gargoyle in the next BELL_S seconds, which then never drop and never hurt; a rope is no obstacle", () => { + const round = synth({ items: [[120, 1, "bell", 0], [200, 1, "garg", 0], [205, 0, "garg", 0], [900, 2, "garg", 0]] }); + round.input.fire = false; + pewAt(round, 20, 1); + assert.equal(round.runner.bells[0], false); + const score = round.score; + until(round, () => round.you.x > 60, 3000); + run(round, 4, { fire: true }); + until(round, () => round.runner.bells[0], 1500); + assert.equal(round.runner.bells[0], true); + const ring = events(round, "pewBell")[0]; + assert.equal(ring.stunned, 2, "the two gargoyles in range"); + assert.equal(round.runner.gargs[0].state, "stun"); + assert.equal(round.runner.gargs[1].state, "stun"); + assert.equal(round.runner.gargs[2].state, "perch", "the far one is not"); + assert.ok(round.score - score >= pew.BELL_POINTS); + assert.equal(round.bonusRound.perf.acts, 3, "the bell and two stunned"); + until(round, () => round.you.x > 240, 6000); + assert.equal(round.bonusRound.hearts, 5, "a stunned gargoyle and a rope hurt nothing"); + assert.equal(round.runner.gargs[0].state, "stun"); + // A bell stays rung after a restart. + pew.PEW.place[0](round, { groundAt: ghoul.groundAt }); + assert.equal(round.runner.bells[0], true); + // Passing under a rope that is not shot costs nothing either. + const rope = synth({ items: [[100, 1, "bell", 0]] }); + rope.input.fire = false; + pewAt(rope, 20, 1); + until(rope, () => rope.you.x > 150, 4000); + assert.equal(rope.bonusRound.hearts, 5); +}); + +/* ------------------------------------------------------ souls and combo */ + +test("Ghoul Rush's Holy Roller: wax souls are taken in passing (lane and height), and each builds the combo: the multiplier is 1 plus one for each COMBO_STEP in a row (to MULT_MAX), each soul pays 10 times it", () => { + const line = []; + for (let i = 0; i < 24; i++) line.push([60 + i * 3, 1, 1.5, 0]); + const round = synth({ souls: line }); + round.input.fire = false; + pewAt(round, 20, 1); + const score = round.score; + until(round, () => round.you.x > 160, 6000); + assert.equal(round.runner.got, 24); + assert.equal(events(round, "pewSoul").length, 24); + assert.equal(round.runner.combo, 24); + assert.equal(round.runner.best, 24); + assert.equal(round.runner.mult, pew.multOf(24)); + assert.equal(pew.multOf(24), 4); + assert.equal(pew.multOf(7), 1); + assert.equal(pew.multOf(8), 2); + assert.equal(pew.multOf(1000), pew.MULT_MAX); + let want = 0; + for (let n = 1; n <= 24; n++) want += pew.SOUL_POINTS * pew.multOf(n); + assert.equal(round.score - score, want); + assert.ok(events(round, "pewSoul").some((e) => e.up), "a multiplier step is marked"); + // A soul in another lane or too high is missed; a jump takes the high one. + const miss = synth({ souls: [[60, 0, 1.5, 0], [90, 1, 5.8, 0], [120, 2, 1.5, 0]] }); + miss.input.fire = false; + pewAt(miss, 20, 1); + until(miss, () => miss.you.x > 160, 4000); + assert.equal(miss.runner.got, 0); + assert.ok(miss.runner.souls.every((s) => s === 2), "all missed"); + const high = synth({ souls: [[100, 1, 5.5, 0]] }); + high.input.fire = false; + pewAt(high, 20, 1); + until(high, () => (100 - high.you.x) / high.runner.v <= 0.33, 4000); + jump(high); + until(high, () => high.you.x > 130, 2000); + assert.equal(high.runner.got, 1, "a jump takes a soul in an arc"); + const low = synth({ souls: [[100, 1, 0.9, 0]] }); + low.input.fire = false; + pewAt(low, 20, 1); + until(low, () => (100 - low.you.x) / low.runner.v <= 0.1, 4000); + tap(low, "down"); + until(low, () => low.you.x > 130, 2000); + assert.equal(low.runner.got, 1, "a slide takes a soul in a line through it"); +}); + +test("Ghoul Rush's Holy Roller: the combo runs out COMBO_MS after the last soul and a hit breaks it", () => { + const round = synth({ souls: [[60, 1, 1.5, 0], [63, 1, 1.5, 0], [66, 1, 1.5, 0]] }); + round.input.fire = false; + pewAt(round, 20, 1); + until(round, () => round.runner.combo === 3, 4000); + assert.equal(round.runner.combo, 3); + assert.equal(round.runner.comboMs, pew.COMBO_MS); + run(round, pew.COMBO_MS + 50); + assert.equal(round.runner.combo, 0, "run out"); + assert.equal(round.runner.mult, 1); + assert.equal(round.runner.best, 3, "the best is kept"); +}); + +test("Ghoul Rush's Holy Roller: a halo pulls the souls of the lanes beside you in for MAG_MS, and without it they are missed", () => { + const souls = [[60, 1, 2.4, 1]]; + for (let i = 0; i < 10; i++) souls.push([100 + i * 3, i % 2 ? 0 : 2, 1.5, 0]); + const round = synth({ souls }); + round.input.fire = false; + pewAt(round, 20, 1); + until(round, () => round.you.x > 170, 6000); + assert.equal(events(round, "pewHalo").length, 1); + assert.equal(round.runner.got, 10, "all ten side souls pulled in"); + assert.ok(round.score >= pew.HALO_POINTS); + const none = synth({ souls: souls.slice(1) }); + none.input.fire = false; + pewAt(none, 20, 1); + until(none, () => none.you.x > 170, 6000); + assert.equal(none.runner.got, 0, "without the halo they are out of reach"); + // The magnet times out. + const late = synth({ souls: [[60, 1, 2.4, 1], [400, 0, 1.5, 0]] }); + late.input.fire = false; + pewAt(late, 20, 1); + until(late, () => late.you.x > 200, 6000); + assert.ok(late.runner.magnet === 0 || late.runner.magnet < pew.MAG_MS, "the magnet counts down"); + until(late, () => late.you.x > 430, 6000); + assert.equal(late.runner.got, 0, "too late for the far soul"); +}); + +/* ----------------------------------------------------------- the ramp */ + +test("Ghoul Rush's Holy Roller speeds up the whole way: the pace climbs by the second, the organ swells at each speed in SWELLS, and an idle ride over the whole course ends after about 66 seconds with 3 to 9 dice", () => { + const round = pewRound(); + round.infinite = true; + round.input.fire = false; + const samples = []; + const swells = []; + let t = 0; + for (; t < 90000 && round.phase === "play"; t += 4) { + ghoul.advance(round, 4, never); + if (t % 10000 === 0) samples.push(round.runner.v); + for (const e of round.events) if (e.type === "pewSpeed") swells.push([t, e.n]); + round.events.length = 0; + } + assert.equal(round.phase, "clear"); + assert.ok(t >= 63000 && t <= 70000, `${t} ms to the end`); + for (let i = 1; i < samples.length; i++) assert.ok(samples[i] > samples[i - 1] + 4, `faster at ${i * 10} s: ${samples.map((s) => s.toFixed(0))}`); + assert.deepEqual(swells.map((s) => s[1]), [0, 1, 2, 3], "four swells in order"); + assert.ok(swells[0][0] > 8000 && swells[3][0] < t, "spread over the ride"); + const b = round.bonusRound; + assert.equal(b.won, true); + assert.ok(b.dice >= BONUS_FLOOR && b.dice <= 9, `${b.dice} dice`); + assert.equal(round.runner.done, true); +}); + +test("Ghoul Rush's Holy Roller's art rises with the pace: the beat is the organ's, 132 to the minute, throbbing from its stroke", () => { + assert.equal(BPM, 132); + assert.ok(pulse(0) > 0.99 && pulse(5000 % (60000 / 132)) < 1); + const beat = 60000 / BPM; + assert.ok(pulse(beat * 3 + 1) > 0.95, "on the stroke"); + assert.ok(pulse(beat * 3 + beat * 0.9) < 0.1, "dying away"); + const track = ghoulSfx.default.music.ghoulPewDirge; + assert.equal(track.bpm, BPM, "the track keeps the beat the pillars throb to"); +}); + +/* ------------------------------------------------------------- grading */ + +test("Ghoul Rush's Holy Roller's grade: 3 to 9 dice by hearts left, clean passes, gargoyles and bells (the acts), and the steady die (souls taken share)", () => { + const mk = (hearts, hits, acts, steadyDie) => { + const b = makeBonus({ stats: { kills: 0 } }); + b.hearts = hearts; + Object.assign(b.perf, { total: counted.length, hits: Array.from({ length: hits }, (_, i) => `x${i}`), acts, goal: pew.ACTS_GOAL, steady: steadyDie }); + return b; + }; + assert.equal(diceFor(mk(5, 0, pew.ACTS_GOAL, true)), 9); + assert.equal(diceFor(mk(1, counted.length, 0, false)), BONUS_FLOOR); + assert.equal(diceFor(mk(5, 0, 0, false)), 7, "no acts and no steady"); + assert.equal(diceFor(mk(5, 0, pew.ACTS_GOAL - 1, true)), 8); + assert.equal(diceFor(mk(3, 0, pew.ACTS_GOAL, true)), 8, "fewer hearts, one die less"); + assert.ok(pew.ACTS_GOAL <= pew.gargsOf(R).length + pew.bellsOf(R).length + pew.gargsOf(R).length, "the acts goal is reachable"); + // The steady die is the share of the souls laid out. + const round = synth({ souls: Array.from({ length: 10 }, (_, i) => [60 + i * 3, 1, 1.5, 0]) }); + round.input.fire = false; + pewAt(round, 20, 1); + until(round, () => round.runner.got >= 5, 4000); + assert.equal(round.bonusRound.perf.steady, false, "5 of 10 is under the share"); + until(round, () => round.runner.got >= 6, 4000); + assert.equal(round.bonusRound.perf.steady, true, `6 of 10 is ${pew.SOUL_SHARE}`); + assert.equal(pew.soulShare(round.spec.ride, round.runner), 0.6); + // The room's own count. + const real = pewRound(); + assert.equal(real.bonusRound.perf.total, counted.length); + assert.equal(real.bonusRound.perf.goal, pew.ACTS_GOAL); +}); + +/* ------------------------------------------------ the end of the round */ + +test("Ghoul Rush's Holy Roller: the last heart gone ends the round with nothing at once (no life lost, the dice in hand kept) and the run goes on to the Choir", () => { + const round = synth({ items: [[100, 1, "pillar", 0]] }); + round.dice = 2; + round.input.fire = false; + pewAt(round, 50, 1); + round.bonusRound.hearts = 1; + const score = round.score; + until(round, () => round.phase === "clear", 6000); + assert.equal(round.bonusRound.hearts, 0); + assert.equal(round.bonusRound.over, true); + assert.equal(round.bonusRound.won, false); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, false); + assert.equal(end[0].dice, 0); + assert.equal(round.over, false, "no game over"); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + assert.ok(round.score >= score); + assert.equal(round.phase, "clear"); + run(round, ghoul.CARD_LOST_MS + 100); + assert.equal(round.spec.id, "choir"); + assert.equal(round.bonusRound, null); + assert.equal(round.runner, null, "the shared ride slot is empty again"); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + assert.ok(["ready", "bossintro"].includes(round.phase), `the next room (the Choir's boss) begins: ${round.phase}`); +}); + +test("Ghoul Rush's Holy Roller: the checkpoints are passed in order (an event each) and the place hook puts the pew back at the last one passed, keeping its souls and what it shot", () => { + const round = synth({ checks: [100, 200, 300], souls: [[60, 1, 1.5, 0], [150, 1, 1.5, 0], [250, 1, 1.5, 0]] }); + round.input.fire = false; + pewAt(round, 50, 1); + until(round, () => round.runner.check >= 1, 6000); + const checks = events(round, "pewCheck"); + assert.deepEqual(checks.map((e) => e.n), [1, 2]); + assert.equal(round.runner.got, 2); + pew.PEW.place[0](round, { groundAt: ghoul.groundAt }); + assert.equal(round.runner.check, 1); + assert.equal(round.you.x, 200, "back at the last checkpoint"); + assert.equal(round.runner.got, 2, "the souls taken stay taken"); + assert.equal(round.runner.lane, 1); + assert.equal(round.runner.v, pew.speedAt(200)); + // Souls behind the checkpoint are behind it: not offered again. + assert.ok(round.runner.souls[0] !== 0 && round.runner.souls[1] !== 0); +}); + +test("Ghoul Rush's Holy Roller: at the finish the ride ends, Planny steps to the door and the card pays 3 to 9 Lucky dice (more for a clean ride than a rough one)", () => { + const rough = pewRound(); + rough.infinite = true; + rough.input.fire = false; + until(rough, () => rough.phase === "clear", 80000, never); + assert.equal(rough.bonusRound.won, true); + const dice = rough.bonusRound.dice; + assert.ok(dice >= 3 && dice <= 9); + assert.equal(rough.runner.done, true); + run(rough, ghoul.CARD_MS + 100); + assert.equal(rough.spec.id, "choir"); + assert.equal(rough.dice, Math.min(9, dice)); +}); + +test("Ghoul Rush's Holy Roller: endless lives (round.infinite) spare the hearts for every cause, through the same lose path", () => { + for (const [kind, len] of [["pillar", 0], ["confessional", 0], ["pewx", 0], ["kneeler", 0], ["stand", 0], ["cracks", 7], ["hatch", 0], ["censer", 0], ["banner", 0], ["beam", 0]]) { + const r = synth({ items: [[80, 1, kind, len]] }); + r.infinite = true; + r.input.fire = false; + pewAt(r, 30, 1); + until(r, () => events(r, "lose").length > 0, 3000); + assert.equal(events(r, "lose").length, 1, kind); + assert.equal(events(r, "lose")[0].cause, pew.KINDS[kind].cause, kind); + assert.equal(r.bonusRound.hearts, 5, kind); + assert.equal(r.lives, 3); + } + const g = synth({ items: [[300, 1, "garg", 0]] }); + g.infinite = true; + g.input.fire = false; + pewAt(g, 20, 1); + until(g, () => events(g, "lose").length > 0, 12000); + assert.equal(g.bonusRound.hearts, 5); +}); + +test("Ghoul Rush's Holy Roller: no random number is drawn in the room (a ride of 20 seconds, moving, jumping, sliding and shooting, on a draw that throws)", () => { + const round = pewRound(); + round.infinite = true; + for (let t = 0; t < 20000; t += 4) { + round.input.fire = true; + round.input.left = t % 1200 < 4; + round.input.right = t % 1700 < 4; + round.input.down = t % 900 < 4; + if (t % 1000 === 0) round.input.jump = ghoul.JUMP_BUFFER_MS; + ghoul.advance(round, 4, never); + round.events.length = 0; + } + assert.equal(round.phase, "play"); +}); + +/* ------------------------------------------------------ sounds and words */ + +test("Ghoul Rush's Holy Roller: every event has a voice that plays once, every cause has words and a sound, a soul's tick climbs with the combo, and the voices are tones that exist", () => { + assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...pew.EVENTS].sort(), "a voice for every event and no more"); + const tones = ghoulSfx.default.tones; + for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) { + const name = PEW_VOICES[kind] && PEW_VOICES[kind][act]; + assert.ok(name, `${event} has a ${kind}.${act} voice`); + assert.ok(tones[name], `${name} exists`); + assert.equal(VOICES[kind][act], name, "joined to the game's voices"); + const played = heard({ type: event, what: "kneeler", points: 50, mult: 2, combo: 5, share: 0.7, stunned: 1 }).played; + assert.ok(played.includes(name), `${event} plays ${name}`); + assert.equal(played.length, 1, `${event} plays once`); + } + const causes = Object.values(pew.KINDS).map((k) => k.cause).filter(Boolean); + for (const cause of causes) { + assert.ok(LOSE_WORDS[cause], `${cause} has words`); + assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`); + assert.ok(heard({ type: "lose", cause, hearts: 3 }).played.length > 0, `${cause} sounds`); + } + assert.equal(Object.keys(LOSE_WORDS).length, causes.length, "words for every cause and no more"); + const pitches = []; + for (const [combo, mult] of [[1, 1], [6, 1], [9, 2], [30, 4]]) pitches.push(heard({ type: "pewSoul", combo, mult }).pitches[0]); + for (let i = 1; i < pitches.length; i++) assert.ok(pitches[i] > pitches[i - 1], `the soul tick climbs: ${pitches}`); + // The tones stay under 1.2 s and the track is made of known parts. + for (const name of Object.keys(tones).filter((n) => n.startsWith("ghoulPew"))) { + for (const l of tones[name].layers) assert.ok((l.seconds || 0) + (l.delay || 0) <= 1.2 + 1e-9, `${name} layer under 1.2 s`); + } + const track = ghoulSfx.default.music.ghoulPewDirge; + assert.ok(track.bpm >= 120, "a driving tempo"); + for (const id of track.order) assert.ok(track.patterns[id], id); + for (const p of Object.values(track.patterns)) { + const lens = Object.values(p).map((line) => line.split(/\s+/).filter((t) => t && t !== "|").length); + assert.ok(lens.every((n) => n === lens[0]) && lens[0] % 16 === 0, `voices of one length: ${lens}`); + } + assert.equal(track.order.length % 2, 0, "built from parts that loop"); + for (const text of [JSON.stringify(ghoulSfx.default.music.ghoulPewDirge)]) assert.ok(!text.includes(String.fromCharCode(0x2014))); +}); + +test("Ghoul Rush's Holy Roller: the room's own names do not collide with the game's (events, causes, voice kinds)", () => { + for (const e of pew.EVENTS) assert.ok(e.startsWith("pew"), e); + for (const k of Object.keys(PEW_VOICES)) assert.ok(k.startsWith("pew"), k); + for (const k of Object.keys(LOSE_WORDS)) assert.ok(k.startsWith("pew"), k); + assert.deepEqual(Object.keys(pew.PEW).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []); + assert.equal(typeof ghoul.ROOM_MUSIC.pew, "string"); +}); + +/* --------------------------------------------------------------- drawing */ + +test("Ghoul Rush's Holy Roller draws on a fake canvas at many moments without throwing: the whole nave from behind, each kind of thing at every distance, every lane, in the air and sliding, each gargoyle state, a rung bell, the halo, a hit, the finish, the cards and the stage select going straight into it", () => { + const calls = { n: 0 }; + const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => (calls.n++, {})), set: (t, name, value) => ((t[name] = value), true) }); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + g.resize(900, 900); + g.key("action"); + g.tick(16); + const r = g.round; + through(r); + r.offer = ["chapel"]; + r.phaseMs = 0; + ghoul.pickStage(r, 0); + while (r.spec.id !== "pew") through(r); + r.lives = 99; + r.phase = "play"; + const states = ["perch", "warn", "drop", "stand", "stun", "broken"]; + let k = 0; + for (let x = ROOM.start + 5; x < R.finish; x += 53) { + k++; + r.phase = "play"; + r.runner.done = false; + Object.assign(r.you, { x, y: 12, safeMs: k % 5 === 0 ? 1e9 : 0, out: 0 }); + const c = r.runner; + c.lane = [0, 1, 2, 0.4, 1.6][k % 5]; + c.laneTo = Math.round(c.lane); + c.h = k % 3 === 0 ? 3 + (k % 4) : 0; + c.slide = k % 4 === 1 ? 400 : 0; + c.bump = k % 7 === 0 ? 100 : 0; + c.lean = ((k % 3) - 1) * 0.7; + c.magnet = k % 6 === 0 ? 2000 : 0; + c.combo = k % 9; + c.mult = 1 + (k % 3); + c.v = pew.speedAt(x); + c.gargs = c.gargs.map((gg, i) => ({ ...gg, state: states[(i + k) % 6], t: 100, hp: 1 + ((i + k) % 2) })); + c.bells = c.bells.map((_, i) => (i + k) % 2 === 0); + r.shots.push({ x: x + 12, y: 14, vx: 130, vy: 0, gone: 0, lane: k % 3 }); + r.you.safeMs = 1e9; + for (let n = 0; n < 3; n++) g.tick(16); + r.shots.length = 0; + } + assert.ok(calls.n > 20000, `a lot was drawn (${calls.n})`); + assert.equal(r.spec.id, "pew"); + // A crash and the lost card. + const crash = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + crash.resize(900, 900); + crash.key("action"); + crash.tick(16); + const cr = crash.round; + through(cr); + cr.offer = ["chapel"]; + cr.phaseMs = 0; + ghoul.pickStage(cr, 0); + while (cr.spec.id !== "pew") through(cr); + cr.phase = "play"; + cr.you.safeMs = 0; + const pillar = cues.find((q) => q.kind === "pillar"); + Object.assign(cr.you, { x: pillar.x - 3 }); + cr.runner.lane = cr.runner.laneTo = pillar.lane; + for (let n = 0; n < 40; n++) crash.tick(16); + assert.ok(cr.bonusRound.hearts < cr.bonusRound.max || cr.phase !== "play", "the crash draws too"); + for (const won of [true, false]) { + const d = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + d.resize(900, 900); + d.key("action"); + d.tick(16); + const dr = d.round; + through(dr); + dr.offer = ["chapel"]; + dr.phaseMs = 0; + ghoul.pickStage(dr, 0); + while (dr.spec.id !== "pew") through(dr); + dr.phase = "play"; + endBonus(dr, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) }); + for (let n = 0; n < 12; n++) { + d.tick(16); + bonusTick(dr, { tone() {}, fx: {} }); + } + } + // The stage select goes straight into it. + const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + pick.resize(900, 900); + pick.stageSelect(); + const p = pick.round; + const at = ghoul.STAGES.findIndex((s) => s.id === "chapel"); + for (let i = 0; i < at; i++) ghoul.steerSelect(p, 1, 0); + for (let i = 0; i < 3; i++) ghoul.steerSelect(p, 0, 1); + assert.equal(p.select.room, 3); + pick.tick(16); + ghoul.takeSelect(p); + assert.equal(p.spec.id, "pew"); + assert.equal(p.runner.id, "pew"); + assert.equal(p.runner.lane, 1); + pick.tick(16); +}); + +/* ----------------------------------------------------------- the bots */ + +const mix = (a, b) => { + let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +// A bot that plays it well: it steers to the lane with the souls and the bells that has nothing in the way for the next +// second or so, jumps and slides at the right moment, and holds the blaster. `miss` is the share of answers it fails to give. +function goodBot(round, seed, miss = 0.03) { + const { you, runner: c, input: inp } = round; + inp.left = inp.right = inp.down = false; + inp.fire = true; + if (round.phase !== "play" || !c || c.done) return; + const v = c.v; + const soulsOf = R.souls; + const ok = (q) => mix(seed * 7919, q.i * 31 + q.lane * 7 + q.x) >= miss; + const standing = (q) => (q.kind === "garg" ? c.gargs[q.i].state !== "stun" && c.gargs[q.i].state !== "broken" : pew.KINDS[q.kind].answer === "SWITCH"); + const blocked = (lane) => cues.some((q) => q.lane === lane && standing(q) && (q.x - you.x) / v < 1.15 && (q.end - you.x) / v > -0.1); + const score = (lane) => { + if (blocked(lane)) return -1000; + let s = -0.6 * Math.abs(lane - c.laneTo); + for (let i = c.sNext; i < soulsOf.length && soulsOf[i][0] < you.x + v * 1.6; i++) if (c.souls[i] === 0 && soulsOf[i][1] === lane) s += soulsOf[i][3] ? 3 : 1; + for (const q of cues) if (q.kind === "bell" && q.lane === lane && !c.bells[q.i] && (q.x - you.x) / v < 3.5 && q.x > you.x) s += 12; + return s; + }; + const here = Math.round(c.laneTo); + let best = here; + for (const l of [0, 1, 2]) if (score(l) > score(best) + (l === here ? 0 : 0.5)) best = l; + if (blocked(here) || best !== here) { + const dir = Math.sign(best - c.laneTo); + if (dir && !(dir < 0 ? c.hl : c.hr)) inp[dir < 0 ? "left" : "right"] = true; + } + if (Math.abs(c.lane - c.laneTo) > 0.3) return; + for (const q of cues) { + if (q.lane !== here || !ok(q)) continue; + const toNear = (q.x - you.x) / v; + const toMid = ((q.x + q.end) / 2 - you.x) / v; + if (q.answer === "JUMP" && toMid <= 0.33 && toMid > 0.2 && c.h <= 0) round.input.jump = ghoul.JUMP_BUFFER_MS; + if (q.answer === "SLIDE" && toNear <= 0.15 && toNear > 0 && c.h <= 0 && !c.hd) inp.down = true; + } +} +function idleBot(round) { + const inp = round.input; + inp.left = inp.right = inp.down = false; + inp.fire = true; +} +function rideWith(seed, bot, limit = 100000) { + const round = pewRound(seed); + const lost = []; + let t = 0; + for (; t < limit && round.phase !== "clear" && !round.over; t += 16) { + bot(round); + ghoul.advance(round, 16, steady); + for (const e of round.events) if (e.type === "lose") lost.push(e.cause); + round.events.length = 0; + } + return { round, lost, ms: t }; +} + +test("Ghoul Rush's Holy Roller: a bot that plays it well finishes the whole nave in 60 to 75 seconds with good dice, never a run life, past every checkpoint, most of the souls and a long combo", () => { + const dice = []; + for (let seed = 1; seed <= 8; seed++) { + const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed)); + const b = round.bonusRound; + assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")})`); + assert.ok(ms > 60000 && ms < 76000, `${ms} ms`); + assert.ok(b.dice >= 6 && b.dice <= ghoul.MAX_DICE, `${b.dice} dice (seed ${seed}, lost ${lost.join(",")})`); + assert.equal(round.lives, 3, "never a run life"); + assert.equal(round.runner.check, R.checks.length - 1, "past every checkpoint"); + assert.ok(round.runner.got >= pew.soulTotal(R) * 0.5, `${round.runner.got} souls`); + dice.push(b.dice); + } + assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 7, `${dice.join(",")}`); + // A perfect bot: nothing touched, every heart kept, most souls, the combo up. + const { round, lost } = rideWith(3, (r) => goodBot(r, 3, 0)); + assert.deepEqual(lost, [], "a perfect ride loses nothing"); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.bonusRound.perf.hits.length, 0); + assert.ok(round.runner.best >= 30, `a combo of ${round.runner.best}`); + assert.equal(round.bonusRound.perf.steady, true); + assert.ok(round.bonusRound.perf.acts >= pew.ACTS_GOAL - 3, `${round.bonusRound.perf.acts} acts`); + assert.ok(round.bonusRound.dice >= 8, `${round.bonusRound.dice} dice for a clean ride`); +}); + +test("Ghoul Rush's Holy Roller: a bot that never dodges (holding fire) loses all five hearts in the first third, ends with 0 dice and the run goes on", () => { + for (let seed = 1; seed <= 6; seed++) { + const { round, lost } = rideWith(seed, idleBot); + const b = round.bonusRound; + assert.equal(b.won, false, "never finishes"); + assert.equal(b.dice, 0); + assert.equal(b.hearts, 0); + assert.equal(lost.length, 5); + assert.ok(round.you.x < R.finish * 0.5, `out at ${round.you.x}`); + assert.equal(round.lives, 3); + assert.equal(round.over, false); + } +}); diff --git a/scripts/test-web-console-activities-ghoul-retry.mjs b/scripts/test-web-console-activities-ghoul-retry.mjs index 84235b1..c91ae85 100644 --- a/scripts/test-web-console-activities-ghoul-retry.mjs +++ b/scripts/test-web-console-activities-ghoul-retry.mjs @@ -4,6 +4,7 @@ import test from "node:test"; import assert from "node:assert/strict"; import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { skipStory as storySkip } from "../src/web-console/public/activities/ghoul-story.js"; import { MERCY_FAR, MERCY_NEAR, mercyKind, mercySpot, mix3 } from "../src/web-console/public/activities/ghoul-powers.js"; const steady = () => 0.5; @@ -57,6 +58,13 @@ function die(round, cause = "zombie") { const everyRoom = () => ghoul.STAGES.flatMap((st, si) => st.rooms.map((id, ri) => ({ st, si, ri, id }))); const special = (round) => Boolean(round.spec.ride || round.spec.bonus || round.bonusRound); +// Past the intro story at once (it has its own tests): a run opens on it, and the tests that play from the hall skip it. +function skipStory(g) { + if (g.round.phase !== "story") return; + storySkip(g.round); + g.tick(0); +} + test("Ghoul Rush retry mercy: the first attempt of a room spawns nothing, the second exactly one power-up a few steps ahead of Planny on the floor", () => { const round = inRoom(-1, 0); assert.equal(mercies(round).length, 0); @@ -298,6 +306,7 @@ test("Ghoul Rush retry mercy: the game draws the pickup, its shimmer and its wor const g = ghoul.default.create({ canvas }); g.resize(900, 900); g.key("action"); + skipStory(g); g.round.dice = 0; for (let ms = 0; ms < 4000; ms += 16) g.tick(16); const r = g.round; diff --git a/scripts/test-web-console-activities-ghoul-sanatorium.mjs b/scripts/test-web-console-activities-ghoul-sanatorium.mjs index a56cc1e..10b0b17 100644 --- a/scripts/test-web-console-activities-ghoul-sanatorium.mjs +++ b/scripts/test-web-console-activities-ghoul-sanatorium.mjs @@ -10,6 +10,7 @@ import { VOICES, react } from "../src/web-console/public/activities/ghoul-draw.j const steady = () => 0.5; const events = (round, type) => round.events.filter((e) => e.type === type); +// The four rooms that are walked, and the stage's five with the bonus gurney ride between the Theater and the Ward (its own suite: ghoul-gurney). const ROOM_IDS = ["admissions", "baths", "theater", "ward"]; function through(round) { @@ -84,7 +85,7 @@ const heard = (e, extra = {}) => { test("Ghoul Rush's Blackmoor Sanatorium is a stage of three rooms and the Night Ward, its monsters and boss joined to the game's, with two power-ups of its own and a place for each kind", () => { const st = ghoul.stageById("sanatorium"); - assert.deepEqual(st.rooms, ROOM_IDS); + assert.deepEqual(st.rooms, ["admissions", "baths", "theater", "codeblue", "ward"]); assert.equal(st.boss, "matron"); assert.equal(st.title, "Blackmoor Sanatorium"); assert.equal(st.sub, "Visiting hours ended in 1912"); @@ -92,7 +93,7 @@ test("Ghoul Rush's Blackmoor Sanatorium is a stage of three rooms and the Night assert.equal(ghoul.BOSSES.matron, sn.BOSSES.matron); assert.equal(sn.BOSSES.matron.sub, "Stay out of her lantern light"); for (const id of st.rooms) assert.ok(ghoul.ROOM_MUSIC[id], `${id} has music`); - const [admissions, baths, theater, ward] = st.rooms.map((id) => ghoul.roomById(id)); + const [admissions, baths, theater, ward] = ROOM_IDS.map((id) => ghoul.roomById(id)); const returning = ["zombie", "crawl", "ghost", "spitter"]; for (const room of [admissions, baths, theater]) { assert.ok(room.key, `${room.id}: a key`); diff --git a/scripts/test-web-console-activities-ghoul-sled.mjs b/scripts/test-web-console-activities-ghoul-sled.mjs index 5563512..d0ad25b 100644 --- a/scripts/test-web-console-activities-ghoul-sled.mjs +++ b/scripts/test-web-console-activities-ghoul-sled.mjs @@ -3,6 +3,7 @@ import { test } from "node:test"; import assert from "node:assert/strict"; import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { skipBossIntro } from "./ghoul-test-helpers.mjs"; import * as sl from "../src/web-console/public/activities/ghoul-sled.js"; import * as ct from "../src/web-console/public/activities/ghoul-cart.js"; import { EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as SLED_LOOKS, VOICES as SLED_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-sled-draw.js"; @@ -102,7 +103,7 @@ test("Ghoul Rush's Coffin Sled is the Frozen Lake's fourth room, between the Bla const st = ghoul.stageById("frozen"); assert.deepEqual(st.rooms, ["huts", "lodge", "blackice", "sled", "widow"]); assert.equal(st.boss, "frostwidow"); - assert.equal(ghoul.STAGES.at(-1), st, "still the last stage in the list"); + assert.equal(ghoul.STAGES.at(-2), st, "the last stage in the list but Gallows Bog"); assert.deepEqual([ROOM.title, ROOM.sub], ["Coffin Sled", "Hold on. The hill is longer than it looks"]); assert.equal(ROOM.dark, false, "a moonlit night, always lit"); assert.equal(ROOM.key, null); @@ -540,6 +541,8 @@ test("Ghoul Rush's Coffin Sled: the last heart gone ends the round with nothing assert.equal(round.sled, null); assert.equal(round.lives, 3); assert.equal(round.dice, 2); + assert.equal(round.phase, "bossintro", "the boss room opens on its card"); + skipBossIntro(ghoul, round); assert.equal(round.phase, "ready"); }); diff --git a/scripts/test-web-console-activities-ghoul-story.mjs b/scripts/test-web-console-activities-ghoul-story.mjs new file mode 100644 index 0000000..0507a43 --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-story.mjs @@ -0,0 +1,455 @@ +// Web console tests, Ghoul Rush's intro story: 6 to 8 pages that fit the field, never name the hero, stay generic about stages (no names, no counts) and speak to YOU; a run opens on it and ends in The Long Hall; the lockout, the typing that finishes first, every key and a click, the skip by holding fire, a pause that holds it; never in the practice stage select, on a respawn or in a new room; every page draws on a fake canvas at many moments; every sound it asks for exists. +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js"; +import { INTROS } from "../src/web-console/public/activities/ghoul-intros.js"; +import { + CHAR_MS, + FINALE_TITLE, + LAST_HINT, + MAX_LINE, + PAGES, + RELOCK_MS, + REVEAL_AT_MS, + SKIP_HINT, + SKIP_HOLD_MS, + STORY_HINT, + STORY_LOCK_MS, + beginStory, + endStory, + lineAt, + pageChars, + pressStory, + releaseStory, + revealEnd, + shown, + skipStory, + stepStory, + takeStory, + typed, +} from "../src/web-console/public/activities/ghoul-story.js"; +import { SCENE_H, TEXT_SIZE } from "../src/web-console/public/activities/ghoul-story-draw.js"; +import { toneNames } from "../src/web-console/public/tones.js"; + +const steady = () => 0.5; +const DASH = String.fromCharCode(0x2014); +const ALL = PAGES.flatMap((p) => [p.chapter, ...p.lines]).join("\n"); + +function fakeCtx(texts) { + return new Proxy({}, { + get: (t, name) => (name in t ? t[name] : name === "fillText" ? (s) => texts.push(s) : () => {}), + set: (t, name, value) => ((t[name] = value), true), + }); +} + +// A window game with the story up (a real run's first press), and its sounds. +function openGame(extra = {}) { + const texts = []; + const sounds = []; + const hums = []; + const ctx = fakeCtx(texts); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, tone: (name) => sounds.push(name), hum: (id, name) => hums.push([id, name]), ...extra }); + g.resize(900, 900); + g.key("action"); + return { g, texts, sounds, hums }; +} +const tick = (g, ms) => { + for (let t = 0; t < ms; t += 16) g.tick(16); +}; +// To the point where a press counts on the page the game is on (and the typing is still going unless it is long past). +const lock = (g) => tick(g, STORY_LOCK_MS + 20); +// To the end of the typing. +const typedOut = (g) => tick(g, revealEnd(PAGES[g.round.story.page]) - g.round.story.ms + 40); + +test("Ghoul Rush story: 6 to 8 pages, 2 to 4 short lines each, no em dash, never the hero's name, and YOU on every page", () => { + assert.ok(PAGES.length >= 6 && PAGES.length <= 8, `${PAGES.length} pages`); + assert.equal(new Set(PAGES.map((p) => p.id)).size, PAGES.length, "unique ids"); + const field = ghoul.FIELD_W; + for (const p of PAGES) { + assert.ok(p.chapter && p.scene && p.pal.sky && p.pal.ground && p.pal.a && p.pal.glow, `${p.id} has a heading, a scene and colors`); + assert.ok(p.lines.length >= 2 && p.lines.length <= 4, `${p.id} has 2 to 4 lines`); + const text = [p.chapter, ...p.lines].join("\n"); + assert.ok(!text.includes(DASH), `${p.id} has no em dash`); + assert.ok(!/planny|the player|the hero|\bhero\b/i.test(text), `${p.id} never names the hero`); + assert.ok(/\bYOU(R)?\b/.test(text), `${p.id} speaks to YOU`); + for (const line of p.lines) { + assert.ok(line.length <= MAX_LINE, `${p.id}: "${line}" is ${line.length} characters`); + // The same width guess the intro card's test uses (0.62 em a letter), at the story's own size. + assert.ok(line.length * TEXT_SIZE * 0.62 <= field - 1, `${p.id}: "${line}" fits the field`); + } + for (const [at, name, vol, rate] of p.cues) { + assert.ok(at >= 0 && at < 9000 && vol > 0 && vol <= 1 && rate > 0, `${p.id}: a cue is timed and audible`); + assert.ok(toneNames().includes(name) || Object.hasOwn(ghoulSfx.tones, name), `${p.id}: ${name} is a tone`); + } + } + assert.ok(ALL.includes("YOU")); + const lines = PAGES.flatMap((p) => p.lines); + assert.equal(new Set(lines).size, lines.length, "no line used twice"); + const cards = new Set(Object.values(INTROS).flatMap((i) => i.lines)); + assert.ok(lines.every((l) => !cards.has(l)), "no line copied from a stage's card"); + assert.ok(PAGES[PAGES.length - 1].scene === "begin" && FINALE_TITLE === "THE RUN BEGINS", "the last page is the run beginning"); +}); + +test("Ghoul Rush story: it names the house and the way in, and stays generic about stages (no names, no counts)", () => { + const text = ALL.toLowerCase(); + assert.ok(text.includes("marrow manor"), "the house has a name"); + assert.ok(text.includes("flashlight") && text.includes("flinch"), "what YOU carry, and what it does to the house"); + assert.ok(text.includes("fright"), "what it eats"); + assert.ok(text.includes("long hall"), "the way in"); + assert.ok(text.includes("starves"), "what happens if YOU escape"); + assert.ok(/inside/.test(text), "the places are inside the house"); + // More stages will come: the story never names one (the house itself, Marrow Manor, is not the stage The Manor). + for (const st of ghoul.STAGES) { + const name = st.title.replace(/^The /, "").toLowerCase(); + if (name === "manor") continue; + assert.ok(!text.includes(name), `the story does not name the stage ${st.title}`); + } + const named = ["east wing", "graveyard", "grounds", "chapel", "sanatorium", "blackmoor", "hollow end", "deep seam", "midnight carnival", "frozen lake", "pit beneath"]; + for (const n of named) assert.ok(!text.includes(n), `the story does not name ${n}`); + assert.ok((text.match(/carnival/g) || []).length <= 1, "at most one passing example of a place"); +}); + +test("Ghoul Rush story: no page names a count of stages, rooms, doors or keepers", () => { + const count = /\b(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|twenty|\d+)\b[\s-]+(\w+\s+)?(stages?|rooms?|doors?|keepers?|levels?|places?|worlds?|bosses)\b/i; + for (const p of PAGES) { + for (const line of [p.chapter, ...p.lines]) { + assert.ok(!/\d/.test(line), p.id + ": no digit in " + line); + assert.ok(!count.test(line), p.id + ": " + line + " names a count"); + } + } + assert.ok(!/\b(ten|all ten|every one of the)\b/i.test(ALL), "no ten anywhere in the story"); + // The check itself catches what it should. + assert.ok(count.test("Ten rooms, ten keepers") && count.test("seven doors") && count.test("3 stages") && !count.test("Door after door")); +}); + +test("Ghoul Rush story: the typing, the lines and the page numbers add up", () => { + const pg = PAGES[2]; + assert.equal(pageChars(pg), pg.lines.reduce((n, l) => n + l.length, 0)); + assert.equal(shown(pg, 0), 0); + assert.equal(shown(pg, REVEAL_AT_MS), 0); + assert.equal(shown(pg, REVEAL_AT_MS + CHAR_MS * 5), 5); + assert.equal(shown(pg, 1e9), pageChars(pg)); + assert.equal(shown(pg, 0, true), pageChars(pg), "full shows everything at once"); + assert.equal(revealEnd(pg), REVEAL_AT_MS + pageChars(pg) * CHAR_MS); + assert.ok(revealEnd(pg) < 9000, "a page types out in a few seconds"); + assert.deepEqual(typed(pg, 0), pg.lines.map(() => "")); + assert.deepEqual(typed(pg, pageChars(pg)), pg.lines); + const half = typed(pg, pg.lines[0].length + 3); + assert.equal(half[0], pg.lines[0]); + assert.equal(half[1], pg.lines[1].slice(0, 3)); + assert.equal(lineAt(pg, 0), 0); + assert.equal(lineAt(pg, pg.lines[0].length), 1); + assert.equal(lineAt(pg, pageChars(pg)), pg.lines.length - 1); +}); + +test("Ghoul Rush story: a run opens on it with the hall behind it, and it ends in The Long Hall, announced then", () => { + const r = ghoul.newRound(3); + assert.equal(r.phase, "play", "the round itself still starts in the hall (the window adds the story)"); + assert.equal(r.story, undefined); + beginStory(r); + assert.equal(r.phase, "story"); + assert.equal(r.story.page, 0); + assert.equal(r.spec.id, "hall", "the hall is set up behind it"); + assert.deepEqual(r.events.filter((e) => e.type === "storyPage").map((e) => e.page), [0]); + assert.equal(r.events.some((e) => e.type === "room"), false, "no room is announced yet"); + // Nothing in the hall moves while it is up. + r.input.right = true; + const x = r.you.x; + ghoul.advance(r, 2000, steady); + assert.equal(r.you.x, x); + assert.equal(r.phase, "story"); + r.events.length = 0; + endStory(r); + assert.equal(r.phase, "play"); + assert.equal(r.story, null); + assert.equal(r.spec.id, "hall", "the run's first room is the hall"); + assert.equal(r.room, 1); + assert.deepEqual(r.events.filter((e) => e.type === "room").map((e) => e.room), [1]); + assert.ok(r.events.some((e) => e.type === "storyEnd")); +}); + +test("Ghoul Rush story: a press turns a page only after the lockout, typing finishes first, and the last page enters the hall", () => { + const r = ghoul.newRound(3); + beginStory(r); + assert.equal(takeStory(r), false, "not at once"); + ghoul.advance(r, STORY_LOCK_MS - 40, steady); + assert.equal(takeStory(r), false, "not before the lockout"); + assert.equal(r.story.page, 0); + ghoul.advance(r, 60, steady); + // Typing still going: the first press finishes it, the page stays. + assert.ok(r.story.ms < revealEnd(PAGES[0])); + assert.equal(takeStory(r), true); + assert.equal(r.story.page, 0, "the page has not turned"); + assert.equal(r.story.full, true, "the typing is done"); + assert.equal(takeStory(r), false, "a second press right on top of it does not count"); + ghoul.advance(r, RELOCK_MS + 20, steady); + assert.equal(takeStory(r), true); + assert.equal(r.story.page, 1, "now the page turns"); + assert.equal(r.story.ms, 0); + assert.equal(r.story.full, false); + assert.equal(takeStory(r), false, "each page has its own lockout"); + // Through every page the way a patient reader would: wait out the typing, press once. + for (let at = 1; at < PAGES.length; at++) { + assert.equal(r.story.page, at); + ghoul.advance(r, revealEnd(PAGES[at]) + 20, steady); + assert.equal(takeStory(r), true); + } + assert.equal(r.phase, "play", "the last page's press enters the hall"); + assert.equal(r.story, null); + assert.equal(takeStory(r), false, "nothing to take after"); + assert.equal(r.spec.id, "hall"); +}); + +test("Ghoul Rush story: the window's keys, any move and fire alike, turn pages; repeats and early presses never do; a click does", () => { + for (const name of ["left", "right", "up", "down", "action"]) { + const { g } = openGame(); + assert.equal(g.round.phase, "story", `${name}: a run opens on the story`); + assert.equal(g.round.input.fire, false, "the press that starts never fires"); + g.key(name); + assert.equal(g.round.story.page, 0, `${name}: early press ignored`); + assert.equal(g.round.story.full, false); + lock(g); + g.key(name, true); + assert.equal(g.round.story.full, false, `${name}: a repeat is ignored`); + g.release(name); + g.key(name); + assert.equal(g.round.story.full, true, `${name}: a fresh press finishes the typing first`); + tick(g, RELOCK_MS + 40); + g.key(name, true); + assert.equal(g.round.story.page, 0, `${name}: a repeat never turns the page`); + g.release(name); + g.key(name); + assert.equal(g.round.story.page, 1, `${name}: the next press turns it`); + assert.equal(g.round.input.fire, false, `${name}: no shot is fired at the story`); + assert.equal(g.round.input.up || g.round.input.left || g.round.input.right || g.round.input.down, false, `${name}: no move is kept`); + assert.equal(g.round.you.x, ghoul.roomById("hall").start, `${name}: YOU has not moved`); + } + const { g } = openGame(); + g.pointer("down", 10, 10); + assert.equal(g.round.story.page, 0, "a click before the lockout does nothing"); + lock(g); + g.pointer("move", 10, 10); + g.pointer("up", 10, 10); + assert.equal(g.round.story.full, false); + g.pointer("down", 10, 10); + assert.equal(g.round.story.full, true, "a click finishes the typing first"); + tick(g, RELOCK_MS + 40); + g.pointer("down", 10, 10); + assert.equal(g.round.story.page, 1, "and the next click turns the page"); +}); + +test("Ghoul Rush story: holding fire for a second skips the whole story, a tap or a short hold does not, and the bar shows it", () => { + const { g, texts } = openGame(); + // A fire held from the start: the key's repeats never start the clock. + for (let k = 0; k < 30; k++) g.key("action", true); + tick(g, 2000); + assert.equal(g.round.phase, "story", "a held key from the run's own press never skips"); + assert.equal(g.round.story.hold, -1); + // Too short a hold. + const { g: h } = openGame(); + h.key("action"); + assert.equal(h.round.story.hold, 0, "a fresh press starts the clock"); + tick(h, SKIP_HOLD_MS - 200); + assert.equal(h.round.phase, "story"); + assert.ok(h.round.story.hold > 0); + texts.length = 0; + h.release("action"); + assert.equal(h.round.story.hold, -1, "let go stops the clock"); + tick(h, 2000); + assert.equal(h.round.phase, "story"); + // Held the whole second: the story is over at once, whatever page it was on, and the hall is announced. + const { g: k, sounds } = openGame(); + lock(k); + k.key("action"); + k.key("action", true); + tick(k, SKIP_HOLD_MS + 100); + assert.equal(k.round.phase, "play", "the hold skipped the story"); + assert.equal(k.round.story, null); + assert.equal(k.round.spec.id, "hall"); + assert.ok(k.round.page === undefined); + assert.ok(sounds.includes("ghoulRoomIn"), "the hall's door sounds as the run starts"); + // The skip bar draws while it is held, the hint on every page. + const { g: m, texts: seen } = openGame(); + m.key("action"); + tick(m, 500); + assert.ok(seen.includes(SKIP_HINT.toUpperCase()), "the skip hint shows"); + assert.ok(m.round.story.hold >= 400); + // skipStory and pressStory are the plain functions behind it. + const r = ghoul.newRound(1); + assert.equal(skipStory(r), false, "no story, nothing to skip"); + beginStory(r); + assert.equal(pressStory(r, true), false, "a repeat is nothing"); + assert.equal(pressStory(r, false), true); + assert.equal(r.story.hold, 0); + stepStory(r, SKIP_HOLD_MS - 1); + assert.equal(r.phase, "story"); + releaseStory(r); + assert.equal(r.story.hold, -1); + assert.equal(skipStory(r), true); + assert.equal(r.phase, "play"); +}); + +test("Ghoul Rush story: a pause holds it, the hint of every page shows once a press counts, and the skip hint is always up", () => { + const { g, texts } = openGame(); + tick(g, 100); + g.pause(); + const held = g.round.story.ms; + tick(g, 2000); + assert.equal(g.round.story.ms, held, "a pause holds the page's clock"); + g.key("action"); + g.key("left"); + assert.equal(g.round.story.hold, -1, "no key counts while paused"); + assert.equal(g.round.story.page, 0); + g.resume(); + tick(g, 100); + assert.ok(g.round.story.ms > held); + // Every page: the skip hint, the heading, the page's text, and the hint once a press counts. + for (let at = 0; at < PAGES.length; at++) { + g.round.story = { page: at, ms: 0, full: false, arm: 0, hold: -1, cue: 99, shown: 0 }; + texts.length = 0; + g.tick(1); + assert.ok(texts.includes(SKIP_HINT.toUpperCase()), `page ${at + 1} shows how to skip`); + assert.equal(texts.includes(STORY_HINT) || texts.includes(LAST_HINT), false, "no continue hint inside the lockout"); + g.round.story.ms = STORY_LOCK_MS + 100; + texts.length = 0; + g.tick(1); + assert.ok(texts.includes(at === PAGES.length - 1 ? LAST_HINT : STORY_HINT), `page ${at + 1} shows the continue hint once a press counts`); + assert.ok(texts.includes(PAGES[at].chapter), `page ${at + 1} shows its heading`); + g.round.story.ms = 60000; + g.round.story.full = true; + texts.length = 0; + g.tick(1); + for (const line of PAGES[at].lines) assert.ok(texts.includes(line), `page ${at + 1}: "${line}" is drawn in full`); + } +}); + +test("Ghoul Rush story: never in the practice stage select, on a respawn or in a new room, and a new run shows it again", () => { + const { g } = openGame(); + assert.equal(g.round.phase, "story"); + g.stageSelect(); + assert.equal(g.round.phase, "select", "the stage select opens on its list, not the story"); + assert.equal(g.round.story, undefined); + assert.equal(g.round.practice, true); + g.key("action"); + assert.notEqual(g.round.phase, "story", "and a room taken from it goes on"); + // A real run: skip it, then a lost life and a new room never bring it back. + const { g: h } = openGame(); + skipStory(h.round); + h.tick(16); + assert.equal(h.round.phase, "play"); + h.round.dice = 0; + h.round.you.safeMs = 0; + ghoul.lose(h.round, "zombie"); + tick(h, ghoul.CRASH_MS + 400); + assert.notEqual(h.round.phase, "story", "no story on a respawn"); + assert.equal(h.round.story, null); + h.round.phase = "clear"; + h.round.phaseMs = 1; + h.tick(16); + assert.notEqual(h.round.phase, "story", "no story in a new room"); + assert.equal(h.round.phase, "pick", "the hall's door leads to the stage pick, never the story"); + h.round.phaseMs = 0; + ghoul.pickStage(h.round); + assert.equal(h.round.phase, "intro", "and a stage opens on its own card"); + tick(h, ghoul.INTRO_MIN_MS + 100); + ghoul.takeIntro(h.round); + tick(h, ghoul.READY_MS + 200); + assert.equal(h.round.phase, "play"); + // The end screen and a new run: the story again. + h.round.lives = 1; + h.round.dice = 0; + h.round.infinite = false; + ghoul.lose(h.round, "zombie"); + for (let k = 0; k < 300 && h.state === "running"; k++) h.tick(16); + assert.equal(h.state, "over"); + h.key("action"); + assert.equal(h.state, "running"); + assert.equal(h.round.phase, "story", "every new run opens on it"); + assert.equal(h.round.story.page, 0); + // The pure round never has it (the tests that walk the rules rely on that). + assert.equal(ghoul.newRound(9).phase, "play"); +}); + +test("Ghoul Rush story: its sounds play (a drone under it, its timed tones, a page turn, the hall's door) and the hall's music waits", () => { + const { g, sounds, hums } = openGame(); + const music = []; + tick(g, 1200); + assert.ok(hums.some(([id, name]) => id === "ghoul:story" && name === "ghoulStoryDrone"), "the story's drone runs under it"); + assert.ok(hums.every(([id]) => id === "ghoul:story"), "no monster or house hum under the story"); + assert.ok(Object.hasOwn(ghoulSfx.hums, "ghoulStoryDrone")); + const first = PAGES[0].cues[0][1]; + assert.ok(sounds.includes(first), `${first} plays at the first page's start`); + assert.ok(sounds.includes("tickSoft"), "a soft blip while it types"); + lock(g); + typedOut(g); + tick(g, RELOCK_MS + 40); + sounds.length = 0; + g.key("left"); + g.tick(16); + assert.equal(g.round.story.page, 1); + assert.ok(sounds.includes("ghoulStoryPage"), "a page turn rustles"); + assert.equal(music.length, 0); + // Every tone and hum the story owns keeps this game's prefix. + for (const name of Object.keys(ghoulSfx.tones)) if (name.startsWith("ghoulStory")) assert.match(name, /^ghoulStory[A-Z]/); + assert.ok(Object.keys(ghoulSfx.tones).filter((n) => n.startsWith("ghoulStory")).length >= 8, "a handful of house tones"); +}); + +test("Ghoul Rush story: endless lives and the stage code are untouched by it", () => { + const { g } = openGame(); + g.cheat(true); + assert.equal(g.round.infinite, true); + lock(g); + g.key("up"); + assert.equal(g.round.infinite, true, "the code survives the story"); + skipStory(g.round); + g.tick(16); + g.round.lives = 1; + ghoul.lose(g.round, "zombie"); + tick(g, ghoul.CRASH_MS + 400); + assert.equal(g.round.lives, 1, "no life is lost with the code on"); + assert.equal(g.state, "running"); +}); + +test("Ghoul Rush story: every page draws on a fake canvas at many moments, the finale's title letter by letter, without throwing", () => { + for (let at = 0; at < PAGES.length; at++) { + const texts = []; + const ctx = fakeCtx(texts); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + g.resize(900, 900); + g.key("action"); + for (const ms of [0, 1, 120, 450, 900, 1500, 2300, 3100, 4000, 5200, 6500, 8000, 12000, 40000]) { + for (const full of [false, true]) { + for (const hold of [-1, 500]) { + g.round.story = { page: at, ms, full, arm: 0, hold, cue: 99, shown: 0 }; + g.tick(1); + } + } + } + assert.ok(texts.some((t) => PAGES[at].chapter === t), `page ${at + 1} draws its heading`); + if (at === PAGES.length - 1) { + g.round.story = { page: at, ms: 6000, full: true, arm: 0, hold: -1, cue: 99, shown: 0 }; + texts.length = 0; + g.tick(1); + for (const ch of FINALE_TITLE) if (ch !== " ") assert.ok(texts.includes(ch), `the finale draws ${ch}`); + } + } + assert.ok(SCENE_H > 20 && SCENE_H < 40, "the scene keeps to the top of the field"); +}); + +test("Ghoul Rush story: the whole run still goes through it on a real clock, from the first press to the hall, ready to play", () => { + const { g, texts } = openGame(); + assert.equal(g.round.phase, "story"); + let guard = 0; + while (g.round.phase === "story" && guard++ < 40) { + typedOut(g); + tick(g, RELOCK_MS + 40); + g.key("right"); + g.release("right"); + } + assert.equal(g.round.phase, "play"); + assert.equal(g.round.spec.id, "hall"); + texts.length = 0; + tick(g, 100); + assert.ok(texts.some((t) => String(t).includes("The Long Hall")), "the hall is announced once the story is out"); +}); diff --git a/scripts/test-web-console-activities-ghoul-tray.mjs b/scripts/test-web-console-activities-ghoul-tray.mjs new file mode 100644 index 0000000..a8e9076 --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-tray.mjs @@ -0,0 +1,894 @@ +// Web console tests, Ghoul Rush's Servants' Back Stairs (the East Wing's bonus round, between the Attic and the Crypt): its shape (every gap between flights clears with a jump and swallows a tray that does not jump, every low can be ducked, spacing, checkpoints, greased stretches, the clock), the tray's speed on slopes and grease, its jump and duck, a pot, cutlery, a ham, pans, the cook's dish, the domes and plates (the courses), the cherries, a fall down the stairs, the checkpoint, the jump off the last shelf and the door, the bonus round's hearts and dice (3 to 9), endless lives for every new cause, a voice for every event, the drawing, and bots that ride the whole route (one that dodges well, one that never does). +// Run with: node --test scripts/test-web-console-activities-ghoul-tray.mjs +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { skipBossIntro } from "./ghoul-test-helpers.mjs"; +import * as tr from "../src/web-console/public/activities/ghoul-tray.js"; +import * as ct from "../src/web-console/public/activities/ghoul-cart.js"; +import * as sl from "../src/web-console/public/activities/ghoul-sled.js"; +import { EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as TRAY_LOOKS, VOICES as TRAY_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-tray-draw.js"; +import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js"; +import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-draw.js"; +import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-bonus.js"; + +const steady = () => 0.5; +// The pack draws no random number: a run on this fails on the first draw. +const never = () => { + throw new Error("the tray drew a random number"); +}; +const events = (round, type) => round.events.filter((e) => e.type === type); + +function through(round) { + round.phase = "clear"; + round.phaseMs = 1; + ghoul.advance(round, 4, steady); +} + +// A round in the Servants' Back Stairs reached the way play reaches it, nothing woken, the clocks +// long, the bonus round on (five hearts). +function trayRound(seed = 5) { + const round = ghoul.newRound(seed); + round.lives = 3; + round.dice = 0; + through(round); + round.offer = ["wing"]; + round.phaseMs = 0; + ghoul.pickStage(round, 0); + while (round.spec.id !== "tray") through(round); + round.phase = "play"; + for (const st of round.spawns) st.over = true; + round.monsters.length = 0; + round.hordeMs = Infinity; + round.timeMs = 1e9; + round.bonus = 1e9; + round.events.length = 0; + return round; +} + +const NONE = { runner: "tray", time: 1e9, finish: 1e6, track: [], pots: [], lows: [], cooks: [], domes: [], plates: [], grease: [], checks: [] }; +// The same round over a ride of its own (a plain track to measure the tray on). +function synth(ride) { + const round = trayRound(); + round.runner = null; + round.spec = { ...round.spec, start: 10, ground: [[0, 5, 0]], ride: { ...NONE, ...ride } }; + tr.TRAY.place[0](round, {}); + return round; +} +const FLAT = [[[0, 20], [4000, 20]]]; +const DOWN = [[[0, 40], [4000, 40 - 0.15 * 4000]]]; +const UP = [[[0, 0], [4000, 0.3 * 4000]]]; + +// The tray on line `line` of the ride at `x`, at speed `v`. +function trayAt(round, x, line, { v = tr.TRAY_V, safe = false } = {}) { + const y = ct.trackY(round.spec.ride, line, x); + assert.ok(y !== null, `line ${line} runs under ${x}`); + Object.assign(round.you, { x, y, vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false }); + Object.assign(round.runner, { line, v, coyote: 0 }); + round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24)); +} + +function run(round, ms, keys = {}, random = steady) { + Object.assign(round.input, keys); + for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random); + for (const key of Object.keys(keys)) round.input[key] = typeof keys[key] === "number" ? 0 : false; +} + +function until(round, done, ms = 6000, random = steady) { + let t = 0; + for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random); + return t; +} + +const press = (round) => { + round.input.jump = ghoul.JUMP_BUFFER_MS; + round.input.up = true; +}; + +const heard = (e, extra = {}) => { + const played = []; + const noop = () => {}; + const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra }; + react({ x: 10, y: 6, tx: 20, ty: 6, ...e }, kit); + return { played }; +}; + +const ROOM = ghoul.roomById("tray"); +const R = ROOM.ride; +const lines = ct.linesOf(R); +const floorOf = (x) => ghoul.groundAt(ROOM, x); +const slopeAtLine = (L, i) => (L.pts[i + 1][1] - L.pts[i][1]) / (L.pts[i + 1][0] - L.pts[i][0]); + +/* -------------------------------------------------------------- the room */ + +test("Ghoul Rush's Servants' Back Stairs is the East Wing's fourth room, between the Attic and the Crypt: lit, no key, no boss, no pickups, a ride about 60 to 70 seconds long, a bonus round with its own track", () => { + const st = ghoul.stageById("wing"); + assert.deepEqual(st.rooms, ["kitchen", "conservatory", "attic", "tray", "crypt"]); + assert.equal(st.boss, ghoul.roomById("crypt").boss); + assert.deepEqual([ROOM.title, ROOM.sub], ["Last Orders", "Dinner is served. You are dinner"]); + assert.equal(ROOM.dark, false); + assert.equal(ROOM.key, null); + assert.equal(ROOM.boss, null); + assert.equal(ROOM.bonus, true, "a bonus round"); + assert.equal(R.runner, "tray"); + assert.ok(ROOM.length >= 2400 && ROOM.length <= 3400, `${ROOM.length} units long`); + assert.equal(ghoul.ROOM_MUSIC.tray, "ghoulTrayRide"); + assert.ok(ghoulSfx.default.music.ghoulTrayRide, "its own track"); + assert.deepEqual(Object.keys(tr.TRAY.monsters), [], "no new monster kinds"); + assert.equal(LOOKS.tray, TRAY_LOOKS.tray); + assert.equal(LOOKS.tray.pack, "tray"); + assert.ok(Object.isFrozen(R) && Object.isFrozen(R.track) && Object.isFrozen(R.track[0][0]) && Object.isFrozen(R.domes[0]), "frozen all the way down"); + assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0 && ROOM.items.length === 0, "no monsters and no pickups: the things on the route are the pack's own"); + assert.equal(ROOM.ground.length, 2); + assert.ok(ROOM.ground[0][1] < 60 && ROOM.ground[1][0] > ROOM.length - 100, "floor only at the ends"); + assert.equal(ROOM.ground[1][0], R.finish); + assert.ok(ROOM.door > R.finish && ROOM.door > ROOM.length - 14); + assert.ok(floorOf(ROOM.door - 2) > -Infinity, "floor to walk out on"); + for (const L of lines) for (let i = 0; i + 1 < L.pts.length; i++) assert.ok(L.pts[i + 1][0] > L.pts[i][0], "x rises"); + assert.ok(ct.trackY(R, 0, ROOM.start) > floorOf(ROOM.start), "the tray starts over the landing"); + const secs = (lines.at(-1).x1 - ROOM.start) / tr.TRAY_V; + assert.ok(secs >= 62 && secs <= 80, `${secs.toFixed(1)} s at TRAY_V`); + // Every line stays inside the room, clear of the roof and of the fall. + for (const L of lines) for (const [, y] of L.pts) assert.ok(y > 8 && y < 40, `a track height of ${y}`); + // Stairs fall about 0.17, shelves climb about 0.28 or run flat, nothing steeper. + for (const L of lines) { + for (let i = 0; i + 1 < L.pts.length; i++) { + const s = slopeAtLine(L, i); + assert.ok(s >= -0.2 && s <= 0.32, `a slope of ${s.toFixed(3)}`); + } + } + assert.equal(lines.length, 18); + assert.deepEqual([R.pots.length, R.lows.length, R.cooks.length], [16, 11, 4]); + assert.ok(R.domes.length >= 12 && R.plates.length >= 10, "more courses than the seven a meal needs"); + assert.ok(R.domes.length + R.plates.length >= 3 * tr.COURSES_GOAL, "a seven course meal is within reach, not a given"); + assert.ok(R.domes.some(([, , lift]) => lift === 0) && R.domes.some(([, , lift]) => lift >= 5), "some domes on the track, some in the air"); + assert.ok(R.plates.some(([, , lift]) => lift <= 3) && R.plates.some(([, , lift]) => lift >= 4), "plates to shoot standing and from a jump"); + assert.ok(ROOM.candy.length >= 200, "cherries all along"); + assert.match(R.how, /UP to jump, DOWN to duck/); +}); + +test("Ghoul Rush's Servants' Back Stairs: the lip's launch alone carries the tray onto the dining table at any speed it can have there, landing 2 to 40 past its start", () => { + const lip = lines.at(-1); + const end = lip.pts.at(-1); + const rise = ct.slopeOf(R, lines.length - 1, lip.x1); + assert.ok(rise >= tr.RAMP_SLOPE, "the last shelf ends rising"); + const table = floorOf(R.finish + 1); + for (const v of [tr.TRAY_MIN, 34, tr.TRAY_V, 55, tr.GREASE_V, tr.TRAY_MAX]) { + let vy = rise * v + tr.RAMP_POP; + let x = end[0]; + let y = end[1]; + for (let t = 0; t < 3; t += 0.002) { + vy -= tr.TRAY_G * 0.002; + x += v * 0.002; + y += vy * 0.002; + if (vy < 0 && y <= table) break; + } + assert.ok(x >= R.finish + 2 && x <= R.finish + 40, `at ${v} it lands ${x - R.finish} past the table's start`); + } +}); + +test("Ghoul Rush's Servants' Back Stairs: every gap between flights clears with a jump at the edge or a few units early, and a tray that never jumps drops into it", () => { + assert.equal(lines.length - 1, 17, "seventeen gaps"); + for (let i = 0; i + 1 < lines.length - 1; i++) { + const a = lines[i]; + const b = lines[i + 1]; + const gap = b.x0 - a.x1; + assert.ok(gap >= 9 && gap <= 18, `gap ${i} is ${gap} wide`); + const end = a.pts.at(-1); + const slope = ct.slopeOf(R, i, a.x1); + assert.ok(slope < 0, "gaps lie at the foot of a flight (no ramp launch)"); + for (const v of [40, 44, 50, 60]) { + assert.equal(tr.flight(R, a.x1, end[1], slope * v, v), null, `gap ${i}, no jump, at ${v}`); + for (const early of [0, 4]) { + const x = a.x1 - early; + const y = ct.trackY(R, i, x); + const s = tr.flight(R, x, y, tr.TRAY_JUMP_V + ct.slopeOf(R, i, x) * v, v); + assert.ok(s, `gap ${i}: a jump ${early} early at ${v} lands`); + assert.equal(s.line, i + 1, `gap ${i} cleared, at ${v}, ${early} early`); + } + } + } +}); + +// The kit's numbers the room is built to. +function k() { + return { HIT_W: ghoul.HIT_W, HIT_H: ghoul.HIT_H, DUCK_H: ghoul.DUCK_H }; +} + +test("Ghoul Rush's Servants' Back Stairs: every thing is on a line, off the ends, spaced for a player (22 between jumps and 38 between a jump and a duck), greased stretches flat, a low's underside between a ducked box and a standing one", () => { + const jumps = []; + for (const [x, line, kind] of R.pots) { + assert.ok(ct.trackY(R, line, x) !== null, `a pot at ${x} stands on line ${line}`); + jumps.push([x - (kind ? 2.4 : 2), x + (kind ? 2.4 : 2)]); + assert.ok(x - lines[line].x0 > 8 && lines[line].x1 - x > 14, `a pot at ${x} well inside its line`); + } + // A cook's dish meets the tray about 14 to 2 short of him. + for (const [x, line] of R.cooks) { + assert.ok(ct.trackY(R, line, x) !== null); + assert.ok(x - lines[line].x0 > 50 && lines[line].x1 - x > 14, `a cook at ${x} well inside his line`); + jumps.push([x - 14, x - 2]); + } + for (let i = 0; i + 1 < lines.length; i++) jumps.push([lines[i].x1, lines[i + 1].x0]); + const ducks = R.lows.map(([x0, x1]) => [x0, x1]); + jumps.sort((a, b) => a[0] - b[0]); + for (let i = 0; i + 1 < jumps.length; i++) assert.ok(jumps[i + 1][0] - jumps[i][1] >= 22, `jumps at ${jumps[i][1]} and ${jumps[i + 1][0]}`); + for (const [d0, d1] of ducks) { + for (const [j0, j1] of jumps) assert.ok(j0 - d1 >= 38 || d0 - j1 >= 38, `a jump at ${j0} and a duck at ${d0}`); + } + for (let i = 0; i < ducks.length; i++) { + const [x0, x1, y, kind] = R.lows[i]; + assert.ok(kind === 0 || kind === 1); + let hi = 0; + let lo = 99; + for (let x = x0 - k().HIT_W / 2; x <= x1 + k().HIT_W / 2; x += 0.25) { + const g = ct.linesAt(R, x)[0]; + assert.ok(g, "a shelf under a low"); + hi = Math.max(hi, g[1]); + lo = Math.min(lo, g[1]); + } + assert.ok(hi + k().DUCK_H < y, `a ducked box clears the low at ${x0}`); + assert.ok(lo + k().HIT_H > y, `a standing box hits the low at ${x0}`); + for (const [j0, j1] of ducks) if (j0 !== x0) assert.ok(j0 - x1 > 20 || x0 - j1 > 20); + } + // The grease: on flat shelf only, and nothing in it spaced shorter than the faster tray needs (30). + assert.equal(R.grease.length, 5); + for (const [a, b] of R.grease) { + for (let x = a; x <= b; x += 1) { + const line = ct.linesAt(R, x)[0][0]; + assert.equal(ct.slopeOf(R, line, x), 0, `grease at ${x} is on the flat`); + } + const inside = jumps.filter(([j0, j1]) => j1 > a - 30 && j0 < b + 30); + for (let i = 0; i + 1 < inside.length; i++) assert.ok(inside[i + 1][0] - inside[i][1] >= 30, `jumps at ${inside[i][1]} and ${inside[i + 1][0]} on the grease`); + } + // Checkpoints every 300 to 400 units, each on a shelf and clear of a thing. + const cs = R.checks; + for (let i = 0; i < cs.length; i++) { + assert.ok(ct.linesAt(R, cs[i]).length, `checkpoint ${i} on a shelf`); + if (i) assert.ok(cs[i] - cs[i - 1] >= 300 && cs[i] - cs[i - 1] <= 400, `${cs[i] - cs[i - 1]} between checkpoints`); + for (const [j0, j1] of jumps) assert.ok(j0 - cs[i] > 20 || cs[i] - j1 > 4, `a thing at ${j0} near checkpoint ${i}`); + } + assert.ok(cs[0] < 450 && R.finish - cs.at(-1) > 200); +}); + +/* ------------------------------------------------------------ the tray */ + +test("Ghoul Rush's Servants' Back Stairs: the tray rolls at TRAY_V on the flat, GREASE_V on the grease, faster down a flight and slower up a shelf, never past TRAY_MIN or TRAY_MAX, and no key changes it", () => { + const flat = synth({ track: FLAT }); + run(flat, 3000); + assert.ok(Math.abs(flat.runner.v - tr.TRAY_V) < 0.5, `${flat.runner.v} on the flat`); + const slick = synth({ track: FLAT, grease: [[0, 4000]] }); + run(slick, 4000); + assert.ok(Math.abs(slick.runner.v - tr.GREASE_V) < 0.5, `${slick.runner.v} on the grease`); + assert.ok(tr.GREASE_V > tr.TRAY_V + 10, "a real pickup"); + const down = synth({ track: DOWN }); + run(down, 4000); + assert.ok(down.runner.v > tr.TRAY_V && down.runner.v <= tr.TRAY_MAX); + const up = synth({ track: UP }); + run(up, 4000); + assert.ok(up.runner.v < tr.TRAY_V && up.runner.v >= tr.TRAY_MIN); + const keyed = synth({ track: FLAT }); + run(keyed, 3000, { left: true }); + assert.ok(Math.abs(keyed.runner.v - tr.TRAY_V) < 0.5, "left does not brake"); + run(keyed, 1000, { right: true }); + assert.ok(Math.abs(keyed.runner.v - tr.TRAY_V) < 0.5, "right does not lean"); + assert.equal(greasyAt(slick, 100), true); + assert.equal(greasyAt(flat, 100), false); +}); +function greasyAt(round, x) { + return tr.greasy(round.spec.ride, x); +} + +test("Ghoul Rush's Servants' Back Stairs: the tray jumps about 13 high for about three quarters of a second, a press saved for a landing jumps on it, one just after a line's end still jumps", () => { + const round = synth({ track: FLAT }); + press(round); + let peak = 0; + const start = round.you.y; + let t = 0; + for (; t < 2000; t += 4) { + ghoul.advance(round, 4, steady); + peak = Math.max(peak, round.you.y - start); + if (t > 40 && round.runner.line >= 0) break; + } + round.input.up = false; + assert.ok(peak > 12 && peak < 14.5, `${peak} high`); + assert.ok(t > 650 && t < 850, `${t} ms in the air`); + assert.equal(events(round, "trayJump").length, 1); + assert.equal(events(round, "trayLand").length, 1); + const edge = synth({ track: [[[0, 20], [60, 20]], [[75, 20], [400, 20]]] }); + trayAt(edge, 59, 0); + run(edge, 40); + assert.equal(edge.runner.line, -1, "off the end"); + press(edge); + run(edge, 8); + assert.equal(events(edge, "trayJump").length, 1, "the grace jump"); +}); + +test("Ghoul Rush's Servants' Back Stairs: down ducks (and a press of up jumps instead of ducking), a ducked Planny passes under a ham or pans and a standing one hits them (causes ham and pans), at the cost of a heart", () => { + for (const [kind, cause] of [[0, "ham"], [1, "pans"]]) { + const round = synth({ track: FLAT, lows: [[60, 66, 23.0, kind]] }); + run(round, 20, { down: true }); + assert.equal(events(round, "trayDuck").length, 1); + round.input.down = true; + until(round, () => round.you.x > 75, 3000); + round.input.down = false; + assert.equal(round.bonusRound.hearts, 5); + const hit = synth({ track: FLAT, lows: [[60, 66, 23.0, kind]] }); + until(hit, () => hit.bonusRound.hearts < 5, 3000); + assert.equal(hit.bonusRound.hearts, 4); + assert.equal(hit.lives, 3, "not a life"); + assert.equal(events(hit, "lose")[0].cause, cause); + assert.equal(events(hit, "trayCrash")[0].what, cause); + assert.equal(hit.phase, "play", "the ride plays on"); + assert.ok(hit.you.safeMs > 0, "blinking safe"); + assert.deepEqual(hit.bonusRound.perf.hits, ["l0"]); + run(hit, 1000); + assert.equal(hit.bonusRound.hearts, 4, "the same low costs nothing twice"); + } + const jump = synth({ track: FLAT, lows: [[60, 66, 23.0, 0]] }); + trayAt(jump, 40, 0); + press(jump); + until(jump, () => jump.bonusRound.hearts < 5 || jump.you.x > 80, 3000); + assert.equal(jump.bonusRound.hearts, 4, "a jump does not clear a low"); + const both = synth({ track: FLAT }); + both.input.down = true; + press(both); + run(both, 20); + assert.equal(both.you.ducking, false); + assert.equal(events(both, "trayJump").length, 1); +}); + +test("Ghoul Rush's Servants' Back Stairs: a rolling pot and a drop of cutlery are cleared by a jump and cost a heart otherwise (causes pot and cutlery), each only once", () => { + for (const [kind, cause] of [[0, "pot"], [1, "cutlery"]]) { + const hit = synth({ track: FLAT, pots: [[60, 0, kind]] }); + until(hit, () => hit.bonusRound.hearts < 5, 3000); + assert.equal(hit.bonusRound.hearts, 4); + assert.equal(events(hit, "lose")[0].cause, cause); + assert.deepEqual(hit.bonusRound.perf.hits, ["p0"]); + run(hit, 1500); + assert.equal(hit.bonusRound.hearts, 4, "once"); + const clear = synth({ track: FLAT, pots: [[60, 0, kind]] }); + trayAt(clear, 60 - 14, 0); + press(clear); + until(clear, () => clear.you.x > 80, 3000); + assert.equal(clear.bonusRound.hearts, 5, `a jump clears ${cause}`); + } +}); + +test("Ghoul Rush's Servants' Back Stairs: a cook wakes COOK_NEAR short, winds up, flings a dish that flies back along the track (jump it: cause dish otherwise), and one bolt shoots the cook (150 points) or the dish", () => { + const room = () => synth({ track: FLAT, cooks: [[220, 0]] }); + const hit = room(); + trayAt(hit, 100, 0); + until(hit, () => hit.runner.cooks[0].state === "up", 3000); + assert.ok(hit.runner.cooks[0].state === "up" && 220 - hit.you.x <= tr.COOK_NEAR && 220 - hit.you.x > tr.COOK_NEAR - 6); + assert.equal(events(hit, "trayCookUp").length, 1); + until(hit, () => hit.runner.cooks[0].dish, 1500); + assert.equal(events(hit, "trayToss").length, 1); + assert.ok(hit.runner.cooks[0].dish.x < 220); + until(hit, () => hit.bonusRound.hearts < 5, 3000); + assert.equal(hit.bonusRound.hearts, 4); + assert.equal(events(hit, "lose")[0].cause, "dish"); + assert.deepEqual(hit.bonusRound.perf.hits, ["c0"]); + assert.equal(hit.runner.cooks[0].dish, null, "the dish is spent"); + // A jump as it comes clears it. + const jump = room(); + trayAt(jump, 100, 0); + for (let t = 0; t < 6000 && jump.you.x < 240; t += 4) { + const d = jump.runner.cooks[0].dish; + if (d && d.x - jump.you.x < 14 && d.x - jump.you.x > 4 && jump.runner.line >= 0) press(jump); + ghoul.advance(jump, 4, steady); + } + jump.input.up = false; + assert.equal(jump.bonusRound.hearts, 5, "jumped"); + // The cook shot while winding up: 150 points, no dish ever. + const shoot = room(); + trayAt(shoot, 100, 0); + const score = shoot.score; + shoot.input.fire = true; + until(shoot, () => shoot.runner.cooks[0].state === "broken", 3000); + shoot.input.fire = false; + assert.equal(shoot.runner.cooks[0].state, "broken"); + assert.equal(events(shoot, "trayCookHit")[0].points, tr.COOK_POINTS); + assert.ok(shoot.score - score >= tr.COOK_POINTS); + run(shoot, 3000); + assert.equal(shoot.bonusRound.hearts, 5, "no dish"); + assert.equal(events(shoot, "trayToss").length, 0); + // A dish shot out of the air breaks (nothing scored). + const dish = room(); + trayAt(dish, 100, 0); + until(dish, () => dish.runner.cooks[0].dish, 3000); + dish.runner.cooks[0].state = "spent"; + dish.input.fire = true; + until(dish, () => !dish.runner.cooks[0].dish, 1500); + dish.input.fire = false; + assert.equal(events(dish, "trayDishBreak").length, 1); + assert.equal(dish.bonusRound.perf.acts, 0, "not a course"); +}); + +test("Ghoul Rush's Servants' Back Stairs: running through a dome serves a course (80 points; a high one takes a jump), and a plate is served by a bolt, not by touching it (120 points)", () => { + const round = synth({ track: FLAT, domes: [[60, 0, 0], [100, 0, 7]] }); + const score = round.score; + until(round, () => round.runner.domes[0], 3000); + assert.equal(round.runner.domes[0], true); + assert.equal(round.runner.served, 1); + assert.equal(round.bonusRound.perf.acts, 1); + assert.equal(events(round, "trayDome")[0].n, 1); + assert.equal(events(round, "trayDome")[0].points, tr.DOME_POINTS); + assert.ok(round.score - score >= tr.DOME_POINTS); + until(round, () => round.you.x > 130, 3000); + assert.equal(round.runner.domes[1], false, "a high dome is not run through"); + const hop = synth({ track: FLAT, domes: [[100, 0, 7]] }); + trayAt(hop, 92, 0); + press(hop); + until(hop, () => hop.runner.domes[0] || hop.you.x > 130, 3000); + hop.input.up = false; + assert.equal(hop.runner.domes[0], true, "a jump takes a high dome"); + // A plate: touching it, even jumping through it, serves nothing. + const touch = synth({ track: FLAT, plates: [[100, 0, 2.4]] }); + trayAt(touch, 86, 0); + press(touch); + until(touch, () => touch.you.x > 130, 3000); + touch.input.up = false; + assert.equal(touch.runner.plates[0], false); + assert.equal(touch.runner.served, 0); + // Shot with a standing bolt, it is served. + const shot = synth({ track: FLAT, plates: [[100, 0, 2.4]] }); + shot.input.fire = true; + until(shot, () => shot.runner.plates[0], 3000); + shot.input.fire = false; + assert.equal(shot.runner.plates[0], true); + assert.equal(shot.runner.served, 1); + assert.equal(events(shot, "trayPlate")[0].points, tr.PLATE_POINTS); + assert.equal(shot.bonusRound.perf.acts, 1); + // A high plate needs a bolt from a jump: a standing bolt flies under it. + const high = synth({ track: FLAT, plates: [[100, 0, 6]] }); + high.input.fire = true; + until(high, () => high.you.x > 130, 3000); + assert.equal(high.runner.plates[0], false, "a level bolt flies under it"); + // What is eaten stays eaten after a restart in the same room. + const again = synth({ track: FLAT, domes: [[60, 0, 0]] }); + again.runner.domes[0] = true; + again.runner.served = 1; + again.runner.check = -1; + tr.TRAY.place[0](again, {}); + assert.equal(again.runner.domes[0], true); + assert.equal(again.runner.served, 1); +}); + +test("Ghoul Rush's Servants' Back Stairs: bolts follow the stairs (the same height over the track on a descent)", () => { + const probe = synth({ track: DOWN }); + probe.input.fire = true; + run(probe, 300); + probe.input.fire = false; + assert.ok(probe.shots.length > 0); + for (const s of probe.shots) { + const over = s.y - (40 - 0.15 * s.x); + assert.ok(Math.abs(over - ghoul.SHOT_Y) < 0.5, `a bolt ${over.toFixed(2)} over the track`); + } + assert.equal(probe.bonusRound.perf.acts, 0); +}); + +test("Ghoul Rush's Servants' Back Stairs: a gap with no jump is a heart (cause tumble), the tray goes back on the shelf ahead at TRAY_V and rolls on; a jump over it costs nothing", () => { + const gap = [[[0, 20], [60, 20]], [[75, 20], [400, 20]]]; + const fall = synth({ track: gap }); + trayAt(fall, 30, 0); + until(fall, () => fall.bonusRound.hearts < 5, 3000); + assert.equal(fall.bonusRound.hearts, 4); + assert.equal(events(fall, "lose")[0].cause, "tumble"); + assert.equal(fall.phase, "play"); + assert.equal(fall.lives, 3); + until(fall, () => fall.runner.line === 1 && fall.you.x > 90, 3000); + assert.equal(fall.runner.line, 1, "back on the shelf ahead"); + assert.equal(fall.bonusRound.hearts, 4); + const hop = synth({ track: gap }); + trayAt(hop, 30, 0); + run(hop, 500); + press(hop); + run(hop, 20); + hop.input.up = false; + until(hop, () => hop.you.x > 100, 3000); + assert.equal(hop.bonusRound.hearts, 5, "jumped"); +}); + +test("Ghoul Rush's Servants' Back Stairs: the last heart gone ends the round with nothing at once (no life lost, the dice in hand kept) and the run goes on to the Crypt", () => { + const round = trayRound(); + round.dice = 2; + round.bonusRound.hearts = 1; + trayAt(round, lines[0].x1 - 6, 0); + round.you.safeMs = 0; + until(round, () => round.phase === "clear", 6000); + assert.equal(round.bonusRound.hearts, 0); + assert.equal(round.bonusRound.over, true); + assert.equal(round.bonusRound.won, false); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.deepEqual([end[0].won, end[0].dice], [false, 0]); + assert.equal(round.over, false, "no game over"); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + run(round, ghoul.CARD_LOST_MS + 100); + assert.equal(round.spec.id, "crypt"); + assert.equal(round.bonusRound, null); + assert.equal(round.runner, null); + assert.equal(round.lives, 3); + assert.equal(round.dice, 2); + assert.equal(round.phase, "bossintro", "the boss room opens on its card"); + skipBossIntro(ghoul, round); + assert.equal(round.phase, "ready"); +}); + +test("Ghoul Rush's Servants' Back Stairs: the checkpoints are passed in order (an event each) and the ride goes back to the last one after the last heart's restart", () => { + const round = trayRound(); + const first = R.checks[0]; + const li = ct.linesAt(R, first)[0][0]; + trayAt(round, first - 3, li, { safe: true }); + until(round, () => round.runner.check === 0, 1000); + assert.equal(round.runner.check, 0); + assert.equal(events(round, "trayCheck")[0].n, 1); + trayAt(round, R.checks[1] - 3, ct.linesAt(R, R.checks[1])[0][0], { safe: true }); + until(round, () => round.runner.check === 1, 1000); + assert.equal(round.runner.check, 1); + tr.TRAY.place[0](round, {}); + assert.equal(round.you.x, R.checks[1], "back at the last checkpoint passed"); + assert.equal(round.runner.check, 1); +}); + +test("Ghoul Rush's Servants' Back Stairs: off the lip the tray launches, lands on the table and stops (trayFinish), the door opens, and walking out ends the round with 3 to 9 Lucky dice", () => { + const round = trayRound(); + round.dice = 1; + const last = lines.length - 1; + trayAt(round, lines[last].x1 - 12, last, { safe: true }); + until(round, () => round.runner.done, 4000); + assert.equal(round.runner.done, true); + assert.equal(events(round, "trayLaunch").length, 1); + assert.equal(events(round, "trayLaunch")[0].last, true); + assert.equal(events(round, "trayFinish").length, 1); + assert.ok(round.you.x > R.finish + 4 && round.you.x < R.finish + 40, `${round.you.x} landed`); + assert.equal(round.you.y, floorOf(round.you.x)); + assert.equal(round.hasKey, true, "the door opens"); + assert.equal(round.phase, "play"); + round.input.right = true; + until(round, () => round.phase === "clear", 20000); + round.input.right = false; + assert.equal(round.phase, "clear"); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, true); + assert.ok(end[0].dice >= BONUS_FLOOR && end[0].dice <= ghoul.MAX_DICE, `${end[0].dice} dice`); + assert.equal(round.dice, Math.min(ghoul.MAX_DICE, 1 + end[0].dice)); + assert.equal(round.lives, 3); + run(round, ghoul.CARD_MS + 100); + assert.equal(round.spec.id, "crypt"); + assert.equal(round.runner, null); +}); + +test("Ghoul Rush's Servants' Back Stairs: no random number is drawn in the room (a ride of 20 seconds, jumping and shooting, on a draw that throws)", () => { + const round = trayRound(); + trayAt(round, 120, 1, { safe: true }); + round.input.fire = true; + for (let t = 0; t < 20000; t += 4) { + if (t % 1500 === 0) press(round); + ghoul.advance(round, 4, never); + round.events.length = 0; + round.you.safeMs = 1e9; + if (round.phase !== "play") break; + } + assert.ok(round.you.x > 600); +}); + +/* ----------------------------------------------------------- the grade */ + +test("Ghoul Rush's Servants' Back Stairs' grade: the dice formula, a seven course meal for the die, and the cherries die (45% of them)", () => { + const round = trayRound(); + const b = round.bonusRound; + assert.equal(b.perf.goal, tr.COURSES_GOAL); + assert.equal(tr.COURSES_GOAL, 7); + assert.equal(b.perf.total, R.pots.length + R.lows.length + R.cooks.length + lines.length - 1); + assert.equal(b.perf.steady, false, "no cherries yet"); + const mk = (perf) => { + const x = makeBonus({ stats: { kills: 0 } }); + Object.assign(x.perf, { total: b.perf.total, goal: tr.COURSES_GOAL }, perf); + return x; + }; + assert.equal(diceFor(mk({ hits: [], acts: 7, steady: true })), 9, "a perfect, hungry ride"); + assert.equal(diceFor(mk({ hits: [], acts: 6, steady: true })), 8, "a sixth course short"); + assert.equal(diceFor(mk({ hits: [], acts: 7, steady: false })), 8, "no cherries"); + assert.equal(diceFor(mk({ hits: [], acts: 0, steady: false })) >= BONUS_FLOOR, true); + const hit = mk({ hits: R.pots.map((_, i) => `p${i}`), acts: 0, steady: false }); + hit.hearts = 1; + assert.equal(diceFor(hit), BONUS_FLOOR + Math.round((2 * (b.perf.total - R.pots.length)) / b.perf.total), "hit a lot, no courses"); + // Courses reach the grade as they are served. + const meal = synth({ track: FLAT, domes: Array.from({ length: 8 }, (_, i) => [40 + i * 12, 0, 0]) }); + until(meal, () => meal.runner.served >= 7, 4000); + assert.equal(meal.bonusRound.perf.acts, 7); + // Cherries: 45% of the room's. + const goal = Math.ceil(tr.CHERRY_SHARE * round.candy.length); + trayAt(round, 60, 0, { safe: true }); + for (let i = 0; i < goal - 1; i++) round.candy[i] = true; + run(round, 500); + assert.equal(b.perf.steady, false, "one cherry short"); + round.candy[goal - 1] = true; + run(round, 500); + assert.equal(b.perf.steady, true, "enough cherries"); +}); + +test("Ghoul Rush's Servants' Back Stairs: endless lives (round.infinite) spare the hearts for every cause, through the same lose path", () => { + const tries = [ + { pots: [[60, 0, 0]] }, { pots: [[60, 0, 1]] }, { lows: [[56, 62, 23.0, 0]] }, { lows: [[56, 62, 23.0, 1]] }, { cooks: [[170, 0]] }, + ]; + for (const t of tries) { + const r = synth({ track: FLAT, ...t }); + r.infinite = true; + if (t.cooks) trayAt(r, 100, 0); + until(r, () => events(r, "lose").length > 0, 6000); + assert.ok(events(r, "lose").length > 0, JSON.stringify(Object.keys(t))); + assert.equal(r.bonusRound.hearts, 5, JSON.stringify(Object.keys(t))); + assert.equal(r.lives, 3); + } + const crack = synth({ track: [[[0, 20], [60, 20]], [[75, 20], [400, 20]]] }); + crack.infinite = true; + trayAt(crack, 30, 0); + until(crack, () => events(crack, "lose").length > 0, 3000); + assert.equal(crack.bonusRound.hearts, 5); + assert.equal(crack.lives, 3); +}); + +test("Ghoul Rush's Servants' Back Stairs: the Garlic shield takes a hit instead of a heart", () => { + const round = synth({ track: FLAT, pots: [[60, 0, 0]] }); + round.you.garlic = true; + until(round, () => round.you.x > 70, 3000); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.you.garlic, false, "spent"); +}); + +/* ------------------------------------------------------ sounds and words */ + +test("Ghoul Rush's Servants' Back Stairs: every event has a voice that plays, every cause has words and a sound, and every tone exists and is at most 1.2 s", () => { + assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...tr.EVENTS].sort(), "a voice for every event and no more"); + for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) { + const name = TRAY_VOICES[kind] && TRAY_VOICES[kind][act]; + assert.ok(name, `${event} has a ${kind}.${act} voice`); + assert.ok(ghoulSfx.default.tones[name], `${name} exists`); + assert.equal(VOICES[kind][act], name, "joined to the game's voices"); + assert.ok(heard({ type: event, what: "pot", points: 50 }).played.includes(name), `${event} plays ${name}`); + const len = Math.max(...ghoulSfx.default.tones[name].layers.map((l) => (l.delay || 0) + l.seconds)); + assert.ok(len <= 1.2, `${name} is ${len} s`); + } + for (const cause of ["pot", "cutlery", "ham", "pans", "dish", "tumble"]) { + assert.ok(LOSE_WORDS[cause], `${cause} has words`); + assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`); + assert.ok(heard({ type: "lose", cause, hearts: 3 }).played.length > 0, `${cause} sounds`); + } + assert.equal(heard({ type: "trayJump" }).played.length, 1); + assert.equal(heard({ type: "trayPlate", points: 120, n: 3 }).played.length, 1); +}); + +test("Ghoul Rush's Servants' Back Stairs: the room's own names do not collide with the game's (events, kinds), and the music is a real track", () => { + for (const e of tr.EVENTS) assert.ok(e.startsWith("tray"), e); + const other = new Set(); + for (const pack of [ct, sl]) for (const e of pack.EVENTS || []) other.add(e); + for (const e of tr.EVENTS) assert.ok(!other.has(e), `${e} is the tray's alone`); + assert.deepEqual(Object.keys(tr.TRAY).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []); + const music = ghoulSfx.default.music.ghoulTrayRide; + for (const part of Object.values(music.patterns)) { + for (const row of Object.values(part)) assert.equal(row.split("|").length, 4, "four bars a pattern"); + } + assert.ok(music.order.every((p) => music.patterns[p])); +}); + +/* --------------------------------------------------------------- drawing */ + +test("Ghoul Rush's Servants' Back Stairs draws: the room in a lit and a dark one, the tray on the shelf, in the air and ducking, each thing (pots, cutlery, hams, pans, cooks in each state, a dish, domes and plates whole and taken), a crash, the finish and the cards", () => { + const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) }); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + g.resize(900, 900); + g.key("action"); + g.tick(16); + const r = g.round; + through(r); + r.offer = ["wing"]; + r.phaseMs = 0; + ghoul.pickStage(r, 0); + while (r.spec.id !== "tray") through(r); + r.lives = 99; + const pot = R.pots.find((p) => !p[2]); + const cutlery = R.pots.find((p) => p[2]); + const spots = [ROOM.start + 40, pot[0] - 10, cutlery[0] - 10, R.lows[0][0] - 5, R.lows[3][0] - 5, R.cooks[0][0] - 30, R.domes[3][0] - 8, R.plates[3][0] - 8, R.checks[0], lines[0].x1 - 10, R.grease[0][0] + 10, R.finish - 40]; + for (const dark of [true, false]) { + for (const x of spots) { + r.dark = dark; + r.phase = "play"; + for (const st of r.spawns) st.over = true; + r.hordeMs = Infinity; + r.monsters.length = 0; + const top = ct.linesAt(R, x)[0] || [lines.length - 1, 20]; + trayAt(r, x, top[0], { safe: true }); + r.runner.cooks = r.runner.cooks.map((c, i) => ({ ...c, state: ["down", "up", "toss", "spent", "broken"][i % 5], t: 600, dish: i % 2 ? { x: x + 20, y: top[1] + 1.6 } : null })); + r.runner.domes = r.runner.domes.map((_, i) => i % 3 === 0); + r.runner.plates = r.runner.plates.map((_, i) => i % 4 === 0); + for (const air of [false, true]) { + if (air) Object.assign(r.you, { state: "air", vy: 20, y: r.you.y + 4 }); + if (air) r.runner.line = -1; + r.you.ducking = x === R.lows[0][0] - 5 && !air; + r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: -10, gone: 0 }); + for (let n = 0; n < 4; n++) g.tick(16); + r.monsters.length = 0; + r.you.safeMs = 1e9; + trayAt(r, x, top[0], { safe: true }); + } + } + } + assert.equal(r.spec.id, "tray"); + r.you.safeMs = 0; + trayAt(r, R.pots[2][0] - 3, R.pots[2][1]); + for (let n = 0; n < 30; n++) g.tick(16); + assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too"); + const done = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + done.resize(900, 900); + done.key("action"); + done.tick(16); + const d = done.round; + through(d); + d.offer = ["wing"]; + d.phaseMs = 0; + ghoul.pickStage(d, 0); + while (d.spec.id !== "tray") through(d); + d.phase = "play"; + d.runner.done = true; + d.runner.restX = R.finish + 20; + Object.assign(d.you, { x: R.finish + 30, y: 10, state: "run" }); + d.camX = R.finish - 40; + for (let n = 0; n < 10; n++) done.tick(16); + for (const won of [true, false]) { + endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) }); + d.bonusRound.over = true; + for (let n = 0; n < 10; n++) { + done.tick(16); + bonusTick(d, { tone() {}, fx: {} }); + } + d.bonusRound.over = false; + } + // The stage select goes straight into it. + const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + pick.resize(900, 900); + pick.stageSelect(); + const p = pick.round; + const at = ghoul.STAGES.findIndex((s) => s.id === "wing"); + for (let i = 0; i < at; i++) ghoul.steerSelect(p, 1, 0); + for (let i = 0; i < 3; i++) ghoul.steerSelect(p, 0, 1); + assert.equal(p.select.room, 3); + pick.tick(16); + ghoul.takeSelect(p); + assert.equal(p.spec.id, "tray"); + assert.equal(p.runner.line, 0); + assert.equal(p.you.y, ct.trackY(R, 0, ROOM.start)); + pick.tick(16); +}); + +/* ----------------------------------------------------------- the bots */ + +const mix = (a, b) => { + let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +// A bot that dodges well: it jumps at the end of a line (not the lip), 9 to 15 short of a pot or a +// piece of cutlery and as a dish comes, jumps for the high domes, ducks under every low, and holds +// the blaster. `miss` is the share of things it fails to dodge (by a hash). +function goodBot(round, seed, miss = 0.04) { + const { you, runner: c, input: inp } = round; + inp.left = inp.right = inp.down = false; + inp.fire = true; + if (round.phase !== "play" || !c || c.done) { + inp.up = false; + return; + } + const ok = (x) => mix(seed, Math.round(x)) >= miss; + const look = 9 + (seed % 7); + let jump = false; + if (c.line >= 0) { + const last = c.line === lines.length - 1; + if (!last && lines[c.line].x1 - you.x < 2.2 && ok(lines[c.line].x1)) jump = true; + const ahead = (x) => x - you.x > 6 && x - you.x < look; + for (const [x] of R.pots) if (ahead(x) && ok(x)) jump = true; + R.cooks.forEach((_, i) => { + const d = c.cooks[i].dish; + if (d && d.x - you.x > 4 && d.x - you.x < 12 && ok(d.x)) jump = true; + }); + R.domes.forEach(([x, , lift], i) => { + if (lift > 0 && !c.domes[i] && ahead(x - 3)) jump = true; + }); + for (const [x0, x1] of R.lows) if (you.x > x0 - 10 && you.x < x1 + 3 && ok(x0)) inp.down = true; + } + if (jump && !inp.down) press(round); + else inp.up = false; +} +function idleBot(round) { + const inp = round.input; + inp.left = inp.right = inp.down = false; + inp.up = false; + inp.fire = true; +} +function rideWith(seed, bot, limit = 100000) { + const round = trayRound(seed); + const lost = []; + let t = 0; + for (; t < limit && round.phase !== "clear" && !round.over; t += 16) { + bot(round); + if (round.runner && round.runner.done && round.phase === "play") round.input.right = true; + ghoul.advance(round, 16, steady); + for (const e of round.events) if (e.type === "lose") lost.push(e.cause); + if (round.runner && !round.runner.done) { + const off = round.you.x - round.camX; + assert.ok(off > 4 && off < 70, `the tray stays in view (${off.toFixed(1)} from the left edge at ${round.you.x.toFixed(0)})`); + } + round.events.length = 0; + } + return { round, lost, ms: t }; +} + +test("Ghoul Rush's Servants' Back Stairs: a bot that dodges well finishes the whole route in 60 to 76 seconds, 6 to 9 dice, a seven course meal, past every checkpoint", () => { + const dice = []; + for (let seed = 1; seed <= 12; seed++) { + const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed)); + const b = round.bonusRound; + assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")})`); + assert.ok(ms > 60000 && ms < 76000, `${ms} ms`); + assert.ok(b.dice >= 6 && b.dice <= ghoul.MAX_DICE, `${b.dice} dice`); + assert.ok(round.runner.served >= tr.COURSES_GOAL, `${round.runner.served} courses`); + assert.equal(round.lives, 3, "never a run life"); + assert.equal(round.runner.check, R.checks.length - 1, "past every checkpoint"); + dice.push(b.dice); + } + assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 7, `${dice.join(",")}`); +}); + +test("Ghoul Rush's Servants' Back Stairs: a bot that never dodges (holding fire) loses all five hearts before the first third, ends with 0 dice and the run goes on", () => { + for (let seed = 1; seed <= 6; seed++) { + const { round, lost } = rideWith(seed, idleBot); + const b = round.bonusRound; + assert.equal(b.won, false, "never finishes"); + assert.equal(b.dice, 0); + assert.equal(b.hearts, 0); + assert.equal(lost.length, 5); + assert.ok(round.you.x < ROOM.length * 0.4, `out at ${round.you.x}`); + assert.equal(round.lives, 3); + assert.equal(round.over, false); + } +}); + +/* ------------------------------------------------------------ telegraphs */ + +test("Ghoul Rush's Servants' Back Stairs telegraphs: DUCK over hams and pans, JUMP over gaps, pots and cutlery, SHOOT for cooks, none for domes or plates, words only on the first three of each kind, the same every time", () => { + const marks = telegraphMarks(R); + const answers = { gap: "JUMP", pot: "JUMP", cutlery: "JUMP", ham: "DUCK", pans: "DUCK", cook: "SHOOT" }; + assert.equal(marks.length, lines.length - 1 + R.pots.length + R.lows.length + R.cooks.length, "one per obstacle, none for the courses"); + for (const m of marks) assert.equal(m.answer, answers[m.kind], m.kind); + const first = R.lows.find((l) => !l[3]); + const m = marks.find((q) => q.x === (first[0] + first[1]) / 2); + assert.equal(m.kind, "ham"); + const xs = [m.lead - 45, m.lead - 41, m.lead - 36, m.lead - 30, m.lead - 10, m.lead, m.lead + 3, m.lead + 7]; + const alphaOf = (x) => (telegraphs(R, x).find((t) => t.kind === "ham" && t.lead === m.lead) || { alpha: 0 }).alpha; + const a = xs.map(alphaOf); + assert.equal(a[0], 0, "not yet in view"); + assert.ok(a[2] > 0 && a[2] < 1, "fading in 40 to 30 ahead"); + assert.equal(a[3], 1); + assert.equal(a[4], 1); + assert.ok(a[6] > 0 && a[6] < 1, "fading as it passes"); + assert.equal(a[7], 0, "gone once passed"); + assert.deepEqual(telegraphs(R, m.lead - 33), telegraphs(R, m.lead - 33), "deterministic"); + for (const kind of ["gap", "pot", "cutlery", "ham", "pans", "cook"]) { + const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead); + assert.ok(of.length >= 3, kind); + of.forEach((q, i) => { + assert.equal(q.n, i); + const shown = telegraphs(R, q.lead - 32).find((t) => t.lead === q.lead); + assert.equal(shown.words, i < 3, `${kind} ${i}`); + }); + } +}); + +test("Ghoul Rush's Servants' Back Stairs' intro banner says the controls plainly", () => { + assert.match(R.how, /UP to jump, DOWN to duck, hold space to shoot/); +}); diff --git a/scripts/test-web-console-activities-ghoul-village.mjs b/scripts/test-web-console-activities-ghoul-village.mjs index 9e3810b..d65a33c 100644 --- a/scripts/test-web-console-activities-ghoul-village.mjs +++ b/scripts/test-web-console-activities-ghoul-village.mjs @@ -89,7 +89,7 @@ const heard = (e, extra = {}) => { test("Ghoul Rush's Hollow End Village is a stage of three rooms and the Green, its monsters and boss joined to the game's, with a power-up of its own, a moon that rises and a place for each kind", () => { const st = ghoul.stageById("village"); - assert.deepEqual(st.rooms, ROOM_IDS); + assert.deepEqual(st.rooms, ["street", "inn", "square", "wagon", "green"], "the Torch Mob bonus ride sits before the Green"); assert.equal(st.boss, "beast"); assert.equal(st.title, "Hollow End Village"); assert.equal(st.sub, "Every curtain twitches as you pass"); @@ -98,7 +98,7 @@ test("Ghoul Rush's Hollow End Village is a stage of three rooms and the Green, i assert.equal(vl.BOSSES.beast.sub, "Shoot it while it clings to the wall"); assert.ok(ghoul.MONSTERS.villager.hp === 3 && ghoul.MONSTERS.hanged.hp === 3 && ghoul.MONSTERS.shutter.hp === 2 && ghoul.BOSSES.beast.hp === 110); for (const id of st.rooms) assert.ok(ghoul.ROOM_MUSIC[id], `${id} has music`); - const [street, inn, square, green] = st.rooms.map((id) => ghoul.roomById(id)); + const [street, inn, square, , green] = st.rooms.map((id) => ghoul.roomById(id)); const returning = ["zombie", "bat", "crow", "hound", "ghost"]; for (const room of [street, inn, square]) { assert.ok(room.key, `${room.id}: a key`); diff --git a/scripts/test-web-console-activities-ghoul-wagon.mjs b/scripts/test-web-console-activities-ghoul-wagon.mjs new file mode 100644 index 0000000..14a4c22 --- /dev/null +++ b/scripts/test-web-console-activities-ghoul-wagon.mjs @@ -0,0 +1,1157 @@ +// Web console tests, Ghoul Rush's Torch Mob (Hollow End Village's bonus round, between the Square and the Green): its shape (every ditch and the bridge clear with a jump and swallow a wagon that does not jump, every low can be ducked, spacing, checkpoints), the wagon's speed (the brake that is also a duck), every obstacle's cost and cause (barrels, crates, washing lines, inn signs, pitchforks, torches, horses, ditches, the river, the mob), the throwers' wind-up and aim, shooting torches and forks out of the air, the horses, the pursuit meter (the gap that clean riding opens and braking, hits and fire close), the hay fire, the catch, hearts of its own, the grade and the dice, endless lives, the checkpoints, the finish, no random numbers, its sounds and its drawing on a fake canvas, and bots that play it well and badly. +// Run with: node --test scripts/test-web-console-activities-ghoul-wagon.mjs +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import * as wg from "../src/web-console/public/activities/ghoul-wagon.js"; +import * as ct from "../src/web-console/public/activities/ghoul-cart.js"; +import { ANSWERS, EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as WAGON_LOOKS, VOICES as WAGON_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-wagon-draw.js"; +import * as ghoulSfx from "../src/web-console/public/activities/ghoul-sfx.js"; +import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-draw.js"; +import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-bonus.js"; + +const steady = () => 0.5; +// The pack draws no random number: a run on this fails on the first draw. +const never = () => { + throw new Error("the wagon drew a random number"); +}; +const events = (round, type) => round.events.filter((e) => e.type === type); + +function through(round) { + round.phase = "clear"; + round.phaseMs = 1; + ghoul.advance(round, 4, steady); +} + +// A round in the Torch Mob reached the way play reaches it, nothing woken, the clocks long, +// the bonus round on (five hearts). +function wagonRound(seed = 5) { + const round = ghoul.newRound(seed); + round.lives = 3; + round.dice = 0; + through(round); + round.offer = ["village"]; + round.phaseMs = 0; + ghoul.pickStage(round, 0); + while (round.spec.id !== "wagon") through(round); + round.phase = "play"; + for (const st of round.spawns) st.over = true; + round.monsters.length = 0; + round.hordeMs = Infinity; + round.timeMs = 1e9; + round.bonus = 1e9; + round.events.length = 0; + return round; +} + +const NONE = { runner: "wagon", time: 1e9, finish: 1e6, track: [], blocks: [], lows: [], throwers: [], horses: [], checks: [], surge: [] }; +// The same round over a ride of its own (a plain road to measure the wagon on). +function synth(ride) { + const round = wagonRound(); + round.spec = { ...round.spec, start: 10, ground: [[0, 5, 0]], ride: { ...NONE, ...ride } }; + wg.WAGON.place[0](round, {}); + return round; +} +const FLAT = [[[0, 20], [6000, 20]]]; + +// The wagon on line `line` of the ride at `x`, at speed `v`. +function wagonAt(round, x, line, { v = wg.WAGON_V, safe = false } = {}) { + const y = ct.trackY(round.spec.ride, line, x); + assert.ok(y !== null, `line ${line} runs under ${x}`); + Object.assign(round.you, { x, y, vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false }); + Object.assign(round.runner, { line, v, coyote: 0 }); + round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24)); +} + +function run(round, ms, keys = {}, random = steady) { + Object.assign(round.input, keys); + for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random); + for (const k of Object.keys(keys)) round.input[k] = typeof keys[k] === "number" ? 0 : false; +} + +function until(round, done, ms = 6000, random = steady) { + let t = 0; + for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random); + return t; +} + +const press = (round) => { + round.input.jump = ghoul.JUMP_BUFFER_MS; + round.input.up = true; +}; + +const heard = (e, extra = {}) => { + const played = []; + const noop = () => {}; + const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, ...extra }; + react({ x: 10, y: 6, tx: 20, ty: 6, ...e }, kit); + return { played }; +}; + +const ROOM = ghoul.roomById("wagon"); +const R = ROOM.ride; +const lines = ct.linesOf(R); +const floorOf = (x) => ghoul.groundAt(ROOM, x); +const FINISH_LINE = lines.length - 1; +const BRIDGE_LINE = lines.findIndex((L, i) => i + 1 < lines.length && L.x1 >= R.bridge[0] && L.x1 <= R.bridge[1]); +const isBridgeGap = (i) => i === BRIDGE_LINE; + +// The kit's numbers the room is built to. +const K = { HIT_W: ghoul.HIT_W, HIT_H: ghoul.HIT_H, DUCK_H: ghoul.DUCK_H }; + +/* -------------------------------------------------------------- the room */ + +test("Ghoul Rush's Torch Mob is Hollow End Village's fourth room, between the Square and the Green: lit, no key, no boss, no pickups, a ride about 60 to 75 seconds long, a bonus round that plays its own track", () => { + const st = ghoul.stageById("village"); + assert.deepEqual(st.rooms, ["street", "inn", "square", "wagon", "green"]); + assert.equal(st.rooms.indexOf("wagon"), st.rooms.length - 2, "just before the boss"); + assert.deepEqual([ROOM.title, ROOM.sub], ["Torch Mob", "Hollow End sends its regards. Loudly"]); + assert.equal(ROOM.dark, false, "a moonlit night, always lit"); + assert.equal(ROOM.key, null); + assert.equal(ROOM.boss, null); + assert.equal(ROOM.bonus, true, "a bonus round"); + assert.equal(R.runner, "wagon"); + assert.equal(R.sled, undefined); + assert.ok(ROOM.length >= 2400 && ROOM.length <= 3000, `${ROOM.length} units long`); + assert.equal(ghoul.ROOM_MUSIC.wagon, "ghoulWagonRide"); + assert.ok(ghoulSfx.default.music.ghoulWagonRide, "its own track"); + assert.deepEqual(Object.keys(wg.WAGON.monsters), [], "no new monster kinds"); + assert.equal(LOOKS.wagon, WAGON_LOOKS.wagon); + assert.equal(LOOKS.wagon.pack, "wagon"); + assert.ok(Object.isFrozen(R) && Object.isFrozen(R.track) && Object.isFrozen(R.track[0][0]) && Object.isFrozen(R.blocks[0]), "frozen all the way down"); + assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0, "no monsters: the things on the road are the pack's own"); + assert.deepEqual([ROOM.candy.length, ROOM.items.length], [0, 0], "no pickups"); + // The ground is the cobbles at the start and the green at the end only. + assert.equal(ROOM.ground.length, 2); + assert.ok(ROOM.ground[0][1] < 60 && ROOM.ground[1][0] > ROOM.length - 150, "floor only at the ends"); + assert.equal(ROOM.ground[1][0], R.finish); + assert.ok(ROOM.door > R.finish && ROOM.door > ROOM.length - 14, "the door at the room's end, past the green's start"); + assert.ok(floorOf(ROOM.door - 2) > -Infinity, "floor to walk out on"); + // Lines run left to right, their points rising in x; the first starts under the wagon. + for (const L of lines) for (let i = 0; i + 1 < L.pts.length; i++) assert.ok(L.pts[i + 1][0] > L.pts[i][0], "x rises"); + assert.ok(ct.trackY(R, 0, ROOM.start) > floorOf(ROOM.start), "the wagon starts on the road over the cobbles"); + // The ride, at the wagon's speed, takes 60 to 75 seconds. + const secs = (lines.at(-1).x1 - ROOM.start) / wg.WAGON_V; + assert.ok(secs >= 60 && secs <= 75, `${secs.toFixed(1)} s at WAGON_V`); + // The road is flat but for the bridge's hump, ramp and far side; never steep but at the two ramps. + for (const L of lines) { + for (let i = 0; i + 1 < L.pts.length; i++) { + const s = (L.pts[i + 1][1] - L.pts[i][1]) / (L.pts[i + 1][0] - L.pts[i][0]); + assert.ok(s >= -0.15 && s <= 0.32, `a slope of ${s.toFixed(3)}`); + } + for (const [, y] of L.pts) assert.ok(y > wg.DERAIL_Y + 8 && y < 36, `a road height of ${y}`); + } + // The clock covers the ride comfortably (and respawns refill it). + assert.equal(ghoul.timeFor(ghoul.roomFor("wagon")), R.time); + assert.ok(R.time >= 1.4 * secs * 1000 && R.time <= 120000, `a ${R.time} ms clock for a ${secs.toFixed(0)} s ride`); + // The last line ends in a lip that launches the wagon onto the green. + assert.ok(ct.slopeOf(R, FINISH_LINE, lines.at(-1).x1) >= wg.RAMP_SLOPE, "the lip launches"); + assert.ok(R.bridge[0] < R.bridge[1] && R.bridge[1] < R.finish); + assert.ok(BRIDGE_LINE > 0, "a line ends at the bridge"); + assert.deepEqual([R.blocks.length, R.lows.length, R.throwers.length, R.horses.length, lines.length - 1], [7, 6, 9, 2, 5], "barrels and crates, washing and signs, throwers, horses, ditches and the bridge"); +}); + +test("Ghoul Rush's Torch Mob: the lip's launch alone carries the wagon onto the green at any speed it can have there, landing 4 to 45 past its start", () => { + const lip = lines.at(-1); + const end = lip.pts.at(-1); + const rise = ct.slopeOf(R, FINISH_LINE, lip.x1); + const green = floorOf(R.finish + 1); + for (const v of [wg.BRAKE_V, 34, wg.WAGON_V, wg.WAGON_V + wg.PANIC_V]) { + let vy = rise * v + wg.RAMP_POP; + let x = end[0]; + let y = end[1]; + for (let t = 0; t < 3; t += 0.002) { + vy -= wg.WAGON_G * 0.002; + x += v * 0.002; + y += vy * 0.002; + if (vy < 0 && y <= green) break; + } + assert.ok(x >= R.finish + 4, `at ${v} it lands ${x - R.finish} past the green's start`); + assert.ok(x <= R.finish + 45 && x < ROOM.length - 4, `at ${v} it lands ${x - R.finish} past the green's start`); + } +}); + +test("Ghoul Rush's Torch Mob: every ditch clears with a jump at the edge or a few units early, and a wagon that never jumps drops into it", () => { + for (let i = 0; i + 1 < lines.length - 1; i++) { + if (isBridgeGap(i)) continue; + const a = lines[i]; + const b = lines[i + 1]; + const gap = b.x0 - a.x1; + assert.ok(gap >= 6 && gap <= 10, `ditch ${i} is ${gap} wide`); + const end = a.pts.at(-1); + assert.ok(ct.slopeOf(R, i, a.x1) <= 0.01, "ditches lie on the flat (no ramp launch)"); + for (const v of [wg.BRAKE_V, wg.WAGON_V, wg.WAGON_V + wg.PANIC_V]) { + assert.equal(wg.flight(R, a.x1, end[1], 0, v), null, `ditch ${i}, no jump, at ${v}`); + for (const early of [0, 4]) { + const x = a.x1 - early; + const s = wg.flight(R, x, ct.trackY(R, i, x), wg.WAGON_JUMP_V, v); + assert.ok(s, `ditch ${i}: a jump ${early} early at ${v} lands`); + assert.equal(s.line, i + 1, `ditch ${i} cleared, at ${v}, ${early} early`); + } + } + } +}); + +test("Ghoul Rush's Torch Mob: the collapsed bridge needs the ramp and a jump at its lip (within about 11 units early) at the wagon's own speed; braking all the way, or no jump, drops it in the river; the horses' panic speed carries it over", () => { + const i = BRIDGE_LINE; + const a = lines[i]; + const lip = a.x1; + const gap = lines[i + 1].x0 - lip; + assert.ok(gap >= 22 && gap <= 30, `the span is ${gap} wide`); + assert.ok(ct.slopeOf(R, i, lip) >= wg.RAMP_SLOPE, "the ramp launches"); + const top = a.pts.at(-1)[1]; + const none = (v) => wg.flight(R, lip, top, ct.slopeOf(R, i, lip) * v + wg.RAMP_POP, v); + const jump = (v, early) => { + const x = lip - early; + return wg.flight(R, x, ct.trackY(R, i, x), wg.WAGON_JUMP_V + ct.slopeOf(R, i, x) * v, v); + }; + assert.equal(none(wg.WAGON_V), null, "the ramp alone is not enough at WAGON_V"); + assert.equal(none(wg.BRAKE_V), null); + assert.ok(none(wg.WAGON_V + wg.PANIC_V), "the bolting horses clear it on the ramp alone"); + for (const early of [0, 2, 4, 8]) { + const s = jump(wg.WAGON_V, early); + assert.ok(s && s.line === i + 1, `a jump ${early} early at WAGON_V lands on the far side`); + } + assert.equal(jump(wg.WAGON_V, 16), null, "a jump far too early falls short"); + assert.equal(jump(wg.BRAKE_V, 0), null, "braked all the way, even a good jump falls"); + assert.ok(jump(36, 0), "a wagon a little slow still clears"); + assert.equal(R.surge.length, 1); + assert.ok(R.surge[0][1] < lip - 20 && R.surge[0][0] > R.bridge[0], "the mob quickens on the bridge's run-up, before the ramp"); +}); + +test("Ghoul Rush's Torch Mob: every thing is on a line, spaced for a player (20 between jumps and 30 beside a duck), a low's underside between a ducked box and a standing one, checkpoints clear of everything", () => { + const wins = []; + const lineAt = (x) => lines.findIndex((L) => x >= L.x0 && x <= L.x1); + for (const [x, line, kind] of R.blocks) { + assert.ok(ct.trackY(R, line, x) !== null && lineAt(x) === line, `a block at ${x} stands on line ${line}`); + assert.ok(kind === 0 || kind === 1); + assert.ok(x - lines[line].x0 > 20 && lines[line].x1 - x > 20, `a block at ${x} well inside its line`); + wins.push([x - 5.7, x - 0.3, true]); + } + for (const [x0, x1, y, kind] of R.lows) { + assert.ok(kind === 0 || kind === 1); + let hi = 0; + let lo = 99; + for (let x = x0 - K.HIT_W / 2; x <= x1 + K.HIT_W / 2; x += 0.25) { + const g = ct.linesAt(R, x)[0]; + assert.ok(g, "road under a low"); + hi = Math.max(hi, g[1]); + lo = Math.min(lo, g[1]); + } + assert.ok(hi + K.DUCK_H < y, `a ducked box clears the low at ${x0}`); + assert.ok(lo + K.HIT_H > y, `a standing box hits the low at ${x0}`); + wins.push([x0 - 1.2, x1 + 1.2, false]); + } + for (const [x, line, kind] of R.throwers) { + assert.ok(ct.trackY(R, line, x) !== null && lineAt(x) === line, `a thrower at ${x} on line ${line}`); + assert.ok(kind === 0 || kind === 1); + const meet = x - wg.THROW_MEET; + assert.ok(lineAt(meet) === lineAt(meet - 14) && lineAt(meet) === lineAt(meet + 6), `a throw at ${x} meets the wagon on one line`); + wins.push(kind ? [meet - 11, meet + 7, true] : [meet - 5, meet + 5, false]); + } + for (const [x, line] of R.horses) { + assert.ok(lineAt(x) === line && lineAt(x - 30) === line && lineAt(x + 4) === line, `a horse at ${x} runs along line ${line}`); + wins.push([x - 34, x - 8, true]); + } + for (let i = 0; i + 1 < lines.length; i++) wins.push(isBridgeGap(i) ? [lines[i].x1 - 15, lines[i].x1 + 30, true] : [lines[i].x1 - 11, lines[i].x1 + 28, true]); + wins.sort((p, q) => p[0] - q[0]); + for (let i = 0; i + 1 < wins.length; i++) { + const gap = wins[i + 1][0] - wins[i][1]; + assert.ok(gap >= (wins[i][2] && wins[i + 1][2] ? 20 : 30), `windows at ${wins[i][1]} and ${wins[i + 1][0]} are ${gap.toFixed(0)} apart`); + } + const cs = R.checks; + assert.equal(cs.length, 7); + for (let i = 0; i < cs.length; i++) { + assert.ok(ct.linesAt(R, cs[i]).length, `checkpoint ${i} on the road`); + if (i) assert.ok(cs[i] - cs[i - 1] >= 250 && cs[i] - cs[i - 1] <= 450, `${cs[i] - cs[i - 1]} between checkpoints`); + for (const [w0, w1] of wins) assert.ok(w0 - cs[i] > 8 || cs[i] - w1 > 4, `a thing at ${w0} near checkpoint ${i}`); + } + assert.ok(cs[0] < 500 && R.finish - cs.at(-1) > 150); +}); + +/* ------------------------------------------------------------ the wagon */ + +test("Ghoul Rush's Torch Mob rolls at WAGON_V on the road whatever key is held, DOWN brakes it toward BRAKE_V and ducks, letting go brings it back, and it keeps its speed in the air", () => { + const flat = synth({ track: FLAT }); + assert.equal(flat.runner.v, wg.WAGON_V); + assert.equal(flat.runner.id, "wagon"); + run(flat, 2000); + assert.ok(Math.abs(flat.runner.v - wg.WAGON_V) < 0.01); + run(flat, 1500, { right: true }); + run(flat, 1500, { left: true }); + assert.ok(Math.abs(flat.runner.v - wg.WAGON_V) < 0.01, "right and left do nothing"); + assert.ok(Math.abs(flat.you.x - (10 + ((2000 + 1500 + 1500) / 1000) * wg.WAGON_V)) < 1, "rides on at WAGON_V"); + // The brake. + flat.input.down = true; + run(flat, 100); + assert.equal(flat.you.ducking, true, "down ducks"); + assert.equal(flat.runner.braking, true); + assert.ok(events(flat, "wagonBrake").length === 1, "one brake cue"); + run(flat, 2000); + assert.ok(Math.abs(flat.runner.v - wg.BRAKE_V) < 0.5, `${flat.runner.v} braked`); + assert.ok(flat.runner.v >= wg.BRAKE_V - 0.01); + flat.input.down = false; + run(flat, 2000); + assert.ok(Math.abs(flat.runner.v - wg.WAGON_V) < 0.5, "back to speed"); + assert.equal(flat.you.ducking, false); + // A press of up jumps rather than ducking, and the air holds the speed. + flat.input.down = true; + press(flat); + run(flat, 40); + assert.equal(flat.you.state, "air"); + assert.equal(flat.you.ducking, false); + const v = flat.runner.v; + run(flat, 300); + assert.equal(flat.runner.v, v, "no brake in the air"); + flat.input.down = false; +}); + +test("Ghoul Rush's Torch Mob jumps about 7 high for about 0.6 s (a gap of about 26 at WAGON_V), a press saved for a landing jumps on it, one just after a line's end still jumps, and one long after does not", () => { + const w = synth({ track: FLAT }); + run(w, 200); + const y0 = w.you.y; + press(w); + let top = y0; + let t = 0; + for (; t < 1500; t += 4) { + ghoul.advance(w, 4, steady); + w.input.jump = 0; + top = Math.max(top, w.you.y); + if (t > 40 && w.runner.line >= 0) break; + } + assert.ok(top - y0 > 6.5 && top - y0 < 7.6, `${(top - y0).toFixed(2)} high`); + assert.ok(t > 560 && t < 680, `${t} ms in the air`); + assert.equal(events(w, "wagonJump").length, 1); + assert.equal(events(w, "wagonLand").length, 1); + // Coyote time off a line's end. + const gap = synth({ track: [[[0, 20], [60, 20]], [[75, 20], [400, 20]]] }); + until(gap, () => gap.you.state === "air", 3000); + assert.equal(gap.you.state, "air"); + press(gap); + run(gap, 16); + assert.ok(gap.you.vy > 20, "a jump just after the end"); + const late = synth({ track: [[[0, 20], [60, 20]], [[75, 20], [400, 20]]] }); + until(late, () => late.you.state === "air", 3000); + run(late, 200); + press(late); + run(late, 16); + assert.ok(late.you.vy < 0, "no jump long after"); +}); + +/* ------------------------------------------------------------ obstacles */ + +test("Ghoul Rush's Torch Mob: a barrel and a crate are cleared by a jump and cost a heart otherwise (causes barrel and crate), each only once, smashed after", () => { + const w = synth({ track: FLAT, blocks: [[100, 0, 0], [220, 0, 1]] }); + // A jump clears a barrel. + wagonAt(w, 88, 0); + w.input.jump = 0; + until(w, () => w.you.x + wg.REACH > 100 - 8, 2000); + press(w); + run(w, 600); + assert.equal(w.bonusRound.hearts, 5); + assert.equal(w.runner.smashed[0], false); + // No jump hits it. + wagonAt(w, 90, 0); + run(w, 400); + assert.equal(w.bonusRound.hearts, 4); + assert.equal(events(w, "lose").at(-1).cause, "barrel"); + assert.equal(w.runner.smashed[0], true, "smashed"); + assert.deepEqual(w.bonusRound.perf.hits, ["b0"]); + assert.equal(w.runner.line, 0, "the wagon rolls on"); + assert.equal(w.phase, "play"); + assert.ok(w.you.safeMs > 0, "blinking safe"); + // A crate. + wagonAt(w, 212, 0); + w.you.safeMs = 0; + run(w, 400); + assert.equal(w.bonusRound.hearts, 3); + assert.equal(events(w, "lose").at(-1).cause, "crate"); + assert.deepEqual(w.bonusRound.perf.hits, ["b0", "b1"]); + // A smashed one is no longer in the way. + wagonAt(w, 90, 0); + w.you.safeMs = 0; + run(w, 400); + assert.equal(w.bonusRound.hearts, 3); +}); + +test("Ghoul Rush's Torch Mob: DOWN passes under a washing line and an inn sign (at the price of the brake), a standing wagon is hit (causes wash and sign), and a jump does not clear one", () => { + const w = synth({ track: FLAT, lows: [[100, 106, 23, 0], [300, 306, 23, 1]] }); + wagonAt(w, 90, 0); + w.input.down = true; + run(w, 800); + w.input.down = false; + assert.equal(w.bonusRound.hearts, 5, "ducked under the washing"); + assert.ok(w.you.x > 106, "and through"); + assert.ok(w.runner.v < wg.WAGON_V - 1, "the duck braked"); + wagonAt(w, 92, 0); + run(w, 400); + assert.equal(w.bonusRound.hearts, 4); + assert.equal(events(w, "lose").at(-1).cause, "wash"); + assert.deepEqual(w.bonusRound.perf.hits, ["l0"]); + wagonAt(w, 292, 0); + w.you.safeMs = 0; + run(w, 500); + assert.equal(w.bonusRound.hearts, 3); + assert.equal(events(w, "lose").at(-1).cause, "sign"); + // A jump at it: the box reaches the low. + const j = synth({ track: FLAT, lows: [[100, 106, 23, 0]] }); + wagonAt(j, 86, 0); + press(j); + run(j, 700); + assert.equal(j.bonusRound.hearts, 4, "a jump runs into it"); + assert.equal(events(j, "lose")[0].cause, "wash"); +}); + +test("Ghoul Rush's Torch Mob: a villager winds up WIND_MS once the wagon is WIND_NEAR short, then throws at where the wagon will be, and a pitchfork meets a wagon at WAGON_V THROW_MEET short of him", () => { + const w = synth({ track: FLAT, throwers: [[400, 0, 0]] }); + wagonAt(w, 400 - wg.WIND_NEAR - 8, 0); + run(w, 100); + assert.equal(w.runner.throwers[0].state, "idle", "still out of range"); + const wind = until(w, () => events(w, "wagonWind").length > 0, 1000); + assert.ok(wind < 300); + assert.equal(events(w, "wagonWind")[0].kind, 0); + assert.equal(w.runner.throwers[0].state, "wind"); + assert.equal(w.runner.props.length, 0, "nothing thrown yet"); + const ms = until(w, () => w.runner.props.length > 0, 2000); + assert.ok(ms >= wg.WIND_MS - 40 && ms <= wg.WIND_MS + 40, `${ms} ms of wind-up`); + assert.equal(events(w, "wagonThrow").length, 1); + assert.equal(w.runner.throwers[0].state, "spent"); + const p = w.runner.props[0]; + const meetAt = w.you.x + w.runner.v * p.T; + assert.ok(Math.abs(p.x1 - meetAt) < 0.5, "aimed at where the wagon will be"); + assert.ok(Math.abs(p.x1 - (400 - wg.THROW_MEET)) < 1.5, `meets ${400 - p.x1} short of the thrower`); + assert.ok(Math.abs(p.y1 - (20 + wg.FORK_Y)) < 0.01, "chest height"); + assert.ok(p.T > 0.35 && p.T < 0.6, `${p.T} s of flight`); + // Nothing else is thrown. + run(w, 1500); + assert.equal(events(w, "wagonThrow").length, 1); +}); + +test("Ghoul Rush's Torch Mob: a hurled pitchfork costs a heart (cause fork) to a standing wagon, passes over a ducked one and under a jumping one, and the same torch is shot or ducked in vain", () => { + const throwAt = (kind, keys) => { + const w = synth({ track: FLAT, throwers: [[400, 0, kind]] }); + wagonAt(w, 400 - wg.WIND_NEAR + 2, 0); + return w; + }; + // Standing: hit. + const stand = throwAt(0); + run(stand, 1500); + assert.equal(stand.bonusRound.hearts, 4); + assert.equal(events(stand, "lose")[0].cause, "fork"); + assert.deepEqual(stand.bonusRound.perf.hits, ["t0"]); + // Ducked while it passes: untouched (and the brake is the price). + const duck = throwAt(0); + until(duck, () => duck.runner.props.length > 0, 1500); + duck.input.down = true; + run(duck, 800); + duck.input.down = false; + assert.equal(duck.bonusRound.hearts, 5, "ducked under it"); + // Jumped: it goes under. + const jump = throwAt(0); + until(jump, () => jump.runner.props.length > 0, 1500); + run(jump, 80); + press(jump); + run(jump, 900); + assert.equal(jump.bonusRound.hearts, 5, "jumped it"); + // A torch aims low at the hay: standing is hit, a jump clears it. + const torchStand = throwAt(1); + run(torchStand, 1500); + assert.equal(torchStand.bonusRound.hearts, 4); + assert.equal(events(torchStand, "lose")[0].cause, "torch"); + const torchJump = throwAt(1); + until(torchJump, () => torchJump.runner.props.length > 0, 1500); + run(torchJump, 120); + press(torchJump); + run(torchJump, 900); + assert.equal(torchJump.bonusRound.hearts, 5, "jumped the torch"); + assert.equal(torchJump.runner.fireMs, 0); +}); + +test("Ghoul Rush's Torch Mob: a torch that lands on the hay is a heart (cause torch), sets it alight for FIRE_MS, and the mob closes faster while it burns; ducking smothers it sooner", () => { + const set = () => { + const w = synth({ track: FLAT, throwers: [[400, 0, 1]] }); + wagonAt(w, 400 - wg.WIND_NEAR + 2, 0); + until(w, () => w.bonusRound.hearts < 5, 2000); + return w; + }; + const w = set(); + assert.equal(w.bonusRound.hearts, 4); + assert.equal(events(w, "lose")[0].cause, "torch"); + assert.equal(events(w, "wagonFire").length, 1); + assert.ok(w.runner.fireMs > wg.FIRE_MS - 100 && w.runner.fireMs <= wg.FIRE_MS); + const burn = until(w, () => w.runner.fireMs <= 0, 5000); + assert.ok(burn > wg.FIRE_MS - 200 && burn < wg.FIRE_MS + 100, `${burn} ms burning`); + assert.equal(events(w, "wagonOut").length, 1); + // Smothered by ducking: out in a third of the time. + const s = set(); + s.input.down = true; + const quick = until(s, () => s.runner.fireMs <= 0, 5000); + s.input.down = false; + assert.ok(quick < (wg.FIRE_MS / wg.SMOTHER) + 150, `${quick} ms smothered`); + // The fire's pull on the mob, alone: it runs faster with the hay alight. + const a = synth({ track: FLAT }); + const b = synth({ track: FLAT }); + b.runner.fireMs = 1e9; + a.runner.gap = b.runner.gap = 20; + run(a, 1000); + run(b, 1000); + assert.ok(a.runner.gap - b.runner.gap > wg.FIRE_BOOST - 1.5, `${a.runner.gap} to ${b.runner.gap}`); +}); + +test("Ghoul Rush's Torch Mob: bolts shoot a pitchfork (40 points) or a torch (60 points) out of the air, which pushes the mob back and counts as an act; a torch shot is no fire", () => { + for (const kind of [0, 1]) { + const w = synth({ track: FLAT, throwers: [[400, 0, kind]] }); + wagonAt(w, 400 - wg.WIND_NEAR + 2, 0); + w.runner.gap = 20; + until(w, () => w.runner.props.length > 0, 1500); + const score = w.score; + // A bolt where the throw will be, level with it. + const p = w.runner.props[0]; + until(w, () => w.runner.props[0].x < w.you.x + 14, 800); + const q = w.runner.props[0]; + w.shots.push({ x: q.x - 1, y: q.y, vx: 130, vy: 0, gone: 0 }); + const g = w.runner.gap; + run(w, 40); + assert.ok(q.dead, `the ${kind ? "torch" : "fork"} is shot`); + assert.equal(w.score - score, kind ? wg.TORCH_POINTS : wg.FORK_POINTS); + assert.equal(w.bonusRound.perf.acts, 1); + const shot = events(w, "wagonShot")[0]; + assert.equal(shot.kind, kind); + assert.ok(w.runner.gap - g >= (kind ? wg.TORCH_BACK : wg.FORK_BACK) - 0.5, "the mob falls back"); + run(w, 1500); + assert.equal(w.bonusRound.hearts, 5, "no hit"); + assert.equal(w.runner.fireMs, 0, "no fire"); + void p; + } + // The gap never goes over GAP_MAX. + const w = synth({ track: FLAT, throwers: [[400, 0, 1]] }); + wagonAt(w, 400 - wg.WIND_NEAR + 2, 0); + w.runner.gap = wg.GAP_MAX - 1; + until(w, () => w.runner.props.length > 0 && w.runner.props[0].x < w.you.x + 14, 2000); + const q = w.runner.props[0]; + w.shots.push({ x: q.x - 1, y: q.y, vx: 130, vy: 0, gone: 0 }); + run(w, 40); + assert.equal(w.runner.gap, wg.GAP_MAX); +}); + +test("Ghoul Rush's Torch Mob: a spooked horse rears HORSE_REAR_MS when the wagon is HORSE_NEAR short, then charges; a jump clears it, a standing wagon is trampled (cause horse), and HORSE_HP bolts turn it back (120 points)", () => { + const set = () => { + const w = synth({ track: FLAT, horses: [[400, 0]] }); + wagonAt(w, 400 - wg.HORSE_NEAR - 8, 0); + return w; + }; + const w = set(); + run(w, 150); + assert.equal(w.runner.horses[0].state, "wait"); + until(w, () => w.runner.horses[0].state === "rear", 500); + assert.equal(events(w, "wagonRear").length, 1); + const rear = until(w, () => w.runner.horses[0].state === "run", 1000); + assert.ok(rear >= wg.HORSE_REAR_MS - 20 && rear <= wg.HORSE_REAR_MS + 20, `${rear} ms rearing`); + assert.ok(w.runner.horses[0].x === 400, "it did not move while it reared"); + run(w, 100); + assert.ok(w.runner.horses[0].x < 400, "charging"); + until(w, () => w.bonusRound.hearts < 5, 2000); + assert.equal(w.bonusRound.hearts, 4); + assert.equal(events(w, "lose")[0].cause, "horse"); + assert.deepEqual(w.bonusRound.perf.hits, ["h0"]); + // Jumped. + const j = set(); + until(j, () => j.runner.horses[0].state === "run", 2000); + until(j, () => 0 < j.runner.horses[0].x - (j.you.x + wg.REACH) && j.runner.horses[0].x - (j.you.x + wg.REACH) < 14, 2000); + press(j); + run(j, 1200); + assert.equal(j.bonusRound.hearts, 5, "jumped the horse"); + // Shot back. + const s = set(); + until(s, () => s.runner.horses[0].state === "run", 2000); + const score = s.score; + for (let k = 0; k < wg.HORSE_HP; k++) { + const h = s.runner.horses[0]; + s.shots.push({ x: h.x - 1, y: s.you.y + 2.4, vx: 130, vy: 0, gone: 0 }); + run(s, 20); + if (k < wg.HORSE_HP - 1) assert.equal(events(s, "wagonHorseHit").length, k + 1); + } + assert.equal(s.runner.horses[0].state, "fled"); + assert.equal(events(s, "wagonHorseTurn").length, 1); + assert.equal(s.score - score, wg.HORSE_POINTS); + assert.equal(s.bonusRound.perf.acts, 1); + run(s, 1500); + assert.equal(s.bonusRound.hearts, 5, "turned back, no harm"); +}); + +/* -------------------------------------------------------------- the mob */ + +test("Ghoul Rush's Torch Mob: the mob runs at MOB_V, so clean riding opens the gap (to GAP_MAX), the brake closes it, a hit shoves it HIT_CLOSE closer, and it starts at GAP_START", () => { + const w = synth({ track: FLAT }); + assert.equal(w.runner.gap, wg.GAP_START); + run(w, 1000); + assert.ok(Math.abs(w.runner.gap - (wg.GAP_START + wg.WAGON_V - wg.MOB_V)) < 0.2, `${w.runner.gap} after a clean second`); + run(w, 5000); + assert.equal(w.runner.gap, wg.GAP_MAX, "never over GAP_MAX"); + w.input.down = true; + run(w, 1500); + const g = w.runner.gap; + assert.ok(g < wg.GAP_MAX - 8, `braking closed it to ${g.toFixed(1)}`); + run(w, 1000); + w.input.down = false; + assert.ok(g - w.runner.gap > 6, "held down, it keeps closing"); + // A hit shoves it. + const h = synth({ track: FLAT, blocks: [[60, 0, 0]] }); + h.runner.gap = 30; + wagonAt(h, 50, 0); + const before = h.runner.gap; + until(h, () => h.bonusRound.hearts < 5, 1000); + assert.ok(before - h.runner.gap > wg.HIT_CLOSE - 1, `${before} to ${h.runner.gap}`); +}); + +test("Ghoul Rush's Torch Mob: inside PANIC_ON the horses bolt (PANIC_V faster) until PANIC_OFF, so the gap recovers; the brake still overrides it", () => { + const w = synth({ track: FLAT }); + w.runner.gap = 8; + run(w, 200); + assert.equal(w.runner.panic, true); + assert.equal(events(w, "wagonPanic").length, 1); + run(w, 300); + assert.ok(w.runner.v > wg.WAGON_V + 5, `${w.runner.v} bolting`); + until(w, () => !w.runner.panic, 4000); + assert.ok(w.runner.gap >= wg.PANIC_OFF - 0.01 && w.runner.gap < wg.PANIC_OFF + 2, `calm again at ${w.runner.gap}`); + until(w, () => Math.abs(w.runner.v - wg.WAGON_V) < 0.5, 3000); + assert.ok(Math.abs(w.runner.v - wg.WAGON_V) < 0.5); + const b = synth({ track: FLAT }); + b.runner.gap = wg.PANIC_ON - 2; + b.input.down = true; + run(b, 1500); + b.input.down = false; + assert.ok(b.runner.v < wg.BRAKE_V + 1, "braking all the same"); +}); + +test("Ghoul Rush's Torch Mob: the mob quickens on a surge span, and a catch at CATCH_GAP is a heart (cause mob) that sends it back to GAP_RESET, with the wagon rolling on", () => { + const a = synth({ track: FLAT, surge: [[0, 1e6, 7]] }); + const b = synth({ track: FLAT }); + a.runner.gap = b.runner.gap = 30; + run(a, 1000); + run(b, 1000); + assert.ok(Math.abs(b.runner.gap - a.runner.gap - 7) < 0.3, `${b.runner.gap} to ${a.runner.gap}`); + assert.equal(wg.surgeAt(R, R.surge[0][0] + 1), R.surge[0][2]); + assert.equal(wg.surgeAt(R, 5), 0); + const w = synth({ track: FLAT }); + w.runner.gap = wg.CATCH_GAP + 0.1; + w.input.down = true; + until(w, () => w.bonusRound.hearts < 5, 3000); + w.input.down = false; + assert.equal(w.bonusRound.hearts, 4); + assert.equal(events(w, "lose")[0].cause, "mob"); + assert.equal(events(w, "wagonCatch").length, 1); + assert.equal(w.runner.gap, wg.GAP_RESET); + assert.equal(w.runner.catches, 1); + assert.equal(w.runner.panic, false); + assert.equal(w.phase, "play"); + assert.ok(w.bonusRound.perf.hits.includes("m1"), "a catch counts against the grade"); + assert.equal(w.runner.done, false); + assert.equal(w.lives, 3); + // While blinking safe a catch costs nothing (the Garlic's shield too) but still sends it back. + const safe = synth({ track: FLAT }); + safe.you.safeMs = 1e9; + safe.runner.gap = wg.CATCH_GAP + 0.05; + safe.input.down = true; + until(safe, () => safe.runner.catches > 0, 3000); + safe.input.down = false; + assert.equal(safe.bonusRound.hearts, 5); + assert.equal(safe.runner.gap, wg.GAP_RESET); +}); + +/* -------------------------------------------------------- falls, the end */ + +test("Ghoul Rush's Torch Mob: a ditch with no jump is a heart (cause ditch), the wagon goes back on the road ahead at WAGON_V and rolls on; the bridge's gap is the river; a jump over costs nothing", () => { + const ditch = lines.findIndex((L, i) => i + 1 < lines.length && !isBridgeGap(i)); + const w = wagonRound(); + const L = lines[ditch]; + const noJump = () => { + const r = wagonRound(); + wagonAt(r, L.x1 - 14, ditch, { v: wg.WAGON_V }); + r.runner.gap = 30; + return r; + }; + const r = noJump(); + until(r, () => r.bonusRound.hearts < 5, 3000); + assert.equal(r.bonusRound.hearts, 4); + assert.equal(events(r, "lose")[0].cause, "ditch"); + assert.ok(r.bonusRound.perf.hits.includes(`k${ditch}`)); + assert.equal(r.phase, "play"); + assert.ok(r.you.x >= lines[ditch + 1].x0, `back on the road at ${r.you.x}`); + assert.equal(r.runner.line, ditch + 1); + assert.equal(r.runner.v, wg.WAGON_V); + run(r, 300); + assert.ok(r.you.x > lines[ditch + 1].x0); + // The bridge. + const b = wagonRound(); + wagonAt(b, lines[BRIDGE_LINE].x1 - 14, BRIDGE_LINE); + until(b, () => b.bonusRound.hearts < 5, 3000); + assert.equal(events(b, "lose")[0].cause, "river"); + assert.equal(b.runner.line, BRIDGE_LINE + 1); + // A jump clears a ditch for free. + const j = wagonRound(); + wagonAt(j, L.x1 - 10, ditch); + until(j, () => lines[ditch].x1 - j.you.x < 2, 1000); + press(j); + run(j, 1200); + assert.equal(j.bonusRound.hearts, 5); + assert.equal(j.runner.line, ditch + 1); + void w; +}); + +test("Ghoul Rush's Torch Mob: the last heart gone ends the round with nothing at once (no life lost, the dice in hand kept) and the run goes on to the Green", () => { + const w = synth({ track: FLAT, blocks: [[70, 0, 0]] }); + w.dice = 4; + w.lives = 3; + w.bonusRound.hearts = 1; + wagonAt(w, 60, 0); + until(w, () => w.phase === "clear", 6000); + assert.equal(w.phase, "clear"); + assert.equal(w.bonusRound.hearts, 0); + assert.equal(w.bonusRound.won, false); + assert.equal(w.bonusRound.dice, 0); + assert.equal(w.lives, 3, "no life lost"); + assert.equal(w.dice, 4, "the dice in hand kept"); + assert.equal(w.over, false, "not game over"); + assert.equal(events(w, "bonusEnd").length, 1); + assert.equal(events(w, "bonusEnd")[0].won, false); + run(w, ghoul.CARD_LOST_MS + 100); + assert.equal(w.spec.id, "green"); + assert.equal(w.runner, null); + assert.equal(w.bonusRound, null); + assert.equal(w.lives, 3); + assert.equal(w.dice, 4); +}); + +test("Ghoul Rush's Torch Mob: the checkpoints are passed in order (an event each) and the ride goes back to the last one passed after the last heart", () => { + const w = wagonRound(); + w.runner.gap = 30; + wagonAt(w, R.checks[0] - 6, ct.linesAt(R, R.checks[0])[0][0], { safe: true }); + until(w, () => w.runner.check === 0, 2000); + assert.equal(events(w, "wagonCheck").length, 1); + assert.equal(events(w, "wagonCheck")[0].n, 1); + wagonAt(w, R.checks[2] - 5, ct.linesAt(R, R.checks[2])[0][0], { safe: true }); + w.runner.check = 0; + until(w, () => w.runner.check === 2, 2000); + assert.equal(events(w, "wagonCheck").length, 3, "one for each passed, in order"); + assert.deepEqual(events(w, "wagonCheck").map((e) => e.n), [1, 2, 3]); + // A place after that goes back to the checkpoint, with the catches kept. + w.runner.catches = 2; + wg.WAGON.place[0](w, {}); + assert.equal(w.runner.check, 2); + assert.equal(w.you.x, R.checks[2]); + assert.equal(w.runner.catches, 2); + assert.equal(w.runner.gap, wg.GAP_START); +}); + +test("Ghoul Rush's Torch Mob: off the lip the wagon launches, lands on the green and stops (wagonFinish), the door opens, and walking out ends the round with 3 to 9 Lucky dice", () => { + const round = wagonRound(); + round.dice = 1; + const last = lines.length - 1; + wagonAt(round, lines[last].x1 - 12, last, { safe: true }); + round.runner.gap = 30; + until(round, () => round.runner.done, 4000); + assert.equal(round.runner.done, true); + assert.equal(events(round, "wagonLaunch").length, 1); + assert.equal(events(round, "wagonLaunch")[0].last, true); + const fin = events(round, "wagonFinish"); + assert.equal(fin.length, 1); + assert.ok(round.you.x > R.finish + 4 && round.you.x < R.finish + 45, `${round.you.x} landed`); + assert.equal(round.you.y, floorOf(round.you.x)); + assert.equal(round.hasKey, true, "the door opens"); + assert.equal(round.bonusRound.hearts, 5); + assert.equal(round.phase, "play"); + // He walks out to the door. + round.input.right = true; + until(round, () => round.phase === "clear", 20000); + round.input.right = false; + assert.equal(round.phase, "clear"); + const end = events(round, "bonusEnd"); + assert.equal(end.length, 1); + assert.equal(end[0].won, true); + assert.ok(end[0].dice >= BONUS_FLOOR && end[0].dice <= ghoul.MAX_DICE, `${end[0].dice} dice`); + assert.equal(round.dice, Math.min(ghoul.MAX_DICE, 1 + end[0].dice)); + assert.equal(round.lives, 3); + run(round, ghoul.CARD_MS + 100); + assert.equal(round.spec.id, "green"); + assert.equal(round.runner, null); +}); + +test("Ghoul Rush's Torch Mob: no random number is drawn in the room (a ride of 20 seconds, jumping, ducking and shooting, on a draw that throws)", () => { + const w = wagonRound(); + w.you.safeMs = 1e9; + for (let t = 0; t < 20000; t += 16) { + w.input.fire = true; + w.input.down = t % 3000 < 400; + if (t % 1900 < 20) press(w); + w.you.safeMs = 1e9; + ghoul.advance(w, 16, never); + w.events.length = 0; + } + assert.ok(w.you.x > 600); + assert.equal(w.runner.id, "wagon"); +}); + +test("Ghoul Rush's Torch Mob's grade: the dice formula, shooting 8 things for the die, and the steady die (the mob kept far: the gap's average over the ride)", () => { + const w = synth({ track: FLAT }); + const b = w.bonusRound; + assert.equal(b.perf.goal, wg.ACTS_GOAL); + assert.equal(b.perf.steady, true); + const full = wagonRound(); + assert.equal(full.bonusRound.perf.total, R.blocks.length + R.lows.length + R.throwers.length + R.horses.length + (lines.length - 1)); + // The dice: the floor, plus hearts, clean riding, acts and the steady die. + const mk = (hearts, hits, acts, steadyDie) => { + const bb = makeBonus({ stats: { kills: 0 } }); + bb.hearts = hearts; + bb.perf = { total: 29, hits: Array.from({ length: hits }, (_, i) => `x${i}`), acts, goal: wg.ACTS_GOAL, steady: steadyDie, kills0: 0 }; + return diceFor(bb, 0); + }; + assert.equal(mk(5, 0, 8, true), 9, "a perfect ride"); + assert.equal(mk(5, 0, 7, true), 8, "one act short"); + assert.equal(mk(5, 0, 8, false), 8, "the mob came too close"); + assert.ok(mk(1, 20, 0, false) >= BONUS_FLOOR && mk(1, 20, 0, false) <= 4); + // The steady die follows the average gap. + const s = synth({ track: FLAT }); + s.runner.gap = 10; + s.runner.gapMs = 20000; + s.runner.gapSum = 10 * 20000; + run(s, 100); + assert.equal(s.bonusRound.perf.steady, false, "the mob stayed close"); + const t = synth({ track: FLAT }); + run(t, 3000); + assert.equal(t.bonusRound.perf.steady, true, "far behind"); + // Brake all the way and the average falls under STEADY_GAP. + const u = synth({ track: FLAT }); + u.input.down = true; + until(u, () => u.runner.catches > 0 || u.bonusRound.perf.steady === false, 20000); + u.input.down = false; + assert.ok(u.bonusRound.perf.steady === false || u.runner.catches > 0, "the brake held down costs the steady die"); + assert.ok(wg.STEADY_GAP > wg.PANIC_OFF && wg.STEADY_GAP < wg.GAP_MAX); +}); + +test("Ghoul Rush's Torch Mob: endless lives (round.infinite) spare the hearts for every cause, through the same lose path", () => { + const w = wagonRound(); + w.infinite = true; + w.runner.gap = 30; + wagonAt(w, 60, 0); + w.spec = { ...w.spec, ride: { ...R, blocks: [[70, 0, 0], ...R.blocks.slice(1)] } }; + until(w, () => events(w, "lose").length > 0, 1000); + assert.equal(w.bonusRound.hearts, 5); + assert.equal(events(w, "lose")[0].cause, "barrel"); + const m = synth({ track: FLAT }); + m.infinite = true; + m.runner.gap = wg.CATCH_GAP + 0.1; + m.input.down = true; + until(m, () => m.runner.catches > 0, 3000); + m.input.down = false; + assert.equal(m.bonusRound.hearts, 5); + assert.equal(events(m, "lose")[0].cause, "mob"); + assert.equal(m.phase, "play"); +}); + +test("Ghoul Rush's Torch Mob: the Garlic shield takes a hit instead of a heart", () => { + const w = synth({ track: FLAT, blocks: [[60, 0, 0]] }); + w.you.garlic = true; + wagonAt(w, 50, 0); + until(w, () => !w.you.garlic, 1000); + assert.equal(w.bonusRound.hearts, 5); + assert.equal(w.you.garlic, false); +}); + +/* ----------------------------------------------------------- sound, names */ + +test("Ghoul Rush's Torch Mob: every event has a voice that plays, every cause has words and a sound, and the voices are tones that exist", () => { + assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...wg.EVENTS].sort(), "a voice for every event and no more"); + const tones = ghoulSfx.default.tones; + for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) { + const name = WAGON_VOICES[kind] && WAGON_VOICES[kind][act]; + assert.ok(name, `${event} has a ${kind}.${act} voice`); + assert.ok(tones[name], `${name} exists`); + assert.equal(VOICES[kind][act], name, "joined to the game's voices"); + assert.ok(heard({ type: event, kind: 1, points: 50 }).played.includes(name), `${event} plays ${name}`); + } + for (const cause of ["barrel", "crate", "wash", "sign", "fork", "torch", "horse", "ditch", "river", "mob"]) { + assert.ok(LOSE_WORDS[cause], `${cause} has words`); + assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`); + assert.ok(heard({ type: "lose", cause, hearts: 3 }).played.length > 0, `${cause} sounds`); + } + assert.equal(heard({ type: "wagonJump" }).played.length, 1); + assert.equal(heard({ type: "wagonShot", kind: 0, points: 40 }).played.length, 1); + // No tone runs over 1.2 s, and the track's voices all run the same number of steps. + for (const name of Object.keys(ghoulSfx.default.tones).filter((n) => n.startsWith("ghoulWagon"))) { + const layers = ghoulSfx.default.tones[name].layers; + assert.ok(Math.max(...layers.map((l) => (l.delay || 0) + l.seconds)) <= 1.2, `${name} is short`); + } + const track = ghoulSfx.default.music.ghoulWagonRide; + for (const id of track.order) assert.ok(track.patterns[id], `pattern ${id}`); + for (const [id, p] of Object.entries(track.patterns)) { + const steps = Object.entries(p).map(([voice, s]) => [voice, s.split(/\s+/).filter((t) => t && t !== "|").length]); + for (const [voice, n] of steps) { + assert.ok(track.voices[voice], `${voice} is a voice`); + assert.equal(n, 64, `${id}.${voice} runs 64 steps`); + } + } +}); + +test("Ghoul Rush's Torch Mob: the room's own names do not collide with the game's (hazards, events, kinds, the other rides' state)", () => { + for (const e of wg.EVENTS) assert.ok(e.startsWith("wagon"), e); + const other = new Set(); + for (const pack of [ct]) for (const e of pack.EVENTS || []) other.add(e); + for (const e of wg.EVENTS) assert.ok(!other.has(e), `${e} is the wagon's alone`); + assert.deepEqual(Object.keys(wg.WAGON).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []); + assert.equal(typeof ghoul.ROOM_MUSIC.wagon, "string"); + // It keeps to the shared slot: no new round field, and the Cart's state is left null in its room. + const w = wagonRound(); + assert.equal(w.runner.id, "wagon"); + assert.equal(w.cart, null); + assert.ok(!("wagon" in w)); +}); + +/* --------------------------------------------------------------- drawing */ + +test("Ghoul Rush's Torch Mob draws: the room, the wagon on the road, in the air and braking, each thing (barrels, crates, washing, signs, throwers winding up, throws in flight, horses in each state), the mob close and far, the fire, a crash, the finish and the cards", () => { + const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) }); + const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + g.resize(900, 900); + g.key("action"); + g.tick(16); + const r = g.round; + through(r); + r.offer = ["village"]; + r.phaseMs = 0; + ghoul.pickStage(r, 0); + while (r.spec.id !== "wagon") through(r); + r.lives = 99; + const bridge = (R.bridge[0] + R.bridge[1]) / 2; + const spots = [ROOM.start + 40, R.blocks[0][0] - 10, R.lows[0][0] - 5, R.lows[1][0] - 5, R.throwers[0][0] - 40, R.throwers[1][0] - 40, R.horses[0][0] - 30, R.checks[0], lines[0].x1 - 10, bridge - 20, lines[BRIDGE_LINE].x1 - 6, R.finish - 40]; + for (const dark of [true, false]) { + for (const x of spots) { + r.dark = dark; + r.phase = "play"; + for (const st of r.spawns) st.over = true; + r.hordeMs = Infinity; + r.monsters.length = 0; + const top = ct.linesAt(R, x)[0] || [lines.length - 1, 20]; + wagonAt(r, x, top[0], { safe: true }); + r.runner.throwers = r.runner.throwers.map((t, i) => ({ ...t, state: ["idle", "wind", "spent"][i % 3], t: 300 })); + r.runner.horses = r.runner.horses.map((h, i) => ({ ...h, state: ["wait", "rear", "run", "hit", "fled"][(i + 1) % 5], t: 300, x: R.horses[i][0] - 10 })); + r.runner.smashed = r.runner.smashed.map((_, i) => i % 3 === 0); + r.runner.props = [ + { kind: 0, x0: x + 30, y0: top[1] + 8.5, x1: x + 12, y1: top[1] + 3.2, T: 0.5, t: 0.2, s: 0.4, x: x + 22, y: top[1] + 6, dead: false, age: 0 }, + { kind: 1, x0: x + 30, y0: top[1] + 11, x1: x + 12, y1: top[1] + 1.6, T: 0.5, t: 0.2, s: 0.4, x: x + 20, y: top[1] + 8, dead: false, age: 0 }, + { kind: 1, x0: x + 30, y0: top[1] + 11, x1: x + 12, y1: top[1] + 1.6, T: 0.5, t: 0.5, s: 1, x: x + 12, y: top[1] + 1.6, dead: true, age: 100 }, + ]; + for (const air of [false, true]) { + for (const state of [{ gap: 34, fireMs: 0 }, { gap: 9, fireMs: 2000, panic: true }]) { + Object.assign(r.runner, state); + if (air) Object.assign(r.you, { state: "air", vy: 20, y: r.you.y + 4 }); + if (air) r.runner.line = -1; + r.you.ducking = x === R.lows[0][0] - 5 && !air; + r.runner.braking = r.you.ducking; + r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: -10, gone: 0 }); + for (let k = 0; k < 4; k++) g.tick(16); + r.monsters.length = 0; + r.you.safeMs = 1e9; + wagonAt(r, x, top[0], { safe: true }); + } + } + } + } + assert.equal(r.spec.id, "wagon"); + // A crash and the mob's catch. + r.you.safeMs = 0; + r.runner.gap = 30; + r.runner.props = []; + r.runner.smashed = r.runner.smashed.map(() => false); + wagonAt(r, R.blocks.find((b) => b[2] === 0)[0] - 8, R.blocks[0][1]); + for (let k = 0; k < 60; k++) g.tick(16); + assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too"); + const done = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + done.resize(900, 900); + done.key("action"); + done.tick(16); + const d = done.round; + through(d); + d.offer = ["village"]; + d.phaseMs = 0; + ghoul.pickStage(d, 0); + while (d.spec.id !== "wagon") through(d); + d.phase = "play"; + d.runner.done = true; + d.runner.restX = R.finish + 20; + Object.assign(d.you, { x: R.finish + 30, y: 7, state: "run" }); + d.camX = R.finish - 40; + for (let k = 0; k < 10; k++) done.tick(16); + for (const won of [true, false]) { + endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) }); + d.bonusRound.over = true; + for (let k = 0; k < 10; k++) { + done.tick(16); + bonusTick(d, { tone() {}, fx: {} }); + } + d.bonusRound.over = false; + } + // The stage select goes straight into it. + const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } }); + pick.resize(900, 900); + pick.stageSelect(); + const p = pick.round; + const at = ghoul.STAGES.findIndex((s) => s.id === "village"); + for (let i = 0; i < at; i++) ghoul.steerSelect(p, 1, 0); + for (let i = 0; i < 3; i++) ghoul.steerSelect(p, 0, 1); + assert.equal(p.select.room, 3); + pick.tick(16); + ghoul.takeSelect(p); + assert.equal(p.spec.id, "wagon"); + assert.equal(p.runner.line, 0); + assert.equal(p.you.y, ct.trackY(R, 0, ROOM.start)); + pick.tick(16); +}); + +/* ----------------------------------------------------------- the bots */ + +// A bot that plays well: it jumps at the end of a line (and at the bridge's lip, a little early), 7 to 12 short of a +// barrel, a crate or a charging horse, jumps a torch and ducks a pitchfork as they come, ducks every low, and +// holds the blaster. `miss` is the share of things it fails to dodge (by a hash). +const mix = (a, b) => { + let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +function goodBot(round, seed, miss = 0.04) { + const { you, runner: c, input: inp } = round; + inp.left = inp.right = inp.down = false; + inp.fire = true; + if (round.phase !== "play" || !c || c.done) { + inp.up = false; + return; + } + const ok = (x) => mix(seed, Math.round(x)) >= miss; + const look = 3 + (seed % 5); + let jump = false; + if (c.line >= 0) { + const last = c.line === lines.length - 1; + if (!last && lines[c.line].x1 - you.x < 2.2 && ok(lines[c.line].x1)) jump = true; + const cx = you.x + wg.REACH; + R.blocks.forEach(([x], i) => { + if (!c.smashed[i] && x - cx > 7 && x - cx < 7 + look && ok(x)) jump = true; + }); + c.horses.forEach((h, i) => { + if (h.state === "run" && h.x - cx > 13 && h.x - cx < 13 + look && ok(R.horses[i][0])) jump = true; + }); + for (const p of c.props) { + if (p.dead || p.x === undefined || !ok(p.x0)) continue; + const d = p.x - you.x; + if (p.kind && d > 6 && d < 12) jump = true; + if (!p.kind && d > -4 && d < 10) inp.down = true; + } + for (const [x0, x1] of R.lows) if (you.x > x0 - 3 && you.x < x1 + 2 && ok(x0)) inp.down = true; + } + if (jump && !inp.down) press(round); + else inp.up = false; +} +function idleBot(round) { + const inp = round.input; + inp.left = inp.right = inp.down = false; + inp.up = false; + inp.fire = false; +} +function rideWith(seed, bot, limit = 100000) { + const round = wagonRound(seed); + const lost = []; + let t = 0; + for (; t < limit && round.phase !== "clear" && !round.over; t += 16) { + bot(round); + if (round.runner && round.runner.done && round.phase === "play") round.input.right = true; + ghoul.advance(round, 16, steady); + for (const e of round.events) if (e.type === "lose") lost.push(e.cause); + if (round.runner && !round.runner.done) { + const off = round.you.x - round.camX; + assert.ok(off > 4 && off < 70, `the wagon stays in view (${off.toFixed(1)} from the left edge at ${round.you.x.toFixed(0)})`); + } + round.events.length = 0; + } + return { round, lost, ms: t }; +} + +test("Ghoul Rush's Torch Mob: a bot that dodges well finishes the whole road in 60 to 76 seconds, 6 to 9 dice, a few hearts lost at most, past every checkpoint", () => { + const dice = []; + for (let seed = 1; seed <= 12; seed++) { + const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed)); + const b = round.bonusRound; + assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")})`); + assert.ok(ms > 60000 && ms < 77000, `${ms} ms`); + assert.ok(b.dice >= 5 && b.dice <= ghoul.MAX_DICE, `${b.dice} dice`); + assert.equal(round.lives, 3, "never a run life"); + assert.equal(round.runner.done, true); + dice.push(b.dice); + } + assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 6, `${dice.join(",")}`); +}); + +test("Ghoul Rush's Torch Mob: a bot that never dodges loses all five hearts before the first half, ends with 0 dice and the run goes on", () => { + for (let seed = 1; seed <= 6; seed++) { + const { round, lost } = rideWith(seed, idleBot); + const b = round.bonusRound; + assert.equal(b.won, false, "never finishes"); + assert.equal(b.dice, 0); + assert.equal(b.hearts, 0); + assert.equal(lost.length, 5); + assert.ok(round.you.x < ROOM.length * 0.6, `out at ${round.you.x}`); + assert.equal(round.lives, 3); + assert.equal(round.over, false); + } +}); + +test("Ghoul Rush's Torch Mob: a bot that rides without ever braking or ducking but holds fire keeps the mob far, and one that holds DOWN the whole way is caught again and again", () => { + const seed = 3; + const braker = rideWith(seed, (r) => { + goodBot(r, seed, 1); + r.input.down = true; + }, 40000); + assert.ok(braker.lost.filter((c) => c === "mob").length >= 2, `${braker.lost.join(",")}`); +}); + +/* ------------------------------------------------------------ telegraphs */ + +test("Ghoul Rush's Torch Mob telegraphs: DUCK over washing lines, signs and pitchfork throwers, JUMP over ditches, the bridge, barrels, crates, torch throwers and horses, words only on the first three of each kind, the same every time", () => { + const marks = telegraphMarks(R); + assert.equal(marks.length, (R.track.length - 1) + R.blocks.length + R.lows.length + R.throwers.length + R.horses.length, "one per thing to dodge"); + for (const m of marks) assert.equal(m.answer, ANSWERS[m.kind], m.kind); + assert.equal(marks.filter((m) => m.kind === "bridge").length, 1); + assert.equal(marks.filter((m) => m.kind === "fork").every((m) => m.answer === "DUCK"), true); + assert.equal(marks.filter((m) => m.kind === "torch").every((m) => m.answer === "JUMP"), true); + const first = R.lows.find((l) => !l[3]); + const m = marks.find((q) => q.x === (first[0] + first[1]) / 2); + assert.equal(m.kind, "wash"); + const xs = [m.lead - 45, m.lead - 41, m.lead - 36, m.lead - 30, m.lead - 10, m.lead, m.lead + 3, m.lead + 7]; + const alphaOf = (x) => (telegraphs(R, x).find((t) => t.kind === "wash" && t.lead === m.lead) || { alpha: 0 }).alpha; + const a = xs.map(alphaOf); + assert.equal(a[0], 0, "not yet in view"); + assert.ok(a[2] > 0 && a[2] < 1, "fading in 40 to 30 ahead"); + assert.equal(a[3], 1); + assert.equal(a[4], 1); + assert.ok(a[6] > 0 && a[6] < 1, "fading as it passes"); + assert.equal(a[7], 0, "gone once passed"); + // The throwers' glyphs show earlier, over where the throw meets the wagon. + const t = marks.find((q) => q.kind === "fork"); + assert.ok(Math.abs(t.x - (R.throwers.find((q) => !q[2])[0] - wg.THROW_MEET)) < 0.01); + assert.ok(telegraphs(R, t.lead - 55).some((q) => q.lead === t.lead && q.alpha > 0.5), "seen from afar"); + assert.deepEqual(telegraphs(R, m.lead - 33), telegraphs(R, m.lead - 33), "deterministic"); + for (const kind of ["ditch", "barrel", "crate", "wash", "sign", "fork", "torch"]) { + const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead); + assert.ok(of.length >= 2, kind); + of.forEach((q, i) => { + assert.equal(q.n, i); + const shown = telegraphs(R, q.lead - 32).find((s) => s.lead === q.lead); + assert.equal(shown.words, i < 3, `${kind} ${i}`); + }); + } +}); + +test("Ghoul Rush's Torch Mob's intro banner says the controls plainly, DOWN's price included", () => { + assert.match(R.how, /UP to jump, DOWN to duck/); + assert.match(R.how, /slows you/); +}); diff --git a/scripts/test-web-console-activities-ghoul.mjs b/scripts/test-web-console-activities-ghoul.mjs index fddd4ee..00e978b 100644 --- a/scripts/test-web-console-activities-ghoul.mjs +++ b/scripts/test-web-console-activities-ghoul.mjs @@ -11,6 +11,7 @@ import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as ghoul from "../src/web-console/public/activities/ghoul.js"; +import { skipStory as storySkip } from "../src/web-console/public/activities/ghoul-story.js"; import { BANNER_SHADE, CHUNK, GAUGE_COOL, GAUGE_HOT, GAUGE_WARM, LOOKS, SEAM, VOICES, contrast, gaugeColor, hudLayout, labelSpot, limbInk } from "../src/web-console/public/activities/ghoul-draw.js"; import { ACCENTS } from "../src/web-console/public/palette.js"; import { humNames, toneNames } from "../src/web-console/public/tones.js"; @@ -22,6 +23,13 @@ const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), ".."); const GHOUL_TONES = Object.freeze(["ghoulBlast", "ghoulStomp", "ghoulBoo", "ghoulRoar", "ghoulCandy", "zombiePop", "zombieGroan", "batSwoop", "doorUnlock", "doorThrough", "creakBoard", "ghoulGrowl", "ghoulShriek", "ghoulSkitter", "ghoulSpit", "ghoulThunder"]); const steady = () => 0.5; +// Past the intro story at once (it has its own tests): a run opens on it, and the tests that play from the hall skip it. +function skipStory(g) { + if (g.round.phase !== "story") return; + storySkip(g.round); + g.tick(0); +} + /* ------------------------------------------------------------ canvases */ // A 2D context whose every method is a no-op that counts itself. @@ -158,6 +166,14 @@ function withTokens(values, fn) { /* ---------------------------------------------------------- round helpers */ +// Past a stage's intro card at once (the card has its own tests). +// Leaves a stage's intro card or a boss room's (phase "intro" or "bossintro"). +function skipIntro(round) { + if (round.phase !== "intro" && round.phase !== "bossintro") return; + round.introMs = ghoul.INTRO_MIN_MS; + ghoul.takeIntro(round); +} + // Goes through the door of the room the round is in. function through(round) { round.phase = "clear"; @@ -254,6 +270,7 @@ test("Ghoul Rush answers the game contract: ready until started, pause and resum assert.equal(g.resize(ghoul.W * ghoul.MIN_CELL, ghoul.H * ghoul.MIN_CELL), true, "just big enough"); assert.equal(g.resize(2000, 2000), true); g.start(); + skipStory(g); g.round.dice = 0; assert.equal(g.state, "running"); g.pause(); @@ -938,7 +955,7 @@ test("Ghoul Rush: every room but a boss's keeps a horde coming in from the edges for (const base of ghoul.ROOMS) { if (base.boss) assert.deepEqual([base.horde.length, base.hordeMs], [0, 0], `${base.id}: no horde in a boss's room`); else if (base.ride && base.ride.gallery) assert.deepEqual([base.horde.length, base.hordeMs], [0, 0], `${base.id}: the dark ride is a gallery, no horde`); - else if (base.ride && base.ride.sled) assert.deepEqual([base.horde.length, base.hordeMs], [0, 0], `${base.id}: the sled's things are the pack's own, no horde`); + else if (base.ride && (base.ride.sled || base.ride.runner)) assert.deepEqual([base.horde.length, base.hordeMs], [0, 0], `${base.id}: a ride's things are the pack's own, no horde`); else assert.ok(base.horde.length > 0 && base.hordeMs > 0, `${base.id} has a horde`); for (const kind of base.horde) assert.ok(ghoul.MONSTERS[kind], `${base.id}: ${kind} is a monster`); } @@ -1020,7 +1037,7 @@ test("Ghoul Rush: Spread shot and Rapid fire run out after their time, the Garli ghoul.applyPower(round, "spread"); ghoul.applyPower(round, "rapid"); ghoul.advance(round, ghoul.POWERS.spread.ms + 8, steady); - assert.deepEqual(round.effects, { spread: 0, rapid: 0, lantern: 0, wings: 0, bell: 0, silver: 0, shears: 0, holy: 0, salts: 0, saw: 0, bane: 0, floss: 0, cocoa: 0 }); + assert.deepEqual(round.effects, { spread: 0, rapid: 0, lantern: 0, wings: 0, bell: 0, silver: 0, shears: 0, holy: 0, salts: 0, saw: 0, bane: 0, floss: 0, cocoa: 0, boots: 0 }); assert.equal(events(round, "expire").length, 2); ghoul.applyPower(round, "garlic"); const z = put(round, "zombie", 30); @@ -1052,6 +1069,34 @@ test("Ghoul Rush: Spread shot and Rapid fire run out after their time, the Garli assert.equal(r2.drops.length, 0, "and taken"); }); +test("Ghoul Rush's Long Hall is always lit until you take its key, then the lights go out and stay out, even after you lose a life; no other room does this", () => { + const spec = ghoul.roomById("hall"); + assert.equal(spec.dark, false); + assert.equal(spec.darkOnKey, true); + for (let seed = 1; seed <= 100; seed++) assert.equal(ghoul.newRound(seed).dark, false, `seed ${seed} starts lit`); + assert.deepEqual(ghoul.ROOMS.filter((r) => r.darkOnKey).map((r) => r.id), ["hall"]); + const round = ghoul.newRound(1); + round.dice = 0; + round.phase = "play"; + ghoul.advance(round, 4, steady); + assert.equal(round.dark, false, "lit on the way to the key"); + assert.equal(round.events.some((e) => e.type === "keyDark"), false); + Object.assign(round.you, { x: spec.key[0], y: spec.key[1], vx: 0, vy: 0, state: "run", safeMs: 1e9 }); + round.camX = Math.max(0, spec.key[0] - 36); + ghoul.advance(round, 4, steady); + assert.equal(round.hasKey, true); + assert.equal(round.dark, true, "the lights go out"); + assert.equal(round.events.filter((e) => e.type === "keyDark").length, 1); + // A lost life keeps the key, so the dark stays too. + ghoul.lose(round, "zombie"); + ghoul.advance(round, ghoul.CRASH_MS + ghoul.READY_MS + 40, steady); + assert.equal(round.spec.id, "hall"); + assert.equal(round.hasKey, true); + assert.equal(round.dark, true, "still out after a respawn"); + // The next run's hall is lit again. + assert.equal(ghoul.newRound(1).dark, false); +}); + test("Ghoul Rush: a room is dark some of the times it is entered, the same each time for a seed, and a lit one never has a Lantern, placed or dropped", () => { const rooms = []; for (let seed = 1; seed <= 400; seed++) { @@ -1064,11 +1109,19 @@ test("Ghoul Rush: a room is dark some of the times it is entered, the same each while (round.spec.id !== "library") through(round); rooms.push(round); } - // Each run's hall. - const halls = Array.from({ length: 400 }, (_, i) => ghoul.newRound(i + 1).dark); - const share = halls.filter(Boolean).length / halls.length; + // The Library across 400 runs. + const share = rooms.filter((r) => r.dark).length / rooms.length; assert.ok(Math.abs(share - ghoul.DARK_CHANCE) < 0.08, `dark ${share} of the time`); - assert.deepEqual(Array.from({ length: 50 }, (_, i) => ghoul.newRound(i + 1).dark), halls.slice(0, 50), "a seed plays the same"); + for (let seed = 1; seed <= 50; seed++) { + const again = ghoul.newRound(seed); + again.dice = 0; + through(again); + again.offer = ["manor"]; + again.phaseMs = 0; + ghoul.pickStage(again, 0); + while (again.spec.id !== "library") through(again); + assert.equal(again.dark, rooms[seed - 1].dark, "a seed plays the same"); + } const lit = rooms.filter((r) => !r.dark); const dark = rooms.filter((r) => r.dark); assert.ok(lit.length && dark.length, "the Library both ways"); @@ -1703,7 +1756,9 @@ test("Ghoul Rush: out of the hall, and out of each boss's room, you pick the nex assert.equal(ghoul.steerPick(r2, 1), r2.offer.length > 1); const want = r2.offer[r2.pick]; assert.equal(ghoul.pickStage(r2), true); - assert.deepEqual([r2.stage, r2.stageAt, r2.offer, r2.room, r2.phase], [want, 0, null, 2, "ready"]); + assert.deepEqual([r2.stage, r2.stageAt, r2.offer, r2.room, r2.phase], [want, 0, null, 2, "intro"], "the stage's intro card comes first"); + skipIntro(r2); + assert.equal(r2.phase, "ready"); assert.equal(r2.spec.id, ghoul.stageById(want).rooms[0]); assert.deepEqual(events(r2, "stage").map((e) => [e.stage, e.n]), [[want, 1]]); // Through the stage's rooms in order, then the boss's door: cleared, and @@ -2320,7 +2375,10 @@ function botPlay(seed, skill, rooms, limitMs = 15 * 60000) { if (round.phase === "pick" && round.phaseMs <= 0) { if (!round.cleared.includes("manor") && !round.offer.includes("manor")) round.offer[0] = "manor"; ghoul.pickStage(round, Math.max(0, round.offer.indexOf("manor"))); + skipIntro(round); } + // A boss room opens on its card (a stage's own was skipped at the pick). + skipIntro(round); bot(round); ghoul.advance(round, 16, random); ms += 16; @@ -2353,8 +2411,10 @@ test("Ghoul Rush: of ten runs a sharp bot gets nearly all through the hall and t // The Rotting Gourd's room (the fifth, after the hall) runs longer: the // blaster has to cool between bursts at a boss. So does the sixth, the // first of whichever stage the pick deals (it changes with every stage - // added: Hollow End's Main Street takes the bot up to a minute). - per.forEach((p, i) => assert.ok(p.secs >= 10 && p.secs <= (i === 4 ? 60 : i === 5 ? 70 : 40), `seed ${seed}: room ${i + 1} took ${p.secs.toFixed(1)} s`)); + // added: Hollow End's Main Street takes the bot up to a minute). The + // Gourd's bound has room for the slow end of the bot's spread, about a + // minute, which is one seed or two in thirty. + per.forEach((p, i) => assert.ok(p.secs >= 10 && p.secs <= (i === 4 ? 65 : i === 5 ? 70 : 40), `seed ${seed}: room ${i + 1} took ${p.secs.toFixed(1)} s`)); } assert.ok(outOfFoyer >= 9, `${outOfFoyer} of 10 through the hall and out of the Foyer`); assert.ok(pastGourd >= 5, `${pastGourd} of 10 past the Gourd`); @@ -2393,6 +2453,14 @@ function takeManor(g) { if (!r.cleared.includes("manor") && !r.offer.includes("manor")) r.offer[0] = "manor"; r.pick = Math.max(0, r.offer.indexOf("manor")); g.key("action"); + leaveIntro(g); +} + +// Past a stage's intro card the way a player does: the minimum wait, then fire. +function leaveIntro(g) { + if (g.round.phase !== "intro" && g.round.phase !== "bossintro") return; + for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 50; ms += 16) g.tick(16); + g.key("action"); } // Starts a game with nothing waking. @@ -2401,6 +2469,7 @@ function ghoulGame(opts = {}) { const g = ghoul.default.create({ canvas, ...opts }); g.resize(900, 900); g.key("action"); + skipStory(g); g.tick(16); quiet(g.round); return { g, calls }; @@ -2463,6 +2532,7 @@ test("Ghoul Rush game: space while paused does nothing (only the window plays on const g = ghoul.default.create({ canvas }); g.resize(900, 900); g.key("action"); + skipStory(g); g.round.dice = 0; assert.equal(g.state, "running"); assert.equal(g.round.input.fire, false, "the press that starts never fires"); @@ -2493,9 +2563,11 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows g.resize(900, 900); assert.ok(texts.some(([t]) => t.includes(`Best: 0 of ${ghoul.STAGES.length} stages`)), "the start screen names the record"); g.key("action"); + skipStory(g); g.round.dice = 0; g.tick(16); const through = () => { + leaveIntro(g); const r = g.round; quiet(r); r.hasKey = true; @@ -2521,7 +2593,8 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows assert.equal(g.round.phase, "pick", "never on a key repeat"); const want = g.round.offer[0]; g.key("action"); - assert.deepEqual([g.round.stage, g.round.input.fire], [want, false], "space takes the stage, and fires nothing"); + assert.deepEqual([g.round.stage, g.round.input.fire, g.round.phase], [want, false, "intro"], "space takes the stage, and fires nothing"); + leaveIntro(g); for (let k = 0; k < ghoul.stageById(want).rooms.length - 1; k++) { through(); assert.equal(saved, 0, "no stage cleared yet"); @@ -2535,6 +2608,7 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows for (let ms = 0; ms < ghoul.PICK_HOLD_MS + 50; ms += 16) g.tick(16); g.key("up"); assert.ok(g.round.stage && g.round.stage !== want, "up takes one too, never the stage just cleared"); + leaveIntro(g); for (let ms = 0; ms < ghoul.READY_MS + 50; ms += 16) g.tick(16); g.round.dice = 0; g.round.lives = 1; @@ -2574,11 +2648,15 @@ test("Ghoul Rush game: stageSelect() (the window's stage code) opens a practice const last = ghoul.STAGES.length - 1; for (let i = 0; i < last + 3; i++) g.key("down"); assert.equal(r.select.at, last, "down stops at the last stage"); - // Two up: the Mine, whose second to last room is a walked one (the Carnival's is the dark ride). + // Two up clamps inside the list; then steer on to the Manor, whose second + // to last room is a runner ride (the Carnival's is the dark ride's + // gallery, whose end screen carries no tally line). g.key("up"); g.key("up"); assert.equal(r.select.at, last - 2); - const st = ghoul.STAGES[last - 2]; + const st = ghoul.STAGES[0]; + for (let i = 0; i < ghoul.STAGES.length; i++) g.key("up"); + assert.equal(r.select.at, 0, "the Manor"); for (let i = 0; i < st.rooms.length + 3; i++) g.key("right"); assert.equal(r.select.room, st.rooms.length - 1, "right stops at the boss room"); g.key("left"); @@ -2647,6 +2725,7 @@ test("Ghoul Rush game: every tone it plays is one tones.js has, its own blips am const g = ghoul.default.create({ canvas: stubCanvas().canvas, tone: (name) => heard.add(name) }); g.resize(900, 900); g.key("action"); + skipStory(g); const bot = makeBot(ghoul, 1, ghoul.seeded(3)); for (let ms = 0; ms < 90000 && g.round.room < 3 && g.state === "running"; ms += 16) { takeManor(g); @@ -2672,6 +2751,7 @@ test("Ghoul Rush game: its own sounds keep its prefix, and a run holds a monster }); g.resize(900, 900); g.key("action"); + skipStory(g); g.round.dice = 0; const bot = makeBot(ghoul, 1, ghoul.seeded(3)); for (let ms = 0; ms < 180000 && g.round.room < 4 && g.state === "running"; ms += 16) { @@ -2696,6 +2776,7 @@ test("Ghoul Rush game: its own sounds keep its prefix, and a run holds a monster const h = ghoul.default.create({ canvas: stubCanvas().canvas, tone: (name) => sounds.push(name) }); h.resize(900, 900); h.key("action"); + skipStory(h); h.round.dice = 0; h.round.lives = 1; for (let k = 0; k < 60; k++) h.tick(16); @@ -2753,6 +2834,7 @@ test("Ghoul Rush game: a banner fades to see-through while something that can hu const g = ghoul.default.create({ canvas }); g.resize(900, 900); g.key("action"); + skipStory(g); quiet(g.round); for (let k = 0; k < 10; k++) g.tick(16); assert.ok(alphas.at(-1) > 0.9, `clear strip: solid (${alphas.at(-1)})`); @@ -2774,6 +2856,7 @@ test("Ghoul Rush game: a \"Ready?\" banner still waiting when play begins is dro const g = ghoul.default.create({ canvas, best: () => 1 }); g.resize(900, 900); g.key("action"); + skipStory(g); g.round.dice = 0; quiet(g.round); g.tick(16); @@ -2822,7 +2905,7 @@ test("Ghoul Rush: every pill's text reads at 4.5:1 on its backing and its timer' assert.ok(k >= 4.5, `${theme}/${id}: "${p.text}" in ${p.ink} on ${under} reads ${k.toFixed(2)}:1`); } } - for (const want of ["THE LONG HALL", `STAGE 0 OF ${ghoul.STAGES.length}`, "♥", "BONUS 0", "~CHAIN x4", "KEY", "~SPREAD", "~RAPID", "GARLIC"]) { + for (const want of ["THE LONG HALL", `STAGE 0 OF ${ghoul.STAGES.length}`, "♥", "BONUS 0", "~CHAIN x4", "~SPREAD", "~RAPID", "GARLIC"]) { const tinted = want.startsWith("~"); const text = tinted ? want.slice(1) : want; assert.ok(seen.some((p) => p.text.includes(text) && (!tinted || p.tints.length)), `${theme}/${id}: "${text}" drawn (${seen.map((p) => p.text)})`); @@ -2883,6 +2966,7 @@ test("Ghoul Rush: the blaster's gauge fills with its heat, notched where the bol const g = ghoul.default.create({ canvas: stubCanvas().canvas }); g.resize(900, 900); g.key("action"); + skipStory(g); for (let k = 0; k < 5; k++) g.tick(16); const gauge = () => g.hud.gauge; assert.equal(gauge().free, ghoul.HEAT_FREE / ghoul.HEAT_MAX, "the notch sits where fireGap() starts to slow"); @@ -2933,6 +3017,7 @@ test("Ghoul Rush game: the opening banner sits in the field from the start's fir g.resize(900, 900); shades.length = 0; g.key("action"); + skipStory(g); assert.equal(shades.length, 1, "the start paints its banner"); const [[top, h]] = shades; assert.ok(top >= 0 && top + h <= ghoul.FIELD_H, `inside the field (${top})`); @@ -2947,6 +3032,7 @@ test("Ghoul Rush game: Planny keeps his star eye in your highlight running, firi const g = ghoul.default.create({ canvas }); g.resize(900, 900); g.key("action"); + skipStory(g); g.round.dice = 0; g.tick(16); quiet(g.round); @@ -2996,6 +3082,7 @@ test("Ghoul Rush game: what never moves in a room is drawn off screen once, CHUN const g = ghoul.default.create({ canvas }); g.resize(900, 900); g.key("action"); + skipStory(g); g.tick(16); quiet(g.round); g.tick(16); @@ -3040,6 +3127,7 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug const g = ghoul.default.create({ canvas }); g.resize(900, 900); g.key("action"); + skipStory(g); for (let n = 1; n <= ghoul.ROOMS.length; n++) { const r = g.round; r.lives = 99; @@ -3052,6 +3140,7 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug g.tick(16); } assert.ok(calls.count > drawn, `room ${n} draws`); + leaveIntro(g); if (r.boss) r.boss.state = "down"; r.hasKey = true; // Through the door, once any life lost in the run is over with. @@ -3070,6 +3159,7 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug g.tick(16); } if (n === ghoul.ROOMS.length) break; + leaveIntro(g); for (let ms = 0; ms < ghoul.READY_MS + 100; ms += 16) g.tick(16); assert.equal(g.round.room, n + 1); } diff --git a/src/web-console/public/activities/ghoul-arms.js b/src/web-console/public/activities/ghoul-arms.js index 34491c1..4b38a8d 100644 --- a/src/web-console/public/activities/ghoul-arms.js +++ b/src/web-console/public/activities/ghoul-arms.js @@ -63,12 +63,14 @@ export const ARM_GAP_MS = 220; export const ARM_BOSS_SHARE = 0.35; // Dynamite: a throw leaves at DYN_VX across and DYN_VY up, blows up DYN_FUSE_MS -// after it leaves; the blast is BLAST_W wide, BLAST_UP over the stick and +// after it leaves, or at once when a monster stands within DYN_PROX of it once it has +// landed; the blast is BLAST_W wide, BLAST_UP over the stick and // BLAST_DOWN under it, shows BLAST_MS, does BLAST_DAMAGE to a monster (and breaks // stone) and DYN_BOSS_DMG to a boss. export const DYN_VX = 30; export const DYN_VY = 38; export const DYN_FUSE_MS = 1000; +export const DYN_PROX = 1; export const BLAST_W = 22; export const BLAST_UP = 9; export const BLAST_DOWN = 3; @@ -79,6 +81,12 @@ export const DYN_BOSS_DMG = 8; export const STAKE_SPEED = 96; export const STAKE_DMG = 12; export const STAKE_BOSS = 8; +// The Harpoon: the same straight pierce, heavier and slower, and the only +// bolt that reaches a lurker's eyes under the water (Gallows Bog, see +// `target` in ghoul-bog.js). +export const HARPOON_SPEED = 84; +export const HARPOON_DMG = 14; +export const HARPOON_BOSS = 8; // The Bottle Rocket: three at once, ahead, up and behind (ghoul-rockets.js). export * from "./ghoul-rockets.js"; // The Hedge Sickle: SICKLE_OUT out and back, SICKLE_DMG a pass. @@ -342,6 +350,7 @@ const USES = freeze({ flash: (round, k) => lobPod(round, k, "flash", true), pie: lobPie, flare: (round, k) => useFlare(round, k, lobVx(round, k, FLARE_VY, FLARE_VX)), + harpoon: (round, k) => armShot(round, k, "harpoon", HARPOON_SPEED, { dmg: HARPOON_DMG, bossDmg: HARPOON_BOSS, pierce: true }), trap: (round) => { const you = round.you; // Five at once, TRAP_GAP apart: two behind, one at his feet, two ahead. @@ -434,7 +443,9 @@ function stepStick(round, h, ms, k) { h.fuse -= ms; h.spin += (ms / 1000) * 14; if (!h.rest && !flyDown(round, h, ms, k)) return false; - if (h.fuse > 0) return true; + // Landed: it also goes off at once when a monster comes within DYN_PROX of it. + const near = h.rest && round.monsters.some((m) => !m.dead && (k.solid(m) || k.stone(m)) && Math.max(0, Math.abs(m.x - h.x) - m.w / 2) <= DYN_PROX && h.y >= m.y - DYN_PROX && h.y <= m.y + m.h + DYN_PROX); + if (h.fuse > 0 && !near) return true; blast(round, h, k); return false; } diff --git a/src/web-console/public/activities/ghoul-banister-draw.js b/src/web-console/public/activities/ghoul-banister-draw.js new file mode 100644 index 0000000..9a86e9b --- /dev/null +++ b/src/web-console/public/activities/ghoul-banister-draw.js @@ -0,0 +1,1044 @@ +// Plan2Code Web Console - Ghoul Rush's Grand Banister, its drawing: a night ride down the Manor's grand staircase on its endless polished banister. A wall of damask and moonlit windows, a zig-zag of staircase flights and landings behind you, portraits whose eyes follow YOU, the mahogany handrail on its balusters (and the brass under-rail where the track splits), vases and candlesticks on the rail, hanging portrait frames, chandeliers swinging on a visible pendulum, ghostly butlers with silver trays, cobwebs, the attic landing at the start and the foyer at the end. +// +// ghoul-draw.js plugs it in. LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are plain +// data; banisterArt(d) takes ghoul-draw.js's drawing helpers (`d`) and hands back the drawing by +// kind, so this file never reaches back into it. Drawn in room units, the way ghoul-draw.js draws: +// y counted down from the field's top, so a world height `y` is drawn at `FIELD_H - y`. The still +// layers' pit is dark under the whole ride, so the wall, the stairs, the rail and what stands on +// it are drawn by `moving` (every frame, over the cached still layers); the hanging frames, the +// chandeliers, the sparks off your feet and the telegraphs by `front`. No random numbers: +// everything comes from a hash. What the art reads off the rules (ghoul-banister.js): +// +// - the room: `spec.ride` ({ track, rails, props, lows, swings, butlers, webs, checks, finish }), +// `spec.ground` (the attic landing at the start and the foyer floor at the end), `spec.door`. +// - `round.runner` (id "banister"; null in any other room): `v`, `line` (-1 in the air), `check`, +// `done`, `clock` (the pendulums' time), `dive`, `butlers` [{ state "wait" | "warn" | "lunge" | +// "broken" | "spent", t, x }], `webs` ["up" | "torn" | "shot"]. +// - YOU: `you.state`, `you.vy`, `you.ducking`, `you.x`, `you.y` (the portraits' eyes follow). +// - events leave short-lived bits in the view's `fx` (`banBits`, `banLand`). + +import { linesOf, trackY } from "./ghoul-cart.js"; +import { BUTLER_H, CANDLE_H, SWING_BOB_W, WEB_HI, WEB_LO, lowerLine, swingAt } from "./ghoul-banister.js"; +import { ANSWER_COLORS, TELEGRAPH_ALPHA, TELEGRAPH_FULL, TELEGRAPH_SEE, TELEGRAPH_WORDS } from "./ghoul-sled-draw.js"; + +const freeze = (o) => Object.freeze(o); +const TAU = Math.PI * 2; +const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x)); + +const pit = (o) => freeze({ pack: "banister", custom: true, noMoon: true, pit: "#0a0610", ...o }); +export const LOOKS = freeze({ + banister: pit({ wallTop: "#1a0b12", wallLow: "#2f1220", paper: "#3d1828", wainscot: "#1c0d12", floorTop: "#8a6a44", floor: "#3a2616", floorEdge: "#140a0c", shelf: "#3a2616", shelfTop: "#8a6a44", window: "#cfd8ff", decor: "stairs", color: "#d9a35a", dark: 0.45 }), +}); + +// How each new kind sounds, by act (the sounds are in ghoul-sfx-banister.js). +export const VOICES = freeze({ + ban: freeze({ jump: "ghoulBanJump", land: "ghoulBanLand", launch: "ghoulBanLaunch", duck: "ghoulBanDuck", switch: "ghoulBanSwitch", crash: "ghoulBanCrash", check: "ghoulBanCheck", finish: "ghoulBanFinish" }), + banbutler: freeze({ warn: "ghoulBanButlerWarn", lunge: "ghoulBanButlerLunge", hit: "ghoulBanButlerHit", break: "ghoulBanButlerBreak" }), + banweb: freeze({ tear: "ghoulBanWebTear", shot: "ghoulBanWebShot" }), +}); + +// What each of the pack's events plays: [kind, act], once. +export const EVENT_VOICE = freeze({ + banJump: ["ban", "jump"], + banLand: ["ban", "land"], + banLaunch: ["ban", "launch"], + banDuck: ["ban", "duck"], + banSwitch: ["ban", "switch"], + banCrash: ["ban", "crash"], + banCheck: ["ban", "check"], + banFinish: ["ban", "finish"], + banButlerWarn: ["banbutler", "warn"], + banButlerLunge: ["banbutler", "lunge"], + banButlerHit: ["banbutler", "hit"], + banButlerBreak: ["banbutler", "break"], + banWebTear: ["banweb", "tear"], + banWebShot: ["banweb", "shot"], +}); +export const LOSE_WORDS = freeze({ vase: "Smashed a vase", candle: "Hit a candlestick", frame: "Hit a hanging frame", swing: "Struck by the chandelier", butler: "Tray to the face", plunge: "Fell off the banister" }); +export const LOSE_SOUNDS = freeze({ + vase: ["smash", 0.6, 1.2], + candle: ["clank", 0.5, 1.1], + frame: ["thud", 0.6, 0.9], + swing: ["smash", 0.6, 0.7], + butler: ["clank", 0.6, 0.7], + plunge: ["ghoulPitFall", 0.55, 0.9], +}); + +const FW = 96; +const BAN_V = 46; +const DUCK_H = 2.4; +const WOOD = "#6b2f1a"; +const WOOD_D = "#2a0f0a"; +const WOOD_L = "#e0a070"; +const BRASS = "#d9b050"; +const BRASS_L = "#fff0b0"; +const GHOST = "#b8d0ec"; +let FH = 54; + +// A number in 0..1 from two integers, the same every time (no random draws). +const rnd = (a, b = 0) => { + let h = Math.imul((a | 0) + 0x9e37, 0x85ebca6b) ^ Math.imul((b | 0) + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +const poly = (c, pts) => { + c.beginPath(); + pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); + c.closePath(); +}; +const seg = (c, x0, y0, x1, y1) => { + c.beginPath(); + c.moveTo(x0, y0); + c.lineTo(x1, y1); + c.stroke(); +}; +const disc = (c, x, y, r) => { + c.beginPath(); + c.arc(x, y, r, 0, TAU); + c.fill(); +}; +const grad = (make, stops) => { + const g = make ? make() : null; + if (!g || typeof g.addColorStop !== "function") return stops[stops.length >> 1][1]; + for (const [o, col] of stops) g.addColorStop(o, col); + return g; +}; +const vgrad = (c, y0, y1, stops) => grad(c.createLinearGradient && (() => c.createLinearGradient(0, y0, 0, y1)), stops); +const rgrad = (c, x, y, r, stops) => grad(c.createRadialGradient && (() => c.createRadialGradient(x, y, 0, x, y, r)), stops); + +// A soft glow at a light. +const HALO = freeze({ warm: "255,190,100", red: "255,70,50", green: "90,240,130", cold: "170,200,255", gold: "255,220,130" }); +function halo(ctx, kind, x, y, r, alpha) { + ctx.globalAlpha = alpha; + ctx.fillStyle = rgrad(ctx, x, y, r, [[0, `rgba(${HALO[kind]},0.9)`], [0.4, `rgba(${HALO[kind]},0.3)`], [1, `rgba(${HALO[kind]},0)`]]); + disc(ctx, x, y, r); + ctx.globalAlpha = 1; +} + +/* ------------------------------------------------------------ the rails */ + +// The y of a line at x (null off its ends). +const yOf = (R, line, x) => trackY(R, line, x); +// The handrail's height at x (null over a break). +const heightAt = (R, x) => { + let best = null; + for (let i = 0; i < R.rails; i++) { + const y = trackY(R, i, x); + if (y !== null && (best === null || y > best)) best = y; + } + return best; +}; + +// The points of line `line` over [xa, xb] (its own, and the ends clipped to the range). +function pathOf(R, line, xa, xb) { + const L = linesOf(R)[line]; + const lo = Math.max(xa, L.x0); + const hi = Math.min(xb, L.x1); + if (hi <= lo) return []; + const out = [[lo, trackY(R, line, lo)]]; + for (const [px, py] of L.pts) if (px > lo + 0.01 && px < hi - 0.01) out.push([px, py]); + out.push([hi, trackY(R, line, hi)]); + return out; +} + +/* ------------------------------------------------------------ telegraphs */ + +export const ANSWERS = freeze({ gap: "JUMP", vase: "JUMP", candle: "JUMP", frame: "DUCK", swing: "DUCK", end: "JUMP", dive: "DIVE" }); +export const COLORS = freeze({ ...ANSWER_COLORS, DIVE: "#d28bff" }); + +const marks = new WeakMap(); +// Every obstacle that wants a glyph: { kind, lead (where it begins), x (its middle), up (height of +// the glyph's anchor), n (which of its kind), answer }, in the room's order. Butlers and webs are +// shot, so they get none; the under-rails get a DIVE at their start and a JUMP at their end. +export function telegraphMarks(R) { + if (marks.has(R)) return marks.get(R); + const out = []; + const count = {}; + const add = (kind, lead, x, up) => { + const n = count[kind] || 0; + count[kind] = n + 1; + out.push({ kind, lead, x, up, n, answer: ANSWERS[kind] }); + }; + for (let i = 0; i + 1 < R.rails; i++) { + const a = R.track[i].at(-1)[0]; + const b = R.track[i + 1][0][0]; + add("gap", a, (a + b) / 2, Math.max(heightAt(R, a - 0.1) ?? 0, heightAt(R, b + 0.1) ?? 0) + 6.5); + } + for (const [x, line, kind] of R.props) add(kind ? "candle" : "vase", x - 2, x, (yOf(R, line, x) ?? 10) + 7.5); + for (const [x0, x1, y] of R.lows) add("frame", x0 - 3.2, (x0 + x1) / 2, y + 6.8); + for (const [cx, line, amp] of R.swings) add("swing", cx - amp - 4, cx, (yOf(R, line, cx) ?? 10) + 9); + for (let i = R.rails; i < R.track.length; i++) { + const L = linesOf(R)[i]; + add("dive", L.x0 - 14, L.x0 + 4, (heightAt(R, L.x0 + 4) ?? 20) + 7); + add("end", L.x1 - 7, L.x1 - 2, L.pts.at(-1)[1] + 6.5); + } + out.sort((p, q) => p.lead - q.lead); + marks.set(R, out); + return out; +} + +// The glyphs showing with you at `x`: { ...mark, alpha (0..1, before the pulse), words }. +export function telegraphs(R, x) { + const out = []; + for (const m of telegraphMarks(R)) { + const d = m.lead - x; + if (d > TELEGRAPH_SEE || d < -6) continue; + const alpha = Math.min(clamp((TELEGRAPH_SEE - d) / (TELEGRAPH_SEE - TELEGRAPH_FULL), 0, 1), clamp((d + 4) / 6, 0, 1)); + if (alpha > 0.01) out.push({ ...m, alpha, words: m.n < TELEGRAPH_WORDS }); + } + return out; +} + +/* --------------------------------------------------------------------- art */ + +export function banisterArt(d) { + const { ellipse, say, label, GOLD } = d; + const ride = (v) => (v.spec && v.spec.ride && v.spec.ride.runner === "banister" ? v.spec.ride : null); + const state = (v) => (v.round && v.round.runner && v.round.runner.id === "banister" ? v.round.runner : null); + const sy = (y) => FH - y; + // Calls fn(x, k) for each repeat of a layer of spacing `W` at parallax `par` (1 moves with the rail). + const strips = (cam, par, W, w, fn) => { + const ox = cam * (1 - par); + const k0 = Math.floor((cam - ox - w) / W); + const k1 = Math.floor((cam + FW - ox) / W); + for (let k = k0; k <= k1; k++) fn(ox + k * W, k); + }; + + /* ------------------------------------------------------------- the room */ + + // The still layers only get the wall's color: the hall is drawn by `moving`. + function backdrop(ctx, v, look, x0, x1) { + ctx.fillStyle = look.wallLow; + ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H); + } + // The attic landing at the start (bare boards, a trunk) and the foyer floor at the end (marble). + function ground(ctx, v, look, a, b, top) { + const y = v.g.FIELD_H - top; + const foyer = a > 100; + ctx.fillStyle = vgrad(ctx, y, y + top, foyer ? [[0, "#d8d2c8"], [0.2, "#8e8878"], [1, "#2a2620"]] : [[0, "#8a6a44"], [0.2, "#4a3420"], [1, "#1c120a"]]); + ctx.fillRect(a, y, b - a, top + 2); + if (foyer) { + ctx.fillStyle = "rgba(20,18,16,0.55)"; + for (let x = Math.floor(a / 4) * 4, k = 0; x < b; x += 4, k++) if (k % 2 === 0) ctx.fillRect(x, y, 4, 1.6); + } else { + ctx.strokeStyle = "rgba(20,10,4,0.7)"; + ctx.lineWidth = 0.12; + for (let x = a; x < b; x += 3.5) seg(ctx, x, y, x, y + 1.8); + } + ctx.fillStyle = foyer ? "#f2ece0" : "#b08a58"; + ctx.fillRect(a, y, b - a, 0.3); + } + function shelf() {} + + // The wall: damask in stripes, gilt dado, and the moonlit tall windows with their shafts. + function wall(ctx, cam, clock) { + ctx.fillStyle = vgrad(ctx, 0, FH, [[0, "#12070d"], [0.5, "#2c1120"], [1, "#150910"]]); + ctx.fillRect(cam - 1, 0, FW + 2, FH); + strips(cam, 0.9, 6, 1, (x, k) => { + ctx.fillStyle = k % 2 ? "rgba(90,30,48,0.28)" : "rgba(30,10,20,0.3)"; + ctx.fillRect(x, 0, 3, FH); + ctx.fillStyle = "rgba(200,150,90,0.1)"; + for (let q = 0; q < 6; q++) { + poly(ctx, [[x + 1.5, 4 + q * 8], [x + 2.2, 5.2 + q * 8], [x + 1.5, 6.4 + q * 8], [x + 0.8, 5.2 + q * 8]]); + ctx.fill(); + } + }); + strips(cam, 0.55, 72, 8, (x, k) => { + const wx = x + 30; + ctx.fillStyle = "rgba(150,170,230,0.07)"; + poly(ctx, [[wx - 3, 8], [wx + 3, 8], [wx + 16, FH], [wx - 10, FH]]); + ctx.fill(); + ctx.fillStyle = vgrad(ctx, 5, 30, [[0, "#9db4e8"], [1, "#2c3a66"]]); + ctx.beginPath(); + ctx.moveTo(wx - 3.6, 30); + ctx.lineTo(wx - 3.6, 12); + ctx.arc(wx, 12, 3.6, Math.PI, 0); + ctx.lineTo(wx + 3.6, 30); + ctx.closePath(); + ctx.fill(); + ctx.strokeStyle = "#1a0d12"; + ctx.lineWidth = 0.35; + ctx.stroke(); + seg(ctx, wx, 8.4, wx, 30); + seg(ctx, wx - 3.6, 17, wx + 3.6, 17); + seg(ctx, wx - 3.6, 23, wx + 3.6, 23); + // A tall drape each side. + ctx.fillStyle = "#4a1020"; + poly(ctx, [[wx - 6.4, 5], [wx - 4, 5], [wx - 4.6, 34], [wx - 7.4, 34]]); + ctx.fill(); + poly(ctx, [[wx + 4, 5], [wx + 6.4, 5], [wx + 7.4, 34], [wx + 4.6, 34]]); + ctx.fill(); + }); + // Dust in the shafts. + for (let q = 0; q < 14; q++) { + const p = (clock / (5200 + (q % 5) * 700) + rnd(q, 1)) % 1; + const mx = cam + ((((rnd(q, 2) * FW - cam * 0.5 - p * 6) % FW) + FW) % FW); + ctx.fillStyle = `rgba(220,226,255,${0.15 + 0.2 * rnd(q, 3)})`; + ctx.fillRect(mx, 6 + p * 40, 0.22, 0.22); + } + } + + // A portrait in a gilt frame whose eyes follow YOU: centered (x, y) in screen units, w by h. + function portrait(ctx, x, y, w, h, n, tx, ty, lit) { + ctx.fillStyle = "rgba(0,0,0,0.35)"; + ctx.fillRect(x - w / 2 + 0.4, y - h / 2 + 0.4, w, h); + ctx.fillStyle = lit ? "#b88a30" : "#8a6420"; + ctx.fillRect(x - w / 2, y - h / 2, w, h); + ctx.fillStyle = "#3a2a10"; + ctx.fillRect(x - w / 2 + 0.55, y - h / 2 + 0.55, w - 1.1, h - 1.1); + const tone = ["#14100e", "#101418", "#18100e"][n % 3]; + ctx.fillStyle = tone; + ctx.fillRect(x - w / 2 + 0.8, y - h / 2 + 0.8, w - 1.6, h - 1.6); + // The sitter: a dark coat, a pale face, and eyes that look at you. + ctx.fillStyle = ["#2a2036", "#2c1c1c", "#1c2a30"][n % 3]; + poly(ctx, [[x - w * 0.34, y + h / 2 - 0.8], [x - w * 0.22, y + h * 0.1], [x + w * 0.22, y + h * 0.1], [x + w * 0.34, y + h / 2 - 0.8]]); + ctx.fill(); + ctx.fillStyle = "#cfc4a8"; + ellipse(ctx, x, y - h * 0.08, w * 0.19, h * 0.2); + ctx.fill(); + const ex = w * 0.085; + const ey = y - h * 0.11; + const dx = tx - x; + const dy = ty - ey; + const len = Math.hypot(dx, dy) || 1; + for (const s of [-1, 1]) { + ctx.fillStyle = "#f4efe0"; + ellipse(ctx, x + s * ex, ey, w * 0.06, w * 0.04); + ctx.fill(); + ctx.fillStyle = "#120808"; + disc(ctx, x + s * ex + (dx / len) * w * 0.026, ey + (dy / len) * w * 0.016, w * 0.024); + } + ctx.strokeStyle = "#5a4a3a"; + ctx.lineWidth = 0.14; + seg(ctx, x - w * 0.06, y + h * 0.02, x + w * 0.06, y + h * 0.02); + } + + // The grand staircase behind you: switchback flights and landings stacked in a zig-zag, each a + // dark mass with a stepped edge, a rail and balusters; a block of it every 150 units. + function stairHall(ctx, cam) { + strips(cam, 0.4, 150, 140, (ox) => { + const flights = [[ox + 6, 18, ox + 118, 30], [ox + 134, 31, ox + 22, 43], [ox + 6, 44.5, ox + 118, 56]]; + flights.forEach(([x0, y0, x1, y1], f) => { + const dir = Math.sign(x1 - x0); + // The mass under the flight, stepped. + ctx.fillStyle = f % 2 ? "#190a12" : "#210e18"; + ctx.beginPath(); + ctx.moveTo(x0, y0 + 9); + for (let s = 0; s <= 28; s++) { + const t = s / 28; + ctx.lineTo(x0 + (x1 - x0) * t, y0 + (y1 - y0) * Math.floor(t * 28) / 28); + ctx.lineTo(x0 + (x1 - x0) * Math.min(1, (s + 1) / 28), y0 + (y1 - y0) * Math.floor(t * 28) / 28); + } + ctx.lineTo(x1, y1 + 9); + ctx.closePath(); + ctx.fill(); + // The tread edges catch the moon. + ctx.strokeStyle = "rgba(190,170,210,0.28)"; + ctx.lineWidth = 0.18; + for (let s = 0; s <= 28; s += 2) { + const t = s / 28; + seg(ctx, x0 + (x1 - x0) * t, y0 + (y1 - y0) * Math.floor(t * 28) / 28, x0 + (x1 - x0) * Math.min(1, (s + 1) / 28), y0 + (y1 - y0) * Math.floor(t * 28) / 28); + } + // Its own rail and balusters above. + ctx.strokeStyle = "#5a2a22"; + ctx.lineWidth = 0.6; + seg(ctx, x0, y0 - 5, x1, y1 - 5); + ctx.strokeStyle = "#3a1a18"; + ctx.lineWidth = 0.3; + for (let s = 0; s <= 14; s++) seg(ctx, x0 + (x1 - x0) * (s / 14), y0 + (y1 - y0) * (s / 14) - 5, x0 + (x1 - x0) * (s / 14), y0 + (y1 - y0) * (s / 14)); + // The landing past the end of it, with a newel post. + ctx.fillStyle = "#2c1420"; + ctx.fillRect(Math.min(x1, x1 + dir * 16), y1, 16, 1.6); + ctx.fillStyle = "#5a2a22"; + ctx.fillRect(x1 + dir * 14 - 0.5, y1 - 6, 1, 6); + disc(ctx, x1 + dir * 14, y1 - 6.4, 0.7); + }); + }); + } + + // The rail itself: mahogany on its balusters (the handrail), and the brass under-rail beside it. + function rails(ctx, v, R, cam) { + const lo = cam - 6; + const hi = cam + FW + 6; + const lines = linesOf(R); + // The stringer and balusters under each handrail line. + for (let i = 0; i < R.rails; i++) { + const L = lines[i]; + if (L.x1 < lo || L.x0 > hi) continue; + const pts = pathOf(R, i, lo, hi); + if (pts.length < 2) continue; + ctx.strokeStyle = "rgba(0,0,0,0.4)"; + ctx.lineWidth = 0.5; + ctx.beginPath(); + pts.forEach(([x, y], q) => (q ? ctx.lineTo(x, sy(y) + 5.2) : ctx.moveTo(x, sy(y) + 5.2))); + ctx.stroke(); + ctx.strokeStyle = "#4a1e16"; + ctx.lineWidth = 0.8; + ctx.beginPath(); + pts.forEach(([x, y], q) => (q ? ctx.lineTo(x, sy(y) + 4.9) : ctx.moveTo(x, sy(y) + 4.9))); + ctx.stroke(); + for (let x = Math.ceil(Math.max(lo, L.x0 + 1) / 3.2) * 3.2; x < Math.min(hi, L.x1 - 0.5); x += 3.2) { + const y = sy(trackY(R, i, x)); + ctx.strokeStyle = "#3a160f"; + ctx.lineWidth = 0.36; + seg(ctx, x, y + 0.5, x, y + 5); + ctx.fillStyle = "#4e2016"; + ellipse(ctx, x, y + 2.3, 0.5, 0.75); + ctx.fill(); + } + } + // The handrails: a dark underside, the wood, a bright line along the top. + for (let i = 0; i < R.rails; i++) { + const L = lines[i]; + if (L.x1 < lo || L.x0 > hi) continue; + const pts = pathOf(R, i, lo, hi); + if (pts.length < 2) continue; + const trace = (dy) => { + ctx.beginPath(); + pts.forEach(([x, y], q) => (q ? ctx.lineTo(x, sy(y) + dy) : ctx.moveTo(x, sy(y) + dy))); + ctx.stroke(); + }; + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + ctx.strokeStyle = WOOD_D; + ctx.lineWidth = 1.7; + trace(0.2); + ctx.strokeStyle = WOOD; + ctx.lineWidth = 1.35; + trace(0); + ctx.strokeStyle = WOOD_L; + ctx.lineWidth = 0.28; + trace(-0.42); + ctx.lineCap = "butt"; + // The ends: a newel post and a ragged broken stub (not at the very first or last). + for (const end of [L.x0, L.x1]) { + if (end < lo || end > hi) continue; + if (end === L.x0 && i === 0) continue; + if (end === L.x1 && i === R.rails - 1) continue; + const y = sy(trackY(R, i, end)); + const left = end === L.x1; + ctx.fillStyle = "#4a1e16"; + ctx.fillRect(end - 0.55, y - 1.4, 1.1, 7.2); + ctx.fillStyle = "#6b2f1a"; + disc(ctx, end, y - 1.7, 0.85); + ctx.fillStyle = WOOD_D; + for (let q = 0; q < 3; q++) { + poly(ctx, [[end, y - 0.2 + q * 0.5], [end + (left ? 1.4 : -1.4) * (1 + q * 0.3), y + 0.1 + q * 0.5], [end, y + 0.5 + q * 0.5]]); + ctx.fill(); + } + } + } + // The brass under-rails. + for (let i = R.rails; i < R.track.length; i++) { + const L = lines[i]; + if (L.x1 < lo || L.x0 > hi) continue; + const pts = pathOf(R, i, lo, hi); + if (pts.length < 2) continue; + const trace = (dy) => { + ctx.beginPath(); + pts.forEach(([x, y], q) => (q ? ctx.lineTo(x, sy(y) + dy) : ctx.moveTo(x, sy(y) + dy))); + ctx.stroke(); + }; + ctx.lineCap = "round"; + ctx.strokeStyle = "rgba(0,0,0,0.45)"; + ctx.lineWidth = 1.1; + trace(0.3); + ctx.strokeStyle = BRASS; + ctx.lineWidth = 0.8; + trace(0); + ctx.strokeStyle = BRASS_L; + ctx.lineWidth = 0.18; + trace(-0.25); + ctx.lineCap = "butt"; + for (let x = Math.ceil(Math.max(lo, L.x0 + 2) / 9) * 9; x < Math.min(hi, L.x1 - 1); x += 9) { + const y = sy(trackY(R, i, x)); + ctx.fillStyle = "#8a6a2c"; + ctx.fillRect(x - 0.3, y + 0.3, 0.6, 2.4); + disc(ctx, x, y + 0.2, 0.55); + } + // The end hangs in the air: a flare of brass. + const end = L.x1; + if (end > lo && end < hi) { + const y = sy(L.pts.at(-1)[1]); + ctx.fillStyle = BRASS; + disc(ctx, end, y, 0.75); + ctx.fillStyle = BRASS_L; + disc(ctx, end - 0.2, y - 0.2, 0.25); + } + } + } + + /* ------------------------------------------------------------ the things */ + + // A vase (kind 0): a blue and white urn with handles; a candlestick (kind 1): a brass stick with a flame. + function prop(ctx, v, x, base, kind, i) { + const clock = v.clock; + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ellipse(ctx, x + 0.3, base + 0.1, 1.7, 0.3); + ctx.fill(); + if (kind === 0) { + ctx.fillStyle = "#e8eef8"; + ctx.beginPath(); + ctx.moveTo(x - 0.8, base); + ctx.bezierCurveTo(x - 1.9, base - 1.2, x - 1.6, base - 2.4, x - 0.7, base - 2.7); + ctx.lineTo(x - 0.9, base - 3.4); + ctx.lineTo(x + 0.9, base - 3.4); + ctx.lineTo(x + 0.7, base - 2.7); + ctx.bezierCurveTo(x + 1.6, base - 2.4, x + 1.9, base - 1.2, x + 0.8, base); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = "#3a5ca8"; + ctx.fillRect(x - 1.5, base - 1.9, 3, 0.5); + poly(ctx, [[x - 0.5, base - 1.2], [x, base - 0.6], [x + 0.5, base - 1.2], [x, base - 1.8]]); + ctx.fill(); + ctx.strokeStyle = "#e8eef8"; + ctx.lineWidth = 0.25; + for (const s of [-1, 1]) { + ctx.beginPath(); + ctx.arc(x + s * 1.2, base - 2.9, 0.7, s > 0 ? -1.3 : Math.PI + 1.3, s > 0 ? 1.4 : Math.PI - 1.4, s < 0); + ctx.stroke(); + } + ctx.fillStyle = "rgba(10,16,40,0.25)"; + ctx.fillRect(x + 0.2, base - 2.5, 0.7, 2.4); + return; + } + ctx.fillStyle = BRASS; + ctx.fillRect(x - 0.18, base - CANDLE_H + 1.2, 0.36, CANDLE_H - 1.8); + ellipse(ctx, x, base - 0.3, 0.8, 0.35); + ctx.fill(); + ellipse(ctx, x, base - 2.6, 0.38, 0.55); + ctx.fill(); + ctx.fillStyle = "#f0e8d2"; + ctx.fillRect(x - 0.28, base - CANDLE_H + 0.1, 0.56, 1.5); + const f = 0.8 + 0.2 * Math.sin(clock / 90 + i * 2); + halo(ctx, "warm", x, base - CANDLE_H - 0.2, 3.6, 0.4 * f); + ctx.fillStyle = "#ffcf6a"; + ellipse(ctx, x, base - CANDLE_H - 0.15, 0.3 * f, 0.62); + ctx.fill(); + ctx.fillStyle = "#fff6c8"; + ellipse(ctx, x, base - CANDLE_H - 0.05, 0.14, 0.32); + ctx.fill(); + } + + // A ghostly butler: pale, translucent, a tailcoat, a bow tie and a silver tray held out. + function butler(ctx, v, b, line, R, i) { + if (b.state === "broken" || b.state === "spent") return; + const clock = v.clock; + const L = linesOf(R)[line]; + const x = b.x; + const base = sy(trackY(R, line, clamp(x, L.x0, L.x1))); + const wait = b.state === "wait"; + const lunge = b.state === "lunge"; + const warn = b.state === "warn"; + const bow = warn ? clamp((500 - b.t) / 260, 0, 1) : lunge ? 1 : 0; + ctx.save(); + ctx.translate(x, base); + ctx.globalAlpha = wait ? 0.22 + 0.06 * Math.sin(clock / 300 + i) : lunge ? 0.9 : 0.8; + ctx.rotate(-0.1 * bow); + // A trail behind a lunge. + if (lunge) { + for (let k = 1; k < 4; k++) { + ctx.globalAlpha = 0.16 / k; + ctx.fillStyle = GHOST; + ctx.fillRect(k * 1.3 - 1, -BUTLER_H + 0.4, 1.8, BUTLER_H - 1); + } + ctx.globalAlpha = 0.9; + } + const bob = Math.sin(clock / 240 + i) * 0.12; + ctx.translate(0, bob - 0.2); + // The tails, the coat, the shirt front and the legs fading to wisps. + ctx.fillStyle = "#1c2236"; + poly(ctx, [[-1.1, -2.2], [1.1, -2.2], [1.5, -0.4], [0.2, -1.1], [-0.2, -0.2], [-1.4, -0.6]]); + ctx.fill(); + ctx.fillStyle = "#222a44"; + poly(ctx, [[-1.15, -4.1], [1.15, -4.1], [1.0, -2.1], [-1.0, -2.1]]); + ctx.fill(); + ctx.fillStyle = "#e8ecf4"; + poly(ctx, [[-0.3, -4.1], [0.3, -4.1], [0.4, -2.4], [-0.4, -2.4]]); + ctx.fill(); + ctx.fillStyle = "#101828"; + poly(ctx, [[-0.5, -4.1], [0, -3.85], [0.5, -4.1], [0.5, -3.7], [0, -3.95], [-0.5, -3.7]]); + ctx.fill(); + ctx.fillStyle = GHOST; + ctx.globalAlpha *= 0.75; + for (const s of [-0.5, 0.5]) { + ellipse(ctx, s, -0.7, 0.34, 0.9); + ctx.fill(); + } + ctx.globalAlpha = wait ? 0.22 : lunge ? 0.9 : 0.8; + // The head: long, pale, with hollow glowing eyes and thin hair. + ctx.fillStyle = "#dfe8f4"; + ellipse(ctx, -0.1 - bow * 0.3, -4.9, 0.72, 0.9); + ctx.fill(); + ctx.fillStyle = "#8a96ae"; + ctx.fillRect(-0.8 - bow * 0.3, -5.7, 1.4, 0.25); + ctx.fillStyle = warn || lunge ? "#ff5a3a" : "#7ec8ff"; + disc(ctx, -0.4 - bow * 0.3, -5.0, 0.16); + disc(ctx, 0.2 - bow * 0.3, -5.0, 0.16); + // The arm out in front (toward you) holding the tray: raised on a bow, level in a lunge. + ctx.strokeStyle = "#222a44"; + ctx.lineWidth = 0.45; + const ty = -3.1 - (warn ? bow * 0.5 : 0); + seg(ctx, -0.7, -3.7, -2.0 - bow * 0.5, ty); + // The silver tray, edge on, with a covered dish that gleams. + ctx.fillStyle = "#e6ecf2"; + ctx.fillRect(-3.4 - bow * 0.5, ty - 0.12, 2.6, 0.26); + ctx.fillStyle = "#b8c4d4"; + ctx.beginPath(); + ctx.arc(-2.1 - bow * 0.5, ty - 0.12, 0.8, Math.PI, 0); + ctx.fill(); + ctx.fillStyle = "#ffffff"; + disc(ctx, -2.3 - bow * 0.5, ty - 0.55, 0.14); + ctx.restore(); + if (!wait) halo(ctx, "cold", x, base - 2.5, 4.2, warn ? 0.2 : 0.28); + // The bow's little "!" over his head. + if (warn) { + ctx.fillStyle = "#ff8a6a"; + ctx.fillRect(x - 0.15, base - BUTLER_H - 2.4, 0.3, 1.1); + ctx.fillRect(x - 0.15, base - BUTLER_H - 1, 0.3, 0.3); + } + } + + // A cobweb strung across the rail: spokes and rings, in tatters once torn. + function web(ctx, x, base, state, i) { + if (state === "shot") return; + const cy = base - (WEB_LO + WEB_HI) / 2; + const r = (WEB_HI - WEB_LO) / 2; + const torn = state === "torn"; + ctx.strokeStyle = torn ? "rgba(230,230,240,0.35)" : "rgba(235,235,245,0.7)"; + ctx.lineWidth = 0.09; + const spokes = torn ? 4 : 8; + for (let s = 0; s < spokes; s++) { + const a = (s / 8) * TAU + 0.3; + const rr = torn ? r * (0.4 + 0.5 * rnd(i, s)) : r; + seg(ctx, x, cy, x + Math.cos(a) * rr * 0.75, cy + Math.sin(a) * rr); + } + if (!torn) { + for (let ring = 1; ring <= 3; ring++) { + ctx.beginPath(); + for (let s = 0; s <= 8; s++) { + const a = (s / 8) * TAU + 0.3; + const rr = r * ring * 0.3 * (1 - 0.1 * Math.sin(s * 2 + i)); + s ? ctx.lineTo(x + Math.cos(a) * rr * 0.75, cy + Math.sin(a) * rr) : ctx.moveTo(x + Math.cos(a) * rr * 0.75, cy + Math.sin(a) * rr); + } + ctx.stroke(); + } + // The anchors to the stairs. + seg(ctx, x - 1.8, cy - r, x - 3, base - WEB_HI - 1.4); + seg(ctx, x + 1.8, cy + r, x + 2.4, base + 0.2); + ctx.fillStyle = "#14080c"; + disc(ctx, x + 0.3, cy - 0.4, 0.2); + } + } + + // A lamp on the newel at a checkpoint: flame green once passed. + function checkpoint(ctx, v, x, base, passed, i) { + const clock = v.clock; + ctx.fillStyle = "#3a2410"; + ctx.fillRect(x + 1, base - 4.8, 0.45, 4.8); + ctx.fillStyle = BRASS; + ellipse(ctx, x + 1.22, base - 4.8, 0.9, 0.35); + ctx.fill(); + const f = 0.85 + 0.15 * Math.sin(clock / 110 + i); + ctx.fillStyle = passed ? "#7dffa0" : "#ffcf6a"; + ellipse(ctx, x + 1.22, base - 5.5, 0.42 * f, 0.75); + ctx.fill(); + halo(ctx, passed ? "green" : "warm", x + 1.2, base - 5.4, 5, passed ? 0.5 : 0.32); + } + + // The foyer: a great arched front door at the end, lit from outside. + function frontDoor(ctx, v, x) { + const top = sy(10); + const w = 7; + halo(ctx, "gold", x, top - 7, 16, 0.5); + ctx.fillStyle = "#3a1a12"; + ctx.fillRect(x - w - 1, top - 20, (w + 1) * 2, 20); + ctx.fillStyle = "#6b3a22"; + ctx.beginPath(); + ctx.moveTo(x - w, top); + ctx.lineTo(x - w, top - 14); + ctx.arc(x, top - 14, w, Math.PI, 0); + ctx.lineTo(x + w, top); + ctx.closePath(); + ctx.fill(); + ctx.strokeStyle = "#2a1208"; + ctx.lineWidth = 0.3; + seg(ctx, x, top - 21, x, top); + ctx.stroke(); + ctx.fillStyle = "rgba(255,220,150,0.25)"; + ctx.beginPath(); + ctx.moveTo(x - w + 1, top); + ctx.lineTo(x - w + 1, top - 14); + ctx.arc(x, top - 14, w - 1, Math.PI, 0); + ctx.lineTo(x + w - 1, top); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = BRASS; + disc(ctx, x - 1, top - 8, 0.4); + disc(ctx, x + 1, top - 8, 0.4); + } + + /* ---------------------------------------------------------- the world */ + + function moving(ctx, v, cam) { + const R = ride(v); + const round = v.round; + const c = state(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + const clock = v.clock; + cam = Math.round(cam * 8) / 8; + const you = round.you; + wall(ctx, cam, clock); + stairHall(ctx, cam); + // The portraits along the wall, their eyes on YOU. + strips(cam, 0.8, 44, 8, (x, k) => { + const w = 5.4 + 1.4 * rnd(k, 5); + const h = w * 1.3; + ctx.globalAlpha = 0.62; + portrait(ctx, x + 22, 8.5 + (k % 3) * 0.6, w, h, k, you.x, sy(you.y) - 2, false); + ctx.globalAlpha = 1; + }); + const lo = cam - 8; + const hi = cam + FW + 8; + rails(ctx, v, R, cam); + R.checks.forEach((x, i) => { + if (x > lo && x < hi) checkpoint(ctx, v, x, sy(heightAt(R, x) ?? 10), i <= c.check, i); + }); + R.webs.forEach(([x, line], i) => { + if (x > lo && x < hi) web(ctx, x, sy(yOf(R, line, x) ?? 10), c.webs[i], i); + }); + R.props.forEach(([x, line, kind], i) => { + if (x > lo && x < hi) prop(ctx, v, x, sy(yOf(R, line, x) ?? 10), kind, i); + }); + R.butlers.forEach(([hx, line], i) => { + if (c.butlers[i].x > lo - 4 && c.butlers[i].x < hi && hx < hi + 20) butler(ctx, v, c.butlers[i], line, R, i); + }); + // The attic landing and the foyer floor, over the wall. + for (const [a, b, top] of v.spec.ground) if (b > lo && a < hi) ground(ctx, v, LOOKS.banister, a, b, top); + if (v.spec.door > lo - 8 && v.spec.door < hi + 8) frontDoor(ctx, v, v.spec.door - 6); + // Dust drifting down in the dark. + for (let q = 0; q < 10; q++) { + const p = (clock / (3600 + (q % 4) * 500) + rnd(q, 9)) % 1; + const mx = cam + ((((rnd(q, 8) * FW - cam * 0.3) % FW) + FW) % FW); + ctx.fillStyle = "rgba(230,220,200,0.35)"; + ctx.fillRect(mx, p * FH, 0.2, 0.2); + } + } + + /* ------------------------------------------------------ the things in front */ + + // A hanging portrait frame: two chains from the roof, a gilt frame, a face that watches YOU. + function frame(ctx, v, x0, x1, y, i, you) { + const clock = v.clock; + const w = x1 - x0; + const top = sy(y) - 4.6; + const sway = Math.sin(clock / 900 + i * 1.7) * 0.025; + ctx.save(); + ctx.translate((x0 + x1) / 2, -2); + ctx.rotate(sway); + ctx.translate(-(x0 + x1) / 2, 2); + ctx.strokeStyle = "#8a7a60"; + ctx.lineWidth = 0.18; + for (const cx of [x0 + 0.9, x1 - 0.9]) { + ctx.setLineDash && ctx.setLineDash([0.5, 0.35]); + seg(ctx, cx, -3, cx, top + 0.2); + ctx.setLineDash && ctx.setLineDash([]); + } + portrait(ctx, (x0 + x1) / 2, top + 2.3, w, 4.6, i + 4, you.x, sy(you.y) - 2, true); + ctx.restore(); + halo(ctx, "warm", (x0 + x1) / 2, sy(y) + 0.4, 4.5, 0.14); + } + + // A chandelier on its pendulum: the chain from the roof, the arc it swings through marked in + // dots, the bob lit red while it hangs too low to duck under, amber while it is safe to. + function chandelier(ctx, v, R, i, c) { + const [cx, line, amp] = R.swings[i]; + const clock = v.clock; + const s = swingAt(R, i, c.clock); + const bx = s.x; + const by = sy(s.bottom) - 1.4; + const rail = yOf(R, line, clamp(bx, linesOf(R)[line].x0, linesOf(R)[line].x1)) ?? 10; + const lethal = s.bottom < rail + DUCK_H + 0.35; + // The arc it swings through, dotted, so the beat can be read ahead of it. + for (let k = -6; k <= 6; k++) { + const u = k / 6; + const bottom = (yOf(R, line, clamp(cx + amp * u, linesOf(R)[line].x0, linesOf(R)[line].x1)) ?? 10) + 2.2 + 3 * u * u; + ctx.fillStyle = Math.abs(u) < 0.32 ? "rgba(255,110,90,0.55)" : "rgba(255,210,130,0.4)"; + disc(ctx, cx + amp * u, sy(bottom) - 1.4, 0.16); + } + // The chain. + ctx.strokeStyle = "#a89870"; + ctx.lineWidth = 0.22; + ctx.setLineDash && ctx.setLineDash([0.55, 0.3]); + seg(ctx, cx, -12, bx, by - 1.1); + ctx.setLineDash && ctx.setLineDash([]); + halo(ctx, lethal ? "red" : "gold", bx, by, 8, lethal ? 0.4 : 0.28); + // The bob: a cap, two tiers of arms, five candles, crystal drops (drawn a third bigger than its box, so it reads at a glance). + ctx.save(); + ctx.translate(bx, by); + ctx.scale(1.3, 1.3); + ctx.translate(-bx, -by); + ctx.fillStyle = BRASS; + ellipse(ctx, bx, by - 1.0, 0.5, 0.4); + ctx.fill(); + ctx.strokeStyle = BRASS; + ctx.lineWidth = 0.3; + for (const [rx, ry, dy] of [[SWING_BOB_W / 2, 0.55, 0.2], [SWING_BOB_W / 3, 0.4, -0.5]]) { + ctx.beginPath(); + ctx.ellipse ? ctx.ellipse(bx, by + dy, rx, ry, 0, 0, Math.PI) : ctx.arc(bx, by + dy, rx, 0, Math.PI); + ctx.stroke(); + } + seg(ctx, bx, by - 0.8, bx, by + 0.9); + for (let k = -2; k <= 2; k++) { + const px = bx + k * (SWING_BOB_W / 5); + ctx.fillStyle = "#f0e8d2"; + ctx.fillRect(px - 0.14, by - 1.3 + Math.abs(k) * 0.12, 0.28, 0.9); + const f = 0.8 + 0.2 * Math.sin(clock / 80 + k * 2 + i); + ctx.fillStyle = "#ffcf6a"; + ellipse(ctx, px, by - 1.5 + Math.abs(k) * 0.12, 0.2 * f, 0.4); + ctx.fill(); + ctx.fillStyle = "rgba(220,240,255,0.85)"; + poly(ctx, [[px - 0.12, by + 0.7], [px, by + 1.35 + 0.15 * Math.abs(k)], [px + 0.12, by + 0.7]]); + ctx.fill(); + } + ctx.restore(); + } + + // A glyph over an obstacle: chevrons and (for the first few of a kind) the word. + function glyph(ctx, v, t) { + const up = t.answer === "JUMP"; + const dive = t.answer === "DIVE"; + const col = COLORS[t.answer]; + const pulse = 0.85 + 0.15 * Math.sin(v.clock / 260 + t.lead); + const bob = Math.sin(v.clock / 260 + t.lead) * 0.35 * (up ? -1 : 1); + const cy = Math.min(FH - 7, FH - t.up) + bob; + const dir = up ? -1 : 1; + const ay = cy + (up ? -2.6 : 2.6); + ctx.save(); + ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA; + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + for (const [pass, w, c] of [[0, 1.3, "rgba(8,2,6,0.8)"], [1, 0.6, col]]) { + ctx.strokeStyle = c; + ctx.lineWidth = w; + for (let k = 0; k < 2; k++) { + const oy = ay + (k - 0.5) * 1.5 * dir - dir * 0.2; + if (k === 1 && pass === 1) ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA * 0.55; + ctx.beginPath(); + ctx.moveTo(t.x - 1.7, oy - dir * 0.9); + ctx.lineTo(t.x, oy + dir * 0.9); + ctx.lineTo(t.x + 1.7, oy - dir * 0.9); + ctx.stroke(); + } + ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA; + } + if (t.words) label(ctx, t.answer, t.x, cy + (up ? 1.2 : -1.2), 2.3, col, "center"); + ctx.restore(); + } + + // Sparks and wood shavings off the rail under your feet, longer the faster you go. + function sparks(ctx, v, R, c) { + const you = v.round.you; + const clock = v.clock; + const lower = lowerLine(R, c.line); + for (let k = 0; k < 12; k++) { + const p = (clock / (300 + (k % 4) * 60) + k * 0.113) % 1; + const x = you.x - 0.6 - p * (2.5 + (c.v / BAN_V) * 3.5) * (0.6 + rnd(k, 1)); + const y = yOf(R, c.line, x) ?? you.y; + ctx.fillStyle = lower ? `rgba(255,230,140,${(1 - p) * 0.9})` : `rgba(255,190,110,${(1 - p) * 0.8})`; + disc(ctx, x, sy(y) - 0.25 - p * (0.6 + rnd(k, 2) * 1.6), 0.12 + (1 - p) * 0.14); + } + ctx.strokeStyle = lower ? "rgba(255,240,170,0.5)" : "rgba(255,220,170,0.4)"; + ctx.lineWidth = 0.1; + for (let k = 0; k < 3; k++) { + const y0 = yOf(R, c.line, you.x - 3) ?? you.y; + seg(ctx, you.x - 3.2 - k, sy(y0) - 0.1, you.x - 6.5 - k * 2 - (c.v - 30) * 0.1, sy(yOf(R, c.line, you.x - 6.5 - k * 2) ?? y0) - 0.1); + } + // A landing's puff of dust. + const fx = v.fx; + const land = fx && fx.banLand !== undefined ? fx.clock - fx.banLand.t0 : 1e9; + if (land < 380) { + for (let k = 0; k < 8; k++) { + const p = land / 380; + ctx.fillStyle = `rgba(230,210,190,${(1 - p) * 0.7})`; + disc(ctx, you.x + (k - 3.5) * 0.9 * (0.5 + p * 1.4), sy(you.y) - 0.3 - p * (1 + rnd(k, 4) * 1.4) * (fx.banLand.big ? 1.6 : 1), 0.28 + p * 0.28); + } + } + } + + function front(ctx, v) { + const R = ride(v); + const round = v.round; + const c = state(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + const cam = Math.round(round.camX * 8) / 8; + const lo = cam - 10; + const hi = cam + FW + 10; + if (!c.done && c.line >= 0) sparks(ctx, v, R, c); + R.lows.forEach(([x0, x1, y], i) => { + if (x1 >= lo && x0 <= hi) frame(ctx, v, x0, x1, y, i, round.you); + }); + R.swings.forEach(([cx, , amp], i) => { + if (cx + amp + 4 >= lo && cx - amp - 4 <= hi) chandelier(ctx, v, R, i, c); + }); + if (!c.done) for (const t of telegraphs(R, round.you.x)) glyph(ctx, v, t); + // Splinters of glass, wood and porcelain, tumbling. + const bits = v.fx && v.fx.banBits; + if (bits) { + for (const b of bits) { + const t = (v.fx.clock - b.t0) / 1000; + if (t < 0 || t > 0.9) continue; + ctx.save(); + ctx.translate(b.x + b.vx * t, sy(b.y + b.vy * t - 30 * t * t)); + ctx.rotate(b.rot + b.vr * t); + ctx.globalAlpha = clamp(1.6 - t * 1.6, 0, 1); + ctx.fillStyle = b.c; + ctx.fillRect(-b.w / 2, -0.12, b.w, 0.24); + ctx.restore(); + } + ctx.globalAlpha = 1; + } + } + + const dim = () => 0; + + /* -------------------------------------------------------------- lights */ + + function lights(v, add) { + const R = ride(v); + const round = v.round; + const c = state(v); + if (!R || !c) return; + const you = round.you; + const clock = v.clock; + const lo = round.camX - 10; + const hi = round.camX + FW + 10; + // A pool of candlelight around you. + add(you.x + 2, you.y + 2.4, 10, 0.55); + R.checks.forEach((x, i) => { + if (x > lo && x < hi) add(x + 1.2, (heightAt(R, x) ?? 10) + 5.4, i <= c.check ? 8 : 7, i <= c.check ? 0.6 : 0.5); + }); + R.props.forEach(([x, line, kind]) => { + if (kind && x > lo && x < hi) add(x, (yOf(R, line, x) ?? 10) + CANDLE_H, 5, 0.35); + }); + R.swings.forEach(([cx, , amp], i) => { + if (cx + amp > lo && cx - amp < hi) { + const s = swingAt(R, i, c.clock); + add(s.x, s.bottom + 1.4, 9, 0.5 + 0.05 * Math.sin(clock / 120 + i)); + } + }); + R.lows.forEach(([x0, x1, y], i) => { + if (x1 > lo && x0 < hi) add((x0 + x1) / 2, y + 2, 5, 0.22 * (0.85 + 0.15 * Math.sin(clock / 220 + i))); + }); + R.butlers.forEach(([, line], i) => { + const b = c.butlers[i]; + if (b.x > lo && b.x < hi && (b.state === "warn" || b.state === "lunge")) add(b.x, (yOf(R, line, clamp(b.x, linesOf(R)[line].x0, linesOf(R)[line].x1)) ?? 10) + 2.5, 5, 0.3); + }); + add(v.spec.door - 6, 18, 14, 0.6); + } + + /* -------------------------------------------------------------- events */ + + // A throttle on a repeating cue. + function gateOnce(fx, key, ms) { + if ((fx[key] || 0) > fx.clock) return false; + fx[key] = fx.clock + ms; + return true; + } + // Glass, wood and china flying out of a spot. + function splinter(fx, x, y, colors) { + fx.banBits = (fx.banBits || []).filter((b) => fx.clock - b.t0 < 1000); + for (let k = 0; k < 9; k++) fx.banBits.push({ x, y, t0: fx.clock, vx: (rnd(k, 1) - 0.5) * 22, vy: 8 + rnd(k, 2) * 14, rot: rnd(k, 3) * TAU, vr: (rnd(k, 4) - 0.5) * 22, w: 0.5 + rnd(k, 5) * 0.9, c: colors[k % colors.length] }); + } + + // What the pack's events look and sound like; true when the event is its own. Each of its + // sounds plays once, from EVENT_VOICE. + function react(e, k) { + const { tone, shake, flash, burst, float, ring, fx } = k; + const voice = EVENT_VOICE[e.type]; + if (!voice) return false; + // The ducking repeats as you hold the key; keep it from stacking. + if (e.type === "banDuck" && !gateOnce(fx, "banDuckMs", 160)) return true; + say(tone, voice[0], voice[1], 0.5); + const DUST = "#d8c8b0"; + switch (e.type) { + case "banJump": + burst(e.x, e.y, DUST, 5, 7, 300); + break; + case "banLand": + fx.banLand = { t0: fx.clock, big: Boolean(e.big) }; + burst(e.x, e.y, DUST, e.big ? 14 : 6, e.big ? 12 : 8, 360); + if (e.big) shake(200, 0.5); + break; + case "banLaunch": + burst(e.x, e.y, DUST, 12, 14, 380); + float(e.x, e.y + 5, e.last ? "Jump!" : "Whee!", GOLD, 2.2); + break; + case "banSwitch": + ring(e.x, e.y + 1, e.lower ? "#ffe08a" : "#e0a070", 1, 6, 360); + float(e.x, e.y + 4, e.lower ? "Under-rail" : "Handrail", GOLD, 1.8); + break; + case "banCrash": + shake(320, 1); + flash("#ffe8c8", 180); + burst(e.x, e.y + 1, e.what === "vase" ? "#e8eef8" : e.what === "swing" ? "#e8d8a0" : "#8a4a2a", 18, 17, 520); + burst(e.x, e.y + 1, "#c9a24a", 8, 14, 360); + splinter(fx, e.x, e.y, e.what === "vase" ? ["#e8eef8", "#3a5ca8"] : ["#8a4a2a", "#c9a24a", "#e8d8a0"]); + break; + case "banCheck": + float(e.x, e.y + 5, "Checkpoint", GOLD, 2.2); + ring(e.x, e.y + 3, "#7dffa0", 1, 8, 500); + break; + case "banFinish": + shake(260, 0.7); + burst(e.x, e.y, DUST, e.big ? 22 : 14, 13, 560); + float(e.x, e.y + 5, "Made it!", GOLD, 2.6); + break; + case "banButlerWarn": + ring(e.x, e.y + 5, "#9ad0ff", 1, 5, 420); + break; + case "banButlerLunge": + burst(e.x, e.y + 2, GHOST, 6, 8, 360); + break; + case "banButlerHit": + burst(e.x, e.y, "#e6ecf2", 5, 9, 280); + break; + case "banButlerBreak": + burst(e.x, e.y, GHOST, 14, 14, 480); + splinter(fx, e.x, e.y, ["#e6ecf2", "#b8d0ec"]); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + case "banWebTear": + burst(e.x, e.y, "#e6e6f0", 6, 5, 380); + break; + case "banWebShot": + burst(e.x, e.y, "#f4f4ff", 10, 8, 420); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + default: + break; + } + return true; + } + + return freeze({ + looks: LOOKS, + backdrop, + ground, + shelf, + front, + moving, + dim, + monsters: freeze({}), + bosses: freeze({}), + missiles: freeze({}), + hazards: freeze({}), + powers: freeze({}), + lights, + react, + }); +} diff --git a/src/web-console/public/activities/ghoul-banister.js b/src/web-console/public/activities/ghoul-banister.js new file mode 100644 index 0000000..ffca9c6 --- /dev/null +++ b/src/web-console/public/activities/ghoul-banister.js @@ -0,0 +1,520 @@ +// Plan2Code Web Console - Ghoul Rush's Grand Banister, its rules: the Manor's bonus round. YOU slide down the grand staircase's endless polished banister, from the attic landing to the foyer, in one long dizzying descent: jump the vases and candlesticks on the rail, duck the hanging portrait frames and the swinging chandeliers (time them by their pendulum), jump the breaks between the landings, shoot or jump the ghostly butlers that lunge with their silver trays, and shoot the cobwebs. As a stage pack that ghoul.js plugs in. +// +// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it, +// handed a kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js (it +// borrows the cart's track helpers). Pack fields used: `ride` (a hook that moves YOU, so +// no key walks you), `place` (put down in a room: a room set up or a respawn) and `target` +// (a bolt strikes something that is no monster: the butlers and the cobwebs). No monster, +// boss or hazard kind, so nothing to merge by name, and NO random number is drawn. +// +// Its state is the shared bonus-ride slot `round.runner` (null in any other room; see +// the "runner" lines in ghoul.js and ghoul-cart.js), and its room marks itself with +// `ride.runner: "banister"`. +// +// THE ROOM (spec.ride, see ghoul-rooms.js): +// +// - `track`: polylines [x, y] the rail runs along. The first `rails` of them are the +// HANDRAIL (the upper rail), 20 flights of stairs: descents (slope -0.10 to -0.11) each +// followed by a short climb (+0.29 to +0.31, the newel at the landing: the rail sweeps up +// and over it), every crest a little lower than the last; a gap between two of them is a +// BREAK in the banister (jump it, as the sled does its cracks: the rail flies on along its +// last slope, a fall below DERAIL_Y is a heart, cause "plunge"). The lines after those are +// the brass UNDER-RAILS, RAIL_SEP (7) under the handrail along the length of one descent +// each (the split track): it begins and ends where the descent does, and ends in the air: +// jump up off its end (the handrail is above and catches you) or it is a plunge. +// The hill ends on a lip rising at 0.277 (over RAMP_SLOPE, so it launches: RAMP_POP) and +// the foyer floor begins `finish` further on, lower; flying onto it ends the ride. +// - Which rail: a jump lands on the HIGHEST rail under you (the handrail). HOLD DOWN in the +// air (a jump with DOWN held, a DIVE) to fall through it onto the under-rail where there is +// one; up from the under-rail jumps back up to the handrail. +// - `props` [x, line, kind] (kind 0 a vase, VASE_W by VASE_H, kind 1 a candlestick, +// CANDLE_W by CANDLE_H: jump), `lows` [x0, x1, y] (a hanging portrait frame, its +// underside y, from there up to the roof: DUCK it; y is 3.0 over the highest handrail +// under it, between a ducked box and a standing one), `swings` [x, line, amp, period ms, +// phase ms] (a chandelier on a chain from the roof, swinging amp each way of x on a +// pendulum of that period: see swingAt. Its bob is SWING_BOB_W wide and hangs from +// SWING_LOW over the handrail under it at the middle of its swing to SWING_LOW + +// SWING_RISE at the ends of it, and the chain makes the whole of it a wall from there up to +// the roof: DUCK it, but only while the bob is above a ducked head; at the middle of its +// swing it hangs lower than a ducked box and no ducking helps, so you pass it while it is +// out at the end of its arc, or take the under-rail, which is under it), `butlers` [x, +// line] (a ghostly butler waits; when you are BUTLER_NEAR short of it it bows BUTLER_WARN_MS, +// then lunges up the rail at you at BUTLER_V for up to BUTLER_LUNGE_MS, BUTLER_W by +// BUTLER_H: jump it, or shoot it, BUTLER_HP bolts), `webs` [x, line] (a cobweb across the +// rail: shoot it for points; riding through only tears it), `checks`, `finish` and +// `time` (the room's clock, ms). +// - The ground is the attic landing at the start and the foyer floor at the end only. +// +// YOU (`round.runner`): { id, v, line, coyote, from, left, check, done, clock, dive, +// butlers, webs }. You ride at (you.x, you.y), always facing right (`you.state` "run" on +// the rail, "air" off it, `you.ducking` ducked on it). Speed `v` relaxes to BAN_V (RELAX) +// and is pushed by the slope (SLOPE_G), between BAN_MIN and BAN_MAX; RIGHT leans (LEAN_ACC) +// and LEFT brakes (BRAKE_ACC) on the rail, which is how you time a chandelier. Up jumps at +// BAN_JUMP_V (plus the slope's own rise) against BAN_G (about 13 high, 0.75 s, 34 across at +// BAN_V), COYOTE_MS of grace after running off a line's end; down ducks (on the rail) or +// dives (in the air). `clock` is the pendulums' time in ms: it only runs while you ride. +// A bolt flies parallel to the rail under it, so the shooting is level with the stairs. +// +// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the ride +// rolls on, you blinking safe BONUS_SAFE_MS; the last heart gone ends the round with nothing, +// at once. A derail puts you back on the handrail (the highest line under you, else the next +// ahead) at BAN_V. Causes: "vase", "candle", "frame", "swing", "butler", "plunge". Every +// obstacle is a number for the grade (`perf.total`: props, lows, swings, butlers and breaks, +// each id once in `perf.hits` if it ever cost a heart). Shooting a butler or a web counts for +// `perf.acts` (the grade's goal is ACTS_GOAL) and the points below. The grade's `steady` die +// is a smooth slide: braking for no more than STEADY_BRAKE_MS in all. +// +// WHAT THE ART READS: `spec.ride` (above), `round.runner` { v, line, check, done, left, clock, +// butlers: [{ state "wait"|"warn"|"lunge"|"broken"|"spent", t, x }], webs: ["up"|"torn"|"shot"] }, +// `round.you` (`state`, `vy`, `ducking`), the events in EVENTS. + +import { linesAt, linesOf, slopeOf, trackY } from "./ghoul-cart.js"; + +const freeze = (o) => Object.freeze(o); +const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v)); + +export const MONSTERS = freeze({}); + +// Every event this pack puts on the field, for the art and the sounds to answer. +export const EVENTS = freeze([ + "banJump", "banLand", "banLaunch", "banDuck", "banSwitch", "banCrash", "banCheck", "banFinish", + "banButlerWarn", "banButlerLunge", "banButlerHit", "banButlerBreak", "banWebTear", "banWebShot", +]); + +// The ride. Speeds are units across a second, BAN_G units a second squared. +export const BAN_V = 46; +export const BAN_MIN = 28; +export const BAN_MAX = 64; +export const SLOPE_G = 60; +export const RELAX = 1.5; +export const LEAN_ACC = 14; +export const BRAKE_ACC = 36; +export const BAN_JUMP_V = 74; +export const BAN_G = 200; +export const COYOTE_MS = 100; +export const RAMP_SLOPE = 0.25; +export const RAMP_POP = 30; +export const LAND_TOL = 0.9; +export const BIG_LAND = 8; +export const DERAIL_Y = 3; +export const CAM_AHEAD = 10; +export const CAM_PER_V = 0.25; +export const RAIL_SEP = 7; +// Obstacles. +export const VASE_W = 2.6; +export const VASE_H = 3.4; +export const CANDLE_W = 1.6; +export const CANDLE_H = 5.4; +export const SWING_BOB_W = 4.4; +export const SWING_LOW = 2.2; +export const SWING_RISE = 3; +export const BUTLER_W = 2.6; +export const BUTLER_H = 5; +export const BUTLER_HP = 2; +export const BUTLER_NEAR = 44; +export const BUTLER_WARN_MS = 500; +export const BUTLER_V = 14; +export const BUTLER_LUNGE_MS = 1400; +export const WEB_W = 3.2; +export const WEB_LO = 0.6; +export const WEB_HI = 5.6; +export const BUTLER_POINTS = 150; +export const WEB_POINTS = 50; +const SHOT_R = 0.5; +// The shots at things (butlers, webs) worth a die, and the braking a smooth slide allows. +export const ACTS_GOAL = 8; +export const STEADY_BRAKE_MS = 3000; + +// Notes for a bonus round that obstacle `id` cost a heart (once each). +function noteHit(round, id) { + const b = round.bonusRound; + if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id); +} + +const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H); +const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0; + +// Whether line `line` is one of the brass under-rails. +export const lowerLine = (R, line) => line >= R.rails; + +// The highest line under x, as [line, y], or null over a break. +const topAt = (R, x) => linesAt(R, x)[0] || null; + +// The line a rider falling from `py` to `y` at `x` lands on: the highest he crossed going +// down, or, diving, the lowest line under him (he falls through a rail with another below it). +function landOn(R, x, py, y, dive) { + const under = linesAt(R, x); + for (let i = 0; i < under.length; i++) { + const [line, ly] = under[i]; + if (!(py >= ly - LAND_TOL && y <= ly)) continue; + if (dive && i + 1 < under.length && under[i + 1][1] < ly - 1) continue; + return { line, y: ly }; + } + return null; +} + +// Where a rider in the air at (x, y) going up at vy and across at v lands, if he does not +// steer (diving, or not): { x, y, line } or null when he derails. The unit suite's measure of +// which breaks a jump clears and which rail a dive lands on. +export function flight(R, x, y, vy, v, dive = false) { + const dt = 0.004; + for (let t = 0; t < 5; t += dt) { + const py = y; + vy = Math.max(-120, vy - BAN_G * dt); + x += v * dt; + y += vy * dt; + if (vy <= 0) { + const f = landOn(R, x, py, y, dive); + if (f) return { x, y: f.y, line: f.line }; + } + if (y < DERAIL_Y) return null; + } + return null; +} + +// Chandelier `i` of the room at `t` ms: { x, u (-1 to 1, where it is on its arc), bottom (its +// underside) }. A pendulum: a sine, hanging lowest at the middle (u 0) and rising toward +// the ends, over the handrail directly under it. +export function swingAt(R, i, t) { + const [cx, line, amp, period, phase] = R.swings[i]; + const u = Math.sin((2 * Math.PI * (t + phase)) / period); + const x = cx + amp * u; + const L = linesOf(R)[line]; + return { x, u, bottom: trackY(R, line, clamp(x, L.x0, L.x1)) + SWING_LOW + SWING_RISE * u * u }; +} + +/* -------------------------------------------------------------- placing */ + +// A fresh set of the room's things, each butler waiting and each web up. What was shot stays +// shot (`old`, the state of an earlier try in the same room). +function things(R, old) { + return { + butlers: R.butlers.map(([x], i) => ({ state: old && old.butlers[i].state === "broken" ? "broken" : "wait", t: 0, x, hp: BUTLER_HP })), + webs: R.webs.map((w, i) => (old && old.webs[i] === "shot" ? "shot" : "up")), + }; +} + +// Put down in the room: on the handrail at the start of a ride, or at the last checkpoint +// passed after the last heart (the same room). +function place(round) { + const R = round.spec.ride; + // (The Cart's `place` runs first and has already zeroed `round.camLead`: another room's lead is not ours to touch.) + if (!R || R.runner !== "banister") { + if (round.runner && round.runner.id === "banister") round.runner = null; + return; + } + const old = round.runner && round.runner.id === "banister" && round.runner.room === round.room ? round.runner : null; + const check = old ? old.check : -1; + const you = round.you; + const x = check >= 0 ? R.checks[check] : round.spec.start; + const top = topAt(R, x); + Object.assign(you, { x, y: top ? top[1] : you.y, vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 }); + round.runner = { id: "banister", room: round.room, check, v: BAN_V, line: top ? top[0] : -1, coyote: 0, from: you.y, left: top ? top[0] : 0, done: false, clock: old ? old.clock : 0, dive: false, ...things(R, old) }; + round.camLead = CAM_AHEAD; + const b = round.bonusRound; + if (b && !b.perf.total) { + b.perf.total = R.props.length + R.lows.length + R.swings.length + R.butlers.length + (R.rails - 1); + b.perf.steady = true; + b.perf.goal = ACTS_GOAL; + } +} + +/* ------------------------------------------------------------ the ride */ + +// After a derail that cost a heart but not the ride: you and the rail go back onto the line +// nearest where you fell (the highest line under you, else the next one ahead) at BAN_V. +function reseat(round, c, R) { + const you = round.you; + const under = topAt(R, you.x); + let line; + let x; + let y; + if (under) { + [line, y] = under; + x = you.x; + } else { + const ahead = linesOf(R) + .map((L, i) => ({ i, x0: L.x0 })) + .filter((L) => L.x0 > you.x && L.i < R.rails) + .sort((a, b) => a.x0 - b.x0)[0]; + line = ahead ? ahead.i : R.rails - 1; + x = ahead ? ahead.x0 + 2 : R.finish - 2; + y = trackY(R, line, x) ?? you.y; + } + Object.assign(you, { x, y, vy: 0, state: "run", shelf: -1, ducking: false, coyote: 0, drop: -1 }); + Object.assign(c, { line, v: BAN_V, coyote: 0, from: y }); +} + +// The ride for one slice. Returns true once it has moved you (every slice of a ride); false +// outside a ride and once you have stepped out onto the foyer floor. +function ride(round, ms, k) { + const R = round.spec.ride; + const c = round.runner; + if (!R || R.runner !== "banister" || !c || c.id !== "banister" || c.done) return false; + const you = round.you; + const inp = round.input; + const dt = ms / 1000; + const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra }); + c.clock += ms; + // Already down on the foyer floor (set there, or past the lip some other way): the ride is over. + if (you.x >= R.finish && you.vy <= 0 && you.y <= k.groundAt(round.spec, you.x) + 0.01) return finish(round, c, R, k.groundAt(round.spec, you.x), k); + // A stomp's bounce (or anything else) lifts you off the rail. + if (you.state === "air" && c.line >= 0) { + c.left = c.line; + c.line = -1; + c.coyote = 0; + c.from = you.y; + } + steerShots(round, R); + const want = inp.jump > 0; + if (c.line >= 0) { + // On the rail. + const slope = slopeOf(R, c.line, you.x); + let a = (BAN_V - c.v) * RELAX - SLOPE_G * slope; + if (inp.right) a += LEAN_ACC; + if (inp.left) a -= BRAKE_ACC; + c.v = clamp(c.v + a * dt, BAN_MIN, BAN_MAX); + // Braking is a bonus round's one thing not to do much of: too much is no smooth slide. + if (inp.left && round.bonusRound && (round.bonusRound.perf.brakeMs = (round.bonusRound.perf.brakeMs || 0) + ms) > STEADY_BRAKE_MS) round.bonusRound.perf.steady = false; + const duck = Boolean(inp.down) && !want; + if (duck && !you.ducking) ev("banDuck"); + you.ducking = duck; + if (want) { + inp.jump = 0; + you.vy = BAN_JUMP_V + slope * c.v; + Object.assign(c, { left: c.line, line: -1, coyote: 0, from: you.y }); + you.state = "air"; + you.ducking = false; + ev("banJump", { v: c.v }); + } else { + const L = linesOf(R)[c.line]; + const nx = you.x + c.v * dt; + you.state = "run"; + you.vy = 0; + if (nx >= L.x1) { + // Off the end of the line, on along its last slope. + const end = L.pts[L.pts.length - 1]; + const rise = slopeOf(R, c.line, L.x1); + you.x = L.x1; + you.y = end[1]; + const ramp = rise >= RAMP_SLOPE; + you.vy = rise * c.v + (ramp ? RAMP_POP : 0); + Object.assign(c, { left: c.line, line: -1, coyote: COYOTE_MS, from: you.y }); + you.state = "air"; + you.ducking = false; + if (ramp) ev("banLaunch", { v: c.v, last: c.left === R.rails - 1 }); + } else { + you.x = nx; + you.y = trackY(R, c.line, nx); + } + } + } else { + // In the air. + c.coyote = Math.max(0, c.coyote - ms); + if (want && c.coyote > 0) { + inp.jump = 0; + c.coyote = 0; + you.vy = BAN_JUMP_V; + c.from = you.y; + ev("banJump", { v: c.v }); + } + c.dive = Boolean(inp.down); + const py = you.y; + you.vy = Math.max(-k.FALL_MAX, you.vy - BAN_G * dt); + you.x += c.v * dt; + you.y += you.vy * dt; + you.ducking = false; + you.state = "air"; + if (you.vy <= 0) { + const f = landOn(R, you.x, py, you.y, c.dive); + if (f) { + you.y = f.y; + you.vy = 0; + you.state = "run"; + const was = lowerLine(R, c.left); + c.line = f.line; + ev("banLand", { big: c.from - f.y >= BIG_LAND }); + if (lowerLine(R, f.line) !== was) ev("banSwitch", { lower: lowerLine(R, f.line) }); + c.from = f.y; + } else if (you.x >= R.finish) { + // Over the foyer floor at the end: down onto it, and the ride is over. + const g = k.groundAt(round.spec, you.x); + if (g > -Infinity && you.y <= g + 0.01) return finish(round, c, R, g, k); + } + } + } + // A press nothing took waits a moment for a landing, then goes. + if (want && inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms); + // Past the end of the world: a break, the end of an under-rail, or the face of the foyer. + if (you.y < DERAIL_Y || k.groundAt(round.spec, you.x) > you.y + 0.5) { + if (!lowerLine(R, c.left)) noteHit(round, `g${c.left}`); + if (k.lose(round, "plunge") && round.phase === "play") reseat(round, c, R); + return true; + } + while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) { + c.check++; + ev("banCheck", { n: c.check + 1 }); + } + round.camLead = CAM_AHEAD + (c.v - BAN_V) * CAM_PER_V; + if (obstacles(round, c, R, k)) return true; + creatures(round, c, R, ms); + return true; +} + +// The ride is over: the banister ends, the door opens, you walk out across the foyer. +function finish(round, c, R, g, k) { + const you = round.you; + c.done = true; + c.restX = you.x; + Object.assign(you, { y: g, vy: 0, state: "run", shelf: -1, ducking: false }); + round.hasKey = true; + round.camLead = 0; + round.events.push({ type: "banFinish", x: you.x, y: you.y, big: c.from - g >= BIG_LAND }); + return false; +} + +// A bolt flies parallel to the rail under it, whatever way you aimed (`s.off`): the stairs are +// steep, and a level bolt would sail over everything on a descent. +function steerShots(round, R) { + for (const s of round.shots) { + if (s.arm || s.free) continue; + if (s.off === undefined) s.off = s.vy; + const top = topAt(R, s.x); + if (top) s.sl = slopeOf(R, top[0], s.x); + s.vy = s.vx * (s.sl ?? 0) + s.off; + } +} + +// What you run into: a prop, a hanging frame, a chandelier, a butler. Returns whether it +// cost a heart. A web only tears. +function obstacles(round, c, R, k) { + const you = round.you; + const hh = duckH(k, you); + for (const [i, [x0, x1, y]] of R.lows.entries()) { + if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > y && k.struck(round, "frame")) { + noteHit(round, `f${i}`); + round.events.push({ type: "banCrash", what: "frame", x: you.x, y: you.y + hh }); + return true; + } + } + for (let i = 0; i < R.swings.length; i++) { + const [cx, , amp] = R.swings[i]; + if (Math.abs(you.x - cx) > amp + SWING_BOB_W + 2) continue; + const s = swingAt(R, i, c.clock); + if (Math.abs(you.x - s.x) < (SWING_BOB_W + k.HIT_W) / 2 && you.y + hh > s.bottom && k.struck(round, "swing")) { + noteHit(round, `w${i}`); + round.events.push({ type: "banCrash", what: "swing", x: s.x, y: s.bottom }); + return true; + } + } + for (const [i, [x, line, kind]] of R.props.entries()) { + if (Math.abs(you.x - x) > 6) continue; + const cause = kind ? "candle" : "vase"; + if (boxHit(k, you, x, trackY(R, line, x), kind ? CANDLE_W : VASE_W, kind ? CANDLE_H : VASE_H) && k.struck(round, cause)) { + noteHit(round, `p${i}`); + round.events.push({ type: "banCrash", what: cause, x, y: you.y }); + return true; + } + } + for (const [i, b] of c.butlers.entries()) { + if (b.state !== "warn" && b.state !== "lunge") continue; + if (Math.abs(you.x - b.x) > 6) continue; + const y = trackY(R, R.butlers[i][1], clamp(b.x, linesOf(R)[R.butlers[i][1]].x0, linesOf(R)[R.butlers[i][1]].x1)); + if (boxHit(k, you, b.x, y, BUTLER_W, BUTLER_H) && k.struck(round, "butler")) { + noteHit(round, `b${i}`); + round.events.push({ type: "banCrash", what: "butler", x: b.x, y: you.y }); + Object.assign(b, { state: "spent", t: 0 }); + return true; + } + } + R.webs.forEach(([x, line], i) => { + if (c.webs[i] !== "up" || Math.abs(you.x - x) > 4) return; + const y = trackY(R, line, x); + if (y !== null && Math.abs(you.x - x) < (k.HIT_W + WEB_W) / 2 && you.y < y + WEB_HI && you.y + hh > y + WEB_LO) { + c.webs[i] = "torn"; + round.events.push({ type: "banWebTear", x, y: y + 3 }); + } + }); + return false; +} + +// The butlers wake when you come near, bow, and lunge up the rail at you. +function creatures(round, c, R, ms) { + const you = round.you; + R.butlers.forEach(([hx, line], i) => { + const b = c.butlers[i]; + const L = linesOf(R)[line]; + const y = () => trackY(R, line, clamp(b.x, L.x0, L.x1)); + if (b.state === "wait") { + const ahead = hx - you.x; + if (ahead < BUTLER_NEAR && ahead > -BUTLER_W) { + Object.assign(b, { state: "warn", t: BUTLER_WARN_MS }); + round.events.push({ type: "banButlerWarn", x: b.x, y: y() }); + } + } else if (b.state === "warn") { + b.t -= ms; + if (b.t <= 0) { + Object.assign(b, { state: "lunge", t: BUTLER_LUNGE_MS }); + round.events.push({ type: "banButlerLunge", x: b.x, y: y() }); + } + } else if (b.state === "lunge") { + b.t -= ms; + b.x = Math.max(L.x0 + 1, b.x - BUTLER_V * (ms / 1000)); + if (b.t <= 0 || b.x < you.x - 10) Object.assign(b, { state: "spent", t: 0 }); + } + }); +} + +/* ------------------------------------------------------------- targets */ + +// A bolt into something to shoot: a butler on the move, a cobweb. True when one took it. +function banisterShot(round, s) { + const R = round.spec.ride; + const c = round.runner; + if (!R || R.runner !== "banister" || !c || c.id !== "banister") return false; + const hit = (x, y0, w, h) => Math.abs(s.x - x) <= w / 2 + SHOT_R && s.y >= y0 - SHOT_R && s.y <= y0 + h + SHOT_R; + const score = (n) => { + round.score += n; + if (round.bonusRound) round.bonusRound.perf.acts++; + }; + for (let i = 0; i < R.butlers.length; i++) { + const b = c.butlers[i]; + if (b.state !== "warn" && b.state !== "lunge") continue; + const L = linesOf(R)[R.butlers[i][1]]; + const y = trackY(R, R.butlers[i][1], clamp(b.x, L.x0, L.x1)); + if (!hit(b.x, y, BUTLER_W, BUTLER_H)) continue; + b.hp--; + if (b.hp > 0) round.events.push({ type: "banButlerHit", x: b.x, y: y + BUTLER_H / 2 }); + else { + Object.assign(b, { state: "broken", t: 0 }); + score(BUTLER_POINTS); + round.events.push({ type: "banButlerBreak", x: b.x, y: y + BUTLER_H / 2, points: BUTLER_POINTS }); + } + return true; + } + for (let i = 0; i < R.webs.length; i++) { + if (c.webs[i] !== "up") continue; + const [x, line] = R.webs[i]; + const y = trackY(R, line, x); + if (y === null || !hit(x, y + WEB_LO, WEB_W, WEB_HI - WEB_LO)) continue; + c.webs[i] = "shot"; + score(WEB_POINTS); + round.events.push({ type: "banWebShot", x, y: y + 3, points: WEB_POINTS }); + return true; + } + return false; +} + +export const BANISTER = freeze({ + id: "banister", + monsters: MONSTERS, + walkers: freeze([]), + zombies: freeze([]), + stackers: freeze([]), + climbers: freeze([]), + act: freeze({}), + horde: freeze({}), + ride: freeze([ride]), + place: freeze([place]), + target: banisterShot, +}); diff --git a/src/web-console/public/activities/ghoul-bog-draw.js b/src/web-console/public/activities/ghoul-bog-draw.js new file mode 100644 index 0000000..09a5028 --- /dev/null +++ b/src/web-console/public/activities/ghoul-bog-draw.js @@ -0,0 +1,1321 @@ +// Plan2Code Web Console - Ghoul Rush's Gallows Bog stage, its drawing: the rooms' looks out on the night swamp (sagging boardwalk planks over black water, mud sheen in the dips, moss veils and fireflies in the hollow, the hag's stilt house lit warm, the open water of her arena), its monsters (a lurker's eyes, a leech swarm, a will-o'-wisp, a bog body), Old Mother Bog and her cauldron, the mud wave and the muck patches, the Stilt Boots' and Harpoon's badges, and what its events look and sound like. +// +// ghoul-draw.js plugs it in. LOOKS, VOICES, LOSE_WORDS and LOSE_SOUNDS are +// plain data; bogArt(d) takes ghoul-draw.js's own drawing helpers (`d`: +// ellipse, circle, roundRect, line, rotate, eye, hash, say, gate, label, +// DANGER, GOLD, FLASH and the eye colors) and hands back the drawing by +// kind, so this file never reaches back into it. Everything is drawn in +// room units, the way ghoul-draw.js draws: y counted down from the field's +// top, a monster from (x, y) at its feet. The bigger figures (the snapping +// lurker, Old Mother Bog) are drawn in a local frame turned to face the +// way they look, y counted up from the feet. Each function says what it +// draws and what in the rules (ghoul-bog.js) it follows. +// +// The sounds are all borrowed house tones until the stage's own are picked +// (the sound page's vote lands in Phase 5); the acts each event asks for +// are already named so the picks drop in. + +import { BOG_RISE_MS, LURKER_SINK_MS, MOTHER_SINK_MS, MOTHER_WIND_MS, MUCK_LAND_MS, RESURFACE_MS, SNAP_MS, SPIT_WIND_MS, WISP_REKINDLE_MS } from "./ghoul-bog.js"; + +const freeze = (o) => Object.freeze(o); +const TAU = Math.PI * 2; + +// Out on the night swamp, like the Grounds but wetter: the "wall" is the +// sky (`wallTop` to `wallLow`), `paper` the far tree line, `wainscot` the +// black water behind, `window` the moon, `scene` what each room's backdrop +// is made of, and `pack` names this file's drawing for ghoul-draw.js. The +// floor and shelf colors are what the planks are drawn in under ground() +// and shelf() below. `hedge` is the lighter green of a mossy edge. +const swamp = (o) => freeze({ wallTop: "#060b08", wallLow: "#12201a", paper: "#1d2e24", wainscot: "#101a12", floorTop: "#3a4430", floor: "#20281a", floorEdge: "#080d06", shelf: "#2a2418", shelfTop: "#463a24", pit: "#010402", window: "#8fb89a", hedge: "#3a5a34", decor: "plants", dark: 0.88, outdoor: true, pack: "bog", ...o }); +export const LOOKS = freeze({ + boardwalk: swamp({ color: "#8fb89a", scene: "boardwalk" }), + hollow: swamp({ color: "#84b3a0", scene: "hollow", wallTop: "#050a0a", wallLow: "#0f1d1c", paper: "#1a2c2a", wainscot: "#0e1614", floorTop: "#36402c", floor: "#1e2618", floorEdge: "#070c05", shelf: "#262217", shelfTop: "#423722", pit: "#010403", window: "#6f9a8a", dark: 0.89 }), + stilts: swamp({ color: "#b3a07a", scene: "stilts", wallTop: "#0a0806", wallLow: "#1c150e", paper: "#2a2116", wainscot: "#161009", floorTop: "#40392a", floor: "#242014", floorEdge: "#0a0805", shelf: "#2e2416", shelfTop: "#4a3c22", pit: "#020201", window: "#a8946a", decor: "rafters", dark: 0.9 }), + drowning: swamp({ color: "#a4b488", scene: "drowning", wallTop: "#070a06", wallLow: "#141c10", paper: "#202a18", wainscot: "#101408", floorTop: "#3c3e2c", floor: "#222418", floorEdge: "#0a0b06", shelf: "#2c281a", shelfTop: "#484026", pit: "#010301", window: "#8aa878", decor: "tombs", dark: 0.9 }), +}); + +// How each new kind sounds, by act (the stage's own tones, ghoul-sfx-bog.js: option 1 of each act +// until the vote, then the picks). The act names are the ones each event and each shared handler +// (`appear`, `hurt`, `die`) asks for. +export const VOICES = freeze({ + lurker: freeze({ appear: "ghoulLurkerAppear", snap: "ghoulLurkerSnap", sink: "ghoulLurkerSink", hurt: "ghoulLurkerHurt", die: "ghoulLurkerDie" }), + leech: freeze({ appear: "ghoulLeechAppear", latch: "ghoulLeechLatch", hurt: "ghoulLeechHurt", die: "ghoulLeechDie" }), + wisp: freeze({ appear: "ghoulWispAppear", out: "ghoulWispOut", relight: "ghoulWispRelight", on: "ghoulWispOn", hurt: "ghoulWispHurt", die: "ghoulWispDie" }), + bogbody: freeze({ appear: "ghoulBogbodyAppear", rise: "ghoulBogbodyRise", hurt: "ghoulBogbodyHurt", die: "ghoulBogbodyDie" }), + motherbog: freeze({ wake: "ghoulMotherWake", wind: "ghoulMotherWind", wave: "ghoulMotherWave", spitWind: "ghoulMotherSpitWind", spit: "ghoulMotherSpit", open: "ghoulMotherOpen", sink: "ghoulMotherSink", bubble: "ghoulMotherBubble", rise: "ghoulMotherRise", muck: "ghoulMotherMuck", hurt: "ghoulMotherHurt", weak: "ghoulMotherWeak", die: "ghoulMotherDie" }), +}); +// The words on a life lost to each new cause, and the sound beside the +// crash: the lurker's snap, a leech latch, the wisp's cold light, a bog +// body's grip, the mud wave, a muck patch and the hag's own touch. +export const LOSE_WORDS = freeze({ lurker: "Snapped", leeches: "Drained", wisp: "Misled", bogbody: "Dragged down", mudwave: "Swamped", muck: "Scalded", motherbog: "Stewed" }); +export const LOSE_SOUNDS = freeze({ + lurker: ["crunch", 0.55, 0.8], + leeches: ["squish", 0.5, 0.7], + wisp: ["wail", 0.35, 0.6], + bogbody: ["squish", 0.5, 0.8], + mudwave: ["thud", 0.6, 0.7], + muck: ["ghoulSizzle", 0.55, 0.7], + motherbog: ["splat", 0.6, 0.5], +}); + +// The bog's inks: wet wood, black water, old mud and the wisp's cold green. +const PLANK = "#4a4634"; +const PLANK_DARK = "#2c2a1c"; +const PLANK_LIT = "#6a6248"; +const PLANK_EDGE = "#17140c"; +const WATER = "#060a08"; +const WATER_SHEEN = "#284038"; +const MUD = "#33291a"; +const MUD_LIT = "#5a4a2c"; +const MUD_DARK = "#1c150c"; +const MOSS = "#3a5a34"; +const MOSS_LIT = "#6a8a4c"; +const WISP = "#9adfc0"; +const WISP_HOT = "#e8fff2"; +const WISP_DIM = "#3a4a40"; +const BOGSKIN = "#4a3a22"; +const BOGSKIN_LIT = "#7a6440"; +const BOGSKIN_DARK = "#241a0e"; +const HAG = "#5a4a2a"; +const HAG_DARK = "#362a14"; +const HAG_LIT = "#8a7448"; +const CAULDRON = "#1e1c14"; +const CAULDRON_LIT = "#7ac86a"; +const LURKER = "#2a3a18"; +const LURKER_LIT = "#54683a"; +const LURKER_MAW = "#b8482e"; +const LEECH = "#3d2a24"; +const LEECH_LIT = "#6a463a"; +const FIRE_FLY = "#d8e88a"; + +export function bogArt(d) { + const { ellipse, circle, roundRect, line, rotate, eye, hash, say, gate, DANGER, GOLD, FLASH, EYE_PALE, EYE_AMBER } = d; + const rnd = (a, b) => hash(a, b) / 997; + const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x)); + const mix = (a, b, p) => a + (b - a) * p; + + // A soft glow as a few stacked discs, `a` the strength at the middle. + function halo(ctx, x, y, r, color, a) { + const was = ctx.globalAlpha; + ctx.fillStyle = color; + for (const [k, s] of [[1, 0.2], [0.72, 0.25], [0.46, 0.3], [0.24, 0.35]]) { + ctx.globalAlpha = was * a * s; + circle(ctx, x, y, r * k); + ctx.fill(); + } + ctx.globalAlpha = was; + } + + /* ------------------------------------------------------- the backdrop */ + + // A dead cypress, bare trunk forking into a few limbs, standing in the + // water line. `h` tall from its base at (x, base). + function deadTree(ctx, x, base, h, color, seed) { + ctx.strokeStyle = color; + ctx.lineWidth = Math.max(0.4, h * 0.045); + ctx.beginPath(); + ctx.moveTo(x, base); + ctx.quadraticCurveTo(x + (rnd(seed, 1) - 0.5) * h * 0.12, base - h * 0.55, x + (rnd(seed, 2) - 0.5) * h * 0.2, base - h); + ctx.stroke(); + ctx.lineWidth = Math.max(0.25, h * 0.022); + for (let k = 0; k < 4; k++) { + const t = 0.45 + k * 0.14; + const bx = x + (rnd(seed, 2) - 0.5) * h * 0.2 * t; + const by = base - h * t; + const dir = rnd(seed, 3 + k) > 0.5 ? 1 : -1; + ctx.beginPath(); + ctx.moveTo(bx, by); + ctx.quadraticCurveTo(bx + dir * h * 0.1, by - h * 0.08, bx + dir * h * (0.14 + rnd(seed, k + 9) * 0.1), by - h * 0.2); + ctx.stroke(); + } + } + + // The night behind a room, from x0 to x1: the sky and its stars, the moon + // thin behind cloud, a far line of drowned trees, and the black water of + // the mire along the bottom with the moon's sheen in it and fog bands + // drifting. + function swampNight(ctx, v, look, x0, x1) { + const { g } = v; + const sky = typeof ctx.createLinearGradient === "function" ? ctx.createLinearGradient(0, 0, 0, g.FIELD_H) : null; + if (sky && typeof sky.addColorStop === "function") { + sky.addColorStop(0, look.wallTop); + sky.addColorStop(0.72, look.wallLow); + sky.addColorStop(1, look.wainscot); + ctx.fillStyle = sky; + } else ctx.fillStyle = look.wallLow; + ctx.fillRect(x0, 0, x1 - x0, g.FIELD_H); + // Stars, fewer and dimmer than the garden's: the swamp eats light. + ctx.fillStyle = "#c8d8c8"; + for (let x = Math.floor(x0 / 3) * 3; x < x1 + 3; x += 3) { + const h = hash(Math.round(x / 3), 71); + if (h % 6) continue; + ctx.globalAlpha = 0.16 + (h % 4) * 0.09; + ctx.fillRect(x + (h % 3), 1 + (h % 21), 0.18, 0.18); + } + ctx.globalAlpha = 1; + // The moon, low and smeared by mist. + for (let x = Math.floor(x0 / 260) * 260 + 170; x < x1 + 12; x += 260) { + halo(ctx, x, 8.5, 10, look.window, 0.42); + ctx.fillStyle = look.window; + ctx.globalAlpha = 0.85; + circle(ctx, x, 8.5, 3.4); + ctx.fill(); + ctx.globalAlpha = 0.16; + ctx.fillStyle = "#5a6a58"; + for (const [cx, cy, cr] of [[-1, -0.8, 0.9], [1.1, 0.9, 0.7], [0.3, -1.7, 0.45], [-1.5, 1.2, 0.4]]) { + circle(ctx, x + cx, 8.5 + cy, cr); + ctx.fill(); + } + } + // Thin cloud banks under it. + for (let x = Math.floor(x0 / 110) * 110 + 30; x < x1 + 40; x += 110) { + const h = hash(Math.round(x / 110), 19); + ctx.globalAlpha = 0.05 + (h % 3) * 0.014; + ctx.fillStyle = "#8aa098"; + ellipse(ctx, x + (h % 34), 12 + (h % 8), 19 + (h % 9), 1); + ctx.fill(); + } + ctx.globalAlpha = 1; + // The far shore: a drowned tree line on the black water. + const shore = g.FIELD_H - 13.5; + ctx.fillStyle = look.paper; + ctx.beginPath(); + ctx.moveTo(x0, g.FIELD_H); + for (let x = x0; x <= x1 + 1; x += 2) ctx.lineTo(x, shore + Math.sin(x / 53) * 1.1 + Math.sin(x / 17 + 2) * 0.5); + ctx.lineTo(x1 + 1, g.FIELD_H); + ctx.closePath(); + ctx.fill(); + for (let x = Math.floor(x0 / 21) * 21; x < x1 + 21; x += 21) { + const n = Math.round(x / 21); + const h = hash(n, 5); + if (h % 5 === 0) continue; + deadTree(ctx, x + (h % 8), shore + 1 + (h % 2), 7 + (h % 6) * 1.1, h % 3 ? look.paper : look.wainscot, n * 13 + 7); + } + // The water itself: black, with the moon's broken sheen and the odd + // bubble where something breathes underneath. + ctx.fillStyle = look.wainscot; + ctx.fillRect(x0, shore + 4, x1 - x0, g.FIELD_H - shore - 4); + for (let x = Math.floor(x0 / 7) * 7; x < x1 + 7; x += 7) { + const n = Math.round(x / 7); + const h = hash(n, 23); + if (h % 4 === 0) continue; + ctx.globalAlpha = 0.05 + (h % 5) * 0.02; + ctx.fillStyle = WATER_SHEEN; + ctx.fillRect(x + (h % 4), shore + 5.5 + (h % 4) * 1.4, 3 + (h % 4), 0.4); + } + for (let x = Math.floor(x0 / 43) * 43 + 11; x < x1 + 43; x += 43) { + const n = Math.round(x / 43); + const h = hash(n, 29); + if (h % 3 === 0) continue; + ctx.globalAlpha = 0.1; + ctx.strokeStyle = WATER_SHEEN; + ctx.lineWidth = 0.15; + ellipse(ctx, x + (h % 13), shore + 8 + (h % 3), 1.2 + (h % 2) * 0.6, 0.4); + ctx.stroke(); + } + ctx.globalAlpha = 1; + // Fog bands over the water. + ctx.fillStyle = "#7a9080"; + for (let x = Math.floor(x0 / 19) * 19; x < x1 + 19; x += 19) { + const h = hash(Math.round(x / 19), 31); + ctx.globalAlpha = 0.05 + (h % 4) * 0.016; + ellipse(ctx, x + (h % 11), g.FIELD_H - 6.5 - (h % 4), 13, 2); + ctx.fill(); + } + ctx.globalAlpha = 1; + return shore; + } + + // A moss veil: strands hanging from a branch or an eave, swaying never + // (the still layer), pale at their moonlit tips. + function mossVeil(ctx, x, top, len, seed) { + for (let k = 0; k < 5; k++) { + const mx = x + (k - 2) * 0.9 + (rnd(seed, k) - 0.5) * 0.6; + const l = len * (0.5 + rnd(seed, k + 11) * 0.7); + ctx.strokeStyle = k % 2 ? MOSS : "#2c4528"; + ctx.lineWidth = 0.3; + ctx.globalAlpha = 0.85; + ctx.beginPath(); + ctx.moveTo(mx, top); + ctx.quadraticCurveTo(mx + (rnd(seed, k + 21) - 0.5) * 1.6, top + l * 0.6, mx + (rnd(seed, k + 31) - 0.5) * 2, top + l); + ctx.stroke(); + ctx.globalAlpha = 0.5; + ctx.fillStyle = MOSS_LIT; + ctx.fillRect(mx + (rnd(seed, k + 31) - 0.5) * 2 - 0.2, top + l - 0.4, 0.45, 0.6); + } + ctx.globalAlpha = 1; + } + + // The hollow: closer dead cypress between you and the water, moss veils + // on their limbs, cypress knees poking out of the pools, firefly flecks + // hanging in the dark. + function hollowStand(ctx, v, look, x0, x1, shore, floorAt) { + const { g } = v; + for (let x = Math.floor(x0 / 37) * 37 + 9; x < x1 + 37; x += 37) { + const n = Math.round(x / 37); + const h = hash(n, 7); + if (h % 4 === 0) continue; + const tx = x + (h % 12); + deadTree(ctx, tx, g.FIELD_H - 2, 16 + (h % 8), "#122016", n * 17 + 3); + if (h % 3 === 0) mossVeil(ctx, tx + 1.5, g.FIELD_H - 11 - (h % 5), 6 + (h % 4), n * 7); + } + // Cypress knees along the floor line. + ctx.fillStyle = "#131c12"; + for (let x = Math.floor(x0 / 9) * 9 + 3; x < x1 + 9; x += 9) { + const n = Math.round(x / 9); + const fy = floorAt(x); + if (fy === null || hash(n, 13) % 3 === 0) continue; + ctx.beginPath(); + ctx.moveTo(x - 0.8, fy); + ctx.lineTo(x, fy - 2.4 - (hash(n, 15) % 3) * 0.7); + ctx.lineTo(x + 0.8, fy); + ctx.closePath(); + ctx.fill(); + } + // Fireflies: small warm flecks adrift above the pools. + for (let x = Math.floor(x0 / 23) * 23 + 6; x < x1 + 23; x += 23) { + const n = Math.round(x / 23); + const h = hash(n, 41); + if (h % 3 === 0) continue; + const fy = floorAt(x + (h % 9)); + if (fy === null) continue; + ctx.globalAlpha = 0.3 + (h % 4) * 0.14; + ctx.fillStyle = FIRE_FLY; + ctx.fillRect(x + (h % 9), fy - 3 - (h % 7), 0.3, 0.3); + ctx.globalAlpha = 0.12; + circle(ctx, x + (h % 9) + 0.15, fy - 3 - (h % 7) + 0.15, 0.8); + ctx.fill(); + } + ctx.globalAlpha = 1; + } + + // The hag's house on its stilts over the water: leaning piles, a sagging + // shack of gray boards, one window warm against the whole cold swamp. + function stiltHouse(ctx, v, x0, x1) { + const { g } = v; + const base = g.FIELD_H - 4; + for (let x = Math.floor(x0 / 130) * 130 + 60; x < x1 + 130; x += 130) { + const n = Math.round(x / 130); + const h = hash(n, 3); + const hx = x + (h % 20) - 10; + const w = 26 + (h % 8); + const top = base - 15 - (h % 4); + // The stilts, two of them a touch splayed. + ctx.strokeStyle = "#171008"; + ctx.lineWidth = 0.9; + line(ctx, hx - w * 0.34, base + 2, hx - w * 0.38, top); + line(ctx, hx + w * 0.34, base + 2, hx + w * 0.38, top); + ctx.lineWidth = 0.5; + line(ctx, hx - w * 0.36, base - 4, hx + w * 0.36, base - 7); + // The shack, leaning a little, roof of sod. + ctx.save(); + ctx.translate(hx, top); + rotate(ctx, (rnd(n, 9) - 0.5) * 0.06); + ctx.fillStyle = "#241a10"; + ctx.fillRect(-w / 2, -8, w, 8); + ctx.strokeStyle = "#0e0a05"; + ctx.lineWidth = 0.18; + for (let bx = -w / 2 + 1; bx < w / 2; bx += 2.1) line(ctx, bx, -8, bx, 0); + ctx.fillStyle = "#161009"; + ctx.beginPath(); + ctx.moveTo(-w / 2 - 2.5, -8); + ctx.lineTo(-w * 0.1, -12.5); + ctx.lineTo(w / 2 + 2.5, -8); + ctx.closePath(); + ctx.fill(); + ctx.strokeStyle = "#0c0804"; + ctx.lineWidth = 0.16; + for (let k = 0; k < 6; k++) line(ctx, -w / 2 - 2 + k * (w / 5), -8 - k * 0.7, -w / 2 - 2 + (k + 2.6) * (w / 5), -8 - k * 0.7); + // The one warm window, cross-barred, a figure's shadow never still. + ctx.fillStyle = "#c8923e"; + ctx.globalAlpha = 0.85; + ctx.fillRect(-w * 0.16, -6.4, w * 0.2, 4); + ctx.globalAlpha = 1; + ctx.fillStyle = "#1a120a"; + ctx.fillRect(-w * 0.16 + w * 0.09, -6.4, 0.5, 4); + ctx.fillRect(-w * 0.16, -4.6, w * 0.2, 0.5); + halo(ctx, 0, -4.4, 4.5, "#c8923e", 0.3); + // A door like a hole. + ctx.fillStyle = "#0a0603"; + ctx.fillRect(w * 0.2, -5.5, w * 0.14, 5.5); + mossVeil(ctx, -w / 2 + 1.5, -8, 5, n * 11); + ctx.restore(); + } + } + + // The Drowning Pool's middle: open water, only the far trees and the + // arena's mooring posts with their rope. + function drowningWater(ctx, v, x0, x1, shore) { + const { g } = v; + for (let x = Math.floor(x0 / 34) * 34 + 8; x < x1 + 34; x += 34) { + const n = Math.round(x / 34); + const h = hash(n, 11); + if (h % 4 === 0) continue; + const px = x + (h % 10); + ctx.fillStyle = "#14100a"; + ctx.fillRect(px - 0.5, shore + 2, 1, g.FIELD_H - shore - 4); + ctx.fillStyle = "#0a0805"; + ctx.fillRect(px - 0.8, shore + 1.4, 1.6, 0.8); + ctx.strokeStyle = "#241c10"; + ctx.lineWidth = 0.18; + ctx.beginPath(); + ctx.moveTo(px, shore + 3.4); + ctx.quadraticCurveTo(px + 8, shore + 5.4, px + 16, shore + 3.6); + ctx.stroke(); + } + } + + // The boardwalk behind you: more of the same sagging planks running back + // along the water on their posts, sinking out of sight. + function farBoardwalk(ctx, v, x0, x1, shore) { + const { g } = v; + ctx.strokeStyle = "#141c14"; + ctx.lineWidth = 0.5; + const deckY = shore + 6.5; + ctx.beginPath(); + ctx.moveTo(x0, deckY); + for (let x = x0; x <= x1 + 1; x += 4) ctx.lineTo(x, deckY + Math.sin(x / 31) * 0.8); + ctx.stroke(); + ctx.lineWidth = 0.35; + for (let x = Math.floor(x0 / 11) * 11 + 4; x < x1 + 11; x += 11) { + const n = Math.round(x / 11); + if (hash(n, 8) % 4 === 0) continue; + const py = deckY + Math.sin(x / 31) * 0.8; + line(ctx, x, py, x + (hash(n, 5) % 3 - 1) * 0.5, g.FIELD_H - 1); + } + } + + // The night behind a room, then what the room is: the hollow's trees and + // moss, the stilt house, the arena's moorings. + function backdrop(ctx, v, look, x0, x1) { + const { spec, g } = v; + const Y = (y) => g.FIELD_H - y; + const floorAt = (x) => { + const gy = v.groundAt(spec, x); + return gy > -Infinity ? Y(gy) : null; + }; + const shore = swampNight(ctx, v, look, x0, x1); + if (look.scene === "boardwalk") farBoardwalk(ctx, v, x0, x1, shore); + else if (look.scene === "hollow") hollowStand(ctx, v, look, x0, x1, shore, floorAt); + else if (look.scene === "stilts") { + hollowStand(ctx, v, look, x0, x1, shore, floorAt); + stiltHouse(ctx, v, x0, x1); + } else if (look.scene === "drowning") drowningWater(ctx, v, x0, x1, shore); + } + + /* ----------------------------------------------------- floors, shelves */ + + // Where a span of `spans` ([x0, x1] pairs) covers [a, b]: the overlaps, + // as [max, min] pairs inside the piece. + function spansIn(spec, key, a, b) { + const out = []; + for (const [s0, s1] of spec[key] || []) { + const lo = Math.max(s0, a); + const hi = Math.min(s1, b); + if (hi - lo > 0.4) out.push([lo, hi]); + } + return out; + } + + // A mud sheen over [a, b] at floor top fy: glossy muck lapping over the + // planks, a lighter meniscus at its edge, bubbles where it breathes. + function mudSheen(ctx, a, b, fy, seed) { + ctx.fillStyle = MUD_DARK; + ctx.beginPath(); + ctx.moveTo(a, fy); + for (let x = a; x <= b; x += 2) ctx.lineTo(x, fy - 0.5 - Math.sin(x / 5 + seed) * 0.3); + ctx.lineTo(b, fy + 1.6); + ctx.lineTo(a, fy + 1.6); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = MUD; + ctx.globalAlpha = 0.9; + ctx.beginPath(); + ctx.moveTo(a, fy - 0.2); + for (let x = a; x <= b; x += 2) ctx.lineTo(x, fy - 0.7 - Math.sin(x / 5 + seed) * 0.3); + ctx.lineTo(b, fy + 0.9); + ctx.lineTo(a, fy + 0.9); + ctx.closePath(); + ctx.fill(); + ctx.globalAlpha = 0.55; + ctx.fillStyle = MUD_LIT; + for (let x = a + 1; x < b - 0.6; x += 3.4) { + const h = hash(seed + Math.round(x * 10), 7); + if (h % 3) ctx.fillRect(x, fy - 0.9 - Math.sin(x / 5 + seed) * 0.3, 1.4 + (h % 3) * 0.4, 0.28); + } + for (let x = a + 2; x < b - 1; x += 5.2) { + const h = hash(seed + Math.round(x * 10), 11); + if (h % 4) continue; + circle(ctx, x, fy - 0.5, 0.22 + (h % 3) * 0.08); + ctx.fill(); + } + ctx.globalAlpha = 1; + } + + // A pool of black water on the boards [a, b] at fy: the surface a shade + // off the planks, the moon's sheen broken across it. + function poolSheen(ctx, a, b, fy, seed) { + ctx.fillStyle = WATER; + ctx.fillRect(a, fy - 0.5, b - a, 1.6); + ctx.fillStyle = WATER_SHEEN; + ctx.globalAlpha = 0.4; + for (let x = a + 0.8; x < b - 0.8; x += 3.1) { + const h = hash(seed + Math.round(x * 10), 5); + if (h % 3 === 0) continue; + ctx.fillRect(x, fy - 0.35 + (h % 3) * 0.3, 1.6 + (h % 4) * 0.4, 0.22); + } + ctx.globalAlpha = 1; + } + + // One floor piece, [a, b] with its top at `top`: the boardwalk's planks, + // sagging a little between their posts, grain and nails, rotted edges; + // where the spec's mud lies over it a wet sheen sits in the dip, where a + // pool lies the water laps the boards. + function ground(ctx, v, look, a, b, top) { + const { spec, g } = v; + const fy = g.FIELD_H - top; + const w = b - a; + const seed = Math.round(a * 7); + const sag = Math.min(1.1, w / 60); + // The planks, top down to the water line: a deck of weathered boards + // with a sagging lower edge. + ctx.fillStyle = look.floor; + ctx.beginPath(); + ctx.moveTo(a, fy); + for (let x = a; x <= b; x += 3) ctx.lineTo(x, fy + Math.sin(((x - a) / w) * Math.PI) * sag * 0.4); + ctx.lineTo(b, fy + top); + ctx.lineTo(a, fy + top); + ctx.closePath(); + ctx.fill(); + // Board seams and the pale worn top edge. + ctx.fillStyle = look.floorTop; + ctx.globalAlpha = 0.9; + for (let x = a; x < b; x += 3) ctx.fillRect(x, fy + Math.sin(((x - a) / w) * Math.PI) * sag * 0.4, Math.min(2.7, b - x), 0.9); + ctx.globalAlpha = 1; + ctx.fillStyle = PLANK_EDGE; + for (let x = a + 2.7; x < b - 0.5; x += 3) ctx.fillRect(x, fy, 0.35, top); + // Grain flecks and nail heads. + for (let x = a + 0.8; x < b - 0.6; x += 1.7) { + const h = hash(seed + Math.round(x * 10), 3); + ctx.fillStyle = h % 2 ? PLANK_DARK : "#3c3a28"; + ctx.globalAlpha = 0.5; + ctx.fillRect(x, fy + 1.4 + (h % 4) * 0.7, 1 + (h % 3) * 0.5, 0.3); + ctx.globalAlpha = 1; + } + for (let x = a + 1.6; x < b - 1; x += 6) { + const h = hash(seed + Math.round(x), 9); + if (h % 3 === 0) continue; + ctx.fillStyle = "#171310"; + ctx.fillRect(x, fy + Math.sin(((x - a) / w) * Math.PI) * sag * 0.4 + 0.35, 0.3, 0.3); + } + // A rotted bite out of the far edge now and then. + const edge = hash(seed, 17) % 5; + if (edge < 2 && w > 12) { + const ex = edge ? a + 1 : b - 1; + ctx.fillStyle = look.wainscot; + ctx.beginPath(); + ctx.moveTo(ex, fy + 1); + for (let k = 0; k < 4; k++) ctx.lineTo(ex + (edge ? -1 : 1) * (0.4 + k * 0.5), fy + 1 + k * (top / 4)); + ctx.lineTo(ex, fy + top); + ctx.closePath(); + ctx.fill(); + } + // Where the mire reaches over it: mud sheen in the dips, pool water in + // the wet spans. + for (const [m0, m1] of spansIn(spec, "mud", a, b)) mudSheen(ctx, m0, m1, fy, seed + Math.round(m0)); + for (const [w0, w1] of spansIn(spec, "water", a, b)) poolSheen(ctx, w0, w1, fy, seed + Math.round(w0)); + } + + // One shelf: more of the same planks on two posts, sagging in the middle. + function shelf(ctx, v, look, a, b, y) { + const { spec, g } = v; + const w = b - a; + const sag = Math.min(0.8, w / 40); + ctx.fillStyle = look.shelf; + ctx.beginPath(); + ctx.moveTo(a, y); + for (let x = a; x <= b; x += 2) ctx.lineTo(x, y + Math.sin(((x - a) / w) * Math.PI) * sag); + ctx.lineTo(b, y + 1.7); + ctx.lineTo(a, y + 1.7); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = look.shelfTop; + for (let x = a; x < b; x += 2) { + const sy = y + Math.sin(((x - a) / w) * Math.PI) * sag; + ctx.fillRect(x, sy, Math.min(1.6, b - x), 0.55); + } + ctx.fillStyle = PLANK_EDGE; + for (let x = a + 1.7; x < b - 0.4; x += 2) ctx.fillRect(x, y + Math.sin(((x - a) / w) * Math.PI) * sag, 0.28, 1.7); + // The posts: two under each board, off into the water. + const gy = v.groundAt(spec, (a + b) / 2); + const postBase = gy > -Infinity ? g.FIELD_H - gy : y + 7; + ctx.fillStyle = "#1a140c"; + for (const px of [a + 1.2, b - 1.6]) { + ctx.fillRect(px, y + 1.5, 0.7, postBase - y - 1.5); + } + } + + /* ------------------------------------------------------------- kinds */ + + // The lurker: while `eyes` just a brow line and two pale eyes at the + // waterline, a ripple either side; while `snap` the whole beast lunging + // out of the water, jaws open on you (SNAP_MS of lunge); while `sink` a + // swirl going back down, the eyes last to go. + function lurker(ctx, v, m, x, y, t, flash) { + const C = (c) => (flash ? FLASH : c); + const d = m.dir || 1; + if (m.act === "snap") { + const p = m.wait > 0 ? clamp(1 - m.wait / SNAP_MS, 0, 1) : 1; + // Out of the water fastest at first, settling into the lunge. + const up = Math.min(1, p * 3); + ctx.save(); + ctx.translate(x, y); + ctx.scale(d, 1); + // The wake it threw up. + ctx.globalAlpha = 0.5 * (1 - p * 0.6); + ctx.fillStyle = WATER_SHEEN; + ellipse(ctx, -d * 0.5, 0.1, m.w * 0.75 * up + 0.5, 0.5); + ctx.fill(); + ctx.globalAlpha = 1; + // The lunge: head and shoulders rearing well clear of the water. + const rise = -up * (m.h * 1.15); + ctx.fillStyle = C(LURKER); + ctx.beginPath(); + ctx.moveTo(-m.w * 0.55, 0); + ctx.quadraticCurveTo(-m.w * 0.5, rise - 1.2, m.w * 0.34, rise - 1.05); + ctx.lineTo(m.w * 0.62, rise - 0.5); + ctx.lineTo(m.w * 0.5, rise - 0.1); + ctx.quadraticCurveTo(0, rise + 0.7, -m.w * 0.55, 0); + ctx.closePath(); + ctx.fill(); + // The jaw, dropped open on the lunge. + const gape = Math.sin(Math.min(1, p * 2) * Math.PI * 0.5); + ctx.fillStyle = C(LURKER_MAW); + ctx.beginPath(); + ctx.moveTo(m.w * 0.5, rise - 0.12); + ctx.lineTo(m.w * (0.56 - 0.1 * gape), rise + 0.9 * gape + 0.15); + ctx.lineTo(-m.w * 0.1, rise + 0.75 * gape + 0.1); + ctx.closePath(); + ctx.fill(); + // Needle teeth along the upper jaw. + ctx.fillStyle = "#d8dcc8"; + for (let k = 0; k < 5; k++) { + const tx = m.w * 0.44 - k * m.w * 0.11; + ctx.beginPath(); + ctx.moveTo(tx, rise - 0.14); + ctx.lineTo(tx + 0.12, rise - 0.14); + ctx.lineTo(tx + 0.05, rise + 0.22 * gape); + ctx.closePath(); + ctx.fill(); + } + // Back ridges and the one eye. + ctx.fillStyle = C(LURKER_LIT); + for (let k = 0; k < 4; k++) { + ctx.beginPath(); + ctx.moveTo(-m.w * 0.5 + k * 0.9, rise * 0.35 - 0.1); + ctx.lineTo(-m.w * 0.28 + k * 0.9, rise * 0.9 - 0.9); + ctx.lineTo(-m.w * 0.1 + k * 0.9, rise * 0.35 - 0.1); + ctx.closePath(); + ctx.fill(); + } + eye(v, x + d * m.w * 0.3, y + rise - 0.62, 0.3, EYE_AMBER); + ctx.restore(); + return; + } + if (m.act === "sink") { + // A swirl where it went down, the eyes just under, going dim. + const p = m.wait > 0 ? clamp(m.wait / LURKER_SINK_MS, 0, 1) : 0; + ctx.strokeStyle = WATER_SHEEN; + ctx.lineWidth = 0.2; + ctx.globalAlpha = 0.7; + for (const [rx, ry] of [[m.w * 0.5, 0.35], [m.w * 0.32, 0.24]]) { + ellipse(ctx, x, y + 0.1, rx * (1.6 - p * 0.6), ry * (1.6 - p * 0.6)); + ctx.stroke(); + } + ctx.globalAlpha = p; + eye(v, x - 0.62, y - 0.1, 0.24, EYE_PALE); + eye(v, x + 0.62, y - 0.1, 0.24, EYE_PALE); + ctx.globalAlpha = 1; + return; + } + // `eyes`: two at the waterline under one heavy brow, a slow blink now + // and then (closed a tenth of the time), a small wake either side. + const blink = (t / 1600 + m.id * 0.13) % 1 > 0.93 ? 0.25 : 1; + ctx.strokeStyle = WATER_SHEEN; + ctx.lineWidth = 0.16; + ctx.globalAlpha = 0.55; + ellipse(ctx, x - 1.1, y + 0.15, 1.5, 0.3); + ctx.stroke(); + ellipse(ctx, x + 1.1, y + 0.15, 1.5, 0.3); + ctx.stroke(); + ctx.globalAlpha = 1; + // The brow: a low dome of wet hide, its moonlit rim keeping the shape + // readable in a dark room. + ctx.fillStyle = C(LURKER); + ctx.beginPath(); + ctx.moveTo(x - 1.6, y + 0.15); + ctx.quadraticCurveTo(x, y - 1.5 * blink, x + 1.6, y + 0.15); + ctx.closePath(); + ctx.fill(); + ctx.strokeStyle = C(LURKER_LIT); + ctx.lineWidth = 0.2; + ctx.globalAlpha = 0.85; + ctx.beginPath(); + ctx.moveTo(x - 1.3, y - 0.12); + ctx.quadraticCurveTo(x, y - 1.35 * blink, x + 1.3, y - 0.12); + ctx.stroke(); + ctx.globalAlpha = 1; + if (blink === 1) { + ctx.fillStyle = C("#cfe0d0"); + circle(ctx, x - 0.55, y - 0.5, 0.26); + ctx.fill(); + circle(ctx, x + 0.55, y - 0.5, 0.26); + ctx.fill(); + ctx.fillStyle = C(LURKER_MAW); + circle(ctx, x - 0.55, y - 0.5, 0.12); + ctx.fill(); + circle(ctx, x + 0.55, y - 0.5, 0.12); + ctx.fill(); + eye(v, x - 0.55, y - 0.5, 0.16, EYE_PALE); + eye(v, x + 0.55, y - 0.5, 0.16, EYE_PALE); + } + } + + // The leech swarm: a roiling blob that never sits still, paler leech + // squiggles curling through it; `drop` is it letting go and falling off + // you, strewn a little. + function leech(ctx, v, m, x, y, t, flash) { + const C = (c) => (flash ? FLASH : c); + const roil = Math.sin(t / 140); + ctx.fillStyle = C(LEECH); + ellipse(ctx, x, y - m.h * 0.45, m.w * 0.52, m.h * 0.45 + roil * 0.12); + ctx.fill(); + ellipse(ctx, x - m.w * 0.22, y - m.h * 0.3, m.w * 0.3, m.h * 0.3 - roil * 0.1); + ctx.fill(); + ellipse(ctx, x + m.w * 0.24, y - m.h * 0.52, m.w * 0.28, m.h * 0.28 + roil * 0.08); + ctx.fill(); + // The squiggles: leech curls over the mass. + ctx.strokeStyle = C(LEECH_LIT); + ctx.lineWidth = 0.2; + for (let k = 0; k < 6; k++) { + const a = (k / 6) * TAU + t / 300; + const sx = x + Math.cos(a) * m.w * 0.3; + const sy = y - m.h * 0.45 + Math.sin(a) * m.h * 0.26; + ctx.beginPath(); + ctx.moveTo(sx - 0.4, sy + Math.sin(a * 3) * 0.14); + ctx.quadraticCurveTo(sx, sy - 0.3, sx + 0.4, sy + Math.cos(a * 2) * 0.14); + ctx.stroke(); + } + // A wet rim under it. + ctx.globalAlpha = 0.4; + ctx.fillStyle = WATER_SHEEN; + ellipse(ctx, x, y + 0.05, m.w * 0.6, 0.3); + ctx.fill(); + ctx.globalAlpha = 1; + eye(v, x - m.w * 0.14, y - m.h * 0.55, 0.14, EYE_PALE); + eye(v, x + m.w * 0.18, y - m.h * 0.5, 0.14, EYE_PALE); + } + + // The will-o'-wisp: `bright` a flame-licked orb of cold light, pulsing, + // shedding a spark or two; `dim` a grey ember sinking; `rekindle` a glow + // gathering where it will burn again, brighter the nearer it is. + function wisp(ctx, v, m, x, y, t, flash) { + const cy = y - m.h / 2; + if (m.act === "dim") { + ctx.fillStyle = WISP_DIM; + ctx.globalAlpha = 0.7; + circle(ctx, x, cy, 0.35); + ctx.fill(); + ctx.globalAlpha = 0.25; + circle(ctx, x, cy, 0.8); + ctx.fill(); + ctx.globalAlpha = 1; + return; + } + if (m.act === "rekindle") { + const p = m.wait > 0 ? clamp(1 - m.wait / WISP_REKINDLE_MS, 0, 1) : 1; + halo(ctx, x, cy, 1.4 + p * 1.2, WISP, 0.3 + p * 0.4); + ctx.fillStyle = WISP; + ctx.globalAlpha = 0.4 + p * 0.55; + circle(ctx, x, cy, 0.3 + p * 0.5); + ctx.fill(); + ctx.globalAlpha = 1; + return; + } + const pulse = 0.85 + Math.sin(t / 210 + m.id) * 0.15; + halo(ctx, x, cy, 2.8 * pulse, WISP, 0.55); + // The flame: a teardrop of near-white in the green. + ctx.fillStyle = flash ? FLASH : WISP; + ctx.beginPath(); + ctx.moveTo(x, cy - m.h * 0.72 * pulse); + ctx.quadraticCurveTo(x + m.w * 0.5, cy - m.h * 0.2, x + m.w * 0.4, cy + m.h * 0.3); + ctx.quadraticCurveTo(x, cy + m.h * 0.62, x - m.w * 0.4, cy + m.h * 0.3); + ctx.quadraticCurveTo(x - m.w * 0.5, cy - m.h * 0.2, x, cy - m.h * 0.72 * pulse); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = WISP_HOT; + ctx.beginPath(); + ctx.moveTo(x, cy - m.h * 0.4 * pulse); + ctx.quadraticCurveTo(x + m.w * 0.22, cy - m.h * 0.05, x, cy + m.h * 0.3); + ctx.quadraticCurveTo(x - m.w * 0.22, cy - m.h * 0.05, x, cy - m.h * 0.4 * pulse); + ctx.closePath(); + ctx.fill(); + // A spark drifting off, now and then. + const sp = (t / 900 + m.id * 0.37) % 1; + if (sp < 0.4) { + ctx.globalAlpha = 0.5 * (1 - sp / 0.4); + ctx.fillStyle = WISP; + ctx.fillRect(x + 0.7 + sp * 2, cy - 0.5 - sp * 3, 0.22, 0.22); + ctx.globalAlpha = 1; + } + } + + // The bog body: a zombie in every way but the muck: while `rise` it is + // climbing out of a wet hole, mud sheeting off; while `walk` it shambles, + // weeds in its shoulders, drips falling off its arms; `lurching` leans it + // further. + function bogbody(ctx, v, m, x, y, t, flash) { + const C = (c) => (flash ? FLASH : c); + const d = m.dir || 1; + const up = m.act === "rise" ? (m.rise > 0 ? clamp(1 - m.rise / BOG_RISE_MS, 0, 1) : 0.4) : 1; + ctx.save(); + ctx.translate(x, y); + ctx.scale(d, 1); + // The hole it came from, while rising. + if (m.act === "rise") { + ctx.fillStyle = MUD_DARK; + ellipse(ctx, 0, 0.1, 2.4, 0.5); + ctx.fill(); + ctx.fillStyle = MUD; + ctx.globalAlpha = 0.6; + ellipse(ctx, 0, 0, 2, 0.35); + ctx.fill(); + ctx.globalAlpha = 1; + } + ctx.translate(0, -up * m.h * 0.04); + const step = m.act === "walk" ? Math.sin(t / 170) : 0; + const lean = m.lurching ? 0.16 : 0.08; + ctx.translate(0, (1 - up) * m.h * 0.8); + ctx.scale(1, up); + ctx.save(); + ctx.rotate(lean * d); + // Legs, caked to the knee. + ctx.strokeStyle = C(BOGSKIN_DARK); + ctx.lineWidth = 0.55; + line(ctx, -0.5, -m.h * 0.42, -0.5 - step * 0.6, -0.1); + line(ctx, 0.5, -m.h * 0.42, 0.5 + step * 0.6, -0.1); + // The trunk: hunched, mud plates cracked open over gray skin. + ctx.fillStyle = C(BOGSKIN); + ctx.beginPath(); + ctx.moveTo(-1.15, -m.h * 0.45); + ctx.quadraticCurveTo(-1.3, -m.h * 0.86, -0.5, -m.h * 0.94); + ctx.lineTo(0.7, -m.h * 0.94); + ctx.quadraticCurveTo(1.3, -m.h * 0.8, 1.15, -m.h * 0.45); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = C(BOGSKIN_LIT); + for (const [px, py, s] of [[-0.6, -m.h * 0.62, 0.5], [0.3, -m.h * 0.55, 0.42], [0.75, -m.h * 0.78, 0.4], [-0.2, -m.h * 0.8, 0.36]]) { + ellipse(ctx, px, py, s, s * 0.6, 0.4); + ctx.fill(); + } + // Arms, hanging and dripping, the front one reaching a little. + ctx.strokeStyle = C(BOGSKIN); + ctx.lineWidth = 0.5; + const reach = m.lurching ? 0.9 : 0.4; + line(ctx, 0.9, -m.h * 0.8, 1.15 + reach, -m.h * 0.34 - reach * 0.4); + line(ctx, -0.9, -m.h * 0.8, -1.05, -m.h * 0.32); + // The head: low, sunk between the shoulders, weeds over it. + ctx.fillStyle = C(BOGSKIN_DARK); + ellipse(ctx, 0.3, -m.h * 0.97, 0.72, 0.62); + ctx.fill(); + ctx.strokeStyle = MOSS_LIT; + ctx.lineWidth = 0.18; + for (const [lx, ly, bend] of [[-0.1, -m.h * 1.22, -0.4], [0.4, -m.h * 1.28, 0.2], [0.75, -m.h * 1.18, 0.6], [-0.55, -m.h * 1.12, -0.7]]) { + ctx.beginPath(); + ctx.moveTo(lx, -m.h * 0.98); + ctx.quadraticCurveTo(lx + bend * 0.4, -m.h * 1.05, lx + bend, ly); + ctx.stroke(); + } + // Drips off the reaching arm. + ctx.fillStyle = MUD_LIT; + ctx.globalAlpha = 0.7; + const drip = (t / 700 + m.id * 0.3) % 1; + if (drip < 0.5) ctx.fillRect(1.15 + reach - 0.1, -m.h * 0.34 + drip * 2.6, 0.18, 0.3); + ctx.globalAlpha = 1; + ctx.restore(); + eye(v, x + d * 0.12, y - m.h * 0.97 * up - (1 - up) * 0.5, 0.2, EYE_PALE); + eye(v, x + d * 0.52, y - m.h * 0.95 * up - (1 - up) * 0.5, 0.2, EYE_PALE); + ctx.restore(); + } + + /* ---------------------------------------------------- Old Mother Bog */ + + // Her cauldron at (cx, feet): a potted belly of black iron on three feet + // over a small fire. `lit` is the weak window: the lid off and the green + // glow out of it, readable at a glance. + function cauldron(ctx, v, cx, fy, lit, t, flash) { + // The fire under it, always low; brighter while it is open. + ctx.fillStyle = "#c86a2e"; + ctx.globalAlpha = lit ? 0.85 : 0.4; + for (let k = 0; k < 3; k++) { + const fl = Math.abs(Math.sin(t / 90 + k * 2)); + ctx.beginPath(); + ctx.moveTo(cx - 0.8 + k * 0.8, fy); + ctx.quadraticCurveTo(cx - 0.7 + k * 0.8, fy - 0.9 - fl * 0.7, cx - 0.5 + k * 0.8, fy - 1.1 - fl * 0.9); + ctx.quadraticCurveTo(cx - 0.3 + k * 0.8, fy - 0.8, cx - 0.2 + k * 0.8, fy); + ctx.closePath(); + ctx.fill(); + } + ctx.globalAlpha = 1; + ctx.fillStyle = flash ? FLASH : CAULDRON; + ellipse(ctx, cx, fy - 1.7, 1.7, 1.35); + ctx.fill(); + ctx.fillRect(cx - 1.6, fy - 1.9, 3.2, 0.5); + for (const s of [-1, 0, 1]) { + ctx.fillRect(cx + s * 1.1 - 0.18, fy - 0.8, 0.36, 0.8); + } + // The rim. + ctx.fillStyle = flash ? FLASH : "#3a382a"; + ellipse(ctx, cx, fy - 3, 1.5, 0.5); + ctx.fill(); + if (lit) { + // Open: a green stew glowing up out of it, a lick of vapor. + ctx.fillStyle = CAULDRON_LIT; + ellipse(ctx, cx, fy - 3, 1.2, 0.36); + ctx.fill(); + halo(ctx, cx, fy - 3.3, 2.4, CAULDRON_LIT, 0.7); + ctx.globalAlpha = 0.5; + ctx.fillStyle = CAULDRON_LIT; + for (let k = 0; k < 3; k++) { + const p = (t / 700 + k / 3) % 1; + circle(ctx, cx - 0.5 + k * 0.5 + Math.sin(p * 6 + k) * 0.3, fy - 3.4 - p * 2, 0.2 * (1 - p) + 0.06); + ctx.fill(); + } + ctx.globalAlpha = 1; + // The lid, off and leaning on its side. + ctx.fillStyle = flash ? FLASH : "#3a382a"; + ctx.save(); + ctx.translate(cx + 2, fy - 0.8); + rotate(ctx, 1.2); + ellipse(ctx, 0, 0, 1.2, 0.4); + ctx.fill(); + ctx.restore(); + } else { + // Lidded: a gray lid with its ring handle. + ctx.fillStyle = flash ? FLASH : "#2c2a20"; + ellipse(ctx, cx, fy - 3.1, 1.35, 0.45); + ctx.fill(); + ctx.strokeStyle = "#4a4836"; + ctx.lineWidth = 0.15; + ellipse(ctx, cx, fy - 3.5, 0.35, 0.2); + ctx.stroke(); + } + } + + // Old Mother Bog herself, feet at (b.x, y): a stooping hag of mud and + // reed, her cauldron beside her. `idle` she hunches over it, drifting; + // `wind` she throws both arms wide to pull the mud wave up; `rest` she + // sags, the cauldron cracking open late in it; `throwWind` she leans in + // to spit; `sink` she is going down in a swirl, `under` only her bubbles + // remain, `resurface` she is coming up wet. + function motherbog(ctx, v, b) { + const { g } = v; + const t = v.clock; + const flash = b.hurt > 0; + const d = b.dir || 1; + // Under the water there is no hag to draw: `sink` shows the swirl where + // she went down, `under` the bubbles over the spot she will rise. + if (b.act === "under") { + const bx = b.sinkX ?? b.x; + const fy = g.FIELD_H - (b.home ?? b.y); + ctx.strokeStyle = WATER_SHEEN; + ctx.lineWidth = 0.2; + ctx.globalAlpha = 0.6; + ellipse(ctx, bx, fy + 0.1, 3.4, 0.7); + ctx.stroke(); + ctx.globalAlpha = 1; + ctx.fillStyle = "#d8f0e0"; + for (let k = 0; k < 8; k++) { + const p = (t / 560 + k / 8) % 1; + ctx.globalAlpha = 0.9 * (1 - p * 0.7); + circle(ctx, bx - 2 + ((k * 53) % 40) / 10 + Math.sin(p * 7 + k) * 0.5, fy - p * 3, 0.42 * (1 - p * 0.4)); + ctx.fill(); + } + ctx.globalAlpha = 1; + return; + } + if (b.act === "sink") { + const fy = g.FIELD_H - (b.home ?? b.y); + ctx.strokeStyle = WATER_SHEEN; + ctx.lineWidth = 0.22; + ctx.globalAlpha = 0.8; + ellipse(ctx, b.x, fy + 0.1, b.w * 0.6, 0.9); + ctx.stroke(); + ellipse(ctx, b.x, fy + 0.1, b.w * 0.38, 0.55); + ctx.stroke(); + ctx.globalAlpha = 1; + // The last of her hat going under. + const p = b.wait > 0 && Number.isFinite(b.wait) ? clamp(1 - b.wait / MOTHER_SINK_MS, 0, 1) : 1; + ctx.fillStyle = flash ? FLASH : HAG_DARK; + ctx.globalAlpha = 1 - p; + ctx.beginPath(); + ctx.moveTo(b.x - 1.6, fy + 0.4); + ctx.lineTo(b.x, fy - 2.6 * (1 - p)); + ctx.lineTo(b.x + 1.6, fy + 0.4); + ctx.closePath(); + ctx.fill(); + ctx.globalAlpha = 1; + return; + } + const x = b.x; + const y = g.FIELD_H - b.y; + const C = (c) => (flash ? FLASH : c); + const resurface = b.act === "resurface" && Number.isFinite(b.wait) ? clamp(b.wait / RESURFACE_MS, 0, 1) : 0; + const wind = b.act === "wind" && Number.isFinite(b.wait) ? clamp(1 - b.wait / MOTHER_WIND_MS, 0, 1) : 0; + const throwP = b.act === "throwWind" && Number.isFinite(b.wait) ? clamp(1 - b.wait / SPIT_WIND_MS, 0, 1) : 0; + const breathe = Math.sin(t / 800); + ctx.save(); + ctx.translate(x, y); + ctx.scale(d, 1); + ctx.translate(0, resurface * b.h * 0.8); + ctx.scale(1, 1 - resurface * 0.9); + // Rising: a ring and water sheeting off her. + if (resurface > 0) { + ctx.strokeStyle = WATER_SHEEN; + ctx.lineWidth = 0.2; + ellipse(ctx, 0, 0.2, b.w * 0.62, 0.8); + ctx.stroke(); + } + // The cauldron on her far side, close enough to tend. + cauldron(ctx, v, b.w * 0.5 + 1.6, 0, b.lit, t, flash); + ctx.save(); + ctx.rotate((b.act === "rest" ? 0.05 : 0.02) * Math.sin(t / 900)); + // The hag's cloak of mud and reed, a humped stoop. + const hunch = b.act === "rest" ? 0.12 : 0; + ctx.fillStyle = C(HAG); + ctx.beginPath(); + ctx.moveTo(-b.w * 0.42, 0); + ctx.quadraticCurveTo(-b.w * 0.5, -b.h * 0.4, -b.w * 0.3, -b.h * (0.62 - hunch)); + ctx.quadraticCurveTo(-b.w * 0.16, -b.h * (0.8 - hunch), 0, -b.h * (0.82 - hunch)); + ctx.quadraticCurveTo(b.w * 0.3, -b.h * (0.8 - hunch), b.w * 0.42, -b.h * 0.42); + ctx.quadraticCurveTo(b.w * 0.5, -b.h * 0.2, b.w * 0.44, 0); + ctx.closePath(); + ctx.fill(); + // Mud plates and reed fringes over the cloak. + ctx.fillStyle = C(HAG_LIT); + for (const [px, py, s] of [[-1.6, -2.2, 0.7], [0.4, -3.4, 0.8], [1.8, -1.8, 0.6], [-0.6, -1.4, 0.5]]) { + ellipse(ctx, px, py, s, s * 0.55, 0.5); + ctx.fill(); + } + ctx.strokeStyle = C(HAG_DARK); + ctx.lineWidth = 0.2; + for (let k = 0; k < 7; k++) { + const fx = -b.w * 0.4 + k * (b.w * 0.8) / 6; + const l = 1 + (hash(k * 13, 5) % 3) * 0.5; + line(ctx, fx, -0.4 - (k % 2) * 0.5, fx + (hash(k, 3) % 3 - 1) * 0.4, -0.4 - (k % 2) * 0.5 + l); + } + // Her arms: thrown wide for the wind, raised over the cauldron for the + // spit, hanging long otherwise. + ctx.strokeStyle = C(HAG_DARK); + ctx.lineWidth = 0.7; + if (b.act === "wind") { + const spread = wind * 1.9; + line(ctx, -0.5, -b.h * 0.62, -1.4 - spread, -b.h * 0.62 - spread * 0.8); + line(ctx, 0.5, -b.h * 0.62, 1.4 + spread, -b.h * 0.62 - spread * 0.8); + // Mud gathered over her head, growing as she pulls. + ctx.fillStyle = MUD_LIT; + circle(ctx, 0, -b.h * 0.62 - spread * 1.6 - 0.8, 0.6 + wind * 1); + ctx.fill(); + ctx.fillStyle = MUD; + circle(ctx, 0, -b.h * 0.62 - spread * 1.6 - 0.8, 0.42 + wind * 0.75); + ctx.fill(); + ctx.fillStyle = "#8a7448"; + ctx.globalAlpha = 0.8; + circle(ctx, -0.25, -b.h * 0.62 - spread * 1.6 - 1.15, 0.2 + wind * 0.25); + ctx.fill(); + ctx.globalAlpha = 1; + } else if (b.act === "throwWind") { + line(ctx, -0.5, -b.h * 0.62, -1.2, -b.h * 0.5); + line(ctx, 0.5, -b.h * 0.62, 1.2 + throwP * 1.2, -b.h * 0.68 - throwP * 1.4); + // The drip of coming spit at her lip. + ctx.fillStyle = CAULDRON_LIT; + ctx.globalAlpha = 0.7; + circle(ctx, 1.9 + throwP * 0.6, -b.h * 0.72 - throwP * 1.6, 0.22 + throwP * 0.2); + ctx.fill(); + ctx.globalAlpha = 1; + } else { + line(ctx, -0.5, -b.h * 0.62, -1.1, -b.h * 0.3 - breathe * 0.2); + line(ctx, 0.5, -b.h * 0.62, 1.15, -b.h * 0.3 + breathe * 0.2); + } + // Her head: a long chin, one good eye, a wisp of hair, her pointed hat + // gone soft with wet. + const headY = -b.h * (0.86 - hunch); + ctx.fillStyle = C("#6a5836"); + ellipse(ctx, 0.3, headY, 0.85, 0.8); + ctx.fill(); + ctx.fillStyle = C(HAG_DARK); + ctx.beginPath(); + ctx.moveTo(-0.9, headY - 0.3); + ctx.quadraticCurveTo(0, headY - 1.9, 1.15, headY - 1.15); + ctx.quadraticCurveTo(1.5, headY - 0.9, 1.1, headY - 0.4); + ctx.lineTo(1.35, headY - 0.3); + ctx.quadraticCurveTo(0.4, headY - 1.05, -0.9, headY - 0.3); + ctx.closePath(); + ctx.fill(); + // The chin and a wart. + ctx.fillStyle = C("#6a5836"); + ctx.beginPath(); + ctx.moveTo(0.7, headY + 0.2); + ctx.quadraticCurveTo(1.5, headY + 0.7, 1.05, headY + 1.15); + ctx.lineTo(0.5, headY + 0.7); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = C(HAG_LIT); + circle(ctx, 1.28, headY + 0.75, 0.12); + ctx.fill(); + ctx.restore(); + // The one good eye, greener while the cauldron is open. + eye(v, x + d * 0.42, y + headY - 0.1, 0.22, b.lit ? CAULDRON_LIT : EYE_AMBER); + ctx.restore(); + } + + /* ------------------------------------------------- hazards and waves */ + + // A muck patch from her cauldron: in the air it is a glob arcing from + // (sx, sy) to where it lands, a ring closing on the spot; then a steaming + // mound of burning muck for MUCK_MS, glowing at its cracks. + function muck(ctx, v, h) { + const { g } = v; + const fy = g.FIELD_H - h.y; + if (h.warn > 0) { + const p = 1 - h.warn / MUCK_LAND_MS; + const bx = h.sx + (h.x - h.sx) * p; + const by = g.FIELD_H - (h.sy + (h.y - h.sy) * p + Math.sin(p * Math.PI) * 10); + ctx.strokeStyle = "rgba(122, 200, 106, 0.7)"; + ctx.lineWidth = 0.3; + ellipse(ctx, h.x, fy - 0.1, (h.w / 2) * (1.3 - p * 0.3), 0.55); + ctx.stroke(); + ctx.fillStyle = "rgba(90, 150, 80, 0.18)"; + ellipse(ctx, h.x, fy - 0.1, (h.w / 2) * (1.3 - p * 0.3), 0.55); + ctx.fill(); + // The glob, wet and heavy. + ctx.fillStyle = MUD; + circle(ctx, bx, by, 0.8); + ctx.fill(); + ctx.fillStyle = MUD_LIT; + circle(ctx, bx - 0.25, by - 0.3, 0.32); + ctx.fill(); + ctx.globalAlpha = 0.5; + circle(ctx, bx - Math.sign(h.x - h.sx || 1) * 1.2, by + 0.6, 0.3); + ctx.fill(); + ctx.globalAlpha = 1; + return; + } + const fade = Math.min(1, h.live / 600); + ctx.globalAlpha = fade; + // The mound: dark muck with green-lit cracks, steaming. + ctx.fillStyle = "#241c0e"; + ctx.beginPath(); + ctx.moveTo(h.x - h.w / 2 - 0.3, fy); + ctx.quadraticCurveTo(h.x - h.w * 0.3, fy - h.h * 0.9, h.x, fy - h.h * 0.95); + ctx.quadraticCurveTo(h.x + h.w * 0.3, fy - h.h * 0.9, h.x + h.w / 2 + 0.3, fy); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = MUD; + ctx.globalAlpha = fade * 0.6; + ctx.beginPath(); + ctx.moveTo(h.x - h.w / 2, fy); + ctx.quadraticCurveTo(h.x - h.w * 0.26, fy - h.h * 0.7, h.x, fy - h.h * 0.75); + ctx.quadraticCurveTo(h.x + h.w * 0.26, fy - h.h * 0.7, h.x + h.w / 2, fy); + ctx.closePath(); + ctx.fill(); + ctx.strokeStyle = CAULDRON_LIT; + ctx.lineWidth = 0.22; + ctx.globalAlpha = fade * 0.9; + for (const [k, bend] of [[0, -0.4], [1, 0.3], [2, -0.2]]) { + ctx.beginPath(); + ctx.moveTo(h.x - h.w * 0.28 + k * h.w * 0.28, fy - 0.2); + ctx.quadraticCurveTo(h.x - h.w * 0.2 + k * h.w * 0.28 + bend, fy - h.h * 0.5, h.x - h.w * 0.1 + k * h.w * 0.28, fy - h.h * 0.8); + ctx.stroke(); + } + ctx.globalAlpha = fade; + // Steam. + ctx.fillStyle = "#8aa88e"; + for (let k = 0; k < 4; k++) { + const p = (v.clock / 1500 + k / 4) % 1; + ctx.globalAlpha = fade * 0.14 * (1 - p); + ellipse(ctx, h.x - h.w * 0.3 + k * h.w * 0.2 + Math.sin(p * 5 + k) * 0.6, fy - h.h - p * 3.5, 1 + p * 0.8, 0.8 + p * 0.5); + ctx.fill(); + } + ctx.globalAlpha = 1; + } + + // The mud wave: a low ridge of muck rolling along the planks, crested + // and dripping, a wet wake behind it. `y` is the floor on screen. + function mudwave(ctx, v, w, y) { + ctx.fillStyle = MUD_DARK; + ellipse(ctx, w.x - w.dir * 2.6, y - 0.1, 2.6, 0.4); + ctx.fill(); + ctx.fillStyle = MUD; + ctx.beginPath(); + ctx.moveTo(w.x - w.dir * 2.4, y); + ctx.quadraticCurveTo(w.x - w.dir * 1.2, y - 3.1, w.x + w.dir * 0.4, y - 2.6); + ctx.quadraticCurveTo(w.x + w.dir * 1.3, y - 1.9, w.x + w.dir * 1.1, y); + ctx.closePath(); + ctx.fill(); + // The curl of its lip, facing the way it rolls. + ctx.fillStyle = MUD_LIT; + ctx.beginPath(); + ctx.moveTo(w.x + w.dir * 0.4, y - 2.6); + ctx.quadraticCurveTo(w.x + w.dir * 1.5, y - 2.9, w.x + w.dir * 1.6, y - 1.7); + ctx.quadraticCurveTo(w.x + w.dir * 1.1, y - 1.9, w.x + w.dir * 0.9, y - 1.4); + ctx.closePath(); + ctx.fill(); + // Dripping clods off the top. + ctx.fillStyle = MUD; + for (let k = 0; k < 4; k++) { + const p = (v.clock / 300 + k / 4) % 1; + ctx.globalAlpha = 0.8 * (1 - p); + circle(ctx, w.x - w.dir * (0.6 + k * 0.5) + Math.sin(k * 3) * 0.3, y - 2.4 - p * 1.2, 0.22 - p * 0.1); + ctx.fill(); + } + ctx.globalAlpha = 1; + } + + /* --------------------------------------------------------- the badges */ + + // The Stilt Boots' badge (inside the ring every power-up shares): two + // tall boots on their stilts, in the ink already set. + function boots(ctx, x, y) { + ctx.lineWidth = 0.26; + for (const s of [-1, 1]) { + // The boot, then the pole of its stilt under it. + line(ctx, x + s * 0.55 - 0.28, y - 0.9, x + s * 0.55 - 0.28, y - 0.25); + line(ctx, x + s * 0.55 - 0.28, y - 0.25, x + s * 0.55 + 0.38, y - 0.25); + line(ctx, x + s * 0.55 + 0.38, y - 0.25, x + s * 0.55 + 0.38, y - 0.45); + line(ctx, x + s * 0.55 + 0.05, y - 0.25, x + s * 0.55 + 0.05, y + 0.95); + line(ctx, x + s * 0.55 - 0.12, y + 0.95, x + s * 0.55 + 0.22, y + 0.95); + } + } + + // The Harpoon's badge: a barbed spear with its line coiled off the butt. + function harpoon(ctx, x, y) { + ctx.lineWidth = 0.24; + line(ctx, x - 0.9, y + 0.9, x + 0.7, y - 0.7); + // The barbed head. + line(ctx, x + 0.7, y - 0.7, x + 1.05, y - 1.05); + line(ctx, x + 0.7, y - 0.7, x + 0.42, y - 0.42); + line(ctx, x + 0.62, y - 0.78, x + 0.9, y - 0.5); + ctx.lineWidth = 0.14; + ctx.beginPath(); + ctx.arc(x - 0.75, y + 0.95, 0.3, 0, TAU); + ctx.stroke(); + } + + /* -------------------------------------------------------------- light */ + + // What lights the dark here: the wisp's cold glow (a great lamp while + // bright, a coal while dim, a gathering while it rekindles), the open + // cauldron's green fire, a muck patch's smoulder. + function lights(v, add) { + for (const m of v.round.monsters) { + if (m.kind !== "wisp") continue; + if (m.act === "bright") add(m.x, m.y + m.h / 2, 6, 0.7); + else if (m.act === "rekindle") add(m.x, m.y + m.h / 2, 3, 0.4); + else if (m.act === "dim") add(m.x, m.y + m.h / 2, 1.2, 0.15); + } + for (const h of v.round.hazards) if (h.kind === "muck" && h.live > 0) add(h.x, h.y + 1, 4, 0.35 * Math.min(1, h.live / 600)); + const b = v.round.boss; + if (b && b.kind === "motherbog" && b.state !== "down" && !b.hidden) { + add(b.x + (b.dir || 1) * (b.w * 0.5 + 1.6), b.y + 3, b.lit ? 8 : 3.5, b.lit ? 0.85 : 0.4); + if (!b.hidden && b.act !== "under") add(b.x + (b.dir || 1) * 0.4, b.y + b.h * 0.86, 4, 0.2); + } + } + + /* ------------------------------------------------------------- events */ + + // What the bog's events look and sound like, beside ghoul-draw.js's own: + // true when `e` was one of them. `k` is the same kit react() is handed. + function react(e, k) { + const { tone, burst, float, ring, glow, shake, fx } = k; + if (e.type === "lurkerSnap") { + say(tone, e.kind, "snap", 0.5); + burst(e.x, e.y, WATER_SHEEN, 8, 8, 350); + shake(140, 0.35); + } else if (e.type === "lurkerSink") { + if (gate(fx, "lurkMs", 300)) say(tone, e.kind, "sink", 0.35); + ring(e.x, e.y, WATER_SHEEN, 0.8, 3, 500); + } else if (e.type === "leechLatch") { + say(tone, e.kind, "latch", 0.45); + float(e.x, e.y + 3, "Latched!", DANGER, 2.2); + } else if (e.type === "leechDie") { + // The kill event already cried its `die`; this is the swarm coming + // apart, visual only. + burst(e.x, e.y, LEECH_LIT, 12, 9, 400); + } else if (e.type === "bogRise") { + say(tone, e.kind, "rise", 0.4); + burst(e.x, e.y + 0.4, MUD_LIT, 9, 8, 380); + } else if (e.type === "wispOut") { + say(tone, e.kind, "out", 0.4); + burst(e.x, e.y, WISP, 8, 7, 300); + } else if (e.type === "wispRelight") { + say(tone, e.kind, "relight", 0.35); + glow(e.x, e.y, 4, 0.5, 400); + } else if (e.type === "wispOn") { + say(tone, e.kind, "on", 0.4); + glow(e.x, e.y, 6, 0.65, 450); + } else if (e.type === "wispLure") { + float(e.x, e.y + 4, "Drawn!", GOLD, 2); + glow(e.x, e.y, 4, 0.4, 350); + } else if (e.type === "motherWind") { + say(tone, e.kind, "wind", 0.5); + float(e.x, e.y + 5, "Mud wave!", DANGER, 2.4); + } else if (e.type === "mudWave") { + say(tone, e.kind, "wave", 0.55); + shake(180, 0.45); + } else if (e.type === "spitWind") { + say(tone, e.kind, "spitWind", 0.4); + glow(e.x, e.y, 5, 0.5, 400); + } else if (e.type === "cauldronSpit") { + say(tone, e.kind, "spit", 0.5); + if (e.tx !== undefined) ring(e.tx, e.ty, CAULDRON_LIT, 1, 5, 700); + if (e.tx2 !== undefined) ring(e.tx2, e.ty2, CAULDRON_LIT, 1, 5, 700); + } else if (e.type === "cauldronOpen") { + if (gate(fx, "openMs", 400)) say(tone, e.kind, "open", 0.4); + glow(e.x, e.y, 7, 0.7, 400); + float(e.x, e.y + 4, "Now!", GOLD, 2.2); + } else if (e.type === "muckLand") { + if (gate(fx, "muckMs", 200)) say(tone, "motherbog", "muck", 0.5); + burst(e.x, e.y + 0.5, MUD_LIT, 12, 10, 450); + glow(e.x, e.y + 1, 6, 0.5, 400); + shake(140, 0.4); + } else if (e.type === "motherSink") { + say(tone, e.kind, "sink", 0.5); + shake(220, 0.5); + } else if (e.type === "motherBubble") { + say(tone, e.kind, "bubble", 0.4); + ring(e.x, e.y, WATER_SHEEN, 1, 4.5, 650); + } else if (e.type === "motherRise") { + say(tone, e.kind, "rise", 0.55); + burst(e.x, e.y + 1, WATER_SHEEN, 14, 12, 500); + shake(200, 0.55); + } else return false; + return true; + } + + return freeze({ + looks: LOOKS, + backdrop, + ground, + shelf, + decor: freeze({}), + monsters: freeze({ lurker, leech, wisp, bogbody }), + bosses: freeze({ motherbog }), + missiles: freeze({}), + hazards: freeze({ muck }), + waves: freeze({ mudwave }), + powers: freeze({ boots, harpoon }), + lights, + react, + }); +} diff --git a/src/web-console/public/activities/ghoul-bog.js b/src/web-console/public/activities/ghoul-bog.js new file mode 100644 index 0000000..c061ea5 --- /dev/null +++ b/src/web-console/public/activities/ghoul-bog.js @@ -0,0 +1,496 @@ +// Plan2Code Web Console - Ghoul Rush's Gallows Bog stage, its rules: the monsters that haunt it (a lurker's eyes in the water, a drifting leech swarm, a will-o'-wisp whose light lures the rest toward you, and a bog body risen from the muck) and its boss, Old Mother Bog, as a stage pack that ghoul.js plugs in. +// +// No imports: ghoul.js hands every rule here a kit `k` of its own helpers +// (walk, throwBone, spawnMonster, groundAt, struck, hurt and the numbers they +// need), so this file never reaches back into it. A pack is plain data and +// functions: +// +// - `monsters`: each kind's numbers, as in ghoul.js's MONSTERS (`perch`: its +// spawn names the height it waits at; `flies`: a horde one comes in high). +// - `walkers`, `zombies`: kinds that join ghoul.js's sets of the same names +// (a bog body is a zombie in every way but how it rises). +// - `act`: what a kind starts out doing; `solid`: whether one can hurt and be +// hit just now; `swoops`: whether a kind is diving low enough to duck +// under; `unseen`: kinds out of sight just now, so shots go through and a +// touch does nothing; `harmless`: kinds that never hurt by touch (the leech +// latches instead); `move`: one slice of a kind's moving; `kill`: what a +// death leaves; `horde`: what a kind comes in from the edge with. +// - `tick`: the stage's own twist, run each slice (the wisp's lure). +// - `shot`: what a bolt that hit a monster does besides its damage (a bright +// wisp is shot out, never hit); `target`: what else a bolt can strike (a +// harpoon finds a lurker's eyes under the water). +// - `bosses`, `boss` (one slice of a boss's fight), `guard` (true while +// shots and stomps glance off), `weak` (the damage multiplier of a shot +// that has just hit), `cause` (what its touch is called) and `hazards` (by +// kind, one slice of something it left on the field). +// +// A lurker is two eyes at the waterline until you cross it: then it snaps +// out of the water, solid and lunging, and sinks back. A leech swarm drifts +// through the wet spans toward you and latches on contact, one heart and it +// drops off. A wisp is a drifting light: near it the dead pull toward you a +// step quicker (the lure), until a bolt puts it out and it rekindles +// somewhere else. A bog body rises out of the mud and walks. +// +// Old Mother Bog drifts along her planks keeping her distance, winds up and +// sends a low wave of mud down the boards to jump, or spits from her +// cauldron to where you stand, leaving a muck patch that burns. The +// cauldron opens late in her rests: a shot into her then counts triple. At +// half her hp she goes under, bubbles show where she comes back up, and she +// fights on with shorter waits and a second patch aimed ahead of your feet. + +const freeze = (o) => Object.freeze(o); + +export const MONSTERS = freeze({ + lurker: freeze({ name: "Lurker", w: 3.4, h: 2.6, hp: 3, speed: 16, points: 150, stomp: true, head: false, color: "#2a3a18" }), + leech: freeze({ name: "Leech Swarm", w: 3, h: 1.8, hp: 2, speed: 9, points: 90, stomp: true, head: false, color: "#3d2a24" }), + wisp: freeze({ name: "Will-o'-Wisp", w: 1.6, h: 1.6, hp: 1, speed: 12, points: 70, stomp: false, head: false, perch: true, flies: true, color: "#9adfc0" }), + bogbody: freeze({ name: "Bog Body", w: 3, h: 5, hp: 4, speed: 7, lurch: 14, points: 120, stomp: true, head: true, color: "#4a3a22" }), +}); + +export const BOSSES = freeze({ + motherbog: freeze({ name: "Old Mother Bog", sub: "Keep to the planks, she owns the water", w: 7, h: 10, hp: 95, points: 3000, color: "#5a4a2a" }), +}); + +// A lurker's eyes snap when you are within SNAP_RANGE across (and SNAP_HIGH +// up or down): it lunges at SNAP_V for SNAP_MS, then sinks for LURKER_SINK_MS +// back to eyes. +export const SNAP_RANGE = 9; +export const SNAP_HIGH = 5; +export const SNAP_V = 34; +export const SNAP_MS = 900; +export const LURKER_SINK_MS = 500; +// A latched leech swarm costs one heart, then it drops off for +// LEECH_DROP_MS and cannot latch again for LEECH_AGAIN_MS. +export const LEECH_DROP_MS = 350; +export const LEECH_AGAIN_MS = 1400; +// A bog body takes BOG_RISE_MS to climb out of the mud (one out of the +// horde's edge, or out of a door, is already up), then lurches like a zombie +// inside LURCH_RANGE. +export const BOG_RISE_MS = 600; +const LURCH_RANGE = 20; +// A wisp put out stays dim for WISP_RELIGHT_MS, then glows at its seeded +// spot for WISP_REKINDLE_MS before it burns bright again. While it is +// bright, every monster within WISP_LURE of it is pulled toward you and +// runs at WISP_HASTE times its speed. +export const WISP_RELIGHT_MS = 6000; +export const WISP_REKINDLE_MS = 600; +export const WISP_LURE = 10; +export const WISP_HASTE = 1.2; +const LURE_HOLD_MS = 120; +// Old Mother Bog keeps MOTHER_KEEP of plank between you, drifting at +// MOTHER_WALK. Between moves she idles MOTHER_IDLE_MS; the mud wave winds up +// MOTHER_WIND_MS and rests MOTHER_REST_MS after, its cauldron open for the +// last MOTHER_OPEN_MS; the spit winds up SPIT_WIND_MS and lands MUCK_LAND_MS +// later, a patch MUCK_W wide and MUCK_H high burning for MUCK_MS. At +// MOTHER_RAGE of her hp she sinks for MOTHER_SINK_MS, bubbles for +// BUBBLE_MS where she will surface, and rises over RESURFACE_MS near you +// (RESURFACE_NEAR or further); after it her waits are MOTHER_QUICK times as +// long and the spit also lands a patch MUCK_LEAD ahead of where you run. +export const MOTHER_KEEP = 14; +export const MOTHER_WALK = 6; +export const MOTHER_IDLE_MS = 1400; +export const MOTHER_WIND_MS = 600; +export const MOTHER_REST_MS = 1500; +export const MOTHER_OPEN_MS = 540; +export const SPIT_WIND_MS = 550; +export const MUCK_LAND_MS = 750; +export const MUCK_MS = 3000; +export const MUCK_W = 5; +export const MUCK_H = 3; +export const MUCK_LEAD = 11; +export const MOTHER_RAGE = 0.5; +export const MOTHER_QUICK = 0.7; +export const MOTHER_SINK_MS = 600; +export const BUBBLE_MS = 700; +export const RESURFACE_MS = 450; +const RESURFACE_NEAR = 14; + +const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v)); + +/* ------------------------------------------------------------ monsters */ + +// Two eyes at the waterline: unseen till you cross it, then a snap out of +// the water, solid and lunging, and a sink back to eyes. +function moveLurker(round, m, ms, k) { + const you = round.you; + const dt = ms / 1000; + if (m.act === "snap") { + m.wait = Math.max(0, m.wait - ms); + k.walk(round, m, k.towardYou(round, m), SNAP_V * round.spec.pace, dt); + if (m.wait) return; + m.act = "sink"; + m.wait = LURKER_SINK_MS; + round.events.push({ type: "lurkerSink", kind: m.kind, x: m.x, y: m.y }); + return; + } + if (m.act === "sink") { + m.wait = Math.max(0, m.wait - ms); + if (m.wait) return; + m.act = "eyes"; + return; + } + m.dir = k.towardYou(round, m); + if (Math.abs(you.x - m.x) < SNAP_RANGE && Math.abs(you.y - m.y) < SNAP_HIGH && you.out <= 0) { + m.act = "snap"; + m.wait = SNAP_MS; + round.events.push({ type: "lurkerSnap", kind: m.kind, x: m.x, y: m.y + 1, dir: m.dir }); + } +} + +// Drifting along its floor toward you; contact is a latch (one heart, cause +// `leeches`, then it drops off and drifts again once it can). +function moveLeech(round, m, ms, k) { + const you = round.you; + const spec = round.spec; + const dt = ms / 1000; + m.latchIn = Math.max(0, (m.latchIn || 0) - ms); + if (m.act === "drop") { + m.wait = Math.max(0, m.wait - ms); + if (m.wait) return; + m.act = "drift"; + return; + } + const hitH = you.ducking ? k.DUCK_H : k.HIT_H; + const touch = Math.abs(you.x - m.x) < (k.HIT_W + m.w * 0.8) / 2 && you.y < m.y + m.h * 0.9 && you.y + hitH > m.y + m.h * 0.1; + if (touch && !(m.latchIn > 0) && you.out <= 0) { + m.act = "drop"; + m.wait = LEECH_DROP_MS; + m.latchIn = LEECH_AGAIN_MS; + round.events.push({ type: "leechLatch", kind: m.kind, x: m.x, y: m.y }); + k.struck(round, "leeches"); + return; + } + const dir = k.towardYou(round, m); + k.walk(round, m, dir, MONSTERS.leech.speed * spec.pace, dt); + m.dir = dir; +} + +// A mud-caked riser: it climbs out of the muck (harmless till up, the +// zombie rule), then shambles and lurches like one. A horde one, or one out +// of a door, is already up. +function moveBogbody(round, m, ms, k) { + const you = round.you; + if (m.act === "rise") { + if (m.horde) { + m.act = "walk"; + } else { + if (!(m.rise > 0)) { + m.rise = BOG_RISE_MS; + round.events.push({ type: "bogRise", kind: m.kind, x: m.x, y: m.y }); + } + m.rise = Math.max(0, m.rise - ms); + if (!m.rise) m.act = "walk"; + return; + } + } + const near = Math.abs(you.x - m.x) < LURCH_RANGE && Math.abs(you.y - m.y) < 6; + k.walk(round, m, k.towardYou(round, m), (near ? MONSTERS.bogbody.lurch : MONSTERS.bogbody.speed) * round.spec.pace, ms / 1000); + m.lurching = near; +} + +// A drifting light: while bright it wanders toward your chest (its dips are +// duckable), while dim it sinks and waits out its relight, and while +// rekindling it glows where it will burn again. +function moveWisp(round, m, ms, k) { + const you = round.you; + const spec = round.spec; + const dt = ms / 1000; + if (m.act === "dim") { + m.wait = Math.max(0, m.wait - ms); + const floor = k.groundAt(spec, m.x); + if (Number.isFinite(floor)) m.y = Math.max(floor + 0.6, m.y - 18 * dt); + if (m.wait) return; + if (m.relight) { + m.x = m.relight.x; + m.y = m.relight.y; + } + m.act = "rekindle"; + m.wait = WISP_REKINDLE_MS; + round.events.push({ type: "wispRelight", kind: m.kind, x: m.x, y: m.y }); + return; + } + if (m.act === "rekindle") { + m.wait = Math.max(0, m.wait - ms); + if (m.wait) return; + m.act = "bright"; + round.events.push({ type: "wispOn", kind: m.kind, x: m.x, y: m.y }); + return; + } + const speed = MONSTERS.wisp.speed * spec.pace; + const ty = you.y + k.SHOT_Y - m.h / 2; + const dx = you.x - m.x; + const dy = ty - m.y; + const d = Math.hypot(dx, dy) || 1; + m.x += (dx / d) * speed * dt; + m.y += (dy / d) * speed * dt; + m.y += Math.sin(m.t / 190 + m.id) * 4 * dt; + m.dir = Math.sign(dx) || m.dir; + m.y = Math.max(k.groundAt(spec, m.x) + 0.6, Math.min(k.CHANDELIER_Y, m.y)); +} + +// A bolt puts a bright wisp out (never hurt: it is light), starting its +// rekindle clock and seeding the spot it will burn again from its id. +function wispShot(round, m, s, k) { + if (m.kind !== "wisp" || m.act !== "bright") return 1; + m.act = "dim"; + m.wait = WISP_RELIGHT_MS; + m.vx = 0; + m.vy = 0; + const spec = round.spec; + const rx = clamp(m.x + (((m.id * 37) % 23) - 11), 4, spec.length - 4); + m.relight = { x: rx, y: Math.min(k.CHANDELIER_Y, Math.max(k.groundAt(spec, rx) + 7, 10)) }; + round.events.push({ type: "wispOut", kind: m.kind, x: m.x, y: m.y + m.h / 2 }); + return 0; +} + +// A dispersed swarm is told so (its voice lands with the art). +function leechDies(round, m) { + round.events.push({ type: "leechDie", kind: m.kind, x: m.x, y: m.y + m.h / 2 }); +} + +/* --------------------------------------------------------- the wisp lure */ + +// The stage's twist, run each slice: the dead inside a bright wisp's light +// are pulled toward you and run quicker, till the wisp dims or they drift +// out of it. In another stage's room it never touches `lure` or `hasteMs`: +// those fields are another pack's there (the grounds' moth call). +function bogTick(round, ms) { + if (round.stage !== "bog") return; + const wisps = []; + for (const w of round.monsters) if (!w.dead && w.kind === "wisp" && w.act === "bright") wisps.push(w); + for (const m of round.monsters) { + if (m.dead || m.kind === "wisp") continue; + let near = false; + for (const w of wisps) { + if (Math.hypot(m.x - w.x, m.y - w.y) <= WISP_LURE) { + near = true; + break; + } + } + if (near) { + if (!(m.lure > 0)) round.events.push({ type: "wispLure", kind: m.kind, x: m.x, y: m.y + m.h }); + m.lure = LURE_HOLD_MS; + m.hasteMs = LURE_HOLD_MS; + m.haste = WISP_HASTE; + } else if (m.lure > 0) { + m.lure = 0; + m.hasteMs = 0; + m.haste = 1; + } + } +} + +/* ------------------------------------------------------------ the hag */ + +const motherWait = (round, b, v) => (v * (b.raged ? MOTHER_QUICK : 1)) / round.spec.pace; + +// The plank nearest `x` within reach, as { x, y }, or null over open water. +function plankAt(spec, x, k) { + for (const d of [0, 2, -2, 4, -4, 6, -6]) { + const g = k.groundAt(spec, x + d); + if (Number.isFinite(g)) return { x: x + d, y: g }; + } + return null; +} + +function moveMother(round, b, ms, random, k) { + const you = round.you; + const spec = round.spec; + const dt = ms / 1000; + const wait = (v) => motherWait(round, b, v); + if (!b.act) { + b.act = "idle"; + b.wait = wait(MOTHER_IDLE_MS); + } + b.wait -= ms; + if (b.act !== "sink" && b.act !== "under" && b.act !== "resurface") b.dir = Math.sign(you.x - b.x) || b.dir; + // At half her hp she goes under once, and comes back up meaner. + if (!b.sank && b.hp <= b.max * MOTHER_RAGE) { + b.sank = true; + b.raged = true; + b.home = b.y; + b.act = "sink"; + b.wait = MOTHER_SINK_MS; + b.hidden = true; + // Down at once: a box she slides through you with while nothing can hurt + // her is a hit you could not answer. + b.y = b.home - (b.h + 4); + round.events.push({ type: "motherSink", kind: b.kind, x: b.x, y: b.home }); + return; + } + // The cauldron opens late in a rest: a shot then counts triple (see `weak`). + const open = b.act === "rest" && b.wait <= MOTHER_OPEN_MS; + if (open && !b.lit) round.events.push({ type: "cauldronOpen", kind: b.kind, x: b.x + b.dir * b.w * 0.3, y: b.y + b.h * 0.35 }); + b.lit = open; + if (b.act === "idle") { + // She drifts to keep about MOTHER_KEEP of plank between her and you, + // never stepping off the boards onto open water. + const side = Math.sign(b.x - you.x) || 1; + const goal = clamp(you.x + side * MOTHER_KEEP, k.arenaMin(round, b), k.arenaMax(round, b)); + if (Math.abs(goal - b.x) > 1 && k.groundAt(spec, goal) === b.y) { + const nx = b.x + Math.sign(goal - b.x) * MOTHER_WALK * spec.pace * dt; + if (k.groundAt(spec, nx) === b.y) b.x = nx; + } + if (b.wait > 0) return; + // The mud wave and the cauldron in turn. + b.attacks++; + if (b.attacks % 2) { + b.act = "wind"; + b.wait = wait(MOTHER_WIND_MS); + round.events.push({ type: "motherWind", kind: b.kind, x: b.x, y: b.y + b.h * 0.6, dir: b.dir }); + } else { + b.act = "throwWind"; + b.wait = wait(SPIT_WIND_MS); + round.events.push({ type: "spitWind", kind: b.kind, x: b.x + b.dir * b.w * 0.3, y: b.y + b.h * 0.55, dir: b.dir }); + } + return; + } + if (b.act === "wind") { + if (b.wait > 0) return; + const floor = k.groundAt(spec, b.x); + round.waves.push({ x: b.x + b.dir * (b.w / 2), y: floor, dir: b.dir, life: 6000, kind: "mudwave", cause: "mudwave" }); + round.events.push({ type: "mudWave", kind: b.kind, x: b.x + b.dir * (b.w / 2), y: floor, dir: b.dir }); + b.act = "rest"; + b.wait = wait(MOTHER_REST_MS); + return; + } + if (b.act === "throwWind") { + if (b.wait > 0) return; + const sx = b.x + b.dir * b.w * 0.35; + const sy = b.y + b.h * 0.55; + const at = { type: "cauldronSpit", kind: b.kind, x: sx, y: sy }; + const x = clamp(you.x, spec.arena + 2, spec.length - 2); + const spot = plankAt(spec, x, k); + if (spot) { + round.hazards.push({ kind: "muck", x: spot.x, y: spot.y, w: MUCK_W, h: MUCK_H, warn: MUCK_LAND_MS, live: 0, cause: "muck", sx, sy }); + Object.assign(at, { tx: spot.x, ty: spot.y }); + } + // Meaner: a second patch lands ahead of where you run. + if (b.raged) { + let ahead = (Math.sign(you.vx) || you.face || 1) * MUCK_LEAD; + let x2 = clamp(x + ahead, spec.arena + 2, spec.length - 2); + if (Math.abs(x2 - x) < MUCK_W) x2 = clamp(x - ahead, spec.arena + 2, spec.length - 2); + const spot2 = plankAt(spec, x2, k); + if (spot2 && (!spot || spot2.x !== spot.x)) { + round.hazards.push({ kind: "muck", x: spot2.x, y: spot2.y, w: MUCK_W, h: MUCK_H, warn: MUCK_LAND_MS, live: 0, cause: "muck", sx, sy }); + Object.assign(at, { tx2: spot2.x, ty2: spot2.y }); + } + } + round.events.push(at); + b.act = "idle"; + b.wait = wait(MOTHER_REST_MS); + return; + } + if (b.act === "rest") { + if (b.wait > 0) return; + b.act = "idle"; + b.wait = wait(MOTHER_IDLE_MS); + return; + } + if (b.act === "sink") { + if (b.wait > 0) return; + // Where she comes back up: on a plank near you, never on top of you. + const lo = spec.arena + 4 + b.w / 2; + const hi = spec.length - 4 - b.w / 2; + let spot = null; + for (const d of [RESURFACE_NEAR, -RESURFACE_NEAR, RESURFACE_NEAR * 1.7, -RESURFACE_NEAR * 1.7, RESURFACE_NEAR * 2.4, -RESURFACE_NEAR * 2.4]) { + const x = clamp(you.x + d, lo, hi); + if (Math.abs(x - you.x) >= 6 && k.groundAt(spec, x) === b.home) { + spot = x; + break; + } + } + if (spot === null) for (const d of [0, 8, -8]) { + const x = clamp(b.x + d, lo, hi); + if (Math.abs(x - you.x) >= 6 && k.groundAt(spec, x) === b.home) { + spot = x; + break; + } + } + b.sinkX = spot ?? clamp(b.x, lo, hi); + b.act = "under"; + b.wait = BUBBLE_MS; + round.events.push({ type: "motherBubble", kind: b.kind, x: b.sinkX, y: b.home }); + return; + } + if (b.act === "under") { + if (b.wait > 0) return; + // Up at once where the bubbles showed, touchable and hittable again. + b.x = b.sinkX; + b.y = b.home; + b.hidden = false; + b.act = "resurface"; + b.wait = RESURFACE_MS; + round.events.push({ type: "motherRise", kind: b.kind, x: b.x, y: b.home }); + return; + } + if (b.act === "resurface") { + if (b.wait > 0) return; + b.act = "rest"; + b.wait = wait(MOTHER_REST_MS); + return; + } +} + +// A muck patch: a glob in the air for `warn`, then burning for MUCK_MS +// where it came down. Returns whether it is still on the field. +function stepMuck(round, h, ms) { + if (h.warn > 0) { + h.warn = Math.max(0, h.warn - ms); + if (h.warn > 0) return true; + h.live = MUCK_MS; + round.events.push({ type: "muckLand", x: h.x, y: h.y }); + return true; + } + h.live -= ms; + return h.live > 0; +} + +// A harpoon is the one bolt that reaches a lurker's eyes under the water: +// every other shot goes through them (they are `unseen`). +function harpoonShot(round, s, k) { + if (s.arm !== "harpoon") return false; + for (const m of round.monsters) { + if (m.dead || m.kind !== "lurker" || !m.unseen || (s.hit || []).includes(m.id)) continue; + if (Math.abs(s.x - m.x) > m.w / 2 + 0.5 || s.y < m.y - 0.5 || s.y > m.y + m.h + 0.5) continue; + s.hit = [...(s.hit || []), m.id]; + k.hurt(round, m, s.dmg || 1, "harpoon"); + round.events.push({ type: "harpoonHit", kind: m.kind, x: s.x, y: s.y }); + } + return false; +} + +export const BOG = freeze({ + id: "bog", + monsters: MONSTERS, + walkers: freeze(["lurker", "leech"]), + zombies: freeze(["bogbody"]), + stackers: freeze(["bogbody"]), + climbers: freeze(["bogbody"]), + act: freeze({ lurker: "eyes", leech: "drift", wisp: "bright", bogbody: "rise" }), + swoops: freeze({ wisp: (m) => m.act === "bright" }), + // A lurker can hurt and be hit only while it is snapping; a dim or + // rekindling wisp can do neither. + solid: freeze({ + lurker: (m) => m.act === "snap", + wisp: (m) => m.act === "bright", + }), + // A lurker's eyes are never solid: a stomp or a bolt passes over them. + unseen: freeze({ lurker: (round, m) => m.act !== "snap" }), + // The swarm never hurts by touch: it latches instead (see moveLeech). + harmless: freeze({ leech: () => true }), + move: freeze({ lurker: moveLurker, leech: moveLeech, wisp: moveWisp, bogbody: moveBogbody }), + kill: freeze({ leech: leechDies }), + horde: freeze({}), + tick: freeze([bogTick]), + shot: wispShot, + target: harpoonShot, + bosses: BOSSES, + boss: freeze({ motherbog: moveMother }), + // She is gone while she is under: shots and stomps meet only water. + guard: freeze({ motherbog: (b) => Boolean(b.hidden) }), + // A shot into the open cauldron counts triple. + weak: freeze({ motherbog: (b) => (b.lit ? 3 : 1) }), + cause: freeze({ motherbog: () => "motherbog" }), + hazards: freeze({ muck: stepMuck }), +}); diff --git a/src/web-console/public/activities/ghoul-bogboat-draw.js b/src/web-console/public/activities/ghoul-bogboat-draw.js new file mode 100644 index 0000000..245e371 --- /dev/null +++ b/src/web-console/public/activities/ghoul-bogboat-draw.js @@ -0,0 +1,949 @@ +// Plan2Code Web Console - Ghoul Rush's Bog Runner, its drawing: a fan-boat skim down a black channel through the night swamp. A pale low moon and a few stars, drowned cypress trees that scroll by at their own speeds, mist, the black water of the channel in front and the raised mud flats behind it (joined by a mud ramp at each bank), sunken snags, cypress knees, moss veils and low limbs, the hag's charms hanging on strings, gas pockets bubbling up, the fan boat with its caged propeller and the leech swarm that boils in its wake. +// +// ghoul-draw.js plugs it in. LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are plain +// data (the voices are the room's own tones, in ghoul-sfx-bogboat.js); bogboatArt(d) takes +// ghoul-draw.js's drawing helpers (`d`) and hands back the drawing by kind, so this file never +// reaches back into it. Drawn in room units, the way ghoul-draw.js draws: y counted down from +// the field's top, so a world height `y` is drawn at `FIELD_H - y`. The still layers are only +// the sky's color: the world is drawn by `moving` (every frame, over them; no cached layers, no +// random numbers: everything comes from a hash), the lows, the bow, the mist, the signs and the +// two gauges in front of Planny by `front`. What the art reads off the rules (ghoul-bogboat.js): +// +// - the room: `spec.ride` ({ banks, snags, knees, veils, limbs, props, gas, checks, finish }), +// the flat floor in `spec.ground`. +// - `round.runner` (id "bogboat"; null in any other room): `lane`, `from`, `swMs`, `h`, `air`, +// `v`, `gap`, `panic`, `clog`, `stall`, `done`, `restX`, `check`, `props` [{ state "up" | +// "broken" }], `gas` [{ state "up" | "burst" | "spent", t }]. +// - Planny: `you.x`, `you.y`, `you.vy`, `you.ducking`. +// - events leave short-lived bits in the view's `fx` (`bogboatBits`, `bogboatLand`). + +import { CLOG_MAX, CLOG_WARN, GAP_MAX, GAS_BURST_MS, GAS_H, GAS_UP, GAS_W, KNEE_W, LANE_Y, LOW_Y, PANIC_ON, PROP_H, PROP_UP, SNAG_W, WAKE_CATCH, baseOf, laneNow } from "./ghoul-bogboat.js"; + +const freeze = (o) => Object.freeze(o); +const TAU = Math.PI * 2; +const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x)); + +const water = (o) => freeze({ pack: "bogboat", custom: true, noMoon: true, pit: "#010303", ...o }); +export const LOOKS = freeze({ + bogboat: water({ wallTop: "#04080c", wallLow: "#0d1a22", paper: "#16262e", wainscot: "#0a1216", floorTop: "#2c3a3e", floor: "#182226", floorEdge: "#060a0c", shelf: "#242c28", shelfTop: "#3c4a42", window: "#bcd6d0", decor: "plants", color: "#8aa8b4", dark: 0.5 }), +}); + +// How each new kind sounds, by act (the room's own tones, ghoul-sfx-bogboat.js). +export const VOICES = freeze({ + bogboat: freeze({ jump: "ghoulBogboatJump", land: "ghoulBogboatLand", duck: "ghoulBogboatDuck", switch: "ghoulBogboatSwitch", crash: "ghoulBogboatCrash", check: "ghoulBogboatCheck", finish: "ghoulBogboatFinish" }), + bogboatwake: freeze({ panic: "ghoulBogboatPanic", catch: "ghoulBogboatCatch" }), + bogboatfan: freeze({ clog: "ghoulBogboatClog", stall: "ghoulBogboatStall" }), + bogboatshot: freeze({ gas: "ghoulBogboatGas", prop: "ghoulBogboatProp" }), +}); + +// What each of the pack's events plays: [kind, act], once. +export const EVENT_VOICE = freeze({ + bogboatJump: ["bogboat", "jump"], + bogboatLand: ["bogboat", "land"], + bogboatDuck: ["bogboat", "duck"], + bogboatSwitch: ["bogboat", "switch"], + bogboatCrash: ["bogboat", "crash"], + bogboatCheck: ["bogboat", "check"], + bogboatFinish: ["bogboat", "finish"], + bogboatPanic: ["bogboatwake", "panic"], + bogboatCatch: ["bogboatwake", "catch"], + bogboatClog: ["bogboatfan", "clog"], + bogboatStall: ["bogboatfan", "stall"], + bogboatGas: ["bogboatshot", "gas"], + bogboatProp: ["bogboatshot", "prop"], +}); +export const LOSE_WORDS = freeze({ snag: "Ran onto a snag", knee: "Hit the cypress knees", veil: "Tangled in moss", limb: "Ducked too late", wake: "Swarmed" }); +export const LOSE_SOUNDS = freeze({ + snag: ["smash", 0.6, 0.7], + knee: ["clank", 0.5, 0.6], + veil: ["squish", 0.45, 0.8], + limb: ["clank", 0.5, 0.8], + wake: ["squish", 0.5, 0.7], +}); + +const FW = 96; +const WATER_Y = LANE_Y[0]; +const FLATS_Y = LANE_Y[1]; +let FH = 54; +const MOSS = "#3a5a34"; +const MOSS_D = "#223a22"; +const MUD = "#3a2d1c"; +const MUD_D = "#1c150c"; +const MUD_LIT = "#6a5632"; +const WOOD = "#3a2e1e"; +const WOOD_D = "#1e160e"; +const HULL = "#2e3a3a"; +const HULL_LIT = "#52666a"; +const RUST = "#7a3a1e"; +const SWARM = "#1a1210"; +const GAS = "#c8f06a"; +const BONE = "#d8d0b8"; + +// A number in 0..1 from two integers, the same every time (no random draws). +const rnd = (a, b = 0) => { + let h = Math.imul((a | 0) + 0x9e37, 0x85ebca6b) ^ Math.imul((b | 0) + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +const poly = (c, pts) => { + c.beginPath(); + pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); + c.closePath(); +}; +const seg = (c, x0, y0, x1, y1) => { + c.beginPath(); + c.moveTo(x0, y0); + c.lineTo(x1, y1); + c.stroke(); +}; +const disc = (c, x, y, r) => { + c.beginPath(); + c.arc(x, y, r, 0, TAU); + c.fill(); +}; +const grad = (make, stops) => { + const g = make ? make() : null; + if (!g || typeof g.addColorStop !== "function") return stops[stops.length >> 1][1]; + for (const [o, col] of stops) g.addColorStop(o, col); + return g; +}; +const vgrad = (c, y0, y1, stops) => grad(c.createLinearGradient && (() => c.createLinearGradient(0, y0, 0, y1)), stops); +const rgrad = (c, x, y, r, stops) => grad(c.createRadialGradient && (() => c.createRadialGradient(x, y, 0, x, y, r)), stops); +const Y = (y) => FH - y; +// A soft glow: a radial gradient, a flat disc where the canvas cannot do one. +function halo(ctx, x, y, r, color, alpha) { + ctx.globalAlpha = alpha; + ctx.fillStyle = rgrad(ctx, x, y, r, [[0, color], [1, "rgba(0,0,0,0)"]]); + ctx.fillRect(x - r, y - r, r * 2, r * 2); + ctx.globalAlpha = 1; +} + +/* ------------------------------------------------------------- telegraphs */ + +// What to do about each obstacle, shown as a glyph that fades in ahead of it, for the lane the +// boat is in: JUMP (an arrow up, cyan) over snags and cypress knees, DUCK (an arrow down, amber) +// under moss veils and limbs, SHOOT (a crosshair, red) at the first gas pockets. Everything comes +// from the room's `ride` fields and where the boat is (no random numbers, no rules). +export const TELEGRAPH_SEE = 40; +export const TELEGRAPH_FULL = 30; +export const TELEGRAPH_WORDS = 3; +export const TELEGRAPH_ALPHA = 0.78; +export const SHOOT_GLYPHS = 4; +export const ANSWERS = freeze({ snag: "JUMP", knee: "JUMP", veil: "DUCK", limb: "DUCK", gas: "SHOOT" }); +export const ANSWER_COLORS = freeze({ JUMP: "#5fe3ff", DUCK: "#ffb02e", SHOOT: "#ff6a6a" }); + +const marks = new WeakMap(); +// Every obstacle that wants a glyph: { kind, lane, lead (where it begins), x (its middle), up (height of +// the glyph's anchor), n (which of its kind), answer }, in the room's order. Only the first SHOOT_GLYPHS +// gas pockets of the ride are marked: the lesson, then the player knows. +export function telegraphMarks(R) { + if (marks.has(R)) return marks.get(R); + const out = []; + const count = {}; + const add = (kind, lane, lead, x, up) => { + const n = count[kind] || 0; + count[kind] = n + 1; + out.push({ kind, lane, lead, x, up: LANE_Y[lane] + up, n, answer: ANSWERS[kind] }); + }; + for (const [x, lane] of R.snags) add("snag", lane, x - 3, x, 7.6); + for (const [x, lane] of R.knees) add("knee", lane, x - 3.4, x, 6.2); + for (const [x0, x1, lane] of R.veils) add("veil", lane, x0 - 3.2, (x0 + x1) / 2, 7.4); + for (const [x0, x1, lane] of R.limbs) add("limb", lane, x0 - 3.2, (x0 + x1) / 2, 7.4); + for (const [x, lane] of R.gas) add("gas", lane, x - 2, x, 8); + out.sort((p, q) => p.lead - q.lead); + marks.set(R, out.filter((m) => m.kind !== "gas" || m.n < SHOOT_GLYPHS)); + return marks.get(R); +} + +// The glyphs showing with the boat at `x` in `lane`: { ...mark, alpha (0..1, before the pulse), words }. +export function telegraphs(R, x, lane) { + const out = []; + for (const m of telegraphMarks(R)) { + if (m.lane !== lane) continue; + const d = m.lead - x; + if (d > TELEGRAPH_SEE || d < -6) continue; + const alpha = Math.min(clamp((TELEGRAPH_SEE - d) / (TELEGRAPH_SEE - TELEGRAPH_FULL), 0, 1), clamp((d + 4) / 6, 0, 1)); + if (alpha > 0.01) out.push({ ...m, alpha, words: m.n < TELEGRAPH_WORDS }); + } + return out; +} + +/* --------------------------------------------------------------------- art */ + +export function bogboatArt(d) { + const { ellipse, say, label, GOLD } = d; + const ride = (v) => (v.spec && v.spec.ride && v.spec.ride.runner === "bogboat" ? v.spec.ride : null); + const runner = (v) => (v.round && v.round.runner && v.round.runner.id === "bogboat" ? v.round.runner : null); + + // The still layers get only the sky's color; `moving` draws the world. + function backdrop(ctx, v, look, x0, x1) { + ctx.fillStyle = look.wallLow; + ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H); + } + function ground() {} + function shelf() {} + + /* ---------------------------------------------------------- the sky and far scenery */ + + function sky(ctx, v, cam) { + ctx.fillStyle = vgrad(ctx, 0, FH, [[0, "#03070a"], [0.55, "#0c1a20"], [1, "#1c3036"]]); + ctx.fillRect(cam - 1, 0, FW + 2, FH); + for (let k = 0; k < 34; k++) { + const x = cam + ((((rnd(k, 1) * FW - cam * 0.02) % FW) + FW) % FW); + ctx.globalAlpha = 0.18 + 0.4 * rnd(k, 3) * (0.7 + 0.3 * Math.sin(v.clock / 600 + k)); + ctx.fillStyle = "#cfe2dc"; + ctx.fillRect(x, rnd(k, 2) * 24, 0.2, 0.2); + } + ctx.globalAlpha = 1; + // The moon: low, pale green and smeared by mist, riding with the view. + const mx = cam + 68; + halo(ctx, mx, 11, 15, "rgba(170,215,200,0.5)", 0.5); + ctx.fillStyle = "#d4ece4"; + disc(ctx, mx, 11, 3.8); + ctx.fillStyle = "rgba(120,160,150,0.45)"; + disc(ctx, mx - 1.1, 10.4, 0.9); + disc(ctx, mx + 1, 12, 0.6); + ctx.fillStyle = "rgba(10,22,26,0.5)"; + for (let k = 0; k < 3; k++) ellipse(ctx, cam + ((((rnd(k, 9) * 140 - v.clock / 110 - cam * 0.05) % 140) + 140) % 140) - 20, 9 + k * 2.6, 12 + rnd(k, 4) * 6, 0.55); + ctx.fill(); + } + + // Drowned cypresses at a slow parallax: a trunk, flared foot, a few bare limbs and a hanging rag of moss. + function trees(ctx, cam, par, base, scale, color, seed) { + const u0 = cam * par; + const gap = 17; + for (let slot = Math.floor((u0 - 6) / gap); slot <= Math.floor((u0 + FW + 8) / gap); slot++) { + const r = rnd(slot, seed); + if (r < 0.18) continue; + const x = cam + (slot * gap - u0) + r * 7; + const h = (9 + rnd(slot, seed + 1) * 9) * scale; + ctx.fillStyle = color; + ctx.strokeStyle = color; + poly(ctx, [[x - 1.1 * scale, base], [x - 0.35 * scale, base - h], [x + 0.35 * scale, base - h], [x + 1.1 * scale, base]]); + ctx.fill(); + ctx.lineWidth = 0.3 * scale; + for (let k = 0; k < 3; k++) { + const dir = (k + slot) % 2 ? 1 : -1; + seg(ctx, x, base - h * (0.5 + k * 0.17), x + dir * (2.6 - k * 0.5) * scale, base - h * (0.6 + k * 0.17)); + } + ctx.lineWidth = 0.16 * scale; + for (let k = 0; k < 3; k++) seg(ctx, x + (k - 1) * 0.9 * scale, base - h * 0.62, x + (k - 1) * 0.95 * scale, base - h * 0.62 + (2 + rnd(slot, k + 5) * 2) * scale); + } + } + + // Mist: low soft bands drifting along the water. + function mist(ctx, v, cam, alpha) { + for (let k = 0; k < 5; k++) { + const x = cam + ((((rnd(k, 21) * FW * 1.4 - v.clock / (900 + k * 150) - cam * 0.1) % (FW * 1.4)) + FW * 1.4) % (FW * 1.4)) - 14; + ctx.globalAlpha = alpha * (0.6 + 0.4 * rnd(k, 22)); + ctx.fillStyle = "#9cb8b0"; + ellipse(ctx, x, Y(WATER_Y + 1.2 + k * 1.6), 16 + rnd(k, 23) * 8, 1.1 + k * 0.25); + ctx.fill(); + } + ctx.globalAlpha = 1; + } + + /* -------------------------------------------------------------- the water and the flats */ + + // The channel: black water with the moon's sheen sliding by and the raised mud flats behind it. + function channel(ctx, v, cam, R) { + const top = Y(WATER_Y); + ctx.fillStyle = vgrad(ctx, top, FH, [[0, "#0c1e22"], [0.25, "#061014"], [1, "#020608"]]); + ctx.fillRect(cam - 1, top, FW + 2, WATER_Y + 1); + ctx.fillStyle = "rgba(150,200,190,0.16)"; + for (let k = Math.floor(cam / 3.2); k < Math.floor((cam + FW) / 3.2) + 1; k++) { + if (rnd(k, 31) < 0.4) continue; + ctx.fillRect(k * 3.2 + Math.sin(v.clock / 700 + k) * 0.6, top + 0.5 + rnd(k, 34) * 6, 0.9 + rnd(k, 35) * 1.6, 0.18); + } + // The flats: a raised terrace of mud behind the channel, gleaming, reeds along its top. + const fy = Y(FLATS_Y); + ctx.fillStyle = vgrad(ctx, fy, top, [[0, MUD_LIT], [0.1, MUD], [1, MUD_D]]); + ctx.fillRect(cam - 1, fy, FW + 2, top - fy + 0.1); + ctx.fillStyle = "rgba(180,170,120,0.22)"; + for (let k = Math.floor(cam / 4); k < Math.floor((cam + FW) / 4) + 1; k++) ctx.fillRect(k * 4 + rnd(k, 41) * 2, fy + 0.5 + rnd(k, 42) * 3.4, 1.6 + rnd(k, 43), 0.2); + ctx.fillStyle = "#4a5a34"; + ctx.fillRect(cam - 1, fy, FW + 2, 0.35); + ctx.strokeStyle = "#5a6a3a"; + ctx.lineWidth = 0.14; + for (let k = Math.floor(cam / 2.2); k < Math.floor((cam + FW) / 2.2) + 1; k++) { + if (rnd(k, 44) < 0.4) continue; + const h = 1.4 + rnd(k, 45) * 1.6; + seg(ctx, k * 2.2, fy + 0.2, k * 2.2 + Math.sin(v.clock / 900 + k) * 0.3, fy - h); + } + ctx.fillStyle = "#14201c"; + ctx.fillRect(cam - 1, top - 0.9, FW + 2, 0.9); + ctx.fillStyle = "#2c4a44"; + ctx.fillRect(cam - 1, top - 0.9, FW + 2, 0.18); + // At each bank the edge is a mud ramp, with chevrons pointing up it. + for (const [a, b] of R.banks) { + if (b < cam - 4 || a > cam + FW + 4) continue; + ctx.fillStyle = "#2a2012"; + poly(ctx, [[a, top], [a, fy], [b, fy]]); + ctx.fill(); + ctx.strokeStyle = "#6a5632"; + ctx.lineWidth = 0.35; + seg(ctx, a, top, b, fy); + ctx.strokeStyle = "rgba(200,230,170,0.55)"; + ctx.lineWidth = 0.22; + for (let k = 0; k < 3; k++) { + const cx = a + 3 + k * 4.2; + const cy = top - ((cx - a) / (b - a)) * (top - fy) - 0.6; + ctx.beginPath(); + ctx.moveTo(cx - 0.8, cy + 0.6); + ctx.lineTo(cx, cy); + ctx.lineTo(cx - 0.8, cy - 0.6); + ctx.stroke(); + } + } + } + + // A bank's posts: a leaning stake with a dim green lantern at each end of the ramp. + function bankPosts(ctx, v, a, b) { + for (const [px, lit] of [[a - 0.4, 1], [b + 0.4, 0]]) { + ctx.fillStyle = WOOD; + ctx.fillRect(px - 0.4, Y(WATER_Y + 4.4), 0.8, 4.4); + ctx.fillStyle = "#7dffa0"; + ctx.globalAlpha = 0.65 + 0.25 * Math.sin(v.clock / 330 + lit); + disc(ctx, px, Y(WATER_Y + 5.1), 0.5); + ctx.globalAlpha = 1; + halo(ctx, px, Y(WATER_Y + 5.1), 4, "rgba(125,255,160,0.8)", 0.3); + } + } + + /* ---------------------------------------------------------------- the things */ + + // A sunken snag: a rotting log lying across the lane, a broken stub up, weed on it. + function snag(ctx, x, lane, i) { + const y = Y(LANE_Y[lane]); + ctx.save(); + ctx.translate(x, y); + ctx.fillStyle = "rgba(0,0,0,0.35)"; + ellipse(ctx, 0, 0.05, SNAG_W * 0.9, 0.3); + ctx.fill(); + ctx.fillStyle = WOOD; + poly(ctx, [[-1.7, 0], [-1.5, -1.2], [-0.4, -1.5], [0.6, -3.8], [1.3, -3.9], [1.4, -1.6], [1.8, -1.0], [1.7, 0]]); + ctx.fill(); + ctx.fillStyle = WOOD_D; + ctx.fillRect(-1.7, -0.5, 3.4, 0.5); + ctx.fillStyle = "#5a4a32"; + ctx.fillRect(0.7, -3.8, 0.35, 2.4); + ctx.strokeStyle = MOSS; + ctx.lineWidth = 0.14; + for (let k = 0; k < 3; k++) seg(ctx, -1.2 + k * 1.1, -1.3, -1.2 + k * 1.1 + Math.sin(i + k) * 0.4, -2.3 - rnd(i, k) * 0.6); + ctx.restore(); + } + + // Cypress knees: three gray cones breaking the surface, wet at the foot. + function knees(ctx, x, lane, i) { + const y = Y(LANE_Y[lane]); + ctx.save(); + ctx.translate(x, y); + ctx.fillStyle = "rgba(0,0,0,0.35)"; + ellipse(ctx, 0, 0.05, KNEE_W * 0.6, 0.3); + ctx.fill(); + [[-1.6, 1.7, 1.2], [0, 2.4, 1.5], [1.7, 1.5, 1.1]].forEach(([dx, h, w], k) => { + ctx.fillStyle = k % 2 ? "#5a5a48" : "#4a4a3a"; + poly(ctx, [[dx - w / 2, 0], [dx - w * 0.15, -h], [dx + w * 0.15, -h * 0.95], [dx + w / 2, 0]]); + ctx.fill(); + ctx.fillStyle = "rgba(180,200,190,0.18)"; + ctx.fillRect(dx - w / 2, -0.3, w, 0.3); + }); + ctx.restore(); + } + + // A curtain of moss hung from a cypress limb: its underside LOW_Y over the lane. + function veil(ctx, v, x0, x1, lane, i) { + const under = Y(LANE_Y[lane]) - LOW_Y; + const tx = x1 + 3; + ctx.lineCap = "round"; + ctx.strokeStyle = "#0e0a06"; + ctx.lineWidth = 0.9; + ctx.beginPath(); + ctx.moveTo(tx, FH + 1); + ctx.quadraticCurveTo(tx + 0.5, under + 6, tx - 0.3, under - 3); + ctx.stroke(); + ctx.lineWidth = 0.7; + seg(ctx, tx - 0.2, under - 1.8, x0 - 2, under - 1.2); + ctx.lineCap = "butt"; + for (let k = 0; k < 11; k++) { + const hx = x0 - 1.5 + (k * (x1 - x0 + 3)) / 10; + const len = 1.0 + rnd(i * 13 + k, 2) * 2.2; + const sway = Math.sin(v.clock / 520 + hx) * 0.35; + ctx.strokeStyle = k % 2 ? MOSS : MOSS_D; + ctx.lineWidth = 0.3; + seg(ctx, hx, under - 1.2, hx + sway, under + len); + } + } + + // A low cypress limb: twisted, bare, with a few moss rags. + function limb(ctx, v, x0, x1, lane, i) { + const under = Y(LANE_Y[lane]) - LOW_Y; + const tx = x1 + 3.4; + ctx.lineCap = "round"; + for (const [col, extra] of [["rgba(150,190,180,0.35)", 0.3], ["#0e0a06", 0]]) { + ctx.strokeStyle = col; + ctx.lineWidth = 0.8 + extra; + ctx.beginPath(); + ctx.moveTo(tx, FH + 1); + ctx.quadraticCurveTo(tx + 0.6, under + 6, tx - 0.4, under - 2.4); + ctx.stroke(); + ctx.lineWidth = 0.95 + extra; + ctx.beginPath(); + ctx.moveTo(tx - 0.2, under - 1); + ctx.quadraticCurveTo(x1 - 1, under - 1.8, x0 - 2.4, under - 0.5); + ctx.stroke(); + } + ctx.strokeStyle = "#0e0a06"; + ctx.lineWidth = 0.4; + seg(ctx, x0 + 1.2, under - 0.8, x0 - 0.2, under + 0.6); + ctx.lineCap = "butt"; + for (let k = 0; k < 4; k++) { + const hx = x0 - 1.4 + k * ((x1 - x0 + 3) / 3); + ctx.strokeStyle = k % 2 ? MOSS : MOSS_D; + ctx.lineWidth = 0.22; + seg(ctx, hx, under - 0.3, hx + Math.sin(v.clock / 480 + hx) * 0.25, under + 0.8 + rnd(i * 7 + k, 3) * 1.4); + } + } + + // One of the hag's charms on a string from a bent pole: a skull (kind 0) or a blue bottle (kind 1). + function prop(ctx, v, x, lane, kind, p, i) { + const base = Y(LANE_Y[lane]); + const sway = Math.sin(v.clock / 600 + i * 1.7) * 0.45; + const top = base - PROP_UP - PROP_H - 3.2; + ctx.strokeStyle = WOOD; + ctx.lineWidth = 0.3; + seg(ctx, x + 3, base + 0.4, x + 3, top); + seg(ctx, x + 3, top, x + sway * 0.3, top - 0.4); + ctx.strokeStyle = "#8a7a5a"; + ctx.lineWidth = 0.1; + seg(ctx, x + sway * 0.3, top - 0.4, x + sway, base - PROP_UP - PROP_H - 0.2); + if (p.state === "broken") return; + const cy = base - PROP_UP - PROP_H / 2; + if (kind === 0) { + ctx.fillStyle = BONE; + disc(ctx, x + sway, cy - 0.2, 1.05); + ctx.fillRect(x + sway - 0.6, cy + 0.6, 1.2, 0.8); + ctx.fillStyle = "#14100c"; + ctx.fillRect(x + sway - 0.55, cy - 0.45, 0.4, 0.45); + ctx.fillRect(x + sway + 0.15, cy - 0.45, 0.4, 0.45); + } else { + ctx.fillStyle = "#4a8cc8"; + poly(ctx, [[x + sway - 0.4, cy - 1.2], [x + sway + 0.4, cy - 1.2], [x + sway + 0.4, cy - 0.4], [x + sway + 1.0, cy + 0.2], [x + sway + 1.0, cy + 1.2], [x + sway - 1.0, cy + 1.2], [x + sway - 1.0, cy + 0.2], [x + sway - 0.4, cy - 0.4]]); + ctx.fill(); + ctx.fillStyle = "rgba(255,255,255,0.45)"; + ctx.fillRect(x + sway - 0.7, cy + 0.1, 0.25, 0.9); + } + halo(ctx, x + sway, cy, 3, "rgba(190,230,255,0.8)", 0.22); + } + + // A gas pocket: a cluster of sickly bubbles rising over the lane; once shot, a cloud that spreads and thins. + function gasPocket(ctx, v, x, lane, g, i) { + const cy = Y(LANE_Y[lane] + GAS_UP + GAS_H / 2); + if (g.state === "spent") return; + if (g.state === "burst") { + const p = 1 - g.t / GAS_BURST_MS; + ctx.fillStyle = GAS; + for (let k = 0; k < 9; k++) { + ctx.globalAlpha = (1 - p) * 0.42; + disc(ctx, x + (rnd(k, 51) - 0.5) * (3 + p * 11), cy + (rnd(k, 52) - 0.6) * (2 + p * 4), 1.2 + p * 2.2); + } + ctx.globalAlpha = 1; + return; + } + halo(ctx, x, cy, 4.4, "rgba(200,240,100,0.9)", 0.3 + 0.1 * Math.sin(v.clock / 260 + i)); + for (let k = 0; k < 6; k++) { + const ph = ((v.clock / 1300 + rnd(i, k + 60)) % 1); + const bx = x + (rnd(i * 5 + k, 53) - 0.5) * GAS_W * 0.8; + const by = cy + GAS_H * 0.5 - ph * GAS_H; + ctx.globalAlpha = 0.85 * Math.sin(ph * Math.PI); + ctx.strokeStyle = GAS; + ctx.lineWidth = 0.14; + ctx.beginPath(); + ctx.arc(bx, by, 0.5 + rnd(i * 3 + k, 54) * 0.7, 0, TAU); + ctx.stroke(); + } + ctx.globalAlpha = 1; + } + + // A checkpoint: a stake across the channel with a black pennant and a gold star, lit once passed. + function checkpoint(ctx, v, x, passed) { + const top = Y(30); + ctx.fillStyle = WOOD; + ctx.fillRect(x - 0.3, top, 0.6, Y(WATER_Y) - top); + ctx.fillStyle = passed ? "#244a30" : "#10181a"; + poly(ctx, [[x + 0.3, top + 0.4], [x + 6, top + 0.4 + Math.sin(v.clock / 300) * 0.3], [x + 5, top + 3.4], [x + 6, top + 6.2], [x + 0.3, top + 6.2]]); + ctx.fill(); + ctx.fillStyle = passed ? "#7dffa0" : GOLD; + const sx = x + 3; + const sy = top + 3.2; + ctx.beginPath(); + for (let k = 0; k < 10; k++) { + const r = k % 2 ? 0.5 : 1.3; + ctx.lineTo(sx + Math.sin((k * Math.PI) / 5) * r, sy - Math.cos((k * Math.PI) / 5) * r); + } + ctx.closePath(); + ctx.fill(); + halo(ctx, sx, sy, 5, passed ? "rgba(125,255,160,0.8)" : "rgba(255,210,90,0.8)", 0.3); + } + + // The landing at the end of the channel: a plank pier on stilts with two lantern posts and the stilt shack's door. + function landing(ctx, v, x) { + const gy = Y(WATER_Y); + ctx.fillStyle = WOOD; + ctx.fillRect(x - 12, gy - 0.9, 28, 0.9); + ctx.fillStyle = WOOD_D; + for (let k = -3; k <= 3; k++) ctx.fillRect(x + k * 4, gy, 0.7, 4); + for (const px of [x - 6, x + 8]) { + ctx.fillStyle = WOOD; + ctx.fillRect(px - 0.4, gy - 8, 0.8, 7.1); + ctx.fillStyle = "#ffcf5a"; + ctx.globalAlpha = 0.8 + 0.15 * Math.sin(v.clock / 200 + px); + disc(ctx, px, gy - 8.6, 0.7); + ctx.globalAlpha = 1; + halo(ctx, px, gy - 8.6, 6, "rgba(255,200,90,0.9)", 0.35); + } + ctx.fillStyle = "#1c150c"; + ctx.fillRect(x + 1, gy - 12, 6, 11.1); + ctx.fillStyle = "#6a4a28"; + ctx.fillRect(x + 2.2, gy - 9.6, 3.6, 8.7); + ctx.fillStyle = "#ffcf5a"; + ctx.fillRect(x + 4.8, gy - 5, 0.5, 0.5); + poly(ctx, [[x, gy - 12], [x + 4, gy - 15.4], [x + 8, gy - 12]]); + ctx.fillStyle = "#2a2012"; + ctx.fill(); + } + + /* ------------------------------------------------------------------ the swarm */ + + // The leech swarm boiling in the wake: dark blobs and flicking tails just under the surface, `gap` units + // behind the boat, thicker and higher the closer it is, red eyes once it is close. + function swarm(ctx, v, c, x, base) { + const near = clamp(1 - (c.gap - WAKE_CATCH) / (GAP_MAX - WAKE_CATCH), 0, 1); + const sx = x - c.gap; + const n = 9 + Math.round(near * 16); + const boil = c.panic ? 1 : 0.35; + ctx.fillStyle = SWARM; + for (let k = 0; k < n; k++) { + const wob = Math.sin(v.clock / (110 + k * 17) + k * 2.3); + const bx = sx + (rnd(k, 71) - 0.5) * (6 + near * 10) + wob * 0.9 * boil; + const by = base + 0.6 - Math.abs(Math.sin(v.clock / (170 + k * 23) + k)) * (0.8 + near * 2.2) * boil; + ellipse(ctx, bx, by, 1.3 + rnd(k, 72) * 1.1, 0.55 + rnd(k, 73) * 0.4); + ctx.fill(); + if (c.panic && k % 3 === 0) { + ctx.fillStyle = "#ff4a3a"; + ctx.fillRect(bx + 0.3, by - 0.3, 0.32, 0.32); + ctx.fillStyle = SWARM; + } + } + ctx.strokeStyle = "rgba(150,200,190,0.5)"; + ctx.lineWidth = 0.14; + for (let k = 0; k < 4; k++) { + const p = (v.clock / 600 + k / 4) % 1; + ctx.globalAlpha = (1 - p) * (0.3 + near * 0.4); + ctx.beginPath(); + ctx.arc(sx + (k - 1.5) * 1.8, base + 0.2, 0.6 + p * 2.2, Math.PI, TAU); + ctx.stroke(); + } + ctx.globalAlpha = 1; + } + + /* --------------------------------------------------------------------- the boat */ + + // The boat's transform: at Planny's feet (the water under it), tilted nose up on the way up, a gentle bob. + function place(ctx, v, c, fn) { + const you = v.round.you; + const x = c.done ? c.restX : you.x; + const y = c.done ? WATER_Y : you.y; + const tilt = c.air ? clamp(c.vy / 320, -0.16, 0.16) : 0; + const bob = !c.done && !c.air ? Math.sin(v.clock / 260) * 0.12 : 0; + ctx.save(); + ctx.translate(x, Y(y) + bob); + ctx.rotate(-tilt); + fn(x); + ctx.restore(); + } + + // The back: the hull, the fan's cage on its mast with the blades turning, the spray it throws, the lantern. + function boatBack(ctx, v, c, x) { + const speed = clamp(c.v / 40, 0, 1.2); + // The spray and the wake behind the stern. + if (!c.done) { + for (let k = 0; k < 7; k++) { + const p = (v.clock / 480 + k / 7) % 1; + ctx.fillStyle = `rgba(190,225,215,${(1 - p) * 0.42 * speed})`; + disc(ctx, -9.5 - p * 8 * speed - 1, 0.1 - Math.sin(p * Math.PI) * (1 + speed * 1.4), 0.3 + p * 0.8); + } + ctx.strokeStyle = "rgba(190,225,215,0.35)"; + ctx.lineWidth = 0.16; + seg(ctx, -8, 0.15, -8 - 12 * speed, 0.3); + seg(ctx, -7, 0.55, -7 - 8 * speed, 0.7); + } + ctx.fillStyle = "rgba(0,0,0,0.35)"; + ellipse(ctx, -2, 0.1, 8, 0.4); + ctx.fill(); + // The flat hull: a long dark tub with a rusted patch and a pale gunwale line. + ctx.fillStyle = HULL; + poly(ctx, [[-8.6, -0.1], [-8.6, -2.1], [-7.2, -2.7], [4.6, -2.7], [6.2, -1.9], [6.4, -0.1]]); + ctx.fill(); + ctx.fillStyle = "#1c2626"; + ctx.fillRect(-8.6, -0.7, 15, 0.7); + ctx.fillStyle = RUST; + ctx.fillRect(-3.8, -2.0, 2.1, 0.9); + ctx.fillStyle = HULL_LIT; + ctx.fillRect(-7.2, -2.8, 11.8, 0.3); + // The fan's mast and cage at the stern, the blades a flicker of spokes. + ctx.fillStyle = "#2a3030"; + ctx.fillRect(-8.4, -7.4, 0.8, 4.8); + ctx.fillRect(-9.2, -2.9, 2.4, 0.5); + ctx.strokeStyle = "#7a8a86"; + ctx.lineWidth = 0.14; + ctx.beginPath(); + ctx.arc(-8, -6.1, 2.4, 0, TAU); + ctx.stroke(); + const a = c.done || c.stall > 0 ? 0 : v.clock / 28; + ctx.lineWidth = 0.22; + for (let k = 0; k < 3; k++) seg(ctx, -8, -6.1, -8 + Math.cos(a + (k * TAU) / 3) * 2.2 * 0.3, -6.1 + Math.sin(a + (k * TAU) / 3) * 2.2); + ctx.fillStyle = "#4a5a58"; + disc(ctx, -8, -6.1, 0.35); + if (c.stall > 0 && !c.done) { + ctx.fillStyle = MUD; + disc(ctx, -8, -6.1, 1.1); + ctx.fillStyle = "rgba(60,46,28,0.7)"; + disc(ctx, -9.2, -4.6, 0.7); + } + // A lantern on a post at the bow, glowing. + ctx.fillStyle = "#2a3030"; + ctx.fillRect(5.2, -4.8, 0.4, 2.2); + ctx.fillStyle = "#e8ffb0"; + disc(ctx, 5.4, -5.1, 0.6); + halo(ctx, 5.4, -5.1, 7, "rgba(210,255,150,0.9)", 0.4); + } + + // The front: the gunwale over Planny's legs and the low windshield. + function boatFront(ctx) { + ctx.fillStyle = HULL; + poly(ctx, [[-2.6, -0.4], [4.4, -0.4], [4.4, -2.1], [3.6, -2.4], [-2.6, -2.4]]); + ctx.fill(); + ctx.fillStyle = HULL_LIT; + ctx.fillRect(-2.5, -2.45, 6.1, 0.22); + ctx.fillStyle = "#1c2626"; + ctx.fillRect(-2.6, -0.9, 7, 0.5); + ctx.strokeStyle = "#7a8a86"; + ctx.lineWidth = 0.22; + seg(ctx, 3.6, -2.4, 3.2, -4.4); + ctx.fillStyle = "rgba(150,200,210,0.2)"; + poly(ctx, [[3.4, -2.5], [3.1, -4.2], [2.2, -4.2], [2.5, -2.5]]); + ctx.fill(); + } + + /* ----------------------------------------------------------------- mist and signs */ + + // A see-through glyph over an obstacle: chevrons or a crosshair, and (for the first few) the word. + function glyph(ctx, v, t) { + const col = ANSWER_COLORS[t.answer]; + const pulse = 0.85 + 0.15 * Math.sin(v.clock / 260 + t.lead); + const cy = Math.min(FH - 7, FH - t.up) + Math.sin(v.clock / 260 + t.lead) * 0.35; + ctx.save(); + ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA; + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + if (t.answer === "SHOOT") { + for (const [w, c] of [[1.2, "rgba(2,8,10,0.8)"], [0.5, col]]) { + ctx.strokeStyle = c; + ctx.lineWidth = w; + ctx.beginPath(); + ctx.arc(t.x, cy - 1.2, 1.5, 0, TAU); + ctx.stroke(); + seg(ctx, t.x - 2.4, cy - 1.2, t.x - 0.6, cy - 1.2); + seg(ctx, t.x + 0.6, cy - 1.2, t.x + 2.4, cy - 1.2); + seg(ctx, t.x, cy - 3.6, t.x, cy - 1.8); + seg(ctx, t.x, cy - 0.6, t.x, cy + 1.2); + } + if (t.words) label(ctx, "SHOOT", t.x, cy + 2.4, 2.1, col, "center"); + } else { + const up = t.answer === "JUMP"; + const dir = up ? -1 : 1; + const ay = cy + (up ? -2.6 : 2.6); + for (const [w, c] of [[1.3, "rgba(2,8,10,0.8)"], [0.6, col]]) { + ctx.strokeStyle = c; + ctx.lineWidth = w; + for (let k = 0; k < 2; k++) { + const oy = ay + (k - 0.5) * 1.5 * dir - dir * 0.2; + ctx.beginPath(); + ctx.moveTo(t.x - 1.7, oy - dir * 0.9); + ctx.lineTo(t.x, oy + dir * 0.9); + ctx.lineTo(t.x + 1.7, oy - dir * 0.9); + ctx.stroke(); + } + } + if (t.words) label(ctx, t.answer, t.x, cy + (up ? 1.2 : -1.2), 2.3, col, "center"); + } + ctx.restore(); + } + + // The wake meter across the top (the swarm at one end, the boat at the other, red as they close, + // THEY ARE CLOSE inside PANIC_ON) and the fan's clog gauge beside it. + function gauges(ctx, v, c, cam) { + const x = cam + 2.4; + const y = 3.2; + const W = 34; + const p = clamp((c.gap - WAKE_CATCH) / (GAP_MAX - WAKE_CATCH), 0, 1); + ctx.fillStyle = "rgba(2,8,10,0.72)"; + ctx.fillRect(x - 0.6, y - 1, W + 1.2, 8.2); + ctx.fillStyle = "#16222a"; + ctx.fillRect(x + 6, y + 0.2, W - 12, 1.7); + const close = c.gap < PANIC_ON; + const pulse = close ? 0.65 + 0.35 * Math.sin(v.clock / 110) : 1; + ctx.globalAlpha = pulse; + ctx.fillStyle = close ? "#ff4a3a" : p < 0.55 ? "#ffb02e" : "#7dffa0"; + ctx.fillRect(x + 6, y + 0.2, (W - 12) * p, 1.7); + ctx.globalAlpha = 1; + ctx.fillStyle = SWARM; + ellipse(ctx, x + 2.4, y + 1.1, 1.6, 0.75); + ctx.fill(); + if (close) { + ctx.fillStyle = "#ff4a3a"; + ctx.fillRect(x + 2.9, y + 0.7, 0.3, 0.3); + } + ctx.fillStyle = HULL_LIT; + poly(ctx, [[x + W - 5, y + 1.8], [x + W - 4.4, y + 0.5], [x + W - 1.4, y + 0.5], [x + W - 0.6, y + 1.8]]); + ctx.fill(); + label(ctx, close ? "THEY ARE CLOSE" : "WAKE", x + 6, y + 4, 1.5, close ? "#ff6a6a" : "#bcd6d0", "left"); + // The clog gauge. + const q = c.clog / CLOG_MAX; + const hot = c.clog >= CLOG_WARN || c.stall > 0; + ctx.fillStyle = "#16222a"; + ctx.fillRect(x + 6, y + 5.3, W - 12, 1.3); + ctx.globalAlpha = hot ? 0.6 + 0.4 * Math.sin(v.clock / 100) : 1; + ctx.fillStyle = hot ? "#ff5a3a" : q > 0.4 ? "#ffb02e" : "#9ac8b8"; + ctx.fillRect(x + 6, y + 5.3, (W - 12) * q, 1.3); + ctx.globalAlpha = 1; + label(ctx, c.stall > 0 ? "STALLED" : "FAN", x, y + 6.6, 1.3, c.stall > 0 ? "#ff6a6a" : "#bcd6d0", "left"); + } + + /* ------------------------------------------------------------------- the room */ + + const lanePass = (ctx, v, R, c, cam, lane) => { + const lo = cam - 12; + const hi = cam + FW + 12; + R.snags.forEach(([x, l], i) => { + if (l === lane && x > lo && x < hi) snag(ctx, x, l, i); + }); + R.knees.forEach(([x, l], i) => { + if (l === lane && x > lo && x < hi) knees(ctx, x, l, i); + }); + R.props.forEach(([x, l, kind], i) => { + if (l === lane && x > lo && x < hi) prop(ctx, v, x, l, kind, c.props[i], i); + }); + R.gas.forEach(([x, l], i) => { + if (l === lane && x > lo && x < hi) gasPocket(ctx, v, x, l, c.gas[i], i); + }); + }; + + // The whole world, over the still layers: sky, trees, water and flats, the things by lane, the boat, the swarm. + function moving(ctx, v, cam) { + const R = ride(v); + const c = runner(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + sky(ctx, v, cam); + trees(ctx, cam, 0.14, Y(FLATS_Y + 1), 0.8, "#0a161a", 3); + trees(ctx, cam, 0.3, Y(FLATS_Y + 0.6), 1.15, "#0e1e22", 7); + mist(ctx, v, cam, 0.16); + channel(ctx, v, cam, R); + R.banks.forEach(([a, b]) => { + if (b > cam - 4 && a < cam + FW + 4) bankPosts(ctx, v, a, b); + }); + R.checks.forEach((x, i) => { + if (x > cam - 8 && x < cam + FW + 8) checkpoint(ctx, v, x, i <= c.check); + }); + if (R.finish > cam - 20 && R.finish < cam + FW + 20) landing(ctx, v, R.finish + 16); + const here = laneNow(c); + const inWater = c.done || here === 0; + lanePass(ctx, v, R, c, cam, 1); + if (!inWater) swarm(ctx, v, c, v.round.you.x, Y(baseOf(c))); + if (!inWater) place(ctx, v, c, (x) => boatBack(ctx, v, c, x)); + lanePass(ctx, v, R, c, cam, 0); + if (inWater && !c.done) swarm(ctx, v, c, v.round.you.x, Y(baseOf(c))); + if (inWater) place(ctx, v, c, (x) => boatBack(ctx, v, c, x)); + // A landing's splash. + const fx = v.fx; + const land = fx && fx.bogboatLand !== undefined ? fx.clock - fx.bogboatLand.t0 : 1e9; + if (land < 380) { + const p = land / 380; + ctx.fillStyle = `rgba(170,210,200,${(1 - p) * 0.7})`; + for (let k = 0; k < 8; k++) disc(ctx, v.round.you.x + (k - 3.5) * 1.1 * (0.6 + p * 1.5), Y(baseOf(c)) - 0.3 - p * (0.8 + rnd(k, 4) * 1.4), 0.3 + p * 0.3); + } + } + + // In front of Planny: the gunwale, the lows (veils and limbs), the splinters, the mist, the signs, the gauges. + function front(ctx, v) { + const R = ride(v); + const c = runner(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + const round = v.round; + const cam = Math.round(round.camX * 8) / 8; + place(ctx, v, c, () => boatFront(ctx)); + R.veils.forEach(([x0, x1, lane], i) => { + if (x1 >= cam - 10 && x0 <= cam + FW + 10) veil(ctx, v, x0, x1, lane, i); + }); + R.limbs.forEach(([x0, x1, lane], i) => { + if (x1 >= cam - 10 && x0 <= cam + FW + 10) limb(ctx, v, x0, x1, lane, i); + }); + mist(ctx, v, cam, 0.12); + if (!c.done) for (const t of telegraphs(R, round.you.x, laneNow(c))) glyph(ctx, v, t); + const bits = v.fx && v.fx.bogboatBits; + if (bits) { + for (const b of bits) { + const t = (v.fx.clock - b.t0) / 1000; + if (t < 0 || t > 0.9) continue; + ctx.save(); + ctx.translate(b.x + b.vx * t, FH - (b.y + b.vy * t - 30 * t * t)); + ctx.rotate(b.rot + b.vr * t); + ctx.globalAlpha = clamp(1.6 - t * 1.6, 0, 1); + ctx.fillStyle = b.c; + ctx.fillRect(-b.w / 2, -0.12, b.w, 0.24); + ctx.restore(); + } + ctx.globalAlpha = 1; + } + gauges(ctx, v, c, cam); + } + + const dim = () => 0; + + /* -------------------------------------------------------------- lights */ + + function lights(v, add) { + const R = ride(v); + const c = runner(v); + if (!R || !c) return; + const round = v.round; + const you = round.you; + const lo = round.camX - 10; + const hi = round.camX + FW + 10; + // The bow lantern's pool on the water ahead and its warmth over the boat. + add(you.x + 6, you.y + 2.4, 14, 0.7); + add(you.x - 3, you.y + 3, 8, 0.4); + R.checks.forEach((x, i) => { + if (x > lo && x < hi) add(x + 3, 26, 9, i <= c.check ? 0.55 : 0.4); + }); + R.banks.forEach(([a, b]) => { + if (b > lo && a < hi) { + add(a - 0.4, WATER_Y + 5, 5, 0.35); + add(b + 0.4, WATER_Y + 5, 5, 0.35); + } + }); + R.gas.forEach(([x, lane], i) => { + if (x > lo && x < hi && c.gas[i].state === "up") add(x, LANE_Y[lane] + GAS_UP + 1.6, 5, 0.4); + }); + if (R.finish > lo - 20 && R.finish < hi) add(R.finish + 16, 18, 14, 0.6); + } + + /* -------------------------------------------------------------- events */ + + // A throttle on a repeating cue. + function gateOnce(fx, key, ms) { + if ((fx[key] || 0) > fx.clock) return false; + fx[key] = fx.clock + ms; + return true; + } + // Splinters of wood and weed flying out of a spot. + function splinter(fx, x, y, colors) { + fx.bogboatBits = (fx.bogboatBits || []).filter((b) => fx.clock - b.t0 < 1000); + for (let k = 0; k < 9; k++) fx.bogboatBits.push({ x, y, t0: fx.clock, vx: (rnd(k, 1) - 0.5) * 22, vy: 8 + rnd(k, 2) * 14, rot: rnd(k, 3) * TAU, vr: (rnd(k, 4) - 0.5) * 22, w: 0.5 + rnd(k, 5) * 0.9, c: colors[k % colors.length] }); + } + + // What the pack's events look and sound like; true when the event is its own. Each of its + // sounds plays once, from EVENT_VOICE. + function react(e, k) { + const { shake, flash, burst, float, ring, fx } = k; + const voice = EVENT_VOICE[e.type]; + if (!voice) return false; + if (e.type === "bogboatDuck" && !gateOnce(fx, "bogboatDuckMs", 160)) return true; + say(k.tone, voice[0], voice[1], 0.5); + const SPRAY = "#9cc4b8"; + switch (e.type) { + case "bogboatJump": + burst(e.x, e.y, SPRAY, 5, 7, 300); + break; + case "bogboatLand": + fx.bogboatLand = { t0: fx.clock, big: Boolean(e.big) }; + burst(e.x, e.y, SPRAY, e.big ? 14 : 6, e.big ? 12 : 8, 360); + if (e.big) shake(180, 0.45); + break; + case "bogboatSwitch": + burst(e.x, e.y, MUD_LIT, 6, 8, 320); + float(e.x, e.y + 6, e.to ? "Flats" : "Channel", "#7dffa0", 2); + break; + case "bogboatCrash": + shake(320, 1); + flash("#b8e0d0", 200); + burst(e.x, e.y + 1, e.what === "veil" ? MOSS : "#6a5a3a", 18, 17, 520); + burst(e.x, e.y + 1, SPRAY, 8, 14, 360); + splinter(fx, e.x, e.y + 2, e.what === "veil" ? [MOSS, MOSS_D] : ["#2a1e14", "#4a3c28", "#5a5a48"]); + break; + case "bogboatCheck": + float(e.x, e.y + 5, "Checkpoint", GOLD, 2.2); + ring(e.x, e.y + 3, "#7dffa0", 1, 8, 500); + break; + case "bogboatFinish": + shake(240, 0.6); + burst(e.x, e.y, SPRAY, 14, 13, 560); + float(e.x, e.y + 6, "Made it!", GOLD, 2.6); + break; + case "bogboatPanic": + flash("#102018", 220); + float(e.x, e.y + 8, "They are close!", "#ff6a6a", 2.4); + break; + case "bogboatCatch": + shake(300, 0.9); + flash("#3a0a0a", 240); + burst(e.x - 8, e.y, SWARM, 14, 12, 460); + float(e.x, e.y + 7, "Swarmed!", "#ff6a6a", 2.4); + break; + case "bogboatClog": + float(e.x, e.y + 8, "The fan is clogging", "#ffb02e", 2.2); + break; + case "bogboatStall": + shake(200, 0.5); + burst(e.x - 8, e.y + 3, MUD, 10, 9, 420); + float(e.x, e.y + 8, "Stalled!", "#ff6a6a", 2.4); + break; + case "bogboatGas": + flash("#e8ff9a", 140); + burst(e.x, e.y, GAS, 14, 13, 520); + ring(e.x, e.y, GAS, 1, 9, 420); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + case "bogboatProp": + burst(e.x, e.y, e.kind ? "#4a8cc8" : BONE, 12, 12, 440); + splinter(fx, e.x, e.y, e.kind ? ["#4a8cc8", "#9cd0ff"] : [BONE, "#8a7a5a"]); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + default: + break; + } + return true; + } + + return freeze({ + looks: LOOKS, + backdrop, + ground, + shelf, + front, + moving, + dim, + monsters: freeze({}), + bosses: freeze({}), + missiles: freeze({}), + hazards: freeze({}), + powers: freeze({}), + lights, + react, + }); +} diff --git a/src/web-console/public/activities/ghoul-bogboat.js b/src/web-console/public/activities/ghoul-bogboat.js new file mode 100644 index 0000000..c39705b --- /dev/null +++ b/src/web-console/public/activities/ghoul-bogboat.js @@ -0,0 +1,420 @@ +// Plan2Code Web Console - Ghoul Rush's Bog Runner, its rules: Gallows Bog's bonus round. YOU skim a fan boat down a black channel through the swamp at night, with something swimming in your wake: jump the sunken snags and cypress knees, duck the moss veils and low limbs, shoot the hag's charms for points and the gas pockets for a cover burst, and switch between the open channel and the mud flats at the banks, as a stage pack that ghoul.js plugs in. +// +// Modeled on the Midnight Hearse (ghoul-hearse.js: read its header first) for the lanes and +// on the Torch Mob (ghoul-wagon.js) for the pursuit meter, and, like them, handed a kit `k` +// of ghoul.js's own helpers, so this file never imports ghoul.js. Pack fields used: `ride` +// (a hook that moves Planny himself, so no key walks him), `place` (Planny put down in a +// room: a room set up or a respawn) and `target` (a bolt strikes something that is no +// monster: a charm, a gas pocket). It adds no monster, boss or hazard kind, so there is +// nothing to merge by name, and it draws NO random number. Its state is `round.runner` +// (the shared slot for a rolling bonus ride, with `id: "bogboat"`; null in any other room) +// and the room's `ride.runner` is "bogboat". Every event it puts on the field starts with +// `bogboat`. +// +// THE TWIST: THE WAKE. A swarm of leeches boils up in the fan's wake, `gap` units back +// (GAP_START at the start, never over GAP_MAX). It swims at WAKE_V, the boat at its own +// speed: clean riding on open water (BOGBOAT_V) wins ground and everything else loses it: +// DOWN held (an ease of the throttle, and a duck) holds the boat at EASE_V, the mud flats +// slow it (FLATS_V, and FLATS_EASE_V when eased), a fan stalled in the mud stops it dead, +// and a hit shoves the swarm HIT_CLOSE closer. A gas pocket shot pushes it back GAS_PUSH. +// Inside PANIC_ON the swarm boils (the art shows it and the wake meter reads THEY ARE +// CLOSE) until PANIC_OFF. At WAKE_CATCH it has you: a heart (cause "wake"), and it falls +// back to WAKE_FALLBACK. +// +// THE ROOM (spec.ride, see ghoul-rooms.js): the ground is one flat floor under the water; +// there are two LANES, the open channel (lane 0, LANE_Y[0]) and the mud flats beside it +// (lane 1, LANE_Y[1], a raised bank), and every obstacle stands in one of them, [x, lane, +// ...]: +// +// - `banks` [x0, x1]: the banks, where the channel's edge shelves down into the flats; +// inside one, LEFT puts the boat in the channel and RIGHT on the flats (SWITCH_MS to +// hop the shelf). The art draws them as mud ramps. Nothing stands in a lane near one. +// - `snags` [x, lane]: a sunken log, SNAG_W by SNAG_H: jump (cause "snag"). +// - `knees` [x, lane]: a cluster of cypress knees, KNEE_W by KNEE_H: jump (cause "knee"). +// - `veils` [x0, x1, lane]: a curtain of moss, its underside LOW_Y over the lane: duck +// (cause "veil"). +// - `limbs` [x0, x1, lane]: a low cypress limb, its underside LOW_Y over the lane: duck +// (cause "limb"). +// - `props` [x, lane, kind]: one of the hag's charms (kind 0 a skull on a string, kind 1 +// a blue bottle) hung at chest height. It never hurts; shoot it (one bolt) for +// PROP_POINTS and an act. +// - `gas` [x, lane]: a pocket of marsh gas bubbling up. It never hurts; shoot it for +// GAS_POINTS, an act and a cover burst that pushes the wake back GAS_PUSH. +// - `checks` (x positions of the checkpoints), `finish` (where the ride ends: the boat +// cuts its fan and Planny steps out to the door) and `time` (the room's clock, ms). +// +// THE BOAT (`round.runner`): { id, room, check, lane (where it is bound), from (the lane +// it left), swMs (switch time left), h (height over the lane), air, vy, v, gap, panic, +// clog, stall, faced, props, gas, done, restX, ... }. It runs at the speed its lane and +// throttle ask (eased toward it at RELAX a second); UP jumps at JUMP_V against GRAVITY +// (about 13 high, 0.75 s), DOWN ducks and eases; a switch cannot be made in the air and a +// jump or a duck cannot be made in one. A bolt flies level. +// +// THE CLOG: on the flats the fan sucks mud: the `clog` gauge rises CLOG_RISE a second at +// full throttle and cools CLOG_COOL a second eased (and on the channel). At CLOG_WARN the +// art flashes it; at CLOG_MAX the fan STALLS for STALL_MS (the boat coasts to a stop and +// the wake gains), then starts again at CLOG_RESTART. +// +// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the boat +// rolls on, Planny blinking safe BONUS_SAFE_MS; the last heart gone ends the round with +// nothing, at once. Causes: "snag", "knee", "veil", "limb", "wake". The grade's +// `perf.total` is the obstacles the boat FACED (passed in their lane; a lane switched away +// from is dodged and not counted, a catch adds one of its own), each id once in +// `perf.hits` if it ever cost a heart. Shooting a charm or a gas pocket counts for +// `perf.acts` (the goal is ACTS_GOAL, 8 of them) and the points below. The steady die is a +// swarm that never boiled (the wake never reached PANIC_ON). +// +// Checkpoints are passed at their x (`bogboatCheck`); a restart after the last heart goes +// back to the last one passed (that ends the round, as the sled's does). +// +// WHAT THE ART READS: `spec.ride` (above), `round.runner` { lane, from, swMs, h, air, v, +// gap, panic, clog, stall, done, restX, check, props: [{ state "up"|"broken" }], gas: [{ +// state "up"|"burst"|"spent", t }] }, `round.you` (`state`, `vy`, `ducking`), the events in +// EVENTS. + +const freeze = (o) => Object.freeze(o); +const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v)); + +export const MONSTERS = freeze({}); + +// Every event this pack puts on the field, for the art and the sounds to answer. +export const EVENTS = freeze([ + "bogboatJump", "bogboatLand", "bogboatDuck", "bogboatSwitch", "bogboatCrash", "bogboatCheck", "bogboatFinish", + "bogboatPanic", "bogboatCatch", "bogboatClog", "bogboatStall", "bogboatGas", "bogboatProp", +]); + +// The boat. Speeds are units across a second, GRAVITY units a second squared. +export const BOGBOAT_V = 40; +export const EASE_V = 24; +export const FLATS_V = 28; +export const FLATS_EASE_V = 22; +export const RELAX = 5; +export const JUMP_V = 74; +export const GRAVITY = 200; +export const BIG_LAND = 9; +export const LANE_Y = freeze([9, 15]); +export const SWITCH_MS = 360; +export const SWITCH_HOP = 1.6; +export const CAM_AHEAD = 12; +// Obstacles. +export const SNAG_W = 3.2; +export const SNAG_H = 3.8; +export const KNEE_W = 4.6; +export const KNEE_H = 2.4; +export const LOW_Y = 3.0; +export const PROP_W = 2.2; +export const PROP_H = 2.4; +export const PROP_UP = 1.6; +export const GAS_W = 3.6; +export const GAS_H = 3.2; +export const GAS_UP = 1.2; +export const GAS_BURST_MS = 700; +export const PROP_POINTS = 60; +export const GAS_POINTS = 90; +const SHOT_R = 0.5; +// The wake. +export const WAKE_V = 28; +export const GAP_START = 28; +export const GAP_MAX = 36; +export const WAKE_CATCH = 8; +export const WAKE_FALLBACK = 24; +export const PANIC_ON = 18; +export const PANIC_OFF = 22; +export const HIT_CLOSE = 8; +export const GAS_PUSH = 8; +// The clog. +export const CLOG_MAX = 100; +export const CLOG_WARN = 70; +export const CLOG_RISE = 30; +export const CLOG_COOL = 40; +export const CLOG_RESTART = 35; +export const STALL_MS = 1400; +// The shots at things (charms, gas pockets) worth a die. +export const ACTS_GOAL = 8; + +const mine = (round) => (round.runner && round.runner.id === "bogboat" ? round.runner : null); +const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H); +const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0; +const smooth = (p) => p * p * (3 - 2 * p); + +// The lane the boat counts as being in: the one it left until half way through a switch. +export const laneNow = (c) => (c.swMs > 0 && 1 - c.swMs / SWITCH_MS < 0.5 ? c.from : c.lane); +// The height of the water under the boat (its lane's, eased across a switch, with a little hop). +export function baseOf(c) { + if (c.swMs <= 0) return LANE_Y[c.lane]; + const p = 1 - c.swMs / SWITCH_MS; + return LANE_Y[c.from] + (LANE_Y[c.lane] - LANE_Y[c.from]) * smooth(p) + Math.sin(p * Math.PI) * SWITCH_HOP; +} + +// Notes for a bonus round that obstacle `id` was faced (counted for the grade) and, with +// `cost`, that it cost a heart (once each). +function face(round, c, id, cost = false) { + const b = round.bonusRound; + if (!b) return; + if (!c.faced[id]) { + c.faced[id] = true; + b.perf.total++; + } + if (cost && !b.perf.hits.includes(id)) b.perf.hits.push(id); +} + +/* -------------------------------------------------------------- placing */ + +// A fresh set of the room's things, each charm hanging and each pocket full. What was shot +// stays shot (`old`, the boat of an earlier try in the same room). +function things(R, old) { + const was = (list, i, state) => (old && old[list] && old[list][i] && old[list][i].state === state ? state : null); + return { + props: R.props.map((p, i) => ({ state: was("props", i, "broken") || "up" })), + gas: R.gas.map((g, i) => ({ state: was("gas", i, "spent") || was("gas", i, "burst") ? "spent" : "up", t: 0 })), + }; +} + +// Planny put down in the room: at the helm at the start of a ride, or at the last +// checkpoint passed after the last heart (the same room). +function place(round, k) { + const R = round.spec.ride; + // (The Cart's `place` runs first, leaves a ride with a `runner` alone and has already zeroed `round.camLead`.) + if (!R || R.runner !== "bogboat") { + if (mine(round)) round.runner = null; + return; + } + const old = mine(round); + const again = old && old.room === round.room; + const check = again ? old.check : -1; + const you = round.you; + const x = check >= 0 ? R.checks[check] : round.spec.start; + Object.assign(you, { x, y: LANE_Y[0], vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 }); + round.runner = { + id: "bogboat", room: round.room, check, lane: 0, from: 0, swMs: 0, h: 0, vy: 0, air: false, peak: 0, v: BOGBOAT_V, + gap: GAP_START, panic: false, panicked: again ? old.panicked : false, clog: 0, warned: false, stall: 0, + faced: again ? old.faced : {}, catches: again ? old.catches : 0, done: false, restX: 0, ...things(R, again ? old : null), + }; + round.camLead = CAM_AHEAD; + const b = round.bonusRound; + if (b) { + b.perf.goal = ACTS_GOAL; + if (!again) b.perf.total = 0; + if (round.runner.panicked) b.perf.steady = false; + } +} + +/* ------------------------------------------------------------ the ride */ + +// The boat's motion for one slice. Returns true once it has moved Planny (every slice of +// a ride); false outside a ride and once he has stepped out. +function ride(round, ms, k) { + const R = round.spec.ride; + const c = mine(round); + if (!R || R.runner !== "bogboat" || !c || c.done) return false; + const you = round.you; + const inp = round.input; + const dt = ms / 1000; + const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra }); + if (you.x >= R.finish) return finish(round, c, R, k); + // The throttle: the lane and DOWN set the speed it eases toward, a stalled fan none. + const ease = Boolean(inp.down) && !c.air; + const flats = c.lane === 1; + const target = c.stall > 0 ? 0 : flats ? (ease ? FLATS_EASE_V : FLATS_V) : ease ? EASE_V : BOGBOAT_V; + c.v = c.stall > 0 && c.v < 0.5 ? 0 : c.v + (target - c.v) * Math.min(1, RELAX * dt); + you.x += c.v * dt; + // The banks: LEFT is the channel, RIGHT the flats. + const want = inp.left && !inp.right ? 0 : inp.right && !inp.left ? 1 : -1; + const bank = R.banks.some(([a, b]) => you.x >= a && you.x <= b); + if (bank && !c.air && c.swMs <= 0 && want >= 0 && want !== c.lane) startSwitch(c, want, ev, you); + if (c.swMs > 0) { + c.swMs = Math.max(0, c.swMs - ms); + you.ducking = false; + you.state = "run"; + you.vy = 0; + } else { + // On the water: jump, duck, or in the air. + const jump = inp.jump > 0; + if (!c.air && jump) { + inp.jump = 0; + c.air = true; + c.h = 0.001; + c.vy = JUMP_V; + c.peak = 0; + you.ducking = false; + ev("bogboatJump"); + } else if (!c.air) { + const duck = Boolean(inp.down); + if (duck && !you.ducking) ev("bogboatDuck"); + you.ducking = duck; + } + if (c.air) { + c.vy -= GRAVITY * dt; + c.h += c.vy * dt; + c.peak = Math.max(c.peak, c.h); + you.ducking = false; + if (c.h <= 0) { + ev("bogboatLand", { big: c.peak >= BIG_LAND }); + Object.assign(c, { air: false, h: 0, vy: 0 }); + } + } + you.state = c.air ? "air" : "run"; + you.vy = c.air ? c.vy : 0; + } + you.y = baseOf(c) + (c.swMs > 0 ? 0 : c.h); + // A press nothing took waits a moment for a landing, then goes. + if (inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms); + while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) { + c.check++; + ev("bogboatCheck", { n: c.check + 1 }); + } + round.camLead = CAM_AHEAD; + clogging(round, c, ms, ev, ease); + if (obstacles(round, c, R, k)) return true; + wake(round, c, ms, ev, k); + return true; +} + +function startSwitch(c, to, ev, you) { + Object.assign(c, { from: c.lane, lane: to, swMs: SWITCH_MS, air: false, h: 0, vy: 0 }); + ev("bogboatSwitch", { to, y: LANE_Y[to], x: you.x }); +} + +// The ride is over: the boat cuts its fan at the finish, the door opens, Planny steps out. +function finish(round, c, R, k) { + const you = round.you; + c.done = true; + c.restX = you.x; + Object.assign(c, { air: false, h: 0, vy: 0, swMs: 0 }); + Object.assign(you, { y: k.groundAt(round.spec, you.x), vy: 0, state: "run", shelf: -1, ducking: false }); + round.hasKey = true; + round.camLead = 0; + round.events.push({ type: "bogboatFinish", x: you.x, y: you.y }); + return false; +} + +// The fan on the flats: mud clogs it while it runs full, an ease or open water clears it, +// and a clogged fan stalls the boat for STALL_MS. +function clogging(round, c, ms, ev, ease) { + const dt = ms / 1000; + if (c.stall > 0) { + c.stall -= ms; + if (c.stall <= 0) Object.assign(c, { stall: 0, clog: CLOG_RESTART, warned: false }); + return; + } + const flats = laneNow(c) === 1 && c.swMs <= 0; + c.clog = clamp(c.clog + (flats && !ease ? CLOG_RISE : -CLOG_COOL) * dt, 0, CLOG_MAX); + if (c.clog >= CLOG_WARN && !c.warned) { + c.warned = true; + ev("bogboatClog"); + } else if (c.clog < CLOG_WARN - 15) c.warned = false; + if (c.clog >= CLOG_MAX) { + c.stall = STALL_MS; + ev("bogboatStall"); + } +} + +// A heart lost on obstacle `id`: it was faced and cost, the wake closes, and the crash is +// an event. Returns true. +function cost(round, c, id, what, x) { + face(round, c, id, true); + c.gap = Math.max(WAKE_CATCH + 1, c.gap - HIT_CLOSE); + round.events.push({ type: "bogboatCrash", what, x, y: round.you.y }); + return true; +} + +// What the boat runs into: a snag, cypress knees, a moss veil or a limb. Returns whether it +// cost a heart. (Nothing counts while it hops between lanes: the banks keep their +// neighborhood clear.) +function obstacles(round, c, R, k) { + const you = round.you; + if (c.swMs > 0) return false; + const lane = c.lane; + const base = LANE_Y[lane]; + const hh = duckH(k, you); + const seen = (id, x) => { + if (you.x >= x && !c.faced[id]) face(round, c, id); + }; + for (const [i, [x, l]] of R.snags.entries()) { + if (l !== lane) continue; + seen(`s${i}`, x); + if (Math.abs(you.x - x) <= 6 && boxHit(k, you, x, base, SNAG_W, SNAG_H) && k.struck(round, "snag")) return cost(round, c, `s${i}`, "snag", x); + } + for (const [i, [x, l]] of R.knees.entries()) { + if (l !== lane) continue; + seen(`k${i}`, x); + if (Math.abs(you.x - x) <= 6 && boxHit(k, you, x, base, KNEE_W, KNEE_H) && k.struck(round, "knee")) return cost(round, c, `k${i}`, "knee", x); + } + for (const [list, key, cause, what] of [[R.veils, "v", "veil", "veil"], [R.limbs, "l", "limb", "limb"]]) { + for (const [i, [x0, x1, l]] of list.entries()) { + if (l !== lane) continue; + seen(`${key}${i}`, (x0 + x1) / 2); + if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > base + LOW_Y && k.struck(round, cause)) return cost(round, c, `${key}${i}`, what, you.x); + } + } + return false; +} + +// The wake: its gap, the panic, the grade's steady die, and a catch at WAKE_CATCH. +function wake(round, c, ms, ev, k) { + const dt = ms / 1000; + c.gap = clamp(c.gap + (c.v - WAKE_V) * dt, 0, GAP_MAX); + if (!c.panic && c.gap < PANIC_ON) { + c.panic = true; + c.panicked = true; + if (round.bonusRound) round.bonusRound.perf.steady = false; + ev("bogboatPanic"); + } else if (c.panic && c.gap >= PANIC_OFF) c.panic = false; + for (const g of c.gas) if (g.state === "burst" && (g.t -= ms) <= 0) g.state = "spent"; + if (c.gap > WAKE_CATCH) return; + c.gap = WAKE_FALLBACK; + c.panic = false; + c.catches++; + face(round, c, `w${c.catches}`, true); + ev("bogboatCatch"); + k.struck(round, "wake"); +} + +/* ------------------------------------------------------------- targets */ + +// A bolt into something to shoot: a charm, a gas pocket. True when one took it (the bolt is +// spent). +function bogboatShot(round, s) { + const R = round.spec.ride; + const c = mine(round); + if (!R || R.runner !== "bogboat" || !c) return false; + const hit = (x, y0, w, h) => Math.abs(s.x - x) <= w / 2 + SHOT_R && s.y >= y0 - SHOT_R && s.y <= y0 + h + SHOT_R; + const score = (n) => { + round.score += n; + if (round.bonusRound) round.bonusRound.perf.acts++; + }; + for (let i = 0; i < R.gas.length; i++) { + const g = c.gas[i]; + const [x, lane] = R.gas[i]; + if (g.state !== "up" || !hit(x, LANE_Y[lane] + GAS_UP, GAS_W, GAS_H)) continue; + Object.assign(g, { state: "burst", t: GAS_BURST_MS }); + c.gap = Math.min(GAP_MAX, c.gap + GAS_PUSH); + score(GAS_POINTS); + round.events.push({ type: "bogboatGas", x, y: LANE_Y[lane] + GAS_UP + GAS_H / 2, points: GAS_POINTS }); + return true; + } + for (let i = 0; i < R.props.length; i++) { + const p = c.props[i]; + const [x, lane, kind] = R.props[i]; + if (p.state !== "up" || !hit(x, LANE_Y[lane] + PROP_UP, PROP_W, PROP_H)) continue; + p.state = "broken"; + score(PROP_POINTS); + round.events.push({ type: "bogboatProp", x, y: LANE_Y[lane] + PROP_UP + PROP_H / 2, kind, points: PROP_POINTS }); + return true; + } + return false; +} + +export const BOGBOAT = freeze({ + id: "bogboat", + monsters: MONSTERS, + walkers: freeze([]), + zombies: freeze([]), + stackers: freeze([]), + climbers: freeze([]), + act: freeze({}), + horde: freeze({}), + ride: freeze([ride]), + place: freeze([place]), + target: bogboatShot, +}); diff --git a/src/web-console/public/activities/ghoul-boss-intros.js b/src/web-console/public/activities/ghoul-boss-intros.js new file mode 100644 index 0000000..cb1244d --- /dev/null +++ b/src/web-console/public/activities/ghoul-boss-intros.js @@ -0,0 +1,31 @@ +// Plan2Code Web Console - Ghoul Rush's boss intro cards, the words: per boss id, the boss's name and a one-line epithet. ghoul-bossintro-draw.js draws the card; scripts/test-web-console-activities-ghoul-bossintro.mjs makes sure every boss room has an entry. +// +// Rules (see "Boss intro screens" in prototypes/Ghoul-Rush-TODO.md): +// `name` must equal the boss's `name` in its stage pack's `bosses` table (the +// Gourd's is in BOSSES in ghoul.js); `epithet` is a short menacing tagline, +// at most MAX_EPITHET characters, US English, no em dash, never the hero's +// name (if it addresses the player at all, it is YOU). `accent` is optional: +// the color of the name and the spotlight's rim (the boss's own color by default). +// The card's backdrop uses the stage's palette from ghoul-intros.js. + +export const MAX_EPITHET = 44; + +const freeze = Object.freeze; +const entry = (name, epithet, accent = null) => freeze({ name, epithet, accent }); + +export const BOSS_INTROS = freeze({ + gourd: entry("The Rotting Gourd", "Harvest time is over"), + bones: entry("Old Rattlebones", "At your service. Forever."), + angel: entry("Mother Mourning", "She has been waiting for YOU"), + keeper: entry("The Groundskeeper", "Everything gets trimmed"), + choirmaster: entry("The Choirmaster", "One more voice for the choir"), + matron: entry("The Night Matron", "Lights out, dear"), + beast: entry("The Beast of Hollow End", "The moon is full tonight"), + tommy: entry("The Tommyknocker", "Knock knock. Nobody is home"), + ringmaster: entry("The Ringmaster", "The show must go on"), + frostwidow: entry("The Frost Widow", "Cold hands, colder heart"), + motherbog: entry("Old Mother Bog", "Dinner climbed in on its own"), +}); + +// The card for a boss id, or null for a boss with none. +export const bossIntroFor = (id) => BOSS_INTROS[id] || null; diff --git a/src/web-console/public/activities/ghoul-bossintro-draw.js b/src/web-console/public/activities/ghoul-bossintro-draw.js new file mode 100644 index 0000000..887399b --- /dev/null +++ b/src/web-console/public/activities/ghoul-bossintro-draw.js @@ -0,0 +1,256 @@ +// Plan2Code Web Console - Ghoul Rush's boss intro card: a full-field "BOSS FIGHT" card shown when a boss room is entered, before the fight. A big title whose letters slam in one by one (red and orange glow, the whole card shaking at each landing, a heartbeat pulsing under it), the boss itself drawn from its own art at a big scale, spotlit on a dark backdrop in the stage's palette, its name big beneath it, a one-line epithet and a pulsing hint to press a key. +// +// ghoul-draw.js plugs it in, the way it plugs in ghoul-intro-draw.js: +// bossIntroArt(d) takes its drawing helpers (`d`: label, circle, BOSS_ART, +// drawGourdFire, GOLD, BONE) and hands back `(ctx, v)`, drawn over the whole +// field while `round.phase === "bossintro"` (also while paused). `round.introMs` +// is how long the card has been up (it stops with the game). The words live in +// ghoul-boss-intros.js, the colors in the stage's palette in ghoul-intros.js. +// The boss is drawn through the same fake boss the stage pick uses +// (ghoul-picker-draw.js); an art that throws or is missing falls back to a +// big dark silhouette with glowing eyes. Field units (96 by 54). + +import { INTRO_MIN_MS } from "./ghoul-run.js"; +import { introFor } from "./ghoul-intros.js"; +import { bossIntroFor } from "./ghoul-boss-intros.js"; +import { REACH } from "./ghoul-picker-draw.js"; + +export const BOSS_HINT = "Press any move key or fire to start the fight"; +export const BOSS_TITLE = "BOSS FIGHT"; +const TAU = Math.PI * 2; +const SLAM_MS = 190; +const STAGGER_MS = 95; +const START_MS = 200; +const FLOOR_Y = 38.5; +const MAX_H = 25; +const MAX_W = 40; +// How far a boss's art reaches past its box (the stage pick's table, plus the Gourd's stem and the Ringmaster's hat and puppet), and how far its picture is nudged to sit in the middle of the card. +const REACH_BY = Object.freeze({ ...REACH, gourd: 1.2, ringmaster: 1.4 }); +const NUDGE = Object.freeze({ ringmaster: 14 }); +const FALLBACK = Object.freeze({ a: "#ffb347", b: "#c2410c", glow: "#ff8a1f" }); + +const rnd = (i, salt = 0) => { + const x = Math.sin(i * 12.9898 + salt * 78.233) * 43758.5453; + return x - Math.floor(x); +}; +// A color eased toward white by `amount`, so a dark boss color still reads on the dark card (anything but #rrggbb is left alone). +export function lift(color, amount = 0.35) { + const m = /^#([0-9a-f]{6})$/i.exec(color || ""); + if (!m) return color; + const n = parseInt(m[1], 16); + const mix = (c) => Math.round(c + (255 - c) * amount); + return `rgb(${mix((n >> 16) & 255)}, ${mix((n >> 8) & 255)}, ${mix(n & 255)})`; +} +const clamp01 = (x) => Math.min(1, Math.max(0, x)); +const dot = (ctx, x, y, r, fill) => { + ctx.beginPath(); + ctx.arc(x, y, Math.max(0.05, r), 0, TAU); + ctx.fillStyle = fill; + ctx.fill(); +}; + +// The ms at which letter `i` of the title lands. +export const landAt = (i) => START_MS + i * STAGGER_MS + SLAM_MS; + +// The card's shake at `t` ms: a decaying jolt from each letter that just landed, a faint one with each heartbeat. +export function shakeAt(t) { + let amp = 0; + [...BOSS_TITLE].forEach((ch, i) => { + const dt = t - landAt(i); + if (ch !== " " && dt >= 0 && dt < 260) amp += 0.9 * (1 - dt / 260); + }); + const beat = (t % 1000) / 1000; + if (t > 1200 && beat < 0.08) amp += 0.18; + return amp; +} + +// The heartbeat's pulse in [0, 1]: two thumps a second apart. +export const beatAt = (t) => { + const p = (t % 1000) / 1000; + return Math.max(Math.exp(-p * 18), 0.7 * Math.exp(-Math.abs(p - 0.2) * 22)); +}; + +export function bossIntroArt(d) { + const { label, circle, BOSS_ART, drawGourdFire, GOLD, BONE } = d; + + // The boss standing on its mark, from its real art; false when the art is missing or throws. + function drawBossPicture(ctx, v, id, t, x, floorY) { + const def = v.bosses[id]; + const art = BOSS_ART[id]; + if (!def) return false; + const k = Math.min(MAX_H / (def.h * (REACH_BY[id] || 1)), MAX_W / def.w); + const pic = { g: { FIELD_H: 0 }, clock: 1000 + t, spec: null, groundAt: () => 0, eyes: [] }; + const b = { kind: id, x: 0, y: 0, w: def.w, h: def.h, hurt: 0, dir: -1, wait: Infinity, landX: 0, windup: 0, act: "", state: "fight", t: 0, hp: 1, max: 1, lit: true }; + const breathe = 1 + 0.018 * Math.sin(t / 430); + ctx.save(); + ctx.translate(x, floorY); + ctx.rotate(0.012 * Math.sin(t / 1100)); + ctx.scale(k * breathe, k * (1 + (breathe - 1) * 1.6)); + let ok = false; + try { + if (typeof art === "function") { + art(ctx, pic, b); + if (id === "gourd" && typeof drawGourdFire === "function") drawGourdFire(ctx, pic, b); + ok = true; + } + } catch (e) { + ok = false; + } + if (ok) { + const e = pic.eyes || []; + const pulse = 0.8 + 0.2 * Math.sin(t / 160); + for (let i = 0; i + 3 < e.length; i += 4) { + ctx.fillStyle = e[i + 3]; + ctx.globalAlpha = 0.22 * pulse; + circle(ctx, e[i], e[i + 1], e[i + 2] * 2.8); + ctx.fill(); + ctx.globalAlpha = 1; + circle(ctx, e[i], e[i + 1], e[i + 2]); + ctx.fill(); + } + } else { + // A big dark shape with two eyes, so the card never has a hole in it. + ctx.fillStyle = "#020104"; + ctx.beginPath(); + ctx.ellipse(0, -def.h / 2, def.w / 2, def.h / 2, 0, 0, TAU); + ctx.fill(); + dot(ctx, -def.w * 0.14, -def.h * 0.64, 0.5, "#ff3b1f"); + dot(ctx, def.w * 0.14, -def.h * 0.64, 0.5, "#ff3b1f"); + } + ctx.restore(); + return ok; + } + + return function bossIntroCard(ctx, v) { + const { g, round } = v; + const id = round.spec && round.spec.boss; + const info = bossIntroFor(id); + if (!info) return; + const stage = introFor(round.stage); + const pal = (stage && stage.palette) || FALLBACK; + const def = v.bosses[id] || {}; + const accent = info.accent || def.color || BONE; + const t = round.introMs || 0; + const W = g.FIELD_W; + const H = g.FIELD_H; + const fade = Math.min(1, t / 260); + const beat = beatAt(t); + const amp = shakeAt(t); + const n = Math.floor(t / 45); + ctx.save(); + ctx.translate((rnd(n, 1) - 0.5) * amp, (rnd(n, 2) - 0.5) * amp); + ctx.globalAlpha = fade; + ctx.fillStyle = "#050308"; + ctx.fillRect(-2, -2, W + 4, H + 4); + // The stage's color rising from the floor, a red wash that thumps with the heart. + for (let i = 0; i < 6; i++) { + ctx.globalAlpha = fade * (0.05 + 0.018 * (5 - i)); + ctx.fillStyle = pal.b; + ctx.fillRect(-2, H - (i + 1) * (H / 6), W + 4, H / 6); + } + ctx.globalAlpha = fade * (0.06 + 0.1 * beat); + ctx.fillStyle = "#b0120a"; + ctx.fillRect(-2, -2, W + 4, H + 4); + // The spotlight: a cone from above and a pool of light on the floor. + const cx = W / 2; + ctx.globalAlpha = fade * (0.12 + 0.03 * Math.sin(t / 700) + 0.03 * beat); + ctx.fillStyle = pal.glow; + ctx.beginPath(); + ctx.moveTo(cx - 4, 12); + ctx.lineTo(cx + 4, 12); + ctx.lineTo(cx + 22, FLOOR_Y + 1); + ctx.lineTo(cx - 22, FLOOR_Y + 1); + ctx.fill(); + ctx.globalAlpha = fade * 0.18; + ctx.beginPath(); + ctx.ellipse(cx, FLOOR_Y, 24, 3.2, 0, 0, TAU); + ctx.fill(); + ctx.globalAlpha = fade * 0.3; + ctx.beginPath(); + ctx.ellipse(cx, FLOOR_Y, 15, 1.9, 0, 0, TAU); + ctx.fill(); + // The floor, dark. + ctx.globalAlpha = fade; + ctx.fillStyle = "#08050b"; + ctx.fillRect(-2, FLOOR_Y + 0.4, W + 4, H - FLOOR_Y); + ctx.fillStyle = pal.b; + ctx.globalAlpha = fade * 0.5; + ctx.fillRect(-2, FLOOR_Y + 0.2, W + 4, 0.35); + // Embers drifting up. + for (let i = 0; i < 26; i++) { + const p = (t / 4200 + rnd(i)) % 1; + ctx.globalAlpha = fade * (1 - p) * 0.8; + dot(ctx, rnd(i, 1) * W + Math.sin(t / 700 + i) * 1.6, FLOOR_Y + 3 - p * (FLOOR_Y + 3), 0.18 + rnd(i, 2) * 0.22, i % 3 ? "#ff7a1a" : "#ffd27a"); + } + // The boss steps out of the dark. + const rise = clamp01((t - 500) / 900); + ctx.globalAlpha = fade * rise; + drawBossPicture(ctx, v, id, t, cx + (NUDGE[id] || 0), FLOOR_Y); + // The spotlight's glare over it, so it stands lit, not just in front of a light. + ctx.globalCompositeOperation = "lighter"; + ctx.fillStyle = pal.glow; + for (const s of [1, 0.78, 0.56]) { + ctx.globalAlpha = fade * rise * (0.035 + 0.01 * beat); + ctx.beginPath(); + ctx.ellipse(cx, FLOOR_Y - 12, 17 * s, 17 * s, 0, 0, TAU); + ctx.fill(); + } + ctx.globalCompositeOperation = "source-over"; + ctx.globalAlpha = fade; + // The title, one letter at a time, each slamming down from big and white-hot. + const chars = [...BOSS_TITLE]; + const em = chars.reduce((s, ch) => s + (ch === " " ? 0.4 : 0.68), 0); + const size = Math.min(10, 86 / em); + let x = cx - (em * size) / 2; + chars.forEach((ch, i) => { + const w = (ch === " " ? 0.4 : 0.68) * size; + const lx = x + w / 2; + x += w; + if (ch === " ") return; + const at = t - START_MS - i * STAGGER_MS; + if (at <= 0) return; + const p = clamp01(at / SLAM_MS); + const sc = 1 + 2.2 * (1 - p) * (1 - p); + const landed = p >= 1; + const ly = 7.2 + (landed ? 0 : -(1 - p) * 2); + ctx.globalAlpha = fade * (0.35 + 0.65 * p); + if (landed) { + ctx.globalAlpha = fade * (0.3 + 0.2 * Math.sin(t / 220 - i * 0.7) + 0.2 * beat); + label(ctx, ch, lx, ly, size * 1.16, "#ff6a00", "center"); + ctx.globalAlpha = fade; + } + label(ctx, ch, lx + 0.35, ly + 0.55, size * sc, "rgba(0, 0, 0, 0.7)", "center"); + label(ctx, ch, lx, ly, size * sc, i % 2 ? "#ff3b1f" : "#ff7a1a", "center"); + if (landed) { + // A white-hot flash as it lands. + const dt = at - SLAM_MS; + if (dt < 120) { + ctx.globalAlpha = fade * (1 - dt / 120) * 0.9; + label(ctx, ch, lx, ly, size, "#ffffff", "center"); + } + ctx.globalAlpha = fade; + } + }); + // The name, big, then the epithet. + const nameP = clamp01((t - 1300) / 450); + ctx.globalAlpha = fade * nameP; + const nameSize = Math.min(5, 84 / (info.name.length * 0.62)); + label(ctx, info.name.toUpperCase(), cx, 43.3 + (1 - nameP) * 1.4, nameSize * 1.06, "rgba(0, 0, 0, 0.8)", "center", W - 6, true); + label(ctx, info.name.toUpperCase(), cx, 43.1 + (1 - nameP) * 1.4, nameSize, lift(accent), "center", W - 6, true); + const epP = clamp01((t - 1750) / 450); + ctx.globalAlpha = fade * epP; + label(ctx, info.epithet, cx, 47.6 + (1 - epP) * 1.0, 2.3, BONE, "center", W - 8, true); + // The hint, pulsing once a key is let through (the card waits for it as long as YOU like). + if (t >= INTRO_MIN_MS) { + ctx.globalAlpha = fade * (0.8 + 0.2 * Math.sin(t / 260)); + label(ctx, BOSS_HINT, cx, 51.6, 1.9, pal.glow || GOLD, "center", W - 6); + } + // A frame that flushes red with each beat. + ctx.globalAlpha = fade * (0.55 + 0.45 * beat); + ctx.strokeStyle = "#ff4a1c"; + ctx.lineWidth = 0.45; + ctx.strokeRect(1.2, 1.2, W - 2.4, H - 2.4); + ctx.restore(); + ctx.globalAlpha = 1; + }; +} diff --git a/src/web-console/public/activities/ghoul-cart.js b/src/web-console/public/activities/ghoul-cart.js index f1911b3..13b0d3d 100644 --- a/src/web-console/public/activities/ghoul-cart.js +++ b/src/web-console/public/activities/ghoul-cart.js @@ -228,7 +228,7 @@ const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 function place(round, k) { const R = round.spec.ride; round.camLead = 0; - if (!R || R.gallery || R.sled) { + if (!R || R.gallery || R.sled || R.runner) { round.cart = null; return; } diff --git a/src/web-console/public/activities/ghoul-chapel-draw.js b/src/web-console/public/activities/ghoul-chapel-draw.js index 9533fb6..c157923 100644 --- a/src/web-console/public/activities/ghoul-chapel-draw.js +++ b/src/web-console/public/activities/ghoul-chapel-draw.js @@ -11,7 +11,7 @@ // face the way they look, y counted up from the feet. Each function says // what it draws and what in the rules (ghoul-chapel.js) it follows. -import { CENSER_WIND_MS, CUE_MS, GAPS, HASTE_RANGE, PIPE_AT, PIPE_H, PIPE_W, ROW_GAP, SMOKE_MS } from "./ghoul-chapel.js"; +import { CENSER_WIND_MS, CUE_MS, GAPS, HASTE_RANGE, PIPE_AT, PIPE_DROP_MS, PIPE_H, PIPE_W, ROW_GAP, SMOKE_MS } from "./ghoul-chapel.js"; const freeze = (o) => Object.freeze(o); const TAU = Math.PI * 2; @@ -76,6 +76,8 @@ const PIPE_DULL_LIT = "#a39d8c"; const PIPE_DARK = "#2e2b24"; const PIPE_LIT = "#f2d878"; const NOTE_COLOR = "#f4ead0"; +const NOTE_FAST = "#ff9a6a"; +const NOTE_SLOW = "#9fd0ff"; const INK = "#0e0a14"; const HOLY = "#9fd8ff"; const GHOSTLY = "#c9d6f2"; @@ -1927,14 +1929,17 @@ export function chapelArt(d) { } // A note of the Choirmaster's, a big black eighth note edged in light so it - // reads on any wall, a short tail of staff behind it; and, once per column, - // a gold bracket on the staff where the column has its gap. + // reads on any wall, a tail of staff behind it; and, once per column, a gold + // bracket on the staff where the column has its gap. A fast column has a hot + // edge and a long tail, a slow one a cold edge and a short tail. function note(ctx, v, h) { const cx = h.x; const cy = v.g.FIELD_H - h.y - h.h / 2; - ctx.strokeStyle = rgba("#f0c860", 0.28); + const pace = h.pace ?? 1; + const edge = pace > 1.2 ? NOTE_FAST : pace < 0.9 ? NOTE_SLOW : NOTE_COLOR; + ctx.strokeStyle = rgba(pace > 1.2 ? NOTE_FAST : "#f0c860", 0.28); ctx.lineWidth = 0.16; - line(ctx, cx + 0.4, cy, cx + 9, cy); + line(ctx, cx + 0.4, cy, cx + 0.4 + 8.6 * pace, cy); const mates = v.round.hazards.filter((o) => o.kind === "note" && Math.abs(o.x - h.x) < 0.2); const first = mates.reduce((lo, o) => (o.row < lo.row ? o : lo), mates[0]); if (first === h) { @@ -1958,24 +1963,36 @@ export function chapelArt(d) { } } // The note: a pale edge, then the black. - for (const [c, s] of [[NOTE_COLOR, 1.38], [INK, 1.2]]) noteGlyph(ctx, cx, cy + 0.5, s, c); + for (const [c, s] of [[edge, 1.38], [INK, 1.2]]) noteGlyph(ctx, cx, cy + 0.5, s, c); ctx.fillStyle = "rgba(255, 255, 255, 0.35)"; ellipse(ctx, cx - 0.2, cy + 0.3, 0.3, 0.14, -0.45); ctx.fill(); eye(v, cx + 0.4, cy - 0.6, 0.16, "#ffe9a0"); } + // A fresh pipe falling from over the field onto the dead one it replaces, + // gathering speed as it comes. + function fallingPipe(ctx, v, p) { + pipe(ctx, v, p, false, false); + const fallen = 1 - Math.min(1, p.dropMs / PIPE_DROP_MS); + ctx.save(); + ctx.translate(0, -v.g.FIELD_H * (1 - fallen * fallen)); + pipe(ctx, v, p, true, false); + ctx.restore(); + } + /* -------------------------------------------------------- Choirmaster */ // One organ pipe standing on the floor at `p.x`, tall and brass. Sounding // it shakes, glows, breathes puffs and sound from its mouth and sends notes // up, with an hp sign hung over it once it has been hit; silenced it is - // dark, dented and cracked, its top bent, its mouth sooty and cold. - function pipe(ctx, v, p, on, hurt) { + // dark, dented and cracked, its top bent, its mouth sooty and cold, and it + // rattles (`stir`) when the next column will bring the pipes back. + function pipe(ctx, v, p, on, hurt, stir) { const w = p.w; const t = v.clock; const fy = v.g.FIELD_H - p.y; - const x = p.x + (on ? Math.sin(t / 15 + p.i * 2) * 0.09 : 0); + const x = p.x + (on ? Math.sin(t / 15 + p.i * 2) * 0.09 : stir ? Math.sin(t / 22 + p.i * 2) * 0.22 : 0); const top = fy - p.h; const mouth = fy - 1.9 - (p.h - 1.9) * 0.2; const was = ctx.globalAlpha; @@ -2117,7 +2134,10 @@ export function chapelArt(d) { const was = ctx.globalAlpha; if (v.spec) { const pipes = b.pipes || PIPE_AT.map((dx, i) => ({ i, x: v.spec.arena + dx, y: b.y, w: PIPE_W, h: PIPE_H[i], hp: 1, max: 1, on: true, hurt: 0 })); - for (const p of pipes) pipe(ctx, v, p, p.on, p.hurt > 0); + for (const p of pipes) { + if (p.dropMs > 0) fallingPipe(ctx, v, p); + else pipe(ctx, v, p, p.on, p.hurt > 0, b.quiet === 1); + } } const sounding = Boolean(v.spec) && (!b.pipes || b.pipes.some((p) => p.on)); const open = Boolean(v.spec) && Boolean(b.pipes) && !sounding; @@ -2396,7 +2416,7 @@ export function chapelArt(d) { if (b && b.kind === "choirmaster" && b.state !== "down") { add(b.x, b.y + b.h * 0.55, 8, 0.45); if (b.act === "cue") add(b.x - 2, b.y + b.h + 1, 7, 0.7); - if (b.pipes) for (const p of b.pipes) if (p.on) add(p.x, p.y + p.h * 0.6, 6.5, 0.5); + if (b.pipes) for (const p of b.pipes) if (p.on && !(p.dropMs > 0)) add(p.x, p.y + p.h * 0.6, 6.5, 0.5); } } @@ -2461,7 +2481,11 @@ export function chapelArt(d) { } else if (e.type === "pipeSound") { say(tone, e.kind, "pipeSound", 0.5); glow(e.x, e.y, 8, 0.6, 400); + burst(e.x, 6, PIPE_DULL, 10, 12, 350); + shake(160, 0.5); float(e.x, e.y + 6, "It sounds again!", DANGER, 2.2); + } else if (e.type === "pipesStir") { + float(e.x, e.y + 6, "The pipes stir!", DANGER, 2.4); } else if (e.type === "choirOpen") { say(tone, e.kind, "open", 0.6); flash("#bfe8ff", 300); @@ -2470,7 +2494,7 @@ export function chapelArt(d) { say(tone, e.kind, "rage", 0.8); flash("#c0303a", 400); shake(400, 0.8); - k.banner("The hymn quickens", "The pipes will sound again", "#e86a78", 1600); + k.banner("The hymn quickens", "Faster notes, closer together", "#e86a78", 1600); } else if (e.type === "notesCue") { say(tone, e.kind, "cue", 0.45); glow(e.x, e.y, 5, 0.6, CUE_MS); diff --git a/src/web-console/public/activities/ghoul-chapel.js b/src/web-console/public/activities/ghoul-chapel.js index af9fe95..ed5f206 100644 --- a/src/web-console/public/activities/ghoul-chapel.js +++ b/src/web-console/public/activities/ghoul-chapel.js @@ -49,9 +49,13 @@ // columns of notes (`note` hazards) that fly along the room at the heights of // the lines of a staff, each column missing one note: be at the gap's height // when it passes (the floor for the lowest gap, a board for each higher one). -// He raises his baton first (`cue`). At half his hp (`rage`) silenced pipes -// sound again one at a time, the notes come faster and now and then two -// columns come close together. +// He raises his baton first (`cue`). Each column flies at a speed of its own, +// some far faster than others, and never so fast that it catches the column +// ahead (you always get time between two gaps). Once all four pipes are silent +// he is open for PIPES_BACK columns, then fresh pipes drop in from the roof at +// full hp and he is guarded until you silence them again. At half his hp +// (`rage`) the notes come faster and now and then two columns come close +// together. const freeze = (o) => Object.freeze(o); @@ -118,10 +122,15 @@ export const HOLY_GHOSTS = freeze(["ghost", "chorister", "wraith"]); // tall, each PIPE_HP of hp; a sounding one spews a ghost every PIPE_SPEW_MS or // so. His columns are made of notes NOTE across at the heights ROWS over the // floor (a staff's five lines, ROW_GAP apart), one of the first GAPS rows -// missing; one flies NOTE_V a second (NOTE_V_RAGE at half hp), a column every -// COLUMN_MS (COLUMN_RAGE_MS), his baton up CUE_MS first. At half his hp -// (RAGE) a silenced pipe sounds again every RESOUND_MS, and PAIR_CHANCE of the -// columns have a second PAIR_MS behind, its gap next to the first's. +// missing; a column flies at NOTE_V a second (NOTE_V_RAGE at half hp) times one +// of NOTE_PACE, drawn afresh for each column, but slowed if it would reach the +// arena's far end less than NOTE_SEP_MS behind the column ahead. A column comes +// every COLUMN_MS (COLUMN_RAGE_MS), his baton up CUE_MS first. At half his hp +// (RAGE) PAIR_CHANCE of the columns have a second PAIR_MS behind, as fast as +// the first, its gap next to the first's. With every pipe silent, the +// PIPES_BACK'th column (a pair is one) brings them all back: each falls for +// PIPE_DROP_MS, PIPE_DROP_STAGGER_MS after the one before, and cannot be shot +// until it lands. export const BOSSES = freeze({ choirmaster: freeze({ name: "The Choirmaster", sub: "Silence the pipes one by one", w: 8, h: 17, hp: 100, points: 3500, color: "#d8b0b8" }), }); @@ -140,6 +149,8 @@ export const ROWS = freeze([0, 1, 2, 3, 4].map((i) => ROW_0 + i * ROW_GAP)); export const GAPS = 4; export const NOTE_V = 22; export const NOTE_V_RAGE = 28; +export const NOTE_PACE = freeze([0.55, 0.8, 1, 1.35, 1.75]); +export const NOTE_SEP_MS = 1500; export const IDLE_MS = 1400; export const CUE_MS = 700; export const COLUMN_MS = 3200; @@ -147,7 +158,9 @@ export const COLUMN_RAGE_MS = 2300; export const PAIR_MS = 1100; export const PAIR_CHANCE = 0.4; export const RAGE = 0.5; -export const RESOUND_MS = 6000; +export const PIPES_BACK = 4; +export const PIPE_DROP_MS = 600; +export const PIPE_DROP_STAGGER_MS = 150; const SHOT_R = 0.5; const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v)); @@ -398,7 +411,7 @@ function pipeShot(round, s, k) { const b = round.boss; if (!b || b.kind !== "choirmaster" || b.state !== "fight" || !b.pipes) return false; for (const p of b.pipes) { - if (!p.on || Math.abs(s.x - p.x) > p.w / 2 + SHOT_R || s.y < p.y - SHOT_R || s.y > p.y + p.h) continue; + if (!p.on || p.dropMs > 0 || Math.abs(s.x - p.x) > p.w / 2 + SHOT_R || s.y < p.y - SHOT_R || s.y > p.y + p.h) continue; // A thrown weapon strikes harder than a bolt (ghoul-arms.js). p.hp = Math.max(0, p.hp - (s.pipeDmg || 1)); p.hurt = 120; @@ -413,15 +426,46 @@ function pipeShot(round, s, k) { return false; } +// Where a note leaves the field, past the arena's far end. +const noteEnd = (round) => round.spec.arena - 6; + +// The speed of a new column from `x`: drawn from NOTE_PACE, then held down so +// it reaches the arena's far end NOTE_SEP_MS or more behind the last column +// still flying. It starts behind that column, so it is that far behind or +// further at every spot on the way. +function columnSpeed(round, base, x, random) { + const v = base * NOTE_PACE[Math.floor(random() * NOTE_PACE.length) % NOTE_PACE.length]; + const end = noteEnd(round); + let ahead = 0; + for (const h of round.hazards) if (h.kind === "note" && h.v > 0) ahead = Math.max(ahead, (h.x - end) / h.v); + return Math.min(v, (x - end) / (ahead + NOTE_SEP_MS / 1000)); +} + // A column of notes at the staff over the floor under him, row `gap` left out. -function launch(round, b, gap, k, pair) { +// A pair's second column keeps the first's speed, and with it the gap between. +function launch(round, b, gap, k, pair, random) { const base = k.groundAt(round.spec, b.x); const x = b.x - b.w / 2 - 1; - const v = (rage(b) ? NOTE_V_RAGE : NOTE_V) * round.spec.pace; + const usual = (rage(b) ? NOTE_V_RAGE : NOTE_V) * round.spec.pace; + const v = pair ? b.noteV : columnSpeed(round, usual, x, random); + b.noteV = v; ROWS.forEach((row, i) => { - if (i !== gap) round.hazards.push({ kind: "note", x, y: base + row - NOTE / 2, w: NOTE, h: NOTE, row: i, v, live: 1, life: 7000, cause: "note" }); + if (i !== gap) round.hazards.push({ kind: "note", x, y: base + row - NOTE / 2, w: NOTE, h: NOTE, row: i, v, pace: v / usual, live: 1, life: 12000, cause: "note" }); }); - round.events.push({ type: "notes", kind: b.kind, x, y: base, gap, pair, rows: ROWS.length }); + round.events.push({ type: "notes", kind: b.kind, x, y: base, gap, pair, v, rows: ROWS.length }); +} + +// A column (or a pair) is away. While every pipe is silent it counts toward +// their return: the last but one warns you, the last drops them in. +function columnDone(round, b) { + b.act = "idle"; + b.wait = (rage(b) ? COLUMN_RAGE_MS : COLUMN_MS) / round.spec.pace; + if (b.quiet === null) return; + b.quiet -= 1; + if (b.quiet === 1) round.events.push({ type: "pipesStir", kind: b.kind, x: b.x, y: b.y + b.h * 0.6 }); + if (b.quiet > 0) return; + b.pipes.forEach((p, i) => Object.assign(p, { on: true, hp: p.max, hurt: 0, dropMs: PIPE_DROP_MS + i * PIPE_DROP_STAGGER_MS, spewIn: PIPE_SPEW_MS * 0.5 })); + b.quiet = null; } // The gap next to `gap`, one step up or down, whichever is on the staff. @@ -446,20 +490,27 @@ function moveChoirmaster(round, b, ms, random, k) { b.pipes = makePipes(round, k); b.act = "glide"; b.wait = 0; - b.resoundIn = RESOUND_MS; + b.quiet = null; } b.dir = -1; if (!b.raged && rage(b)) { b.raged = true; - b.resoundIn = RESOUND_MS; round.events.push({ type: "choirRage", kind: b.kind, x: b.x, y: b.y + b.h / 2 }); } - // The pipes: a sounding one spews a ghost now and then; in a rage the - // silent ones sound again, one every RESOUND_MS. + // Columns left before the pipes come back, counted only while all are silent. + if (b.pipes.some((p) => p.on)) b.quiet = null; + else b.quiet ??= PIPES_BACK; + // The pipes: one on its way down lands, one sounding spews a ghost now and + // then. const ghosts = () => round.monsters.filter((m) => !m.dead && m.kind === "ghost").length; for (const p of b.pipes) { p.hurt = Math.max(0, p.hurt - ms); if (!p.on) continue; + if (p.dropMs > 0) { + p.dropMs = Math.max(0, p.dropMs - ms); + if (!p.dropMs) round.events.push({ type: "pipeSound", kind: b.kind, x: p.x, y: p.y + p.h / 2, pipe: p.i }); + continue; + } p.spewIn -= ms * pace; if (p.spewIn > 0) continue; if (ghosts() >= GHOST_CAP) { @@ -470,16 +521,6 @@ function moveChoirmaster(round, b, ms, random, k) { k.spawnMonster(round, "ghost", p.x, p.y + p.h * 0.75, { force: true, phase: (p.x * 97) % 3100 }); round.events.push({ type: "pipeSpew", kind: b.kind, x: p.x, y: p.y + p.h * 0.75, pipe: p.i }); } - if (b.raged) { - const silent = b.pipes.filter((p) => !p.on); - if (!silent.length) b.resoundIn = RESOUND_MS; - else if ((b.resoundIn -= ms) <= 0) { - b.resoundIn = RESOUND_MS; - const p = silent[Math.floor(random() * silent.length) % silent.length]; - Object.assign(p, { on: true, hp: p.max, spewIn: PIPE_SPEW_MS * 0.5 }); - round.events.push({ type: "pipeSound", kind: b.kind, x: p.x, y: p.y + p.h / 2, pipe: p.i }); - } - } if (b.act === "glide") { const home = spec.length - HOME_FROM_END; const step = GLIDE_V * dt; @@ -500,20 +541,16 @@ function moveChoirmaster(round, b, ms, random, k) { b.wait = CUE_MS / pace; round.events.push({ type: "notesCue", kind: b.kind, x: b.x - b.w / 2, y: b.y + b.h * 0.75, gap, second: b.second }); } else if (b.act === "cue") { - launch(round, b, b.gap, k, false); + launch(round, b, b.gap, k, false, random); if (b.second !== null) { b.act = "pair"; b.wait = PAIR_MS / pace; - } else { - b.act = "idle"; - b.wait = (rage(b) ? COLUMN_RAGE_MS : COLUMN_MS) / pace; - } + } else columnDone(round, b); } else if (b.act === "pair") { b.gap = b.second; - launch(round, b, b.second, k, true); + launch(round, b, b.second, k, true, random); b.second = null; - b.act = "idle"; - b.wait = (rage(b) ? COLUMN_RAGE_MS : COLUMN_MS) / pace; + columnDone(round, b); } } @@ -521,7 +558,7 @@ function moveChoirmaster(round, b, ms, random, k) { function stepNote(round, h, ms) { h.x -= h.v * (ms / 1000); h.life -= ms; - return h.life > 0 && h.x > round.spec.arena - 6; + return h.life > 0 && h.x > noteEnd(round); } export const CHAPEL = freeze({ diff --git a/src/web-console/public/activities/ghoul-dice-draw.js b/src/web-console/public/activities/ghoul-dice-draw.js index 9c98003..7177451 100644 --- a/src/web-console/public/activities/ghoul-dice-draw.js +++ b/src/web-console/public/activities/ghoul-dice-draw.js @@ -6,7 +6,7 @@ // file never reaches back into it. Everything is drawn in field units, y // counted down from the field's top. -import { DICE_FACES, TUMBLE_MS } from "./ghoul-dice.js"; +import { DICE_FACES, LEAD_MS, TUMBLE_MS } from "./ghoul-dice.js"; const BODY = "#f4f1e8"; const EDGE = "#8f8a7d"; @@ -27,6 +27,8 @@ const PIPS = Object.freeze([ // The panel the big die rolls on, and the die in it. const PANEL_W = 44; const PANEL_H = 40; +// The least gap between the panel and the field's edge. +const MARGIN = 1.5; const DIE_SIZE = 15; // Candidate spots for the panel's middle, tried in order: the field's middle // first, then to either side; a row high on the field and one low. @@ -37,7 +39,7 @@ const WORD = "LUCKY-SAVE"; const LUCKY_MS = 2800; export function diceArt(d) { - const { circle, roundRect, rotate, label, GOLD, DANGER } = d; + const { circle, roundRect, rotate, label, GOLD, DANGER, hudLayout } = d; // A die of side `s` at (x, y), turned `angle`, showing `face`; `ink` is its // pips' color (a saving face is gold). @@ -75,7 +77,20 @@ export function diceArt(d) { // Where the panel's middle goes, as far from Planny's spot as the field // lets it: the first candidate that does not touch him. + // How much the panel is scaled to fit inside the field with a margin. + function panelFit(g) { + return Math.min(1, (g.FIELD_H - 2 * MARGIN) / PANEL_H, (g.FIELD_W - 2 * MARGIN) / PANEL_W); + } + function panelAt(v, roll) { + const at = panelSpot(v, roll); + const { g } = v; + const hw = (PANEL_W * panelFit(g)) / 2; + const hh = (PANEL_H * panelFit(g)) / 2; + return { x: Math.min(g.FIELD_W - hw - MARGIN, Math.max(hw + MARGIN, at.x)), y: Math.min(g.FIELD_H - hh - MARGIN, Math.max(hh + MARGIN, at.y)) }; + } + + function panelSpot(v, roll) { const { g, round } = v; const cam = Math.round(round.camX * 8) / 8; const sx = roll.x - cam; @@ -95,12 +110,60 @@ export function diceArt(d) { return first; } + // Where the die's pill sits in the HUD strip, in field units (the strip is + // above the field, so y is negative); the strip's right end when it is not shown. + function hudDiceSpot(v) { + const { g, round } = v; + for (const p of hudLayout(v.pillH, g.W, round.infinite ? Infinity : round.lives, v.hud, g.HUD_H)) { + if (typeof p.text === "string" && p.text.startsWith("DICE")) return { x: p.x + p.w / 2 - g.PAD, y: p.y + p.h / 2 - g.HUD_H }; + } + return { x: g.W - g.PAD * 2 - 8, y: -g.HUD_H / 2 }; + } + // The die in hand while the round holds to roll: tumbling in from above, // landing on its face with a pop, and a line saying where it stands. function roll(ctx, v) { const r = v.round.roll; if (!r) return; const { x, y } = panelAt(v, r); + // The whole panel shrinks to fit a small field, and sits inside it, so no edge is cut off. + const fit = panelFit(v.g); + ctx.save(); + ctx.translate(x, y); + ctx.scale(fit, fit); + ctx.translate(-x, -y); + rollIn(ctx, v, r, x, y, fit); + ctx.restore(); + } + + function rollIn(ctx, v, r, x, y, fit) { + // The lead-in: the panel grows out of the die, which flies up from its pill in the HUD. + if (r.t < LEAD_MS) { + const e = 1 - (1 - r.t / LEAD_MS) ** 3; + const spot = hudDiceSpot(v); + // The HUD spot, in the shrunk panel's own space. + const from = { x: x + (spot.x - x) / fit, y: y + (spot.y - y) / fit }; + const s = 0.12 + 0.88 * e; + ctx.save(); + ctx.globalAlpha = e; + ctx.translate(x, y); + ctx.scale(s, s); + ctx.translate(-x, -y); + ctx.fillStyle = "rgba(0, 0, 0, 0.62)"; + roundRect(ctx, x - PANEL_W / 2, y - PANEL_H / 2, PANEL_W, PANEL_H, 2.5); + ctx.fill(); + ctx.strokeStyle = "rgba(255, 255, 255, 0.35)"; + ctx.lineWidth = 0.3; + ctx.stroke(); + ctx.restore(); + const gx = from.x + (x - from.x) * e; + const gy = from.y + (y - 6 - from.y) * e; + ctx.fillStyle = "rgba(244, 241, 232, 0.25)"; + circle(ctx, gx, gy, (3 + DIE_SIZE * 0.6 * e)); + ctx.fill(); + die(ctx, gx, gy, 3 + (DIE_SIZE - 3) * e, 1 + (Math.floor(r.t / 60) * 5) % 6, (1 - e) * 9); + return; + } const lucky = r.landed && (!!DICE_FACES[r.face].revive || !!r.heart); ctx.fillStyle = "rgba(0, 0, 0, 0.62)"; roundRect(ctx, x - PANEL_W / 2, y - PANEL_H / 2, PANEL_W, PANEL_H, 2.5); @@ -127,10 +190,10 @@ export function diceArt(d) { ctx.globalAlpha = 1; } } else { - const p = r.t / TUMBLE_MS; + const p = (r.t - LEAD_MS) / (TUMBLE_MS - LEAD_MS); face = 1 + (Math.floor(r.t / 70) * 5) % 6; angle = (1 - p) ** 1.5 * 12; - dy = Math.abs(Math.sin(r.t / 105)) * -2.5 * (1 - p) - 3.5 * (1 - Math.min(1, r.t / 220)) ** 2; + dy = Math.abs(Math.sin(r.t / 105)) * -2.5 * (1 - p) - 3.5 * (1 - Math.min(1, (r.t - LEAD_MS) / 220)) ** 2; } die(ctx, x, at + dy, size, face, angle, lucky ? "#b8860b" : INK); let text = "A 4 or better saves you"; @@ -154,7 +217,7 @@ export function diceArt(d) { function react(e, k) { const { tone, burst, float, ring, flash, glow, shake, banner, fx, powers: POWERS } = k; if (e.type === "diceStart") { - tone("whoosh", 0.3, 0.6); + tone("ghoulDiceDrone", 0.6); tone("heartbeat", 0.45); ring(e.x, e.y + 2.5, BODY, 2, 8, 500); } else if (e.type === "diceRoll") { diff --git a/src/web-console/public/activities/ghoul-dice.js b/src/web-console/public/activities/ghoul-dice.js index b91e5e7..b61e323 100644 --- a/src/web-console/public/activities/ghoul-dice.js +++ b/src/web-console/public/activities/ghoul-dice.js @@ -35,8 +35,10 @@ export const DICE_FACES = Object.freeze({ 5: Object.freeze({ revive: true, give: Object.freeze(["life"]), line: "Back to life, +1 heart!", word: "+1 heart!" }), 6: Object.freeze({ revive: true, give: Object.freeze(["life", "garlic"]), line: "Back to life, +1 heart + Garlic!", word: "+1 heart + Garlic!" }), }); -export const ROLL_MS = 3200; -export const TUMBLE_MS = 600; +// The lead-in: the screen holds under a drone while a die flies from the HUD to the middle and grows into the panel. +export const LEAD_MS = 800; +export const TUMBLE_MS = LEAD_MS + 600; +export const ROLL_MS = LEAD_MS + 3200; // The clock a saved time-up gets back. export const SAVED_TIME_MS = 15000; // The most a pit's revive spot may move along the ground to stand clear of @@ -93,7 +95,6 @@ export function beginRoll(round, cause, kit) { round.phaseMs = 0; round.input.jump = 0; round.events.push({ type: "diceStart", cause, n: round.dice, x: at.x, y: at.y }); - round.events.push({ type: "diceRoll", n: round.dice, x: at.x, y: at.y }); return true; } @@ -105,7 +106,10 @@ export const heartFace = (round, face) => !round.bonusRound && round.lives <= 1 // (`kit.takeLife`), leaving its gift, if any, for the respawn. export function rollDice(round, ms, random, kit) { const r = round.roll; + const was = r.t; r.t += ms; + // The die leaves the HUD: the drone plays through the lead-in, and the rattle starts when it arrives. + if (was < LEAD_MS && r.t >= LEAD_MS) round.events.push({ type: "diceRoll", n: round.dice, x: r.x, y: r.y }); if (!r.landed && r.t >= TUMBLE_MS) { r.landed = true; r.face = 1 + Math.min(5, Math.floor(random() * 6)); diff --git a/src/web-console/public/activities/ghoul-draw.js b/src/web-console/public/activities/ghoul-draw.js index 9cc7afa..8db5314 100644 --- a/src/web-console/public/activities/ghoul-draw.js +++ b/src/web-console/public/activities/ghoul-draw.js @@ -38,16 +38,28 @@ import { LOOKS as SANATORIUM_LOOKS, LOSE_SOUNDS as SANATORIUM_LOSE_SOUNDS, LOSE_ import { LOOKS as VILLAGE_LOOKS, LOSE_SOUNDS as VILLAGE_LOSE_SOUNDS, LOSE_WORDS as VILLAGE_LOSE_WORDS, VOICES as VILLAGE_VOICES, villageArt } from "./ghoul-village-draw.js"; import { LOOKS as MINE_LOOKS, LOSE_SOUNDS as MINE_LOSE_SOUNDS, LOSE_WORDS as MINE_LOSE_WORDS, VOICES as MINE_VOICES, mineArt } from "./ghoul-mine-draw.js"; import { LOOKS as CART_LOOKS, LOSE_SOUNDS as CART_LOSE_SOUNDS, LOSE_WORDS as CART_LOSE_WORDS, VOICES as CART_VOICES, cartArt } from "./ghoul-cart-draw.js"; +import { LOOKS as WAGON_LOOKS, LOSE_SOUNDS as WAGON_LOSE_SOUNDS, LOSE_WORDS as WAGON_LOSE_WORDS, VOICES as WAGON_VOICES, wagonArt } from "./ghoul-wagon-draw.js"; import { LOOKS as SLED_LOOKS, LOSE_SOUNDS as SLED_LOSE_SOUNDS, LOSE_WORDS as SLED_LOSE_WORDS, VOICES as SLED_VOICES, sledArt } from "./ghoul-sled-draw.js"; +import { LOOKS as BANISTER_LOOKS, LOSE_SOUNDS as BANISTER_LOSE_SOUNDS, LOSE_WORDS as BANISTER_LOSE_WORDS, VOICES as BANISTER_VOICES, banisterArt } from "./ghoul-banister-draw.js"; +import { LOOKS as HEARSE_LOOKS, LOSE_SOUNDS as HEARSE_LOSE_SOUNDS, LOSE_WORDS as HEARSE_LOSE_WORDS, VOICES as HEARSE_VOICES, hearseArt } from "./ghoul-hearse-draw.js"; +import { LOOKS as GURNEY_LOOKS, LOSE_SOUNDS as GURNEY_LOSE_SOUNDS, LOSE_WORDS as GURNEY_LOSE_WORDS, VOICES as GURNEY_VOICES, gurneyArt } from "./ghoul-gurney-draw.js"; +import { LOOKS as PEW_LOOKS, LOSE_SOUNDS as PEW_LOSE_SOUNDS, LOSE_WORDS as PEW_LOSE_WORDS, VOICES as PEW_VOICES, pewArt } from "./ghoul-pew-draw.js"; +import { LOOKS as MOWER_LOOKS, LOSE_SOUNDS as MOWER_LOSE_SOUNDS, LOSE_WORDS as MOWER_LOSE_WORDS, VOICES as MOWER_VOICES, mowerArt } from "./ghoul-mower-draw.js"; +import { LOOKS as TRAY_LOOKS, LOSE_SOUNDS as TRAY_LOSE_SOUNDS, LOSE_WORDS as TRAY_LOSE_WORDS, VOICES as TRAY_VOICES, trayArt } from "./ghoul-tray-draw.js"; import { LOOKS as CARNIVAL_LOOKS, LOSE_SOUNDS as CARNIVAL_LOSE_SOUNDS, LOSE_WORDS as CARNIVAL_LOSE_WORDS, VOICES as CARNIVAL_VOICES, carnivalArt } from "./ghoul-carnival-draw.js"; import { LOOKS as FROZEN_LOOKS, LOSE_SOUNDS as FROZEN_LOSE_SOUNDS, LOSE_WORDS as FROZEN_LOSE_WORDS, VOICES as FROZEN_VOICES, frozenArt } from "./ghoul-frozen-draw.js"; +import { LOOKS as BOG_LOOKS, LOSE_SOUNDS as BOG_LOSE_SOUNDS, LOSE_WORDS as BOG_LOSE_WORDS, VOICES as BOG_VOICES, bogArt } from "./ghoul-bog-draw.js"; +import { LOOKS as BOGBOAT_LOOKS, LOSE_SOUNDS as BOGBOAT_LOSE_SOUNDS, LOSE_WORDS as BOGBOAT_LOSE_WORDS, VOICES as BOGBOAT_VOICES, bogboatArt } from "./ghoul-bogboat-draw.js"; import { diceArt } from "./ghoul-dice-draw.js"; import { gameOverBanner } from "./ghoul-gameover-draw.js"; +import { introArt } from "./ghoul-intro-draw.js"; +import { storyArt } from "./ghoul-story-draw.js"; import { bonusArt } from "./ghoul-bonus-draw.js"; import { LOOKS as RIDE_LOOKS, LOSE_SOUNDS as RIDE_LOSE_SOUNDS, LOSE_WORDS as RIDE_LOSE_WORDS, VOICES as RIDE_VOICES, react as rideReact } from "./ghoul-ride-voices.js"; import { rideArt } from "./ghoul-ride-draw.js"; import { armsArt } from "./ghoul-arms-draw.js"; import { pickerArt } from "./ghoul-picker-draw.js"; +import { bossIntroArt } from "./ghoul-bossintro-draw.js"; import { monsterArt } from "./ghoul-monsters-draw.js"; const FALLBACK_COLORS = Object.freeze({ board: "#ffffff", line: "#e4ddd1", you: "#206cc3", ink: "#1d1a17" }); @@ -116,9 +128,18 @@ export const LOOKS = Object.freeze({ ...MINE_LOOKS, ...CART_LOOKS, ...SLED_LOOKS, + ...BANISTER_LOOKS, + ...HEARSE_LOOKS, + ...GURNEY_LOOKS, + ...PEW_LOOKS, + ...MOWER_LOOKS, + ...TRAY_LOOKS, + ...WAGON_LOOKS, ...CARNIVAL_LOOKS, ...FROZEN_LOOKS, ...RIDE_LOOKS, + ...BOG_LOOKS, + ...BOGBOAT_LOOKS, crypt: Object.freeze({ wallTop: "#0a0b0e", wallLow: "#1b1e25", paper: "#262a33", wainscot: "#14161b", floorTop: "#43474f", floor: "#22252b", floorEdge: "#0a0b0d", shelf: "#30343c", shelfTop: "#4a4f58", pit: "#010102", window: "#b4bfd1", decor: "tombs", color: "#b4bfd1", dark: 0.9 }), }); export const lookOf = (id) => LOOKS[id] || LOOKS.foyer; @@ -242,12 +263,14 @@ const { drawZombie, drawZombieKin, drawHuntsman, drawCrawler, drawBat, drawGhost // backdrops (a look's `pack` names whose, the Graveyard's by default), graves, // monsters, bosses, missiles, hazards, waves, power-up badges and lights by // kind, and what their events look and sound like. -const HELP = { drawPower, ellipse, circle, roundRect, line, rotate, eye, hash, say, gate, label, drawBoneShape, BONE, DANGER, GOLD, FLASH, EYE_RED, EYE_PALE, EYE_AMBER }; +const HELP = { hudLayout, drawPower, ellipse, circle, roundRect, line, rotate, eye, hash, say, gate, label, drawBoneShape, BONE, DANGER, GOLD, FLASH, EYE_RED, EYE_PALE, EYE_AMBER }; const ARMS_ART = armsArt(HELP); -const PACK_ART = { arms: ARMS_ART, bones: boneArt(HELP), graveyard: graveyardArt(HELP), grounds: groundsArt(HELP), chapel: chapelArt(HELP), sanatorium: sanatoriumArt(HELP), village: villageArt(HELP), mine: mineArt(HELP), cart: cartArt(HELP), sled: sledArt(HELP), carnival: carnivalArt(HELP), frozen: frozenArt(HELP), ride: { backdrop() {}, lights() {}, react: rideReact } }; +const PACK_ART = { arms: ARMS_ART, bones: boneArt(HELP), graveyard: graveyardArt(HELP), grounds: groundsArt(HELP), chapel: chapelArt(HELP), sanatorium: sanatoriumArt(HELP), village: villageArt(HELP), mine: mineArt(HELP), cart: cartArt(HELP), sled: sledArt(HELP), banister: banisterArt(HELP), hearse: hearseArt(HELP), codeblue: gurneyArt(HELP), pew: pewArt(HELP), mower: mowerArt(HELP), tray: trayArt(HELP), wagon: wagonArt(HELP), carnival: carnivalArt(HELP), frozen: frozenArt(HELP), bog: bogArt(HELP), bogboat: bogboatArt(HELP), ride: { backdrop() {}, lights() {}, react: rideReact } }; const packs = Object.values(PACK_ART); const DICE = diceArt(HELP); const OVER_BANNER = gameOverBanner(HELP); +const INTRO_CARD = introArt(HELP); +const STORY_CARD = storyArt({ ...HELP, LOOKS }); const BONUS = bonusArt(HELP, DICE.die); // The Carnival's dark ride draws the whole field itself (ghoul-ride-draw.js). const RIDE = rideArt(HELP, DICE.die); @@ -1723,7 +1746,7 @@ function drawGlowing(ctx, v) { /* ------------------------------------------------------------ feedback */ const KILL_WORDS = Object.freeze({ head: "Headshot!", stomp: "Crunch!", crush: "Flattened!", garlic: "Garlic!" }); -const LOSE_WORDS = Object.freeze({ time: "Out of time", pit: "Into the dark", bone: "Skull cracked", chandelier: "Crushed", acid: "Burned alive", wave: "Thrown down", ...BONES_LOSE_WORDS, ...GROUNDS_LOSE_WORDS, ...CHAPEL_LOSE_WORDS, ...SANATORIUM_LOSE_WORDS, ...VILLAGE_LOSE_WORDS, ...MINE_LOSE_WORDS, ...CART_LOSE_WORDS, ...SLED_LOSE_WORDS, ...CARNIVAL_LOSE_WORDS, ...FROZEN_LOSE_WORDS,...RIDE_LOSE_WORDS, hound: "Mauled", spider: "Bitten", wraith: "Taken", hands: "Dragged under", mourner: "Mourned", robber: "Buried alive", crow: "Pecked", legs: "Kicked down", stone: "Struck by a headstone", fist: "Crushed by stone", angel: "Turned to stone" }); +const LOSE_WORDS = Object.freeze({ time: "Out of time", pit: "Into the dark", bone: "Skull cracked", chandelier: "Crushed", acid: "Burned alive", wave: "Thrown down", ...BONES_LOSE_WORDS, ...BANISTER_LOSE_WORDS, ...GROUNDS_LOSE_WORDS, ...CHAPEL_LOSE_WORDS, ...SANATORIUM_LOSE_WORDS, ...VILLAGE_LOSE_WORDS, ...MINE_LOSE_WORDS, ...CART_LOSE_WORDS, ...SLED_LOSE_WORDS, ...HEARSE_LOSE_WORDS, ...GURNEY_LOSE_WORDS, ...PEW_LOSE_WORDS, ...MOWER_LOSE_WORDS, ...TRAY_LOSE_WORDS, ...WAGON_LOSE_WORDS, ...CARNIVAL_LOSE_WORDS, ...FROZEN_LOSE_WORDS,...RIDE_LOSE_WORDS, ...BOG_LOSE_WORDS, ...BOGBOAT_LOSE_WORDS, hound: "Mauled", spider: "Bitten", wraith: "Taken", hands: "Dragged under", mourner: "Mourned", robber: "Buried alive", crow: "Pecked", legs: "Kicked down", stone: "Struck by a headstone", fist: "Crushed by stone", angel: "Turned to stone" }); // What spills from each kind when it dies, and whether it leaves a stain. const STAINS = Object.freeze({ ghost: false, wraith: false, skeleton: false, bat: true }); @@ -1857,6 +1880,11 @@ export function react(e, k) { burst(e.x, e.y, GOLD, 16, 14); ring(e.x, e.y, GOLD, 1, 7, 500); banner("The key", "Now find the door. Fast", GOLD, 1100); + } else if (e.type === "keyDark") { + tone("ghoulLightsOut", 0.6); + flash("#000000", 200); + shake(160, 0.3); + float(e.x, e.y + 5, "The lights go out!", DANGER, 2.4); } else if (e.type === "garlic") { tone("shield"); tone("ghoulGarlicPop", 0.55); @@ -1961,7 +1989,7 @@ export function react(e, k) { } burst(e.x, e.y, e.how === "head" ? BONE : BLOOD, 4, 10, 260); if (e.how === "head") float(e.x, e.y + 6, "Skull!", GOLD, 2); - else if (e.weak) float(e.x, e.y + 4, e.kind === "keeper" ? "Lantern!" : "Double!", GOLD, 2); + else if (e.weak) float(e.x, e.y + 4, e.kind === "keeper" ? "Lantern!" : e.kind === "motherbog" ? "Triple!" : "Double!", GOLD, 2); } else if (e.type === "bossDown") { tone("explode", 0.9, 0.8); say(tone, e.kind, "die", 0.8); @@ -1998,6 +2026,12 @@ export function react(e, k) { tone("ghoulToll", 0.35, 1.2); tone("doorCreak", 0.3, 0.7); } else if (e.type === "pickMove") tone("tickSoft", 0.3, 1.2); + else if (e.type === "intro") tone("ghoulStageIntro", 0.6); + else if (e.type === "bossIntro") tone("ghoulBossIntro", 0.75); + // The intro story (ghoul-story.js): a page turns, a timed sound, the last page opens the hall. + else if (e.type === "storyPage") e.page && tone("ghoulStoryPage", 0.3); + else if (e.type === "storyTone") tone(e.name, e.vol, e.rate); + else if (e.type === "storyEnd") flash("#fff3c4", 320); else if (e.type === "stage") { tone("doorUnlock", 0.5); tone("ghoulThunder", 0.4, 0.9); @@ -2062,10 +2096,19 @@ export const VOICES = Object.freeze({ ...MINE_VOICES, ...CART_VOICES, ...SLED_VOICES, + ...BANISTER_VOICES, + ...HEARSE_VOICES, + ...GURNEY_VOICES, + ...PEW_VOICES, + ...MOWER_VOICES, + ...TRAY_VOICES, + ...WAGON_VOICES, ...CARNIVAL_VOICES, ...FROZEN_VOICES, ...RIDE_VOICES, angel: Object.freeze({ wake: "ghoulAngelWake", weep: "ghoulAngelWeep", watch: "ghoulAngelWatch", see: "ghoulAngelSee", slam: "ghoulAngelSlam", wings: "ghoulAngelWings", hurt: "ghoulAngelHurt", die: "ghoulAngelDie" }), + ...BOG_VOICES, + ...BOGBOAT_VOICES, }); // Plays a kind's voice for an act, if it has one, its pitch a touch varied. function say(tone, kind, act, level) { @@ -2103,7 +2146,16 @@ const LOSE_SOUNDS = Object.freeze({ ...FROZEN_LOSE_SOUNDS, ...CART_LOSE_SOUNDS, ...SLED_LOSE_SOUNDS, + ...BANISTER_LOSE_SOUNDS, + ...HEARSE_LOSE_SOUNDS, + ...GURNEY_LOSE_SOUNDS, + ...PEW_LOSE_SOUNDS, + ...MOWER_LOSE_SOUNDS, + ...TRAY_LOSE_SOUNDS, + ...WAGON_LOSE_SOUNDS, ...RIDE_LOSE_SOUNDS, + ...BOG_LOSE_SOUNDS, + ...BOGBOAT_LOSE_SOUNDS, }); // The door's boom in each of the eight rooms, the Crypt deepest. const ROOM_PITCH = Object.freeze([1, 1.1, 0.95, 1.2, 1.05, 1.15, 0.9, 0.75]); @@ -2188,7 +2240,10 @@ function layPills(h, W, lives, hud, stripH) { if (hud.hearts) put(hud.hearts, GOLD); else put(`BONUS ${hud.bonus}`, hud.bonus > 0 ? GOLD : DANGER); if (hud.chain > 1) put(`CHAIN x${hud.chain}`, GOLD, hud.chainFill); - if (hud.key) put("KEY", GOLD); + if (hud.key) { + out.push({ x, y, w: h * 1.5, h, key: hud.key, color: GOLD }); + x += h * 1.5 + gap; + } for (const e of hud.effects) put(e.text, e.color, e.fill); if (gw) out.push({ x: W - edge - gw, y: y0, w: gw, h, gauge: true }); if (aw) out.push({ x: W - edge - (gw ? gw + gap : 0) - aw, y: y0, w: aw, h, arm: true, text: hud.arm.text }); @@ -2213,10 +2268,47 @@ function drawPills(ctx, v) { for (const p of hudLayout(v.pillH, g.W, v.round.infinite ? Infinity : v.round.lives, v.hud, g.HUD_H)) { if (p.gauge) drawGauge(ctx, p.x, p.y, p.w, p.h, v.hud.gauge, v.clock); else if (p.arm) ART.armPill(ctx, p, v, SANS); + else if (p.key) drawKeyPill(ctx, p, v.clock); else pill(ctx, p.x, p.y, p.h, p.text, p.color, p.fill); } } +// The room's key in the strip: a gold key on a pill once it is found, a dotted +// outline of one (dim, waiting) until then. +function drawKeyPill(ctx, p, clock) { + const { x, y, w, h } = p; + const have = p.key === "have"; + ctx.fillStyle = PILL; + roundRect(ctx, x, y, w, h, h / 2); + ctx.fill(); + ctx.save(); + ctx.translate(x + w / 2, y + h * 0.52); + const u = h * 0.34; + ctx.rotate(-0.6); + ctx.beginPath(); + ctx.arc(-u * 1.05, 0, u * 0.7, 0, Math.PI * 2); + ctx.moveTo(-u * 0.35, 0); + ctx.lineTo(u * 1.35, 0); + ctx.moveTo(u * 0.85, 0); + ctx.lineTo(u * 0.85, u * 0.7); + ctx.moveTo(u * 1.35, 0); + ctx.lineTo(u * 1.35, u * 0.7); + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + if (have) { + ctx.strokeStyle = GOLD; + ctx.lineWidth = u * 0.5; + ctx.stroke(); + } else { + ctx.globalAlpha = 0.5 + 0.12 * Math.sin(clock / 400); + ctx.strokeStyle = "#ffffff"; + ctx.lineWidth = u * 0.34; + ctx.setLineDash([u * 0.45, u * 0.55]); + ctx.stroke(); + } + ctx.restore(); +} + // The blaster's gauge: LIGHT on the pill's dark backing, then a bar that // fills as the blaster heats and empties as it cools, with a notch where the // bolts start to slow and the stretch past it tinted red. Past the notch the @@ -2313,6 +2405,7 @@ function drawTally(ctx, v, lines) { // The choice of stage, the stage select and each stage's color (ghoul-picker-draw.js). const { drawPicker, drawSelect, stageColor } = pickerArt({ lookOf, label, roundRect, circle, BOSS_ART, drawGourdFire, GOLD }); +const BOSS_CARD = bossIntroArt({ label, circle, BOSS_ART, drawGourdFire, GOLD, BONE }); /* --------------------------------------------------------------- scene */ @@ -2380,6 +2473,32 @@ export function drawScene(ctx, v) { ctx.restore(); return; } + // Holy Roller is an endless-runner drawn whole by its own art (ghoul-pew-draw.js): the nave in pseudo-3D from behind the + // pew. The hearts, the flash, the banner, the cards and the HUD pills go over it as they do over the dark ride. + if (round.runner && round.runner.id === "pew") { + PACK_ART.pew.field(ctx, v); + for (const f of v.fx.floats) { + ctx.globalAlpha = Math.min(1, (f.life / f.max) * 1.6); + const at = labelSpot(f.text, f.x, Y(f.y) - f.rise, f.size, g.FIELD_W, g.FIELD_H); + label(ctx, f.text, at.x, at.y, f.size, f.color, "center", at.max); + } + ctx.globalAlpha = 1; + if (round.bonusRound && (v.state === "running" || v.state === "paused")) drawBonusHearts(ctx, v); + if (v.flash) { + ctx.globalAlpha = 0.24 * (v.flash.life / v.flash.max); + ctx.fillStyle = v.flash.color; + ctx.fillRect(0, 0, g.FIELD_W, g.FIELD_H); + ctx.globalAlpha = 1; + } + if (v.state === "running" && round.phase === "clear") BONUS.card(ctx, v); + if (v.state === "running" && v.banner && round.phase !== "pick" && round.phase !== "select" && round.phase !== "roll") drawBanner(ctx, v, v.banner); + if (v.state === "running" && v.fx.lucky) DICE.lucky(ctx, v); + ctx.restore(); + ctx.translate(-g.PAD, -g.HUD_H); + drawPills(ctx, v); + ctx.restore(); + return; + } const cam = Math.round(round.camX * 8) / 8; if (v.shake) ctx.translate(v.shake.x, v.shake.y); ctx.translate(-cam, 0); @@ -2478,6 +2597,9 @@ export function drawScene(ctx, v) { if (v.state === "running" && v.fx.lucky) DICE.lucky(ctx, v); if ((v.state === "running" || v.state === "paused") && round.phase === "pick" && round.offer) drawPicker(ctx, v); if ((v.state === "running" || v.state === "paused") && round.phase === "select" && round.select) drawSelect(ctx, v); + if ((v.state === "running" || v.state === "paused") && round.phase === "intro") INTRO_CARD(ctx, v); + if ((v.state === "running" || v.state === "paused") && round.phase === "bossintro") BOSS_CARD(ctx, v); + if ((v.state === "running" || v.state === "paused") && round.phase === "story") STORY_CARD(ctx, v); if (v.state === "over" && v.lost && !v.won) OVER_BANNER(ctx, v); if (v.tally) drawTally(ctx, v, v.tally); ctx.restore(); diff --git a/src/web-console/public/activities/ghoul-frozen-draw.js b/src/web-console/public/activities/ghoul-frozen-draw.js index f6c6818..c515870 100644 --- a/src/web-console/public/activities/ghoul-frozen-draw.js +++ b/src/web-console/public/activities/ghoul-frozen-draw.js @@ -80,6 +80,7 @@ export const EVENT_VOICE = freeze({ veilMelt: ["frostwidow", "melt"], veilUp: ["frostwidow", "up"], barrelKick: ["frostwidow", "kick"], + barrelKnock: ["frostwidow", "kick"], barrelBurst: ["frostwidow", "burst"], blizzard: ["frostwidow", "gust"], blizzardBlow: ["frostwidow", "blow"], @@ -1387,6 +1388,10 @@ export function frozenArt(d) { burst(e.x, e.y + 1.7, "#ff8a1a", 6, 6, 260); ring(e.x, e.y + 1.7, "#ff8a1a", 1, 4, 300); break; + case "barrelKnock": + shake(60, 0.15); + burst(e.x, e.y + 1.7, "#ffb050", 3 + e.n, 8, 220); + break; case "barrelKick": shake(80, 0.25); burst(e.x, e.y + 1.7, "#ffb050", 8, 12, 300); diff --git a/src/web-console/public/activities/ghoul-frozen.js b/src/web-console/public/activities/ghoul-frozen.js index 65bd8c4..fdffd4d 100644 --- a/src/web-console/public/activities/ghoul-frozen.js +++ b/src/web-console/public/activities/ghoul-frozen.js @@ -147,7 +147,7 @@ export const BOSSES = freeze({ export const EVENTS = freeze([ "iceCrack", "iceBreak", "iceBack", "handWarn", "handUp", "shadeShow", "shadeWind", "shadeLunge", "shatter", "frozenMelt", "iceWraithWake", "iceWraithWind", "iceWraithDive", "freezeHit", - "widowDrop", "widowRise", "widowRage", "veilMelt", "veilDown", "veilUp", "barrelPlace", "barrelKick", "barrelBurst", + "widowDrop", "widowRise", "widowRage", "veilMelt", "veilDown", "veilUp", "barrelPlace", "barrelKick", "barrelKnock", "barrelBurst", "blizzard", "blizzardBlow", "blizzardEnd", "spikeWarn", "spikeUp", "webWind", "webShot", "webLand", "wraithCall", ]); @@ -226,18 +226,20 @@ export const FREEZE_MS = 700; // The Frost Widow. export const HANG_OVER = 20; -export const HANG_V = 12; +export const HANG_V = 10; export const FIRST_HANG_MS = 4200; export const HANG_MS = 5200; export const DROP_MS = 700; export const RISE_MS = 800; export const LOW_MS = 9000; -export const LOW_V = 5; +export const LOW_V = 4; export const LOW_KEEP = 14; -export const LAND_AWAY = 24; +export const LAND_AWAY = 32; export const WIDOW_RAGE = 0.5; export const RAGE_QUICK = 0.75; -export const WRAITH_CAP = 2; +export const WRAITH_CAP = 1; +// After a call, no wraith is called again for this long (ms): the rage's first one, then one every so often. +export const WRAITH_GAP_MS = 20000; // A called wraith hovers this long (ms) before its first shriek, so it can be shot first. export const WRAITH_CALL_MS = 1600; // The veil, the heart and the mouth. @@ -255,6 +257,8 @@ export const BARREL_V = 34; export const BARREL_LIFE_MS = 5000; export const BARREL_DMG = 3; export const BARREL_BOSS = 3; +// A still barrel shrugs off a stray bolt: it takes this many bolts to topple it (a thrown weapon kicks it at once). +export const BARREL_HITS = 4; // The blizzard. export const BLIZZARD_FIRST_MS = 7000; export const BLIZZARD_EVERY_MS = 12000; @@ -265,8 +269,8 @@ export const BLIZZARD_COVER = 0.5; export const COVER_NEAR = 5; // The spikes. export const SPIKE_FIRST_MS = 2200; -export const SPIKE_EVERY_MS = 2800; -export const SPIKE_LOW_MS = 3400; +export const SPIKE_EVERY_MS = 3600; +export const SPIKE_LOW_MS = 4400; export const SPIKE_WARN_MS = 800; export const SPIKE_UP_MS = 1000; export const SPIKE_W = 4; @@ -779,6 +783,8 @@ function target(round, s) { if (h.kind === "webGlob") { h.life = 0; round.events.push({ type: "webLand", x: h.x, y: h.y, shot: true }); + } else if (!s.arm && (h.knocks = (h.knocks || 0) + 1) < BARREL_HITS) { + round.events.push({ type: "barrelKnock", x: h.x, y: h.y, n: h.knocks }); } else { h.state = "roll"; h.vx = (Math.sign(s.vx) || 1) * BARREL_V; @@ -793,12 +799,14 @@ function target(round, s) { // Up to WRAITH_CAP ice wraiths come in from the arena's edges. function callWraiths(round, b, k) { const spec = round.spec; + if (round.clock < (b.wraithAt || 0)) return; let alive = round.monsters.filter((m) => m.kind === "icewraith" && !m.dead).length; for (const [x, side] of [[spec.arena + 6, 1], [spec.length - 6, -1]]) { if (alive >= WRAITH_CAP) break; const y = b.floor + 22; if (k.spawnMonster(round, "icewraith", x, y, { act: "hover", wait: WRAITH_CALL_MS, home: y, dir: -side, force: true })) { alive++; + b.wraithAt = round.clock + WRAITH_GAP_MS; round.events.push({ type: "wraithCall", kind: b.kind, x, y }); } } diff --git a/src/web-console/public/activities/ghoul-gurney-draw.js b/src/web-console/public/activities/ghoul-gurney-draw.js new file mode 100644 index 0000000..6f6c73c --- /dev/null +++ b/src/web-console/public/activities/ghoul-gurney-draw.js @@ -0,0 +1,1067 @@ +// Plan2Code Web Console - Ghoul Rush's Code Blue, its drawing: a runaway hospital gurney down the sanatorium's corridors at night. A mint wall with doors, a handrail and a ceiling of fluorescent tubes that buzz and flicker, linoleum floors that rise and fall in ramps, elevator shafts open to a black drop, wheelchairs rolling, IV stands, doorways with orderlies in them, hanging surgical lamps and swinging doors, buzzing surge lamps hung high, the gurney with Planny strapped to it, and a heartbeat monitor trace across the top. +// +// ghoul-draw.js plugs it in. LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are +// plain data; gurneyArt(d) takes ghoul-draw.js's drawing helpers (`d`) and hands back the +// drawing by kind, so this file never reaches back into it. Drawn in room units, the way +// ghoul-draw.js draws: y counted down from the field's top, so a world height `y` is drawn +// at `FIELD_H - y`. The still layers' pit is dark under the whole ride, so the wall, the +// floor and what stands on it are drawn by `moving` (every frame, over the still layers); +// the lows, the gurney in front of Planny, the telegraphs, the countdown and the monitor are +// drawn by `front`. No random numbers: everything comes from a hash. +// +// THE TWIST ON THE SCREEN: the game's own dark (ghoul-draw.js drawDark) lies over the field, +// cut open at each light and by Planny's flashlight cone. `dim` is how dark the corridor is +// (0.97 in a blackout, a hash of the clock flickering in the countdown), and `lights` is +// what stays lit in it: the dying emergency strips along the floor, a faint pool on what +// is near (so an obstacle shows as an outline), the telegraph glyphs, the surge lamps, the +// checkpoints and the monitor's band across the top. What the art reads off the rules +// (ghoul-gurney.js): +// +// - the room: `spec.ride` ({ track, chairs, stands, lows [x0, x1, y, kind], orderlies, lamps, +// waves, checks, finish }), `spec.ground` (the start's floor and the ambulance bay). +// - `round.runner` ({ pack: "codeblue", ... }, null in any other room): `v`, `line` (-1 in +// the air), `check`, `done`, `phase`, `n`, `dark`, `pulse`, `every`, `flat`, `orderlies` +// [{ state "door" | "warn" | "up" | "sink" | "broken" | "spent", t }], `chairs` [{ x, +// rolling }], `lamps` [broken], `waves` [{ off }]; `round.bonusRound.hearts`. +// - Planny: `you.state`, `you.vy` (tilts the gurney in the air), `you.ducking`, `you.x`, `you.y`. +// - events leave short-lived bits in the view's `fx` (`blueBits`, `blueLand`). + +import { ANSWER_COLORS } from "./ghoul-sled-draw.js"; + +const freeze = (o) => Object.freeze(o); +const TAU = Math.PI * 2; +const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x)); + +const ID = "codeblue"; +const pit = (o) => freeze({ pack: ID, custom: true, noMoon: true, pit: "#05090c", ...o }); +export const LOOKS = freeze({ + codeblue: pit({ wallTop: "#0c1412", wallLow: "#1c2b27", paper: "#2b3f38", wainscot: "#141f1b", floorTop: "#8fa79c", floor: "#3a4a43", floorEdge: "#0a100e", shelf: "#3a4a43", shelfTop: "#a8b8b0", window: "#c0e8d8", decor: "none", color: "#b0e0cc", dark: 0.5 }), +}); + +// How each new kind sounds, by act (the sounds are in ghoul-sfx-gurney.js). +export const VOICES = freeze({ + blue: freeze({ jump: "ghoulBlueJump", land: "ghoulBlueLand", launch: "ghoulBlueLaunch", duck: "ghoulBlueDuck", crash: "ghoulBlueCrash", check: "ghoulBlueCheck", finish: "ghoulBlueFinish", warn: "ghoulBlueWarn", dark: "ghoulBlueDark", lit: "ghoulBlueLit", beat: "ghoulBlueBeat", flat: "ghoulBlueFlat", chair: "ghoulBlueChair" }), + blueorderly: freeze({ warn: "ghoulBlueOrderlyWarn", up: "ghoulBlueOrderlyUp", hit: "ghoulBlueOrderlyHit", break: "ghoulBlueOrderlyBreak" }), + bluelamp: freeze({ break: "ghoulBlueLampBreak" }), +}); + +// What each of the pack's events plays: [kind, act], once (a beat on the flat is its own act). +export const EVENT_VOICE = freeze({ + blueJump: ["blue", "jump"], + blueLand: ["blue", "land"], + blueLaunch: ["blue", "launch"], + blueDuck: ["blue", "duck"], + blueCrash: ["blue", "crash"], + blueCheck: ["blue", "check"], + blueFinish: ["blue", "finish"], + blueWarn: ["blue", "warn"], + blueDark: ["blue", "dark"], + blueLit: ["blue", "lit"], + blueBeat: ["blue", "beat"], + blueChair: ["blue", "chair"], + blueOrderlyWarn: ["blueorderly", "warn"], + blueOrderlyUp: ["blueorderly", "up"], + blueOrderlyHit: ["blueorderly", "hit"], + blueOrderlyBreak: ["blueorderly", "break"], + blueLamp: ["bluelamp", "break"], +}); +export const LOSE_WORDS = freeze({ wheelchair: "Hit a wheelchair", ivstand: "Tangled in an IV stand", overhead: "Ducked too late", lunged: "Tackled by an orderly", elevator: "Down the elevator shaft" }); +export const LOSE_SOUNDS = freeze({ + wheelchair: ["clank", 0.6, 0.8], + ivstand: ["clank", 0.5, 1.2], + overhead: ["smash", 0.5, 0.9], + lunged: ["ghoulHandsGrab", 0.5, 0.9], + elevator: ["ghoulPitFall", 0.55, 0.8], +}); + +const FW = 96; +const GURNEY_V = 48; +const WALL = "#33493f"; +const METAL = "#9aa8a4"; +const METAL_D = "#5c6a66"; +const SHEET = "#e8f0ea"; +const SHEET_D = "#b4c4ba"; + +// A number in 0..1 from two integers, the same every time (no random draws). +const rnd = (a, b = 0) => { + let h = Math.imul((a | 0) + 0x9e37, 0x85ebca6b) ^ Math.imul((b | 0) + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +const poly = (c, pts) => { + c.beginPath(); + pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); + c.closePath(); +}; +const seg = (c, x0, y0, x1, y1) => { + c.beginPath(); + c.moveTo(x0, y0); + c.lineTo(x1, y1); + c.stroke(); +}; +const disc = (c, x, y, r) => { + c.beginPath(); + c.arc(x, y, r, 0, TAU); + c.fill(); +}; +const ring = (c, x, y, r) => { + c.beginPath(); + c.arc(x, y, r, 0, TAU); + c.stroke(); +}; +const grad = (make, stops) => { + const g = make ? make() : null; + if (!g || typeof g.addColorStop !== "function") return stops[stops.length >> 1][1]; + for (const [o, col] of stops) g.addColorStop(o, col); + return g; +}; +const vgrad = (c, y0, y1, stops) => grad(c.createLinearGradient && (() => c.createLinearGradient(0, y0, 0, y1)), stops); +const rgrad = (c, x, y, r, stops) => grad(c.createRadialGradient && (() => c.createRadialGradient(x, y, 0, x, y, r)), stops); +const ellipse = (c, x, y, rx, ry, rot = 0) => { + c.beginPath(); + if (typeof c.ellipse === "function") c.ellipse(x, y, rx, ry, rot, 0, TAU); + else c.arc(x, y, Math.max(rx, ry), 0, TAU); +}; + +// A soft round glow per color, drawn as a radial gradient (a plain disc where the context has none). +const HALO = freeze({ warm: "255,214,140", red: "255,70,50", green: "90,240,130", cold: "170,230,255", white: "235,245,255", amber: "255,170,40" }); +function halo(ctx, kind, x, y, r, alpha) { + if (alpha <= 0.01) return; + ctx.globalAlpha = alpha; + ctx.fillStyle = rgrad(ctx, x, y, r, [[0, `rgba(${HALO[kind]},0.9)`], [0.4, `rgba(${HALO[kind]},0.35)`], [1, `rgba(${HALO[kind]},0)`]]); + ctx.fillRect(x - r, y - r, r * 2, r * 2); + ctx.globalAlpha = 1; +} + +/* ------------------------------------------------------------ the track */ + +const yOn = (pts, x) => { + if (x <= pts[0][0]) return pts[0][1]; + let i = 0; + while (i < pts.length - 2 && x > pts[i + 1][0]) i++; + const [xa, ya] = pts[i]; + const [xb, yb] = pts[i + 1]; + if (x >= xb) return yb; + return ya + ((yb - ya) * (x - xa)) / (xb - xa); +}; +const heightAt = (R, x) => { + let best = null; + for (const pts of R.track) { + if (x < pts[0][0] || x > pts[pts.length - 1][0]) continue; + const y = yOn(pts, x); + if (best === null || y > best) best = y; + } + return best; +}; + +/* ------------------------------------------------------------- telegraphs */ + +// What to do about each obstacle, a glyph that fades in ahead of it: DUCK for a lamp or a door +// overhead (an arrow down, amber), JUMP for a shaft, a wheelchair or an IV stand (an arrow up, +// cyan), SHOOT for a surge lamp (red). Orderlies get none: their door shivering is their warning. +export const TELEGRAPH_SEE = 40; +export const TELEGRAPH_FULL = 30; +export const TELEGRAPH_WORDS = 3; +export const TELEGRAPH_ALPHA = 0.72; +export const ANSWERS = freeze({ shaft: "JUMP", chair: "JUMP", stand: "JUMP", lamp: "DUCK", door: "DUCK", surge: "SHOOT" }); +const COLORS = freeze({ ...ANSWER_COLORS, SHOOT: "#ff6a50" }); + +const marks = new WeakMap(); +// Every obstacle that wants a glyph: { kind, lead (where it begins), x (its middle), up (height +// of the glyph's anchor), n (which of its kind), answer }, in the room's order. +export function telegraphMarks(R) { + if (marks.has(R)) return marks.get(R); + const out = []; + const count = {}; + const add = (kind, lead, x, up) => { + const n = count[kind] || 0; + count[kind] = n + 1; + out.push({ kind, lead, x, up, n, answer: ANSWERS[kind] }); + }; + for (let i = 0; i + 1 < R.track.length; i++) { + const a = R.track[i].at(-1)[0]; + const b = R.track[i + 1][0][0]; + add("shaft", a, (a + b) / 2, Math.max(heightAt(R, a - 0.1) ?? 0, heightAt(R, b + 0.1) ?? 0) + 6.5); + } + for (const [x] of R.chairs) add("chair", x - 8, x, (heightAt(R, x) ?? 10) + 7); + for (const [x] of R.stands) add("stand", x, x, (heightAt(R, x) ?? 10) + 9); + for (const [x0, x1, y, kind] of R.lows) add(kind ? "door" : "lamp", x0 - 3.2, (x0 + x1) / 2, y + 6.8); + for (const [x, line] of R.lamps) add("surge", x - 24, x, (R.track[line] ? yOn(R.track[line], x) : 10) + 12.5); + out.sort((p, q) => p.lead - q.lead); + marks.set(R, out); + return out; +} + +// The glyphs showing with the gurney at `x`: { ...mark, alpha (0..1, before the pulse), words }. +export function telegraphs(R, x) { + const out = []; + for (const m of telegraphMarks(R)) { + const d = m.lead - x; + if (d > TELEGRAPH_SEE || d < -6) continue; + const alpha = Math.min(clamp((TELEGRAPH_SEE - d) / (TELEGRAPH_SEE - TELEGRAPH_FULL), 0, 1), clamp((d + 4) / 6, 0, 1)); + if (alpha > 0.01) out.push({ ...m, alpha, words: m.n < (m.kind === "surge" ? 2 : TELEGRAPH_WORDS) }); + } + return out; +} + +/* --------------------------------------------------------------------- art */ + +export function gurneyArt(d) { + const { say, label, GOLD } = d; + const ride = (v) => (v.spec && v.spec.ride && v.spec.ride.runner === ID ? v.spec.ride : null); + const state = (v) => (v.round && v.round.runner && v.round.runner.pack === ID ? v.round.runner : null); + let FH = 54; + const worldY = (y) => FH - y; + const baseOf = (R, x, line) => FH - (R.track[line] && x >= R.track[line][0][0] && x <= R.track[line].at(-1)[0] ? yOn(R.track[line], x) : (heightAt(R, x) ?? 10)); + + /* ------------------------------------------------------------- the room */ + + // The still layers only get the corridor's color: the world is drawn by `moving`. + function backdrop(ctx, v, look, x0, x1) { + ctx.fillStyle = look.wallLow; + ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H); + } + // The start's floor and the ambulance bay at the end: bare concrete with painted lines. + function ground(ctx, v, look, a, b, top) { + const y = v.g.FIELD_H - top; + ctx.fillStyle = vgrad(ctx, y, y + top, [[0, "#7a8480"], [0.3, "#4a5450"], [1, "#1c2220"]]); + ctx.fillRect(a, y, b - a, top + 2); + ctx.fillStyle = "#c8d2cc"; + ctx.fillRect(a, y, b - a, 0.3); + ctx.fillStyle = "#e6c84a"; + for (let x = a + 2; x < b - 2; x += 6) ctx.fillRect(x, y + 1.6, 3, 0.35); + } + function shelf() {} + + /* ------------------------------------------------- the corridor itself */ + + // The ceiling tubes' state: lit (a few flicker), buzzing in the countdown, dead in the dark. + function tubeOn(c, clock, k) { + if (c && c.phase === "dark") return false; + if (c && c.phase === "warn") return rnd(Math.floor(clock / 65), k + 11 * c.n) > 0.18 + 0.2 * (4 - c.n); + return rnd(Math.floor(clock / 110), k) > 0.05; + } + + function wall(ctx, v, R, c, cam) { + const clock = v.clock; + ctx.fillStyle = vgrad(ctx, 0, FH, [[0, "#070c0b"], [0.12, "#16231f"], [0.55, WALL], [1, "#1e2b26"]]); + ctx.fillRect(cam - 1, 0, FW + 2, FH); + // The ceiling: a dark band with a tube every 24 units. + ctx.fillStyle = "#0a1210"; + ctx.fillRect(cam - 1, 0, FW + 2, 4.2); + ctx.fillStyle = "#1e2c27"; + ctx.fillRect(cam - 1, 4.2, FW + 2, 0.4); + const k0 = Math.floor((cam - 8) / 24); + const k1 = Math.floor((cam + FW + 8) / 24); + for (let k = k0; k <= k1; k++) { + const x = k * 24 + 6; + const on = tubeOn(c, clock, k); + ctx.fillStyle = on ? "#f0fff6" : "#26332e"; + ctx.fillRect(x, 3.2, 10, 0.7); + ctx.fillStyle = METAL_D; + ctx.fillRect(x - 0.5, 3.0, 11, 0.25); + if (on) halo(ctx, "white", x + 5, 4.6, 11, 0.28); + } + // The wall's doors, a room number over each, every 48 units, on the local floor; a window between. + const j0 = Math.floor((cam - 12) / 48); + const j1 = Math.floor((cam + FW + 6) / 48); + for (let j = j0; j <= j1; j++) { + const x = j * 48 + 14; + const fy = heightAt(R, x + 2.5) ?? heightAt(R, x) ?? 14; + const base = worldY(fy); + ctx.fillStyle = "#101a17"; + ctx.fillRect(x - 0.5, base - 12.4, 6, 12.4); + ctx.fillStyle = "#4a5f55"; + ctx.fillRect(x, base - 12, 5, 12); + ctx.fillStyle = "#6f8a7e"; + ctx.fillRect(x + 1, base - 10.6, 3, 2.6); + ctx.fillStyle = METAL; + ctx.fillRect(x + 4, base - 5.6, 0.5, 0.9); + ctx.fillStyle = "#d0d8d2"; + ctx.fillRect(x + 1.6, base - 13.5, 1.8, 0.8); + const wx = j * 48 + 38; + ctx.fillStyle = "#0d1614"; + ctx.fillRect(wx - 0.4, 8.4, 6.8, 7.2); + ctx.fillStyle = "#1c3a44"; + ctx.fillRect(wx, 8.8, 6, 6.4); + ctx.fillStyle = "rgba(190,230,255,0.18)"; + poly(ctx, [[wx + 0.6, 15], [wx + 3.4, 9], [wx + 4.6, 9], [wx + 1.8, 15]]); + ctx.fill(); + ctx.strokeStyle = "#0d1614"; + ctx.lineWidth = 0.25; + seg(ctx, wx + 3, 8.8, wx + 3, 15.2); + } + // The handrail along the wall, following the floor (a line each, none over a shaft). + ctx.strokeStyle = "#7d8c86"; + ctx.lineWidth = 0.35; + for (const pts of R.track) { + if (pts[pts.length - 1][0] < cam - 4 || pts[0][0] > cam + FW + 4) continue; + ctx.beginPath(); + pts.forEach(([x, y], i) => (i ? ctx.lineTo(x, worldY(y + 5.2)) : ctx.moveTo(x, worldY(y + 5.2)))); + ctx.stroke(); + } + } + + // The elevator shafts: a black drop between two lines, door frames at each lip, cables, a car's glow far below. + function shafts(ctx, v, R, c, cam) { + const clock = v.clock; + for (let i = 0; i + 1 < R.track.length; i++) { + const [xa, ya] = R.track[i].at(-1); + const [xb, yb] = R.track[i + 1][0]; + if (xb < cam - 6 || xa > cam + FW + 6) continue; + const top = worldY(Math.max(ya, yb) + 12); + ctx.fillStyle = "#020405"; + ctx.fillRect(xa, top, xb - xa, FH - top + 1); + ctx.strokeStyle = "#2a3532"; + ctx.lineWidth = 0.12; + for (let k = 1; k < 4; k++) seg(ctx, xa + ((xb - xa) * k) / 4, top, xa + ((xb - xa) * k) / 4, FH); + halo(ctx, "amber", (xa + xb) / 2, FH - 1.5, 9, 0.4); + // The door frames and the floor indicator over the opening. + for (const [x, y, side] of [[xa, ya, -1], [xb, yb, 1]]) { + ctx.fillStyle = METAL_D; + ctx.fillRect(x - (side < 0 ? 1.4 : 0), worldY(y + 9.2), 1.4, 9.2); + ctx.fillStyle = METAL; + ctx.fillRect(x - (side < 0 ? 0.4 : 0), worldY(y + 9.2), 0.4, 9.2); + } + const my = worldY(Math.max(ya, yb) + 9.8); + ctx.fillStyle = METAL_D; + ctx.fillRect(xa - 1.4, my, xb - xa + 2.8, 0.9); + const blink = 0.5 + 0.5 * Math.sin(clock / 220 + i); + ctx.fillStyle = `rgba(255,170,40,${0.5 + 0.5 * blink})`; + ctx.fillRect((xa + xb) / 2 - 0.8, my + 0.15, 1.6, 0.6); + halo(ctx, "amber", (xa + xb) / 2, my + 0.5, 4, 0.35 * blink); + } + } + + // The floors: linoleum with a bright lip, a baseboard stripe, and a ragged edge at each line's end. + function floors(ctx, R, cam) { + for (const pts of R.track) { + if (pts[pts.length - 1][0] < cam - 4 || pts[0][0] > cam + FW + 4) continue; + ctx.beginPath(); + pts.forEach(([x, y], i) => (i ? ctx.lineTo(x, worldY(y)) : ctx.moveTo(x, worldY(y)))); + ctx.lineTo(pts.at(-1)[0], FH + 1); + ctx.lineTo(pts[0][0], FH + 1); + ctx.closePath(); + ctx.fillStyle = vgrad(ctx, 8, FH, [[0, "#9fb4aa"], [0.12, "#51645c"], [0.4, "#26332e"], [1, "#0a100e"]]); + ctx.fill(); + ctx.strokeStyle = "#e4f2ea"; + ctx.lineWidth = 0.32; + ctx.beginPath(); + pts.forEach(([x, y], i) => (i ? ctx.lineTo(x, worldY(y)) : ctx.moveTo(x, worldY(y)))); + ctx.stroke(); + // The floor's checker seams, dashes following the slope. + ctx.fillStyle = "rgba(10,20,16,0.4)"; + const a = Math.max(pts[0][0], Math.floor((cam - 2) / 8) * 8); + const b = Math.min(pts.at(-1)[0], cam + FW + 2); + for (let x = a; x < b; x += 8) ctx.fillRect(x, worldY(yOn(pts, x)) + 1.0, 4, 0.3); + } + } + + /* ------------------------------------------------------------ the things */ + + // A wheelchair, side on: a big spoked wheel, a caster, a vinyl seat and back, handles, a footrest. + function chair(ctx, v, x, base, ch, i) { + const spin = (ch.rolling ? -(ch.x * 0.9) : 0) + i; + ctx.save(); + ctx.translate(x, base); + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ellipse(ctx, 0, 0.05, 2.6, 0.3); + ctx.fill(); + ctx.strokeStyle = METAL_D; + ctx.lineWidth = 0.28; + // The frame, seat and back. + seg(ctx, -1.2, -1.6, 1.4, -1.6); + seg(ctx, -1.2, -1.6, -1.6, -3.6); + seg(ctx, 1.4, -1.6, 2.0, -0.7); + seg(ctx, -1.6, -3.6, -2.2, -3.6); + ctx.fillStyle = "#2a2e3a"; + ctx.fillRect(-1.4, -2.0, 2.8, 0.5); + ctx.fillRect(-1.9, -3.7, 0.7, 1.9); + // The big wheel, with spokes turning, and a caster at the front. + ctx.strokeStyle = "#1a1e22"; + ctx.lineWidth = 0.34; + ring(ctx, -0.6, -1.5, 1.5); + ctx.strokeStyle = METAL; + ctx.lineWidth = 0.1; + ring(ctx, -0.6, -1.5, 1.1); + for (let k = 0; k < 6; k++) { + const a = spin + (k * TAU) / 6; + seg(ctx, -0.6, -1.5, -0.6 + Math.cos(a) * 1.4, -1.5 + Math.sin(a) * 1.4); + } + ctx.fillStyle = "#1a1e22"; + disc(ctx, 1.9, -0.45, 0.45); + ctx.fillStyle = METAL; + ctx.fillRect(1.9, -0.5, 0.1, -0.2); + seg(ctx, 2.0, -0.7, 2.6, -0.9); + ctx.restore(); + } + + // An IV stand: a five-footed base on casters, a tall pole, a hook with a swaying bag and its tube. + function stand(ctx, v, x, base, i) { + const sway = Math.sin(v.clock / 380 + i) * 0.15; + ctx.save(); + ctx.translate(x, base); + ctx.strokeStyle = METAL; + ctx.lineWidth = 0.22; + seg(ctx, 0, -0.6, 0, -6.2); + seg(ctx, -1.5, -0.45, 1.5, -0.45); + seg(ctx, -1.5, -0.45, -1.2, -0.1); + seg(ctx, 1.5, -0.45, 1.2, -0.1); + ctx.fillStyle = "#1a1e22"; + disc(ctx, -1.4, -0.2, 0.22); + disc(ctx, 1.4, -0.2, 0.22); + seg(ctx, -1.2, -6.1, 1.2, -6.1); + // The bag: translucent blue, a tube down to a dripping tip. + ctx.fillStyle = "rgba(150,210,235,0.75)"; + poly(ctx, [[0.9 + sway, -6.0], [1.9 + sway, -6.0], [2.0 + sway, -4.4], [1.4 + sway, -3.9], [0.8 + sway, -4.4]]); + ctx.fill(); + ctx.fillStyle = "rgba(255,255,255,0.5)"; + ctx.fillRect(1.0 + sway, -5.8, 0.25, 1.2); + ctx.strokeStyle = "rgba(200,230,240,0.8)"; + ctx.lineWidth = 0.08; + ctx.beginPath(); + ctx.moveTo(1.4 + sway, -3.9); + ctx.quadraticCurveTo(0.2, -3.0, 0.5, -1.4); + ctx.stroke(); + ctx.restore(); + } + + // A doorway in the wall with an orderly in it: a shut door, shivering, flung open with a hulking orderly lunging out, sinking back, or empty. + function doorway(ctx, v, x, base, o, i) { + const clock = v.clock; + const open = o.state === "up" || o.state === "sink" || o.state === "spent" || o.state === "broken"; + ctx.fillStyle = "#0b1210"; + ctx.fillRect(x - 3.1, base - 8.6, 6.2, 8.6); + ctx.fillStyle = open ? "#16100e" : "#4a5f55"; + ctx.fillRect(x - 2.7, base - 8.2, 5.4, 8.2); + if (!open) { + const shake = o.state === "warn" ? Math.sin(clock / 24) * 0.22 : 0; + ctx.fillStyle = "#586f64"; + ctx.fillRect(x - 2.4 + shake, base - 7.9, 4.8, 7.9); + ctx.fillStyle = "#6f8a7e"; + ctx.fillRect(x - 1.6 + shake, base - 6.8, 3.2, 2.4); + if (o.state === "warn") { + halo(ctx, "red", x, base - 4.5, 5, 0.5 + 0.3 * Math.sin(clock / 60)); + ctx.fillStyle = "rgba(255,90,60,0.7)"; + ctx.fillRect(x + 2.3 + shake, base - 8.0, 0.35, 8); + } + ctx.fillStyle = METAL; + ctx.fillRect(x + 1.5 + shake, base - 3.6, 0.5, 0.8); + return; + } + // The door flung back against the wall. + ctx.fillStyle = "#586f64"; + poly(ctx, [[x - 2.7, base - 8.2], [x - 3.6, base - 7.6], [x - 3.6, base - 0.4], [x - 2.7, base]]); + ctx.fill(); + if (o.state === "spent" || o.state === "broken") { + if (o.state === "broken") { + ctx.fillStyle = "#3a1a1e"; + ellipse(ctx, x, base - 0.2, 1.6, 0.3); + ctx.fill(); + } + return; + } + // The orderly: a huge figure in a stained white coat, a bald pale head, a gauze mask, arms reaching. + const out = o.state === "sink" ? clamp(o.t / 300, 0, 1) : clamp((1600 - o.t) / 160, 0, 1); + const lean = 1.4 * out + Math.sin(clock / 90 + i) * 0.15; + ctx.save(); + ctx.translate(x, base); + ctx.fillStyle = "#cdd8d0"; + poly(ctx, [[-1.8, 0], [-1.6, -3.4], [-0.8, -4.7], [0.9 + lean * 0.5, -4.7], [1.8 + lean, -3.2], [1.9 + lean * 0.3, 0]]); + ctx.fill(); + ctx.fillStyle = "#8a2a2a"; + ctx.fillRect(-0.4, -3.6, 1.2, 1.5); + ctx.fillRect(0.2, -2.0, 0.8, 0.9); + ctx.fillStyle = "#b8c4b8"; + ellipse(ctx, 0.5 + lean * 0.6, -5.4, 0.85, 0.95); + ctx.fill(); + ctx.fillStyle = "#e0e8dc"; + ctx.fillRect(-0.2 + lean * 0.6, -5.3, 1.4, 0.8); + ctx.fillStyle = "#0b1218"; + ctx.fillRect(0.0 + lean * 0.6, -5.8, 0.35, 0.3); + ctx.fillRect(0.8 + lean * 0.6, -5.8, 0.35, 0.3); + ctx.strokeStyle = "#cdd8d0"; + ctx.lineWidth = 0.7; + ctx.lineCap = "round"; + seg(ctx, 1.4 + lean * 0.5, -4.2, 3.2 + lean * 1.2, -3.6 + Math.sin(clock / 70) * 0.3); + seg(ctx, 0.8, -4.0, 2.6 + lean, -2.6); + ctx.lineCap = "butt"; + ctx.restore(); + v.eyes.push(x + 0.2 + lean * 0.6, base - 5.65, 0.3, "#ff5a4a"); + v.eyes.push(x + 1.0 + lean * 0.6, base - 5.65, 0.3, "#ff5a4a"); + } + + // A surge lamp: a caged emergency lamp hung high on a chain, buzzing and spitting sparks; shot, it shorts out and smokes. + function surge(ctx, v, x, base, broken, i, wave) { + const clock = v.clock; + const cy = base - 7.4; + ctx.strokeStyle = "#3a4642"; + ctx.lineWidth = 0.18; + seg(ctx, x, 0, x, cy - 1.5); + ctx.fillStyle = METAL_D; + ctx.fillRect(x - 0.9, cy - 1.7, 1.8, 0.5); + ctx.fillStyle = broken ? "#1a1e1e" : "#ffe6a0"; + ellipse(ctx, x, cy, 1.1, 1.3); + ctx.fill(); + ctx.strokeStyle = METAL; + ctx.lineWidth = 0.14; + ring(ctx, x, cy, 1.4); + seg(ctx, x - 1.4, cy, x + 1.4, cy); + seg(ctx, x, cy - 1.4, x, cy + 1.4); + if (broken) { + for (let k = 0; k < 4; k++) { + const p = ((clock / 700 + k * 0.27) % 1); + ctx.fillStyle = `rgba(110,120,120,${0.5 * (1 - p)})`; + disc(ctx, x + (rnd(k, i) - 0.5) * 1.2, cy - 1.6 - p * 3, 0.3 + p * 0.5); + } + return; + } + const buzz = 0.5 + 0.5 * Math.sin(clock / 45 + i * 3); + halo(ctx, "warm", x, cy, 6, 0.35 + 0.4 * buzz * (rnd(Math.floor(clock / 60), i) > 0.4 ? 1 : 0.3)); + ctx.strokeStyle = "#fff6c8"; + ctx.lineWidth = 0.12; + for (let k = 0; k < 3; k++) { + const a = rnd(Math.floor(clock / 80), i * 4 + k) * TAU; + const r = 1.6 + rnd(Math.floor(clock / 80), i * 5 + k) * 1.4; + seg(ctx, x + Math.cos(a) * 1.3, cy + Math.sin(a) * 1.3, x + Math.cos(a) * r, cy + Math.sin(a) * r); + } + } + + // A checkpoint: a post with a lantern, red until passed, then green. + function checkpoint(ctx, v, x, base, on, i) { + const clock = v.clock; + ctx.strokeStyle = "#1a2220"; + ctx.lineWidth = 0.35; + seg(ctx, x, base + 0.2, x, base - 5.4); + seg(ctx, x, base - 5.2, x + 1.1, base - 5.2); + const pulse = on ? 1 : 0.7 + 0.3 * Math.sin(clock / 160 + i); + halo(ctx, on ? "green" : "red", x + 1.1, base - 4.5, on ? 4.2 : 3.6, 0.7 * pulse); + ctx.fillStyle = "#14181a"; + ctx.fillRect(x + 0.6, base - 5.3, 1, 1.7); + ctx.fillStyle = on ? "#7dffa0" : "#ff5a40"; + ctx.fillRect(x + 0.75, base - 5.1, 0.7, 1.3); + ctx.fillStyle = on ? "#eaffee" : "#ffc0a0"; + ctx.fillRect(x + 0.95, base - 4.9, 0.25, 0.5); + } + + // The finish: the ambulance doors thrown open on the bay, a green EXIT sign, and an ambulance's flashing lights. + function finishGate(ctx, v, x, base) { + const clock = v.clock; + ctx.fillStyle = "#0a100e"; + ctx.fillRect(x - 2, base - 15, 20, 15); + ctx.fillStyle = "#26332e"; + ctx.fillRect(x - 1, base - 14, 18, 14); + // The ambulance's back: a white box, a red cross, its lights turning. + ctx.fillStyle = "#e8eeea"; + ctx.fillRect(x + 3, base - 10.5, 11, 10.5); + ctx.fillStyle = "#c8d2cc"; + ctx.fillRect(x + 3, base - 4.2, 11, 0.5); + ctx.fillStyle = "#d62a34"; + ctx.fillRect(x + 7.8, base - 8.6, 1.6, 4.6); + ctx.fillRect(x + 6.4, base - 7.1, 4.4, 1.6); + const sw = Math.floor(clock / 220) % 2; + ctx.fillStyle = sw ? "#ff3a3a" : "#3a6aff"; + ctx.fillRect(x + 3.4, base - 11.3, 2.2, 0.8); + ctx.fillStyle = sw ? "#3a6aff" : "#ff3a3a"; + ctx.fillRect(x + 11.4, base - 11.3, 2.2, 0.8); + halo(ctx, "red", x + 4.5, base - 11, 7, sw ? 0.5 : 0.15); + halo(ctx, "cold", x + 12.5, base - 11, 7, sw ? 0.15 : 0.5); + ctx.fillStyle = "#14181a"; + disc(ctx, x + 6, base - 0.2, 1.2); + disc(ctx, x + 12, base - 0.2, 1.2); + ctx.fillStyle = "#1f8a4a"; + ctx.fillRect(x + 5, base - 14.8, 7, 1.6); + label(ctx, "EXIT", x + 8.5, base - 13.4, 1.3, "#d8ffe4", "center"); + } + + /* ---------------------------------------------------------- the world */ + + function moving(ctx, v, cam) { + const R = ride(v); + const c = state(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + cam = Math.round(cam * 8) / 8; + wall(ctx, v, R, c, cam); + shafts(ctx, v, R, c, cam); + floors(ctx, R, cam); + const lo = cam - 8; + const hi = cam + FW + 8; + R.checks.forEach((x, i) => { + if (x > lo && x < hi) checkpoint(ctx, v, x, baseOf(R, x, R.track.findIndex((p) => x >= p[0][0] && x <= p.at(-1)[0])), i <= c.check, i); + }); + if (R.finish > lo - 14 && R.finish < hi) finishGate(ctx, v, R.finish + 10, worldY(10)); + R.orderlies.forEach(([x, line], i) => { + if (x > lo && x < hi) doorway(ctx, v, x, baseOf(R, x, line), c.orderlies[i], i); + }); + R.lamps.forEach(([x, line], i) => { + if (x > lo && x < hi) surge(ctx, v, x, baseOf(R, x, line), Boolean(c.lamps[i]), i, c.waves[i]); + }); + R.stands.forEach(([x, line], i) => { + if (x > lo && x < hi) stand(ctx, v, x, baseOf(R, x, line), i); + }); + R.chairs.forEach(([x0, line], i) => { + const ch = c.chairs[i]; + if (ch.x > lo && ch.x < hi) chair(ctx, v, ch.x, baseOf(R, ch.x, line), ch, i); + }); + // The bay and the start's floor, over the wall (the still layers' were painted under it). + for (const [a, b, top] of v.spec.ground) if (b > lo && a < hi) ground(ctx, v, LOOKS.codeblue, a, b, top); + // A finished ride: the gurney rests where it came to a stop, behind Planny as he walks out. + if (c.done) gurney(ctx, v, R, c); + } + + /* ---------------------------------------------------- the gurney, in front */ + + // The gurney with Planny strapped on (he is drawn by the game behind its sheet and belts): frame, wheels, mattress, sheet, straps, an IV pole and a beacon. + function gurney(ctx, v, R, c) { + const { round } = v; + const you = round.you; + const clock = v.clock; + const fx = v.fx; + const done = c.done; + const x = done && c.restX !== undefined ? c.restX : you.x; + let y = done ? (v.spec.ground.find(([a, b]) => x >= a && x <= b) || [0, 0, 10])[2] : you.y; + let pitch; + if (done) pitch = 0; + else if (c.line >= 0) pitch = Math.atan2((heightAt(R, x + 3) ?? y) - (heightAt(R, x - 3) ?? y), 6) * 0.95; + else pitch = clamp(you.vy / Math.max(14, c.v), -1, 1) * 0.4; + const fast = !done && c.line >= 0; + const shake = fast ? Math.sin(clock / 29) * 0.04 * (c.v / GURNEY_V) : 0; + ctx.save(); + ctx.translate(x, FH - y + shake); + ctx.rotate(-pitch); + // Sparks off the squealing wheels, longer the faster it goes. + if (fast) { + for (let k = 0; k < 10; k++) { + const p = ((clock / (260 + (k % 4) * 50) + k * 0.131) % 1); + ctx.fillStyle = `rgba(255,${190 - Math.floor(p * 90)},80,${(1 - p) * 0.9})`; + disc(ctx, -2.6 - p * (2.5 + (c.v / GURNEY_V) * 3) * (0.6 + rnd(k, 1)), -0.2 - p * (0.6 + rnd(k, 2) * 1.5), 0.12 + (1 - p) * 0.14); + } + } + ctx.save(); + ctx.scale(1.1, 1.3); + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ellipse(ctx, 0.1, 0.1, 3.8, 0.25); + ctx.fill(); + // The undercarriage: two legs with a cross brace, and the wheels with a hub that turns. + ctx.strokeStyle = METAL; + ctx.lineWidth = 0.18; + seg(ctx, -2.8, -1.1, -2.8, -0.4); + seg(ctx, 2.8, -1.1, 2.8, -0.4); + seg(ctx, -2.8, -1.0, 2.8, -0.6); + ctx.strokeStyle = "#1a1e22"; + ctx.lineWidth = 0.3; + for (const wx of [-2.8, 2.8]) { + ring(ctx, wx, -0.45, 0.45); + ctx.strokeStyle = METAL; + ctx.lineWidth = 0.1; + const a = x * 1.3 + wx; + seg(ctx, wx, -0.45, wx + Math.cos(a) * 0.4, -0.45 + Math.sin(a) * 0.4); + ctx.strokeStyle = "#1a1e22"; + ctx.lineWidth = 0.3; + } + // The mattress on its steel frame, a side rail, the head raised, and a pillow. + ctx.fillStyle = METAL_D; + ctx.fillRect(-3.8, -1.35, 7.6, 0.28); + ctx.fillStyle = "#3a5a6a"; + ctx.beginPath(); + ctx.moveTo(-3.7, -1.35); + ctx.lineTo(3.7, -1.35); + ctx.lineTo(3.7, -1.9); + ctx.lineTo(-3.7, -1.9); + ctx.closePath(); + ctx.fill(); + ctx.strokeStyle = METAL; + ctx.lineWidth = 0.1; + seg(ctx, -3.6, -2.5, 3.6, -2.5); + seg(ctx, -2.4, -2.5, -2.4, -1.35); + seg(ctx, 0.4, -2.5, 0.4, -1.35); + seg(ctx, 2.6, -2.5, 2.6, -1.35); + ctx.restore(); + // The sheet over his legs and the two belts across him, in front of Planny. + ctx.fillStyle = SHEET; + poly(ctx, [[-3.5, -0.9], [-3.3, -2.7], [-2.2, -3.0], [0.2, -2.8], [2.2, -3.0], [3.5, -2.6], [3.6, -0.9]]); + ctx.fill(); + ctx.fillStyle = SHEET_D; + poly(ctx, [[-0.6, -0.9], [-0.4, -2.8], [0.6, -2.85], [0.9, -0.9]]); + ctx.fill(); + ctx.strokeStyle = "rgba(120,140,130,0.6)"; + ctx.lineWidth = 0.08; + seg(ctx, -2.4, -2.6, -2.1, -1.3); + seg(ctx, 1.8, -2.7, 2.0, -1.2); + for (const by of [-3.0, -2.2]) { + ctx.fillStyle = "#2a3a6a"; + ctx.fillRect(-3.0, by * 1.0 - 0.18, 6.0, 0.4); + ctx.fillStyle = "#c9a24a"; + ctx.fillRect(0.2, by * 1.0 - 0.22, 0.5, 0.48); + } + // The IV pole at the foot and its swaying bag, and a red beacon that blinks. + ctx.strokeStyle = METAL; + ctx.lineWidth = 0.14; + seg(ctx, 3.9, -2.5, 3.9, -7.4); + seg(ctx, 3.9, -7.4, 3.0, -7.4); + const sw = Math.sin(clock / 210) * 0.2; + ctx.fillStyle = "rgba(150,210,235,0.8)"; + poly(ctx, [[2.6 + sw, -7.3], [3.4 + sw, -7.3], [3.5 + sw, -5.9], [3.0 + sw, -5.5], [2.5 + sw, -5.9]]); + ctx.fill(); + const blink = Math.floor(clock / 260) % 2; + ctx.fillStyle = blink ? "#ff4a3a" : "#5a1a16"; + disc(ctx, -3.9, -2.3, 0.28); + if (blink && !done) halo(ctx, "red", -3.9, -2.3, 3.2, 0.5); + // A landing's puff of dust. + const land = fx && fx.blueLand !== undefined ? fx.clock - fx.blueLand.t0 : 1e9; + if (land < 380) { + for (let k = 0; k < 7; k++) { + const p = land / 380; + ctx.fillStyle = `rgba(200,210,205,${(1 - p) * 0.7})`; + disc(ctx, (k - 3) * 0.9 * (0.5 + p * 1.4), -0.3 - p * (0.8 + rnd(k, 4) * 1.4) * (fx.blueLand.big ? 1.6 : 1), 0.25 + p * 0.3); + } + } + ctx.restore(); + } + + // A hanging surgical lamp (kind 0): a ceiling arm and a big disc of bulbs; or a pair of swinging doors (kind 1) hung from the ceiling, their bottom edge the underside. + function low(ctx, v, x0, x1, y, kind, i) { + const clock = v.clock; + const cx = (x0 + x1) / 2; + const bottom = worldY(y); + const sway = Math.sin(clock / 330 + i * 1.7) * 0.5; + if (!kind) { + ctx.strokeStyle = METAL_D; + ctx.lineWidth = 0.4; + seg(ctx, cx, 0, cx, bottom - 1.4); + seg(ctx, cx, bottom - 1.4, cx + sway, bottom - 0.9); + ctx.fillStyle = "#c8d2cc"; + ellipse(ctx, cx + sway, bottom - 0.5, (x1 - x0) / 2 + 0.6, 0.85); + ctx.fill(); + ctx.fillStyle = "#7a8682"; + ellipse(ctx, cx + sway, bottom - 0.2, (x1 - x0) / 2 + 0.2, 0.45); + ctx.fill(); + ctx.fillStyle = "#fff6d8"; + for (let k = 0; k < 5; k++) disc(ctx, cx + sway + (k - 2) * ((x1 - x0) / 5.5), bottom + 0.05, 0.28); + halo(ctx, "warm", cx + sway, bottom + 0.4, 6, 0.4); + return; + } + // Two door slabs with portholes, swinging on their hinges at each side and a rubber strip along the bottom. + const w = (x1 - x0) / 2; + for (const side of [-1, 1]) { + const hx = side < 0 ? x0 : x1; + const lean = sway * side * -1; + ctx.fillStyle = "#586f64"; + poly(ctx, [[hx, 0], [hx - side * w, 0], [hx - side * w + lean, bottom], [hx + lean * 0.2, bottom]]); + ctx.fill(); + ctx.fillStyle = "#6f8a7e"; + poly(ctx, [[hx - side * w * 0.2, bottom - 2.4], [hx - side * w * 0.8, bottom - 2.4], [hx - side * w * 0.8 + lean * 0.8, bottom - 4.6], [hx - side * w * 0.2 + lean * 0.3, bottom - 4.6]]); + ctx.fill(); + ctx.fillStyle = "#1c3a44"; + disc(ctx, hx - side * w * 0.5 + lean * 0.6, bottom - 3.6, 0.7); + ctx.fillStyle = "#14181a"; + ctx.fillRect(Math.min(hx, hx - side * w + lean), bottom - 0.3, w, 0.3); + } + ctx.strokeStyle = "#2a3430"; + ctx.lineWidth = 0.15; + seg(ctx, cx, 0, cx, bottom); + } + + // A glyph over an obstacle, saying what to do about it. + function glyph(ctx, v, t) { + const up = t.answer === "JUMP"; + const shoot = t.answer === "SHOOT"; + const col = COLORS[t.answer]; + const pulse = 0.85 + 0.15 * Math.sin(v.clock / 260 + t.lead); + const bob = Math.sin(v.clock / 260 + t.lead) * 0.35 * (up ? -1 : 1); + const cy = Math.min(FH - 7, FH - t.up) + bob; + const ay = cy + (up ? -2.6 : 2.6); + ctx.save(); + ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA; + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + if (shoot) { + for (const [w, cc] of [[1.2, "rgba(4,8,22,0.8)"], [0.5, col]]) { + ctx.strokeStyle = cc; + ctx.lineWidth = w; + ring(ctx, t.x, cy - 1.8, 1.6); + seg(ctx, t.x - 2.4, cy - 1.8, t.x - 0.9, cy - 1.8); + seg(ctx, t.x + 0.9, cy - 1.8, t.x + 2.4, cy - 1.8); + seg(ctx, t.x, cy - 3.3, t.x, cy - 4.4); + } + } else { + const dir = up ? -1 : 1; + for (const [pass, w, cc] of [[0, 1.3, "rgba(4,8,22,0.8)"], [1, 0.6, col]]) { + ctx.strokeStyle = cc; + ctx.lineWidth = w; + for (let k = 0; k < 2; k++) { + const oy = ay + (k - 0.5) * 1.5 * dir - dir * 0.2; + if (k === 1 && pass === 1) ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA * 0.55; + ctx.beginPath(); + ctx.moveTo(t.x - 1.7, oy - dir * 0.9); + ctx.lineTo(t.x, oy + dir * 0.9); + ctx.lineTo(t.x + 1.7, oy - dir * 0.9); + ctx.stroke(); + } + ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA; + } + } + if (t.words) label(ctx, t.answer, t.x, shoot ? cy + 1.2 : cy + (up ? 1.2 : -1.2), 2.3, col, "center"); + ctx.restore(); + } + + /* ------------------------------------------- the countdown and the monitor */ + + // The heartbeat monitor: a trace across the top that scrolls left, a spike per beat, the beats closer the fewer hearts are left, a flat red line at the last heart. + function monitor(ctx, v, c, cam) { + const b = v.round.bonusRound; + const hearts = b ? b.hearts : 5; + const flat = Boolean(c.flat) || hearts <= 1; + const every = c.every || 1000; + const y0 = 9.4; + const amp = 2.3; + const x0 = cam + 5; + const W = 80; + const speed = 30; + ctx.fillStyle = "rgba(2,10,8,0.55)"; + ctx.fillRect(x0 - 1, y0 - 3.4, W + 12, 6.8); + ctx.strokeStyle = flat ? "#ff5a4a" : "#6dffb0"; + ctx.lineWidth = 0.22; + ctx.lineJoin = "round"; + ctx.beginPath(); + const age0 = c.pulse * every; + for (let px = 0; px <= W; px += 0.5) { + const ago = ((W - px) / speed) * 1000; + let s = 0; + if (!flat) { + for (let k = 0; k < 6; k++) { + const dt = (age0 + k * every - ago) / 1000; + if (dt < -0.3 || dt > 0.5) continue; + s += 0.18 * Math.exp(-(((dt + 0.16) / 0.035) ** 2)) - 0.22 * Math.exp(-(((dt + 0.03) / 0.012) ** 2)) + Math.exp(-((dt / 0.014) ** 2)) - 0.4 * Math.exp(-(((dt - 0.035) / 0.014) ** 2)) + 0.32 * Math.exp(-(((dt - 0.22) / 0.05) ** 2)); + } + } + const yy = y0 - s * amp; + if (px === 0) ctx.moveTo(x0 + px, yy); + else ctx.lineTo(x0 + px, yy); + } + ctx.stroke(); + ctx.fillStyle = flat ? "#ff5a4a" : "#d8ffe8"; + disc(ctx, x0 + W, y0, 0.4); + label(ctx, flat ? "FLAT" : `${Math.round(60000 / every)}`, x0 + W + 10, y0 + 0.7, 2.2, flat ? "#ff5a4a" : "#6dffb0", "right"); + } + + // LIGHTS OUT and its countdown, in the middle of the screen, red. + function countdown(ctx, v, c, cam) { + if (c.phase !== "warn") return; + const pulse = 0.7 + 0.3 * Math.sin(v.clock / 70); + ctx.globalAlpha = pulse; + label(ctx, "LIGHTS OUT", cam + FW / 2, 16, 2.6, "#ff8070", "center"); + label(ctx, String(c.n), cam + FW / 2, 24, 8, "#ff4a3a", "center"); + ctx.globalAlpha = 1; + } + + function front(ctx, v) { + const R = ride(v); + const round = v.round; + const c = state(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + const cam = Math.round(round.camX * 8) / 8; + const lo = cam - 8; + const hi = cam + FW + 8; + if (!c.done) gurney(ctx, v, R, c); + R.lows.forEach(([x0, x1, y, kind], i) => { + if (x1 >= lo && x0 <= hi) low(ctx, v, x0, x1, y, kind, i); + }); + if (!c.done) for (const t of telegraphs(R, round.you.x)) glyph(ctx, v, t); + // Glass and sparks from a shot lamp, tumbling. + const bits = v.fx && v.fx.blueBits; + if (bits) { + for (const b of bits) { + const t = (v.fx.clock - b.t0) / 1000; + if (t < 0 || t > 0.9) continue; + ctx.save(); + ctx.translate(b.x + b.vx * t, FH - (b.y + b.vy * t - 30 * t * t)); + ctx.rotate(b.rot + b.vr * t); + ctx.globalAlpha = clamp(1.6 - t * 1.6, 0, 1); + ctx.fillStyle = b.c; + ctx.fillRect(-b.w / 2, -0.12, b.w, 0.24); + ctx.restore(); + } + ctx.globalAlpha = 1; + } + countdown(ctx, v, c, cam); + monitor(ctx, v, c, cam); + } + + /* -------------------------------------------------- the dark and its lights */ + + // How dark the corridor is: the blackout's fade, a flicker in the countdown, none otherwise. + function dim(v) { + const c = state(v); + if (!c || !ride(v)) return 0; + if (c.phase === "dark") return 0.97 * c.dark; + if (c.phase === "warn") return rnd(Math.floor(v.clock / 70), 7 + c.n) > 0.62 - 0.12 * (3 - c.n) ? 0.8 : 0; + return 0; + } + + // What stays lit in the dark: the monitor's band across the top, the telegraph glyphs, a faint + // pool on every obstacle near (so it shows as an outline) and the emergency strips along the + // floor, dying away through the blackout; lit always: the surge lamps, the checkpoints, the lip. + function lights(v, add) { + const R = ride(v); + const c = state(v); + if (!R || !c) return; + const round = v.round; + const you = round.you; + const clock = v.clock; + const cam = round.camX; + const lo = cam - 10; + const hi = cam + FW + 10; + const dark = c.phase === "dark" || c.phase === "warn"; + // The monitor's band. + for (const dx of [16, 48, 80]) add(cam + dx, FH - 9, 22, 0.85); + if (c.phase === "warn") add(cam + FW / 2, FH - 20, 14, 0.8); + // The pool of light the gurney's beacon throws. + add(you.x - 1, you.y + 2, 7, 0.4); + if (dark) { + // The emergency strips, red, along the floor every 20 units, dying away. + const w = R.waves[c.wave] || R.waves.find(([x0, x1]) => you.x < x1) || [0, 1]; + const left = clamp(1 - (you.x - w[0]) / Math.max(1, w[1] - w[0]), 0, 1); + const a = 0.12 + 0.2 * left; + for (let x = Math.floor(lo / 20) * 20; x < hi; x += 20) { + const fy = heightAt(R, x); + if (fy === null) continue; + add(x + 6, fy + 0.8, 6.5, a * (0.7 + 0.3 * Math.sin(clock / 230 + x)) * (rnd(Math.floor(clock / 140), x | 0) > 0.08 ? 1 : 0.3)); + } + // Each thing near, a faint pool: the outline. + const near = (x) => x > you.x - 4 && x < you.x + 62; + R.chairs.forEach(([x0, line], i) => { + if (near(c.chairs[i].x)) add(c.chairs[i].x, (heightAt(R, c.chairs[i].x) ?? 10) + 2, 4, 0.2); + }); + R.stands.forEach(([x]) => near(x) && add(x, (heightAt(R, x) ?? 10) + 3, 4, 0.2)); + R.orderlies.forEach(([x], i) => near(x) && c.orderlies[i].state !== "spent" && add(x, (heightAt(R, x) ?? 10) + 3, 4.5, c.orderlies[i].state === "up" ? 0.3 : 0.18)); + R.lows.forEach(([x0, x1, y]) => near((x0 + x1) / 2) && add((x0 + x1) / 2, y + 0.5, 5, 0.22)); + for (let i = 0; i + 1 < R.track.length; i++) { + const [xa, ya] = R.track[i].at(-1); + if (near(xa)) add(xa + 6, Math.max(ya, R.track[i + 1][0][1]) + 1.5, 8, 0.28 + 0.1 * Math.sin(clock / 200 + i)); + } + for (const t of telegraphs(R, you.x)) add(t.x, t.up, 3.6, 0.32 * t.alpha); + } + R.checks.forEach((x, i) => { + if (x > lo && x < hi) add(x + 1.1, (heightAt(R, x) ?? 10) + 4.5, i <= c.check ? 8 : 7, i <= c.check ? 0.6 : 0.5); + }); + R.lamps.forEach(([x, line], i) => { + if (x > lo && x < hi && !c.lamps[i]) add(x, (heightAt(R, x) ?? 10) + 7.4, 6, 0.7); + }); + R.orderlies.forEach(([x], i) => { + if (x > lo && x < hi && c.orderlies[i].state === "warn") add(x, (heightAt(R, x) ?? 10) + 4, 5, 0.5); + }); + if (R.finish > lo - 14 && R.finish < hi) add(R.finish + 19, 17, 14, 0.6); + if (v.fx && v.fx.blueLand && v.fx.clock - v.fx.blueLand.t0 < 260) add(you.x, you.y + 1, 6, 0.4); + } + + /* -------------------------------------------------------------- events */ + + // A throttle on a repeating cue. + function gateOnce(fx, key, ms) { + if ((fx[key] || 0) > fx.clock) return false; + fx[key] = fx.clock + ms; + return true; + } + // Glass and sparks flying out of a spot. + function splinter(fx, x, y, colors) { + fx.blueBits = (fx.blueBits || []).filter((b) => fx.clock - b.t0 < 1000); + for (let k = 0; k < 9; k++) fx.blueBits.push({ x, y, t0: fx.clock, vx: (rnd(k, 1) - 0.5) * 22, vy: 8 + rnd(k, 2) * 14, rot: rnd(k, 3) * TAU, vr: (rnd(k, 4) - 0.5) * 22, w: 0.5 + rnd(k, 5) * 0.9, c: colors[k % colors.length] }); + } + + // What the pack's events look and sound like; true when the event is its own. Each of its + // sounds plays once, from EVENT_VOICE. + function react(e, k) { + const { tone, shake, flash, burst, float, ring: ringFx, fx } = k; + const voice = EVENT_VOICE[e.type]; + if (!voice) return false; + if (e.type === "blueDuck" && !gateOnce(fx, "blueDuckMs", 160)) return true; + say(tone, voice[0], e.type === "blueBeat" && e.flat ? "flat" : voice[1], e.type === "blueBeat" ? 0.4 : 0.5); + switch (e.type) { + case "blueJump": + burst(e.x, e.y, "#cfd8d4", 5, 7, 300); + break; + case "blueLand": + fx.blueLand = { t0: fx.clock, big: Boolean(e.big) }; + burst(e.x, e.y, "#ffb060", e.big ? 12 : 6, e.big ? 12 : 8, 360); + if (e.big) shake(200, 0.5); + break; + case "blueLaunch": + burst(e.x, e.y, "#ffb060", 12, 14, 380); + float(e.x, e.y + 5, e.last ? "Out the doors!" : "Whee!", GOLD, 2.2); + break; + case "blueCrash": + shake(320, 1); + flash("#ffd0d0", 200); + burst(e.x, e.y + 1, e.what === "orderly" ? "#cdd8d0" : "#9aa8a4", 18, 17, 520); + burst(e.x, e.y + 1, "#ff6a50", 8, 14, 360); + break; + case "blueCheck": + float(e.x, e.y + 5, "Checkpoint", GOLD, 2.2); + ringFx(e.x, e.y + 3, "#7dffa0", 1, 8, 500); + break; + case "blueFinish": + shake(260, 0.7); + burst(e.x, e.y, "#cfd8d4", e.big ? 22 : 14, 13, 560); + float(e.x, e.y + 5, "Made it!", GOLD, 2.6); + break; + case "blueWarn": + flash("#ff4030", 70); + ringFx(e.x, e.y + 3, "#ff5a4a", 1, 10, 420); + break; + case "blueDark": + shake(160, 0.6); + break; + case "blueLit": + float(e.x, e.y + 6, "Lights on", GOLD, 2.2); + break; + case "blueChair": + burst(e.x, e.y + 0.5, "#cfd8d4", 4, 5, 300); + break; + case "blueOrderlyWarn": + burst(e.x, e.y + 3, "#ff6a50", 5, 4, 380); + break; + case "blueOrderlyUp": + burst(e.x, e.y + 1, "#cfd8d4", 8, 8, 360); + shake(120, 0.4); + break; + case "blueOrderlyHit": + burst(e.x, e.y, "#cdd8d0", 5, 9, 280); + break; + case "blueOrderlyBreak": + burst(e.x, e.y, "#cdd8d0", 14, 14, 480); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + case "blueLamp": + burst(e.x, e.y, "#fff0b0", 14, 14, 460); + splinter(fx, e.x, e.y, ["#fff6c8", "#ffd060", "#ffffff"]); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + float(e.x, e.y - 2, "Lights stay on", "#d8ffe4", 2); + break; + default: + break; + } + return true; + } + + return freeze({ + looks: LOOKS, + backdrop, + ground, + shelf, + front, + moving, + dim, + monsters: freeze({}), + bosses: freeze({}), + missiles: freeze({}), + hazards: freeze({}), + powers: freeze({}), + lights, + react, + }); +} diff --git a/src/web-console/public/activities/ghoul-gurney.js b/src/web-console/public/activities/ghoul-gurney.js new file mode 100644 index 0000000..306a304 --- /dev/null +++ b/src/web-console/public/activities/ghoul-gurney.js @@ -0,0 +1,586 @@ +// Plan2Code Web Console - Ghoul Rush's Code Blue, its rules: Blackmoor Sanatorium's bonus round. YOU lie strapped to a runaway hospital gurney that flies down the sanatorium's endless corridors and ramps, wheels squealing: jump the wheelchairs, IV stands and elevator shafts, duck the hanging surgical lamps and swinging doors, shoot the orderlies who lunge from doorways, while the lights go out in timed waves, as a stage pack that ghoul.js plugs in. +// +// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it, handed a +// kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js (it borrows the +// cart's track helpers). Pack fields used: `ride` (a hook that moves Planny himself, so no +// key walks him), `place` (Planny put down in a room: a room set up or a respawn) and +// `target` (a bolt strikes something that is no monster: the orderlies and the surge +// lamps). It adds no monster, boss or hazard kind and draws NO random number. +// +// THE SLOT: the ride's state lives in `round.runner` (the shared slot for a rolling bonus +// ride, null in any other room), marked `pack: "codeblue"`; the room's ride spec has +// `runner: "codeblue"`, which the Cart's `place` knows to leave alone. Another ride's +// `place` could null the slot in this room, so a copy is kept (BACK) and put back. +// +// THE ROOM (spec.ride, see ghoul-rooms.js): +// +// - `track`: polylines [x, y] the gurney rolls along, one per corridor; a gap between two +// lines is an ELEVATOR SHAFT (jump it; a fall below DERAIL_Y is a heart, cause +// "elevator"). Corridors are flat with ramps (slope up to 0.22) between floors; the +// last line ends on a loading ramp rising over RAMP_SLOPE, which launches the gurney +// out of the ambulance doors onto the bay (`finish` is where the bay begins). +// - `chairs` [x, line] (a wheelchair, CHAIR_W by CHAIR_H, jump: it starts rolling at you +// CHAIR_V when the gurney is CHAIR_NEAR short of it, at most CHAIR_MAX), `stands` [x, line] +// (an IV stand, STAND_W by STAND_H, jump), `lows` [x0, x1, y, kind] (a hanging surgical +// lamp, kind 0, or a swinging door, kind 1: its underside is y, 3.0 over the track, so +// DUCK it), `orderlies` [x, line] (an orderly in a doorway: the door shivers +// ORDERLY_WARN_MS when the gurney is ORDERLY_NEAR short, then he lunges onto the track +// ORDERLY_UP_MS, ORDERLY_W by ORDERLY_H: jump it, or shoot it, ORDERLY_HP bolts), +// `lamps` [x, line] (the surge lamp of wave i: see below), `waves` [x0, x1] (the span +// of each blackout), `checks` (x positions of the checkpoints), `finish`, `time` (the +// room's clock, ms) and `how` (the controls line). +// - The ground is the start's floor and the ambulance bay at the end only. +// +// THE TWIST, LIGHTS OUT: the lights go out in waves. WARN_UNITS (84) before a wave's x0 the +// corridor flickers and buzzes and a countdown (3, 2, 1, one number every TICK_UNITS) +// runs; from x0 to x1 it is pitch black, only the flashlight cone, the dying emergency +// strips and a faint glow on what is near show. Wave i has a surge lamp, SURGE_BACK +// before x0, hung SURGE_LO to SURGE_HI over the track: a bolt fired from the air (a hop +// while holding fire) hits it, it shorts out harmlessly, and that blackout is called off +// (`waves[i].off`): the section stays lit. A heartbeat monitor runs across the top: it +// beeps every BEAT_MS[hearts] and flatlines at the last heart (FLAT_MS). +// +// THE GURNEY (`round.runner`): { pack, room, check, v, line, coyote, from, left, done, +// wave (the wave in its countdown or dark, else -1), phase ("lit" | "warn" | "dark"), n +// (the countdown number), dark (0..1), waves: [{ off, hit }], hitWaves, beatMs, pulse, every +// (the beat's length in ms), flat, +// orderlies, chairs, lamps }. Planny rides at (you.x, you.y), always facing right (`you.state` +// "run" on the floor, "air" off it, `you.ducking` ducked). Speed `v` relaxes to GURNEY_V +// (RELAX) and is pushed by the slope (SLOPE_G), between GURNEY_MIN and GURNEY_MAX. Up +// jumps at JUMP_V (plus the slope's own rise) against GRAV (about 13 high, 0.75 s), +// COYOTE_MS of grace after running off a line's end; down ducks. A bolt flies parallel +// to the track under it (`s.off` keeps what he aimed). +// +// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the gurney +// rolls on, Planny blinking safe BONUS_SAFE_MS; the last heart gone ends the round with +// nothing, at once. A derail puts him back on the track at GURNEY_V. Causes: "wheelchair", +// "ivstand", "overhead" (a lamp or a door), "lunged" (an orderly), "elevator" (a fall). +// Every obstacle is a number for the grade (`perf.total`: chairs, stands, lows, orderlies +// and shafts, each id once in `perf.hits` if it ever cost a heart). Shooting an orderly or +// a surge lamp counts for `perf.acts` (the goal is ACTS_GOAL) and the points below. The +// grade's `steady` die rewards clean dark stretches: it holds while at most WAVE_SLACK +// blackouts (countdown and dark) have cost a heart; a wave called off is a clean one. +// +// WHAT THE ART READS: `spec.ride` (above), `round.runner` { v, line, check, done, wave, +// phase, n, dark, waves, pulse, orderlies: [{ state "door"|"warn"|"up"|"sink"|"broken"| +// "spent", t }], chairs: [{ x, rolling }], lamps: [broken] }, `round.bonusRound.hearts`, +// `round.you` (`state`, `vy`, `ducking`), the events in EVENTS. + +import { linesAt, linesOf, slopeOf, trackY } from "./ghoul-cart.js"; + +const freeze = (o) => Object.freeze(o); +const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v)); + +export const ID = "codeblue"; +export const MONSTERS = freeze({}); + +// Every event this pack puts on the field, for the art and the sounds to answer. +export const EVENTS = freeze([ + "blueJump", "blueLand", "blueLaunch", "blueDuck", "blueCrash", "blueCheck", "blueFinish", + "blueWarn", "blueDark", "blueLit", "blueBeat", "blueChair", + "blueOrderlyWarn", "blueOrderlyUp", "blueOrderlyHit", "blueOrderlyBreak", "blueLamp", +]); + +// The gurney. Speeds are units across a second, GRAV units a second squared. +export const GURNEY_V = 48; +export const GURNEY_MIN = 36; +export const GURNEY_MAX = 60; +export const SLOPE_G = 40; +export const RELAX = 1.5; +export const JUMP_V = 74; +export const GRAV = 200; +export const COYOTE_MS = 100; +export const RAMP_SLOPE = 0.25; +export const RAMP_POP = 30; +export const LAND_TOL = 0.9; +export const BIG_LAND = 8; +export const DERAIL_Y = 3; +export const CAM_AHEAD = 10; +export const CAM_PER_V = 0.25; +// Obstacles. +export const CHAIR_W = 3.4; +export const CHAIR_H = 3.6; +export const CHAIR_NEAR = 64; +export const CHAIR_V = 12; +export const CHAIR_MAX = 18; +export const STAND_W = 1.8; +export const STAND_H = 6.2; +export const ORDERLY_W = 2.6; +export const ORDERLY_H = 5.4; +export const ORDERLY_HP = 2; +export const ORDERLY_NEAR = 40; +export const ORDERLY_WARN_MS = 450; +export const ORDERLY_UP_MS = 1600; +export const ORDERLY_SINK_MS = 300; +export const ORDERLY_POINTS = 100; +// The surge lamp: hung high, so a bolt from the air hits it, and the points. +export const LAMP_W = 2.6; +export const SURGE_LO = 3.8; +export const SURGE_HI = 11; +export const SURGE_BACK = 70; +export const LAMP_POINTS = 150; +const SHOT_R = 0.5; +// The lights-out rhythm: the countdown's length and tick, and how fast the dark falls and lifts. +export const WARN_UNITS = 84; +export const TICK_UNITS = 28; +export const FADE_IN = 8; +export const FADE_OUT = 14; +// The heartbeat monitor: a beat every so many ms by hearts left, and the flat tone's repeat at the last. +export const BEAT_MS = freeze({ 5: 1000, 4: 780, 3: 600, 2: 440 }); +export const FLAT_MS = 1600; +// The clean dark stretches die: at most this many blackouts may cost a heart. +export const WAVE_SLACK = 1; +// The shots at things (orderlies, surge lamps) worth a die. +export const ACTS_GOAL = 8; + +// Notes for a bonus round that obstacle `id` cost a heart (once each), and for the grade +// that the blackout it happened in (if any) was not clean. +function noteHit(round, c, id) { + const b = round.bonusRound; + if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id); + const w = c ? c.wave : -1; + if (c && w >= 0 && c.waves[w] && !c.waves[w].hit) { + c.waves[w].hit = true; + c.hitWaves++; + if (b) b.perf.steady = c.hitWaves <= WAVE_SLACK; + } +} + +const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H); +const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0; + +// The highest line under x, as [line, y], or null over a shaft. +const topAt = (R, x) => linesAt(R, x)[0] || null; + +// The highest line the gurney, falling from `py` to `y` at `x`, crossed going down. +function landOn(R, x, py, y) { + for (const [line, ly] of linesAt(R, x)) if (py >= ly - LAND_TOL && y <= ly) return { line, y: ly }; + return null; +} + +// Where a gurney in the air at (x, y) going up at vy and across at v lands, if it does +// not steer: { x, y, line } or null when it derails. The unit suite's measure of which +// shafts a jump clears. +export function flight(R, x, y, vy, v) { + const dt = 0.004; + for (let t = 0; t < 5; t += dt) { + const py = y; + vy = Math.max(-120, vy - GRAV * dt); + x += v * dt; + y += vy * dt; + if (vy <= 0) { + const f = landOn(R, x, py, y); + if (f) return { x, y: f.y, line: f.line }; + } + if (y < DERAIL_Y) return null; + } + return null; +} + +// The lights at x: { i, phase, n, dark }. `waves` is the runner's list (a wave called +// off is skipped). The countdown is 3, 2, 1 (n), one number every TICK_UNITS; the dark +// falls over FADE_IN from x0 and lifts over FADE_OUT before x1. +export function lightsAt(R, x, waves) { + for (let i = 0; i < R.waves.length; i++) { + const [x0, x1] = R.waves[i]; + if (waves && waves[i] && waves[i].off) continue; + if (x >= x0 - WARN_UNITS && x < x0) return { i, phase: "warn", n: Math.ceil((x0 - x) / TICK_UNITS), dark: 0 }; + if (x >= x0 && x < x1) return { i, phase: "dark", n: 0, dark: Math.min(1, (x - x0) / FADE_IN + 0.15, (x1 - x) / FADE_OUT) }; + } + return { i: -1, phase: "lit", n: 0, dark: 0 }; +} + +/* -------------------------------------------------------------- placing */ + +// The copy of a ride's state that another pack's `place` cannot take away. +const BACK = new WeakMap(); +// This ride's state, put back in the shared slot if something cleared it; null elsewhere. +function mine(round) { + const c = round.runner; + if (c && c.pack === ID) return c; + const back = BACK.get(round); + if (back && back.room === round.room && round.spec.ride && round.spec.ride.runner === ID) { + round.runner = back; + return back; + } + return null; +} + +// A fresh set of the room's things, each orderly in his doorway and each chair where it +// stood. What was shot stays shot (`old`, the state of an earlier try in the same room). +function things(R, old) { + const was = (list, i, state) => (old && old[list] && old[list][i] && old[list][i].state === state ? state : null); + return { + orderlies: R.orderlies.map((o, i) => ({ state: was("orderlies", i, "broken") || "door", t: 0, hp: ORDERLY_HP })), + chairs: R.chairs.map(([x]) => ({ x, rolling: false, rolled: 0 })), + lamps: R.lamps.map((l, i) => Boolean(old && old.lamps[i])), + waves: R.waves.map((w, i) => ({ off: Boolean(old && old.waves[i].off), hit: Boolean(old && old.waves[i].hit) })), + }; +} + +// Planny put down in the room: on the gurney at the start of a ride, or at the last +// checkpoint passed after the last heart (the same room). +function place(round, k) { + const R = round.spec.ride; + // (The Cart's `place` runs first and has already zeroed `round.camLead`: another room's lead is not ours to touch.) + if (!R || R.runner !== ID) { + if (round.runner && round.runner.pack === ID) round.runner = null; + BACK.delete(round); + return; + } + const old = mine(round); + const again = Boolean(old && old.room === round.room); + const check = again ? old.check : -1; + const you = round.you; + const x = check >= 0 ? R.checks[check] : round.spec.start; + const top = topAt(R, x); + Object.assign(you, { x, y: top ? top[1] : you.y, vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 }); + const c = { pack: ID, room: round.room, check, v: GURNEY_V, line: top ? top[0] : -1, coyote: 0, from: you.y, left: top ? top[0] : 0, done: false, wave: -1, phase: "lit", n: 0, dark: 0, hitWaves: again ? old.hitWaves : 0, beatMs: 0, pulse: 0, every: BEAT_MS[5], flat: false, ...things(R, again ? old : null) }; + round.runner = c; + BACK.set(round, c); + round.camLead = CAM_AHEAD; + const b = round.bonusRound; + if (b && !b.perf.total) { + b.perf.total = R.chairs.length + R.stands.length + R.lows.length + R.orderlies.length + (R.track.length - 1); + b.perf.steady = true; + b.perf.goal = ACTS_GOAL; + } +} + +/* ------------------------------------------------------------ the ride */ + +// After a derail that cost a heart but not the ride: Planny and the gurney go back onto +// the track nearest where they fell (the highest line under him, else the next one +// ahead) at GURNEY_V. He blinks safe (ghoul.js's takeLife). +function reseat(round, c, R) { + const you = round.you; + const under = topAt(R, you.x); + let line; + let x; + let y; + if (under) { + [line, y] = under; + x = you.x; + } else { + const ahead = linesOf(R) + .map((L, i) => ({ i, x0: L.x0 })) + .filter((L) => L.x0 > you.x) + .sort((a, b) => a.x0 - b.x0)[0]; + line = ahead ? ahead.i : linesOf(R).length - 1; + x = ahead ? ahead.x0 + 2 : R.finish - 2; + y = trackY(R, line, x) ?? you.y; + } + Object.assign(you, { x, y, vy: 0, state: "run", shelf: -1, ducking: false, coyote: 0, drop: -1 }); + Object.assign(c, { line, v: GURNEY_V, coyote: 0, from: y }); +} + +// The gurney's motion for one slice. Returns true once it has moved Planny (every slice +// of a ride); false outside a ride and once he has stepped out onto the ambulance bay. +function ride(round, ms, k) { + const R = round.spec.ride; + if (!R || R.runner !== ID) return false; + const c = mine(round); + if (!c || c.done) return false; + const you = round.you; + const inp = round.input; + const dt = ms / 1000; + const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra }); + // Already down on the bay (set there, or past the lip some other way): the ride is over. + if (you.x >= R.finish && you.vy <= 0 && you.y <= k.groundAt(round.spec, you.x) + 0.01) return finish(round, c, R, k.groundAt(round.spec, you.x)); + // A stomp's bounce (or anything else) lifts the gurney off its line. + if (you.state === "air" && c.line >= 0) { + c.left = c.line; + c.line = -1; + c.coyote = 0; + c.from = you.y; + } + steerShots(round, R); + const want = inp.jump > 0; + if (c.line >= 0) { + // On the floor. + const slope = slopeOf(R, c.line, you.x); + c.v = clamp(c.v + ((GURNEY_V - c.v) * RELAX - SLOPE_G * slope) * dt, GURNEY_MIN, GURNEY_MAX); + const duck = Boolean(inp.down) && !want; + if (duck && !you.ducking) ev("blueDuck"); + you.ducking = duck; + if (want) { + inp.jump = 0; + you.vy = JUMP_V + slope * c.v; + Object.assign(c, { left: c.line, line: -1, coyote: 0, from: you.y }); + you.state = "air"; + you.ducking = false; + ev("blueJump", { v: c.v }); + } else { + const L = linesOf(R)[c.line]; + const nx = you.x + c.v * dt; + you.state = "run"; + you.vy = 0; + if (nx >= L.x1) { + // Off the end of the line, on along its last slope. + const end = L.pts[L.pts.length - 1]; + const rise = slopeOf(R, c.line, L.x1); + you.x = L.x1; + you.y = end[1]; + const ramp = rise >= RAMP_SLOPE; + you.vy = rise * c.v + (ramp ? RAMP_POP : 0); + Object.assign(c, { left: c.line, line: -1, coyote: COYOTE_MS, from: you.y }); + you.state = "air"; + you.ducking = false; + if (ramp) ev("blueLaunch", { v: c.v, last: c.left === linesOf(R).length - 1 }); + } else { + you.x = nx; + you.y = trackY(R, c.line, nx); + } + } + } else { + // In the air. + c.coyote = Math.max(0, c.coyote - ms); + if (want && c.coyote > 0) { + inp.jump = 0; + c.coyote = 0; + you.vy = JUMP_V; + c.from = you.y; + ev("blueJump", { v: c.v }); + } + const py = you.y; + you.vy = Math.max(-k.FALL_MAX, you.vy - GRAV * dt); + you.x += c.v * dt; + you.y += you.vy * dt; + you.ducking = false; + you.state = "air"; + if (you.vy <= 0) { + const f = landOn(R, you.x, py, you.y); + if (f) { + you.y = f.y; + you.vy = 0; + you.state = "run"; + c.line = f.line; + ev("blueLand", { big: c.from - f.y >= BIG_LAND }); + c.from = f.y; + } else if (you.x >= R.finish) { + // Over the bay at the end: down onto it, and the ride is over. + const g = k.groundAt(round.spec, you.x); + if (g > -Infinity && you.y <= g + 0.01) return finish(round, c, R, g); + } + } + } + // A press nothing took waits a moment for a landing, then goes. + if (want && inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms); + // Past the end of the world: a shaft, or the face of the bay. + if (you.y < DERAIL_Y || k.groundAt(round.spec, you.x) > you.y + 0.5) { + noteHit(round, c, `k${c.left}`); + if (k.lose(round, "elevator") && round.phase === "play") reseat(round, c, R); + return true; + } + while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) { + c.check++; + ev("blueCheck", { n: c.check + 1 }); + } + round.camLead = CAM_AHEAD + (c.v - GURNEY_V) * CAM_PER_V; + blackout(round, c, R); + heartbeat(round, c, ms); + if (obstacles(round, c, R, k)) return true; + creatures(round, c, R, ms); + return true; +} + +// The ride is over: the gurney halts on the bay, the door opens, Planny walks out. +function finish(round, c, R, g) { + const you = round.you; + c.done = true; + c.restX = you.x; + c.wave = -1; + c.phase = "lit"; + c.n = 0; + c.dark = 0; + Object.assign(you, { y: g, vy: 0, state: "run", shelf: -1, ducking: false }); + round.hasKey = true; + round.camLead = 0; + round.events.push({ type: "blueFinish", x: you.x, y: you.y, big: c.from - g >= BIG_LAND }); + return false; +} + +// A bolt flies parallel to the track under it, whatever way he aimed (`s.off`): the +// floor rises and falls, and a level bolt would miss a surge lamp or a lunging orderly on a ramp. +function steerShots(round, R) { + for (const s of round.shots) { + if (s.arm || s.free) continue; + if (s.off === undefined) s.off = s.vy; + const top = topAt(R, s.x); + if (top) s.sl = slopeOf(R, top[0], s.x); + s.vy = s.vx * (s.sl ?? 0) + s.off; + } +} + +/* ------------------------------------------------------ the lights, the beat */ + +// The blackout's state for where the gurney is: the countdown's ticks, the dark falling +// and lifting, each an event for the sounds and the art. +function blackout(round, c, R) { + const you = round.you; + const now = lightsAt(R, you.x, c.waves); + const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra }); + if (now.phase === "warn" && (c.phase !== "warn" || c.n !== now.n)) ev("blueWarn", { n: now.n, wave: now.i }); + if (now.phase === "dark" && c.phase !== "dark") ev("blueDark", { wave: now.i }); + if (now.phase === "lit" && c.phase === "dark") ev("blueLit", { wave: c.wave }); + if (now.phase === "warn" && c.phase === "dark") ev("blueLit", { wave: c.wave }); + c.wave = now.i; + c.phase = now.phase; + c.n = now.n; + c.dark = now.dark; +} + +// The heartbeat monitor: a beat every BEAT_MS[hearts] ms, quicker the fewer hearts are left, +// and a flat tone at the last heart. `pulse` (0..1) is where the sweep is in its beat. +function heartbeat(round, c, ms) { + const b = round.bonusRound; + const hearts = b ? b.hearts : 5; + const flat = hearts <= 1; + const every = flat ? FLAT_MS : BEAT_MS[clamp(hearts, 2, 5)]; + c.beatMs += ms; + if (c.beatMs >= every) { + c.beatMs -= every; + round.events.push({ type: "blueBeat", x: round.you.x, y: round.you.y, flat, hearts, bpm: Math.round(60000 / every) }); + } + c.every = every; + c.flat = flat; + c.pulse = Math.min(1, c.beatMs / every); +} + +/* ----------------------------------------------------------- obstacles */ + +// What the gurney runs into: a wheelchair, an IV stand, a lamp or a door overhead, an +// orderly. Returns whether it cost a heart. +function obstacles(round, c, R, k) { + const you = round.you; + const hh = duckH(k, you); + for (const [i, [x0, x1, y]] of R.lows.entries()) { + if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > y && k.struck(round, "overhead")) { + noteHit(round, c, `l${i}`); + round.events.push({ type: "blueCrash", what: "low", x: you.x, y: you.y + hh }); + return true; + } + } + for (const [i, [, line]] of R.chairs.entries()) { + const x = c.chairs[i].x; + if (Math.abs(you.x - x) > 6) continue; + if (boxHit(k, you, x, trackY(R, line, x), CHAIR_W, CHAIR_H) && k.struck(round, "wheelchair")) { + noteHit(round, c, `c${i}`); + round.events.push({ type: "blueCrash", what: "chair", x, y: you.y }); + return true; + } + } + for (const [i, [x, line]] of R.stands.entries()) { + if (Math.abs(you.x - x) > 6) continue; + if (boxHit(k, you, x, trackY(R, line, x), STAND_W, STAND_H) && k.struck(round, "ivstand")) { + noteHit(round, c, `s${i}`); + round.events.push({ type: "blueCrash", what: "stand", x, y: you.y }); + return true; + } + } + for (const [i, [x, line]] of R.orderlies.entries()) { + const o = c.orderlies[i]; + if (o.state !== "up" || Math.abs(you.x - x) > 5) continue; + if (boxHit(k, you, x, trackY(R, line, x), ORDERLY_W, ORDERLY_H) && k.struck(round, "lunged")) { + noteHit(round, c, `o${i}`); + round.events.push({ type: "blueCrash", what: "orderly", x, y: you.y }); + Object.assign(o, { state: "sink", t: ORDERLY_SINK_MS }); + return true; + } + } + return false; +} + +// The wheelchairs set rolling at the gurney, and the orderlies' doors that burst open, when it comes near. +function creatures(round, c, R, ms) { + const you = round.you; + const dt = ms / 1000; + R.chairs.forEach(([x0, line], i) => { + const ch = c.chairs[i]; + if (!ch.rolling) { + const ahead = ch.x - you.x; + if (ahead < CHAIR_NEAR && ahead > -CHAIR_W) { + ch.rolling = true; + round.events.push({ type: "blueChair", x: ch.x, y: trackY(R, line, ch.x) }); + } + } else { + ch.rolled = Math.min(CHAIR_MAX, ch.rolled + CHAIR_V * dt); + ch.x = x0 - ch.rolled; + } + }); + R.orderlies.forEach(([x, line], i) => { + const o = c.orderlies[i]; + const y = trackY(R, line, x); + if (o.state === "door") { + const ahead = x - you.x; + if (ahead < ORDERLY_NEAR && ahead > -ORDERLY_W) { + Object.assign(o, { state: "warn", t: ORDERLY_WARN_MS }); + round.events.push({ type: "blueOrderlyWarn", x, y }); + } + } else if (o.state === "warn" || o.state === "up" || o.state === "sink") { + o.t -= ms; + if (o.t > 0) return; + if (o.state === "warn") { + Object.assign(o, { state: "up", t: ORDERLY_UP_MS }); + round.events.push({ type: "blueOrderlyUp", x, y }); + } else if (o.state === "up") Object.assign(o, { state: "sink", t: ORDERLY_SINK_MS }); + else Object.assign(o, { state: "spent", t: 0 }); + } + }); +} + +/* ------------------------------------------------------------- targets */ + +// A bolt into something to shoot: an orderly lunging from his doorway, a surge lamp. True +// when one took it (the bolt is spent). A lamp shorted out calls its blackout off. +function gurneyShot(round, s) { + const R = round.spec.ride; + if (!R || R.runner !== ID) return false; + const c = mine(round); + if (!c) return false; + const hit = (x, y0, w, h) => Math.abs(s.x - x) <= w / 2 + SHOT_R && s.y >= y0 - SHOT_R && s.y <= y0 + h + SHOT_R; + const score = (n) => { + round.score += n; + if (round.bonusRound) round.bonusRound.perf.acts++; + }; + for (let i = 0; i < R.orderlies.length; i++) { + const o = c.orderlies[i]; + const [x, line] = R.orderlies[i]; + const y = trackY(R, line, x); + if (o.state !== "up" || !hit(x, y, ORDERLY_W, ORDERLY_H)) continue; + o.hp--; + if (o.hp > 0) round.events.push({ type: "blueOrderlyHit", x, y: y + ORDERLY_H / 2 }); + else { + Object.assign(o, { state: "broken", t: 0 }); + score(ORDERLY_POINTS); + round.events.push({ type: "blueOrderlyBreak", x, y: y + ORDERLY_H / 2, points: ORDERLY_POINTS }); + } + return true; + } + for (let i = 0; i < R.lamps.length; i++) { + if (c.lamps[i]) continue; + const [x, line] = R.lamps[i]; + const y = trackY(R, line, x); + if (!hit(x, y + SURGE_LO, LAMP_W, SURGE_HI - SURGE_LO)) continue; + c.lamps[i] = true; + c.waves[i].off = true; + score(LAMP_POINTS); + round.events.push({ type: "blueLamp", x, y: y + (SURGE_LO + SURGE_HI) / 2, points: LAMP_POINTS, wave: i }); + return true; + } + return false; +} + +export const GURNEY = freeze({ + id: ID, + monsters: MONSTERS, + walkers: freeze([]), + zombies: freeze([]), + stackers: freeze([]), + climbers: freeze([]), + act: freeze({}), + horde: freeze({}), + ride: freeze([ride]), + place: freeze([place]), + target: gurneyShot, +}); diff --git a/src/web-console/public/activities/ghoul-hearse-draw.js b/src/web-console/public/activities/ghoul-hearse-draw.js new file mode 100644 index 0000000..f7c904d --- /dev/null +++ b/src/web-console/public/activities/ghoul-hearse-draw.js @@ -0,0 +1,1308 @@ +// Plan2Code Web Console - Ghoul Rush's Midnight Hearse, its drawing: a night drive along a cemetery road in a runaway black hearse. A moon and stars, far hills and a mid layer of crypts, dead trees and iron fences that scroll by at their own speeds, the gravel road in front and the raised grass verge behind it (joined by a ramp at each lane gate), open graves, headstones and fallen crosses, low branches and the lychgate arch, hands in grave mounds, crows, closed stretches (a fallen oak, a hedge wall), lanterns, fog banks, the hearse with its coffins and the ghouls that sit up out of the ones thrown out. +// +// ghoul-draw.js plugs it in. LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are plain +// data (the voices are the room's own tones, in ghoul-sfx-hearse.js); hearseArt(d) takes +// ghoul-draw.js's drawing helpers (`d`) and hands back the drawing by kind, so this file +// never reaches back into it. Drawn in room units, the way ghoul-draw.js draws: y counted down +// from the field's top, so a world height `y` is drawn at `FIELD_H - y`. The still layers are +// only the sky's color: the world is drawn by `moving` (every frame, over them; no cached +// layers, no random numbers: everything comes from a hash), the lows, the cab's door, the fog, +// the signs and the lamp gauge in front of Planny by `front`. What the art reads off the rules +// (ghoul-hearse.js): +// +// - the room: `spec.ride` ({ gates, graves, stones, lows, hands, crows, blocks, lanterns, fog, +// checks, finish }), the flat road in `spec.ground`. +// - `round.runner` (id "hearse"; null in any other room): `lane`, `from`, `swMs`, `h`, `air`, `lamp`, +// `out`, `fog`, `coffins`, `lit` [taken], `done`, `restX`, `check`, `hands` [{ state "mound" | "warn" | +// "up" | "sink" | "broken" | "spent", t }], `crows` [{ state "perch" | "fly" | "gone" | "broken", x }], +// `sitters` [{ x, ox, lane, state "fly" | "sit" | "hid" | "broken", t }]. +// - Planny: `you.x`, `you.y`, `you.vy`, `you.ducking`. +// - events leave short-lived bits in the view's `fx` (`hearseBits`, `hearseLand`). + +import { CROW_H, FLY_MS, GRAVE_W, HAND_H, LANE_Y, LAMP_MAX, LOW_Y, SIT_MS, SIT_RISE_MS, baseOf, laneNow } from "./ghoul-hearse.js"; + +const freeze = (o) => Object.freeze(o); +const TAU = Math.PI * 2; +const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x)); + +const pit = (o) => freeze({ pack: "hearse", custom: true, noMoon: true, pit: "#05080f", ...o }); +export const LOOKS = freeze({ + hearse: pit({ wallTop: "#04060d", wallLow: "#1b2438", paper: "#10162a", wainscot: "#0a0e1c", floorTop: "#3b332c", floor: "#241f1a", floorEdge: "#0a0805", shelf: "#3a3a44", shelfTop: "#7a7a88", window: "#dfe6f0", decor: "graves", color: "#c8b8d8", dark: 0.5 }), +}); + +// How each new kind sounds, by act (the room's own tones, ghoul-sfx-hearse.js). +export const VOICES = freeze({ + hearse: freeze({ jump: "ghoulHearseJump", land: "ghoulHearseLand", duck: "ghoulHearseDuck", switch: "ghoulHearseSwitch", crash: "ghoulHearseCrash", check: "ghoulHearseCheck", finish: "ghoulHearseFinish" }), + hearsehand: freeze({ warn: "ghoulHearseHandWarn", up: "ghoulHearseHandUp", hit: "ghoulHearseHandHit", break: "ghoulHearseHandBreak" }), + hearsecrow: freeze({ wake: "ghoulHearseCrowWake", hit: "ghoulHearseCrowHit" }), + hearselamp: freeze({ lantern: "ghoulHearseLantern", out: "ghoulHearseLampOut", lit: "ghoulHearseLampLit" }), + hearsecoffin: freeze({ fly: "ghoulHearseCoffin", up: "ghoulHearseSitUp", hit: "ghoulHearseSitHit" }), +}); + +// What each of the pack's events plays: [kind, act], once. +export const EVENT_VOICE = freeze({ + hearseJump: ["hearse", "jump"], + hearseLand: ["hearse", "land"], + hearseDuck: ["hearse", "duck"], + hearseSwitch: ["hearse", "switch"], + hearseCrash: ["hearse", "crash"], + hearseCheck: ["hearse", "check"], + hearseFinish: ["hearse", "finish"], + hearseHandWarn: ["hearsehand", "warn"], + hearseHandUp: ["hearsehand", "up"], + hearseHandHit: ["hearsehand", "hit"], + hearseHandBreak: ["hearsehand", "break"], + hearseCrowWake: ["hearsecrow", "wake"], + hearseCrowHit: ["hearsecrow", "hit"], + hearseLantern: ["hearselamp", "lantern"], + hearseLampOut: ["hearselamp", "out"], + hearseLampLit: ["hearselamp", "lit"], + hearseCoffin: ["hearsecoffin", "fly"], + hearseSitUp: ["hearsecoffin", "up"], + hearseSitHit: ["hearsecoffin", "hit"], +}); +export const LOSE_WORDS = freeze({ grave: "Fell in a grave", tomb: "Hit a headstone", cross: "Hit a fallen cross", branch: "Ducked too late", grasp: "Grabbed by a hand", crow: "Pecked by a crow", wreck: "Wrecked on the road" }); +export const LOSE_SOUNDS = freeze({ + grave: ["ghoulRockLand", 0.55, 0.8], + tomb: ["smash", 0.6, 0.7], + cross: ["clank", 0.5, 0.7], + branch: ["clank", 0.5, 0.8], + grasp: ["ghoulHandsGrab", 0.5, 1], + crow: ["ghoulShriek", 0.3, 0.8], + wreck: ["smash", 0.65, 0.6], +}); + +const FW = 96; +const ROAD = LANE_Y[0]; +const VERGE = LANE_Y[1]; +const BLOCK_H = 14.5; +let FH = 54; +const BONE = "#d8d0b8"; +const STONE_C = "#8d949b"; +const STONE_D = "#4e545b"; +const MOSS = "#2d3b24"; +const BLACK = "#14121a"; +const CHROME = "#b9b2a0"; +const VELVET = "#5a1020"; +const SOIL = "#3a2c1e"; +const SOIL_D = "#1e160e"; + +// A number in 0..1 from two integers, the same every time (no random draws). +const rnd = (a, b = 0) => { + let h = Math.imul((a | 0) + 0x9e37, 0x85ebca6b) ^ Math.imul((b | 0) + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +const poly = (c, pts) => { + c.beginPath(); + pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); + c.closePath(); +}; +const seg = (c, x0, y0, x1, y1) => { + c.beginPath(); + c.moveTo(x0, y0); + c.lineTo(x1, y1); + c.stroke(); +}; +const disc = (c, x, y, r) => { + c.beginPath(); + c.arc(x, y, r, 0, TAU); + c.fill(); +}; +const grad = (make, stops) => { + const g = make ? make() : null; + if (!g || typeof g.addColorStop !== "function") return stops[stops.length >> 1][1]; + for (const [o, col] of stops) g.addColorStop(o, col); + return g; +}; +const vgrad = (c, y0, y1, stops) => grad(c.createLinearGradient && (() => c.createLinearGradient(0, y0, 0, y1)), stops); +const rgrad = (c, x, y, r, stops) => grad(c.createRadialGradient && (() => c.createRadialGradient(x, y, 0, x, y, r)), stops); +const Y = (y) => FH - y; +// A soft glow: a radial gradient, a flat disc where the canvas cannot do one. +function halo(ctx, x, y, r, color, alpha) { + ctx.globalAlpha = alpha; + ctx.fillStyle = rgrad(ctx, x, y, r, [[0, color], [1, "rgba(0,0,0,0)"]]); + ctx.fillRect(x - r, y - r, r * 2, r * 2); + ctx.globalAlpha = 1; +} + +/* ------------------------------------------------------------- telegraphs */ + +// What to do about each obstacle, shown as a glyph that fades in ahead of it, for the lane the +// hearse is in: JUMP (an arrow up, cyan) over graves, headstones and crosses, DUCK (an arrow down, +// amber) under low branches and the arch, SHOOT (a crosshair, red) at hands and crows, SWITCH (green, +// the lane to take) at the gate before a closed stretch. Everything comes from the room's `ride` +// fields and where the hearse is (no random numbers, no rules). +export const TELEGRAPH_SEE = 40; +export const TELEGRAPH_FULL = 30; +export const TELEGRAPH_WORDS = 3; +export const TELEGRAPH_ALPHA = 0.78; +export const ANSWERS = freeze({ grave: "JUMP", stone: "JUMP", cross: "JUMP", branch: "DUCK", arch: "DUCK", hand: "SHOOT", crow: "SHOOT", block: "SWITCH" }); +export const ANSWER_COLORS = freeze({ JUMP: "#5fe3ff", DUCK: "#ffb02e", SHOOT: "#ff6a6a", SWITCH: "#7dffa0" }); + +const marks = new WeakMap(); +// Every obstacle that wants a glyph: { kind, lane, lead (where it begins), x (its middle), up (height of +// the glyph's anchor), n (which of its kind), answer }, in the room's order. A closed stretch's glyph +// stands at the gate before it (the last one that ends 22 or more short of it) and names the other lane. +export function telegraphMarks(R) { + if (marks.has(R)) return marks.get(R); + const out = []; + const count = {}; + const add = (kind, lane, lead, x, up) => { + const n = count[kind] || 0; + count[kind] = n + 1; + out.push({ kind, lane, lead, x, up: LANE_Y[lane] + up, n, answer: ANSWERS[kind] }); + }; + for (const [x, lane] of R.graves) add("grave", lane, x - 6, x, 8.4); + for (const [x, lane, kind] of R.stones) add(kind ? "cross" : "stone", lane, x - 3, x, kind ? 6.4 : 7.6); + for (const [x0, x1, lane, kind] of R.lows) add(kind ? "arch" : "branch", lane, x0 - 3.2, (x0 + x1) / 2, kind ? 7.6 : 7.4); + for (const [x, lane] of R.hands) add("hand", lane, x - 2, x, 8); + for (const [x, lane, up] of R.crows) add("crow", lane, x - 17 - 2, x - 17, up + 4.6); + for (const [x0, , lane] of R.blocks) { + const gate = R.gates.filter(([, b]) => b + 22 <= x0).at(-1); + if (gate) add("block", lane, gate[1], (gate[0] + gate[1]) / 2, 16); + } + out.sort((p, q) => p.lead - q.lead); + marks.set(R, out); + return out; +} + +// The glyphs showing with the hearse at `x` in `lane`: { ...mark, alpha (0..1, before the pulse), words }. +export function telegraphs(R, x, lane) { + const out = []; + for (const m of telegraphMarks(R)) { + if (m.lane !== lane) continue; + const d = m.lead - x; + if (d > TELEGRAPH_SEE || d < -6) continue; + const alpha = Math.min(clamp((TELEGRAPH_SEE - d) / (TELEGRAPH_SEE - TELEGRAPH_FULL), 0, 1), clamp((d + 4) / 6, 0, 1)); + if (alpha > 0.01) out.push({ ...m, alpha, words: m.n < TELEGRAPH_WORDS || m.kind === "block" }); + } + return out; +} + +/* --------------------------------------------------------------------- art */ + +export function hearseArt(d) { + const { ellipse, say, label, GOLD } = d; + const ride = (v) => (v.spec && v.spec.ride && v.spec.ride.runner === "hearse" ? v.spec.ride : null); + const runner = (v) => (v.round && v.round.runner && v.round.runner.id === "hearse" ? v.round.runner : null); + + // The still layers get only the sky's color; `moving` draws the world. + function backdrop(ctx, v, look, x0, x1) { + ctx.fillStyle = look.wallLow; + ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H); + } + function ground() {} + function shelf() {} + + /* ---------------------------------------------------------- the sky and far scenery */ + + function sky(ctx, v, cam) { + ctx.fillStyle = vgrad(ctx, 0, FH, [[0, "#04060d"], [0.55, "#121a2e"], [1, "#2a3552"]]); + ctx.fillRect(cam - 1, 0, FW + 2, FH); + const clock = v.clock; + for (let k = 0; k < 46; k++) { + const x = cam + ((((rnd(k, 1) * FW - cam * 0.02) % FW) + FW) % FW); + ctx.globalAlpha = 0.25 + 0.5 * rnd(k, 3) * (0.7 + 0.3 * Math.sin(clock / 500 + k)); + ctx.fillStyle = "#dfe6f4"; + ctx.fillRect(x, rnd(k, 2) * 26, 0.22, 0.22); + } + ctx.globalAlpha = 1; + // The moon: pale, with a halo and a few maria, riding with the view. + const mx = cam + 74; + const my = 9; + halo(ctx, mx, my, 16, "rgba(190,205,240,0.5)", 0.55); + ctx.fillStyle = "#e8edf6"; + disc(ctx, mx, my, 4.4); + ctx.fillStyle = "rgba(150,160,190,0.45)"; + disc(ctx, mx - 1.3, my - 0.8, 1.1); + disc(ctx, mx + 1.2, my + 1.2, 0.8); + disc(ctx, mx + 0.6, my - 1.8, 0.5); + // Cloud streaks sliding across it. + ctx.fillStyle = "rgba(20,28,48,0.55)"; + for (let k = 0; k < 3; k++) ellipse(ctx, cam + ((((rnd(k, 9) * 140 - clock / 90 - cam * 0.05) % 140) + 140) % 140) - 20, 5 + k * 3.4, 12 + rnd(k, 4) * 6, 0.6); + ctx.fill(); + } + + // Far hills: a soft ridge made of sines, at a slow parallax. + function hills(ctx, cam, par, base, amp, color, seed) { + const u0 = cam * par; + ctx.fillStyle = color; + ctx.beginPath(); + ctx.moveTo(cam - 1, FH); + for (let px = -1; px <= FW + 3; px += 3) { + const u = u0 + px; + ctx.lineTo(cam + px, Y(base + amp * (0.5 * Math.sin(u * 0.045 + seed) + 0.35 * Math.sin(u * 0.11 + seed * 2) + 0.15 * Math.sin(u * 0.27)))); + } + ctx.lineTo(cam + FW + 3, FH); + ctx.closePath(); + ctx.fill(); + } + + // The mid layer (parallax 0.35): crypts, dead trees, crosses and iron fence, every 14 units a slot. + function cemetery(ctx, cam) { + const par = 0.35; + const base = Y(VERGE + 0.4); + const u0 = cam * par; + for (let slot = Math.floor((u0 - 4) / 14); slot <= Math.floor((u0 + FW + 8) / 14); slot++) { + const r = rnd(slot, 11); + const x = cam + (slot * 14 - u0) + r * 6; + ctx.fillStyle = "#0d1322"; + ctx.strokeStyle = "#0d1322"; + if (r < 0.2) { + // A crypt: a box, a gable, a dark door. + ctx.fillRect(x - 3.2, base - 6, 6.4, 6); + poly(ctx, [[x - 4, base - 6], [x, base - 9], [x + 4, base - 6]]); + ctx.fill(); + ctx.fillStyle = "#04060c"; + ctx.fillRect(x - 0.9, base - 3.6, 1.8, 3.6); + } else if (r < 0.45) { + // A dead tree: a trunk and bare limbs. + ctx.lineWidth = 0.5; + seg(ctx, x, base, x + 0.3, base - 8); + ctx.lineWidth = 0.28; + for (let k = 0; k < 4; k++) seg(ctx, x + 0.2, base - 3 - k * 1.5, x + (k % 2 ? 2.8 : -2.8) * (1 - k * 0.12), base - 4.6 - k * 1.6); + } else if (r < 0.7) { + // A cross and a slab. + ctx.fillRect(x - 0.3, base - 4.4, 0.6, 4.4); + ctx.fillRect(x - 1.3, base - 3.5, 2.6, 0.55); + ctx.fillRect(x + 2.4, base - 2.6, 1.8, 2.6); + } else { + // Iron fence with spear tops. + ctx.lineWidth = 0.12; + for (let k = 0; k < 9; k++) { + seg(ctx, x + k * 0.8 - 3, base, x + k * 0.8 - 3, base - 3); + poly(ctx, [[x + k * 0.8 - 3.2, base - 3], [x + k * 0.8 - 3, base - 3.7], [x + k * 0.8 - 2.8, base - 3]]); + ctx.fill(); + } + seg(ctx, x - 3, base - 1, x + 4, base - 1); + } + } + } + + /* -------------------------------------------------------------- the road and the verge */ + + // The gravel road (the floor's dark slab) with its ruts and pebbles, and the raised verge behind it. + function roadway(ctx, v, cam, R) { + const top = Y(ROAD); + ctx.fillStyle = vgrad(ctx, top, top + ROAD, [[0, "#4a4036"], [0.2, "#322a23"], [1, "#171310"]]); + ctx.fillRect(cam - 1, top, FW + 2, ROAD + 1); + ctx.fillStyle = "rgba(0,0,0,0.35)"; + ctx.fillRect(cam - 1, top + 2.2, FW + 2, 0.35); + ctx.fillRect(cam - 1, top + 4.4, FW + 2, 0.3); + for (let k = Math.floor(cam / 2.5); k < Math.floor((cam + FW) / 2.5) + 1; k++) { + if (rnd(k, 31) < 0.55) continue; + ctx.fillStyle = rnd(k, 32) < 0.5 ? "rgba(120,106,90,0.5)" : "rgba(10,8,6,0.5)"; + ctx.fillRect(k * 2.5 + rnd(k, 33), top + 0.5 + rnd(k, 34) * 6, 0.35 + rnd(k, 35) * 0.5, 0.25); + } + // The verge: a raised terrace behind the road, a stone curb at its foot, grass on top. + const vy = Y(VERGE); + ctx.fillStyle = vgrad(ctx, vy, top, [[0, "#2e3d26"], [0.12, "#1f2a1a"], [1, "#16110c"]]); + ctx.fillRect(cam - 1, vy, FW + 2, top - vy + 0.1); + ctx.fillStyle = "#4a5a38"; + ctx.fillRect(cam - 1, vy, FW + 2, 0.4); + for (let k = Math.floor(cam / 1.7); k < Math.floor((cam + FW) / 1.7) + 1; k++) { + const h = 0.4 + rnd(k, 41) * 0.7; + ctx.fillStyle = k % 3 ? "#3b4d2c" : "#2a3a20"; + ctx.fillRect(k * 1.7, vy - h + 0.3, 0.16, h); + } + ctx.fillStyle = "#5c5c66"; + ctx.fillRect(cam - 1, top - 1.2, FW + 2, 1.2); + ctx.fillStyle = "#3a3a44"; + for (let k = Math.floor(cam / 5); k < Math.floor((cam + FW) / 5) + 1; k++) ctx.fillRect(k * 5, top - 1.2, 0.15, 1.2); + ctx.fillStyle = "#7a7a88"; + ctx.fillRect(cam - 1, top - 1.2, FW + 2, 0.2); + // At each lane gate the bank is a ramp, with chevrons painted on it. + for (const [a, b] of R.gates) { + if (b < cam - 4 || a > cam + FW + 4) continue; + // The bank is cut away above the ramp (a dirt slope up from the road to the verge). + ctx.fillStyle = "#2a241d"; + poly(ctx, [[a, top], [a, vy], [b, vy]]); + ctx.fill(); + ctx.strokeStyle = "#6a5a46"; + ctx.lineWidth = 0.35; + seg(ctx, a, top, b, vy); + ctx.strokeStyle = "rgba(240,230,190,0.6)"; + ctx.lineWidth = 0.22; + for (let k = 0; k < 3; k++) { + const cx = a + 3 + k * 4.2; + const cy = top - ((cx - a) / (b - a)) * (top - vy) - 0.6; + ctx.beginPath(); + ctx.moveTo(cx - 0.8, cy + 0.6); + ctx.lineTo(cx, cy); + ctx.lineTo(cx - 0.8, cy - 0.6); + ctx.stroke(); + } + } + } + + /* ---------------------------------------------------------------- the things */ + + // The gate's posts: a stone post with a lamp at each end of the ramp, and a dim green lantern between. + function gatePosts(ctx, v, a, b) { + for (const [px, lit] of [[a - 0.4, 1], [b + 0.4, 0]]) { + ctx.fillStyle = "#4a4a54"; + ctx.fillRect(px - 0.5, Y(ROAD + 4.2), 1, 4.2); + ctx.fillStyle = "#6a6a76"; + ctx.fillRect(px - 0.7, Y(ROAD + 4.2), 1.4, 0.4); + ctx.fillStyle = "#7dffa0"; + ctx.globalAlpha = 0.7 + 0.25 * Math.sin(v.clock / 300 + lit); + disc(ctx, px, Y(ROAD + 5), 0.55); + ctx.globalAlpha = 1; + halo(ctx, px, Y(ROAD + 5), 4, "rgba(125,255,160,0.8)", 0.35); + } + } + + // An open grave at x on a lane: a dark pit between heaps of soil, a shovel in one, a plank across the edge. + function grave(ctx, x, lane, i) { + const y = Y(LANE_Y[lane]); + const w = GRAVE_W; + ctx.fillStyle = "#04030a"; + poly(ctx, [[x - w / 2 + 0.6, y - 0.1], [x + w / 2 - 0.6, y - 0.1], [x + w / 2 - 1.6, y + 2.6], [x - w / 2 + 1.6, y + 2.6]]); + ctx.fill(); + ctx.fillStyle = SOIL_D; + ctx.fillRect(x - w / 2 + 1.6, y + 1.5, w - 3.2, 1.1); + // The soil heaped each side and its cut face. + for (const s of [-1, 1]) { + ctx.fillStyle = SOIL; + poly(ctx, [[x + s * (w / 2 - 0.5), y], [x + s * (w / 2 + 1.2), y - 1.7], [x + s * (w / 2 + 3.2), y - 0.6], [x + s * (w / 2 + 4.4), y]]); + ctx.fill(); + ctx.fillStyle = "#4e3b28"; + ctx.fillRect(x + s * (w / 2 + 0.3) - 0.2, y - 0.8, 0.4, 0.4); + } + // A shovel stuck in the right heap. + ctx.strokeStyle = "#7a5a34"; + ctx.lineWidth = 0.22; + seg(ctx, x + w / 2 + 2.2, y - 0.6, x + w / 2 + 1.8, y - 3.4); + ctx.fillStyle = "#8a8a94"; + poly(ctx, [[x + w / 2 + 1.5, y - 3.4], [x + w / 2 + 2.1, y - 3.4], [x + w / 2 + 2.2, y - 4.4], [x + w / 2 + 1.4, y - 4.4]]); + ctx.fill(); + // A pale rim of an old coffin's corner showing in the pit. + ctx.fillStyle = "rgba(180,160,120,0.35)"; + poly(ctx, [[x - 1.5, y + 1.4], [x + 2.2, y + 1.9], [x + 2.4, y + 2.5], [x - 1.7, y + 2.2]]); + ctx.fill(); + if (rnd(i, 7) < 0.5) { + ctx.strokeStyle = BONE; + ctx.lineWidth = 0.18; + seg(ctx, x - 2.4, y + 2.1, x - 1.2, y + 1.5); + } + } + + // A leaning headstone (a slab, an obelisk or a rounded one) or a fallen cross lying in the road. + function stone(ctx, x, lane, kind, i) { + const y = Y(LANE_Y[lane]); + ctx.save(); + ctx.translate(x, y); + ctx.fillStyle = "rgba(0,0,0,0.35)"; + ellipse(ctx, 0.3, 0.05, kind ? 3.2 : 2, 0.3); + ctx.fill(); + if (kind) { + // A cross knocked flat: the long beam, the arm, a broken base, moss. + ctx.rotate(-0.04); + ctx.fillStyle = STONE_C; + ctx.fillRect(-2.7, -1.0, 5.4, 0.95); + ctx.fillRect(-0.4, -1.8, 0.9, 1.8); + ctx.fillStyle = STONE_D; + ctx.fillRect(-2.7, -0.4, 5.4, 0.35); + ctx.fillStyle = MOSS; + ctx.fillRect(-2.1, -1.05, 1.4, 0.2); + ctx.fillRect(1.0, -1.05, 1.1, 0.2); + ctx.fillStyle = STONE_C; + poly(ctx, [[2.7, -1.0], [3.4, -0.5], [2.9, 0], [2.7, 0]]); + ctx.fill(); + } else { + ctx.rotate((rnd(i, 4) - 0.5) * 0.2); + const shape = i % 3; + ctx.fillStyle = STONE_C; + if (shape === 0) { + ctx.beginPath(); + ctx.moveTo(-1.3, 0); + ctx.lineTo(-1.3, -3.2); + ctx.arc(0, -3.2, 1.3, Math.PI, 0); + ctx.lineTo(1.3, 0); + ctx.closePath(); + ctx.fill(); + } else if (shape === 1) { + poly(ctx, [[-1.1, 0], [-0.8, -3.7], [0, -4.4], [0.8, -3.7], [1.1, 0]]); + ctx.fill(); + } else { + poly(ctx, [[-1.3, 0], [-1.3, -2.6], [-0.2, -3.3], [0.4, -2.8], [1.3, -3.4], [1.3, 0]]); + ctx.fill(); + } + ctx.fillStyle = STONE_D; + ctx.fillRect(0.5, -3, 0.8, 3); + ctx.strokeStyle = "#394048"; + ctx.lineWidth = 0.13; + seg(ctx, -0.7, -2.4, 0.6, -2.4); + seg(ctx, -0.7, -1.7, 0.2, -1.7); + ctx.fillStyle = MOSS; + ctx.fillRect(-1.3, -0.5, 1.3, 0.5); + } + ctx.restore(); + } + + // A hand in its mound: a heap of soil that stirs, then an arm reaching up with grasping fingers. + function hand(ctx, v, x, lane, h, i) { + const y = Y(LANE_Y[lane]); + const clock = v.clock; + const shake = h.state === "warn" ? Math.sin(clock / 30) * 0.18 : 0; + ctx.fillStyle = SOIL; + poly(ctx, [[x - 2.2, y], [x - 1.1 + shake, y - 1.1], [x + 0.8 + shake, y - 1.3], [x + 2.2, y]]); + ctx.fill(); + ctx.fillStyle = "#4e3b28"; + ctx.fillRect(x - 0.5, y - 1.1, 0.4, 0.3); + const rise = h.state === "up" ? clamp((1600 - h.t) / 260, 0, 1) : h.state === "sink" ? clamp(h.t / 300, 0, 1) : 0; + if (rise <= 0) return; + const top = y - 0.8 - (HAND_H - 0.8) * rise; + ctx.strokeStyle = "#7a8a64"; + ctx.lineWidth = 0.7; + ctx.lineCap = "round"; + const sway = Math.sin(clock / 160 + i) * 0.25; + ctx.beginPath(); + ctx.moveTo(x, y - 0.6); + ctx.quadraticCurveTo(x + sway, (y + top) / 2, x + sway * 1.4, top + 0.8); + ctx.stroke(); + ctx.lineWidth = 0.22; + for (let k = -2; k <= 2; k++) seg(ctx, x + sway * 1.4 + k * 0.28, top + 0.9, x + sway * 1.4 + k * 0.5 + Math.sin(clock / 90 + k) * 0.2, top - 0.2 - (2 - Math.abs(k)) * 0.15); + ctx.fillStyle = "#6b7a5e"; + ctx.fillRect(x + sway * 1.4 - 0.7, top + 0.7, 1.4, 0.9); + ctx.lineCap = "butt"; + } + + // A crow: perched on a fence post, or flying left with its wings going. + function crow(ctx, v, w, lane, up, i) { + const base = Y(LANE_Y[lane]); + const clock = v.clock; + const ink = "#2c2836"; + if (w.state === "perch") { + const py = base - up + 0.2; + ctx.fillStyle = "#3a2c1e"; + ctx.fillRect(w.x - 0.3, py + 0.4, 0.6, up); + ctx.fillStyle = ink; + ellipse(ctx, w.x, py - 0.4, 1.1, 0.8); + ctx.fill(); + disc(ctx, w.x - 0.9, py - 1.1, 0.45); + poly(ctx, [[w.x - 1.3, py - 1.1], [w.x - 2.1, py - 0.95], [w.x - 1.3, py - 0.8]]); + ctx.fill(); + ctx.fillStyle = "#ff4a3a"; + ctx.fillRect(w.x - 1.1, py - 1.25, 0.16, 0.16); + ctx.fillStyle = "#5a5470"; + poly(ctx, [[w.x + 0.9, py - 0.2], [w.x + 2.1, py + 0.3], [w.x + 0.7, py + 0.3]]); + ctx.fill(); + return; + } + if (w.state !== "fly") return; + const cy = base - up - CROW_H / 2; + const flap = Math.sin(clock / 55 + i * 2); + ctx.fillStyle = ink; + ellipse(ctx, w.x, cy, 1.15, 0.6); + ctx.fill(); + disc(ctx, w.x - 1.1, cy - 0.15, 0.42); + poly(ctx, [[w.x - 1.45, cy - 0.15], [w.x - 2.3, cy], [w.x - 1.45, cy + 0.1]]); + ctx.fill(); + ctx.fillStyle = "#ff4a3a"; + ctx.fillRect(w.x - 1.3, cy - 0.3, 0.14, 0.14); + ctx.fillStyle = "#5a5470"; + poly(ctx, [[w.x - 0.3, cy - 0.2], [w.x + 0.9, cy - 0.2 - flap * 1.5], [w.x + 1.9, cy - 0.4 - flap * 1.9], [w.x + 0.6, cy + 0.1]]); + ctx.fill(); + poly(ctx, [[w.x + 1.0, cy + 0.1], [w.x + 2.2, cy + 0.1], [w.x + 1.0, cy + 0.4]]); + ctx.fillStyle = ink; + ctx.fill(); + } + + // A closed stretch: a fallen oak's tangle across the road (lane 0), or a hedge wall with an iron fence (lane 1). + function block(ctx, v, x0, x1, lane, i) { + const y = Y(LANE_Y[lane]); + const w = x1 - x0; + if (lane === 0) { + // The root ball at the left, the trunk, snapped limbs bristling up. + ctx.fillStyle = "#1a130d"; + ctx.fillRect(x0 + 2, y - 9.6, w - 3, 9.6); + ctx.fillStyle = "#2a1e14"; + ctx.fillRect(x0 + 2, y - 9.6, w - 3, 1.2); + ctx.fillStyle = "#0f0b08"; + for (let k = 0; k < 14; k++) ctx.fillRect(x0 + 3 + rnd(i * 20 + k, 1) * (w - 6), y - 9 + rnd(i * 20 + k, 2) * 8.6, 0.2, 1.4 + rnd(i * 20 + k, 3) * 2); + ctx.fillStyle = "#1a130d"; + disc(ctx, x0 + 4, y - 7.2, 7); + ctx.fillStyle = SOIL_D; + disc(ctx, x0 + 2.4, y - 7.4, 4.6); + ctx.strokeStyle = "#1a130d"; + ctx.lineCap = "round"; + for (let k = 0; k < 11; k++) { + const a = Math.PI * 0.55 + (k / 10) * Math.PI * 0.9; + ctx.lineWidth = 0.5 - k * 0.02; + seg(ctx, x0 + 4 + Math.cos(a) * 5, y - 7.2 - Math.sin(a) * 5, x0 + 4 + Math.cos(a) * 9.4, y - 7.2 - Math.sin(a) * 9.4); + } + ctx.lineCap = "butt"; + ctx.lineWidth = 0.7; + for (let k = 0; k < 9; k++) { + const bx = x0 + 8 + k * ((w - 10) / 8); + const top = y - BLOCK_H * (0.6 + 0.4 * rnd(i * 9 + k, 5)); + seg(ctx, bx, y - 8.6, bx + (rnd(i * 9 + k, 6) - 0.5) * 3, top); + seg(ctx, bx + (rnd(i * 9 + k, 6) - 0.5) * 1.5, (y - 8.6 + top) / 2, bx + (rnd(i * 9 + k, 7) - 0.3) * 4, top + 2); + } + ctx.fillStyle = "rgba(160,200,240,0.18)"; + ctx.fillRect(x0 + 2, y - 9.6, w - 3, 0.25); + } else { + // A hedge wall (dense, clipped, with a tall dead top) and the bars of an iron fence along its foot. + ctx.fillStyle = "#16240f"; + ctx.fillRect(x0, y - BLOCK_H, w, BLOCK_H); + ctx.fillStyle = "#223616"; + for (let k = 0; k < 40; k++) disc(ctx, x0 + rnd(i * 50 + k, 1) * w, y - rnd(i * 50 + k, 2) * BLOCK_H, 0.9 + rnd(i * 50 + k, 3) * 1.4); + ctx.fillStyle = "#0e1a09"; + for (let k = 0; k < 6; k++) ctx.fillRect(x0 + (k + 0.5) * (w / 6), y - BLOCK_H, 0.35, BLOCK_H); + ctx.strokeStyle = "#0a0a10"; + ctx.lineWidth = 0.2; + for (let k = 0; k <= w; k += 1.4) { + seg(ctx, x0 + k, y, x0 + k, y - 4.6); + poly(ctx, [[x0 + k - 0.25, y - 4.6], [x0 + k, y - 5.4], [x0 + k + 0.25, y - 4.6]]); + ctx.fillStyle = "#0a0a10"; + ctx.fill(); + } + seg(ctx, x0, y - 2.4, x1, y - 2.4); + // Red eyes in the leaves. + ctx.fillStyle = "#ff3a2a"; + ctx.globalAlpha = 0.6 + 0.3 * Math.sin(v.clock / 400 + i); + for (let k = 0; k < 3; k++) { + const ex = x0 + 4 + rnd(i * 7 + k, 8) * (w - 8); + const ey = y - 6 - rnd(i * 7 + k, 9) * 6; + ctx.fillRect(ex, ey, 0.22, 0.22); + ctx.fillRect(ex + 0.7, ey, 0.22, 0.22); + } + ctx.globalAlpha = 1; + } + } + + // A lantern on a post in a lane: glowing until it is taken. + function lantern(ctx, v, x, lane, taken, i) { + const y = Y(LANE_Y[lane]); + ctx.strokeStyle = "#2a2a34"; + ctx.lineWidth = 0.28; + seg(ctx, x + 1, y, x + 1, y - 4.8); + seg(ctx, x + 1, y - 4.8, x, y - 4.8); + ctx.fillStyle = "#2a2a34"; + ctx.fillRect(x - 0.6, y - 4.8, 1.2, 0.3); + if (taken) return; + const flick = 0.85 + 0.15 * Math.sin(v.clock / 120 + i * 3); + ctx.fillStyle = "#ffcf5a"; + ctx.globalAlpha = flick; + ctx.fillRect(x - 0.45, y - 4.4, 0.9, 1.1); + ctx.globalAlpha = 1; + ctx.fillStyle = "#ffe9a0"; + ctx.fillRect(x - 0.2, y - 4.1, 0.4, 0.55); + ctx.strokeStyle = "#2a2a34"; + ctx.lineWidth = 0.12; + ctx.strokeRect(x - 0.45, y - 4.4, 0.9, 1.1); + halo(ctx, x, y - 3.9, 4.2, "rgba(255,200,90,0.9)", 0.4 * flick); + } + + // A checkpoint: a pole across the road with a black banner and a gold star, lit once passed. + function checkpoint(ctx, v, x, passed) { + const top = Y(30); + ctx.fillStyle = "#2a2a34"; + ctx.fillRect(x - 0.3, top, 0.6, Y(ROAD) - top); + ctx.fillStyle = passed ? "#244a30" : "#1a1420"; + poly(ctx, [[x + 0.3, top + 0.4], [x + 6, top + 0.4 + Math.sin(v.clock / 300) * 0.3], [x + 5, top + 3.4], [x + 6, top + 6.2], [x + 0.3, top + 6.2]]); + ctx.fill(); + ctx.fillStyle = passed ? "#7dffa0" : GOLD; + const sx = x + 3; + const sy = top + 3.2; + ctx.beginPath(); + for (let k = 0; k < 10; k++) { + const r = k % 2 ? 0.5 : 1.3; + ctx.lineTo(sx + Math.sin((k * Math.PI) / 5) * r, sy - Math.cos((k * Math.PI) / 5) * r); + } + ctx.closePath(); + ctx.fill(); + halo(ctx, sx, sy, 5, passed ? "rgba(125,255,160,0.8)" : "rgba(255,210,90,0.8)", 0.3); + } + + // The cemetery gate at the end of the road: two stone piers and an iron arch with a cross. + function finishGate(ctx, v, x) { + const gy = Y(ROAD); + for (const px of [x - 7, x + 7]) { + ctx.fillStyle = "#5a5a66"; + ctx.fillRect(px - 1.4, gy - 15, 2.8, 15); + ctx.fillStyle = "#7a7a88"; + ctx.fillRect(px - 1.8, gy - 15.6, 3.6, 0.9); + ctx.fillStyle = "#3a3a44"; + ctx.fillRect(px + 0.5, gy - 15, 0.9, 15); + ctx.fillStyle = "#7dffa0"; + disc(ctx, px, gy - 17, 0.8); + halo(ctx, px, gy - 17, 6, "rgba(125,255,160,0.8)", 0.4); + } + ctx.strokeStyle = "#0e0e14"; + ctx.lineWidth = 0.42; + ctx.beginPath(); + ctx.moveTo(x - 7, gy - 14); + ctx.quadraticCurveTo(x, gy - 22, x + 7, gy - 14); + ctx.stroke(); + ctx.lineWidth = 0.22; + for (let k = -5; k <= 5; k++) seg(ctx, x + k * 1.2, gy - 14.8 - (1 - (k / 6) ** 2) * 4.4, x + k * 1.2, gy - 11); + seg(ctx, x, gy - 20.2, x, gy - 23); + seg(ctx, x - 1, gy - 22, x + 1, gy - 22); + } + + /* --------------------------------------------------------- coffins and sitters */ + + // A coffin, side on: a long hexagon with a brass plate; `open` shows the lid propped up. + function coffin(ctx, w, h, open) { + ctx.fillStyle = "#4a2e1c"; + poly(ctx, [[-w / 2, 0], [-w / 2 + h * 0.5, -h], [w / 2 - h * 0.5, -h], [w / 2, 0]]); + ctx.fill(); + ctx.fillStyle = "#6a4528"; + ctx.fillRect(-w / 2 + h * 0.6, -h, w - h * 1.2, h * 0.25); + ctx.fillStyle = "#c9a24a"; + ctx.fillRect(-0.4, -h * 0.65, 0.8, h * 0.3); + if (open) { + ctx.save(); + ctx.translate(-w / 2 + 0.2, -h); + ctx.rotate(-0.9); + ctx.fillStyle = "#6a4528"; + ctx.fillRect(0, -0.35, w * 0.9, 0.35); + ctx.restore(); + } + } + + // A pale ghoul sitting up out of a coffin lid at (x, base): rises over SIT_RISE_MS and lurches. + function ghoul(ctx, v, x, base, rise, i) { + const up = 3.2 * clamp(rise, 0, 1); + const sway = Math.sin(v.clock / 180 + i) * 0.3 * rise; + ctx.fillStyle = "#8a9a7e"; + poly(ctx, [[x - 1.3 + sway, base - 0.6], [x - 1.1 + sway, base - 0.6 - up * 0.7], [x + 1.1 + sway, base - 0.6 - up * 0.7], [x + 1.3 + sway, base - 0.6]]); + ctx.fill(); + ctx.fillStyle = "#a9b89c"; + disc(ctx, x + sway, base - 0.6 - up, 0.95); + ctx.fillStyle = "#1a0a0a"; + ctx.fillRect(x - 0.5 + sway, base - 0.85 - up, 0.35, 0.4); + ctx.fillRect(x + 0.2 + sway, base - 0.85 - up, 0.35, 0.4); + ctx.fillRect(x - 0.3 + sway, base - 0.2 - up, 0.6, 0.35); + ctx.fillStyle = "#ff4a3a"; + ctx.fillRect(x - 0.4 + sway, base - 0.8 - up, 0.15, 0.15); + ctx.fillRect(x + 0.3 + sway, base - 0.8 - up, 0.15, 0.15); + ctx.strokeStyle = "#8a9a7e"; + ctx.lineWidth = 0.28; + seg(ctx, x - 1.1 + sway, base - 0.6 - up * 0.6, x - 2.2 + sway, base - 1.2 - up * 0.2); + seg(ctx, x + 1.1 + sway, base - 0.6 - up * 0.6, x + 2.2 + sway, base - 1.2 - up * 0.3); + } + + // The coffins thrown out: tumbling through the air, then lying in the lane with the lid up and a ghoul sat up in it. + function sitters(ctx, v, c, lane) { + c.sitters.forEach((s, i) => { + if (s.lane !== lane) return; + const base = Y(LANE_Y[s.lane]); + if (s.state === "fly") { + const p = 1 - s.t / FLY_MS; + const ox = s.ox - 4; + ctx.save(); + ctx.translate(ox + (s.x - ox) * p, base - 3 - Math.sin(p * Math.PI) * 9 + 3 * p); + ctx.rotate(p * 9); + coffin(ctx, 7, 1.9, false); + ctx.restore(); + return; + } + ctx.save(); + ctx.translate(s.x, base); + ctx.fillStyle = "rgba(0,0,0,0.35)"; + ellipse(ctx, 0, 0.05, 4, 0.3); + ctx.fill(); + coffin(ctx, 7, 1.7, s.state !== "hid"); + ctx.restore(); + if (s.state === "sit") ghoul(ctx, v, s.x + 0.8, base - 1.0, (SIT_MS - s.t) / SIT_RISE_MS, i); + }); + } + + /* ------------------------------------------------------------------ the hearse */ + + // The hearse's transform: at Planny's feet (the road under it), tilted nose up on the way up, rumbling a little. + function place(ctx, v, c, fn) { + const round = v.round; + const you = round.you; + const x = c.done ? c.restX : you.x; + const y = c.done ? ROAD : you.y; + const tilt = c.air ? clamp(c.vy / 320, -0.16, 0.16) : 0; + const rumble = !c.done && !c.air ? Math.sin(v.clock / 45) * 0.07 : 0; + ctx.save(); + ctx.translate(x, Y(y) + rumble); + ctx.rotate(-tilt); + fn(x); + ctx.restore(); + } + + // The back: wheels, chassis, the coffin bay with its coffins under glass, cab seat, the lamp. Local y counts down. + function hearseBack(ctx, v, c, x) { + const clock = v.clock; + const lamp = c.lamp > 0; + ctx.fillStyle = "rgba(0,0,0,0.35)"; + ellipse(ctx, -4.5, 0.05, 9, 0.4); + ctx.fill(); + // Ghostly exhaust drifting back. + if (!c.done) { + for (let k = 0; k < 6; k++) { + const p = ((clock / 520 + k / 6) % 1); + ctx.fillStyle = `rgba(150,230,170,${(1 - p) * 0.4})`; + disc(ctx, -12.9 - p * 6, -1.4 - p * 2.6, 0.35 + p * 0.9); + } + } + // Chassis and fenders. + ctx.fillStyle = BLACK; + ctx.fillRect(-12.8, -1.6, 16.2, 0.9); + for (const wx of [-9.3, 0.9]) { + ctx.beginPath(); + ctx.arc(wx, -1.6, 1.95, Math.PI, 0); + ctx.fill(); + } + // The coffin bay: dark inside, the coffins on end in a row, glass over them. + ctx.fillStyle = BLACK; + ctx.fillRect(-12.6, -5.8, 10.3, 4.4); + ctx.fillStyle = "#07060b"; + ctx.fillRect(-12.1, -5.1, 9.3, 3.3); + const rattle = c.done || c.air ? 0 : 0.05; + for (let k = 0; k < c.coffins; k++) { + const cx = -11.2 + k * 1.82; + const ry = Math.sin(clock / 60 + k * 2) * rattle; + ctx.fillStyle = "#4a2e1c"; + poly(ctx, [[cx - 0.8, -1.9 + ry], [cx - 0.95, -3.7 + ry], [cx - 0.45, -4.9 + ry], [cx + 0.45, -4.9 + ry], [cx + 0.95, -3.7 + ry], [cx + 0.8, -1.9 + ry]]); + ctx.fill(); + ctx.fillStyle = "#6a4528"; + ctx.fillRect(cx - 0.45, -4.8 + ry, 0.9, 0.3); + ctx.fillStyle = "#c9a24a"; + ctx.fillRect(cx - 0.18, -3.5 + ry, 0.36, 0.5); + } + ctx.fillStyle = "rgba(120,160,200,0.2)"; + ctx.fillRect(-12.1, -5.1, 9.3, 3.3); + ctx.fillStyle = "rgba(255,255,255,0.12)"; + poly(ctx, [[-12.1, -5.1], [-9.6, -5.1], [-11.2, -1.8], [-12.1, -1.8]]); + ctx.fill(); + // Velvet curtains at the glass's ends, brass rail, roof trim, urns and plumes. + ctx.fillStyle = VELVET; + poly(ctx, [[-12.1, -5.1], [-11.1, -5.1], [-12.1, -2.4]]); + ctx.fill(); + poly(ctx, [[-2.8, -5.1], [-3.8, -5.1], [-2.8, -2.4]]); + ctx.fill(); + ctx.fillStyle = CHROME; + ctx.fillRect(-12.8, -6.3, 10.7, 0.55); + ctx.fillRect(-12.6, -1.5, 10.3, 0.22); + ctx.fillStyle = "#c9a24a"; + for (const ux of [-12, -7.5, -3]) { + ctx.fillRect(ux - 0.2, -7.0, 0.4, 0.8); + disc(ctx, ux, -7.3, 0.55); + } + ctx.strokeStyle = "#0a0910"; + ctx.lineWidth = 0.38; + ctx.lineCap = "round"; + for (const [px, dir] of [[-12.2, -1], [-3.2, 1]]) { + const sway = Math.sin(clock / 130 + px) * 0.35; + ctx.beginPath(); + ctx.moveTo(px, -6.6); + ctx.quadraticCurveTo(px + dir * 1.4 + sway, -9, px + dir * 3.2 + sway, -8.1); + ctx.stroke(); + } + ctx.lineCap = "butt"; + // The cab: a bench seat, the wheel, the dash, the front fascia with its lamp. + ctx.fillStyle = VELVET; + ctx.fillRect(-2.2, -3.8, 1.2, 2.4); + ctx.fillRect(-2.2, -1.9, 3, 0.5); + ctx.fillStyle = BLACK; + ctx.fillRect(-2.3, -2.5, 5.7, 1.1); + ctx.strokeStyle = "#7a5a34"; + ctx.lineWidth = 0.2; + seg(ctx, 1.9, -3.6, 1.2, -2.7); + ctx.lineWidth = 0.14; + ellipse(ctx, 2.0, -3.7, 0.25, 0.7); + ctx.stroke(); + ctx.fillStyle = CHROME; + ctx.fillRect(3.2, -2.9, 0.5, 2); + ctx.fillStyle = lamp ? "#e8ffb0" : "#26302a"; + disc(ctx, 3.7, -2.4, 0.65); + if (lamp) halo(ctx, 3.7, -2.4, 7, "rgba(210,255,150,0.9)", 0.45); + // The wheels turn with the road. + for (const wx of [-9.3, 0.9]) { + ctx.fillStyle = "#0a0a0c"; + disc(ctx, wx, -1.55, 1.55); + ctx.fillStyle = CHROME; + disc(ctx, wx, -1.55, 1.0); + ctx.fillStyle = "#1a1a20"; + disc(ctx, wx, -1.55, 0.78); + ctx.strokeStyle = CHROME; + ctx.lineWidth = 0.1; + const a = c.done ? 0 : x / 1.55; + for (let k = 0; k < 6; k++) seg(ctx, wx, -1.55, wx + Math.cos(a + (k * TAU) / 6) * 0.95, -1.55 + Math.sin(a + (k * TAU) / 6) * 0.95); + ctx.fillStyle = CHROME; + disc(ctx, wx, -1.55, 0.22); + } + } + + // The front: the cab's door over Planny's legs and the windshield post. + function hearseFront(ctx, v, c) { + ctx.fillStyle = BLACK; + poly(ctx, [[-2.3, -0.5], [3.3, -0.5], [3.3, -2.2], [2.5, -2.45], [-2.3, -2.45]]); + ctx.fill(); + ctx.strokeStyle = CHROME; + ctx.lineWidth = 0.12; + ctx.beginPath(); + ctx.moveTo(-2.1, -2.2); + ctx.lineTo(3.1, -2.2); + ctx.stroke(); + ctx.fillStyle = CHROME; + ctx.fillRect(-0.4, -1.9, 0.9, 0.18); + ctx.fillStyle = "rgba(255,255,255,0.1)"; + ctx.fillRect(-2.1, -2.35, 5.2, 0.2); + ctx.strokeStyle = CHROME; + ctx.lineWidth = 0.26; + seg(ctx, 2.9, -2.4, 2.5, -4.6); + ctx.fillStyle = "rgba(150,190,230,0.2)"; + poly(ctx, [[2.7, -2.5], [2.4, -4.4], [1.4, -4.4], [1.7, -2.5]]); + ctx.fill(); + } + + /* ----------------------------------------------------------------- fog and signs */ + + // A fog bank: banks of soft blobs along the road, thick at the ground, fading at its ends. + function fog(ctx, v, x0, x1, cam, i) { + const clock = v.clock; + const lo = Math.max(x0, cam - 20); + const hi = Math.min(x1, cam + FW + 20); + for (let x = Math.floor(lo / 9) * 9; x < hi; x += 9) { + const edge = Math.min(clamp((x - x0) / 30, 0, 1), clamp((x1 - x) / 30, 0, 1)); + if (edge <= 0) continue; + for (let k = 0; k < 3; k++) { + const bx = x + rnd(i * 90 + x, k) * 9 + Math.sin(clock / 1700 + x + k) * 2; + const by = Y(2.5 + k * 5.5 + rnd(x, k + 5) * 3); + ctx.globalAlpha = 0.34 * edge * (1 - k * 0.22); + ctx.fillStyle = "#b9c4d4"; + ellipse(ctx, bx, by, 9 + rnd(x, k + 8) * 4, 2.4 + k * 0.4); + ctx.fill(); + } + } + ctx.globalAlpha = 1; + } + + // A see-through glyph over an obstacle: chevrons or a crosshair, and (for the first few) the word. + function glyph(ctx, v, t) { + const col = ANSWER_COLORS[t.answer]; + const pulse = 0.85 + 0.15 * Math.sin(v.clock / 260 + t.lead); + const cy = Math.min(FH - 7, FH - t.up) + Math.sin(v.clock / 260 + t.lead) * 0.35; + ctx.save(); + ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA; + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + if (t.answer === "SHOOT") { + for (const [w, c] of [[1.2, "rgba(4,8,22,0.8)"], [0.5, col]]) { + ctx.strokeStyle = c; + ctx.lineWidth = w; + ctx.beginPath(); + ctx.arc(t.x, cy - 1.2, 1.5, 0, TAU); + ctx.stroke(); + seg(ctx, t.x - 2.4, cy - 1.2, t.x - 0.6, cy - 1.2); + seg(ctx, t.x + 0.6, cy - 1.2, t.x + 2.4, cy - 1.2); + seg(ctx, t.x, cy - 3.6, t.x, cy - 1.8); + seg(ctx, t.x, cy - 0.6, t.x, cy + 1.2); + } + if (t.words) label(ctx, "SHOOT", t.x, cy + 2.4, 2.1, col, "center"); + } else if (t.answer === "SWITCH") { + // A pair of arrows, the lane to take written under them: LEFT is the road, RIGHT the verge. + const road = t.lane === 1; + const dir = road ? -1 : 1; + for (const [w, c] of [[1.3, "rgba(4,8,22,0.8)"], [0.6, col]]) { + ctx.strokeStyle = c; + ctx.lineWidth = w; + for (let k = 0; k < 2; k++) { + const ox = t.x + dir * (k * 1.6 - 1.6); + ctx.beginPath(); + ctx.moveTo(ox - dir * 0.9, cy - 1.7); + ctx.lineTo(ox + dir * 0.9, cy); + ctx.lineTo(ox - dir * 0.9, cy + 1.7); + ctx.stroke(); + } + } + label(ctx, road ? "LEFT: ROAD" : "RIGHT: VERGE", t.x, cy + 3.4, 2.1, col, "center"); + } else { + const up = t.answer === "JUMP"; + const dir = up ? -1 : 1; + const ay = cy + (up ? -2.6 : 2.6); + for (const [w, c] of [[1.3, "rgba(4,8,22,0.8)"], [0.6, col]]) { + ctx.strokeStyle = c; + ctx.lineWidth = w; + for (let k = 0; k < 2; k++) { + const oy = ay + (k - 0.5) * 1.5 * dir - dir * 0.2; + ctx.beginPath(); + ctx.moveTo(t.x - 1.7, oy - dir * 0.9); + ctx.lineTo(t.x, oy + dir * 0.9); + ctx.lineTo(t.x + 1.7, oy - dir * 0.9); + ctx.stroke(); + } + } + if (t.words) label(ctx, t.answer, t.x, cy + (up ? 1.2 : -1.2), 2.3, col, "center"); + } + ctx.restore(); + } + + // The lamp gauge and the coffins left, in the corner of the view. + function gauge(ctx, v, c, cam) { + const x = cam + 2.4; + const y = 8.2; + const p = c.lamp / LAMP_MAX; + const low = p < 0.25; + ctx.fillStyle = "rgba(4,6,14,0.7)"; + ctx.fillRect(x - 0.6, y - 1, 30.2, 4.6); + ctx.fillStyle = "#1a1a24"; + ctx.fillRect(x + 4.2, y + 0.2, 17, 1.7); + const pulse = low ? 0.6 + 0.4 * Math.sin(v.clock / 120) : 1; + ctx.globalAlpha = pulse; + ctx.fillStyle = low ? "#ff5a3a" : p < 0.5 ? "#ffb02e" : "#ffe27a"; + ctx.fillRect(x + 4.2, y + 0.2, 17 * p, 1.7); + ctx.globalAlpha = 1; + ctx.fillStyle = c.out ? "#555a66" : "#ffcf5a"; + ctx.fillRect(x + 0.4, y + 0.1, 1.8, 2.2); + ctx.fillStyle = "#2a2a34"; + ctx.fillRect(x + 0.9, y - 0.5, 0.8, 0.6); + label(ctx, c.out ? "OUT" : "LAMP", x + 4.4, y + 3.2, 1.5, c.out ? "#ff6a6a" : "#ffe9a0", "left"); + for (let k = 0; k < 5; k++) { + ctx.fillStyle = k < c.coffins ? "#8a5a34" : "#2a2a34"; + poly(ctx, [[x + 22.2 + k * 1.5, y + 2.2], [x + 22.4 + k * 1.5, y + 0.6], [x + 23.0 + k * 1.5, y + 0.2], [x + 23.6 + k * 1.5, y + 0.6], [x + 23.8 + k * 1.5, y + 2.2]]); + ctx.fill(); + } + } + + /* ------------------------------------------------------------------- the room */ + + const lanePass = (ctx, v, R, c, cam, lane) => { + const lo = cam - 12; + const hi = cam + FW + 12; + R.graves.forEach(([x, l], i) => { + if (l === lane && x > lo && x < hi) grave(ctx, x, l, i); + }); + R.stones.forEach(([x, l, kind], i) => { + if (l === lane && x > lo && x < hi) stone(ctx, x, l, kind, i); + }); + R.hands.forEach(([x, l], i) => { + if (l === lane && x > lo && x < hi) hand(ctx, v, x, l, c.hands[i], i); + }); + R.lanterns.forEach(([x, l], i) => { + if (l === lane && x > lo && x < hi) lantern(ctx, v, x, l, c.lit[i], i); + }); + R.crows.forEach(([x, l, up], i) => { + const w = c.crows[i]; + if (l === lane && w.x > lo && w.x < hi) crow(ctx, v, w, l, up, i); + }); + R.blocks.forEach(([x0, x1, l], i) => { + if (l === lane && x1 > lo && x0 < hi) block(ctx, v, x0, x1, l, i); + }); + sitters(ctx, v, c, lane); + }; + + // The whole world, over the still layers: sky, hills, the cemetery, road and verge, the things by lane, the hearse. + function moving(ctx, v, cam) { + const R = ride(v); + const c = runner(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + sky(ctx, v, cam); + hills(ctx, cam, 0.12, 26, 6, "#0b1020", 1.3); + hills(ctx, cam, 0.22, 20, 5, "#0e1526", 4.1); + cemetery(ctx, cam); + roadway(ctx, v, cam, R); + R.gates.forEach(([a, b]) => { + if (b > cam - 4 && a < cam + FW + 4) gatePosts(ctx, v, a, b); + }); + R.checks.forEach((x, i) => { + if (x > cam - 8 && x < cam + FW + 8) checkpoint(ctx, v, x, i <= c.check); + }); + if (R.finish > cam - 20 && R.finish < cam + FW + 20) finishGate(ctx, v, R.finish + 16); + const here = laneNow(c); + const inRoad = c.done || here === 0; + lanePass(ctx, v, R, c, cam, 1); + if (!inRoad) place(ctx, v, c, (x) => hearseBack(ctx, v, c, x)); + lanePass(ctx, v, R, c, cam, 0); + if (inRoad) place(ctx, v, c, (x) => hearseBack(ctx, v, c, x)); + // A landing's puff of dust. + const fx = v.fx; + const land = fx && fx.hearseLand !== undefined ? fx.clock - fx.hearseLand.t0 : 1e9; + if (land < 380) { + const p = land / 380; + ctx.fillStyle = `rgba(150,130,110,${(1 - p) * 0.7})`; + for (let k = 0; k < 8; k++) disc(ctx, v.round.you.x + (k - 3.5) * 1.1 * (0.6 + p * 1.5), Y(baseOf(c)) - 0.3 - p * (0.8 + rnd(k, 4) * 1.4), 0.3 + p * 0.3); + } + } + + // In front of Planny: the cab's door, the lows (branches and the arch), the splinters, the fog, the signs, the gauge. + function front(ctx, v) { + const R = ride(v); + const c = runner(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + const round = v.round; + const cam = Math.round(round.camX * 8) / 8; + place(ctx, v, c, () => hearseFront(ctx, v, c)); + R.lows.forEach(([x0, x1, lane, kind], i) => { + if (x1 >= cam - 10 && x0 <= cam + FW + 10) low(ctx, v, x0, x1, lane, kind, i); + }); + R.fog.forEach(([a, b], i) => { + if (b > cam - 20 && a < cam + FW + 20) fog(ctx, v, a, b, cam, i); + }); + if (!c.done && !c.out) for (const t of telegraphs(R, round.you.x, laneNow(c))) glyph(ctx, v, t); + const bits = v.fx && v.fx.hearseBits; + if (bits) { + for (const b of bits) { + const t = (v.fx.clock - b.t0) / 1000; + if (t < 0 || t > 0.9) continue; + ctx.save(); + ctx.translate(b.x + b.vx * t, FH - (b.y + b.vy * t - 30 * t * t)); + ctx.rotate(b.rot + b.vr * t); + ctx.globalAlpha = clamp(1.6 - t * 1.6, 0, 1); + ctx.fillStyle = b.c; + ctx.fillRect(-b.w / 2, -0.12, b.w, 0.24); + ctx.restore(); + } + ctx.globalAlpha = 1; + } + gauge(ctx, v, c, cam); + } + + // A low branch (kind 0: a gnarled limb across the lane from a trunk to the right, with moss and hanging chains) + // or the lychgate arch (kind 1: two stone posts and a tiled roof): its underside is LOW_Y over the lane. + function low(ctx, v, x0, x1, lane, kind, i) { + const base = Y(LANE_Y[lane]); + const under = base - LOW_Y; + const w = x1 - x0; + const clock = v.clock; + if (kind === 1) { + const top = under - 3.4; + for (const px of [x0 - 4.4, x1 + 2.8]) { + ctx.fillStyle = "#6a5a40"; + ctx.fillRect(px, top, 1.6, base - top); + ctx.fillStyle = "#4a3c28"; + ctx.fillRect(px + 1.0, top, 0.6, base - top); + ctx.fillStyle = "#8a7a5a"; + ctx.fillRect(px - 0.3, base - 0.5, 2.2, 0.5); + } + ctx.fillStyle = "#3a2c1e"; + ctx.fillRect(x0 - 4.7, top + 2.4, w + 9.4, 1.0); + // The pitched, tiled roof. + ctx.fillStyle = "#2a2230"; + poly(ctx, [[x0 - 5.6, top + 2.4], [(x0 + x1) / 2, top - 2.2], [x1 + 5.6, top + 2.4]]); + ctx.fill(); + ctx.strokeStyle = "#171320"; + ctx.lineWidth = 0.12; + for (let k = 1; k < 4; k++) seg(ctx, x0 - 5.6 + k * 0.8, top + 2.4 - k * 0.9, x1 + 5.6 - k * 0.8, top + 2.4 - k * 0.9); + ctx.fillStyle = "#5a5a66"; + ctx.fillRect((x0 + x1) / 2 - 0.2, top - 3.0, 0.4, 1.2); + ctx.fillRect((x0 + x1) / 2 - 0.8, top - 2.6, 1.6, 0.35); + // A lamp hanging from the beam. + const mx = (x0 + x1) / 2; + ctx.strokeStyle = "#2a2a34"; + ctx.lineWidth = 0.12; + seg(ctx, mx, top + 3.4, mx, top + 4.2); + ctx.fillStyle = "#ffcf5a"; + ctx.globalAlpha = 0.75 + 0.2 * Math.sin(clock / 150 + i); + ctx.fillRect(mx - 0.35, top + 4.2, 0.7, 0.9); + ctx.globalAlpha = 1; + halo(ctx, mx, top + 4.6, 4.4, "rgba(255,200,90,0.9)", 0.3); + return; + } + const tx = x1 + 3.6; + ctx.lineCap = "round"; + for (const [col, extra] of [["rgba(170,190,230,0.4)", 0.3], ["#150f0a", 0]]) { + ctx.strokeStyle = col; + ctx.lineWidth = 0.75 + extra; + ctx.beginPath(); + ctx.moveTo(tx, FH + 1); + ctx.quadraticCurveTo(tx + 0.6, under + 6, tx - 0.4, under - 2.4); + ctx.stroke(); + ctx.lineWidth = 0.95 + extra; + ctx.beginPath(); + ctx.moveTo(tx - 0.2, under - 1.0); + ctx.quadraticCurveTo(x1 - 1, under - 1.6, x0 - 3.2, under - 0.5); + ctx.stroke(); + } + ctx.strokeStyle = "#150f0a"; + ctx.lineWidth = 0.45; + seg(ctx, x0 + 1.5, under - 0.8, x0 - 0.5, under + 0.55); + seg(ctx, x0 - 2.4, under - 0.45, x0 - 3.6, under + 0.7); + seg(ctx, x1 - 1, under - 1.4, x1 - 1.8, under - 3.6); + ctx.lineCap = "butt"; + // Moss and rotted rope dangling from the limb. + for (let k = 0; k < 6; k++) { + const hx = x0 - 2.7 + k * (w + 4.5) / 5; + const len = 0.9 + rnd(i * 9 + k, 2) * 1.5; + const sway = Math.sin(clock / 500 + hx) * 0.2; + ctx.strokeStyle = k % 2 ? "#3b4d2c" : "#2a3a20"; + ctx.lineWidth = 0.18; + seg(ctx, hx, under - 0.3, hx + sway, under + len); + } + ctx.strokeStyle = "#7a7a84"; + ctx.lineWidth = 0.1; + seg(ctx, x0 + w / 2, under - 0.4, x0 + w / 2 + 0.2, under + 1.6); + ctx.fillStyle = "#7a7a84"; + ctx.fillRect(x0 + w / 2 - 0.2, under + 1.6, 0.6, 0.4); + } + + const dim = (v) => { + const c = runner(v); + return c && c.out ? 0.8 : 0; + }; + + /* -------------------------------------------------------------- lights */ + + function lights(v, add) { + const R = ride(v); + const c = runner(v); + if (!R || !c) return; + const round = v.round; + const you = round.you; + const lo = round.camX - 10; + const hi = round.camX + FW + 10; + // The headlamp's pool on the road ahead, and the lamp's warmth over the hearse; both shrink with the lamp. + const f = c.out ? 0.2 : 0.55 + 0.45 * (c.lamp / LAMP_MAX); + add(you.x + 6, you.y + 2.4, 14 * f + 3, 0.7); + add(you.x - 3, you.y + 3, 9 * f + 2, 0.5); + R.lanterns.forEach(([x, l], i) => { + if (x > lo && x < hi && !c.lit[i]) add(x, LANE_Y[l] + 3.9, 7, 0.55); + }); + R.checks.forEach((x, i) => { + if (x > lo && x < hi) add(x + 3, 26, 9, i <= round.runner.check ? 0.55 : 0.4); + }); + R.gates.forEach(([a, b]) => { + if (b > lo && a < hi) { + add(a - 0.4, ROAD + 5, 5, 0.35); + add(b + 0.4, ROAD + 5, 5, 0.35); + } + }); + R.hands.forEach(([x, l], i) => { + const h = c.hands[i]; + if (x > lo && x < hi && (h.state === "up" || h.state === "warn")) add(x, LANE_Y[l] + 2, 4, 0.3); + }); + for (const s of c.sitters) if (s.state === "sit") add(s.x, LANE_Y[s.lane] + 2, 5, 0.4); + R.lows.forEach(([x0, x1, l, kind]) => { + if (kind && x1 > lo && x0 < hi) add((x0 + x1) / 2, LANE_Y[l] + 6.5, 6, 0.4); + }); + if (R.finish > lo - 20 && R.finish < hi) add(R.finish + 16, 18, 14, 0.6); + } + + /* -------------------------------------------------------------- events */ + + // A throttle on a repeating cue. + function gateOnce(fx, key, ms) { + if ((fx[key] || 0) > fx.clock) return false; + fx[key] = fx.clock + ms; + return true; + } + // Splinters of wood and bone flying out of a spot. + function splinter(fx, x, y, colors) { + fx.hearseBits = (fx.hearseBits || []).filter((b) => fx.clock - b.t0 < 1000); + for (let k = 0; k < 9; k++) fx.hearseBits.push({ x, y, t0: fx.clock, vx: (rnd(k, 1) - 0.5) * 22, vy: 8 + rnd(k, 2) * 14, rot: rnd(k, 3) * TAU, vr: (rnd(k, 4) - 0.5) * 22, w: 0.5 + rnd(k, 5) * 0.9, c: colors[k % colors.length] }); + } + + // What the pack's events look and sound like; true when the event is its own. Each of its + // sounds plays once, from EVENT_VOICE. + function react(e, k) { + const { tone, shake, flash, burst, float, ring, fx } = k; + const voice = EVENT_VOICE[e.type]; + if (!voice) return false; + if (e.type === "hearseDuck" && !gateOnce(fx, "hearseDuckMs", 160)) return true; + say(tone, voice[0], voice[1], 0.5); + const DUST = "#8a7a66"; + switch (e.type) { + case "hearseJump": + burst(e.x, e.y, DUST, 5, 7, 300); + break; + case "hearseLand": + fx.hearseLand = { t0: fx.clock, big: Boolean(e.big) }; + burst(e.x, e.y, DUST, e.big ? 14 : 6, e.big ? 12 : 8, 360); + if (e.big) shake(180, 0.45); + break; + case "hearseSwitch": + burst(e.x, e.y, DUST, 6, 8, 320); + float(e.x, e.y + 6, e.to ? "Verge" : "Road", "#7dffa0", 2); + break; + case "hearseCrash": + shake(320, 1); + flash("#ffd9a0", 200); + burst(e.x, e.y + 1, e.what === "stone" || e.what === "cross" ? STONE_C : "#6a4528", 18, 17, 520); + burst(e.x, e.y + 1, DUST, 8, 14, 360); + if (e.what === "wreck") splinter(fx, e.x, e.y + 2, ["#2a1e14", "#4a3c28", "#3b4d2c"]); + break; + case "hearseCheck": + float(e.x, e.y + 5, "Checkpoint", GOLD, 2.2); + ring(e.x, e.y + 3, "#7dffa0", 1, 8, 500); + break; + case "hearseFinish": + shake(240, 0.6); + burst(e.x, e.y, DUST, 14, 13, 560); + float(e.x, e.y + 6, "Made it!", GOLD, 2.6); + break; + case "hearseHandWarn": + burst(e.x, e.y + 0.5, SOIL, 5, 4, 460); + break; + case "hearseHandUp": + burst(e.x, e.y + 1, SOIL, 8, 8, 360); + break; + case "hearseHandHit": + burst(e.x, e.y, "#7a8a64", 5, 9, 280); + break; + case "hearseHandBreak": + burst(e.x, e.y, "#7a8a64", 14, 14, 480); + splinter(fx, e.x, e.y, [BONE, "#7a8a64"]); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + case "hearseCrowWake": + burst(e.x, e.y, "#2c2836", 6, 8, 340); + break; + case "hearseCrowHit": + burst(e.x, e.y, "#2c2836", 14, 13, 460); + burst(e.x, e.y, "#5a5470", 8, 10, 380); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + case "hearseLantern": + burst(e.x, e.y, "#ffcf5a", 10, 9, 420); + float(e.x, e.y + 3, "Lamp", "#ffe27a", 2); + break; + case "hearseLampOut": + flash("#05060c", 260); + float(e.x, e.y + 8, "The lamp is out!", "#ff6a6a", 2.4); + break; + case "hearseLampLit": + flash("#ffe9a0", 160); + ring(e.x, e.y + 3, "#ffe27a", 1, 9, 420); + break; + case "hearseCoffin": + shake(160, 0.5); + burst(e.x, e.y, "#6a4528", 8, 12, 400); + float(e.x, e.y + 5, e.left ? "A coffin flies!" : "The last coffin!", "#ffb02e", 2.2); + break; + case "hearseSitUp": + burst(e.x, e.y + 1, DUST, 8, 8, 400); + ring(e.x, e.y + 2, "#a9b89c", 1, 6, 400); + break; + case "hearseSitHit": + burst(e.x, e.y, "#a9b89c", 14, 14, 480); + splinter(fx, e.x, e.y, [BONE, "#6a4528"]); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + default: + break; + } + return true; + } + + return freeze({ + looks: LOOKS, + backdrop, + ground, + shelf, + front, + moving, + dim, + monsters: freeze({}), + bosses: freeze({}), + missiles: freeze({}), + hazards: freeze({}), + powers: freeze({}), + lights, + react, + }); +} + diff --git a/src/web-console/public/activities/ghoul-hearse.js b/src/web-console/public/activities/ghoul-hearse.js new file mode 100644 index 0000000..f4995ea --- /dev/null +++ b/src/web-console/public/activities/ghoul-hearse.js @@ -0,0 +1,503 @@ +// Plan2Code Web Console - Ghoul Rush's Midnight Hearse, its rules: the Graveyard's bonus round. YOU hijack a runaway black hearse, horse-less and haunted, and tear along the cemetery road at night with the coffins rattling in the back: jump the open graves, headstones and fallen crosses, duck the low branches and the lychgate arch, shoot the grasping hands and the carrion crows, switch between the road and the grass verge at the lane gates, and keep the lamp lit. As a stage pack that ghoul.js plugs in. +// +// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it, handed a +// kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js. Pack fields used: +// `ride` (a hook that moves Planny himself, so no key walks him), `place` (Planny put +// down in a room: a room set up or a respawn) and `target` (a bolt strikes something that +// is no monster: the hands, the crows and the ghouls out of the coffins). It adds no +// monster, boss or hazard kind, so there is nothing to merge by name, and it draws NO +// random number. Its state is `round.runner` (the shared slot for a rolling bonus ride, +// with `id: "hearse"`; null in any other room) and the room's `ride.runner` is "hearse". +// +// THE ROOM (spec.ride, see ghoul-rooms.js): the ground is one flat road; there are two +// LANES, the road (lane 0, LANE_Y[0]) and the grass verge beside it (lane 1, LANE_Y[1], +// a raised bank), and every obstacle stands in one of them, [x, lane, ...]: +// +// - `graves` [x, lane]: an open grave, GRAVE_W wide (jump it, or fall in: cause "grave"). +// - `stones` [x, lane, kind]: kind 0 a leaning headstone (STONE_W by STONE_H, cause "tomb"), +// kind 1 a fallen cross (CROSS_W by CROSS_H, cause "cross"); jump. +// - `lows` [x0, x1, lane, kind]: a low branch (kind 0) or the lychgate arch (kind 1); its +// underside is LOW_Y over the lane, so DUCK it (cause "branch"). +// - `hands` [x, lane]: a hand grasping out of a grave mound; stirs when the hearse is +// HAND_NEAR short, shivers HAND_WARN_MS, reaches HAND_UP_MS (HAND_W by HAND_H): jump it +// or shoot it (HAND_HP bolts; cause "grasp"). +// - `crows` [x, lane, h]: a carrion crow perched at x; when the hearse is CROW_NEAR short +// it takes wing and flies back at the hearse at CROW_V, CROW_W by CROW_H, its underside +// `h` over the lane (h over a ducked box, under a standing one): duck it, jump it, or +// shoot it, one bolt (cause "crow"). Its x is where it perches: it meets the hearse +// about CROW_NEAR * V / (V + CROW_V) short of that. +// - `blocks` [x0, x1, lane]: a stretch of the lane that is closed (a fallen oak across the +// road, a hedge wall on the verge): the hearse cannot get through. Go round by the lane +// gate before it, or smash in (cause "wreck", a heart) and be thrown into the other lane. +// - `gates` [x0, x1]: the lane gates; inside one, LEFT puts the hearse on the road and RIGHT +// on the verge (SWITCH_MS to hop the curb). Nothing stands in a lane near a gate. +// - `lanterns` [x, lane]: a hanging lantern the hearse takes by passing it (not ducking is +// no matter, a jump over it is: LANTERN_TOP) for LANTERN_GAIN of lamp. +// - `fog` [x0, x1]: a fog bank: the lamp burns faster in it and the art draws it thick. +// - `checks` (x positions of the checkpoints), `finish` (where the ride ends: the hearse +// brakes and Planny walks out to the door) and `time` (the room's clock, ms). +// +// THE HEARSE (`round.runner`): { id, room, check, lane (where it is bound), from (the lane +// it left), swMs (switch time left), h (height over the lane), air, v, lamp, out, broken, +// coffins, lit, hands, crows, sitters, faced, done, restX }. It runs at HEARSE_V whatever +// is pressed; up jumps at JUMP_V against GRAVITY (about 13 high, 0.75 s, 31 across); down +// ducks; a switch cannot be made in the air and a jump or a duck cannot be made in one. +// A bolt flies level. +// +// THE LAMP: it starts at LAMP_MAX, burns down LAMP_DRAIN a second (and LAMP_FOG more in +// the fog), and each lantern gives LANTERN_GAIN. At nothing it goes OUT (`out`, +// `broken`): the night closes in (the art dims the room and the signs fade) until the +// next lantern. A lamp that never went out is the grade's `steady` die. +// +// THE COFFINS: five in the back (COFFINS). Each hit that costs a heart throws one out +// ahead: it lands SIT_AHEAD on in the lane the hearse is in, the lid pops and a ghoul +// sits up; shoot it for SIT_POINTS (it never hurts; it ducks back down as the hearse +// reaches it or after SIT_MS). A hearse with none left throws no more. +// +// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the +// hearse rolls on, Planny blinking safe BONUS_SAFE_MS; the last heart gone ends the round +// with nothing, at once. Causes: "grave", "tomb", "cross", "branch", "grasp", "crow", +// "wreck". The grade's `perf.total` is the obstacles the hearse FACED (passed in their +// lane; a lane switched away from is dodged and not counted), each id once in +// `perf.hits` if it ever cost a heart. Shooting a hand, a crow or a sitter counts for +// `perf.acts` (the goal is ACTS_GOAL, 8 of them) and the points below. +// +// Checkpoints are passed at their x (`hearseCheck`); a restart after the last heart goes +// back to the last one passed (that ends the round, as the sled's does). +// +// WHAT THE ART READS: `spec.ride` (above), `round.runner` { lane, from, swMs, h, air, lamp, +// out, fog, coffins, lit, done, restX, check, hands: [{ state "mound"|"warn"|"up"|"sink"| +// "broken"|"spent", t }], crows: [{ state "perch"|"fly"|"gone"|"broken", x }], sitters: [{ +// x, ox, lane, state "fly"|"sit"|"hid"|"broken", t }] }, `round.you` (`state`, `vy`, +// `ducking`), the events in EVENTS. + +const freeze = (o) => Object.freeze(o); + +export const MONSTERS = freeze({}); + +// Every event this pack puts on the field, for the art and the sounds to answer. +export const EVENTS = freeze([ + "hearseJump", "hearseLand", "hearseDuck", "hearseSwitch", "hearseCrash", "hearseCheck", "hearseFinish", + "hearseHandWarn", "hearseHandUp", "hearseHandHit", "hearseHandBreak", "hearseCrowWake", "hearseCrowHit", + "hearseLantern", "hearseLampOut", "hearseLampLit", "hearseCoffin", "hearseSitUp", "hearseSitHit", +]); + +// The hearse. Speeds are units across a second, GRAVITY units a second squared. +export const HEARSE_V = 42; +export const JUMP_V = 74; +export const GRAVITY = 200; +export const BIG_LAND = 9; +export const LANE_Y = freeze([9, 15]); +export const SWITCH_MS = 360; +export const SWITCH_HOP = 1.6; +export const CAM_AHEAD = 12; +// Obstacles. +export const GRAVE_W = 10; +export const GRAVE_DEEP = 1.2; +export const STONE_W = 2.6; +export const STONE_H = 4.4; +export const CROSS_W = 5.4; +export const CROSS_H = 1.8; +export const LOW_Y = 3.0; +export const HAND_W = 2.6; +export const HAND_H = 3.6; +export const HAND_HP = 2; +export const HAND_NEAR = 34; +export const HAND_WARN_MS = 450; +export const HAND_UP_MS = 1600; +export const HAND_SINK_MS = 300; +export const CROW_W = 2.2; +export const CROW_H = 1.6; +export const CROW_NEAR = 56; +export const CROW_V = 18; +// Points for what is shot. +export const HAND_POINTS = 100; +export const CROW_POINTS = 80; +export const SIT_POINTS = 150; +export const LANTERN_POINTS = 25; +const SHOT_R = 0.5; +// The lamp. +export const LAMP_MAX = 100; +export const LAMP_DRAIN = 2.2; +export const LAMP_FOG = 2; +export const LANTERN_GAIN = 22; +export const LANTERN_R = 2.2; +export const LANTERN_TOP = 7; +// The coffins in the back, and the ghoul out of each. +export const COFFINS = 5; +export const FLY_MS = 600; +export const SIT_AHEAD = 56; +export const SIT_MS = 3000; +export const SIT_RISE_MS = 250; +export const SIT_W = 2.8; +export const SIT_H = 4.4; +// The shots at things (hands, crows, sitters) worth a die. +export const ACTS_GOAL = 8; + +const mine = (round) => (round.runner && round.runner.id === "hearse" ? round.runner : null); +const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H); +const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0; +const smooth = (p) => p * p * (3 - 2 * p); + +// The lane the hearse counts as being in: the one it left until half way through a switch. +export const laneNow = (c) => (c.swMs > 0 && 1 - c.swMs / SWITCH_MS < 0.5 ? c.from : c.lane); +// The height of the road under the hearse (its lane's, eased across a switch, with a little hop). +export function baseOf(c) { + if (c.swMs <= 0) return LANE_Y[c.lane]; + const p = 1 - c.swMs / SWITCH_MS; + return LANE_Y[c.from] + (LANE_Y[c.lane] - LANE_Y[c.from]) * smooth(p) + Math.sin(p * Math.PI) * SWITCH_HOP; +} + +// Notes for a bonus round that obstacle `id` was faced (counted for the grade) and, with +// `cost`, that it cost a heart (once each). +function face(round, c, id, cost = false) { + const b = round.bonusRound; + if (!b) return; + if (!c.faced[id]) { + c.faced[id] = true; + b.perf.total++; + } + if (cost && !b.perf.hits.includes(id)) b.perf.hits.push(id); +} + +/* -------------------------------------------------------------- placing */ + +// A fresh set of the room's things, each hand in its mound and each crow perched. What was +// shot stays shot, and a lantern taken stays taken (`old`, the hearse of an earlier try in +// the same room). +function things(R, old) { + const was = (list, i, state) => (old && old[list] && old[list][i] && old[list][i].state === state ? state : null); + return { + hands: R.hands.map((h, i) => ({ state: was("hands", i, "broken") || "mound", t: 0, hp: HAND_HP })), + crows: R.crows.map(([x], i) => ({ state: was("crows", i, "broken") || "perch", x })), + lit: R.lanterns.map((l, i) => Boolean(old && old.lit[i])), + }; +} + +// Planny put down in the room: at the wheel at the start of a ride, or at the last +// checkpoint passed after the last heart (the same room). +function place(round, k) { + const R = round.spec.ride; + // (The Cart's `place` runs first, leaves a ride with a `runner` alone and has already zeroed `round.camLead`.) + if (!R || R.runner !== "hearse") { + if (mine(round)) round.runner = null; + return; + } + const old = mine(round); + const again = old && old.room === round.room; + const check = again ? old.check : -1; + const you = round.you; + const x = check >= 0 ? R.checks[check] : round.spec.start; + Object.assign(you, { x, y: LANE_Y[0], vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 }); + round.runner = { + id: "hearse", room: round.room, check, lane: 0, from: 0, swMs: 0, h: 0, air: false, peak: 0, v: HEARSE_V, + lamp: again ? old.lamp : LAMP_MAX, out: false, broken: again ? old.broken : false, fog: false, coffins: again ? old.coffins : COFFINS, + sitters: [], faced: again ? old.faced : {}, wasDown: false, done: false, restX: 0, ...things(R, again ? old : null), + }; + round.camLead = CAM_AHEAD; + const b = round.bonusRound; + if (b) { + b.perf.goal = ACTS_GOAL; + if (!again) b.perf.total = 0; + } + if (b && round.runner.broken) b.perf.steady = false; +} + +/* ------------------------------------------------------------ the ride */ + +// The hearse's motion for one slice. Returns true once it has moved Planny (every slice of +// a ride); false outside a ride and once he has stepped out. +function ride(round, ms, k) { + const R = round.spec.ride; + const c = mine(round); + if (!R || R.runner !== "hearse" || !c || c.done) return false; + const you = round.you; + const inp = round.input; + const dt = ms / 1000; + const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra }); + if (you.x >= R.finish) return finish(round, c, R, k); + you.x += HEARSE_V * dt; + // The lane gates: LEFT is the road, RIGHT the verge. + const want = inp.left && !inp.right ? 0 : inp.right && !inp.left ? 1 : -1; + const gate = R.gates.some(([a, b]) => you.x >= a && you.x <= b); + if (gate && !c.air && c.swMs <= 0 && want >= 0 && want !== c.lane) startSwitch(c, want, ev, you); + if (c.swMs > 0) { + c.swMs = Math.max(0, c.swMs - ms); + you.ducking = false; + you.state = "run"; + you.vy = 0; + } else { + // On the road: jump, duck, or in the air. + const jump = inp.jump > 0; + if (!c.air && jump) { + inp.jump = 0; + c.air = true; + c.h = 0.001; + c.vy = JUMP_V; + c.peak = 0; + you.ducking = false; + ev("hearseJump"); + } else if (!c.air) { + const duck = Boolean(inp.down); + if (duck && !you.ducking) ev("hearseDuck"); + you.ducking = duck; + } + if (c.air) { + c.vy -= GRAVITY * dt; + c.h += c.vy * dt; + c.peak = Math.max(c.peak, c.h); + you.ducking = false; + if (c.h <= 0) { + ev("hearseLand", { big: c.peak >= BIG_LAND }); + Object.assign(c, { air: false, h: 0, vy: 0 }); + } + } + you.state = c.air ? "air" : "run"; + you.vy = c.air ? c.vy : 0; + } + you.y = baseOf(c) + (c.swMs > 0 ? 0 : c.h); + // A press nothing took waits a moment for a landing, then goes. + if (inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms); + while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) { + c.check++; + ev("hearseCheck", { n: c.check + 1 }); + } + round.camLead = CAM_AHEAD; + lamp(round, c, R, ms, ev); + if (obstacles(round, c, R, k)) return true; + creatures(round, c, R, ms); + return true; +} + +function startSwitch(c, to, ev, you) { + Object.assign(c, { from: c.lane, lane: to, swMs: SWITCH_MS, air: false, h: 0, vy: 0 }); + ev("hearseSwitch", { to, y: LANE_Y[to], x: you.x }); +} + +// The ride is over: the hearse brakes at the finish, the door opens, Planny walks out. +function finish(round, c, R, k) { + const you = round.you; + c.done = true; + c.restX = you.x; + Object.assign(c, { air: false, h: 0, vy: 0, swMs: 0 }); + Object.assign(you, { y: k.groundAt(round.spec, you.x), vy: 0, state: "run", shelf: -1, ducking: false }); + round.hasKey = true; + round.camLead = 0; + round.events.push({ type: "hearseFinish", x: you.x, y: you.y }); + return false; +} + +// The lamp burns down (faster in the fog), a lantern passed gives it back, and one that +// goes out leaves the night closed in until the next. +function lamp(round, c, R, ms, ev) { + const you = round.you; + const dt = ms / 1000; + const b = round.bonusRound; + c.fog = R.fog.some(([a, z]) => you.x >= a && you.x <= z); + c.lamp = Math.max(0, c.lamp - (LAMP_DRAIN + (c.fog ? LAMP_FOG : 0)) * dt); + if (c.lamp <= 0 && !c.out) { + c.out = true; + c.broken = true; + if (b) b.perf.steady = false; + ev("hearseLampOut"); + } + const lane = laneNow(c); + R.lanterns.forEach(([x, l], i) => { + if (c.lit[i] || l !== lane || Math.abs(you.x - x) > LANTERN_R || you.y > LANE_Y[l] + LANTERN_TOP) return; + c.lit[i] = true; + c.lamp = Math.min(LAMP_MAX, c.lamp + LANTERN_GAIN); + round.score += LANTERN_POINTS; + ev("hearseLantern", { x, y: LANE_Y[l] + 3.4, points: LANTERN_POINTS }); + if (c.out) { + c.out = false; + ev("hearseLampLit"); + } + }); +} + +// A heart lost on obstacle `id`: it was faced and cost, a coffin flies out ahead, and the +// crash is an event. Returns true. +function cost(round, c, id, what, x) { + face(round, c, id, true); + round.events.push({ type: "hearseCrash", what, x, y: round.you.y }); + if (c.coffins > 0) { + c.coffins--; + const lane = laneNow(c); + const tx = round.you.x + SIT_AHEAD; + c.sitters.push({ x: tx, ox: round.you.x, lane, state: "fly", t: FLY_MS }); + round.events.push({ type: "hearseCoffin", x: round.you.x - 4, y: round.you.y + 3, tx, lane, left: c.coffins }); + } + return true; +} + +// What the hearse runs into: a grave, a headstone or a cross, a low branch or the arch, a +// hand, a crow, a closed stretch. Returns whether it cost a heart. (Nothing counts while it +// hops between lanes: the lanes' gates keep their neighborhood clear.) +function obstacles(round, c, R, k) { + const you = round.you; + if (c.swMs > 0) return false; + const lane = c.lane; + const base = LANE_Y[lane]; + const hh = duckH(k, you); + const seen = (id, x) => { + if (you.x >= x && !c.faced[id]) face(round, c, id); + }; + for (const [i, [x, l]] of R.graves.entries()) { + if (l !== lane) continue; + seen(`g${i}`, x); + if (Math.abs(you.x - x) < GRAVE_W / 2 - 1 && you.y < base + GRAVE_DEEP && k.struck(round, "grave")) return cost(round, c, `g${i}`, "grave", x); + } + for (const [i, [x, l, kind]] of R.stones.entries()) { + if (l !== lane) continue; + seen(`s${i}`, x); + if (Math.abs(you.x - x) > 6) continue; + if (boxHit(k, you, x, base, kind ? CROSS_W : STONE_W, kind ? CROSS_H : STONE_H) && k.struck(round, kind ? "cross" : "tomb")) return cost(round, c, `s${i}`, kind ? "cross" : "stone", x); + } + for (const [i, [x0, x1, l]] of R.lows.entries()) { + if (l !== lane) continue; + seen(`l${i}`, (x0 + x1) / 2); + if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > base + LOW_Y && k.struck(round, "branch")) return cost(round, c, `l${i}`, "low", you.x); + } + for (const [i, [x, l]] of R.hands.entries()) { + const h = c.hands[i]; + if (l !== lane) continue; + seen(`h${i}`, x); + if (h.state !== "up" || Math.abs(you.x - x) > 5) continue; + if (boxHit(k, you, x, base, HAND_W, HAND_H) && k.struck(round, "grasp")) { + Object.assign(h, { state: "sink", t: HAND_SINK_MS }); + return cost(round, c, `h${i}`, "hand", x); + } + } + for (const [i, [, l, up]] of R.crows.entries()) { + const w = c.crows[i]; + if (l !== lane || w.state !== "fly") continue; + seen(`c${i}`, w.x); + if (boxHit(k, you, w.x, base + up, CROW_W, CROW_H) && k.struck(round, "crow")) { + w.state = "gone"; + return cost(round, c, `c${i}`, "crow", w.x); + } + } + for (const [i, [x0, x1, l]] of R.blocks.entries()) { + if (l !== lane) continue; + face(round, c, `b${i}`); + if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2) { + // Thrown across into the other lane, a heart lighter (unless safe a moment). + const hit = k.struck(round, "wreck"); + startSwitch(c, 1 - lane, (type, extra) => round.events.push({ type, x: you.x, y: you.y, ...extra }), you); + if (hit) return cost(round, c, `b${i}`, "wreck", you.x); + return false; + } + } + return false; +} + +// The hands in their mounds, the crows on their perches and the ghouls out of the coffins wake +// as the hearse comes near. +function creatures(round, c, R, ms) { + const you = round.you; + const dt = ms / 1000; + R.hands.forEach(([x, lane], i) => { + const h = c.hands[i]; + const y = LANE_Y[lane]; + if (h.state === "mound") { + const ahead = x - you.x; + if (ahead < HAND_NEAR && ahead > -HAND_W) { + Object.assign(h, { state: "warn", t: HAND_WARN_MS }); + round.events.push({ type: "hearseHandWarn", x, y }); + } + } else if (h.state === "warn" || h.state === "up" || h.state === "sink") { + h.t -= ms; + if (h.t > 0) return; + if (h.state === "warn") { + Object.assign(h, { state: "up", t: HAND_UP_MS }); + round.events.push({ type: "hearseHandUp", x, y }); + } else if (h.state === "up") Object.assign(h, { state: "sink", t: HAND_SINK_MS }); + else Object.assign(h, { state: "spent", t: 0 }); + } + }); + R.crows.forEach(([x, lane, up], i) => { + const w = c.crows[i]; + if (w.state === "perch") { + if (x - you.x < CROW_NEAR && x - you.x > -CROW_W) { + w.state = "fly"; + round.events.push({ type: "hearseCrowWake", x, y: LANE_Y[lane] + up }); + } + } else if (w.state === "fly") { + w.x -= CROW_V * dt; + if (w.x < you.x - 16) w.state = "gone"; + } + }); + for (const s of c.sitters) { + if (s.state === "fly") { + s.t -= ms; + if (s.t <= 0) { + Object.assign(s, { state: "sit", t: SIT_MS }); + round.events.push({ type: "hearseSitUp", x: s.x, y: LANE_Y[s.lane] }); + } + } else if (s.state === "sit") { + s.t -= ms; + if (s.t <= 0 || you.x > s.x - 3) s.state = "hid"; + } + } +} + +/* ------------------------------------------------------------- targets */ + +// A bolt into something to shoot: a hand reaching out, a crow, a ghoul sat up out of a +// coffin. True when one took it (the bolt is spent). +function hearseShot(round, s) { + const R = round.spec.ride; + const c = mine(round); + if (!R || R.runner !== "hearse" || !c) return false; + const hit = (x, y0, w, h) => Math.abs(s.x - x) <= w / 2 + SHOT_R && s.y >= y0 - SHOT_R && s.y <= y0 + h + SHOT_R; + const score = (n) => { + round.score += n; + if (round.bonusRound) round.bonusRound.perf.acts++; + }; + for (let i = 0; i < R.hands.length; i++) { + const h = c.hands[i]; + const [x, lane] = R.hands[i]; + const y = LANE_Y[lane]; + if (h.state !== "up" || !hit(x, y, HAND_W, HAND_H)) continue; + h.hp--; + if (h.hp > 0) round.events.push({ type: "hearseHandHit", x, y: y + HAND_H / 2 }); + else { + Object.assign(h, { state: "broken", t: 0 }); + score(HAND_POINTS); + round.events.push({ type: "hearseHandBreak", x, y: y + HAND_H / 2, points: HAND_POINTS }); + } + return true; + } + for (let i = 0; i < R.crows.length; i++) { + const w = c.crows[i]; + const [, lane, up] = R.crows[i]; + if ((w.state !== "fly" && w.state !== "perch") || !hit(w.x, LANE_Y[lane] + up, CROW_W, CROW_H)) continue; + w.state = "broken"; + score(CROW_POINTS); + round.events.push({ type: "hearseCrowHit", x: w.x, y: LANE_Y[lane] + up + CROW_H / 2, points: CROW_POINTS }); + return true; + } + for (const p of c.sitters) { + if (p.state !== "sit" || SIT_MS - p.t < SIT_RISE_MS || !hit(p.x, LANE_Y[p.lane], SIT_W, SIT_H)) continue; + p.state = "broken"; + score(SIT_POINTS); + round.events.push({ type: "hearseSitHit", x: p.x, y: LANE_Y[p.lane] + SIT_H / 2, points: SIT_POINTS }); + return true; + } + return false; +} + +export const HEARSE = freeze({ + id: "hearse", + monsters: MONSTERS, + walkers: freeze([]), + zombies: freeze([]), + stackers: freeze([]), + climbers: freeze([]), + act: freeze({}), + horde: freeze({}), + ride: freeze([ride]), + place: freeze([place]), + target: hearseShot, +}); + diff --git a/src/web-console/public/activities/ghoul-intro-draw.js b/src/web-console/public/activities/ghoul-intro-draw.js new file mode 100644 index 0000000..19bdbb6 --- /dev/null +++ b/src/web-console/public/activities/ghoul-intro-draw.js @@ -0,0 +1,336 @@ +// Plan2Code Web Console - Ghoul Rush's stage intro card: a full-field title card with the stage's name in big colored letters dropping in one by one and then glowing, a small themed flourish drawn with canvas shapes (frost crystals, bunting, pickaxe sparks, drifting leaves, candle flames, ...), a few lines of flavor text fading in, the boss's name and a hint to press a key. +// +// ghoul-draw.js plugs it in, the way it plugs in ghoul-gameover-draw.js: +// introArt(d) takes its drawing helpers (`d`: label, GOLD, BONE) and hands back +// `(ctx, v)`, drawn over the whole field while `round.phase === "intro"` (also +// while paused). `round.introMs` is how long the card has been up (it stops with +// the game, so a pause holds the animation). The words and colors live in +// ghoul-intros.js. Field units (96 by 54), y counted down from the field's top. + +import { INTRO_MIN_MS } from "./ghoul-run.js"; +import { introFor } from "./ghoul-intros.js"; + +export const INTRO_HINT = "Press any move key or fire to enter"; +export const TITLE_SIZE = 5.6; +export const LINE_SIZE = 2.3; +const DROP_MS = 520; +const STAGGER_MS = 70; +const TAU = Math.PI * 2; + +// How wide a letter runs, in ems: narrow, wide, and the rest. +const advance = (ch) => (" .,:;'!iIjl".includes(ch) ? 0.36 : "mwMW".includes(ch) ? 0.95 : 0.66); + +// The title's letters: x offsets from its middle, and the size that keeps it inside `max` units. +export function titleLayout(title, max = 88) { + const em = [...title].reduce((s, ch) => s + advance(ch), 0); + const size = Math.min(TITLE_SIZE, max / em); + let x = -(em * size) / 2; + const xs = [...title].map((ch) => { + const at = x + (advance(ch) * size) / 2; + x += advance(ch) * size; + return at; + }); + return { size, xs }; +} + +// A letter's height above its rest `t` ms after it began to fall: 1 high up, 0 at rest, one small bounce. +export function dropAt(t) { + if (t <= 0) return 1; + if (t >= DROP_MS) return 0; + const p = t / DROP_MS; + if (p < 0.6) return 1 - (p / 0.6) ** 2; + return Math.sin(((p - 0.6) / 0.4) * Math.PI) * 0.14; +} + +// A steady pseudo-random number in [0, 1) for item `i` and a salt. +export const rnd = (i, salt = 0) => { + const x = Math.sin(i * 12.9898 + salt * 78.233) * 43758.5453; + return x - Math.floor(x); +}; + +export const poly = (ctx, pts, fill) => { + ctx.beginPath(); + pts.forEach(([x, y], i) => (i ? ctx.lineTo(x, y) : ctx.moveTo(x, y))); + ctx.closePath(); + ctx.fillStyle = fill; + ctx.fill(); +}; +export const dot = (ctx, x, y, r, fill) => { + ctx.beginPath(); + ctx.arc(x, y, Math.max(0.05, r), 0, TAU); + ctx.fillStyle = fill; + ctx.fill(); +}; +export const stroke = (ctx, x1, y1, x2, y2, color, w) => { + ctx.beginPath(); + ctx.moveTo(x1, y1); + ctx.lineTo(x2, y2); + ctx.strokeStyle = color; + ctx.lineWidth = w; + ctx.stroke(); +}; +// Draws `fn` at `alpha` times the alpha it was called with. +export const faint = (ctx, alpha, fn) => { + const was = ctx.globalAlpha; + ctx.globalAlpha = was * Math.max(0, Math.min(1, alpha)); + fn(); + ctx.globalAlpha = was; +}; +// A flame: a teardrop of height h at (x, y), wavering. +export const flame = (ctx, x, y, h, t, i, color) => { + const sway = Math.sin(t / 120 + i * 2) * h * 0.18; + const hh = h * (0.9 + 0.1 * Math.sin(t / 90 + i)); + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.quadraticCurveTo(x - h * 0.45, y - hh * 0.4, x + sway, y - hh); + ctx.quadraticCurveTo(x + h * 0.45, y - hh * 0.4, x, y); + ctx.fillStyle = color; + ctx.fill(); +}; +// A frost crystal: three crossing arms and a diamond heart. +const flake = (ctx, x, y, r, rot, color) => { + for (let k = 0; k < 3; k++) { + const a = rot + (k * Math.PI) / 3; + stroke(ctx, x - Math.cos(a) * r, y - Math.sin(a) * r, x + Math.cos(a) * r, y + Math.sin(a) * r, color, Math.max(0.12, r * 0.14)); + } + poly(ctx, [[x, y - r * 0.5], [x + r * 0.3, y], [x, y + r * 0.5], [x - r * 0.3, y]], color); +}; + +// Each stage's flourish: (ctx, t, pal, W, H) drawn behind the words. +const FLOURISH = { + // Bats crossing the sky. + manor(ctx, t, pal, W) { + for (let i = 0; i < 4; i++) { + const x = ((t / 30 + i * 31) % (W + 16)) - 8; + const y = 6 + i * 9 + Math.sin(t / 400 + i) * 2; + const f = Math.sin(t / 80 + i) * 1.6; + poly(ctx, [[x, y], [x - 3, y - 1.6 + f], [x - 1.4, y + 0.4], [x, y + 0.8], [x + 1.4, y + 0.4], [x + 3, y - 1.6 + f]], pal.glow); + } + }, + // Dust in the lamplight and a spider on a thread. + wing(ctx, t, pal, W, H) { + for (let i = 0; i < 26; i++) dot(ctx, rnd(i) * W + Math.sin(t / 900 + i) * 2, H - ((t / 40 + rnd(i, 1) * H) % H), 0.2 + rnd(i, 2) * 0.35, pal.glow); + const drop = 8 + Math.sin(t / 700) * 3; + stroke(ctx, W - 10, 0, W - 10, drop, pal.glow, 0.15); + dot(ctx, W - 10, drop + 0.8, 0.9, pal.a); + }, + // Headstones in a rolling mist. + graveyard(ctx, t, pal, W, H) { + for (let i = 0; i < 6; i++) { + const x = 7 + i * 16 + (i % 2) * 3; + const h = 5 + (i % 3) * 1.8; + ctx.fillStyle = "rgba(10, 18, 14, 0.9)"; + ctx.fillRect(x - 2, H - h, 4, h); + ctx.beginPath(); + ctx.arc(x, H - h, 2, Math.PI, 0); + ctx.fill(); + } + for (let i = 0; i < 5; i++) { + faint(ctx, 0.35, () => { + ctx.beginPath(); + ctx.ellipse(((t / 90 + i * 23) % (W + 30)) - 15, H - 2.2 - (i % 2), 14, 1.8, 0, 0, TAU); + ctx.fillStyle = pal.glow; + ctx.fill(); + }); + } + }, + // Leaves drifting down. + grounds(ctx, t, pal, W, H) { + for (let i = 0; i < 16; i++) { + const y = ((t / 28 + rnd(i) * H * 2) % (H + 6)) - 3; + const x = rnd(i, 1) * W + Math.sin(t / 600 + i * 1.7) * 4; + ctx.beginPath(); + ctx.ellipse(x, y, 1.1, 0.55, t / 500 + i, 0, TAU); + ctx.fillStyle = i % 3 ? pal.a : pal.glow; + ctx.fill(); + } + }, + // Candles in two rows with wavering flames. + chapel(ctx, t, pal, W, H) { + for (let i = 0; i < 8; i++) { + const x = i < 4 ? 4 + i * 3.4 : W - 4 - (i - 4) * 3.4; + const h = 5 + (i % 3) * 1.5; + ctx.fillStyle = "#efe6cf"; + ctx.fillRect(x - 0.7, H - h, 1.4, h); + flame(ctx, x, H - h, 2.6, t, i, pal.glow); + flame(ctx, x, H - h - 0.1, 1.4, t + 40, i, "#fff3c4"); + } + }, + // A heartbeat that runs across the bottom, and a blinking cross. + sanatorium(ctx, t, pal, W, H) { + ctx.beginPath(); + for (let x = 0; x <= W; x += 0.8) { + const p = (((x + t / 22) % 40) + 40) % 40; + const y = p > 14 && p < 15 ? -5 : p >= 15 && p < 16.5 ? 3 : p >= 16.5 && p < 17.5 ? -1 : 0; + if (x) ctx.lineTo(x, H - 4 + y); + else ctx.moveTo(x, H - 4 + y); + } + ctx.strokeStyle = pal.glow; + ctx.lineWidth = 0.35; + ctx.stroke(); + if (Math.sin(t / 700) > -0.2) { + ctx.fillStyle = pal.glow; + ctx.fillRect(W - 9, 3, 3, 1); + ctx.fillRect(W - 8, 2, 1, 3); + } + }, + // A crescent moon and windows that blink. + village(ctx, t, pal, W, H) { + dot(ctx, W - 14, 11, 4.5, pal.glow); + dot(ctx, W - 12.4, 10, 4.2, "#0e0c28"); + for (let i = 0; i < 9; i++) { + const lit = Math.sin(t / 900 + i * 2.3) > -0.4; + ctx.fillStyle = "rgba(8, 6, 24, 0.9)"; + ctx.fillRect(3 + i * 10.4, H - 6, 6, 6); + ctx.fillStyle = lit ? pal.glow : "rgba(40, 40, 80, 0.8)"; + ctx.fillRect(4.6 + i * 10.4, H - 4.6, 2.8, 2.4); + } + }, + // Sparks flying off a pickaxe's strike, low at both sides. + mine(ctx, t, pal, W, H) { + for (const side of [0, 1]) { + const bx = side ? W - 7 : 7; + stroke(ctx, bx - 3, H - 3, bx + 3, H - 9, "#8a6a42", 0.6); + stroke(ctx, bx - 3.5, H - 8, bx + 3.5, H - 9.5, "#cfd5da", 0.9); + for (let i = 0; i < 12; i++) { + const p = (t / 700 + rnd(i, side)) % 1; + const a = -Math.PI * (0.15 + 0.7 * rnd(i, 3 + side)); + const sp = 7 + rnd(i, 5) * 8; + faint(ctx, 1 - p, () => dot(ctx, bx + Math.cos(a) * sp * p, H - 8 + Math.sin(a) * sp * p + 24 * p * p, 0.35, i % 2 ? pal.glow : "#fff3c4")); + } + } + }, + // Bunting along the top, swaying, with bulbs. + carnival(ctx, t, pal) { + const cols = [pal.a, pal.glow, "#fde047", pal.b]; + for (let row = 0; row < 2; row++) { + for (let i = 0; i < 12; i++) { + const x = 4 + i * 8; + const sag = Math.sin((i / 11) * Math.PI) * (3 + row * 2.5) + row * 3; + const sw = Math.sin(t / 400 + i + row) * 0.5; + poly(ctx, [[x - 2, sag], [x + 2, sag], [x + sw, sag + 4]], cols[(i + row) % 4]); + dot(ctx, x, sag - 0.3, 0.3 + 0.15 * Math.sin(t / 150 + i), "#fffbe8"); + } + } + }, + // Frost crystals falling and twinkling. + frozen(ctx, t, pal, W, H) { + for (let i = 0; i < 14; i++) { + const y = ((t / 40 + rnd(i) * H * 2) % (H + 8)) - 4; + const x = rnd(i, 1) * W + Math.sin(t / 800 + i) * 3; + faint(ctx, 0.5 + 0.5 * Math.sin(t / 220 + i * 1.9) ** 2, () => flake(ctx, x, y, 0.8 + rnd(i, 2) * 1.6, t / 1500 + i, pal.glow)); + } + }, + // Wisp motes drifting over rising mud bubbles. + bog(ctx, t, pal, W, H) { + for (let i = 0; i < 7; i++) { + const x = ((rnd(i, 4) * W + t / 60 + Math.sin(t / 700 + i) * 6) % (W + 8)) - 4; + const y = H * 0.25 + rnd(i, 5) * H * 0.5 + Math.sin(t / 500 + i * 1.7) * 3; + faint(ctx, 0.5 + 0.5 * Math.sin(t / 300 + i * 2.1), () => dot(ctx, x, y, 0.7 + rnd(i, 6) * 0.6, pal.glow)); + } + for (let i = 0; i < 6; i++) { + const p = (t / 1600 + rnd(i, 7)) % 1; + const x = 8 + rnd(i, 8) * (W - 16); + faint(ctx, 1 - p, () => { + ctx.beginPath(); + ctx.arc(x, H - 3 - p * 10, 0.5 + p * 0.8, 0, TAU); + ctx.strokeStyle = pal.a; + ctx.lineWidth = 0.2; + ctx.stroke(); + }); + } + }, + // The hall: dust and a flickering torch at each end. + hall(ctx, t, pal, W, H) { + for (let i = 0; i < 18; i++) dot(ctx, rnd(i) * W, H - ((t / 45 + rnd(i, 1) * H) % H), 0.25, pal.glow); + for (const x of [5, W - 5]) { + ctx.fillStyle = "#3a2a18"; + ctx.fillRect(x - 0.5, H - 8, 1, 5); + flame(ctx, x, H - 8, 3.2, t, x, pal.glow); + } + }, +}; + +export function introArt(d) { + const { label, GOLD, BONE } = d; + return function introCard(ctx, v) { + const { g, round } = v; + const info = introFor(round.stage); + if (!info) return; + const t = round.introMs || 0; + const W = g.FIELD_W; + const H = g.FIELD_H; + const pal = info.palette; + const fade = Math.min(1, t / 320); + ctx.save(); + ctx.globalAlpha = fade * 0.97; + ctx.fillStyle = "#07050c"; + ctx.fillRect(0, 0, W, H); + // Bands of the stage's color rising from the floor, a glow behind the title. + for (let i = 0; i < 8; i++) { + ctx.globalAlpha = fade * (0.05 + 0.02 * (7 - i)); + ctx.fillStyle = pal.b; + ctx.fillRect(0, H - (i + 1) * (H / 8), W, H / 8); + } + ctx.globalAlpha = fade * (0.1 + 0.04 * Math.sin(t / 500)); + ctx.beginPath(); + ctx.ellipse(W / 2, 16, 38, 11, 0, 0, TAU); + ctx.fillStyle = pal.glow; + ctx.fill(); + ctx.globalAlpha = fade; + (FLOURISH[round.stage] || FLOURISH.hall)(ctx, t, pal, W, H); + ctx.globalAlpha = fade; + // A frame in the stage's color. + ctx.strokeStyle = pal.glow; + ctx.lineWidth = 0.4; + ctx.strokeRect(1.2, 1.2, W - 2.4, H - 2.4); + // The kicker, then the title letter by letter. + label(ctx, info.kicker.toUpperCase(), W / 2, 6, 1.9, BONE, "center", W - 8); + const { size, xs } = titleLayout(info.title); + const chars = [...info.title]; + for (let i = 0; i < chars.length; i++) { + if (chars[i] === " ") continue; + const at = t - 200 - i * STAGGER_MS; + const landed = at >= DROP_MS; + const x = W / 2 + xs[i]; + const y = 15 - dropAt(at) * 20 + (landed ? Math.sin(t / 260 - i * 0.6) * size * 0.05 : 0); + ctx.globalAlpha = fade * Math.min(1, Math.max(0, at / 80 + 0.2)); + // The glow breathes under each landed letter. + if (landed) { + ctx.globalAlpha = fade * (0.25 + 0.2 * Math.sin(t / 300 - i * 0.5)); + label(ctx, chars[i], x, y, size * 1.12, pal.glow, "center"); + ctx.globalAlpha = fade; + } + label(ctx, chars[i], x + 0.3, y + 0.5, size, "rgba(0, 0, 0, 0.65)", "center"); + label(ctx, chars[i], x, y, size, i % 2 ? pal.b : pal.a, "center"); + // A lighter top edge once landed. + if (landed) { + ctx.globalAlpha = fade * 0.55; + label(ctx, chars[i], x, y - size * 0.06, size * 0.94, pal.a, "center"); + ctx.globalAlpha = fade; + } + } + // A divider, then the flavor lines fading up one at a time. + const lineAt = 1000; + ctx.globalAlpha = fade * Math.min(1, Math.max(0, (t - 800) / 400)); + stroke(ctx, W / 2 - 20, 22, W / 2 + 20, 22, pal.glow, 0.3); + dot(ctx, W / 2, 22, 0.8 + 0.2 * Math.sin(t / 250), pal.glow); + info.lines.forEach((line, i) => { + const p = Math.min(1, Math.max(0, (t - lineAt - i * 550) / 450)); + ctx.globalAlpha = fade * p; + label(ctx, line, W / 2, 27.5 + i * 4.4 + (1 - p) * 1.2, LINE_SIZE, BONE, "center", W - 4); + }); + if (info.boss) { + const p = Math.min(1, Math.max(0, (t - lineAt - info.lines.length * 550) / 450)); + ctx.globalAlpha = fade * p; + label(ctx, `BOSS: ${info.boss.toUpperCase()}`, W / 2, 46.5, 2, GOLD, "center", W - 8); + } + // The hint, pulsing once a key is let through (the card waits for it as long as YOU like). + if (t >= INTRO_MIN_MS) { + ctx.globalAlpha = fade * (0.55 + 0.45 * Math.sin(t / 260)); + label(ctx, INTRO_HINT, W / 2, 51.2, 1.9, pal.glow, "center"); + } + ctx.restore(); + ctx.globalAlpha = 1; + }; +} diff --git a/src/web-console/public/activities/ghoul-intros.js b/src/web-console/public/activities/ghoul-intros.js new file mode 100644 index 0000000..df7189a --- /dev/null +++ b/src/web-console/public/activities/ghoul-intros.js @@ -0,0 +1,85 @@ +// Plan2Code Web Console - Ghoul Rush's stage intro cards, the words and colors: per stage id, the title, a palette, a kicker line, 3 or 4 lines of flavor text and the boss's name. ghoul-intro-draw.js draws them; scripts/test-web-console-activities-ghoul-intro.mjs makes sure every stage in STAGES has one. +// +// Rules for the text (see "Stage intro screens" in prototypes/Ghoul-Rush-TODO.md): +// 3 or 4 lines, each at most MAX_LINE characters (the card is 96 units wide), +// always addressed to YOU (never the hero's name), no em dash, US English, +// spooky-fun and a little menacing, naming the boss and what it has done. +// The palette: `a` the title's top color, `b` its bottom color, `glow` the +// halo and the flourish's color. + +export const MAX_LINE = 60; + +const freeze = Object.freeze; +const intro = (title, a, b, glow, kicker, boss, lines) => freeze({ title, palette: freeze({ a, b, glow }), kicker, boss, lines: freeze(lines) }); + +export const INTROS = freeze({ + manor: intro("The Manor", "#ffb347", "#c2410c", "#ff8a1f", "Where the screaming started", "The Rotting Gourd", [ + "The Manor has stood empty for a century. It is not empty.", + "The Rotting Gourd grows in the cellar and has gone sour.", + "It ate the last owners, the staff and the dinner guests.", + "YOU are next on the menu. Squash it before it squashes YOU.", + ]), + wing: intro("The East Wing", "#e9d5ff", "#7c3aed", "#c084fc", "The servants never left", "Old Rattlebones", [ + "The staff kept working long after they stopped breathing.", + "Old Rattlebones, the butler, still keeps the house tidy.", + "He keeps the guests too. They are all in the crypt.", + "Do not let him show YOU in. YOU would never be shown out.", + ]), + graveyard: intro("The Graveyard", "#d1fae5", "#4b6a5a", "#9fe6c4", "Everyone here was buried in a hurry", "Mother Mourning", [ + "Nobody here was buried with proper paperwork, or manners.", + "Mother Mourning weeps at every grave. Count them: all hers.", + "She turns around when YOU move, and so do the headstones.", + "Dry her tears for good. YOU have the only handkerchief.", + ]), + grounds: intro("The Grounds", "#bef264", "#b45309", "#facc15", "The gardener never stopped working", "The Groundskeeper", [ + "The hedges are trimmed. So is the lawn. So were the guests.", + "The Groundskeeper walks his rounds with shears and lantern.", + "He has been pruning the village since before it had a name.", + "Stay out of his flower beds. YOU would make fine compost.", + ]), + chapel: intro("The Chapel", "#fde68a", "#be123c", "#fb923c", "Service is still in session", "The Choirmaster", [ + "The bell tolls hourly, and no one is left to pull the rope.", + "The Choirmaster drills his pipes until they scream in tune.", + "He needs one more voice, and he has YOU in mind.", + "Silence the organ before YOU are asked to sing.", + ]), + sanatorium: intro("Blackmoor Sanatorium", "#a7f3d0", "#0f766e", "#5eead4", "Visiting hours ended in 1912", "The Night Matron", [ + "The patients never checked out, and the lights flicker.", + "The Night Matron makes rounds with a lantern and a needle.", + "She has cured every ward of everything, including breathing.", + "Bedtime for YOU, she says. YOU do not intend to nap.", + ]), + village: intro("Hollow End Village", "#c4b5fd", "#312e81", "#a5b4fc", "Every curtain twitches as you pass", "The Beast of Hollow End", [ + "Every lock is bolted and every shutter nailed. Not for YOU.", + "The Beast of Hollow End prowls the rooftops after dark.", + "It took the baker, the blacksmith and the bell ringer.", + "The moon is full tonight. YOU are the only one outside.", + ]), + mine: intro("The Deep Seam Mine", "#fdba74", "#7c2d12", "#fbbf24", "They are still knocking", "The Tommyknocker", [ + "The miners went down for coal and never came back up.", + "The Tommyknocker taps on the timbers, and the roof listens.", + "Follow the knocking and it leads YOU to a dead end.", + "Bring a light, a steady aim and a very good excuse.", + ]), + carnival: intro("The Midnight Carnival", "#fda4af", "#7e22ce", "#f472b6", "Every game is rigged in its favor", "The Ringmaster", [ + "Step right up! The tickets are free, the exits are not.", + "The Ringmaster pulls the strings, and the whole town dances.", + "He has been cutting new puppets since the carnival opened.", + "YOU are in the crowd, so YOU are in the show. Take a bow.", + ]), + frozen: intro("The Frozen Lake", "#bae6fd", "#1d4ed8", "#e0f2fe", "The ice remembers who fell through", "The Frost Widow", [ + "The lake froze solid overnight, with the swimmers inside.", + "The Frost Widow spins her veil from snow and slow breath.", + "She keeps every one who fell through. YOU are on thin ice.", + "Melt her heart, if she has one. Watch YOUR step, and toes.", + ]), + bog: intro("Gallows Bog", "#d6ee9c", "#44521c", "#9fd06b", "The mud does not like to let go", "Old Mother Bog", [ + "The boardwalk sank years ago. The walkers never left.", + "Old Mother Bog stirs her pot under the black water.", + "Chase the pretty lights and they will lead YOU under.", + "The mud holds what it catches. Do not let it hold YOU.", + ]), +}); + +// The card for a stage id, or null for an id with none (the hall is no stage and has no card). +export const introFor = (id) => INTROS[id] || null; diff --git a/src/web-console/public/activities/ghoul-mower-draw.js b/src/web-console/public/activities/ghoul-mower-draw.js new file mode 100644 index 0000000..7cb5be5 --- /dev/null +++ b/src/web-console/public/activities/ghoul-mower-draw.js @@ -0,0 +1,1210 @@ +// Plan2Code Web Console - Ghoul Rush's Gardener's Revenge, its drawing: a night ride on a rusty ride-on mower down a long overgrown lawn. A moon and stars, the manor on its hill and a far row of topiary and iron railings that scroll by at different speeds, the lawn with its mow stripes, ponds and ha-ha ditches, the things on it (tall grass that is cut as the blades pass, weeds, thorn hedges, gnomes, barrows, flowerpots, snapping topiary beasts, checkpoint lanterns, the finish gate), and in front the mower itself with its blades and heat gauge, the hedge arches and clothes lines of gloves, the lawn gauge and the glyphs that say what to do about what is coming. +// +// ghoul-draw.js plugs it in. LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are plain data +// (the sounds are in ghoul-sfx-mower.js); mowerArt(d) takes ghoul-draw.js's drawing helpers (`d`) and +// hands back the drawing by kind, so this file never reaches back into it. Drawn in room units, the way +// ghoul-draw.js draws: y counted down from the field's top, so a world height `y` is drawn at +// `FIELD_H - y`. The still layers' pit is dark under the whole ride, so the sky, the far scenery, the +// lawn and what stands on it are drawn by `moving` (every frame, over the cached still layers): +// parallax tiles and lawn chunks are cached in offscreen canvases of this file's own (no random +// numbers: everything comes from a hash). The lows, the mower and the gauges are drawn by `front`. +// What the art reads off the rules (ghoul-mower.js): +// +// - the room: `spec.ride` ({ track, gaps, junk, lows [x0, x1, y, kind], hedges, beasts, grass, +// weeds, checks, finish }), `spec.ground` (the lawn at the start and at the end). +// - `round.runner` (id "mower"; null in any other room): `v`, `line` (-1 in the air), `check`, `done`, +// `heat`, `jam` (ms left), `blade` (down), `lawn` (0 to 1), `grass` [[cut cells]], `hedges` [cut], +// `weeds` [cut], `beasts` [{ state "idle" | "warn" | "snap" | "sink" | "spent" | "broken", t }]. +// - Planny: `you.state`, `you.vy` (tilts the mower in the air), `you.ducking`, `you.x`, `you.y`. +// - events leave short-lived bits in the view's `fx` (`mowerBits`, `mowerLand`). + +const freeze = (o) => Object.freeze(o); +const TAU = Math.PI * 2; +const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x)); + +const pit = (o) => freeze({ pack: "mower", custom: true, noMoon: true, pit: "#05090a", ...o }); +export const LOOKS = freeze({ + mower: pit({ wallTop: "#04080f", wallLow: "#1b2d33", paper: "#0e1a12", wainscot: "#0a160c", floorTop: "#4c8a34", floor: "#2a2012", floorEdge: "#080c06", shelf: "#2a4a22", shelfTop: "#437a34", window: "#e8f0d8", decor: "plants", color: "#9fe08a", dark: 0.5 }), +}); + +// How each new kind sounds, by act (the sounds are in ghoul-sfx-mower.js). +export const VOICES = freeze({ + mower: freeze({ jump: "ghoulMowerJump", land: "ghoulMowerLand", duck: "ghoulMowerDuck", crash: "ghoulMowerCrash", check: "ghoulMowerCheck", finish: "ghoulMowerFinish", grass: "ghoulMowerGrass", hedge: "ghoulMowerHedge", weed: "ghoulMowerWeed", jam: "ghoulMowerJam" }), + mowerbeast: freeze({ warn: "ghoulMowerBeastWarn", snap: "ghoulMowerBeastSnap", hit: "ghoulMowerBeastHit", break: "ghoulMowerBeastBreak" }), +}); + +// What each of the pack's events plays: [kind, act], once. +export const EVENT_VOICE = freeze({ + mowerJump: ["mower", "jump"], + mowerLand: ["mower", "land"], + mowerDuck: ["mower", "duck"], + mowerCrash: ["mower", "crash"], + mowerCheck: ["mower", "check"], + mowerFinish: ["mower", "finish"], + mowerGrass: ["mower", "grass"], + mowerHedge: ["mower", "hedge"], + mowerWeed: ["mower", "weed"], + mowerJam: ["mower", "jam"], + mowerBeastWarn: ["mowerbeast", "warn"], + mowerBeastSnap: ["mowerbeast", "snap"], + mowerBeastHit: ["mowerbeast", "hit"], + mowerBeastBreak: ["mowerbeast", "break"], +}); +export const LOSE_WORDS = freeze({ + gnome: "Ran over a gnome", + barrow: "Hit a wheelbarrow", + pot: "Smashed a flowerpot", + arch: "Hit a hedge arch", + line: "Tangled in the washing", + thorns: "Caught in the thorns", + snap: "Snapped up by topiary", + pond: "Drove into the pond", + ditch: "Fell in the ditch", +}); +export const LOSE_SOUNDS = freeze({ + gnome: ["smash", 0.5, 1.1], + barrow: ["clank", 0.6, 0.8], + pot: ["smash", 0.6, 0.8], + arch: ["clank", 0.5, 0.7], + line: ["ghoulHandsGrab", 0.5, 1], + thorns: ["ghoulHandsGrab", 0.5, 0.8], + snap: ["clank", 0.5, 1.2], + pond: ["splashBig", 0.6, 1], + ditch: ["ghoulPitFall", 0.55, 0.9], +}); + +const FW = 96; +const CH = 48; +const SEAM = 0.5; +const LANE = 12; +const BLADE_REACH = 9; +let FH = 54; + +// A number in 0..1 from two integers, the same every time (no random draws). +const rnd = (a, b = 0) => { + let h = Math.imul((a | 0) + 0x9e37, 0x85ebca6b) ^ Math.imul((b | 0) + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +const poly = (c, pts) => { + c.beginPath(); + pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); + c.closePath(); +}; +const seg = (c, x0, y0, x1, y1) => { + c.beginPath(); + c.moveTo(x0, y0); + c.lineTo(x1, y1); + c.stroke(); +}; +const disc = (c, x, y, r) => { + c.beginPath(); + c.arc(x, y, r, 0, TAU); + c.fill(); +}; +const grad = (make, stops) => { + const g = make ? make() : null; + if (!g || typeof g.addColorStop !== "function") return stops[stops.length >> 1][1]; + for (const [o, col] of stops) g.addColorStop(o, col); + return g; +}; +const vgrad = (c, y0, y1, stops) => grad(c.createLinearGradient && (() => c.createLinearGradient(0, y0, 0, y1)), stops); +const rgrad = (c, x, y, r, stops) => grad(c.createRadialGradient && (() => c.createRadialGradient(x, y, 0, x, y, r)), stops); + +/* --------------------------------------------------- cached offscreen layers */ + +const layers = new Map(); +let layerScale = 0; +const offscreen = (w, h) => { + if (typeof OffscreenCanvas === "function") return new OffscreenCanvas(w, h); + if (typeof document !== "undefined") return Object.assign(document.createElement("canvas"), { width: w, height: h }); + return null; +}; +// A layer of `w` by `h` units painted once by paint(c) in unit coordinates, then reused; null where +// the context cannot say its scale (the caller paints direct). +function layerFor(ctx, key, w, h, paint) { + const m = typeof ctx.getTransform === "function" ? ctx.getTransform() : null; + if (!m || !(m.a > 0)) return null; + const a = m.a; + if (a !== layerScale) { + layers.clear(); + layerScale = a; + } + let layer = layers.get(key); + if (layer) { + layers.delete(key); + layers.set(key, layer); + return layer; + } + try { + layer = offscreen(Math.ceil(w * a), Math.ceil(h * a)); + const g = layer && layer.getContext("2d"); + if (!g) return null; + g.scale(a, a); + paint(g); + } catch { + return null; + } + layers.set(key, layer); + if (layers.size > 40) layers.delete(layers.keys().next().value); + return layer; +} + +// A soft round glow sprite per color, drawn scaled at a light. +const HALO = freeze({ warm: "255,196,110", red: "255,70,50", green: "90,240,130", cold: "150,205,255", white: "235,245,255", lime: "190,255,120" }); +function halo(ctx, kind, x, y, r, alpha) { + const sprite = layerFor(ctx, `mower:halo:${kind}`, 8, 8, (g) => { + g.fillStyle = rgrad(g, 4, 4, 4, [[0, `rgba(${HALO[kind]},1)`], [0.35, `rgba(${HALO[kind]},0.45)`], [1, `rgba(${HALO[kind]},0)`]]); + g.fillRect(0, 0, 8, 8); + }); + ctx.globalAlpha = alpha; + if (sprite) ctx.drawImage(sprite, x - r, y - r, r * 2, r * 2); + else { + ctx.fillStyle = `rgb(${HALO[kind]})`; + ctx.globalAlpha = alpha * 0.4; + disc(ctx, x, y, r * 0.5); + } + ctx.globalAlpha = 1; +} + +// Each tile is painted over [0, W + SEAM] and repeats every W: whatever sticks out of one edge is +// painted again a tile over, so the seams never show. +const wrap = (W, fn) => { + fn(0); + fn(-W); + fn(W); +}; + +// Draws a repeating tile layer at parallax factor `f` (1 moves with the lawn). +function tile(ctx, key, W, f, cam, paint) { + const ox = cam * (1 - f); + const k0 = Math.floor((cam - ox) / W); + const k1 = Math.floor((cam + FW - ox) / W); + const layer = layerFor(ctx, key, W + SEAM, FH, paint); + for (let k = k0; k <= k1; k++) { + const x = Math.round((ox + k * W) * 8) / 8; + if (layer) ctx.drawImage(layer, x, 0, W + SEAM, FH); + else { + ctx.save(); + ctx.translate(x, 0); + paint(ctx); + ctx.restore(); + } + } +} + +/* ------------------------------------------------------- sky and far scenery */ + +const LANE_Y = () => FH - LANE; +const WF = 168; +const WM = 120; + +// The far tile: dark hills with the manor on one, its windows lit, and a few dead and pointed trees. +function paintFar(c) { + const base = LANE_Y(); + wrap(WF, (o) => { + c.fillStyle = "#0a1512"; + c.beginPath(); + c.moveTo(o - 2, base + 1); + c.lineTo(o - 2, base - 6); + c.bezierCurveTo(o + 30, base - 11, o + 50, base - 12, o + 84, base - 9); + c.bezierCurveTo(o + 110, base - 7, o + 130, base - 10, o + WF + 2, base - 6); + c.lineTo(o + WF + 2, base + 1); + c.closePath(); + c.fill(); + // The manor on its hill. + const mx = o + 66; + const my = base - 10.5; + c.fillStyle = "#070d0e"; + c.fillRect(mx, my - 9, 30, 9.5); + poly(c, [[mx - 1, my - 9], [mx + 8, my - 14], [mx + 22, my - 14], [mx + 31, my - 9]]); + c.fill(); + c.fillRect(mx + 11, my - 20, 8, 12); + poly(c, [[mx + 10, my - 20], [mx + 15, my - 25], [mx + 20, my - 20]]); + c.fill(); + c.fillRect(mx + 2, my - 17, 1.4, 4); + c.fillRect(mx + 26, my - 17, 1.4, 4); + for (let k = 0; k < 7; k++) { + c.fillStyle = rnd(k, 3) < 0.6 ? "rgba(255,196,110,0.8)" : "rgba(255,196,110,0.25)"; + c.fillRect(mx + 3 + k * 4, my - 6.4, 1.2, 2); + } + c.fillStyle = "rgba(255,196,110,0.7)"; + c.fillRect(mx + 14.2, my - 17, 1.4, 2.2); + // Trees: pines and a few bare ones. + for (let k = 0; k < 11; k++) { + const x = o + 4 + k * 14.5 + rnd(k, 5) * 4; + if (x > o + 58 && x < o + 100) continue; + const h = 6 + rnd(k, 6) * 7; + const b = base - 5 + Math.sin(k) * 1.5; + c.fillStyle = "#0b1a16"; + if (k % 4 === 3) { + c.strokeStyle = "#0b1a16"; + c.lineWidth = 0.4; + seg(c, x, b, x, b - h); + seg(c, x, b - h * 0.6, x - 2, b - h * 0.95); + seg(c, x, b - h * 0.45, x + 2.2, b - h * 0.8); + } else { + for (let t = 0; t < 3; t++) poly(c, [[x, b - h + t * h * 0.22], [x - 2.2 + t * 0.3, b - h * 0.45 + t * h * 0.2], [x + 2.2 - t * 0.3, b - h * 0.45 + t * h * 0.2]]), c.fill(); + } + } + }); +} + +// One topiary shape standing on `base`: a cone, a ball on a stem, tiers, or a hedge block with an arch. +function topiary(c, x, base, kind, s) { + c.fillStyle = "#0d2417"; + if (kind === 0) poly(c, [[x - 1.6 * s, base], [x, base - 7 * s], [x + 1.6 * s, base]]), c.fill(); + else if (kind === 1) { + c.fillRect(x - 0.3 * s, base - 4 * s, 0.6 * s, 4 * s); + disc(c, x, base - 5.2 * s, 1.8 * s); + } else if (kind === 2) { + for (let t = 0; t < 3; t++) { + c.beginPath(); + c.ellipse(x, base - (1.3 + t * 2.1) * s, (2.2 - t * 0.55) * s, 1.15 * s, 0, 0, TAU); + c.fill(); + } + } else { + c.fillRect(x - 4 * s, base - 4 * s, 8 * s, 4 * s); + c.fillStyle = "#06100b"; + c.beginPath(); + c.arc(x, base, 1.5 * s, Math.PI, 0); + c.fill(); + } +} + +// The mid tile: a row of clipped hedges and topiary behind iron railings with spiked tops, and a statue or two. +function paintMid(c) { + const base = LANE_Y() + 0.6; + wrap(WM, (o) => { + c.fillStyle = "#0a1c12"; + c.fillRect(o - 1, base - 3.4, WM + 2, 3.4); + for (let k = 0; k < 9; k++) topiary(c, o + 6 + k * 13 + rnd(k, 8) * 3, base - 2.4, k % 4, 0.9 + rnd(k, 9) * 0.4); + // Statue pedestals. + for (const sx of [22, 88]) { + c.fillStyle = "#1c2b2a"; + c.fillRect(o + sx - 1.2, base - 4.2, 2.4, 2.4); + c.fillStyle = "#2a3d3b"; + disc(c, o + sx, base - 6, 0.9); + c.fillRect(o + sx - 0.7, base - 5.5, 1.4, 1.5); + } + // Railings. + c.strokeStyle = "#101a1a"; + c.lineWidth = 0.18; + seg(c, o - 1, base - 2.8, o + WM + 1, base - 2.8); + seg(c, o - 1, base - 0.8, o + WM + 1, base - 0.8); + for (let x = 0; x < WM + 1; x += 2.2) { + seg(c, o + x, base, o + x, base - 3.3); + poly(c, [[o + x - 0.3, base - 3.3], [o + x, base - 4.1], [o + x + 0.3, base - 3.3]]); + c.fillStyle = "#101a1a"; + c.fill(); + } + }); +} + +// The sky: a gradient, a moon with its glow and a scatter of stars. +function sky(ctx, cam, clock) { + const h = LANE_Y(); + ctx.fillStyle = vgrad(ctx, 0, h, [[0, "#04080f"], [0.6, "#0f1f26"], [1, "#2a4640"]]); + ctx.fillRect(cam - 1, 0, FW + 2, h + 1); + for (let k = 0; k < 46; k++) { + const sx = (((rnd(k, 1) * 220 - cam * 0.04) % 220) + 220) % 220 - 10; + const twinkle = 0.45 + 0.4 * Math.sin(clock / (500 + rnd(k, 3) * 700) + k); + ctx.fillStyle = `rgba(235,245,255,${twinkle * (0.5 + rnd(k, 4) * 0.5)})`; + ctx.fillRect(cam + sx, rnd(k, 2) * h * 0.7, 0.2, 0.2); + } + const mx = cam + 70 - cam * 0.03; + halo(ctx, "white", mx, 10, 13, 0.35); + ctx.fillStyle = "#f2f2dc"; + disc(ctx, mx, 10, 3.2); + ctx.fillStyle = "rgba(160,160,140,0.35)"; + disc(ctx, mx - 0.9, 9.4, 0.7); + disc(ctx, mx + 1.1, 11.2, 0.5); +} + +/* ------------------------------------------------------------ the lawn */ + +// The lawn from xa to xb: soil under grass, with mow stripes. +function lawn(c, xa, xb) { + const y = LANE_Y(); + c.fillStyle = vgrad(c, y, FH, [[0, "#5a9a3c"], [0.1, "#3b6e2a"], [0.2, "#3a2b18"], [1, "#120c06"]]); + c.fillRect(xa, y, xb - xa, FH - y + 1); + const s0 = Math.floor(xa / 6) * 6; + for (let x = s0; x < xb; x += 12) { + c.fillStyle = "rgba(255,255,255,0.06)"; + c.fillRect(Math.max(x, xa), y, Math.min(x + 6, xb) - Math.max(x, xa), 2.4); + } + c.fillStyle = "#79b84e"; + c.fillRect(xa, y, xb - xa, 0.3); + // Stones and roots in the soil. + for (let x = Math.ceil(xa / 5) * 5; x < xb; x += 5) { + const r = rnd(x, 41); + if (r < 0.5) continue; + c.fillStyle = r < 0.8 ? "#2a1e10" : "#4a3a28"; + disc(c, x + rnd(x, 42) * 3, y + 3.5 + rnd(x, 43) * 6, 0.25 + rnd(x, 44) * 0.3); + } +} + +// A pond in the gap [a, b]: dark water with the moon's glints, reeds and lily pads at its edges. +function pond(c, a, b) { + const y = LANE_Y(); + c.fillStyle = vgrad(c, y, FH, [[0, "#1c4a5a"], [0.4, "#0c2a38"], [1, "#04101a"]]); + c.fillRect(a, y + 0.6, b - a, FH - y); + c.strokeStyle = "rgba(220,235,240,0.35)"; + c.lineWidth = 0.1; + for (let k = 0; k < 4; k++) seg(c, a + 1 + rnd(a, k) * (b - a - 3), y + 1 + k * 0.9, a + 2.2 + rnd(a, k) * (b - a - 3), y + 1 + k * 0.9); + c.fillStyle = "#2f6a3a"; + for (let x = a + 1.5; x < b - 1; x += 2.6) { + c.beginPath(); + c.ellipse(x + rnd(a, x) * 0.8, y + 0.6, 0.9, 0.22, 0, 0, TAU); + c.fill(); + } + c.strokeStyle = "#1c3a24"; + c.lineWidth = 0.18; + seg(c, a + 0.3, y, a + 0.1, y - 2); + seg(c, a + 0.9, y, a + 1.2, y - 2.4); + seg(c, b - 0.4, y, b - 0.2, y - 2.1); +} + +// A ha-ha ditch in the gap [a, b]: a dark trench with a brick wall on each face. +function ditch(c, a, b) { + const y = LANE_Y(); + c.fillStyle = "#06080a"; + c.fillRect(a, y, b - a, FH - y); + c.fillStyle = "#3a2a22"; + c.fillRect(a, y, 0.7, FH - y); + c.fillRect(b - 0.7, y, 0.7, FH - y); + c.strokeStyle = "#1e1612"; + c.lineWidth = 0.08; + for (let r = 0; r < 8; r++) { + seg(c, a, y + 1 + r * 1.3, a + 0.7, y + 1 + r * 1.3); + seg(c, b - 0.7, y + 1 + r * 1.3, b, y + 1 + r * 1.3); + } + c.fillStyle = "rgba(140,160,120,0.5)"; + for (let k = 0; k < 6; k++) disc(c, a + 1 + rnd(a, k + 7) * (b - a - 2), y + 3 + rnd(a, k + 9) * 8, 0.18); +} + +// A chunk of the lawn: the lines, with the ponds and ditches under the gaps between them. +function paintLane(c, R, xa, xb) { + const lines = R.track.map((pts) => [pts[0][0], pts[pts.length - 1][0]]); + lines.forEach(([x0, x1], i) => { + if (i + 1 >= lines.length) return; + const a = x1; + const b = lines[i + 1][0]; + if (b < xa || a > xb) return; + if (R.gaps[i]) ditch(c, a, b); + else pond(c, a, b); + }); + for (const [x0, x1] of lines) if (x1 > xa && x0 < xb) lawn(c, Math.max(x0, xa), Math.min(x1, xb)); +} + +/* ------------------------------------------------------------ telegraphs */ + +// What to do about what is coming, shown as a glyph that fades in ahead of it: DUCK for a hedge arch +// or a line of gloves (an arrow down, amber), JUMP for a pond, a ditch or junk (an arrow up, cyan), CUT for +// a thorn hedge (chevrons to the right, green: hold fire; a jump works too). Beasts, weeds and grass +// get none. Everything comes from the room's `ride` fields and where the mower is. +export const TELEGRAPH_SEE = 40; +export const TELEGRAPH_FULL = 30; +export const TELEGRAPH_WORDS = 3; +export const TELEGRAPH_ALPHA = 0.72; +export const ANSWERS = freeze({ pond: "JUMP", ditch: "JUMP", junk: "JUMP", arch: "DUCK", line: "DUCK", hedge: "CUT" }); +export const ANSWER_COLORS = freeze({ JUMP: "#5fe3ff", DUCK: "#ffb02e", CUT: "#8cff6a" }); + +const marks = new WeakMap(); +// Every obstacle that wants a glyph: { kind, lead (where it begins), x (its middle), up (height of +// the glyph's anchor), n (which of its kind), answer }, in the room's order. +export function telegraphMarks(R) { + if (marks.has(R)) return marks.get(R); + const out = []; + const count = {}; + const add = (kind, lead, x, up) => { + const n = count[kind] || 0; + count[kind] = n + 1; + out.push({ kind, lead, x, up, n, answer: ANSWERS[kind] }); + }; + for (let i = 0; i + 1 < R.track.length; i++) { + const a = R.track[i].at(-1)[0]; + const b = R.track[i + 1][0][0]; + add(R.gaps[i] ? "ditch" : "pond", a, (a + b) / 2, LANE + 6.5); + } + for (const [x] of R.junk) add("junk", x, x, LANE + 7); + for (const x of R.hedges) add("hedge", x, x, LANE + 7); + for (const [x0, x1, y, kind] of R.lows) add(kind ? "line" : "arch", kind ? x0 - 5 : x0 - 4, (x0 + x1) / 2, y + 6.8); + out.sort((p, q) => p.lead - q.lead); + marks.set(R, out); + return out; +} + +// The glyphs showing with the mower at `x`: { ...mark, alpha (0..1, before the pulse), words }. +export function telegraphs(R, x) { + const out = []; + for (const m of telegraphMarks(R)) { + const d = m.lead - x; + if (d > TELEGRAPH_SEE || d < -6) continue; + const alpha = Math.min(clamp((TELEGRAPH_SEE - d) / (TELEGRAPH_SEE - TELEGRAPH_FULL), 0, 1), clamp((d + 4) / 6, 0, 1)); + if (alpha > 0.01) out.push({ ...m, alpha, words: m.n < TELEGRAPH_WORDS }); + } + return out; +} + +/* --------------------------------------------------------------------- art */ + +export function mowerArt(d) { + const { ellipse, say, label, GOLD, EYE_PALE } = d; + const ride = (v) => (v.spec && v.spec.ride && v.spec.ride.runner === "mower" ? v.spec.ride : null); + const state = (v) => (v.round && v.round.runner && v.round.runner.id === "mower" ? v.round.runner : null); + const worldY = (y) => FH - y; + + /* ------------------------------------------------------------- the room */ + + // The still layers only get the sky's color: the world is drawn by `moving`. + function backdrop(ctx, v, look, x0, x1) { + ctx.fillStyle = look.wallLow; + ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H); + } + // The lawn at the start and at the end (drawn again by `moving`, over the sky). + function ground(ctx, v, look, a, b, top) { + FH = v.g.FIELD_H; + lawn(ctx, a, b); + } + function shelf() {} + + /* ------------------------------------------------------------ the things */ + + // Tall grass: tufts of long blades, swaying. A cut cell is a short stubble with a pale cut mark. + function grassCells(ctx, v, g, row, gi) { + const y = worldY(LANE); + const clock = v.clock; + for (let j = 0; j < row.length; j++) { + const x = g[0] + j; + if (x < v.round.camX - 2 || x > v.round.camX + FW + 2) continue; + if (row[j]) { + ctx.strokeStyle = "#8ccb5a"; + ctx.lineWidth = 0.16; + seg(ctx, x + 0.2, y, x + 0.25, y - 0.45); + seg(ctx, x + 0.7, y, x + 0.65, y - 0.4); + continue; + } + const sway = Math.sin(clock / 420 + x * 0.6) * 0.3; + for (let b = 0; b < 3; b++) { + const hgt = 2.3 + rnd(gi * 41 + j, b) * 1.6; + const bx = x + 0.15 + b * 0.32 + rnd(j, b + 5) * 0.1; + ctx.strokeStyle = b === 1 ? "#6aab3c" : "#3f7a2a"; + ctx.lineWidth = 0.22; + ctx.beginPath(); + ctx.moveTo(bx, y + 0.1); + ctx.quadraticCurveTo(bx + sway * 0.4, y - hgt * 0.6, bx + sway + (b - 1) * 0.25, y - hgt); + ctx.stroke(); + } + } + } + + // A weed patch: a spiky clump with one sickly flower; cut it is a few short stubs. + function weed(ctx, v, x, cut, i) { + const y = worldY(LANE); + if (cut) { + ctx.strokeStyle = "#6a8a3a"; + ctx.lineWidth = 0.15; + seg(ctx, x - 0.5, y, x - 0.5, y - 0.4); + seg(ctx, x + 0.3, y, x + 0.3, y - 0.35); + return; + } + const sway = Math.sin(v.clock / 300 + i) * 0.25; + ctx.strokeStyle = "#5a7a2a"; + ctx.lineWidth = 0.2; + for (let b = -3; b <= 3; b++) seg(ctx, x + b * 0.25, y, x + b * 0.5 + sway, y - 1.6 - (3 - Math.abs(b)) * 0.3); + ctx.strokeStyle = "#4a6a22"; + seg(ctx, x, y, x + sway, y - 3.1); + ctx.fillStyle = i % 2 ? "#d27ae0" : "#f0d65a"; + disc(ctx, x + sway, y - 3.3, 0.55); + ctx.fillStyle = "#3a2a10"; + disc(ctx, x + sway, y - 3.3, 0.2); + } + + // A thorn hedge: a clipped dark block, thorns bristling out of it and a few red berries; cut, a heap of shards. + function hedge(ctx, v, x, cut, i) { + const y = worldY(LANE); + if (cut) { + ctx.fillStyle = "#1e4a22"; + for (let k = 0; k < 6; k++) ctx.fillRect(x - 1.7 + k * 0.6, y - 0.5 - rnd(i, k) * 0.5, 0.5, 0.6); + return; + } + const w = 3.4; + const h = 3.8; + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ellipse(ctx, x + 0.3, y + 0.05, w * 0.6, 0.3); + ctx.fill(); + ctx.fillStyle = "#1c4a24"; + ctx.beginPath(); + ctx.moveTo(x - w / 2, y); + ctx.lineTo(x - w / 2, y - h * 0.8); + ctx.quadraticCurveTo(x, y - h * 1.1, x + w / 2, y - h * 0.8); + ctx.lineTo(x + w / 2, y); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = "#2c6a30"; + ctx.fillRect(x - w / 2 + 0.2, y - h * 0.7, w - 0.4, 0.35); + ctx.strokeStyle = "#7a5a3a"; + ctx.lineWidth = 0.14; + for (let k = 0; k < 9; k++) { + const tx = x - w / 2 + 0.2 + (k / 8) * (w - 0.4); + const ty = y - 0.4 - rnd(i, k + 20) * (h * 0.85); + seg(ctx, tx, ty, tx + (k % 2 ? 0.55 : -0.55), ty - 0.5); + } + ctx.fillStyle = "#d02828"; + for (let k = 0; k < 4; k++) disc(ctx, x - 1.2 + k * 0.8, y - 1 - rnd(i, k + 30) * 2.2, 0.2); + } + + // Garden junk: a gnome with a pointy red hat and glowing eyes, a rusty wheelbarrow, a cracked flowerpot. + function junk(ctx, v, x, kind, i) { + const y = worldY(LANE); + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ellipse(ctx, x + 0.3, y + 0.05, kind === 1 ? 3 : 1.5, 0.3); + ctx.fill(); + if (kind === 0) { + ctx.fillStyle = "#4a6a8a"; + ctx.fillRect(x - 0.9, y - 1.9, 1.8, 1.9); + ctx.fillStyle = "#e8d8b8"; + disc(ctx, x, y - 2.6, 0.9); + ctx.fillStyle = "#dcdcd0"; + poly(ctx, [[x - 0.8, y - 2.4], [x + 0.8, y - 2.4], [x, y - 1.4]]); + ctx.fill(); + ctx.fillStyle = "#c42a2a"; + poly(ctx, [[x - 1.1, y - 3.0], [x + 1.1, y - 3.0], [x + 0.2, y - 4.4]]); + ctx.fill(); + v.eyes.push(x - 0.35, y - 2.7, 0.24, EYE_PALE); + v.eyes.push(x + 0.35, y - 2.7, 0.24, EYE_PALE); + ctx.fillStyle = "#c8ff90"; + disc(ctx, x - 0.35, y - 2.7, 0.14); + disc(ctx, x + 0.35, y - 2.7, 0.14); + } else if (kind === 1) { + ctx.fillStyle = "#7a3a1c"; + poly(ctx, [[x - 2.4, y - 2.4], [x + 1.6, y - 2.4], [x + 0.9, y - 1.0], [x - 1.4, y - 1.0]]); + ctx.fill(); + ctx.fillStyle = "#4a2410"; + ctx.fillRect(x - 2.2, y - 2.6, 3.6, 0.3); + ctx.strokeStyle = "#5a5048"; + ctx.lineWidth = 0.22; + seg(ctx, x + 1.2, y - 1.8, x + 2.6, y - 2.9); + seg(ctx, x - 2.2, y - 2.4, x - 2.6, y - 3.2); + ctx.fillStyle = "#2a2a2a"; + disc(ctx, x + 0.9, y - 0.7, 0.7); + ctx.fillStyle = "#6a6258"; + disc(ctx, x + 0.9, y - 0.7, 0.2); + ctx.fillStyle = "#d8d0b8"; + for (let k = 0; k < 3; k++) ellipse(ctx, x - 1.2 + k * 0.9, y - 2.8, 0.5, 0.3), ctx.fill(); + } else { + ctx.fillStyle = "#a8502c"; + poly(ctx, [[x - 1.1, y - 3.0], [x + 1.1, y - 3.0], [x + 0.7, y], [x - 0.7, y]]); + ctx.fill(); + ctx.fillStyle = "#c06a3c"; + ctx.fillRect(x - 1.3, y - 3.4, 2.6, 0.7); + ctx.strokeStyle = "#3a2410"; + ctx.lineWidth = 0.1; + seg(ctx, x - 0.2, y - 3.0, x + 0.1, y - 1.2); + ctx.strokeStyle = "#3a4a2a"; + ctx.lineWidth = 0.18; + seg(ctx, x, y - 3.4, x - 0.5, y - 4.9); + seg(ctx, x + 0.2, y - 3.4, x + 0.9, y - 4.6); + ctx.fillStyle = "#8a2a4a"; + disc(ctx, x - 0.5, y - 5.0, 0.35); + } + } + + // A snapping topiary beast: a clipped hound of green hedge. Asleep it sits beside the lane; it shivers, + // then lunges into it with its jaws opening and shutting; shot, it is a stump of leaves. + function beast(ctx, v, x, b, i) { + const y = worldY(LANE); + const clock = v.clock; + if (b.state === "broken") { + ctx.fillStyle = "#1c4a24"; + ellipse(ctx, x, y - 0.3, 1.6, 0.5); + ctx.fill(); + ctx.fillStyle = "#3a6a2a"; + for (let k = 0; k < 5; k++) ctx.fillRect(x - 1.5 + k * 0.7, y - 0.9 - rnd(i, k) * 0.4, 0.4, 0.5); + return; + } + const lunge = b.state === "snap" ? clamp((1400 - b.t) / 160, 0, 1) : b.state === "sink" ? clamp(b.t / 300, 0, 1) : 0; + const shake = b.state === "warn" ? Math.sin(clock / 26) * 0.2 : 0; + const s = 0.85 + lunge * 0.15; + const bx = x + shake - lunge * 0.4; + ctx.save(); + ctx.translate(bx, y); + ctx.scale(s, s); + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ellipse(ctx, 0.3, 0.05, 2.6, 0.35); + ctx.fill(); + // The body, a clipped hound: haunch, back, shoulders, legs. + ctx.fillStyle = "#1c4a24"; + ctx.beginPath(); + ctx.moveTo(-2.4, 0); + ctx.lineTo(-2.5, -2.0); + ctx.quadraticCurveTo(-2.2, -3.4, -0.8, -3.4); + ctx.lineTo(0.9, -3.5); + ctx.quadraticCurveTo(1.8, -3.5, 2.0, -2.6); + ctx.lineTo(2.1, 0); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = "#2c6a30"; + ctx.fillRect(-2.1, -3.2, 3.7, 0.4); + // The head with its jaws: they open wide while it snaps. + const gape = b.state === "snap" ? 0.5 + 0.5 * Math.abs(Math.sin(clock / 90)) : b.state === "warn" ? 0.1 : 0.05; + ctx.save(); + ctx.translate(1.6, -3.0); + ctx.fillStyle = "#1c4a24"; + poly(ctx, [[0, 0], [1.9, -0.2 - gape], [1.9, -0.9 - gape], [0, -1.5]]); + ctx.fill(); + poly(ctx, [[0, 0], [1.9, 0.2 + gape], [1.9, 0.9 + gape * 0.4], [0, 1.0]]); + ctx.fill(); + ctx.fillStyle = "#f0ece0"; + for (let k = 0; k < 3; k++) { + poly(ctx, [[0.5 + k * 0.5, -0.4 - gape * 0.4], [0.7 + k * 0.5, -0.1], [0.9 + k * 0.5, -0.4 - gape * 0.4]]); + ctx.fill(); + } + ctx.fillStyle = "#0a1a0c"; + ellipse(ctx, 0.1, -0.7, 0.5, 0.45); + ctx.fill(); + // Ears of trimmed leaves. + ctx.fillStyle = "#2c6a30"; + poly(ctx, [[-0.3, -1.3], [-0.1, -2.5], [0.6, -1.4]]); + ctx.fill(); + ctx.restore(); + ctx.restore(); + const awake = b.state !== "idle" && b.state !== "spent"; + if (awake) { + const ex = bx + 1.9 * s; + const ey = y - 3.7 * s; + v.eyes.push(ex, ey, 0.34, "#ff4a2a"); + ctx.fillStyle = "#ff6a3a"; + disc(ctx, ex, ey, 0.22); + } + } + + // A checkpoint: a post with a lantern, red until passed, then green. + function checkpoint(ctx, v, x, on, i) { + const base = worldY(LANE); + ctx.strokeStyle = "#2a2018"; + ctx.lineWidth = 0.35; + seg(ctx, x, base + 0.2, x, base - 5.4); + seg(ctx, x, base - 5.2, x + 1.1, base - 5.2); + const pulse = on ? 1 : 0.7 + 0.3 * Math.sin(v.clock / 160 + i); + halo(ctx, on ? "green" : "red", x + 1.1, base - 4.5, on ? 4.2 : 3.6, 0.7 * pulse); + ctx.fillStyle = "#1c1a22"; + ctx.fillRect(x + 0.6, base - 5.3, 1, 1.7); + ctx.fillStyle = on ? "#7dffa0" : "#ff5a40"; + ctx.fillRect(x + 0.75, base - 5.1, 0.7, 1.3); + } + + // The finish: a garden arch with a string of lanterns and a checkered pennant. + function finishGate(ctx, x) { + const base = worldY(LANE); + ctx.fillStyle = "#1c4a24"; + ctx.fillRect(x, base - 9, 2, 9); + ctx.fillRect(x + 12, base - 9, 2, 9); + ctx.beginPath(); + ctx.arc(x + 7, base - 9, 7, Math.PI, 0); + ctx.lineWidth = 2; + ctx.strokeStyle = "#1c4a24"; + ctx.stroke(); + for (let k = 0; k < 5; k++) { + const a = Math.PI + ((k + 0.5) / 5) * Math.PI; + const lx = x + 7 + Math.cos(a) * 7; + const ly = base - 9 + Math.sin(a) * 7 + 0.8; + halo(ctx, "warm", lx, ly, 2.6, 0.55); + ctx.fillStyle = k % 2 ? "#ffcf6a" : "#ff8a4a"; + ctx.fillRect(lx - 0.35, ly - 0.2, 0.7, 1); + } + for (let r = 0; r < 3; r++) for (let c = 0; c < 6; c++) { + ctx.fillStyle = (r + c) % 2 ? "#14141a" : "#f4f4f8"; + ctx.fillRect(x + 4 + c * 0.9, base - 19 + r * 0.9, 0.9, 0.9); + } + } + + /* ---------------------------------------------------------- the world */ + + function moving(ctx, v, cam) { + const R = ride(v); + const c = state(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + const clock = v.clock; + cam = Math.round(cam * 8) / 8; + sky(ctx, cam, clock); + tile(ctx, "mower:far", WF, 0.12, cam, paintFar); + tile(ctx, "mower:mid", WM, 0.34, cam, paintMid); + const k0 = Math.max(0, Math.floor(cam / CH)); + const k1 = Math.floor((cam + FW) / CH); + for (let k = k0; k <= k1; k++) { + const layer = layerFor(ctx, `mower:lane:${k}`, CH + SEAM, FH, (g) => { + g.translate(-k * CH, 0); + paintLane(g, R, k * CH - 6, k * CH + CH + SEAM + 6); + }); + if (layer) ctx.drawImage(layer, k * CH, 0, CH + SEAM, FH); + else if (k === k0) paintLane(ctx, R, cam - 6, cam + FW + 6); + } + for (const [a, b, top] of v.spec.ground) if (a >= R.finish - 1 && b > cam - 8 && a < cam + FW + 8) ground(ctx, v, LOOKS.mower, a, b, top); + const lo = cam - 8; + const hi = cam + FW + 8; + // Ripples on the ponds. + R.track.forEach((pts, i) => { + if (i + 1 >= R.track.length || R.gaps[i]) return; + const a = pts.at(-1)[0]; + const b = R.track[i + 1][0][0]; + if (b < lo || a > hi) return; + ctx.strokeStyle = "rgba(210,235,245,0.4)"; + ctx.lineWidth = 0.08; + for (let k = 0; k < 3; k++) { + const p = ((clock / 1800 + k / 3 + a * 0.01) % 1); + ctx.beginPath(); + ctx.ellipse(a + (b - a) * (0.25 + 0.25 * k), worldY(LANE) + 0.9, 0.4 + p * 1.6, 0.12 + p * 0.25, 0, 0, TAU); + ctx.stroke(); + } + }); + R.checks.forEach((x, i) => { + if (x > lo && x < hi) checkpoint(ctx, v, x, i <= c.check, i); + }); + if (R.finish > lo - 14 && R.finish < hi) finishGate(ctx, R.finish + 12); + R.grass.forEach((g, i) => { + if (g[1] > lo && g[0] < hi) grassCells(ctx, v, g, c.grass[i], i); + }); + R.weeds.forEach((x, i) => { + if (x > lo && x < hi) weed(ctx, v, x, c.weeds[i], i); + }); + R.hedges.forEach((x, i) => { + if (x > lo && x < hi) hedge(ctx, v, x, c.hedges[i], i); + }); + R.junk.forEach(([x, kind], i) => { + if (x > lo && x < hi) junk(ctx, v, x, kind, i); + }); + R.beasts.forEach((x, i) => { + if (x > lo && x < hi) beast(ctx, v, x, c.beasts[i], i); + }); + // A finished ride: the mower rests where it stopped, behind Planny as he walks out. + if (c.done) mower(ctx, v, R, c); + // Fireflies drifting over the lawn. + for (let k = 0; k < 14; k++) { + const fx = cam + ((rnd(k, 60) * 120 + clock / 90 * (0.4 + rnd(k, 61))) % 110); + const fy = FH - LANE - 3 - rnd(k, 62) * 12 + Math.sin(clock / 700 + k) * 1.2; + ctx.fillStyle = `rgba(200,255,140,${0.25 + 0.35 * Math.sin(clock / 330 + k * 2) ** 2})`; + disc(ctx, fx, fy, 0.14); + } + } + + /* ------------------------------------------------------ the mower, in front */ + + // Draws the ride-on mower with Planny on it (he is drawn by the game under it): a rusty deck, a seat, + // a wheel with a cracked headlight, a smoking exhaust, and the blades out front. + function mower(ctx, v, R, c) { + const { round } = v; + const you = round.you; + const clock = v.clock; + const fx = v.fx; + const done = c.done; + const x = done && c.restX !== undefined ? c.restX : you.x; + const y = done ? LANE : you.y; + const pitch = done || c.line >= 0 ? 0 : clamp(you.vy / 40, -1, 1) * 0.3; + const bump = !done && c.line >= 0 ? Math.sin(clock / 37) * 0.05 * (c.blade ? 2 : 1) : 0; + ctx.save(); + ctx.translate(x, FH - y + bump); + ctx.rotate(-pitch); + // The blade zone ahead: a faint cone while the blades are down, with a whirl of cut grass. + if (c.blade && !done) { + ctx.fillStyle = "rgba(180,255,120,0.12)"; + poly(ctx, [[2.6, -0.2], [BLADE_REACH, -1.6], [BLADE_REACH, 0.2]]); + ctx.fill(); + ctx.strokeStyle = "rgba(210,255,170,0.55)"; + ctx.lineWidth = 0.12; + for (let k = 0; k < 6; k++) { + const p = ((clock / 160 + k * 0.17) % 1); + seg(ctx, 3 + p * (BLADE_REACH - 3), -0.4 - p * 0.9 * (k % 3), 3.6 + p * (BLADE_REACH - 3), -0.6 - p * 0.9 * (k % 3)); + } + } + // The wheels turn with the lawn. + const turn = (done ? 0 : x * 0.5) % TAU; + const wheel = (wx, wy, r) => { + ctx.fillStyle = "#16120e"; + disc(ctx, wx, wy, r); + ctx.fillStyle = "#6a5a4a"; + disc(ctx, wx, wy, r * 0.5); + ctx.strokeStyle = "#2a2018"; + ctx.lineWidth = 0.12; + for (let k = 0; k < 4; k++) { + const a = turn + (k * TAU) / 4; + seg(ctx, wx, wy, wx + Math.cos(a) * r * 0.95, wy + Math.sin(a) * r * 0.95); + } + }; + // Exhaust smoke from a pipe at the back. + if (!done) { + for (let k = 0; k < 6; k++) { + const p = ((clock / 700 + k / 6) % 1); + ctx.fillStyle = `rgba(150,150,140,${(1 - p) * 0.45})`; + disc(ctx, -2.8 - p * 3 - c.v * 0.04, -3.4 - p * 3, 0.25 + p * 0.6); + } + } + wheel(-2.1, -1.2, 1.25); + wheel(2.6, -0.7, 0.75); + // The body: a rusty deck, an engine hood, a seat, a steering column, a headlight. + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ellipse(ctx, 0.2, 0.05, 4, 0.3); + ctx.fill(); + ctx.fillStyle = vgrad(ctx, -3, 0, [[0, "#b8501c"], [0.6, "#7a3414"], [1, "#4a2008"]]); + poly(ctx, [[-3.7, -1.2], [-3.7, -2.7], [-1.2, -2.9], [0.2, -2.5], [3.1, -2.1], [3.6, -1.1], [3.2, -0.5], [-3.2, -0.5]]); + ctx.fill(); + ctx.strokeStyle = "#2a1004"; + ctx.lineWidth = 0.1; + ctx.stroke(); + ctx.fillStyle = "#3a1a08"; + for (const [sx, sy] of [[-2.8, -1.5], [-0.4, -1.2], [1.6, -1.6]]) disc(ctx, sx, sy, 0.2); + ctx.fillStyle = "#1c1a1a"; + ctx.fillRect(-3.4, -3.2, 2.2, 0.55); + ctx.fillStyle = "#e8d89a"; + disc(ctx, 3.4, -1.4, 0.4); + halo(ctx, "warm", 3.6, -1.4, 3.4, 0.5); + // The steering wheel. + ctx.strokeStyle = "#2a2018"; + ctx.lineWidth = 0.2; + seg(ctx, 1.4, -2.3, 1.9, -4.2); + seg(ctx, 1.4, -4.4, 2.5, -4.0); + // The blade deck out front and its spinning blades (a blur when down, a dull bar when up). + ctx.fillStyle = "#4a4640"; + ctx.fillRect(3, -0.9, 1.9, 0.7); + if (c.blade && !done) { + ctx.strokeStyle = "#e8f0f8"; + ctx.lineWidth = 0.2; + for (let k = 0; k < 2; k++) { + const a = (clock / 30 + k * Math.PI) % TAU; + seg(ctx, 4 + Math.cos(a) * 1.3, -0.3 + Math.sin(a) * 0.3, 4 - Math.cos(a) * 1.3, -0.3 - Math.sin(a) * 0.3); + } + ctx.fillStyle = "rgba(220,240,255,0.3)"; + ellipse(ctx, 4, -0.3, 1.5, 0.4); + ctx.fill(); + } else if (c.jam > 0) { + ctx.fillStyle = "#a02a1a"; + ctx.fillRect(3.3, -0.7, 1.4, 0.3); + for (let k = 0; k < 5; k++) { + const p = ((clock / 500 + k / 5) % 1); + ctx.fillStyle = `rgba(210,210,210,${(1 - p) * 0.6})`; + disc(ctx, 3.8 + Math.sin(k * 3 + clock / 200) * 0.6, -1.2 - p * 3.4, 0.3 + p * 0.7); + } + } else { + ctx.fillStyle = "#8a8a84"; + ctx.fillRect(3.3, -0.7, 1.4, 0.2); + } + // A landing's puff of dust. + const land = fx && fx.mowerLand !== undefined ? fx.clock - fx.mowerLand.t0 : 1e9; + if (land < 360) { + for (let k = 0; k < 7; k++) { + const p = land / 360; + ctx.fillStyle = `rgba(190,210,160,${(1 - p) * 0.7})`; + disc(ctx, (k - 3) * 0.9 * (0.5 + p * 1.3), -0.2 - p * (0.8 + rnd(k, 4) * 1.3), 0.25 + p * 0.3); + } + } + ctx.restore(); + if (done) return; + // The heat gauge over the mower: green to red; flashes while jammed. + const gx = x - 2.6; + const gy = FH - y - 8.6; + ctx.fillStyle = "rgba(4,8,6,0.65)"; + ctx.fillRect(gx - 0.2, gy - 0.2, 5.4, 1.1); + const hot = c.jam > 0 ? Math.floor(clock / 120) % 2 === 0 : false; + ctx.fillStyle = c.jam > 0 ? (hot ? "#ff3a2a" : "#7a1a12") : c.heat > 0.75 ? "#ffb02e" : "#8cff6a"; + ctx.fillRect(gx, gy, 5 * clamp(c.heat, 0, 1), 0.7); + if (c.jam > 0) label(ctx, "JAMMED", x, gy - 0.8, 1.8, "#ff6a4a", "center"); + } + + /* ----------------------------------------------------------- lows, glyphs */ + + // A dark band along the lawn under a low: soft ends. + function shadow(ctx, xa, xb, kind) { + ctx.fillStyle = `rgba(4,8,6,${kind ? 0.25 : 0.4})`; + ctx.fillRect(xa, worldY(LANE) - 0.2, xb - xa, 1.6); + } + + // A hedge arch: two clipped pillars and a rounded lintel of hedge, with a rose or two; or a clothes line: + // two posts, a sagging rope, and ghostly gloves hanging from it. + function low(ctx, v, x0, x1, y, kind, i) { + const clock = v.clock; + const under = worldY(y); + const w = x1 - x0; + if (kind === 0) { + const top = under - 3.2; + const foot = worldY(LANE) + 0.2; + for (const px of [x0 - 3, x1 + 1.4]) { + ctx.fillStyle = "#1c4a24"; + ctx.fillRect(px, top, 1.8, foot - top); + ctx.fillStyle = "#2c6a30"; + ctx.fillRect(px + 0.2, top, 0.4, foot - top); + } + ctx.fillStyle = "#1c4a24"; + ctx.beginPath(); + ctx.moveTo(x0 - 3.2, under + 0.2); + ctx.lineTo(x0 - 3.2, top + 1.4); + ctx.quadraticCurveTo((x0 + x1) / 2, top - 1.6, x1 + 3.4, top + 1.4); + ctx.lineTo(x1 + 3.4, under + 0.2); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = "#2c6a30"; + for (let k = 0; k < 8; k++) disc(ctx, x0 - 2.6 + k * ((w + 5.8) / 7), top + 1.3 - Math.sin((k / 7) * Math.PI) * 1.2, 0.5); + ctx.fillStyle = "#c42a3a"; + for (let k = 0; k < 4; k++) disc(ctx, x0 - 2 + k * ((w + 4) / 3), top + 1.5 - Math.sin((k / 3) * Math.PI) * 1.0, 0.28); + ctx.strokeStyle = "#0e2a12"; + ctx.lineWidth = 0.14; + for (let k = 0; k < 6; k++) seg(ctx, x0 - 2.5 + k * ((w + 5) / 5), under - 0.1, x0 - 2.3 + k * ((w + 5) / 5), under + 0.7); + halo(ctx, "lime", (x0 + x1) / 2, under + 0.6, 4, 0.12); + return; + } + // The posts at each end and the rope sagging between them. + const px0 = x0 - 1.5; + const px1 = x1 + 1.5; + const topY = under - 4.4; + const foot = worldY(LANE) + 0.2; + ctx.strokeStyle = "#4a3a28"; + ctx.lineWidth = 0.5; + seg(ctx, px0, foot, px0, topY); + seg(ctx, px1, foot, px1, topY); + seg(ctx, px0 - 0.6, topY + 0.3, px0 + 0.6, topY + 0.3); + seg(ctx, px1 - 0.6, topY + 0.3, px1 + 0.6, topY + 0.3); + const sag = (t) => topY + 0.3 + Math.sin(t * Math.PI) * 1.4; + ctx.strokeStyle = "#d8d0b8"; + ctx.lineWidth = 0.12; + ctx.beginPath(); + for (let k = 0; k <= 12; k++) ctx.lineTo(px0 + ((px1 - px0) * k) / 12, sag(k / 12)); + ctx.stroke(); + // Gloves hanging down to just over the lawn's reach: pale hands that sway. + const n = Math.max(4, Math.round(w / 1.6)); + for (let k = 0; k < n; k++) { + const t = (k + 0.5) / n; + const gx = px0 + (px1 - px0) * t; + const gy = sag(t); + const len = under + 0.9 - gy + rnd(i * 11 + k, 3) * 0.6; + const sw = Math.sin(clock / 260 + k + i) * 0.35; + ctx.strokeStyle = "rgba(200,215,230,0.7)"; + ctx.lineWidth = 0.22; + seg(ctx, gx, gy, gx + sw * 0.4, gy + len - 1); + ctx.fillStyle = "rgba(225,235,245,0.85)"; + ellipse(ctx, gx + sw * 0.5, gy + len - 0.5, 0.55, 0.75); + ctx.fill(); + for (let f = 0; f < 4; f++) seg(ctx, gx + sw * 0.5 + (f - 1.5) * 0.22, gy + len - 0.1, gx + sw * 0.7 + (f - 1.5) * 0.3, gy + len + 0.45); + if (k % 3 === 0) halo(ctx, "cold", gx + sw * 0.5, gy + len - 0.4, 1.8, 0.25); + } + } + + // A see-through glyph over an obstacle: a pair of chevrons and (for the first few) the word. + function glyph(ctx, v, t) { + const dir = t.answer === "JUMP" ? -1 : t.answer === "DUCK" ? 1 : 0; + const col = ANSWER_COLORS[t.answer]; + const pulse = 0.85 + 0.15 * Math.sin(v.clock / 260 + t.lead); + const bob = Math.sin(v.clock / 260 + t.lead) * 0.35 * (dir || 1); + const cy = Math.min(FH - 7, FH - t.up) + bob; + const ay = cy + dir * 2.6; + ctx.save(); + ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA; + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + for (const [pass, w, c] of [[0, 1.3, "rgba(4,8,6,0.8)"], [1, 0.6, col]]) { + ctx.strokeStyle = c; + ctx.lineWidth = w; + for (let k = 0; k < 2; k++) { + ctx.beginPath(); + if (dir) { + const oy = ay + (k - 0.5) * 1.5 * dir - dir * 0.2; + if (k === 1 && pass === 1) ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA * 0.55; + ctx.moveTo(t.x - 1.7, oy - dir * 0.9); + ctx.lineTo(t.x, oy + dir * 0.9); + ctx.lineTo(t.x + 1.7, oy - dir * 0.9); + } else { + const ox = t.x + (k - 0.5) * 1.5; + if (k === 1 && pass === 1) ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA * 0.55; + ctx.moveTo(ox - 0.7, cy - 1.5); + ctx.lineTo(ox + 0.7, cy); + ctx.lineTo(ox - 0.7, cy + 1.5); + } + ctx.stroke(); + } + ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA; + } + if (t.words) label(ctx, t.answer, t.x, cy + (dir < 0 ? 1.2 : dir > 0 ? -1.2 : 2.6), 2.3, col, "center"); + ctx.restore(); + } + + // The lawn gauge along the bottom: how much of the lawn is cut, with the mark where the die is won. + function lawnGauge(ctx, v, cam, c) { + const w = 30; + const x = cam + (FW - w) / 2; + const y = FH - 3.2; + ctx.fillStyle = "rgba(4,8,6,0.7)"; + ctx.fillRect(x - 0.4, y - 0.4, w + 0.8, 2.1); + ctx.fillStyle = "#3f7a2a"; + ctx.fillRect(x, y, w * clamp(c.lawn, 0, 1), 1.3); + ctx.fillStyle = "#f0e08a"; + ctx.fillRect(x + w * 0.6 - 0.1, y - 0.4, 0.25, 2.1); + label(ctx, `LAWN ${Math.round(clamp(c.lawn, 0, 1) * 100)}%`, x + w / 2, y + 1.15, 1.7, "#ffffff", "center"); + } + + function front(ctx, v) { + const R = ride(v); + const round = v.round; + const c = state(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + const cam = Math.round(round.camX * 8) / 8; + const lo = cam - 8; + const hi = cam + FW + 8; + if (!c.done) mower(ctx, v, R, c); + R.lows.forEach(([x0, x1, y, kind], i) => { + if (x1 >= lo && x0 <= hi) { + shadow(ctx, kind ? x0 - 1.5 : x0 - 3, kind ? x1 + 1.5 : x1 + 1.4, kind); + low(ctx, v, x0, x1, y, kind, i); + } + }); + if (!c.done) for (const t of telegraphs(R, round.you.x)) glyph(ctx, v, t); + // Clippings and splinters of hedge flying, tumbling. + const bits = v.fx && v.fx.mowerBits; + if (bits) { + for (const b of bits) { + const t = (v.fx.clock - b.t0) / 1000; + if (t < 0 || t > 0.9) continue; + ctx.save(); + ctx.translate(b.x + b.vx * t, FH - (b.y + b.vy * t - 30 * t * t)); + ctx.rotate(b.rot + b.vr * t); + ctx.globalAlpha = clamp(1.6 - t * 1.6, 0, 1); + ctx.fillStyle = b.c; + ctx.fillRect(-b.w / 2, -0.12, b.w, 0.24); + ctx.restore(); + } + ctx.globalAlpha = 1; + } + if (!c.done) lawnGauge(ctx, v, cam, c); + } + + const dim = () => 0; + + /* -------------------------------------------------------------- lights */ + + function lights(v, add) { + const R = ride(v); + const round = v.round; + const c = state(v); + if (!R || !c) return; + const you = round.you; + const lo = round.camX - 10; + const hi = round.camX + FW + 10; + // The headlight's pool ahead. + add(you.x + 6, you.y + 1.5, 11, 0.6); + R.checks.forEach((x, i) => { + if (x > lo && x < hi) add(x + 1.1, LANE + 4.5, i <= c.check ? 8 : 7, i <= c.check ? 0.6 : 0.5); + }); + R.beasts.forEach((x, i) => { + if (x > lo && x < hi && (c.beasts[i].state === "warn" || c.beasts[i].state === "snap")) add(x, LANE + 3, 5, 0.3); + }); + R.lows.forEach(([x0, x1, y], i) => { + if (x1 > lo && x0 < hi) add((x0 + x1) / 2, y + 1, 6, 0.3 * (0.85 + 0.15 * Math.sin(v.clock / 200 + i))); + }); + if (R.finish > lo - 14 && R.finish < hi) add(R.finish + 19, 17, 14, 0.6); + } + + /* -------------------------------------------------------------- events */ + + // A throttle on a repeating cue. + function gateOnce(fx, key, ms) { + if ((fx[key] || 0) > fx.clock) return false; + fx[key] = fx.clock + ms; + return true; + } + // Leaves and splinters flying out of a spot. + function splinter(fx, x, y, colors) { + fx.mowerBits = (fx.mowerBits || []).filter((b) => fx.clock - b.t0 < 1000); + for (let k = 0; k < 9; k++) fx.mowerBits.push({ x, y, t0: fx.clock, vx: (rnd(k, 1) - 0.5) * 22, vy: 8 + rnd(k, 2) * 14, rot: rnd(k, 3) * TAU, vr: (rnd(k, 4) - 0.5) * 22, w: 0.5 + rnd(k, 5) * 0.9, c: colors[k % colors.length] }); + } + + // What the pack's events look and sound like; true when the event is its own. Each of its sounds plays once, from EVENT_VOICE. + function react(e, k) { + const { tone, shake, flash, burst, float, ring, fx } = k; + const voice = EVENT_VOICE[e.type]; + if (!voice) return false; + // The cuts and the ducks repeat as the mower goes; keep them from stacking. + if (e.type === "mowerDuck" && !gateOnce(fx, "mowerDuckMs", 160)) return true; + if (e.type === "mowerGrass" && !gateOnce(fx, "mowerGrassMs", 140)) { + burst(e.tx ?? e.x, e.y + 1, "#6aab3c", 3, 6, 300); + return true; + } + say(tone, voice[0], voice[1], e.type === "mowerGrass" ? 0.35 : 0.5); + switch (e.type) { + case "mowerJump": + burst(e.x, e.y, "#bcd89a", 5, 7, 300); + break; + case "mowerLand": + fx.mowerLand = { t0: fx.clock, big: Boolean(e.big) }; + burst(e.x, e.y, "#8ccb5a", e.big ? 12 : 6, e.big ? 11 : 8, 340); + if (e.big) shake(180, 0.4); + break; + case "mowerCrash": + shake(320, 1); + flash(e.what === "pond" ? "#9fd0ff" : "#ffe0a0", 200); + burst(e.x, e.y + 1, e.what === "pond" ? "#bfe6ff" : "#7a3a1c", 16, 16, 520); + break; + case "mowerCheck": + float(e.x, e.y + 5, "Checkpoint", GOLD, 2.2); + ring(e.x, e.y + 3, "#7dffa0", 1, 8, 500); + break; + case "mowerFinish": + shake(200, 0.5); + burst(e.x, e.y, "#8ccb5a", 14, 12, 520); + float(e.x, e.y + 5, "Mowed!", GOLD, 2.6); + break; + case "mowerGrass": + burst(e.tx ?? e.x, e.y + 1, "#6aab3c", 6, 9, 360); + break; + case "mowerHedge": + burst(e.x, e.y + 2, "#2c6a30", 14, 14, 480); + splinter(fx, e.x, e.y + 2, ["#2c6a30", "#1c4a24", "#7a5a3a"]); + float(e.x, e.y + 5, `+${e.points}`, GOLD, 2); + break; + case "mowerWeed": + burst(e.x, e.y + 1, "#d27ae0", 6, 8, 340); + float(e.x, e.y + 4, `+${e.points}`, GOLD, 1.8); + break; + case "mowerJam": + shake(160, 0.5); + burst(e.x + 4, e.y + 1, "#aaaaaa", 8, 6, 600); + float(e.x, e.y + 6, "Jammed!", "#ff6a4a", 2.2); + break; + case "mowerBeastWarn": + burst(e.x, e.y + 2, "#2c6a30", 5, 4, 420); + break; + case "mowerBeastSnap": + burst(e.x, e.y + 2, "#2c6a30", 7, 8, 360); + break; + case "mowerBeastHit": + burst(e.x, e.y, "#3a8a3a", 6, 9, 280); + break; + case "mowerBeastBreak": + burst(e.x, e.y, "#2c6a30", 14, 14, 480); + splinter(fx, e.x, e.y, ["#2c6a30", "#3a8a3a", "#1c4a24"]); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + default: + break; + } + return true; + } + + return freeze({ + looks: LOOKS, + backdrop, + ground, + shelf, + front, + moving, + dim, + monsters: freeze({}), + bosses: freeze({}), + missiles: freeze({}), + hazards: freeze({}), + powers: freeze({}), + lights, + react, + }); +} diff --git a/src/web-console/public/activities/ghoul-mower.js b/src/web-console/public/activities/ghoul-mower.js new file mode 100644 index 0000000..5c95aaf --- /dev/null +++ b/src/web-console/public/activities/ghoul-mower.js @@ -0,0 +1,547 @@ +// Plan2Code Web Console - Ghoul Rush's Gardener's Revenge, its rules: the Grounds' bonus round. YOU ride the gardener's rusty, haunted ride-on mower down a long straight run through the overgrown estate lawn at night: jump the gnomes, barrows, flowerpots, ponds and ha-ha ditches, duck the hedge arches and the clothes lines of ghostly gloves, shoot the snapping topiary beasts, and MOW: hold fire and the blades come down, cutting the tall grass, the weeds and the thorn hedges just ahead. As a stage pack that ghoul.js plugs in. +// +// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it, handed a +// kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js (it borrows the +// cart's track helpers). Pack fields used: `ride` (a hook that moves Planny himself, so no +// key walks him), `place` (Planny put down in a room: a room set up or a respawn) and +// `target` (a bolt strikes something that is no monster: the topiary beasts). It adds no +// monster, boss or hazard kind and it draws NO random number. Its state is the shared +// bonus-ride slot `round.runner` (id "mower"; null in any other room), the room marks its +// ride `runner: "mower"` (the cart's `place` leaves such a room alone). +// +// THE ROOM (spec.ride, see ghoul-rooms.js): +// +// - `track`: polylines [x, y] the mower rolls along, all flat at one height; a gap between +// two lines is a POND or a HA-HA DITCH (`gaps`: per gap, 0 a pond, 1 a ditch; jump it, or +// the mower drops in: a heart, cause "pond" or "ditch"). The last line ends at `finish`, +// where the lawn's end (the ground) begins at the same height: rolling onto it ends the ride. +// - `junk` [x, kind] (a garden gnome, a wheelbarrow or a flowerpot, JUNK: jump it), `lows` +// [x0, x1, y, kind] (a hedge arch, kind 0, or a clothes line of ghostly gloves, kind 1: its +// underside is y, from there up to the roof, so DUCK it; y is 3.0 over the lawn, between a +// ducked box and a standing one), `hedges` [x] (a thorn hedge across the lane, THORN_W by +// THORN_H: MOW it, or jump it), `beasts` [x] (a snapping topiary beast: it shivers +// BEAST_WARN_MS when the mower is BEAST_NEAR short of it, then lunges into the lane +// BEAST_UP_MS, BEAST_W by BEAST_H: shoot it, BEAST_HP bolts, or jump it), `grass` [x0, x1] +// (tall grass, one cell a unit, mown by the blades), `weeds` [x] (a weed patch with a +// flower, WEED_CELLS cells), `checks` (x positions of the checkpoints), `finish`, `time` +// (the room's clock, ms) and `how` (the controls line). +// +// THE MOWER (`round.runner`): { id, room, check, v, line, coyote, from, left, done, heat, +// jam, blade, bogMs, cut, cells, lawn, grass, hedges, weeds, beasts, ... }. Planny rides +// at (you.x, you.y), always facing right (`you.state` "run" on the lawn, "air" off it, +// `you.ducking` ducked). Speed `v` is MOWER_V, bogging down BOG slower for BOG_MS after a +// cut (nothing else changes it: it is a ride). Up jumps at MOWER_JUMP_V against MOWER_G +// (about 11 high, 0.7 s, 22 across at MOWER_V), COYOTE_MS of grace after running off a line's +// end; down ducks. +// +// THE BLADES: while fire is held and the blades are not jammed they are down (`blade`) and cut +// everything in the zone from the mower's front to BLADE_REACH ahead of it: every grass cell +// (GRASS_POINTS each), every weed patch (WEED_POINTS, an act) and every thorn hedge +// (HEDGE_POINTS, an act). Holding fire heats them (`heat` 0 to 1, HEAT_UP a second; they +// cool COOL a second while let go); full heat JAMS them for JAM_MS (no cutting, smoke), after +// which they restart at JAM_RESUME. So the player pulses them. The bolts fly all the time +// fire is held, as always. `lawn` is the share of the room's cells cut (grass cells plus +// WEED_CELLS a weed patch): the grade's `steady` die is lawn at least LAWN_GOAL. +// +// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the mower rolls +// on, Planny blinking safe BONUS_SAFE_MS; the last heart gone ends the round with nothing, at +// once. A fall puts him back on the lawn ahead at MOWER_V. Causes: "gnome", "barrow", "pot", +// "arch", "line", "thorns", "snap", "pond", "ditch". Every obstacle is a number for the grade +// (`perf.total`: junk, lows, hedges, beasts and gaps, each id once in `perf.hits` if it ever +// cost a heart); cutting a hedge or a weed patch, or shooting a beast, counts for `perf.acts` +// (the grade's goal is ACTS_GOAL). +// +// Checkpoints are passed at their x (`mowerCheck`); a restart after the last heart goes back to the +// last one passed (that ends the round, as the sled's does). +// +// WHAT THE ART READS: `spec.ride` (above), `round.runner` { v, line, check, done, left, heat, +// jam, blade, lawn, cut, grass: [[cut cells]], hedges: [cut], weeds: [cut], beasts: [{ state +// "idle"|"warn"|"snap"|"sink"|"spent"|"broken", t }] }, `round.you` (`state`, `vy`, `ducking`), +// the events in EVENTS. + +import { linesAt, linesOf, trackY } from "./ghoul-cart.js"; + +const freeze = (o) => Object.freeze(o); +const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v)); + +export const MONSTERS = freeze({}); + +// Every event this pack puts on the field, for the art and the sounds to answer. +export const EVENTS = freeze([ + "mowerJump", "mowerLand", "mowerDuck", "mowerCrash", "mowerCheck", "mowerFinish", + "mowerGrass", "mowerHedge", "mowerWeed", "mowerJam", + "mowerBeastWarn", "mowerBeastSnap", "mowerBeastHit", "mowerBeastBreak", +]); + +// The mower. Speeds are units across a second, MOWER_G units a second squared. +export const MOWER_V = 32; +export const BOG = 4; +export const BOG_MS = 220; +export const RELAX = 3; +export const MOWER_JUMP_V = 66; +export const MOWER_G = 190; +export const COYOTE_MS = 100; +export const LAND_TOL = 0.9; +export const BIG_LAND = 5; +export const DERAIL_DROP = 7; +export const CAM_AHEAD = 10; +// The blades. +export const BLADE_REACH = 9; +export const BLADE_NEAR = 0; +export const HEAT_UP = 0.75; +export const COOL = 0.5; +export const JAM_MS = 1800; +export const JAM_RESUME = 0.3; +export const GRASS_POINTS = 4; +export const WEED_POINTS = 40; +export const HEDGE_POINTS = 80; +export const WEED_CELLS = 3; +export const WEED_W = 2.2; +export const LAWN_GOAL = 0.6; +// Obstacles: a gnome, a wheelbarrow, a flowerpot (jump), a thorn hedge (mow or jump). +export const JUNK = freeze([ + freeze({ name: "gnome", w: 2.4, h: 4.2 }), + freeze({ name: "barrow", w: 5.2, h: 3 }), + freeze({ name: "pot", w: 2.2, h: 3.6 }), +]); +export const THORN_W = 3.4; +export const THORN_H = 3.8; +// The snapping topiary beast: wakes, lunges into the lane, and the shots at it. +export const BEAST_W = 3.4; +export const BEAST_H = 4.6; +export const BEAST_HP = 2; +export const BEAST_NEAR = 36; +export const BEAST_WARN_MS = 450; +export const BEAST_UP_MS = 1400; +export const BEAST_SINK_MS = 300; +export const BEAST_POINTS = 150; +const SHOT_R = 0.5; +// The shots and cuts (a hedge, a weed patch, a beast) worth a die. +export const ACTS_GOAL = 14; + +// Notes for a bonus round that obstacle `id` cost a heart (once each). +function noteHit(round, id) { + const b = round.bonusRound; + if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id); +} + +const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H); +const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0; + +// The highest line under x, as [line, y], or null over a gap. +const topAt = (R, x) => linesAt(R, x)[0] || null; + +// The highest line the mower, falling from `py` to `y` at `x`, crossed going down. +function landOn(R, x, py, y) { + for (const [line, ly] of linesAt(R, x)) if (py >= ly - LAND_TOL && y <= ly) return { line, y: ly }; + return null; +} + +// Where a mower in the air at (x, y) going up at vy and across at v lands, if it does not +// steer: { x, y, line } or null when it drops. The unit suite's measure of which gaps a jump clears. +export function flight(R, x, y, vy, v) { + const dt = 0.004; + const floor = y - DERAIL_DROP; + for (let t = 0; t < 5; t += dt) { + const py = y; + vy = Math.max(-120, vy - MOWER_G * dt); + x += v * dt; + y += vy * dt; + if (vy <= 0) { + const f = landOn(R, x, py, y); + if (f) return { x, y: f.y, line: f.line }; + } + if (y < floor) return null; + } + return null; +} + +// The cells of a stretch of tall grass: one a unit. +export const cellsOf = (g) => Math.max(1, Math.ceil(g[1] - g[0])); +// The room's cells in all, the lawn's whole, and how many of them are cut so far in a runner. +export const totalCells = (R) => R.grass.reduce((n, g) => n + cellsOf(g), 0) + R.weeds.length * WEED_CELLS; + +/* -------------------------------------------------------------- placing */ + +// A fresh set of the room's things, each beast asleep. What was cut or shot stays so (`old`, +// the runner of an earlier try in the same room). +function things(R, old) { + const same = Boolean(old && old.id === "mower" && old.grass.length === R.grass.length && old.hedges.length === R.hedges.length && old.weeds.length === R.weeds.length && old.beasts.length === R.beasts.length); + return { + grass: R.grass.map((g, i) => (same && old.grass[i].length === cellsOf(g) ? old.grass[i].slice() : new Array(cellsOf(g)).fill(false))), + hedges: R.hedges.map((_, i) => Boolean(same && old.hedges[i])), + weeds: R.weeds.map((_, i) => Boolean(same && old.weeds[i])), + beasts: R.beasts.map((_, i) => ({ state: same && old.beasts[i].state === "broken" ? "broken" : "idle", t: 0, hp: BEAST_HP })), + }; +} + +// How many cells are cut, from the lists. +function cutCells(c) { + return c.grass.reduce((n, g) => n + g.filter(Boolean).length, 0) + c.weeds.filter(Boolean).length * WEED_CELLS; +} + +// Planny put down in the room: on the mower at the start of a ride, or at the last +// checkpoint passed after the last heart (the same room). +function place(round, k) { + const R = round.spec.ride; + // (The Cart's `place` runs first and has already zeroed `round.camLead`: another room's lead is not ours to touch.) + if (!R || R.runner !== "mower") { + if (round.runner && round.runner.id === "mower") round.runner = null; + return; + } + const again = round.runner && round.runner.id === "mower" && round.runner.room === round.room; + const check = again ? round.runner.check : -1; + const you = round.you; + const x = check >= 0 ? R.checks[check] : round.spec.start; + const top = topAt(R, x); + Object.assign(you, { x, y: top ? top[1] : you.y, vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 }); + const t = things(R, again ? round.runner : null); + const cells = totalCells(R); + round.runner = { id: "mower", room: round.room, check, v: MOWER_V, line: top ? top[0] : -1, coyote: 0, from: you.y, left: top ? top[0] : 0, done: false, heat: 0, jam: 0, blade: false, bogMs: 0, cells, cut: 0, lawn: 0, ...t }; + round.runner.cut = cutCells(round.runner); + round.runner.lawn = cells ? round.runner.cut / cells : 0; + round.camLead = CAM_AHEAD; + const b = round.bonusRound; + if (b && !b.perf.total) { + b.perf.total = R.junk.length + R.lows.length + R.hedges.length + R.beasts.length + (R.track.length - 1); + b.perf.steady = false; + b.perf.goal = ACTS_GOAL; + } +} + +/* ------------------------------------------------------------ the ride */ + +// After a fall that cost a heart but not the ride: Planny and the mower go back onto the +// lawn nearest where they fell (the line under him, else the next one ahead) at MOWER_V. He +// blinks safe (ghoul.js's takeLife). +function reseat(round, c, R) { + const you = round.you; + const under = topAt(R, you.x); + let line; + let x; + let y; + if (under) { + [line, y] = under; + x = you.x; + } else { + const ahead = linesOf(R) + .map((L, i) => ({ i, x0: L.x0 })) + .filter((L) => L.x0 > you.x) + .sort((a, b) => a.x0 - b.x0)[0]; + line = ahead ? ahead.i : linesOf(R).length - 1; + x = ahead ? ahead.x0 + 2 : R.finish - 2; + y = trackY(R, line, x) ?? you.y; + } + Object.assign(you, { x, y, vy: 0, state: "run", shelf: -1, ducking: false, coyote: 0, drop: -1 }); + Object.assign(c, { line, v: MOWER_V, coyote: 0, from: y }); +} + +// The mower's motion for one slice. Returns true once it has moved Planny (every slice of a +// ride); false outside a ride and once he has stepped out onto the lawn's end. +function ride(round, ms, k) { + const R = round.spec.ride; + const c = round.runner; + if (!R || R.runner !== "mower" || !c || c.id !== "mower" || c.done) return false; + const you = round.you; + const inp = round.input; + const dt = ms / 1000; + const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra }); + // Already down on the lawn's end (set there, or rolled on by some other way): the ride is over. + if (you.x >= R.finish && you.vy <= 0 && you.y <= k.groundAt(round.spec, you.x) + 0.01) return finish(round, c, k); + // A stomp's bounce (or anything else) lifts the mower off its line. + if (you.state === "air" && c.line >= 0) { + c.left = c.line; + c.line = -1; + c.coyote = 0; + c.from = you.y; + } + const want = inp.jump > 0; + const target = MOWER_V - (c.bogMs > 0 ? BOG : 0); + c.bogMs = Math.max(0, c.bogMs - ms); + c.v += (target - c.v) * Math.min(1, RELAX * dt); + if (c.line >= 0) { + // On the lawn. + const duck = Boolean(inp.down) && !want; + if (duck && !you.ducking) ev("mowerDuck"); + you.ducking = duck; + if (want) { + inp.jump = 0; + you.vy = MOWER_JUMP_V; + Object.assign(c, { left: c.line, line: -1, coyote: 0, from: you.y }); + you.state = "air"; + you.ducking = false; + ev("mowerJump", { v: c.v }); + } else { + const L = linesOf(R)[c.line]; + const nx = you.x + c.v * dt; + you.state = "run"; + you.vy = 0; + if (nx >= L.x1) { + // Off the end of the line: into a gap, or onto the lawn's end. + you.x = L.x1; + you.y = L.pts[L.pts.length - 1][1]; + Object.assign(c, { left: c.line, line: -1, coyote: COYOTE_MS, from: you.y }); + you.state = "air"; + you.ducking = false; + you.vy = 0; + } else { + you.x = nx; + you.y = trackY(R, c.line, nx); + } + } + } else { + // In the air. + c.coyote = Math.max(0, c.coyote - ms); + if (want && c.coyote > 0) { + inp.jump = 0; + c.coyote = 0; + you.vy = MOWER_JUMP_V; + c.from = you.y; + ev("mowerJump", { v: c.v }); + } + const py = you.y; + you.vy = Math.max(-k.FALL_MAX, you.vy - MOWER_G * dt); + you.x += c.v * dt; + you.y += you.vy * dt; + you.ducking = false; + you.state = "air"; + if (you.vy <= 0) { + const f = landOn(R, you.x, py, you.y); + if (f) { + you.y = f.y; + you.vy = 0; + you.state = "run"; + c.line = f.line; + ev("mowerLand", { big: c.from - f.y >= BIG_LAND || c.from - f.y <= -BIG_LAND }); + c.from = f.y; + } else if (you.x >= R.finish) { + // Over the lawn's end: down onto it, and the ride is over. + const g = k.groundAt(round.spec, you.x); + if (g > -Infinity && you.y <= g + 0.01) return finish(round, c, k, g); + } + } + } + // A press nothing took waits a moment for a landing, then goes. + if (want && inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms); + // Into a gap: a pond or a ditch. + const base = R.track[0][0][1]; + if (you.y < base - DERAIL_DROP || k.groundAt(round.spec, you.x) > you.y + 0.5) { + noteHit(round, `g${c.left}`); + const kind = R.gaps[Math.min(R.gaps.length - 1, Math.max(0, c.left))]; + const hit = { type: "mowerCrash", what: kind ? "ditch" : "pond", x: you.x, y: you.y }; + if (k.lose(round, kind ? "ditch" : "pond")) { + round.events.push(hit); + if (round.phase === "play") reseat(round, c, R); + } + return true; + } + while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) { + c.check++; + ev("mowerCheck", { n: c.check + 1 }); + } + round.camLead = CAM_AHEAD + (c.v - MOWER_V) * 0.25; + mow(round, c, R, ms); + if (obstacles(round, c, R, k)) return true; + creatures(round, c, R, ms); + return true; +} + +// The ride is over: the mower coughs to a halt on the lawn's end, the door opens, Planny walks out. +function finish(round, c, k, g = k.groundAt(round.spec, round.you.x)) { + const you = round.you; + c.done = true; + c.restX = you.x; + c.blade = false; + Object.assign(you, { y: g, vy: 0, state: "run", shelf: -1, ducking: false }); + round.hasKey = true; + round.camLead = 0; + grade(round, c); + round.events.push({ type: "mowerFinish", x: you.x, y: you.y, big: false }); + return false; +} + +// The grade's steady die: the lawn cut reaches LAWN_GOAL. +function grade(round, c) { + c.lawn = c.cells ? c.cut / c.cells : 0; + const b = round.bonusRound; + if (b) b.perf.steady = c.lawn >= LAWN_GOAL; +} + +/* ------------------------------------------------------------- the blades */ + +// The blades for one slice: heat, jam, and what they cut in the zone ahead. +function mow(round, c, R, ms) { + const you = round.you; + const dt = ms / 1000; + const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra }); + if (c.jam > 0) { + c.jam = Math.max(0, c.jam - ms); + c.blade = false; + c.heat = c.jam > 0 ? JAM_RESUME + ((1 - JAM_RESUME) * c.jam) / JAM_MS : JAM_RESUME; + } else if (round.input.fire) { + c.blade = true; + c.heat = Math.min(1, c.heat + HEAT_UP * dt); + if (c.heat >= 1) { + c.blade = false; + c.jam = JAM_MS; + ev("mowerJam"); + } + } else { + c.blade = false; + c.heat = Math.max(0, c.heat - COOL * dt); + } + if (c.blade) { + const z0 = you.x + BLADE_NEAR; + const z1 = you.x + BLADE_REACH; + let cells = 0; + R.grass.forEach((g, i) => { + if (g[1] < z0 || g[0] > z1) return; + const row = c.grass[i]; + for (let j = Math.max(0, Math.floor(z0 - g[0])); j < row.length && g[0] + j < z1; j++) { + const cx = g[0] + j + 0.5; + if (!row[j] && cx >= z0 && cx <= z1) { + row[j] = true; + cells++; + } + } + }); + if (cells) { + c.cut += cells; + round.score += cells * GRASS_POINTS; + ev("mowerGrass", { n: cells, points: cells * GRASS_POINTS, tx: you.x + BLADE_REACH * 0.6 }); + } + let bog = cells > 0; + R.hedges.forEach((x, i) => { + if (c.hedges[i] || x + THORN_W / 2 < z0 || x - THORN_W / 2 > z1) return; + c.hedges[i] = true; + bog = true; + round.score += HEDGE_POINTS; + if (round.bonusRound) round.bonusRound.perf.acts++; + ev("mowerHedge", { x, y: trackY(R, c.line >= 0 ? c.line : c.left, x) ?? you.y, points: HEDGE_POINTS }); + }); + R.weeds.forEach((x, i) => { + if (c.weeds[i] || x + WEED_W / 2 < z0 || x - WEED_W / 2 > z1) return; + c.weeds[i] = true; + c.cut += WEED_CELLS; + round.score += WEED_POINTS; + if (round.bonusRound) round.bonusRound.perf.acts++; + ev("mowerWeed", { x, y: trackY(R, c.line >= 0 ? c.line : c.left, x) ?? you.y, points: WEED_POINTS }); + }); + if (bog) c.bogMs = BOG_MS; + } + grade(round, c); +} + +/* ------------------------------------------------------------ obstacles */ + +// What the mower runs into: junk, a low arch or line, an uncut thorn hedge, a beast's lunge. +// Returns whether it cost a heart. +function obstacles(round, c, R, k) { + const you = round.you; + const hh = duckH(k, you); + for (const [i, [x0, x1, y, kind]] of R.lows.entries()) { + if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > y && k.struck(round, kind ? "line" : "arch")) { + noteHit(round, `l${i}`); + round.events.push({ type: "mowerCrash", what: "low", x: you.x, y: you.y + hh }); + return true; + } + } + for (const [i, [x, kind]] of R.junk.entries()) { + if (Math.abs(you.x - x) > 6) continue; + const J = JUNK[kind]; + if (boxHit(k, you, x, trackY(R, lineAt(R, x), x) ?? you.y, J.w, J.h) && k.struck(round, J.name)) { + noteHit(round, `j${i}`); + round.events.push({ type: "mowerCrash", what: J.name, x, y: you.y }); + return true; + } + } + for (const [i, x] of R.hedges.entries()) { + if (c.hedges[i] || Math.abs(you.x - x) > 6) continue; + if (boxHit(k, you, x, trackY(R, lineAt(R, x), x) ?? you.y, THORN_W, THORN_H) && k.struck(round, "thorns")) { + noteHit(round, `h${i}`); + round.events.push({ type: "mowerCrash", what: "thorns", x, y: you.y }); + return true; + } + } + for (const [i, x] of R.beasts.entries()) { + const b = c.beasts[i]; + if (b.state !== "snap" || Math.abs(you.x - x) > 5) continue; + if (boxHit(k, you, x, trackY(R, lineAt(R, x), x) ?? you.y, BEAST_W, BEAST_H) && k.struck(round, "snap")) { + noteHit(round, `b${i}`); + round.events.push({ type: "mowerCrash", what: "snap", x, y: you.y }); + Object.assign(b, { state: "sink", t: BEAST_SINK_MS }); + return true; + } + } + return false; +} + +// The line a thing at x stands on (the one under it). +const lineAt = (R, x) => { + const top = topAt(R, x); + return top ? top[0] : 0; +}; + +// The topiary beasts wake when the mower comes near: a shiver, then a lunge, then back to a bush. +function creatures(round, c, R, ms) { + const you = round.you; + R.beasts.forEach((x, i) => { + const b = c.beasts[i]; + const y = trackY(R, lineAt(R, x), x) ?? you.y; + if (b.state === "idle") { + const ahead = x - you.x; + if (ahead < BEAST_NEAR && ahead > -BEAST_W) { + Object.assign(b, { state: "warn", t: BEAST_WARN_MS }); + round.events.push({ type: "mowerBeastWarn", x, y }); + } + } else if (b.state === "warn" || b.state === "snap" || b.state === "sink") { + b.t -= ms; + if (b.t > 0) return; + if (b.state === "warn") { + Object.assign(b, { state: "snap", t: BEAST_UP_MS }); + round.events.push({ type: "mowerBeastSnap", x, y }); + } else if (b.state === "snap") Object.assign(b, { state: "sink", t: BEAST_SINK_MS }); + else Object.assign(b, { state: "spent", t: 0 }); + } + }); +} + +/* ------------------------------------------------------------- targets */ + +// A bolt into something to shoot: a topiary beast lunging into the lane. True when one took it +// (the bolt is spent). +function mowerShot(round, s) { + const R = round.spec.ride; + const c = round.runner; + if (!R || R.runner !== "mower" || !c || c.id !== "mower") return false; + for (let i = 0; i < R.beasts.length; i++) { + const b = c.beasts[i]; + const x = R.beasts[i]; + const y = trackY(R, lineAt(R, x), x) ?? 0; + if (b.state !== "snap" || Math.abs(s.x - x) > BEAST_W / 2 + SHOT_R || s.y < y - SHOT_R || s.y > y + BEAST_H + SHOT_R) continue; + b.hp--; + if (b.hp > 0) round.events.push({ type: "mowerBeastHit", x, y: y + BEAST_H / 2 }); + else { + Object.assign(b, { state: "broken", t: 0 }); + round.score += BEAST_POINTS; + if (round.bonusRound) round.bonusRound.perf.acts++; + round.events.push({ type: "mowerBeastBreak", x, y: y + BEAST_H / 2, points: BEAST_POINTS }); + } + return true; + } + return false; +} + +export const MOWER = freeze({ + id: "mower", + monsters: MONSTERS, + walkers: freeze([]), + zombies: freeze([]), + stackers: freeze([]), + climbers: freeze([]), + act: freeze({}), + horde: freeze({}), + ride: freeze([ride]), + place: freeze([place]), + target: mowerShot, +}); diff --git a/src/web-console/public/activities/ghoul-pew-course.js b/src/web-console/public/activities/ghoul-pew-course.js new file mode 100644 index 0000000..b1d0885 --- /dev/null +++ b/src/web-console/public/activities/ghoul-pew-course.js @@ -0,0 +1,140 @@ +// Plan2Code Web Console - Ghoul Rush's Holy Roller, its course: the fixed, seeded run down the Chapel's nave, laid out by TIME and turned into distance. No imports, no random numbers. +// +// The ride speeds up with the distance it has covered (speedAt: V0 at the start, climbing by ACC every +// second), so a second of ride time is a place (xAt). The course is written in seconds, a row of up to three +// things across the three lanes at a time, and every gap between two rows is long enough for a player to +// answer the first and get to the second (the tests walk the whole course to prove a safe path exists +// at every moment). Nothing here draws a random number: the same course every time. +// +// Output (all frozen), x being distance down the aisle and `lane` 0 (left), 1 (middle) or 2 (right): +// - `items`: [x, lane, kind, len] for every thing in the way, sorted by x. `x` is the thing's near +// edge and `len` how deep it runs (0 for the kind's own depth, see KINDS in ghoul-pew.js). Kinds: +// "pillar", "confessional", "pewx" (SWITCH), "kneeler", "stand", "cracks", "hatch" (JUMP), "censer", +// "banner", "beam" (SLIDE), "garg" (SHOOT or switch) and "bell" (a rope: SHOOT, harmless). +// - `souls`: [x, lane, h, type] wax souls (type 0) and halos (type 1, a magnet) with their height. +// - `checks`: the checkpoints' x; `finish`: where the ride ends; `rows`: [x, [kinds...]] for the art/tests. + +export const PEW_START = 8; +export const V0 = 34; +export const ACC = 0.7; +export const V_MAX = 84; +export const RIDE_S = 66; + +// Where the ride is `t` seconds in, and how fast it rolls at distance `x`. +export const xAt = (t) => PEW_START + V0 * t + (ACC * t * t) / 2; +export const speedAt = (x) => Math.min(V_MAX, Math.sqrt(V0 * V0 + 2 * ACC * Math.max(0, x - PEW_START))); + +const r1 = (n) => Math.round(n * 10) / 10; +const SOUL_STEP = 0.14; + +function build() { + const items = []; + const souls = []; + const rows = []; + const it = (t, lane, kind, len = 0) => items.push([r1(xAt(t)), lane, kind, len]); + const row = (t, kinds) => { + kinds.forEach((kind, lane) => kind && it(t, lane, kind, kind === "cracks" ? 7 : 0)); + rows.push([r1(xAt(t)), kinds]); + }; + const line = (t0, t1, lane, h = 1.5) => { + for (let t = t0; t <= t1 + 1e-9; t += SOUL_STEP) souls.push([r1(xAt(t)), lane, h, 0]); + }; + // Souls rising over a jump and coming down again, centered at time t. + const arc = (t, lane, peak = 4.4, half = 0.42) => { + for (let u = -half; u <= half + 1e-9; u += SOUL_STEP) souls.push([r1(xAt(t + u + 0.1)), lane, 1.4 + peak * (1 - (u / half) ** 2), 0]); + }; + const halo = (t, lane) => souls.push([r1(xAt(t)), lane, 2.4, 1]); + const [K, X, P, C, B, I, M, S, H, G, R, CR] = ["kneeler", "pewx", "pillar", "confessional", "banner", "censer", "beam", "stand", "hatch", "garg", "bell", "cracks"]; + const _ = null; + + // Act one: each answer on its own. JUMP, SWITCH, SLIDE, SWITCH again, a row that asks for all three, SHOOT. + row(3.4, [K, K, K]); + arc(3.4, 1); + row(6, [X, X, _]); + line(5.5, 6.6, 2); + row(8.5, [B, B, B]); + line(8.1, 8.9, 0, 0.9); + line(8.1, 8.9, 2, 0.9); + row(11, [_, C, C]); + line(10.4, 11.8, 0); + row(13.4, [P, K, I]); + arc(13.4, 1); + line(13, 13.8, 2, 0.9); + row(15.8, [_, G, _]); + line(15.2, 16.2, 0); + line(15.2, 16.2, 2); + // Act two: a bell rope that clears the gargoyles after it, staggered switching, jump-then-slide. + it(18.2, 0, R); + row(20.8, [G, G, _]); + line(20.2, 21.4, 2); + halo(22.2, 2); + row(23, [X, _, X]); + line(22.6, 23.4, 1); + row(24.6, [_, X, X]); + line(24.3, 24.9, 0); + row(26.2, [X, X, _]); + line(25.9, 26.5, 2); + row(28.2, [K, K, K]); + arc(28.2, 0); + arc(28.2, 1); + arc(28.2, 2); + row(29.6, [B, B, B]); + line(29.3, 29.9, 1, 0.9); + row(31.4, [H, CR, H]); + arc(31.4, 0); + arc(31.4, 2); + row(33.4, [I, P, I]); + line(33, 33.8, 0, 0.9); + line(33, 33.8, 2, 0.9); + halo(34.6, 0); + line(35, 36, 0); + line(35, 36, 1); + line(35, 36, 2); + row(37, [M, M, M]); + line(36.7, 37.5, 1, 0.9); + row(38.8, [C, _, C]); + line(38.4, 39.4, 1); + row(40.4, [S, K, S]); + arc(40.4, 1); + // Act three: faster and closer. Mixed rows, a second bell, gargoyles on both flanks. + it(42, 1, R); + row(44, [_, G, G]); + line(43.6, 44.6, 0); + row(45.6, [P, _, B]); + line(45.2, 46, 1); + row(47, [K, B, K]); + arc(47, 0); + arc(47, 2); + row(48.4, [_, C, _]); + line(48, 48.8, 0); + line(48, 48.8, 2); + row(49.8, [X, _, _]); + line(49.4, 50.2, 2); + row(51.2, [H, H, H]); + arc(51.2, 1); + row(52.6, [B, B, B]); + line(52.3, 52.9, 0, 0.9); + halo(53.8, 2); + row(54.6, [P, P, _]); + line(54.2, 55, 2); + row(56, [_, P, P]); + line(55.6, 56.4, 0); + row(57.4, [G, _, G]); + line(57, 57.8, 1); + row(59, [I, K, I]); + arc(59, 1); + row(60.6, [P, _, P]); + line(60.2, 61, 1); + row(62, [M, M, M]); + line(61.7, 62.5, 1, 0.9); + row(63.5, [_, P, _]); + line(63.1, 63.9, 0); + line(63.1, 63.9, 2); + line(64.4, 65.4, 1, 2); + items.sort((a, b) => a[0] - b[0] || a[1] - b[1]); + souls.sort((a, b) => a[0] - b[0] || a[1] - b[1]); + return { items, souls, rows, checks: [16.5, 31, 46, 58].map((t) => r1(xAt(t))), finish: r1(xAt(RIDE_S)) }; +} + +const deep = (v) => (Array.isArray(v) ? Object.freeze(v.map(deep)) : v); +export const COURSE = Object.freeze(Object.fromEntries(Object.entries(build()).map(([k, v]) => [k, deep(v)]))); diff --git a/src/web-console/public/activities/ghoul-pew-draw.js b/src/web-console/public/activities/ghoul-pew-draw.js new file mode 100644 index 0000000..f0bb731 --- /dev/null +++ b/src/web-console/public/activities/ghoul-pew-draw.js @@ -0,0 +1,249 @@ +// Plan2Code Web Console - Ghoul Rush's Holy Roller, its drawing: the Chapel's runaway pew seen from behind, an endless-runner down the nave in three lanes. The whole field is drawn by this ride's own art (`field`, in pseudo-3D by ghoul-pew-world.js) the way the Carnival's dark ride draws its gallery; ghoul-draw.js hands it the frame and then draws the hearts, the cards, the banner and the HUD pills on top. +// +// ghoul-draw.js plugs it in. LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are plain data; +// pewArt(d) takes ghoul-draw.js's drawing helpers (`d`) and hands back the pack the usual way plus `field`, so +// this file never reaches back into it (it reads only the rules' numbers from ghoul-pew.js). Everything of +// the ride's own is read off `round.runner` (see ghoul-pew.js) and the room's `ride`; the events leave +// short-lived bits in the view's `fx` (floats, bursts and rings in field units, y counted up from the field's bottom). + +import { SOUL_SHARE, V0, V_MAX, soulShare, soulTotal } from "./ghoul-pew.js"; +import { HOR, LW, worldArt } from "./ghoul-pew-world.js"; + +const freeze = (o) => Object.freeze(o); +const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x)); + +const look = (o) => freeze({ pack: "pew", custom: true, noMoon: true, pit: "#07040c", ...o }); +export const LOOKS = freeze({ + pew: look({ wallTop: "#0c0816", wallLow: "#1c1230", paper: "#2a1c40", wainscot: "#1a1020", floorTop: "#6a6070", floor: "#2e2834", floorEdge: "#0c0a10", shelf: "#4a3220", shelfTop: "#8a6440", window: "#d8a0f0", decor: "pews", color: "#f0c870", dark: 0.3 }), +}); + +// How each new kind sounds, by act (the sounds in ghoul-sfx-pew.js). +export const VOICES = freeze({ + pew: freeze({ + lane: "ghoulPewLane", bump: "ghoulPewBump", jump: "ghoulPewJump", land: "ghoulPewLand", slide: "ghoulPewSlide", dive: "ghoulPewDive", + soul: "ghoulPewSoul", halo: "ghoulPewHalo", crash: "ghoulPewCrash", check: "ghoulPewCheck", finish: "ghoulPewFinish", speed: "ghoulPewSpeed", + }), + pewgarg: freeze({ warn: "ghoulPewGargWarn", drop: "ghoulPewGargDrop", chip: "ghoulPewGargChip", hit: "ghoulPewGargHit" }), + pewbell: freeze({ ring: "ghoulPewBell" }), +}); + +// What each of the pack's events plays: [kind, act], once. +export const EVENT_VOICE = freeze({ + pewLane: ["pew", "lane"], + pewBump: ["pew", "bump"], + pewJump: ["pew", "jump"], + pewLand: ["pew", "land"], + pewSlide: ["pew", "slide"], + pewDive: ["pew", "dive"], + pewSoul: ["pew", "soul"], + pewHalo: ["pew", "halo"], + pewCrash: ["pew", "crash"], + pewCheck: ["pew", "check"], + pewFinish: ["pew", "finish"], + pewSpeed: ["pew", "speed"], + pewGargWarn: ["pewgarg", "warn"], + pewGargDrop: ["pewgarg", "drop"], + pewGargChip: ["pewgarg", "chip"], + pewGargHit: ["pewgarg", "hit"], + pewBell: ["pewbell", "ring"], +}); +export const LOSE_WORDS = freeze({ + pewPillar: "Ran into a pillar", pewConfessional: "Into a confessional", pewCrosswise: "Crashed into a pew", pewKneeler: "Tripped on a kneeler", + pewCandle: "Hit a candle stand", pewFlagstone: "Cracked on a flagstone", pewHatch: "Fell down a crypt hatch", pewCenser: "Censer to the head", + pewBanner: "Banner to the face", pewBeam: "Struck by a beam", pewGargoyle: "Flattened by a gargoyle", +}); +export const LOSE_SOUNDS = freeze({ + pewPillar: ["thud", 0.55, 0.8], + pewConfessional: ["thud", 0.5, 0.9], + pewCrosswise: ["thud", 0.5, 1], + pewKneeler: ["thud", 0.5, 1.1], + pewCandle: ["clank", 0.5, 1.1], + pewFlagstone: ["ghoulRockLand", 0.5, 0.9], + pewHatch: ["ghoulPitFall", 0.55, 1], + pewCenser: ["clank", 0.5, 0.8], + pewBanner: ["thud", 0.4, 1.2], + pewBeam: ["smash", 0.5, 0.8], + pewGargoyle: ["crunch", 0.55, 0.7], +}); + +// The progress track along the field's top: the ride, its checkpoints and where the pew is. +export const BAR = freeze({ x0: 22, x1: 74, y: 3 }); + +export function pewArt(d) { + const { label, GOLD, say } = d; + const world = worldArt(d); + const pewOf = (round) => (round && round.runner && round.runner.id === "pew" ? round.runner : null); + + // The still layers never draw this room (the field is the ride's), so they only get the nave's dark. + function backdrop(ctx, v, lk, x0, x1) { + ctx.fillStyle = lk.wallLow; + ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H); + } + const ground = () => {}; + const shelf = () => {}; + const lights = () => {}; + const dim = () => 0; + + /* ----------------------------------------------------------- the frame */ + + // The whole field: the nave in pseudo-3D, the ride's own HUD strip, then the effects the events left. + function field(ctx, v) { + const { round, g } = v; + const c = pewOf(round); + if (!c) return; + const R = round.spec.ride; + const you = round.you; + ctx.save(); + if (v.shake) ctx.translate(v.shake.x * 0.6, v.shake.y * 0.6); + world.paint(ctx, v); + ctx.restore(); + const Y = (y) => g.FIELD_H - y; + // The progress track with its checkpoints and the pew on it. + const { x0, x1, y } = BAR; + const p = clamp((you.x - round.spec.start) / (R.finish - round.spec.start), 0, 1); + ctx.globalAlpha = 0.6; + ctx.fillStyle = "#05060f"; + ctx.fillRect(x0 - 0.6, y - 0.9, x1 - x0 + 1.2, 1.8); + ctx.globalAlpha = 1; + const speedK = clamp((c.v - V0) / (V_MAX - V0), 0, 1); + ctx.fillStyle = speedK > 0.66 ? "#ff8a4a" : speedK > 0.33 ? "#ffd36a" : "#7fd0ff"; + ctx.fillRect(x0, y - 0.45, (x1 - x0) * p, 0.9); + for (const cx of R.checks) { + const k = (cx - round.spec.start) / (R.finish - round.spec.start); + ctx.fillStyle = cx <= you.x ? "#7dffa0" : "#cdbfe6"; + ctx.fillRect(x0 + (x1 - x0) * k - 0.15, y - 1.1, 0.3, 2.2); + } + ctx.fillStyle = GOLD; + ctx.beginPath(); + ctx.arc(x0 + (x1 - x0) * p, y, 0.9, 0, Math.PI * 2); + ctx.fill(); + // Souls on the left, the combo on the right. + label(ctx, `SOULS ${c.got}/${soulTotal(R)}`, 3, 6.2, 2, soulShare(R, c) >= SOUL_SHARE ? "#7dffa0" : "#f0e8d8", "left"); + if (c.combo > 1) { + const pop = 1 + Math.max(0, 1 - (v.fx.clock - (v.fx.pewPop || -1e4)) / 220) * 0.3; + label(ctx, `x${c.mult} ${c.combo} IN A ROW`, g.FIELD_W - 3, 6.4, 2.1 * pop, c.mult > 1 ? GOLD : "#f0e8d8", "right"); + } + if (c.magnet > 0) label(ctx, "HALO", g.FIELD_W - 3, 9.6, 1.7, "#ffd75a", "right"); + // Floats, bursts and rings that events left (field units, y up). + for (const q of v.fx.parts) { + ctx.globalAlpha = Math.max(0, q.life / q.max); + ctx.fillStyle = q.color; + ctx.fillRect(q.x - q.size / 2, Y(q.y) - q.size / 2, q.size, q.size); + } + for (const r of v.fx.rings) { + const k = 1 - r.life / r.max; + ctx.globalAlpha = (1 - k) * 0.8; + ctx.strokeStyle = r.color; + ctx.lineWidth = 0.5 * (1 - k) + 0.15; + ctx.beginPath(); + ctx.arc(r.x, Y(r.y), r.r0 + k * r.grow, 0, Math.PI * 2); + ctx.stroke(); + } + ctx.globalAlpha = 1; + } + + /* -------------------------------------------------------------- events */ + + // A throttle on a repeating cue. + function gateOnce(fx, key, ms) { + if ((fx[key] || 0) > fx.clock) return false; + fx[key] = fx.clock + ms; + return true; + } + // Where the pew is on the screen (x) and a height over its feet (y up from the field's bottom). + const heroX = (lane) => 48 + (lane - 1) * 0.45 * LW; + + // What the pack's events look and sound like; true when the event is its own. Each of its + // sounds plays once, from EVENT_VOICE (a soul's tick climbs with the combo). + function react(e, k) { + const { tone, shake, flash, burst, float, ring, fx } = k; + const voice = EVENT_VOICE[e.type]; + if (!voice) return false; + if ((e.type === "pewSlide" || e.type === "pewLane") && !gateOnce(fx, `${e.type}Ms`, 90)) return true; + if (e.type === "pewSoul") tone(VOICES.pew.soul, 0.28, 1 + 0.05 * Math.min(12, (e.combo || 1) - 1) + 0.12 * ((e.mult || 1) - 1)); + else say(tone, voice[0], voice[1], e.type === "pewSpeed" ? 0.4 : 0.5); + const x = heroX(e.lane === undefined ? 1 : e.lane); + const fy = 54 - 36; + switch (e.type) { + case "pewJump": + burst(x, 54 - 6, "#b89a78", 5, 7, 300); + break; + case "pewLand": + burst(x, 54 - 7, "#b0a4b8", e.big ? 14 : 6, e.big ? 12 : 8, 360); + if (e.big) shake(180, 0.5); + break; + case "pewBump": + shake(160, 0.5); + burst(x + (e.dir || 0) * 5, 54 - 14, "#cfd2e6", 5, 6, 260); + break; + case "pewSoul": + burst(heroX(e.lane), fy - (e.h || 1.5) * 2, "#ffd36a", 2, 5, 240); + if (e.up) { + fx.pewPop = fx.clock; + ring(48, 54 - 22, "#ffd36a", 1, 9, 500); + float(48, 54 - 14, `Combo x${e.mult}`, GOLD, 2.6); + } + break; + case "pewHalo": + ring(48, 54 - 24, "#ffd75a", 1, 14, 600); + float(48, 54 - 16, "Halo!", GOLD, 2.6); + break; + case "pewCrash": + shake(340, 1); + flash("#ffe0a8", 220); + burst(x, 54 - 16, e.what === "garg" ? "#8a96bc" : "#8a5a36", 18, 17, 520); + if (e.lost > 5) float(48, 54 - 16, "Combo lost", "#cdbfe6", 2); + break; + case "pewCheck": + float(48, 54 - 34, "Checkpoint", GOLD, 2.4); + ring(48, 54 - 30, "#7dffa0", 1, 10, 500); + break; + case "pewFinish": + shake(260, 0.7); + burst(48, 54 - 24, "#ffd36a", 24, 14, 600); + float(48, 54 - 30, e.share >= SOUL_SHARE ? "Amen! A full choir" : "Amen!", GOLD, 2.8); + break; + case "pewSpeed": + ring(48, 54 - HOR, "#9ab0ff", 4, 40, 520); + float(48, 54 - 40, "Faster!", "#ffb02e", 2.2); + break; + case "pewGargWarn": + shake(120, 0.25); + break; + case "pewGargDrop": + shake(200, 0.55); + burst(heroX(e.lane), 54 - 22, "#8a96bc", 10, 9, 420); + break; + case "pewGargChip": + burst(heroX(e.lane), 54 - 24, "#8a96bc", 6, 8, 300); + break; + case "pewGargHit": + burst(heroX(e.lane), 54 - 24, "#8a96bc", 14, 14, 480); + float(heroX(e.lane), 54 - 28, `+${e.points}`, GOLD, 2.2); + break; + case "pewBell": + ring(heroX(e.lane), 54 - 26, "#ffd36a", 1, 14, 700); + float(48, 54 - 30, e.stunned > 0 ? `+${e.points} Stunned!` : `+${e.points}`, GOLD, 2.4); + break; + default: + break; + } + return true; + } + + return freeze({ + looks: LOOKS, + backdrop, + ground, + shelf, + dim, + monsters: freeze({}), + bosses: freeze({}), + missiles: freeze({}), + hazards: freeze({}), + powers: freeze({}), + lights, + react, + field, + }); +} diff --git a/src/web-console/public/activities/ghoul-pew-world.js b/src/web-console/public/activities/ghoul-pew-world.js new file mode 100644 index 0000000..6dc7b26 --- /dev/null +++ b/src/web-console/public/activities/ghoul-pew-world.js @@ -0,0 +1,947 @@ +// Plan2Code Web Console - Ghoul Rush's Holy Roller, its world: the nave seen from behind the pew, in pseudo-3D. Drawn by ghoul-pew-draw.js's `field`; reads the rules in ghoul-pew.js, draws no random number (every scatter is a hash). +// +// THE PROJECTION (reusable for any "run into the screen" view, field units, the field being 96 wide and 54 high): +// a point is (l, dz, h): `l` across the aisle in lanes (0 the middle lane, +1 the right one), `dz` how far down the +// aisle ahead of the pew (negative once passed), `h` its height. With scale = NEAR / (NEAR + dz) it lands at +// x = VPX + (l - camL) * LW * scale, y = HOR + (GY0 - HOR) * scale - h * HS * scale +// so the horizon (dz infinite) is the vanishing point (VPX, HOR) and the pew (dz 0) stands at scale 1 on the floor line GY0. +// The camera slides a little with the pew's lane (camL). The scene goes far to near in CELL-deep cells anchored to the world +// (so they scroll), each with its floor tiles, wall, window and its light, pews and pillar with a rib over the aisle, then the +// things standing in the cell; fog is the cell's alpha going to nothing over FADE_D. The art of the things is in `thing`. + +import { BUMP_MS, KINDS, LOW_Y, V0, V_MAX, cuesOf, gargRise } from "./ghoul-pew.js"; + +const TAU = Math.PI * 2; +const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x)); + +export const VPX = 48; +export const HOR = 19; +export const GY0 = 46; +export const NEAR = 26; +export const LW = 14.5; +export const HS = 2.1; +export const CELL = 16; +export const TILE = 8; +export const SEE = 290; +export const FADE_D = 250; +export const BPM = 132; +export const BEAT_MS = 60000 / BPM; +export const ANSWER_COLORS = Object.freeze({ JUMP: "#5fe3ff", SLIDE: "#ffb02e", SWITCH: "#ff5a6a", SHOOT: "#ff8a4a" }); +const GLASS = Object.freeze(["216,50,60", "60,111,224", "240,180,58", "63,181,106", "166,90,216"]); +const WALL_L = 5.8; + +// A number in 0..1 from two integers, the same every time (no random draws). +export const rnd = (a, b = 0) => { + let h = Math.imul((a | 0) + 0x9e37, 0x85ebca6b) ^ Math.imul((b | 0) + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +const grad = (make, stops) => { + const g = make ? make() : null; + if (!g || typeof g.addColorStop !== "function") return stops[stops.length >> 1][1]; + for (const [o, col] of stops) g.addColorStop(o, col); + return g; +}; +const vgrad = (c, y0, y1, stops) => grad(c.createLinearGradient && (() => c.createLinearGradient(0, y0, 0, y1)), stops); +const rgrad = (c, x, y, r, stops) => grad(c.createRadialGradient && (() => c.createRadialGradient(x, y, 0, x, y, r)), stops); +const quad = (c, a, b, e, f) => { + c.beginPath(); + c.moveTo(a[0], a[1]); + c.lineTo(b[0], b[1]); + c.lineTo(e[0], e[1]); + c.lineTo(f[0], f[1]); + c.closePath(); +}; +const seg = (c, a, b) => { + c.beginPath(); + c.moveTo(a[0], a[1]); + c.lineTo(b[0], b[1]); + c.stroke(); +}; +const disc = (c, x, y, r) => { + c.beginPath(); + c.arc(x, y, Math.max(0.01, r), 0, TAU); + c.fill(); +}; + +// The beat: 1 on the organ's stroke, falling away. +export const pulse = (clock) => Math.exp(-((clock % BEAT_MS) / BEAT_MS) * 4.5); +// How much of a thing `dz` ahead the fog leaves. +export const fog = (dz) => (dz < 120 ? 1 : clamp(1 - (dz - 120) / (FADE_D - 120), 0, 1)); + +export function worldArt(d) { + const { label, circle } = d; + let camL = 0; + let FW = 96; + let FH = 54; + let clock = 0; + let beat = 0; + // Where (l, dz, h) lands: [x, y, scale]. + // (The view narrows a little as the ride speeds up: `near` falls from NEAR.) + let near = NEAR; + const sc = (dz) => near / (near + Math.max(dz, -near * 0.55)); + const P = (l, dz, h = 0) => { + const s = sc(dz); + return [VPX + (l - camL) * LW * s, HOR + (GY0 - HOR) * s - h * HS * s, s]; + }; + // A box from lateral l0..l1, near depth z0 to far z1, height h0..h1: the faces the camera sees. + function box(ctx, l0, l1, z0, z1, h0, h1, c) { + const eye = (GY0 - HOR) / HS; + const n = [P(l0, z0, h0), P(l1, z0, h0), P(l1, z0, h1), P(l0, z0, h1)]; + if (c.side) { + const left = l1 <= camL; + const l = left ? l1 : l0; + if (left || l0 >= camL) { + quad(ctx, P(l, z0, h0), P(l, z1, h0), P(l, z1, h1), P(l, z0, h1)); + ctx.fillStyle = c.side; + ctx.fill(); + } + } + if (c.top && h1 < eye) { + quad(ctx, P(l0, z0, h1), P(l1, z0, h1), P(l1, z1, h1), P(l0, z1, h1)); + ctx.fillStyle = c.top; + ctx.fill(); + } + quad(ctx, n[0], n[1], n[2], n[3]); + ctx.fillStyle = c.front; + ctx.fill(); + return n; + } + // A wall-plane (or floor) quad between two corners at depths za..zb. + const wall = (ctx, l, za, zb, h0, h1, fill) => { + quad(ctx, P(l, za, h0), P(l, zb, h0), P(l, zb, h1), P(l, za, h1)); + ctx.fillStyle = fill; + ctx.fill(); + }; + const floor = (ctx, l0, l1, za, zb, fill) => { + quad(ctx, P(l0, za, 0), P(l1, za, 0), P(l1, zb, 0), P(l0, zb, 0)); + ctx.fillStyle = fill; + ctx.fill(); + }; + const glow = (ctx, x, y, r, rgb, a) => { + if (a <= 0.01 || r < 0.2) return; + ctx.globalAlpha = a; + ctx.fillStyle = rgrad(ctx, x, y, r, [[0, `rgba(${rgb},0.9)`], [0.4, `rgba(${rgb},0.35)`], [1, `rgba(${rgb},0)`]]); + ctx.fillRect(x - r, y - r, r * 2, r * 2); + }; + + /* ------------------------------------------------------------ the room */ + + // The vault, the far altar's glow and the floor's base. + function backdrop(ctx) { + ctx.fillStyle = vgrad(ctx, 0, HOR + 8, [[0, "#070a18"], [0.7, "#141a38"], [1, "#2a3052"]]); + ctx.fillRect(0, 0, FW, FH); + ctx.fillStyle = vgrad(ctx, HOR, FH, [[0, "#242a4a"], [0.5, "#161a30"], [1, "#0c0e1c"]]); + ctx.fillRect(0, HOR, FW, FH - HOR); + // The altar at the end of the nave: a rose window and its warm blaze. + const a = 0.75 + 0.25 * beat; + glow(ctx, VPX, HOR - 1, 34, "255,196,120", 0.55 * a); + glow(ctx, VPX, HOR - 1, 14, "255,236,190", 0.9 * a); + ctx.globalAlpha = 1; + ctx.fillStyle = "#1b1a2c"; + ctx.fillRect(VPX - 3, HOR - 3.4, 6, 3.4); + ctx.fillStyle = "#ffe7a8"; + ctx.fillRect(VPX - 0.25, HOR - 3.4, 0.5, 2.2); + ctx.fillRect(VPX - 1, HOR - 2.7, 2, 0.4); + ctx.fillStyle = `rgba(255,214,130,${0.7 + 0.3 * beat})`; + for (const k of [-2.2, -1.2, 1.2, 2.2]) disc(ctx, VPX + k, HOR - 3.8, 0.35); + } + + function cell(ctx, you, c, j) { + const z0 = j * CELL - you.x; + const f = fog(z0); + if (f <= 0.02) return; + ctx.globalAlpha = f; + const warm = "255,190,110"; + // Floor: two tiles, flagstone then carpet. + for (let t = 0; t < 2; t++) { + const za = z0 + t * TILE; + const zb = za + TILE; + const alt = (j * 2 + t) % 2; + floor(ctx, -WALL_L, WALL_L, za, zb, alt ? "#2b3150" : "#252a46"); + floor(ctx, -2.65, 2.65, za, zb, alt ? "#3a4166" : "#333a5e"); + floor(ctx, -1.5, 1.5, za, zb, alt ? "#6b1c2e" : "#5c1727"); + // Tile joints and the carpet's gold edge and lane stitching. + ctx.strokeStyle = "rgba(8,10,24,0.55)"; + ctx.lineWidth = 0.22 * sc(za); + seg(ctx, P(-2.65, za), P(2.65, za)); + } + ctx.strokeStyle = "rgba(231,180,76,0.75)"; + ctx.lineWidth = Math.max(0.12, 0.34 * sc(z0)); + seg(ctx, P(-1.5, z0), P(-1.5, z0 + CELL)); + seg(ctx, P(1.5, z0), P(1.5, z0 + CELL)); + ctx.strokeStyle = "rgba(231,180,76,0.32)"; + ctx.lineWidth = Math.max(0.1, 0.22 * sc(z0)); + for (const l of [-0.5, 0.5]) { + ctx.beginPath(); + for (let k = 0; k < 4; k++) { + const a = P(l, z0 + k * 4); + const b = P(l, z0 + k * 4 + 2.6); + ctx.moveTo(a[0], a[1]); + ctx.lineTo(b[0], b[1]); + } + ctx.stroke(); + } + for (const side of [-1, 1]) { + const wl = side * WALL_L; + // The wall, its wainscot and cornice, and the clerestory's lancet window with its light. + wall(ctx, wl, z0, z0 + CELL, 0, 44, side < 0 ? "#222844" : "#262c4a"); + wall(ctx, wl, z0, z0 + CELL, 0, 5.5, "#161a30"); + box(ctx, side < 0 ? -WALL_L : WALL_L - 0.55, side < 0 ? -WALL_L + 0.55 : WALL_L, z0, z0 + CELL, 13.2, 14.4, { front: "#59629a", side: "#6f7ab0", top: "#8a96c4" }); + // The slim shaft that carries a rib up the wall. + box(ctx, side < 0 ? -WALL_L : WALL_L - 0.5, side < 0 ? -WALL_L + 0.5 : WALL_L, z0, z0 + 2, 14.4, 32, { front: "#4b5480", side: "#6a76a6" }); + const gi = Math.abs(j * 3 + (side > 0 ? 1 : 0)) % GLASS.length; + const rgb = GLASS[(gi + (side > 0 ? 2 : 0)) % GLASS.length]; + const lit = 0.6 + 0.35 * beat; + const w = [ + [z0 + 4, 16.5], + [z0 + 12, 16.5], + [z0 + 12, 27], + [z0 + 8, 32], + [z0 + 4, 27], + ]; + ctx.beginPath(); + w.forEach(([z, h], i) => { + const p = P(wl, z, h); + if (i) ctx.lineTo(p[0], p[1]); + else ctx.moveTo(p[0], p[1]); + }); + ctx.closePath(); + ctx.fillStyle = "#0d1020"; + ctx.fill(); + ctx.fillStyle = `rgba(${rgb},${lit})`; + ctx.fill(); + ctx.strokeStyle = "rgba(10,12,28,0.85)"; + ctx.lineWidth = Math.max(0.08, 0.26 * sc(z0 + 8)); + ctx.stroke(); + seg(ctx, P(wl, z0 + 8, 16.5), P(wl, z0 + 8, 32)); + seg(ctx, P(wl, z0 + 4, 22), P(wl, z0 + 12, 22)); + // God rays: a slanted shaft from the window to a patch on the floor, in the glass's color. + ctx.globalCompositeOperation = "lighter"; + const patch = side * 0.8; + quad(ctx, P(wl, z0 + 4, 16.5), P(wl, z0 + 12, 16.5), P(patch, z0 + 14, 0), P(patch + side * 2.1, z0 + 5, 0)); + ctx.fillStyle = `rgba(${rgb},${0.05 + 0.04 * beat})`; + ctx.fill(); + quad(ctx, P(patch + side * 2.1, z0 + 5, 0), P(patch, z0 + 14, 0), P(patch - side * 0.9, z0 + 15, 0), P(patch + side * 1.3, z0 + 6, 0)); + ctx.fillStyle = `rgba(${rgb},${0.1 + 0.07 * beat})`; + ctx.fill(); + ctx.globalCompositeOperation = "source-over"; + // The pews along the aisle: seat and back. + const l0 = side < 0 ? -4.2 : 3.1; + const l1 = side < 0 ? -3.1 : 4.2; + for (let k = 0; k < 2; k++) { + const za = z0 + 8 * k + 0.8; + const tint = (j + k) % 2; + box(ctx, l0, l1, za, za + 6.4, 0, 1.7, { front: tint ? "#4a2c1a" : "#42261a", side: tint ? "#6a4128" : "#5e3a24", top: "#8a5a36" }); + const b0 = side < 0 ? l0 : l1 - 0.35; + const b1 = side < 0 ? l0 + 0.35 : l1; + box(ctx, b0, b1, za, za + 6.4, 1.7, 4.2, { front: "#3a2114", side: "#5a361f", top: "#7a4c2c" }); + } + // The pillar, with a sconce on it, and the rib across the vault. + const pl = side * 4.75; + const stone = { front: "#4b5480", side: "#6a76a6", top: "#7e8ab8" }; + const cap = { front: "#59629a", side: "#77839f", top: "#8a96bc" }; + box(ctx, pl - 0.55, pl + 0.55, z0, z0 + 2.4, 0, 13, stone); + box(ctx, pl - 0.8, pl + 0.8, z0 - 0.2, z0 + 2.6, 0, 1.6, cap); + box(ctx, pl - 0.8, pl + 0.8, z0 - 0.2, z0 + 2.6, 11.6, 13.2, cap); + const sp = P(pl - side * 0.6, z0 + 0.3, 8); + glow(ctx, sp[0], sp[1], 9 * sp[2] + 0.5, warm, 0.5 * f * (0.8 + 0.2 * beat)); + ctx.globalAlpha = f; + ctx.fillStyle = "#ffd890"; + disc(ctx, sp[0], sp[1], 0.4 * sp[2] + 0.1); + if (side > 0) { + ctx.strokeStyle = "#59629a"; + ctx.lineWidth = Math.max(0.2, 1.0 * sc(z0)); + const a = P(-5.4, z0 + 1, 32); + const b = P(5.4, z0 + 1, 32); + const m = P(0, z0 + 1, 45); + ctx.beginPath(); + ctx.moveTo(a[0], a[1]); + ctx.quadraticCurveTo(m[0], m[1] - 2 * m[2] * HS, b[0], b[1]); + ctx.stroke(); + } + } + ctx.globalAlpha = 1; + } + + /* ----------------------------------------------------------- the things */ + + // A telegraph glyph over a thing: a colored mark, with its word on the first few. + function glyph(ctx, kind, answer, l, dz, h, words, extra) { + if (dz > 130 || dz < -6) return; + const p = P(l, dz, h); + const s = p[2]; + const col = ANSWER_COLORS[answer]; + const a = clamp((130 - dz) / 50, 0, 1) * (dz < 0 ? clamp(1 + dz / 6, 0, 1) : 1) * (0.72 + 0.28 * Math.sin(clock / 130)); + if (a < 0.03) return; + ctx.globalAlpha = a; + ctx.strokeStyle = col; + ctx.fillStyle = col; + ctx.lineWidth = Math.max(0.3, 0.7 * s); + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + const r = Math.max(0.7, 2.3 * s); + const x = p[0]; + const y = p[1]; + if (answer === "JUMP") { + ctx.beginPath(); + ctx.moveTo(x - r, y + r * 0.5); + ctx.lineTo(x, y - r * 0.6); + ctx.lineTo(x + r, y + r * 0.5); + ctx.moveTo(x - r, y + r * 1.5); + ctx.lineTo(x, y + r * 0.4); + ctx.lineTo(x + r, y + r * 1.5); + ctx.stroke(); + } else if (answer === "SLIDE") { + ctx.beginPath(); + ctx.moveTo(x - r, y - r * 0.5); + ctx.lineTo(x, y + r * 0.6); + ctx.lineTo(x + r, y - r * 0.5); + ctx.moveTo(x - r, y - r * 1.5); + ctx.lineTo(x, y - r * 0.4); + ctx.lineTo(x + r, y - r * 1.5); + ctx.stroke(); + } else if (answer === "SHOOT") { + circle(ctx, x, y, r); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo(x - r * 1.5, y); + ctx.lineTo(x + r * 1.5, y); + ctx.moveTo(x, y - r * 1.5); + ctx.lineTo(x, y + r * 1.5); + ctx.stroke(); + } else { + // SWITCH: an arrow toward each free lane beside it. + for (const dir of extra) { + ctx.beginPath(); + ctx.moveTo(x + dir * r * 0.4, y - r * 0.9); + ctx.lineTo(x + dir * r * 1.6, y); + ctx.lineTo(x + dir * r * 0.4, y + r * 0.9); + ctx.moveTo(x - dir * r * 0.6, y); + ctx.lineTo(x + dir * r * 1.6, y); + ctx.stroke(); + } + } + if (words && s > 0.2) label(ctx, answer === "SWITCH" ? "MOVE" : answer, x, y - r * 2.1, clamp(2.8 * s, 1.2, 2.6), col, "center", 20); + ctx.globalAlpha = 1; + } + + const trim = (ctx, pts, col, w) => { + ctx.strokeStyle = col; + ctx.lineWidth = w; + ctx.beginPath(); + pts.forEach((p, i) => (i ? ctx.lineTo(p[0], p[1]) : ctx.moveTo(p[0], p[1]))); + ctx.stroke(); + }; + + // Red and white hazard stripes across a block's foot: the "go round me" mark. + function hazard(ctx, l0, l1, z, h) { + const n = 6; + for (let k = 0; k < n; k++) { + const a = l0 + ((l1 - l0) * k) / n; + const b = l0 + ((l1 - l0) * (k + 1)) / n; + const lo = P(a, z, 0.2); + const hi = P(b, z, h); + ctx.fillStyle = k % 2 ? "#e8e0d0" : "#d6303c"; + ctx.beginPath(); + ctx.moveTo(lo[0], lo[1]); + ctx.lineTo(P(b, z, 0.2)[0], P(b, z, 0.2)[1]); + ctx.lineTo(hi[0], hi[1]); + ctx.lineTo(P(a, z, h)[0], P(a, z, h)[1]); + ctx.closePath(); + ctx.fill(); + } + } + + function thing(ctx, you, c, q, openSides, words) { + const k = KINDS[q.kind]; + const z0 = q.x - you.x; + const z1 = q.end - you.x; + const f = fog(z0); + if (f <= 0.02 || z1 < -9) return; + const l = q.lane - 1; + ctx.globalAlpha = f; + const col = ANSWER_COLORS[k.answer]; + const wide = 0.42; + let top = 0; + // The mark on the floor ahead of it, in its answer's color. + if (k.answer !== "SHOOT" || q.kind === "garg") { + ctx.globalAlpha = f * 0.3; + floor(ctx, l - 0.47, l + 0.47, z0 - 5, z0 - 3.2, col); + ctx.globalAlpha = f; + } + switch (q.kind) { + case "pillar": { + box(ctx, l - wide, l + wide, z0, z1, 0, 9, { front: "#7b86b4", side: "#59638f", top: "#a0aad0" }); + hazard(ctx, l - wide, l + wide, z0, 1.6); + ctx.strokeStyle = "rgba(30,36,70,0.5)"; + ctx.lineWidth = Math.max(0.1, 0.2 * sc(z0)); + for (const o of [-0.25, 0, 0.25]) seg(ctx, P(l + o, z0, 1.7), P(l + o, z0, 8.6)); + top = 11; + break; + } + case "confessional": { + box(ctx, l - wide, l + wide, z0, z1, 0, 8.5, { front: "#4a2a1a", side: "#6a3c26", top: "#8a5636" }); + const a = P(l - 0.3, z0, 6.4); + const b = P(l + 0.3, z0, 3.4); + ctx.fillStyle = "#14090a"; + ctx.fillRect(a[0], a[1], b[0] - a[0], b[1] - a[1]); + ctx.strokeStyle = "#a07a46"; + ctx.lineWidth = Math.max(0.1, 0.22 * sc(z0)); + ctx.strokeRect(a[0], a[1], b[0] - a[0], b[1] - a[1]); + hazard(ctx, l - wide, l + wide, z0, 1.6); + top = 10.5; + break; + } + case "pewx": { + box(ctx, l - wide - 0.03, l + wide + 0.03, z0, z1, 0, 2.6, { front: "#4a2c1a", side: "#6a4128", top: "#8a5a36" }); + box(ctx, l - wide - 0.03, l + wide + 0.03, z0 + 0.2, z1, 2.6, 5.6, { front: "#3a2114", side: "#5a361f", top: "#7a4c2c" }); + hazard(ctx, l - wide, l + wide, z0, 1.4); + top = 7.5; + break; + } + case "kneeler": { + box(ctx, l - wide, l + wide, z0, z1, 0, 1.3, { front: "#3a2114", side: "#5a361f", top: "#7a4c2c" }); + box(ctx, l - wide + 0.04, l + wide - 0.04, z0, z1, 1.3, k.h, { front: "#a8283c", side: "#7c1a2c", top: "#d04a5c" }); + trim(ctx, [P(l - wide, z0, k.h), P(l + wide, z0, k.h)], col, Math.max(0.2, 0.55 * sc(z0))); + top = k.h + 2.4; + break; + } + case "stand": { + box(ctx, l - 0.28, l + 0.28, z0, z1, 0, 0.9, { front: "#2a2a38", side: "#3c3c50", top: "#58586e" }); + ctx.strokeStyle = "#2c2c3c"; + ctx.lineWidth = Math.max(0.2, 0.5 * sc(z0)); + seg(ctx, P(l, z0 + 1, 0.8), P(l, z0 + 1, 3)); + box(ctx, l - 0.4, l + 0.4, z0, z1, 2.8, 3.4, { front: "#6a6a82", side: "#4a4a60", top: "#9a9ab4" }); + for (const o of [-0.26, 0, 0.26]) { + const p = P(l + o, z0 + 1, 4.2); + glow(ctx, p[0], p[1], 3.8 * p[2] + 0.3, "255,190,100", 0.7 * f); + ctx.globalAlpha = f; + ctx.fillStyle = "#fff0b8"; + ctx.beginPath(); + ctx.ellipse(p[0], p[1], Math.max(0.1, 0.4 * p[2]), Math.max(0.12, 0.8 * p[2]), 0, 0, TAU); + ctx.fill(); + ctx.fillStyle = "#f4efe0"; + const w = P(l + o, z0 + 1, 3.4); + ctx.fillRect(w[0] - 0.25 * w[2], w[1], 0.5 * w[2], Math.max(0.2, p[1] - w[1]) * -1); + } + trim(ctx, [P(l - 0.4, z0, 3.4), P(l + 0.4, z0, 3.4)], col, Math.max(0.2, 0.55 * sc(z0))); + top = 6.4; + break; + } + case "cracks": + case "hatch": { + const hatch = q.kind === "hatch"; + floor(ctx, l - 0.46, l + 0.46, z0, z1, hatch ? "#05060c" : "#4a5074"); + if (hatch) { + box(ctx, l - 0.46, l + 0.46, z1 - 0.7, z1, 0, 2.3, { front: "#6a7090", side: "#4a5074", top: "#8a90b0" }); + ctx.globalCompositeOperation = "lighter"; + floor(ctx, l - 0.3, l + 0.3, z0 + 1, z1 - 1, "rgba(120,255,160,0.1)"); + ctx.globalCompositeOperation = "source-over"; + } else { + ctx.strokeStyle = "#12142a"; + ctx.lineWidth = Math.max(0.12, 0.34 * sc(z0)); + for (let m = 0; m < 3; m++) { + ctx.beginPath(); + for (let n = 0; n <= 6; n++) { + const pp = P(l - 0.4 + m * 0.4 + (n % 2 ? 0.1 : -0.1), z0 + (n * (z1 - z0)) / 6, 0.05); + if (n) ctx.lineTo(pp[0], pp[1]); + else ctx.moveTo(pp[0], pp[1]); + } + ctx.stroke(); + } + box(ctx, l - 0.4, l - 0.2, z0 + 1.2, z0 + 2.4, 0, 0.8, { front: "#7a82a8", side: "#5a628a", top: "#9aa2c8" }); + box(ctx, l + 0.1, l + 0.3, z1 - 2.6, z1 - 1.4, 0, 0.7, { front: "#7a82a8", side: "#5a628a", top: "#9aa2c8" }); + } + trim(ctx, [P(l - 0.46, z0, 0), P(l + 0.46, z0, 0)], col, Math.max(0.25, 0.7 * sc(z0))); + trim(ctx, [P(l - 0.46, z1, 0), P(l + 0.46, z1, 0)], col, Math.max(0.2, 0.5 * sc(z1))); + top = 3.4; + break; + } + case "censer": { + const sway = Math.sin(clock / 380 + q.i * 1.7) * 0.22; + const hang = P(l, z0 + 1, 34); + const ball = P(l + sway, z0 + 1, LOW_Y + 1.3); + ctx.strokeStyle = "#8a7a52"; + ctx.lineWidth = Math.max(0.15, 0.4 * ball[2]); + seg(ctx, hang, ball); + ctx.fillStyle = "#c79a3a"; + disc(ctx, ball[0], ball[1], 1.6 * HS * ball[2] * 0.5 + 0.2); + ctx.fillStyle = "#6a4a14"; + disc(ctx, ball[0], ball[1] + 0.2 * ball[2], 0.7 * HS * ball[2] * 0.5); + ctx.globalAlpha = f * 0.35; + ctx.fillStyle = "#cfd2e6"; + for (let m = 0; m < 3; m++) disc(ctx, ball[0] + Math.sin(clock / 260 + m * 2) * 0.6 * ball[2], ball[1] - (1.6 + m * 1.4) * ball[2] * HS * 0.5, (0.5 + m * 0.3) * ball[2]); + ctx.globalAlpha = f; + trim(ctx, [P(l - 0.4, z0, LOW_Y), P(l + 0.4, z0, LOW_Y)], col, Math.max(0.2, 0.55 * sc(z0))); + top = 8; + break; + } + case "banner": { + const a = P(l - 0.44, z0, 15); + const b = P(l + 0.44, z0, 15); + const lo0 = P(l - 0.44, z0, LOW_Y); + const lo1 = P(l + 0.44, z0, LOW_Y); + const tail = P(l, z0, LOW_Y - 0.9); + ctx.fillStyle = "#5c1a6a"; + ctx.beginPath(); + ctx.moveTo(a[0], a[1]); + ctx.lineTo(b[0], b[1]); + ctx.lineTo(lo1[0], lo1[1]); + ctx.lineTo(tail[0], tail[1]); + ctx.lineTo(lo0[0], lo0[1]); + ctx.closePath(); + ctx.fill(); + ctx.strokeStyle = "#e0b04a"; + ctx.lineWidth = Math.max(0.12, 0.3 * sc(z0)); + ctx.stroke(); + const cx = P(l, z0, 8.5); + ctx.strokeStyle = "#f0d078"; + ctx.lineWidth = Math.max(0.2, 0.6 * cx[2]); + seg(ctx, P(l, z0, 11), P(l, z0, 5.6)); + seg(ctx, P(l - 0.22, z0, 9.2), P(l + 0.22, z0, 9.2)); + trim(ctx, [lo0, tail, lo1], col, Math.max(0.2, 0.6 * sc(z0))); + top = 17; + break; + } + case "beam": { + for (const o of [-0.4, 0.4]) { + ctx.strokeStyle = "#8a7a52"; + ctx.lineWidth = Math.max(0.12, 0.3 * sc(z0)); + seg(ctx, P(l + o, z0 + 1, 5.2), P(l + o, z0 + 1, 34)); + } + box(ctx, l - 0.5, l + 0.5, z0, z1, LOW_Y, 5.2, { front: "#6a4128", side: "#4a2c1a", top: "#8a5a36" }); + trim(ctx, [P(l - 0.5, z0, LOW_Y), P(l + 0.5, z0, LOW_Y)], col, Math.max(0.25, 0.7 * sc(z0))); + top = 8; + break; + } + case "garg": + gargoyle(ctx, you, c, q, z0, f, col); + top = ["stun", "broken"].includes(c.gargs[q.i].state) ? 0 : (c.gargs[q.i].state === "perch" || c.gargs[q.i].state === "warn" ? 17 : 11); + break; + case "bell": + bell(ctx, c, q, z0, f); + top = 0; + break; + default: + break; + } + // Its glyph, for what to do about it. + if (top) { + const free = []; + if (k.answer === "SWITCH") for (const dir of [-1, 1]) if (q.lane + dir >= 0 && q.lane + dir <= 2 && !openSides.some((o) => o === q.lane + dir)) free.push(dir); + glyph(ctx, q.kind, k.answer, l, z0 + 1, top, words, free); + } + ctx.globalAlpha = 1; + } + + // A gargoyle: perched in the arch above its lane, shuddering, dropping, standing, dazed or broken. + function gargoyle(ctx, you, c, q, z0, f, col) { + const g = c.gargs[q.i]; + const l = q.lane - 1; + const rise = gargRise(g); + const shake = g.state === "warn" ? Math.sin(clock / 22) * 0.18 : 0; + const p = P(l + shake, z0 + 1.5, rise * 1.2 + (g.state === "perch" || g.state === "warn" ? 11 : 0)); + const s = p[2] * HS * 1.4; + const x = p[0]; + const y = p[1]; + if (g.state === "broken") { + ctx.fillStyle = "#59638f"; + for (const [ox, oy, r] of [[-0.6, 0, 0.5], [0.4, 0.05, 0.6], [0, -0.3, 0.4]]) disc(ctx, x + ox * s * 1.3, y + oy * s, r * s * 0.8); + return; + } + // The shadow it will fall on. + if (g.state === "perch" || g.state === "warn" || g.state === "drop") { + const fl = P(l, z0 + 1.5, 0); + ctx.globalAlpha = f * (g.state === "perch" ? 0.18 : 0.45); + ctx.fillStyle = col; + ctx.beginPath(); + ctx.ellipse(fl[0], fl[1], 4.4 * fl[2], 1.3 * fl[2], 0, 0, TAU); + ctx.fill(); + ctx.globalAlpha = f; + } + const dazed = g.state === "stun"; + ctx.fillStyle = dazed ? "#7a84b0" : "#6f7aa8"; + ctx.strokeStyle = "#232a4a"; + ctx.lineWidth = Math.max(0.12, 0.3 * s); + // Wings. + for (const sd of [-1, 1]) { + ctx.beginPath(); + ctx.moveTo(x + sd * s * 0.9, y - s * 2.6); + ctx.lineTo(x + sd * s * 3.5, y - s * (dazed ? 2.2 : 4.4)); + ctx.lineTo(x + sd * s * 3.0, y - s * 1.0); + ctx.lineTo(x + sd * s * 1.0, y - s * 1.2); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + } + // Body, head and horns. + roundish(ctx, x, y - s * 1.6, s * 1.6, s * 2.1); + ctx.fillStyle = dazed ? "#8a94c0" : "#8490c0"; + disc(ctx, x, y - s * 3.5, s * 1.15); + ctx.fillStyle = "#59638f"; + for (const sd of [-1, 1]) { + ctx.beginPath(); + ctx.moveTo(x + sd * s * 0.6, y - s * 4.3); + ctx.lineTo(x + sd * s * 1.1, y - s * 5.6); + ctx.lineTo(x + sd * s * 1.2, y - s * 4.1); + ctx.fill(); + } + const eye = dazed ? "#9ab0ff" : g.state === "perch" ? "#80402c" : "#ff4a30"; + ctx.fillStyle = eye; + for (const sd of [-1, 1]) disc(ctx, x + sd * s * 0.45, y - s * 3.6, s * 0.22); + if (!dazed && (g.state === "stand" || g.state === "drop")) { + glow(ctx, x, y - s * 3.5, 4.5 * s, "255,70,40", 0.45 * f); + ctx.globalAlpha = f; + if (g.hp < 2) { + ctx.strokeStyle = "#10142a"; + ctx.lineWidth = Math.max(0.1, 0.25 * s); + seg(ctx, [x - s * 0.5, y - s * 2.6], [x + s * 0.3, y - s * 0.9]); + } + } + if (dazed) { + ctx.fillStyle = "#ffe48a"; + for (let m = 0; m < 3; m++) disc(ctx, x + Math.cos(clock / 200 + m * 2.1) * s * 1.6, y - s * 5.2 + Math.sin(clock / 200 + m * 2.1) * s * 0.4, s * 0.28); + } + } + function roundish(ctx, x, y, rx, ry) { + ctx.beginPath(); + ctx.ellipse(x, y, Math.max(0.05, rx), Math.max(0.05, ry), 0, 0, TAU); + ctx.fill(); + ctx.stroke(); + } + + // A bell rope: from the vault down to a tassel, the bell up in the dark; rung, it swings. + function bell(ctx, c, q, z0, f) { + const rung = c.bells[q.i]; + const l = q.lane - 1; + const sw = rung ? Math.sin(clock / 90) * 0.18 : 0; + const top = P(l, z0, 34); + const bot = P(l + sw, z0, 5.6); + ctx.strokeStyle = "#b9a374"; + ctx.lineWidth = Math.max(0.3, 1.0 * bot[2]); + seg(ctx, top, bot); + ctx.fillStyle = "#d9b45a"; + disc(ctx, bot[0], bot[1], Math.max(0.4, 0.9 * bot[2])); + const b = P(l + sw * 2, z0, 14); + ctx.fillStyle = rung ? "#ffe9a0" : "#c79a3a"; + ctx.beginPath(); + ctx.moveTo(b[0] - 1.5 * b[2] * HS * 0.8, b[1] + 1.2 * b[2] * HS * 0.8); + ctx.quadraticCurveTo(b[0] - 1.2 * b[2] * HS * 0.8, b[1] - 1.8 * b[2] * HS * 0.8, b[0], b[1] - 1.8 * b[2] * HS * 0.8); + ctx.quadraticCurveTo(b[0] + 1.2 * b[2] * HS * 0.8, b[1] - 1.8 * b[2] * HS * 0.8, b[0] + 1.5 * b[2] * HS * 0.8, b[1] + 1.2 * b[2] * HS * 0.8); + ctx.closePath(); + ctx.fill(); + if (rung) glow(ctx, b[0], b[1], 7 * b[2] + 1, "255,226,140", 0.6 * f); + ctx.globalAlpha = f; + trim(ctx, [P(l - 0.3, z0, 6), P(l + 0.3, z0, 6)], ANSWER_COLORS.SHOOT, 0.3); + if (!rung) glyph(ctx, "bell", "SHOOT", l, z0, 10.5, true, []); + } + + /* --------------------------------------------------------------- souls */ + + // A wax soul: a golden candle flame with a white core; a halo, a gold ring that draws souls in. + function soul(ctx, c, you, s, i) { + const [sx, lane, h, type] = s; + let dz = sx - you.x; + const f = fog(dz); + if (f <= 0.02 || dz < -7) return; + let l = lane - 1; + let hh = h; + if (c.magnet > 0 && dz < 26) { + const k = clamp(1 - dz / 26, 0, 1) ** 2; + l += (c.lane - 1 - l) * k; + hh += (c.h + 2.2 - hh) * k; + dz *= 1 - k * 0.5; + } + const p = P(l, dz, hh + Math.sin(clock / 260 + i) * 0.25); + const r = p[2] * HS; + ctx.globalAlpha = f; + if (type === 1) { + glow(ctx, p[0], p[1], 6 * r + 1, "255,220,120", 0.7 * f); + ctx.globalAlpha = f; + ctx.strokeStyle = "#ffd75a"; + ctx.lineWidth = Math.max(0.2, 0.55 * r); + ctx.beginPath(); + ctx.ellipse(p[0], p[1], 1.5 * r, 0.55 * r, 0, 0, TAU); + ctx.stroke(); + ctx.beginPath(); + ctx.ellipse(p[0], p[1] - 0.2 * r, 1.1 * r, 0.4 * r, 0, 0, TAU); + ctx.stroke(); + ctx.fillStyle = "#fff4c0"; + disc(ctx, p[0], p[1] + 1.1 * r, 0.55 * r); + return; + } + glow(ctx, p[0], p[1], 2.8 * r + 0.4, "255,190,70", 0.55 * f); + ctx.globalAlpha = f; + const w = Math.max(0.18, 0.55 * r); + ctx.fillStyle = "#ffbc3a"; + ctx.beginPath(); + ctx.moveTo(p[0], p[1] - 1.3 * r); + ctx.quadraticCurveTo(p[0] + w * 1.5, p[1] + 0.1 * r, p[0], p[1] + 0.9 * r); + ctx.quadraticCurveTo(p[0] - w * 1.5, p[1] + 0.1 * r, p[0], p[1] - 1.3 * r); + ctx.fill(); + ctx.fillStyle = "#fff6d0"; + ctx.beginPath(); + ctx.ellipse(p[0], p[1] + 0.25 * r, w * 0.55, 0.55 * r, 0, 0, TAU); + ctx.fill(); + } + + /* ------------------------------------------------------------- the pew */ + + // A bolt flying down its lane. + function bolt(ctx, you, s) { + const dz = s.x - you.x; + if (dz < -4 || dz > 120) return; + const lane = s.lane === undefined ? 1 : s.lane; + const p = P(lane - 1, dz, 2.4); + const q = P(lane - 1, dz - 6, 2.4); + ctx.globalAlpha = 1; + ctx.strokeStyle = "rgba(255,244,170,0.55)"; + ctx.lineWidth = Math.max(0.3, 1.1 * p[2]); + ctx.lineCap = "round"; + seg(ctx, p, q); + glow(ctx, p[0], p[1], 4 * p[2] + 0.5, "255,240,150", 0.8); + ctx.globalAlpha = 1; + ctx.fillStyle = "#fffbe0"; + disc(ctx, p[0], p[1], Math.max(0.3, 0.7 * p[2])); + } + + // The pew and YOU on it from behind: runners with sparks, the backrest ahead, the seat, the rear panel, then YOU, + // a little blue square with stick arms, the flashlight out in front and its beam down the aisle. + function hero(ctx, v, you, c) { + const lean = c.lean; + const hx = P(c.lane - 1, 0, 0)[0]; + const lift = c.h * HS; + const gy = GY0; + const slide = c.slide > 0 && c.h <= 0; + const speedK = clamp((c.v - V0) / (V_MAX - V0), 0, 1); + const bob = c.h > 0 ? 0 : Math.sin(clock / 55) * 0.18 * (0.5 + speedK); + const bump = c.bump > 0 ? Math.sin(clock / 18) * 0.5 * (c.bump / BUMP_MS) : 0; + const x = hx + bump; + const y = gy - lift + bob; + const blink = you.safeMs > 0 && Math.floor(v.clock / 90) % 2 === 0; + // Shadow on the floor. + ctx.globalAlpha = 0.4 / (1 + c.h * 0.12); + ctx.fillStyle = "#04050c"; + ctx.beginPath(); + ctx.ellipse(hx, gy + 0.9, 6.2 / (1 + c.h * 0.05), 1.6, 0, 0, TAU); + ctx.fill(); + ctx.globalAlpha = blink ? 0.45 : 1; + ctx.save(); + ctx.translate(x, y); + ctx.rotate(lean * 0.17 + (c.h > 0 ? clamp(c.vh / 260, -0.1, 0.1) : 0)); + // Beam of the flashlight, drawn first so everything of the pew is over it. + ctx.globalCompositeOperation = "lighter"; + const beam = ctx.createLinearGradient ? ctx.createLinearGradient(0, -7, 0, -26) : null; + if (beam && beam.addColorStop) { + beam.addColorStop(0, "rgba(255,236,170,0.5)"); + beam.addColorStop(1, "rgba(255,236,170,0)"); + } + ctx.fillStyle = beam || "rgba(255,236,170,0.2)"; + ctx.beginPath(); + ctx.moveTo(3.4, -7); + ctx.lineTo(1.5, -26); + ctx.lineTo(13, -26); + ctx.closePath(); + ctx.fill(); + ctx.globalCompositeOperation = "source-over"; + // Runners and sparks. + ctx.fillStyle = "#2a1a10"; + ctx.fillRect(-4.7, -0.9, 9.4, 0.9); + if (c.h <= 0) { + ctx.fillStyle = "#ffd36a"; + for (let k = 0; k < 2 + Math.floor(speedK * 5); k++) { + const t = (clock / 120 + k * 0.37) % 1; + const sx = (k % 2 ? 1 : -1) * (3.5 + rnd(k, 3) * 1.2); + disc(ctx, sx + (k % 2 ? 1 : -1) * t * 2, -0.3 - t * 2.2, 0.28 * (1 - t)); + } + } + const sq = slide ? 0.55 : 1; + // Backrest (ahead of him, seen from behind), the seat, the rear panel. + ctx.fillStyle = "#3a2114"; + ctx.fillRect(-5.2, -8.2 * sq - 1, 10.4, 3.1 * sq); + ctx.fillStyle = "#7a4c2c"; + ctx.fillRect(-5.2, -8.2 * sq - 1, 10.4, 0.6); + ctx.fillStyle = "#6a4128"; + ctx.fillRect(-4.6, -3.2, 9.2, 0.8); + ctx.fillStyle = "#4a2c1a"; + ctx.beginPath(); + ctx.moveTo(-4.8, -0.9); + ctx.lineTo(4.8, -0.9); + ctx.lineTo(4.8, -3.1); + ctx.quadraticCurveTo(0, -4.2, -4.8, -3.1); + ctx.closePath(); + ctx.fill(); + ctx.strokeStyle = "#8a5a36"; + ctx.lineWidth = 0.22; + ctx.stroke(); + ctx.fillStyle = "#c9a24a"; + disc(ctx, 0, -2.1, 0.45); + // YOU: legs, arms, the blue square back, the flashlight in the right hand. + const ink = (v.colors && v.colors.ink) || "#1d1a17"; + const body = (v.colors && v.colors.you) || "#206cc3"; + ctx.save(); + ctx.translate(0, -3.2); + ctx.scale(1, sq); + ctx.strokeStyle = ink; + ctx.lineWidth = 0.4; + ctx.lineCap = "round"; + const step = Math.sin(clock / 70) * 0.25 * (c.h > 0 ? 0 : 1); + seg(ctx, [-1.1, -1.2], [-1.4 + step, 0]); + seg(ctx, [1.1, -1.2], [1.4 - step, 0]); + ctx.fillStyle = ink; + ctx.beginPath(); + ctx.ellipse(-1.5 + step, 0.1, 0.8, 0.4, 0, 0, TAU); + ctx.ellipse(1.5 - step, 0.1, 0.8, 0.4, 0, 0, TAU); + ctx.fill(); + ctx.fillStyle = body; + ctx.strokeStyle = ink; + ctx.lineWidth = 0.35; + ctx.fillRect(-3, -7.6, 6, 6.4); + ctx.strokeRect(-3, -7.6, 6, 6.4); + ctx.fillStyle = "rgba(255,255,255,0.18)"; + ctx.fillRect(-2.6, -7.2, 1.4, 5.6); + ctx.fillStyle = ink; + ctx.fillRect(-1.2, -9.0, 2.4, 1.4); + // Arms out ahead, bracing, the light in the right hand. + ctx.lineWidth = 0.45; + seg(ctx, [-3, -5.6], [-4.3, -7.4 + step]); + seg(ctx, [3, -5.6], [4.2, -8.6]); + ctx.fillStyle = "#e8e4d4"; + ctx.fillRect(3.4, -10.2, 1.6, 2); + ctx.fillStyle = "#fff4c0"; + disc(ctx, 4.2, -10.4, 0.8); + ctx.restore(); + ctx.restore(); + ctx.globalAlpha = 1; + // Garlic and the halo's ring around him. + if (c.magnet > 0) { + ctx.strokeStyle = "rgba(255,215,90,0.8)"; + ctx.lineWidth = 0.35; + ctx.beginPath(); + ctx.ellipse(hx, y - 5, 8 + Math.sin(clock / 120) * 0.6, 7, 0, 0, TAU); + ctx.stroke(); + } + } + + /* ----------------------------------------------------------- the frame */ + + // Dust in the shafts, and the speed: streaks and a vignette that rise with the ride's pace. + function air(ctx, you, c) { + ctx.fillStyle = "#ffdca0"; + for (let i = 0; i < 46; i++) { + const zz = ((rnd(i, 1) * SEE - you.x * 0.9) % SEE + SEE) % SEE; + const l = (rnd(i, 2) - 0.5) * 8; + const h = 1 + rnd(i, 3) * 20; + const p = P(l + Math.sin(clock / 1700 + i) * 0.2, zz, h + Math.cos(clock / 1300 + i * 2) * 0.3); + ctx.globalAlpha = fog(zz) * (0.1 + 0.3 * rnd(i, 4)) * (0.6 + 0.4 * beat); + disc(ctx, p[0], p[1], Math.max(0.08, 0.28 * p[2])); + } + const k = clamp((c.v - V0) / (V_MAX - V0), 0, 1); + ctx.globalAlpha = 1; + // Streaks from the vanishing point, longer and brighter the faster it goes. + ctx.lineCap = "round"; + for (let i = 0; i < 26; i++) { + const a = rnd(i, 7) * TAU; + const run = (you.x * 0.02 * (0.5 + rnd(i, 8)) + rnd(i, 9)) % 1; + const r0 = 14 + run * run * 66; + const r1 = r0 + 3 + k * 22 * run; + ctx.strokeStyle = `rgba(200,220,255,${(0.1 + 0.6 * k) * run})`; + ctx.lineWidth = 0.15 + 0.5 * run; + ctx.beginPath(); + ctx.moveTo(VPX + Math.cos(a) * r0 * 1.5, HOR + 8 + Math.sin(a) * r0 * 0.75); + ctx.lineTo(VPX + Math.cos(a) * r1 * 1.5, HOR + 8 + Math.sin(a) * r1 * 0.75); + ctx.stroke(); + } + ctx.fillStyle = rgrad(ctx, VPX, 30, 76, [[0.45, "rgba(3,4,14,0)"], [1, `rgba(3,4,14,${0.3 + 0.4 * k})`]]); + ctx.fillRect(0, 0, FW, FH); + } + + function paint(ctx, v) { + const { round } = v; + const c = round.runner; + const you = round.you; + FW = v.g.FIELD_W; + FH = v.g.FIELD_H; + clock = v.fx && typeof v.fx.clock === "number" ? v.fx.clock : v.clock || 0; + beat = pulse(clock); + camL = (c.lane - 1) * 0.55; + near = NEAR - 6 * clamp((c.v - V0) / (V_MAX - V0), 0, 1); + const R = round.spec.ride; + backdrop(ctx); + const j1 = Math.floor((you.x + SEE) / CELL); + const j0 = Math.floor((you.x - 10) / CELL); + const cues = cuesOf(R); + const flank = new Map(); + // Which lanes of a block's row stay open, for the arrows. + for (const q of cues) { + if (KINDS[q.kind].answer !== "SWITCH") continue; + const key = Math.round(q.x); + if (!flank.has(key)) flank.set(key, []); + flank.get(key).push(q.lane); + } + // The things and souls bucketed by the cell their near end stands in, drawn far to near. + const lo = (list, get, x) => { + let a = 0; + let b = list.length; + while (a < b) { + const m = (a + b) >> 1; + if (get(list[m]) < x) a = m + 1; + else b = m; + } + return a; + }; + const first = lo(cues, (q) => q.x, you.x - 12); + const sFirst = lo(R.souls, (s) => s[0], you.x - 8); + const after = []; + // The cues to draw, in order of depth, with the nearest (already passed) after the hero. + const draw = []; + for (let i = first; i < cues.length && cues[i].x < you.x + SEE; i++) draw.push(cues[i]); + for (let i = Math.max(0, first - 8); i < first; i++) if (cues[i].end > you.x - 10) draw.push(cues[i]); + draw.sort((a, b) => b.x - a.x); + // Count the "words" in order of approach, nearest first. + const order = {}; + for (const q of cues) { + const a = KINDS[q.kind].answer; + order[q.id] = ((order[a] = (order[a] || 0) + 1) <= 3); + } + let di = 0; + let si = Math.min(R.souls.length, sFirst + 400); + // Souls to draw, nearest first. + while (si > sFirst && R.souls[si - 1][0] > you.x + SEE) si--; + const soulsNear = []; + for (let j = j1; j >= j0; j--) { + cell(ctx, you, c, j); + const zEnd = j * CELL; + // Things and souls whose near end lies from this cell's start to the next one's. + while (di < draw.length && draw[di].x >= zEnd) { + const q = draw[di++]; + if ((q.x + q.end) / 2 < you.x - 1) after.push(q); + else thing(ctx, you, c, q, flank.get(Math.round(q.x)) || [], order[q.id]); + } + while (si > sFirst && R.souls[si - 1][0] >= zEnd) { + si--; + if (c.souls[si] === 0) soulsNear.push(si); + } + // Draw this cell's souls (far end first) now. + while (soulsNear.length) { + const n = soulsNear.shift(); + soul(ctx, c, you, R.souls[n], n); + } + } + while (di < draw.length) { + const q = draw[di++]; + if ((q.x + q.end) / 2 < you.x - 1) after.push(q); + else thing(ctx, you, c, q, flank.get(Math.round(q.x)) || [], order[q.id]); + } + for (const s of round.shots) if (!s.arm && !s.free) bolt(ctx, you, s); + hero(ctx, v, you, c); + for (const q of after) thing(ctx, you, c, q, flank.get(Math.round(q.x)) || [], false); + air(ctx, you, c); + ctx.globalAlpha = 1; + } + + return { paint }; +} diff --git a/src/web-console/public/activities/ghoul-pew.js b/src/web-console/public/activities/ghoul-pew.js new file mode 100644 index 0000000..cb4fb7c --- /dev/null +++ b/src/web-console/public/activities/ghoul-pew.js @@ -0,0 +1,475 @@ +// Plan2Code Web Console - Ghoul Rush's Holy Roller, its rules: the Chapel's bonus round. YOU surf a runaway church pew down the nave's aisle, seen from behind, in three lanes that speed up the whole way: change lane, jump the kneelers, candle stands, flagstone cracks and crypt hatches, slide under the censers, banners and fallen beams, shoot the gargoyles that drop from the arches (or ring a bell rope to stun them), and gather the wax souls for a combo. A stage pack that ghoul.js plugs in. +// +// An endless-runner (a Subway Surfers) rather than a side-view ride, so it is handed a kit `k` of +// ghoul.js's own helpers like the Coffin Sled (ghoul-sled.js) but never imports ghoul.js. Pack fields +// used: `ride` (a hook that moves Planny himself, so no key walks him), `place` (Planny put down in a +// room: a room set up or a respawn) and `target` (a bolt strikes something that is no monster: a +// gargoyle or a bell rope). It adds no monster, boss or hazard kind, and it draws NO random number. +// Its state lives in the shared ride slot `round.runner` (`id` "pew"), and its room says `runner: "pew"`. +// +// THE FIELD IS THE ART'S ALONE: ghoul-draw.js hands the whole field to pewArt's `field` (a pseudo-3D +// view down the aisle from behind the pew), so Planny's (x, y) here is only the distance run (`you.x`) and +// the floor under it; the lane and height are the pew's own (`c.lane`, `c.h`). +// +// THE COURSE (spec.ride, built by ghoul-pew-course.js, written in seconds and laid by the ramp): +// +// - `items`: [x, lane, kind, len] (see KINDS: SWITCH the lane for a block, JUMP a low thing, SLIDE under +// a high one, SHOOT a gargoyle or a bell rope); `souls`: [x, lane, h, type] (type 1 a halo, a magnet); +// `checks` and `finish` (the distance where the ride ends) and `time` (the clock, ms) and `how`. +// - The ride speeds up with the distance covered, from V0 to about 80 over RIDE_S (speedAt): a clear +// ramp, so a run is about 66 s whatever you do. The art reads `c.v` for its speed lines and vignette. +// +// THE PEW (`round.runner`, null in any other room): { id, room, v, lane (a float, 0 to 2, sliding +// to `laneTo`), lean, h (height over the aisle), vh, slide (ms left), dive, bump, check, done, +// souls (0 open, 1 taken, 2 missed), got, combo, best, mult, comboMs, magnet, gargs, bells, hit, ... }. +// LEFT and RIGHT (a press) change lane (LANE_RATE lanes a second; a press at an edge lane bumps the +// wall, `pewBump`), UP jumps (JUMP_V against JUMP_G, about 6 high and two thirds of a second), DOWN slides +// for SLIDE_MS (in the air it fast-falls and slides on landing), hold fire to shoot straight down the lane. +// +// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the pew rolls on: it is +// shoved to the nearest calm lane and blinks safe for BONUS_SAFE_MS; the last heart gone ends the round +// with nothing, at once. A counted hit breaks the combo. Causes (the game shares them, all prefixed): +// see KINDS. A gargoyle shot (two bolts) or stunned by a bell, a bell rung and the souls taken are +// the grade's: `perf.total` obstacles, `perf.hits` the ids that cost a heart, `perf.acts` against +// ACTS_GOAL, and `perf.steady` once SOUL_SHARE of the souls laid out are taken. +// +// WHAT THE ART READS: `spec.ride`, `round.runner` (above; gargs: [{ state "perch"|"warn"|"drop"|"stand"| +// "stun"|"broken", t, hp }], bells: [rung]), `round.you` (`x`, `safeMs`), `round.shots` ({ x, lane }), the +// events in EVENTS. + +import { ACC, COURSE, PEW_START, RIDE_S, V0, V_MAX, speedAt, xAt } from "./ghoul-pew-course.js"; + +export { ACC, COURSE, PEW_START, RIDE_S, V0, V_MAX, speedAt, xAt }; + +const freeze = (o) => Object.freeze(o); +const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v)); + +export const MONSTERS = freeze({}); + +// Every event this pack puts on the field, for the art and the sounds to answer. +export const EVENTS = freeze([ + "pewLane", "pewBump", "pewJump", "pewLand", "pewSlide", "pewDive", "pewSoul", "pewHalo", "pewCrash", "pewCheck", "pewFinish", + "pewGargWarn", "pewGargDrop", "pewGargChip", "pewGargHit", "pewBell", "pewSpeed", +]); + +// The pew. Speeds are units down the aisle a second. +export const LANES = 3; +export const LANE_RATE = 6.5; +export const LANE_HIT = 0.5; +export const HIT_Z = 1.1; +export const JUMP_V = 36; +export const JUMP_G = 110; +export const FAST_FALL = -62; +export const STAND_H = 4.4; +export const SLIDE_H = 2; +export const SLIDE_MS = 700; +export const BUMP_MS = 180; +// The speeds at which the organ swells: the ride is picking up. +export const SWELLS = freeze([44, 54, 64, 74]); +// The things. `d` the depth of one (a row of cracks says its own), `h` the height of a low one +// (clear it with your feet over `h`), `low` the underside of a high one over the aisle. +export const LOW_Y = 2.8; +export const KINDS = freeze({ + pillar: freeze({ answer: "SWITCH", d: 3.2, cause: "pewPillar" }), + confessional: freeze({ answer: "SWITCH", d: 7, cause: "pewConfessional" }), + pewx: freeze({ answer: "SWITCH", d: 3.6, cause: "pewCrosswise" }), + kneeler: freeze({ answer: "JUMP", d: 3.2, h: 2, cause: "pewKneeler" }), + stand: freeze({ answer: "JUMP", d: 2.2, h: 3.4, cause: "pewCandle" }), + cracks: freeze({ answer: "JUMP", d: 7, h: 0.8, cause: "pewFlagstone" }), + hatch: freeze({ answer: "JUMP", d: 5.5, h: 0.8, cause: "pewHatch" }), + censer: freeze({ answer: "SLIDE", d: 2.6, low: LOW_Y, cause: "pewCenser" }), + banner: freeze({ answer: "SLIDE", d: 1.8, low: LOW_Y, cause: "pewBanner" }), + beam: freeze({ answer: "SLIDE", d: 3, low: LOW_Y, cause: "pewBeam" }), + garg: freeze({ answer: "SHOOT", d: 3, h: 5, cause: "pewGargoyle" }), + bell: freeze({ answer: "SHOOT", d: 1.6, cause: "" }), +}); +// The gargoyles: wake GARG_LEAD_S seconds short, shudder, drop from GARG_PERCH up, take GARG_HP bolts. +export const GARG_LEAD_S = 1.55; +export const GARG_WARN_MS = 600; +export const GARG_DROP_MS = 260; +export const GARG_PERCH = 14; +export const GARG_HP = 2; +export const GARG_POINTS = 150; +// A bell rung stuns every gargoyle still ahead of the pew within BELL_S seconds of the ride beyond the bell's rope. +export const BELL_S = 3.4; +export const BELL_POINTS = 100; +// The wax souls: a combo of COMBO_STEP in a row adds one to the multiplier (to MULT_MAX), COMBO_MS to the next. +export const SOUL_POINTS = 10; +export const HALO_POINTS = 50; +export const COMBO_STEP = 8; +export const MULT_MAX = 5; +export const COMBO_MS = 2200; +export const MAG_MS = 4500; +export const MAG_Z = 26; +export const SOUL_SHARE = 0.6; +// The shots at things (gargoyles shot or stunned, bells rung) worth a die. +export const ACTS_GOAL = 6; + +export const multOf = (n) => Math.min(MULT_MAX, 1 + Math.floor(n / COMBO_STEP)); + +// Notes for a bonus round that cue `id` cost a heart (once each). +function noteHit(round, id) { + const b = round.bonusRound; + if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id); +} + +// Every thing in the course as a cue, by x: { id, kind, i (among its kind), x, lane, len, end, answer }. Built once. +const CUES = new WeakMap(); +export function cuesOf(R) { + let cues = CUES.get(R); + if (!cues) { + const seen = {}; + cues = R.items.map(([x, lane, kind, len]) => { + const i = seen[kind] || 0; + seen[kind] = i + 1; + const d = len || KINDS[kind].d; + return freeze({ id: `${kind}${i}`, kind, i, x, lane, len: d, end: x + d, answer: KINDS[kind].answer }); + }); + CUES.set(R, freeze(cues)); + cues = CUES.get(R); + } + return cues; +} +// The cues that count for the grade (the bells are only for shooting). +export const countedOf = (R) => cuesOf(R).filter((q) => q.kind !== "bell"); +export const gargsOf = (R) => cuesOf(R).filter((q) => q.kind === "garg"); +export const bellsOf = (R) => cuesOf(R).filter((q) => q.kind === "bell"); +export const soulTotal = (R) => R.souls.filter((s) => s[3] === 0).length; + +/* -------------------------------------------------------------- placing */ + +// A fresh set of the course's creatures: each gargoyle perched, each bell hanging. What was shot, +// stunned or rung stays so (`old`, the pew of an earlier try in the same room). +function things(R, old) { + const keep = (s) => s === "broken" || s === "stun"; + return { + gargs: gargsOf(R).map((q, i) => ({ state: old && old.gargs[i] && keep(old.gargs[i].state) ? old.gargs[i].state : "perch", t: 0, hp: GARG_HP })), + bells: bellsOf(R).map((q, i) => Boolean(old && old.bells[i])), + souls: old ? old.souls : R.souls.map(() => 0), + }; +} + +// Planny put down in the room: on the pew at the start of a ride, or at the last checkpoint +// passed (the same room). +function place(round, k) { + const R = round.spec.ride; + if (!R || R.runner !== "pew") { + // (Another ride's state in the shared slot is not ours to touch.) + if (round.runner && round.runner.id === "pew") round.runner = null; + return; + } + const again = round.runner && round.runner.id === "pew" && round.runner.room === round.room; + const old = again ? round.runner : null; + const check = again ? round.runner.check : -1; + const x = check >= 0 ? R.checks[check] : round.spec.start; + const set = things(R, old); + Object.assign(round.you, { x, y: k.groundAt(round.spec, x), vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 }); + // Souls laid before the checkpoint are behind us now. + const next = R.souls.findIndex((s, i) => s[0] >= x - 1 || (set.souls[i] = set.souls[i] || 2, false)); + round.runner = { + id: "pew", room: round.room, check, v: speedAt(x), lane: 1, laneTo: 1, lean: 0, h: 0, vh: 0, slide: 0, dive: false, bump: 0, bumpDir: 0, + hl: false, hr: false, hd: false, done: false, swell: SWELLS.findIndex((s) => s > speedAt(x)) < 0 ? SWELLS.length : SWELLS.findIndex((s) => s > speedAt(x)), + got: old ? old.got : 0, combo: 0, best: old ? old.best : 0, mult: 1, comboMs: 0, magnet: 0, sNext: next < 0 ? R.souls.length : next, hit: {}, shove: 0, + ...set, + }; + const b = round.bonusRound; + if (b && !b.perf.total) { + b.perf.total = countedOf(R).length; + b.perf.steady = false; + b.perf.goal = ACTS_GOAL; + } +} + +/* ------------------------------------------------------------ the ride */ + +// The pew's motion for one slice. Returns true once it has moved Planny (every slice of a ride); +// false once the ride is over. +function ride(round, ms, k) { + const R = round.spec.ride; + const c = round.runner; + if (!R || R.runner !== "pew" || !c || c.id !== "pew" || c.done) return false; + const you = round.you; + const inp = round.input; + const dt = ms / 1000; + const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, lane: c.lane, h: c.h, ...extra }); + c.v = speedAt(you.x); + while (c.swell < SWELLS.length && c.v >= SWELLS[c.swell]) ev("pewSpeed", { n: c.swell++, v: c.v }); + steerShots(round, c); + // Lanes: a press (not a held key) moves one lane; at the edge it bumps the wall. + const left = Boolean(inp.left); + const right = Boolean(inp.right); + for (const [now, was, dir] of [[left, c.hl, -1], [right, c.hr, 1]]) { + if (!now || was) continue; + const to = c.laneTo + dir; + if (to < 0 || to >= LANES) { + c.bump = BUMP_MS; + c.bumpDir = dir; + ev("pewBump", { dir }); + } else { + c.laneTo = to; + ev("pewLane", { dir, to }); + } + } + c.hl = left; + c.hr = right; + const dl = c.laneTo - c.lane; + const step = LANE_RATE * dt; + c.lane = Math.abs(dl) <= step ? c.laneTo : c.lane + Math.sign(dl) * step; + c.lean += (clamp(c.laneTo - c.lane, -1, 1) - c.lean) * Math.min(1, dt * 16); + c.bump = Math.max(0, c.bump - ms); + // Jump and slide. + const ground = c.h <= 0 && c.vh <= 0; + if (inp.jump > 0 && ground) { + inp.jump = 0; + c.vh = JUMP_V; + c.h = 0.001; + c.slide = 0; + ev("pewJump"); + } else if (inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms); + const down = Boolean(inp.down); + if (down && !c.hd) { + if (c.h <= 0 && c.vh <= 0) { + if (c.slide <= 0) ev("pewSlide"); + c.slide = SLIDE_MS; + } else if (!c.dive) { + c.dive = true; + c.vh = Math.min(c.vh, FAST_FALL); + ev("pewDive"); + } + } + c.hd = down; + c.slide = Math.max(0, c.slide - ms); + if (c.h > 0 || c.vh > 0) { + c.vh = Math.max(-120, c.vh - JUMP_G * dt); + c.h += c.vh * dt; + if (c.h <= 0) { + ev("pewLand", { big: c.vh < -45 }); + c.h = 0; + c.vh = 0; + if (c.dive) { + c.slide = SLIDE_MS; + ev("pewSlide"); + } + c.dive = false; + } + } + you.x += c.v * dt; + Object.assign(you, { y: k.groundAt(round.spec, you.x), vy: c.vh, state: c.h > 0 ? "air" : "run", ducking: c.slide > 0, face: 1 }); + if (you.x >= R.finish) return finish(round, c, R, k); + while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) { + c.check++; + ev("pewCheck", { n: c.check + 1 }); + } + obstacles(round, c, R, k); + creatures(round, c, R, ms); + souls(round, c, R, ms); + return true; +} + +// The ride is over: Planny steps to the door, which the next slice walks through, and the card shows. +function finish(round, c, R, k) { + const you = round.you; + c.done = true; + round.hasKey = true; + Object.assign(you, { x: round.spec.door, y: k.groundAt(round.spec, round.spec.door), vy: 0, state: "run", ducking: false }); + const b = round.bonusRound; + const share = soulShare(R, c); + if (b) b.perf.steady = share >= SOUL_SHARE; + round.events.push({ type: "pewFinish", x: you.x, y: you.y, share, best: c.best, got: c.got }); + return true; +} + +export const soulShare = (R, c) => c.got / Math.max(1, soulTotal(R)); + +// A bolt flies straight down its lane, level: the lane is the pew's at the moment it is fired. +function steerShots(round, c) { + for (const s of round.shots) { + if (s.arm || s.free) continue; + if (s.lane === undefined) s.lane = clamp(Math.round(c.lane), 0, LANES - 1); + s.vy = 0; + s.y = round.you.y + 2.4; + } +} + +// Whether the pew, in its lane and at its height, is in a cue's way right now. +export function touching(c, q, x) { + const kind = KINDS[q.kind]; + if (q.kind === "bell" || Math.abs(c.lane - q.lane) >= LANE_HIT) return false; + if (x < q.x - HIT_Z || x > q.end + HIT_Z) return false; + if (kind.answer === "SWITCH") return true; + if (kind.answer === "JUMP") return c.h < kind.h; + if (kind.answer === "SLIDE") return !(c.slide > 0 && c.h < 0.5); + const g = c.gargs[q.i]; + return g.state === "stand" || (g.state === "drop" && g.t <= GARG_DROP_MS * 0.3); +} + +// The lane nearest `from` with nothing in the way a moment before and after `x`. +export function calmLane(R, c, x, from) { + const gone = (q) => q.kind === "garg" && (c.gargs[q.i].state === "broken" || c.gargs[q.i].state === "stun"); + const open = (lane) => !cuesOf(R).some((q) => q.lane === lane && q.kind !== "bell" && q.end > x - 4 && q.x < x + 14 && !gone(q)); + const order = [0, 1, 2].sort((a, b) => Math.abs(a - from) - Math.abs(b - from) || a - b); + return order.find(open) ?? Math.round(from); +} + +// What the pew runs into. A counted hit shoves it to a calm lane; it does the heart's cost through k.struck. +function obstacles(round, c, R, k) { + const you = round.you; + for (const q of cuesOf(R)) { + if (q.x > you.x + 8) break; + if (q.end < you.x - 8 || c.hit[q.id]) continue; + if (!touching(c, q, you.x)) continue; + if (!k.struck(round, KINDS[q.kind].cause)) continue; + c.hit[q.id] = true; + const lost = c.combo; + c.combo = 0; + c.mult = 1; + c.comboMs = 0; + noteHit(round, q.id); + c.laneTo = calmLane(R, c, you.x, c.lane); + c.vh = Math.min(c.vh, 0); + round.events.push({ type: "pewCrash", what: q.kind, id: q.id, x: you.x, y: you.y, lane: q.lane, h: c.h, lost }); + return; + } +} + +// The gargoyles in the arches wake when the pew comes near: shudder, drop, then stand in the lane. +function creatures(round, c, R, ms) { + const you = round.you; + gargsOf(R).forEach((q, i) => { + const g = c.gargs[i]; + if (g.state === "perch") { + if ((q.x - you.x) / c.v < GARG_LEAD_S && q.end > you.x) { + Object.assign(g, { state: "warn", t: GARG_WARN_MS }); + round.events.push({ type: "pewGargWarn", x: q.x, y: you.y, lane: q.lane }); + } + } else if (g.state === "warn" || g.state === "drop") { + g.t -= ms; + if (g.t > 0) return; + if (g.state === "warn") Object.assign(g, { state: "drop", t: GARG_DROP_MS }); + else { + Object.assign(g, { state: "stand", t: 0 }); + round.events.push({ type: "pewGargDrop", x: q.x, y: you.y, lane: q.lane }); + } + } + }); +} + +// The wax souls: taken in passing (lane and height), or pulled in by a halo's magnet. +function souls(round, c, R, ms) { + const you = round.you; + const S = R.souls; + c.magnet = Math.max(0, c.magnet - ms); + c.comboMs = Math.max(0, c.comboMs - ms); + if (!c.comboMs && c.combo) { + c.combo = 0; + c.mult = 1; + } + const body = c.slide > 0 ? SLIDE_H : STAND_H; + const reach = c.magnet > 0 ? MAG_Z : 1; + for (let i = c.sNext; i < S.length && S[i][0] <= you.x + reach; i++) { + if (c.souls[i] !== 0) continue; + const [sx, lane, h, type] = S[i]; + const pulled = c.magnet > 0 && Math.abs(lane - c.lane) <= 1.05 && sx - you.x <= MAG_Z; + const met = sx <= you.x + 1; + if (!pulled && !met) continue; + const hit = pulled || (Math.abs(lane - c.lane) < 0.6 && h >= c.h - 0.8 && h <= c.h + body + 0.8); + if (!hit) { + c.souls[i] = 2; + continue; + } + c.souls[i] = 1; + if (type === 1) { + c.magnet = MAG_MS; + round.score += HALO_POINTS; + round.events.push({ type: "pewHalo", x: sx, y: you.y, lane, h, points: HALO_POINTS }); + continue; + } + c.got++; + c.combo++; + c.best = Math.max(c.best, c.combo); + c.comboMs = COMBO_MS; + const was = c.mult; + c.mult = multOf(c.combo); + round.score += SOUL_POINTS * c.mult; + round.events.push({ type: "pewSoul", x: sx, y: you.y, lane, h, combo: c.combo, mult: c.mult, up: c.mult > was }); + const b = round.bonusRound; + if (b) b.perf.steady = soulShare(R, c) >= SOUL_SHARE; + } + while (c.sNext < S.length && (c.souls[c.sNext] !== 0 || S[c.sNext][0] < you.x - 2)) { + if (c.souls[c.sNext] === 0) c.souls[c.sNext] = 2; + c.sNext++; + } +} + +/* ------------------------------------------------------------- targets */ + +// How high a gargoyle is over the aisle: GARG_PERCH perched, falling as it drops, 0 standing. +export function gargRise(g) { + if (g.state === "drop") return GARG_PERCH * clamp(g.t / GARG_DROP_MS, 0, 1); + return g.state === "stand" || g.state === "stun" || g.state === "broken" ? 0 : GARG_PERCH; +} + +// A bolt into something to shoot: a gargoyle falling or standing, a bell rope. True when one took it. +function pewShot(round, s) { + const R = round.spec.ride; + const c = round.runner; + if (!R || R.runner !== "pew" || !c || c.id !== "pew") return false; + if (s.lane === undefined) s.lane = clamp(Math.round(c.lane), 0, LANES - 1); + const x0 = s.q === undefined ? s.x - 3 : s.q; + s.q = s.x; + const lo = Math.min(x0, s.x) - 0.6; + const hi = Math.max(x0, s.x) + 0.6; + const over = (q) => q.lane === s.lane && q.end >= lo && q.x <= hi; + const award = (n) => { + round.score += n * c.mult; + if (round.bonusRound) round.bonusRound.perf.acts++; + }; + const gs = gargsOf(R); + for (let i = 0; i < gs.length; i++) { + const g = c.gargs[i]; + if ((g.state !== "drop" && g.state !== "stand") || !over(gs[i])) continue; + const q = gs[i]; + if (--g.hp > 0) { + round.events.push({ type: "pewGargChip", x: q.x, y: round.you.y, lane: q.lane, hp: g.hp }); + return true; + } + Object.assign(g, { state: "broken", t: 0 }); + award(GARG_POINTS); + round.events.push({ type: "pewGargHit", x: q.x, y: round.you.y, lane: q.lane, points: GARG_POINTS * c.mult }); + return true; + } + const bs = bellsOf(R); + for (let i = 0; i < bs.length; i++) { + if (c.bells[i] || !over(bs[i])) continue; + const q = bs[i]; + c.bells[i] = true; + // Every gargoyle still to come (or standing), up to BELL_S seconds of ride beyond the rope, is stunned. + let stunned = 0; + gs.forEach((gq, j) => { + const g = c.gargs[j]; + if (g.state !== "broken" && g.state !== "stun" && gq.end > round.you.x && gq.x <= q.x + c.v * BELL_S) { + Object.assign(g, { state: "stun", t: 0 }); + stunned++; + } + }); + award(BELL_POINTS); + if (round.bonusRound) round.bonusRound.perf.acts += stunned; + round.events.push({ type: "pewBell", x: q.x, y: round.you.y, lane: q.lane, points: BELL_POINTS * c.mult, stunned }); + return true; + } + return false; +} + +export const PEW = freeze({ + id: "pew", + monsters: MONSTERS, + walkers: freeze([]), + zombies: freeze([]), + stackers: freeze([]), + climbers: freeze([]), + act: freeze({}), + horde: freeze({}), + ride: freeze([ride]), + place: freeze([place]), + target: pewShot, +}); diff --git a/src/web-console/public/activities/ghoul-picker-draw.js b/src/web-console/public/activities/ghoul-picker-draw.js index 81619bb..bb23a71 100644 --- a/src/web-console/public/activities/ghoul-picker-draw.js +++ b/src/web-console/public/activities/ghoul-picker-draw.js @@ -7,7 +7,7 @@ // How much taller than its box a boss is drawn (the Groundskeeper's hat and // scythe rise past his head), so the picture leaves room for it. -const REACH = Object.freeze({ keeper: 1.15, choirmaster: 1.1, matron: 1.05, beast: 1.38, frostwidow: 1.0 }); +export const REACH = Object.freeze({ keeper: 1.15, choirmaster: 1.1, matron: 1.05, beast: 1.38, frostwidow: 1.0 }); export function pickerArt(d) { const { lookOf, label, roundRect, circle, BOSS_ART, drawGourdFire, GOLD } = d; diff --git a/src/web-console/public/activities/ghoul-powers.js b/src/web-console/public/activities/ghoul-powers.js index 3b41d1c..0e8e1d1 100644 --- a/src/web-console/public/activities/ghoul-powers.js +++ b/src/web-console/public/activities/ghoul-powers.js @@ -58,6 +58,8 @@ export const POWERS = Object.freeze({ floss: Object.freeze({ name: "Cotton Candy", blurb: "Sticky bolts slow what they hit", color: "#ff9ad5", ms: 10000, weight: 3, stage: "carnival" }), // Found only in The Frozen Lake: no sliding on the ice, no freezing, and thin ice you stand on cracks at half speed. cocoa: Object.freeze({ name: "Hot Cocoa", blurb: "No sliding, no freezing", color: "#c8793a", ms: 10000, weight: 3, stage: "frozen" }), + // Found only in Gallows Bog: the sinking mud never slows or holds you. + boots: Object.freeze({ name: "Stilt Boots", blurb: "The mud lets you go", color: "#b08d4f", ms: 10000, weight: 3, stage: "bog" }), // The secondary weapons, used by tapping fire twice (ghoul-arms.js has what each one does and ghoul-arms-draw.js how it looks). // Each is a bundle of `sticks` going into the bag up to `max`. Weight 0: pickPower never picks one, so they come // from a room's `items` and from their own band of a kill's drop roll (armDrop). No `stage`: common, anywhere. @@ -74,10 +76,11 @@ export const POWERS = Object.freeze({ pie: Object.freeze({ name: "Custard Pie", blurb: "Splat and stun a crowd", color: "#f5e6a8", weight: 0, arm: true, sticks: 2, max: 4, stage: "carnival" }), trap: Object.freeze({ name: "Silver Bear Trap", blurb: "Set at your feet, it snaps", color: "#d0dcea", weight: 0, arm: true, sticks: 2, max: 3, stage: "village" }), flare: Object.freeze({ name: "Road Flare", blurb: "Burns a patch, melts the veil", color: "#ff4a2e", weight: 0, arm: true, sticks: 2, max: 4, stage: "frozen" }), + harpoon: Object.freeze({ name: "Harpoon", blurb: "Pierces, reaches under water", color: "#7fa8b0", weight: 0, arm: true, sticks: 2, max: 4, stage: "bog" }), }); const POWER_ORDER = Object.freeze(Object.keys(POWERS)); // The word on a timed power-up's pill. -export const PILL_WORDS = Object.freeze({ spread: "SPREAD", rapid: "RAPID", lantern: "LANTERN", wings: "WINGS", bell: "BELL", silver: "SILVER", shears: "SHEARS", holy: "HOLY", salts: "SALTS", saw: "SAW", bane: "BANE", hat: "HARD HAT", floss: "FLOSS", cocoa: "COCOA" }); +export const PILL_WORDS = Object.freeze({ spread: "SPREAD", rapid: "RAPID", lantern: "LANTERN", wings: "WINGS", bell: "BELL", silver: "SILVER", shears: "SHEARS", holy: "HOLY", salts: "SALTS", saw: "SAW", bane: "BANE", hat: "HARD HAT", floss: "FLOSS", cocoa: "COCOA", boots: "BOOTS" }); // The power-ups that run on a timer, in the order their pills show. export const TIMED = Object.freeze(POWER_ORDER.filter((k) => POWERS[k].ms)); // Bat wings never flap with a surface this close under a fall. @@ -85,7 +88,7 @@ export const FLAP_CLEAR = 4; export const HOURGLASS_MS = 20000; // Each stage's own weapon (the Mine's own is Dynamite). -export const STAGE_ARMS = Object.freeze({ manor: "ball", wing: "skillet", graveyard: "salt", grounds: "sickle", chapel: "fork", sanatorium: "flash", village: "trap", mine: "dyn", carnival: "pie", frozen: "flare" }); +export const STAGE_ARMS = Object.freeze({ manor: "ball", wing: "skillet", graveyard: "salt", grounds: "sickle", chapel: "fork", sanatorium: "flash", village: "trap", mine: "dyn", carnival: "pie", frozen: "flare", bog: "harpoon" }); // A kill's drop roll (ghoul.js) goes to a weapon in a band of ARM_DROP past the // power-ups and candy, no extra draw, so it shifts no other roll: about one every // two rooms. Where in the band it fell picks which: the stage's own first @@ -210,6 +213,10 @@ export function pickups(round, ms, kit) { if (spec.key && !round.hasKey && near(spec.key[0], spec.key[1] + 1.6, 1.2)) { round.hasKey = true; round.events.push({ type: "key", x: spec.key[0], y: spec.key[1] + 1.6 }); + if (spec.darkOnKey) { + round.dark = true; + round.events.push({ type: "keyDark", x: spec.key[0], y: spec.key[1] + 1.6 }); + } } } @@ -275,7 +282,7 @@ export function mercyKind(round, n, kit) { export function mercySpot(round, kit) { const { spec, you } = round; const dir = you.face >= 0 ? 1 : -1; - const bad = (x) => [...(spec.belts || []), ...(spec.water || [])].some((s) => x >= s[0] - 1 && x <= s[1] + 1); + const bad = (x) => [...(spec.belts || []), ...(spec.water || []), ...(spec.mud || [])].some((s) => x >= s[0] - 1 && x <= s[1] + 1); const firm = (x) => { const s = kit.footing(round, x, you.y); return s && (s.shelf < 0 || spec.shelves[s.shelf][3] !== "crumble") ? s : null; diff --git a/src/web-console/public/activities/ghoul-rooms.js b/src/web-console/public/activities/ghoul-rooms.js index 785aaab..8425300 100644 --- a/src/web-console/public/activities/ghoul-rooms.js +++ b/src/web-console/public/activities/ghoul-rooms.js @@ -47,6 +47,7 @@ // - `chandeliers`: the x of each one; it shakes and drops when you run under. // - `boss`: null, or the boss that waits at the room's end ("gourd", // "bones" or a stage pack's), whose arena is the last FIELD_W of the room. +// - `darkOnKey`: the room's lights go out for good when you take its key. // - `toll`: the bell's period in ms, for a room where the bell tolls (the // Chapel's tower and choir): about every `toll` it swings, then rings and // freezes everything on screen for a second, you included. @@ -65,6 +66,10 @@ // lower (ghoul.js), and blind crawlers hear his steps from further. // The Mine's cage lifts are spawn rows too: ["cage", x, lowest y, highest y] // (the cage's bottom), a floor board Planny rides up and down. +// - `mud`: [x0, x1] spans of the floor that are sinking mud (Gallows Bog): on +// the floor in one Planny keeps sinking while he stands, his run and his +// jump sagging the longer he stays (ghoul.js, `mudAt`, `you.mudMs`); dry +// floor or the air lets him go again. Keep a span on flat floor. // - `belts`: [x0, x1, speed] stretches of the floor that are conveyor belts (the // Carnival's funhouse): standing on the floor in one, Planny is carried along at // `speed` units a second (positive runs right), on top of his own running, never @@ -97,12 +102,49 @@ // `hands` [x, line] (a hand that reaches out of the snow: jump or shoot), `icicles` and `pops` [x, line] (shoot: a hanging // cluster, a ghoul that pops up), `finish` (where the snowbank at the end begins; the last line ends in a lip that // launches the sled onto it) and `how` (the controls line); no `beams`, `rubble`, `crates`, `stop` or `surge`. +// - `ride.runner`: "banister" for the Manor's Grand Banister (ghoul-banister.js): the same `track` (the first `rails` lines are the handrail, +// the rest brass under-rails beside it: the split track), `checks` and `time`, with `props` [x, line, kind] (a vase, kind 0, or a +// candlestick, kind 1: jump), `lows` [x0, x1, y] (a hanging portrait frame: duck), `swings` [x, line, amp, period ms, phase ms] (a +// chandelier on a pendulum: duck it while its bob is high, or take the under-rail), `butlers` [x, line] (lunge with a tray: jump +// or shoot), `webs` [x, line] (shoot), `finish` (where the foyer floor at the end begins) and `how`. State: `round.runner`. +// - `ride.runner`: "tray" for the East Wing's Servants' Back Stairs (ghoul-tray.js): the same `track`, `checks` and `time`, with +// `pots` [x, line, kind] (a rolling pot, kind 0, or a drop of cutlery, kind 1: jump), `lows` [x0, x1, y, kind] (duck: a swinging ham, +// kind 0, or hanging pans, kind 1, its underside y), `cooks` [x, line] (a spectral cook who flings a dish: jump it or shoot the cook), +// `domes` and `plates` [x, line, lift] (courses: run through a dome, shoot a plate), `grease` [x0, x1] (flat stretches where the +// tray speeds up), `finish` (the dining table at the end) and `how`; the room's `candy` are the cherries. The tray's state is +// `round.runner` (ghoul.js keeps that slot for a rolling bonus ride). +// - `ride.runner: "mower"`: the Grounds' Gardener's Revenge (ghoul-mower.js): a flat `track` whose gaps are ponds and ha-ha +// ditches (`gaps`: 0 a pond, 1 a ditch; jump), `junk` [x, kind] (gnome, wheelbarrow, flowerpot: jump), `lows` [x0, x1, y, kind] +// (a hedge arch, or a clothes line of gloves: duck), `hedges` [x] (thorn hedges: mow or jump), `beasts` [x] (snapping topiary: +// shoot or jump), `grass` [x0, x1] and `weeds` [x] (mow targets for the lawn-cut grade), `checks`, `finish` (where the lawn's +// end, the ground, begins), `time` and `how`. State: `round.runner`. +// - `ride.runner`: "pew" for the Chapel's Holy Roller (ghoul-pew.js): no `track`, an endless-runner in three lanes: `items` [x, lane, kind, len] +// (kinds: pillar, confessional, pewx to switch; kneeler, stand, cracks, hatch to jump; censer, banner, beam to slide; garg and bell to shoot), +// `souls` [x, lane, h, type] (wax souls and halos), `checks`, `finish` (the distance where the ride ends), `time` and `how`; built by +// ghoul-pew-course.js. State: `round.runner`. +// - `ride.runner`: "hearse" for the Graveyard's Midnight Hearse (ghoul-hearse.js): no `track`, a flat road of two lanes (0 the road, +// 1 the verge), every thing [x, lane, ...] (`graves`, `stones` [x, lane, kind], `lows` [x0, x1, lane, kind], `hands`, `crows` +// [x, lane, h], `blocks` [x0, x1, lane]), the lane `gates` [x0, x1], `lanterns` [x, lane], `fog` [x0, x1], `checks`, `finish`, +// `time` and `how`. State: `round.runner`. +// - `ride.runner`: "codeblue" for Blackmoor Sanatorium's Code Blue (ghoul-gurney.js): the same `track` (the gaps are elevator shafts), `checks` and +// `time`, with `chairs` [x, line] (a wheelchair that rolls at you: jump), `stands` [x, line] (an IV stand: jump), `lows` [x0, x1, y, kind] +// (duck: a hanging surgical lamp, kind 0, or swinging doors, kind 1, its underside y), `orderlies` [x, line] (lunge from a doorway: jump or +// shoot), `lamps` [x, line] (wave i's surge lamp, hung high: shoot it from the air and that blackout is called off), `waves` [x0, x1] +// (the lights-out spans, each with a flicker and a 3, 2, 1 before x0), `finish` (where the ambulance bay begins) and `how`. +// State: `round.runner`. // - `ride.gallery`: true for the Carnival's dark ride (a shooting gallery, not a track: `time` the clock in ms, `ready` the // intro's ms, `how` the controls line of its banner; see ghoul-ride.js). -// - `bonus`: true for a bonus room (the Runaway Cart, the dark ride, the Coffin Sled): it plays for 5 hearts of its own, pays +// - `ride.runner: "wagon"`: Hollow End Village's Torch Mob (ghoul-wagon.js): the same `track` (the gaps are ditches and the collapsed bridge, the +// ramp before it launches), `checks`, `time`, `finish` and `how`, with `blocks` [x, line, kind] (a barrel, kind 0, or a crate, kind 1: jump), +// `lows` [x0, x1, y, kind] (a washing line, kind 0, or an inn sign, kind 1: duck), `throwers` [x, line, kind] (a villager hurling a pitchfork, +// kind 0, duck, or a torch, kind 1, jump; both can be shot), `horses` [x, line] (a spooked horse: jump or shoot), `surge` [x0, x1, extra] +// (spans where the mob runs faster), `bridge` [x0, x1] (for the art). The mob behind (the gap) is the twist. State: `round.runner`. +// - `bonus`: true for a bonus room (the Runaway Cart, the dark ride, the Coffin Sled, Holy Roller, Code Blue, the Torch Mob): it plays for 5 hearts of its own, pays // Lucky Dice for a finish and costs the run nothing (ghoul-bonus.js). // - `dark`: true for a room always dark, false for one always lit; left out, // each time it is entered it is dark DARK_CHANCE of the time (ghoul.js). +import { COURSE } from "./ghoul-pew-course.js"; + export const FIELD_W = 96; export const FIELD_H = 54; @@ -137,11 +179,13 @@ function room(id, title, sub, spec) { horde: freeze(spec.horde || []), hordeMs: spec.hordeMs || 0, dark: spec.dark ?? null, + darkOnKey: Boolean(spec.darkOnKey), toll: spec.toll || 0, flicker: spec.flicker || 0, moon: spec.moon || 0, rocks: spec.rocks || 0, water: list(spec.water || []), + mud: list(spec.mud || []), belts: list(spec.belts || []), ice: list(spec.ice || []), thin: list(spec.thin || []), @@ -151,7 +195,7 @@ function room(id, title, sub, spec) { export const ROOMS = freeze([ // Every run starts here: a long, easy walk with only zombies, then the - // first choice of stage. + // first choice of stage. Always lit, until you take the key. room("hall", "The Long Hall", "Every door but one is locked", { length: 540, ground: [[0, 180, 6], [180, 186, 8.5], [186, 300, 11], [300, 306, 8.5], [306, 540, 6]], @@ -164,6 +208,8 @@ export const ROOMS = freeze([ spawns: [["zombie", 80], ["zombie", 150], ["zombie", 220], ["door", 280, 2, 2200], ["zombie", 350], ["zombie", 430], ["door", 470, 2, 2200], ["zombie", 505]], horde: ["zombie"], hordeMs: 3400, + dark: false, + darkOnKey: true, }), // Zombies and the first hounds: run, shoot, climb the stairs, jump for the key. room("foyer", "Foyer", "The front door locked behind you", { @@ -208,6 +254,97 @@ export const ROOMS = freeze([ horde: ["zombie", "hound", "bat"], hordeMs: 2300, }), + // The Grand Banister, the Manor's BONUS ROUND (see ghoul-banister.js and ghoul-bonus.js): a ride, not a + // walk. YOU slide down the grand staircase's endless polished banister from the attic landing to the + // foyer, about 65 seconds of it at 46 a second: twenty flights of stairs (each a long descent and a + // short climb over the newel at the landing), seven breaks in the rail to jump, vases and candlesticks + // to jump, hanging portrait frames and swinging chandeliers to duck (the chandeliers on a timed + // pendulum: time them, or take the brass under-rail beneath them), ghostly butlers lunging with + // silver trays and cobwebs to shoot, eight places where a lower rail runs beside the handrail (jump + // and hold DOWN to dive onto it), seven checkpoints and a jump off the end of the rail (the lip) onto + // the foyer floor where the door is. Five hearts of its own. The numbers are generated. + room("banister", "The Grand Banister", "Please keep your hands and ghosts inside the rail", { + length: 3006, + ground: [[0, 30, 35.9], [2928, 3006, 10]], + start: 8, + key: null, + door: 2996, + bonus: true, + dark: false, + candy: [ + [30, 39.2, 1], [44, 38.7, 1], [58, 38.2, 1], [72, 37.6, 1], [86, 36.2, 1], [100, 34.8, 1], [114, 33.4, 1], [128, 31.9, 1], + [142, 30.5, 1], [156, 29.1, 1], [170, 27.7, 1], [184, 29.5, 1], [198, 33.6, 1], [212, 36.9, 1], [220, 29.1, 1], [226, 35.5, 1], + [231, 28, 1], [240, 34.1, 1], [242, 26.9, 1], [253, 25.8, 1], [254, 32.7, 1], [264, 24.7, 1], [268, 31.3, 1], [275, 23.6, 1], + [282, 29.9, 1], [286, 22.5, 1], [296, 28.5, 1], [297, 21.4, 1], [308, 20.3, 1], [310, 27.1, 1], [324, 26.9, 1], [338, 31, 1], + [352, 35, 1], [366, 35.6, 1], [380, 34.1, 1], [394, 32.6, 1], [408, 31.1, 1], [413.7, 33.7, 1], [417.7, 35.3, 1], [421.7, 33.7, 1], + [436, 28.2, 1], [450, 26.7, 1], [464, 28.2, 1], [478, 32.5, 1], [492, 35.6, 1], [499, 27.9, 1], [506, 34.2, 1], [510, 26.8, 1], + [520, 32.8, 1], [521, 25.7, 1], [532, 24.6, 1], [534, 31.4, 1], [543, 23.5, 1], [548, 29.9, 1], [554, 22.3, 1], [562, 28.5, 1], + [565, 21.2, 1], [576, 27.1, 1], [576, 20.1, 1], [587, 19, 1], [590, 25.7, 1], [604, 24.7, 1], [618, 28.9, 1], [632, 33.2, 1], + [646, 34.6, 1], [649, 27.2, 1], [660, 33.1, 1], [660, 26.1, 1], [671, 24.9, 1], [674, 31.6, 1], [682, 23.8, 1], [688, 30.1, 1], + [693, 22.6, 1], [702, 28.7, 1], [704, 21.5, 1], [715, 20.3, 1], [716, 27.2, 1], [726, 19.1, 1], [730, 25.7, 1], [737, 18, 1], + [744, 24.2, 1], [758, 25.3, 1], [772, 29.6, 1], [786, 34, 1], [800, 33.3, 1], [814, 31.8, 1], [828, 30.2, 1], [842, 28.7, 1], + [849.5, 31.1, 1], [853.5, 32.7, 1], [857.5, 31.1, 1], [870, 25.7, 1], [884, 24.2, 1], [898, 25.9, 1], [912, 30.1, 1], [926, 33.5, 1], + [934, 25.6, 1], [940, 32, 1], [945, 24.4, 1], [954, 30.5, 1], [956, 23.3, 1], [967, 22.1, 1], [968, 29, 1], [978, 20.9, 1], + [982, 27.5, 1], [989, 19.7, 1], [996, 25.9, 1], [1000, 18.5, 1], [1010, 24.4, 1], [1011, 17.3, 1], [1024, 22.9, 1], [1038, 25.5, 1], + [1052, 29.6, 1], [1066, 33, 1], [1074, 25.1, 1], [1080, 31.4, 1], [1085, 23.9, 1], [1094, 29.9, 1], [1096, 22.7, 1], [1107, 21.5, 1], + [1108, 28.4, 1], [1118, 20.3, 1], [1122, 26.8, 1], [1129, 19.1, 1], [1136, 25.3, 1], [1140, 17.9, 1], [1150, 23.8, 1], [1151, 16.7, 1], + [1162, 15.4, 1], [1164, 22.2, 1], [1178, 21.1, 1], [1192, 25.3, 1], [1206, 29.5, 1], [1220, 32.1, 1], [1234, 30.7, 1], [1248, 29.2, 1], + [1262, 27.8, 1], [1275.9, 29.6, 1], [1279.9, 31.2, 1], [1283.9, 29.6, 1], [1290, 25, 1], [1304, 23.5, 1], [1318, 22.5, 1], [1332, 26.8, 1], + [1346, 31.2, 1], [1358, 23.8, 1], [1360, 30.6, 1], [1369, 22.7, 1], [1374, 29.2, 1], [1380, 21.6, 1], [1388, 27.8, 1], [1391, 20.5, 1], + [1402, 26.4, 1], [1402, 19.4, 1], [1413, 18.2, 1], [1416, 24.9, 1], [1424, 17.1, 1], [1430, 23.5, 1], [1435, 16, 1], [1444, 22.1, 1], + [1446, 14.9, 1], [1458, 20.7, 1], [1472, 24, 1], [1486, 28, 1], [1500, 30.9, 1], [1507, 23.1, 1], [1514, 29.4, 1], [1518, 22, 1], + [1528, 27.9, 1], [1529, 20.8, 1], [1540, 19.7, 1], [1542, 26.5, 1], [1551, 18.5, 1], [1556, 25, 1], [1562, 17.3, 1], [1570, 23.5, 1], + [1573, 16.2, 1], [1584, 22, 1], [1584, 15, 1], [1595, 13.9, 1], [1598, 20.5, 1], [1612, 21.1, 1], [1626, 25.4, 1], [1640, 29.7, 1], + [1654, 29.4, 1], [1668, 27.9, 1], [1682, 26.4, 1], [1692.2, 28.5, 1], [1696.2, 30.1, 1], [1700.2, 28.5, 1], [1710, 23.4, 1], [1724, 21.9, 1], + [1738, 20.4, 1], [1752, 21.8, 1], [1766, 26, 1], [1780, 29.8, 1], [1789, 21.9, 1], [1794, 28.4, 1], [1800, 20.8, 1], [1808, 26.9, 1], + [1811, 19.6, 1], [1822, 25.5, 1], [1822, 18.5, 1], [1833, 17.4, 1], [1836, 24.1, 1], [1844, 16.3, 1], [1850, 22.7, 1], [1855, 15.2, 1], + [1864, 21.2, 1], [1866, 14, 1], [1878, 19.8, 1], [1892, 22.7, 1], [1906, 26.8, 1], [1920, 28.6, 1], [1934, 27.1, 1], [1948, 25.6, 1], + [1962, 24.1, 1], [1976, 22.6, 1], [1990, 21.1, 1], [2004, 19.7, 1], [2018, 19.4, 1], [2032, 23.5, 1], [2046, 27.5, 1], [2060, 27.6, 1], + [2074, 26.1, 1], [2088, 24.6, 1], [2097.3, 26.7, 1], [2101.3, 28.3, 1], [2105.3, 26.7, 1], [2116, 21.5, 1], [2130, 20, 1], [2144, 18.5, 1], + [2158, 17.8, 1], [2172, 21.9, 1], [2186, 26, 1], [2200, 27.4, 1], [2214, 25.9, 1], [2228, 24.5, 1], [2242, 23, 1], [2256, 21.6, 1], + [2270, 20.1, 1], [2284, 18.7, 1], [2298, 17.2, 1], [2312, 17.4, 1], [2326, 21.6, 1], [2340, 25.8, 1], [2354, 26.4, 1], [2368, 25, 1], + [2382, 23.6, 1], [2396, 22.2, 1], [2410, 20.7, 1], [2424, 19.3, 1], [2438, 17.9, 1], [2452, 16.5, 1], [2466, 18.7, 1], [2480, 22.8, 1], + [2494, 26.6, 1], [2508, 25, 1], [2522, 23.5, 1], [2536, 22, 1], [2548.2, 23.8, 1], [2552.2, 25.4, 1], [2556.2, 23.8, 1], [2564, 18.9, 1], + [2578, 17.3, 1], [2592, 15.8, 1], [2606, 15.9, 1], [2620, 20.2, 1], [2634, 24.5, 1], [2648, 25.1, 1], [2662, 23.6, 1], [2676, 22.1, 1], + [2690, 20.6, 1], [2704, 19.1, 1], [2718, 17.7, 1], [2732, 16.2, 1], [2746, 14.7, 1], [2760, 17.7, 1], [2774, 21.8, 1], [2788, 25.2, 1], + [2802, 23.7, 1], [2816, 22.3, 1], [2830, 20.8, 1], [2844, 19.3, 1], [2846.1, 22.3, 1], [2850.1, 23.9, 1], [2854.1, 22.3, 1], [2858, 17.9, 1], + [2872, 16.4, 1], [2886, 14.9, 1], [2900, 16.5, 1], [2914, 20.4, 1], + ], + items: [], + spawns: [], + horde: [], + ride: { + runner: "banister", + rails: 8, + time: 110000, + finish: 2928, + how: "UP jump, DOWN duck (in the air: dive), LEFT brake, SPACE shoot", + track: [ + [[0, 37.5], [70, 35.1], [176, 24.4], [210, 34.4], [321, 23.3], [357, 33.8], [410.2, 28.2]], + [[425.2, 26.6], [457, 23.3], [489, 33.2], [603, 21.7], [639, 32.6], [752, 20.7], [788, 31.9], [847, 25.5]], + [[860, 24.1], [890, 20.8], [924, 31], [1028, 19.8], [1064, 30.5], [1177, 18.1], [1216, 29.8], [1273.9, 23.9]], + [[1285.9, 22.7], [1317, 19.5], [1348, 29.1], [1460, 17.8], [1497, 28.5], [1607, 16.9], [1643, 27.9], [1688.7, 23]], + [[1703.7, 21.4], [1745, 17], [1779, 27.2], [1881, 16.8], [1914, 26.5], [2015, 15.8], [2050, 26], [2094.8, 21.1]], + [[2107.8, 19.7], [2156, 14.5], [2193, 25.4], [2308, 13.5], [2345, 24.6], [2457, 13.3], [2493, 24], [2544.7, 18.3]], + [[2559.7, 16.7], [2602, 12], [2639, 23.3], [2749, 11.7], [2786, 22.7], [2844.1, 16.6]], + [[2856.1, 15.4], [2892, 11.6], [2918, 18.8]], + [[210, 27.4], [321, 16.3]], + [[489, 26.2], [603, 14.7]], + [[639, 25.6], [752, 13.7]], + [[924, 24], [1028, 12.8]], + [[1064, 23.5], [1177, 11.1]], + [[1348, 22.1], [1460, 10.8]], + [[1497, 21.5], [1607, 9.9]], + [[1779, 20.2], [1881, 9.8]], + ], + props: [[162, 0, 0], [287, 0, 1], [714, 10, 1], [1209, 2, 0], [1239, 2, 1], [1575, 14, 1], [1731, 4, 0], [1911, 4, 1], [2065, 4, 0], [2237, 5, 1], [2388, 5, 0], [2587, 6, 0]], + lows: [[236, 243, 35], [665, 672, 33.1], [1524, 1531, 28.9], [1807, 1814, 27.5], [2148, 2155, 18.6], [2430, 2437, 19.2]], + swings: [[530, 1, 9, 2400, 1088], [966, 2, 9, 2500, 1588], [1104, 2, 9, 2500, 1497], [1389, 3, 9, 2800, 624], [1969, 4, 9, 2700, 690], [2293, 5, 9, 2600, 973], [2683, 6, 9, 2600, 1273]], + butlers: [[361, 0], [793, 1], [1648, 3], [2036, 4], [2209, 5], [2360, 5], [2491, 5], [2625, 6]], + webs: [[302, 8], [466, 1], [738, 1], [888, 2], [1300, 3], [1602, 3], [2253, 5], [2645, 6]], + checks: [388, 734, 1123, 1442, 1819, 2169, 2519], + }, + }), // The first boss. room("ballroom", "Ballroom", "The music stopped years ago. The dancing did not", { length: 200, @@ -268,6 +405,99 @@ export const ROOMS = freeze([ horde: ["zombie", "hound", "bat"], hordeMs: 2000, }), + // The Servants' Back Stairs, the East Wing's BONUS ROUND (see ghoul-tray.js and ghoul-bonus.js): a ride, not a + // walk. YOU ride a silver serving tray down the cramped back stairs and through the steamy basement kitchens, + // about a minute of it at 44 a second (faster on the greased stretches): 18 laps of a climb onto a pantry shelf, a flat run along it and + // a flight of stairs down, with a gap between two flights each time; rolling pots and drops of cutlery to jump, + // swinging hams and hanging copper pans to duck, spectral cooks who fling dishes (jump them or shoot the cook), + // silver domes to run through and flying plates to shoot (seven of them is a full seven course meal), cherries + // along the way, eight checkpoints, and a launch off the end of the last shelf (the lip) onto the dining table where + // the door is. Five hearts of its own. The numbers are generated. + room("tray", "Last Orders", "Dinner is served. You are dinner", { + length: 3176, + ground: [[0, 30, 28.6], [3086, 3176, 21.8]], + start: 8, + key: null, + door: 3166, + bonus: true, + dark: false, + candy: [ + [20, 32.6, 1], [34, 32.6, 1], [41, 32.1, 1], [46, 34.7, 1], [51, 32.1, 1], [62, 28.2, 1], [76, 25.8, 1], + [95, 24.3, 1], [99, 26.3, 1], [103, 24.3, 1], [104, 21, 1], [118, 24.9, 1], [132, 28.8, 1], [146, 32.2, 1], + [157, 33.4, 1], [162, 36, 1], [167, 33.4, 1], [174, 32.2, 1], [188, 32.2, 1], [202, 32.2, 1], [230, 29.5, 1], + [244, 27.1, 1], [258, 24.8, 1], [273, 24, 1], [277, 26, 1], [281, 24, 1], [286, 21.8, 1], [300, 25.7, 1], + [314, 29.7, 1], [328, 31.9, 1], [342, 31.9, 1], [347, 33.1, 1], [352, 35.7, 1], [357, 33.1, 1], [370, 31.9, 1], + [384, 31.9, 1], [398, 30.9, 1], [412, 28.5, 1], [426, 26.1, 1], [440, 23.7, 1], [451, 23.5, 1], [455, 25.5, 1], + [459, 23.5, 1], [468, 22.5, 1], [482, 26.5, 1], [496, 30.4, 1], [524, 31.5, 1], [538, 31.5, 1], [552, 31.5, 1], + [555, 32.7, 1], [560, 35.3, 1], [565, 32.7, 1], [580, 29.8, 1], [583, 29.7, 1], [588, 32.3, 1], [593, 29.7, 1], + [608, 25.1, 1], [629, 23.3, 1], [633, 25.3, 1], [637, 23.3, 1], [650, 23.4, 1], [664, 27.3, 1], [678, 31.2, 1], + [685, 32.4, 1], [690, 35, 1], [695, 32.4, 1], [706, 31.2, 1], [720, 31.2, 1], [734, 31.2, 1], [748, 31.2, 1], + [776, 26.4, 1], [790, 24, 1], [807, 22.9, 1], [811, 24.9, 1], [815, 22.9, 1], [818, 20.2, 1], [832, 24.1, 1], + [846, 28, 1], [860, 30.8, 1], [874, 30.8, 1], [902, 30.8, 1], [916, 30.8, 1], [930, 30.1, 1], [944, 27.7, 1], + [958, 25.3, 1], [972, 22.9, 1], [985, 22.5, 1], [989, 24.5, 1], [993, 22.5, 1], [1000, 20.9, 1], [1014, 24.8, 1], + [1028, 28.7, 1], [1042, 30.4, 1], [1045, 31.6, 1], [1050, 34.2, 1], [1055, 31.6, 1], [1070, 30.4, 1], [1084, 30.4, 1], + [1112, 29, 1], [1126, 26.7, 1], [1140, 24.3, 1], [1154, 22, 1], [1163, 22.2, 1], [1167, 24.2, 1], [1171, 22.2, 1], + [1182, 21.7, 1], [1196, 25.6, 1], [1210, 29.5, 1], [1238, 30.1, 1], [1252, 30.1, 1], [1266, 30.1, 1], [1280, 30.1, 1], + [1308, 25.7, 1], [1322, 23.3, 1], [1341, 21.8, 1], [1345, 23.8, 1], [1349, 21.8, 1], [1350, 18.5, 1], [1364, 22.4, 1], + [1378, 26.3, 1], [1392, 29.7, 1], [1406, 29.7, 1], [1415, 30.9, 1], [1420, 33.5, 1], [1425, 30.9, 1], [1434, 29.7, 1], + [1448, 29.7, 1], [1462, 29.4, 1], [1476, 27, 1], [1490, 24.6, 1], [1504, 22.3, 1], [1519, 21.5, 1], [1523, 23.5, 1], + [1527, 21.5, 1], [1532, 19.3, 1], [1546, 23.2, 1], [1560, 27.2, 1], [1574, 29.4, 1], [1602, 29.4, 1], [1616, 29.4, 1], + [1627, 30.6, 1], [1632, 33.2, 1], [1637, 30.6, 1], [1644, 28.4, 1], [1658, 26, 1], [1672, 23.6, 1], [1686, 21.2, 1], + [1697, 21, 1], [1701, 23, 1], [1705, 21, 1], [1714, 20, 1], [1728, 24, 1], [1742, 27.9, 1], [1770, 29, 1], + [1784, 29, 1], [1798, 29, 1], [1801, 30.2, 1], [1806, 32.8, 1], [1811, 30.2, 1], [1826, 27.3, 1], [1829, 27.1, 1], + [1834, 29.7, 1], [1839, 27.1, 1], [1854, 22.5, 1], [1875, 20.7, 1], [1879, 22.7, 1], [1883, 20.7, 1], [1896, 20.8, 1], + [1910, 24.7, 1], [1924, 28.6, 1], [1938, 28.6, 1], [1952, 28.6, 1], [1980, 28.6, 1], [1994, 28.6, 1], [2008, 26.2, 1], + [2022, 23.9, 1], [2036, 21.5, 1], [2053, 20.4, 1], [2057, 22.4, 1], [2061, 20.4, 1], [2064, 17.7, 1], [2078, 21.6, 1], + [2092, 25.5, 1], [2106, 28.3, 1], [2109, 29.5, 1], [2114, 32.1, 1], [2119, 29.5, 1], [2134, 28.3, 1], [2148, 28.3, 1], + [2162, 28.3, 1], [2204, 22.8, 1], [2218, 20.4, 1], [2231, 20, 1], [2235, 22, 1], [2239, 20, 1], [2246, 18.4, 1], + [2260, 22.3, 1], [2274, 26.2, 1], [2288, 27.9, 1], [2293, 29.1, 1], [2298, 31.7, 1], [2303, 29.1, 1], [2316, 27.9, 1], + [2330, 27.9, 1], [2358, 26.5, 1], [2372, 24.2, 1], [2386, 21.8, 1], [2400, 19.5, 1], [2409, 19.7, 1], [2413, 21.7, 1], + [2417, 19.7, 1], [2428, 19.2, 1], [2442, 23.1, 1], [2456, 27, 1], [2470, 27.6, 1], [2483, 28.8, 1], [2488, 31.4, 1], + [2493, 28.8, 1], [2498, 27.6, 1], [2512, 27.6, 1], [2526, 27.6, 1], [2540, 25.6, 1], [2554, 23.2, 1], [2568, 20.8, 1], + [2587, 19.3, 1], [2591, 21.3, 1], [2595, 19.3, 1], [2596, 16, 1], [2610, 19.9, 1], [2624, 23.8, 1], [2638, 27.2, 1], + [2666, 27.2, 1], [2680, 27.2, 1], [2694, 27.2, 1], [2736, 22.1, 1], [2750, 19.7, 1], [2765, 18.9, 1], [2769, 20.9, 1], + [2773, 18.9, 1], [2778, 16.7, 1], [2792, 20.6, 1], [2806, 24.6, 1], [2820, 26.8, 1], [2825, 28, 1], [2830, 30.6, 1], + [2835, 28, 1], [2848, 26.8, 1], [2862, 26.8, 1], [2890, 25.8, 1], [2904, 23.4, 1], [2918, 21.1, 1], [2932, 18.7, 1], + [2943, 18.6, 1], [2947, 20.6, 1], [2951, 18.6, 1], [2960, 17.5, 1], [2974, 21.5, 1], [2988, 25.4, 1], [3003, 27.7, 1], + [3008, 30.3, 1], [3013, 27.7, 1], [3016, 26.5, 1], [3030, 26.5, 1], [3044, 26.5, 1], [3058, 28.2, 1], + ], + items: [], + spawns: [], + horde: [], + ride: { + runner: "tray", + time: 110000, + finish: 3086, + how: "UP to jump, DOWN to duck, hold space to shoot", + track: [ + [[0, 30], [36, 30], [94, 20.1]], + [[104, 18.4], [144, 29.6], [214, 29.6], [272, 19.8]], + [[282, 18.1], [322, 29.3], [392, 29.3], [450, 19.4]], + [[460, 17.7], [500, 28.9], [570, 28.9], [628, 19.1]], + [[638, 17.4], [678, 28.6], [748, 28.6], [806, 18.7]], + [[816, 17], [856, 28.2], [926, 28.2], [984, 18.3]], + [[994, 16.6], [1034, 27.8], [1104, 27.8], [1162, 18]], + [[1172, 16.3], [1212, 27.5], [1282, 27.5], [1340, 17.6]], + [[1350, 15.9], [1390, 27.1], [1460, 27.1], [1518, 17.3]], + [[1528, 15.6], [1568, 26.8], [1638, 26.8], [1696, 16.9]], + [[1706, 15.2], [1746, 26.4], [1816, 26.4], [1874, 16.5]], + [[1884, 14.8], [1924, 26], [1994, 26], [2052, 16.2]], + [[2062, 14.5], [2102, 25.7], [2172, 25.7], [2230, 15.8]], + [[2240, 14.1], [2280, 25.3], [2350, 25.3], [2408, 15.5]], + [[2418, 13.8], [2458, 25], [2528, 25], [2586, 15.1]], + [[2596, 13.4], [2636, 24.6], [2706, 24.6], [2764, 14.7]], + [[2774, 13], [2814, 24.2], [2884, 24.2], [2942, 14.4]], + [[2952, 12.7], [2992, 23.9], [3052, 23.9], [3076, 30.6]], + ], + pots: [[46, 0, 0], [162, 1, 0], [352, 2, 0], [560, 3, 0], [588, 3, 0], [690, 4, 0], [1050, 6, 1], [1420, 8, 0], [1632, 9, 0], [1806, 10, 0], [1834, 10, 0], [2114, 12, 0], [2298, 13, 1], [2488, 14, 0], [2830, 16, 1], [3008, 17, 0]], + lows: [[206, 214, 32.6, 1], [512, 519, 31.9, 0], [890, 898, 31.2, 1], [1092, 1099, 30.8, 0], [1224, 1231, 30.5, 0], [1582, 1589, 29.8, 0], [1758, 1765, 29.4, 0], [1958, 1966, 29, 1], [2346, 2353, 28.3, 0], [2648, 2655, 27.6, 0], [2872, 2879, 27.2, 0]], + cooks: [[766, 4], [1296, 7], [2190, 12], [2720, 15]], + domes: [[52, 0, 7], [168, 1, 7], [358, 2, 7], [566, 3, 7], [696, 4, 7], [716, 4, 0], [912, 5, 6.5], [1056, 6, 6.5], [1252, 7, 6.5], [1426, 8, 7], [1638, 9, 7], [1812, 10, 7], [1980, 11, 6.5], [2120, 12, 7], [2140, 12, 0], [2304, 13, 7], [2340, 13, 0], [2494, 14, 7], [2676, 15, 6.5], [2836, 16, 6.5], [3014, 17, 7]], + plates: [[74, 0, 2.4], [230, 1, 2.4], [392, 2, 3], [540, 3, 2.4], [730, 4, 3], [928, 5, 2.4], [1119, 6, 5], [1268, 7, 4], [1460, 8, 3], [1656, 9, 4], [1786, 10, 2.4], [1996, 11, 2.4], [2154, 12, 3], [2368, 13, 3], [2528, 14, 3], [2692, 15, 4], [2899, 16, 5], [3032, 17, 2.4]], + grease: [[324, 390], [858, 924], [1392, 1458], [1926, 1992], [2460, 2526]], + checks: [298, 654, 1010, 1366, 1722, 2078, 2434, 2790], + }, + }), // The second boss, down among the tombs. room("crypt", "Crypt", "Something old is awake down here", { length: 200, @@ -322,6 +552,67 @@ export const ROOMS = freeze([ horde: ["rotter", "crow"], hordeMs: 2200, }), + // The Midnight Hearse, the Graveyard's BONUS ROUND (see ghoul-hearse.js and ghoul-bonus.js): a ride, not a + // walk. Planny hijacks a runaway black hearse and tears along the cemetery road at 42 a second, about 64 + // seconds of it, on a flat road with two lanes (the road, and the grass verge, a raised bank beside it) + // that he switches at thirteen lane gates: open graves, headstones and fallen crosses to jump, low branches + // and the lychgate arch to duck, grasping hands and carrion crows to shoot, five closed stretches (a fallen + // oak on the road, a hedge wall on the verge) to go round, lanterns that keep the lamp lit, fog banks that + // burn it down, and six checkpoints. Five hearts of its own; a heart lost throws a coffin out ahead and a + // ghoul sits up in it to shoot. The numbers are generated: thirteen sections of four slots between the gates. + room("hearse", "The Midnight Hearse", "Everyone else is already dead on time", { + length: 2760, + ground: [[0, 2760, 9]], + start: 8, + key: null, + door: 2750, + bonus: true, + dark: false, + candy: [ + [124, 11, 3], [124, 17, 3], [141, 17.5, 3], [181, 23.5, 3], [184, 11, 3], [221, 17.5, 3], + [244, 11, 3], [244, 17, 3], [261, 23.5, 3], [341, 23.5, 3], [364, 11, 3], [364, 17, 3], + [381, 17.5, 3], [421, 23.5, 3], [424, 11, 3], [461, 17.5, 3], [461, 23.5, 3], [484, 11, 3], + [484, 17, 3], [541, 23.5, 3], [604, 17, 3], [621, 23.5, 3], [661, 17.5, 3], [664, 17, 3], + [724, 11, 3], [724, 17, 3], [741, 17.5, 3], [781, 23.5, 3], [784, 11, 3], [821, 17.5, 3], + [821, 23.5, 3], [844, 11, 3], [844, 17, 3], [861, 23.5, 3], [941, 17.5, 3], [964, 11, 3], + [1021, 17.5, 3], [1024, 17, 3], [1061, 23.5, 3], [1084, 11, 3], [1084, 17, 3], [1141, 23.5, 3], + [1144, 11, 3], [1181, 17.5, 3], [1204, 11, 3], [1204, 17, 3], [1221, 23.5, 3], [1261, 17.5, 3], + [1264, 17, 3], [1324, 11, 3], [1324, 17, 3], [1341, 23.5, 3], [1384, 17, 3], [1421, 23.5, 3], + [1444, 11, 3], [1444, 17, 3], [1461, 17.5, 3], [1541, 17.5, 3], [1564, 11, 3], [1564, 17, 3], + [1581, 23.5, 3], [1621, 17.5, 3], [1624, 17, 3], [1661, 17.5, 3], [1661, 23.5, 3], [1684, 11, 3], + [1684, 17, 3], [1744, 11, 3], [1781, 17.5, 3], [1804, 11, 3], [1821, 23.5, 3], [1861, 17.5, 3], + [1864, 17, 3], [1924, 11, 3], [1924, 17, 3], [1941, 23.5, 3], [1981, 17.5, 3], [1984, 17, 3], + [2021, 23.5, 3], [2044, 11, 3], [2044, 17, 3], [2061, 17.5, 3], [2164, 17, 3], [2181, 23.5, 3], + [2221, 17.5, 3], [2224, 17, 3], [2261, 23.5, 3], [2284, 11, 3], [2284, 17, 3], [2341, 17.5, 3], + [2344, 17, 3], [2381, 23.5, 3], [2404, 11, 3], [2404, 17, 3], [2421, 17.5, 3], [2461, 17.5, 3], + [2461, 23.5, 3], [2524, 11, 3], [2524, 17, 3], [2541, 23.5, 3], [2581, 17.5, 3], [2584, 17, 3], + [2621, 17.5, 3], [2621, 23.5, 3], [2644, 11, 3], [2644, 17, 3], + ], + items: [], + spawns: [], + horde: [], + ride: { + runner: "hearse", + time: 110000, + finish: 2690, + how: "LEFT or RIGHT at a gate: switch lane. UP jump, DOWN duck, SPACE shoot", + gates: [[100, 116], [300, 316], [500, 516], [700, 716], [900, 916], [1100, 1116], [1300, 1316], [1500, 1516], [1700, 1716], [1900, 1916], [2100, 2116], [2300, 2316], [2500, 2516]], + graves: [[144, 0], [464, 0], [744, 0], [1184, 0], [1464, 0], [1784, 0], [2464, 0], [2464, 1], [2624, 0], [2624, 1]], + stones: [[184, 1, 0], [464, 1, 0], [624, 1, 0], [864, 1, 0], [1024, 0, 1], [1144, 1, 0], [1344, 1, 0], [1544, 0, 1], [1664, 1, 0], [1864, 0, 1], [2224, 0, 1], [2384, 1, 0], [2584, 0, 1]], + lows: [[221, 227, 0, 1], [261, 267, 1, 0], [421, 427, 1, 0], [541, 547, 1, 0], [821, 827, 1, 0], [1421, 1427, 1, 0], [1821, 1827, 1, 0], [2021, 2027, 1, 0], [2261, 2267, 1, 0]], + hands: [[350, 1], [670, 0], [950, 0], [1070, 1], [1270, 0], [1630, 0], [1990, 0], [2190, 1], [2350, 0]], + crows: [[401, 0, 2.6], [801, 1, 2.6], [841, 0, 2.6], [1241, 1, 2.6], [1601, 1, 2.6], [1681, 0, 2.6], [1961, 1, 2.6], [2081, 0, 2.6], [2441, 0, 2.6], [2561, 1, 2.6]], + blocks: [[560, 592, 0], [960, 992, 1], [1360, 1392, 0], [1760, 1792, 1], [2160, 2192, 0]], + lanterns: [ + [164, 0], [244, 0], [204, 1], [284, 1], [364, 0], [444, 0], [644, 0], [764, 0], + [844, 0], [804, 1], [884, 1], [964, 0], [1044, 0], [1164, 0], [1244, 0], [1444, 0], + [1404, 1], [1484, 1], [1564, 0], [1644, 0], [1764, 0], [1844, 0], [1964, 0], [2044, 0], + [2004, 1], [2084, 1], [2244, 0], [2364, 0], [2444, 0], [2564, 0], [2604, 1], + ], + fog: [[560, 700], [1160, 1300], [1760, 1900], [2290, 2430]], + checks: [480, 880, 1280, 1680, 2080, 2480], + }, + }), // The Graveyard's boss: Mother Mourning, in the plot at the end. room("angel", "Angel's Rest", "She has wept here for two hundred years", { length: 200, @@ -378,6 +669,67 @@ export const ROOMS = freeze([ horde: ["moth", "zombie", "topiary", "moth"], hordeMs: 2000, }), + // The Gardener's Revenge, the Grounds' BONUS ROUND (see ghoul-mower.js and ghoul-bonus.js): a ride, not a + // walk. YOU ride the gardener's rusty ride-on mower down one long straight run through the overgrown + // lawn, about 65 seconds of it at 32 a second: 8 gnomes, wheelbarrows and flowerpots and 8 thorn hedges + // to jump, 8 hedge arches and clothes lines of ghostly gloves to duck, 4 ponds and 3 ha-ha ditches to + // jump, 5 snapping topiary beasts to shoot, and the twist: hold fire and the blades cut the tall grass, + // the weed patches and the thorn hedges ahead (the blades overheat and jam, so you pulse them). Five + // checkpoints, then the lawn's end where the door is. Five hearts of its own. The numbers are generated: + // a slot every 52 units from 80 to 1900 holds one obstacle, the grass and weeds lie between. + room("mower", "The Gardener's Revenge", "The lawn has not been mowed since 1893", { + length: 2120, + ground: [[0, 30, 12], [2000, 2120, 12]], + start: 8, + key: null, + door: 2110, + bonus: true, + dark: false, + candy: [ + [76, 20, 1], [80, 21.5, 1], [84, 20, 1], [100, 13.8, 1], [152, 13.8, 1], [204, 13.8, 1], [232, 20, 1], [236, 21.5, 1], + [240, 20, 1], [256, 13.8, 1], [288, 20, 1], [308, 13.8, 1], [336, 20, 1], [340, 21.5, 1], [344, 20, 1], [360, 13.8, 1], + [412, 13.8, 1], [464, 13.8, 1], [492, 20, 1], [496, 21.5, 1], [500, 20, 1], [516, 13.8, 1], [548, 20, 1], [568, 13.8, 1], + [620, 13.8, 1], [672, 13.8, 1], [700, 20, 1], [704, 21.5, 1], [708, 20, 1], [724, 13.8, 1], [752, 20, 1], [756, 21.5, 1], + [760, 20, 1], [776, 13.8, 1], [808, 20, 1], [828, 13.8, 1], [880, 13.8, 1], [932, 13.8, 1], [960, 20, 1], [964, 21.5, 1], + [968, 20, 1], [984, 13.8, 1], [1012, 20, 1], [1016, 21.5, 1], [1020, 20, 1], [1036, 13.8, 1], [1068, 20, 1], [1088, 13.8, 1], + [1140, 13.8, 1], [1192, 13.8, 1], [1220, 20, 1], [1224, 21.5, 1], [1228, 20, 1], [1244, 13.8, 1], [1276, 20, 1], [1296, 13.8, 1], + [1324, 20, 1], [1328, 21.5, 1], [1332, 20, 1], [1348, 13.8, 1], [1400, 13.8, 1], [1452, 13.8, 1], [1480, 20, 1], [1484, 21.5, 1], + [1488, 20, 1], [1504, 13.8, 1], [1536, 20, 1], [1556, 13.8, 1], [1584, 20, 1], [1588, 21.5, 1], [1592, 20, 1], [1608, 13.8, 1], + [1660, 13.8, 1], [1712, 13.8, 1], [1740, 20, 1], [1744, 21.5, 1], [1748, 20, 1], [1764, 13.8, 1], [1816, 13.8, 1], [1868, 13.8, 1], + [1900, 20, 1], [1920, 13.8, 1], [1946, 13.8, 1], [1972, 13.8, 1], + ], + items: [["rapid", 366, 15.5], ["garlic", 730, 15.5], ["cocoa", 1094, 15.5], ["spread", 1510, 15.5]], + spawns: [], + horde: [], + ride: { + runner: "mower", + time: 105000, + finish: 2000, + how: "UP to jump, DOWN to duck, hold space to shoot and mow", + track: [ + [[0, 12], [282.5, 12]], [[293.5, 12], [544, 12]], + [[552, 12], [802.5, 12]], [[813.5, 12], [1064, 12]], + [[1072, 12], [1270.5, 12]], [[1281.5, 12], [1532, 12]], + [[1540, 12], [1894.5, 12]], [[1905.5, 12], [2000, 12]], + ], + gaps: [0, 1, 0, 1, 0, 1, 0], + junk: [[80, 0], [236, 1], [496, 2], [756, 0], [964, 2], [1224, 1], [1484, 0], [1744, 2]], + lows: [[181, 187, 15, 0], [439, 449, 15, 1], [649, 655, 15, 0], [907, 917, 15, 1], [1169, 1175, 15, 0], [1427, 1437, 15, 1], [1689, 1695, 15, 0], [1791, 1801, 15, 1]], + hedges: [132, 392, 600, 860, 1120, 1380, 1640, 1848], + beasts: [340, 704, 1016, 1328, 1588], + grass: [ + [36, 58], [100, 112], [152, 171], [204, 219], [256, 278], [308, 326], + [360, 374], [412, 433], [464, 481], [516, 529], [568, 588], [620, 636], + [672, 684], [724, 743], [776, 791], [828, 850], [880, 898], [932, 946], + [984, 1005], [1036, 1053], [1088, 1101], [1140, 1160], [1192, 1208], [1244, 1256], + [1296, 1315], [1348, 1363], [1400, 1422], [1452, 1470], [1504, 1518], [1556, 1577], + [1608, 1625], [1660, 1673], [1712, 1732], [1764, 1780], [1816, 1828], [1868, 1887], + [1920, 1935], [1915, 1985], + ], + weeds: [144, 248, 352, 456, 560, 664, 768, 872, 976, 1080, 1184, 1288, 1392, 1496, 1600, 1704, 1808, 1912], + checks: [418, 782, 1146, 1510, 1822], + }, + }), // The Grounds' boss: the Groundskeeper, in his yard behind the gazebo. room("yard", "The Groundskeeper's Yard", "He has been tending this garden a long time", { length: 200, @@ -440,6 +792,34 @@ export const ROOMS = freeze([ horde: ["monk", "chorister", "bellbat", "zombie"], hordeMs: 2000, }), + // Holy Roller, the Chapel's BONUS ROUND (see ghoul-pew.js and ghoul-bonus.js): an endless-runner, seen from + // behind. YOU surf a runaway church pew down the nave's aisle in three lanes, faster and faster for about 66 + // seconds: change lane, jump the low things, slide under the high ones, shoot the gargoyles (or ring a bell rope + // to stun them) and gather the wax souls for a combo. The course is written in ghoul-pew-course.js (seconds, + // laid by the speed ramp) and the whole field is drawn by the Chapel's own pseudo-3D art, so this room's + // ground is only the floor under the distance run and the door Planny steps to at the finish. Five hearts of its own. + room("pew", "Holy Roller", "The organist has been waiting for YOU", { + length: COURSE.finish + 60, + ground: [[0, COURSE.finish + 60, 12]], + start: 8, + key: null, + door: COURSE.finish + 30, + bonus: true, + dark: false, + candy: [], + items: [], + spawns: [], + horde: [], + ride: { + runner: "pew", + time: 110000, + finish: COURSE.finish, + how: "LEFT/RIGHT change lane, UP jump, DOWN slide, hold space to shoot", + items: COURSE.items, + souls: COURSE.souls, + checks: COURSE.checks, + }, + }), // The Chapel's boss: the Choirmaster at his organ. Boards at three heights // for the staff's gaps (a note is passed on the floor or on a board). room("choir", "The Choir", "He has been rehearsing for centuries", { @@ -504,6 +884,51 @@ export const ROOMS = freeze([ hordeMs: 2000, flicker: 6500, }), + // Code Blue, Blackmoor Sanatorium's BONUS ROUND (see ghoul-gurney.js and ghoul-bonus.js): a ride, not a + // walk. YOU lie strapped to a runaway hospital gurney that flies down the sanatorium's endless corridors + // and ramps, about 67 seconds of it at 48 a second: eight corridors joined by seven elevator shafts to jump, + // 8 wheelchairs (they roll at you) and 7 IV stands to jump, 11 hanging surgical lamps and swinging doors to duck, + // 11 orderlies who lunge from doorways (jump or shoot), seven checkpoints, and a loading ramp at the end that + // launches the gurney out of the ambulance doors onto the bay where the door is. Five hearts of its own. + // The twist is the lights: 6 blackouts, each announced by a flicker and a 3, 2, 1, then pitch black (only the + // flashlight cone, the dying emergency strips and a faint glow on what is near), unless the buzzing surge lamp + // hung high before it is shot out from the air (no low hangs in the 80 before a lamp: room to hop). The numbers are generated. + room("codeblue", "Code Blue", "Please remain calm. The gurney will not", { + length: 3294, + ground: [[0, 30, 20.6], [3216, 3294, 10]], + start: 8, + key: null, + door: 3284, + bonus: true, + dark: false, + candy: [], + items: [], + spawns: [], + horde: [], + ride: { + runner: "codeblue", + time: 100000, + finish: 3216, + how: "UP to jump, DOWN to duck, hold space to shoot", + track: [ + [[0, 22], [75, 22], [108, 17], [194, 17], [226, 22], [312, 22], [339, 18], [370, 18]], + [[382, 16], [476, 16], [508, 12], [639, 12], [673, 18], [745, 18], [762, 18]], + [[776, 15], [849, 15], [910, 24], [1024, 24], [1078, 17], [1160, 17]], + [[1173, 13], [1298, 13], [1330, 17], [1407, 17], [1459, 25], [1531, 25], [1561, 25]], + [[1576, 23], [1696, 23], [1762, 15], [1871, 15], [1898, 19], [1968, 19]], + [[1980, 16], [2067, 16], [2121, 24], [2250, 24], [2279, 29], [2376, 29]], + [[2390, 28], [2483, 28], [2539, 20], [2633, 20], [2681, 27], [2770, 27], [2788, 27]], + [[2804, 22], [2904, 22], [2958, 14], [3048, 14], [3074, 19], [3110, 19], [3180, 11.6], [3206, 18.8]], + ], + chairs: [[288, 0], [445, 1], [996, 2], [1227, 3], [1275, 3], [1828, 4], [2454, 6], [3021, 7]], + stands: [[236, 0], [511, 1], [683, 1], [1103, 2], [1901, 4], [2704, 6], [2856, 7]], + lows: [[48.8, 55.2, 25, 1], [122, 128.4, 20, 0], [556.6, 563, 15, 0], [620.8, 627.2, 15, 1], [1336.8, 1343.2, 20, 0], [1466.6, 1473, 28, 1], [1502.8, 1509.2, 28, 1], [1673.6, 1680, 26, 1], [2034.8, 2041.2, 19, 1], [2601.4, 2607.8, 23, 0], [3082, 3088.4, 22, 1]], + orderlies: [[840, 2], [913, 2], [948, 2], [1404, 3], [1628, 4], [1780, 4], [2133, 5], [2212, 5], [2283, 5], [2550, 6], [2966, 7]], + lamps: [[350, 0], [830, 2], [1310, 3], [1770, 4], [2250, 5], [2730, 6]], + waves: [[420, 590], [900, 1080], [1380, 1570], [1840, 2040], [2320, 2530], [2800, 3000]], + checks: [390, 784, 1181, 1584, 1988, 2398, 2812], + }, + }), // The Sanatorium's boss: the Night Matron, on her rounds in the ward. Two // medicine cabinets (raised floor blocks 4.5 high at 136 and 164: cover from // her lantern, which hangs 8 over her feet; bolts stop at them too) and, up @@ -570,6 +995,47 @@ export const ROOMS = freeze([ hordeMs: 2285, moon: 35000, }), + // The Torch Mob, Hollow End Village's BONUS ROUND (see ghoul-wagon.js and ghoul-bonus.js): a ride, not a + // walk. Planny steals a hay wagon and races out of the village down the cobbled road and over the old stone + // bridge, about 68 seconds of it at 42 a second, a torch-and-pitchfork mob on his heels: 7 barrels and crates + // to jump, 6 washing lines and inn signs to duck, 4 ditches and the collapsed bridge (off its ramp) to jump, + // 9 villagers who hurl pitchforks (duck) and torches (jump) from windows and roofs, any of them to shoot, 2 + // spooked horses, seven checkpoints and a lip off the end onto the green. The mob's gap is the twist (the + // brake and the hits close it, clean riding and shot torches open it). Five hearts of its own. No candy and no pickups. + room("wagon", "Torch Mob", "Hollow End sends its regards. Loudly", { + length: 2990, + ground: [[0, 40, 14], [2880, 2990, 7]], + start: 34, + key: null, + door: 2980, + bonus: true, + dark: false, + candy: [], + items: [], + spawns: [], + horde: [], + ride: { + runner: "wagon", + time: 105000, + finish: 2880, + how: "UP to jump, DOWN to duck (it slows you), hold space to shoot", + bridge: [2236, 2730], + track: [ + [[0, 16], [376, 16]], + [[384, 16], [880, 16]], + [[888, 16], [1370, 16]], + [[1378, 16], [1940, 16]], + [[1948, 16], [2236, 16], [2330, 22], [2552, 22], [2576, 29.2]], + [[2602, 23], [2690, 23], [2760, 16], [2866, 16], [2880, 19.92]], + ], + blocks: [[133,0,0], [303,0,1], [673,1,0], [1173,2,1], [1673,3,0], [2153,4,1], [2803,5,0]], + lows: [[210,216,19,0], [584,590,19,1], [978,984,19,0], [1470,1476,19,1], [1860,1866,19,0], [2652,2658,26,1]], + throwers: [[520,1,0], [790,1,1], [1290,2,0], [1590,3,1], [2080,4,0], [2330,4,1], [2400,4,0], [2490,4,1], [2730,5,0]], + horses: [[1100,2], [1790,3]], + surge: [[2330, 2540, 6]], + checks: [460, 830, 1230, 1640, 2000, 2270, 2690], + }, + }), // The Village's boss: the Beast, on the green. The arena's two ends are the // walls it clings to (not terrain: nothing to jump); boards at 12 and 17.5 // either side, the high ones above the floor-bound Beast's reach (10.5 tall). @@ -966,6 +1432,120 @@ export const ROOMS = freeze([ spawns: [["zombie", 40], ["frozen", 66]], boss: "frostwidow", }), + // Gallows Bog: a sunken boardwalk over the mire. Rotting planks with gaps, + // boards that give way, and mud that grabs you in the dips. The stage's own + // kinds: lurkers' eyes in the mud, leech swarms in the wet, wisps to lure + // the dead onto you and bog bodies risen from the muck; Stilt Boots and the + // Harpoon are placed before what they answer. + room("boardwalk", "Sunken Boardwalk", "Mind the gaps. Something lives in them", { + length: 480, + ground: [[0, 90, 6], [100, 180, 6], [190, 262, 6], [262, 268, 8.5], [268, 320, 11], [330, 402, 6], [410, 480, 6]], + mud: [[24, 84], [118, 172], [342, 396]], + shelves: [[40, 56, 11], [140, 156, 15], [200, 216, 15], [236, 252, 24], [240, 248, 15], [344, 360, 15], [372, 388, 15, "crumble"], [420, 436, 15]], + key: [244, 24], + door: 470, + candy: [[18, 8.5, 4], [41, 14, 3], [102, 8.5, 4], [141, 18, 3], [201, 18, 3], [237, 27, 3], [282, 13.5, 4], [345, 18, 3], [412, 8.5, 4], [421, 18, 3]], + items: [["boots", 20, 6], ["wings", 60, 6], ["harpoon", 128, 6], ["spread", 148, 15], ["garlic", 208, 15], ["rocket", 350, 6]], + sky: [["crystal", 238, 44], ["crystal", 244, 46], ["crystal", 250, 44]], + spawns: [["lurker", 40], ["leech", 60], ["lurker", 140], ["leech", 155], ["bogbody", 174], ["wisp", 210, 14], ["door", 214, 2, 1800, "bogbody"], ["bogbody", 290], ["lurker", 356], ["leech", 375], ["wisp", 400, 14]], + horde: ["leech", "wisp", "bogbody"], + hordeMs: 2600, + }), + // Cypress Hollow: shallow pools of black water beside the mud, moss-veiled + // boards, a little harder. + room("hollow", "Cypress Hollow", "The moss is breathing", { + length: 520, + ground: [[0, 120, 6], [120, 126, 8.5], [126, 200, 11], [200, 206, 8.5], [206, 300, 6], [310, 404, 6], [404, 410, 8.5], [410, 446, 11], [454, 520, 6]], + water: [[22, 78], [216, 286]], + mud: [[90, 114], [322, 396], [460, 510]], + shelves: [[30, 46, 11], [96, 112, 15], [140, 156, 17], [162, 178, 17, "crumble"], [226, 242, 15], [250, 266, 24], [262, 278, 15], [330, 346, 15], [356, 372, 15], [386, 402, 15, "crumble"], [420, 436, 17], [466, 482, 15]], + key: [258, 24], + door: 510, + candy: [[18, 8.5, 4], [31, 14, 3], [97, 18, 3], [141, 20, 3], [208, 8.5, 4], [227, 18, 3], [251, 27, 3], [331, 18, 3], [357, 18, 3], [412, 13.5, 4], [421, 20, 3], [467, 18, 3]], + items: [["wings", 40, 6], ["boots", 86, 6], ["lantern", 104, 15], ["spread", 232, 15], ["harpoon", 312, 6], ["hourglass", 428, 17]], + sky: [["crystal", 252, 44], ["silver", 258, 46], ["crystal", 264, 44]], + spawns: [["leech", 40], ["lurker", 100], ["wisp", 150, 16], ["bogbody", 200], ["leech", 250], ["door", 336, 3, 1500, "bogbody"], ["lurker", 340], ["wisp", 430, 16], ["bogbody", 470], ["leech", 485]], + horde: ["leech", "bogbody", "wisp"], + hordeMs: 2300, + }), + // Stilt House: the hag's house on stilts, its floors stacked shelves over + // the swamp. The hardest of the three. + room("stilts", "Stilt House", "She has been expecting you", { + length: 560, + ground: [[0, 140, 6], [150, 236, 6], [236, 242, 8.5], [242, 248, 11], [248, 254, 13.5], [254, 330, 16], [330, 336, 13.5], [336, 342, 11], [342, 348, 8.5], [348, 430, 6], [438, 560, 6]], + water: [[160, 230]], + mud: [[30, 132], [356, 424], [446, 540]], + shelves: [[20, 36, 11], [56, 72, 15], [100, 116, 15, "crumble"], [160, 176, 15], [196, 212, 15], [266, 282, 22], [292, 308, 24], [358, 374, 15], [400, 416, 15], [462, 478, 15], [500, 516, 17], [520, 536, 17, "crumble"]], + key: [300, 24], + door: 550, + candy: [[18, 8.5, 4], [57, 18, 3], [101, 18, 3], [161, 18, 3], [197, 18, 3], [266, 25, 3], [293, 27, 3], [359, 18, 3], [401, 18, 3], [440, 8.5, 4], [463, 18, 3], [501, 20, 3]], + items: [["wings", 60, 6], ["rapid", 168, 15], ["dyn", 204, 15], ["boots", 350, 6], ["harpoon", 380, 6], ["garlic", 404, 15], ["rocket", 508, 17]], + sky: [["crystal", 296, 44], ["crystal", 302, 46], ["crystal", 308, 44]], + spawns: [["lurker", 70], ["wisp", 140, 16], ["leech", 190], ["bogbody", 240], ["lurker", 390], ["door", 412, 3, 1400, "bogbody"], ["wisp", 460, 16], ["bogbody", 480], ["leech", 500]], + horde: ["bogbody", "leech"], + hordeMs: 2000, + }), + // The Bog Runner, Gallows Bog's BONUS ROUND: a fan-boat skim over black + // water with a leech swarm in its wake. A ride, not a walk; the course is + // from a one-off hash generator (no random draws), the rules are in + // ghoul-bogboat.js. + room("bogboat", "The Bog Runner", "Something swims in your wake", { + length: 2400, + ground: [[0, 2400, 9]], + start: 8, + key: null, + door: 2390, + bonus: true, + dark: false, + candy: [ + [14, 11.5, 4], [140, 11.6, 3], [144, 11.6, 3], [180, 17.5, 3], [210, 11.6, 3], [216, 10.4, 3], [216, 17.6, 3], [240, 17.6, 3], + [252, 17.5, 3], [280, 11.6, 3], [344, 10.4, 3], [344, 23.5, 3], [350, 11.6, 3], [380, 10.4, 3], [380, 17.6, 3], [416, 10.4, 3], + [416, 17.6, 3], [420, 11.6, 3], [450, 17.6, 3], [452, 17.5, 3], [452, 17.6, 3], [490, 11.6, 3], [544, 17.5, 3], [544, 17.6, 3], + [560, 11.6, 3], [580, 17.5, 3], [580, 17.6, 3], [616, 11.6, 3], [616, 17.6, 3], [630, 11.6, 3], [652, 17.5, 3], [652, 17.6, 3], + [660, 17.6, 3], [700, 11.6, 3], [744, 17.5, 3], [744, 17.6, 3], [770, 11.6, 3], [780, 11.6, 3], [780, 16.4, 3], [816, 10.4, 3], + [816, 17.6, 3], [840, 11.6, 3], [852, 10.4, 3], [852, 17.6, 3], [870, 17.6, 3], [910, 11.6, 3], [944, 10.4, 3], [944, 16.4, 3], + [980, 11.6, 3], [980, 23.5, 3], [980, 11.6, 3], [1016, 10.4, 3], [1016, 16.4, 3], [1050, 11.6, 3], [1052, 17.5, 3], [1052, 17.6, 3], + [1080, 17.6, 3], [1120, 11.6, 3], [1144, 11.6, 3], [1144, 17.6, 3], [1180, 11.6, 3], [1180, 17.6, 3], [1190, 11.6, 3], [1216, 17.6, 3], + [1252, 17.5, 3], [1252, 17.6, 3], [1260, 11.6, 3], [1290, 17.6, 3], [1330, 11.6, 3], [1344, 11.6, 3], [1344, 23.5, 3], [1380, 23.5, 3], + [1400, 11.6, 3], [1416, 17.5, 3], [1416, 23.5, 3], [1452, 10.4, 3], [1452, 16.4, 3], [1470, 11.6, 3], [1500, 17.6, 3], [1540, 11.6, 3], + [1544, 17.5, 3], [1544, 17.6, 3], [1580, 17.5, 3], [1610, 11.6, 3], [1616, 10.4, 3], [1616, 17.6, 3], [1652, 17.5, 3], [1680, 11.6, 3], + [1710, 17.6, 3], [1744, 11.6, 3], [1744, 17.6, 3], [1750, 11.6, 3], [1780, 11.6, 3], [1816, 17.5, 3], [1816, 17.6, 3], [1820, 11.6, 3], + [1852, 10.4, 3], [1852, 17.6, 3], [1890, 11.6, 3], [1920, 17.6, 3], [1944, 17.5, 3], [1944, 17.6, 3], [1960, 11.6, 3], [1980, 17.5, 3], + [1980, 23.5, 3], [2016, 17.5, 3], [2030, 11.6, 3], [2052, 10.4, 3], [2052, 23.5, 3], [2100, 11.6, 3], [2130, 17.6, 3], [2144, 10.4, 3], + [2144, 23.5, 3], [2170, 11.6, 3], [2180, 11.6, 3], [2180, 16.4, 3], [2216, 11.6, 3], [2216, 17.6, 3], [2240, 11.6, 3], [2252, 10.4, 3], + [2252, 23.5, 3], [2330, 11.5, 4], + ], + spawns: [], + horde: [], + ride: { + runner: "bogboat", + how: "LEFT or RIGHT at a bank: switch lane. UP jump, DOWN duck, SPACE shoot", + time: 100000, + finish: 2320, + checks: [480, 960, 1440, 1920], + banks: [[90, 106], [290, 306], [490, 506], [690, 706], [890, 906], [1090, 1106], [1290, 1306], [1490, 1506], [1690, 1706], [1890, 1906], [2090, 2106]], + snags: [[180, 0], [452, 0], [580, 0], [744, 0], [980, 1], [1052, 0], [1252, 0], [1344, 1], [1416, 0], [1416, 1], [1580, 0], [1652, 0], [1980, 0], [2052, 1], [2144, 1], [2252, 1]], + knees: [[252, 0], [344, 1], [544, 0], [652, 0], [1380, 1], [1544, 0], [1816, 0], [1944, 0], [1980, 1], [2016, 0]], + veils: [[340, 348, 0], [776, 784, 1], [848, 856, 0], [940, 948, 0], [940, 948, 1], [1448, 1456, 0], [1448, 1456, 1], [1848, 1856, 0], [2048, 2056, 0], [2140, 2148, 0], [2176, 2184, 1], [2248, 2256, 0]], + limbs: [[213, 219, 0], [377, 383, 0], [413, 419, 0], [813, 819, 0], [1013, 1019, 0], [1013, 1019, 1], [1613, 1619, 0]], + props: [[144, 0, 0], [544, 1, 0], [580, 1, 1], [616, 0, 1], [616, 1, 0], [780, 0, 1], [816, 1, 0], [1052, 1, 0], [1144, 0, 1], [1144, 1, 0], [1180, 0, 1], [1180, 1, 1], [1344, 0, 0], [1744, 0, 1], [1780, 0, 0], [1944, 1, 1]], + gas: [[216, 1], [380, 1], [416, 1], [452, 1], [652, 1], [744, 1], [852, 1], [980, 0], [1216, 1], [1252, 1], [1544, 1], [1616, 1], [1744, 1], [1816, 1], [1852, 1], [2180, 0], [2216, 0], [2216, 1]], + }, + }), + // The Drowning Pool, Gallows Bog's boss room: planks over open black + // water, the hag's arena. Old Mother Bog's fight lands with the pack's + // boss rules in Phase 2; `dark` is left to the roll. + room("drowning", "The Drowning Pool", "Keep to the planks, she owns the water", { + length: 200, + ground: [[0, 60, 6], [68, 132, 6], [140, 200, 6]], + shelves: [[112, 124, 12], [132, 146, 18], [160, 172, 12], [150, 162, 18]], + key: null, + door: 194, + candy: [[18, 8.5, 5], [70, 8.5, 5]], + items: [["garlic", 24, 6]], + spawns: [["zombie", 44], ["crawl", 96]], + boss: "motherbog", + }), ]); const ROOM_IDS = new Set(ROOMS.map((r) => r.id)); @@ -981,15 +1561,16 @@ function stage(id, title, sub, rooms) { } export const STAGES = freeze([ - stage("manor", "The Manor", "Where the screaming started", ["foyer", "gallery", "library", "ballroom"]), - stage("wing", "The East Wing", "The servants never left", ["kitchen", "conservatory", "attic", "crypt"]), - stage("graveyard", "The Graveyard", "Everyone here was buried in a hurry", ["lychgate", "graves", "mausoleums", "angel"]), - stage("grounds", "The Grounds", "The gardener never stopped working", ["maze", "topiary", "gazebo", "yard"]), - stage("chapel", "The Chapel", "Service is still in session", ["nave", "tower", "loft", "choir"]), - stage("sanatorium", "Blackmoor Sanatorium", "Visiting hours ended in 1912", ["admissions", "baths", "theater", "ward"]), - stage("village", "Hollow End Village", "Every curtain twitches as you pass", ["street", "inn", "square", "green"]), + stage("manor", "The Manor", "Where the screaming started", ["foyer", "gallery", "library", "banister", "ballroom"]), + stage("wing", "The East Wing", "The servants never left", ["kitchen", "conservatory", "attic", "tray", "crypt"]), + stage("graveyard", "The Graveyard", "Everyone here was buried in a hurry", ["lychgate", "graves", "mausoleums", "hearse", "angel"]), + stage("grounds", "The Grounds", "The gardener never stopped working", ["maze", "topiary", "gazebo", "mower", "yard"]), + stage("chapel", "The Chapel", "Service is still in session", ["nave", "tower", "loft", "pew", "choir"]), + stage("sanatorium", "Blackmoor Sanatorium", "Visiting hours ended in 1912", ["admissions", "baths", "theater", "codeblue", "ward"]), + stage("village", "Hollow End Village", "Every curtain twitches as you pass", ["street", "inn", "square", "wagon", "green"]), stage("mine", "The Deep Seam Mine", "They are still knocking", ["shaft", "tunnels", "collapse", "cart", "seam"]), stage("carnival", "The Midnight Carnival", "Every game is rigged in its favor", ["midway", "mirrors", "funhouse", "darkride", "bigtop"]), stage("frozen", "The Frozen Lake", "The ice remembers who fell through", ["huts", "lodge", "blackice", "sled", "widow"]), + stage("bog", "Gallows Bog", "The mud does not like to let go", ["boardwalk", "hollow", "stilts", "bogboat", "drowning"]), ]); export const stageById = (id) => STAGES.find((s) => s.id === id) || null; diff --git a/src/web-console/public/activities/ghoul-run.js b/src/web-console/public/activities/ghoul-run.js index 0ff2d10..c491f40 100644 --- a/src/web-console/public/activities/ghoul-run.js +++ b/src/web-console/public/activities/ghoul-run.js @@ -175,6 +175,64 @@ export function nextRoom(round, random, kit) { round.events.push({ type: "offer", offer: offer.slice() }); } +// A stage's intro card (ghoul-intros.js, drawn by ghoul-intro-draw.js) holds +// the first room's "Ready?" back until YOU press a key: any move (left, right, +// up, down), fire, or a click moves it on, and not before INTRO_MIN_MS (so a +// key still held never skips it; a key repeat never counts). It never moves on +// by itself: it waits as long as YOU like (a pause holds it). Only entering a +// stage's first room. +export const INTRO_MIN_MS = 1200; + +function startIntro(round, kit) { + if (!kit.introFor(round.stage)) return; + // The room's own announcement waits for the end of the card. + const at = round.events.findIndex((e) => e.type === "room"); + if (at >= 0) round.events.splice(at, 1); + round.phase = "intro"; + round.phaseMs = 0; + round.introMs = 0; + round.input.jump = 0; + round.events.push({ type: "intro", stage: round.stage }); +} + +// Whether a full-field card (a stage's intro or a boss's) is up. +export const onCard = (round) => round.phase === "intro" || round.phase === "bossintro"; + +// A boss room's intro card (ghoul-boss-intros.js, drawn by ghoul-bossintro-draw.js): +// the same rules as the stage's card, shown once when the boss room is entered +// (after the last room or the bonus ride, or from the stage select), never on +// a respawn. The boss room is already set up behind it. +function startBossIntro(round, kit) { + const id = round.spec && round.spec.boss; + if (!id || !kit.bossIntroFor(id)) return; + const at = round.events.findIndex((e) => e.type === "room"); + if (at >= 0) round.events.splice(at, 1); + round.phase = "bossintro"; + round.phaseMs = 0; + round.introMs = 0; + round.input.jump = 0; + round.events.push({ type: "bossIntro", boss: id, stage: round.stage }); +} + +function endIntro(round, kit) { + round.phase = "ready"; + round.phaseMs = round.bonusRound ? (round.spec.ride && round.spec.ride.ready) || kit.BONUS_READY_MS : kit.READY_MS; + round.input.jump = 0; + round.events.push({ type: "room", room: round.room }); +} + +// One slice of the card: it only counts the time (the lockout and the animation). +export function stepIntro(round, ms) { + round.introMs = (round.introMs || 0) + ms; +} + +// A move key, fire or a click: on into the room, once the card has been up a moment. +export function takeIntro(round, kit) { + if (!onCard(round) || (round.introMs || 0) < INTRO_MIN_MS) return false; + endIntro(round, kit); + return true; +} + function enter(round, id, kit) { round.room++; setupRoom(round, id, kit); @@ -183,6 +241,7 @@ function enter(round, id, kit) { // A bonus room announces itself before its name. if (round.bonusRound) round.events.push({ type: "bonusStart", hearts: round.bonusRound.hearts, max: round.bonusRound.max, how: round.spec.ride ? round.spec.ride.how : undefined }); round.events.push({ type: "room", room: round.room }); + startBossIntro(round, kit); } // While choosing: `dir` -1 or 1 moves the pick between what is offered. @@ -209,6 +268,7 @@ export function pickStage(round, i = round.pick, kit) { round.stageAt = 0; round.events.push({ type: "stage", stage: st.id, n: round.cleared.length + 1, of: STAGES.length }); enter(round, st.rooms[0], kit); + startIntro(round, kit); return true; } @@ -248,6 +308,7 @@ export function takeSelect(round, kit) { round.stageAt = sel.room; round.events.push({ type: "stage", stage: st.id, n: 1, of: kit.STAGES.length }); enter(round, st.rooms[sel.room], kit); + if (!sel.room) startIntro(round, kit); return true; } diff --git a/src/web-console/public/activities/ghoul-sfx-banister.js b/src/web-console/public/activities/ghoul-sfx-banister.js new file mode 100644 index 0000000..150bcea --- /dev/null +++ b/src/web-console/public/activities/ghoul-sfx-banister.js @@ -0,0 +1,241 @@ +// Plan2Code Web Console - ghoul: The Grand Banister's own sound effects and music track, merged into ghoul-sfx.js; defines only. +// +// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulBan` sound for the ride's +// things) and `music` (a track for the room, named in ROOM_MUSIC in ghoul.js). Built from the house +// tone layers only (no external audio), each tone under 1.2 s; the music is a loop built from +// parts. These are first drafts, to be picked by ear. A name may be defined only once across +// tones.js and every game's file. No imports. + +export const BANISTER_SFX = { + tones: { + // The Grand Banister: the bonus ride: you slide down the grand staircase's polished rail, jumping, ducking and shooting. + // Jumps: A push off the wood and a rush of air. + ghoulBanJump: { + layers: [ + { type: "noise", seconds: 0.2, attack: 0.06, gain: 0.34, filter: { type: "bandpass", from: 2600, to: 1400, q: 4 } }, + { type: "triangle", from: 170, to: 130, seconds: 0.08, attack: 0.002, gain: 0.5, filter: { type: "lowpass", from: 700, to: 500, q: 1 } }, + ], + }, + // Lands: A slap of wood and a squeak of polish. + ghoulBanLand: { + layers: [ + { type: "triangle", from: 150, to: 95, seconds: 0.12, attack: 0.002, gain: 0.7, filter: { type: "lowpass", from: 800, to: 500, q: 1 } }, + { type: "brown", seconds: 0.1, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 400, to: 300, q: 1 } }, + { type: "sine", from: 1400, to: 1900, seconds: 0.09, attack: 0.01, gain: 0.12, delay: 0.05, vibrato: { rate: 30, depth: 0.04 } }, + ], + }, + // Launches off the end of the rail: A long whoosh and a whoop. + ghoulBanLaunch: { + layers: [ + { type: "noise", seconds: 0.8, attack: 0.3, gain: 0.5, filter: { type: "bandpass", from: 400, to: 2400, q: 2 } }, + { type: "pink", seconds: 0.8, attack: 0.4, gain: 0.3, filter: { type: "bandpass", from: 240, to: 1700, q: 1 } }, + { type: "sine", from: 320, to: 880, seconds: 0.5, attack: 0.1, gain: 0.36, vibrato: { rate: 6, depth: 0.05 } }, + ], + }, + // Ducks: A quick swish under the lamp. + ghoulBanDuck: { + layers: [ + { type: "noise", seconds: 0.18, attack: 0.07, gain: 0.5, filter: { type: "bandpass", from: 500, to: 2400, q: 1.5 } }, + ], + }, + // Switches rails: A brass ring. + ghoulBanSwitch: { + layers: [ + { type: "sine", from: 1568, to: 1555, seconds: 0.3, attack: 0.003, gain: 0.3 }, + { type: "sine", from: 3136, to: 3110, seconds: 0.2, attack: 0.003, gain: 0.14 }, + { type: "sine", from: 2349, to: 2330, seconds: 0.24, attack: 0.003, gain: 0.18, delay: 0.05 }, + ], + }, + // Crash: Wood cracks and china and crystal shatter. + ghoulBanCrash: { + layers: [ + { type: "sine", from: 90, to: 34, seconds: 0.22, attack: 0, gain: 0.9 }, + { type: "brown", seconds: 0.18, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 260, to: 260, q: 1 } }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 3600, to: 2400, q: 5 }, delay: 0.02 }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 4400, to: 3000, q: 6 }, delay: 0.09 }, + { type: "sine", from: 3900, to: 3700, seconds: 0.3, attack: 0.002, gain: 0.12, delay: 0.1 }, + ], + }, + // Checkpoint: A chime of the hall clock. + ghoulBanCheck: { + layers: [ + { type: "sine", from: 784, to: 780, seconds: 0.5, attack: 0.004, gain: 0.34 }, + { type: "sine", from: 1568, to: 1560, seconds: 0.4, attack: 0.004, gain: 0.14 }, + { type: "sine", from: 988, to: 984, seconds: 0.6, attack: 0.004, gain: 0.34, delay: 0.16 }, + { type: "sine", from: 1976, to: 1968, seconds: 0.45, attack: 0.004, gain: 0.14, delay: 0.16 }, + ], + }, + // Finish: A fanfare of the house organ. + ghoulBanFinish: { + layers: [ + { type: "triangle", seconds: 0.95, attack: 0.01, gain: 0.7, notes: [440, 523, 659, 880] }, + { type: "square", seconds: 0.95, attack: 0.01, gain: 0.12, notes: [220, 262, 330, 440], filter: { type: "lowpass", from: 1600, to: 1200, q: 1 } }, + { type: "sine", seconds: 0.95, attack: 0.01, gain: 0.22, notes: [880, 1047, 1319, 1760] }, + ], + }, + // Butler: A ghostly butler on the stairs: it bows, then lunges with its silver tray. Shoot it twice, or jump it. + // Bows: A polite ring of a service bell. + ghoulBanButlerWarn: { + layers: [ + { type: "sine", from: 2637, to: 2620, seconds: 0.3, attack: 0.002, gain: 0.3 }, + { type: "sine", from: 5274, to: 5240, seconds: 0.16, attack: 0.002, gain: 0.1 }, + { type: "sine", from: 2637, to: 2620, seconds: 0.34, attack: 0.002, gain: 0.3, delay: 0.2 }, + { type: "sine", from: 5274, to: 5240, seconds: 0.18, attack: 0.002, gain: 0.1, delay: 0.2 }, + ], + }, + // Lunges: A hiss of cold air and a hollow moan. + ghoulBanButlerLunge: { + layers: [ + { type: "noise", seconds: 0.3, attack: 0.1, gain: 0.4, filter: { type: "bandpass", from: 1800, to: 900, q: 2 } }, + { type: "sawtooth", from: 200, to: 140, seconds: 0.4, attack: 0.05, gain: 0.4, vibrato: { rate: 9, depth: 0.12 }, filter: { type: "bandpass", from: 800, to: 420, q: 3 } }, + { type: "square", from: 100, to: 80, seconds: 0.4, attack: 0.05, gain: 0.16, filter: { type: "lowpass", from: 420, to: 420, q: 1 } }, + ], + }, + // Takes a bolt: A clang on the tray. + ghoulBanButlerHit: { + layers: [ + { type: "noise", seconds: 0.04, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 2800, to: 1800, q: 3 } }, + { type: "square", from: 1250, to: 1100, seconds: 0.12, attack: 0.002, gain: 0.26, filter: { type: "bandpass", from: 1800, to: 1400, q: 4 } }, + { type: "sine", from: 2100, to: 2040, seconds: 0.3, attack: 0.002, gain: 0.14 }, + ], + }, + // Breaks: The tray clatters down and the ghost sighs away. + ghoulBanButlerBreak: { + layers: [ + { type: "noise", seconds: 0.04, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 2800, to: 1800, q: 3 } }, + { type: "square", from: 1100, to: 800, seconds: 0.1, attack: 0.002, gain: 0.26, filter: { type: "bandpass", from: 1600, to: 1200, q: 4 } }, + { type: "noise", seconds: 0.04, delay: 0.1, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 2200, to: 1500, q: 4 } }, + { type: "noise", seconds: 0.04, delay: 0.17, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 3000, to: 2000, q: 4 } }, + { type: "triangle", from: 330, to: 220, seconds: 0.6, attack: 0.25, gain: 0.34, vibrato: { rate: 5, depth: 0.03 }, filter: { type: "lowpass", from: 1400, to: 800, q: 1 }, delay: 0.1 }, + { type: "pink", seconds: 0.6, attack: 0.3, gain: 0.12, filter: { type: "bandpass", from: 500, to: 300, q: 5 }, delay: 0.1 }, + ], + }, + // Cobweb: A web strung across the rail: shoot it for points; riding through only tears it. + // Tears: A soft dry rip. + ghoulBanWebTear: { + layers: [ + { type: "noise", seconds: 0.16, attack: 0.02, gain: 0.3, filter: { type: "highpass", from: 2400, to: 3600, q: 1 } }, + { type: "noise", seconds: 0.1, attack: 0.01, gain: 0.2, delay: 0.05, filter: { type: "bandpass", from: 4200, to: 3200, q: 3 } }, + ], + }, + // Shot: A quick zip and a pop. + ghoulBanWebShot: { + layers: [ + { type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 3400, to: 2200, q: 3 } }, + { type: "sine", from: 1800, to: 700, seconds: 0.08, attack: 0.002, gain: 0.2 }, + { type: "noise", seconds: 0.12, attack: 0.01, gain: 0.2, delay: 0.04, filter: { type: "highpass", from: 3000, to: 4200, q: 1 } }, + ], + }, + }, + music: { + // The Grand Banister: a harpsichord waltz at a gallop. The hall's harpsichord runs + // broken chords over a slow organ and a walking bass in A minor (Am, F, C, E), + // with a thin violin line over the second round and a ticking clock of hats. At + // high dread a chandelier-bright octave and a riser join. + ghoulBanister: { + bpm: 150, + rush: 12, + voices: { + harp: { wave: "pulse", duty: 0.25, gain: 0.13, decay: 0.16, sustain: 0.15 }, + harp2: { wave: "pulse", duty: 0.125, gain: 0.06, decay: 0.12, sustain: 0.1, from: 0.85 }, + organ: { wave: "triangle", gain: 0.1, decay: 0.8, sustain: 0.85, from: 0.1 }, + violin: { wave: "sawtooth", gain: 0.045, decay: 0.3, sustain: 0.7, from: 0.35, vibrato: { rate: 5.2, depth: 0.035, delay: 0.1 } }, + bass: { wave: "triangle", gain: 0.4, decay: 0.1, sustain: 0.5 }, + kick: { kit: true, gain: 0.24, from: 0.2 }, + hat: { kit: true, gain: 0.08, from: 0.45 }, + snap: { kit: true, gain: 0.14, from: 0.6 }, + riser: { wave: "sawtooth", gain: 0.03, decay: 0.3, sustain: 1, from: 0.8, vibrato: { rate: 0.6, depth: 0.04, delay: 0 } }, + }, + patterns: { + A: { + harp: + "A4 . C5 . E5 . A5 . E5 . C5 . E5 . C5 . | F4 . A4 . C5 . F5 . C5 . A4 . C5 . A4 . | " + + "E4 . G4 . C5 . E5 . C5 . G4 . C5 . G4 . | E4 . G#4 . B4 . E5 . D5 . B4 . G#4 . B4 .", + harp2: + "A5 . . . E6 . . . A5 . . . E6 . . . | F5 . . . C6 . . . F5 . . . C6 . . . | " + + "E5 . . . C6 . . . E5 . . . C6 . . . | E5 . . . B5 . . . E5 . . . B5 . . .", + organ: + "A3^037 - - - - - - - - - - - - - - - | F3^047 - - - - - - - - - - - - - - - | " + + "C3^047 - - - - - - - - - - - - - - - | E3^047 - - - - - - - - - - - - - - -", + violin: + ". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " + + ". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .", + bass: + "A2 . . . . . A2 . . . . . A2 . . . | F2 . . . . . F2 . . . . . F2 . . . | " + + "C3 . . . . . C3 . . . . . C3 . . . | E2 . . . . . E2 . . . . . E2 . . .", + kick: + "k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . . | " + + "k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . .", + hat: + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " + + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .", + snap: + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .", + riser: + "A3^037 - - - - - - - - - - - - - - - | F3^047 - - - - - - - - - - - - - - - | " + + "C4^047 - - - - - - - - - - - - - - - | E3^047 - - - - - - - - - - - - - - -", + }, + B: { + harp: + "A4 . C5 . E5 . A5 . E5 . C5 . E5 . C5 . | D5 . F5 . A5 . D6 . A5 . F5 . A5 . F5 . | " + + "C5 . E5 . G5 . C6 . G5 . E5 . G5 . E5 . | B4 . D#5 . F#5 . B5 . F#5 . D#5 . G#4 . B4 .", + harp2: + "A5 . . . E6 . . . A5 . . . E6 . . . | D6 . . . A5 . . . D6 . . . A5 . . . | " + + "C6 . . . G5 . . . C6 . . . G5 . . . | B5 . . . F#5 . . . B5 . . . F#5 . . .", + organ: + "A3^037 - - - - - - - - - - - - - - - | D3^037 - - - - - - - - - - - - - - - | " + + "C3^047 - - - - - - - - - - - - - - - | B2^047 - - - - - - - - - - - - - - -", + violin: + "E5 - - - - - D5 - C5 - - - B4 - - - | A4 - - - - - - - D5 - - - F5 - - - | " + + "G5 - - - - - E5 - C5 - - - E5 - - - | D#5 - - - - - F#5 - B4 - - - - - - -", + bass: + "A2 . . . . . A2 . . . . . A2 . . . | D3 . . . . . D3 . . . . . D3 . . . | " + + "C3 . . . . . C3 . . . . . C3 . . . | B2 . . . . . B2 . . . . . B2 . . .", + kick: + "k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . . | " + + "k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . .", + hat: + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " + + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .", + snap: + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .", + riser: + "A3^037 - - - - - - - - - - - - - - - | D3^037 - - - - - - - - - - - - - - - | " + + "C4^047 - - - - - - - - - - - - - - - | B3^047 - - - - - - - - - - - - - - -", + }, + C: { + harp: + "E5 . A4 . C5 . E5 . A5 . E5 . C5 . A4 . | F5 . A4 . C5 . F5 . A5 . F5 . C5 . A4 . | " + + "G5 . C5 . E5 . G5 . C6 . G5 . E5 . C5 . | G#4 . B4 . E5 . G#5 . B5 . G#5 . E5 . B4 .", + harp2: + "A5 A5 . . E6 E6 . . A5 A5 . . E6 E6 . . | F5 F5 . . C6 C6 . . F5 F5 . . C6 C6 . . | " + + "E5 E5 . . C6 C6 . . E5 E5 . . C6 C6 . . | E5 E5 . . B5 B5 . . E5 E5 . . B5 B5 . .", + organ: + "A3^037 - - - - - - - - - - - - - - - | F3^047 - - - - - - - - - - - - - - - | " + + "C3^047 - - - - - - - - - - - - - - - | E3^047 - - - - - - - - - - - - - - -", + violin: + "A5 - - - - - - - E5 - - - A5 - - - | A5 - - - - - - - C6 - - - A5 - - - | " + + "G5 - - - - - - - E5 - - - G5 - - - | G#5 - - - - - B5 - E6 - - - - - - -", + bass: + "A2 . A2 . . . A2 . A2 . A2 . . . A2 . | F2 . F2 . . . F2 . F2 . F2 . . . F2 . | " + + "C3 . C3 . . . C3 . C3 . C3 . . . C3 . | E2 . E2 . . . E2 . E2 . E2 . . . E2 .", + kick: + "k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . . | " + + "k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . .", + hat: + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " + + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .", + snap: + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .", + riser: + "A3^037 - - - - - - - - - - - - - - - | F3^047 - - - - - - - - - - - - - - - | " + + "C4^047 - - - - - - - - - - - - - - - | E3^047 - - - - - - - - - - - - - - -", + }, + }, + order: ["A", "A", "B", "A", "C", "B", "A", "C"], + }, + }, +}; diff --git a/src/web-console/public/activities/ghoul-sfx-bog.js b/src/web-console/public/activities/ghoul-sfx-bog.js new file mode 100644 index 0000000..e52b560 --- /dev/null +++ b/src/web-console/public/activities/ghoul-sfx-bog.js @@ -0,0 +1,339 @@ +// Plan2Code Web Console - ghoul: Gallows Bog's own sound effects and music tracks, merged into ghoul-sfx.js; defines only. +// +// Same shape and rules as ghoul-sfx-mine.js: `tones` (the stage's monsters' and boss's +// `ghoul` sounds, none over 1.2 s with its delay) and `music` (a track per room, +// named in ROOM_MUSIC in ghoul.js). The tones are first drafts (option 1 of each act on +// prototypes/sounds/ghoul-rush/bog.html) until the user's vote replaces them with +// prototypes/ghoul-rush-tools/wire-bog-sounds.cjs; the rooms play borrowed tracks until +// wire-music-bog.cjs lands the picked ones. A name may be defined only once across +// tones.js and every game's file. No imports. + +export const BOG_SFX = { + tones: { + // Bog Lurker: A pair of eyes in the black water: it watches from under the boards, sinks when you turn, then snaps at your feet. + // Surfaces: Bubbles and ripple. + ghoulLurkerAppear: { + layers: [ + { type: "sine", from: 861, to: 1464, seconds: 0.05, delay: 0.02, attack: 0, gain: 0.35 }, + { type: "sine", from: 856, to: 1456, seconds: 0.05, delay: 0.12, attack: 0, gain: 0.35 }, + { type: "sine", from: 691, to: 1174, seconds: 0.05, delay: 0.16, attack: 0, gain: 0.35 }, + { type: "sine", from: 648, to: 1101, seconds: 0.05, delay: 0.12, attack: 0, gain: 0.35 }, + { type: "noise", seconds: 0.2, attack: 0.01, gain: 0.4, filter: { type: "bandpass", from: 700, to: 2600, q: 1.2 } }, + { type: "pink", seconds: 0.26, attack: 0.03, gain: 0.25, delay: 0.04, filter: { type: "highpass", from: 1800, to: 3000, q: 1 } }, + { type: "sine", from: 300, to: 120, seconds: 0.12, attack: 0.003, gain: 0.2 }, + ], + }, + // Snaps: Jaws clap. + ghoulLurkerSnap: { + layers: [ + { type: "noise", seconds: 0.05, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 1080, to: 720, q: 2 } }, + { type: "square", from: 540, to: 180, seconds: 0.05, attack: 0, gain: 0.36 }, + { type: "noise", seconds: 0.04, delay: 0.06, attack: 0, gain: 0.63, filter: { type: "bandpass", from: 1560, to: 1080, q: 3 } }, + { type: "sine", from: 99, to: 36, seconds: 0.25, attack: 0, gain: 0.7, delay: 0.03 }, + { type: "brown", seconds: 0.2, attack: 0, gain: 0.56, filter: { type: "lowpass", from: 288, to: 288, q: 1 }, delay: 0.03 }, + { type: "noise", seconds: 0.25, attack: 0.01, gain: 0.4, delay: 0.02, filter: { type: "bandpass", from: 700, to: 2600, q: 1.2 } }, + { type: "pink", seconds: 0.33, attack: 0.03, gain: 0.25, delay: 0.06, filter: { type: "highpass", from: 1800, to: 3000, q: 1 } }, + { type: "sine", from: 300, to: 120, seconds: 0.12, attack: 0.003, gain: 0.2, delay: 0.02 }, + ], + }, + // Sinks: Slow gurgle under. + ghoulLurkerSink: { + layers: [ + { type: "sine", from: 98, to: 74, seconds: 0.7, attack: 0.05, gain: 0.9, vibrato: { rate: 15, depth: 0.4 } }, + { type: "brown", seconds: 0.7, attack: 0.05, gain: 0.7, filter: { type: "lowpass", from: 700, to: 300, q: 1 } }, + { type: "sine", from: 147, to: 118, seconds: 0.49, delay: 0.11, attack: 0.03, gain: 0.4, vibrato: { rate: 9, depth: 0.5 } }, + { type: "sine", from: 240, to: 55, seconds: 0.5, attack: 0.02, gain: 0.4, delay: 0.1 }, + { type: "brown", seconds: 0.5, attack: 0.04, gain: 0.4, delay: 0.1, filter: { type: "lowpass", from: 700, to: 110, q: 1 } }, + { type: "noise", seconds: 0.25, attack: 0.05, gain: 0.15, delay: 0.15, filter: { type: "bandpass", from: 900, to: 300, q: 2 } }, + ], + }, + // Hit: Grunt. + ghoulLurkerHurt: { + layers: [ + { type: "sawtooth", from: 82, to: 57, seconds: 0.16, attack: 0.01, gain: 0.9, vibrato: { rate: 8, depth: 0.1 }, filter: { type: "lowpass", from: 891, to: 891, q: 1 } }, + { type: "brown", seconds: 0.13, attack: 0.01, gain: 0.6, filter: { type: "lowpass", from: 450, to: 450, q: 1 } }, + ], + }, + // Dies: Sinking groan. + ghoulLurkerDie: { + layers: [ + { type: "sawtooth", from: 69, to: 49, seconds: 0.9, attack: 0.12, gain: 0.9, vibrato: { rate: 8, depth: 0.07 }, filter: { type: "lowpass", from: 900, to: 450, q: 5 } }, + { type: "sawtooth", from: 70, to: 49, seconds: 0.9, attack: 0.14, gain: 0.5, filter: { type: "lowpass", from: 720, to: 360, q: 3 } }, + { type: "brown", seconds: 0.9, attack: 0.1, gain: 0.6, filter: { type: "bandpass", from: 252, to: 189, q: 2 } }, + { type: "sine", from: 98, to: 74, seconds: 0.6, attack: 0.05, gain: 0.45, vibrato: { rate: 15, depth: 0.4 }, delay: 0.3 }, + { type: "brown", seconds: 0.6, attack: 0.05, gain: 0.35, filter: { type: "lowpass", from: 700, to: 300, q: 1 }, delay: 0.3 }, + { type: "sine", from: 147, to: 118, seconds: 0.42, delay: 0.39, attack: 0.03, gain: 0.2, vibrato: { rate: 9, depth: 0.5 } }, + ], + }, + // Leech Swarm: A drifting cloud of black leeches over the water: they flow toward you, latch on and drain a life. + // Drifts in: Chittering. + ghoulLeechAppear: { + layers: [ + { type: "square", from: 566, to: 396, seconds: 0.03, gain: 0.5, filter: { type: "bandpass", from: 849, to: 566, q: 4 } }, + { type: "square", from: 668, to: 468, seconds: 0.03, delay: 0.04, gain: 0.5, filter: { type: "bandpass", from: 1002, to: 668, q: 4 } }, + { type: "square", from: 649, to: 454, seconds: 0.03, delay: 0.08, gain: 0.5, filter: { type: "bandpass", from: 974, to: 649, q: 4 } }, + { type: "square", from: 596, to: 417, seconds: 0.03, delay: 0.12, gain: 0.5, filter: { type: "bandpass", from: 893, to: 596, q: 4 } }, + { type: "square", from: 605, to: 423, seconds: 0.03, delay: 0.16, gain: 0.5, filter: { type: "bandpass", from: 907, to: 605, q: 4 } }, + { type: "square", from: 559, to: 392, seconds: 0.03, delay: 0.2, gain: 0.5, filter: { type: "bandpass", from: 839, to: 559, q: 4 } }, + { type: "square", from: 626, to: 439, seconds: 0.03, delay: 0.24, gain: 0.5, filter: { type: "bandpass", from: 940, to: 626, q: 4 } }, + { type: "square", from: 433, to: 303, seconds: 0.03, delay: 0.28, gain: 0.5, filter: { type: "bandpass", from: 649, to: 433, q: 4 } }, + ], + }, + // Latches on: Squelch and chitter. + ghoulLeechLatch: { + layers: [ + { type: "brown", seconds: 0.3, attack: 0.01, gain: 0.8, filter: { type: "lowpass", from: 1560, to: 180, q: 1 } }, + { type: "sine", from: 312, to: 72, seconds: 0.22, attack: 0.01, gain: 0.56 }, + { type: "noise", seconds: 0.12, attack: 0.01, gain: 0.32, filter: { type: "bandpass", from: 1080, to: 360, q: 3 } }, + { type: "square", from: 661, to: 463, seconds: 0.03, delay: 0.1, gain: 0.5, filter: { type: "bandpass", from: 992, to: 661, q: 4 } }, + { type: "square", from: 532, to: 372, seconds: 0.03, delay: 0.13, gain: 0.5, filter: { type: "bandpass", from: 797, to: 532, q: 4 } }, + { type: "square", from: 466, to: 326, seconds: 0.03, delay: 0.16, gain: 0.5, filter: { type: "bandpass", from: 698, to: 466, q: 4 } }, + { type: "square", from: 462, to: 323, seconds: 0.03, delay: 0.19, gain: 0.5, filter: { type: "bandpass", from: 693, to: 462, q: 4 } }, + { type: "square", from: 569, to: 398, seconds: 0.03, delay: 0.22, gain: 0.5, filter: { type: "bandpass", from: 853, to: 569, q: 4 } }, + { type: "square", from: 556, to: 389, seconds: 0.03, delay: 0.25, gain: 0.5, filter: { type: "bandpass", from: 834, to: 556, q: 4 } }, + ], + }, + // Hit: Squeak. + ghoulLeechHurt: { + layers: [ + { type: "sine", from: 462, to: 601, seconds: 0.08, attack: 0.01, gain: 0.8, vibrato: { rate: 40, depth: 0.08 } }, + { type: "sine", from: 554, to: 716, seconds: 0.07, delay: 0.1, attack: 0.01, gain: 0.6, vibrato: { rate: 40, depth: 0.08 } }, + ], + }, + // Dies: Splat. + ghoulLeechDie: { + layers: [ + { type: "noise", seconds: 0.28, attack: 0, gain: 0.9, filter: { type: "lowpass", from: 3900, to: 300, q: 1 } }, + { type: "square", from: 210, to: 60, seconds: 0.16, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 900, to: 900, q: 1 } }, + { type: "sine", from: 1350, to: 1950, seconds: 0.05, delay: 0.2, gain: 0.25 }, + { type: "sine", from: 1140, to: 1650, seconds: 0.05, delay: 0.34, gain: 0.18 }, + ], + }, + // Will-o'-Wisp: A cold green light that drifts over the water: the dead are pulled toward you inside its glow; a shot puts it out, and it relights. + // Glows: Rising chime. + ghoulWispAppear: { + layers: [ + { type: "sine", from: 880, to: 1320, seconds: 0.5, attack: 0.02, gain: 0.5 }, + { type: "sine", from: 1175, to: 1760, seconds: 0.5, attack: 0.02, gain: 0.3, delay: 0.1 }, + ], + }, + // Goes out: Falling ring. + ghoulWispOut: { + layers: [ + { type: "sine", notes: [1000, 840, 670, 500], seconds: 0.7, attack: 0.02, gain: 0.6, vibrato: { rate: 7, depth: 0.02 } }, + { type: "triangle", notes: [1500, 1260, 1000, 750], seconds: 0.7, attack: 0.02, gain: 0.25 }, + ], + }, + // Relights: Spark and chime. + ghoulWispRelight: { + layers: [ + { type: "noise", seconds: 0.06, attack: 0.003, gain: 0.5, filter: { type: "bandpass", from: 3500, to: 5000, q: 3 } }, + { type: "sine", from: 700, to: 1400, seconds: 0.4, attack: 0.02, gain: 0.5, delay: 0.05 }, + ], + }, + // Burns bright: Held wail. + ghoulWispOn: { + layers: [ + { type: "sine", from: 1100, to: 1650, seconds: 0.38, attack: 0.15, gain: 0.48, vibrato: { rate: 6, depth: 0.04 } }, + { type: "sine", from: 1650, to: 770, seconds: 0.56, delay: 0.34, attack: 0.04, gain: 0.48, vibrato: { rate: 6, depth: 0.05 } }, + { type: "triangle", from: 2211, to: 1540, seconds: 0.9, attack: 0.3, gain: 0.12 }, + { type: "pink", seconds: 0.9, attack: 0.3, gain: 0.12, filter: { type: "bandpass", from: 2200, to: 2200, q: 8 } }, + ], + }, + // Hit: Squeak. + ghoulWispHurt: { + layers: [ + { type: "sine", from: 1300, to: 1690, seconds: 0.08, attack: 0.01, gain: 0.8, vibrato: { rate: 40, depth: 0.08 } }, + { type: "sine", from: 1560, to: 2015, seconds: 0.07, delay: 0.1, attack: 0.01, gain: 0.6, vibrato: { rate: 40, depth: 0.08 } }, + ], + }, + // Dies: Long falling ring. + ghoulWispDie: { + layers: [ + { type: "sine", notes: [1200, 1008, 804, 600], seconds: 1, attack: 0.02, gain: 0.6, vibrato: { rate: 7, depth: 0.02 } }, + { type: "triangle", notes: [1800, 1512, 1200, 900], seconds: 1, attack: 0.02, gain: 0.25 }, + ], + }, + // Bog Body: An old drowned thing that climbs out of the muck and walks: it is harmless while it climbs, then it drags at you. + // Shows itself: Low groan. + ghoulBogbodyAppear: { + layers: [ + { type: "sawtooth", from: 83, to: 59, seconds: 0.8, attack: 0.12, gain: 0.9, vibrato: { rate: 20, depth: 0.07 }, filter: { type: "lowpass", from: 800, to: 400, q: 5 } }, + { type: "sawtooth", from: 83, to: 58, seconds: 0.8, attack: 0.14, gain: 0.5, filter: { type: "lowpass", from: 640, to: 320, q: 3 } }, + { type: "brown", seconds: 0.8, attack: 0.1, gain: 0.6, filter: { type: "bandpass", from: 300, to: 225, q: 2 } }, + ], + }, + // Climbs out: Squelch and groan. + ghoulBogbodyRise: { + layers: [ + { type: "brown", seconds: 0.3, attack: 0.01, gain: 0.8, filter: { type: "lowpass", from: 780, to: 90, q: 1 } }, + { type: "sine", from: 156, to: 36, seconds: 0.22, attack: 0.01, gain: 0.56 }, + { type: "noise", seconds: 0.12, attack: 0.01, gain: 0.32, filter: { type: "bandpass", from: 540, to: 180, q: 3 } }, + { type: "sawtooth", from: 60, to: 94, seconds: 0.8, attack: 0.12, gain: 0.54, vibrato: { rate: 20, depth: 0.07 }, filter: { type: "lowpass", from: 800, to: 400, q: 5 }, delay: 0.1 }, + { type: "sawtooth", from: 60, to: 93, seconds: 0.8, attack: 0.14, gain: 0.3, filter: { type: "lowpass", from: 640, to: 320, q: 3 }, delay: 0.1 }, + { type: "brown", seconds: 0.8, attack: 0.1, gain: 0.36, filter: { type: "bandpass", from: 300, to: 225, q: 2 }, delay: 0.1 }, + ], + }, + // Hit: Grunt. + ghoulBogbodyHurt: { + layers: [ + { type: "sawtooth", from: 98, to: 68, seconds: 0.16, attack: 0.01, gain: 0.9, vibrato: { rate: 20, depth: 0.1 }, filter: { type: "lowpass", from: 880, to: 880, q: 1 } }, + { type: "brown", seconds: 0.13, attack: 0.01, gain: 0.6, filter: { type: "lowpass", from: 500, to: 500, q: 1 } }, + ], + }, + // Dies: Long groan, squelch. + ghoulBogbodyDie: { + layers: [ + { type: "sawtooth", from: 83, to: 59, seconds: 1, attack: 0.12, gain: 0.9, vibrato: { rate: 20, depth: 0.07 }, filter: { type: "lowpass", from: 800, to: 400, q: 5 } }, + { type: "sawtooth", from: 83, to: 58, seconds: 1, attack: 0.14, gain: 0.5, filter: { type: "lowpass", from: 640, to: 320, q: 3 } }, + { type: "brown", seconds: 1, attack: 0.1, gain: 0.6, filter: { type: "bandpass", from: 300, to: 225, q: 2 } }, + { type: "brown", seconds: 0.3, attack: 0.01, gain: 0.7, filter: { type: "lowpass", from: 910, to: 105, q: 1 }, delay: 0.5 }, + { type: "sine", from: 182, to: 42, seconds: 0.22, attack: 0.01, gain: 0.49, delay: 0.5 }, + { type: "noise", seconds: 0.12, attack: 0.01, gain: 0.28, filter: { type: "bandpass", from: 630, to: 210, q: 3 }, delay: 0.5 }, + ], + }, + // Old Mother Bog: A hag of mud and reeds stewing in her cauldron in the Drowning Pool: she sends a wave of mud down the boards, spits from the pot, then sinks and comes up somewhere else. + // Wakes: Big roar. + ghoulMotherWake: { + layers: [ + { type: "sawtooth", from: 54, to: 69, seconds: 0.39, attack: 0.05, gain: 0.9, vibrato: { rate: 5, depth: 0.1 }, filter: { type: "lowpass", from: 300, to: 2200, q: 4 } }, + { type: "sawtooth", from: 69, to: 42, seconds: 0.77, delay: 0.33, attack: 0.02, gain: 0.9, vibrato: { rate: 5, depth: 0.12 }, filter: { type: "lowpass", from: 2200, to: 260, q: 4 } }, + { type: "sawtooth", from: 30, to: 22, seconds: 1.1, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 500, to: 500, q: 1 } }, + { type: "brown", seconds: 1.1, attack: 0.06, gain: 0.8, filter: { type: "lowpass", from: 900, to: 180, q: 1 } }, + { type: "sine", from: 30, to: 21, seconds: 1.1, attack: 0.05, gain: 0.7 }, + ], + }, + // Winds up the wave: Rising groan. + ghoulMotherWind: { + layers: [ + { type: "sawtooth", from: 48, to: 75, seconds: 0.9, attack: 0.12, gain: 0.9, vibrato: { rate: 5, depth: 0.07 }, filter: { type: "lowpass", from: 1000, to: 500, q: 5 } }, + { type: "sawtooth", from: 48, to: 75, seconds: 0.9, attack: 0.14, gain: 0.5, filter: { type: "lowpass", from: 800, to: 400, q: 3 } }, + { type: "brown", seconds: 0.9, attack: 0.1, gain: 0.6, filter: { type: "bandpass", from: 240, to: 180, q: 2 } }, + { type: "noise", seconds: 0.6, attack: 0.21, gain: 0.4, filter: { type: "bandpass", from: 180, to: 1080, q: 1.5 }, delay: 0.2 }, + ], + }, + // Mud wave: Rumble and splash. + ghoulMotherWave: { + layers: [ + { type: "brown", seconds: 1, attack: 0.08, gain: 0.8, filter: { type: "lowpass", from: 180, to: 70, q: 1 } }, + { type: "sine", from: 48, to: 30, seconds: 1, attack: 0.05, gain: 0.64 }, + { type: "noise", seconds: 0.4, attack: 0.01, gain: 0.64, delay: 0.1, filter: { type: "bandpass", from: 490, to: 1820, q: 1.2 } }, + { type: "pink", seconds: 0.52, attack: 0.03, gain: 0.4, delay: 0.14, filter: { type: "highpass", from: 1260, to: 2100, q: 1 } }, + { type: "sine", from: 210, to: 84, seconds: 0.12, attack: 0.003, gain: 0.32, delay: 0.1 }, + ], + }, + // Gulps for a spit: Gurgle and gasp. + ghoulMotherSpitWind: { + layers: [ + { type: "sine", from: 96, to: 72, seconds: 0.6, attack: 0.05, gain: 0.9, vibrato: { rate: 15, depth: 0.4 } }, + { type: "brown", seconds: 0.6, attack: 0.05, gain: 0.7, filter: { type: "lowpass", from: 700, to: 300, q: 1 } }, + { type: "sine", from: 144, to: 115, seconds: 0.42, delay: 0.09, attack: 0.03, gain: 0.4, vibrato: { rate: 9, depth: 0.5 } }, + { type: "noise", seconds: 0.22, attack: 0.15, gain: 0.7, filter: { type: "bandpass", from: 770, to: 1680, q: 4 }, delay: 0.3 }, + { type: "sawtooth", from: 84, to: 109, seconds: 0.2, attack: 0.14, gain: 0.25, filter: { type: "lowpass", from: 980, to: 980, q: 1 }, delay: 0.3 }, + ], + }, + // Spits: Spit and splat. + ghoulMotherSpit: { + layers: [ + { type: "noise", seconds: 0.1, attack: 0, gain: 0.8, filter: { type: "highpass", from: 1260, to: 1260, q: 1 } }, + { type: "sine", from: 490, to: 105, seconds: 0.16, delay: 0.02, gain: 0.6 }, + { type: "brown", seconds: 0.12, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 294, to: 294, q: 1 } }, + { type: "noise", seconds: 0.28, attack: 0, gain: 0.54, filter: { type: "lowpass", from: 1820, to: 140, q: 1 }, delay: 0.15 }, + { type: "square", from: 98, to: 28, seconds: 0.16, attack: 0, gain: 0.3, filter: { type: "lowpass", from: 420, to: 420, q: 1 }, delay: 0.15 }, + { type: "sine", from: 630, to: 910, seconds: 0.05, delay: 0.35, gain: 0.15 }, + { type: "sine", from: 532, to: 770, seconds: 0.05, delay: 0.49, gain: 0.11 }, + ], + }, + // Cauldron opens: Lid clank, bubbles. + ghoulMotherOpen: { + layers: [ + { type: "sine", from: 260, to: 250, seconds: 0.35, attack: 0.003, gain: 0.6 }, + { type: "sine", from: 718, to: 702, seconds: 0.2, attack: 0.003, gain: 0.3 }, + { type: "noise", seconds: 0.04, attack: 0.003, gain: 0.5, filter: { type: "bandpass", from: 1300, to: 1300, q: 2 } }, + { type: "sine", from: 330, to: 560, seconds: 0.05, delay: 0.24, attack: 0, gain: 0.35 }, + { type: "sine", from: 462, to: 785, seconds: 0.05, delay: 0.41, attack: 0, gain: 0.35 }, + { type: "sine", from: 384, to: 653, seconds: 0.05, delay: 0.38, attack: 0, gain: 0.35 }, + { type: "sine", from: 702, to: 1193, seconds: 0.05, delay: 0.43, attack: 0, gain: 0.35 }, + { type: "sine", from: 860, to: 1462, seconds: 0.05, delay: 0.23, attack: 0, gain: 0.35 }, + ], + }, + // Sinks: Long gurgle, rumble. + ghoulMotherSink: { + layers: [ + { type: "sine", from: 84, to: 63, seconds: 0.9, attack: 0.05, gain: 0.9, vibrato: { rate: 15, depth: 0.4 } }, + { type: "brown", seconds: 0.9, attack: 0.05, gain: 0.7, filter: { type: "lowpass", from: 700, to: 300, q: 1 } }, + { type: "sine", from: 126, to: 101, seconds: 0.63, delay: 0.14, attack: 0.03, gain: 0.4, vibrato: { rate: 9, depth: 0.5 } }, + { type: "brown", seconds: 1, attack: 0.08, gain: 0.5, filter: { type: "lowpass", from: 180, to: 70, q: 1 } }, + { type: "sine", from: 48, to: 30, seconds: 1, attack: 0.05, gain: 0.4 }, + ], + }, + // Bubbles warn: Few bubbles. + ghoulMotherBubble: { + layers: [ + { type: "sine", from: 435, to: 740, seconds: 0.05, delay: 0.46, attack: 0, gain: 0.35 }, + { type: "sine", from: 538, to: 915, seconds: 0.05, delay: 0.15, attack: 0, gain: 0.35 }, + { type: "sine", from: 783, to: 1331, seconds: 0.05, delay: 0.09, attack: 0, gain: 0.35 }, + { type: "sine", from: 440, to: 748, seconds: 0.05, delay: 0.04, attack: 0, gain: 0.35 }, + ], + }, + // Resurfaces: Rising roar. + ghoulMotherRise: { + layers: [ + { type: "sawtooth", from: 54, to: 69, seconds: 0.35, attack: 0.05, gain: 0.9, vibrato: { rate: 5, depth: 0.1 }, filter: { type: "lowpass", from: 300, to: 2200, q: 4 } }, + { type: "sawtooth", from: 69, to: 42, seconds: 0.7, delay: 0.3, attack: 0.02, gain: 0.9, vibrato: { rate: 5, depth: 0.12 }, filter: { type: "lowpass", from: 2200, to: 260, q: 4 } }, + { type: "sawtooth", from: 30, to: 22, seconds: 1, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 500, to: 500, q: 1 } }, + { type: "brown", seconds: 1, attack: 0.06, gain: 0.8, filter: { type: "lowpass", from: 900, to: 180, q: 1 } }, + { type: "sine", from: 30, to: 21, seconds: 1, attack: 0.05, gain: 0.7 }, + { type: "noise", seconds: 0.4, attack: 0.01, gain: 0.48, filter: { type: "bandpass", from: 490, to: 1820, q: 1.2 } }, + { type: "pink", seconds: 0.52, attack: 0.03, gain: 0.3, delay: 0.04, filter: { type: "highpass", from: 1260, to: 2100, q: 1 } }, + { type: "sine", from: 210, to: 84, seconds: 0.12, attack: 0.003, gain: 0.24 }, + ], + }, + // Muck lands: Splat. + ghoulMotherMuck: { + layers: [ + { type: "noise", seconds: 0.28, attack: 0, gain: 0.9, filter: { type: "lowpass", from: 2080, to: 160, q: 1 } }, + { type: "square", from: 112, to: 32, seconds: 0.16, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 480, to: 480, q: 1 } }, + { type: "sine", from: 720, to: 1040, seconds: 0.05, delay: 0.2, gain: 0.25 }, + { type: "sine", from: 608, to: 880, seconds: 0.05, delay: 0.34, gain: 0.18 }, + ], + }, + // Hit: Short roar. + ghoulMotherHurt: { + layers: [ + { type: "sawtooth", from: 59, to: 76, seconds: 0.16, attack: 0.05, gain: 0.9, vibrato: { rate: 5, depth: 0.1 }, filter: { type: "lowpass", from: 300, to: 2200, q: 4 } }, + { type: "sawtooth", from: 76, to: 46, seconds: 0.32, delay: 0.14, attack: 0.02, gain: 0.9, vibrato: { rate: 5, depth: 0.12 }, filter: { type: "lowpass", from: 2200, to: 260, q: 4 } }, + { type: "sawtooth", from: 33, to: 24, seconds: 0.45, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 500, to: 500, q: 1 } }, + { type: "brown", seconds: 0.45, attack: 0.06, gain: 0.8, filter: { type: "lowpass", from: 900, to: 180, q: 1 } }, + { type: "sine", from: 33, to: 23, seconds: 0.45, attack: 0.05, gain: 0.7 }, + ], + }, + // Weak spot: Crack and roar. + ghoulMotherWeak: { + layers: [ + { type: "noise", seconds: 0.05, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 1260, to: 840, q: 2 } }, + { type: "square", from: 630, to: 210, seconds: 0.05, attack: 0, gain: 0.36 }, + { type: "noise", seconds: 0.04, delay: 0.06, attack: 0, gain: 0.63, filter: { type: "bandpass", from: 1820, to: 1260, q: 3 } }, + { type: "sawtooth", from: 54, to: 69, seconds: 0.21, attack: 0.05, gain: 0.63, vibrato: { rate: 5, depth: 0.1 }, filter: { type: "lowpass", from: 300, to: 2200, q: 4 }, delay: 0.05 }, + { type: "sawtooth", from: 69, to: 42, seconds: 0.42, delay: 0.23, attack: 0.02, gain: 0.63, vibrato: { rate: 5, depth: 0.12 }, filter: { type: "lowpass", from: 2200, to: 260, q: 4 } }, + { type: "sawtooth", from: 30, to: 22, seconds: 0.6, attack: 0.08, gain: 0.42, filter: { type: "lowpass", from: 500, to: 500, q: 1 }, delay: 0.05 }, + { type: "brown", seconds: 0.6, attack: 0.06, gain: 0.56, filter: { type: "lowpass", from: 900, to: 180, q: 1 }, delay: 0.05 }, + { type: "sine", from: 30, to: 21, seconds: 0.6, attack: 0.05, gain: 0.49, delay: 0.05 }, + ], + }, + // Dies: Falling roar, rumble. + ghoulMotherDie: { + layers: [ + { type: "sawtooth", from: 49, to: 62, seconds: 0.42, attack: 0.05, gain: 0.9, vibrato: { rate: 5, depth: 0.1 }, filter: { type: "lowpass", from: 300, to: 2200, q: 4 } }, + { type: "sawtooth", from: 62, to: 38, seconds: 0.84, delay: 0.36, attack: 0.02, gain: 0.9, vibrato: { rate: 5, depth: 0.12 }, filter: { type: "lowpass", from: 2200, to: 260, q: 4 } }, + { type: "sawtooth", from: 27, to: 20, seconds: 1.2, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 500, to: 500, q: 1 } }, + { type: "brown", seconds: 1.2, attack: 0.06, gain: 0.8, filter: { type: "lowpass", from: 900, to: 180, q: 1 } }, + { type: "sine", from: 27, to: 20, seconds: 1.2, attack: 0.05, gain: 0.7 }, + { type: "brown", seconds: 1.2, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 180, to: 70, q: 1 } }, + { type: "sine", from: 48, to: 30, seconds: 1.2, attack: 0.05, gain: 0.48 }, + ], + }, + }, + music: { + }, +}; diff --git a/src/web-console/public/activities/ghoul-sfx-bogboat.js b/src/web-console/public/activities/ghoul-sfx-bogboat.js new file mode 100644 index 0000000..6f66651 --- /dev/null +++ b/src/web-console/public/activities/ghoul-sfx-bogboat.js @@ -0,0 +1,203 @@ +// Plan2Code Web Console - ghoul: The Bog Runner's own sound effects and music track, merged into ghoul-sfx.js; defines only. +// +// Same shape and rules as ghoul-sfx-hearse.js: `tones` (a `ghoulBogboat` sound for the +// fan boat's things, built from the house tone layers, none over 1.2 s with its delay) and +// `music` (the room's track, `ghoulBoatRide`, named in ROOM_MUSIC in ghoul.js: a drone and a +// fan's chug under a reedy line, built from four-bar parts the way the hearse's is). Both are +// first drafts, to be picked by ear later (Phase 5's pick pages). A name may be defined only +// once across tones.js and every game's file. No imports (the little helpers below are local). + +const bars = (...b) => b.join(" | "); +// The fan's chug under the line: a root on the off steps, the propeller nobody is turning. +const chug = (n) => `${n} . ${n} . ${n} ${n} . ${n} ${n} . ${n} . ${n} ${n} . .`; +const FLOOR = "k . . . k . . . k . . . k . . ."; +const OFFBEAT = ". . h . . . h . . . h . . . h ."; +const SNAP = ". . . . s . . . . . . . s . . ."; +// One slow drone note on the first step of a bar. +const drone = (n) => `${n} - - - - - - - - - - - - - - -`; + +export const BOGBOAT_SFX = { + tones: { + // The Bog Runner: the bonus ride down the black channel, jumping, ducking, switching lanes and shooting. + // Jumps: the fan screams up and the hull lifts clear of the water. + ghoulBogboatJump: { + layers: [ + { type: "sawtooth", from: 120, to: 300, seconds: 0.26, attack: 0.04, gain: 0.28, filter: { type: "lowpass", from: 600, to: 2200, q: 2 } }, + { type: "noise", seconds: 0.22, attack: 0.08, gain: 0.3, filter: { type: "bandpass", from: 600, to: 2600, q: 1.5 } }, + ], + }, + // Lands: a flat smack on the water and a spray. + ghoulBogboatLand: { + layers: [ + { type: "sine", from: 130, to: 52, seconds: 0.16, attack: 0, gain: 0.7 }, + { type: "noise", seconds: 0.2, attack: 0.02, gain: 0.4, filter: { type: "bandpass", from: 1400, to: 500, q: 1.5 } }, + { type: "brown", seconds: 0.12, attack: 0, gain: 0.4, filter: { type: "lowpass", from: 300, to: 180, q: 1 } }, + ], + }, + // Ducks: a quick swish under the limb. + ghoulBogboatDuck: { + layers: [ + { type: "noise", seconds: 0.18, attack: 0.06, gain: 0.45, filter: { type: "bandpass", from: 700, to: 2800, q: 1.5 } }, + ], + }, + // Switches lane: a shudder up the mud ramp and a wet slap. + ghoulBogboatSwitch: { + layers: [ + { type: "sine", from: 150, to: 70, seconds: 0.12, attack: 0, gain: 0.6 }, + { type: "brown", seconds: 0.3, attack: 0.04, gain: 0.5, filter: { type: "lowpass", from: 500, to: 160, q: 1 } }, + { type: "noise", seconds: 0.16, attack: 0.03, gain: 0.25, delay: 0.14, filter: { type: "bandpass", from: 500, to: 1500, q: 2 } }, + ], + }, + // Crash: wood, a splash and the prop catching. + ghoulBogboatCrash: { + layers: [ + { type: "sine", from: 98, to: 32, seconds: 0.3, attack: 0, gain: 1 }, + { type: "brown", seconds: 0.25, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 260, to: 200, q: 1 } }, + { type: "noise", seconds: 0.4, attack: 0.1, gain: 0.45, delay: 0.03, filter: { type: "bandpass", from: 800, to: 3000, q: 2 } }, + { type: "square", from: 320, to: 150, seconds: 0.1, gain: 0.2, delay: 0.08 }, + ], + }, + // Checkpoint: a single bell over the water. + ghoulBogboatCheck: { + layers: [ + { type: "sine", from: 587, to: 584, seconds: 0.6, attack: 0.003, gain: 0.34 }, + { type: "sine", from: 1175, to: 1168, seconds: 0.4, attack: 0.003, gain: 0.14 }, + { type: "sine", from: 880, to: 876, seconds: 0.5, attack: 0.003, gain: 0.22, delay: 0.1 }, + ], + }, + // The finish: the fan winding down, then the pier's bell. + ghoulBogboatFinish: { + layers: [ + { type: "sawtooth", from: 420, to: 90, seconds: 0.7, attack: 0.03, gain: 0.2, vibrato: { rate: 14, depth: 0.05 }, filter: { type: "lowpass", from: 1400, to: 300, q: 2 } }, + { type: "noise", seconds: 0.5, attack: 0.1, gain: 0.28, filter: { type: "bandpass", from: 1400, to: 500, q: 2 } }, + { type: "sine", from: 220, to: 216, seconds: 0.6, attack: 0.003, gain: 0.5, delay: 0.5 }, + ], + }, + // The swarm boils close behind: a rising wet churn. + ghoulBogboatPanic: { + layers: [ + { type: "noise", seconds: 0.6, attack: 0.25, gain: 0.4, filter: { type: "bandpass", from: 300, to: 1800, q: 3 } }, + { type: "sine", from: 70, to: 120, seconds: 0.6, attack: 0.2, gain: 0.35, vibrato: { rate: 9, depth: 0.08 } }, + ], + }, + // The swarm has you: a snap of tiny teeth under a squelch. + ghoulBogboatCatch: { + layers: [ + { type: "noise", seconds: 0.35, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 2800, to: 900, q: 3 } }, + { type: "sine", from: 140, to: 50, seconds: 0.3, attack: 0, gain: 0.7 }, + { type: "square", from: 900, to: 400, seconds: 0.04, gain: 0.14, delay: 0.05 }, + { type: "square", from: 800, to: 380, seconds: 0.04, gain: 0.14, delay: 0.11 }, + ], + }, + // The fan is clogging: a labouring grind. + ghoulBogboatClog: { + layers: [ + { type: "sawtooth", from: 150, to: 90, seconds: 0.45, attack: 0.05, gain: 0.26, vibrato: { rate: 24, depth: 0.1 }, filter: { type: "lowpass", from: 700, to: 300, q: 2 } }, + { type: "brown", seconds: 0.4, attack: 0.1, gain: 0.4, filter: { type: "lowpass", from: 400, to: 160, q: 1 } }, + ], + }, + // The fan stalls: a cough, a clunk and silence. + ghoulBogboatStall: { + layers: [ + { type: "sawtooth", from: 240, to: 40, seconds: 0.5, attack: 0.01, gain: 0.3, filter: { type: "lowpass", from: 900, to: 150, q: 2 } }, + { type: "square", from: 90, to: 60, seconds: 0.08, gain: 0.3, delay: 0.5 }, + { type: "brown", seconds: 0.3, attack: 0, gain: 0.5, delay: 0.5, filter: { type: "lowpass", from: 260, to: 120, q: 1 } }, + ], + }, + // A gas pocket shot: a fat bubbling pop and a hiss. + ghoulBogboatGas: { + layers: [ + { type: "sine", from: 180, to: 520, seconds: 0.12, attack: 0, gain: 0.5 }, + { type: "noise", seconds: 0.5, attack: 0.02, gain: 0.4, filter: { type: "bandpass", from: 3200, to: 1200, q: 2 } }, + { type: "sine", from: 240, to: 600, seconds: 0.1, attack: 0, gain: 0.3, delay: 0.14 }, + ], + }, + // A charm shot: a rattle of bone or a clink of glass. + ghoulBogboatProp: { + layers: [ + { type: "noise", seconds: 0.14, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 3600, to: 1800, q: 3 } }, + { type: "sine", from: 1320, to: 880, seconds: 0.2, attack: 0.002, gain: 0.26 }, + { type: "sine", from: 420, to: 160, seconds: 0.14, attack: 0, gain: 0.4 }, + ], + }, + }, + music: { + // The Bog Runner: a fan boat at a chug through the dark. E minor: a drone under the + // chug, a reedy pulse line that wanders around the root and flat second, four on the + // floor and a snap on two and four; at high dread a shrill octave joins. The swarm is + // in the water behind it. + ghoulBoatRide: { + bpm: 150, + rush: 8, + voices: { + reed: { wave: "pulse", duty: 0.2, gain: 0.13, decay: 0.2, sustain: 0.65, vibrato: { rate: 5, depth: 0.014, delay: 0.2 } }, + drone: { wave: "sine", gain: 0.3, decay: 0.9, sustain: 0.6 }, + bass: { wave: "triangle", gain: 0.45, decay: 0.08, sustain: 0.5 }, + kick: { kit: true, gain: 0.28, from: 0.2 }, + hat: { kit: true, gain: 0.1, from: 0.4 }, + snap: { kit: true, gain: 0.16, from: 0.55 }, + shrill: { wave: "pulse", duty: 0.125, gain: 0.05, decay: 0.1, sustain: 0.4, from: 0.85 }, + }, + patterns: { + A: { + reed: bars( + "E5 - - - G5 - - - B5 - - - G5 - E5 -", + "F5 - - - A5 - - - C6 - - - A5 - F5 -", + "E5 - - - G5 - - - B5 - D6 - B5 - G5 -", + "F5 - E5 - D5 - E5 - . . E5 - - - - -", + ), + drone: bars(drone("E3"), drone("F3"), drone("E3"), drone("B2")), + bass: bars(chug("E2"), chug("F2"), chug("E2"), chug("B1")), + kick: bars(FLOOR, FLOOR, FLOOR, FLOOR), + hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT), + snap: bars(SNAP, SNAP, SNAP, SNAP), + shrill: bars( + "E6 . E6 . G6 . G6 . B6 . B6 . G6 . E6 .", + "F6 . F6 . A6 . A6 . C7 . C7 . A6 . F6 .", + "E6 . E6 . G6 . G6 . B6 . D7 . B6 . G6 .", + "F6 . E6 . D6 . E6 . . . E6 . . . . .", + ), + }, + B: { + reed: bars( + "B5 - B5 - A5 - G5 - F5 - E5 - F5 - G5 -", + "C6 - C6 - B5 - A5 - G5 - F5 - G5 - A5 -", + "B5 - B5 - A5 - G5 - F5 - E5 - F5 - G5 -", + "B4 - D5 - F5 - B5 - . . B5 - A5 - F5 -", + ), + drone: bars(drone("E3"), drone("F3"), drone("E3"), drone("B2")), + bass: bars(chug("E2"), chug("F2"), chug("E2"), chug("B1")), + kick: bars(FLOOR, FLOOR, FLOOR, FLOOR), + hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT), + snap: bars(SNAP, SNAP, SNAP, SNAP), + shrill: bars( + "B6 . B6 . A6 . G6 . F6 . E6 . F6 . G6 .", + "C7 . C7 . B6 . A6 . G6 . F6 . G6 . A6 .", + "B6 . B6 . A6 . G6 . F6 . E6 . F6 . G6 .", + "B5 . D6 . F6 . B6 . . . B6 . A6 . F6 .", + ), + }, + C: { + reed: bars( + "G5 - - - - - E5 - G5 - - - B5 - - -", + "A5 - - - - - F5 - A5 - - - C6 - - -", + "G5 - - - - - E5 - G5 - - - B5 - - -", + "F5 - - - D5 - - - B4 - - - E4 - - -", + ), + drone: bars(drone("E3"), drone("F3"), drone("E3"), drone("B2")), + bass: bars(chug("E2"), chug("F2"), chug("E2"), chug("B1")), + kick: bars(FLOOR, FLOOR, FLOOR, FLOOR), + hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT), + snap: bars(SNAP, SNAP, SNAP, SNAP), + shrill: bars( + "G6 . . . . . E6 . G6 . . . B6 . . .", + "A6 . . . . . F6 . A6 . . . C7 . . .", + "G6 . . . . . E6 . G6 . . . B6 . . .", + "F6 . . . D6 . . . B5 . . . E5 . . .", + ), + }, + }, + order: ["A", "A", "B", "A", "C", "B", "A", "C", "B", "A"], + }, + }, +}; diff --git a/src/web-console/public/activities/ghoul-sfx-gurney.js b/src/web-console/public/activities/ghoul-sfx-gurney.js new file mode 100644 index 0000000..cf34c04 --- /dev/null +++ b/src/web-console/public/activities/ghoul-sfx-gurney.js @@ -0,0 +1,223 @@ +// Plan2Code Web Console - ghoul: Code Blue's own sound effects and music track, merged into ghoul-sfx.js; defines only. +// +// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulBlue` sound for the +// gurney's things) and `music` (a track for the room, named in ROOM_MUSIC in ghoul.js). +// Every tone is built from the house's layers and is at most 1.2 s long. These are first +// picks and still pending a listen: the sounds and the track are to be chosen by ear. A +// name may be defined only once across tones.js and every game's file. No imports. + +export const GURNEY_SFX = { + tones: { + // Code Blue: The bonus ride: YOU lie strapped to a runaway hospital gurney, jumping, ducking and shooting as the lights go out in waves. + // Jumps: Wheels squeal as the gurney lifts. + ghoulBlueJump: { + layers: [ + { type: "noise", seconds: 0.2, attack: 0.05, gain: 0.3, filter: { type: "bandpass", from: 1200, to: 2800, q: 6 } }, + { type: "square", from: 300, to: 560, seconds: 0.1, gain: 0.1 }, + ], + }, + // Lands: Clatter of casters and a thud. + ghoulBlueLand: { + layers: [ + { type: "sine", from: 130, to: 55, seconds: 0.14, attack: 0, gain: 0.6 }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1900, to: 1500, q: 6 } }, + { type: "noise", seconds: 0.04, delay: 0.06, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 2300, to: 1700, q: 6 } }, + { type: "noise", seconds: 0.3, attack: 0.09, gain: 0.2, delay: 0.08, filter: { type: "bandpass", from: 3000, to: 1500, q: 5 } }, + ], + }, + // Launches off the loading ramp: Big whoosh and a whoop. + ghoulBlueLaunch: { + layers: [ + { type: "noise", seconds: 0.8, attack: 0.3, gain: 0.5, filter: { type: "bandpass", from: 400, to: 2500, q: 2 } }, + { type: "sine", from: 300, to: 900, seconds: 0.5, attack: 0.1, gain: 0.35, vibrato: { rate: 6, depth: 0.05 } }, + ], + }, + // Ducks: Quick swish. + ghoulBlueDuck: { + layers: [ + { type: "noise", seconds: 0.2, attack: 0.07, gain: 0.5, filter: { type: "bandpass", from: 420, to: 2520, q: 1.5 } }, + ], + }, + // Crash: Metal clang and a groan. + ghoulBlueCrash: { + layers: [ + { type: "sine", from: 140, to: 50, seconds: 0.25, attack: 0, gain: 1 }, + { type: "square", from: 220, to: 90, seconds: 0.2, attack: 0, gain: 0.3 }, + { type: "noise", seconds: 0.35, attack: 0.02, gain: 0.35, delay: 0.02, filter: { type: "bandpass", from: 1500, to: 3500, q: 2 } }, + { type: "brown", seconds: 0.25, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 300, to: 200, q: 1 } }, + ], + }, + // Checkpoint: Two monitor pings. + ghoulBlueCheck: { + layers: [ + { type: "sine", from: 1318, to: 1318, seconds: 0.12, attack: 0.004, gain: 0.35 }, + { type: "sine", from: 1760, to: 1760, seconds: 0.18, attack: 0.004, gain: 0.35, delay: 0.1 }, + ], + }, + // Finish: Fanfare notes. + ghoulBlueFinish: { + layers: [ + { type: "triangle", seconds: 0.9, attack: 0.01, gain: 0.7, notes: [392, 523, 659, 784] }, + { type: "sine", seconds: 0.9, attack: 0.01, gain: 0.25, notes: [784, 1047, 1319, 1568] }, + ], + }, + // Countdown tick (3, 2, 1): An electric buzz and a beep. + ghoulBlueWarn: { + layers: [ + { type: "sawtooth", from: 118, to: 112, seconds: 0.2, attack: 0.01, gain: 0.3, vibrato: { rate: 50, depth: 0.04 } }, + { type: "noise", seconds: 0.14, attack: 0.01, gain: 0.3, filter: { type: "highpass", from: 3000, to: 3000 } }, + { type: "sine", from: 880, to: 880, seconds: 0.1, attack: 0.004, gain: 0.3, delay: 0.1 }, + ], + }, + // Lights out: A power-down groan and a thunk. + ghoulBlueDark: { + layers: [ + { type: "sine", from: 900, to: 60, seconds: 0.9, attack: 0.01, gain: 0.4 }, + { type: "noise", seconds: 0.6, attack: 0.02, gain: 0.4, filter: { type: "lowpass", from: 800, to: 100, q: 1 } }, + { type: "brown", seconds: 0.2, attack: 0, gain: 0.8, delay: 0.05, filter: { type: "lowpass", from: 200, to: 120, q: 1 } }, + ], + }, + // Lights back on: A power-up rise and a pop. + ghoulBlueLit: { + layers: [ + { type: "sine", from: 120, to: 700, seconds: 0.5, attack: 0.02, gain: 0.35 }, + { type: "noise", seconds: 0.06, attack: 0, gain: 0.4, delay: 0.45, filter: { type: "highpass", from: 2500, to: 2500 } }, + { type: "triangle", seconds: 0.25, attack: 0.01, gain: 0.3, delay: 0.5, notes: [659, 988] }, + ], + }, + // Heartbeat monitor: A clean beep. + ghoulBlueBeat: { + layers: [ + { type: "sine", from: 1000, to: 1000, seconds: 0.1, attack: 0.003, gain: 0.4 }, + ], + }, + // Flatline: One long tone. + ghoulBlueFlat: { + layers: [ + { type: "sine", from: 1000, to: 1000, seconds: 1.1, attack: 0.003, gain: 0.35 }, + { type: "sine", from: 2000, to: 2000, seconds: 1.1, attack: 0.003, gain: 0.05 }, + ], + }, + // Wheelchair: A squeaky wheel starts to roll. + ghoulBlueChair: { + layers: [ + { type: "noise", seconds: 0.25, attack: 0.04, gain: 0.3, filter: { type: "bandpass", from: 800, to: 1700, q: 8 } }, + { type: "square", from: 600, to: 760, seconds: 0.05, gain: 0.08, delay: 0.05 }, + { type: "square", from: 640, to: 800, seconds: 0.05, gain: 0.08, delay: 0.13 }, + ], + }, + // Orderly: The door shivers in its frame. + ghoulBlueOrderlyWarn: { + layers: [ + { type: "noise", seconds: 0.3, attack: 0.02, gain: 0.35, filter: { type: "bandpass", from: 200, to: 420, q: 3 } }, + { type: "square", from: 90, to: 80, seconds: 0.05, gain: 0.25 }, + { type: "square", from: 90, to: 80, seconds: 0.05, gain: 0.25, delay: 0.1 }, + { type: "square", from: 90, to: 80, seconds: 0.05, gain: 0.25, delay: 0.2 }, + ], + }, + // Orderly: The door flies open and he roars. + ghoulBlueOrderlyUp: { + layers: [ + { type: "brown", seconds: 0.2, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 400, to: 200, q: 1 } }, + { type: "sawtooth", from: 110, to: 80, seconds: 0.45, attack: 0.03, gain: 0.3, delay: 0.05, vibrato: { rate: 18, depth: 0.05 } }, + ], + }, + // Orderly: A bolt thumps into him. + ghoulBlueOrderlyHit: { + layers: [ + { type: "sine", from: 110, to: 60, seconds: 0.12, attack: 0, gain: 0.7 }, + { type: "noise", seconds: 0.12, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 600, to: 300, q: 2 } }, + ], + }, + // Orderly: Down he goes. + ghoulBlueOrderlyBreak: { + layers: [ + { type: "sawtooth", from: 200, to: 50, seconds: 0.5, attack: 0.01, gain: 0.35 }, + { type: "noise", seconds: 0.35, attack: 0.01, gain: 0.4, filter: { type: "lowpass", from: 1500, to: 200, q: 1 } }, + { type: "sine", from: 90, to: 40, seconds: 0.3, attack: 0, gain: 0.7, delay: 0.1 }, + ], + }, + // Surge lamp: Glass shatters and a zap. + ghoulBlueLampBreak: { + layers: [ + { type: "noise", seconds: 0.3, attack: 0, gain: 0.5, filter: { type: "highpass", from: 2200, to: 2200 } }, + { type: "sine", from: 3000, to: 200, seconds: 0.22, attack: 0, gain: 0.25 }, + { type: "square", from: 140, to: 60, seconds: 0.18, attack: 0, gain: 0.2, delay: 0.04 }, + ], + }, + }, + music: { + // Code Blue: monitor rush. A pulsing minor-key chase: an urgent staccato lead over a driving + // bass, a kick on every beat, hats and a snap, and a monitor beep once a bar that keeps + // the heartbeat; at high dread a stab and an octave-up lead join. + ghoulBlueRide: { + bpm: 144, + rush: 10, + voices: { + lead: { wave: "pulse", duty: 0.25, gain: 0.1, decay: 0.07, sustain: 0.3 }, + bass: { wave: "triangle", gain: 0.4, decay: 0.08, sustain: 0.6 }, + kick: { kit: true, gain: 0.26, from: 0.15 }, + hat: { kit: true, gain: 0.1, from: 0.35 }, + snap: { kit: true, gain: 0.16, from: 0.5 }, + beep: { wave: "sine", gain: 0.1, decay: 0.12, sustain: 0.2 }, + stab: { wave: "sawtooth", gain: 0.05, decay: 0.1, sustain: 0.3, from: 0.75 }, + lead2: { wave: "pulse", duty: 0.125, gain: 0.06, decay: 0.08, sustain: 0.3, from: 0.9 }, + }, + patterns: { + A: { + lead: + "D5 . . F5 . . A5 . . F5 . . E5 . D5 . | Bb4 . . D5 . . F5 . . D5 . . C5 . Bb4 . | " + + "G4 . . Bb4 . . D5 . . Bb4 . . A4 . G4 . | A4 . . C#5 . . E5 . . A5 . G5 . F5 . E5", + bass: + "D2 . D2 . D2 . D2 . D2 . D2 . D2 . D2 . | Bb1 . Bb1 . Bb1 . Bb1 . Bb1 . Bb1 . Bb1 . Bb1 . | " + + "G1 . G1 . G1 . G1 . G1 . G1 . G1 . G1 . | A1 . A1 . A1 . A1 . A1 . A1 . A1 . A1 .", + kick: + "k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . . | " + + "k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . .", + hat: + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " + + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .", + snap: + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .", + beep: + "E6 . . . . . . . . . . . . . . . | E6 . . . . . . . . . . . . . . . | " + + "E6 . . . . . . . . . . . . . . . | E6 . . . . . . . . . . . . . . .", + stab: + "D4^037 . . . . . . . . . . . . . . . | Bb3^047 . . . . . . . . . . . . . . . | " + + "G3^037 . . . . . . . . . . . . . . . | A3^047 . . . . . . . . . . . . . . .", + lead2: + "D6 . . F6 . . A6 . . F6 . . E6 . D6 . | Bb5 . . D6 . . F6 . . D6 . . C6 . Bb5 . | " + + "G5 . . Bb5 . . D6 . . Bb5 . . A5 . G5 . | A5 . . C#6 . . E6 . . A6 . G6 . F6 . E6", + }, + B: { + lead: + "A5 . F5 . D5 . F5 . A5 . . D6 . C6 . A5 | F5 . D5 . Bb4 . D5 . F5 . . Bb5 . A5 . F5 | " + + "D5 . Bb4 . G4 . Bb4 . D5 . . G5 . F5 . D5 | E5 . C#5 . A4 . C#5 . E5 . . A5 . G5 . E5", + bass: + "D2 . . D2 . . D2 . D2 . . D2 . . D2 . | Bb1 . . Bb1 . . Bb1 . Bb1 . . Bb1 . . Bb1 . | " + + "G1 . . G1 . . G1 . G1 . . G1 . . G1 . | A1 . . A1 . . A1 . A1 . . A1 . . A1 .", + kick: + "k . . . k . . . k . . . k . . k | k . . . k . . . k . . . k . . k | " + + "k . . . k . . . k . . . k . . k | k . . . k . . . k . . . k . k k", + hat: + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " + + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .", + snap: + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . s", + beep: + "E6 . . . . . . . E6 . . . . . . . | E6 . . . . . . . E6 . . . . . . . | " + + "E6 . . . . . . . E6 . . . . . . . | E6 . . . . . . . E6 . . . . . . .", + stab: + "D4^037 . . . . . . . D4^037 . . . . . . . | Bb3^047 . . . . . . . Bb3^047 . . . . . . . | " + + "G3^037 . . . . . . . G3^037 . . . . . . . | A3^047 . . . . . . . A3^047 . . . . . . .", + lead2: + "A6 . F6 . D6 . F6 . A6 . . D7 . C7 . A6 | F6 . D6 . Bb5 . D6 . F6 . . Bb6 . A6 . F6 | " + + "D6 . Bb5 . G5 . Bb5 . D6 . . G6 . F6 . D6 | E6 . C#6 . A5 . C#6 . E6 . . A6 . G6 . E6", + }, + }, + order: ["A", "A", "B", "A", "B", "B", "A", "B", "A", "A", "B", "B", "A"], + }, + }, +}; diff --git a/src/web-console/public/activities/ghoul-sfx-hearse.js b/src/web-console/public/activities/ghoul-sfx-hearse.js new file mode 100644 index 0000000..01430a6 --- /dev/null +++ b/src/web-console/public/activities/ghoul-sfx-hearse.js @@ -0,0 +1,247 @@ +// Plan2Code Web Console - ghoul: The Midnight Hearse's own sound effects and music track, merged into ghoul-sfx.js; defines only. +// +// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulHearse` sound for the +// hearse's things, built from the house tone layers, none over 1.2 s with its delay) and +// `music` (the room's track, `ghoulHearseRide`, named in ROOM_MUSIC in ghoul.js: a +// funeral march at a gallop, built from four-bar parts the way the sled's is). Both are +// first drafts, to be picked by ear later. A name may be defined only once across +// tones.js and every game's file. No imports (the little helpers below are local). + +const bars = (...b) => b.join(" | "); +// The gallop under the march: a root on the beat's off steps, the horses' hoofbeat that no horse is making. +const gallop = (n) => `${n} . ${n} ${n} . ${n} ${n} . ${n} . ${n} ${n} . ${n} ${n} .`; +const FLOOR = "k . . . k . . . k . . . k . . ."; +const OFFBEAT = ". . h . . . h . . . h . . . h ."; +const SNAP = ". . . . s . . . . . . . s . . ."; +// One toll of a bell on the first step of a bar. +const toll = (n) => `${n} . . . . . . . . . . . . . . .`; + +export const HEARSE_SFX = { + tones: { + // The midnight hearse: the bonus ride along the cemetery road, jumping, ducking, switching lanes and shooting. + // Jumps: the engine roars and the coffins lift. + ghoulHearseJump: { + layers: [ + { type: "sawtooth", from: 90, to: 240, seconds: 0.26, attack: 0.04, gain: 0.3, filter: { type: "lowpass", from: 500, to: 1800, q: 2 } }, + { type: "noise", seconds: 0.2, attack: 0.07, gain: 0.3, filter: { type: "bandpass", from: 400, to: 1800, q: 1.5 } }, + ], + }, + // Lands: a thud and the coffins rattling. + ghoulHearseLand: { + layers: [ + { type: "sine", from: 110, to: 46, seconds: 0.16, attack: 0, gain: 0.8 }, + { type: "brown", seconds: 0.12, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 300, to: 200, q: 1 } }, + { type: "square", from: 420, to: 380, seconds: 0.02, gain: 0.14, delay: 0.06 }, + { type: "square", from: 520, to: 470, seconds: 0.02, gain: 0.14, delay: 0.1 }, + { type: "square", from: 360, to: 330, seconds: 0.02, gain: 0.14, delay: 0.15 }, + ], + }, + // Ducks: a quick swish under the branch. + ghoulHearseDuck: { + layers: [ + { type: "noise", seconds: 0.18, attack: 0.06, gain: 0.5, filter: { type: "bandpass", from: 500, to: 2400, q: 1.5 } }, + ], + }, + // Switches lane: two bumps over the curb. + ghoulHearseSwitch: { + layers: [ + { type: "sine", from: 170, to: 80, seconds: 0.1, attack: 0, gain: 0.7 }, + { type: "noise", seconds: 0.14, attack: 0.03, gain: 0.3, filter: { type: "bandpass", from: 800, to: 2000, q: 2 } }, + { type: "sine", from: 150, to: 70, seconds: 0.12, attack: 0, gain: 0.6, delay: 0.17 }, + ], + }, + // Crash: wood, iron and a coffin lid. + ghoulHearseCrash: { + layers: [ + { type: "sine", from: 92, to: 30, seconds: 0.3, attack: 0, gain: 1 }, + { type: "brown", seconds: 0.25, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 260, to: 220, q: 1 } }, + { type: "noise", seconds: 0.4, attack: 0.12, gain: 0.4, delay: 0.03, filter: { type: "bandpass", from: 900, to: 3200, q: 2 } }, + { type: "square", from: 300, to: 160, seconds: 0.1, gain: 0.2, delay: 0.08 }, + { type: "square", from: 240, to: 120, seconds: 0.1, gain: 0.2, delay: 0.18 }, + ], + }, + // Checkpoint: a single bell. + ghoulHearseCheck: { + layers: [ + { type: "sine", from: 523, to: 520, seconds: 0.6, attack: 0.003, gain: 0.34 }, + { type: "sine", from: 1047, to: 1040, seconds: 0.4, attack: 0.003, gain: 0.14 }, + { type: "sine", from: 784, to: 780, seconds: 0.5, attack: 0.003, gain: 0.22, delay: 0.1 }, + ], + }, + // The finish: brakes squealing, then a toll. + ghoulHearseFinish: { + layers: [ + { type: "sawtooth", from: 1100, to: 380, seconds: 0.6, attack: 0.03, gain: 0.16, vibrato: { rate: 18, depth: 0.04 }, filter: { type: "bandpass", from: 1800, to: 900, q: 3 } }, + { type: "noise", seconds: 0.55, attack: 0.1, gain: 0.3, filter: { type: "bandpass", from: 1500, to: 600, q: 2 } }, + { type: "sine", from: 196, to: 192, seconds: 0.6, attack: 0.003, gain: 0.5, delay: 0.5 }, + ], + }, + // A hand stirs in the grave mound: earth shifting. + ghoulHearseHandWarn: { + layers: [ + { type: "brown", seconds: 0.4, attack: 0.15, gain: 0.5, filter: { type: "lowpass", from: 200, to: 420, q: 1 } }, + { type: "sine", from: 70, to: 90, seconds: 0.4, attack: 0.1, gain: 0.3 }, + ], + }, + // The hand reaches up: clawing dirt. + ghoulHearseHandUp: { + layers: [ + { type: "noise", seconds: 0.3, attack: 0.1, gain: 0.45, filter: { type: "bandpass", from: 500, to: 2600, q: 2 } }, + { type: "square", from: 110, to: 200, seconds: 0.2, gain: 0.16 }, + ], + }, + // A hit on the hand: a dull smack. + ghoulHearseHandHit: { + layers: [ + { type: "sine", from: 300, to: 190, seconds: 0.09, attack: 0, gain: 0.5 }, + { type: "noise", seconds: 0.08, attack: 0, gain: 0.35, filter: { type: "bandpass", from: 1200, to: 900, q: 3 } }, + ], + }, + // The hand breaks: bone and dirt. + ghoulHearseHandBreak: { + layers: [ + { type: "noise", seconds: 0.3, attack: 0, gain: 0.55, filter: { type: "bandpass", from: 2400, to: 700, q: 2 } }, + { type: "sine", from: 210, to: 70, seconds: 0.25, attack: 0, gain: 0.6 }, + { type: "square", from: 700, to: 300, seconds: 0.05, gain: 0.14, delay: 0.04 }, + ], + }, + // A crow takes wing: two caws and the flap. + ghoulHearseCrowWake: { + layers: [ + { type: "sawtooth", from: 900, to: 520, seconds: 0.16, attack: 0.01, gain: 0.26, filter: { type: "bandpass", from: 1100, to: 800, q: 3 } }, + { type: "sawtooth", from: 800, to: 460, seconds: 0.18, attack: 0.01, gain: 0.26, delay: 0.2, filter: { type: "bandpass", from: 1000, to: 700, q: 3 } }, + { type: "noise", seconds: 0.35, attack: 0.1, gain: 0.2, delay: 0.1, filter: { type: "bandpass", from: 3000, to: 1500, q: 4 } }, + ], + }, + // A crow shot: a puff of feathers. + ghoulHearseCrowHit: { + layers: [ + { type: "noise", seconds: 0.2, attack: 0.02, gain: 0.4, filter: { type: "bandpass", from: 3400, to: 1800, q: 2 } }, + { type: "sine", from: 520, to: 240, seconds: 0.12, attack: 0, gain: 0.4 }, + ], + }, + // A lantern taken: glass chimes. + ghoulHearseLantern: { + layers: [ + { type: "sine", from: 1568, to: 1560, seconds: 0.3, attack: 0.002, gain: 0.3 }, + { type: "sine", from: 2093, to: 2085, seconds: 0.3, attack: 0.002, gain: 0.22, delay: 0.06 }, + { type: "sine", from: 2637, to: 2625, seconds: 0.24, attack: 0.002, gain: 0.14, delay: 0.12 }, + ], + }, + // The lamp goes out: a sigh down into the dark. + ghoulHearseLampOut: { + layers: [ + { type: "sine", from: 440, to: 96, seconds: 0.7, attack: 0.01, gain: 0.45 }, + { type: "brown", seconds: 0.5, attack: 0.1, gain: 0.5, filter: { type: "lowpass", from: 500, to: 120, q: 1 } }, + ], + }, + // The lamp lit again: a whump of flame. + ghoulHearseLampLit: { + layers: [ + { type: "sine", from: 220, to: 660, seconds: 0.3, attack: 0.02, gain: 0.4 }, + { type: "noise", seconds: 0.25, attack: 0.08, gain: 0.3, filter: { type: "bandpass", from: 1800, to: 4200, q: 2 } }, + ], + }, + // A coffin flies out of the back: a whoosh, then the knocks. + ghoulHearseCoffin: { + layers: [ + { type: "noise", seconds: 0.5, attack: 0.2, gain: 0.35, filter: { type: "bandpass", from: 300, to: 1500, q: 1.5 } }, + { type: "square", from: 180, to: 110, seconds: 0.08, gain: 0.2, delay: 0.4 }, + { type: "square", from: 150, to: 95, seconds: 0.08, gain: 0.2, delay: 0.52 }, + ], + }, + // The lid pops and a ghoul sits up: a crack and a moan. + ghoulHearseSitUp: { + layers: [ + { type: "square", from: 160, to: 320, seconds: 0.08, gain: 0.26 }, + { type: "sine", from: 130, to: 210, seconds: 0.55, attack: 0.12, gain: 0.3, vibrato: { rate: 5, depth: 0.05 }, delay: 0.06 }, + ], + }, + // The sat-up ghoul shot: a bony pop. + ghoulHearseSitHit: { + layers: [ + { type: "noise", seconds: 0.12, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 2200, to: 900, q: 3 } }, + { type: "sine", from: 420, to: 150, seconds: 0.16, attack: 0, gain: 0.5 }, + ], + }, + }, + music: { + // The Midnight Hearse: a funeral march at a gallop. D minor: the organ says the dirge + // (D, Bb, C, then an A major that never resolves) over a hoofbeat bass nobody is + // making, a bell tolling each bar, four on the floor and a snap on two and four; at + // high dread a riser and a shrill octave join. The march that cannot slow down. + ghoulHearseRide: { + bpm: 142, + rush: 8, + voices: { + organ: { wave: "pulse", duty: 0.25, gain: 0.13, decay: 0.2, sustain: 0.7, vibrato: { rate: 5, depth: 0.012, delay: 0.2 } }, + toll: { wave: "sine", gain: 0.32, decay: 0.9, sustain: 0.15 }, + bass: { wave: "triangle", gain: 0.45, decay: 0.08, sustain: 0.5 }, + kick: { kit: true, gain: 0.28, from: 0.2 }, + hat: { kit: true, gain: 0.1, from: 0.4 }, + snap: { kit: true, gain: 0.16, from: 0.55 }, + shrill: { wave: "pulse", duty: 0.125, gain: 0.05, decay: 0.1, sustain: 0.4, from: 0.85 }, + }, + patterns: { + A: { + organ: bars( + "D5 - - - F5 - - - A5 - - - F5 - D5 -", + "Bb4 - - - D5 - - - F5 - - - D5 - Bb4 -", + "C5 - - - E5 - - - G5 - - - E5 - C5 -", + "A4 - - - C#5 - - - E5 - A5 - G5 - E5 -", + ), + toll: bars(toll("D4"), toll("Bb3"), toll("C4"), toll("A3")), + bass: bars(gallop("D3"), gallop("Bb2"), gallop("C3"), gallop("A2")), + kick: bars(FLOOR, FLOOR, FLOOR, FLOOR), + hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT), + snap: bars(SNAP, SNAP, SNAP, SNAP), + shrill: bars( + "D6 . D6 . F6 . F6 . A6 . A6 . F6 . D6 .", + "Bb5 . Bb5 . D6 . D6 . F6 . F6 . D6 . Bb5 .", + "C6 . C6 . E6 . E6 . G6 . G6 . E6 . C6 .", + "A5 . A5 . C#6 . C#6 . E6 . A6 . G6 . E6 .", + ), + }, + B: { + organ: bars( + "A5 - A5 - G5 - F5 - E5 - D5 - E5 - F5 -", + "F5 - F5 - E5 - D5 - C5 - Bb4 - C5 - D5 -", + "E5 - E5 - D5 - C5 - Bb4 - A4 - Bb4 - C5 -", + "A4 - C#5 - E5 - A5 - . . A5 - G5 - E5 -", + ), + toll: bars(toll("D4"), toll("Bb3"), toll("C4"), toll("A3")), + bass: bars(gallop("D3"), gallop("Bb2"), gallop("C3"), gallop("A2")), + kick: bars(FLOOR, FLOOR, FLOOR, FLOOR), + hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT), + snap: bars(SNAP, SNAP, SNAP, SNAP), + shrill: bars( + "A6 . A6 . G6 . F6 . E6 . D6 . E6 . F6 .", + "F6 . F6 . E6 . D6 . C6 . Bb5 . C6 . D6 .", + "E6 . E6 . D6 . C6 . Bb5 . A5 . Bb5 . C6 .", + "A5 . C#6 . E6 . A6 . . . A6 . G6 . E6 .", + ), + }, + C: { + organ: bars( + "F5 - - - - - D5 - F5 - - - A5 - - -", + "D5 - - - - - Bb4 - D5 - - - F5 - - -", + "E5 - - - - - C5 - E5 - - - G5 - - -", + "E5 - - - C#5 - - - A4 - - - E4 - - -", + ), + toll: bars(toll("D4"), toll("Bb3"), toll("C4"), toll("A3")), + bass: bars(gallop("D3"), gallop("Bb2"), gallop("C3"), gallop("A2")), + kick: bars(FLOOR, FLOOR, FLOOR, FLOOR), + hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT), + snap: bars(SNAP, SNAP, SNAP, SNAP), + shrill: bars( + "F6 . . . . . D6 . F6 . . . A6 . . .", + "D6 . . . . . Bb5 . D6 . . . F6 . . .", + "E6 . . . . . C6 . E6 . . . G6 . . .", + "E6 . . . C#6 . . . A5 . . . E5 . . .", + ), + }, + }, + order: ["A", "A", "B", "A", "C", "B", "A", "C", "B", "A"], + }, + }, +}; diff --git a/src/web-console/public/activities/ghoul-sfx-mower.js b/src/web-console/public/activities/ghoul-sfx-mower.js new file mode 100644 index 0000000..f8ccdde --- /dev/null +++ b/src/web-console/public/activities/ghoul-sfx-mower.js @@ -0,0 +1,221 @@ +// Plan2Code Web Console - ghoul: The Gardener's Revenge's own sound effects and music track, merged into ghoul-sfx.js; defines only. +// +// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulMower` sound for the +// mower's things, each under 1.2 s, built only from the house's tone layers) and `music` (a +// track for the room, `ghoulMowerRide`, named in ROOM_MUSIC in ghoul.js). The sounds and the +// track are first drafts, to be picked by ear. A name may be defined only once across tones.js +// and every game's file. No imports. + +export const MOWER_SFX = { + tones: { + // The Gardener's Revenge: the bonus ride: you mow a long lawn on a haunted ride-on mower, jumping, ducking, shooting and cutting. + // Jump: the engine revs as the deck bounces up. + ghoulMowerJump: { + layers: [ + { type: "sawtooth", from: 70, to: 150, seconds: 0.3, attack: 0.02, gain: 0.5, vibrato: { rate: 22, depth: 0.1 }, filter: { type: "lowpass", from: 900, to: 1500, q: 2 } }, + { type: "noise", seconds: 0.2, attack: 0.06, gain: 0.3, filter: { type: "bandpass", from: 500, to: 1800, q: 1.5 } }, + { type: "triangle", from: 180, to: 320, seconds: 0.18, attack: 0.01, gain: 0.3 }, + ], + }, + // Land: a clunk of the deck and a rattle of the chassis. + ghoulMowerLand: { + layers: [ + { type: "sine", from: 110, to: 50, seconds: 0.14, attack: 0, gain: 0.8 }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1600, to: 900, q: 5 } }, + { type: "square", from: 330, to: 270, seconds: 0.03, delay: 0.04, gain: 0.14 }, + { type: "noise", seconds: 0.05, delay: 0.08, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 1300, to: 800, q: 6 } }, + ], + }, + // Duck: a quick swish under a branch. + ghoulMowerDuck: { + layers: [ + { type: "noise", seconds: 0.18, attack: 0.06, gain: 0.5, filter: { type: "bandpass", from: 350, to: 1900, q: 1.5 } }, + ], + }, + // Crash: a clang of metal, a thud and a rattle of loose parts. + ghoulMowerCrash: { + layers: [ + { type: "sine", from: 90, to: 34, seconds: 0.25, attack: 0, gain: 1 }, + { type: "square", from: 520, to: 300, seconds: 0.12, attack: 0, gain: 0.22, filter: { type: "bandpass", from: 800, to: 500, q: 3 } }, + { type: "noise", seconds: 0.3, attack: 0.01, gain: 0.45, delay: 0.02, filter: { type: "bandpass", from: 2200, to: 700, q: 2 } }, + { type: "noise", seconds: 0.04, delay: 0.16, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1500, to: 1000, q: 6 } }, + { type: "noise", seconds: 0.04, delay: 0.23, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 1900, to: 1200, q: 6 } }, + ], + }, + // Checkpoint: a rusty bicycle bell, twice. + ghoulMowerCheck: { + layers: [ + { type: "sine", from: 1976, to: 1960, seconds: 0.25, attack: 0.003, gain: 0.3 }, + { type: "sine", from: 4150, to: 4100, seconds: 0.12, attack: 0.003, gain: 0.12 }, + { type: "sine", from: 1976, to: 1960, seconds: 0.3, attack: 0.003, gain: 0.3, delay: 0.14 }, + { type: "sine", from: 4150, to: 4100, seconds: 0.14, attack: 0.003, gain: 0.12, delay: 0.14 }, + ], + }, + // Finish: the engine coughs, rattles and dies, then a triumphant ding. + ghoulMowerFinish: { + layers: [ + { type: "sawtooth", from: 120, to: 40, seconds: 0.7, attack: 0.01, gain: 0.5, vibrato: { rate: 14, depth: 0.2 }, filter: { type: "lowpass", from: 700, to: 200, q: 2 } }, + { type: "noise", seconds: 0.5, attack: 0.05, gain: 0.25, filter: { type: "bandpass", from: 900, to: 300, q: 1.5 } }, + { type: "triangle", seconds: 0.5, attack: 0.01, delay: 0.6, gain: 0.5, notes: [659, 880, 1175] }, + ], + }, + // Grass: the blades biting a swathe, a quick chatter. + ghoulMowerGrass: { + layers: [ + { type: "noise", seconds: 0.1, attack: 0.02, gain: 0.4, filter: { type: "bandpass", from: 3200, to: 1800, q: 2.5 } }, + { type: "sawtooth", from: 200, to: 170, seconds: 0.08, attack: 0.005, gain: 0.2, vibrato: { rate: 40, depth: 0.15 }, filter: { type: "lowpass", from: 1200, to: 900, q: 1 } }, + ], + }, + // Hedge: the blades chop a thorn hedge, a crunch with a thunk. + ghoulMowerHedge: { + layers: [ + { type: "noise", seconds: 0.18, attack: 0.005, gain: 0.7, filter: { type: "bandpass", from: 2400, to: 800, q: 1.5 } }, + { type: "square", from: 260, to: 110, seconds: 0.1, attack: 0, gain: 0.3, filter: { type: "lowpass", from: 1200, to: 500, q: 1 } }, + { type: "brown", seconds: 0.2, attack: 0.01, gain: 0.6, filter: { type: "lowpass", from: 500, to: 300, q: 1 } }, + { type: "triangle", seconds: 0.2, delay: 0.1, attack: 0.005, gain: 0.35, notes: [784, 1047] }, + ], + }, + // Weed: a small pop of a weed patch. + ghoulMowerWeed: { + layers: [ + { type: "sine", from: 500, to: 950, seconds: 0.08, attack: 0.002, gain: 0.5 }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.3, filter: { type: "bandpass", from: 2600, to: 2000, q: 3 } }, + ], + }, + // Jam: the blades overheat: a clank, a grind winding down and a long hiss of steam. + ghoulMowerJam: { + layers: [ + { type: "square", from: 140, to: 60, seconds: 0.2, attack: 0, gain: 0.4, filter: { type: "lowpass", from: 900, to: 400, q: 3 } }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 1400, to: 900, q: 5 } }, + { type: "sawtooth", from: 190, to: 50, seconds: 0.6, attack: 0.02, delay: 0.05, gain: 0.35, vibrato: { rate: 18, depth: 0.3 }, filter: { type: "lowpass", from: 800, to: 150, q: 2 } }, + { type: "noise", seconds: 0.8, attack: 0.1, delay: 0.1, gain: 0.3, filter: { type: "highpass", from: 3500, to: 5000 } }, + ], + }, + // Topiary Beast: a bush that comes alive and lunges across the lane, snapping its hedge-trimmed jaws. + // Warn: leaves rustle and shake. + ghoulMowerBeastWarn: { + layers: [ + { type: "noise", seconds: 0.4, attack: 0.15, gain: 0.4, filter: { type: "bandpass", from: 1800, to: 3200, q: 1.5 }, vibrato: { rate: 24, depth: 0.2 } }, + { type: "pink", seconds: 0.4, attack: 0.2, gain: 0.25, filter: { type: "bandpass", from: 900, to: 1500, q: 1 } }, + ], + }, + // Snap: the lunge and two clacks of the shears. + ghoulMowerBeastSnap: { + layers: [ + { type: "noise", seconds: 0.2, attack: 0.06, gain: 0.45, filter: { type: "bandpass", from: 600, to: 2400, q: 1.5 } }, + { type: "square", from: 880, to: 300, seconds: 0.04, delay: 0.1, attack: 0, gain: 0.35 }, + { type: "noise", seconds: 0.04, delay: 0.1, attack: 0, gain: 0.55, filter: { type: "bandpass", from: 3000, to: 2000, q: 4 } }, + { type: "square", from: 780, to: 260, seconds: 0.04, delay: 0.22, attack: 0, gain: 0.35 }, + { type: "noise", seconds: 0.04, delay: 0.22, attack: 0, gain: 0.55, filter: { type: "bandpass", from: 2800, to: 1900, q: 4 } }, + ], + }, + // Hit: a bolt strikes it: a leafy thwack. + ghoulMowerBeastHit: { + layers: [ + { type: "noise", seconds: 0.06, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 1800, to: 1000, q: 2 } }, + { type: "square", from: 640, to: 220, seconds: 0.05, attack: 0, gain: 0.3 }, + { type: "pink", seconds: 0.15, delay: 0.03, attack: 0.02, gain: 0.3, filter: { type: "bandpass", from: 1400, to: 800, q: 1 } }, + ], + }, + // Break: it is trimmed to a stump: a crunch of cut branches. + ghoulMowerBeastBreak: { + layers: [ + { type: "noise", seconds: 0.3, attack: 0.01, gain: 0.7, filter: { type: "bandpass", from: 2600, to: 700, q: 1.5 } }, + { type: "brown", seconds: 0.25, attack: 0.01, gain: 0.6, filter: { type: "lowpass", from: 500, to: 250, q: 1 } }, + { type: "square", from: 500, to: 160, seconds: 0.08, attack: 0, gain: 0.3 }, + { type: "triangle", seconds: 0.3, delay: 0.1, attack: 0.005, gain: 0.35, notes: [988, 1319, 1760] }, + ], + }, + }, + music: { + // The Gardener's Revenge: a sputtering waltz-march. A reedy pulse lead walks an E minor + // figure over a chugging two-stroke bass (a bass note on every beat's offbeat, like an + // engine), a kick and a snare crack on the backbeat; a thin siren-like wheeze joins as the + // dread grows. The bridge drops the drums for a creeping line. + ghoulMowerRide: { + bpm: 138, + rush: 8, + voices: { + lead: { wave: "pulse", duty: 0.25, gain: 0.1, decay: 0.12, sustain: 0.45 }, + bass: { wave: "triangle", gain: 0.42, decay: 0.08, sustain: 0.5 }, + chug: { wave: "sawtooth", gain: 0.07, decay: 0.06, sustain: 0.2, from: 0.15 }, + kick: { kit: true, gain: 0.26, from: 0.2 }, + hat: { kit: true, gain: 0.1, from: 0.35 }, + snap: { kit: true, gain: 0.16, from: 0.5 }, + wheeze: { wave: "sawtooth", gain: 0.03, decay: 0.3, sustain: 1, from: 0.75, vibrato: { rate: 0.7, depth: 0.05, delay: 0 } }, + }, + patterns: { + A: { + lead: + "E4 . G4 . B4 . G4 . E4 . G4 . B4 . G4 . | E4 . G4 . A4 . F#4 . E4 . G4 . A4 . F#4 . | " + + "E4 . G4 . B4 . D5 . B4 . G4 . B4 . D5 . | C5 . B4 . A4 . G4 . F#4 . . . B4 . . .", + bass: + "E2 . . E2 . . E2 . E2 . . E2 . . E2 . | E2 . . E2 . . E2 . E2 . . E2 . . E2 . | " + + "C2 . . C2 . . C2 . C2 . . C2 . . C2 . | B1 . . B1 . . B1 . B1 . . B1 . . B1 .", + chug: + ". . E3 . . . E3 . . . E3 . . . E3 . | . . E3 . . . E3 . . . E3 . . . E3 . | " + + ". . C3 . . . C3 . . . C3 . . . C3 . | . . B2 . . . B2 . . . B2 . . . B2 .", + kick: + "k . . . . . k . k . . . . . k . | k . . . . . k . k . . . . . k . | " + + "k . . . . . k . k . . . . . k . | k . . . . . k . k . . . . . k .", + hat: + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " + + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .", + snap: + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .", + wheeze: + "B3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - - | " + + "G3 - - - - - - - - - - - - - - - | F#3 - - - - - - - - - - - - - - -", + }, + B: { + lead: + "B4 . D5 . E5 . D5 . B4 . D5 . E5 . G5 . | F#5 . E5 . D5 . B4 . A4 . B4 . D5 . . . | " + + "E5 . D5 . B4 . D5 . E5 . G5 . E5 . D5 . | C5 . D5 . B4 . A4 . B4 . . . . . . .", + bass: + "E2 . . E2 . . E2 . E2 . . E2 . . E2 . | A1 . . A1 . . A1 . A1 . . A1 . . A1 . | " + + "C2 . . C2 . . C2 . C2 . . C2 . . C2 . | B1 . . B1 . . B1 . B1 . . B1 . . B1 .", + chug: + ". . E3 . . . E3 . . . E3 . . . E3 . | . . A2 . . . A2 . . . A2 . . . A2 . | " + + ". . C3 . . . C3 . . . C3 . . . C3 . | . . B2 . . . B2 . . . B2 . . . B2 .", + kick: + "k . . . . . k . k . . . . . k . | k . . . . . k . k . . . . . k . | " + + "k . . . . . k . k . . . . . k . | k . . . . . k . k . . . k . k .", + hat: + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " + + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . h . h .", + snap: + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . s s", + wheeze: + "E4 - - - - - - - - - - - - - - - | C#4 - - - - - - - - - - - - - - - | " + + "C4 - - - - - - - - - - - - - - - | B3 - - - - - - - - - - - - - - -", + }, + C: { + lead: + "E4 . . . G4 . . . B4 . . . G4 . . . | A4 . . . F#4 . . . E4 . . . . . . . | " + + "E4 . . . G4 . . . B4 . . . D5 . . . | C5 . . . B4 . . . A4 . . . . . . .", + bass: + "E2 . . . . . . . E2 . . . . . . . | A1 . . . . . . . A1 . . . . . . . | " + + "C2 . . . . . . . C2 . . . . . . . | B1 . . . . . . . B1 . . . . . . .", + chug: + ". . . . . . E3 . . . . . . . E3 . | . . . . . . A2 . . . . . . . A2 . | " + + ". . . . . . C3 . . . . . . . C3 . | . . . . . . B2 . . . . . . . B2 .", + kick: + ". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " + + ". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .", + hat: + ". . . . h . . . . . . . h . . . | . . . . h . . . . . . . h . . . | " + + ". . . . h . . . . . . . h . . . | . . . . h . . . . . . . h . . .", + snap: + ". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " + + ". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .", + wheeze: + "B3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - - | " + + "G3 - - - - - - - - - - - - - - - | F#3 - - - - - - - - - - - - - - -", + }, + }, + order: ["A", "A", "B", "A", "C", "B", "A", "B", "C"], + }, + }, +}; diff --git a/src/web-console/public/activities/ghoul-sfx-pew.js b/src/web-console/public/activities/ghoul-sfx-pew.js new file mode 100644 index 0000000..d119f39 --- /dev/null +++ b/src/web-console/public/activities/ghoul-sfx-pew.js @@ -0,0 +1,220 @@ +// Plan2Code Web Console - ghoul: Holy Roller's own sound effects and music track, merged into ghoul-sfx.js; defines only. +// +// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoul` sound for the runner's +// moves and things, each under 1.2 s) and `music` (a track for the room, named in ROOM_MUSIC in ghoul.js). +// The sounds and the track are first drafts in the house's tone layers; they are still to be +// picked by ear. A name may be defined only once across tones.js and every game's file. No imports. + +export const PEW_SFX = { + tones: { + // Lane change: a quick whoosh as the pew slides across. + ghoulPewLane: { + layers: [ + { type: "noise", seconds: 0.16, attack: 0.04, gain: 0.4, filter: { type: "bandpass", from: 600, to: 2400, q: 1.4 } }, + { type: "triangle", from: 180, to: 260, seconds: 0.12, attack: 0.01, gain: 0.18 }, + ], + }, + // A lane press at the edge: a tiny bump on the chapel wall. + ghoulPewBump: { + layers: [ + { type: "sine", from: 120, to: 70, seconds: 0.1, attack: 0, gain: 0.6 }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.25, filter: { type: "lowpass", from: 900, to: 400, q: 1 } }, + ], + }, + // Jump: wood creak and a lift. + ghoulPewJump: { + layers: [ + { type: "noise", seconds: 0.18, attack: 0.05, gain: 0.3, filter: { type: "bandpass", from: 700, to: 1800, q: 4 } }, + { type: "triangle", from: 240, to: 420, seconds: 0.2, attack: 0.02, gain: 0.3 }, + ], + }, + // Landing: a wooden thump. + ghoulPewLand: { + layers: [ + { type: "sine", from: 130, to: 55, seconds: 0.14, attack: 0, gain: 0.8 }, + { type: "noise", seconds: 0.06, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 900, to: 500, q: 3 } }, + ], + }, + // Slide: a scrape of wood on stone. + ghoulPewSlide: { + layers: [ + { type: "noise", seconds: 0.4, attack: 0.03, gain: 0.42, filter: { type: "bandpass", from: 2200, to: 900, q: 2 } }, + { type: "sawtooth", from: 110, to: 80, seconds: 0.35, attack: 0.02, gain: 0.1, filter: { type: "lowpass", from: 700, to: 300, q: 1 } }, + ], + }, + // Down in the air, a fast fall: a falling whistle. + ghoulPewDive: { + layers: [ + { type: "sine", from: 900, to: 260, seconds: 0.2, attack: 0.01, gain: 0.2 }, + { type: "noise", seconds: 0.18, attack: 0.02, gain: 0.2, filter: { type: "highpass", from: 1200, to: 1200, q: 1 } }, + ], + }, + // A wax soul taken: a bright tick (the art raises its pitch with the combo). + ghoulPewSoul: { + layers: [ + { type: "sine", from: 880, to: 880, seconds: 0.1, attack: 0.003, gain: 0.3 }, + { type: "triangle", from: 1760, to: 1760, seconds: 0.08, attack: 0.003, gain: 0.12 }, + { type: "noise", seconds: 0.02, attack: 0, gain: 0.1, filter: { type: "highpass", from: 5000, to: 5000, q: 1 } }, + ], + }, + // A halo caught: a rising shimmer. + ghoulPewHalo: { + layers: [ + { type: "sine", from: 660, to: 1320, seconds: 0.5, attack: 0.01, gain: 0.28 }, + { type: "sine", from: 990, to: 1980, seconds: 0.5, attack: 0.01, gain: 0.16, delay: 0.04 }, + { type: "sine", from: 1320, to: 2640, seconds: 0.4, attack: 0.01, gain: 0.1, delay: 0.08 }, + ], + }, + // A hit: splintering wood and a sour organ chord. + ghoulPewCrash: { + layers: [ + { type: "sine", from: 96, to: 34, seconds: 0.25, attack: 0, gain: 0.95 }, + { type: "brown", seconds: 0.2, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 300, to: 260, q: 1 } }, + { type: "noise", seconds: 0.3, attack: 0.04, gain: 0.4, delay: 0.02, filter: { type: "bandpass", from: 1200, to: 3200, q: 2 } }, + { type: "sawtooth", from: 196, to: 190, seconds: 0.5, attack: 0.02, gain: 0.2, delay: 0.05, filter: { type: "lowpass", from: 900, to: 500, q: 1 } }, + { type: "sawtooth", from: 208, to: 200, seconds: 0.5, attack: 0.02, gain: 0.2, delay: 0.05, filter: { type: "lowpass", from: 900, to: 500, q: 1 } }, + { type: "sawtooth", from: 233, to: 225, seconds: 0.5, attack: 0.02, gain: 0.2, delay: 0.05, filter: { type: "lowpass", from: 900, to: 500, q: 1 } }, + ], + }, + // Checkpoint: two chapel bell strokes. + ghoulPewCheck: { + layers: [ + { type: "sine", from: 784, to: 776, seconds: 0.4, attack: 0.003, gain: 0.3 }, + { type: "sine", from: 2093, to: 2070, seconds: 0.2, attack: 0.003, gain: 0.12 }, + { type: "sine", from: 988, to: 980, seconds: 0.5, attack: 0.003, gain: 0.3, delay: 0.16 }, + { type: "sine", from: 2637, to: 2610, seconds: 0.25, attack: 0.003, gain: 0.12, delay: 0.16 }, + ], + }, + // Finish: an organ fanfare, a major chord. + ghoulPewFinish: { + layers: [ + { type: "square", seconds: 1, attack: 0.02, gain: 0.2, notes: [262, 330, 392, 523], filter: { type: "lowpass", from: 1600, to: 1600, q: 1 } }, + { type: "triangle", seconds: 1, attack: 0.02, gain: 0.4, notes: [131, 165, 196, 262] }, + { type: "sine", seconds: 1, attack: 0.02, gain: 0.2, notes: [523, 659, 784, 1047] }, + ], + }, + // The ride picks up speed: an organ swell, rising. + ghoulPewSpeed: { + layers: [ + { type: "sawtooth", from: 147, to: 294, seconds: 0.7, attack: 0.3, gain: 0.2, filter: { type: "lowpass", from: 600, to: 1600, q: 1 } }, + { type: "sawtooth", from: 220, to: 440, seconds: 0.7, attack: 0.3, gain: 0.14, filter: { type: "lowpass", from: 600, to: 1600, q: 1 } }, + { type: "noise", seconds: 0.6, attack: 0.3, gain: 0.18, filter: { type: "bandpass", from: 500, to: 3000, q: 1.5 } }, + ], + }, + // Gargoyle: a stone gargoyle in the arches. It shudders (grinding stone) ... + ghoulPewGargWarn: { + layers: [ + { type: "brown", seconds: 0.45, attack: 0.05, gain: 0.5, filter: { type: "bandpass", from: 300, to: 700, q: 3 } }, + { type: "sawtooth", from: 92, to: 70, seconds: 0.45, attack: 0.05, gain: 0.3, vibrato: { rate: 18, depth: 0.12 }, filter: { type: "lowpass", from: 500, to: 300, q: 2 } }, + ], + }, + // ... drops into the lane (a heavy stone thud) ... + ghoulPewGargDrop: { + layers: [ + { type: "sine", from: 74, to: 28, seconds: 0.3, attack: 0, gain: 1 }, + { type: "brown", seconds: 0.25, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 240, to: 200, q: 1 } }, + { type: "noise", seconds: 0.1, attack: 0, gain: 0.35, delay: 0.02, filter: { type: "bandpass", from: 1400, to: 800, q: 2 } }, + ], + }, + // ... a first bolt chips it (a stone crack) ... + ghoulPewGargChip: { + layers: [ + { type: "noise", seconds: 0.05, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 2200, to: 1400, q: 3 } }, + { type: "square", from: 520, to: 300, seconds: 0.04, attack: 0, gain: 0.2 }, + ], + }, + // ... and the second bolt breaks it: stone cracking apart. + ghoulPewGargHit: { + layers: [ + { type: "noise", seconds: 0.05, attack: 0, gain: 0.8, filter: { type: "bandpass", from: 1800, to: 1000, q: 2 } }, + { type: "square", from: 600, to: 200, seconds: 0.05, attack: 0, gain: 0.3 }, + { type: "noise", seconds: 0.04, delay: 0.07, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 2600, to: 1600, q: 3 } }, + { type: "brown", seconds: 0.3, attack: 0.02, gain: 0.5, delay: 0.04, filter: { type: "lowpass", from: 500, to: 200, q: 1 } }, + ], + }, + // Bell rope: shoot it and the bell rings, a deep stroke, and the gargoyles ahead are stunned. + ghoulPewBell: { + layers: [ + { type: "sine", from: 392, to: 386, seconds: 1.1, attack: 0.004, gain: 0.5 }, + { type: "sine", from: 784, to: 772, seconds: 0.9, attack: 0.004, gain: 0.22 }, + { type: "sine", from: 1180, to: 1160, seconds: 0.6, attack: 0.004, gain: 0.14 }, + { type: "sine", from: 1990, to: 1960, seconds: 0.35, attack: 0.004, gain: 0.08 }, + { type: "noise", seconds: 0.04, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 3000, to: 2000, q: 3 } }, + ], + }, + }, + music: { + // Holy Roller: the organist's chase. A driving D minor organ ride at 132 beats a minute (the pulse the + // art throbs in the pillars and windows): four on the floor, a pedal bass in eighths, organ chords on the + // off-beats, a reed line that climbs through the bars, and a bell stroke on the backbeat. Built to loop: + // two four-bar phrases that answer each other, round and round. + ghoulPewDirge: { + bpm: 132, + rush: 0, + voices: { + organ: { wave: "square", gain: 0.045, decay: 0.12, sustain: 0.6, vibrato: { rate: 5, depth: 0.01, delay: 0.2 } }, + reed: { wave: "sawtooth", gain: 0.04, decay: 0.12, sustain: 0.6, vibrato: { rate: 5.5, depth: 0.018, delay: 0.2 } }, + pedal: { wave: "triangle", gain: 0.42, decay: 0.2, sustain: 0.7 }, + kick: { kit: true, gain: 0.22, from: 0 }, + toll: { kit: true, gain: 0.12, from: 0.35 }, + }, + patterns: { + A: { + organ: + ". . D4^037 - . . D4^037 - . . D4^037 - . . D4^037 - | " + + ". . Bb3^047 - . . Bb3^047 - . . Bb3^047 - . . Bb3^047 - | " + + ". . G3^037 - . . G3^037 - . . G3^037 - . . G3^037 - | " + + ". . A3^047 - . . A3^047 - . . A3^047 - . . A3^047 -", + reed: + "D5 - F5 - A5 - F5 - D5 - F5 - A5 - F5 - | " + + "D5 - F5 - Bb5 - F5 - D5 - F5 - Bb5 - F5 - | " + + "D5 - G5 - Bb5 - G5 - D5 - G5 - Bb5 - G5 - | " + + "E5 - A5 - C#6 - A5 - E5 - A5 - C#6 - A5 -", + pedal: + "D2 - D2 - D2 - D2 - D2 - D2 - D2 - D2 - | " + + "Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - | " + + "G1 - G1 - G1 - G1 - G1 - G1 - G1 - G1 - | " + + "A1 - A1 - A1 - A1 - A1 - A1 - A1 - A1 -", + kick: + "k . . . k . . . k . . . k . . . | " + + "k . . . k . . . k . . . k . . . | " + + "k . . . k . . . k . . . k . . . | " + + "k . . . k . . . k . . . k . . .", + toll: + ". . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . s .", + }, + B: { + organ: + ". . F4^037 - . . F4^037 - . . F4^037 - . . F4^037 - | " + + ". . G3^037 - . . G3^037 - . . G3^037 - . . G3^037 - | " + + ". . Bb3^047 - . . Bb3^047 - . . Bb3^047 - . . Bb3^047 - | " + + ". . A3^047 - . . A3^047 - . . A3^047 - . . A3^047 -", + reed: + "A5 - F5 - A5 - D6 - A5 - F5 - A5 - D6 - | " + + "G5 - D5 - G5 - Bb5 - G5 - D5 - G5 - Bb5 - | " + + "F5 - D5 - F5 - Bb5 - F5 - D5 - F5 - Bb5 - | " + + "E5 - A5 - C#6 - E6 - D6 - A5 - F5 - A4 -", + pedal: + "F1 - F1 - F1 - F1 - F1 - F1 - F1 - F1 - | " + + "G1 - G1 - G1 - G1 - G1 - G1 - G1 - G1 - | " + + "Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - | " + + "A1 - A1 - A1 - A1 - A1 - A1 - A1 - A1 -", + kick: + "k . . . k . . . k . . . k . . . | " + + "k . . . k . . . k . . . k . . . | " + + "k . . . k . . . k . . . k . . . | " + + "k . . . k . . . k . . . k . k .", + toll: + ". . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . .", + }, + }, + order: ["A", "B", "A", "B", "A", "B"], + }, + }, +}; diff --git a/src/web-console/public/activities/ghoul-sfx-story.js b/src/web-console/public/activities/ghoul-sfx-story.js new file mode 100644 index 0000000..9db062e --- /dev/null +++ b/src/web-console/public/activities/ghoul-sfx-story.js @@ -0,0 +1,116 @@ +// Plan2Code Web Console - ghoul: the game's intro story's own sounds, merged into ghoul-sfx.js; defines only. +// +// Same shape and rules as ghoul-sfx-tray.js: `tones` (one-shots named in the pages' `cues` in +// ghoul-story.js: wind, a distant bell, a heartbeat, a door creak, knocks, a whisper, a flashlight +// click, a page turn, the last page's "begin") and `hums` (the low drone that runs under the whole +// story, asked for every tick by ghoul.js while the story is up). Made from the house tone +// layers only; no tone is longer than 1.2 s. A name may be defined only once across tones.js and +// every game's file. No imports. + +export const STORY_SFX = { + tones: { + // A long cold gust over open ground. + ghoulStoryWind: { + layers: [ + { type: "noise", seconds: 1.15, attack: 0.5, gain: 0.34, filter: { type: "bandpass", from: 420, to: 1100, q: 1.6 } }, + { type: "brown", seconds: 1.1, attack: 0.4, gain: 0.5, filter: { type: "lowpass", from: 260, to: 520 } }, + { type: "sine", from: 310, to: 380, seconds: 1.0, attack: 0.5, delay: 0.1, gain: 0.05, vibrato: { rate: 5, depth: 0.04 } }, + ], + }, + // A far-off bell: a dull strike and a long, falling ring. + ghoulStoryBell: { + layers: [ + { type: "sine", from: 233, to: 231, seconds: 1.15, attack: 0.004, gain: 0.34 }, + { type: "sine", from: 466, to: 462, seconds: 1.0, attack: 0.004, gain: 0.16 }, + { type: "sine", from: 700, to: 694, seconds: 0.8, attack: 0.004, gain: 0.08 }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.2, filter: { type: "lowpass", from: 1400, to: 700 } }, + ], + }, + // Two heavy beats of a heart under the floor. + ghoulStoryBeat: { + layers: [ + { type: "sine", from: 62, to: 38, seconds: 0.22, attack: 0.008, gain: 0.7 }, + { type: "brown", seconds: 0.16, attack: 0.004, gain: 0.5, filter: { type: "lowpass", from: 200, to: 90 } }, + { type: "sine", from: 56, to: 34, seconds: 0.26, attack: 0.008, delay: 0.3, gain: 0.55 }, + { type: "brown", seconds: 0.18, attack: 0.004, delay: 0.3, gain: 0.4, filter: { type: "lowpass", from: 180, to: 80 } }, + ], + }, + // A door opening on dry hinges. + ghoulStoryCreak: { + layers: [ + { type: "sawtooth", from: 150, to: 310, seconds: 1.0, attack: 0.1, gain: 0.12, vibrato: { rate: 13, depth: 0.08 }, filter: { type: "bandpass", from: 700, to: 1500, q: 7 } }, + { type: "sawtooth", from: 180, to: 250, seconds: 0.8, attack: 0.2, delay: 0.2, gain: 0.08, vibrato: { rate: 9, depth: 0.06 }, filter: { type: "bandpass", from: 1100, to: 800, q: 6 } }, + { type: "noise", seconds: 0.9, attack: 0.3, gain: 0.05, filter: { type: "bandpass", from: 2400, to: 1800, q: 3 } }, + ], + }, + // Three slow knocks from the wrong side of a wall. + ghoulStoryKnock: { + layers: [0, 0.3, 0.6].flatMap((delay, i) => [ + { type: "sine", from: 140 - i * 6, to: 90, seconds: 0.09, attack: 0.002, delay, gain: 0.6 }, + { type: "noise", seconds: 0.04, attack: 0, delay, gain: 0.3, filter: { type: "bandpass", from: 900, to: 500, q: 3 } }, + ]), + }, + // A whisper in the next room: breath shaped into almost-words. + ghoulStoryWhisper: { + layers: [ + { type: "pink", seconds: 1.1, attack: 0.3, gain: 0.3, filter: { type: "bandpass", from: 1700, to: 2600, q: 5 } }, + { type: "pink", seconds: 0.9, attack: 0.25, delay: 0.15, gain: 0.2, filter: { type: "bandpass", from: 3000, to: 2100, q: 6 } }, + { type: "sine", from: 190, to: 170, seconds: 1.0, attack: 0.4, gain: 0.04, vibrato: { rate: 7, depth: 0.05 } }, + ], + }, + // A flashlight clicking on: a switch, a hum of current, a bright bloom. + ghoulStoryClick: { + layers: [ + { type: "square", from: 1600, to: 900, seconds: 0.018, attack: 0, gain: 0.3 }, + { type: "noise", seconds: 0.03, attack: 0, delay: 0.02, gain: 0.3, filter: { type: "highpass", from: 3000, to: 4000 } }, + { type: "triangle", from: 400, to: 1250, seconds: 0.45, attack: 0.05, delay: 0.06, gain: 0.16 }, + { type: "sine", from: 1250, to: 1260, seconds: 0.5, attack: 0.02, delay: 0.3, gain: 0.08 }, + ], + }, + // A page turning: a soft paper whoosh. + ghoulStoryPage: { + layers: [ + { type: "noise", seconds: 0.22, attack: 0.05, gain: 0.2, filter: { type: "bandpass", from: 1600, to: 4200, q: 1.2 } }, + { type: "sine", from: 330, to: 262, seconds: 0.2, attack: 0.01, gain: 0.05 }, + ], + }, + // A crow, once, from somewhere in the dark. + ghoulStoryCrow: { + layers: [ + { type: "sawtooth", from: 520, to: 360, seconds: 0.2, attack: 0.01, gain: 0.16, filter: { type: "bandpass", from: 1200, to: 900, q: 3 } }, + { type: "sawtooth", from: 500, to: 330, seconds: 0.22, attack: 0.01, delay: 0.26, gain: 0.14, filter: { type: "bandpass", from: 1100, to: 800, q: 3 } }, + ], + }, + // A swallow: something very large clearing its throat. + ghoulStoryGulp: { + layers: [ + { type: "sine", from: 95, to: 48, seconds: 0.6, attack: 0.15, gain: 0.5, vibrato: { rate: 8, depth: 0.1 } }, + { type: "brown", seconds: 0.5, attack: 0.2, gain: 0.5, filter: { type: "lowpass", from: 500, to: 120 } }, + { type: "noise", seconds: 0.2, attack: 0.02, delay: 0.5, gain: 0.1, filter: { type: "bandpass", from: 800, to: 400, q: 2 } }, + ], + }, + // A lock turning and a bolt thrown home. + ghoulStoryLock: { + layers: [ + { type: "noise", seconds: 0.03, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 2600, to: 2000, q: 8 } }, + { type: "noise", seconds: 0.05, attack: 0, delay: 0.14, gain: 0.6, filter: { type: "bandpass", from: 1200, to: 700, q: 6 } }, + { type: "sine", from: 120, to: 70, seconds: 0.25, attack: 0.004, delay: 0.14, gain: 0.5 }, + ], + }, + // The last page: a slammed chord, a rising sweep and a flash of bright metal. The run begins. + ghoulStoryBegin: { + layers: [ + { type: "sawtooth", from: 110, to: 108, seconds: 1.0, attack: 0.005, gain: 0.4, filter: { type: "lowpass", from: 2600, to: 400 } }, + { type: "sawtooth", from: 165, to: 163, seconds: 1.0, attack: 0.005, gain: 0.34, filter: { type: "lowpass", from: 2600, to: 400 } }, + { type: "sawtooth", from: 220, to: 218, seconds: 0.9, attack: 0.005, gain: 0.3, filter: { type: "lowpass", from: 2600, to: 400 } }, + { type: "brown", seconds: 0.5, attack: 0.003, gain: 0.7, filter: { type: "lowpass", from: 500, to: 100 } }, + { type: "noise", seconds: 0.6, attack: 0.3, gain: 0.14, delay: 0.5, filter: { type: "highpass", from: 1500, to: 6000 } }, + { type: "triangle", from: 880, to: 1760, seconds: 0.45, attack: 0.02, delay: 0.6, gain: 0.14 }, + ], + }, + }, + hums: { + // Under every page: a low, slow breath, a house asleep with one eye open. + ghoulStoryDrone: { parts: [{ type: "sawtooth", freq: 55 }, { type: "sawtooth", freq: 55.7, gain: 0.8 }, { type: "sine", freq: 82.4, gain: 0.35 }], noise: { color: "brown", gain: 0.4 }, filter: { type: "lowpass", freq: 220, q: 3, follow: 0.6 }, pulse: { rate: 0.35, depth: 0.5 }, peak: 0.035 }, + }, +}; diff --git a/src/web-console/public/activities/ghoul-sfx-tray.js b/src/web-console/public/activities/ghoul-sfx-tray.js new file mode 100644 index 0000000..3bc180e --- /dev/null +++ b/src/web-console/public/activities/ghoul-sfx-tray.js @@ -0,0 +1,225 @@ +// Plan2Code Web Console - ghoul: The Servants' Back Stairs' own sound effects and music track, merged into ghoul-sfx.js; defines only. +// +// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulTray` sound for the tray's +// things, named in ghoul-tray-draw.js's VOICES) and `music` (the room's track, named in +// ROOM_MUSIC in ghoul.js). Made from the house tone layers only; no tone is longer than 1.2 s. +// Sound and music picks are still pending (these are first drafts to be picked by ear). A name +// may be defined only once across tones.js and every game's file. No imports. + +export const TRAY_SFX = { + tones: { + // The Servants' Back Stairs: the bonus ride: you rush down the back stairs and through the kitchens on a silver tray. + // Jumps: A tin clank and a whoosh. + ghoulTrayJump: { + layers: [ + { type: "square", from: 560, to: 320, seconds: 0.06, attack: 0, gain: 0.16 }, + { type: "noise", seconds: 0.2, attack: 0.06, gain: 0.34, filter: { type: "bandpass", from: 2800, to: 1300, q: 5 } }, + { type: "noise", seconds: 0.28, attack: 0.1, gain: 0.3, delay: 0.04, filter: { type: "bandpass", from: 300, to: 1700, q: 1.5 } }, + ], + }, + // Lands: Cutlery clatter. + ghoulTrayLand: { + layers: [ + { type: "noise", seconds: 0.04, attack: 0, gain: 0.54, filter: { type: "bandpass", from: 2400, to: 1900, q: 7 } }, + { type: "triangle", from: 880, to: 700, seconds: 0.05, gain: 0.2 }, + { type: "noise", seconds: 0.04, delay: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 3100, to: 2500, q: 7 } }, + { type: "noise", seconds: 0.04, delay: 0.09, attack: 0, gain: 0.46, filter: { type: "bandpass", from: 1900, to: 1500, q: 7 } }, + { type: "noise", seconds: 0.3, attack: 0.09, gain: 0.26, delay: 0.1, filter: { type: "bandpass", from: 3500, to: 1800, q: 4 } }, + ], + }, + // Launches off the last shelf: A big whoosh and a rising ting. + ghoulTrayLaunch: { + layers: [ + { type: "noise", seconds: 0.8, attack: 0.3, gain: 0.5, filter: { type: "bandpass", from: 400, to: 2600, q: 2 } }, + { type: "sine", from: 400, to: 1200, seconds: 0.5, attack: 0.1, gain: 0.36, vibrato: { rate: 6, depth: 0.05 } }, + { type: "sine", from: 2093, to: 2093, seconds: 0.4, attack: 0.003, gain: 0.2, delay: 0.5 }, + ], + }, + // Ducks: A quick swish. + ghoulTrayDuck: { + layers: [ + { type: "noise", seconds: 0.18, attack: 0.06, gain: 0.5, filter: { type: "bandpass", from: 500, to: 2400, q: 1.5 } }, + ], + }, + // Crash: A pot dropped down the stairs. + ghoulTrayCrash: { + layers: [ + { type: "sine", from: 110, to: 38, seconds: 0.25, attack: 0, gain: 1 }, + { type: "square", from: 720, to: 380, seconds: 0.08, attack: 0, gain: 0.22 }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.7, delay: 0.02, filter: { type: "bandpass", from: 1800, to: 1400, q: 6 } }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.6, delay: 0.09, filter: { type: "bandpass", from: 2300, to: 1700, q: 6 } }, + { type: "noise", seconds: 0.4, attack: 0.12, gain: 0.3, delay: 0.05, filter: { type: "bandpass", from: 1400, to: 3200, q: 2 } }, + ], + }, + // Checkpoint: A service bell, ding ding. + ghoulTrayCheck: { + layers: [ + { type: "sine", from: 1760, to: 1750, seconds: 0.5, attack: 0.003, gain: 0.34 }, + { type: "sine", from: 3520, to: 3500, seconds: 0.35, attack: 0.003, gain: 0.16 }, + { type: "sine", from: 5280, to: 5250, seconds: 0.2, attack: 0.003, gain: 0.08 }, + { type: "sine", from: 1760, to: 1750, seconds: 0.5, attack: 0.003, gain: 0.34, delay: 0.14 }, + { type: "sine", from: 3520, to: 3500, seconds: 0.35, attack: 0.003, gain: 0.16, delay: 0.14 }, + ], + }, + // Finish: A fanfare, and plates ringing. + ghoulTrayFinish: { + layers: [ + { type: "triangle", seconds: 0.9, attack: 0.01, gain: 0.7, notes: [392, 494, 587, 784] }, + { type: "sine", seconds: 0.9, attack: 0.01, gain: 0.25, notes: [784, 988, 1175, 1568] }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.4, delay: 0.7, filter: { type: "highpass", from: 3500, to: 3500, q: 1 } }, + ], + }, + // A silver dome: Run through it and it chimes up the scale. + ghoulTrayDome: { + layers: [ + { type: "sine", from: 2637, to: 2620, seconds: 0.28, attack: 0.003, gain: 0.3 }, + { type: "sine", from: 3951, to: 3930, seconds: 0.22, attack: 0.003, gain: 0.2, delay: 0.06 }, + { type: "sine", from: 5274, to: 5250, seconds: 0.18, attack: 0.003, gain: 0.14, delay: 0.12 }, + { type: "noise", seconds: 0.03, attack: 0, gain: 0.3, filter: { type: "highpass", from: 5000, to: 5000, q: 1 } }, + ], + }, + // A flying plate: Caught with a china clink and a sweet chime. + ghoulTrayPlate: { + layers: [ + { type: "sine", from: 3322, to: 3300, seconds: 0.12, attack: 0.002, gain: 0.3 }, + { type: "sine", from: 4435, to: 4400, seconds: 0.08, attack: 0.002, gain: 0.2, delay: 0.03 }, + { type: "noise", seconds: 0.03, attack: 0, gain: 0.35, filter: { type: "highpass", from: 4000, to: 4000, q: 1 } }, + { type: "sine", from: 1568, to: 1560, seconds: 0.3, attack: 0.003, gain: 0.3, delay: 0.1 }, + { type: "sine", from: 2093, to: 2085, seconds: 0.4, attack: 0.003, gain: 0.3, delay: 0.17 }, + ], + }, + // Spectral cook: A cook who winds up to fling a dish at you (shoot him, or jump the dish). + // Appears: A hollow, hungry groan. + ghoulTrayCookUp: { + layers: [ + { type: "sawtooth", from: 170, to: 105, seconds: 0.5, attack: 0.06, gain: 0.3, vibrato: { rate: 6, depth: 0.08 }, filter: { type: "lowpass", from: 800, to: 400, q: 2 } }, + { type: "pink", seconds: 0.5, attack: 0.1, gain: 0.14, filter: { type: "bandpass", from: 520, to: 300, q: 1 } }, + ], + }, + // Flings the dish: A whoosh. + ghoulTrayToss: { + layers: [ + { type: "noise", seconds: 0.3, attack: 0.1, gain: 0.4, filter: { type: "bandpass", from: 700, to: 2200, q: 2 } }, + { type: "triangle", from: 300, to: 520, seconds: 0.15, attack: 0.01, gain: 0.2 }, + ], + }, + // Shot: A pop and a sigh. + ghoulTrayCookHit: { + layers: [ + { type: "sine", from: 620, to: 190, seconds: 0.1, attack: 0, gain: 0.6 }, + { type: "noise", seconds: 0.14, attack: 0, gain: 0.3, filter: { type: "bandpass", from: 1600, to: 600, q: 2 } }, + { type: "sine", from: 230, to: 110, seconds: 0.4, attack: 0.02, gain: 0.3, delay: 0.05, vibrato: { rate: 5, depth: 0.1 } }, + ], + }, + // A dish shot out of the air: China smashing. + ghoulTrayDishBreak: { + layers: [ + { type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "highpass", from: 3000, to: 3000, q: 1 } }, + { type: "noise", seconds: 0.04, attack: 0, gain: 0.45, delay: 0.04, filter: { type: "bandpass", from: 4200, to: 3000, q: 5 } }, + { type: "noise", seconds: 0.04, attack: 0, gain: 0.4, delay: 0.09, filter: { type: "bandpass", from: 3400, to: 2400, q: 5 } }, + { type: "square", from: 1400, to: 600, seconds: 0.05, attack: 0, gain: 0.16 }, + ], + }, + }, + music: { + // The Servants' Back Stairs: kitchen galop. A clattering, hurried polka for the tray's rush + // down the back stairs: a pulse lead skipping over a stair-step oompah bass, a tin tick of + // cutlery on the offbeats, a kick, a hat and the snap of a pan. At high dread a riser and + // a second lead an octave up join in. + ghoulTrayRide: { + bpm: 172, + rush: 10, + voices: { + lead: { wave: "pulse", duty: 0.25, gain: 0.12, decay: 0.08, sustain: 0.35 }, + tin: { wave: "pulse", duty: 0.125, gain: 0.05, decay: 0.03, sustain: 0.2, from: 0.15 }, + bass: { wave: "triangle", gain: 0.4, decay: 0.08, sustain: 0.5 }, + kick: { kit: true, gain: 0.26, from: 0.2 }, + hat: { kit: true, gain: 0.1, from: 0.4 }, + snap: { kit: true, gain: 0.16, from: 0.55 }, + riser: { wave: "sawtooth", gain: 0.035, decay: 0.3, sustain: 1, from: 0.8, vibrato: { rate: 0.6, depth: 0.04, delay: 0 } }, + lead2: { wave: "pulse", duty: 0.25, gain: 0.07, decay: 0.1, sustain: 0.3, from: 0.9 }, + }, + patterns: { + A: { + lead: + "D5 . F5 . A5 . F5 . D5 . F5 . A5 . D6 . | C5 . E5 . G5 . E5 . C5 . E5 . G5 . C6 . | " + + "Bb4 . D5 . F5 . D5 . Bb4 . D5 . F5 . Bb5 . | A4 . C#5 . E5 . A5 . E5 . C#5 . A4 . . .", + tin: + ". D6 . D6 . D6 . D6 . D6 . D6 . D6 . D6 | . C6 . C6 . C6 . C6 . C6 . C6 . C6 . C6 | " + + ". Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 | . A5 . A5 . A5 . A5 . A5 . A5 . A5 . A5", + bass: + "D3 . A3 . D3 . A3 . D3 . A3 . D3 . A3 . | C3 . G3 . C3 . G3 . C3 . G3 . C3 . G3 . | " + + "Bb2 . F3 . Bb2 . F3 . Bb2 . F3 . Bb2 . F3 . | A2 . E3 . A2 . E3 . A2 . E3 . A2 . E3 .", + kick: + "k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . . | " + + "k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . .", + hat: + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " + + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .", + snap: + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .", + riser: + "D4 - - - - - - - - - - - - - - - | C4 - - - - - - - - - - - - - - - | " + + "Bb3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -", + lead2: + "D5 D5 D5 D5 F5 F5 F5 F5 A5 A5 A5 A5 . . . . | C5 C5 C5 C5 E5 E5 E5 E5 G5 G5 G5 G5 . . . . | " + + "Bb4 Bb4 Bb4 Bb4 D5 D5 D5 D5 F5 F5 F5 F5 . . . . | A4 A4 A4 A4 C#5 C#5 C#5 C#5 E5 E5 E5 E5 . . . .", + }, + B: { + lead: + "A5 . F5 . D5 . F5 . A5 . F5 . D5 . A4 . | G5 . E5 . C5 . E5 . G5 . E5 . C5 . G4 . | " + + "F5 . D5 . Bb4 . D5 . F5 . D5 . Bb4 . F4 . | E5 . C#5 . A4 . C#5 . E5 . C#5 . A4 . . .", + tin: + ". D6 . D6 . D6 . D6 . D6 . D6 . D6 . D6 | . C6 . C6 . C6 . C6 . C6 . C6 . C6 . C6 | " + + ". Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 | . A5 . A5 . A5 . A5 . A5 . A5 . A5 . A5", + bass: + "D3 . A3 . D3 . A3 . D3 . A3 . D3 . A3 . | C3 . G3 . C3 . G3 . C3 . G3 . C3 . G3 . | " + + "Bb2 . F3 . Bb2 . F3 . Bb2 . F3 . Bb2 . F3 . | A2 . E3 . A2 . E3 . A2 . E3 . A2 . E3 .", + kick: + "k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . . | " + + "k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . .", + hat: + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " + + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .", + snap: + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .", + riser: + "D4 - - - - - - - - - - - - - - - | C4 - - - - - - - - - - - - - - - | " + + "Bb3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -", + lead2: + "A5 A5 A5 A5 F5 F5 F5 F5 D5 D5 D5 D5 . . . . | G5 G5 G5 G5 E5 E5 E5 E5 C5 C5 C5 C5 . . . . | " + + "F5 F5 F5 F5 D5 D5 D5 D5 Bb4 Bb4 Bb4 Bb4 . . . . | E5 E5 E5 E5 C#5 C#5 C#5 C#5 A4 A4 A4 A4 . . . .", + }, + C: { + lead: + "G5 . Bb5 . D6 . Bb5 . G5 . Bb5 . D6 . G6 . | F5 . A5 . C6 . A5 . F5 . A5 . C6 . F6 . | " + + "Eb5 . G5 . Bb5 . G5 . Eb5 . G5 . Bb5 . Eb6 . | A5 . C#6 . E6 . C#6 . A5 . E5 . A4 . . .", + tin: + ". G6 . G6 . G6 . G6 . G6 . G6 . G6 . G6 | . F6 . F6 . F6 . F6 . F6 . F6 . F6 . F6 | " + + ". Eb6 . Eb6 . Eb6 . Eb6 . Eb6 . Eb6 . Eb6 . Eb6 | . A5 . A5 . A5 . A5 . A5 . A5 . A5 . A5", + bass: + "G2 . D3 . G2 . D3 . G2 . D3 . G2 . D3 . | F2 . C3 . F2 . C3 . F2 . C3 . F2 . C3 . | " + + "Eb2 . Bb2 . Eb2 . Bb2 . Eb2 . Bb2 . Eb2 . Bb2 . | A2 . E3 . A2 . E3 . A2 . E3 . A2 . E3 .", + kick: + "k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . . | " + + "k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . .", + hat: + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " + + ". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .", + snap: + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " + + ". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .", + riser: + "G3 - - - - - - - - - - - - - - - | F3 - - - - - - - - - - - - - - - | " + + "Eb3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -", + lead2: + "G5 G5 G5 G5 Bb5 Bb5 Bb5 Bb5 D6 D6 D6 D6 . . . . | F5 F5 F5 F5 A5 A5 A5 A5 C6 C6 C6 C6 . . . . | " + + "Eb5 Eb5 Eb5 Eb5 G5 G5 G5 G5 Bb5 Bb5 Bb5 Bb5 . . . . | A5 A5 A5 A5 C#6 C#6 C#6 C#6 E6 E6 E6 E6 . . . .", + }, + }, + order: ["A", "B", "A", "C", "B", "A", "B", "A", "C", "B", "A"], + }, + }, +}; diff --git a/src/web-console/public/activities/ghoul-sfx-wagon.js b/src/web-console/public/activities/ghoul-sfx-wagon.js new file mode 100644 index 0000000..41971e7 --- /dev/null +++ b/src/web-console/public/activities/ghoul-sfx-wagon.js @@ -0,0 +1,230 @@ +// Plan2Code Web Console - ghoul: The Torch Mob's own sound effects and music track, merged into ghoul-sfx.js; defines only. +// +// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulWagon` sound for the +// wagon's things) and `music` (a track for the room, named in ROOM_MUSIC in ghoul.js). Both are +// built here from the house's tone layers (no audio files); the picks are still to be made by ear, +// so each is a first sketch. No tone runs over 1.2 s; the track is built from short patterns. A +// name may be defined only once across tones.js and every game's file. No imports. + +export const WAGON_SFX = { + tones: { + // Torch Mob: The bonus ride: you race a stolen hay wagon out of Hollow End with the whole village behind you. + // Jumps: Wheels leave the cobbles with a creak. + ghoulWagonJump: { + layers: [ + { type: "noise", seconds: 0.2, attack: 0.06, gain: 0.34, filter: { type: "bandpass", from: 1200, to: 2600, q: 3 } }, + { type: "sawtooth", from: 150, to: 230, seconds: 0.18, attack: 0.04, gain: 0.2, vibrato: { rate: 22, depth: 0.1 }, filter: { type: "bandpass", from: 500, to: 900, q: 4 } }, + ], + }, + // Lands: Wheels and planks clatter back down. + ghoulWagonLand: { + layers: [ + { type: "sine", from: 120, to: 50, seconds: 0.16, attack: 0, gain: 0.8 }, + { type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1500, to: 900, q: 4 } }, + { type: "noise", seconds: 0.05, delay: 0.06, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 1900, to: 1200, q: 4 } }, + { type: "noise", seconds: 0.05, delay: 0.11, attack: 0, gain: 0.3, filter: { type: "bandpass", from: 1300, to: 800, q: 4 } }, + ], + }, + // Launches off the bridge ramp: A whoosh and a whooping horse. + ghoulWagonLaunch: { + layers: [ + { type: "noise", seconds: 0.8, attack: 0.3, gain: 0.5, filter: { type: "bandpass", from: 300, to: 2200, q: 2 } }, + { type: "sawtooth", from: 420, to: 1150, seconds: 0.55, attack: 0.08, gain: 0.3, vibrato: { rate: 9, depth: 0.08 }, filter: { type: "bandpass", from: 1100, to: 1700, q: 3 } }, + { type: "triangle", from: 280, to: 640, seconds: 0.5, attack: 0.1, gain: 0.3 }, + ], + }, + // Brakes: Wood scrapes on stone, an axle squeal. + ghoulWagonBrake: { + layers: [ + { type: "noise", seconds: 0.3, attack: 0.05, gain: 0.45, filter: { type: "bandpass", from: 1800, to: 700, q: 2 } }, + { type: "sawtooth", from: 900, to: 620, seconds: 0.28, attack: 0.03, gain: 0.16, vibrato: { rate: 30, depth: 0.05 }, filter: { type: "bandpass", from: 1500, to: 800, q: 6 } }, + ], + }, + // Crash: Splintering wood. + ghoulWagonCrash: { + layers: [ + { type: "sine", from: 96, to: 36, seconds: 0.25, attack: 0, gain: 1 }, + { type: "brown", seconds: 0.2, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 300, to: 300, q: 1 } }, + { type: "noise", seconds: 0.05, delay: 0.02, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 2400, to: 1500, q: 3 } }, + { type: "noise", seconds: 0.05, delay: 0.08, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 3000, to: 2000, q: 3 } }, + { type: "noise", seconds: 0.3, delay: 0.1, attack: 0.1, gain: 0.25, filter: { type: "bandpass", from: 1200, to: 3000, q: 2 } }, + ], + }, + // Checkpoint: The village's church bell. + ghoulWagonCheck: { + layers: [ + { type: "sine", from: 392, to: 388, seconds: 0.9, attack: 0.004, gain: 0.45 }, + { type: "sine", from: 784, to: 776, seconds: 0.7, attack: 0.004, gain: 0.22 }, + { type: "sine", from: 1180, to: 1170, seconds: 0.5, attack: 0.004, gain: 0.12 }, + { type: "sine", from: 523, to: 520, seconds: 0.8, attack: 0.004, gain: 0.3, delay: 0.16 }, + { type: "sine", from: 1046, to: 1040, seconds: 0.5, attack: 0.004, gain: 0.14, delay: 0.16 }, + ], + }, + // Finish: A fanfare through the gate. + ghoulWagonFinish: { + layers: [ + { type: "triangle", seconds: 0.9, attack: 0.01, gain: 0.7, notes: [392, 494, 587, 784] }, + { type: "sine", seconds: 0.9, attack: 0.01, gain: 0.25, notes: [784, 988, 1175, 1568] }, + ], + }, + // Horses bolt: The mob is close, a panicked whinny. + ghoulWagonPanic: { + layers: [ + { type: "sawtooth", from: 520, to: 1250, seconds: 0.35, attack: 0.04, gain: 0.34, vibrato: { rate: 24, depth: 0.1 }, filter: { type: "bandpass", from: 1400, to: 2200, q: 3 } }, + { type: "sawtooth", from: 1250, to: 640, seconds: 0.5, attack: 0.02, gain: 0.3, delay: 0.35, vibrato: { rate: 20, depth: 0.12 }, filter: { type: "bandpass", from: 1600, to: 900, q: 3 } }, + ], + }, + // Caught: The mob's roar and a hard knock. + ghoulWagonCatch: { + layers: [ + { type: "sawtooth", from: 110, to: 70, seconds: 0.7, attack: 0.04, gain: 0.5, vibrato: { rate: 13, depth: 0.15 }, filter: { type: "lowpass", from: 900, to: 400, q: 2 } }, + { type: "noise", seconds: 0.7, attack: 0.1, gain: 0.35, filter: { type: "bandpass", from: 500, to: 1500, q: 1 } }, + { type: "sine", from: 80, to: 36, seconds: 0.25, attack: 0, gain: 0.9, delay: 0.05 }, + ], + }, + // Hay catches: A flare and crackle. + ghoulWagonFire: { + layers: [ + { type: "noise", seconds: 0.5, attack: 0.1, gain: 0.5, filter: { type: "bandpass", from: 500, to: 2800, q: 1.5 } }, + { type: "pink", seconds: 0.6, attack: 0.2, gain: 0.3, filter: { type: "bandpass", from: 800, to: 3200, q: 1 } }, + { type: "noise", seconds: 0.03, delay: 0.25, attack: 0, gain: 0.5, filter: { type: "highpass", from: 3500, to: 3500 } }, + { type: "noise", seconds: 0.03, delay: 0.38, attack: 0, gain: 0.5, filter: { type: "highpass", from: 3800, to: 3800 } }, + ], + }, + // Fire out: A hiss that dies away. + ghoulWagonOut: { + layers: [ + { type: "noise", seconds: 0.5, attack: 0.02, gain: 0.35, filter: { type: "bandpass", from: 4200, to: 1800, q: 1.5 } }, + ], + }, + // Thrower: A villager in a window or on a roof, with a pitchfork or a torch for the wagon (shoot it or dodge it). + // Winds up: A torch flares and a grunt. + ghoulWagonWind: { + layers: [ + { type: "noise", seconds: 0.4, attack: 0.15, gain: 0.34, filter: { type: "bandpass", from: 600, to: 2400, q: 2 } }, + { type: "sawtooth", from: 150, to: 110, seconds: 0.3, attack: 0.04, gain: 0.3, vibrato: { rate: 9, depth: 0.1 }, filter: { type: "lowpass", from: 700, to: 450, q: 2 }, delay: 0.1 }, + ], + }, + // Throws: A swish through the air. + ghoulWagonThrow: { + layers: [ + { type: "noise", seconds: 0.25, attack: 0.08, gain: 0.5, filter: { type: "bandpass", from: 3000, to: 900, q: 3 } }, + { type: "sine", from: 900, to: 400, seconds: 0.2, attack: 0.02, gain: 0.12 }, + ], + }, + // Shot down: A crack and a shower of sparks. + ghoulWagonShot: { + layers: [ + { type: "noise", seconds: 0.05, attack: 0, gain: 0.8, filter: { type: "bandpass", from: 2000, to: 1300, q: 2 } }, + { type: "square", from: 900, to: 300, seconds: 0.05, attack: 0, gain: 0.3 }, + { type: "noise", seconds: 0.04, delay: 0.06, attack: 0, gain: 0.5, filter: { type: "highpass", from: 3500, to: 3500 } }, + { type: "sine", from: 2600, to: 3800, seconds: 0.16, attack: 0.002, gain: 0.15, delay: 0.05 }, + ], + }, + // A torch lands short: A soft thud and sputter. + ghoulWagonEmber: { + layers: [ + { type: "brown", seconds: 0.1, attack: 0, gain: 0.4, filter: { type: "lowpass", from: 300, to: 300, q: 1 } }, + { type: "noise", seconds: 0.2, delay: 0.04, attack: 0.04, gain: 0.2, filter: { type: "bandpass", from: 3000, to: 1500, q: 2 } }, + ], + }, + // Spooked Horse: A loose horse that rears, then charges down the road (jump it, or shoot it three times to turn it). + // Rears: A whinny. + ghoulWagonRear: { + layers: [ + { type: "sawtooth", from: 700, to: 1500, seconds: 0.3, attack: 0.03, gain: 0.34, vibrato: { rate: 26, depth: 0.1 }, filter: { type: "bandpass", from: 1500, to: 2400, q: 3 } }, + { type: "sawtooth", from: 1500, to: 800, seconds: 0.4, attack: 0.02, gain: 0.3, delay: 0.3, vibrato: { rate: 22, depth: 0.12 }, filter: { type: "bandpass", from: 1700, to: 1000, q: 3 } }, + { type: "noise", seconds: 0.2, attack: 0.05, gain: 0.15, filter: { type: "bandpass", from: 2400, to: 3600, q: 1.5 } }, + ], + }, + // Takes a bolt: A startled snort. + ghoulWagonHorseHit: { + layers: [ + { type: "noise", seconds: 0.05, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 1600, to: 1100, q: 2 } }, + { type: "sawtooth", from: 420, to: 300, seconds: 0.18, attack: 0.01, gain: 0.35, vibrato: { rate: 14, depth: 0.1 }, filter: { type: "lowpass", from: 1200, to: 700, q: 2 }, delay: 0.03 }, + { type: "noise", seconds: 0.15, delay: 0.08, attack: 0.03, gain: 0.25, filter: { type: "bandpass", from: 800, to: 400, q: 1 } }, + ], + }, + // Turns back: A whinny and hooves galloping away. + ghoulWagonHorseTurn: { + layers: [ + { type: "sawtooth", from: 800, to: 1400, seconds: 0.25, attack: 0.02, gain: 0.3, vibrato: { rate: 24, depth: 0.1 }, filter: { type: "bandpass", from: 1500, to: 2200, q: 3 } }, + { type: "noise", seconds: 0.04, delay: 0.25, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 500, to: 300, q: 4 } }, + { type: "noise", seconds: 0.04, delay: 0.33, attack: 0, gain: 0.45, filter: { type: "bandpass", from: 520, to: 320, q: 4 } }, + { type: "noise", seconds: 0.04, delay: 0.4, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 500, to: 300, q: 4 } }, + { type: "noise", seconds: 0.04, delay: 0.5, attack: 0, gain: 0.3, filter: { type: "bandpass", from: 520, to: 320, q: 4 } }, + { type: "noise", seconds: 0.04, delay: 0.57, attack: 0, gain: 0.2, filter: { type: "bandpass", from: 500, to: 300, q: 4 } }, + ], + }, + }, + music: { + // Torch Mob: a runaway hoedown. A sawing fiddle line over a galloping bass (long, short, short + // on every beat) and a stomping kick and snare, in D minor, quick enough to feel chased. As the + // dread rises a drone of low chords and a high second fiddle join, and the tempo climbs. + ghoulWagonRide: { + bpm: 168, + rush: 14, + voices: { + fiddle: { wave: "pulse", duty: 0.25, gain: 0.11, decay: 0.12, sustain: 0.55, vibrato: { rate: 5.5, depth: 0.02, delay: 0.1 } }, + chord: { wave: "pulse", duty: 0.125, gain: 0.045, decay: 0.05, sustain: 0.4, from: 0.25 }, + bass: { wave: "triangle", gain: 0.42, decay: 0.07, sustain: 0.45 }, + drums: { kit: true, gain: 0.24 }, + fiddle2: { wave: "pulse", duty: 0.5, gain: 0.05, decay: 0.1, sustain: 0.5, from: 0.6 }, + }, + patterns: { + A: { + fiddle: + "D5 - F5 - A5 - F5 - D5 - F5 - A5 - D6 - | C6 - A5 - F5 - A5 - C6 - A5 - F5 - A5 - | " + + "Bb5 - G5 - D5 - G5 - Bb5 - G5 - D5 - G5 - | A5 - - - E5 - - - A5 - C#6 - E6 - - -", + chord: + "D4^037 - - - D4^037 - - - D4^037 - - - D4^037 - - - | F4^047 - - - F4^047 - - - F4^047 - - - F4^047 - - - | " + + "Bb3^047 - - - Bb3^047 - - - Bb3^047 - - - Bb3^047 - - - | A3^047 - - - A3^047 - - - A3^047 - - - A3^047 - - -", + bass: + "D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 | F2 . F3 F2 F2 . F3 F2 F2 . F3 F2 F2 . F3 F2 | " + + "Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 | A1 . A2 A1 A1 . A2 A1 A1 . A2 A1 A1 . A2 A1", + drums: + "k . h . s . h . k . h k s . h . | k . h . s . h . k . h k s . h . | " + + "k . h . s . h . k . h k s . h . | k . h . s . h . k . h k s . s s", + fiddle2: + "A5 - - - - - - - F5 - - - - - - - | A5 - - - - - - - C6 - - - - - - - | " + + "D6 - - - - - - - Bb5 - - - - - - - | E6 - - - - - - - A5 - - - - - - -", + }, + B: { + fiddle: + "A5 - A5 D6 - D6 A5 - F5 - A5 - D6 - - - | G5 - G5 C6 - C6 G5 - E5 - G5 - C6 - - - | " + + "F5 - F5 Bb5 - Bb5 F5 - D5 - F5 - Bb5 - - - | E5 - G5 - Bb5 - A5 - G5 - E5 - C#5 - A4 -", + chord: + "D4^037 - - - D4^037 - - - D4^037 - - - D4^037 - - - | C4^047 - - - C4^047 - - - C4^047 - - - C4^047 - - - | " + + "Bb3^047 - - - Bb3^047 - - - Bb3^047 - - - Bb3^047 - - - | A3^047 - - - A3^047 - - - A3^047 - - - A3^047 - - -", + bass: + "D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 | C2 . C3 C2 C2 . C3 C2 C2 . C3 C2 C2 . C3 C2 | " + + "Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 | A1 . A2 A1 A1 . A2 A1 A1 . A2 A1 A1 . A2 A1", + drums: + "k . h . s . h . k . h k s . h . | k . h . s . h . k . h k s . h . | " + + "k . h . s . h . k . h k s . h . | k . h . s . h . k . h k s . s s", + fiddle2: + "D6 - - - - - - - D6 - - - - - - - | E6 - - - - - - - E6 - - - - - - - | " + + "F6 - - - - - - - D6 - - - - - - - | E6 - - - - - - - A5 - - - - - - -", + }, + C: { + fiddle: + "F5 - A5 - D6 - A5 - F5 - A5 - D6 - F6 - | E6 - D6 - C6 - A5 - E5 - A5 - C6 - E6 - | " + + "D6 - Bb5 - G5 - Bb5 - D6 - Bb5 - G5 - D5 - | C#6 - E6 - A5 - C#6 - E5 - A5 - C#6 - E6 -", + chord: + "D4^037 - - - D4^037 - - - D4^037 - - - D4^037 - - - | A3^037 - - - A3^037 - - - A3^037 - - - A3^037 - - - | " + + "G3^037 - - - G3^037 - - - G3^037 - - - G3^037 - - - | A3^047 - - - A3^047 - - - A3^047 - - - A3^047 - - -", + bass: + "D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 | A1 . A2 A1 A1 . A2 A1 A1 . A2 A1 A1 . A2 A1 | " + + "G1 . G2 G1 G1 . G2 G1 G1 . G2 G1 G1 . G2 G1 | A1 . A2 A1 A1 . A2 A1 A1 . A2 A1 A1 . A2 A1", + drums: + "k . h k s . h . k . h k s . h k | k . h k s . h . k . h k s . h k | " + + "k . h k s . h . k . h k s . h k | k . h k s . h . k s k s k s s s", + fiddle2: + "F6 - - - - - - - A6 - - - - - - - | E6 - - - - - - - C6 - - - - - - - | " + + "D6 - - - - - - - Bb5 - - - - - - - | E6 - - - - - - - A6 - - - - - - -", + }, + }, + order: ["A", "A", "B", "A", "C", "B", "A", "B", "C", "A"], + }, + }, +}; diff --git a/src/web-console/public/activities/ghoul-sfx.js b/src/web-console/public/activities/ghoul-sfx.js index 8ee91f2..f001bce 100644 --- a/src/web-console/public/activities/ghoul-sfx.js +++ b/src/web-console/public/activities/ghoul-sfx.js @@ -20,12 +20,22 @@ import { MINE_SFX } from "./ghoul-sfx-mine.js"; import { CARNIVAL_SFX } from "./ghoul-sfx-carnival.js"; import { FROZEN_SFX } from "./ghoul-sfx-frozen.js"; import { SLED_SFX } from "./ghoul-sfx-sled.js"; +import { BANISTER_SFX } from "./ghoul-sfx-banister.js"; +import { HEARSE_SFX } from "./ghoul-sfx-hearse.js"; +import { BOG_SFX } from "./ghoul-sfx-bog.js"; +import { BOGBOAT_SFX } from "./ghoul-sfx-bogboat.js"; +import { GURNEY_SFX } from "./ghoul-sfx-gurney.js"; +import { PEW_SFX } from "./ghoul-sfx-pew.js"; +import { MOWER_SFX } from "./ghoul-sfx-mower.js"; +import { WAGON_SFX } from "./ghoul-sfx-wagon.js"; +import { TRAY_SFX } from "./ghoul-sfx-tray.js"; import { ARMS_SFX } from "./ghoul-sfx-arms.js"; import { RIDE_SFX } from "./ghoul-sfx-ride.js"; +import { STORY_SFX } from "./ghoul-sfx-story.js"; // Each stage's sounds and tracks, by stage: `tones`, `hums` and `music` as // below, any of them left out. -const STAGE_SFX = Object.freeze([GRAVEYARD_SFX, GROUNDS_SFX, CHAPEL_SFX, SANATORIUM_SFX, VILLAGE_SFX, MINE_SFX, CARNIVAL_SFX, FROZEN_SFX,SLED_SFX, ARMS_SFX, RIDE_SFX]); +const STAGE_SFX = Object.freeze([GRAVEYARD_SFX, GROUNDS_SFX, CHAPEL_SFX, SANATORIUM_SFX, VILLAGE_SFX, MINE_SFX, CARNIVAL_SFX, FROZEN_SFX,SLED_SFX, HEARSE_SFX, BOG_SFX, BOGBOAT_SFX, GURNEY_SFX, PEW_SFX, MOWER_SFX, WAGON_SFX, TRAY_SFX, ARMS_SFX, RIDE_SFX, BANISTER_SFX, STORY_SFX]); const fromStages = (key) => Object.assign({}, ...STAGE_SFX.map((st) => st[key] || {})); // One second of the laugh track (part 0, 1 or 2): every event is placed on the @@ -121,6 +131,14 @@ const HOUSE = { { type: "noise", seconds: 0.25, delay: 0.5, gain: 0.15, filter: { type: "highpass", from: 5000, to: 8000 } }, ], }, + // The Lucky die leaving the HUD: the screen holds under a low drone that swells and closes in. + ghoulDiceDrone: { + layers: [ + { type: "sawtooth", from: 52, to: 78, seconds: 0.85, attack: 0.3, gain: 0.35, filter: { type: "lowpass", from: 200, to: 700 } }, + { type: "sine", from: 104, to: 156, seconds: 0.85, attack: 0.3, gain: 0.3, vibrato: { rate: 6, depth: 0.03 } }, + { type: "noise", seconds: 0.8, gain: 0.12, filter: { type: "bandpass", from: 300, to: 2400, q: 1 } }, + ], + }, // A Lucky die's 1: a wind-up toy laughing at you, a ratchet clicking before // each buzzy "ha", running down as its spring does. ghoulDiceLaugh: { @@ -138,6 +156,27 @@ const HOUSE = { // pseudo-voices at staggered pitches, a hiss of applause beneath, the lot // slowing and sagging as its spring runs down (about 3.2 s in all). ...Object.fromEntries([0, 1, 2].map((part) => [part ? `ghoulLaughTrack${part + 1}` : "ghoulLaughTrack", { layers: laughPart(part) }])), + // A stage's intro card opening: a low swell and a minor arpeggio climbing to a held, shimmering top note (about 1 s). + ghoulStageIntro: { + layers: [ + { type: "sawtooth", from: 55, to: 82, seconds: 1.0, attack: 0.2, gain: 0.3, filter: { type: "lowpass", from: 300, to: 1200 } }, + ...[[0, 220], [0.14, 262], [0.28, 330], [0.42, 440]].map(([delay, hz]) => ({ type: "triangle", from: hz, to: hz * 1.01, seconds: 0.55, delay, attack: 0.01, gain: 0.32 })), + { type: "sine", from: 880, to: 884, seconds: 0.5, delay: 0.56, attack: 0.02, gain: 0.22, vibrato: { rate: 6, depth: 0.01 } }, + { type: "noise", seconds: 0.5, delay: 0.5, gain: 0.08, filter: { type: "highpass", from: 3000, to: 6000 } }, + ], + }, + // A boss fight's card: four slamming drum hits (the letters of BOSS), a heartbeat, then low brass-like saws swelling in a dark minor chord (about 1.2 s). + ghoulBossIntro: { + layers: [ + ...[0.2, 0.3, 0.4, 0.5].map((delay) => ({ type: "sine", from: 120, to: 38, seconds: 0.22, delay, attack: 0.002, gain: 0.8 })), + ...[0.2, 0.3, 0.4, 0.5].map((delay) => ({ type: "brown", seconds: 0.12, delay, attack: 0, gain: 0.55, filter: { type: "lowpass", from: 900, to: 150 } })), + ...[0.7, 0.86].map((delay) => ({ type: "sine", from: 70, to: 40, seconds: 0.22, delay, attack: 0.004, gain: 0.7 })), + { type: "sawtooth", from: 55, to: 58, seconds: 1.15, delay: 0.05, attack: 0.5, gain: 0.34, filter: { type: "lowpass", from: 320, to: 900 } }, + { type: "sawtooth", from: 65.4, to: 69, seconds: 1.1, delay: 0.1, attack: 0.5, gain: 0.3, filter: { type: "lowpass", from: 320, to: 900 } }, + { type: "sawtooth", from: 82.4, to: 87, seconds: 1.05, delay: 0.15, attack: 0.5, gain: 0.26, filter: { type: "lowpass", from: 320, to: 1000 } }, + { type: "noise", seconds: 0.3, delay: 0.85, attack: 0.2, gain: 0.08, filter: { type: "highpass", from: 2500, to: 5500 } }, + ], + }, // A horror stinger: a minor chord stabbed on low saws, the fight on. ghoulStinger: { layers: [ diff --git a/src/web-console/public/activities/ghoul-story-draw.js b/src/web-console/public/activities/ghoul-story-draw.js new file mode 100644 index 0000000..d59c1b4 --- /dev/null +++ b/src/web-console/public/activities/ghoul-story-draw.js @@ -0,0 +1,811 @@ +// Plan2Code Web Console - Ghoul Rush's intro story, drawn: eight animated scenes (a lonely road, the house on its hill, the hunger, the long arms, the world inside the windows, why YOU, no way back, The Long Hall as the game draws it) in canvas shapes, with the page's heading, its lines typing out, the hints and the skip bar over them. +// +// ghoul-draw.js plugs it in, the way it plugs in ghoul-intro-draw.js: +// storyArt(d) takes its drawing helpers (`d`: label, GOLD, BONE, LOOKS) and hands back +// `(ctx, v)`, drawn over the whole field while `round.phase === "story"` (also +// while paused). `round.story.ms` is the page's clock (it stops with the game, +// so a pause holds every animation). The words, colors and sounds live in +// ghoul-story.js. Field units (96 by 54), y counted down from the field's top; +// a scene gets the top SCENE_H units, the words the band below. No gradients +// (the tests' fake canvas has none): bands of flat color and alpha instead. + +import { INTROS } from "./ghoul-intros.js"; +import { dot, faint, flame, poly, rnd, stroke, titleLayout, dropAt } from "./ghoul-intro-draw.js"; +import { CHAR_MS, FINALE_TITLE, LAST_HINT, PAGES, SKIP_HINT, REVEAL_AT_MS, SKIP_HOLD_MS, STORY_HINT, lineAt, ready, revealEnd, shown, typed } from "./ghoul-story.js"; + +export const SCENE_H = 33; +export const TEXT_SIZE = 2.3; +const TAU = Math.PI * 2; +const W = 96; +const H = 54; +const clamp = (x, lo = 0, hi = 1) => Math.max(lo, Math.min(hi, x)); +// Eases 0..1 in and out. +const smooth = (x) => { + const k = clamp(x); + return k * k * (3 - 2 * k); +}; +const rect = (ctx, x, y, w, h, fill) => { + ctx.fillStyle = fill; + ctx.fillRect(x, y, w, h); +}; +const circle = (ctx, x, y, r, fill) => dot(ctx, x, y, r, fill); +const star = (ctx, cx, cy, R, r, fill, rot = 0) => { + const pts = []; + for (let i = 0; i < 10; i++) { + const a = rot - Math.PI / 2 + (i * Math.PI) / 5; + const rad = i % 2 ? r : R; + pts.push([cx + Math.cos(a) * rad, cy + Math.sin(a) * rad]); + } + poly(ctx, pts, fill); +}; +// A flicker for light number `i`: mostly on, now and then guttering. +const flick = (i, t) => clamp(0.65 + 0.35 * Math.sin(t / (150 + (i % 5) * 41) + i * 1.9) + 0.2 * Math.sin(t / 53 + i), 0.15, 1); + +/* ------------------------------------------------------- shared pieces */ + +// A sky of flat bands: the page's sky color, lighter toward the horizon. +function sky(ctx, pal, to = SCENE_H) { + rect(ctx, 0, 0, W, to, pal.sky); + for (let i = 0; i < 6; i++) faint(ctx, 0.05, () => rect(ctx, 0, to - (i + 1) * (to / 7), W, to / 7, pal.glow)); +} +function stars(ctx, t, n, maxY, color = "#ffffff") { + for (let i = 0; i < n; i++) faint(ctx, 0.3 + 0.7 * (0.5 + 0.5 * Math.sin(t / (300 + rnd(i, 4) * 500) + i)), () => dot(ctx, rnd(i) * W, rnd(i, 1) * maxY, 0.14 + rnd(i, 2) * 0.16, color)); +} +function moon(ctx, x, y, r, color, t) { + for (let i = 3; i >= 1; i--) faint(ctx, 0.05 + 0.01 * Math.sin(t / 700), () => circle(ctx, x, y, r * (1 + i * 0.5), color)); + circle(ctx, x, y, r, color); + faint(ctx, 0.18, () => { + circle(ctx, x - r * 0.3, y - r * 0.2, r * 0.22, "#8a93b8"); + circle(ctx, x + r * 0.35, y + r * 0.3, r * 0.15, "#8a93b8"); + circle(ctx, x + r * 0.1, y - r * 0.5, r * 0.12, "#8a93b8"); + }); +} +// A rolling hill line filled down to `to`, scrolled by `off` units. +function hills(ctx, base, amp, color, off, seed, to = SCENE_H) { + const pts = [[0, to]]; + for (let x = 0; x <= W + 2; x += 2) pts.push([x, base - amp * (0.6 * Math.sin((x + off) * 0.07 + seed) + 0.4 * Math.sin((x + off) * 0.17 + seed * 2))]); + pts.push([W + 2, to]); + poly(ctx, pts, color); +} +// A dead tree, trunk at (x, y), `h` tall, three bare limbs. +function tree(ctx, x, y, h, color, sway = 0) { + const limb = (x1, y1, x2, y2, w) => stroke(ctx, x1, y1, x2, y2, color, w); + limb(x, y, x + sway * 0.2, y - h, h * 0.07); + limb(x + sway * 0.2, y - h * 0.55, x - h * 0.3 + sway * 0.4, y - h * 0.85, h * 0.04); + limb(x + sway * 0.2, y - h * 0.7, x + h * 0.32 + sway * 0.5, y - h * 0.98, h * 0.04); + limb(x + sway * 0.2, y - h * 0.9, x + h * 0.08 + sway, y - h * 1.15, h * 0.03); +} +// Drifting banks of fog. +function fog(ctx, t, y, color, alpha, speed = 0.01, n = 5) { + for (let i = 0; i < n; i++) { + faint(ctx, alpha, () => { + ctx.beginPath(); + ctx.ellipse((((t * speed * 1000) / 1000 + i * (W / n + 7)) % (W + 40)) - 20, y + (i % 2) * 1.2, 15, 1.8, 0, 0, TAU); + ctx.fillStyle = color; + ctx.fill(); + }); + } +} +function lightning(ctx, t, times, S = SCENE_H) { + let a = 0; + for (const at of times) { + const d = t - at; + if (d >= 0 && d < 420) a = Math.max(a, d < 60 ? 1 : d < 160 ? 0.3 : d < 220 ? 0.8 : 0.9 * (1 - (d - 220) / 200)); + } + if (a > 0) faint(ctx, a * 0.55, () => rect(ctx, 0, 0, W, S, "#e6ecff")); + return a; +} + +// A house in silhouette, its feet at (x, y), `s` times its size (about 34 units wide, 25 tall at s 1: a turret on the left, the main roof, a wing on the right, a chimney). It stands on a stone foundation course along its whole width; draw a hill (knoll) over its feet afterward so no part of the base hangs in the air. `o`: t, body color, win(i) -> { c, a } for each of ten windows, mouth (the door a gaping mouth, 0..1 open). +const WINS = [[-14, -14], [-14, -9], [-8.5, -9], [-5, -9], [3.5, -9], [7, -9], [-8.5, -4.6], [7, -4.6], [11.5, -5.4], [-1, -15.2]]; +// The main roof's height over x (house units, x from -11 to 11): the chimney stands on this. +const roofAt = (dx) => -19.5 + (Math.abs(dx) / 11) * 8.5; +function house(ctx, x, y, s, o = {}) { + const t = o.t || 0; + const body = o.body || "#0c0815"; + const rr = (dx, dy, w, h, c) => rect(ctx, x + dx * s, y + dy * s, w * s, h * s, c); + const tri = (pts, c) => poly(ctx, pts.map(([px, py]) => [x + px * s, y + py * s]), c); + rr(-15, -17, 5, 17, body); + tri([[-16, -17], [-12.5, -25], [-9, -17]], body); + rr(10, -8, 7, 8, body); + tri([[9, -8], [13.5, -13.5], [18, -8]], body); + rr(-10, -11, 20, 11, body); + tri([[-11, -11], [0, -19.5], [11, -11]], body); + // The chimney runs down INTO the roof: past the slope at both its sides, to the eaves. + const cx0 = 4.8; + const cx1 = 7.2; + rr(cx0, -22, cx1 - cx0, Math.max(roofAt(cx0), roofAt(cx1)) + 22 + 1.5, body); + rr(cx0 - 0.4, -22.5, cx1 - cx0 + 0.8, 0.8, body); + rr(-11.5, -17.2, 9, 0.4, "#1a1228"); + // The stone foundation course, wall to wall, with its blocks. + const stone = o.stone || "#1b1530"; + rr(-16.5, -1.5, 35, 1.5, stone); + rr(-16.5, -1.5, 35, 0.2, "#2a2146"); + for (let k = -16.5; k < 18.5; k += 2.4) rr(k + ((Math.round(k) % 2) ? 0.6 : 0), -1.5, 0.14, 1.5, body); + rr(-16.5, -0.75, 35, 0.12, body); + WINS.forEach(([dx, dy], i) => { + const w = o.win ? o.win(i) : { c: "#ffd27a", a: flick(i, t) }; + if (!w || !(w.a > 0)) { + rr(dx, dy, 2, 2.6, "#05030a"); + return; + } + faint(ctx, w.a * 0.12, () => rr(dx - 0.6, dy - 0.6, 3.2, 3.8, w.c)); + faint(ctx, w.a, () => rr(dx, dy, 2, 2.6, w.c)); + rr(dx + 0.9, dy, 0.2, 2.6, body); + rr(dx, dy + 1.2, 2, 0.2, body); + }); + // The door: an arch, or a mouth. + const open = o.mouth || 0; + rr(-1.7, -4.8 - open * 0.8, 3.4, 4.8 + open * 0.8, o.mouth !== undefined ? "#2a0508" : "#050308"); + circle(ctx, x, y - 4.8 * s - open * 0.8 * s, 1.7 * s, o.mouth !== undefined ? "#2a0508" : "#050308"); + if (o.mouth !== undefined) { + faint(ctx, 0.5 + 0.3 * Math.sin(t / 200), () => rr(-1.2, -3.2, 2.4, 2.8, "#ff3b30")); + for (let i = 0; i < 4; i++) { + tri([[-1.6 + i * 0.85, -4.9 - open * 0.8], [-1.2 + i * 0.85, -3.7 - open * 0.8 * 0.4], [-0.8 + i * 0.85, -4.9 - open * 0.8]], "#efe6cf"); + tri([[-1.6 + i * 0.85, 0], [-1.2 + i * 0.85, -1.2 - open * 0.3], [-0.8 + i * 0.85, 0]], "#efe6cf"); + } + } +} + +// The little hero, facing right, feet at (x, y), `s` times its size (4.4 units tall at s 1): a box, a star for an eye, stick arms and two small feet, a flashlight in one hand. `o`: t, walk, lit (the beam's alpha, for a glow at the lens), cheer. +function hero(ctx, x, y, s, face, o = {}) { + const t = o.t || 0; + const stepA = o.walk ? Math.sin(t / 110) : 0; + const bob = o.walk ? Math.abs(stepA) * 0.28 : 0; + ctx.save(); + ctx.translate(x, y - bob * s); + ctx.scale(s * face, s); + ctx.lineCap = "round"; + ctx.strokeStyle = "#cfc4a6"; + ctx.lineWidth = 0.32; + for (const k of [-1, 1]) { + const fx = k * 0.75 + (o.walk ? stepA * 0.7 * k : 0); + stroke(ctx, k * 0.6, -1.2, fx, -0.2, "#cfc4a6", 0.32); + ctx.beginPath(); + ctx.ellipse(fx + 0.15, -0.18, 0.6, 0.32, 0, 0, TAU); + ctx.fillStyle = "#cfc4a6"; + ctx.fill(); + } + // The free arm behind, then the box. + stroke(ctx, -1.6, -2.7, -2.2 - (o.cheer ? 0.4 : 0), o.cheer ? -5.2 : -1.6 + (o.walk ? stepA * 0.5 : 0), "#cfc4a6", 0.32); + rect(ctx, -1.6, -4.4, 3.2, 3.2, "#1e2838"); + ctx.strokeStyle = "#cfc4a6"; + ctx.lineWidth = 0.22; + ctx.strokeRect(-1.6, -4.4, 3.2, 3.2); + star(ctx, 0.15, -3.6, 0.95, 0.4, "#ffd24a", o.t ? Math.sin(t / 900) * 0.15 : 0); + ctx.beginPath(); + ctx.arc(0.15, -2.55, 0.45, 0.15 * Math.PI, 0.85 * Math.PI); + ctx.lineWidth = 0.18; + ctx.strokeStyle = "#cfc4a6"; + ctx.stroke(); + // The flashlight, held out level. + stroke(ctx, 1.6, -2.6, 2.5, -2.25, "#cfc4a6", 0.32); + rect(ctx, 2.3, -2.6, 1.6, 0.7, "#4a4f5a"); + rect(ctx, 3.7, -2.75, 0.4, 1, "#c9ced6"); + ctx.lineCap = "butt"; + ctx.restore(); + if (o.lit > 0) faint(ctx, o.lit * 0.9, () => circle(ctx, x + face * 4.1 * s, y - 2.25 * s - bob * s, 0.7 * s, "#fffbe0")); + return { x: x + face * 4.2 * s, y: y - 2.25 * s - bob * s }; +} +// A cone of light from `from` out `len` units, `spread` wide at the far end. +function beam(ctx, from, len, spread, alpha, color = "#fff3b0", tilt = 0) { + if (!(alpha > 0)) return; + for (let i = 0; i < 3; i++) { + const sp = spread * (1 - i * 0.3); + faint(ctx, alpha * (0.12 + i * 0.06), () => poly(ctx, [[from.x, from.y - 0.3], [from.x + len, from.y + tilt - sp], [from.x + len, from.y + tilt + sp], [from.x, from.y + 0.3]], color)); + } +} + +// A mix of two #rrggbb colors, `k` of the way from a to b. +const mix = (a, b, k) => { + const pa = [1, 3, 5].map((i) => parseInt(a.slice(i, i + 2), 16)); + const pb = [1, 3, 5].map((i) => parseInt(b.slice(i, i + 2), 16)); + return `rgb(${pa.map((v, i) => Math.round(v + (pb[i] - v) * k)).join(",")})`; +}; +const ell = (ctx, x, y, rx, ry, fill) => { + ctx.beginPath(); + ctx.ellipse(x, y, rx, ry, 0, 0, TAU); + ctx.fillStyle = fill; + ctx.fill(); +}; +// An arch: a door or window, its feet at y + h, a half circle on top. +function archPath(ctx, x, y, w, h) { + ctx.beginPath(); + ctx.moveTo(x, y + h); + ctx.lineTo(x, y + w / 2); + ctx.arc(x + w / 2, y + w / 2, w / 2, Math.PI, 0); + ctx.lineTo(x + w, y + h); + ctx.closePath(); +} +function arch(ctx, x, y, w, h, fill) { + archPath(ctx, x, y, w, h); + ctx.fillStyle = fill; + ctx.fill(); +} +// A shambling dark shape, feet at (x, y): head, hunched body, arms out in front (toward the left), `a` its alpha. +function ghoulShape(ctx, x, y, s, t, i, a = 1) { + const c = "#060409"; + const lurch = Math.sin(t / 380 + i * 1.7); + faint(ctx, a, () => { + stroke(ctx, x - 0.5 * s, y - 2.2 * s, x - 0.9 * s + lurch * 0.3, y, c, 0.6 * s); + stroke(ctx, x + 0.5 * s, y - 2.2 * s, x + 0.9 * s - lurch * 0.3, y, c, 0.6 * s); + poly(ctx, [[x - 1.3 * s, y - 2.4 * s], [x + 1.4 * s, y - 2.4 * s], [x + 1 * s, y - 4.3 * s], [x - 1 * s, y - 4.3 * s]], c); + stroke(ctx, x - 0.8 * s, y - 3.8 * s, x - 3.2 * s, y - 3.5 * s + lurch * 0.3, c, 0.45 * s); + stroke(ctx, x - 0.6 * s, y - 3.4 * s, x - 3 * s, y - 2.9 * s - lurch * 0.3, c, 0.45 * s); + circle(ctx, x - 0.2 * s, y - 4.7 * s, 0.95 * s, c); + }); +} +// A hill's top: flat under the whole of what stands on it (`flat` each side of cx, at height y), then rounded shoulders easing down `depth` over `slope` units to the ground behind. Draw it AFTER the house so the base is set into it. +function knoll(ctx, cx, y, flat, slope, depth, color, to = SCENE_H) { + const x0 = cx - flat - slope; + const x1 = cx + flat + slope; + const pts = [[x0, to]]; + for (let x = x0; x < x1 + 0.5; x += 1) pts.push([Math.min(x, x1), y + depth * smooth((Math.abs(Math.min(x, x1) - cx) - flat) / slope)]); + pts.push([x1, to]); + poly(ctx, pts, color); +} +// Grass tufts along a crest. +function tufts(ctx, x0, x1, y, color, t = 0) { + for (let x = x0; x < x1; x += 1.7) stroke(ctx, x, y + 0.2, x + 0.3 + Math.sin(t / 400 + x) * 0.3, y - 0.8 - rnd(x) * 0.5, color, 0.18); +} + +// The three little places seen through the house's windows (each drawn inside its window's clip: `x`, `y` the window's top left, `w` by `h`). +function lakeInside(ctx, x, y, w, h, t) { + rect(ctx, x, y, w, h, "#0e1a30"); + for (let i = 0; i < 9; i++) faint(ctx, 0.4 + 0.5 * Math.sin(t / 500 + i), () => dot(ctx, x + rnd(i, 3) * w, y + 1 + rnd(i, 4) * 6, 0.17, "#ffffff")); + poly(ctx, [[x, y + 11], [x + 5, y + 8.6], [x + 11, y + 10.8], [x + 17, y + 8.8], [x + w, y + 10.5], [x + w, y + h], [x, y + h]], "#0a1020"); + for (const [px, ph] of [[3, 5], [6.5, 4], [18, 5.2], [20.5, 3.6]]) poly(ctx, [[x + px - 1.1, y + 11.6], [x + px, y + 11.6 - ph], [x + px + 1.1, y + 11.6]], "#050a14"); + ell(ctx, x + w / 2, y + h - 3.6, w * 0.55, 2.9, "#bae6fd"); + stroke(ctx, x + 4, y + h - 3.6, x + 10, y + h - 4.4, "#e0f2fe", 0.15); + stroke(ctx, x + 10, y + h - 4.4, x + 16, y + h - 3, "#e0f2fe", 0.15); + const rise = 0.65 + 0.35 * Math.sin(t / 900); + stroke(ctx, x + 14.5, y + h - 3.8, x + 14.5, y + h - 3.8 - 3 * rise, "#8fb7d1", 0.4); + for (let i = -1; i <= 1; i++) stroke(ctx, x + 14.5 + i * 0.4, y + h - 6.8 * rise - 0.8 + 3 * (1 - rise) * 0.2, x + 14.5 + i * 0.6, y + h - 7.8 * rise, "#8fb7d1", 0.2); +} +function wheelInside(ctx, x, y, w, h, t) { + rect(ctx, x, y, w, h, "#241628"); + for (let i = 0; i < 6; i++) rect(ctx, x + i * 4 + 1, y, 1.4, h, "#2f1d34"); + const cx = x + w / 2; + const cy = y + h - 7.2; + const r = 6.3; + ctx.beginPath(); + ctx.arc(cx, cy, r, 0, TAU); + ctx.strokeStyle = "#f472b6"; + ctx.lineWidth = 0.3; + ctx.stroke(); + for (let i = 0; i < 8; i++) { + const a = t / 2200 + (i * TAU) / 8; + const gx = cx + Math.cos(a) * r; + const gy = cy + Math.sin(a) * r; + stroke(ctx, cx, cy, gx, gy, "#c04a8a", 0.18); + circle(ctx, gx, gy + 0.5, 0.65, i % 2 ? "#fde047" : "#fb7185"); + } + for (let i = 0; i < 16; i++) faint(ctx, 0.5 + 0.5 * Math.sin(t / 220 + i), () => dot(ctx, cx + Math.cos((i * TAU) / 16) * r, cy + Math.sin((i * TAU) / 16) * r, 0.2, "#fff1c4")); + stroke(ctx, cx - 2.6, y + h - 2.2, cx, cy, "#6a3a60", 0.35); + stroke(ctx, cx + 2.6, y + h - 2.2, cx, cy, "#6a3a60", 0.35); + circle(ctx, cx, cy, 0.7, "#fbcfe8"); +} +function villageInside(ctx, x, y, w, h, t) { + rect(ctx, x, y, w, h, "#10142e"); + circle(ctx, x + 16, y + 4.5, 1.7, "#f3e9c0"); + for (let i = 0; i < 6; i++) faint(ctx, 0.5 + 0.4 * Math.sin(t / 450 + i), () => dot(ctx, x + rnd(i, 7) * 12 + 1, y + 1 + rnd(i, 8) * 5, 0.16, "#ffffff")); + poly(ctx, [[x, y + 12], [x + 8, y + 9.6], [x + 15, y + 11.4], [x + w, y + 10], [x + w, y + h], [x, y + h]], "#0a0d22"); + for (let i = 0; i < 4; i++) { + const hx = x + 2 + i * 5; + const hh = 3.2 + (i % 2) * 1.2; + rect(ctx, hx, y + h - 2.2 - hh, 3.4, hh, "#2e2a66"); + poly(ctx, [[hx - 0.4, y + h - 2.2 - hh], [hx + 1.7, y + h - 2.2 - hh - 1.7], [hx + 3.8, y + h - 2.2 - hh]], "#1d1a4a"); + rect(ctx, hx + 1.1, y + h - 2.2 - hh + 0.9, 1.2, 1.2, Math.sin(t / 700 + i * 2) > -0.4 ? "#ffd27a" : "#0b0a22"); + } +} + +/* ------------------------------------------------------------- scenes */ + +const SCENES = { + // I. A lonely road at night: parallax hills and trees, a moon, a house far off with one winking window, eyes in the bushes, YOU walking with the flashlight. + road(ctx, p) { + const { t, pal } = p; + sky(ctx, pal); + stars(ctx, t, 46, 19); + moon(ctx, 76, 9, 4.6, "#dfe9ff", t); + hills(ctx, 21, 2.4, "#0e1838", 0, 1); + // The house on the far hill, one window winking. + house(ctx, 70, 19.6, 0.28, { t, body: "#080b1c", stone: "#12183a", win: (i) => (i === 3 ? { c: "#ffd27a", a: Math.sin(t / 800) > -0.3 ? 0.9 : 0 } : null) }); + // Its ridge: a hilltop flat under the whole house, so its base is set into the land. + knoll(ctx, 70.2, 19.6, 6, 34, 12, "#060a16"); + tufts(ctx, 64, 77, 19.6, "#080b1c", t); + hills(ctx, 25, 3, "#0a1028", t * 0.006, 3); + for (let i = 0; i < 4; i++) tree(ctx, ((i * 31 - t * 0.012) % (W + 24) + (W + 24)) % (W + 24) - 8, 28, 9 + (i % 2) * 3, "#05060f", Math.sin(t / 500 + i) * 1.4); + fog(ctx, t, 27.3, "#8da4e0", 0.1, 0.012); + rect(ctx, 0, 28, W, SCENE_H - 28, pal.ground); + rect(ctx, 0, 28.4, W, 2.6, "#171c36"); + // The road runs on from here up the land to the house on its ridge. + poly(ctx, [[45, 28.6], [56, 28.6], [70.9, 19.8], [69.5, 19.8]], "#1d2342"); + for (let i = 0; i < 9; i++) rect(ctx, (((i * 13 - t * 0.02) % (W + 14)) + W + 14) % (W + 14) - 6, 29.5, 5, 0.4, "#2b3358"); + // Fence posts racing past, and grass bending in the wind. + for (let i = 0; i < 6; i++) { + const x = (((i * 19 - t * 0.03) % (W + 19)) + W + 19) % (W + 19) - 4; + rect(ctx, x, 30.2, 0.7, 3, "#03040a"); + } + for (let i = 0; i < 40; i++) stroke(ctx, i * 2.4 + 0.5, 33, i * 2.4 + 0.5 + Math.sin(t / 300 + i * 0.8) * 0.9 + 0.6, 31.2, "#03040a", 0.2); + // Two eyes in the dark that open, then close. + const blink = (t % 5200) / 5200; + if (blink > 0.35 && blink < 0.8 && blink % 0.18 > 0.02) { + circle(ctx, 62, 26.2, 0.32, "#ffe14a"); + circle(ctx, 63.6, 26.2, 0.32, "#ffe14a"); + } + const lens = hero(ctx, 24, 30.2, 1.15, 1, { t, walk: true }); + beam(ctx, lens, 24, 3.4, 0.7 + 0.1 * Math.sin(t / 90)); + }, + + // II. The house on the hill: lightning, flickering windows, bats, clouds over the moon, a pale shape in the tower, a slow push-in. + house(ctx, p) { + const { t, pal } = p; + sky(ctx, pal); + stars(ctx, t, 30, 14); + moon(ctx, 18, 8, 4.2, "#e8dcff", t); + for (let i = 0; i < 4; i++) { + faint(ctx, 0.85, () => { + ctx.beginPath(); + ctx.ellipse((((t / 120 + i * 29) % (W + 40)) - 20), 7 + (i % 2) * 5, 14, 2.4, 0, 0, TAU); + ctx.fillStyle = "#120a26"; + ctx.fill(); + }); + } + const k = 1 + t / 60000; + ctx.save(); + ctx.translate(60, 22); + ctx.scale(k, k); + ctx.translate(-60, -22); + hills(ctx, 31, 0, "#0a0614", 0, 0); + const lit = (i) => { + if (i === 0 && t > 3800 && t < 5600) return { c: "#e8f2ff", a: 0.95 }; + return { c: "#ffc15a", a: flick(i, t) }; + }; + house(ctx, 60, 22, 1.05, { t, win: lit }); + // The hill: a wide dome flat under the whole house (turret to wing), set over its foundation. + knoll(ctx, 61, 22, 19.5, 22, 9, "#07040d"); + tufts(ctx, 41, 81, 22, "#030207", t); + // A pale shape in the tower window, a while in. + if (t > 3800 && t < 5600) { + rect(ctx, 60 - 14 * 1.05 + 0.5, 22 - 14 * 1.05 + 1, 0.9, 1.5, "#04030a"); + circle(ctx, 60 - 14 * 1.05 + 0.95, 22 - 14 * 1.05 + 0.9, 0.4, "#04030a"); + } + // The fence in front. + for (let x = 30; x < 92; x += 2.2) { + rect(ctx, x, 27.5, 0.35, 5, "#030207"); + poly(ctx, [[x - 0.3, 27.5], [x + 0.18, 26.2], [x + 0.65, 27.5]], "#030207"); + } + rect(ctx, 30, 29, 62, 0.3, "#030207"); + ctx.restore(); + // Bats, and clouds sliding over the moon. + for (let i = 0; i < 4; i++) { + const x = ((t / 22 + i * 29) % (W + 20)) - 10; + const y = 6 + i * 4 + Math.sin(t / 380 + i) * 2; + const f = Math.sin(t / 70 + i) * 1.4; + poly(ctx, [[x, y], [x - 2.6, y - 1.3 + f], [x - 1.2, y + 0.4], [x, y + 0.7], [x + 1.2, y + 0.4], [x + 2.6, y - 1.3 + f]], "#04030a"); + } + lightning(ctx, t, [150, 3100]); + }, + + // III. The hunger: the house's door is a mouth; small frightened figures walk toward it and their fright streams in as light. + hunger(ctx, p) { + const { t, pal } = p; + sky(ctx, pal); + const beat = Math.max(0, Math.sin(t / 380)) ** 6; + faint(ctx, 0.12 + 0.18 * beat, () => rect(ctx, 0, 0, W, SCENE_H, "#7f1d1d")); + rect(ctx, 0, 29, W, SCENE_H - 29, pal.ground); + house(ctx, 66, 29.5, 1.05, { t, mouth: 0.5 + 0.5 * Math.sin(t / 650), win: (i) => ({ c: "#ff2d2d", a: 0.5 + 0.5 * flick(i, t) }) }); + // The chimney glows with each swallow. + faint(ctx, 0.3 + 0.7 * beat, () => circle(ctx, 66 + 6 * 1.05, 29.5 - 21 * 1.05, 2, "#ff5a36")); + // Little figures with their arms up, each shedding fright that flies to the mouth. + for (let i = 0; i < 4; i++) { + const fx = 8 + i * 9; + const fy = 29.5; + const sway = Math.sin(t / 240 + i * 2) * 0.4; + stroke(ctx, fx, fy - 1.2, fx + sway, fy - 3, "#d8cfe8", 0.35); + stroke(ctx, fx + sway, fy - 2.6, fx + sway - 1, fy - 3.8, "#d8cfe8", 0.25); + stroke(ctx, fx + sway, fy - 2.6, fx + sway + 1, fy - 3.8, "#d8cfe8", 0.25); + stroke(ctx, fx, fy - 1.2, fx - 0.5, fy, "#d8cfe8", 0.25); + stroke(ctx, fx, fy - 1.2, fx + 0.5, fy, "#d8cfe8", 0.25); + circle(ctx, fx + sway, fy - 3.7, 0.8, "#d8cfe8"); + circle(ctx, fx + sway, fy - 3.6, 0.28, "#2a0508"); + for (let j = 0; j < 6; j++) { + const q = ((t / 1800 + j / 6 + i * 0.13) % 1); + const x0 = fx + sway; + const y0 = fy - 3.7; + const x1 = 66; + const y1 = 29.5 - 2.4; + const cx = (x0 + x1) / 2; + const cy = Math.min(y0, y1) - 9 - i; + const mx = (1 - q) * (1 - q) * x0 + 2 * (1 - q) * q * cx + q * q * x1; + const my = (1 - q) * (1 - q) * y0 + 2 * (1 - q) * q * cy + q * q * y1; + faint(ctx, Math.sin(q * Math.PI), () => circle(ctx, mx, my, 0.45 - q * 0.2, "#fecaca")); + } + } + fog(ctx, t, 29, "#7f1d1d", 0.18, 0.008, 4); + ctx.globalAlpha = 1; + }, + + // IV. A house with long arms: the house on its hill, its windows waking, its shadow stretching across the ground and long dark arms reaching out of it to both edges; things it swallowed ride the arms back in. + arms(ctx, p) { + const { t, pal, line, full, grow } = p; + sky(ctx, pal); + stars(ctx, t, 24, 12); + moon(ctx, 86, 7, 2.8, "#cfe9dc", t); + hills(ctx, 27.5, 1.2, "#07140f", 0, 6); + rect(ctx, 0, 29, W, SCENE_H - 29, "#0d251c"); + const on = (n) => full || line >= n; + const wake = grow(0, 900); + const reach = 0.1 + 0.9 * grow(1, 1700); + // The shadow: the house's, thrown a long way across the ground. + const len = 6 + 40 * grow(1, 1700); + faint(ctx, 0.8, () => poly(ctx, [[38, 29.2], [38 - len, 31.4], [38 - len * 0.92, 32.2], [46, 33]], "#020604")); + // The house on its hill, its windows eyes, its door a mouth. + house(ctx, 48, 28, 0.85, { t, mouth: 0.15 + 0.5 * wake * (0.5 + 0.5 * Math.sin(t / 600)), win: (i) => ({ c: pal.glow, a: 0.12 + wake * (0.3 + 0.5 * flick(i, t)) }) }); + knoll(ctx, 48.5, 28, 16, 14, 1, "#0d251c"); + tufts(ctx, 33, 65, 28, "#030a07", t); + // One arm: a quadratic curve out of the house, tapering to a hooked hand; returns where a point `q` along it is. + const arm = (x0, y0, cx, cy, x1, y1, seed) => { + const at = (q) => { + const k = q * reach; + const wob = Math.sin(t / 520 + seed * 2 + q * 5) * 0.6 * q; + return [(1 - k) * (1 - k) * x0 + 2 * (1 - k) * k * cx + k * k * x1 + wob * 0.4, (1 - k) * (1 - k) * y0 + 2 * (1 - k) * k * cy + k * k * y1 + wob]; + }; + ctx.lineCap = "round"; + let prev = at(0); + for (let i = 1; i <= 16; i++) { + const cur = at(i / 16); + const w = 1.1 * (1 - (i / 16) * 0.75) + 0.2; + faint(ctx, 0.35, () => stroke(ctx, prev[0], prev[1], cur[0], cur[1], pal.glow, w + 0.25)); + prev = cur; + } + faint(ctx, 1, () => { + let a = at(0); + for (let i = 1; i <= 16; i++) { + const b = at(i / 16); + stroke(ctx, a[0], a[1], b[0], b[1], "#030a06", 1.2 * (1 - (i / 16) * 0.75) + 0.25); + a = b; + } + }); + const end = at(1); + const dir = x1 < x0 ? -1 : 1; + for (let f = -1; f <= 1; f++) stroke(ctx, end[0], end[1], end[0] + dir * 1.3, end[1] + f * 0.9 + Math.sin(t / 300 + f) * 0.2, "#041009", 0.25); + ctx.lineCap = "butt"; + return at; + }; + const arms = [ + arm(41, 27, 22, 33, 3, 30, 1), + arm(40.5, 19, 21, 6, 4, 14, 2), + arm(56, 27, 76, 33, 93, 29, 3), + arm(57, 20, 78, 7, 93, 13, 4), + ]; + // What it has swallowed rides the arms home: small lights in the colors of other places. + if (on(2)) { + const cols = ["#bae6fd", "#f472b6", "#fde68a", "#fca5a5"]; + arms.forEach((at, i) => { + for (let j = 0; j < 3; j++) { + const q = 1 - ((t / 2600 + j / 3 + i * 0.21) % 1); + const [mx, my] = at(q); + faint(ctx, Math.sin(q * Math.PI) * 0.9, () => circle(ctx, mx, my, 0.5, cols[(i + j) % 4])); + } + }); + } + fog(ctx, t, 30.5, "#6ee7b7", 0.07, 0.008, 4); + }, + + // V. A world inside: the house's front is a wall of windows, and through each one a whole tiny place sits inside a room (a frozen lake, a ferris wheel, a village), lighting one by one. + far(ctx, p) { + const { t, pal, full, grow } = p; + sky(ctx, pal); + stars(ctx, t, 26, 6); + // The front of the house: a wall, a gable and a chimney. + const wall = "#0b0a1e"; + rect(ctx, 5, 9, 86, SCENE_H - 9, wall); + poly(ctx, [[2, 9.5], [48, 0.8], [94, 9.5]], wall); + rect(ctx, 74, 1.5, 3, 6, wall); + rect(ctx, 5, 28.4, 86, 0.4, "#1a1838"); + const windows = [[9, 0], [37, 1], [65, 2]]; + windows.forEach(([x0, n]) => { + const lit = full ? 1 : n === 0 ? grow(1, 900) : grow(n + 1, 900); + const y0 = 11.5; + const w = 22; + const h = 16.5; + arch(ctx, x0 - 1, y0 - 1, w + 2, h + 1, "#1d1a40"); + // Seen through: the room inside. + ctx.save(); + archPath(ctx, x0, y0, w, h); + ctx.clip(); + rect(ctx, x0, y0, w, h, "#0a0818"); + if (n === 0) lakeInside(ctx, x0, y0, w, h, t); + else if (n === 1) wheelInside(ctx, x0, y0, w, h, t); + else villageInside(ctx, x0, y0, w, h, t); + // The room: a hanging bulb on its cord, boards in front and a baseboard. + stroke(ctx, x0 + w / 2, y0, x0 + w / 2, y0 + 2.6, "#0a0818", 0.15); + faint(ctx, 0.14 * flick(n * 3 + 1, t), () => circle(ctx, x0 + w / 2, y0 + 3.2, 2.4, "#ffd27a")); + circle(ctx, x0 + w / 2, y0 + 3.2, 0.5, "#fff1c4"); + rect(ctx, x0, y0 + h - 2.2, w, 2.2, "#2a1c14"); + rect(ctx, x0, y0 + h - 2.2, w, 0.3, "#4a3424"); + for (let k = 0; k < 4; k++) rect(ctx, x0 + 2 + k * 6 + n, y0 + h - 1.9, 0.15, 1.9, "#120c08"); + // Dark until its line is typed. + faint(ctx, 0.85 * (1 - lit), () => rect(ctx, x0, y0, w, h, "#06050f")); + ctx.restore(); + // The frame, the sill and the cross bar. + rect(ctx, x0 - 1.5, y0 + h, w + 3, 0.9, "#1d1a40"); + }); + // The ground at its feet. + rect(ctx, 0, 30.4, W, SCENE_H - 30.4, pal.ground); + tufts(ctx, 3, 93, 30.4, "#030210", t); + fog(ctx, t, 31.5, "#a78bfa", 0.06, 0.008, 4); + }, + + // VI. Why YOU: in the dark, the house watches with dim red windows; the flashlight clicks on, the house flinches and goes dark, then winks at YOU. + why(ctx, p) { + const { t, pal } = p; + sky(ctx, pal); + stars(ctx, t, 26, 15); + const click = 1500; + const wink = 3400; + const lit = t >= click; + const since = t - click; + const shake = lit && since < 800 ? (rnd(Math.floor(t / 40)) - 0.5) * 1.4 * (1 - since / 800) : 0; + rect(ctx, 0, 29, W, SCENE_H - 29, pal.ground); + house(ctx, 73 + shake, 29.5, 1.05, { + t, + win: (i) => { + if (t < click) return { c: "#7f1d1d", a: 0.3 + 0.4 * flick(i, t) }; + if (t < wink) return null; + const open = Math.floor((t - wink) / 260); + return i <= open ? { c: "#fde047", a: i === open ? 0.4 : 0.9 } : null; + }, + }); + const lens = hero(ctx, 18, 30.2, 1.3, 1, { t, lit: lit ? clamp(1 - since / 500, 0, 1) : 0 }); + if (lit) { + const a = clamp(since / 250) * (0.8 + 0.1 * Math.sin(t / 70)); + beam(ctx, lens, 38, 5.5, a); + faint(ctx, a * 0.4, () => { + ctx.beginPath(); + ctx.ellipse(61 + shake, 23, 3, 8, 0, 0, TAU); + ctx.fillStyle = "#fff3b0"; + ctx.fill(); + }); + // Flinch marks off the house's corners. + if (since < 700) for (let i = 0; i < 5; i++) stroke(ctx, 57 + i * 1.2, 14 + i * 2.2, 54 + i * 0.4 - since / 90, 12 + i * 2.2, "#fff3b0", 0.25); + } + fog(ctx, t, 30, "#8da4e0", 0.07, 0.01, 4); + if (!lit) faint(ctx, 0.25 * (1 - Math.min(1, t / 1500)), () => rect(ctx, 0, 0, W, SCENE_H, "#000")); + // The click's bloom. + if (since >= 0 && since < 200) faint(ctx, 0.35 * (1 - since / 200), () => rect(ctx, 0, 0, W, SCENE_H, "#fffbe0")); + }, + + // VII. No way back: the road behind YOU folds up like a napkin; a row of doors runs on ahead past the edge, each with its keeper's light under it, and they lock one by one. + trap(ctx, p) { + const { t, pal } = p; + sky(ctx, pal); + rect(ctx, 0, 7, W, 22, "#12070f"); + const glows = Object.values(INTROS).map((i) => i.palette.glow); + for (let i = 0; i < 11; i++) { + const glow = glows[i % glows.length]; + const x = 5 + i * 9; + const lockAt = 1400 + i * 420; + const locked = t >= lockAt; + rect(ctx, x, 13, 7, 15, "#1f0e1c"); + // The keeper's light under the door, until it is locked. + if (!locked) faint(ctx, 0.55 + 0.35 * Math.sin(t / 150 + i), () => rect(ctx, x + 0.4, 26.5, 6.2, 1.5, glow)); + else if (t < lockAt + 200) faint(ctx, 1 - (t - lockAt) / 200, () => rect(ctx, x + 0.4, 13.4, 6.2, 14.4, glow)); + rect(ctx, x, 13, 7, 0.5, "#3a1a34"); + circle(ctx, x + 3.5, 15.2, 0.6, glow); + circle(ctx, x + 5.4, 21, 0.35, "#c9ced6"); + if (locked) { + const pop = clamp((t - lockAt) / 160); + rect(ctx, x + 3.4 - 1.1 * pop, 19.5, 2.2 * pop, 1.8 * pop, "#ef4444"); + ctx.beginPath(); + ctx.arc(x + 3.5, 19.5, 0.9 * pop, Math.PI, 0); + ctx.strokeStyle = "#c9ced6"; + ctx.lineWidth = 0.3; + ctx.stroke(); + } + } + rect(ctx, 0, 28, W, SCENE_H - 28, pal.ground); + // The road behind YOU, pleating up from the far end toward YOU. + const front = clamp(t / 3200) * 8; + for (let i = 0; i < 8; i++) { + const x0 = i * 5; + const fold = smooth(front - (7 - i) + 1); + const h = fold * 6; + const up = i % 2; + poly(ctx, [[x0, 31], [x0 + 5, 31], [x0 + 5, 31 - (up ? h * 0.3 : h)], [x0, 31 - (up ? h : h * 0.3)]], i % 2 ? "#2a2440" : "#1b1830"); + if (fold > 0.02) faint(ctx, 0.5, () => rect(ctx, x0, 31 - (up ? h * 0.3 : h) - 0.2, 5, 0.3, "#8a7fb0")); + } + rect(ctx, 40, 29.5, W - 40, 1.6, "#1b1830"); + const lens = hero(ctx, 50, 31, 1.25, 1, { t }); + beam(ctx, lens, 22, 3, 0.55); + fog(ctx, t, 31, "#c084fc", 0.07, 0.01, 4); + }, + + // VIII. The Long Hall as the game draws it, side on: the hall's own wall colors, striped paper, arched windows, a portrait, candle sconces, the wainscot and the floor boards, the exit door at the far end; YOU at the left switch the flashlight on and its cone lights the hall, where dark shapes with glowing eyes wait; THE RUN BEGINS drops in letter by letter and the light flares. + begin(ctx, p) { + const { t, pal, look } = p; + const FY = 28; + // The wall: the hall's top and bottom colors in flat bands, and the old striped paper. + for (let i = 0; i < 10; i++) rect(ctx, 0, (i * FY) / 10, W, FY / 10 + 0.1, mix(look.wallTop, look.wallLow, i / 9)); + for (let x = 0; x < W + 4; x += 4) { + const n = Math.round(x / 4); + faint(ctx, 0.3 + (n % 3) * 0.08, () => rect(ctx, x, 0, 1.6, FY - 2, look.paper)); + } + // A crack, and the arched windows with the sickly moon (the game's own window). + stroke(ctx, 41, 2, 40.4, 6, "rgba(0, 0, 0, 0.5)", 0.18); + stroke(ctx, 40.4, 6, 41.2, 9, "rgba(0, 0, 0, 0.5)", 0.18); + for (const [wx, n] of [[28.5, 0], [64.5, 1]]) { + const x = wx - 3.5; + const top = 5; + const w = 7; + const h = 14; + arch(ctx, x - 0.5, top - 0.5, w + 1, h + 0.5, look.wainscot); + arch(ctx, x, top, w, h, "#05070d"); + faint(ctx, 0.55, () => circle(ctx, x + w * (0.3 + n * 0.2), top + h * 0.28, w * 0.16, look.window)); + faint(ctx, 0.7, () => ell(ctx, x + w * (0.25 + n * 0.2), top + h * 0.31, w * 0.22, w * 0.07, "#05070d")); + faint(ctx, 0.12, () => rect(ctx, x, top + h * 0.55, w, h * 0.45, look.window)); + rect(ctx, x + w / 2 - 0.2, top + 0.5, 0.4, h - 0.5, look.wainscot); + rect(ctx, x, top + h * 0.55, w, 0.4, look.wainscot); + } + // A portrait in a tarnished frame: a long pale face with empty eyes. + rect(ctx, 44.2, 7.6, 5.6, 7.4, "#4a3a1a"); + rect(ctx, 44.7, 8.1, 4.6, 6.4, "#141a14"); + ell(ctx, 47, 10.8, 1.1, 1.8, "#7a7468"); + ell(ctx, 46.55, 10.4, 0.25, 0.4, "#000000"); + ell(ctx, 47.45, 10.4, 0.25, 0.4, "#000000"); + ell(ctx, 47, 11.8, 0.25, 0.4, "#000000"); + rect(ctx, 45, 12.9, 4, 1.4, "#1a1210"); + // The wainscot, then the floor: its lit edge, its boards and their seams. + rect(ctx, 0, FY - 4, W, 4, look.wainscot); + rect(ctx, 0, FY - 4.25, W, 0.25, look.floorEdge); + rect(ctx, 0, FY, W, SCENE_H - FY, look.floor); + rect(ctx, 0, FY, W, 1.2, look.floorTop); + rect(ctx, 0, FY, W, 0.25, look.floorEdge); + for (let i = 0; i < 12; i++) rect(ctx, 2 + i * 8.5, FY + 0.25, 0.16, 0.95, look.floorEdge); + for (let i = 0; i < 12; i++) rect(ctx, 6 + i * 8.5, FY + 1.2, 0.16, SCENE_H - FY - 1.2, look.floorEdge); + rect(ctx, 0, FY + 2.6, W, 0.16, look.floorEdge); + // The exit at the right end: an arched door in its frame, a thin gold line round it. + arch(ctx, 82.4, FY - 15.2, 9.6, 15.2, look.shelf); + arch(ctx, 83.2, FY - 14.4, 8, 14.4, "#0e0806"); + faint(ctx, 0.25 + 0.15 * Math.sin(t / 500), () => { + rect(ctx, 83.2, FY - 0.5, 8, 0.5, "#fbbf24"); + rect(ctx, 86.9, FY - 14.4, 0.4, 14.4, "#fbbf24"); + }); + rect(ctx, 89.2, FY - 7.4, 0.5, 1.4, "#c9a24a"); + // Candle sconces, the candle burned low, a warm pool on the wall. + [18, 38, 55, 76].forEach((sx, i) => { + const f = flick(i + 2, t); + faint(ctx, 0.035 * f, () => circle(ctx, sx, 11.5, 7, "#ffb84a")); + faint(ctx, 0.05 * f, () => circle(ctx, sx, 11.5, 3.4, "#ffb84a")); + rect(ctx, sx - 0.3, 12, 0.6, 2.4, "#3a2e16"); + rect(ctx, sx - 0.45, 10.6, 0.9, 1.5, "#b8ae94"); + flame(ctx, sx, 10.6, 1.7, t, sx, "#ffb84a"); + }); + // The far end of the hall sinks into the dark. + for (let i = 0; i < 8; i++) faint(ctx, 0.07, () => rect(ctx, 50 + i * 6, 0, W - 50 - i * 6, SCENE_H, "#050308")); + // YOU click the flashlight on at the left and its cone lights the hall. + const clickAt = 450; + const lit = smooth((t - clickAt) / 260); + const lens = hero(ctx, 10, FY + 1.3, 1.3, 1, { t, lit: t >= clickAt ? clamp(1 - (t - clickAt) / 500) : 0 }); + beam(ctx, lens, 78, 6.4, lit * (0.8 + 0.08 * Math.sin(t / 80)), "#fff3b0", 0.4); + if (t >= clickAt && t < clickAt + 200) faint(ctx, 0.25 * (1 - (t - clickAt) / 200), () => rect(ctx, 0, 0, W, SCENE_H, "#fffbe0")); + // Dark shapes far down the hall, their eyes opening one by one. + [[55, 1.15, "#ff3b30"], [66, 1.05, "#ffe14a"], [75, 1.2, "#ff3b30"]].forEach(([mx, ms, eye], i) => { + const sway = Math.sin(t / 700 + i * 2) * 0.9; + const open = smooth((t - 1200 - i * 600) / 400); + ghoulShape(ctx, mx + sway, FY + 1.1, ms, t, i, i === 2 ? 0.55 : 1); + if (open > 0) { + const bx = mx + sway - 0.2 * ms; + const by = FY + 1.1 - 4.6 * ms; + faint(ctx, open * 0.35, () => { + circle(ctx, bx - 0.5 * ms, by, 0.55 * ms, eye); + circle(ctx, bx + 0.5 * ms, by, 0.55 * ms, eye); + }); + faint(ctx, open, () => { + circle(ctx, bx - 0.5 * ms, by, 0.28 * ms, eye); + circle(ctx, bx + 0.5 * ms, by, 0.28 * ms, eye); + }); + } + }); + // The title, on a dark band so it reads over the windows. + faint(ctx, 0.6 * smooth((t - 2800) / 400), () => rect(ctx, 0, 3.4, W, 13, "#050308")); + const { size, xs } = titleLayout(FINALE_TITLE, 88); + const chars = [...FINALE_TITLE]; + const base = 3000; + for (let i = 0; i < chars.length; i++) { + if (chars[i] === " ") continue; + const at = t - base - i * 70; + const fall = dropAt(at); + p.label(ctx, chars[i], 48 + xs[i] + 0.3, 9.8 - fall * 15 + 0.5, size * 0.95, "rgba(0, 0, 0, 0.7)", "center"); + const landed = at >= 520; + if (at > -40) { + if (landed) faint(ctx, 0.25 + 0.2 * Math.sin(t / 280 - i * 0.5), () => p.label(ctx, chars[i], 48 + xs[i], 9.8, size * 1.1, pal.glow, "center")); + p.label(ctx, chars[i], 48 + xs[i], 9.8 - fall * 15 + (landed ? Math.sin(t / 260 - i * 0.6) * size * 0.04 : 0), size * 0.95, i % 2 ? "#fbbf24" : "#fff3c4", "center"); + } + } + // The flare as the last stinger lands. + const flare = t - 3900; + if (flare >= 0 && flare < 700) faint(ctx, 0.55 * (1 - flare / 700), () => rect(ctx, 0, 0, W, SCENE_H, "#fff3c4")); + }, +}; + +/* --------------------------------------------------------------- the page */ + +// The width of `text` as the label helper sets it (it must have just set the font), or a guess where a canvas cannot measure. +const widthOf = (ctx, text, size) => { + const m = typeof ctx.measureText === "function" ? ctx.measureText(text) : null; + return m && typeof m.width === "number" ? m.width : text.length * size * 0.58; +}; + +export function storyArt(d) { + const { label, GOLD, BONE, LOOKS } = d; + return function storyPage(ctx, v) { + const { round } = v; + const s = round.story; + if (!s) return; + const pg = PAGES[s.page]; + const t = s.ms; + const n = shown(pg, t, s.full); + const line = lineAt(pg, n); + const done = n >= pg.lines.reduce((c, l) => c + l.length, 0); + ctx.save(); + ctx.globalAlpha = 1; + rect(ctx, 0, 0, W, H, "#050308"); + // The scene, clipped to its top. + ctx.save(); + ctx.beginPath(); + ctx.rect(0, 0, W, SCENE_H); + ctx.clip(); + // grow(n, ms): 0 to 1 over ms from when line n starts typing (1 once the page is typed out). + const startOf = (i) => REVEAL_AT_MS + pg.lines.slice(0, i).reduce((c, l) => c + l.length, 0) * CHAR_MS; + const grow = (i, ms = 1200) => (s.full || done ? 1 : smooth((t - startOf(i)) / ms)); + SCENES[pg.scene](ctx, { t, pal: pg.pal, line, full: s.full || done, label, grow, look: LOOKS.hall }); + ctx.restore(); + ctx.globalAlpha = 1; + // A soft dark foot to the scene, and the band for the words. + for (let i = 0; i < 4; i++) faint(ctx, 0.12, () => rect(ctx, 0, SCENE_H - (i + 1) * 0.6, W, 0.6, "#050308")); + rect(ctx, 0, SCENE_H, W, H - SCENE_H, "#07050c"); + rect(ctx, 0, SCENE_H, W, 0.25, pg.pal.glow); + // The heading, fading in, with the page's dots and the skip hint along the top. + faint(ctx, clamp((t - 150) / 350), () => { + label(ctx, pg.chapter, W / 2, SCENE_H + 2.3, 2.1, pg.pal.a, "center", W - 8); + stroke(ctx, W / 2 - 14, SCENE_H + 4.1, W / 2 + 14, SCENE_H + 4.1, pg.pal.glow, 0.2); + }); + // The lines typing out. + const shownLines = typed(pg, n); + shownLines.forEach((text, i) => { + if (!text) return; + const size = TEXT_SIZE; + const full = pg.lines[i]; + label(ctx, "", 0, 0, size, BONE, "left"); + const x0 = W / 2 - widthOf(ctx, full, size) / 2; + const y = SCENE_H + 6.7 + i * 3.35; + label(ctx, text, x0, y, size, BONE, "left", W - 4); + if (i === line && !done) { + const w = widthOf(ctx, text, size); + faint(ctx, 0.5 + 0.5 * Math.sin(t / 110), () => rect(ctx, x0 + w + 0.3, y - 1, 0.7, 2, pg.pal.glow)); + } + }); + // The page dots, the skip hint and its bar. + PAGES.forEach((_, i) => circle(ctx, 3 + i * 2.2, 3, i === s.page ? 0.7 : 0.35, i === s.page ? pg.pal.glow : "rgba(255, 255, 255, 0.35)")); + faint(ctx, 0.85, () => label(ctx, SKIP_HINT.toUpperCase(), W - 3, 3, 1.5, BONE, "right", 40)); + if (s.hold >= 0) { + const k = clamp(s.hold / SKIP_HOLD_MS); + rect(ctx, W - 3 - 30, 4.9, 30, 0.7, "rgba(255, 255, 255, 0.2)"); + rect(ctx, W - 3 - 30, 4.9, 30 * k, 0.7, GOLD); + } + // The hint, pulsing once a press counts. + if (ready(s)) { + const last = s.page === PAGES.length - 1; + faint(ctx, 0.55 + 0.45 * Math.sin(t / 260), () => label(ctx, last ? LAST_HINT : STORY_HINT, W / 2, H - 1.5, 1.6, pg.pal.glow, "center", W - 6)); + } + // A fade up from black as each page opens. + if (t < 500) faint(ctx, 1 - t / 500, () => rect(ctx, 0, 0, W, H, "#000")); + ctx.restore(); + ctx.globalAlpha = 1; + }; +} +// The ms a page's typing ends, for the tests. +export { revealEnd }; diff --git a/src/web-console/public/activities/ghoul-story.js b/src/web-console/public/activities/ghoul-story.js new file mode 100644 index 0000000..f21cbfd --- /dev/null +++ b/src/web-console/public/activities/ghoul-story.js @@ -0,0 +1,216 @@ +// Plan2Code Web Console - Ghoul Rush's intro story: eight short pages shown after YOU start a run and before The Long Hall, the words as data and the rules (lockout, reveal, skip) as plain functions over a round. ghoul-story-draw.js draws the scenes; ghoul-sfx-story.js has the sounds; scripts/test-web-console-activities-ghoul-story.mjs checks it all. +// +// The lore bible lives in prototypes/Ghoul-Rush-TODO.md ("The game's intro +// story"): read it before you change a page or add a stage, so the story +// never contradicts a stage's intro card (ghoul-intros.js). In short: the house +// is MARROW MANOR, a hungry thing older than the valley that eats fright; it +// copies what it eats and builds it again INSIDE itself, so every place of horror +// (a village, a lake, a carnival) is a room, a whole world, within the house; YOU +// once switched a flashlight on in its hall and it flinched, so it called YOU back; the road +// behind YOU is gone, every door YOU pick is locked after YOU, and if YOU get +// out, it starves. +// +// Rules for the text: 2 to 4 lines a page, each at most MAX_LINE characters +// (the field is 96 units wide), always YOU (never the hero's name, "the player" +// or "the hero"), no em dash, US English, spooky-fun, one joke a page at most. +// +// A page: `id`, `scene` (the drawing's id in ghoul-story-draw.js), `chapter` +// (its heading), `pal` ({ sky, ground, a, glow }: the scene's colors and the +// heading's and halo's), `lines` and `cues` ([ms, tone, level, pitch] sounds +// timed from the page's start). +// +// KEEP THE STORY GENERIC: never name a stage, never give a count of stages, rooms, +// doors or keepers. More stages will come, and the story must stay true. +// +// The phase `story` (round.phase): round.story = { page, ms, full, arm, hold, +// cue }. `ms` is the page's clock (a pause holds it), `full` is whether a press +// has finished the typing, `arm` the earliest ms the next press counts, `hold` +// how long fire has been held (-1 when it is not), `cue` the next sound due. + +export const MAX_LINE = 60; +// A press counts only after a page has been up this long (a held key or a key's repeats never skip a page), and again a moment after a press finished the typing. +export const STORY_LOCK_MS = 600; +export const RELOCK_MS = 200; +// Fire held this long skips the whole story. +export const SKIP_HOLD_MS = 1000; +// The typing: it starts a little after the page fades in, then one character each CHAR_MS. +export const REVEAL_AT_MS = 450; +export const CHAR_MS = 26; +export const STORY_HINT = "Press any move key or fire to go on"; +export const LAST_HINT = "Press any move key or fire to enter the hall"; +export const SKIP_HINT = "Hold fire to skip the story"; +export const FINALE_TITLE = "THE RUN BEGINS"; + +const freeze = Object.freeze; +const page = (id, scene, chapter, pal, lines, cues) => freeze({ id, scene, chapter, pal: freeze(pal), lines: freeze(lines), cues: freeze(cues.map((c) => freeze(c))) }); + +export const PAGES = freeze([ + page("road", "road", "I. THE ROAD", { sky: "#0b1230", ground: "#06070f", a: "#bcd4ff", glow: "#7aa2ff" }, [ + "Midnight. YOU walk a road no map has ever admitted to.", + "Your flashlight is the friendliest thing for miles.", + "The road is not leading YOU. It is herding YOU.", + ], [[0, "ghoulStoryWind", 0.5, 1], [2800, "ghoulStoryBell", 0.3, 0.8], [4600, "ghoulStoryWind", 0.3, 0.85]]), + page("house", "house", "II. THE HOUSE ON THE HILL", { sky: "#160d2b", ground: "#08050f", a: "#e9d5ff", glow: "#c084fc" }, [ + "That is Marrow Manor, older than the valley under it.", + "Every window is lit. Nobody has paid the bill in a century.", + "It is not waiting for guests. It is waiting for YOU.", + ], [[0, "ghoulThunder", 0.4, 0.9], [1900, "ghoulStoryCrow", 0.3, 1], [3600, "ghoulStoryCreak", 0.3, 1]]), + page("hunger", "hunger", "III. WHAT MARROW EATS", { sky: "#1a0a0c", ground: "#0a0405", a: "#fecaca", glow: "#f87171" }, [ + "Marrow does not eat food. Marrow eats fright.", + "Every scream is a meal. Every shiver, a snack.", + "It was a cottage once, then it got a taste for it.", + "A scared guest is a fresh guest. YOU look very fresh.", + ], [[0, "ghoulStoryBeat", 0.5, 1], [2500, "ghoulStoryWhisper", 0.35, 1], [4300, "ghoulStoryBeat", 0.5, 0.95], [6000, "ghoulStoryGulp", 0.35, 1]]), + page("arms", "arms", "IV. A HOUSE WITH LONG ARMS", { sky: "#0e1a16", ground: "#05100c", a: "#d1fae5", glow: "#6ee7b7" }, [ + "Marrow is not only a house. It is a hunger with a roof.", + "Its shadow reaches farther than the road YOU walked.", + "Whatever it swallows, it keeps, and it builds inside.", + ], [[0, "ghoulStoryGulp", 0.4, 1], [1900, "ghoulStoryBeat", 0.4, 0.9], [3600, "ghoulStoryBell", 0.25, 1]]), + page("far", "far", "V. A WORLD INSIDE", { sky: "#14122e", ground: "#07061a", a: "#fde68a", glow: "#fbbf24" }, [ + "Peek through a window. The room is bigger than the house.", + "Marrow copies what it eats, then builds it again inside.", + "Whole villages in there. Even a carnival it never forgot.", + "None of it is real. All of it can still swallow YOU.", + ], [[0, "ghoulStoryKnock", 0.4, 1], [2300, "ghoulStoryBell", 0.3, 1.2], [4300, "ghoulStoryKnock", 0.35, 1.1], [6100, "ghoulStoryWind", 0.3, 1.3]]), + page("why", "why", "VI. WHY YOU", { sky: "#0a1620", ground: "#04080d", a: "#fff3b0", glow: "#fde047" }, [ + "On a dare, YOU once clicked a flashlight on in its hall.", + "Marrow flinched. Nothing had ever made it flinch.", + "Light shows a house for what it is: a draft with a mortgage.", + "It never forgot YOU. Every window has winked at YOU since.", + ], [[0, "ghoulStoryWhisper", 0.35, 0.8], [1500, "ghoulStoryClick", 0.5, 1], [3400, "ghoulStoryBeat", 0.35, 1.2], [5200, "ghoulStoryWhisper", 0.3, 1.2]]), + page("trap", "trap", "VII. NO WAY BACK", { sky: "#190a14", ground: "#0b0408", a: "#fbcfe8", glow: "#f472b6" }, [ + "Behind YOU, the road folds up like a napkin.", + "Door after door YOU pick, Marrow locks behind YOU.", + "A keeper in each room. The deeper YOU go, the worse.", + "Win, and every window goes dark. Marrow starves for good.", + ], [[0, "ghoulStoryLock", 0.5, 1], [1200, "ghoulStoryCreak", 0.3, 0.8], [3200, "ghoulStoryLock", 0.5, 0.85], [5200, "ghoulStoryLock", 0.5, 0.75]]), + page("begin", "begin", "VIII. THE LONG HALL", { sky: "#100c12", ground: "#281a14", a: "#e9ddf3", glow: "#c4a8dc" }, [ + "Ahead lies The Long Hall, candles lit, nobody home.", + "Far below it all, something enormous is still beating.", + "Switch on YOUR light. Let it flinch again.", + ], [[0, "ghoulStoryCreak", 0.4, 1], [2300, "ghoulStoryBeat", 0.5, 1], [3900, "ghoulStoryBegin", 0.8, 1]]), +]); + +// The characters on a page, and the ms its typing is done. +export const pageChars = (pg) => pg.lines.reduce((n, l) => n + l.length, 0); +export const revealEnd = (pg) => REVEAL_AT_MS + pageChars(pg) * CHAR_MS; + +// How many characters of the page (all its lines in a row) are showing `ms` in; `full` shows all. +export function shown(pg, ms, full = false) { + const total = pageChars(pg); + if (full) return total; + return Math.max(0, Math.min(total, Math.floor((ms - REVEAL_AT_MS) / CHAR_MS))); +} + +// The text showing on each line, given the characters showing in all. +export function typed(pg, count) { + let left = count; + return pg.lines.map((line) => { + const n = Math.max(0, Math.min(line.length, left)); + left -= line.length; + return line.slice(0, n); + }); +} + +// Which line the typing is on (the last one once it is done). +export function lineAt(pg, count) { + let left = count; + for (let i = 0; i < pg.lines.length; i++) { + if (left < pg.lines[i].length) return i; + left -= pg.lines[i].length; + } + return pg.lines.length - 1; +} + +// Whether a press would count right now (not before the lockout). +export const ready = (s) => s.ms >= Math.max(STORY_LOCK_MS, s.arm); + +/* ------------------------------------------------------------ the phase */ + +function showPage(round, at) { + const s = round.story; + s.page = at; + s.ms = 0; + s.full = false; + s.arm = 0; + s.cue = 0; + round.events.push({ type: "storyPage", page: at }); +} + +// Opens the story on its first page: the round waits behind it, the hall already set up. +export function beginStory(round) { + round.phase = "story"; + round.phaseMs = 0; + round.input.jump = 0; + round.story = { page: 0, ms: 0, full: false, arm: 0, hold: -1, cue: 0, shown: 0 }; + round.events.push({ type: "storyPage", page: 0 }); +} + +// Out of the story into The Long Hall: the room is announced now, as a round's first room always was. +export function endStory(round) { + round.story = null; + round.phase = "play"; + round.phaseMs = 0; + round.input.jump = 0; + round.events.push({ type: "storyEnd" }); + round.events.push({ type: "room", room: round.room || 1 }); +} + +// One slice of the story: the page's clock, its sounds and typing blips, and a fire key held long enough to skip it all. +export function stepStory(round, ms) { + const s = round.story; + if (!s) return; + const pg = PAGES[s.page]; + if (s.hold >= 0) { + s.hold += ms; + if (s.hold >= SKIP_HOLD_MS) { + endStory(round); + return; + } + } + s.ms += ms; + while (s.cue < pg.cues.length && pg.cues[s.cue][0] <= s.ms) { + const [, name, vol, rate] = pg.cues[s.cue++]; + round.events.push({ type: "storyTone", name, vol, rate }); + } + // A soft blip every third character typed. + const now = shown(pg, s.ms, s.full); + if (!s.full && Math.floor(now / 3) > Math.floor(s.shown / 3)) round.events.push({ type: "storyTone", name: "tickSoft", vol: 0.1, rate: 1.5 }); + s.shown = now; +} + +// A press (a move key, fire or a click): finishes the typing first, then turns the page, and the last page opens the hall. False when it does not count (too soon, or not in the story). +export function takeStory(round) { + const s = round.story; + if (round.phase !== "story" || !s || !ready(s)) return false; + const pg = PAGES[s.page]; + if (!s.full && s.ms < revealEnd(pg)) { + s.full = true; + s.arm = s.ms + RELOCK_MS; + return true; + } + if (s.page + 1 >= PAGES.length) endStory(round); + else showPage(round, s.page + 1); + return true; +} + +// Fire pressed (a fresh press starts the skip's clock and also counts as a press) or repeating (nothing). +export function pressStory(round, repeat) { + const s = round.story; + if (round.phase !== "story" || !s || repeat) return false; + s.hold = 0; + takeStory(round); + return true; +} + +// Fire let go: the skip's clock stops. +export function releaseStory(round) { + if (round.story) round.story.hold = -1; +} + +// The whole story at once. +export function skipStory(round) { + if (round.phase !== "story" || !round.story) return false; + endStory(round); + return true; +} diff --git a/src/web-console/public/activities/ghoul-tray-draw.js b/src/web-console/public/activities/ghoul-tray-draw.js new file mode 100644 index 0000000..6bbec08 --- /dev/null +++ b/src/web-console/public/activities/ghoul-tray-draw.js @@ -0,0 +1,930 @@ +// Plan2Code Web Console - Ghoul Rush's Servants' Back Stairs, its drawing: a rush down the back stairs and through the basement kitchens on a silver serving tray. A tiled wall of arches behind, a rail of hanging copper pots and ovens in the middle distance, steam and drifting flour, the shelves and stair flights the tray rides (a sheen of grease on the quick stretches), rolling pots and cutlery, hams and copper pans hanging from the ceiling, spectral cooks flinging dishes, silver domes and flying plates with a dessert, service bells for checkpoints, the dining table at the end, and the tray with Planny on it. +// +// ghoul-draw.js plugs it in. LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are plain +// data; trayArt(d) takes ghoul-draw.js's drawing helpers (`d`) and hands back the drawing by +// kind, so this file never reaches back into it. Drawn in room units, the way ghoul-draw.js +// draws: y counted down from the field's top, so a world height `y` is drawn at `FIELD_H - y`. +// The still layers' pit is dark under the whole ride, so the world is drawn by `moving` (every +// frame, over them); the ham and pans (lows), the tray itself, the flour in front and the +// glyphs that say what to do are drawn by `front`. No random numbers: everything comes from a +// hash. What the art reads off the rules (ghoul-tray.js): +// +// - the room: `spec.ride` ({ track, pots, lows [x0, x1, y, kind], cooks, domes, plates, grease, +// checks, finish }), `spec.ground` (the landing at the start and the dining table at the end). +// - `round.runner` (id "tray"; any other state is none of ours): `v`, `line` (-1 in the air), +// `check`, `done`, `served`, `domes` [taken], `plates` [caught], `cooks` [{ state "down" | "up" +// | "toss" | "spent" | "broken", t, dish: null | { x, y } }]. +// - Planny: `you.state`, `you.vy` (tilts the tray in the air), `you.ducking`, `you.x`, `you.y`. +// - events leave short-lived bits in the view's `fx` (`trayBits`, `trayLand`). + +const freeze = (o) => Object.freeze(o); +const TAU = Math.PI * 2; +const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x)); + +const pit = (o) => freeze({ pack: "tray", custom: true, noMoon: true, pit: "#0c0706", ...o }); +export const LOOKS = freeze({ + tray: pit({ wallTop: "#1a120e", wallLow: "#3a2a22", paper: "#4a3a30", wainscot: "#2c201a", floorTop: "#c9bfa6", floor: "#6a5a48", floorEdge: "#2a1e16", shelf: "#6a4a30", shelfTop: "#a8825a", window: "#ffd9a0", decor: "kitchen", color: "#e8c890", dark: 0.45 }), +}); + +// How each new kind sounds, by act (first drafts, in ghoul-sfx-tray.js). +export const VOICES = freeze({ + tray: freeze({ jump: "ghoulTrayJump", land: "ghoulTrayLand", launch: "ghoulTrayLaunch", duck: "ghoulTrayDuck", crash: "ghoulTrayCrash", check: "ghoulTrayCheck", finish: "ghoulTrayFinish" }), + traydome: freeze({ get: "ghoulTrayDome" }), + trayplate: freeze({ catch: "ghoulTrayPlate" }), + traycook: freeze({ up: "ghoulTrayCookUp", toss: "ghoulTrayToss", hit: "ghoulTrayCookHit" }), + traydish: freeze({ break: "ghoulTrayDishBreak" }), +}); + +// What each of the pack's events plays: [kind, act], once. +export const EVENT_VOICE = freeze({ + trayJump: ["tray", "jump"], + trayLand: ["tray", "land"], + trayLaunch: ["tray", "launch"], + trayDuck: ["tray", "duck"], + trayCrash: ["tray", "crash"], + trayCheck: ["tray", "check"], + trayFinish: ["tray", "finish"], + trayDome: ["traydome", "get"], + trayPlate: ["trayplate", "catch"], + trayCookUp: ["traycook", "up"], + trayToss: ["traycook", "toss"], + trayCookHit: ["traycook", "hit"], + trayDishBreak: ["traydish", "break"], +}); +export const LOSE_WORDS = freeze({ pot: "Tripped on a pot", cutlery: "Skewered by cutlery", ham: "Hit by a ham", pans: "Clonked by the pans", dish: "Hit by a dish", tumble: "Down the stairs" }); +export const LOSE_SOUNDS = freeze({ + pot: ["clank", 0.6, 0.8], + cutlery: ["clank", 0.5, 1.3], + ham: ["smash", 0.5, 0.8], + pans: ["clank", 0.6, 0.6], + dish: ["smash", 0.6, 1], + tumble: ["ghoulPitFall", 0.55, 0.9], +}); + +const FW = 96; +let FH = 54; +const COPPER = "#c8793a"; +const COPPER_D = "#8a4a22"; +const SILVER = "#dde3ee"; +const SILVER_D = "#9aa4b8"; +const CHINA = "#f4f1e8"; + +// A number in 0..1 from two integers, the same every time (no random draws). +const rnd = (a, b = 0) => { + let h = Math.imul((a | 0) + 0x9e37, 0x85ebca6b) ^ Math.imul((b | 0) + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +const poly = (c, pts) => { + c.beginPath(); + pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); + c.closePath(); +}; +const seg = (c, x0, y0, x1, y1) => { + c.beginPath(); + c.moveTo(x0, y0); + c.lineTo(x1, y1); + c.stroke(); +}; +const disc = (c, x, y, r) => { + c.beginPath(); + c.arc(x, y, r, 0, TAU); + c.fill(); +}; +// A vertical gradient, or its middle color on a context with none. +const vgrad = (c, y0, y1, stops) => { + const g = typeof c.createLinearGradient === "function" ? c.createLinearGradient(0, y0, 0, y1) : null; + if (!g || typeof g.addColorStop !== "function") return stops[stops.length >> 1][1]; + for (const [o, col] of stops) g.addColorStop(o, col); + return g; +}; +// A soft glow: a few stacked translucent discs (cheap, and the same on any context). +function glow(c, x, y, r, rgb, alpha) { + for (let k = 3; k >= 1; k--) { + c.fillStyle = `rgba(${rgb},${alpha * (0.14 + (3 - k) * 0.1)})`; + disc(c, x, y, (r * k) / 3); + } +} + +/* ------------------------------------------------------------ the track */ + +const yOn = (pts, x) => { + if (x <= pts[0][0]) return pts[0][1]; + let i = 0; + while (i < pts.length - 2 && x > pts[i + 1][0]) i++; + const [xa, ya] = pts[i]; + const [xb, yb] = pts[i + 1]; + if (x >= xb) return yb; + return ya + ((yb - ya) * (x - xa)) / (xb - xa); +}; +const heightAt = (R, x) => { + let best = null; + for (const pts of R.track) { + if (x < pts[0][0] || x > pts[pts.length - 1][0]) continue; + const y = yOn(pts, x); + if (best === null || y > best) best = y; + } + return best; +}; + +/* ------------------------------------------------------------ telegraphs */ + +// What to do about each obstacle, as a glyph that fades in ahead of it: DUCK for a ham or pans (an +// arrow down, amber), JUMP for a gap, a pot or cutlery (an arrow up, cyan), SHOOT for a cook (a +// ring, red; a jump over his dish works too). Domes and plates are rewards and get none. It all +// comes from the room's `ride` fields and where the tray is (no random numbers, no rules). +export const TELEGRAPH_SEE = 40; +export const TELEGRAPH_FULL = 30; +export const TELEGRAPH_WORDS = 3; +export const TELEGRAPH_ALPHA = 0.72; +export const ANSWERS = freeze({ gap: "JUMP", pot: "JUMP", cutlery: "JUMP", ham: "DUCK", pans: "DUCK", cook: "SHOOT" }); +export const ANSWER_COLORS = freeze({ JUMP: "#5fe3ff", DUCK: "#ffb02e", SHOOT: "#ff7a6a" }); + +const marks = new WeakMap(); +// Every obstacle that wants a glyph: { kind, lead (where it begins), x (its middle), up (height of +// the glyph's anchor), n (which of its kind), answer }, in the room's order. +export function telegraphMarks(R) { + if (marks.has(R)) return marks.get(R); + const out = []; + const count = {}; + const add = (kind, lead, x, up) => { + const n = count[kind] || 0; + count[kind] = n + 1; + out.push({ kind, lead, x, up, n, answer: ANSWERS[kind] }); + }; + for (let i = 0; i + 1 < R.track.length; i++) { + const a = R.track[i].at(-1)[0]; + const b = R.track[i + 1][0][0]; + add("gap", a, (a + b) / 2, Math.max(heightAt(R, a - 0.1) ?? 0, heightAt(R, b + 0.1) ?? 0) + 6.5); + } + for (const [x, , kind] of R.pots) add(kind ? "cutlery" : "pot", x, x, (heightAt(R, x) ?? 10) + 7); + for (const [x0, x1, y, kind] of R.lows) add(kind ? "pans" : "ham", x0 - 3.2, (x0 + x1) / 2, y + (kind ? 7 : 7.4)); + for (const [x] of R.cooks) add("cook", x - 40, x, (heightAt(R, x) ?? 10) + 9); + out.sort((p, q) => p.lead - q.lead); + marks.set(R, out); + return out; +} + +// The glyphs showing with the tray at `x`: { ...mark, alpha (0..1, before the pulse), words }. +export function telegraphs(R, x) { + const out = []; + for (const m of telegraphMarks(R)) { + const d = m.lead - x; + if (d > TELEGRAPH_SEE || d < -6) continue; + const alpha = Math.min(clamp((TELEGRAPH_SEE - d) / (TELEGRAPH_SEE - TELEGRAPH_FULL), 0, 1), clamp((d + 4) / 6, 0, 1)); + if (alpha > 0.01) out.push({ ...m, alpha, words: m.n < TELEGRAPH_WORDS }); + } + return out; +} + +/* --------------------------------------------------------------------- art */ + +export function trayArt(d) { + const { ellipse, say, label, GOLD } = d; + const ride = (v) => (v.spec && v.spec.ride && v.spec.ride.runner === "tray" ? v.spec.ride : null); + const state = (v) => (v.round && v.round.runner && v.round.runner.id === "tray" ? v.round.runner : null); + const worldY = (y) => FH - y; + const baseOf = (R, x, line) => worldY(heightAt(R, x) ?? 10); + + /* ------------------------------------------------------------- the room */ + + // The still layers only get the wall's color: the world is drawn by `moving`. + function backdrop(ctx, v, look, x0, x1) { + ctx.fillStyle = look.wallLow; + ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H); + } + // The landing at the top of the stairs (flagstones), and the dining table at the end (a long + // table under a white cloth, a runner of red along it). + function ground(ctx, v, look, a, b, top) { + const R = ride(v); + const y = v.g.FIELD_H - top; + if (R && a >= R.finish - 1) { + ctx.fillStyle = "#5a3a22"; + ctx.fillRect(a, y, b - a, top + 2); + ctx.fillStyle = "#f2efe6"; + ctx.fillRect(a, y, b - a, 1.1); + ctx.fillStyle = "#b2182b"; + ctx.fillRect(a, y + 0.1, b - a, 0.35); + ctx.fillStyle = "#d9d3c4"; + for (let x = a; x < b; x += 3.2) ctx.fillRect(x, y + 1.1, 1.4, Math.min(top, 5)); + return; + } + ctx.fillStyle = vgrad(ctx, y, y + top, [[0, "#c9bfa6"], [0.3, "#8f846c"], [1, "#2a2018"]]); + ctx.fillRect(a, y, b - a, top + 2); + ctx.strokeStyle = "rgba(20,14,8,0.4)"; + ctx.lineWidth = 0.1; + for (let x = a; x <= b; x += 4) seg(ctx, x, y, x, y + 3); + seg(ctx, a, y + 1.5, b, y + 1.5); + ctx.fillStyle = "#f2ead2"; + ctx.fillRect(a, y, b - a, 0.3); + } + function shelf() {} + + /* --------------------------------------------------------- the distance */ + + // The kitchen behind: warm dark, a wall of white tile with arches, a rail of hanging pots and + // ladles, brick ovens, drifting steam. Parallax tiles drawn straight, no layers cached. + function distance(ctx, cam, clock) { + ctx.fillStyle = vgrad(ctx, 0, FH, [[0, "#0e0908"], [0.5, "#241813"], [1, "#4a3426"]]); + ctx.fillRect(cam - 1, 0, FW + 2, FH); + // The tiled wall, a band of white tile lines, behind. + const wall = cam * 0.88; + ctx.fillStyle = "rgba(214,206,186,0.14)"; + ctx.fillRect(cam - 1, 12, FW + 2, 34); + ctx.strokeStyle = "rgba(230,222,200,0.12)"; + ctx.lineWidth = 0.1; + for (let r = 0; r < 9; r++) seg(ctx, cam - 1, 13 + r * 3.8, cam + FW + 1, 13 + r * 3.8); + for (let x = Math.floor(wall / 3.8) * 3.8; x < wall + FW + 4; x += 3.8) seg(ctx, x + cam - wall, 12, x + cam - wall, 46); + // Arches every 36 with a hanging lamp, slow. + const par = 0.82; + for (let k = Math.floor((cam * par - 10) / 36); k <= Math.floor((cam * par + FW + 10) / 36); k++) { + const ax = cam + (k * 36 - cam * par); + ctx.fillStyle = "rgba(10,6,4,0.55)"; + ctx.beginPath(); + ctx.moveTo(ax, 46); + ctx.lineTo(ax, 24); + ctx.arc(ax + 7, 24, 7, Math.PI, 0); + ctx.lineTo(ax + 14, 46); + ctx.closePath(); + ctx.fill(); + ctx.strokeStyle = "#5a4a3a"; + ctx.lineWidth = 0.5; + ctx.stroke(); + glow(ctx, ax + 7, 10 + rnd(k, 1) * 3, 6, "255,190,110", 0.5 + 0.1 * Math.sin(clock / 300 + k)); + } + // The rail of hanging pots and ladles in the middle distance. + const mid = 0.62; + ctx.strokeStyle = "#2a1e16"; + ctx.lineWidth = 0.5; + seg(ctx, cam - 1, 9, cam + FW + 1, 9); + for (let k = Math.floor((cam * mid - 4) / 11); k <= Math.floor((cam * mid + FW + 4) / 11); k++) { + const px = cam + (k * 11 - cam * mid); + const drop = 3 + rnd(k, 2) * 5; + const kind = Math.floor(rnd(k, 3) * 3); + ctx.strokeStyle = "#2a1e16"; + ctx.lineWidth = 0.18; + seg(ctx, px, 9, px, 9 + drop); + ctx.fillStyle = kind === 2 ? SILVER_D : COPPER_D; + if (kind === 0) { + ctx.fillRect(px - 1.5, 9 + drop, 3, 2.4); + ctx.fillStyle = "rgba(255,200,140,0.3)"; + ctx.fillRect(px - 1.2, 9 + drop + 0.2, 0.5, 2); + } else if (kind === 1) { + disc(ctx, px, 9 + drop + 1.6, 1.7); + ctx.fillStyle = "#1a120c"; + disc(ctx, px, 9 + drop + 1.6, 0.9); + } else { + ctx.fillRect(px - 0.2, 9 + drop, 0.4, 3.4); + disc(ctx, px, 9 + drop + 3.6, 0.9); + } + } + // Steam, rising and fading. + for (let k = 0; k < 14; k++) { + const p = (clock / (3200 + (k % 5) * 400) + rnd(k, 7)) % 1; + const sx = cam + ((((rnd(k, 8) * 120 - cam * 0.5) % 120) + 120) % 120) - 12 - p * 4; + ctx.fillStyle = `rgba(235,235,230,${0.16 * (1 - p)})`; + disc(ctx, sx, FH - 8 - p * 34, 2 + p * 4); + } + } + + /* ------------------------------------------------------------ the track */ + + // The shelves and stair flights of every line in view: a wooden fill down to the bottom, a + // pale rim, plank lines and brackets on the shelves, step noses and risers on the flights, and + // a ragged lip at each line's end over the dark gap. + function paintTrack(ctx, R, lo, hi, clock) { + for (const pts of R.track) { + if (pts[pts.length - 1][0] < lo || pts[0][0] > hi) continue; + const top = pts.map(([x, y]) => [x, FH - y]); + ctx.fillStyle = vgrad(ctx, FH - 40, FH, [[0, "#6a4a30"], [0.6, "#3a281c"], [1, "#150e0a"]]); + poly(ctx, [...top, [pts.at(-1)[0], FH + 1], [pts[0][0], FH + 1]]); + ctx.fill(); + for (let i = 0; i + 1 < pts.length; i++) { + const [xa, ya] = pts[i]; + const [xb, yb] = pts[i + 1]; + if (xb < lo || xa > hi) continue; + const slope = (yb - ya) / (xb - xa); + if (slope < -0.08) { + // Stairs: a nose every 2.2 across with a dark riser under it. + for (let x = xa; x < xb; x += 2.2) { + const y = FH - yOn(pts, x); + ctx.fillStyle = "#c9a878"; + ctx.fillRect(x, y, 2.2, 0.35); + ctx.fillStyle = "rgba(10,6,4,0.55)"; + poly(ctx, [[x, y + 0.35], [x + 2.2, y + 0.35 + 0.37 * 2.2 * 0.5], [x, y + 0.35 + 0.9]]); + ctx.fill(); + } + } else { + // A shelf: a pale board, plank joins, brackets underneath, and a jar here and there. + ctx.fillStyle = "#a8825a"; + poly(ctx, [[xa, FH - ya], [xb, FH - yb], [xb, FH - yb + 0.9], [xa, FH - ya + 0.9]]); + ctx.fill(); + ctx.fillStyle = "#e0c08c"; + poly(ctx, [[xa, FH - ya], [xb, FH - yb], [xb, FH - yb + 0.25], [xa, FH - ya + 0.25]]); + ctx.fill(); + ctx.strokeStyle = "rgba(30,18,10,0.5)"; + ctx.lineWidth = 0.1; + for (let x = Math.ceil(xa / 9) * 9; x < xb; x += 9) seg(ctx, x, FH - yOn(pts, x), x, FH - yOn(pts, x) + 0.9); + for (let x = Math.ceil(xa / 14) * 14; x < xb; x += 14) { + const y = FH - yOn(pts, x); + ctx.strokeStyle = "#2a1e16"; + ctx.lineWidth = 0.3; + seg(ctx, x, y + 0.9, x - 1.6, y + 3.4); + } + } + } + // The ragged lip at the end of the line, over the gap. + const [ex, ey] = pts[pts.length - 1]; + ctx.fillStyle = "#2a1e16"; + poly(ctx, [[ex, FH - ey], [ex + 0.5, FH - ey + 1.6], [ex - 0.4, FH - ey + 2.6], [ex, FH - ey + 4]]); + ctx.fill(); + } + // The grease: a sheen on the quick stretches, with a glint that slides along. + for (const [a, b] of R.grease) { + if (b < lo || a > hi) continue; + for (let x = Math.max(a, lo); x < Math.min(b, hi); x += 1) { + const y = FH - (heightAt(R, x) ?? 10); + ctx.fillStyle = "rgba(255,226,120,0.5)"; + ctx.fillRect(x, y - 0.05, 1.05, 0.38); + } + const gx = a + (((clock / 14) % (b - a + 12)) - 6); + if (gx > a && gx < b) { + ctx.fillStyle = "rgba(255,255,230,0.8)"; + ctx.fillRect(gx, FH - (heightAt(R, gx) ?? 10) - 0.05, 3, 0.4); + } + } + } + + /* ------------------------------------------------------------ the things */ + + // A service bell on a post: red until passed, then green. + function checkpoint(ctx, v, x, base, on, i) { + ctx.strokeStyle = "#2a1e16"; + ctx.lineWidth = 0.35; + seg(ctx, x, base + 0.2, x, base - 4.4); + ctx.fillStyle = on ? "#bff0c8" : SILVER; + ctx.beginPath(); + ctx.arc(x, base - 4.4, 1.5, Math.PI, 0); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = SILVER_D; + ctx.fillRect(x - 1.8, base - 4.5, 3.6, 0.3); + disc(ctx, x, base - 6, 0.3); + const pulse = on ? 1 : 0.7 + 0.3 * Math.sin(v.clock / 160 + i); + glow(ctx, x, base - 5, 3.6, on ? "90,240,130" : "255,70,50", 0.7 * pulse); + } + + // A rolling pot: a copper stockpot on its side with a handle, wobbling; or a heap of dropped cutlery. + function pot(ctx, v, x, base, kind, i) { + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ellipse(ctx, x, base + 0.1, kind ? 2.8 : 1.9, 0.3); + ctx.fill(); + if (kind) { + ctx.lineCap = "round"; + for (let k = 0; k < 7; k++) { + const a = -0.5 + k * 0.17 + (rnd(i, k) - 0.5) * 0.3; + ctx.strokeStyle = k % 2 ? SILVER : SILVER_D; + ctx.lineWidth = 0.22; + const bx = x - 2 + k * 0.65; + seg(ctx, bx, base, bx + Math.sin(a) * 2.2, base - 1.2 - Math.abs(Math.cos(a)) * 0.5); + ctx.fillStyle = SILVER; + disc(ctx, bx + Math.sin(a) * 2.2, base - 1.4, 0.3); + } + ctx.lineCap = "butt"; + return; + } + ctx.save(); + ctx.translate(x, base - 1.4); + ctx.rotate(Math.sin(v.clock / 140 + i) * 0.12); + ctx.fillStyle = COPPER; + ctx.fillRect(-1.4, -1.4, 2.8, 2.8); + ctx.fillStyle = COPPER_D; + ctx.fillRect(-1.4, 0.7, 2.8, 0.7); + ctx.fillStyle = "rgba(255,220,170,0.55)"; + ctx.fillRect(-1.1, -1.2, 0.5, 2.2); + ctx.fillStyle = "#1a120c"; + ellipse(ctx, 1.4, 0, 0.3, 1.2); + ctx.fill(); + ctx.strokeStyle = "#2a1e16"; + ctx.lineWidth = 0.28; + seg(ctx, -1.4, -0.4, -2.6, -0.8); + ctx.restore(); + } + + // A silver dome (a cloche) on its plate, a handle ball on top, a shine; gone once run through. + function dome(ctx, v, x, y, i) { + const bob = Math.sin(v.clock / 300 + i * 1.7) * 0.25; + ctx.save(); + ctx.translate(x, y + bob); + glow(ctx, 0, -1.4, 3.2, "230,240,255", 0.45); + ctx.fillStyle = SILVER_D; + ellipse(ctx, 0, -0.15, 1.9, 0.3); + ctx.fill(); + ctx.fillStyle = vgrad(ctx, -2.4, 0, [[0, "#ffffff"], [0.5, SILVER], [1, SILVER_D]]); + ctx.beginPath(); + ctx.moveTo(-1.6, -0.2); + ctx.arc(0, -0.2, 1.6, Math.PI, 0); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = SILVER; + disc(ctx, 0, -2.0, 0.28); + ctx.fillStyle = "rgba(255,255,255,0.8)"; + ellipse(ctx, -0.6, -1.1, 0.3, 0.55, -0.5); + ctx.fill(); + ctx.restore(); + } + + // A flying plate with a dessert (a little cake and a cherry), turning end over end a little. + function plate(ctx, v, x, y, i) { + const t = v.clock / 160 + i * 2.1; + const bob = Math.sin(v.clock / 260 + i) * 0.35; + ctx.save(); + ctx.translate(x, y + bob); + glow(ctx, 0, 0, 3.6, "255,200,220", 0.4); + ctx.rotate(Math.sin(t) * 0.35); + ctx.fillStyle = CHINA; + ellipse(ctx, 0, 0.5, 1.7, 0.4); + ctx.fill(); + ctx.strokeStyle = "#5a7ac8"; + ctx.lineWidth = 0.1; + ellipse(ctx, 0, 0.5, 1.3, 0.28); + ctx.stroke(); + ctx.fillStyle = "#8a5a3a"; + ctx.fillRect(-0.7, -0.5, 1.4, 0.9); + ctx.fillStyle = "#ffd0e0"; + ctx.fillRect(-0.7, -0.75, 1.4, 0.35); + ctx.fillStyle = "#d4162e"; + disc(ctx, 0, -1.05, 0.34); + ctx.restore(); + } + + // A spectral cook: a pale, see-through chef with a tall hat and a dark glowing eye, a plate in his raised hand while he winds up, flung forward after. + function cook(ctx, v, x, base, o, i) { + if (o.state === "down" || o.state === "spent") return; + const clock = v.clock; + if (o.state === "broken") return; + const wind = o.state === "up" ? clamp(1 - o.t / 700, 0, 1) : 1; + const rise = o.state === "up" ? Math.min(1, (700 - o.t) / 160) : 1; + ctx.save(); + ctx.translate(x, base + (1 - rise) * 4); + ctx.globalAlpha = 0.7 + 0.15 * Math.sin(clock / 180 + i); + glow(ctx, 0, -3, 5, "170,220,255", 0.4); + ctx.fillStyle = "#cfe3f0"; + // The body: an apron over a rounded coat. + poly(ctx, [[-1.6, 0], [-1.3, -3.4], [1.3, -3.4], [1.6, 0]]); + ctx.fill(); + ctx.fillStyle = "#f4f8fc"; + ctx.fillRect(-1, -2.6, 2, 2.6); + ctx.fillStyle = "#cfe3f0"; + disc(ctx, 0, -4.1, 1.05); + // The hat. + ctx.fillStyle = "#f4f8fc"; + ctx.fillRect(-0.9, -5.3, 1.8, 0.7); + disc(ctx, -0.6, -5.7, 0.8); + disc(ctx, 0.6, -5.7, 0.8); + disc(ctx, 0, -6.1, 0.9); + // The eyes and a hungry mouth. + ctx.fillStyle = "#101820"; + disc(ctx, -0.35, -4.2, 0.2); + disc(ctx, 0.35, -4.2, 0.2); + ctx.fillRect(-0.45, -3.7, 0.9, 0.18); + // The arm: up with a plate while winding, then out toward the tray. + ctx.strokeStyle = "#cfe3f0"; + ctx.lineWidth = 0.5; + ctx.lineCap = "round"; + const ax = o.state === "toss" ? -2.8 : -1.6 - wind * 0.4; + const ay = o.state === "toss" ? -3.1 : -3 - wind * 2.2; + seg(ctx, -1.2, -3, ax, ay); + ctx.lineCap = "butt"; + if (o.state === "up") { + ctx.fillStyle = CHINA; + ellipse(ctx, ax, ay - 0.3, 1.3, 0.3); + ctx.fill(); + } + ctx.restore(); + } + + // A dish in flight, spinning, toward the tray. + function dish(ctx, v, dd, i) { + ctx.save(); + ctx.translate(dd.x, worldY(dd.y) - 0.7); + glow(ctx, 0, 0, 2.6, "255,235,200", 0.35); + ctx.fillStyle = CHINA; + ellipse(ctx, 0, 0, 1.1, 0.25 + 0.5 * Math.abs(Math.sin(v.clock / 70 + i))); + ctx.fill(); + ctx.strokeStyle = "#5a7ac8"; + ctx.lineWidth = 0.08; + ellipse(ctx, 0, 0, 0.8, 0.15 + 0.35 * Math.abs(Math.sin(v.clock / 70 + i))); + ctx.stroke(); + ctx.restore(); + } + + // The dining table's banner over the door: LAST ORDERS, lit. + function banner(ctx, v, x) { + ctx.strokeStyle = "#2a1e16"; + ctx.lineWidth = 0.4; + seg(ctx, x - 14, FH - 30, x + 20, FH - 30); + ctx.fillStyle = "#7a1426"; + poly(ctx, [[x - 12, FH - 30], [x + 18, FH - 30], [x + 18, FH - 23], [x + 3, FH - 21], [x - 12, FH - 23]]); + ctx.fill(); + label(ctx, "LAST ORDERS", x + 3, FH - 25.6, 3, "#ffd98a", "center"); + } + + /* ---------------------------------------------------------- the world */ + + function moving(ctx, v, cam) { + const R = ride(v); + const c = state(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + const clock = v.clock; + cam = Math.round(cam * 8) / 8; + distance(ctx, cam, clock); + const lo = cam - 8; + const hi = cam + FW + 8; + paintTrack(ctx, R, lo - 6, hi + 6, clock); + R.checks.forEach((x, i) => { + if (x > lo && x < hi) checkpoint(ctx, v, x, baseOf(R, x), i <= c.check, i); + }); + if (R.finish > lo - 24 && R.finish < hi) banner(ctx, v, R.finish + 28); + // The shadow of a ham or pans on the shelf beneath it. + for (const [x0, x1, , kind] of R.lows) { + if (x1 < lo || x0 > hi) continue; + ctx.fillStyle = `rgba(4,2,2,${kind ? 0.3 : 0.4})`; + ctx.fillRect(x0 - 0.5, baseOf(R, x0) - 0.1, x1 - x0 + 1, 0.5); + } + R.pots.forEach(([x, line, kind], i) => { + if (x > lo && x < hi) pot(ctx, v, x, baseOf(R, x, line), kind, i); + }); + R.cooks.forEach(([x, line], i) => { + const o = c.cooks[i]; + if (x > lo && x < hi) cook(ctx, v, x, baseOf(R, x, line), o, i); + if (o.dish) dish(ctx, v, o.dish, i); + }); + R.domes.forEach(([x, line, lift], i) => { + if (x > lo && x < hi && !c.domes[i]) dome(ctx, v, x, baseOf(R, x, line) - lift, i); + }); + R.plates.forEach(([x, line, lift], i) => { + if (x > lo && x < hi && !c.plates[i]) plate(ctx, v, x, baseOf(R, x, line) - lift - 1.4, i); + }); + // The dining table, over the sky (the still layers' was painted under it). + for (const [a, b, top] of v.spec.ground) if (a >= R.finish - 1 && b > lo && a < hi) ground(ctx, v, LOOKS.tray, a, b, top); + } + + /* ----------------------------------------------------- the tray, in front */ + + // The big silver tray, side on: a shallow oval with a raised rim, two handles, a shine and a dent; + // clattering on the stairs, scattering crumbs. Planny is drawn by the game over it. + function tray(ctx, v, R, c) { + const { round } = v; + const you = round.you; + const clock = v.clock; + const done = c.done; + const x = done && c.restX !== undefined ? c.restX : you.x; + const y = done ? (v.spec.ground.find(([a, b]) => x >= a && x <= b) || [0, 0, 10])[2] : you.y; + let pitch = 0; + if (!done) pitch = c.line >= 0 ? Math.atan2((heightAt(R, x + 3) ?? y) - (heightAt(R, x - 3) ?? y), 6) * 0.95 : clamp(you.vy / Math.max(14, c.v), -1, 1) * 0.5; + const shake = !done && c.line >= 0 ? Math.sin(clock / 29) * 0.04 * (c.v / 44) : 0; + ctx.save(); + ctx.translate(x, FH - y + shake); + ctx.rotate(-pitch); + // Sparks and crumbs off the rim, longer the faster it goes. + if (!done && c.line >= 0) { + for (let k = 0; k < 9; k++) { + const p = (clock / (300 + (k % 4) * 60) + k * 0.13) % 1; + ctx.fillStyle = `rgba(255,230,160,${(1 - p) * 0.8})`; + disc(ctx, -3.4 - p * (2.5 + (c.v / 44) * 3) * (0.6 + rnd(k, 1)), -0.1 - p * (0.8 + rnd(k, 2) * 1.6), 0.12 + (1 - p) * 0.16); + } + } + ctx.scale(1.12, 1.3); + ctx.fillStyle = "rgba(10,6,4,0.35)"; + ellipse(ctx, 0, 0.6, 3.9, 0.25); + ctx.fill(); + // The dish of the tray: a shallow silver bowl, a rim, a bright top. + ctx.fillStyle = vgrad(ctx, -0.6, 0.6, [[0, "#ffffff"], [0.4, SILVER], [1, SILVER_D]]); + ctx.beginPath(); + ctx.moveTo(-3.9, -0.3); + ctx.quadraticCurveTo(-3.6, 0.5, -2.4, 0.5); + ctx.lineTo(2.4, 0.5); + ctx.quadraticCurveTo(3.6, 0.5, 3.9, -0.3); + ctx.lineTo(3.3, -0.3); + ctx.lineTo(-3.3, -0.3); + ctx.closePath(); + ctx.fill(); + ctx.strokeStyle = "#7a8498"; + ctx.lineWidth = 0.1; + ctx.stroke(); + ctx.fillStyle = "#ffffff"; + ctx.fillRect(-3.6, -0.34, 7.2, 0.14); + // The handles at each end, and a few dents. + ctx.strokeStyle = SILVER_D; + ctx.lineWidth = 0.18; + ctx.beginPath(); + ctx.arc(-3.95, -0.1, 0.35, Math.PI * 1.5, Math.PI * 0.5, true); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(3.95, -0.1, 0.35, Math.PI * 1.5, Math.PI * 0.5, false); + ctx.stroke(); + ctx.fillStyle = "rgba(110,120,140,0.5)"; + ellipse(ctx, 1.6, 0.1, 0.35, 0.12); + ctx.fill(); + // A landing's puff of flour. + const fx = v.fx; + const land = fx && fx.trayLand !== undefined ? fx.clock - fx.trayLand.t0 : 1e9; + if (land < 380) { + for (let k = 0; k < 8; k++) { + const p = land / 380; + ctx.fillStyle = `rgba(250,246,236,${(1 - p) * 0.8})`; + disc(ctx, (k - 3.5) * 0.9 * (0.5 + p * 1.4), -0.3 - p * (1 + rnd(k, 4) * 1.6) * (fx.trayLand.big ? 1.6 : 1), 0.3 + p * 0.3); + } + } + ctx.restore(); + } + + // Hams on hooks, or a rack of copper pans, hanging from the ceiling over the track. + function low(ctx, v, x0, x1, y, kind, i) { + const clock = v.clock; + const under = worldY(y); + const xm = (x0 + x1) / 2; + if (kind === 0) { + // A rail with two hams swinging a little on ropes. + ctx.strokeStyle = "#2a1e16"; + ctx.lineWidth = 0.4; + seg(ctx, x0 - 1, 1.5, x1 + 1, 1.5); + for (const [h, px] of [[0, x0 + 1.8], [1, x1 - 1.8]]) { + const sw = Math.sin(clock / 380 + i * 1.3 + h * 1.9) * 0.5; + const len = under - 3.4 - 1.5; + ctx.strokeStyle = "#6a5030"; + ctx.lineWidth = 0.16; + seg(ctx, px, 1.5, px + sw, 1.5 + len); + ctx.save(); + ctx.translate(px + sw, 1.5 + len); + ctx.fillStyle = "#b8545a"; + ellipse(ctx, 0, 1.7, 1.5, 1.9); + ctx.fill(); + ctx.fillStyle = "#d98a8a"; + ellipse(ctx, -0.4, 1.2, 0.5, 0.9); + ctx.fill(); + ctx.fillStyle = "#e8dcc0"; + ctx.fillRect(-0.2, -0.4, 0.4, 0.9); + ctx.restore(); + } + } else { + // A rack with copper pans on ropes, their bases about the underside. + ctx.strokeStyle = "#2a1e16"; + ctx.lineWidth = 0.3; + seg(ctx, x0 - 1, 1.5, x0 - 1, under - 3.6); + seg(ctx, x1 + 1, 1.5, x1 + 1, under - 3.6); + ctx.lineWidth = 0.45; + seg(ctx, x0 - 1.4, under - 3.6, x1 + 1.4, under - 3.6); + const n = 4; + for (let k = 0; k < n; k++) { + const px = x0 + 0.6 + (k * (x1 - x0 - 1.2)) / (n - 1); + const sw = Math.sin(clock / 420 + i + k * 1.4) * 0.15; + ctx.strokeStyle = "#6a5030"; + ctx.lineWidth = 0.14; + seg(ctx, px, under - 3.6, px + sw, under - 2.8); + ctx.fillStyle = COPPER; + ctx.beginPath(); + ctx.arc(px + sw, under - 1.6, 1.2, 0, TAU); + ctx.fill(); + ctx.fillStyle = "#1a120c"; + disc(ctx, px + sw, under - 1.6, 0.8); + ctx.fillStyle = COPPER_D; + ctx.fillRect(px + sw - 0.2, under - 0.4, 0.4, 0.4); + } + } + ctx.globalAlpha = 0.4 + 0.15 * Math.sin(clock / 400 + i); + glow(ctx, xm, under + 0.2, 4, "255,200,130", 0.4); + ctx.globalAlpha = 1; + } + + // A see-through glyph over an obstacle: a pair of chevrons (a ring for a cook) and, for the first few, the word. + function glyph(ctx, v, t) { + const up = t.answer === "JUMP"; + const col = ANSWER_COLORS[t.answer]; + const pulse = 0.85 + 0.15 * Math.sin(v.clock / 260 + t.lead); + const cy = Math.min(FH - 7, FH - t.up) + Math.sin(v.clock / 260 + t.lead) * 0.35; + ctx.save(); + ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA; + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + if (t.answer === "SHOOT") { + for (const [w, c] of [[1.2, "rgba(8,4,4,0.8)"], [0.5, col]]) { + ctx.strokeStyle = c; + ctx.lineWidth = w; + ctx.beginPath(); + ctx.arc(t.x, cy - 2.2, 1.4, 0, TAU); + ctx.stroke(); + seg(ctx, t.x - 2.2, cy - 2.2, t.x + 2.2, cy - 2.2); + seg(ctx, t.x, cy - 4.4, t.x, cy); + } + } else { + const dir = up ? -1 : 1; + const ay = cy + (up ? -2.6 : 2.6); + for (const [w, c] of [[1.3, "rgba(8,4,4,0.8)"], [0.6, col]]) { + ctx.strokeStyle = c; + ctx.lineWidth = w; + for (let k = 0; k < 2; k++) { + const oy = ay + (k - 0.5) * 1.5 * dir - dir * 0.2; + ctx.beginPath(); + ctx.moveTo(t.x - 1.7, oy - dir * 0.9); + ctx.lineTo(t.x, oy + dir * 0.9); + ctx.lineTo(t.x + 1.7, oy - dir * 0.9); + ctx.stroke(); + } + } + } + if (t.words) label(ctx, t.answer, t.x, cy + (up || t.answer === "SHOOT" ? 1.2 : -1.2), 2.3, col, "center"); + ctx.restore(); + } + + function front(ctx, v) { + const R = ride(v); + const round = v.round; + const c = state(v); + if (!R || !c) return; + FH = v.g.FIELD_H; + const cam = Math.round(round.camX * 8) / 8; + const lo = cam - 8; + const hi = cam + FW + 8; + tray(ctx, v, R, c); + R.lows.forEach(([x0, x1, y, kind], i) => { + if (x1 >= lo && x0 <= hi) low(ctx, v, x0, x1, y, kind, i); + }); + // Clouds of flour drifting over the route, here and there: they dim the view, never hide a glyph. + for (let n = Math.max(0, Math.floor((cam - 40) / 230)); n <= Math.floor((cam + FW + 40) / 230); n++) { + const bx = 140 + n * 230; + for (let k = 0; k < 5; k++) { + const px = bx + (rnd(n, k) - 0.3) * 26 + Math.sin(v.clock / 900 + k + n) * 1.5; + if (px < lo - 10 || px > hi + 10) continue; + const py = FH - (heightAt(R, px) ?? 20) - 2 - rnd(n, k + 9) * 5; + ctx.fillStyle = `rgba(246,240,226,${0.1 + 0.05 * rnd(n, k + 3)})`; + disc(ctx, px, py, 3 + rnd(n, k + 5) * 4); + } + } + if (!c.done) for (const t of telegraphs(R, round.you.x)) glyph(ctx, v, t); + // Splinters of china and tin from a broken dish or a cook, tumbling. + const bits = v.fx && v.fx.trayBits; + if (bits) { + for (const b of bits) { + const t = (v.fx.clock - b.t0) / 1000; + if (t < 0 || t > 0.9) continue; + ctx.save(); + ctx.translate(b.x + b.vx * t, FH - (b.y + b.vy * t - 30 * t * t)); + ctx.rotate(b.rot + b.vr * t); + ctx.globalAlpha = clamp(1.6 - t * 1.6, 0, 1); + ctx.fillStyle = b.c; + ctx.fillRect(-b.w / 2, -0.12, b.w, 0.24); + ctx.restore(); + } + ctx.globalAlpha = 1; + } + // The course count, a small plate of dots under the hearts' pill: one per course, a gold one for each eaten. + if (!c.done && round.phase === "play") { + const goal = 7; + for (let k = 0; k < goal; k++) { + const x = cam + FW / 2 - (goal * 2.2) / 2 + k * 2.2 + 1.1; + ctx.fillStyle = k < c.served ? "#ffd24a" : "rgba(220,220,230,0.28)"; + disc(ctx, x, 8.6, 0.8); + ctx.strokeStyle = "rgba(20,12,8,0.6)"; + ctx.lineWidth = 0.12; + ctx.beginPath(); + ctx.arc(x, 8.6, 0.8, 0, TAU); + ctx.stroke(); + } + } + } + + const dim = () => 0; + + /* -------------------------------------------------------------- lights */ + + function lights(v, add) { + const R = ride(v); + const round = v.round; + const c = state(v); + if (!R || !c) return; + const you = round.you; + const clock = v.clock; + const lo = round.camX - 10; + const hi = round.camX + FW + 10; + add(you.x + 2, you.y + 2.4, 10, 0.6); + R.checks.forEach((x, i) => { + if (x > lo && x < hi) add(x, (heightAt(R, x) ?? 10) + 5, i <= c.check ? 8 : 7, i <= c.check ? 0.6 : 0.5); + }); + R.domes.forEach(([x, line, lift], i) => { + if (x > lo && x < hi && !c.domes[i]) add(x, (heightAt(R, x) ?? 10) + lift + 1.5, 4, 0.3); + }); + R.plates.forEach(([x, line, lift], i) => { + if (x > lo && x < hi && !c.plates[i]) add(x, (heightAt(R, x) ?? 10) + lift + 1.4, 4, 0.3); + }); + R.cooks.forEach(([x], i) => { + if (x > lo && x < hi && (c.cooks[i].state === "up" || c.cooks[i].state === "toss")) add(x, (heightAt(R, x) ?? 10) + 3, 5, 0.3); + }); + R.lows.forEach(([x0, x1, y], i) => { + if (x1 > lo && x0 < hi) add((x0 + x1) / 2, y + 1, 6, 0.3 * (0.85 + 0.15 * Math.sin(clock / 200 + i))); + }); + if (R.finish > lo - 24 && R.finish < hi) add(R.finish + 28, 22, 16, 0.6); + if (v.fx && v.fx.trayLand && v.fx.clock - v.fx.trayLand.t0 < 260) add(you.x, you.y + 1, 6, 0.4); + } + + /* -------------------------------------------------------------- events */ + + // A throttle on a repeating cue. + function gateOnce(fx, key, ms) { + if ((fx[key] || 0) > fx.clock) return false; + fx[key] = fx.clock + ms; + return true; + } + // China and tin flying out of a spot. + function splinter(fx, x, y, colors) { + fx.trayBits = (fx.trayBits || []).filter((b) => fx.clock - b.t0 < 1000); + for (let k = 0; k < 9; k++) fx.trayBits.push({ x, y, t0: fx.clock, vx: (rnd(k, 1) - 0.5) * 22, vy: 8 + rnd(k, 2) * 14, rot: rnd(k, 3) * TAU, vr: (rnd(k, 4) - 0.5) * 22, w: 0.5 + rnd(k, 5) * 0.9, c: colors[k % colors.length] }); + } + + // What the pack's events look and sound like; true when the event is its own. Each of its + // sounds plays once, from EVENT_VOICE. + function react(e, k) { + const { shake, flash, burst, float, ring, fx, tone } = k; + const voice = EVENT_VOICE[e.type]; + if (!voice) return false; + if (e.type === "trayDuck" && !gateOnce(fx, "trayDuckMs", 160)) return true; + say(tone, voice[0], voice[1], 0.5); + switch (e.type) { + case "trayJump": + burst(e.x, e.y, CHINA, 5, 7, 300); + break; + case "trayLand": + fx.trayLand = { t0: fx.clock, big: Boolean(e.big) }; + burst(e.x, e.y, SILVER, e.big ? 14 : 6, e.big ? 12 : 8, 360); + if (e.big) shake(200, 0.5); + break; + case "trayLaunch": + burst(e.x, e.y, SILVER, 12, 14, 380); + float(e.x, e.y + 5, e.last ? "Jump!" : "Whee!", GOLD, 2.2); + break; + case "trayCrash": + shake(320, 1); + flash("#ffe2b0", 200); + burst(e.x, e.y + 1, e.what === "pot" || e.what === "pans" ? COPPER : SILVER, 18, 17, 520); + burst(e.x, e.y + 1, "#f4f1e8", 8, 14, 360); + break; + case "trayCheck": + float(e.x, e.y + 5, "Checkpoint", GOLD, 2.2); + ring(e.x, e.y + 3, "#7dffa0", 1, 8, 500); + break; + case "trayFinish": + shake(260, 0.7); + burst(e.x, e.y, CHINA, e.big ? 22 : 14, 13, 560); + float(e.x, e.y + 5, e.served >= 7 ? "Seven courses!" : "Made it!", GOLD, 2.6); + break; + case "trayDome": + burst(e.x, e.y, SILVER, 10, 10, 420); + ring(e.x, e.y, "#cfe6ff", 1, 6, 400); + float(e.x, e.y + 3, `Course ${e.n}`, GOLD, 2); + break; + case "trayPlate": + burst(e.x, e.y, "#ffd0e0", 12, 12, 460); + splinter(fx, e.x, e.y, [CHINA, "#5a7ac8", "#ffd0e0"]); + float(e.x, e.y + 3, `Course ${e.n}`, GOLD, 2); + break; + case "trayCookUp": + burst(e.x, e.y + 1, "#cfe3f0", 6, 6, 400); + break; + case "trayToss": + burst(e.x, e.y, CHINA, 4, 6, 260); + break; + case "trayCookHit": + burst(e.x, e.y, "#cfe3f0", 14, 14, 480); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + case "trayDishBreak": + burst(e.x, e.y, CHINA, 10, 12, 380); + splinter(fx, e.x, e.y, [CHINA, "#5a7ac8"]); + break; + default: + break; + } + return true; + } + + return freeze({ + looks: LOOKS, + backdrop, + ground, + shelf, + front, + moving, + dim, + monsters: freeze({}), + bosses: freeze({}), + missiles: freeze({}), + hazards: freeze({}), + powers: freeze({}), + lights, + react, + }); +} diff --git a/src/web-console/public/activities/ghoul-tray.js b/src/web-console/public/activities/ghoul-tray.js new file mode 100644 index 0000000..3ae8a15 --- /dev/null +++ b/src/web-console/public/activities/ghoul-tray.js @@ -0,0 +1,496 @@ +// Plan2Code Web Console - Ghoul Rush's Servants' Back Stairs, its rules: the East Wing's bonus round. YOU ride a huge silver serving tray down the cramped back stairs and through the steamy basement kitchens in one long clattering rush: jump the rolling pots, dropped cutlery and the gaps between flights, duck the swinging hams and hanging copper pans, shoot (or jump) the dishes the spectral cooks fling, and eat your way through the courses on the route, as a stage pack that ghoul.js plugs in. +// +// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it, handed a +// kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js (it borrows the +// Cart's track helpers). Pack fields used: `ride` (a hook that moves Planny himself, so no +// key walks him), `place` (Planny put down in a room) and `target` (a bolt strikes something +// that is no monster: the plates, the cooks and their dishes). It adds no monster, boss or +// hazard kind and draws NO random number. Its state is `round.runner` (the shared slot for a +// rolling bonus ride, with `id: "tray"`), and the room's `ride.runner` is "tray". +// +// THE ROOM (spec.ride, see ghoul-rooms.js): +// +// - `track`: polylines [x, y] the tray slides along (the sled's: a gap between two lines is a +// crack to jump, cause "tumble"). The route is 17 laps of a climb onto a pantry shelf (+0.28), +// a flat run along it and a flight of back stairs down (-0.17), each lap a little lower than +// the last; a gap between two lines is the gap between two flights. The last line ends on a +// rising lip (over RAMP_SLOPE) that launches the tray onto the dining table at `finish`. +// - `pots` [x, line, kind] (a rolling pot, kind 0, or a drop of cutlery, kind 1: POT_W by POT_H +// or CUTLERY_W by CUTLERY_H, JUMP), `lows` [x0, x1, y, kind] (a swinging ham, kind 0, or +// hanging copper pans, kind 1: the underside is y, to the roof, so DUCK it: 3.0 over the +// highest track under it), `cooks` [x, line] (a spectral cook who, when the tray is COOK_NEAR +// short of him, winds up COOK_WIND_MS and flings a dish that flies left at DISH_V at +// DISH_LO up: JUMP it, or shoot the cook, one bolt, or the dish itself), +// `domes` [x, line, lift] (a silver dome, DOME_W by DOME_H, lift over the track: run through +// it, a high one takes a jump), `plates` [x, line, lift] (a flying plate with a dessert, +// PLATE_W by PLATE_H: SHOOT it to catch the dessert), `grease` [x0, x1] (flat stretches +// where the tray picks up to GREASE_V), `checks`, `finish` and `time`. The room's `candy` are +// the cherries along the route. +// +// THE TWIST (the courses): every dome run through and every plate shot is a course +// (`round.runner.served`); SEVEN (COURSES_GOAL) is a full seven course meal and the grade's +// "acts" die. The cherries taken are the other die (CHERRY_SHARE of them: `perf.steady`). So +// the best ride is a hungry, aggressive one: jumping for the high domes, shooting plates on +// the way, over greased stretches that come quicker than the rest. +// +// THE TRAY (`round.runner`): { id, room, v, line, coyote, from, left, check, done, served, +// domes, plates, cooks, cherries, ... }. Planny rides at (you.x, you.y), always facing right. +// Speed `v` relaxes to TRAY_V (GREASE_V on a grease stretch) and is pushed by the slope +// (SLOPE_G), between TRAY_MIN and TRAY_MAX. Up jumps (TRAY_JUMP_V against TRAY_G: about 13 +// high, 0.75 s, 33 across at TRAY_V), COYOTE_MS of grace; down ducks. A bolt flies parallel +// to the track (`s.off` keeps what he aimed). +// +// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life; the tray rolls on, +// Planny blinking safe BONUS_SAFE_MS; the last heart gone ends the round with nothing. Causes: +// "pot", "cutlery", "ham", "pans", "dish", "tumble" (a fall). Every obstacle is a number for +// the grade (`perf.total`: pots, lows, cooks and cracks, each id once in `perf.hits`). +// +// WHAT THE ART READS: `spec.ride`, `round.runner` { v, line, check, done, served, domes +// [taken], plates [caught], cooks: [{ state "down" | "up" | "toss" | "spent" | "broken", t, +// dish: null | { x, y } }] }, `round.you`, the events in EVENTS. + +import { linesAt, linesOf, slopeOf, trackY } from "./ghoul-cart.js"; + +const freeze = (o) => Object.freeze(o); +const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v)); + +export const MONSTERS = freeze({}); + +// Every event this pack puts on the field, for the art and the sounds to answer. +export const EVENTS = freeze([ + "trayJump", "trayLand", "trayLaunch", "trayDuck", "trayCrash", "trayCheck", "trayFinish", + "trayDome", "trayPlate", "trayCookUp", "trayToss", "trayCookHit", "trayDishBreak", +]); + +// The tray. Speeds are units across a second, TRAY_G units a second squared. +export const TRAY_V = 44; +export const GREASE_V = 60; +export const TRAY_MIN = 28; +export const TRAY_MAX = 66; +export const SLOPE_G = 60; +export const RELAX = 1.5; +export const TRAY_JUMP_V = 74; +export const TRAY_G = 200; +export const COYOTE_MS = 100; +export const RAMP_SLOPE = 0.25; +export const RAMP_POP = 30; +export const LAND_TOL = 0.9; +export const BIG_LAND = 8; +export const DERAIL_Y = 3; +export const CAM_AHEAD = 10; +export const CAM_PER_V = 0.25; +// Obstacles. +export const POT_W = 2.8; +export const POT_H = 2.8; +export const CUTLERY_W = 4.6; +export const CUTLERY_H = 1.8; +export const COOK_W = 2.8; +export const COOK_H = 4.8; +export const COOK_NEAR = 58; +export const COOK_WIND_MS = 700; +export const COOK_STAY_MS = 1500; +export const DISH_V = 24; +export const DISH_W = 2.2; +export const DISH_H = 1.4; +export const DISH_LO = 1.6; +// The courses: a dome run through, a plate shot, a cook shot, and the points for each. +export const DOME_W = 2.8; +export const DOME_H = 2.4; +export const PLATE_W = 3.2; +export const PLATE_H = 2.8; +export const DOME_POINTS = 80; +export const PLATE_POINTS = 120; +export const COOK_POINTS = 150; +const SHOT_R = 0.5; +// The grade: a seven course meal is the acts die; the cherries are the steady die. +export const COURSES_GOAL = 7; +export const CHERRY_SHARE = 0.45; + +// Notes for a bonus round that obstacle `id` cost a heart (once each). +function noteHit(round, id) { + const b = round.bonusRound; + if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id); +} + +const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H); +const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0; + +// The highest line under x, as [line, y], or null over a crack. +const topAt = (R, x) => linesAt(R, x)[0] || null; + +// The tray's state in this round, or null (the shared slot may hold another ride's). +const mine = (round) => (round.runner && round.runner.id === "tray" ? round.runner : null); + +// Whether x is on a greased stretch. +export const greasy = (R, x) => R.grease.some(([a, b]) => x >= a && x <= b); + +// The highest line the tray, falling from `py` to `y` at `x`, crossed going down. +function landOn(R, x, py, y) { + for (const [line, ly] of linesAt(R, x)) if (py >= ly - LAND_TOL && y <= ly) return { line, y: ly }; + return null; +} + +// Where a tray in the air at (x, y) going up at vy and across at v lands, if it does not +// steer: { x, y, line } or null when it derails. The unit suite's measure of which gaps a jump clears. +export function flight(R, x, y, vy, v) { + const dt = 0.004; + for (let t = 0; t < 5; t += dt) { + const py = y; + vy = Math.max(-120, vy - TRAY_G * dt); + x += v * dt; + y += vy * dt; + if (vy <= 0) { + const f = landOn(R, x, py, y); + if (f) return { x, y: f.y, line: f.line }; + } + if (y < DERAIL_Y) return null; + } + return null; +} + +/* -------------------------------------------------------------- placing */ + +// A fresh set of the room's things. What was eaten or shot stays so (`old`, the tray of an earlier try). +function things(R, old) { + const was = (list, i, state) => (old && old.cooks[i] && old.cooks[i].state === state ? state : null); + return { + domes: R.domes.map((d, i) => Boolean(old && old.domes[i])), + plates: R.plates.map((p, i) => Boolean(old && old.plates[i])), + cooks: R.cooks.map((c, i) => ({ state: was("cooks", i, "broken") || "down", t: 0, dish: null })), + }; +} + +// Planny put down in the room: on the tray at the start of a ride, or at the last checkpoint +// passed after the last heart (the same room). Any other room: this ride's state goes. +function place(round, k) { + const R = round.spec.ride; + if (!R || R.runner !== "tray") { + if (mine(round)) round.runner = null; + return; + } + const old = mine(round); + const again = old && old.room === round.room; + const check = again ? old.check : -1; + const you = round.you; + const x = check >= 0 ? R.checks[check] : round.spec.start; + const top = topAt(R, x); + Object.assign(you, { x, y: top ? top[1] : you.y, vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 }); + round.runner = { id: "tray", room: round.room, check, v: TRAY_V, line: top ? top[0] : -1, coyote: 0, from: you.y, left: top ? top[0] : 0, done: false, served: again ? old.served : 0, cherries: again ? old.cherries : 0, cherryMs: 0, ...things(R, again ? old : null) }; + round.camLead = CAM_AHEAD; + const b = round.bonusRound; + if (b && !b.perf.total) { + b.perf.total = R.pots.length + R.lows.length + R.cooks.length + (R.track.length - 1); + b.perf.steady = false; + b.perf.goal = COURSES_GOAL; + } +} + +/* ------------------------------------------------------------ the ride */ + +// After a tumble that cost a heart but not the ride: Planny and the tray go back onto the +// track nearest where they fell (the highest line under him, else the next one ahead) at TRAY_V. +function reseat(round, c, R) { + const you = round.you; + const under = topAt(R, you.x); + let line; + let x; + let y; + if (under) { + [line, y] = under; + x = you.x; + } else { + const ahead = linesOf(R) + .map((L, i) => ({ i, x0: L.x0 })) + .filter((L) => L.x0 > you.x) + .sort((a, b) => a.x0 - b.x0)[0]; + line = ahead ? ahead.i : linesOf(R).length - 1; + x = ahead ? ahead.x0 + 2 : R.finish - 2; + y = trackY(R, line, x) ?? you.y; + } + Object.assign(you, { x, y, vy: 0, state: "run", shelf: -1, ducking: false, coyote: 0, drop: -1 }); + Object.assign(c, { line, v: TRAY_V, coyote: 0, from: y }); +} + +// The grade's cherries: the souls taken against what is laid out; and the courses served so far. +function appetite(round, c) { + c.cherries = round.candy.reduce((n, got) => n + (got ? 1 : 0), 0); + const b = round.bonusRound; + if (b) { + b.perf.steady = c.cherries >= Math.ceil(CHERRY_SHARE * round.candy.length); + b.perf.acts = c.served; + } +} + +// The tray's motion for one slice. Returns true once it has moved Planny (every slice of a +// ride); false outside a ride and once he has stepped out onto the dining table. +function ride(round, ms, k) { + const R = round.spec.ride; + const c = mine(round); + if (!R || R.runner !== "tray" || !c || c.done) return false; + const you = round.you; + const inp = round.input; + const dt = ms / 1000; + const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra }); + // Already down on the table (set there, or past the lip some other way): the ride is over. + if (you.x >= R.finish && you.vy <= 0 && you.y <= k.groundAt(round.spec, you.x) + 0.01) return finish(round, c, R, k.groundAt(round.spec, you.x), k); + // A stomp's bounce (or anything else) lifts the tray off its line. + if (you.state === "air" && c.line >= 0) { + c.left = c.line; + c.line = -1; + c.coyote = 0; + c.from = you.y; + } + steerShots(round, R); + const want = inp.jump > 0; + if (c.line >= 0) { + // On the stairs or the shelf. + const slope = slopeOf(R, c.line, you.x); + const goal = greasy(R, you.x) ? GREASE_V : TRAY_V; + c.v = clamp(c.v + ((goal - c.v) * RELAX - SLOPE_G * slope) * dt, TRAY_MIN, TRAY_MAX); + const duck = Boolean(inp.down) && !want; + if (duck && !you.ducking) ev("trayDuck"); + you.ducking = duck; + if (want) { + inp.jump = 0; + you.vy = TRAY_JUMP_V + slope * c.v; + Object.assign(c, { left: c.line, line: -1, coyote: 0, from: you.y }); + you.state = "air"; + you.ducking = false; + ev("trayJump", { v: c.v }); + } else { + const L = linesOf(R)[c.line]; + const nx = you.x + c.v * dt; + you.state = "run"; + you.vy = 0; + if (nx >= L.x1) { + // Off the end of the line, on along its last slope. + const end = L.pts[L.pts.length - 1]; + const rise = slopeOf(R, c.line, L.x1); + you.x = L.x1; + you.y = end[1]; + const ramp = rise >= RAMP_SLOPE; + you.vy = rise * c.v + (ramp ? RAMP_POP : 0); + Object.assign(c, { left: c.line, line: -1, coyote: COYOTE_MS, from: you.y }); + you.state = "air"; + you.ducking = false; + if (ramp) ev("trayLaunch", { v: c.v, last: c.left === linesOf(R).length - 1 }); + } else { + you.x = nx; + you.y = trackY(R, c.line, nx); + } + } + } else { + // In the air. + c.coyote = Math.max(0, c.coyote - ms); + if (want && c.coyote > 0) { + inp.jump = 0; + c.coyote = 0; + you.vy = TRAY_JUMP_V; + c.from = you.y; + ev("trayJump", { v: c.v }); + } + const py = you.y; + you.vy = Math.max(-k.FALL_MAX, you.vy - TRAY_G * dt); + you.x += c.v * dt; + you.y += you.vy * dt; + you.ducking = false; + you.state = "air"; + if (you.vy <= 0) { + const f = landOn(R, you.x, py, you.y); + if (f) { + you.y = f.y; + you.vy = 0; + you.state = "run"; + c.line = f.line; + ev("trayLand", { big: c.from - f.y >= BIG_LAND }); + c.from = f.y; + } else if (you.x >= R.finish) { + // Over the dining table at the end: down onto it, and the ride is over. + const g = k.groundAt(round.spec, you.x); + if (g > -Infinity && you.y <= g + 0.01) return finish(round, c, R, g, k); + } + } + } + // A press nothing took waits a moment for a landing, then goes. + if (want && inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms); + // Past the end of the world: a gap, or the edge of the table. + if (you.y < DERAIL_Y || k.groundAt(round.spec, you.x) > you.y + 0.5) { + noteHit(round, `k${c.left}`); + if (k.lose(round, "tumble") && round.phase === "play") reseat(round, c, R); + return true; + } + while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) { + c.check++; + ev("trayCheck", { n: c.check + 1 }); + } + round.camLead = CAM_AHEAD + (c.v - TRAY_V) * CAM_PER_V; + c.cherryMs -= ms; + if (c.cherryMs <= 0) { + c.cherryMs = 400; + appetite(round, c); + } + eat(round, c, R, k); + if (obstacles(round, c, R, k)) return true; + creatures(round, c, R, ms); + return true; +} + +// The ride is over: the tray halts on the table, the door opens, Planny walks out. +function finish(round, c, R, g, k) { + const you = round.you; + c.done = true; + c.restX = you.x; + Object.assign(you, { y: g, vy: 0, state: "run", shelf: -1, ducking: false }); + round.hasKey = true; + round.camLead = 0; + appetite(round, c); + round.events.push({ type: "trayFinish", x: you.x, y: you.y, big: c.from - g >= BIG_LAND, served: c.served }); + return false; +} + +// A bolt flies parallel to the track under it, whatever way he aimed (`s.off`): the stairs are +// steep, and a level bolt would sail over everything on a descent. +function steerShots(round, R) { + for (const s of round.shots) { + if (s.arm || s.free) continue; + if (s.off === undefined) s.off = s.vy; + const top = topAt(R, s.x); + if (top) s.sl = slopeOf(R, top[0], s.x); + s.vy = s.vx * (s.sl ?? 0) + s.off; + } +} + +// A course served: the points and the count. +function serve(round, c, type, x, y, points) { + c.served++; + round.score += points; + const b = round.bonusRound; + if (b) b.perf.acts = c.served; + round.events.push({ type, x, y, points, n: c.served, goal: COURSES_GOAL }); +} + +// The silver domes: run through one (a high one takes a jump) and it is a course. +function eat(round, c, R, k) { + const you = round.you; + R.domes.forEach(([x, line, lift], i) => { + if (c.domes[i] || Math.abs(you.x - x) > 4) return; + const y0 = trackY(R, line, x) + lift; + if (!boxHit(k, you, x, y0, DOME_W, DOME_H)) return; + c.domes[i] = true; + serve(round, c, "trayDome", x, y0 + DOME_H / 2, DOME_POINTS); + }); +} + +// What the tray runs into: a pot, a drop of cutlery, a ham or pans, a dish. Returns whether it cost a heart. +function obstacles(round, c, R, k) { + const you = round.you; + const hh = duckH(k, you); + for (const [i, [x0, x1, y, kind]] of R.lows.entries()) { + if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > y && k.struck(round, kind ? "pans" : "ham")) { + noteHit(round, `l${i}`); + round.events.push({ type: "trayCrash", what: kind ? "pans" : "ham", x: you.x, y: you.y + hh }); + return true; + } + } + for (const [i, [x, line, kind]] of R.pots.entries()) { + if (Math.abs(you.x - x) > 6) continue; + if (boxHit(k, you, x, trackY(R, line, x), kind ? CUTLERY_W : POT_W, kind ? CUTLERY_H : POT_H) && k.struck(round, kind ? "cutlery" : "pot")) { + noteHit(round, `p${i}`); + round.events.push({ type: "trayCrash", what: kind ? "cutlery" : "pot", x, y: you.y }); + return true; + } + } + for (const [i, cook] of c.cooks.entries()) { + const d = cook.dish; + if (!d || Math.abs(you.x - d.x) > 5) continue; + if (boxHit(k, you, d.x, d.y, DISH_W, DISH_H) && k.struck(round, "dish")) { + noteHit(round, `c${i}`); + round.events.push({ type: "trayCrash", what: "dish", x: d.x, y: d.y }); + cook.dish = null; + return true; + } + } + return false; +} + +// The cooks wake when the tray comes near, wind up and fling a dish back along the track. +function creatures(round, c, R, ms) { + const you = round.you; + const dt = ms / 1000; + R.cooks.forEach(([x, line], i) => { + const o = c.cooks[i]; + const y = trackY(R, line, x); + if (o.state === "down") { + const ahead = x - you.x; + if (ahead < COOK_NEAR && ahead > -COOK_W) { + Object.assign(o, { state: "up", t: COOK_WIND_MS }); + round.events.push({ type: "trayCookUp", x, y }); + } + } else if (o.state === "up" || o.state === "toss") { + o.t -= ms; + if (o.t <= 0 && o.state === "up") { + Object.assign(o, { state: "toss", t: COOK_STAY_MS, dish: { x: x - 1.2, y: y + DISH_LO } }); + round.events.push({ type: "trayToss", x, y: y + DISH_LO + 1 }); + } else if (o.t <= 0) Object.assign(o, { state: "spent", t: 0 }); + } + // A dish in flight, along the track it left, until it is behind the tray or far from its cook. + const d = o.dish; + if (d) { + d.x -= DISH_V * dt; + const ty = trackY(R, line, d.x); + if (ty !== null) d.y = ty + DISH_LO; + if (d.x < you.x - 10 || d.x < x - 110) o.dish = null; + } + }); +} + +/* ------------------------------------------------------------- targets */ + +// A bolt into something to shoot: a flying plate (a course), a cook winding up or flinging, a +// dish in the air. True when one took it (the bolt is spent). +function trayShot(round, s) { + const R = round.spec.ride; + const c = mine(round); + if (!R || R.runner !== "tray" || !c) return false; + const hit = (x, y0, w, h) => Math.abs(s.x - x) <= w / 2 + SHOT_R && s.y >= y0 - SHOT_R && s.y <= y0 + h + SHOT_R; + for (let i = 0; i < R.plates.length; i++) { + if (c.plates[i]) continue; + const [x, line, lift] = R.plates[i]; + const y0 = trackY(R, line, x) + lift; + if (!hit(x, y0, PLATE_W, PLATE_H)) continue; + c.plates[i] = true; + serve(round, c, "trayPlate", x, y0 + PLATE_H / 2, PLATE_POINTS); + return true; + } + for (let i = 0; i < R.cooks.length; i++) { + const o = c.cooks[i]; + const [x, line] = R.cooks[i]; + const y = trackY(R, line, x); + if (o.dish && hit(o.dish.x, o.dish.y, DISH_W, DISH_H)) { + round.events.push({ type: "trayDishBreak", x: o.dish.x, y: o.dish.y }); + o.dish = null; + return true; + } + if ((o.state === "up" || o.state === "toss") && hit(x, y, COOK_W, COOK_H)) { + Object.assign(o, { state: "broken", t: 0 }); + round.score += COOK_POINTS; + round.events.push({ type: "trayCookHit", x, y: y + COOK_H / 2, points: COOK_POINTS }); + return true; + } + } + return false; +} + +export const TRAY = freeze({ + id: "tray", + monsters: MONSTERS, + walkers: freeze([]), + zombies: freeze([]), + stackers: freeze([]), + climbers: freeze([]), + act: freeze({}), + horde: freeze({}), + ride: freeze([ride]), + place: freeze([place]), + target: trayShot, +}); diff --git a/src/web-console/public/activities/ghoul-wagon-draw.js b/src/web-console/public/activities/ghoul-wagon-draw.js new file mode 100644 index 0000000..c4c8221 --- /dev/null +++ b/src/web-console/public/activities/ghoul-wagon-draw.js @@ -0,0 +1,1297 @@ +// Plan2Code Web Console - Ghoul Rush's Torch Mob, its drawing: a night race out of Hollow End on a stolen hay wagon. A warm-edged night sky and a moon, far rooftops and a church spire, the lit houses of the street, the cobbled road with its ditches, the old stone bridge over a dark river with its collapsed span, barrels and crates, washing lines and inn signs, villagers in windows and on roofs with pitchforks and torches, spooked horses, the hay wagon with its horse and its load (burning, when a torch lands), and the mob behind, torches and pitchforks and moonhounds, closer or further as the rules say. No random numbers: everything comes from a hash. +// +// ghoul-draw.js plugs it in. LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are plain +// data (the sounds live in ghoul-sfx-wagon.js); wagonArt(d) takes ghoul-draw.js's drawing +// helpers (`d`) and hands back the drawing by kind, so this file never reaches back into it. +// Drawn in room units, the way ghoul-draw.js draws: y counted down from the field's top, so a +// world height `y` is drawn at `FIELD_H - y`. The still layers' pit is dark under the whole +// ride, so the sky, the houses, the road and what stands on it are drawn by `moving` (every +// frame, behind Planny); the lows (washing lines, signs), the throws in the air, the hay's fire +// and the mob's meter by `front`. What the art reads off the rules (ghoul-wagon.js): +// +// - the room: `spec.ride` ({ track, blocks, lows, throwers, horses, checks, bridge, finish }), +// `spec.ground` (the cobbles at the start and the green at the end). +// - `round.runner` (null in any other room): `gap`, `v`, `line` (-1 in the air), `check`, +// `done`, `panic`, `fireMs`, `throwers` [{ state, t }], `props` [{ kind, x0, y0, x1, y1, x, +// y, s, dead, age }], `horses` [{ state, t, x }], `smashed`. +// - Planny: `you.state`, `you.vy`, `you.ducking`, `you.x`, `you.y`. +// - events leave short-lived bits in the view's `fx` (`wagonBits`, `wagonLand`). + +import { ANSWER_COLORS, TELEGRAPH_ALPHA } from "./ghoul-sled-draw.js"; +import { CATCH_GAP, GAP_MAX, PANIC_ON, REACH, THROW_MEET, WAGON_V, WIND_MS } from "./ghoul-wagon.js"; + +const freeze = (o) => Object.freeze(o); +const TAU = Math.PI * 2; +const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x)); + +const pit = (o) => freeze({ pack: "wagon", custom: true, noMoon: true, pit: "#05060f", ...o }); +export const LOOKS = freeze({ + wagon: pit({ wallTop: "#0a0d22", wallLow: "#1a1830", paper: "#2a2038", wainscot: "#1c1626", floorTop: "#5a5560", floor: "#26222c", floorEdge: "#100c14", shelf: "#3a2c24", shelfTop: "#7a5c40", window: "#ffc878", decor: "pots", color: "#ffb35a", dark: 0.5 }), +}); + +// How each new kind sounds, by act (the sounds are in ghoul-sfx-wagon.js). +export const VOICES = freeze({ + wagon: freeze({ jump: "ghoulWagonJump", land: "ghoulWagonLand", launch: "ghoulWagonLaunch", brake: "ghoulWagonBrake", crash: "ghoulWagonCrash", check: "ghoulWagonCheck", finish: "ghoulWagonFinish", panic: "ghoulWagonPanic", catch: "ghoulWagonCatch", fire: "ghoulWagonFire", out: "ghoulWagonOut" }), + wagonthrow: freeze({ wind: "ghoulWagonWind", throw: "ghoulWagonThrow", shot: "ghoulWagonShot", ember: "ghoulWagonEmber" }), + wagonhorse: freeze({ rear: "ghoulWagonRear", hit: "ghoulWagonHorseHit", turn: "ghoulWagonHorseTurn" }), +}); + +// What each of the pack's events plays: [kind, act], once. +export const EVENT_VOICE = freeze({ + wagonJump: ["wagon", "jump"], + wagonLand: ["wagon", "land"], + wagonLaunch: ["wagon", "launch"], + wagonBrake: ["wagon", "brake"], + wagonCrash: ["wagon", "crash"], + wagonCheck: ["wagon", "check"], + wagonFinish: ["wagon", "finish"], + wagonPanic: ["wagon", "panic"], + wagonCatch: ["wagon", "catch"], + wagonFire: ["wagon", "fire"], + wagonOut: ["wagon", "out"], + wagonWind: ["wagonthrow", "wind"], + wagonThrow: ["wagonthrow", "throw"], + wagonShot: ["wagonthrow", "shot"], + wagonEmber: ["wagonthrow", "ember"], + wagonRear: ["wagonhorse", "rear"], + wagonHorseHit: ["wagonhorse", "hit"], + wagonHorseTurn: ["wagonhorse", "turn"], +}); +export const LOSE_WORDS = freeze({ barrel: "Hit a barrel", crate: "Hit a crate", wash: "Tangled in the washing", sign: "Signed off", fork: "Pitchforked", torch: "Set alight", horse: "Trampled", ditch: "Fell in a ditch", river: "Into the river", mob: "Caught by the mob" }); +export const LOSE_SOUNDS = freeze({ + barrel: ["clank", 0.5, 0.7], + crate: ["smash", 0.5, 0.9], + wash: ["squish", 0.4, 1.1], + sign: ["clank", 0.5, 0.8], + fork: ["crunch", 0.5, 1], + torch: ["ghoulSizzle", 0.5, 0.8], + horse: ["thud", 0.6, 0.7], + ditch: ["ghoulPitFall", 0.55, 1], + river: ["splash", 0.6, 0.8], + mob: ["ghoulToll", 0.6, 0.7], +}); + +const FW = 96; +const WHEEL = 2.2; +const WATER = 7; +let FH = 54; + +// A number in 0..1 from two integers, the same every time (no random draws). +const rnd = (a, b = 0) => { + let h = Math.imul((a | 0) + 0x9e37, 0x85ebca6b) ^ Math.imul((b | 0) + 0x7f4a, 0xc2b2ae35); + h ^= h >>> 13; + h = Math.imul(h, 0x5bd1e995); + h ^= h >>> 15; + return (h >>> 0) / 4294967296; +}; +const poly = (c, pts) => { + c.beginPath(); + pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); + c.closePath(); +}; +const seg = (c, x0, y0, x1, y1) => { + c.beginPath(); + c.moveTo(x0, y0); + c.lineTo(x1, y1); + c.stroke(); +}; +const disc = (c, x, y, r) => { + c.beginPath(); + c.arc(x, y, r, 0, TAU); + c.fill(); +}; +const grad = (make, stops) => { + const g = make ? make() : null; + if (!g || typeof g.addColorStop !== "function") return stops[stops.length >> 1][1]; + for (const [o, col] of stops) g.addColorStop(o, col); + return g; +}; +const vgrad = (c, y0, y1, stops) => grad(c.createLinearGradient && (() => c.createLinearGradient(0, y0, 0, y1)), stops); +const rgrad = (c, x, y, r, stops) => grad(c.createRadialGradient && (() => c.createRadialGradient(x, y, 0, x, y, r)), stops); + +// A soft glow of "r,g,b" at a spot. +function glow(ctx, rgb, x, y, r, alpha) { + ctx.globalAlpha = alpha; + ctx.fillStyle = rgrad(ctx, x, y, r, [[0, `rgba(${rgb},0.9)`], [0.4, `rgba(${rgb},0.35)`], [1, `rgba(${rgb},0)`]]); + ctx.fillRect(x - r, y - r, r * 2, r * 2); + ctx.globalAlpha = 1; +} +const WARM = "255,170,80"; + +/* ----------------------------------------------------------- the geometry */ + +// The deck's height at x (the highest line under it), or null over a gap. +const yOn = (pts, x) => { + for (let i = 0; i + 1 < pts.length; i++) { + if (x <= pts[i + 1][0]) return pts[i][1] + ((pts[i + 1][1] - pts[i][1]) * (x - pts[i][0])) / (pts[i + 1][0] - pts[i][0]); + } + return pts[pts.length - 1][1]; +}; +const heightAt = (R, x) => { + let best = null; + for (const pts of R.track) if (x >= pts[0][0] && x <= pts[pts.length - 1][0]) best = Math.max(best ?? -Infinity, yOn(pts, x)); + return best; +}; +// The nearest deck height, over a gap too. +const deckNear = (R, x) => { + const h = heightAt(R, x); + if (h !== null) return h; + let best = 16; + let bd = Infinity; + for (const pts of R.track) { + for (const e of [pts[0], pts[pts.length - 1]]) { + if (Math.abs(e[0] - x) < bd) { + bd = Math.abs(e[0] - x); + best = e[1]; + } + } + } + return best; +}; + +/* ------------------------------------------------------------- telegraphs */ + +// What to do about what is coming, as a glyph that fades in ahead of it: DUCK for a washing line, +// an inn sign or a hurled pitchfork, JUMP for a barrel, a crate, a ditch, the bridge, a hurled +// torch or a horse. Everything comes from the room's `ride` fields and where the wagon is (no +// random numbers, no rules). +export const TELEGRAPH_SEE = 40; +export const TELEGRAPH_FULL = 30; +export const THROW_SEE = 66; +export const TELEGRAPH_WORDS = 3; +export const ANSWERS = freeze({ ditch: "JUMP", bridge: "JUMP", barrel: "JUMP", crate: "JUMP", horse: "JUMP", torch: "JUMP", wash: "DUCK", sign: "DUCK", fork: "DUCK" }); + +const marks = new WeakMap(); +// Every obstacle that wants a glyph: { kind, lead (where the wagon acts), x (its middle), up (height of +// the glyph's anchor), n (which of its kind), answer, see }, in the room's order. +export function telegraphMarks(R) { + if (marks.has(R)) return marks.get(R); + const out = []; + const count = {}; + const add = (kind, lead, x, up, see = TELEGRAPH_SEE) => { + const n = count[kind] || 0; + count[kind] = n + 1; + out.push({ kind, lead, x, up, n, answer: ANSWERS[kind], see }); + }; + for (let i = 0; i + 1 < R.track.length; i++) { + const a = R.track[i].at(-1)[0]; + const b = R.track[i + 1][0][0]; + const bridge = R.bridge && a >= R.bridge[0] && a <= R.bridge[1]; + add(bridge ? "bridge" : "ditch", a - (bridge ? 6 : 3), (a + b) / 2, (heightAt(R, a - 0.1) ?? 16) + 7.5); + } + for (const [x, line, kind] of R.blocks) add(kind ? "crate" : "barrel", x - REACH - 3, x, (heightAt(R, x) ?? 16) + 8); + for (const [x0, x1, y, kind] of R.lows) add(kind ? "sign" : "wash", x0 - 3.2, (x0 + x1) / 2, y + 6.4); + for (const [x, line, kind] of R.throwers) add(kind ? "torch" : "fork", x - THROW_MEET - 2, x - THROW_MEET, (heightAt(R, x - THROW_MEET) ?? 16) + 9, THROW_SEE); + for (const [x] of R.horses) add("horse", x - 24, x - 14, (heightAt(R, x) ?? 16) + 9, TELEGRAPH_SEE + 20); + out.sort((p, q) => p.lead - q.lead); + marks.set(R, out); + return out; +} + +// The glyphs showing with the wagon at `x`: { ...mark, alpha (0..1, before the pulse), words }. +export function telegraphs(R, x) { + const out = []; + for (const m of telegraphMarks(R)) { + const d = m.lead - x; + if (d > m.see || d < -6) continue; + const alpha = Math.min(clamp((m.see - d) / (TELEGRAPH_SEE - TELEGRAPH_FULL), 0, 1), clamp((d + 4) / 6, 0, 1)); + if (alpha > 0.01) out.push({ ...m, alpha, words: m.n < TELEGRAPH_WORDS }); + } + return out; +} + +/* --------------------------------------------------------------------- art */ + +export function wagonArt(d) { + const { ellipse, say, label, GOLD } = d; + const ride = (v) => (v.spec && v.spec.ride && v.spec.ride.runner === "wagon" ? v.spec.ride : null); + const Y = (y) => FH - y; + const roadAt = (R, x) => deckNear(R, x) - WHEEL; + + /* ------------------------------------------------------------- the room */ + + // The still layers only get the sky's color: the world is drawn by `moving`. + function backdrop(ctx, v, look, x0, x1) { + ctx.fillStyle = look.wallLow; + ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H); + } + // The cobbles at the start, the green's grass at the end. + function ground(ctx, v, look, a, b, top) { + const y = v.g.FIELD_H - top; + const R = ride(v); + if (R && a >= R.finish - 1) { + ctx.fillStyle = vgrad(ctx, y, y + top, [[0, "#4c7a3a"], [0.25, "#2c5028"], [1, "#101c14"]]); + ctx.fillRect(a, y, b - a, top + 2); + ctx.fillStyle = "#6a9a4a"; + ctx.fillRect(a, y, b - a, 0.3); + ctx.strokeStyle = "#1c3820"; + ctx.lineWidth = 0.12; + for (let x = a; x < b; x += 1.4) seg(ctx, x, y, x + 0.3 * (rnd(x * 10, 2) - 0.5), y - 0.7 - rnd(x * 10, 1) * 0.6); + return; + } + ctx.fillStyle = vgrad(ctx, y, y + top, [[0, "#6a6470"], [0.3, "#3e3a46"], [1, "#16121a"]]); + ctx.fillRect(a, y, b - a, top + 2); + } + function shelf() {} + + /* ------------------------------------------------------------- the sky */ + + function sky(ctx, cam, clock) { + ctx.fillStyle = vgrad(ctx, 0, FH, [[0, "#060a1e"], [0.5, "#161a3c"], [0.8, "#3c2438"], [1, "#6a3a30"]]); + ctx.fillRect(cam - 1, 0, FW + 2, FH); + for (let k = 0; k < 40; k++) { + const sx = cam + ((((rnd(k, 1) * FW - cam * 0.05) % FW) + FW) % FW); + const tw = 0.4 + 0.6 * Math.abs(Math.sin(clock / 700 + k)); + ctx.fillStyle = `rgba(235,240,255,${0.2 + 0.45 * tw * rnd(k, 3)})`; + ctx.fillRect(sx, 1 + rnd(k, 2) * 20, 0.22 + rnd(k, 4) * 0.12, 0.22); + } + const mx = cam + 68 - cam * 0.02; + glow(ctx, "220,228,255", mx, 10, 13, 0.4); + ctx.fillStyle = "#f2efe2"; + disc(ctx, mx, 10, 3.8); + ctx.fillStyle = "rgba(160,160,180,0.5)"; + disc(ctx, mx - 1.1, 9, 0.9); + disc(ctx, mx + 1.3, 11, 1); + } + + // A row of roofs at parallax `f`: gabled houses `slot` wide on a base `base` down from the top, the + // tall ones a church spire, `lit` the share of windows glowing. + function skyline(ctx, cam, f, slot, base, hmin, hmax, body, roof, lit, clock, seed) { + const lo = cam * f - 24; + const hi = cam * f + FW + 24; + for (let n = Math.floor(lo / slot); n * slot < hi; n++) { + const x = n * slot + cam * (1 - f); + const w = slot * (0.62 + rnd(n, seed) * 0.34); + const h = hmin + rnd(n, seed + 1) * (hmax - hmin); + const top = base - h; + ctx.fillStyle = body; + ctx.fillRect(x, top, w, h + 8); + ctx.fillStyle = roof; + poly(ctx, [[x - 0.8, top], [x + w / 2, top - w * 0.38], [x + w + 0.8, top]]); + ctx.fill(); + if (rnd(n, seed + 2) > 0.55) ctx.fillRect(x + w * 0.7, top - w * 0.4, 1.1, w * 0.4); + if (n % 9 === 4) { + ctx.fillStyle = roof; + poly(ctx, [[x + w * 0.3, top], [x + w / 2, top - 15], [x + w * 0.7, top]]); + ctx.fill(); + } + if (lit > 0) { + for (let r = 0; r < 2; r++) { + for (let cx = 0; cx < 2; cx++) { + const on = rnd(n * 7 + r * 2 + cx, seed + 3) < lit && Math.sin(clock / (600 + rnd(n, 9) * 500) + n + r) > -0.7; + if (!on) continue; + ctx.fillStyle = "#ffc070"; + ctx.fillRect(x + w * (0.22 + cx * 0.4), top + 2 + r * 4.2, 1.5, 2.1); + } + } + } + } + } + + /* ------------------------------------------------------------ the street */ + + // The houses along the street at the road's own pace: a door, windows, a lantern, a sign over a tavern. + function street(ctx, v, R, cam, lo, hi) { + const clock = v.clock; + const base = Y(13.8); + for (let n = Math.floor((cam - 14) / 24); n * 24 < cam + FW + 14; n++) { + const x = n * 24 + 1; + const mid = x + 11; + if (R.bridge && mid > R.bridge[0] - 14 && mid < R.bridge[1] + 12) continue; + if (mid > R.finish - 10) continue; + const w = 21 + rnd(n, 1) * 2; + const h = 17 + rnd(n, 2) * 8; + const top = base - h; + const tone = rnd(n, 3); + ctx.fillStyle = tone < 0.34 ? "#241c30" : tone < 0.67 ? "#2c2028" : "#1e2230"; + ctx.fillRect(x, top, w, h + 1); + // Timber framing. + ctx.strokeStyle = "rgba(10,6,12,0.55)"; + ctx.lineWidth = 0.28; + seg(ctx, x + w * 0.33, top, x + w * 0.33, base); + seg(ctx, x + w * 0.66, top, x + w * 0.66, base); + seg(ctx, x, top + h * 0.45, x + w, top + h * 0.45); + // The roof, with a chimney. + ctx.fillStyle = "#14101c"; + poly(ctx, [[x - 1.4, top + 0.2], [x + w / 2, top - 6.4 - rnd(n, 4) * 2], [x + w + 1.4, top + 0.2]]); + ctx.fill(); + ctx.fillRect(x + w * (0.15 + rnd(n, 5) * 0.55), top - 6, 1.6, 4); + // Windows, some lit and one a twitching curtain. + for (const [wx, wy] of [[0.12, 0.12], [0.5, 0.12], [0.12, 0.55], [0.5, 0.55]]) { + if (wy > 0.5 && wx < 0.3 && rnd(n, 6) > 0.5) continue; + const px = x + w * wx + 0.5; + const py = top + h * wy + 1.5; + const on = rnd(n * 5 + Math.round(wx * 9), 8) > 0.38; + ctx.fillStyle = on ? "#ffbe62" : "#0c0a14"; + ctx.fillRect(px, py, 3.4, 4.2); + ctx.strokeStyle = "#0a0610"; + ctx.lineWidth = 0.2; + seg(ctx, px + 1.7, py, px + 1.7, py + 4.2); + seg(ctx, px, py + 2.1, px + 3.4, py + 2.1); + if (on && rnd(n, 11) > 0.5 && Math.sin(clock / 500 + n * 3 + wx * 9) > 0.55) { + ctx.fillStyle = "#6a3a2a"; + ctx.fillRect(px + 1.2, py, 1.1, 3.4); + } + if (on) glow(ctx, WARM, px + 1.7, py + 2.1, 4.4, 0.3); + } + // The door, and a lantern beside it. + const dx = x + w * (0.72 + rnd(n, 12) * 0.08); + ctx.fillStyle = "#1a0e0a"; + ctx.fillRect(dx, base - 6.4, 3.4, 6.4); + ctx.fillStyle = "#4a3020"; + ctx.fillRect(dx + 0.3, base - 6.1, 2.8, 0.3); + ctx.fillStyle = "#2a3a2a"; + ctx.fillRect(dx - 0.6, base - 0.5, 4.6, 0.5); + const lx = dx - 1.4; + ctx.fillStyle = "#ffcf7a"; + ctx.fillRect(lx, base - 6.6, 0.8, 1.2); + glow(ctx, WARM, lx + 0.4, base - 6, 5, 0.4 + 0.1 * Math.sin(clock / 170 + n)); + // A tavern's hanging sign. + if (rnd(n, 13) > 0.7) { + ctx.fillStyle = "#3a2616"; + ctx.fillRect(x + w - 0.2, top + h * 0.3, 3.2, 0.3); + ctx.fillStyle = "#5a3c20"; + ctx.fillRect(x + w + 0.8, top + h * 0.3 + 0.3, 1.9, 2.2); + } + } + } + + /* ------------------------------------------------------------- the road */ + + // The cobbled road on each line, a dark earth under it, the ditches between. + function road(ctx, R, lo, hi) { + for (const pts of R.track) { + const a = pts[0][0]; + const b = pts[pts.length - 1][0]; + if (b < lo || a > hi) continue; + const top = pts.map(([x, y]) => [x, Y(y - WHEEL)]); + ctx.fillStyle = vgrad(ctx, 0, FH, [[0, "#16121c"], [1, "#0a0810"]]); + poly(ctx, [...top, [b, FH + 1], [a, FH + 1]]); + ctx.fill(); + // The cobbled face. + ctx.fillStyle = vgrad(ctx, FH - 24, FH, [[0, "#6c6672"], [1, "#2a2630"]]); + poly(ctx, [...top, ...top.map(([x, y]) => [x, y + 3.4]).reverse()]); + ctx.fill(); + ctx.strokeStyle = "rgba(10,8,14,0.55)"; + ctx.lineWidth = 0.14; + for (let x = Math.max(a, Math.floor(lo / 2.2) * 2.2); x <= Math.min(b, hi); x += 2.2) { + const y = yOn(pts, x); + seg(ctx, x, Y(y - WHEEL) + 0.1, x + 0.2, Y(y - WHEEL) + 3.2); + } + for (let r = 1; r < 3; r++) { + ctx.beginPath(); + for (let x = Math.max(a, lo); x <= Math.min(b, hi); x += 2.2) ctx.lineTo(x, Y(yOn(pts, x) - WHEEL) + r * 1.1); + ctx.stroke(); + } + ctx.strokeStyle = "rgba(255,225,190,0.35)"; + ctx.lineWidth = 0.22; + ctx.beginPath(); + for (let x = Math.max(a, lo); x <= Math.min(b, hi); x += 2.2) ctx.lineTo(x, Y(yOn(pts, x) - WHEEL)); + ctx.stroke(); + } + } + + // The gaps between lines: a ditch of dark mud and a puddle's glint, or the river under the bridge. + function gaps(ctx, v, R, lo, hi) { + for (let i = 0; i + 1 < R.track.length; i++) { + const a = R.track[i].at(-1); + const b = R.track[i + 1][0]; + if (b[0] < lo || a[0] > hi) continue; + const ya = Y(a[1] - WHEEL); + const yb = Y(b[1] - WHEEL); + const bridge = R.bridge && a[0] >= R.bridge[0] && a[0] <= R.bridge[1]; + // The broken edges, jagged stone. + ctx.fillStyle = bridge ? "#3c3a48" : "#2a242c"; + poly(ctx, [[a[0], ya], [a[0] + 0.6, ya + 1.4], [a[0] - 0.4, ya + 2.6], [a[0] + 0.5, ya + 4], [a[0] - 0.2, ya + 6], [a[0] - 3, ya + 6], [a[0] - 3, ya]]); + ctx.fill(); + poly(ctx, [[b[0], yb], [b[0] - 0.6, yb + 1.6], [b[0] + 0.4, yb + 3], [b[0] - 0.5, yb + 4.4], [b[0] + 0.2, yb + 6], [b[0] + 3, yb + 6], [b[0] + 3, yb]]); + ctx.fill(); + if (!bridge) { + ctx.fillStyle = "#07060e"; + ctx.fillRect(a[0], Math.min(ya, yb), b[0] - a[0], FH - Math.min(ya, yb) + 1); + ctx.fillStyle = "rgba(60,90,130,0.45)"; + ellipse(ctx, (a[0] + b[0]) / 2, FH - 3.2, (b[0] - a[0]) / 2, 0.5); + ctx.fill(); + } + } + } + + // The old stone bridge: the arches under the hump, the river below with the moon's glint, the parapet along the top. + function bridge(ctx, v, R, cam, lo, hi) { + const [bx0, bx1] = R.bridge; + if (bx1 < lo || bx0 > hi) return; + const clock = v.clock; + const wy = FH - WATER; + // The river, behind everything under the road. + ctx.fillStyle = vgrad(ctx, wy, FH, [[0, "#14284a"], [1, "#060a18"]]); + ctx.fillRect(Math.max(bx0 - 6, lo), wy, Math.min(bx1 + 6, hi) - Math.max(bx0 - 6, lo), WATER + 1); + ctx.strokeStyle = "rgba(190,210,255,0.25)"; + ctx.lineWidth = 0.16; + for (let k = 0; k < 14; k++) { + const x = Math.max(bx0 - 6, lo) + rnd(k, 5) * (Math.min(bx1 + 6, hi) - Math.max(bx0 - 6, lo)); + const y = wy + 1 + rnd(k, 6) * (WATER - 1.5); + seg(ctx, x, y, x + 2 + Math.sin(clock / 500 + k) * 0.6, y); + } + // The stone body of the bridge under the line's hump, with arches cut out. + for (const pts of R.track) { + const a = Math.max(pts[0][0], bx0, lo); + const b = Math.min(pts[pts.length - 1][0], bx1, hi); + if (b <= a) continue; + const top = []; + for (let x = a; x <= b + 0.01; x += 2) top.push([x, Y(yOn(pts, x) - WHEEL)]); + top.push([b, Y(yOn(pts, b) - WHEEL)]); + ctx.fillStyle = "#2c2a3a"; + poly(ctx, [...top, [b, wy + 0.5], [a, wy + 0.5]]); + ctx.fill(); + ctx.fillStyle = "#060914"; + for (let x = Math.ceil(a / 44) * 44 + 20; x < b - 6; x += 44) { + ctx.beginPath(); + ctx.moveTo(x - 9, wy + 0.5); + ctx.lineTo(x - 9, wy - 4.5); + ctx.arc(x, wy - 4.5, 9, Math.PI, 0); + ctx.lineTo(x + 9, wy + 0.5); + ctx.closePath(); + ctx.fill(); + } + // The parapet along the top, with a capstone, and a lamp now and then. + ctx.fillStyle = "#3a384a"; + poly(ctx, [...top.map(([x, y]) => [x, y - 3]), ...top.slice().reverse()]); + ctx.fill(); + ctx.fillStyle = "#54516a"; + poly(ctx, [...top.map(([x, y]) => [x, y - 3.3]), ...top.map(([x, y]) => [x, y - 2.8]).reverse()]); + ctx.fill(); + ctx.strokeStyle = "rgba(10,8,18,0.5)"; + ctx.lineWidth = 0.14; + for (let x = Math.ceil(a / 3.6) * 3.6; x < b; x += 3.6) { + const y = Y(yOn(pts, x) - WHEEL); + seg(ctx, x, y - 3, x, y); + } + } + for (let x = Math.ceil(bx0 / 60) * 60 + 10; x < bx1; x += 60) { + if (x < lo || x > hi) continue; + const y = Y((heightAt(R, x) ?? deckNear(R, x)) - WHEEL); + ctx.fillStyle = "#1c1a26"; + ctx.fillRect(x - 0.25, y - 8.5, 0.5, 5.5); + ctx.fillStyle = "#ffd488"; + ctx.fillRect(x - 0.7, y - 9.6, 1.4, 1.3); + glow(ctx, WARM, x, y - 9, 6, 0.4 + 0.08 * Math.sin(clock / 150 + x)); + } + } + + /* ----------------------------------------------------------- the things */ + + // A barrel with hoops, or a crate with an X: tall from the road, with the cargo's top a little over the deck. + function block(ctx, x, base, kind, i) { + const h = WHEEL + 3.4; + ctx.fillStyle = "rgba(0,0,0,0.35)"; + ellipse(ctx, x + 0.4, base, kind ? 2 : 1.7, 0.35); + ctx.fill(); + if (kind) { + const w = 3.4; + ctx.fillStyle = "#7a5a34"; + ctx.fillRect(x - w / 2, base - h, w, h); + ctx.fillStyle = "#5a3e22"; + ctx.fillRect(x - w / 2, base - h, w, 0.5); + ctx.fillRect(x - w / 2, base - 0.5, w, 0.5); + ctx.fillRect(x - w / 2, base - h, 0.5, h); + ctx.fillRect(x + w / 2 - 0.5, base - h, 0.5, h); + ctx.strokeStyle = "#5a3e22"; + ctx.lineWidth = 0.3; + seg(ctx, x - w / 2 + 0.4, base - h + 0.4, x + w / 2 - 0.4, base - 0.4); + seg(ctx, x + w / 2 - 0.4, base - h + 0.4, x - w / 2 + 0.4, base - 0.4); + ctx.fillStyle = "rgba(255,225,170,0.2)"; + ctx.fillRect(x - w / 2 + 0.3, base - h + 0.3, w - 0.6, 0.25); + return; + } + const w = 2.6; + ctx.fillStyle = "#6a4426"; + ctx.beginPath(); + ctx.moveTo(x - w / 2, base); + ctx.quadraticCurveTo(x - w / 2 - 0.5, base - h / 2, x - w / 2, base - h); + ctx.lineTo(x + w / 2, base - h); + ctx.quadraticCurveTo(x + w / 2 + 0.5, base - h / 2, x + w / 2, base); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = "rgba(255,210,150,0.22)"; + ctx.fillRect(x - w / 2 + 0.2, base - h, 0.5, h); + ctx.fillStyle = "#2c2c34"; + for (const f of [0.18, 0.5, 0.82]) ctx.fillRect(x - w / 2 - 0.3, base - h * f - 0.2, w + 0.6, 0.4); + ctx.fillStyle = "#3a2414"; + ellipse(ctx, x, base - h, w / 2, 0.4); + ctx.fill(); + if (i % 2) { + ctx.fillStyle = "#c8b890"; + ctx.fillRect(x - 0.5, base - h * 0.62, 1, 1.2); + } + } + + // A thrower's perch: a lit window with a shutter (kind 0) or a roof ledge (kind 1) and the villager in it. + function thrower(ctx, v, x, deck, kind, t) { + const clock = v.clock; + const wind = t.state === "wind" ? 1 - clamp(t.t / WIND_MS, 0, 1) : t.state === "spent" ? 1 : 0; + if (kind === 0) { + const cy = Y(deck + 8.5); + ctx.fillStyle = "#120c14"; + ctx.fillRect(x - 2.4, cy - 3, 4.8, 5.8); + ctx.fillStyle = "#ffb85a"; + ctx.fillRect(x - 1.9, cy - 2.5, 3.8, 4.8); + glow(ctx, WARM, x, cy, 7, 0.5); + // Him: a face, a nightcap and a shoulder, the pitchfork arm cocked back as he winds up. + ctx.fillStyle = "#281a20"; + ellipse(ctx, x, cy + 2.3, 1.6, 1.3); + ctx.fill(); + ctx.fillStyle = "#d9b08a"; + disc(ctx, x, cy - 0.3, 0.95); + ctx.fillStyle = "#e8e0d0"; + poly(ctx, [[x - 1, cy - 0.9], [x + 0.2, cy - 2.7], [x + 1.1, cy - 0.9]]); + ctx.fill(); + ctx.fillStyle = "#1c1014"; + disc(ctx, x - 0.35, cy - 0.35, 0.18); + disc(ctx, x + 0.35, cy - 0.35, 0.18); + ctx.fillRect(x - 0.4, cy + 0.2, 0.8, 0.25); + if (t.state !== "spent") { + const ang = -0.5 - wind * 0.9; + ctx.save(); + ctx.translate(x + 0.6, cy + 1.6); + ctx.rotate(ang); + ctx.strokeStyle = "#5a4028"; + ctx.lineWidth = 0.28; + seg(ctx, -0.5, 0, 3.6, 0); + ctx.strokeStyle = "#b0b4c0"; + ctx.lineWidth = 0.2; + seg(ctx, 3.6, -0.6, 3.6, 0.6); + for (const o of [-0.6, 0, 0.6]) seg(ctx, 3.6, o, 4.8, o); + ctx.restore(); + } + // The open shutters. + ctx.fillStyle = "#3a2a1e"; + ctx.fillRect(x - 3.4, cy - 3, 1, 5.8); + ctx.fillRect(x + 2.4, cy - 3, 1, 5.8); + return; + } + // On the roof: a ledge of tiles, and a villager raising a torch. + const ry = Y(deck + 11); + ctx.fillStyle = "#1a1220"; + poly(ctx, [[x - 4.6, ry + 1.2], [x - 3.4, ry - 0.2], [x + 3.4, ry - 0.2], [x + 4.6, ry + 1.2]]); + ctx.fill(); + ctx.fillStyle = "#2c2030"; + ctx.fillRect(x - 3.4, ry - 0.2, 6.8, 0.35); + ctx.fillStyle = "#1c141c"; + ellipse(ctx, x, ry - 1.9, 1.1, 1.8); + ctx.fill(); + ctx.fillStyle = "#d4aa84"; + disc(ctx, x, ry - 4.2, 0.9); + ctx.fillStyle = "#14101a"; + poly(ctx, [[x - 1.1, ry - 4.7], [x, ry - 6.1], [x + 1.1, ry - 4.7]]); + ctx.fill(); + if (t.state !== "spent") { + const up = 0.7 + wind * 0.9; + ctx.strokeStyle = "#1c141c"; + ctx.lineWidth = 0.4; + seg(ctx, x + 0.6, ry - 2.8, x + 1.4 + wind * 0.8, ry - 2.8 - up * 1.8); + torch(ctx, x + 1.4 + wind * 0.8, ry - 2.8 - up * 1.8, -0.2, clock, 0.9); + } + } + + // A torch held at (x, y), tilted by `ang` off upright: the stick and a flame that flickers. + function torch(ctx, x, y, ang, clock, size = 1) { + ctx.save(); + ctx.translate(x, y); + ctx.rotate(ang); + ctx.strokeStyle = "#3a2414"; + ctx.lineWidth = 0.34 * size; + seg(ctx, 0, 1.2 * size, 0, -0.3 * size); + const f = 1 + 0.18 * Math.sin(clock / 60 + x * 3) + 0.1 * Math.sin(clock / 37 + y); + ctx.fillStyle = "#ff7a22"; + poly(ctx, [[-0.7 * size, -0.2 * size], [0, -2.5 * size * f], [0.75 * size, -0.2 * size]]); + ctx.fill(); + ctx.fillStyle = "#ffd25a"; + poly(ctx, [[-0.4 * size, -0.2 * size], [0, -1.6 * size * f], [0.45 * size, -0.2 * size]]); + ctx.fill(); + ctx.restore(); + glow(ctx, WARM, x, y - 1.2 * size, 4.4 * size, 0.55); + } + + // A pitchfork flying left: the shaft and three tines, along its line of flight. + function fork(ctx, x, y, ang) { + ctx.save(); + ctx.translate(x, y); + ctx.rotate(ang); + ctx.strokeStyle = "#5a4028"; + ctx.lineWidth = 0.3; + seg(ctx, -1.8, 0, 1.6, 0); + ctx.strokeStyle = "#c4c8d4"; + ctx.lineWidth = 0.2; + seg(ctx, -1.8, -0.7, -1.8, 0.7); + for (const o of [-0.7, 0, 0.7]) seg(ctx, -1.8, o, -3.1, o); + ctx.restore(); + } + + // A horse seen side on at (x, base), facing `dir`: galloping (`pose` "run"), rearing, or standing, its color, `lift` of the legs tucking in the air. + function horse(ctx, x, base, dir, pose, clock, color, mane, tuck = 0) { + ctx.save(); + ctx.translate(x, base); + ctx.scale(dir, 1); + const rear = pose === "rear"; + if (rear) ctx.rotate(-0.75); + const gal = Math.sin(clock / 65 + x); + // Legs behind the body. + ctx.strokeStyle = "#1c1218"; + ctx.lineWidth = 0.55; + const leg = (hx, ph, front) => { + const sw = rear && front ? -1.2 : Math.sin(clock / 65 + ph) * (pose === "run" ? 1.5 : 0.3) * (1 - tuck); + const lift = pose === "run" ? Math.max(0, Math.cos(clock / 65 + ph)) * 0.8 * (1 - tuck) : 0; + ctx.beginPath(); + ctx.moveTo(hx, -2.1); + ctx.lineTo(hx + sw * 0.5, -1.1 - lift - tuck); + ctx.lineTo(hx + sw, -lift - tuck * 1.2); + ctx.stroke(); + }; + leg(-1.7, 0, false); + leg(-1.1, 1.6, false); + ctx.fillStyle = color; + // The body, the neck and the head. + ellipse(ctx, 0, -2.9 + gal * 0.12, 2.5, 1.25); + ctx.fill(); + ctx.beginPath(); + ctx.moveTo(1.3, -3.4); + ctx.quadraticCurveTo(2.5, -4.6, 2.9, -5.6); + ctx.lineTo(3.9, -5.3); + ctx.quadraticCurveTo(3.4, -4.0, 2.2, -2.7); + ctx.closePath(); + ctx.fill(); + ctx.beginPath(); + ctx.moveTo(2.9, -5.9); + ctx.lineTo(4.9, -5.3); + ctx.lineTo(4.7, -4.5); + ctx.lineTo(2.9, -4.8); + ctx.closePath(); + ctx.fill(); + ctx.fillStyle = mane; + poly(ctx, [[1.1, -3.7], [2.2, -5.5], [2.8, -6.1], [2.6, -5.0], [1.7, -3.4]]); + ctx.fill(); + poly(ctx, [[-2.4, -3.2], [-3.6, -2.3 + gal * 0.4], [-3.4, -3.8], [-2.3, -3.6]]); + ctx.fill(); + ctx.fillStyle = "#fff4e0"; + disc(ctx, 3.8, -5.35, 0.22); + ctx.fillStyle = "#ff5a3a"; + disc(ctx, 3.85, -5.35, 0.1); + leg(1.5, 0.8, true); + leg(1.0, 2.4, true); + ctx.restore(); + } + + // A villager of the mob, running right: legs, a cloak, the head, and a torch or a pitchfork held high. + function mobber(ctx, x, base, i, clock, close) { + const ph = clock / 80 + i * 1.7; + const h = 4.6 + rnd(i, 1) * 0.6; + ctx.strokeStyle = "#0c0810"; + ctx.lineWidth = 0.5; + seg(ctx, x - 0.2, base - 2, x - 0.2 + Math.sin(ph) * 1.1, base - Math.max(0, Math.cos(ph)) * 0.7); + seg(ctx, x + 0.2, base - 2, x + 0.2 - Math.sin(ph) * 1.1, base - Math.max(0, -Math.cos(ph)) * 0.7); + ctx.fillStyle = ["#2a1c22", "#1e2230", "#2a2418", "#201a2c"][i % 4]; + poly(ctx, [[x - 1.3, base - 1.7 + Math.sin(ph * 2) * 0.1], [x - 0.9, base - h + 1], [x + 0.8, base - h + 1], [x + 1.1, base - 1.7], [x + 0.2, base - 1.2]]); + ctx.fill(); + ctx.fillStyle = "#cfa882"; + disc(ctx, x + 0.2, base - h + 0.2, 0.85); + ctx.fillStyle = "#14101a"; + if (i % 3 === 0) poly(ctx, [[x - 0.9, base - h + 0.1], [x + 0.2, base - h - 1.2], [x + 1.3, base - h + 0.1]]); + else ctx.fillRect(x - 0.9, base - h - 0.5, 2.2, 0.7); + ctx.fill(); + // The arm and what it holds, lit by the torches. + const ax = x + 0.7; + const ay = base - h + 1.6; + ctx.strokeStyle = "#1c141c"; + ctx.lineWidth = 0.4; + if (i % 3 === 1) { + seg(ctx, ax, ay, ax + 0.9, ay - 1.8); + ctx.strokeStyle = "#5a4028"; + ctx.lineWidth = 0.28; + seg(ctx, ax + 0.9, ay + 0.4, ax + 1.4, ay - 4.4); + ctx.strokeStyle = "#c0c4d0"; + ctx.lineWidth = 0.2; + seg(ctx, ax + 0.8, ay - 4.4, ax + 2.0, ay - 4.4); + for (const o of [0.8, 1.4, 2.0]) seg(ctx, ax + o, ay - 4.4, ax + o + 0.1, ay - 5.6); + } else { + seg(ctx, ax, ay, ax + 0.9, ay - 1.6); + torch(ctx, ax + 1.0, ay - 2.4 + Math.sin(ph) * 0.2, 0.1 + 0.05 * Math.sin(ph), clock + i * 40, 1); + } + void close; + } + + // A moonhound at a gallop, running right: lean grey, long legs, eyes that glow. + function hound(ctx, x, base, i, clock) { + const ph = clock / 55 + i * 2.1; + const bob = Math.sin(ph) * 0.35; + ctx.save(); + ctx.translate(x, base); + ctx.strokeStyle = "#8a90a4"; + ctx.lineWidth = 0.42; + for (const [lx, o] of [[-1.5, 0], [-0.9, 1.6], [1.0, 0.8], [1.6, 2.4]]) { + const sw = Math.sin(ph + o) * 1.5; + ctx.beginPath(); + ctx.moveTo(lx, -1.9); + ctx.lineTo(lx + sw * 0.5, -1.0 - Math.max(0, Math.cos(ph + o)) * 0.7); + ctx.lineTo(lx + sw, -Math.max(0, Math.cos(ph + o)) * 0.9); + ctx.stroke(); + } + ctx.fillStyle = "#a4abbe"; + ellipse(ctx, 0, -2.6 + bob, 2.2, 0.95); + ctx.fill(); + poly(ctx, [[1.5, -3.2 + bob], [3.2, -3.9 + bob], [4.5, -3.3 + bob], [3.3, -2.6 + bob], [1.6, -2.4 + bob]]); + ctx.fill(); + ctx.fillStyle = "#6a7088"; + poly(ctx, [[2.4, -3.8 + bob], [2.9, -4.9 + bob], [3.3, -3.8 + bob]]); + ctx.fill(); + poly(ctx, [[-2.1, -2.7 + bob], [-3.8, -3.4 + bob + Math.sin(ph) * 0.3], [-2.0, -2.3 + bob]]); + ctx.fill(); + ctx.fillStyle = "#ffd25a"; + disc(ctx, 3.3, -3.4 + bob, 0.2); + ctx.restore(); + glow(ctx, "255,210,90", x + 3.3, base - 3.4 + bob, 1.6, 0.5); + } + + // The mob behind the wagon: the front man `gap` back, the villagers and the hounds streaming after, + // lit by their own torches. + function theMob(ctx, v, R, c, fx) { + const you = v.round.you; + const clock = v.clock; + const gd = fx.wagonGap; + const front = you.x - gd; + const close = clamp(1 - gd / GAP_MAX, 0, 1); + glow(ctx, WARM, front - 6, Y(roadAt(R, front) + 6), 26, 0.35 + 0.35 * close); + // The hounds run ahead of the men. + for (let i = 0; i < 3; i++) { + const hx = front + 3.6 - i * 3.2 + Math.sin(clock / 300 + i) * 0.5; + hound(ctx, hx, Y(deckNear(R, hx) - WHEEL), i, clock); + } + for (let i = 0; i < 12; i++) { + const mx = front - 1.5 - i * 2.4 - rnd(i, 4) * 1.2; + if (mx < v.round.camX - 4) break; + const by = Y(deckNear(R, mx) - WHEEL) + (i % 2 ? 0.15 : -0.1); + mobber(ctx, mx, by, i, clock, close); + } + } + + /* ------------------------------------------------------------- the wagon */ + + // The wagon, side on: the horse, the pole, the bed with its wheels, the hay load (charred and burning + // when a torch has landed). Planny stands on the bed; the game draws him after this. + function wagon(ctx, v, R, c) { + const you = v.round.you; + const clock = v.clock; + const air = c.line < 0; + const x = c.done && c.restX !== undefined ? c.restX : you.x; + const y = c.done ? Y(deckNear(R, x)) : Y(you.y); + const tilt = air ? clamp(you.vy / 90, -0.22, 0.22) : 0; + const burning = c.fireMs > 0; + ctx.save(); + ctx.translate(x, y); + ctx.rotate(-tilt); + // The horse, galloping hard, ahead of the pole. + horse(ctx, 8.6, WHEEL - 0.1 + (air ? 0 : Math.sin(clock / 65) * 0.12), 1, c.done ? "stand" : "run", clock, "#5a4030", "#1c1410", air ? 0.8 : c.braking ? 0.3 : 0); + // The harness and the pole. + ctx.strokeStyle = "#3a2616"; + ctx.lineWidth = 0.4; + seg(ctx, 3.2, 0.3, 7.6, -1.4); + ctx.strokeStyle = "#8a6a44"; + ctx.lineWidth = 0.14; + seg(ctx, 7.8, -2.2, 3.4, -0.6); + // The bed and the side rails. + ctx.fillStyle = "#6a4a2c"; + ctx.fillRect(-5.4, 0, 9, 0.9); + ctx.fillStyle = "#4a3220"; + ctx.fillRect(-5.4, 0.7, 9, 0.35); + ctx.fillStyle = "#7c5a36"; + ctx.fillRect(-5.4, -2.8, 0.5, 2.8); + ctx.fillRect(2.9, -2.4, 0.5, 2.4); + // The hay: a heap of bales over the bed's back half. + const hay = burning ? ["#6a4a20", "#4a3418", "#2c2014"] : ["#e0bf5a", "#c8a040", "#a68230"]; + ctx.fillStyle = hay[0]; + ctx.beginPath(); + ctx.moveTo(-5.0, 0); + ctx.quadraticCurveTo(-5.2, -3.8, -3.2, -4.2); + ctx.quadraticCurveTo(-1.2, -4.6, -0.6, -2.4); + ctx.lineTo(-0.5, 0); + ctx.closePath(); + ctx.fill(); + ctx.strokeStyle = hay[2]; + ctx.lineWidth = 0.14; + for (let k = 0; k < 6; k++) seg(ctx, -4.6 + k * 0.7, -0.6, -4.4 + k * 0.7 + (k % 2) * 0.4, -3.6 + (k % 3) * 0.3); + ctx.fillStyle = hay[1]; + ctx.fillRect(-5, -2.1, 4.4, 0.25); + ctx.fillRect(-4.4, -3.5, 3.4, 0.25); + // The driver's footboard. + ctx.fillStyle = "#4a3220"; + ctx.fillRect(1.2, -1.2, 1.7, 1.2); + ctx.fillStyle = "#3a2616"; + ctx.fillRect(1.2, -1.2, 1.7, 0.3); + // The wheels, spokes turning with the road. + const roll = (x * 0.55) % TAU; + for (const wx of [-3.2, 2.0]) { + ctx.save(); + ctx.translate(wx, 0.2); + ctx.fillStyle = "rgba(0,0,0,0.0)"; + ctx.strokeStyle = "#2a1c12"; + ctx.lineWidth = 0.5; + ctx.beginPath(); + ctx.arc(0, 0, WHEEL - 0.2, 0, TAU); + ctx.stroke(); + ctx.strokeStyle = "#7c5a36"; + ctx.lineWidth = 0.28; + ctx.beginPath(); + ctx.arc(0, 0, WHEEL - 0.55, 0, TAU); + ctx.stroke(); + ctx.lineWidth = 0.22; + for (let k = 0; k < 6; k++) seg(ctx, 0, 0, Math.cos(roll + (k * TAU) / 6) * (WHEEL - 0.6), Math.sin(roll + (k * TAU) / 6) * (WHEEL - 0.6)); + ctx.fillStyle = "#c9a24a"; + disc(ctx, 0, 0, 0.35); + ctx.restore(); + } + ctx.restore(); + // Sparks off the wheels while braking, dust behind. + if (!c.done && c.line >= 0) { + const f = clamp(c.v / WAGON_V, 0.4, 1.4); + for (let k = 0; k < 8; k++) { + const p = (clock / (300 + (k % 3) * 60) + k * 0.137) % 1; + ctx.fillStyle = `rgba(120,108,128,${(1 - p) * 0.4})`; + disc(ctx, x - 5 - p * 4 * f * (0.6 + rnd(k, 1)), y + WHEEL - 0.4 - p * (0.6 + rnd(k, 2) * 1.2), 0.25 + p * 0.35); + } + if (c.braking) { + for (let k = 0; k < 7; k++) { + const p = (clock / 160 + k * 0.19) % 1; + ctx.fillStyle = `rgba(255,${180 + ((k * 17) % 60)},90,${1 - p})`; + ctx.fillRect(x - 3.2 - p * 3.5, y + WHEEL - 0.5 - p * 0.9 * rnd(k, 3), 0.28, 0.28); + ctx.fillRect(x + 2.0 - p * 3, y + WHEEL - 0.5 - p * 0.9 * rnd(k, 4), 0.28, 0.28); + } + } + } + } + + // The hay's fire, in front of Planny: flames licking up off the load, smoke streaming back. + function hayFire(ctx, v, c) { + const you = v.round.you; + const clock = v.clock; + const x = you.x; + const y = Y(you.y); + const k = clamp(c.fireMs / 500, 0.3, 1); + for (let i = 0; i < 9; i++) { + const fx0 = x - 4.8 + (i % 5) * 0.95 + rnd(i, 1) * 0.3; + const hh = (1.4 + rnd(i, 2) * 1.5 + Math.sin(clock / 70 + i * 2) * 0.5) * k; + const by = y - 1.6 - (i % 3) * 0.55; + ctx.fillStyle = i % 2 ? "#ff7a22" : "#ff5a1a"; + poly(ctx, [[fx0 - 0.55, by], [fx0 + Math.sin(clock / 90 + i) * 0.3, by - hh * 1.4], [fx0 + 0.55, by]]); + ctx.fill(); + ctx.fillStyle = "#ffd25a"; + poly(ctx, [[fx0 - 0.3, by], [fx0, by - hh * 0.8], [fx0 + 0.3, by]]); + ctx.fill(); + } + glow(ctx, "255,120,40", x - 2.8, y - 3, 9, 0.5 * k + 0.1 * Math.sin(clock / 60)); + for (let i = 0; i < 6; i++) { + const p = (clock / 700 + i * 0.17) % 1; + ctx.fillStyle = `rgba(40,34,44,${(1 - p) * 0.5})`; + disc(ctx, x - 4 - p * 7, y - 4 - p * 3.4, 0.5 + p * 1.1); + } + } + + /* ------------------------------------------------------------- the world */ + + function moving(ctx, v, cam) { + const R = ride(v); + const round = v.round; + const c = round && round.runner; + if (!R || !c || c.id !== "wagon") return; + FH = v.g.FIELD_H; + const clock = v.clock; + cam = Math.round(cam * 8) / 8; + const lo = cam - 10; + const hi = cam + FW + 10; + sky(ctx, cam, clock); + skyline(ctx, cam, 0.14, 14, FH - 18, 7, 13, "#0c1128", "#0a0e22", 0, clock, 10); + skyline(ctx, cam, 0.4, 22, FH - 13, 11, 18, "#171630", "#0f0e20", 0.7, clock, 20); + street(ctx, v, R, cam, lo, hi); + bridge(ctx, v, R, cam, lo, hi); + road(ctx, R, lo, hi); + gaps(ctx, v, R, lo, hi); + // Checkpoints: a lamp post and a bell. + R.checks.forEach((x, i) => { + if (x > lo && x < hi) checkpoint(ctx, v, x, Y(roadAt(R, x)), i <= c.check); + }); + if (R.finish > lo - 14 && R.finish < hi) gate(ctx, v, R, R.finish); + // The throwers' perches, the things in the road, the loose horses. + R.throwers.forEach(([x, line, kind], i) => { + if (x > lo - 6 && x < hi + 6) thrower(ctx, v, x, deckNear(R, x), kind, c.throwers[i]); + }); + R.blocks.forEach(([x, line, kind], i) => { + if (x > lo && x < hi && !c.smashed[i]) block(ctx, x, Y(roadAt(R, x)), kind, i); + }); + R.horses.forEach(([hx, line], i) => { + const h = c.horses[i]; + if (h.state === "gone" || h.x < lo - 6 || h.x > hi + 6) return; + const dir = h.state === "fled" ? -1 : -1; + const base = Y(roadAt(R, h.x)); + horse(ctx, h.x, h.state === "hit" ? base - 0.5 : base, dir, h.state === "rear" ? "rear" : h.state === "wait" ? "stand" : "run", clock, "#c9c2b6", "#5a5460"); + if (h.state === "rear") glow(ctx, "255,230,200", h.x, base - 4, 6, 0.18); + }); + // The end of the road: the green's grass over the sky. + for (const [a, b, top] of v.spec.ground) if (a >= R.finish - 1 && b > lo && a < hi) ground(ctx, v, LOOKS.wagon, a, b, top); + const fx = v.fx || {}; + fx.wagonGap = fx.wagonGap === undefined ? c.gap : fx.wagonGap + (c.gap - fx.wagonGap) * 0.22; + if (!c.done) theMob(ctx, v, R, c, fx); + wagon(ctx, v, R, c); + } + + // A lamp post with a bell: dim until passed, then lit green. + function checkpoint(ctx, v, x, base, passed) { + ctx.fillStyle = "#1c1a24"; + ctx.fillRect(x - 0.3, base - 8, 0.6, 8); + ctx.fillRect(x - 0.3, base - 8, 2.4, 0.5); + ctx.fillStyle = passed ? "#9cffb0" : "#ffcf7a"; + ctx.fillRect(x + 1.5, base - 7.6, 1, 1.4); + glow(ctx, passed ? "120,255,160" : WARM, x + 2, base - 7, 6, passed ? 0.55 : 0.4); + ctx.fillStyle = "#c9a24a"; + poly(ctx, [[x - 1.4, base - 5.2], [x - 0.9, base - 6.2], [x - 0.4, base - 5.2]]); + ctx.fill(); + } + + // The village gate at the end of the road: two stone posts with braziers, and the green beyond. + function gate(ctx, v, R, x) { + const base = Y(deckNear(R, x - 14) - WHEEL); + for (const px of [x + 3, x + 24]) { + ctx.fillStyle = "#3c3a4a"; + ctx.fillRect(px, base - 15, 2.4, 15); + ctx.fillStyle = "#54516a"; + ctx.fillRect(px - 0.4, base - 15.6, 3.2, 0.8); + ctx.fillStyle = "#1c1a24"; + ctx.fillRect(px - 0.2, base - 17.4, 2.8, 1.8); + ctx.fillStyle = "#ff8a30"; + poly(ctx, [[px + 0.2, base - 17.3], [px + 1.2, base - 20 + Math.sin(v.clock / 70 + px) * 0.4], [px + 2.2, base - 17.3]]); + ctx.fill(); + glow(ctx, WARM, px + 1.2, base - 18.4, 9, 0.5); + } + ctx.strokeStyle = "#2a2434"; + ctx.lineWidth = 0.5; + ctx.beginPath(); + ctx.moveTo(x + 5.4, base - 14); + ctx.quadraticCurveTo(x + 14, base - 17, x + 24, base - 14); + ctx.stroke(); + } + + /* ------------------------------------------------------------ in front */ + + // A washing line: two poles, a sagging rope with shirts hanging down to its underside `y`. + // An inn sign: a post, a bracket and a board swinging from it, down to `y`. + function low(ctx, v, R, x0, x1, y, kind, i) { + const clock = v.clock; + const under = Y(y); + const road = Y(roadAt(R, x0)); + if (kind === 0) { + const xa = x0 - 1.6; + const xb = x1 + 1.6; + ctx.fillStyle = "#2c2018"; + ctx.fillRect(xa - 0.25, under - 7.4, 0.5, road - under + 7.4); + ctx.fillRect(xb - 0.25, under - 7.4, 0.5, road - under + 7.4); + ctx.strokeStyle = "#8a7a60"; + ctx.lineWidth = 0.14; + ctx.beginPath(); + ctx.moveTo(xa, under - 5.6); + ctx.quadraticCurveTo((xa + xb) / 2, under - 4.6, xb, under - 5.6); + ctx.stroke(); + const cols = ["#d8d4cc", "#b04a4a", "#6a8ac0", "#e0c878", "#9a7ac0"]; + for (let k = 0; k < 4; k++) { + const px = xa + 1.2 + k * ((xb - xa - 2.4) / 3); + const sway = Math.sin(clock / 330 + k + i) * 0.25; + const drop = 4.6 - (k % 2) * 0.4; + ctx.fillStyle = cols[(k + i) % cols.length]; + poly(ctx, [[px - 1, under - 5.2], [px + 1, under - 5.2], [px + 1.1 + sway, under - 5.2 + drop - 0.1], [px - 0.9 + sway, under - 5.2 + drop]]); + ctx.fill(); + ctx.fillStyle = "rgba(0,0,0,0.18)"; + ctx.fillRect(px - 1, under - 5.2, 2, 0.3); + } + glow(ctx, WARM, (x0 + x1) / 2, under - 2, 6, 0.12); + return; + } + const px = x1 + 2.6; + ctx.fillStyle = "#3a2616"; + ctx.fillRect(px - 0.3, under - 7.2, 0.6, road - under + 7.2); + ctx.fillRect(x0 - 0.8, under - 6.9, px - x0 + 0.8, 0.5); + ctx.strokeStyle = "#8a8a98"; + ctx.lineWidth = 0.12; + const sw = Math.sin(clock / 420 + i) * 0.35; + seg(ctx, x0, under - 6.4, x0 + sw * 0.4, under - 2.4); + seg(ctx, x1, under - 6.4, x1 + sw * 0.4, under - 2.4); + ctx.fillStyle = "#5a3c20"; + ctx.fillRect(x0 - 0.9 + sw, under - 2.6, x1 - x0 + 1.8, 2.7); + ctx.fillStyle = "#c9a24a"; + ctx.fillRect(x0 - 0.9 + sw, under - 2.6, x1 - x0 + 1.8, 0.3); + ctx.fillStyle = "#e8d8a8"; + const mx = (x0 + x1) / 2 + sw; + ctx.fillRect(mx - 0.8, under - 1.9, 1.3, 1.3); + ctx.strokeStyle = "#e8d8a8"; + ctx.lineWidth = 0.18; + ctx.beginPath(); + ctx.arc(mx + 0.9, under - 1.3, 0.5, -1.4, 1.4); + ctx.stroke(); + glow(ctx, WARM, mx, under - 1.2, 5, 0.18); + } + + // A see-through glyph over an obstacle: a pair of chevrons and (for the first few) the word. + function glyph(ctx, v, t) { + const up = t.answer === "JUMP"; + const col = ANSWER_COLORS[t.answer]; + const pulse = 0.85 + 0.15 * Math.sin(v.clock / 260 + t.lead); + const bob = Math.sin(v.clock / 260 + t.lead) * 0.35 * (up ? -1 : 1); + const cy = Math.max(9, Math.min(FH - 7, FH - t.up)) + bob; + const ay = cy + (up ? -2.6 : 2.6); + ctx.save(); + ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA; + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + const dir = up ? -1 : 1; + for (const [pass, w, c] of [[0, 1.3, "rgba(4,4,16,0.8)"], [1, 0.6, col]]) { + ctx.strokeStyle = c; + ctx.lineWidth = w; + for (let k = 0; k < 2; k++) { + const oy = ay + (k - 0.5) * 1.5 * dir - dir * 0.2; + if (k === 1 && pass === 1) ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA * 0.55; + ctx.beginPath(); + ctx.moveTo(t.x - 1.7, oy - dir * 0.9); + ctx.lineTo(t.x, oy + dir * 0.9); + ctx.lineTo(t.x + 1.7, oy - dir * 0.9); + ctx.stroke(); + } + ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA; + } + if (t.words) label(ctx, t.answer, t.x, cy + (up ? 1.2 : -1.2), 2.3, col, "center"); + ctx.restore(); + } + + // The mob's meter along the top left: how far back they are, red as they close, with a word when it matters. + function meter(ctx, v, c) { + const x = 4; + const y = 9.2; + const w = 34; + const near = clamp(1 - c.gap / GAP_MAX, 0, 1); + ctx.fillStyle = "rgba(6,4,14,0.62)"; + ctx.fillRect(x - 0.8, y - 0.8, w + 1.6, 2.6); + ctx.fillStyle = "#1c1824"; + ctx.fillRect(x, y, w, 1); + const col = near < 0.35 ? "#6ee08a" : near < 0.62 ? "#ffc23a" : "#ff4a3a"; + ctx.fillStyle = col; + ctx.fillRect(x, y, w * near, 1); + // The catch line, and the panic line. + ctx.fillStyle = "#ffffff"; + ctx.fillRect(x + w * (1 - CATCH_GAP / GAP_MAX), y - 0.3, 0.25, 1.6); + ctx.fillStyle = "rgba(255,255,255,0.5)"; + ctx.fillRect(x + w * (1 - PANIC_ON / GAP_MAX), y - 0.2, 0.18, 1.4); + const word = c.fireMs > 0 ? "HAY ON FIRE" : c.gap < PANIC_ON ? "THEY ARE CLOSE" : "THE MOB"; + const wc = c.fireMs > 0 || c.gap < PANIC_ON ? (Math.sin(v.clock / 110) > 0 ? "#ff6a4a" : "#ffd25a") : "#d8d0e0"; + label(ctx, word, x, y + 3.1, 1.7, wc, "left"); + torch(ctx, x + w * near, y - 0.6, 0, v.clock, 0.7); + } + + function front(ctx, v) { + const R = ride(v); + const round = v.round; + const c = round && round.runner; + if (!R || !c || c.id !== "wagon") return; + FH = v.g.FIELD_H; + const cam = Math.round(round.camX * 8) / 8; + const lo = cam - 8; + const hi = cam + FW + 8; + if (c.fireMs > 0 && !c.done) hayFire(ctx, v, c); + R.lows.forEach(([x0, x1, y, kind], i) => { + if (x1 >= lo - 4 && x0 <= hi) low(ctx, v, R, x0, x1, y, kind, i); + }); + // The throws in the air. + for (const p of c.props) { + if (p.x === undefined) continue; + if (p.dead && !p.kind) continue; + if (p.dead) { + // A torch burned out on the road: a last flicker. + if (p.age < 400) { + ctx.globalAlpha = 1 - p.age / 400; + torch(ctx, p.x, Y(p.y) , 1.2, v.clock, 0.8); + ctx.globalAlpha = 1; + } + continue; + } + const ahead = propDir(p); + if (p.kind) torch(ctx, p.x, Y(p.y), ((v.clock / 110) % TAU) * 1, v.clock, 1.1); + else fork(ctx, p.x, Y(p.y), ahead); + } + // What to do about what is coming, over it. + if (!c.done) for (const t of telegraphs(R, round.you.x)) glyph(ctx, v, t); + // Splinters, sparks and straw from a crash, tumbling. + const bits = v.fx && v.fx.wagonBits; + if (bits) { + for (const b of bits) { + const t = (v.fx.clock - b.t0) / 1000; + if (t < 0 || t > 0.9) continue; + ctx.save(); + ctx.translate(b.x + b.vx * t, FH - (b.y + b.vy * t - 30 * t * t)); + ctx.rotate(b.rot + b.vr * t); + ctx.globalAlpha = clamp(1.6 - t * 1.6, 0, 1); + ctx.fillStyle = b.c; + ctx.fillRect(-b.w / 2, -0.12, b.w, 0.24); + ctx.restore(); + } + ctx.globalAlpha = 1; + } + // The mob closing in: the edge of the screen goes red. + if (!c.done) { + const red = clamp((PANIC_ON + 6 - c.gap) / 14, 0, 1); + if (red > 0) { + ctx.fillStyle = rgrad(ctx, cam, FH / 2, 40, [[0, "rgba(255,50,30,0.5)"], [1, "rgba(255,50,30,0)"]]); + ctx.globalAlpha = red * (0.5 + 0.3 * Math.sin(v.clock / 120)); + ctx.fillRect(cam, 0, 40, FH); + ctx.globalAlpha = 1; + } + meter(ctx, v, c); + } + } + + // The direction a pitchfork flies, as an angle for drawing it. + const propDir = (p) => Math.atan2(p.y1 - p.y0, p.x0 - p.x1); + + const dim = () => 0; + + /* -------------------------------------------------------------- lights */ + + function lights(v, add) { + const R = ride(v); + const round = v.round; + const c = round && round.runner; + if (!R || !c || c.id !== "wagon") return; + const you = round.you; + const lo = round.camX - 10; + const hi = round.camX + FW + 10; + add(you.x + 3, you.y + 2.2, 10, 0.6); + if (c.fireMs > 0) add(you.x - 2.5, you.y + 2.5, 12, 0.9); + add(you.x - c.gap, roadAt(R, you.x - c.gap) + 5, 18 + 12 * clamp(1 - c.gap / GAP_MAX, 0, 1), 0.8); + R.checks.forEach((x, i) => { + if (x > lo && x < hi) add(x + 2, roadAt(R, x) + 7, i <= c.check ? 8 : 7, i <= c.check ? 0.6 : 0.5); + }); + R.throwers.forEach(([x, , kind], i) => { + if (x > lo && x < hi && c.throwers[i].state !== "spent") add(x, deckNear(R, x) + (kind ? 11 : 8.5), 6, 0.45); + }); + for (const p of c.props) if (!p.dead && p.kind && p.x !== undefined) add(p.x, p.y, 6, 0.6); + if (v.fx && v.fx.wagonLand && v.fx.clock - v.fx.wagonLand.t0 < 260) add(you.x, you.y + 1, 6, 0.4); + } + + /* -------------------------------------------------------------- events */ + + // A throttle on a repeating cue. + function gateOnce(fx, key, ms) { + if ((fx[key] || 0) > fx.clock) return false; + fx[key] = fx.clock + ms; + return true; + } + // Wood, straw or sparks flying out of a spot. + function splinter(fx, x, y, colors) { + fx.wagonBits = (fx.wagonBits || []).filter((b) => fx.clock - b.t0 < 1000); + for (let k = 0; k < 10; k++) fx.wagonBits.push({ x, y, t0: fx.clock, vx: (rnd(k, 1) - 0.5) * 24, vy: 8 + rnd(k, 2) * 14, rot: rnd(k, 3) * TAU, vr: (rnd(k, 4) - 0.5) * 22, w: 0.5 + rnd(k, 5) * 0.9, c: colors[k % colors.length] }); + } + + // What the pack's events look and sound like; true when the event is its own. Each of its + // sounds plays once, from EVENT_VOICE. + function react(e, k) { + const { tone, shake, flash, burst, float, ring, fx } = k; + const voice = EVENT_VOICE[e.type]; + if (!voice) return false; + // The brake repeats as it is held; keep it from stacking. + if (e.type === "wagonBrake" && !gateOnce(fx, "wagonBrakeMs", 220)) return true; + say(tone, voice[0], voice[1], 0.5); + switch (e.type) { + case "wagonJump": + burst(e.x, e.y, "#8a8496", 5, 7, 300); + break; + case "wagonLand": + fx.wagonLand = { t0: fx.clock, big: Boolean(e.big) }; + burst(e.x, e.y, "#8a8496", e.big ? 14 : 6, e.big ? 12 : 8, 360); + if (e.big) shake(200, 0.5); + break; + case "wagonLaunch": + burst(e.x, e.y, "#ffcf7a", 12, 14, 380); + float(e.x, e.y + 5, e.last ? "Gate!" : "Jump!", GOLD, 2.2); + break; + case "wagonBrake": + burst(e.x, e.y, "#ffb04a", 4, 6, 240); + break; + case "wagonCrash": + shake(320, 1); + flash("#ffd8a0", 200); + burst(e.x, e.y + 1, "#8a5a30", 16, 16, 520); + splinter(fx, e.x, e.y + 1, ["#8a5a30", "#5a3c20", "#c9a24a"]); + break; + case "wagonCheck": + float(e.x, e.y + 5, "Checkpoint", GOLD, 2.2); + ring(e.x, e.y + 3, "#7dffa0", 1, 8, 500); + break; + case "wagonFinish": + shake(260, 0.7); + burst(e.x, e.y, "#6a9a4a", e.big ? 22 : 14, 13, 560); + float(e.x, e.y + 5, "Made it!", GOLD, 2.6); + break; + case "wagonPanic": + float(e.x, e.y + 6, "Faster!", "#ff8a5a", 2.2); + break; + case "wagonCatch": + shake(360, 1.2); + flash("#ff5a30", 240); + float(e.x, e.y + 6, "They got you!", "#ff6a4a", 2.4); + break; + case "wagonFire": + flash("#ff8a30", 180); + burst(e.x - 2, e.y + 2, "#ff8a30", 14, 12, 460); + float(e.x, e.y + 7, "Hay's on fire!", "#ffb04a", 2.2); + break; + case "wagonOut": + burst(e.x - 2, e.y + 3, "#8a8496", 8, 6, 460); + break; + case "wagonWind": + burst(e.x, e.y, "#ffb04a", 4, 4, 360); + break; + case "wagonThrow": + break; + case "wagonShot": + burst(e.x, e.y, e.kind ? "#ffb04a" : "#c4c8d4", 12, 13, 440); + splinter(fx, e.x, e.y, e.kind ? ["#ffb04a", "#ff7a22", "#ffd25a"] : ["#5a4028", "#c4c8d4"]); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + case "wagonEmber": + burst(e.x, e.y, "#ff8a30", 6, 6, 320); + break; + case "wagonRear": + burst(e.x, e.y + 0.5, "#8a8496", 6, 6, 400); + break; + case "wagonHorseHit": + burst(e.x, e.y, "#c9c2b6", 5, 8, 280); + break; + case "wagonHorseTurn": + burst(e.x, e.y, "#c9c2b6", 12, 12, 440); + float(e.x, e.y + 3, `+${e.points}`, GOLD, 2); + break; + default: + break; + } + return true; + } + + return freeze({ + looks: LOOKS, + backdrop, + ground, + shelf, + front, + moving, + dim, + monsters: freeze({}), + bosses: freeze({}), + missiles: freeze({}), + hazards: freeze({}), + powers: freeze({}), + lights, + react, + }); +} diff --git a/src/web-console/public/activities/ghoul-wagon.js b/src/web-console/public/activities/ghoul-wagon.js new file mode 100644 index 0000000..4630479 --- /dev/null +++ b/src/web-console/public/activities/ghoul-wagon.js @@ -0,0 +1,601 @@ +// Plan2Code Web Console - Ghoul Rush's Torch Mob, its rules: Hollow End Village's bonus round. YOU steal a hay wagon and race out of the village down the cobbled road and over the old stone bridge with a torch-and-pitchfork mob on your heels: jump the barrels, crates, ditches and spooked horses, duck the washing lines and inn signs, shoot (or dodge) the pitchforks and torches the villagers hurl from the windows and roofs, and jump the collapsed bridge off its ramp, as a stage pack that ghoul.js plugs in. +// +// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it, handed a +// kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js (it borrows the +// cart's track helpers). Pack fields used: `ride` (a hook that moves Planny himself, so no +// key walks him), `place` (Planny put down in a room: a room set up or a respawn) and +// `target` (a bolt strikes something that is no monster: a hurled torch or pitchfork, a +// spooked horse). It adds no monster, boss or hazard kind, so there is nothing to merge by +// name, and it draws NO random number. Its state lives in `round.runner` (the slot the +// bonus rides share, null in any other room; `id` "wagon"). +// +// THE TWIST: THE MOB. A pack of villagers and moonhounds runs behind the wagon, `gap` +// units back (GAP_START at the start, never over GAP_MAX). The mob runs at MOB_V, the wagon +// at its own speed, so a clean stretch (WAGON_V) wins ground and everything else loses it: +// DOWN held on the road (a duck, and the brake: BRAKE_V) slows the wagon, a hit shoves the +// mob HIT_CLOSE closer, a burning hay load draws it on (FIRE_BOOST) and its surge spans +// (`surge`, the bridge's run-up) quicken it. A torch or pitchfork shot out of the air pushes +// it back (TORCH_BACK, FORK_BACK, HORSE_BACK). Inside PANIC_ON the horses bolt (PANIC_V +// faster, until PANIC_OFF), which also carries the wagon further off a ramp. At CATCH_GAP +// the mob has you: a heart (cause "mob"), and it falls back to GAP_RESET. A torch that +// lands on the wagon is a heart (cause "torch") and sets the hay alight for FIRE_MS (the +// mob closes faster for as long, ducking on the hay smothers it SMOTHER times quicker). +// +// THE ROOM (spec.ride, see ghoul-rooms.js; `runner: "wagon"` marks it a ride room that the +// Cart's `place` leaves alone): +// +// - `track`: polylines [x, y] the wagon's deck rides, one per stretch of road; a gap between +// two lines is a DITCH or the collapsed bridge (jump it: the wagon flies on along its last +// slope, drops, and a fall below DERAIL_Y is a heart, cause "ditch", or "river" in +// `bridge`). A line ending rising at over RAMP_SLOPE launches (RAMP_POP): the bridge's ramp +// and the lip at the end (`finish`, where the gate and the green begin, lower). +// - `blocks` [x, line, kind] (kind 0 a barrel, 1 a crate: BARREL_W/CRATE_W by BLOCK_H, jump; +// smashed on a hit), `lows` [x0, x1, y, kind] (a washing line, kind 0, or an inn sign, +// kind 1: its underside is y, from there up, so DUCK it; y is 3.0 over the road under it), +// `throwers` [x, line, kind] (a villager in a window or on a roof at x: kind 0 hurls a +// pitchfork at chest height, DUCK it, kind 1 lobs a torch at the hay, JUMP it; either can +// be shot; he winds up WIND_MS once the wagon is WIND_NEAR short, then throws at where the +// wagon will be, PROJ_V fast: it meets a wagon at WAGON_V THROW_MEET short of him), +// `horses` [x, line] (a spooked horse: it rears HORSE_REAR_MS once the wagon is HORSE_NEAR +// short, then charges at HORSE_V, HORSE_W by HORSE_H over the road: jump it, or shoot it +// HORSE_HP times to turn it back), `checks`, `surge` ([x0, x1, extra] spans where the mob +// runs extra units a second faster), `bridge` ([x0, x1], the stone bridge, for the art), +// `finish` and `time` (the room's clock, ms). +// - The ground is the start's cobbles and the green's grass at the end only. +// +// THE WAGON (`round.runner`): { id, room, v, line, coyote, from, left, check, done, gap, +// panic, fireMs, catches, ... }. Planny rides at (you.x, you.y), facing right (`you.state` +// "run" on the road, "air" off it, `you.ducking` ducked on the hay). Up jumps (WAGON_JUMP_V +// against WAGON_G: about 7 high, 0.6 s, 26 across at WAGON_V), COYOTE_MS of grace off a +// line's end; down ducks and brakes; no key steers. A hit costs one of the round's five +// hearts (ghoul-bonus.js), not a life, and the wagon rolls on, Planny blinking safe +// BONUS_SAFE_MS; the last heart gone ends the round with nothing, at once. A derail puts it +// back on the road ahead. Causes: "barrel", "crate", "wash", "sign", "fork", "torch", +// "horse", "ditch", "river", "mob". Every obstacle is a number for the grade (`perf.total`, +// each id once in `perf.hits` if it ever cost a heart; a catch adds one of its own). Shooting +// a torch, a pitchfork or a horse is an act (ACTS_GOAL of them for the die). The steady die +// is the mob kept far: the gap's average over the ride at least STEADY_GAP. +// +// Checkpoints are passed at their x (`wagonCheck`); a restart after the last heart goes +// back to the last one passed (that ends the round, as the cart's does). +// +// WHAT THE ART READS: `spec.ride` (above), `round.runner` { v, line, gap, panic, fireMs, +// check, done, throwers: [{ state "idle"|"wind"|"spent", t }], props: [{ kind, x, y, s, +// dead }], horses: [{ state "wait"|"rear"|"run"|"hit"|"fled", t, x, hp }], smashed: [bool] }, +// `round.you` (`state`, `vy`, `ducking`), the events in EVENTS. + +import { linesAt, linesOf, slopeOf, trackY } from "./ghoul-cart.js"; + +const freeze = (o) => Object.freeze(o); +const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v)); + +export const MONSTERS = freeze({}); + +// Every event this pack puts on the field, for the art and the sounds to answer. +export const EVENTS = freeze([ + "wagonJump", "wagonLand", "wagonLaunch", "wagonBrake", "wagonCrash", "wagonCheck", "wagonFinish", + "wagonWind", "wagonThrow", "wagonShot", "wagonEmber", "wagonCatch", "wagonPanic", "wagonFire", "wagonOut", + "wagonRear", "wagonHorseHit", "wagonHorseTurn", +]); + +// The wagon. Speeds are units across a second, WAGON_G units a second squared. +export const WAGON_V = 42; +export const BRAKE_V = 20; +export const PANIC_V = 9; +export const RELAX = 5; +export const WAGON_JUMP_V = 46; +export const WAGON_G = 150; +export const COYOTE_MS = 100; +export const RAMP_SLOPE = 0.25; +export const RAMP_POP = 22; +export const LAND_TOL = 0.9; +export const BIG_LAND = 8; +export const DERAIL_Y = 3; +// The camera sits this far behind its usual spot, so the mob shows at the left edge. +export const CAM_LEAD = -15; +// How far in front of Planny the wagon's nose (and the horse's chest) meets a barrel or a horse. +export const REACH = 3; +// The mob. +export const MOB_V = 40; +export const GAP_START = 24; +export const GAP_MAX = 32; +export const GAP_RESET = 20; +export const CATCH_GAP = 6.5; +export const PANIC_ON = 14; +export const PANIC_OFF = 19; +export const HIT_CLOSE = 10; +export const TORCH_BACK = 6; +export const FORK_BACK = 3; +export const HORSE_BACK = 4; +export const FIRE_MS = 3200; +export const FIRE_BOOST = 8; +export const SMOTHER = 3; +export const STEADY_GAP = 20; +// Obstacles. +export const BARREL_W = 2.6; +export const CRATE_W = 3.4; +export const BLOCK_H = 3.4; +export const HORSE_W = 4.6; +export const HORSE_H = 4.2; +export const HORSE_HP = 3; +export const HORSE_NEAR = 62; +export const HORSE_REAR_MS = 500; +export const HORSE_V = 26; +export const HORSE_FLEE_V = 48; +// The throwers: wound up WIND_MS once the wagon is WIND_NEAR short, the throw aimed at where +// the wagon will be, PROJ_V fast. A pitchfork flies down to chest height (FORK_Y over the deck) +// from the sill (SILL_Y), a torch lobs from the roof (ROOF_Y) to the hay (TORCH_Y). +export const WIND_NEAR = 62; +export const WIND_MS = 550; +export const PROJ_V = 40; +export const THROW_MEET = 19; +export const FORK_Y = 3.2; +export const FORK_HALF_W = 1.6; +export const FORK_TOL = 0.4; +export const TORCH_Y = 1.6; +export const SILL_Y = 8.5; +export const ROOF_Y = 11; +export const LOB = 3.5; +export const HAY_BACK = 4.5; +export const HAY_FRONT = 1.2; +export const HAY_H = 3; +export const BOLT_R = 0.5; +export const PROP_HIT = 1.3; +export const TORCH_POINTS = 60; +export const FORK_POINTS = 40; +export const HORSE_POINTS = 120; +// The things shot out of the air (or turned back) that are worth a die. +export const ACTS_GOAL = 8; + +// Notes for a bonus round that obstacle `id` cost a heart (once each). +function noteHit(round, id) { + const b = round.bonusRound; + if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id); +} + +const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H); +const boxHit = (k, cx, you, x, y0, w, h) => Math.abs(cx - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0; + +// The highest line under x, as [line, y], or null over a gap. +const topAt = (R, x) => linesAt(R, x)[0] || null; + +// The mob's extra speed at x (the surge spans). +export function surgeAt(R, x) { + for (const [x0, x1, extra] of R.surge || []) if (x >= x0 && x <= x1) return extra; + return 0; +} + +// The highest line the wagon, falling from `py` to `y` at `x`, crossed going down. +function landOn(R, x, py, y) { + for (const [line, ly] of linesAt(R, x)) if (py >= ly - LAND_TOL && y <= ly) return { line, y: ly }; + return null; +} + +// Where a wagon in the air at (x, y) going up at vy and across at v lands, if nothing changes: +// { x, y, line } or null when it derails. The unit suite's measure of which gaps a jump clears. +export function flight(R, x, y, vy, v) { + const dt = 0.004; + for (let t = 0; t < 5; t += dt) { + const py = y; + vy = Math.max(-120, vy - WAGON_G * dt); + x += v * dt; + y += vy * dt; + if (vy <= 0) { + const f = landOn(R, x, py, y); + if (f) return { x, y: f.y, line: f.line }; + } + if (y < DERAIL_Y) return null; + } + return null; +} + +// Where a throw flies, at time fraction s (0 at the window, 1 where it meets the wagon): +// a pitchfork on a straight line down to chest height that goes on past it level (so a wagon slowed +// by the brake still meets it at chest height), a torch on a lob that ends there. +export function propAt(p, s) { + const x = p.x0 + (p.x1 - p.x0) * s; + const y = p.y0 + (p.y1 - p.y0) * (p.kind ? s : Math.min(1, s)) + (p.kind === 1 ? LOB * 4 * s * (1 - s) : 0); + return { x, y }; +} + +/* -------------------------------------------------------------- placing */ + +// A fresh set of the room's things: every thrower still, every horse waiting. +function things(R) { + return { + throwers: R.throwers.map(() => ({ state: "idle", t: 0 })), + horses: R.horses.map((h) => ({ state: "wait", t: 0, x: h[0], hp: HORSE_HP })), + smashed: R.blocks.map(() => false), + props: [], + }; +} + +// Planny put down in the room: on the wagon at the start of a ride, or at the last +// checkpoint passed after the last heart (the same room). +function place(round, k) { + const R = round.spec.ride; + if (!R || R.runner !== "wagon") { + if (round.runner && round.runner.id === "wagon") round.runner = null; + return; + } + const again = round.runner && round.runner.id === "wagon" && round.runner.room === round.room; + const check = again ? round.runner.check : -1; + const you = round.you; + const x = check >= 0 ? R.checks[check] : round.spec.start; + const top = topAt(R, x); + Object.assign(you, { x, y: top ? top[1] : you.y, vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 }); + round.runner = { id: "wagon", room: round.room, check, v: WAGON_V, line: top ? top[0] : -1, coyote: 0, from: you.y, left: top ? top[0] : 0, done: false, gap: GAP_START, panic: false, fireMs: 0, braking: false, catches: again ? round.runner.catches : 0, gapMs: 0, gapSum: 0, ...things(R) }; + round.camLead = CAM_LEAD; + const b = round.bonusRound; + if (b && !b.perf.total) { + b.perf.total = R.blocks.length + R.lows.length + R.throwers.length + R.horses.length + (R.track.length - 1); + b.perf.steady = true; + b.perf.goal = ACTS_GOAL; + } +} + +/* ------------------------------------------------------------ the ride */ + +// After a derail that cost a heart but not the ride: Planny and the wagon go back onto the +// road nearest where they fell (the highest line under him, else the next one ahead) at +// WAGON_V. He blinks safe (ghoul.js's takeLife). +function reseat(round, c, R) { + const you = round.you; + const under = topAt(R, you.x); + let line; + let x; + let y; + if (under) { + [line, y] = under; + x = you.x; + } else { + const ahead = linesOf(R) + .map((L, i) => ({ i, x0: L.x0 })) + .filter((L) => L.x0 > you.x) + .sort((a, b) => a.x0 - b.x0)[0]; + line = ahead ? ahead.i : linesOf(R).length - 1; + x = ahead ? ahead.x0 + 2 : R.finish - 2; + y = trackY(R, line, x) ?? you.y; + } + Object.assign(you, { x, y, vy: 0, state: "run", shelf: -1, ducking: false, coyote: 0, drop: -1 }); + Object.assign(c, { line, v: WAGON_V, coyote: 0, from: y }); +} + +// The grade's steady die: the mob kept far, the gap's average over the ride so far. +function steadiness(round, c) { + const b = round.bonusRound; + if (b && c.gapMs > 0) b.perf.steady = c.gapSum / c.gapMs >= STEADY_GAP; +} + +// The wagon's motion for one slice. Returns true once it has moved Planny (every slice +// of a ride); false outside a ride and once he has stepped out onto the green. +function ride(round, ms, k) { + const R = round.spec.ride; + const c = round.runner; + if (!R || R.runner !== "wagon" || !c || c.id !== "wagon" || c.done) return false; + const you = round.you; + const inp = round.input; + const dt = ms / 1000; + const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra }); + // Already down on the green (set there, or past the lip some other way): the ride is over. + if (you.x >= R.finish && you.vy <= 0 && you.y <= k.groundAt(round.spec, you.x) + 0.01) return finish(round, c, R, k.groundAt(round.spec, you.x), k); + // A stomp's bounce (or anything else) lifts the wagon off its line. + if (you.state === "air" && c.line >= 0) { + c.left = c.line; + c.line = -1; + c.coyote = 0; + c.from = you.y; + } + const want = inp.jump > 0; + if (c.line >= 0) { + // On the road: the mob's pull and the brake set the speed. + const brake = Boolean(inp.down) && !want; + if (brake && !c.braking) ev("wagonBrake"); + c.braking = brake; + const target = brake ? BRAKE_V : WAGON_V + (c.panic ? PANIC_V : 0); + c.v += (target - c.v) * Math.min(1, RELAX * dt); + you.ducking = brake; + if (want) { + inp.jump = 0; + you.vy = WAGON_JUMP_V; + Object.assign(c, { left: c.line, line: -1, coyote: 0, from: you.y, braking: false }); + you.state = "air"; + you.ducking = false; + ev("wagonJump", { v: c.v }); + } else { + const L = linesOf(R)[c.line]; + const nx = you.x + c.v * dt; + you.state = "run"; + you.vy = 0; + if (nx >= L.x1) { + // Off the end of the line, on along its last slope. + const end = L.pts[L.pts.length - 1]; + const rise = slopeOf(R, c.line, L.x1); + you.x = L.x1; + you.y = end[1]; + const ramp = rise >= RAMP_SLOPE; + you.vy = rise * c.v + (ramp ? RAMP_POP : 0); + Object.assign(c, { left: c.line, line: -1, coyote: COYOTE_MS, from: you.y, braking: false }); + you.state = "air"; + you.ducking = false; + if (ramp) ev("wagonLaunch", { v: c.v, last: c.left === linesOf(R).length - 1 }); + } else { + you.x = nx; + you.y = trackY(R, c.line, nx); + } + } + } else { + // In the air: the speed it left with. + c.coyote = Math.max(0, c.coyote - ms); + if (want && c.coyote > 0) { + inp.jump = 0; + c.coyote = 0; + you.vy = WAGON_JUMP_V; + c.from = you.y; + ev("wagonJump", { v: c.v }); + } + const py = you.y; + you.vy = Math.max(-k.FALL_MAX, you.vy - WAGON_G * dt); + you.x += c.v * dt; + you.y += you.vy * dt; + you.ducking = false; + c.braking = false; + you.state = "air"; + if (you.vy <= 0) { + const f = landOn(R, you.x, py, you.y); + if (f) { + you.y = f.y; + you.vy = 0; + you.state = "run"; + c.line = f.line; + ev("wagonLand", { big: c.from - f.y >= BIG_LAND }); + c.from = f.y; + } else if (you.x >= R.finish) { + // Over the green at the end: down onto it, and the ride is over. + const g = k.groundAt(round.spec, you.x); + if (g > -Infinity && you.y <= g + 0.01) return finish(round, c, R, g, k); + } + } + } + // A press nothing took waits a moment for a landing, then goes. + if (want && inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms); + // Past the end of the world: a ditch, or the river under the bridge. + if (you.y < DERAIL_Y || k.groundAt(round.spec, you.x) > you.y + 0.5) { + const river = R.bridge && you.x >= R.bridge[0] && you.x <= R.bridge[1]; + noteHit(round, `k${c.left}`); + if (k.lose(round, river ? "river" : "ditch") && round.phase === "play") reseat(round, c, R); + return true; + } + while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) { + c.check++; + ev("wagonCheck", { n: c.check + 1 }); + } + round.camLead = CAM_LEAD; + if (obstacles(round, c, R, k)) return true; + creatures(round, c, R, ms, k); + if (flying(round, c, R, ms, k)) return true; + mob(round, c, R, ms, k); + return true; +} + +// The ride is over: the wagon halts on the green, the door opens, Planny walks out. +function finish(round, c, R, g, k) { + const you = round.you; + c.done = true; + c.restX = you.x; + Object.assign(you, { y: g, vy: 0, state: "run", shelf: -1, ducking: false }); + round.hasKey = true; + round.camLead = 0; + steadiness(round, c); + round.events.push({ type: "wagonFinish", x: you.x, y: you.y, big: c.from - g >= BIG_LAND }); + return false; +} + +// A hit that took a heart: the mob closes, the cause is noted for the grade. +function hurt(round, c, k, cause, id, extra) { + if (!k.struck(round, cause)) return false; + noteHit(round, id); + c.gap = Math.max(CATCH_GAP + 1, c.gap - HIT_CLOSE); + round.events.push({ type: "wagonCrash", cause, x: round.you.x, y: round.you.y, ...extra }); + return true; +} + +// What the wagon runs into: a barrel or crate, a washing line or an inn sign, a charging horse. +// Returns whether it cost a heart. +function obstacles(round, c, R, k) { + const you = round.you; + const hh = duckH(k, you); + const cx = you.x + REACH; + for (const [i, [x0, x1, y, kind]] of R.lows.entries()) { + if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > y && hurt(round, c, k, kind ? "sign" : "wash", `l${i}`, { what: "low", y: you.y + hh })) return true; + } + for (const [i, [x, line, kind]] of R.blocks.entries()) { + if (c.smashed[i] || Math.abs(cx - x) > 6) continue; + if (boxHit(k, cx, you, x, trackY(R, line, x), kind ? CRATE_W : BARREL_W, BLOCK_H) && hurt(round, c, k, kind ? "crate" : "barrel", `b${i}`, { what: "block", x, kind })) { + c.smashed[i] = true; + return true; + } + } + for (const [i, h] of c.horses.entries()) { + if (h.state !== "run") continue; + const y = trackY(R, R.horses[i][1], h.x); + if (y !== null && boxHit(k, cx, you, h.x, y, HORSE_W, HORSE_H) && hurt(round, c, k, "horse", `h${i}`, { what: "horse", x: h.x })) { + h.state = "hit"; + h.t = 600; + return true; + } + } + return false; +} + +// The throwers wind up and throw; the horses rear and charge. +function creatures(round, c, R, ms, k) { + const you = round.you; + R.throwers.forEach(([x, line, kind], i) => { + const t = c.throwers[i]; + const y = trackY(R, line, x) ?? you.y; + if (t.state === "idle") { + const ahead = x - you.x; + if (ahead < WIND_NEAR && ahead > 4) { + Object.assign(t, { state: "wind", t: WIND_MS }); + round.events.push({ type: "wagonWind", x, y: y + (kind ? ROOF_Y : SILL_Y), kind }); + } + } else if (t.state === "wind") { + t.t -= ms; + if (t.t > 0) return; + t.state = "spent"; + // Aimed at where the wagon will be when the throw gets there. + const d = Math.max(1, x - you.x); + const tm = d / (c.v + PROJ_V); + const mx = you.x + c.v * tm; + const my = (topAt(R, mx) || [0, you.y])[1]; + const p = { kind, x0: x, y0: y + (kind ? ROOF_Y : SILL_Y), x1: mx, y1: my + (kind ? TORCH_Y : FORK_Y), T: tm, t: 0, s: 0, dead: false, age: 0, id: i }; + c.props.push(p); + round.events.push({ type: "wagonThrow", x, y: p.y0, kind }); + } + }); + c.horses.forEach((h, i) => { + const [hx, line] = R.horses[i]; + if (h.state === "wait") { + const ahead = hx - you.x; + if (ahead < HORSE_NEAR && ahead > 0) { + Object.assign(h, { state: "rear", t: HORSE_REAR_MS }); + round.events.push({ type: "wagonRear", x: hx, y: trackY(R, line, hx) }); + } + } else if (h.state === "rear") { + h.t -= ms; + if (h.t <= 0) Object.assign(h, { state: "run", t: 0 }); + } else if (h.state === "run" || h.state === "fled") { + h.x -= (h.state === "run" ? HORSE_V : HORSE_FLEE_V) * (ms / 1000); + if (h.x < you.x - 14 || trackY(R, line, h.x) === null) h.state = "gone"; + } else if (h.state === "hit") { + h.t -= ms; + h.x -= HORSE_V * (ms / 1000); + if (h.t <= 0) h.state = "gone"; + } + }); +} + +// The hurled torches and pitchforks in flight: one that reaches the wagon is a heart (a torch +// also sets the hay alight); a torch lands where it is aimed and burns out; a fork goes on. +// Returns whether the wagon was hit. +function flying(round, c, R, ms, k) { + const you = round.you; + const hh = duckH(k, you); + let hit = false; + for (const p of c.props) { + if (p.dead) { + p.age += ms; + continue; + } + p.t += ms / 1000; + p.s = p.t / p.T; + const { x, y } = propAt(p, p.kind ? Math.min(1, p.s) : p.s); + p.x = x; + p.y = y; + if (!hit) { + const on = p.kind + ? x > you.x - HAY_BACK && x < you.x + HAY_FRONT && y > you.y - 0.2 && y < you.y + HAY_H + : Math.abs(x - you.x) < k.HIT_W / 2 + FORK_HALF_W && y > you.y - FORK_TOL && y < you.y + hh; + if (on && hurt(round, c, k, p.kind ? "torch" : "fork", `t${p.id}`, { what: p.kind ? "torch" : "fork" })) { + p.dead = true; + hit = true; + if (p.kind) { + c.fireMs = FIRE_MS; + round.events.push({ type: "wagonFire", x: you.x, y: you.y }); + } + continue; + } + } + if (p.kind && p.s >= 1) { + p.dead = true; + round.events.push({ type: "wagonEmber", x, y }); + } else if (!p.kind && (p.s > 1.8 || y < -2)) p.dead = true; + } + c.props = c.props.filter((p) => !p.dead || p.age < 500); + return hit; +} + +// The mob: its gap, the panic, the hay fire and the grade's steady die, and a catch at CATCH_GAP. +function mob(round, c, R, ms, k) { + const you = round.you; + const dt = ms / 1000; + const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra }); + if (c.fireMs > 0) { + c.fireMs -= ms * (you.ducking && c.line >= 0 ? SMOTHER : 1); + if (c.fireMs <= 0) { + c.fireMs = 0; + ev("wagonOut"); + } + } + const mobV = MOB_V + surgeAt(R, you.x) + (c.fireMs > 0 ? FIRE_BOOST : 0); + c.gap = clamp(c.gap + (c.v - mobV) * dt, 0, GAP_MAX); + if (!c.panic && c.gap < PANIC_ON) { + c.panic = true; + ev("wagonPanic"); + } else if (c.panic && c.gap >= PANIC_OFF) c.panic = false; + c.gapMs += ms; + c.gapSum += c.gap * ms; + steadiness(round, c); + if (c.gap > CATCH_GAP) return; + c.gap = GAP_RESET; + c.panic = false; + c.catches++; + noteHit(round, `m${c.catches}`); + ev("wagonCatch"); + k.struck(round, "mob"); +} + +/* ------------------------------------------------------------- targets */ + +// A bolt into something to shoot: a torch or pitchfork in the air, a horse. True when one +// took it (the bolt is spent). +function wagonShot(round, s) { + const R = round.spec.ride; + const c = round.runner; + if (!R || R.runner !== "wagon" || !c || c.id !== "wagon") return false; + const score = (n) => { + round.score += n; + if (round.bonusRound) round.bonusRound.perf.acts++; + }; + for (const p of c.props) { + if (p.dead || p.x === undefined) continue; + if (Math.abs(s.x - p.x) > PROP_HIT + BOLT_R || Math.abs(s.y - p.y) > PROP_HIT + BOLT_R) continue; + p.dead = true; + const pts = p.kind ? TORCH_POINTS : FORK_POINTS; + score(pts); + c.gap = Math.min(GAP_MAX, c.gap + (p.kind ? TORCH_BACK : FORK_BACK)); + round.events.push({ type: "wagonShot", x: p.x, y: p.y, kind: p.kind, points: pts }); + return true; + } + for (let i = 0; i < c.horses.length; i++) { + const h = c.horses[i]; + if (h.state !== "run" && h.state !== "rear") continue; + const y = trackY(R, R.horses[i][1], h.x); + if (y === null || Math.abs(s.x - h.x) > HORSE_W / 2 + BOLT_R || s.y < y - BOLT_R || s.y > y + HORSE_H + BOLT_R) continue; + h.hp--; + if (h.hp > 0) round.events.push({ type: "wagonHorseHit", x: h.x, y: y + HORSE_H / 2 }); + else { + h.state = "fled"; + score(HORSE_POINTS); + c.gap = Math.min(GAP_MAX, c.gap + HORSE_BACK); + round.events.push({ type: "wagonHorseTurn", x: h.x, y: y + HORSE_H / 2, points: HORSE_POINTS }); + } + return true; + } + return false; +} + +export const WAGON = freeze({ + id: "wagon", + monsters: MONSTERS, + walkers: freeze([]), + zombies: freeze([]), + stackers: freeze([]), + climbers: freeze([]), + act: freeze({}), + horde: freeze({}), + ride: freeze([ride]), + place: freeze([place]), + target: wagonShot, +});