Add Ghoul Rush's finale at Marrow Manor: the House's three kills, two rides and the ending

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-03 20:32:49 -08:00
1 parent d716e3c3f5
commit e681d1f70d
56 files changed
+16585 -141

No files matched your search

+28 -1
View File
@@ -268,7 +268,28 @@ Optional local browser UI shipped with **every** skill. Source lives in `src/web
| `public/activities/ghoul-rush/core/ghoul-fight.js` | Bosses and damage: a boss's fight and fall, hurting and killing a monster, losing a life. |
| `public/activities/ghoul-rush/core/ghoul-play.js` | The play loop: `KIT` and `RUN_KIT`, the blaster and bolts, hits, stomps, timers, one slice of play, and `advance()`. |
| `public/activities/ghoul-rush/core/ghoul-window.js` | The game's contract with the Activities page: `create`, keys and pointer, what events set off, `ROOM_MUSIC`, the view handed to the drawing. |
| `public/activities/ghoul-rush/stages/marrow/ghoul-marrow.js` | The finale's rules: Marrow, the house itself. Kill I, The Lawn: its windows, moves and retreat. Not plugged in yet. |
| `public/activities/ghoul-rush/stages/marrow/ghoul-marrow.js` | The finale's rules (`MARROW`, a pack in `PACKS`): Marrow, the house itself, the boss of `FINALE` (`core/ghoul-rooms.js`: after `RUN_STAGES` stages a run goes there with no offer, and clearing its last room wins). Kill I, The Lawn (room `lawn`): the house stands at the arena's right and YOU are kept `WALL_GAP` off it; its real hit box sits at the room's far end and is always `guard`ed, so only its twelve `WINDOWS` hurt it, through the pack's `target` (`windowShot`: the first lit window at a bolt's height; each holds `ceil(bossHp / 12)`, `b.hp` their sum; a bolt past the far wall is spent). Windows are `dark`, `lit` (a few at a time, `LIT_N`, `LIT_MS`, `RELIGHT_MS`) or `out` for good, kept in `round.marrow` across a life lost; rows open by windows out (`rowsOpen`). Moves by weighted `pickMove` (shingles, carpet, pickets; bricks and doormen from phase 1; stomp in phase 2; and only while YOU are up in the oak, `isHigh`, `HIGH_WEIGHTS`: lightning, a `marrowBolt` hazard that glows on YOUR branch then strikes down to it, and crows out of the door's mouth, the Graveyard's carrion crows marked `houseCrow`, at most `CROWS_CAP`). After the kill `b.t` runs the retreat (`retreatStep`: sag, a false "YOU ESCAPED!", a laugh, the sink, `b.gone`, which lifts the wall to its standing front door) |
| `public/activities/ghoul-rush/stages/marrow/ghoul-marrow-draw.js` | The finale's drawing: `LOOKS` (`lawn`, `pack: "marrow"`), `VOICES` (the House's acts, tones in `ghoul-sfx-marrow.js`), `LOSE_WORDS`, `LOSE_SOUNDS` and `marrowArt(d)`: the storm on the hill, the dead oak whose branches are the shelves, the mailbox, the house as a face (its windows lit, shuttered or shot out, the door its mouth), its hazards and waves, its retreat (drawn through its fall: `LINGERS` in `ghoul-draw.js`), lights and every event's look and sound |
| `public/activities/ghoul-rush/stages/marrow/ghoul-sfx-marrow.js` | The finale's own sounds as data (no imports): `MARROW_SFX` with `tones` (a `ghoulMarrow<Act>` tone per act of the House, first drafts until the sound vote); merged by `ghoul-sfx.js` via `STAGE_SFX`; the lawn borrows the Drowning Pool's track until its own is picked |
| `public/activities/ghoul-rush/rides/mat/ghoul-mat-room.js` | The finale's first ride's room (`MAT_ROOM`, data, read by `core/ghoul-rooms.js`, in `FINALE.rooms` once `ready`) |
| `public/activities/ghoul-rush/rides/mat/ghoul-mat.js` | The finale's first ride, Down the Hatch (`MAT`, a pack in `PACKS`): surfing the WELCOME mat down the House's throat |
| `public/activities/ghoul-rush/rides/mat/ghoul-mat-draw.js` | Down the Hatch's drawing: `LOOKS`, `VOICES`, `LOSE_WORDS`, `LOSE_SOUNDS` and `matArt(d)` |
| `public/activities/ghoul-rush/rides/mat/ghoul-sfx-mat.js` | Down the Hatch's own sounds as data (`MAT_SFX`), merged by `ghoul-sfx.js` |
| `public/activities/ghoul-rush/stages/marrow/ghoul-dollhouse-room.js` | The finale's second kill's room (`DOLLHOUSE_ROOM`, data, in `FINALE.rooms` once `ready`) |
| `public/activities/ghoul-rush/stages/marrow/ghoul-marrow-eye.js` | The finale's second kill, Every Room at Once (`EYE`, a pack in `PACKS`): the Eye in the dollhouse, shades of the keepers YOU beat, the lurch |
| `public/activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js` | Every Room at Once's drawing: `LOOKS`, `VOICES`, `LOSE_WORDS`, `LOSE_SOUNDS` and `eyeArt(d)` (shades through `d.bossArt`) |
| `public/activities/ghoul-rush/stages/marrow/ghoul-sfx-marrow-eye.js` | Every Room at Once's own sounds as data (`EYE_SFX`), merged by `ghoul-sfx.js` |
| `public/activities/ghoul-rush/rides/bonestair/ghoul-bonestair-room.js` | The finale's second ride's room (`BONESTAIR_ROOM`, data, in `FINALE.rooms` once `ready`) |
| `public/activities/ghoul-rush/rides/bonestair/ghoul-bonestair.js` | The finale's second ride, The Bone Stair (`BONESTAIR`, a pack in `PACKS`): down the stair ahead of the collapse |
| `public/activities/ghoul-rush/rides/bonestair/ghoul-bonestair-draw.js` | The Bone Stair's drawing: `LOOKS`, `VOICES`, `LOSE_WORDS`, `LOSE_SOUNDS` and `bonestairArt(d)` |
| `public/activities/ghoul-rush/rides/bonestair/ghoul-sfx-bonestair.js` | The Bone Stair's own sounds as data (`BONESTAIR_SFX`), merged by `ghoul-sfx.js` |
| `public/activities/ghoul-rush/stages/marrow/ghoul-pit-room.js` | The finale's last kill's room (`PIT_ROOM`, data, in `FINALE.rooms` once `ready`) |
| `public/activities/ghoul-rush/stages/marrow/ghoul-marrow-heart.js` | The finale's last kill, The Heart of Marrow (`HEART`, a pack in `PACKS`): the beat, the ribs, HOLD FIRE (`round.flood` stops the blaster in `fire()`) |
| `public/activities/ghoul-rush/stages/marrow/ghoul-marrow-heart-draw.js` | The Heart of Marrow's drawing: `LOOKS`, `VOICES`, `LOSE_WORDS`, `LOSE_SOUNDS` and `heartArt(d)` |
| `public/activities/ghoul-rush/stages/marrow/ghoul-sfx-marrow-heart.js` | The Heart of Marrow's own sounds as data (`HEART_SFX`), merged by `ghoul-sfx.js` |
| `public/activities/ghoul-rush/story/ghoul-ending.js` | The ending once the House is dead (phase `ending`, shaped like `ghoul-story.js`): `beginEnding` (from `finish` in `ghoul-run.js`), `stepEnding`, `takeEnding`, `pressEnding`, `releaseEnding`, `skipEnding`, `ENDING_TRACK`; it wins the run at its end |
| `public/activities/ghoul-rush/story/ghoul-ending-draw.js` | The ending's drawing: `endingArt(d)` hands back `{ card, react }`, plugged into `drawScene` and `react` |
| `public/activities/ghoul-rush/story/ghoul-sfx-ending.js` | The ending's own sounds and music as data (`ENDING_SFX`), merged by `ghoul-sfx.js` |
| `public/activities/ghoul-rush/draw/ghoul-draw.js` | Ghoul Rush's drawing: `drawScene(ctx, view)` from one view object `ghoul.js` refills each frame, in room units turned the right way up and scrolled by the camera: the strip above the field in the page's colors with the pills (laid out by `hudLayout`: the room, lives, the bonus, the chain with its window emptying, the key once held, the power-ups; a second row rather than run off the board, the rows centered in the strip), still layers `CHUNK` units of a room wide drawn off screen once per room and scale and copied each frame (a few kept; each room's look in fixed colors, `LOOKS`: wallpaper, moonlit windows, decor by room (portraits, bookcases, curtains, pots, ferns, rafters with cobwebs, headstones), wainscot, floorboards, pits, shelves, wall doors and loose boards), the crumbling boards, a wall door standing open, the chandeliers, the exit door (padlocked, then open and glowing), candy, power-ups and the key, the monsters (a zombie in a ragged shirt with mismatched eyes, lurching; a crawler's hand through the boards, then crawling; a bat with flapping wings; a sheet ghost fading in and out; a skeleton raising a bone; gourdlings), bones and shockwaves, the bosses (the Great Gourd with a carved glowing face and a red shadow where it will land; Old Rattlebones, drawn by `ghoul-bones-draw.js`) and the boss bar, Planny (his star eye in your highlight in every state, stick arms, one holding the flashlight blaster that flares as it fires, stepping, arms up in the air or cheering, spinning with an "o" when hit, slumped at the end, garlic circling him while he has some; arms and feet in `limbInk(look)`), the bolts, sparks, rings, floating words kept on the field by `labelSpot`, the chain's big number, banners (`BANNER_SHADE`) the stage pick (`drawPicker`: a card per stage offered with its picture, `drawStagePicture`, its first room's wall and moonlit window over its boss room's floor with its boss standing there drawn by the same `BOSS_ART` as in play, name, line and boss, the one picked out raised and edged in gold, `stageColor` its boss room's), and the start and end strip with the big final score and a dot per stage, lit in each cleared stage's color (gold for the record before a run); `react(e, kit)` turns each event into those effects and its blips, a monster's own sound through `VOICES` (each kind's tone in `ghoul-sfx.js` by act: `appear` (a runner's `warn`, a bat's `wake`, a wraith's `notice`), `climb`, `hop`, `growl`, `lunge`, `shriek`, `dive`, `spit`, `throw`, `hurt` (one every 140 ms), `die`, and a boss's `wake`, `hop`, `slam`, `windup`; a "throw" event names its thrower in `by` and a "spit" its spitter in `kind`); the stage packs' drawing (`ART`: an `outdoor` look draws its pack's backdrop instead of walls, graves for doors, and each pack's monsters, bosses, missiles, hazards and lights by kind; a pack may also draw `sky` (every frame, under the still layers, so its backdrop leaves the sky clear) and `moving` (what moves in its scenery, over the still layers)); `readColors(canvas)`, `contrast`, `lookOf`; decides nothing |
| `public/activities/ghoul-rush/core/ghoul-rooms.js` | Ghoul Rush's rooms and stages as data (no imports): the long hall every run starts in (`ROOMS[0]`), then `STAGES` (each an id, title, line and four room ids, the last a boss's, checked at load; `stageById`, `roomById`), `FIELD_W`, `FIELD_H`, `FLOOR_Y`, `CEILING_Y`, `CHANDELIER_Y`, and per room its look, name and line, length, ground pieces (pits between, steps and walls), shelves (`crumble` kind), start, key, door, candy rows, power-ups, spawns (zombies, wall doors, crawlers' boards, bats, ghosts, skeletons), chandeliers and boss (`gourd`, `bones` or a pack's, the last room of its stage); a door's fifth entry names what comes out of it (rotters out of the Graveyard's graves) |
| `public/activities/ghoul-rush/stages/wing/ghoul-bones.js` | Old Rattlebones' fight, the East Wing's boss, as a boss pack in the shape of the stage packs (no imports; `ghoul.js` hands each rule its kit `k`; it plugs in through `PACKS` with `bosses`, `boss` and `hazards`, and `ghoul.js` re-exports `BONES_KEEP`, `BONES_MS`, `BONES_RAGE_MS`, `BONES_WINDUP_MS` and `VOLLEY`): 90 hp; every `BONES_MS` he winds up for a volley, a slam or the skull, picked at random by `pickAct` (never one three times running, the first a volley); the skull is a `skull` hazard that flies level at your chest `SKULL_REACH` past you and curves back to his neck while `b.headless` (no weak spot; a bolt to the skull does `SKULL_HIT`, eaten, with `SKULL_STAGGER_MS` between hits); at half his hp (`BONES_RAGE`) he shakes (`BONES_SHAKE_MS`), attacks every `BONES_RAGE_MS`, slams in a double (`DOUBLE_GAP_MS`), hurls bone rain (`rain` hazards: a shadow for `RAIN_WARN_MS`, then a bone) and raises skeletons (`raise` hazards, at most `MAX_BONY` alive or cracking). |
@@ -357,6 +378,12 @@ Optional local browser UI shipped with **every** skill. Source lives in `src/web
| `scripts/test-web-console-activities-ghoul-carnival.mjs` | The Carnival's suite: the rooms and the belts, grinners and their balloon cap, balloons and their acid, the marionette's drop and its string, Mirror You (the delay, the mirrored moves, jumps, its bolts and their canceling, stunned by a pie), the strongman, the circus hound (a swoop, duckable), Cotton Candy, the Custard Pie, every Ringmaster move (stalk, leap, charge, stomp, whip, the strings following, open, rage, hounds, the script), no random draws, endless lives for every new cause, and a voice for every act |
| `scripts/test-web-console-activities-ghoul-grounds.mjs` | The Grounds' suite: each monster's behavior, the shears, the Groundskeeper's moves and phases, a voice for every act, each event playing exactly one picked sound, and every picked tone present in the merged tones |
| `scripts/test-web-console-activities-ghoul-bog.mjs` | Gallows Bog's suite: the stage row and its rooms, the mud (slow, sink, jump, shelf, boots), each monster's behavior (the lurker's eyes and snap, the leech's latch, the wisp's light, the bog body's rise), the wisp lure and its fairness cap, the harpoon under the water, Old Mother Bog's wave, weak cauldron, muck, sink and resurface, every move (wind-up, telegraph event, effect, a clean dodge costs nothing, a hit a heart), the phase unlocks, cooldowns and caps, planks while standing, her fall clearing every hazard and add, a skilled bot that must kill her in 60 to 120 s on four seeds and an idle bot she kills, a voice for every act with exactly one picked sound per event, words and a sound for every cause, both cards, the round flow, drawing dark and lit, and a seeded bot on a draw that throws if the pack asks for a random number |
| `scripts/test-web-console-activities-ghoul-marrow.mjs` | The finale's suite: the win condition (`RUN_STAGES` picks that never repeat, then the House with no offer, its stage card and the boss's, the win), the select listing it last at depth 0, the memo (one past every stage only on a win, never from practice) and the words that count `RUN_STAGES`; Kill I, The Lawn: the wall and the out-of-reach guarded box, every window hit from the surface serving its row and passed while shuttered, a window out for good across a life lost, rows opening by windows out, `pickMove`'s rules, each move's telegraph, hit (its cause) and dodge, the doormen's cap, endless lives, the retreat's beats in order and the door it leaves, a steady bot's fight length at full depth and an idle one's death, the voices, words and sounds, and drawing every state lit and dark |
| `scripts/test-web-console-activities-ghoul-mat.mjs` | Down the Hatch's suite: the track, every obstacle's telegraph, hit and dodge, the squeezes, bile, the grade, a good bot finishing and one that never dodges losing its three hearts without a game over |
| `scripts/test-web-console-activities-ghoul-eye.mjs` | Kill II's suite: the Eye's flare, opening and guard, a shade move for every boss in `STAGES`, the lurch and the dresser, the retreat, a bot's fight length, voices and drawing |
| `scripts/test-web-console-activities-ghoul-bonestair.mjs` | The Bone Stair's suite: the flights and seams, the rubble's meter, every obstacle's telegraph, hit and dodge, the grade, and the bot sims |
| `scripts/test-web-console-activities-ghoul-heart.mjs` | Kill III's suite: the beat and its waves, the ribs' window, every attack's warning, the clamp at 1 hp and HOLD FIRE, the white-out and the door of light, a bot's fight length, voices and drawing |
| `scripts/test-web-console-activities-ghoul-ending.mjs` | The ending's suite: the pages' rules, a press turning pages, holding fire to skip, the win once at the end, every scene drawn |
| `scripts/test-web-console-activities-ghoul-lantern.mjs` | The Drowned Lantern's suite: the room and its tables, the walk and the slide, steps on wood, the flare and the oil, the shrines, Mother's wake and rise and the boat, each hunter's rule (the Lurker's hearing, lane and dash, the guardian and roaming wisps, the leeches at the light's edge and their bite, the bodies that take only the still, Mother's hand and its gaps), hearts, endless lives and the grade, the clock, determinism (no random drawn), the balance (a bot that ignores the hunters loses every shrine order, one that plays them wins each with hearts left), the rule tags and banner marks, the hums, voices and drawing |
| `public/activities/ghoul-rush/draw/ghoul-picker-draw.js` | The choice of stage, its drawing: `pickerArt(d)`, handed `ghoul-draw.js`'s helpers (`lookOf`, `label`, `roundRect`, `circle`, `BOSS_ART`, `drawGourdFire`, `GOLD`), returning `drawPicker` (a card per stage offered: its picture of its rooms with its boss standing there, its name, line and boss, the pick raised and edged in gold, and how to choose), `drawSelect` (the stage select for testing: every stage in a list, two columns past 8, the one picked out with its picture and a chip per room) and `stageColor` (a stage's boss room's color, also the tally dots'). Split from `ghoul-draw.js` to keep it under the 3,000-line cap |
| `public/activities/ghoul-rush/core/ghoul-powers.js` | Ghoul Rush's power-ups and pickups (no imports: `ghoul.js` hands its rules a kit, `POWER_KIT`, of `landing` and the numbers they need): `POWERS` (each power-up's name, line, color, `ms` if timed, drop `weight`, and its rule, the Lantern's `dark`), `TIMED`, `PILL_WORDS`, `FLAP_CLEAR`, `HOURGLASS_MS`, `CANDY_POINTS`, `POWER_POINTS`, `CRYSTAL_POINTS`, `powerHere(round, kind)` (whether a power-up can turn up in the room as it is now; a new rule, such as a stage-only power-up, goes in `POWERS` and is checked here), `pickPower`, `applyPower(round, kind, kit)` (`ghoul.js` exports it bound to its kit as `applyPower(round, kind)`) and `pickups` (candy, placed and dropped power-ups, crystals up high and the key, taken by touch; drops fall and fade). Split from `ghoul.js` to keep it under the 3,000-line cap |
+6 -2
View File
@@ -982,8 +982,12 @@ Ghoul Rush at 65).
and out of each boss's room you **choose the next stage** from two
(one, once a single stage is left) never played that run, each card
showing the stage with its boss standing in it: left and right pick one
out, space or up goes in. Clear every stage and you **escape**, a win.
Each stage cleared makes the next quicker and tougher. Every other room keeps a **horde**
out, space or up goes in. Clear six stages and the run takes you back to
**Marrow Manor** for the finale, a fight against **the house itself**: on its
front lawn, shoot out every lit window, the only part of it that can be hurt,
while it throws its roof, its carpet and its fence at you, and calls down
lightning and sends crows out of its door the moment you climb the oak. Kill it and you
**escape**, a win. Each stage cleared makes the next quicker and tougher. Every other room keeps a **horde**
pouring in from the edges of the view, mostly ahead, so standing still is
never safe. **Zombies** shamble out of doors in the wall and sprint once
you are close, **crawlers** drag themselves up through loose boards,
+1 -1
View File
@@ -11,7 +11,7 @@
"fix:eol": "node scripts/fix-line-endings.mjs",
"play": "node scripts/play.mjs",
"pretest": "node scripts/fix-line-endings.mjs",
"test": "node scripts/validate-char-count.js && node install.js --build-skills && node scripts/parse-check.mjs && node scripts/check-skill-table.mjs && node scripts/node-test.mjs scripts/test-line-endings.mjs scripts/test-us-english.mjs scripts/test-script-git.mjs scripts/test-git-repo.mjs scripts/test-skill-scripts.mjs scripts/test-script-changelog.mjs scripts/test-web-console-git.mjs scripts/test-web-console-git-board.mjs scripts/test-web-console-chat.mjs scripts/test-web-console-subagents.mjs scripts/test-web-console-pointers.mjs scripts/test-console-wire-budgets.mjs scripts/test-web-console-speed.mjs scripts/test-web-console-qa.mjs scripts/test-web-console-concurrency.mjs scripts/test-web-console-workspace.mjs scripts/test-web-console-lifecycle.mjs scripts/test-web-console-chat-stress.mjs scripts/test-web-console-server.mjs scripts/test-web-console-session.mjs scripts/test-web-console-logic.mjs scripts/test-web-console-activities.mjs scripts/test-web-console-activities-rapids.mjs scripts/test-web-console-activities-bounce.mjs scripts/test-web-console-activities-bounce-game.mjs scripts/test-web-console-activities-ghoul.mjs scripts/test-web-console-activities-ghoul-graveyard.mjs scripts/test-web-console-activities-ghoul-grounds.mjs scripts/test-web-console-activities-ghoul-chapel.mjs scripts/test-web-console-activities-ghoul-sanatorium.mjs scripts/test-web-console-activities-ghoul-village.mjs scripts/test-web-console-activities-ghoul-mine.mjs scripts/test-web-console-activities-ghoul-carnival.mjs scripts/test-web-console-activities-ghoul-frozen.mjs scripts/test-web-console-activities-ghoul-bog.mjs scripts/test-web-console-activities-ghoul-ride.mjs scripts/test-web-console-activities-ghoul-cart.mjs scripts/test-web-console-activities-ghoul-sled.mjs scripts/test-web-console-activities-ghoul-banister.mjs scripts/test-web-console-activities-ghoul-gurney.mjs scripts/test-web-console-activities-ghoul-hearse.mjs scripts/test-web-console-activities-ghoul-wagon.mjs scripts/test-web-console-activities-ghoul-pew.mjs scripts/test-web-console-activities-ghoul-mower.mjs scripts/test-web-console-activities-ghoul-tray.mjs scripts/test-web-console-activities-ghoul-arms.mjs scripts/test-web-console-activities-ghoul-dice.mjs scripts/test-web-console-activities-ghoul-gameover.mjs scripts/test-web-console-activities-ghoul-intro.mjs scripts/test-web-console-activities-ghoul-bossintro.mjs scripts/test-web-console-activities-ghoul-story.mjs scripts/test-web-console-activities-ghoul-bones.mjs scripts/test-web-console-activities-ghoul-retry.mjs scripts/test-web-console-activities-bounce-cars.mjs scripts/test-web-console-tones.mjs scripts/test-web-console-skills.mjs scripts/test-web-console-spec-states.mjs scripts/test-web-console-state.mjs scripts/test-web-console-shape.mjs scripts/test-script-pathfinder.mjs scripts/test-skill-test-runs.mjs scripts/test-launcher.mjs scripts/test-agents-file.mjs scripts/test-agent-lookup.mjs scripts/test-web-console-source.mjs scripts/test-web-console-hardening.mjs scripts/test-web-console-embed.mjs scripts/test-web-console-in-app.mjs scripts/test-web-console-loop.mjs scripts/test-web-console-handoffs.mjs scripts/test-web-console-notepad.mjs scripts/test-script-xray.mjs scripts/test-script-finalize.mjs scripts/test-getting-started.mjs scripts/test-install-update.mjs scripts/test-browser-helper.mjs scripts/test-web-console-page-cards.mjs scripts/test-web-console-page-dashboard.mjs scripts/test-web-console-page-session.mjs scripts/test-web-console-page-ask.mjs scripts/test-web-console-page-workspace.mjs scripts/test-web-console-page-help.mjs scripts/test-web-console-page-prefs.mjs scripts/test-web-console-page-git.mjs scripts/test-web-console-page-notepad.mjs scripts/test-web-console-page-send.mjs scripts/test-web-console-page-loop.mjs scripts/test-web-console-page-activities.mjs scripts/test-web-console-page-setup.mjs scripts/test-standalone-check.mjs scripts/test-check-versions.mjs scripts/test-app-meter.mjs"
"test": "node scripts/validate-char-count.js && node install.js --build-skills && node scripts/parse-check.mjs && node scripts/check-skill-table.mjs && node scripts/node-test.mjs scripts/test-line-endings.mjs scripts/test-us-english.mjs scripts/test-script-git.mjs scripts/test-git-repo.mjs scripts/test-skill-scripts.mjs scripts/test-script-changelog.mjs scripts/test-web-console-git.mjs scripts/test-web-console-git-board.mjs scripts/test-web-console-chat.mjs scripts/test-web-console-subagents.mjs scripts/test-web-console-pointers.mjs scripts/test-console-wire-budgets.mjs scripts/test-web-console-speed.mjs scripts/test-web-console-qa.mjs scripts/test-web-console-concurrency.mjs scripts/test-web-console-workspace.mjs scripts/test-web-console-lifecycle.mjs scripts/test-web-console-chat-stress.mjs scripts/test-web-console-server.mjs scripts/test-web-console-session.mjs scripts/test-web-console-logic.mjs scripts/test-web-console-activities.mjs scripts/test-web-console-activities-rapids.mjs scripts/test-web-console-activities-bounce.mjs scripts/test-web-console-activities-bounce-game.mjs scripts/test-web-console-activities-ghoul.mjs scripts/test-web-console-activities-ghoul-graveyard.mjs scripts/test-web-console-activities-ghoul-grounds.mjs scripts/test-web-console-activities-ghoul-chapel.mjs scripts/test-web-console-activities-ghoul-sanatorium.mjs scripts/test-web-console-activities-ghoul-village.mjs scripts/test-web-console-activities-ghoul-mine.mjs scripts/test-web-console-activities-ghoul-carnival.mjs scripts/test-web-console-activities-ghoul-frozen.mjs scripts/test-web-console-activities-ghoul-bog.mjs scripts/test-web-console-activities-ghoul-marrow.mjs scripts/test-web-console-activities-ghoul-mat.mjs scripts/test-web-console-activities-ghoul-eye.mjs scripts/test-web-console-activities-ghoul-bonestair.mjs scripts/test-web-console-activities-ghoul-heart.mjs scripts/test-web-console-activities-ghoul-ending.mjs scripts/test-web-console-activities-ghoul-ride.mjs scripts/test-web-console-activities-ghoul-cart.mjs scripts/test-web-console-activities-ghoul-sled.mjs scripts/test-web-console-activities-ghoul-banister.mjs scripts/test-web-console-activities-ghoul-gurney.mjs scripts/test-web-console-activities-ghoul-hearse.mjs scripts/test-web-console-activities-ghoul-wagon.mjs scripts/test-web-console-activities-ghoul-pew.mjs scripts/test-web-console-activities-ghoul-mower.mjs scripts/test-web-console-activities-ghoul-tray.mjs scripts/test-web-console-activities-ghoul-arms.mjs scripts/test-web-console-activities-ghoul-dice.mjs scripts/test-web-console-activities-ghoul-gameover.mjs scripts/test-web-console-activities-ghoul-intro.mjs scripts/test-web-console-activities-ghoul-bossintro.mjs scripts/test-web-console-activities-ghoul-story.mjs scripts/test-web-console-activities-ghoul-bones.mjs scripts/test-web-console-activities-ghoul-retry.mjs scripts/test-web-console-activities-bounce-cars.mjs scripts/test-web-console-tones.mjs scripts/test-web-console-skills.mjs scripts/test-web-console-spec-states.mjs scripts/test-web-console-state.mjs scripts/test-web-console-shape.mjs scripts/test-script-pathfinder.mjs scripts/test-skill-test-runs.mjs scripts/test-launcher.mjs scripts/test-agents-file.mjs scripts/test-agent-lookup.mjs scripts/test-web-console-source.mjs scripts/test-web-console-hardening.mjs scripts/test-web-console-embed.mjs scripts/test-web-console-in-app.mjs scripts/test-web-console-loop.mjs scripts/test-web-console-handoffs.mjs scripts/test-web-console-notepad.mjs scripts/test-script-xray.mjs scripts/test-script-finalize.mjs scripts/test-getting-started.mjs scripts/test-install-update.mjs scripts/test-browser-helper.mjs scripts/test-web-console-page-cards.mjs scripts/test-web-console-page-dashboard.mjs scripts/test-web-console-page-session.mjs scripts/test-web-console-page-ask.mjs scripts/test-web-console-page-workspace.mjs scripts/test-web-console-page-help.mjs scripts/test-web-console-page-prefs.mjs scripts/test-web-console-page-git.mjs scripts/test-web-console-page-notepad.mjs scripts/test-web-console-page-send.mjs scripts/test-web-console-page-loop.mjs scripts/test-web-console-page-activities.mjs scripts/test-web-console-page-setup.mjs scripts/test-standalone-check.mjs scripts/test-check-versions.mjs scripts/test-app-meter.mjs"
},
"devDependencies": {
"gpt-tokenizer": "2.9.0",
@@ -0,0 +1,765 @@
// Web console tests, Ghoul Rush's Bone Stair (the finale's second ride, between Kill II and the Pit): its shape (the spiral's flights and seams, every gap of missing treads clears with a jump and swallows YOU without one, every ribcage can be ducked, spacing, checkpoints, the last step over the Pit's floor), the run's speed (DOWN and LEFT slow YOU), every obstacle's cost and cause (missing treads, treads giving way, ribcages, skeletons, hands, masonry, the rubble), the telegraphs (shadows, creaks and cracks, fingers over the edge, skeletons rising), shooting skeletons down, the pursuit meter (the gap that clean running opens and hits, ducks and holds close), the catch, three hearts of its own, the grade and the dice, endless lives, 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-bonestair.mjs
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
import * as bs from "../src/web-console/public/activities/ghoul-rush/rides/bonestair/ghoul-bonestair.js";
import { BONESTAIR_ROOM } from "../src/web-console/public/activities/ghoul-rush/rides/bonestair/ghoul-bonestair-room.js";
import { ANSWERS, EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as STAIR_LOOKS, VOICES as STAIR_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-rush/rides/bonestair/ghoul-bonestair-draw.js";
import * as ghoulSfx from "../src/web-console/public/activities/ghoul-rush/sfx/ghoul-sfx.js";
import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-rush/core/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 stair 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 on The Bone Stair reached the way a run reaches it: six stages behind it, on
// through the finale's rooms before it; the clocks long, the bonus round on (three hearts).
function stairRound(seed = 5) {
const round = ghoul.newRound(seed);
round.lives = 3;
round.dice = 0;
through(round);
round.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES).map((st) => st.id);
round.offer = null;
for (let n = 0; n < 14 && round.spec.id !== "bonestair"; n++) through(round);
assert.equal(round.spec.id, "bonestair");
round.phase = "play";
round.timeMs = 1e9;
round.bonus = 1e9;
round.events.length = 0;
return round;
}
const ROOM = ghoul.roomById("bonestair");
const R = ROOM.ride;
const F = R.flights;
const floorOf = (x) => ghoul.groundAt(ROOM, x);
const K = { HIT_W: ghoul.HIT_W, HIT_H: ghoul.HIT_H, DUCK_H: ghoul.DUCK_H };
const NONE = { runner: "bonestair", hearts: 3, time: 1e9, finish: 6020, top: [0, 20, 36], flights: [[20, 6020, 36, -600]], gaps: [], rot: [], ribs: [], skels: [], hands: [], stones: [], surge: [], checks: [] };
// The same round over a stair of its own: one long flight to measure the run on (or `ride`'s).
function synth(ride) {
const round = stairRound();
round.spec = { ...round.spec, start: 30, length: 7000, ground: [[0, 20, 36]], ride: { ...NONE, ...ride } };
bs.BONESTAIR.place[0](round, {});
return round;
}
// A gentle stair for the obstacle tests: one flight dropping a unit every ten.
const GENTLE = [[20, 4020, 36, -364]];
// YOU on the stair at x, at speed v.
function stairAt(round, x, { v = bs.RUN_V, safe = false } = {}) {
const y = bs.stairY(round.spec.ride, x);
assert.ok(y !== null, `the stair 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, { v, coyote: 0, heldMs: 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 };
};
// Where YOU, in the air at (x, y) going up at vy and across at v, come down: { x, y } on the
// stair, or null for a fall through (the room's own geometry, gaps and the seams' lift).
function flight(x, y, vy, v) {
const dt = 0.004;
for (let t = 0; t < 4; t += dt) {
const px = x;
let py = y;
vy = Math.max(-ghoul.FALL_MAX, vy - bs.STAIR_G * dt);
x += v * dt;
y += vy * dt;
for (const s of bs.seams(R)) if (px < s.x && x >= s.x) {
y += s.rise;
py += s.rise;
}
const line = bs.stairY(R, x);
if (line === null) return null;
const inGap = R.gaps.some(([a, b]) => x > a && x < b);
if (vy <= 0 && !inGap && py >= line - bs.LAND_TOL && y <= line) return { x, y: line };
if (y < line - bs.FALL_DEPTH) return null;
}
return null;
}
/* -------------------------------------------------------------- the room */
test("Ghoul Rush's Bone Stair is the finale's second ride, between Kill II and the Pit: ready, lit, no key, no boss, no pickups, a bonus round of three hearts and about 30 seconds", () => {
assert.equal(BONESTAIR_ROOM.ready, true);
const rooms = ghoul.FINALE.rooms;
assert.ok(rooms.includes("bonestair"));
assert.ok(rooms.indexOf("bonestair") > rooms.indexOf("lawn"));
if (rooms.includes("dollhouse")) assert.equal(rooms.indexOf("bonestair"), rooms.indexOf("dollhouse") + 1, "just after Kill II");
if (rooms.includes("pit")) assert.equal(rooms.indexOf("pit"), rooms.indexOf("bonestair") + 1, "just before the Pit");
assert.deepEqual([ROOM.title, ROOM.sub], ["The Bone Stair", "Every step down is someone"]);
assert.equal(ROOM.dark, false);
assert.equal(ROOM.key, null);
assert.equal(ROOM.boss, null);
assert.equal(ROOM.bonus, true);
assert.equal(R.runner, "bonestair");
assert.equal(R.hearts, 3, "three hearts, not five");
assert.equal(typeof ghoul.ROOM_MUSIC.bonestair, "string", "a track (borrowed until its own is voted)");
assert.deepEqual(Object.keys(bs.BONESTAIR.monsters), []);
assert.equal(LOOKS.bonestair, STAIR_LOOKS.bonestair);
assert.equal(LOOKS.bonestair.pack, "bonestair");
assert.ok(Object.isFrozen(R) && Object.isFrozen(R.flights) && Object.isFrozen(R.flights[0]) && Object.isFrozen(R.ribs[0]), "frozen all the way down");
assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0, "no monsters: the stair's things are the pack's own");
assert.deepEqual([ROOM.candy.length, ROOM.items.length], [0, 0], "no pickups");
// The ground: the cellar landing at the start and the Pit's floor at the end only.
assert.equal(ROOM.ground.length, 2);
assert.deepEqual([...ROOM.ground[0]], [...R.top]);
assert.equal(ROOM.ground[1][0], R.finish, "the Pit's floor starts under the last step");
assert.ok(ROOM.ground[1][2] < F.at(-1)[3] - 8, "a real drop off the last step");
assert.ok(ROOM.door > R.finish + 20 && ROOM.door > ROOM.length - 14, "the door at the room's end, out on the Pit's floor");
assert.ok(floorOf(ROOM.door - 2) > -Infinity);
// About 30 seconds at a clean run, on a clock that holds it comfortably (the game's ride rule: 70 to 120 s).
const secs = (R.finish - ROOM.start) / bs.RUN_V;
assert.ok(secs >= 26 && secs <= 34, `${secs.toFixed(1)} s at RUN_V`);
assert.equal(ghoul.timeFor(ghoul.roomFor("bonestair")), R.time);
assert.ok(R.time >= 70000 && R.time <= 120000);
assert.deepEqual([R.gaps.length, R.rot.length, R.ribs.length, R.skels.length, R.hands.length, R.stones.length], [4, 3, 3, 4, 3, 3], "gaps, give-ways, ribcages, skeletons, hands, masonry");
});
test("Ghoul Rush's Bone Stair: the spiral is a run of flights, each starting where the last ended, high again; crossing a seam lifts YOU by the flight's height and the field never runs out going down", () => {
assert.equal(F[0][0], R.top[1], "the first flight starts at the landing's end");
assert.equal(F[0][2], R.top[2], "level with it");
for (let i = 0; i < F.length; i++) {
const [x0, x1, y0, y1] = F[i];
assert.ok(x1 > x0 && y1 < y0, `flight ${i} goes down`);
assert.ok(y0 < ghoul.FIELD_H - 12 && y1 > 10, `flight ${i} stays on the field (${y0} to ${y1})`);
const slope = (y1 - y0) / (x1 - x0);
assert.ok(slope > -0.2 && slope < -0.1, `flight ${i}'s slope ${slope.toFixed(3)}`);
if (i) assert.equal(x0, F[i - 1][1], "no hole at a seam");
}
assert.equal(F.at(-1)[1], R.finish);
const seams = bs.seams(R);
assert.equal(seams.length, F.length - 1);
for (const s of seams) assert.ok(s.rise > 15, "high again");
// Running across a seam on the treads.
const round = stairRound();
const sx = F[0][1];
stairAt(round, sx - 6, { safe: true });
run(round, 300);
assert.ok(round.you.x > sx);
assert.ok(Math.abs(round.you.y - bs.stairY(R, round.you.x)) < 1e-6, "on the next flight's treads");
assert.ok(round.you.y > F[1][2] - 3, "high again");
assert.equal(events(round, "stairTurn").length, 1);
assert.equal(round.runner.flight, 1);
// And in the air: a jump just before a seam lands on the next flight.
const air = stairRound();
stairAt(air, sx - 8, { safe: true });
press(air);
until(air, () => air.you.state === "air", 200);
until(air, () => air.you.state === "run", 2000);
assert.ok(air.you.x > sx && Math.abs(air.you.y - bs.stairY(R, air.you.x)) < 1e-6, "landed round the column");
// A bolt winds round with YOU.
const shot = stairRound();
stairAt(shot, sx - 14, { safe: true });
shot.input.fire = true;
run(shot, 30);
shot.input.fire = false;
const s = shot.shots[0];
assert.ok(s, "a bolt");
until(shot, () => s.x > sx + 10, 600);
assert.ok(Math.abs(s.y - (bs.stairY(R, s.x) + ghoul.SHOT_Y)) < 1.2, `the bolt flies along the next flight (${s.y.toFixed(1)} over ${bs.stairY(R, s.x).toFixed(1)})`);
});
test("Ghoul Rush's Bone Stair: every stretch of missing treads clears with a jump at its edge or a few units early (at a run or a duck's speed), and running off it without one is a fall", () => {
for (const [x0, x1] of R.gaps) {
const w = x1 - x0;
assert.ok(w >= 6 && w <= 9, `a gap at ${x0} is ${w} wide`);
assert.equal(bs.flightAt(R, x0), bs.flightAt(R, x1), "inside one flight");
// Off the edge with no jump.
assert.equal(flight(x0, bs.stairY(R, x0), bs.slopeAt(R, x0) * bs.RUN_V, bs.RUN_V), null, `no jump at ${x0}`);
for (const v of [bs.DUCK_V, bs.RUN_V]) {
for (const early of [0, 3, 6]) {
const x = x0 - early;
const land = flight(x, bs.stairY(R, x), bs.STAIR_JUMP_V, v);
assert.ok(land && land.x > x1, `a jump ${early} early at ${v} clears the gap at ${x0}`);
}
}
}
// In play: a fall costs a heart (cause "stairGap") and puts YOU back on the treads past it.
const round = stairRound();
const [x0, x1] = R.gaps[0];
stairAt(round, x0 - 6);
until(round, () => events(round, "lose").length > 0, 2000);
assert.equal(events(round, "lose")[0].cause, "stairGap");
assert.equal(round.bonusRound.hearts, 2);
assert.equal(round.phase, "play", "the run goes on");
assert.ok(round.you.x > x1 && round.you.state === "run", "back on the treads past it");
assert.equal(events(round, "stairDrop").length, 1);
// A jump clears it in play.
const ok = stairRound();
stairAt(ok, x0 - 4);
press(ok);
until(ok, () => ok.you.x > x1 + 4, 2000);
assert.equal(events(ok, "lose").length, 0);
});
test("Ghoul Rush's Bone Stair: every ribcage's underside sits between a ducked box and a standing one along its width; ducking passes, standing is a heart (cause \"stairRib\"); ducking slows YOU", () => {
for (const [x, under] of R.ribs) {
const hi = bs.stairY(R, x - bs.RIB_W / 2 - K.HIT_W / 2);
const lo = bs.stairY(R, x + bs.RIB_W / 2 + K.HIT_W / 2);
assert.ok(hi + K.DUCK_H < under, `a ducked box clears the ribcage at ${x}`);
assert.ok(lo + K.HIT_H > under, `a standing box hits the ribcage at ${x}`);
}
const [x] = R.ribs[0];
const stand = stairRound();
stairAt(stand, x - 10);
until(stand, () => events(stand, "lose").length > 0, 1000);
assert.equal(events(stand, "lose")[0].cause, "stairRib");
const duck = stairRound();
stairAt(duck, x - 8);
duck.input.down = true;
until(duck, () => duck.you.x > x + 6, 2000);
duck.input.down = false;
assert.equal(events(duck, "lose").length, 0);
assert.ok(duck.runner.v < bs.RUN_V - 4, "a duck slows YOU");
// And the speeds.
const s = synth({ flights: GENTLE });
run(s, 1500, { down: true });
assert.ok(Math.abs(s.runner.v - bs.DUCK_V) < 1);
run(s, 1500, { left: true });
assert.ok(Math.abs(s.runner.v - bs.HOLD_V) < 1, "LEFT holds back");
run(s, 2500);
assert.ok(Math.abs(s.runner.v - bs.RUN_V) < 1, "back up to a run");
});
test("Ghoul Rush's Bone Stair: masonry warns first (a shadow, a creak at once, a crack halfway, more than a second in all), lands ahead of a runner, and lies as a pile to jump; under it, or into the pile, is a heart (cause \"stairStone\")", () => {
assert.ok(bs.STONE_MS >= 1200, "a long, clear warning");
const round = synth({ flights: GENTLE, stones: [[300]] });
stairAt(round, 200, { safe: true });
until(round, () => events(round, "stairCreak").length > 0, 2000);
const at = round.you.x;
assert.ok(300 - at <= bs.STONE_NEAR && 300 - at > bs.STONE_NEAR - 2);
assert.equal(round.runner.stones[0].state, "warn");
until(round, () => events(round, "stairCrack").length > 0, 2000);
assert.ok(Math.abs(round.runner.stones[0].t - bs.STONE_MS / 2) < 20, "the crack halfway");
until(round, () => events(round, "stairThud").length > 0, 2000);
assert.equal(round.runner.stones[0].state, "pile");
assert.ok(300 - round.you.x > 10, `it lands ahead of a runner (${(300 - round.you.x).toFixed(1)} short)`);
// Into the pile: a heart.
round.you.safeMs = 0;
until(round, () => events(round, "lose").length > 0, 1000);
assert.equal(events(round, "lose")[0].cause, "stairStone");
// Jumped: clean.
const ok = synth({ flights: GENTLE, stones: [[300]] });
stairAt(ok, 200);
until(ok, () => ok.runner.stones[0].state === "pile", 3000);
until(ok, () => 300 - ok.you.x < 8, 1000);
press(ok);
until(ok, () => ok.you.x > 306, 1000);
assert.equal(events(ok, "lose").length, 0);
// Under it as it lands: a heart.
const under = synth({ flights: GENTLE, stones: [[300]] });
stairAt(under, 200);
until(under, () => under.runner.stones[0].state === "warn" && under.runner.stones[0].t < 200, 3000);
stairAt(under, 299.5, { v: 0 });
under.runner.heldMs = 1e9;
until(under, () => events(under, "lose").length > 0, 2000);
assert.equal(events(under, "lose")[0].cause, "stairStone");
});
test("Ghoul Rush's Bone Stair: a bone hand's fingers creep over the edge first (HAND_WARN_MS), then it grabs; a jump clears it, a grab is a heart (cause \"stairHand\") and holds YOU still a moment", () => {
assert.ok(bs.HAND_WARN_MS >= 700);
const round = synth({ flights: GENTLE, hands: [[300]] });
stairAt(round, 220);
until(round, () => events(round, "stairReach").length > 0, 3000);
assert.ok(300 - round.you.x <= bs.HAND_NEAR);
until(round, () => events(round, "stairGrab").length > 0, 2000);
assert.ok(300 - round.you.x > 10, "it grabs ahead of YOU, in plain sight");
until(round, () => events(round, "lose").length > 0, 1000);
assert.equal(events(round, "lose")[0].cause, "stairHand");
assert.equal(round.runner.heldMs > 0 || round.runner.v < 1, true, "held");
const x = round.you.x;
run(round, bs.HELD_MS - 40);
assert.ok(Math.abs(round.you.x - x) < 0.01, "still while held");
run(round, 400);
assert.ok(round.you.x > x + 2, "and off again");
// Jumped.
const ok = synth({ flights: GENTLE, hands: [[300]] });
stairAt(ok, 220);
until(ok, () => 300 - ok.you.x < 7, 3000);
press(ok);
until(ok, () => ok.you.x > 306, 1000);
assert.equal(events(ok, "lose").length, 0);
});
test("Ghoul Rush's Bone Stair: a skeleton rises over the treads first, then climbs up at YOU; SKEL_HP bolts knock it down (an act, points, a little ground back), and running into it is a heart (cause \"stairSkel\")", () => {
const round = synth({ flights: GENTLE, skels: [[300]] });
stairAt(round, 200);
until(round, () => events(round, "stairRise").length > 0, 3000);
assert.ok(300 - round.you.x <= bs.SKEL_NEAR);
assert.equal(round.runner.skels[0].state, "rise");
until(round, () => round.runner.skels[0].state === "climb", 2000);
const x0 = round.runner.skels[0].x;
run(round, 200);
assert.ok(round.runner.skels[0].x < x0, "climbing up the stair at YOU");
until(round, () => events(round, "lose").length > 0, 2000);
assert.equal(events(round, "lose")[0].cause, "stairSkel");
assert.equal(round.runner.skels[0].state, "smashed");
// Shot down.
const shot = synth({ flights: GENTLE, skels: [[300]] });
stairAt(shot, 200);
shot.input.fire = true;
until(shot, () => shot.runner.skels[0].state === "down" || events(shot, "lose").length > 0, 3000);
assert.equal(shot.runner.skels[0].state, "down");
assert.equal(events(shot, "stairSkelHit").length, bs.SKEL_HP - 1);
assert.equal(events(shot, "stairSkelDown").length, 1);
assert.equal(shot.bonusRound.perf.acts, 1);
assert.ok(shot.score >= bs.SKEL_POINTS);
until(shot, () => shot.you.x > 310, 2000);
assert.equal(events(shot, "lose").length, 0);
// A waiting skeleton takes no bolt.
const early = synth({ flights: GENTLE, skels: [[300]] });
assert.equal(bs.BONESTAIR.target(early, { x: 300, y: bs.stairY(early.spec.ride, 300) + 2 }), false);
});
test("Ghoul Rush's Bone Stair: treads that give way start crumbling once YOU are in, at a speed between a duck and a run: a runner outruns it, a ducker drops through (cause \"stairGive\") and is put back past the stretch", () => {
assert.ok(bs.ROT_V > bs.DUCK_V && bs.ROT_V > bs.HOLD_V && bs.ROT_V < bs.RUN_V);
for (const [x0, x1] of R.rot) {
assert.ok(x1 - x0 >= 30, "long enough to matter");
assert.equal(bs.flightAt(R, x0), bs.flightAt(R, x1), "inside one flight");
for (const [a, b] of R.gaps) if (a > x0 && b < x1) assert.ok(a - x0 > 15 && x1 - b > 15, "a gap inside one is well clear of its ends");
}
const runner = synth({ flights: GENTLE, rot: [[200, 260]] });
stairAt(runner, 180);
until(runner, () => runner.you.x > 270, 3000);
assert.equal(events(runner, "stairRot").length, 1);
assert.equal(events(runner, "lose").length, 0, "outrun");
const ducker = synth({ flights: GENTLE, rot: [[200, 260]] });
stairAt(ducker, 180);
ducker.input.down = true;
until(ducker, () => events(ducker, "lose").length > 0, 4000);
ducker.input.down = false;
assert.equal(events(ducker, "lose")[0].cause, "stairGive");
assert.ok(ducker.you.x > 260 && ducker.you.state === "run", "back on the treads past it");
// Blinking safe after a heart, it waits behind YOU.
const safe = synth({ flights: GENTLE, rot: [[200, 260]] });
stairAt(safe, 180, { safe: true });
safe.input.down = true;
until(safe, () => safe.you.x > 262, 6000);
safe.input.down = false;
assert.equal(events(safe, "lose").length, 0);
});
test("Ghoul Rush's Bone Stair: the rubble behind gains on a duck or a hold and loses to a clean run; at CATCH_GAP it has YOU (a heart, cause \"stairRubble\") and falls back; a hit shoves it closer", () => {
const s = synth({ flights: GENTLE });
assert.equal(s.runner.gap, bs.GAP_START);
run(s, 3000);
assert.ok(s.runner.gap > bs.GAP_START, "a clean run wins ground");
assert.ok(s.runner.gap <= bs.GAP_MAX);
const d = synth({ flights: GENTLE });
const g0 = d.runner.gap;
run(d, 1000, { down: true });
assert.ok(d.runner.gap < g0, "a duck loses ground");
const caught = synth({ flights: GENTLE });
caught.input.left = true;
until(caught, () => events(caught, "lose").length > 0, 10000);
caught.input.left = false;
assert.equal(events(caught, "lose")[0].cause, "stairRubble");
assert.equal(events(caught, "stairCatch").length, 1);
assert.equal(caught.runner.gap, bs.GAP_RESET);
assert.ok(events(caught, "stairClose").length >= 1, "a warning before it");
const hit = synth({ flights: GENTLE, ribs: [[200, bs.stairY({ ...NONE, flights: GENTLE }, 197) + 3]] });
stairAt(hit, 190);
const before = hit.runner.gap;
until(hit, () => events(hit, "lose").length > 0, 1000);
assert.ok(hit.runner.gap < before - bs.HIT_CLOSE + 1, "the hit lets it closer");
assert.ok(hit.runner.v <= bs.STUMBLE_V, "and YOU stumble");
});
test("Ghoul Rush's Bone Stair: checkpoints are passed, and running off the last step drops YOU onto the Pit's floor: the run is over, the way out open, and YOU walk to the door", () => {
const round = stairRound();
stairAt(round, R.checks[0] - 4, { safe: true });
run(round, 300);
assert.equal(round.runner.check, 0);
assert.equal(events(round, "stairCheck").length, 1);
const end = stairRound();
stairAt(end, R.finish - 6, { safe: true });
until(end, () => end.runner.done, 3000);
assert.equal(events(end, "stairEdge").length, 1);
assert.equal(events(end, "stairFinish").length, 1);
assert.equal(end.hasKey, true);
assert.equal(end.you.y, floorOf(end.you.x));
assert.ok(end.you.x > R.finish && end.you.x < ROOM.door);
end.input.right = true;
until(end, () => end.phase !== "play", 4000);
assert.equal(end.phase, "clear");
assert.equal(end.bonusRound.won, true);
assert.ok(end.bonusRound.dice >= BONUS_FLOOR);
});
test("Ghoul Rush's Bone Stair: no random number is drawn in the room (20 seconds of running, jumping, ducking and shooting, on a draw that throws)", () => {
const r = stairRound();
for (let t = 0; t < 20000; t += 16) {
r.input.fire = t % 4000 < 1500;
r.input.down = t % 3000 < 300;
if (t % 1700 < 20) press(r);
r.you.safeMs = 1e9;
ghoul.advance(r, 16, never);
r.events.length = 0;
}
assert.ok(r.you.x > 500);
assert.equal(r.runner.id, "bonestair");
});
test("Ghoul Rush's Bone Stair's grade: three hearts pay at most one die for hearts, every skeleton shot is the acts die, the rubble kept far is the steady die", () => {
const full = stairRound();
const b = full.bonusRound;
assert.equal(b.max, 3);
assert.equal(b.hearts, 3);
assert.equal(b.perf.goal, R.skels.length);
assert.equal(b.perf.total, R.gaps.length + R.rot.length + R.ribs.length + R.skels.length + R.hands.length + R.stones.length);
const mk = (hearts, hits, acts, steadyDie) => {
const bb = makeBonus({ stats: { kills: 0 }, spec: { ride: R } });
bb.hearts = hearts;
bb.perf = { total: 20, hits: Array.from({ length: hits }, (_, i) => `x${i}`), acts, goal: R.skels.length, steady: steadyDie, kills0: 0 };
return diceFor(bb, 0);
};
assert.equal(mk(3, 0, R.skels.length, true), 8, "a perfect run");
assert.equal(mk(3, 0, R.skels.length - 1, true), 7, "a skeleton missed");
assert.equal(mk(1, 3, 0, false), 5);
const s = synth({ flights: GENTLE });
s.runner.gap = 8;
s.runner.gapMs = 20000;
s.runner.gapSum = 8 * 20000;
run(s, 100);
assert.equal(s.bonusRound.perf.steady, false, "the rubble stayed close");
const t = synth({ flights: GENTLE });
run(t, 3000);
assert.equal(t.bonusRound.perf.steady, true);
});
test("Ghoul Rush's Bone Stair: endless lives (round.infinite) spare the hearts for every cause, the Garlic shield takes a hit instead of a heart", () => {
const r = stairRound();
r.infinite = true;
stairAt(r, R.gaps[0][0] - 6);
until(r, () => events(r, "lose").length > 0, 2000);
assert.equal(r.bonusRound.hearts, 3);
assert.equal(events(r, "lose")[0].cause, "stairGap");
assert.equal(r.phase, "play");
const m = synth({ flights: GENTLE });
m.infinite = true;
m.input.left = true;
until(m, () => m.runner.catches > 0, 10000);
assert.equal(m.bonusRound.hearts, 3);
const g = synth({ flights: GENTLE, ribs: [[200, bs.stairY({ ...NONE, flights: GENTLE }, 197) + 3]] });
g.you.garlic = true;
stairAt(g, 190);
until(g, () => !g.you.garlic, 1000);
assert.equal(g.bonusRound.hearts, 3);
});
/* ----------------------------------------------------------- sound, names */
test("Ghoul Rush's Bone Stair: every event has a voice that plays, every cause has words and a sound, every tone exists and is short", () => {
assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...bs.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 = STAIR_VOICES[kind] && STAIR_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, n: 0, points: 50, cause: "stairGap" }).played.includes(name), `${event} plays ${name}`);
}
for (const cause of bs.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(tones[LOSE_SOUNDS[cause][0]] || ["thud", "crunch"].includes(LOSE_SOUNDS[cause][0]), `${cause}'s sound is a tone`);
assert.ok(heard({ type: "lose", cause, hearts: 2 }).played.length > 0, `${cause} sounds`);
}
for (const name of Object.keys(tones).filter((n) => n.startsWith("ghoulStair"))) {
const layers = tones[name].layers;
assert.ok(Math.max(...layers.map((l) => (l.delay || 0) + l.seconds)) <= 1.2, `${name} is short`);
for (const l of layers) assert.ok(l.gain > 0 && l.gain <= 1);
}
});
test("Ghoul Rush's Bone Stair: its names are its own (every event, cause and tone starts with its prefix), and it keeps to the shared ride slot", () => {
for (const e of bs.EVENTS) assert.ok(e.startsWith("stair"), e);
for (const c of bs.CAUSES) assert.ok(c.startsWith("stair"), c);
for (const kind of Object.keys(STAIR_VOICES)) for (const name of Object.values(STAIR_VOICES[kind])) assert.ok(name.startsWith("ghoulStair"), name);
assert.deepEqual(Object.keys(bs.BONESTAIR).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []);
const r = stairRound();
assert.equal(r.runner.id, "bonestair");
assert.ok(!("bonestair" in r));
});
/* ------------------------------------------------------------ telegraphs */
test("Ghoul Rush's Bone Stair telegraphs: JUMP over gaps, hands and masonry, DUCK over ribcages, SHOOT over skeletons, RUN where the treads will give way, words on the first three of each kind, seen from afar, the same every time", () => {
const marks = telegraphMarks(R);
assert.equal(marks.length, R.gaps.length + R.rot.length + R.ribs.length + R.skels.length + R.hands.length + R.stones.length, "one per thing");
for (const m of marks) assert.equal(m.answer, ANSWERS[m.kind], m.kind);
assert.deepEqual(ANSWERS, { gap: "JUMP", hand: "JUMP", stone: "JUMP", rib: "DUCK", skel: "SHOOT", rot: "RUN" });
const m = marks.find((q) => q.kind === "rib");
const alphaOf = (x) => (telegraphs(R, x).find((t) => t.kind === "rib" && t.lead === m.lead) || { alpha: 0 }).alpha;
assert.equal(alphaOf(m.lead - 45), 0, "not yet");
assert.ok(alphaOf(m.lead - 36) > 0 && alphaOf(m.lead - 36) < 1, "fading in");
assert.equal(alphaOf(m.lead - 20), 1);
assert.equal(alphaOf(m.lead + 7), 0, "gone once passed");
const sk = marks.find((q) => q.kind === "skel");
assert.ok(telegraphs(R, sk.lead - 55).some((q) => q.lead === sk.lead && q.alpha > 0.5), "a skeleton seen from further");
assert.deepEqual(telegraphs(R, m.lead - 33), telegraphs(R, m.lead - 33), "deterministic");
for (const kind of Object.keys(ANSWERS)) {
const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead);
of.forEach((q, i) => {
assert.equal(q.n, i);
const shown = telegraphs(R, q.lead - 30).find((s) => s.lead === q.lead);
assert.equal(shown.words, i < 3, `${kind} ${i}`);
});
}
});
test("Ghoul Rush's Bone Stair: every thing sits on the treads, clear of the seams (none within 14 before one or 20 after), and spaced for a player", () => {
const seams = bs.seams(R).map((s) => s.x);
const things = [...R.gaps.map(([a, b]) => [a, b]), ...R.ribs.map(([x]) => [x - bs.RIB_W / 2, x + bs.RIB_W / 2]), ...R.hands.map(([x]) => [x, x]), ...R.stones.map(([x]) => [x, x]), ...R.rot.map(([a, b]) => [a, b])];
for (const [a, b] of things) {
assert.ok(bs.stairY(R, a) !== null && bs.stairY(R, b) !== null && a > F[0][0] && b < R.finish - 8);
for (const s of seams) assert.ok(b < s - 14 || a > s + 20, `${a} to ${b} is clear of the seam at ${s}`);
}
for (const [x] of R.skels) for (const s of seams) assert.ok(x < s - 14 || x > s + 30, `a skeleton at ${x} has room to climb from the seam at ${s}`);
const xs = [...R.gaps.map(([a]) => a), ...R.ribs.map(([x]) => x), ...R.hands.map(([x]) => x), ...R.stones.map(([x]) => x), ...R.skels.map(([x]) => x)].sort((p, q) => p - q);
for (let i = 0; i + 1 < xs.length; i++) assert.ok(xs[i + 1] - xs[i] >= 22, `${xs[i]} and ${xs[i + 1]} are ${xs[i + 1] - xs[i]} apart`);
for (const x of R.checks) for (const [a, b] of things) assert.ok(x < a - 10 || x > b + 10, `a checkpoint at ${x} is clear`);
});
test("Ghoul Rush's Bone Stair's intro banner says the controls plainly", () => {
assert.match(R.how, /UP jump, DOWN duck/);
assert.match(R.how, /SPACE to shoot/);
assert.match(R.how, /YOU/);
});
/* --------------------------------------------------------------- drawing */
test("Ghoul Rush's Bone Stair draws: the stair, each thing in each state, a seam, the rubble far and close, a crash, the last step and the floor, the result card, and the stage select straight into it", () => {
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.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES).map((st) => st.id);
r.offer = null;
for (let n = 0; n < 14 && r.spec.id !== "bonestair"; n++) through(r);
r.lives = 99;
const spots = [ROOM.start + 4, R.gaps[0][0] - 8, R.ribs[0][0] - 6, R.hands[0][0] - 20, R.stones[0][0] - 30, R.skels[0][0] - 30, R.rot[0][0] + 10, F[0][1] - 1, F[0][1] + 6, R.checks[0], R.finish - 10];
for (const dark of [true, false]) {
for (const x of spots) {
r.dark = dark;
r.phase = "play";
stairAt(r, x, { safe: true });
r.runner.hands = r.runner.hands.map((h, i) => ({ state: ["reach", "grab", "hold", "wait"][i % 4], t: 300 }));
r.runner.stones = r.runner.stones.map((s, i) => ({ state: ["warn", "pile", "warn"][i % 3], t: i === 2 ? 100 : 700, cracked: true }));
r.runner.skels = r.runner.skels.map((s, i) => ({ state: ["rise", "climb", "down", "wait"][i % 4], t: 300, x: R.skels[i][0] - 3, hp: 2 }));
r.runner.rot = r.runner.rot.map((q, i) => (i === 0 ? { state: "go", front: R.rot[0][0] + 6 } : q));
for (const gap of [24, 6]) {
r.runner.gap = gap;
r.runner.close = gap < bs.CLOSE_ON;
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);
stairAt(r, x, { safe: true });
}
r.you.ducking = true;
g.tick(16);
Object.assign(r.you, { state: "air", vy: 10, y: r.you.y + 3, ducking: false });
g.tick(16);
}
}
assert.equal(r.spec.id, "bonestair");
// A crash.
r.you.safeMs = 0;
r.runner.hands = r.runner.hands.map(() => ({ state: "wait", t: 0 }));
stairAt(r, R.ribs[0][0] - 8);
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");
// Down on the Pit's floor, and the card.
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.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES).map((st) => st.id);
d.offer = null;
for (let n = 0; n < 14 && d.spec.id !== "bonestair"; n++) through(d);
d.phase = "play";
d.runner.done = true;
Object.assign(d.you, { x: R.finish + 16, y: floorOf(R.finish + 16), 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;
for (let i = 0; i < ghoul.SELECTABLE.length; i++) ghoul.steerSelect(p, 1, 0);
const at = ghoul.FINALE.rooms.indexOf("bonestair");
for (let i = 0; i < at; i++) ghoul.steerSelect(p, 0, 1);
assert.equal(p.select.room, at);
pick.tick(16);
ghoul.takeSelect(p);
assert.equal(p.spec.id, "bonestair");
assert.equal(p.runner.id, "bonestair");
assert.equal(p.you.y, R.top[2]);
assert.equal(p.bonusRound.max, 3);
pick.tick(16);
});
/* ----------------------------------------------------------- the bots */
// A bot that plays well: it jumps at the edge of missing treads, over a grabbing hand and a pile of
// masonry, ducks every ribcage, and fires only while a skeleton is up ahead (a held blaster runs
// hot). `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) {
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 = seed % 4;
inp.fire = c.skels.some((s) => (s.state === "rise" || s.state === "climb") && s.x > you.x && s.x - you.x < 75);
let jump = false;
if (you.state === "run") {
for (const [x0] of R.gaps) if (x0 - you.x > 0 && x0 - you.x < 1.5 + look * 0.5 && ok(x0)) jump = true;
R.hands.forEach(([x], i) => {
const h = c.hands[i];
if ((h.state === "grab" || h.state === "reach") && x - you.x > 4 && x - you.x < 7 + look && ok(x)) jump = true;
});
R.stones.forEach(([x], i) => {
if (c.stones[i].state === "pile" && x - you.x > 7 && x - you.x < 9 + look && ok(x)) jump = true;
});
for (const [x] of R.ribs) if (you.x > x - bs.RIB_W / 2 - 3 && you.x < x + bs.RIB_W / 2 + 2 && ok(x)) 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 = inp.up = inp.fire = false;
}
function rideWith(seed, bot, limit = 80000) {
const round = stairRound(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, `YOU stay 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 Bone Stair: a bot that dodges well runs the whole stair in about 30 seconds, every skeleton shot, all three hearts kept, 8 dice, past every checkpoint", () => {
for (let seed = 1; seed <= 4; 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 > 26000 && ms < 36000, `${ms} ms`);
assert.equal(b.hearts, 3, lost.join(","));
assert.equal(b.dice, 8);
assert.equal(round.lives, 3, "never a run life");
assert.equal(round.runner.done, true);
assert.equal(round.runner.check, R.checks.length - 1);
}
});
test("Ghoul Rush's Bone Stair: a bot that misses some things still mostly finishes, never with a run life lost", () => {
let won = 0;
for (let seed = 1; seed <= 8; seed++) {
const { round } = rideWith(seed, (r) => goodBot(r, seed, 0.12));
if (round.bonusRound.won) won++;
assert.equal(round.lives, 3);
assert.equal(round.over, false);
}
assert.ok(won >= 4, `${won} of 8 finished`);
});
test("Ghoul Rush's Bone Stair: a bot that never dodges loses all three hearts in the first half, ends with 0 dice, BONUS LOST, and the run goes on with no game over", () => {
for (let seed = 1; seed <= 3; 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, 3);
assert.ok(round.you.x < R.finish * 0.5, `out at ${round.you.x}`);
assert.equal(round.lives, 3, "never a run life");
assert.equal(round.over, false, "no game over");
// On into the next room.
until(round, () => round.spec.id !== "bonestair", 12000);
assert.notEqual(round.spec.id, "bonestair");
assert.equal(round.over, false);
}
});
test("Ghoul Rush's Bone Stair: a bot that ducks or holds back the whole way is caught by the rubble again and again", () => {
for (const key of ["down", "left"]) {
const { lost } = rideWith(3, (r) => {
goodBot(r, 3);
if (r.runner && !r.runner.done) r.input[key] = true;
}, 30000);
assert.ok(lost.filter((c) => c === "stairRubble").length >= 2, `${key}: ${lost.join(",")}`);
}
});
@@ -34,6 +34,11 @@ function selectInto(at, room, texts = [], opts = {}) {
g.round.select = { at, room };
g.round.practice = true;
g.key("action");
// A stage that opens on its boss's room (the finale) shows its own card first.
if (g.round.phase === "intro") {
g.round.introMs = ghoul.INTRO_MIN_MS;
g.key("action");
}
return g;
}
@@ -244,7 +249,8 @@ test("Ghoul Rush boss intros: the card draws for every boss at many moments, thr
const sizes = { W: 96, H: 54 };
for (const room of bossRooms) {
const id = room.boss;
const st = ghoul.STAGES.find((s) => s.boss === id);
// The stage that holds this boss's room (the finale holds three).
const st = ghoul.SELECTABLE.find((s) => s.rooms.includes(room.id));
const calls = [];
const BOSS_ART = new Proxy({}, { get: (t, k) => (k === id ? (ctx, pic, b) => calls.push([pic, b]) : undefined) });
const texts = [];
@@ -261,7 +267,7 @@ test("Ghoul Rush boss intros: the card draws for every boss at many moments, thr
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);
const g = selectInto(ghoul.SELECTABLE.indexOf(st), st.rooms.indexOf(room.id), g2texts);
assert.equal(g.round.phase, "bossintro", id);
for (let ms = 0; ms < 5000; ms += 80) {
g.round.introMs = ms;
@@ -102,7 +102,7 @@ test("Ghoul Rush: a Lucky die is as common as a 1UP, comes only as a drop, and i
assert.equal(dark.drops.length, 1, "a kill drops a power-up on a low roll");
});
test("Ghoul Rush: picking up Lucky dice stacks them to nine, then pays points like a 1UP at its cap, and the dice show in a pill", () => {
test("Ghoul Rush: picking up Lucky dice stacks them to MAX_HELD_DICE (13), then pays points like a 1UP at its cap, and the dice show in a pill", () => {
const round = hall();
const drop = { id: 1, kind: "die", x: round.you.x, y: round.you.y + 1, vx: 0, vy: 0, life: 9000, rest: true };
round.drops.push(drop);
@@ -110,12 +110,13 @@ test("Ghoul Rush: picking up Lucky dice stacks them to nine, then pays points li
assert.equal(round.dice, 1);
assert.equal(round.drops.length, 0);
assert.equal(events(round, "power")[0].kind, "die");
for (let k = 0; k < 8; k++) ghoul.applyPower(round, "die");
assert.equal(round.dice, 9);
assert.equal(ghoul.MAX_HELD_DICE, 13);
for (let k = 0; k < 20; k++) ghoul.applyPower(round, "die");
assert.equal(round.dice, ghoul.MAX_HELD_DICE, "stacks to the cap");
const score = round.score;
ghoul.applyPower(round, "die");
assert.equal(round.dice, 10, "no cap");
assert.equal(round.score, score, "no points instead");
assert.equal(round.dice, ghoul.MAX_HELD_DICE, "no more past it");
assert.equal(round.score, score + ghoul.POWER_POINTS, "points instead");
const canvas = { getContext: () => null };
const game = ghoul.default.create({ canvas });
game.start();
@@ -239,13 +240,18 @@ test("Ghoul Rush: a 5 saves him with a heart and no shield, a 4 just saves him,
lose(held, "pit");
ghoul.advance(held, ghoul.ROLL_MS + 8, rolls(FOUR));
assert.equal(held.you.garlic, true, "a shield he already held stays");
const some = hall(1);
some.lives = 9;
lose(some, "zombie");
ghoul.advance(some, ghoul.ROLL_MS + 8, rolls(FIVE));
assert.equal(some.lives, 10, "a heart under the cap");
const full = hall(1);
full.lives = 9;
full.lives = ghoul.MAX_LIVES;
const score = full.score;
lose(full, "zombie");
ghoul.advance(full, ghoul.ROLL_MS + 8, rolls(FIVE));
assert.equal(full.lives, 10, "no cap");
assert.equal(full.score, score, "no points instead");
assert.equal(full.lives, ghoul.MAX_LIVES, "never past MAX_LIVES (13)");
assert.equal(full.score, score + ghoul.POWER_POINTS, "points instead");
});
test("Ghoul Rush: a 3 costs the life and he comes back with Rapid fire and a Garlic shield, a 2 with Bottle Rockets and a Garlic shield", () => {
@@ -0,0 +1,380 @@
// Web console tests, Ghoul Rush's ending: four pages that obey the story's rules (2 to 4 short lines, no digits, no em dash, YOU on each, the gag's FINAL NOTICE); the House's last room opens it instead of the win; a press turns pages only after the lockout and finishes the typing first; holding fire skips it, a tap never does; the last page wins the run once, with n = round.winN; the window's keys, a click, a pause, its track and its sounds; every scene draws on a fake canvas at many moments; every event it raises has a react; every tone it names exists.
// Run with: node --test scripts/test-web-console-activities-ghoul-ending.mjs
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
import ghoulSfx from "../src/web-console/public/activities/ghoul-rush/sfx/ghoul-sfx.js";
import { react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
import { PAGES as STORY_PAGES } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-story.js";
import {
CLICK_OFF_MS,
ENDING_HINT,
ENDING_LOCK_MS,
ENDING_TRACK,
FLAG_MS,
LAST_HINT,
LIGHTS_OUT,
MAX_LINE,
PAGES,
RELOCK_MS,
SKIP_HINT,
SKIP_HOLD_MS,
SLIDE_MS,
STAMP_MS,
UNFOLD_MS,
beginEnding,
pressEnding,
releaseEnding,
revealEnd,
skipEnding,
stepEnding,
takeEnding,
} from "../src/web-console/public/activities/ghoul-rush/story/ghoul-ending.js";
import { SCENE_H, TEXT_SIZE, endingArt, roadFlat, windowLit } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-ending-draw.js";
import { compileTrack } from "../src/web-console/public/music.js";
import { toneNames } from "../src/web-console/public/tones.js";
const steady = () => 0.5;
const DASH = String.fromCharCode(0x2014);
const events = (round, type) => round.events.filter((e) => e.type === type);
const isTone = (name) => toneNames().includes(name) || Object.hasOwn(ghoulSfx.tones, name);
function fakeCtx(texts) {
return new Proxy({}, {
get: (t, name) => (name in t ? t[name] : name === "fillText" ? (s) => texts.push(String(s)) : () => {}),
set: (t, name, value) => ((t[name] = value), true),
});
}
function through(round) {
round.phase = "clear";
round.phaseMs = 1;
ghoul.advance(round, 4, steady);
}
// A round walked through the hall and every stage to the House, then through each of the finale's rooms until the ending opens.
function toEnding(seed = 4) {
const round = ghoul.newRound(seed);
round.dice = 0;
through(round);
round.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES).map((st) => st.id);
round.offer = null;
through(round);
assert.equal(round.stage, ghoul.FINALE.id, "the House");
for (let k = 0; k < 20 && round.phase !== "ending"; k++) through(round);
assert.equal(round.phase, "ending", "the House's last room opens the ending");
return round;
}
// A window game in the ending, from the stage select's last entry (the House), and its sounds.
function openGame() {
const texts = [];
const sounds = [];
const tracks = [];
const ctx = fakeCtx(texts);
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, tone: (name) => sounds.push(name), music: (name) => tracks.push(name) });
g.resize(900, 900);
g.stageSelect();
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g.key("down");
g.key("action");
assert.equal(g.round.stage, ghoul.FINALE.id);
for (let k = 0; k < 20 && g.round.phase !== "ending"; k++) through(g.round);
assert.equal(g.round.phase, "ending");
g.tick(16);
return { g, texts, sounds, tracks };
}
const tick = (g, ms) => {
for (let t = 0; t < ms; t += 16) g.tick(16);
};
const lock = (g) => tick(g, ENDING_LOCK_MS + 20);
// To the point the page can turn: its typing done and its scene played out.
const playedOut = (pg) => Math.max(revealEnd(pg), pg.wait);
const typedOut = (g) => tick(g, playedOut(PAGES[g.round.ending.page]) - g.round.ending.ms + 40);
test("Ghoul Rush ending: four pages, 2 to 4 short lines each that fit the field, no digits, no em dash, never the hero's name, YOU on every page", () => {
assert.equal(PAGES.length, 4);
assert.deepEqual(PAGES.map((p) => p.chapter), ["LIGHTS OUT", "THE ROAD", "MORNING", "FINAL NOTICE"]);
assert.equal(new Set(PAGES.map((p) => p.id)).size, PAGES.length, "unique ids");
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(!/\d/.test(text), `${p.id} has no digit`);
assert.ok(!/planny|the player|the hero|\bhero\b/i.test(text), `${p.id} never names the hero`);
assert.ok(/\bYOU\b/.test(p.lines.join(" ")), `${p.id} speaks to YOU`);
for (const line of p.lines) {
assert.ok(line.length <= MAX_LINE, `${p.id}: "${line}" is ${line.length} characters`);
assert.ok(line.length * TEXT_SIZE * 0.62 <= ghoul.FIELD_W - 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(isTone(name), `${p.id}: ${name} is a tone`);
}
assert.ok(p.cues.every((c, i) => i === 0 || c[0] >= p.cues[i - 1][0]), `${p.id}: its cues are in order`);
}
const lines = PAGES.flatMap((p) => p.lines);
assert.equal(new Set(lines).size, lines.length, "no line used twice");
const story = new Set(STORY_PAGES.flatMap((p) => p.lines));
assert.ok(lines.every((l) => !story.has(l)), "no line copied from the intro story");
const all = lines.join("\n");
assert.ok(all.includes("FINAL NOTICE") && /unpaid bills/.test(all), "the mailbox gag lands");
assert.ok(/unfolds/.test(all) && /cottage/.test(all), "the road and the cottage it was once");
assert.equal(ENDING_TRACK, "ghoulMarrowEnding");
});
test("Ghoul Rush ending: the scene timings agree with the cues (a falling tone per window, the click, the flag, the slide, the stamp)", () => {
const lights = PAGES[0].cues.filter(([, n]) => n === "ghoulEndingWindow" || n === "ghoulEndingLast");
assert.deepEqual(lights.map(([ms]) => ms), LIGHTS_OUT.map(([, ms]) => ms), "a tone as each window goes out");
assert.equal(lights.at(-1)[1], "ghoulEndingLast", "the last window has its own tone");
const rates = lights.slice(0, -1).map((c) => c[3]);
assert.ok(rates.every((r, i) => i === 0 || r < rates[i - 1]), "each window's tone a little lower");
assert.equal(new Set(LIGHTS_OUT.map(([i]) => i)).size, 10, "every one of the house's ten windows goes out");
assert.ok(LIGHTS_OUT.at(-1)[1] - LIGHTS_OUT.at(-2)[1] >= 1000, "a long breath before the last");
for (const [i, ms] of LIGHTS_OUT) {
assert.equal(windowLit(i, ms - 1), 1);
assert.equal(windowLit(i, ms + 2000), 0);
}
assert.equal(roadFlat(0, 0), 0, "the road starts folded");
assert.equal(roadFlat(0, 20000), 1, "and ends flat");
assert.ok(roadFlat(10, UNFOLD_MS + 600) > roadFlat(0, UNFOLD_MS + 600), "it unfolds from the far end toward YOU");
const cue = (pg, name) => PAGES[pg].cues.find(([, n]) => n === name)?.[0];
assert.equal(cue(1, "ghoulEndingClickOff"), CLICK_OFF_MS);
assert.equal(cue(1, "ghoulEndingFold"), UNFOLD_MS);
assert.equal(cue(3, "ghoulEndingFlag"), FLAG_MS);
assert.equal(cue(3, "ghoulEndingPaper"), SLIDE_MS);
assert.equal(cue(3, "ghoulEndingStamp"), STAMP_MS);
});
test("Ghoul Rush ending: the House's end opens it instead of the win, and nothing else moves while it is up", () => {
const round = toEnding();
assert.equal(round.won, false, "not won yet");
assert.equal(round.over, false);
assert.equal(round.winN, ghoul.RUN_STAGES + 1);
assert.equal(events(round, "won").length, 0);
assert.deepEqual(events(round, "endingPage").map((e) => e.page), [0]);
assert.equal(round.ending.page, 0);
round.input.right = true;
const x = round.you.x;
const clock = round.clock;
ghoul.advance(round, 2000, steady);
assert.equal(round.you.x, x, "YOU stay put");
assert.equal(round.clock, clock, "the room's clock holds");
assert.equal(round.phase, "ending");
assert.ok(round.ending.ms >= 2000);
assert.equal(beginEnding({ ...round, events: [], input: {} }), true, "beginEnding says there is an ending");
});
test("Ghoul Rush ending: a press turns a page only after the lockout, typing finishes first, and the last page wins the run once with n = winN", () => {
const round = toEnding();
round.events.length = 0;
assert.equal(takeEnding(round), false, "not at once");
ghoul.advance(round, ENDING_LOCK_MS - 40, steady);
assert.equal(takeEnding(round), false, "not before the lockout");
ghoul.advance(round, 60, steady);
assert.ok(round.ending.ms < revealEnd(PAGES[0]));
assert.equal(takeEnding(round), true);
assert.equal(round.ending.page, 0, "the first press finishes the typing");
assert.equal(round.ending.full, true);
assert.equal(takeEnding(round), false, "a press right on top of it does not count");
ghoul.advance(round, RELOCK_MS + 20, steady);
assert.equal(takeEnding(round), false, "the page waits for its scene to play out (the last window)");
assert.equal(round.ending.page, 0);
ghoul.advance(round, PAGES[0].wait - round.ending.ms + 10, steady);
assert.ok(round.ending.ms >= LIGHTS_OUT.at(-1)[1], "every window is out by then");
assert.equal(takeEnding(round), true);
assert.equal(round.ending.page, 1, "now the page turns");
assert.equal(round.ending.ms, 0);
assert.equal(takeEnding(round), false, "each page has its own lockout");
for (let at = 1; at < PAGES.length; at++) {
assert.equal(round.ending.page, at);
assert.equal(round.won, false, `not won on page ${at + 1}`);
ghoul.advance(round, playedOut(PAGES[at]) + 20, steady);
assert.equal(takeEnding(round), true);
}
assert.deepEqual(events(round, "endingPage").map((e) => e.page), [1, 2, 3]);
assert.equal(round.won, true, "the last page's press wins");
assert.equal(round.over, true);
assert.equal(round.ending, null);
assert.notEqual(round.phase, "ending");
assert.deepEqual(events(round, "won"), [{ type: "won", stages: round.cleared.length, n: ghoul.RUN_STAGES + 1 }]);
assert.equal(takeEnding(round), false, "nothing to take after");
assert.equal(skipEnding(round), false, "nothing to skip after");
ghoul.advance(round, 2000, steady);
assert.equal(events(round, "won").length, 1, "the won event fires once");
});
test("Ghoul Rush ending: holding fire for a second skips it all on any page, a tap or a short hold does not, and a skip always works", () => {
const r = toEnding();
assert.equal(pressEnding(r, true), false, "a repeat is nothing");
assert.equal(r.ending.hold, -1);
assert.equal(pressEnding(r, false), true);
assert.equal(r.ending.hold, 0, "a fresh press starts the clock");
stepEnding(r, SKIP_HOLD_MS - 50);
assert.equal(r.phase, "ending");
releaseEnding(r);
assert.equal(r.ending.hold, -1, "let go stops the clock");
stepEnding(r, 3000);
assert.equal(r.phase, "ending");
pressEnding(r, false);
stepEnding(r, SKIP_HOLD_MS + 10);
assert.equal(r.won, true, "the hold skipped it all");
assert.equal(r.over, true);
assert.equal(events(r, "won").length, 1);
// A skip from any page.
for (let at = 0; at < PAGES.length; at++) {
const s = toEnding(at + 7);
s.ending.page = at;
assert.equal(skipEnding(s), true);
assert.equal(s.won, true);
assert.equal(events(s, "won")[0].n, s.winN);
}
assert.equal(skipEnding(ghoul.newRound(1)), false, "no ending, nothing to skip");
});
test("Ghoul Rush ending: the window's keys, any move and fire alike, turn pages; repeats and early presses never do; a click does; a pause holds it", () => {
for (const name of ["left", "right", "up", "down", "action"]) {
const { g } = openGame();
g.key(name);
assert.equal(g.round.ending.full, false, `${name}: early press ignored`);
g.release(name);
lock(g);
g.key(name, true);
assert.equal(g.round.ending.full, false, `${name}: a repeat is ignored`);
g.key(name);
assert.equal(g.round.ending.full, true, `${name}: a fresh press finishes the typing first`);
g.release(name);
typedOut(g);
g.key(name);
assert.equal(g.round.ending.page, 1, `${name}: the next press turns it`);
g.release(name);
assert.equal(g.round.input.fire || g.round.input.left || g.round.input.right || g.round.input.up || g.round.input.down, false, `${name}: nothing is kept held`);
}
const { g } = openGame();
lock(g);
g.pointer("down", 10, 10);
assert.equal(g.round.ending.full, true, "a click finishes the typing");
typedOut(g);
g.pointer("down", 10, 10);
assert.equal(g.round.ending.page, 1, "and the next click turns the page");
g.pause();
const held = g.round.ending.ms;
tick(g, 2000);
assert.equal(g.round.ending.ms, held, "a pause holds the page's clock");
g.key("action");
assert.equal(g.round.ending.hold, -1, "no key counts while paused");
g.resume();
tick(g, 100);
assert.ok(g.round.ending.ms > held);
});
test("Ghoul Rush ending: through every page on a real clock to the end screen, with its track, its tones, page turns and the escape", () => {
const { g, texts, sounds, tracks } = openGame();
tick(g, 1300);
assert.ok(tracks.length && tracks.every((t) => t === ENDING_TRACK), "only the ending's track plays under it");
assert.ok(sounds.includes("ghoulEndingHush") && sounds.includes("ghoulEndingWindow"), "the first page's tones play");
let guard = 0;
while (g.state === "running" && guard++ < 20) {
typedOut(g);
tick(g, RELOCK_MS + 40);
g.key("right");
g.release("right");
tick(g, 16);
}
assert.equal(g.state, "over");
assert.equal(g.round.won, true);
assert.ok(sounds.includes("ghoulStoryPage"), "a page turn rustles");
for (const n of ["ghoulEndingFold", "ghoulEndingClickOff", "ghoulEndingBird", "ghoulEndingFlag", "ghoulEndingStamp"]) assert.ok(sounds.includes(n), `${n} played`);
texts.length = 0;
g.resize(900, 900);
assert.ok(texts.some((t) => t.startsWith("You escaped! Marrow starves")), "the end screen follows");
// Held fire skips it in the window too.
const { g: h } = openGame();
for (let k = 0; k < 20; k++) h.key("action", true);
tick(h, 2000);
assert.equal(h.round.phase, "ending", "a held key from before never skips");
h.key("action");
h.key("action", true);
tick(h, SKIP_HOLD_MS + 100);
assert.equal(h.state, "over");
assert.equal(h.round.won, true);
});
test("Ghoul Rush ending: every scene draws on a fake canvas at many moments, with its heading, hints and lines, without throwing", () => {
const { g, texts } = openGame();
for (let at = 0; at < PAGES.length; at++) {
for (const ms of [0, 1, 120, 600, 900, 1100, 1500, 2300, 2900, 3100, 4000, 4600, 5200, 6200, 6500, 8000, 12000, 40000]) {
for (const full of [false, true]) {
for (const hold of [-1, 500]) {
g.round.ending = { page: at, ms, full, arm: 0, hold, cue: 99, shown: 0, back: "clear" };
g.tick(1);
}
}
}
g.round.ending = { page: at, ms: 100, full: false, arm: 0, hold: -1, cue: 99, shown: 0, back: "clear" };
texts.length = 0;
g.tick(1);
assert.ok(texts.includes(SKIP_HINT.toUpperCase()), `page ${at + 1} shows how to skip`);
assert.equal(texts.includes(ENDING_HINT) || texts.includes(LAST_HINT), false, "no continue hint inside the lockout");
if (PAGES[at].wait) {
g.round.ending.ms = PAGES[at].wait - 100;
g.round.ending.full = true;
texts.length = 0;
g.tick(1);
assert.equal(texts.includes(ENDING_HINT) || texts.includes(LAST_HINT), false, `page ${at + 1}: no continue hint while its scene plays out`);
}
g.round.ending.ms = 60000;
g.round.ending.full = true;
texts.length = 0;
g.tick(1);
assert.ok(texts.includes(PAGES[at].chapter), `page ${at + 1} draws its heading`);
assert.ok(texts.includes(at === PAGES.length - 1 ? LAST_HINT : ENDING_HINT), `page ${at + 1} shows the continue hint`);
for (const line of PAGES[at].lines) assert.ok(texts.includes(line), `page ${at + 1}: "${line}" is drawn in full`);
}
assert.ok(texts.includes("FINAL NOTICE"), "the stamp reads FINAL NOTICE");
assert.ok(SCENE_H > 20 && SCENE_H < 40, "the scene keeps to the top of the field");
// The art alone, with no ending: draws nothing and does not throw.
const art = endingArt({ label() {}, GOLD: "#fc0", BONE: "#eee" });
art.card(fakeCtx([]), { round: { ending: null } });
});
test("Ghoul Rush ending: every event it raises has a react, its own react answers only its own events, and every tone it owns is a real, prefixed sound", () => {
const round = toEnding();
const s = round.ending;
for (let at = 0; at < PAGES.length; at++) {
s.page = at;
s.ms = 0;
s.cue = 0;
s.full = false;
stepEnding(round, 10000);
s.arm = 0;
takeEnding(round);
}
skipEnding(round);
const kinds = new Set(round.events.map((e) => e.type));
for (const kind of ["endingPage", "storyTone", "won"]) assert.ok(kinds.has(kind), `${kind} is raised`);
const played = [];
const marks = [];
const fx = { tone: (n) => played.push(n), burst() {}, float() {}, ring() {}, banner: () => ({}), shake() {}, flash() {}, glow() {}, splat() {}, fx: { clock: 0, banners: [] }, markFurthest: (n) => marks.push(n), roomBanner() {}, monsters: {}, powers: {}, bosses: {}, g: ghoul };
for (const e of round.events) {
if (!["endingPage", "storyTone", "won"].includes(e.type)) continue;
react(e, fx);
}
assert.ok(played.includes("ghoulStoryPage"), "a page turn plays its rustle");
assert.ok(played.includes("ghoulEndingWindow") && played.includes("ghoulEndingGag"), "the timed tones play through the story's own event");
assert.deepEqual(marks, [ghoul.RUN_STAGES + 1], "the win marks the House beaten");
const art = endingArt({ label() {}, GOLD: "#fc0", BONE: "#eee" });
const k = { tone() {} };
assert.equal(art.react({ type: "endingPage", page: 1 }, k), true);
for (const type of ["won", "storyTone", "storyPage", "kill", "hit", "room"]) assert.equal(art.react({ type }, k), false, `${type} is not its own`);
const own = Object.keys(ghoulSfx.tones).filter((n) => n.startsWith("ghoulEnding"));
assert.ok(own.length >= 10, "a handful of the ending's own tones");
for (const p of PAGES) for (const [, name] of p.cues) assert.ok(isTone(name), `${name} exists`);
const track = ghoulSfx.music[ENDING_TRACK];
assert.ok(track, "the ending's track is in the game's music");
const song = compileTrack(track);
assert.ok(song.length >= 64, "it runs a few bars");
// The user's pick (eighties horror end credits): a steady middle tempo, never a race.
assert.ok(track.bpm >= 84 && track.bpm <= 120, "a middle tempo");
assert.equal(track.rush || 0, 0, "it never races");
});
@@ -0,0 +1,703 @@
// Web console tests, Ghoul Rush's finale, Kill II, Every Room at Once (the dollhouse): the room
// agrees with the rules' house, the boss's box out of reach and always guarded, the Eye (a lamp
// flares first, it opens, never twice running in one room, hit only through its open box from its
// own floor, a clank while it flares or shuts, two lamps and one true in its last phase), the
// shades (the keepers beaten this run, a fixed three in practice, every stage's boss with a move,
// a door first, at most SHADE_CAP, each move telegraphed, costing a life with its own cause and
// dodged), the lurch (a creak first, YOU slid and stopped at the end walls, a dresser to jump or
// shoot apart), the kill and its retreat in order with the door kept until it has gone, a bot's
// fight length, the voices, words and drawing.
// Run with: node --test scripts/test-web-console-activities-ghoul-eye.mjs
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
import * as ey from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-eye.js";
import { LOOKS, LOSE_SOUNDS, LOSE_WORDS, VOICES } from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js";
import { react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
import { bossIntroFor } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-boss-intros.js";
import { toneNames } from "../src/web-console/public/tones.js";
const steady = () => 0.5;
const events = (round, type) => round.events.filter((e) => e.type === type);
const seededRandom = (seed) => {
let s = seed;
return () => (s = (s * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff;
};
function stubCanvas() {
const calls = { count: 0 };
const ctx = new Proxy({}, {
get: (target, name) => (name in target ? target[name] : () => { calls.count += 1; }),
set: (target, name, value) => { target[name] = value; return true; },
});
return { canvas: { width: 0, height: 0, getContext: () => ctx }, calls, ctx };
}
function through(round) {
round.phase = "clear";
round.phaseMs = 1;
ghoul.advance(round, 4, steady);
}
function skipCard(round) {
round.introMs = ghoul.INTRO_MIN_MS;
return ghoul.takeIntro(round);
}
// YOU standing on the floor `row` (0 to 2) at x, or on a shelf by index.
function standAt(round, x, row = 0) {
const y = ey.EYE_FLOORS[row];
const shelf = row ? round.spec.shelves.findIndex(([a, b, top]) => top === y && b - a > 20) : -1;
Object.assign(round.you, { x, y, vx: 0, vy: 0, state: "run", shelf, coyote: 0, drop: -1, cuttable: false, out: 0, safeMs: 0, face: 1, ducking: false });
}
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;
}
// A run's way to the dollhouse: the finale entered at `depth` stages, on through its rooms to
// this one, its boss's card passed, nothing else woken.
function eyeRound(depth = ghoul.RUN_STAGES) {
const round = ghoul.newRound(5);
round.dice = 0;
through(round);
round.cleared = ghoul.STAGES.slice(0, depth).map((st) => st.id);
round.offer = null;
through(round);
for (let n = 0; round.spec.id !== "dollhouse"; n++) {
assert.ok(n < 10, "the dollhouse is in the finale");
skipCard(round);
skipCard(round);
through(round);
}
skipCard(round);
round.phase = "play";
round.items.fill(true);
round.candy.fill(true);
round.events.length = 0;
return round;
}
// Nothing coming: the Eye shut a long while, no lurch, no door, no shade.
function calm(round) {
const b = round.boss;
Object.assign(b.eye, { state: "shut", ms: 1e9, room: -1, decoy: -1 });
Object.assign(b.lurch, { state: "wait", ms: 1e9 });
b.shadeMs = 1e9;
round.hazards.length = 0;
round.monsters.length = 0;
}
// The fight under way: YOU in the arena, the boss awake, everything calm.
function eyeFight(depth = ghoul.RUN_STAGES) {
const round = eyeRound(depth);
standAt(round, round.spec.arena + 14);
run(round, ghoul.BOSS_INTRO_MS + 100);
assert.equal(round.boss.state, "fight");
calm(round);
round.events.length = 0;
return round;
}
// The Eye opened now in room `i`.
function openIn(round, i) {
Object.assign(round.boss.eye, { state: "open", ms: 1e9, full: 4000, room: i, decoy: -1 });
}
/* --------------------------------------------------------------- the house */
test("Ghoul Rush's dollhouse: the room agrees with the rules' house, comes after the lawn and the mat in the finale, and its boss is the Eye, named on its card", () => {
const base = ghoul.roomById("dollhouse");
assert.equal(base.boss, "marroweye");
const rooms = ghoul.FINALE.rooms;
assert.ok(rooms.indexOf("dollhouse") > rooms.indexOf("lawn"), "after the lawn");
if (rooms.includes("mat")) assert.ok(rooms.indexOf("dollhouse") > rooms.indexOf("mat"), "after the mat");
const spec = ghoul.roomFor("dollhouse");
assert.equal(spec.arena + ey.EYE_COLS * ey.EYE_ROOM_W, spec.length, "the rooms fill the arena");
assert.equal(ghoul.groundAt(spec, spec.arena + 1), ey.EYE_FLOORS[0]);
for (const f of ey.EYE_FLOORS.slice(1)) assert.ok(spec.shelves.some(([a, b, y]) => y === f && a === spec.arena && b === spec.length), `a floor right across at ${f}`);
// A landing between each floor at each end, a jump from each to the next.
for (const [lo, hi] of [[ey.EYE_FLOORS[0], ey.EYE_FLOORS[1]], [ey.EYE_FLOORS[1], ey.EYE_FLOORS[2]]]) {
const landings = spec.shelves.filter(([a, b, y]) => b - a < 20 && y > lo && y < hi);
assert.equal(landings.length, 2, `two landings between ${lo} and ${hi}`);
for (const [, , y] of landings) assert.ok(y - lo <= ghoul.JUMP_TOP - 1 && hi - y <= ghoul.JUMP_TOP - 1, "a jump up to it and on");
}
assert.equal(ghoul.BOSSES.marroweye.name, bossIntroFor("marroweye").name);
assert.ok(LOOKS.dollhouse, "a look");
});
test("Ghoul Rush's dollhouse: the Eye's box is out of everything's reach and always guarded, a lost life keeps its hp, and the fight never costs a life by its box's touch", () => {
const round = eyeFight();
const b = round.boss;
assert.equal(ghoul.guarded(b), true);
assert.ok(b.y > ghoul.FIELD_H, "its box above the field");
assert.equal(b.max, round.spec.bossHp);
b.hp -= 10;
round.lives = 5;
ghoul.lose(round, "eyeRock");
run(round, ghoul.CRASH_MS + ghoul.READY_MS + 100);
assert.notEqual(round.boss, b, "a new boss object after the life lost");
assert.equal(round.boss.hp, b.hp, "the same hp");
// A climb to the top floor and back, under the box's x: no touch.
const r = eyeFight();
for (const row of [0, 1, 2]) {
standAt(r, r.spec.length - 2, row);
jumpUp(r);
run(r, 900);
}
assert.deepEqual(events(r, "lose"), []);
});
/* ----------------------------------------------------------------- the Eye */
test("Ghoul Rush's dollhouse: a lamp flares before the Eye opens (a second step heard), it opens in that room, shuts, and never opens in the same room twice running; its open time shrinks with its phase", () => {
const round = eyeFight();
const b = round.boss;
Object.assign(b.eye, { state: "shut", ms: 1 });
const order = [];
const random = ghoul.seeded(17);
for (let t = 0; t < 420000; t += 4) {
round.you.safeMs = 1e9;
b.shadeMs = 1e9;
b.lurch.ms = 1e9;
ghoul.advance(round, 4, random);
for (const e of round.events) if (e.type.startsWith("eye")) order.push([e.type, e.room, t]);
round.events.length = 0;
round.hazards.length = 0;
round.monsters.length = 0;
}
const flares = order.filter(([type]) => type === "eyeFlare");
const opens = order.filter(([type]) => type === "eyeOpen");
assert.ok(opens.length >= 10, `it opened many times (${opens.length})`);
for (let i = 0; i < opens.length; i++) {
const f = flares[i];
assert.equal(f[1], opens[i][1], "it opens where its lamp flared");
assert.ok(opens[i][2] - f[2] >= ey.EYE_FLARE_MS - 8, "after the whole flare");
if (i) assert.notEqual(opens[i][1], opens[i - 1][1], "never the same room twice running");
}
const steps = order.filter(([type]) => type === "eyeFlareStep").length;
assert.ok(steps >= opens.length && steps <= flares.length, "one step heard each flare");
assert.ok(ey.EYE_OPEN_MS[0] > ey.EYE_OPEN_MS[1] && ey.EYE_OPEN_MS[1] > ey.EYE_OPEN_MS[2], "shorter open each phase");
assert.equal(new Set(opens.map(([, room]) => room)).size, ey.EYE_ROOMS, "every room gets its turn");
});
test("Ghoul Rush's dollhouse: in its last phase two lamps flare and only one is true; the other pops out as the Eye opens", () => {
const round = eyeFight();
const b = round.boss;
b.hp = Math.floor(b.max * ey.PHASE_HP[1]) - 1;
assert.equal(ey.phaseOf(b), 2);
Object.assign(b.eye, { state: "shut", ms: 1 });
run(round, 8);
const flares = events(round, "eyeFlare");
assert.equal(flares.length, 2);
assert.equal(flares.filter((e) => e.decoy).length, 1);
assert.notEqual(flares[0].room, flares[1].room);
round.events.length = 0;
run(round, ey.EYE_FLARE_MS + 20);
assert.equal(events(round, "eyeOpen")[0].room, flares.find((e) => !e.decoy).room, "the true one opens");
assert.equal(events(round, "eyeDud")[0].room, flares.find((e) => e.decoy).room, "the false one pops out");
});
test("Ghoul Rush's dollhouse: the open Eye is hurt from its own floor by a bolt standing or ducked, from either side, never from another floor; flaring or shutting it clanks; shut, bolts pass", () => {
for (let i = 0; i < ey.EYE_ROOMS; i++) {
const r = ey.roomBox(eyeFight().spec, i);
for (const [side, duck] of [[-1, false], [1, true]]) {
const round = eyeFight();
openIn(round, i);
const x = Math.min(round.spec.length - 2, Math.max(round.spec.arena + 2, r.cx + side * 12));
standAt(round, x, r.row);
round.you.face = -side;
const hp = round.boss.hp;
run(round, 500, { fire: true, down: duck });
assert.ok(round.boss.hp < hp, `room ${i} from the ${side < 0 ? "left" : "right"}${duck ? ", ducked" : ""}`);
assert.ok(events(round, "bossHit").every((e) => e.how === "eye" && Math.abs(e.x - r.cx) < 0.01), "the hit shows at the Eye");
// From the floor over it, nothing.
const other = eyeFight();
openIn(other, i);
standAt(other, x, (r.row + 1) % 3);
other.you.face = -side;
run(other, 500, { fire: true });
assert.equal(other.boss.hp, other.boss.max, `room ${i}: not from another floor`);
}
}
for (const state of ["flare", "closing"]) {
const round = eyeFight();
Object.assign(round.boss.eye, { state, ms: 1e9, full: 1e9, room: 1 });
standAt(round, ey.roomBox(round.spec, 1).cx - 12);
run(round, 400, { fire: true });
assert.equal(round.boss.hp, round.boss.max, `${state}: no harm`);
assert.ok(events(round, "bossBlock").length > 0, `${state}: a clank`);
}
const shut = eyeFight();
standAt(shut, ey.roomBox(shut.spec, 1).cx - 12);
run(shut, 400, { fire: true });
assert.deepEqual([shut.boss.hp, events(shut, "bossBlock").length], [shut.boss.max, 0], "shut: bolts fly on");
});
/* -------------------------------------------------------------- the shades */
test("Ghoul Rush's dollhouse: every boss of every stage has a shade's move, a run's shades are the keepers it beat, and practice meets a fixed three", () => {
for (const st of ghoul.STAGES) assert.ok(ey.SHADE_MOVES[st.boss], `${st.boss} (${st.id}) has a shade move`);
for (const of of Object.keys(ey.SHADE_MOVES)) assert.ok(ghoul.BOSSES[of], `${of} is a boss`);
const round = eyeRound();
assert.deepEqual(ey.shadesOf(round, { stageById: ghoul.stageById }), round.cleared.map((id) => ghoul.stageById(id).boss));
assert.deepEqual(ey.shadesOf({ cleared: [] }, { stageById: ghoul.stageById }), [...ey.PRACTICE_SHADES]);
assert.equal(ey.PRACTICE_SHADES.length, 3);
});
test("Ghoul Rush's dollhouse: a door creaks open before its shade steps out, the shade fades in harmless and unhittable, never more than SHADE_CAP, and it fades away at the end of its life", () => {
const round = eyeFight();
const b = round.boss;
round.you.safeMs = 1e9;
b.shadeMs = 0;
run(round, 8);
assert.equal(events(round, "eyeDoor").length, 1, "the door first");
assert.equal(round.monsters.length, 0, "no shade yet");
const door = round.hazards.find((h) => h.kind === "eyeDoorway");
assert.ok(door && round.boss.lastShade === door.of && ey.shadesOf(round, { stageById: ghoul.stageById }).includes(door.of));
run(round, ey.EYE_DOOR_MS);
const m = round.monsters.find((q) => q.kind === "eyeShade");
assert.ok(m, "out steps a shade");
assert.equal(ghoul.solid(m), false, "fading in");
assert.ok(Math.abs(m.x - round.you.x) >= ey.SHADE_CLEAR / 2 || m.y !== round.you.y, "not on top of YOU");
run(round, ey.SHADE_IN_MS + 20);
assert.equal(ghoul.solid(m), true, "then solid");
for (let t = 0; t < 20000; t += 4) {
round.you.safeMs = 1e9;
ghoul.advance(round, 4, steady);
const alive = round.monsters.filter((q) => q.kind === "eyeShade").length + round.hazards.filter((h) => h.kind === "eyeDoorway").length;
assert.ok(alive <= ey.SHADE_CAP[ey.phaseOf(round.boss)], "never past the cap");
}
assert.ok(!round.monsters.includes(m), "gone at the end of its life");
const g = eyeFight();
g.you.safeMs = 1e9;
g.boss.shadeMs = 0;
run(g, 8);
g.boss.shadeMs = 1e9;
run(g, ey.EYE_DOOR_MS + ey.SHADE_LIFE_MS + 100);
assert.equal(g.monsters.length, 0, "a shade left alone fades by itself");
assert.equal(events(g, "eyeShadeOut").length, 1);
});
// A shade of `of` put in at x on YOUR floor, out and ready to move at once.
function shadeAt(round, of, x, row = 0) {
const y = ey.EYE_FLOORS[row];
round.hazards.push({ kind: "eyeDoorway", x, y, w: 3, h: 5, warn: 1, full: 1, live: 0, of, cause: "marroweye" });
run(round, 4);
const m = round.monsters.find((q) => q.kind === "eyeShade" && q.of === of);
Object.assign(m, { act: "idle", wait: 0, life: 1e9 });
round.events.length = 0;
return m;
}
// A full jump: the press, and up held (it stays held: holding it does nothing else) so it is not cut short.
const jumpUp = (r) => {
r.input.jump = ghoul.JUMP_BUFFER_MS;
r.input.up = true;
};
// How YOU dodge each move, called each slice: the shade `m`.
const floorThings = new Set(["eyeRipple", "eyeNote", "eyeHoop", "eyeMud"]);
const DODGE = {
hop: (r) => {
if (r.hazards.some((h) => floorThings.has(h.kind) && Math.abs(h.x - r.you.x) < 2 + h.speed * r.spec.pace * 0.1 && Math.sign(r.you.x - h.x) === h.dir)) jumpUp(r);
},
skull: (r) => {
r.input.down = r.hazards.some((h) => h.kind === "eyeSkull" && Math.abs(h.x - r.you.x) < 6);
},
creep: (r, m) => {
r.you.face = Math.sign(m.x - r.you.x) || 1;
},
scythe: (r) => {
if (r.hazards.some((h) => h.kind === "eyeScythe" && h.warn > 0 && h.warn < 100)) jumpUp(r);
},
dash: (r, m) => {
if (m.going && Math.abs(m.x - r.you.x) < 8 && Math.sign(r.you.x - m.x) === m.dir) jumpUp(r);
},
// Off its mark, away from it, each time it marks YOU.
leap: (r, m) => {
if (m.act === "wind" && Math.abs(m.tx - r.you.x) < 4) {
const away = Math.sign(r.you.x - m.x) || 1;
const x = r.you.x + away * 8;
standAt(r, x > r.spec.arena + 3 && x < r.spec.length - 3 ? x : r.you.x - away * 8);
}
},
// Away from the knocker, out from under each rock marked at YOU.
knock: (r, m) => {
if (!r.hazards.some((q) => q.kind === "eyeRock" && q.warn > 0 && Math.abs(q.x - r.you.x) < 3)) return;
const away = Math.sign(r.you.x - m.x) || 1;
const x = r.you.x + away * 7;
standAt(r, x > r.spec.arena + 3 && x < r.spec.length - 3 ? x : r.you.x - away * 14);
},
// Back the way YOU came: the second icicle falls a step ahead.
icicles: (r) => {
if (!r.hazards.some((q) => q.kind === "eyeIcicle" && q.warn > 0 && Math.abs(q.x - r.you.x) < 2.5)) return;
const x = r.you.x - (r.you.face || 1) * 9;
standAt(r, x > r.spec.arena + 3 && x < r.spec.length - 3 ? x : r.you.x + (r.you.face || 1) * 15);
},
};
DODGE.note = DODGE.hop;
DODGE.hoop = DODGE.hop;
DODGE.mud = DODGE.hop;
const CAUSE = { hop: "eyeRipple", skull: "eyeSkull", creep: "eyeShade", scythe: "eyeScythe", note: "eyeNote", dash: "eyeShade", leap: ["eyePounce", "eyeShade"], knock: "eyeRock", hoop: "eyeHoop", icicles: "eyeIcicle", mud: "eyeMud" };
test("Ghoul Rush's dollhouse: each keeper's shade telegraphs its move before it can hurt, hurts standing YOU with its own cause, and is dodged", () => {
for (const st of ghoul.STAGES) {
const of = st.boss;
const move = ey.SHADE_MOVES[of];
const near = move === "scythe" ? 7 : move === "dash" || move === "leap" || move === "creep" ? 12 : 16;
const hit = eyeFight();
standAt(hit, 70);
const m = shadeAt(hit, of, 70 + near);
// The angel comes on only while YOU look away.
if (move === "creep") hit.you.face = -1;
const losses = [];
let told = Infinity;
for (let t = 0; t < 6000 && !losses.length; t += 4) {
ghoul.advance(hit, 4, steady);
if (events(hit, "eyeShadeWind").length && told === Infinity) told = t;
losses.push(...events(hit, "lose").map((e) => [e.cause, t]));
hit.events.length = 0;
}
assert.equal(losses.length, 1, `${of} (${move}): it hurts`);
assert.ok([CAUSE[move]].flat().includes(losses[0][0]), `${of} (${move}): as ${CAUSE[move]} (${losses[0][0]})`);
if (move !== "creep") assert.ok(losses[0][1] - told >= 600, `${of} (${move}): telegraphed well before (${losses[0][1] - told} ms)`);
const safe = eyeFight();
standAt(safe, 70);
const s = shadeAt(safe, of, 70 + near);
const lost = [];
for (let t = 0; t < 6000; t += 4) {
safe.input.down = false;
DODGE[move](safe, s);
ghoul.advance(safe, 4, steady);
lost.push(...events(safe, "lose").map((e) => e.cause));
safe.events.length = 0;
}
assert.deepEqual(lost, [], `${of} (${move}): dodged`);
assert.ok(m.hp > 0, "its hp");
}
});
test("Ghoul Rush's dollhouse: a shade takes bolts and dies for points, and endless lives spare every hit", () => {
const round = eyeFight();
standAt(round, 60);
const m = shadeAt(round, "gourd", 75);
m.wait = 1e9;
const score = round.score;
run(round, 2000, { fire: true });
assert.ok(!round.monsters.includes(m), "shot down");
assert.ok(events(round, "kill").some((e) => e.kind === "eyeShade"));
assert.ok(round.score > score);
const r = eyeFight();
r.infinite = true;
standAt(r, 70);
shadeAt(r, "keeper", 77);
const lives = r.lives;
run(r, 3000);
assert.ok(events(r, "lose").length >= 1, "hit");
assert.equal(r.lives, lives, "no life spent");
});
/* --------------------------------------------------------------- the lurch */
test("Ghoul Rush's dollhouse: the house creaks before it lurches, slides YOU while YOU stand (never in the air) and stops YOU at its end walls; a dresser comes down YOUR floor: jump it, or shoot it apart", () => {
const round = eyeFight();
const b = round.boss;
standAt(round, 70);
round.you.safeMs = 1e9;
Object.assign(b.lurch, { ms: 0 });
b.planLurch = 1;
run(round, 8);
assert.equal(events(round, "eyeCreak").length, 1, "a creak first");
assert.equal(round.you.x, 70, "nothing slides yet");
const dresser = round.hazards.find((h) => h.kind === "eyeDresser");
assert.ok(dresser && dresser.y === round.you.y && dresser.x < round.you.x, "a dresser uphill on YOUR floor");
run(round, ey.EYE_CREAK_MS);
assert.equal(events(round, "eyeLurch").length, 1);
const x = round.you.x;
run(round, 500);
assert.ok(round.you.x > x + 4, `slid (${(round.you.x - x).toFixed(1)})`);
standAt(round, round.spec.length - 2);
run(round, 800);
assert.ok(round.you.x <= round.spec.length - ey.WALL_PAD + 0.01, "held at the end wall");
// In the air, nothing pushes.
const air = eyeFight();
Object.assign(air.boss.lurch, { state: "go", ms: 1e9, dir: 1 });
standAt(air, 70);
Object.assign(air.you, { state: "air", vy: 0, y: 30, shelf: -1 });
const ax = air.you.x;
ghoul.advance(air, 4, steady);
assert.equal(air.you.x, ax);
// The dresser: it costs a life, a jump clears it, three bolts break it.
const go = () => {
const r = eyeFight();
standAt(r, 64);
r.boss.lurch.ms = 0;
r.boss.planLurch = 1;
run(r, 8);
return r;
};
const hit = go();
let lost = [];
for (let t = 0; t < 5000 && !lost.length; t += 4) {
ghoul.advance(hit, 4, steady);
lost = events(hit, "lose").map((e) => e.cause);
hit.events.length = 0;
}
assert.deepEqual(lost, ["eyeDresser"]);
const jump = go();
for (let t = 0; t < 5000; t += 4) {
const d = jump.hazards.find((h) => h.kind === "eyeDresser" && h.live > 0);
if (d && jump.you.x - d.x < 8 && jump.you.x > d.x) jumpUp(jump);
ghoul.advance(jump, 4, steady);
assert.deepEqual(events(jump, "lose"), [], "jumped");
jump.events.length = 0;
}
const shoot = go();
shoot.you.face = -1;
run(shoot, 2500, { fire: true });
assert.equal(events(shoot, "eyeDresserSmash").length, 1, "shot apart");
assert.deepEqual(events(shoot, "lose"), []);
});
/* ---------------------------------------------------------------- the kill */
test("Ghoul Rush's dollhouse: the last bolt in the Eye is a boss kill; its retreat plays once and in order; the door is kept from YOU until it has gone, then leads on", () => {
const round = eyeFight();
const b = round.boss;
b.hp = 1;
openIn(round, 1);
standAt(round, ey.roomBox(round.spec, 1).cx - 12);
const lives = round.lives;
run(round, 400, { fire: true });
assert.equal(b.state, "down");
assert.equal(round.lives, lives + 1, "a life, as every boss gives");
assert.equal(round.hasKey, true);
const order = [];
for (let t = 0; t < ey.GONE_AT + 1500 && round.phase !== "clear"; t += 4) {
standAt(round, round.spec.door);
round.input.right = true;
ghoul.advance(round, 4, steady);
for (const e of round.events) if (e.type.startsWith("eye")) order.push([e.type, Math.round(b.t)]);
round.events.length = 0;
if (!b.gone) assert.ok(round.you.x <= round.spec.door - ey.DOOR_KEEP + 0.2, "no door until it has gone");
}
assert.deepEqual(order.map(([t]) => t), ["eyeBurst", "eyePeel", "eyeCrack", "eyeCrack", "eyeCrack", "eyeGasp", "eyeSink", "eyeGone"]);
assert.ok(order[1][1] >= ey.PEEL_AT && order.at(-1)[1] >= ey.GONE_AT, "on the retreat's clock");
assert.equal(b.gone, true);
assert.equal(round.phase, "clear", "down its stairway of bones");
const next = ghoul.FINALE.rooms[ghoul.FINALE.rooms.indexOf("dollhouse") + 1];
run(round, ghoul.CLEAR_MS + 50);
if (next) assert.equal(round.spec.id, next, "on to the next room");
else assert.equal(round.won, true, "or the win while it is the last");
});
/* --------------------------------------------------------------- the fight */
// A steady player: when a lamp flares it goes to that room's floor (CLIMB_MS a floor, firing nothing
// on the way: the bot is put there after), stands a way off the Eye facing it and fires while it is
// open; jumps what runs along its floor, the dresser, a dashing shade; ducks a skull; steps out from
// under a rock, an icicle or a beast's mark; and shoots what shade is on its floor while the Eye is shut.
const CLIMB_MS = 1500;
function fight(seed, skilled = true) {
const round = eyeFight();
const random = seededRandom(seed);
Object.assign(round.boss.eye, { state: "shut", ms: 600 });
round.boss.lurch.ms = ey.EYE_LURCH_FIRST_MS;
round.boss.shadeMs = ey.SHADE_FIRST_DOOR_MS;
let at = 0;
let travel = 0;
let t = 0;
const causes = [];
const spec = round.spec;
for (; t < 300000 && round.boss.state !== "down" && !round.over; t += 4) {
const you = round.you;
const inp = round.input;
const b = round.boss;
inp.left = inp.right = inp.fire = inp.down = false;
if (round.phase === "ask") ghoul.answerDie(round, false);
if (skilled && round.phase === "play" && you.out <= 0 && you.state === "run") {
const row = ey.rowOf(you.y);
const level = (h) => Math.abs(h.y - ey.EYE_FLOORS[row]) < 0.5;
const runner = round.hazards.find((h) => (floorThings.has(h.kind) || h.kind === "eyeDresser") && h.live > 0 && level(h) && Math.abs(h.x - you.x) < 3 + (h.speed || ey.DRESSER_SPEED) * 0.13 && Math.sign(you.x - h.x) === (h.dir || 1));
const scythe = round.hazards.find((h) => h.kind === "eyeScythe" && level(h) && h.warn > 0 && h.warn < 100 && Math.abs(h.x - you.x) < h.w / 2 + 2);
const dasher = round.monsters.find((m) => m.kind === "eyeShade" && m.going && m.move === "dash" && Math.abs(m.floor - you.y) < 0.5 && Math.abs(m.x - you.x) < 7);
const skull = round.hazards.find((h) => h.kind === "eyeSkull" && Math.abs(h.y - ey.SKULL_UP - you.y) < 0.5 && Math.abs(h.x - you.x) < 6);
const above = round.hazards.find((h) => (h.kind === "eyeRock" || h.kind === "eyeIcicle") && h.warn > 0 && Math.abs(h.floor - you.y) < 0.5 && Math.abs(h.x - you.x) < 3);
const mark = round.monsters.find((m) => m.kind === "eyeShade" && m.move === "leap" && (m.act === "wind" || m.going) && Math.abs(m.floor - you.y) < 0.5 && Math.abs(m.tx - you.x) < 4);
const e = b.eye;
if (runner || scythe || dasher) jumpUp(round);
else if (skull) inp.down = true;
else if (above || mark) {
const from = above ? above.x : mark.tx;
const dir = from >= you.x ? -1 : 1;
inp[you.x + dir * 4 < spec.arena + 2 || you.x + dir * 4 > spec.length - 2 ? (dir < 0 ? "right" : "left") : dir < 0 ? "left" : "right"] = true;
} else if (travel > 0) travel -= 4;
else if (e && e.room >= 0 && e.state !== "shut") {
const r = ey.roomBox(spec, e.room);
if (r.row !== at) {
travel = CLIMB_MS * Math.abs(r.row - at);
at = r.row;
} else {
const side = r.cx - 13 > spec.arena + 2 ? -1 : 1;
const x = r.cx + side * 13;
if (row !== r.row || Math.abs(you.x - x) > 5) standAt(round, x, r.row);
you.face = -side;
inp.fire = e.state === "open";
}
} else {
const m = round.monsters.find((q) => q.kind === "eyeShade" && ghoul.solid(q) && Math.abs(q.floor - you.y) < 0.5 && Math.abs(q.x - you.x) < 40);
if (m) {
you.face = Math.sign(m.x - you.x) || you.face;
inp.fire = true;
}
}
}
ghoul.advance(round, 4, random);
causes.push(...events(round, "lose").map((e) => e.cause));
round.events.length = 0;
}
return { won: round.boss.state === "down", secs: t / 1000, causes, round };
}
test("Ghoul Rush's dollhouse takes a steady player a real fight at full depth: 60 to 120 seconds on most seeds, with lives to spare; a player who stands still dies", () => {
const times = [];
const lives = [];
let good = 0;
for (const seed of [3, 7, 19, 41]) {
const f = fight(seed);
assert.ok(f.won, `seed ${seed}: it fell (${f.causes}; ${f.secs.toFixed(1)} s, hp ${f.round.boss.hp})`);
assert.ok(f.round.lives > 0, `seed ${seed}: lives to spare (${f.causes})`);
for (const c of f.causes) assert.ok(LOSE_WORDS[c] || ghoul.MONSTERS[c], `${c} is the House's or one of the dead`);
if (process.env.EYE_DEBUG) console.log(`seed ${seed}: ${f.won ? "won" : "lost"} in ${f.secs.toFixed(1)} s, lives ${f.round.lives}, ${f.causes}`);
if (f.secs >= 60 && f.secs <= 120) good++;
times.push(f.secs);
lives.push(f.round.lives);
}
assert.ok(good >= 3, `most seeds in 60 to 120 s (${times.map((x) => x.toFixed(1))}; lives ${lives})`);
const idle = fight(7, false);
assert.equal(idle.won, false);
assert.ok(idle.round.over, `game over (${idle.causes})`);
assert.equal(idle.round.boss.hp, idle.round.boss.max, "and not a scratch on it");
});
/* ------------------------------------------------- voices, words, drawing */
const heard = (e) => {
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, splats: [] }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, markFurthest: noop };
react(e, kit);
return played;
};
test("Ghoul Rush's Eye: a voice for every act in tones.js, every event plays its own sound once, and every cause has words and a sound", () => {
const known = new Set(toneNames());
for (const kind of ["marroweye", "eyeShade"]) for (const [act, name] of Object.entries(VOICES[kind])) assert.ok(known.has(name), `${kind} ${act}: ${name} is a tone`);
const eye = { marroweye: { eyeFlare: "flare", eyeFlareStep: "flareStep", eyeOpen: "open", eyeShut: "shut", eyeDud: "dud", eyeDoor: "door", eyeCreak: "creak", eyeCreakStep: "creakStep", eyeLurch: "lurch", eyeDresserCrash: "crash", eyeDresserSmash: "smash", eyeBurst: "burst", eyePeel: "peel", eyeCrack: "crack", eyeGasp: "gasp", eyeSink: "sink", eyeGone: "gone", bossWake: "wake", bossHit: "hurt", bossDown: "die" }, eyeShade: { eyeShadeIn: "come", eyeShadeOut: "fade", eyeShadeWind: "wind", eyeShadeSlam: "slam", eyeSkullThrow: "throw", eyeShadeGrind: "grind", eyeScythe: "scythe", eyeNote: "note", eyeShadeDash: "dash", eyeShadeLeap: "leap", eyePounce: "pounce", eyeKnock: "knock", eyeRockLand: "rock", eyeHoop: "hoop", eyeIcicleLand: "icicle", eyeMud: "mud", hit: "hurt", kill: "die" } };
for (const [kind, cases] of Object.entries(eye)) {
for (const [type, act] of Object.entries(cases)) {
const played = heard({ type, kind, x: 80, y: 20, xs: [70], ty: 20, tx: 70, at: 70, n: 1, dir: 1, move: "hop", how: "eye", points: 1, mult: 1, life: true });
assert.equal(played.filter((n) => n === VOICES[kind][act]).length, 1, `${type}: ${VOICES[kind][act]} once`);
}
}
// Every event the rules push is one of those.
const pushed = new Set();
const round = eyeFight();
round.you.safeMs = 1e9;
round.boss.hp = Math.floor(round.boss.max * 0.3);
Object.assign(round.boss.eye, { state: "shut", ms: 1 });
round.boss.lurch.ms = 0;
round.boss.shadeMs = 0;
const random = seededRandom(9);
for (let t = 0; t < 60000; t += 4) {
round.you.safeMs = 1e9;
ghoul.advance(round, 4, random);
for (const e of round.events) if (e.type.startsWith("eye")) pushed.add(e.type);
round.events.length = 0;
}
const all = new Set([...Object.keys(eye.marroweye), ...Object.keys(eye.eyeShade), "eyeSkullTurn"]);
for (const type of pushed) assert.ok(all.has(type), `${type} has a reaction`);
for (const cause of ["marroweye", "eyeShade", "eyeRipple", "eyeSkull", "eyeScythe", "eyeNote", "eyePounce", "eyeRock", "eyeHoop", "eyeIcicle", "eyeMud", "eyeDresser"]) {
assert.ok(LOSE_WORDS[cause], `${cause}: words`);
assert.ok(known.has(LOSE_SOUNDS[cause][0]), `${cause}: a sound`);
}
});
test("Ghoul Rush's dollhouse draws: the landing, the fight with the Eye in every state, every keeper's shade and move, the lurch, every beat of the retreat, lit and dark, and its card with the card's fake view", () => {
const { canvas, calls, ctx } = stubCanvas();
const g = ghoul.default.create({ canvas });
g.resize(900, 900);
g.stageSelect();
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g.key("down");
for (let i = 0; i < ghoul.FINALE.rooms.indexOf("dollhouse"); i++) g.key("right");
g.key("action");
for (let n = 0; n < 2 && g.round.phase !== "ready"; n++) {
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 50; ms += 16) g.tick(16);
g.key("action");
}
const r = g.round;
assert.equal(r.spec.id, "dollhouse");
r.infinite = true;
const frame = (label) => {
const before = calls.count;
g.tick(16);
assert.ok(calls.count > before, `${label} draws`);
};
for (const dark of [false, true]) {
r.dark = dark;
standAt(r, 10);
frame("the landing");
standAt(r, r.spec.arena + 14);
for (let ms = 0; ms < 1600; ms += 16) g.tick(16);
for (const [state, decoy] of [["flare", -1], ["flare", 6], ["open", -1], ["closing", -1], ["shut", -1]]) {
Object.assign(r.boss.eye, { state, ms: 300, full: 1000, room: 4, decoy });
frame(`the Eye ${state}`);
}
for (const st of ghoul.STAGES) {
Object.assign(r, { phase: "play" });
Object.assign(r.you, { out: 0, safeMs: 1e9 });
shadeAt(r, st.boss, 90, 1);
for (let ms = 0; ms < 1500; ms += 16) frame(`${st.boss}'s shade`);
r.monsters.length = 0;
r.hazards.length = 0;
}
Object.assign(r.boss.lurch, { state: "creak", ms: 300 });
r.boss.planLurch = 1;
for (let ms = 0; ms < 2000; ms += 16) frame("the lurch");
for (const t of [100, ey.PEEL_AT + 300, ey.CRACK_AT[2] + 100, ey.GASP_AT + 200, ey.SINK_AT + 900, ey.GONE_AT + 100]) {
Object.assign(r.boss, { state: "down", t, gone: t >= ey.GONE_AT });
frame(`the retreat at ${t}`);
}
Object.assign(r.boss, { state: "fight", t: 0, gone: false });
}
// The card draws the boss with its own fake view: no round, no spec, FIELD_H 0.
const before = calls.count;
g.stageSelect();
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g.key("down");
for (let i = 0; i < ghoul.FINALE.rooms.indexOf("dollhouse"); i++) g.key("right");
g.key("action");
assert.equal(g.round.phase, "bossintro");
for (let ms = 0; ms < 3000; ms += 100) {
g.round.introMs = ms;
g.tick(1);
}
assert.ok(calls.count > before, "the card draws");
});
test("Ghoul Rush's Eye draws on its card through its own art with the card's fake view, and every shade through its keeper's", async () => {
const { eyeArt } = await import("../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js");
const { ctx } = stubCanvas();
const noop = () => {};
let borrowed = 0;
const art = eyeArt({ ellipse: noop, circle: noop, roundRect: noop, line: noop, rotate: noop, eye: noop, hash: (a, b) => Math.abs(a * 31 + b) % 997, say: noop, gate: () => true, label: noop, bossArt: () => () => borrowed++, DANGER: "#f00", GOLD: "#fc0" });
const v = { g: { FIELD_H: 0 }, clock: 1000, spec: null, groundAt: () => 0, eyes: [] };
const b = { kind: "marroweye", x: 0, y: 0, w: 30, h: 30, hurt: 0, dir: -1, state: "fight", t: 0, hp: 1, max: 1 };
assert.doesNotThrow(() => art.bosses.marroweye(ctx, v, b));
const game = { g: { FIELD_H: 54 }, clock: 1000, spec: ghoul.roomFor("dollhouse"), round: {}, bosses: ghoul.BOSSES, eyes: [] };
for (const st of ghoul.STAGES) art.monsters.eyeShade(ctx, game, { of: st.boss, act: "idle", wait: 0, dir: 1, move: ey.SHADE_MOVES[st.boss], floor: 6, y: 6 }, 60, 48, 0, false);
assert.equal(borrowed, ghoul.STAGES.length, "each shade drawn through its keeper's art");
});
@@ -818,7 +818,7 @@ test("Ghoul Rush's Frost Widow hangs from the roof with her veil up, three fire
const barrels = round.hazards.filter((h) => h.kind === "barrel");
assert.deepEqual(barrels.map((h) => h.x), fz.BARREL_SPOTS.map((o) => round.spec.arena + o));
assert.ok(barrels.every((h) => h.state === "still" && h.y === 6));
assert.equal(ghoul.roomFor("widow", 7).bossHp, Math.round(90 * (1 + ghoul.BOSS_DEPTH_HP * 7)));
assert.equal(ghoul.roomFor("widow", 7).bossHp, Math.round(90 * (1 + ghoul.BOSS_DEPTH_HP * Math.min(14, ghoul.BOSS_DEPTH_MAX))), "seven stages in counts as fourteen steps, capped");
// A shot at her glances off: the veil, and she is off the floor besides.
for (const [act, y] of [["hang", 26], ["low", 6]]) {
Object.assign(b, { act, y, x: 170, wait: 1e9, lowMs: 1e9 });
@@ -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-rush/ghoul.js";
import { skipStory } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-story.js";
import { skipEnding } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-ending.js";
import { dropAt, gameOverBanner, OVER_WORD } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-gameover-draw.js";
import { toneNames } from "../src/web-console/public/tones.js";
@@ -23,9 +24,14 @@ function winRun(h) {
const r = h.round;
through(r);
while (!r.over) {
// The ending's pages once the House is dead.
if (r.phase === "ending") {
skipEnding(r);
continue;
}
r.phaseMs = 0;
ghoul.pickStage(r);
for (let k = 0; k < 4; k++) through(r);
for (let k = 0; k < 4 && r.phase !== "ending" && !r.over; k++) through(r);
}
}
@@ -0,0 +1,576 @@
// Web console tests, Ghoul Rush's finale, Kill III, The Pit: the room (dark, a pit each side of the
// heart's plinth, the door at its end), the beat (its interval falling with hp, a wave each way on
// the dub, the ribs open only between beats: a bolt counts then and clanks otherwise), each move's
// warning seen and heard before it can hurt, its cost and its dodge, the beat stopping dead and the
// big double wave, the last hp no bolt can take and the HOLD FIRE flood that ends it (the meter,
// the weak beats that only knock it back, the white, the last thump, the fall, the daylight and its
// door), a life lost keeping it all, a bot's fight length at full depth, the voices, words and drawing.
// Run with: node --test scripts/test-web-console-activities-ghoul-heart.mjs
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
import * as hr from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-heart.js";
import { LOSE_SOUNDS, LOSE_WORDS, VOICES, heartArt } from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-heart-draw.js";
import { react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
import { bossIntroFor } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-boss-intros.js";
import { toneNames } from "../src/web-console/public/tones.js";
const steady = () => 0.5;
const events = (round, type) => round.events.filter((e) => e.type === type);
const seededRandom = (seed) => {
let s = seed;
return () => (s = (s * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff;
};
function stubCanvas() {
const calls = { count: 0 };
const ctx = new Proxy({}, {
get: (target, name) => (name in target ? target[name] : () => { calls.count += 1; }),
set: (target, name, value) => { target[name] = value; return true; },
});
return { canvas: { width: 0, height: 0, getContext: () => ctx }, calls, ctx };
}
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, face: 1 });
}
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;
}
// A run in the Pit, `depth` stages behind it, the finale's last room, nothing else awake.
function pitRound(depth = ghoul.RUN_STAGES) {
const round = ghoul.newRound(5);
round.dice = 0;
round.cleared = ghoul.STAGES.slice(0, depth).map((st) => st.id);
round.stage = ghoul.FINALE.id;
round.stageAt = ghoul.FINALE.rooms.indexOf("pit");
ghoul.setupRoom(round, "pit");
round.phase = "play";
round.items.fill(true);
round.candy.fill(true);
round.events.length = 0;
return round;
}
// The fight under way: in the arena, the heart awake, the next move a long way off.
function pitFight(depth = ghoul.RUN_STAGES) {
const round = pitRound(depth);
standAt(round, 100);
run(round, ghoul.BOSS_INTRO_MS + 100);
assert.equal(round.boss.state, "fight");
calm(round);
return round;
}
// Nothing coming: no move for a long while, no beat due, nothing on the field.
function calm(round) {
Object.assign(round.boss, { act: "idle", wait: 1e9, beatMs: -1e9, dubbed: true, opened: true, stopMs: 0, echo: 0 });
round.hazards.length = 0;
round.waves.length = 0;
round.events.length = 0;
}
// The ribs held open (or shut) a long while.
const holdOpen = (b) => Object.assign(b, { beatT: 1e9, beatMs: hr.OPEN_AT + 1, opened: true, dubbed: true });
const holdShut = (b) => Object.assign(b, { beatT: 1e9, beatMs: -1e9, opened: true, dubbed: true });
/* ------------------------------------------------------------ the room */
test("Ghoul Rush's Pit: the finale's last room, always dark, the heart's boss room with a pit each side of its plinth and the door at the end, and its card", () => {
assert.equal(ghoul.FINALE.rooms.at(-1), "pit");
const base = ghoul.roomById("pit");
assert.equal(base.boss, "marrowheart");
assert.equal(base.dark, true);
assert.ok(base.door > base.length - 14);
const spec = ghoul.roomFor("pit", ghoul.RUN_STAGES);
assert.equal(ghoul.groundAt(spec, hr.HEART_X), 6, "the plinth");
assert.equal(ghoul.groundAt(spec, hr.LEFT_LIP + 1), -Infinity, "a pit on its left");
assert.equal(ghoul.groundAt(spec, hr.RIGHT_LIP - 1), -Infinity, "and on its right");
assert.ok(spec.arena < hr.LEFT_LIP - 40, "room to fight on the left");
const info = bossIntroFor("marrowheart");
assert.deepEqual([info.name, info.epithet], ["The Heart of Marrow", "It has never once skipped a beat"]);
assert.equal(ghoul.BOSSES.marrowheart.name, info.name);
const r = pitFight();
const b = r.boss;
assert.deepEqual([b.x, b.y, b.w, b.h], [hr.HEART_X, 6, hr.HEART_BOX_W, hr.HEART_BOX_H], "its box is the plinth");
assert.ok(b.x - b.w / 2 <= hr.LEFT_LIP + 6 && b.x + b.w / 2 >= hr.RIGHT_LIP - 6, "nowhere to stand beside it");
assert.equal(r.dark, true);
// A fall down a pit costs a life.
standAt(r, hr.LEFT_LIP + 2);
r.you.y = 6;
r.you.state = "air";
r.you.vy = -10;
const lives = r.lives;
run(r, 1500);
assert.ok(events(r, "lose").some((e) => e.cause === "pit") || r.lives < lives, "into the dark");
});
/* ------------------------------------------------------------ the beat */
test("Ghoul Rush's Pit: the beat comes every 1.5 s at full hp and quickens toward 0.75 s, a lub then the dub, and the dub sends a wave each way from the lips of the pits", () => {
assert.equal(hr.beatFor(1), 1500);
assert.equal(hr.beatFor(0), 750);
assert.ok(hr.openFor(1) > hr.openFor(0.2), "the ribs' window narrows with hp");
const r = pitFight();
const b = r.boss;
Object.assign(b, { beatT: 1500, beatMs: 1499, dubbed: true, opened: true });
run(r, 8);
assert.equal(events(r, "heartBeat").length, 1, "the lub");
assert.equal(r.waves.length, 0, "no wave yet");
run(r, hr.DUB_MS);
assert.equal(events(r, "heartWave").length, 1, "the dub");
const xs = r.waves.map((w) => [w.kind, w.dir, Math.round(w.x)]);
assert.deepEqual(xs.sort(), [["heartBeat", -1, hr.LEFT_LIP - 1], ["heartBeat", 1, hr.RIGHT_LIP + 1]].sort(), "out of each pit's lip");
// Low on hp, the beats come faster.
calm(r);
b.hp = Math.round(b.max * 0.1);
Object.assign(b, { beatT: 1500, beatMs: 1499 });
let lubs = 0;
const times = [];
for (let t = 0; t < 6000; t += 4) {
ghoul.advance(r, 4, steady);
r.you.safeMs = 1e9;
if (events(r, "heartBeat").length) times.push(t);
lubs += events(r, "heartBeat").length;
r.events.length = 0;
}
const gap = times[2] - times[1];
assert.ok(gap >= 780 && gap <= 900, `quick beats at a tenth of its hp (${gap} ms)`);
});
test("Ghoul Rush's Pit: a bolt into the open ribs hurts it, one while they are shut clanks off, and its weak spot is open only between beats", () => {
const r = pitFight();
const b = r.boss;
standAt(r, 100);
holdShut(b);
run(r, 600, { fire: true });
assert.equal(b.hp, b.max, "shut: no damage");
assert.ok(events(r, "bossBlock").length > 0, "a clank");
calm(r);
r.heat = 0;
r.events.length = 0;
holdOpen(b);
run(r, 600, { fire: true });
assert.ok(b.hp < b.max, "open: it hurts");
assert.ok(events(r, "bossHit").length > 0);
// Over a normal beat, open only in its window.
calm(r);
Object.assign(b, { beatT: 1500, beatMs: 1499 });
const open = [];
for (let t = 0; t < 1500; t += 4) {
r.you.safeMs = 1e9;
ghoul.advance(r, 4, steady);
open.push([t, b.open]);
}
const first = open.find(([, o]) => o);
const last = open.filter(([, o]) => o).at(-1);
assert.ok(first[0] >= hr.OPEN_AT - 10 && first[0] <= hr.OPEN_AT + 10, "opens after the dub");
assert.ok(last[0] - first[0] <= hr.openFor(1) * 1500 + 10, "for its share of the beat");
assert.equal(events(r, "heartOpen").length, 1, "heard once");
});
test("Ghoul Rush's Pit: the beat's wave costs a life standing still (shaken off your feet) and is jumped", () => {
const r = pitFight();
const b = r.boss;
standAt(r, 100);
Object.assign(b, { beatT: 1e9, beatMs: hr.DUB_MS - 1, dubbed: false });
run(r, 900);
assert.deepEqual(events(r, "lose").map((e) => e.cause), ["heartBeat"]);
const j = pitFight();
standAt(j, 100);
Object.assign(j.boss, { beatT: 1e9, beatMs: hr.DUB_MS - 1, dubbed: false });
for (let t = 0; t < 900; t += 4) {
const w = j.waves.find((q) => q.dir < 0);
if (w && w.x - j.you.x > 0 && w.x - j.you.x < 4 && j.you.state === "run") j.input.jump = ghoul.JUMP_BUFFER_MS;
ghoul.advance(j, 4, steady);
}
assert.deepEqual(events(j, "lose"), [], "jumped");
});
/* ------------------------------------------------------------ the moves */
// The fight with `move` next, YOU at x (on a ledge's index when given).
function moveRound(move, x = 100, shelf = -1, share = 1) {
const r = pitFight();
r.boss.hp = Math.max(2, Math.round(r.boss.max * share));
standAt(r, x, shelf);
holdShut(r.boss);
Object.assign(r.boss, { plan: move, wait: 0 });
return r;
}
const HAZARD = { roots: "heartRoot", grab: "heartGrab", clots: "heartClot", quake: "heartChunk" };
const WIND = { roots: "heartRootWind", grab: "heartGrabWind", clots: "heartClotWind", quake: "heartQuake" };
test("Ghoul Rush's Pit: every move is seen and heard well before it can hurt, hurts standing YOU with its own cause, and is dodged", () => {
const cases = [["roots", 100, -1, 1], ["grab", 99, 1, 1], ["clots", 100, -1, 1], ["quake", 100, -1, 0.2]];
for (const [move, x, shelf, share] of cases) {
const r = moveRound(move, x, shelf, share);
ghoul.advance(r, 4, steady);
assert.equal(events(r, WIND[move]).length, 1, `${move}: its warning, heard`);
const hz = r.hazards.filter((h) => h.kind === HAZARD[move]);
assert.ok(hz.length >= 1, `${move}: something placed`);
assert.ok(hz.every((h) => !(h.live > 0) && h.warn >= 900), `${move}: a warning of nearly a second or more before any can hurt`);
// Standing still (the ledge's grab: staying on it) costs a life with its cause.
const lost = [];
for (let t = 0; t < 2500 && !lost.length; t += 4) {
ghoul.advance(r, 4, steady);
if (r.boss.act === "idle") r.boss.wait = 1e9;
lost.push(...events(r, "lose"));
r.events.length = 0;
}
assert.deepEqual(lost.map((e) => e.cause), [HAZARD[move]], `${move}: hurts`);
// Dodged: off the ledge, or a few steps aside from where it will come.
const d = moveRound(move, x, shelf, share);
ghoul.advance(d, 4, steady);
const far = [];
for (let t = 0; t < 2500; t += 4) {
if (d.phase === "play") {
const threat = d.hazards.find((h) => Math.abs(h.x - d.you.x) < (h.w + 2.4) / 2 + 1.2);
if (shelf >= 0) {
if (d.you.shelf >= 0) standAt(d, 75);
} else if (threat) standAt(d, Math.max(d.spec.arena + 4, Math.min(hr.LEFT_LIP - 3, threat.x + (threat.x > d.you.x ? -3.6 : 3.6))));
}
ghoul.advance(d, 4, steady);
if (d.boss.act === "idle") d.boss.wait = 1e9;
far.push(...events(d, "lose"));
d.events.length = 0;
}
assert.deepEqual(far.map((e) => e.cause), [], `${move}: dodged`);
}
});
test("Ghoul Rush's Pit: the pick never plays a move three times running, grabs only while YOU are on a ledge, and the quake only below a quarter", () => {
const b = {};
const random = seededRandom(4);
const picks = [];
for (let i = 0; i < 300; i++) picks.push(hr.pickMove(b, 0, random, false));
for (let i = 2; i < picks.length; i++) assert.ok(!(picks[i] === picks[i - 1] && picks[i] === picks[i - 2]), "never three running");
assert.ok(!picks.includes("grab") && !picks.includes("quake"));
const high = [];
for (let i = 0; i < 200; i++) high.push(hr.pickMove(b, 2, random, true));
assert.ok(high.includes("grab") && high.includes("quake"));
assert.ok(high.filter((p) => p === "grab").length > high.filter((p) => p === "roots").length, "on a ledge, grabs most of all");
assert.equal(hr.phaseFor(0.6), 0);
assert.equal(hr.phaseFor(0.5), 1);
assert.equal(hr.phaseFor(0.25), 2);
});
/* ------------------------------------------------------- the beat stops dead */
test("Ghoul Rush's Pit: below half the beat stops dead: silence, its swell heard well before, then a big double wave each way, and a long gasp of open ribs", () => {
const r = pitFight();
const b = r.boss;
b.hp = Math.round(b.max * 0.45);
r.you.safeMs = 1e9;
Object.assign(b, { beatT: 1500, beatMs: 1499, beats: 99, stopAt: 3 });
const seen = [];
let opened = 0;
let wasOpen = false;
let openMs = 0;
for (let t = 0; t < hr.STOP_MS + 1500; t += 4) {
r.you.safeMs = 1e9;
ghoul.advance(r, 4, steady);
for (const e of r.events) if (e.type.startsWith("heart")) seen.push([e.type, t, !!e.echo]);
if (b.open) openMs += 4;
if (b.open && !wasOpen) opened++;
wasOpen = b.open;
r.events.length = 0;
}
const types = seen.map(([type]) => type);
assert.equal(types[0], "heartStop");
const swell = seen.find(([type]) => type === "heartSwell");
const slams = seen.filter(([type]) => type === "heartSlam");
assert.ok(swell && swell[1] >= hr.STOP_MS - hr.SWELL_MS - 10 && swell[1] <= hr.STOP_MS - hr.SWELL_MS + 10, "the swell, SWELL_MS before");
assert.ok(!types.slice(0, types.indexOf("heartSlam")).includes("heartBeat"), "no beat in the silence");
assert.equal(slams.length, 2, "a double wave");
assert.ok(Math.abs(slams[1][1] - slams[0][1] - hr.BIG_GAP_MS) <= 8, "BIG_GAP_MS apart");
assert.ok(openMs >= hr.openFor(0.45) * hr.beatFor(0.45) * hr.GASP * 0.9, `a long gasp open after it (${openMs} ms)`);
});
/* ------------------------------------------------------------ the hold */
test("Ghoul Rush's Pit: no bolt takes its last hp: it holds at 1, the ribs lock open and HOLD FIRE begins, once, with the story's click; the blaster fires nothing and cools", () => {
const r = pitFight();
const b = r.boss;
standAt(r, 100);
holdOpen(b);
b.hp = 3;
r.heat = 20;
run(r, 1500, { fire: true });
assert.equal(b.hp, 1, "held at 1");
assert.equal(b.state, "fight");
assert.equal(events(r, "heartHold").length, 1, "the hold, once");
assert.equal(r.flood, true);
assert.equal(r.heart.hold, true);
assert.equal(VOICES.marrowheart.hold, "ghoulStoryClick");
const shots = r.stats.shots;
const heat = r.heat;
run(r, 600, { fire: true });
assert.equal(r.stats.shots, shots, "fire held fires nothing");
assert.ok(r.heat <= heat, "and the heat cools");
// A weapon's blow glances off in the hold (the guard).
assert.equal(ghoul.guarded(r.boss), true);
});
test("Ghoul Rush's Pit: in the hold the meter fills over about 4 s of fire held, drains slowly let go; weak beats every 1.5 s send ripples that only knock it back, never a life", () => {
const r = pitFight();
const b = r.boss;
standAt(r, 100);
b.hp = 1;
hr.startHold(r, b);
r.events.length = 0;
// No weak beat for now: the meter alone.
r.heart.beatMs = -1e9;
run(r, 2000, { fire: true });
assert.ok(Math.abs(r.heart.meter - 2000 / hr.HOLD_FILL_MS) < 0.03, `filling (${r.heart.meter})`);
const m = r.heart.meter;
run(r, 1000);
assert.ok(r.heart.meter < m && r.heart.meter > m - 0.2, "drains slowly");
r.heart.beatMs = 0;
run(r, hr.HOLD_BEAT_MS + 20);
assert.equal(events(r, "heartWeakBeat").length, 1, "a weak beat");
assert.equal(r.heart.waves.length, 1, "and its ripple");
r.heart.waves.length = 0;
// A ripple reaching YOU knocks the meter back and costs nothing.
const lives = r.lives;
r.heart.meter = 0.6;
r.heart.waves.push({ x: r.you.x + 0.5, y: 6, dir: -1 });
run(r, 40, { fire: true });
assert.equal(events(r, "heartKnock").length, 1);
assert.ok(r.heart.meter < 0.6 - hr.HOLD_KNOCK + 0.05, "knocked back");
assert.equal(r.lives, lives);
assert.deepEqual(events(r, "lose"), []);
// The flood swells out loud at each quarter climbed.
r.heart.meter = 0.2;
r.heart.step = 0;
r.heart.beatMs = -1e9;
r.heart.waves.length = 0;
r.events.length = 0;
run(r, 2400, { fire: true });
assert.deepEqual(events(r, "heartFlood").map((e) => e.n), [1, 2, 3]);
});
test("Ghoul Rush's Pit: the meter full turns the screen white, the last thump, the fall (a life, the points), then the daylight and its door, the finale's end", () => {
const r = pitFight();
const b = r.boss;
standAt(r, 100);
b.hp = 1;
hr.startHold(r, b);
r.heart.meter = 0.99;
r.heart.step = 3;
r.events.length = 0;
const lives = r.lives;
const order = [];
for (let t = 0; t < hr.FALL_AT + hr.DAYLIGHT_AT + 800; t += 4) {
r.input.fire = t < 300;
ghoul.advance(r, 4, steady);
for (const e of r.events) if (e.type.startsWith("heart") || e.type === "bossDown") order.push([e.type, t]);
if (t > 400 && t < hr.WHITE_HOLD_MS) assert.ok(hr.whiteOf(r) > 0.9, "white");
// (The fall's own slice hands the key over; the next takes it back till the daylight.)
if (b.state === "down" && !b.gone && b.t > 8) assert.equal(r.hasKey, false, "no door until the daylight");
r.events.length = 0;
}
assert.deepEqual(order.map(([type]) => type), ["heartWhite", "heartLast", "bossDown", "heartDaylight"]);
assert.ok(order[1][1] - order[0][1] >= hr.LAST_AT - 10, "the last thump, after the white");
assert.ok(order[2][1] - order[0][1] >= hr.FALL_AT - 10, "then the fall");
assert.equal(b.state, "down");
assert.equal(r.lives, lives + 1, "a life, as every boss gives");
assert.equal(b.gone, true);
assert.equal(r.hasKey, true);
assert.equal(r.flood, false);
assert.equal(hr.whiteOf(r), 0, "the white gone again");
// Through the door of light: the finale's end.
standAt(r, r.spec.door);
run(r, 50);
assert.equal(r.phase, "clear");
run(r, ghoul.CLEAR_MS + 50);
assert.ok(r.phase === "ending" || r.won, `the run's end (${r.phase})`);
});
test("Ghoul Rush's Pit: a life lost keeps its hp and the hold, and the endless-lives code spares every hit", () => {
const r = pitFight();
const b = r.boss;
b.hp = Math.round(b.max * 0.7);
const hp = b.hp;
standAt(r, 100);
Object.assign(b, { beatT: 1e9, beatMs: hr.DUB_MS - 1, dubbed: false });
run(r, 4000);
assert.ok(events(r, "lose").length >= 1);
assert.equal(r.boss.hp, hp, "its hp kept");
// In the hold, a respawn holds on.
const h = pitFight();
h.boss.hp = 1;
hr.startHold(h, h.boss);
h.heart.meter = 0.4;
standAt(h, hr.LEFT_LIP - 1);
h.you.x = hr.LEFT_LIP + 2;
h.you.state = "air";
run(h, 3500);
assert.ok(events(h, "lose").some((e) => e.cause === "pit"));
assert.equal(h.boss.hp, 1);
assert.equal(h.heart.hold, true);
run(h, ghoul.BOSS_INTRO_MS + 200);
assert.equal(h.flood, true, "still holding");
// The endless-lives code.
const e = moveRound("roots");
e.infinite = true;
const lives = e.lives;
run(e, 2500);
assert.ok(events(e, "lose").length >= 1, "hit");
assert.equal(e.lives, lives, "no life spent");
});
/* ------------------------------------------------------------ the fight */
// A steady player on the floor at HOME: fires so its bolts land while the ribs are open, jumps each wave,
// steps aside from a root, a clot or a chunk, and in the hold holds fire and jumps the ripples.
const HOME = 100;
function fight(seed, skilled = true) {
const round = pitFight();
const random = seededRandom(seed);
const b = round.boss;
Object.assign(b, { wait: 600, beatT: 0 });
let t = 0;
const causes = [];
for (; t < 240000 && b.state !== "down" && !round.over; t += 4) {
const you = round.you;
const inp = round.input;
inp.left = inp.right = inp.fire = false;
if (round.phase === "ask") ghoul.answerDie(round, false);
if (skilled && round.phase === "play" && you.out <= 0) {
const h = round.heart;
const waves = h && h.hold ? h.waves : round.waves;
const wave = waves.find((w) => w.dir < 0 && w.x - you.x > 0 && w.x - you.x < (h && h.hold ? 3 : 5));
const threat = round.hazards.find((q) => (q.warn > 0 || q.live > 0) && Math.abs(q.x - you.x) < (q.w + 2.4) / 2 + 0.8);
if (wave && you.state === "run") inp.jump = ghoul.JUMP_BUFFER_MS;
if (threat) {
const dir = threat.x >= you.x ? -1 : 1;
const lo = round.spec.arena + 4;
const hi = hr.LEFT_LIP - 4;
inp[(dir < 0 ? you.x - 3 > lo : you.x + 3 > hi) ? "left" : "right"] = true;
} else if (Math.abs(you.x - HOME) > 6 && !round.hazards.length) inp[you.x < HOME ? "right" : "left"] = true;
else you.face = 1;
// Fired so each bolt lands while the ribs are open (the way a player learns the beat).
const travel = ((hr.HEART_X - hr.HEART_BOX_W / 2 - you.x - 1.8) / 130) * 1000;
const span = hr.openFor(b.hp / b.max) * b.beatT * (b.gasp ? hr.GASP : 1);
const at = (b.beatMs || 0) + travel;
inp.fire = h && h.hold ? true : !(b.stopMs > 0) && at >= hr.OPEN_AT + 10 && at <= hr.OPEN_AT + span - 10 && you.face === 1;
}
ghoul.advance(round, 4, random);
causes.push(...events(round, "lose").map((e) => e.cause));
round.events.length = 0;
}
return { won: b.state === "down", secs: t / 1000, causes, round };
}
test("Ghoul Rush's Pit takes a steady player a real fight at full depth: 60 to 120 seconds on most seeds, with lives to spare; a player who stands still dies", () => {
const times = [];
const lives = [];
let good = 0;
for (const seed of [3, 7, 19, 41]) {
const f = fight(seed);
assert.ok(f.won, `seed ${seed}: it stopped (${f.causes}; ${f.secs.toFixed(1)} s, hp ${f.round.boss.hp})`);
assert.ok(f.round.lives > 0, `seed ${seed}: lives to spare (${f.causes})`);
for (const c of f.causes) assert.ok(LOSE_WORDS[c] || c === "pit", `${c} is the heart's`);
if (f.secs >= 60 && f.secs <= 120) good++;
times.push(f.secs);
lives.push(f.round.lives);
}
assert.ok(good >= 3, `most seeds in 60 to 120 s (${times.map((x) => x.toFixed(1))}; lives ${lives})`);
const idle = fight(7, false);
assert.equal(idle.won, false);
assert.ok(idle.round.over, `game over (${idle.causes})`);
assert.equal(idle.round.boss.hp, idle.round.boss.max, "and not a scratch on it");
});
/* ------------------------------------------------- voices, words, drawing */
const heard = (e) => {
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, markFurthest: noop };
react(e, kit);
return played;
};
test("Ghoul Rush's heart: a voice for every act in tones.js, every event plays its own sound once, and every cause has words and a sound", () => {
const known = new Set(toneNames());
for (const [act, name] of Object.entries(VOICES.marrowheart)) assert.ok(known.has(name), `${act}: ${name} is a tone`);
const at = { kind: "marrowheart", x: 120, y: 20, xs: [100], n: 1 };
const cases = { heartBeat: "beat", heartOpen: "open", heartRootWind: "rootWind", heartRootCrack: "rootCrack", heartRootUp: "rootUp", heartGrabWind: "grabWind", heartGrabTense: "grabTense", heartGrabLash: "grabLash", heartClotWind: "clotWind", heartClotLand: "clotLand", heartQuake: "quake", heartChunkLand: "chunk", heartStop: "stop", heartSwell: "swell", heartSlam: "slam", heartHold: "hold", heartWeakBeat: "weakBeat", heartKnock: "knock", heartFlood: "flood", heartWhite: "white", heartLast: "last", heartDaylight: "daylight", bossWake: "wake", bossHit: "hurt", bossDown: "die" };
for (const [type, act] of Object.entries(cases)) {
const played = heard({ type, ...at, how: "shot", points: 1, life: true });
assert.equal(played.filter((n) => n === VOICES.marrowheart[act]).length, 1, `${type}: ${VOICES.marrowheart[act]} once`);
}
assert.deepEqual(heard({ type: "heartWave", ...at }), [], "the dub is the beat's own second thump");
for (const cause of ["marrowheart", "heartBeat", "heartBig", "heartRoot", "heartGrab", "heartClot", "heartChunk"]) {
assert.ok(LOSE_WORDS[cause], `${cause}: words`);
assert.ok(known.has(LOSE_SOUNDS[cause][0]), `${cause}: a sound`);
}
});
test("Ghoul Rush's Pit draws: the walk in, the heart asleep, every beat's moment, every move's warning and hit, the stopped beat and the slam, the hold, the white, the stopped heart and the daylight, lit and dark, and its card", () => {
const { canvas, calls } = stubCanvas();
const g = ghoul.default.create({ canvas });
g.resize(900, 900);
g.stageSelect();
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g.key("down");
for (let i = 0; i < ghoul.FINALE.rooms.indexOf("pit"); i++) g.key("right");
g.key("action");
for (let n = 0; n < 3 && g.round.phase !== "ready" && g.round.phase !== "play"; n++) {
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 50; ms += 16) g.tick(16);
g.key("action");
}
const r = g.round;
assert.equal(r.spec.id, "pit");
r.infinite = true;
const frame = (label) => {
const before = calls.count;
g.tick(16);
assert.ok(calls.count > before, `${label} draws`);
};
for (const dark of [false, true]) {
r.dark = dark;
standAt(r, 20);
frame("the walk in");
standAt(r, 100);
for (let ms = 0; ms < 1600; ms += 16) g.tick(16);
for (const beatMs of [10, 200, 320, 500, 1300]) {
Object.assign(r.boss, { beatT: 1500, beatMs, wait: 1e9 });
frame(`the beat at ${beatMs}`);
}
for (const [move, share] of [["roots", 1], ["clots", 0.6], ["quake", 0.2]]) {
r.boss.hp = Math.round(r.boss.max * share);
Object.assign(r.boss, { plan: move, act: "idle", wait: 0 });
for (let ms = 0; ms < 1600; ms += 16) frame(move);
}
standAt(r, 99, 1);
Object.assign(r.boss, { plan: "grab", act: "idle", wait: 0 });
for (let ms = 0; ms < 1600; ms += 16) frame("grab");
standAt(r, 100);
Object.assign(r.boss, { stopMs: 1200, swelled: false });
for (let ms = 0; ms < 1800; ms += 16) frame("the stop and the slam");
}
r.boss.hp = 1;
hr.startHold(r, r.boss);
r.heart.meter = 0.5;
r.input.fire = true;
for (let ms = 0; ms < 2600; ms += 16) frame("the hold");
for (let ms = 0; ms < 6000; ms += 16) frame("the white, the fall and the daylight");
assert.equal(r.boss.state, "down");
// The boss card's fake view: no round, no room, the floor at 0.
const def = ghoul.BOSSES.marrowheart;
assert.ok(def.w >= 30 && def.h >= 36, "the card sizes its spotlight to the whole heart");
const noop = () => {};
const art = heartArt({ ellipse: noop, circle: noop, roundRect: noop, line: noop, rotate: noop, hash: (a, b) => Math.abs(a * 31 + b * 17) % 997, say: noop, gate: () => true, label: noop, DANGER: "#ff3030", GOLD: "#f5b301" });
const card = stubCanvas();
const fake = { kind: "marrowheart", x: 0, y: 0, w: def.w, h: def.h, hp: 1, max: 1, state: "fight", t: 0 };
for (const clock of [0, 400, 900]) art.bosses.marrowheart(card.ctx, { g: { FIELD_H: 0 }, clock, spec: null, groundAt: () => 0, eyes: [] }, fake);
assert.ok(card.calls.count > 50, "the card's heart draws");
});
@@ -51,8 +51,8 @@ test("Ghoul Rush intros: every stage has a card of 3 or 4 short lines, no em das
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.deepEqual(Object.keys(INTROS).sort(), ghoul.SELECTABLE.map((st) => st.id).sort(), "no intro for a stage that does not exist");
assert.equal(new Set(ghoul.SELECTABLE.flatMap((st) => introFor(st.id).lines)).size, ghoul.SELECTABLE.reduce((n, st) => n + introFor(st.id).lines.length, 0), "no line used twice");
assert.ok(toneNames().includes("ghoulStageIntro"));
});
@@ -0,0 +1,643 @@
// Web console tests, Ghoul Rush's finale: the win condition (RUN_STAGES stages, then the House
// with no offer, its record one past every stage), the words that count the stages, and Kill I,
// The Lawn: the windows (hit from the surface that serves each row, passed while shuttered, out
// for good across a life lost), the rows opening, each move's telegraph, hit and dodge, the
// weighted pick, the wall in front of the house, the retreat in order and its standing door, a
// bot's fight length, the voices, words and drawing.
// Run with: node --test scripts/test-web-console-activities-ghoul-marrow.mjs
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
import * as mw from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow.js";
import { LOSE_SOUNDS, LOSE_WORDS, VOICES } from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-draw.js";
import { react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
import { bossIntroFor } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-boss-intros.js";
import { introFor } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-intros.js";
import { skipStory } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-story.js";
import { skipEnding } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-ending.js";
import { toneNames } from "../src/web-console/public/tones.js";
const steady = () => 0.5;
const events = (round, type) => round.events.filter((e) => e.type === type);
const seededRandom = (seed) => {
let s = seed;
return () => (s = (s * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff;
};
function stubCanvas() {
const calls = { count: 0 };
const ctx = new Proxy({}, {
get: (target, name) => (name in target ? target[name] : () => { calls.count += 1; }),
set: (target, name, value) => { target[name] = value; return true; },
});
return { canvas: { width: 0, height: 0, getContext: () => ctx }, calls };
}
function textCanvas() {
const texts = [];
const ctx = new Proxy({}, {
get: (target, name) => (name === "fillText" ? (text) => texts.push([String(text)]) : name in target ? target[name] : () => {}),
set: (target, name, value) => { target[name] = value; return true; },
});
return { canvas: { width: 0, height: 0, getContext: () => ctx }, texts };
}
function through(round) {
round.phase = "clear";
round.phaseMs = 1;
ghoul.advance(round, 4, steady);
}
// Through the rest of the House, room by room (each card passed), then past the ending's pages: the win.
function finishHouse(round, g = null) {
for (let n = 0; n < 20 && !round.over; n++) {
if (round.phase === "ending") skipEnding(round);
else {
if (round.phase === "intro" || round.phase === "bossintro") skipCard(round);
if (round.phase === "intro" || round.phase === "bossintro") skipCard(round);
through(round);
}
if (g) g.tick(16);
}
}
function skipCard(round) {
round.introMs = ghoul.INTRO_MIN_MS;
return ghoul.takeIntro(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, face: 1 });
}
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;
}
// A run's way to the House: out of the hall, `depth` stages already behind it, into the
// finale (its stage card and the boss's passed), nothing else woken.
function lawnRound(depth = ghoul.RUN_STAGES) {
const round = ghoul.newRound(5);
round.dice = 0;
through(round);
round.cleared = ghoul.STAGES.slice(0, depth).map((st) => st.id);
round.offer = null;
through(round);
assert.equal(round.spec.id, "lawn");
skipCard(round);
skipCard(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.events.length = 0;
return round;
}
// Nothing moves: no window lit, the next move a long way off.
function calm(round) {
const b = round.boss;
for (const w of round.marrow.windows) if (w.state === "lit") w.state = "dark";
Object.assign(b, { act: "idle", wait: 1e9, litMs: 1e9, relight: 0 });
round.hazards.length = 0;
round.waves.length = 0;
round.monsters.length = 0;
}
// The fight under way: in the arena, the boss awake and idle a long while, no window lit.
function lawnFight(depth = ghoul.RUN_STAGES) {
const round = lawnRound(depth);
standAt(round, 130);
run(round, ghoul.BOSS_INTRO_MS + 100);
assert.equal(round.boss.state, "fight");
calm(round);
round.events.length = 0;
return round;
}
// Where each row is shot from: [x, shelf index or -1 for the floor].
const SERVES = Object.freeze({ 0: [160, -1], 1: [145, 2], 2: [145, 5], 3: [162, 6] });
function lightOnly(round, id) {
for (const w of round.marrow.windows) if (w.state !== "out") w.state = w.id === id ? "lit" : "dark";
}
/* ------------------------------------------------------- the win condition */
test("Ghoul Rush's finale: a run offers RUN_STAGES picks of stages that never repeat, then goes to the House with no offer, its card and the boss's first; clearing it wins", () => {
const round = ghoul.newRound(9);
round.dice = 0;
through(round);
let picks = 0;
while (round.phase === "pick") {
picks++;
round.phaseMs = 0;
ghoul.pickStage(round);
for (let k = 0, n = ghoul.stageById(round.stage).rooms.length; k < n; k++) through(round);
}
assert.equal(picks, ghoul.RUN_STAGES, "six picks");
assert.equal(new Set(round.cleared).size, ghoul.RUN_STAGES, "no stage twice");
assert.equal(events(round, "offer").length, ghoul.RUN_STAGES, "no offer for the House");
assert.deepEqual([round.stage, round.spec.id, round.phase], [ghoul.FINALE.id, "lawn", "intro"], "the sixth clear opens the House's card");
assert.deepEqual(events(round, "stage").at(-1), { type: "stage", stage: "marrow", n: ghoul.RUN_STAGES, of: ghoul.RUN_STAGES });
assert.ok(events(round, "stageClear").every((e) => e.of === ghoul.RUN_STAGES));
assert.ok(introFor("marrow") && bossIntroFor("marrow"), "both cards exist");
assert.equal(skipCard(round), true);
assert.equal(round.phase, "bossintro", "then the boss's card");
assert.equal(skipCard(round), true);
assert.equal(round.phase, "ready");
assert.equal(round.spec.depth, ghoul.RUN_STAGES, "played at full depth");
finishHouse(round);
assert.equal(round.won, true);
assert.deepEqual(events(round, "won").map((e) => e.n), [ghoul.RUN_STAGES + 1]);
});
test("Ghoul Rush's finale is never offered, and the stage select lists it last, played at depth 0", () => {
assert.ok(!ghoul.STAGES.includes(ghoul.FINALE));
assert.equal(ghoul.SELECTABLE.at(-1), ghoul.FINALE);
assert.equal(ghoul.stageById("marrow"), ghoul.FINALE);
assert.equal(ghoul.FINALE.rooms[0], "lawn");
assert.equal(ghoul.roomById("lawn").boss, "marrow");
for (let seed = 1; seed < 30; seed++) {
const r = ghoul.newRound(seed);
r.dice = 0;
through(r);
assert.ok(!r.offer.includes("marrow"));
}
const g = ghoul.default.create({ canvas: stubCanvas().canvas });
g.resize(900, 900);
g.stageSelect();
for (let i = 0; i < ghoul.SELECTABLE.length + 2; i++) g.key("down");
assert.equal(g.round.select.at, ghoul.SELECTABLE.length - 1);
g.key("action");
assert.deepEqual([g.round.stage, g.round.spec.id, g.round.phase], ["marrow", "lawn", "intro"]);
assert.equal(g.round.spec.depth, 0, "practice plays it at depth 0");
});
test("Ghoul Rush's record: the memo counts stages up to RUN_STAGES, goes one past only on a win, never from practice, and the words count RUN_STAGES whatever STAGES holds", () => {
const { canvas, texts } = textCanvas();
let saved = 0;
const g = ghoul.default.create({ canvas, memo: { get: () => saved, set: (n) => (saved = n) } });
g.resize(900, 900);
assert.ok(ghoul.STAGES.length !== ghoul.RUN_STAGES, "the pool is bigger than a run");
assert.ok(texts.some(([t]) => t === `Run. Shoot. Clear ${ghoul.RUN_STAGES} stages, then kill the house`));
assert.ok(texts.some(([t]) => t.includes(`Best: 0 of ${ghoul.RUN_STAGES} stages`)));
g.key("action");
if (g.round.phase === "story") {
skipStory(g.round);
g.tick(0);
}
const r = g.round;
r.dice = 0;
const last = ghoul.STAGES[ghoul.RUN_STAGES - 1];
r.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES - 1).map((s) => s.id);
r.stage = last.id;
r.stageAt = last.rooms.length - 1;
through(r);
g.tick(16);
assert.equal(saved, ghoul.RUN_STAGES, "every stage, not yet the House");
assert.equal(g.hud.stage, "THE HOUSE: KILL 1 OF 3");
finishHouse(r, g);
g.tick(16);
assert.equal(g.state, "over");
assert.equal(saved, ghoul.RUN_STAGES + 1, "the House beaten");
texts.length = 0;
g.resize(900, 900);
assert.ok(texts.some(([t]) => t.startsWith("You escaped! Marrow starves")));
// A memo from before reads as beaten, and the start screen says so.
const again = textCanvas();
const g2 = ghoul.default.create({ canvas: again.canvas, memo: { get: () => 11, set: () => {} } });
g2.resize(900, 900);
assert.ok(again.texts.some(([t]) => t.includes("You have killed the House")));
// Practice never writes it.
let p = 0;
const g3 = ghoul.default.create({ canvas: stubCanvas().canvas, memo: { get: () => p, set: (n) => (p = n) } });
g3.resize(900, 900);
g3.stageSelect();
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g3.key("down");
g3.key("action");
finishHouse(g3.round, g3);
g3.tick(16);
assert.equal(g3.round.won, true);
assert.equal(p, 0, "practice keeps nothing");
});
/* --------------------------------------------------------------- the lawn */
test("Ghoul Rush's lawn: the house fills the arena's right, YOU are kept off it, its box is out of reach and always guarded, and its hp is its windows' sum", () => {
const round = lawnFight();
const b = round.boss;
const spec = round.spec;
assert.equal(ghoul.roomById("lawn").boss, "marrow");
assert.equal(mw.houseLeft(spec), 172);
assert.ok(b.x > mw.houseLeft(spec) + mw.HOUSE_W, "its box past the house's far wall");
assert.equal(ghoul.guarded(b), true);
const share = Math.ceil(spec.bossHp / mw.WINDOWS.length);
assert.equal(b.max, share * mw.WINDOWS.length);
assert.equal(b.hp, round.marrow.windows.reduce((s, w) => s + w.hp, 0));
standAt(round, 160);
run(round, 1500, { right: true });
assert.ok(round.you.x <= mw.houseLeft(spec) - mw.WALL_GAP + 0.5, `held off the house (${round.you.x.toFixed(2)})`);
});
test("Ghoul Rush's lawn: every window can be shot from the surface that serves its row; a shuttered one lets the bolts by", () => {
mw.WINDOWS.forEach(([row, dx], id) => {
const round = lawnFight();
const win = round.marrow.windows[id];
const [x, shelf] = SERVES[row];
standAt(round, x, shelf);
const full = win.hp;
run(round, 1200, { fire: true });
assert.equal(win.hp, full, `window ${id}: shuttered, untouched`);
lightOnly(round, id);
round.heat = 0;
round.events.length = 0;
run(round, 800, { fire: true });
assert.ok(win.hp < full, `window ${id} (row ${row}): hit from ${shelf < 0 ? "the floor" : `shelf ${shelf}`}`);
assert.equal(round.boss.hp, round.marrow.windows.reduce((s, q) => s + q.hp, 0), "hp is the windows' sum");
assert.ok(events(round, "bossHit").every((e) => e.how === "window" && Math.abs(e.x - (mw.houseCenter(round.spec) + dx)) < 0.01), "the hit shows at the window");
});
});
test("Ghoul Rush's lawn: a window shot out stays out across a life lost, and lit windows come only from the rows open by how many are out", () => {
assert.deepEqual([0, 3, 4, 7, 8, 12].map(mw.rowsOpen), [1, 1, 2, 2, 3, 3]);
const round = lawnFight();
const b = round.boss;
const win = round.marrow.windows[0];
b.hp -= win.hp - 1;
win.hp = 1;
lightOnly(round, 0);
standAt(round, 160);
run(round, 400, { fire: true });
assert.equal(win.state, "out");
assert.deepEqual(events(round, "marrowWindowOut").map((e) => e.left), [mw.WINDOWS.length - 1]);
const hp = round.boss.hp;
round.lives = 5;
ghoul.lose(round, "marrowShingle");
run(round, ghoul.CRASH_MS + ghoul.READY_MS + 100);
assert.notEqual(round.boss, b, "a new boss object after the life lost");
assert.equal(round.marrow.windows[0].state, "out", "still out");
assert.equal(round.boss.hp, hp, "the same hp");
const r2 = lawnFight();
const random = seededRandom(4);
r2.boss.litMs = 0;
for (let t = 0; t < 60000; t += 4) {
r2.you.safeMs = 1e9;
r2.boss.wait = 1e9;
ghoul.advance(r2, 4, random);
const out = r2.marrow.windows.filter((w) => w.state === "out").length;
for (const w of r2.marrow.windows) if (w.state === "lit") assert.ok(w.row <= mw.rowsOpen(out), `row ${w.row} lit with ${out} out`);
// Shoot one out now and then, so every row gets its turn.
if (t % 2000 === 0 && out < mw.WINDOWS.length - 1) {
const lit = r2.marrow.windows.find((w) => w.state === "lit");
if (lit) {
r2.boss.hp -= lit.hp;
Object.assign(lit, { hp: 0, state: "out" });
r2.boss.relight = mw.RELIGHT_MS;
}
}
r2.events.length = 0;
}
assert.ok(r2.marrow.windows.filter((w) => w.state === "out").length >= 9, "the fight reached the eyes");
});
test("Ghoul Rush's lawn: the pick opens on the carpet, never one move three times running, the slow moves sit out their cooldown, the doormen only under their cap, and each phase's moves only", () => {
const random = seededRandom(11);
for (const phase of [0, 1, 2]) {
const b = {};
const picks = [];
for (let i = 0; i < 400; i++) picks.push(mw.pickMove(b, phase, random, 0));
assert.equal(picks[0], "carpet");
for (let i = 2; i < picks.length; i++) assert.ok(!(picks[i] === picks[i - 1] && picks[i] === picks[i - 2]), `phase ${phase}: never three running`);
for (const [move, n] of Object.entries(mw.COOLDOWN)) {
const at = picks.flatMap((p, i) => (p === move ? [i] : []));
for (let i = 1; i < at.length; i++) assert.ok(at[i] - at[i - 1] > n, `phase ${phase}: ${move} sits out ${n}`);
}
for (const [move, w] of Object.entries(mw.WEIGHTS)) if (!w[phase]) assert.ok(!picks.includes(move), `phase ${phase}: no ${move}`);
assert.ok(new Set(picks).size >= [3, 5, 6][phase], `phase ${phase}: varied (${[...new Set(picks)]})`);
}
const b = { picks: 3 };
for (let i = 0; i < 100; i++) assert.notEqual(mw.pickMove(b, 1, random, mw.DOORMEN_CAP), "doormen");
// Up in the oak the lightning and the crows join, and only there; the crows under their cap.
for (const phase of [0, 1, 2]) {
const up = {};
const picks = [];
for (let i = 0; i < 400; i++) picks.push(mw.pickMove(up, phase, random, 0, true, 0));
assert.ok(picks.includes("lightning") && picks.includes("crows"), `phase ${phase}: high moves when high`);
const capped = { picks: 3 };
for (let i = 0; i < 100; i++) assert.notEqual(mw.pickMove(capped, phase, random, 0, true, mw.CROWS_CAP), "crows");
}
const round = lawnFight();
standAt(round, 160);
assert.equal(mw.isHigh(round), false, "the lawn is not high");
standAt(round, 143, 2);
assert.equal(mw.isHigh(round), true, "a branch is");
});
test("Ghoul Rush's lawn: up in the oak, lightning glows on YOUR branch before it strikes (a life, struck down), and a step along it or a drop dodges it; from the second phase a second bolt waits ahead", () => {
const go = (outs) => {
const round = lawnFight();
for (const w of round.marrow.windows.slice(0, outs)) {
round.boss.hp -= w.hp;
Object.assign(w, { hp: 0, state: "out" });
}
standAt(round, 141, 2);
Object.assign(round.boss, { plan: "lightning", wait: 0, picks: 1 });
run(round, 4);
return round;
};
const hit = go(0);
assert.equal(events(hit, "marrowStorm").length, 1, "the storm gathers first");
const bolts = hit.hazards.filter((h) => h.kind === "marrowBolt");
assert.deepEqual(bolts.map((h) => [h.x, h.y]), [[141, 18]], "one glow where YOU stand, at YOUR height");
const losses = [];
const heard = [];
for (let t = 0; t < 3000 && !losses.length; t += 4) {
ghoul.advance(hit, 4, steady);
losses.push(...events(hit, "lose"));
for (const e of hit.events) if (e.type === "marrowCharge" || e.type === "marrowStrike") heard.push([e.type, t]);
if (t < mw.LIGHTNING_WARN_MS) assert.equal(losses.length, 0, "never before its glow has run");
hit.events.length = 0;
}
assert.deepEqual(losses.map((e) => e.cause), ["marrowBolt"]);
assert.deepEqual(heard.map(([type]) => type), ["marrowCharge", "marrowCharge", "marrowStrike"], "it charges up out loud twice before it strikes");
assert.ok(heard[0][1] >= 400 && heard[2][1] - heard[1][1] >= 400, "each step well apart");
for (const dodge of [(r) => standAt(r, 145.5, 2), (r) => standAt(r, 141)]) {
const safe = go(0);
dodge(safe);
const lost = [];
for (let t = 0; t < 2500; t += 4) {
ghoul.advance(safe, 4, steady);
if (safe.boss.act === "idle") safe.boss.wait = 1e9;
lost.push(...events(safe, "lose"));
safe.events.length = 0;
}
assert.deepEqual(lost, [], "dodged");
}
const two = go(4);
assert.equal(two.hazards.filter((h) => h.kind === "marrowBolt").length, 2, "a second bolt from the second phase");
});
test("Ghoul Rush's lawn: up in the oak, crows burst out of the door's mouth, climb and dive at YOU, never more than CROWS_CAP of its own", () => {
const round = lawnFight();
standAt(round, 143, 2);
round.you.safeMs = 1e9;
Object.assign(round.boss, { plan: "crows", wait: 0, picks: 1 });
run(round, 4);
assert.equal(round.boss.act, "crowsWind");
run(round, 4);
assert.equal(round.boss.mouth, true, "the door is open");
run(round, mw.CROWS_WIND_MS + 40);
const crows = round.monsters.filter((m) => m.houseCrow);
assert.equal(crows.length, mw.CROWS_N[0]);
assert.ok(crows.every((m) => m.kind === "crow" && Math.abs(m.x - mw.houseLeft(round.spec)) < 8), "out of the door");
assert.equal(events(round, "marrowCrows").length, 1);
run(round, 900);
assert.ok(round.monsters.some((m) => m.houseCrow && m.act === "dive"), "a dive at YOU");
Object.assign(round.boss, { plan: "crows", wait: 0 });
run(round, mw.CROWS_WIND_MS + 60);
assert.ok(round.monsters.filter((m) => m.houseCrow && !m.dead).length <= mw.CROWS_CAP);
});
// A move started now, YOU on the floor at `x`, `outs` windows already shot out (for its phase).
function moveRound(move, x = 150, outs = 0) {
const round = lawnFight();
for (const w of round.marrow.windows.slice(0, outs)) {
round.boss.hp -= w.hp;
Object.assign(w, { hp: 0, state: "out" });
}
standAt(round, x);
Object.assign(round.boss, { plan: move, wait: 0, picks: 1 });
run(round, 4);
assert.equal(round.boss.move, move);
return round;
}
// Steps YOU once out from under the first warning of `kind` that lands where YOU stand.
const stepOut = (kind, dx) => (r) => {
if (r.stepped) return;
const h = r.hazards.find((q) => q.kind === kind && q.warn > 0 && Math.abs(q.x - r.you.x) < 3);
if (!h) return;
r.stepped = true;
standAt(r, r.you.x + dx, r.you.shelf);
};
test("Ghoul Rush's lawn: each move telegraphs before it can hurt, hurts standing YOU with its own cause, and is dodged", () => {
const cases = [
["shingles", "marrowRoof", "marrowShingle", 0, (r) => r.stepped || ((r.stepped = true), standAt(r, 146))],
["pickets", "marrowPicketWind", "marrowPicket", 0, (r) => r.stepped || ((r.stepped = true), standAt(r, 146))],
["carpet", "marrowDoor", "marrowCarpet", 0, (r) => r.stepped || ((r.stepped = true), standAt(r, 143, 2))],
["bricks", "marrowCough", "marrowBrick", 4, stepOut("marrowBrick", -6)],
["stomp", "marrowRear", "marrowQuake", 8, (r) => { if (!r.climbed) { r.climbed = true; standAt(r, 143, 2); } stepOut("marrowShingle", 4)(r); }],
];
for (const [move, tell, cause, outs, dodge] of cases) {
const hit = moveRound(move, 150, outs);
assert.equal(events(hit, tell).length, 1, `${move}: ${tell} first`);
const losses = [];
for (let t = 0; t < 4000 && !losses.length; t += 4) {
ghoul.advance(hit, 4, steady);
losses.push(...events(hit, "lose"));
hit.events.length = 0;
if (t < 300) assert.equal(losses.length, 0, `${move}: never before its warning has run`);
}
assert.deepEqual(losses.map((e) => e.cause), [cause], `${move}: costs a life as ${cause}`);
const safe = moveRound(move, 150, outs);
const lost = [];
for (let t = 0; t < 4000; t += 4) {
dodge(safe);
ghoul.advance(safe, 4, steady);
// The move played out, nothing comes after it.
if (safe.boss.act === "idle") safe.boss.wait = 1e9;
lost.push(...events(safe, "lose"));
safe.events.length = 0;
}
assert.deepEqual(lost.map((e) => e.cause), [], `${move}: dodged`);
}
});
test("Ghoul Rush's lawn: the doormen step out of the door, never more than DOORMEN_CAP of its own, and endless lives spare every hit", () => {
const round = moveRound("doormen", 130, 4);
round.you.safeMs = 1e9;
run(round, mw.DOORMEN_WIND_MS + 50);
assert.equal(round.monsters.filter((m) => m.doorman).length, mw.DOORMEN_N);
assert.equal(events(round, "marrowDoormen").length, 1);
Object.assign(round.boss, { plan: "doormen", wait: 0 });
run(round, mw.DOORMEN_WIND_MS + 60);
assert.ok(round.monsters.filter((m) => m.doorman && !m.dead).length <= mw.DOORMEN_CAP);
const r = moveRound("pickets", 150);
r.infinite = true;
const lives = r.lives;
run(r, 2000);
assert.ok(events(r, "lose").length >= 1, "hit");
assert.equal(r.lives, lives, "no life spent");
});
test("Ghoul Rush's lawn: the last window out is a boss kill, then the retreat plays its beats once and in order, and only then is the door there to walk through", () => {
const round = lawnFight();
const b = round.boss;
for (const w of round.marrow.windows.slice(1)) Object.assign(w, { hp: 0, state: "out" });
round.marrow.windows[0].hp = 1;
b.hp = 1;
lightOnly(round, 0);
const lives = round.lives;
standAt(round, 160);
run(round, 400, { fire: true });
assert.equal(b.state, "down");
assert.equal(round.lives, lives + 1, "a life, as every boss gives");
assert.equal(round.hasKey, true);
const order = [];
for (let t = 0; t < mw.GONE_AT + 1500 && round.phase !== "clear"; t += 4) {
standAt(round, round.spec.door);
round.input.right = true;
ghoul.advance(round, 4, steady);
for (const e of round.events) if (e.type.startsWith("marrow") && e.type !== "marrowWindowOut") order.push([e.type, Math.round(b.t)]);
round.events.length = 0;
if (!b.gone) assert.ok(round.you.x <= mw.houseLeft(round.spec), "no door until it has gone");
}
assert.deepEqual(order.map(([t]) => t), ["marrowSag", "marrowFalseWin", "marrowLaugh", "marrowSink", "marrowGone"]);
assert.ok(order[1][1] >= mw.FALSE_AT && order[4][1] >= mw.GONE_AT, "on the retreat's clock");
assert.equal(b.gone, true);
assert.equal(round.phase, "clear", "through the door it left standing");
run(round, ghoul.CLEAR_MS + 50);
// On down the House's throat, or (the lawn the finale's only room) the win.
if (ghoul.FINALE.rooms.length > 1) assert.equal(round.spec.id, ghoul.FINALE.rooms[1], "on to the next of the House's rooms");
else assert.ok(round.won || round.phase === "ending");
});
/* ------------------------------------------------------------ the fight */
// A steady player: shoots the lowest lit window from the surface serving it (getting there
// takes CLIMB_MS a row, about two branches of the oak, firing nothing on the way: the bot is put there after), jumps the
// carpet and the quake on the floor, and steps out from under a slate, a ripple or a brick.
const CLIMB_MS = 1500;
function fight(seed, skilled = true) {
const round = lawnFight();
const random = seededRandom(seed);
Object.assign(round.boss, { wait: 600, litMs: 0 });
let at = 0;
let travel = 0;
let t = 0;
const causes = [];
for (; t < 240000 && round.boss.state !== "down" && !round.over; t += 4) {
const you = round.you;
const inp = round.input;
inp.left = inp.right = inp.fire = false;
if (round.phase === "ask") ghoul.answerDie(round, false);
if (skilled && round.phase === "play" && you.out <= 0 && you.state === "run") {
const lit = round.marrow.windows.filter((w) => w.state === "lit").sort((a, c) => a.row - c.row);
const threat = round.hazards.find((h) => (h.warn > 0 || h.live > 0) && Math.abs(h.x - you.x) < (h.w + 1.6) / 2 + 0.6 && (h.kind === "marrowShingle" || you.y === h.y));
const wave = round.waves.find((w) => w.y === you.y && w.x - you.x > 0 && w.x - you.x < 5);
if (wave) inp.jump = ghoul.JUMP_BUFFER_MS;
else if (threat) {
const s = you.shelf >= 0 ? round.spec.shelves[you.shelf] : [mw.houseLeft(round.spec) - 60, mw.houseLeft(round.spec) - 2];
const dir = threat.x >= you.x ? -1 : 1;
inp[(dir < 0 ? you.x - 3 > s[0] : you.x + 3 > s[1]) ? "left" : "right"] = true;
} else if (travel > 0) travel -= 4;
else if (lit.length) {
const row = lit[0].row;
const [x, shelf] = SERVES[row];
if (row !== at) {
travel = CLIMB_MS * Math.abs(row - at);
at = row;
} else {
if (you.shelf !== shelf || Math.abs(you.x - x) > 4) standAt(round, x, shelf);
you.face = 1;
inp.fire = true;
}
}
}
ghoul.advance(round, 4, random);
causes.push(...events(round, "lose").map((e) => e.cause));
round.events.length = 0;
}
return { won: round.boss.state === "down", secs: t / 1000, causes, round };
}
test("Ghoul Rush's lawn takes a steady player a real fight at full depth: 60 to 120 seconds on most seeds, with lives to spare; a player who stands still dies", () => {
const times = [];
const lives = [];
let good = 0;
for (const seed of [3, 7, 19, 41]) {
const f = fight(seed);
assert.ok(f.won, `seed ${seed}: it fell (${f.causes}; ${f.secs.toFixed(1)} s, hp ${f.round.boss.hp})`);
assert.ok(f.round.lives > 0, `seed ${seed}: lives to spare (${f.causes})`);
for (const c of f.causes) assert.ok(LOSE_WORDS[c] || ghoul.MONSTERS[c], `${c} is the House's or one of the dead`);
if (f.secs >= 60 && f.secs <= 120) good++;
times.push(f.secs);
lives.push(f.round.lives);
}
assert.ok(good >= 3, `most seeds in 60 to 120 s (${times.map((x) => x.toFixed(1))}; lives ${lives})`);
const idle = fight(7, false);
assert.equal(idle.won, false);
assert.ok(idle.round.over, `game over (${idle.causes})`);
assert.equal(idle.round.boss.hp, idle.round.boss.max, "and not a window touched");
});
/* ------------------------------------------------- voices, words, drawing */
const heard = (e) => {
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, markFurthest: noop };
react(e, kit);
return played;
};
test("Ghoul Rush's House: a voice for every act in tones.js, every event plays its own sound once, and every cause has words and a sound", () => {
const known = new Set(toneNames());
for (const [act, name] of Object.entries(VOICES.marrow)) assert.ok(known.has(name), `${act}: ${name} is a tone`);
const at = { kind: "marrow", x: 190, y: 20, xs: [150], left: 3 };
const cases = { marrowLight: "light", marrowWindowOut: "windowOut", marrowRoof: "roof", marrowDoor: "door", marrowCarpet: "carpet", marrowPicketWind: "picketWind", marrowPicketUp: "picketUp", marrowShingleLand: "shingle", marrowCough: "cough", marrowBrickLand: "brick", marrowDoormen: "doormen", marrowRear: "rear", marrowStomp: "stomp", marrowSag: "sag", marrowFalseWin: "falseWin", marrowLaugh: "laugh", marrowSink: "sink", marrowGone: "gone", marrowStorm: "storm", marrowCharge: "charge", marrowStrike: "strike", marrowCrows: "crows", bossWake: "wake", bossHit: "hurt", bossDown: "die" };
for (const [type, act] of Object.entries(cases)) {
const played = heard({ type, ...at, how: "window", points: 1, life: true });
assert.equal(played.filter((n) => n === VOICES.marrow[act]).length, 1, `${type}: ${VOICES.marrow[act]} once`);
}
for (const cause of ["marrow", "marrowShingle", "marrowCarpet", "marrowPicket", "marrowBrick", "marrowQuake", "marrowBolt"]) {
assert.ok(LOSE_WORDS[cause], `${cause}: words`);
assert.ok(known.has(LOSE_SOUNDS[cause][0]), `${cause}: a sound`);
}
});
test("Ghoul Rush's lawn draws: the run up, the fight with windows of every state, every move's warning and hit, every beat of the retreat, lit and dark", () => {
const { canvas, calls } = stubCanvas();
const g = ghoul.default.create({ canvas });
g.resize(900, 900);
g.stageSelect();
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g.key("down");
g.key("action");
for (let n = 0; n < 2; n++) {
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 50; ms += 16) g.tick(16);
g.key("action");
}
const r = g.round;
r.infinite = true;
const frame = (label) => {
const before = calls.count;
g.tick(16);
assert.ok(calls.count > before, `${label} draws`);
};
for (const dark of [false, true]) {
r.dark = dark;
standAt(r, 40);
frame("the run up");
standAt(r, 130);
for (let ms = 0; ms < 1600; ms += 16) g.tick(16);
r.marrow.windows.forEach((w, i) => (w.state = ["lit", "dark", "out"][i % 3]));
frame("windows lit, shuttered and out");
for (const move of ["shingles", "pickets", "carpet", "bricks", "doormen", "stomp", "lightning", "crows"]) {
Object.assign(r.boss, { plan: move, wait: 0 });
for (let ms = 0; ms < 1400; ms += 16) frame(move);
}
for (const t of [100, mw.FALSE_AT + 100, mw.LAUGH_AT + 100, mw.SINK_AT + 800, mw.GONE_AT + 100]) {
Object.assign(r.boss, { state: "down", t, gone: t >= mw.GONE_AT });
frame(`the retreat at ${t}`);
}
Object.assign(r.boss, { state: "fight", t: 0, gone: false });
}
});
@@ -0,0 +1,914 @@
// Web console tests, Ghoul Rush's Down the Hatch (the finale's first ride, after the Front Lawn): its shape (eleven swallows, every fork's hole swallows a rider who does not jump and its gristle ledge catches one who does, every uvula can be ducked, spacing, checkpoints every 8 to 10 seconds, the lip), the ride's speed on slopes and bile, its jump and duck, a rib, a uvula-lamp, a squeeze's throb, close and ease (peristalsis), the swallowed furniture, a plunge, the checkpoints, the lip and the door, the bonus round's three hearts and dice (3 to 8), endless lives for every cause, a voice for every event, the drawing, the telegraphs, and bots that ride the whole throat (one that rides well finishes, one that never dodges loses all three hearts without a game over).
// Run with: node --test scripts/test-web-console-activities-ghoul-mat.mjs
import { test } from "node:test";
import assert from "node:assert/strict";
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
import * as mt from "../src/web-console/public/activities/ghoul-rush/rides/mat/ghoul-mat.js";
import * as ct from "../src/web-console/public/activities/ghoul-rush/rides/cart/ghoul-cart.js";
import { MAT_ROOM } from "../src/web-console/public/activities/ghoul-rush/rides/mat/ghoul-mat-room.js";
import { EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as MAT_LOOKS, VOICES as MAT_VOICES, telegraphMarks, telegraphs, throbAt } from "../src/web-console/public/activities/ghoul-rush/rides/mat/ghoul-mat-draw.js";
import { MAT_SFX } from "../src/web-console/public/activities/ghoul-rush/rides/mat/ghoul-sfx-mat.js";
import * as ghoulSfx from "../src/web-console/public/activities/ghoul-rush/sfx/ghoul-sfx.js";
import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-rush/core/ghoul-bonus.js";
import { toneNames } from "../src/web-console/public/tones.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 mat 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);
}
function skipCard(round) {
round.introMs = ghoul.INTRO_MIN_MS;
return ghoul.takeIntro(round);
}
// A round in Down the Hatch reached the way a run reaches it (six stages behind it, the Front Lawn
// passed), nothing woken, the clocks long, the bonus round on (three hearts).
function matRound(seed = 5) {
const round = ghoul.newRound(seed);
round.lives = 3;
round.dice = 0;
through(round);
round.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES).map((st) => st.id);
round.offer = null;
through(round);
assert.equal(round.spec.id, "lawn");
skipCard(round);
skipCard(round);
through(round);
assert.equal(round.spec.id, "mat");
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: "mat", hearts: 3, rails: 0, time: 1e9, finish: 1e6, track: [], ribs: [], lows: [], squeezes: [], furniture: [], bile: [], checks: [] };
// The same round over a ride of its own (a plain track to measure the rider on).
function synth(ride) {
const round = matRound();
round.spec = { ...round.spec, start: 10, ground: [[0, 5, 0]], ride: { ...NONE, rails: (ride.track || []).length, ...ride } };
mt.MAT.place[0](round, {});
return round;
}
const FLAT = [[[0, 20], [4000, 20]]];
const DOWN = [[[0, 40], [4000, 40 - 0.1 * 4000]]];
// The rider on line `line` of the ride at `x`, at speed `v`.
function rideAt(round, x, line, { v = mt.MAT_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("mat");
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 floors = lines.slice(0, R.rails);
const ledges = lines.slice(R.rails);
const K = { HIT_W: ghoul.HIT_W, HIT_H: ghoul.HIT_H, DUCK_H: ghoul.DUCK_H };
/* -------------------------------------------------------------- the room */
test("Ghoul Rush's Down the Hatch is the finale's room after the Front Lawn: a bonus ride of three hearts, lit, no key, no boss, about 30 seconds long", () => {
assert.equal(MAT_ROOM.ready, true, "plays in a run");
const fin = ghoul.FINALE.rooms;
assert.equal(fin[0], "lawn");
assert.equal(fin[1], "mat", "straight after the Front Lawn");
assert.deepEqual([ROOM.title, ROOM.sub], ["Down the Hatch", "Wipe your feet"]);
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, "mat");
assert.equal(R.hearts, 3, "three hearts, not five");
assert.equal(typeof ghoul.ROOM_MUSIC.mat, "string", "a track to play");
assert.deepEqual(Object.keys(mt.MAT.monsters), [], "no new monster kinds");
assert.equal(LOOKS.mat, MAT_LOOKS.mat);
assert.equal(LOOKS.mat.pack, "mat");
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");
assert.match(R.how, /UP jump, DOWN duck, SPACE shoot/, "the keys in the how line");
assert.equal(ROOM.ground.length, 2, "the front step and the cellar floor only");
assert.ok(ROOM.ground[0][1] < 60 && ROOM.ground[1][0] > ROOM.length - 100);
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");
assert.ok(floorOf(ROOM.door - 2) > -Infinity);
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 mat starts on the throat over the front step");
// About 30 seconds at the mat's speed.
const secs = (floors.at(-1).x1 - ROOM.start) / mt.MAT_V;
assert.ok(secs >= 27 && secs <= 34, `${secs.toFixed(1)} s at MAT_V`);
// The swallows: descents at about 0.10 and short climbs at about 0.3, never steeper.
let down = 0;
let total = 0;
for (const L of floors) {
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.15 && 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 throat goes down`);
for (const L of lines) for (const [, y] of L.pts) assert.ok(y > mt.DERAIL_Y + 4 && y < 46, `a floor height of ${y}`);
assert.equal(ghoul.timeFor(ghoul.roomFor("mat")), R.time);
assert.ok(R.time >= 2 * secs * 1000, "the clock never matters on a ride");
assert.ok(ct.slopeOf(R, R.rails - 1, floors.at(-1).x1) >= mt.RAMP_SLOPE, "the lip launches");
// The bonus round: three hearts of its own.
const round = matRound();
assert.equal(round.bonusRound.hearts, 3);
assert.equal(round.bonusRound.max, 3);
assert.equal(round.runner.id, "mat");
});
test("Ghoul Rush's Down the Hatch: the lip's launch alone carries the rider onto the cellar floor at any speed it can have there", () => {
const lip = floors.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 [mt.MAT_MIN, 36, mt.MAT_V, 55, mt.MAT_MAX]) {
let vy = rise * v + mt.RAMP_POP;
let x = end[0];
let y = end[1];
for (let t = 0; t < 3; t += 0.002) {
vy -= mt.MAT_G * 0.002;
x += v * 0.002;
y += vy * 0.002;
if (vy < 0 && y <= floor) break;
}
assert.ok(x >= R.finish + 2 && x <= R.finish + 40, `at ${v} it lands ${(x - R.finish).toFixed(1)} past the floor's start`);
}
});
test("Ghoul Rush's Down the Hatch: every fork's hole is too wide to jump across and swallows a rider who does not jump, its gristle ledge catches a jump from before the hole at any speed, and off the ledge's end the rider drops back onto the floor", () => {
assert.equal(R.rails - 1, 2, "two forks");
assert.equal(ledges.length, 2, "a ledge over each");
for (let i = 0; i + 1 < R.rails; i++) {
const a = lines[i];
const b = lines[i + 1];
const gap = b.x0 - a.x1;
assert.ok(gap >= 46, `hole ${i} is ${gap} wide, past a jump at bile speed`);
const end = a.pts.at(-1);
const slope = ct.slopeOf(R, i, a.x1);
assert.ok(slope < 0, "holes lie on descents (no ramp launch)");
// The ledge over it, RAIL_SEP over the throat, from before the hole to past it.
const n = ledges.findIndex((L) => L.x0 < a.x1 && L.x1 > b.x0);
assert.ok(n >= 0, `a ledge over hole ${i}`);
const L = ledges[n];
const line = R.rails + n;
assert.ok(a.x1 - L.x0 >= 16 && L.x1 - b.x0 >= 10, "the ledge starts well before the hole and ends past it");
for (let x = L.x0; x <= Math.min(L.x1, a.x1); x += 2) assert.ok(Math.abs(ct.trackY(R, line, x) - ct.trackY(R, i, x) - mt.RAIL_SEP) < 0.15, `${mt.RAIL_SEP} over at ${x}`);
assert.ok(mt.upperLine(R, line) && !mt.upperLine(R, i));
for (const v of [mt.MAT_MIN + 6, mt.MAT_V, 55, mt.BILE_V]) {
// No jump: into the hole, and a jump with no ledge would not clear it either.
assert.equal(mt.flight(R, a.x1, end[1], slope * v, v), null, `hole ${i}, no jump, at ${v}`);
const bare = { ...R, track: R.track.slice(0, R.rails) };
assert.equal(mt.flight(bare, a.x1 - 2, ct.trackY(R, i, a.x1 - 2), mt.MAT_JUMP_V + slope * v, v), null, `hole ${i} cannot be jumped across at ${v}`);
// A jump from a few units before the ledge to the hole's edge lands on the ledge.
for (const x of [L.x0 - 6, L.x0, L.x0 + 8, a.x1 - 1]) {
const top = ct.linesAt(R, x).find(([ln]) => ln === i);
const s = mt.flight(R, x, top[1], mt.MAT_JUMP_V + ct.slopeOf(R, i, x) * v, v);
assert.ok(s && s.line === line, `hole ${i}: a jump from ${x} at ${v} lands on the ledge (${JSON.stringify(s)})`);
}
}
// Off the ledge's end: down onto the floor beyond the hole.
const tail = L.pts.at(-1);
const f = mt.flight(R, L.x1, tail[1], ct.slopeOf(R, line, L.x1) * mt.MAT_V, mt.MAT_V);
assert.ok(f && f.line === i + 1, `off ledge ${n}, onto the floor`);
}
});
test("Ghoul Rush's Down the Hatch: every thing is on a line and well inside it, spaced for a player (22 between jumps and 38 between a jump and a duck), a uvula's underside between a ducked box and a standing one, the checkpoints every 8 to 10 seconds", () => {
const jumps = [];
for (const [x, line] of R.ribs) {
assert.ok(ct.trackY(R, line, x) !== null, `a rib at ${x} stands on line ${line}`);
assert.ok(!mt.upperLine(R, line), "ribs grow out of the floor");
assert.ok(x - lines[line].x0 > 8 && lines[line].x1 - x > 14, `a rib at ${x} well inside its line`);
jumps.push([x - 2, x + 2]);
}
for (const [x, line, kind] of R.furniture) {
assert.ok(ct.trackY(R, line, x) !== null);
assert.ok([0, 1, 2].includes(kind));
assert.ok(x - lines[line].x0 > 20 && lines[line].x1 - x > 14, `furniture at ${x} has room to tumble`);
jumps.push([x - 12, x + 2]);
}
for (const L of ledges) jumps.push([L.x0 - 14, L.x0 + 26]);
const ducks = [];
for (const [x0, x1] of R.lows) ducks.push([x0, x1]);
for (const [x, line] of R.squeezes) {
assert.ok(ct.trackY(R, line, x) !== null && !mt.upperLine(R, line), `a squeeze at ${x} over the floor`);
assert.ok(!ledges.some((L) => x > L.x0 - 10 && x < L.x1 + 10), "no ledge near a squeeze");
ducks.push([x - mt.SQ_W / 2 - 6, x + mt.SQ_W / 2 + 6]);
}
jumps.sort((p, q) => p[0] - q[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 (const [x0, x1, y] of R.lows) {
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 floor or a ledge under a uvula");
hi = Math.max(hi, g[1]);
lo = Math.min(lo, g[1]);
}
assert.ok(hi + K.DUCK_H < y, `a ducked box clears the uvula at ${x0}`);
assert.ok(lo + K.HIT_H > y, `a standing box hits the uvula at ${x0}`);
}
for (const [x0, x1] of R.bile) assert.ok(x1 > x0 && ct.linesAt(R, (x0 + x1) / 2).length, "bile lies on the floor");
assert.ok(R.ribs.length >= 4 && R.lows.length >= 2 && R.squeezes.length >= 3 && R.furniture.length >= 3 && R.bile.length >= 2);
// Checkpoints every 8 to 10 seconds of riding, on the floor, clear of a jump coming up.
const cs = R.checks;
assert.ok(cs.length >= 3);
for (let i = 0; i < cs.length; i++) {
assert.ok(ct.linesAt(R, cs[i]).length, `checkpoint ${i} on the floor`);
const gap = (cs[i] - (i ? cs[i - 1] : ROOM.start)) / mt.MAT_V;
assert.ok(gap >= 7.5 && gap <= 10, `${gap.toFixed(1)} s to checkpoint ${i}`);
for (const [j0, j1] of jumps) assert.ok(j0 - cs[i] > 20 || cs[i] - j1 > 4, `a jump at ${j0} near checkpoint ${i}`);
}
});
/* ------------------------------------------------------------ the rider */
test("Ghoul Rush's Down the Hatch rolls at MAT_V on the flat, faster down a slope, faster again on bile (BILE_V), never past MAT_MIN or MAT_MAX", () => {
const flat = synth({ track: FLAT });
assert.equal(flat.runner.v, mt.MAT_V);
run(flat, 2000);
assert.ok(Math.abs(flat.runner.v - mt.MAT_V) < 0.01);
assert.equal(flat.you.face, 1);
assert.equal(flat.you.state, "run");
assert.equal(flat.you.y, 20);
const down = synth({ track: DOWN });
run(down, 3000);
assert.ok(Math.abs(down.runner.v - (mt.MAT_V + (mt.SLOPE_G * 0.1) / mt.RELAX)) < 0.2, `${down.runner.v} down a 0.1 slope`);
const slick = synth({ track: FLAT, bile: [[0, 4000]] });
run(slick, 3000);
assert.ok(Math.abs(slick.runner.v - mt.BILE_V) < 0.2, `${slick.runner.v} on bile`);
assert.equal(events(slick, "matBile").length, 1, "one word as it starts");
const steep = synth({ track: [[[0, 10000], [4000, 6000]]] });
run(steep, 3000);
assert.equal(steep.runner.v, mt.MAT_MAX);
const wall = synth({ track: [[[0, 0], [4000, 4000]]] });
run(wall, 3000);
assert.equal(wall.runner.v, mt.MAT_MIN);
});
test("Ghoul Rush's Down the Hatch jumps about 13 high for about three quarters of a second, a press saved for a landing jumps on it, and 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 - (mt.MAT_JUMP_V * mt.MAT_JUMP_V) / (2 * mt.MAT_G)) < 0.4, `${top.toFixed(1)} high`);
assert.ok(t > 650 && t < 850, `${t} ms in the air`);
assert.equal(events(round, "matJump").length, 1);
assert.equal(events(round, "matLand").length, 1);
const buf = synth({ track: FLAT });
press(buf);
run(buf, 640);
press(buf);
until(buf, () => events(buf, "matJump").length >= 2, 1500);
assert.equal(events(buf, "matJump").length, 2, "the saved press jumped again at the landing");
const edge = synth({ track: [[[0, 20], [60, 20]], [[150, 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, "matJump").length, 1, "coyote");
});
test("Ghoul Rush's Down the Hatch: DOWN ducks; a ducked rider passes under a uvula-lamp and a standing one or a jumping one hits it (cause matUvula), a heart and not a life, once", () => {
const duck = synth({ track: FLAT, lows: [[60, 67, 23.0]] });
run(duck, 20, { down: true });
assert.equal(events(duck, "matDuck").length, 1);
duck.input.down = true;
until(duck, () => duck.you.x > 75, 3000);
duck.input.down = false;
assert.equal(duck.bonusRound.hearts, 3);
const hit = synth({ track: FLAT, lows: [[60, 67, 23.0]] });
until(hit, () => hit.bonusRound.hearts < 3, 3000);
assert.equal(hit.bonusRound.hearts, 2);
assert.equal(hit.lives, 3, "not a life");
assert.equal(events(hit, "lose")[0].cause, "matUvula");
assert.equal(events(hit, "matCrash")[0].what, "uvula");
assert.equal(hit.phase, "play", "the ride rolls on");
assert.ok(hit.you.safeMs > 0, "blinking safe");
assert.deepEqual(hit.bonusRound.perf.hits, ["u0"]);
run(hit, 1000);
assert.equal(hit.bonusRound.hearts, 2, "the same uvula costs nothing twice");
const jump = synth({ track: FLAT, lows: [[60, 67, 23.0]] });
rideAt(jump, 40, 0);
press(jump);
until(jump, () => jump.bonusRound.hearts < 3 || jump.you.x > 80, 3000);
assert.equal(jump.bonusRound.hearts, 2, "a jump does not clear a uvula");
});
test("Ghoul Rush's Down the Hatch: a rib bone is cleared by a jump from 9 to 26 short of it and costs a heart otherwise (cause matRib), once", () => {
const hit = synth({ track: FLAT, ribs: [[60, 0]] });
until(hit, () => hit.bonusRound.hearts < 3, 3000);
assert.equal(hit.bonusRound.hearts, 2);
assert.equal(events(hit, "lose")[0].cause, "matRib");
assert.equal(events(hit, "matCrash")[0].what, "rib");
assert.deepEqual(hit.bonusRound.perf.hits, ["r0"]);
run(hit, 500);
assert.equal(hit.bonusRound.hearts, 2);
for (const from of [60 - 26, 60 - 14, 60 - 9]) {
const clear = synth({ track: FLAT, ribs: [[60, 0]] });
rideAt(clear, from, 0);
press(clear);
until(clear, () => clear.you.x > 80, 3000);
assert.equal(clear.bonusRound.hearts, 3, `jumped from ${from}`);
}
// A ducked rider is no lower than a rib.
const low = synth({ track: FLAT, ribs: [[60, 0]] });
low.input.down = true;
until(low, () => low.you.x > 70, 3000);
assert.equal(low.bonusRound.hearts, 2, "ducking does not pass a rib");
});
/* ------------------------------------------------------- peristalsis */
test("Ghoul Rush's Down the Hatch: a squeeze waits, then throbs SQ_WARN_MS (two throbs heard, the walls pulsing) at least 1.5 s before you reach it, closes, holds shut while you pass and eases; a ducked rider passes under it", () => {
const round = synth({ track: FLAT, squeezes: [[200, 0]] });
rideAt(round, 40, 0);
const s = () => round.runner.squeezes[0];
assert.equal(s().state, "wait");
run(round, 100);
assert.equal(s().state, "wait", "far off: waiting");
until(round, () => s().state === "throb", 5000);
const ahead = 200 - round.you.x;
assert.ok(ahead / round.runner.v >= 1.5, `it throbs ${(ahead / round.runner.v).toFixed(2)} s ahead`);
assert.deepEqual(events(round, "matSqueezeThrob").map((e) => e.n), [1]);
assert.ok(throbAt(round.spec.ride, round.runner, 200) > 0, "the walls throb near it");
assert.equal(throbAt(round.spec.ride, round.runner, 280), 0, "and not far from it");
assert.equal(mt.squeezeLow(s()), mt.SQ_OPEN, "still open while it throbs");
const half = until(round, () => events(round, "matSqueezeThrob").length >= 2, 2000);
assert.ok(Math.abs(half - mt.SQ_WARN_MS / 2) < 20, `the second throb ${half} ms in`);
assert.equal(events(round, "matSqueezeThrob")[1].n, 2);
until(round, () => s().state === "close", 2000);
assert.equal(events(round, "matSqueezeClose").length, 1);
until(round, () => s().state === "shut", 1000);
assert.equal(mt.squeezeLow(s()), mt.SQ_LOW);
const early = 200 - mt.SQ_W / 2 - round.you.x;
assert.ok(early > 8, `shut ${early.toFixed(1)} before you reach it`);
// Ducked through it: nothing.
round.input.down = true;
until(round, () => round.you.x > 215, 2000);
round.input.down = false;
assert.equal(round.bonusRound.hearts, 3, "ducked under it");
assert.equal(s().state, "shut", "still shut as you leave it");
until(round, () => s().state === "done", 3000);
assert.equal(mt.squeezeLow({ state: "ease", t: mt.SQ_EASE_MS }), mt.SQ_LOW);
assert.equal(mt.squeezeLow({ state: "ease", t: 0 }), mt.SQ_OPEN);
// At bile speed it still throbs well ahead and is shut before you arrive.
const fast = synth({ track: FLAT, squeezes: [[300, 0]], bile: [[0, 4000]] });
rideAt(fast, 40, 0, { v: mt.BILE_V });
until(fast, () => fast.runner.squeezes[0].state === "shut", 6000);
assert.ok(300 - mt.SQ_W / 2 - fast.you.x > 8, "shut before you get there at bile speed too");
});
test("Ghoul Rush's Down the Hatch: a squeeze shut over you costs a heart standing or jumping (cause matSqueeze), and nothing while it is still open", () => {
const stand = synth({ track: FLAT, squeezes: [[200, 0]] });
rideAt(stand, 40, 0);
until(stand, () => stand.bonusRound.hearts < 3 || stand.you.x > 220, 6000);
assert.equal(stand.bonusRound.hearts, 2);
assert.equal(events(stand, "lose")[0].cause, "matSqueeze");
assert.equal(events(stand, "matCrash")[0].what, "squeeze");
assert.deepEqual(stand.bonusRound.perf.hits, ["s0"]);
const hop = synth({ track: FLAT, squeezes: [[200, 0]] });
rideAt(hop, 40, 0);
until(hop, () => hop.runner.squeezes[0].state === "shut", 6000);
until(hop, () => 200 - hop.you.x < 18, 2000);
press(hop);
until(hop, () => hop.bonusRound.hearts < 3 || hop.you.x > 220, 3000);
assert.equal(hop.bonusRound.hearts, 2, "a jump into it hits");
// Open (a rider placed past its warning), it is nothing.
const open = synth({ track: FLAT, squeezes: [[200, 0]] });
rideAt(open, 196, 0);
open.runner.squeezes[0] = { state: "throb", t: 900, n: 1 };
run(open, 200);
assert.equal(open.bonusRound.hearts, 3);
});
/* ----------------------------------------------------------- furniture */
test("Ghoul Rush's Down the Hatch: a piece of furniture drops from the roof FURN_DROP_MS when you are FURN_LEAD_MS short of it, lands, tumbles up at you and hits (cause matFurniture) if you meet it; a jump clears it", () => {
const hit = synth({ track: FLAT, furniture: [[300, 0, 1]] });
rideAt(hit, 150, 0);
const f = () => hit.runner.furniture[0];
assert.equal(f().state, "wait");
until(hit, () => f().state === "drop", 5000);
const ahead = 300 - hit.you.x;
assert.ok(Math.abs(ahead - (mt.MAT_V * mt.FURN_LEAD_MS) / 1000) < 1, `drops ${ahead.toFixed(1)} ahead`);
assert.equal(events(hit, "matFurnDrop").length, 1);
assert.ok(mt.furnitureLift(f()) > 15, "up near the roof");
assert.equal(hit.bonusRound.hearts, 3, "falling, it hurts nobody far off");
const ms = until(hit, () => f().state === "roll", 2000);
assert.ok(Math.abs(ms - mt.FURN_DROP_MS) < 20);
assert.equal(events(hit, "matFurnLand").length, 1);
assert.ok(f().x - hit.you.x > 28 && f().x - hit.you.x < 42, `lands ${(f().x - hit.you.x).toFixed(1)} ahead: time to see it`);
const x0 = f().x;
run(hit, 100);
assert.ok(x0 - f().x > mt.FURN_V * 0.09, "it tumbles at you");
until(hit, () => hit.bonusRound.hearts < 3, 2000);
assert.equal(events(hit, "lose")[0].cause, "matFurniture");
assert.equal(events(hit, "matCrash")[0].what, "furniture");
assert.equal(f().state, "spent");
assert.deepEqual(hit.bonusRound.perf.hits, ["f0"]);
const jump = synth({ track: FLAT, furniture: [[300, 0, 0]] });
rideAt(jump, 150, 0);
until(jump, () => jump.runner.furniture[0].state === "roll" && jump.runner.furniture[0].x - jump.you.x < 16, 5000);
press(jump);
until(jump, () => jump.you.x > 330, 3000);
assert.equal(jump.bonusRound.hearts, 3);
});
test("Ghoul Rush's Down the Hatch: two bolts break a piece of furniture (FURN_POINTS, an act for the grade), along the slope; what was shot stays shot after a restart", () => {
const round = synth({ track: DOWN, furniture: [[260, 0, 2]] });
rideAt(round, 120, 0);
round.you.safeMs = 1e9;
const start = round.score;
round.input.fire = true;
until(round, () => round.runner.furniture[0].state === "broken", 5000);
round.input.fire = false;
assert.equal(round.runner.furniture[0].state, "broken");
assert.equal(events(round, "matFurnHit").length, mt.FURN_HP - 1);
assert.equal(events(round, "matFurnBreak")[0].points, mt.FURN_POINTS);
assert.equal(round.bonusRound.perf.acts, 1);
assert.ok(round.score - start >= mt.FURN_POINTS);
// 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) assert.ok(Math.abs(s.y - (40 - 0.1 * s.x) - ghoul.SHOT_Y) < 0.5, "a bolt over the floor");
// Nothing to shoot while it waits in the roof.
const idle = synth({ track: FLAT, furniture: [[300, 0, 0]] });
assert.equal(mt.MAT.target(idle, { x: 300, y: 22 }), false);
const again = synth({ track: FLAT, furniture: [[300, 0, 0]] });
again.runner.furniture[0].state = "broken";
mt.MAT.place[0](again, {});
assert.equal(again.runner.furniture[0].state, "broken");
});
/* ------------------------------------------------- forks, holes and hearts */
test("Ghoul Rush's Down the Hatch: a hole with no jump is a heart (cause matPlunge), the rider goes back on the ledge over it (or the floor beyond, with none) at MAT_V and rolls on; a jump onto the ledge passes it, with a switch up and down", () => {
const ride = { track: [[[0, 20], [100, 20]], [[160, 20], [400, 20]], [[80, 27], [175, 27]]], rails: 2 };
const fall = synth(ride);
rideAt(fall, 60, 0);
until(fall, () => fall.bonusRound.hearts < 3, 3000);
assert.equal(fall.bonusRound.hearts, 2);
assert.equal(fall.lives, 3, "not a life");
assert.equal(events(fall, "lose")[0].cause, "matPlunge");
assert.equal(fall.phase, "play");
assert.equal(fall.runner.line, 2, "caught on the ledge over the hole");
assert.equal(fall.you.y, 27);
assert.equal(fall.runner.v, mt.MAT_V);
assert.deepEqual(fall.bonusRound.perf.hits, ["g0"]);
until(fall, () => fall.you.x > 200, 3000);
assert.equal(fall.runner.line, 1, "and down off its end onto the floor");
assert.equal(fall.bonusRound.hearts, 2);
const bare = synth({ track: [[[0, 20], [100, 20]], [[160, 20], [400, 20]]] });
rideAt(bare, 60, 0);
until(bare, () => bare.bonusRound.hearts < 3, 3000);
assert.equal(bare.runner.line, 1, "with no ledge: on the floor beyond the hole");
assert.ok(bare.you.x >= 160 && bare.you.x < 165);
const hop = synth(ride);
rideAt(hop, 76, 0);
press(hop);
until(hop, () => hop.runner.line === 2, 2000);
assert.equal(hop.runner.line, 2, "on the ledge");
assert.equal(events(hop, "matSwitch")[0].up, true);
until(hop, () => hop.you.x > 200, 3000);
assert.equal(hop.runner.line, 1, "back down on the floor");
assert.equal(events(hop, "matSwitch")[1].up, false);
assert.equal(hop.bonusRound.hearts, 3);
});
test("Ghoul Rush's Down the Hatch: the last heart gone ends the round with nothing at once (BONUS LOST: no life lost, the dice in hand kept, no game over) and the run goes on to the next room", () => {
const round = matRound();
round.dice = 2;
round.bonusRound.hearts = 1;
const [x] = R.ribs[0];
rideAt(round, x - 10, ct.linesAt(R, x - 10)[0][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);
const next = ghoul.FINALE.rooms[ghoul.FINALE.rooms.indexOf("mat") + 1];
if (next) {
assert.equal(round.spec.id, next, "on to the next of the House's rooms");
assert.equal(round.bonusRound, null);
assert.equal(round.runner ?? null, null);
assert.equal(round.lives, 3);
assert.equal(round.dice, 2);
} else assert.equal(round.won, true, "the last of the House's rooms ready: on to the win");
});
test("Ghoul Rush's Down the Hatch: the checkpoints are passed in order (an event each) and the ride goes back to the last one after the last heart; another ride's slot is not its own", () => {
const round = matRound();
rideAt(round, R.checks[0] - 6, ct.linesAt(R, R.checks[0] - 6)[0][0]);
round.you.safeMs = 1e9;
until(round, () => round.runner.check >= 0, 4000);
assert.deepEqual(events(round, "matCheck").map((e) => e.n), [1]);
const c0 = round.runner.check;
round.you.x = 1;
mt.MAT.place[0](round, {});
assert.equal(round.you.x, R.checks[c0]);
assert.equal(round.runner.v, mt.MAT_V);
assert.equal(round.runner.check, c0);
assert.equal(round.camLead, mt.CAM_AHEAD);
const fresh = matRound();
assert.equal(fresh.you.x, ROOM.start);
assert.equal(fresh.runner.check, -1);
const other = matRound();
other.runner = { id: "banister" };
other.spec = { ...other.spec, ride: { ...other.spec.ride, runner: "banister" } };
mt.MAT.place[0](other, {});
assert.deepEqual(other.runner, { id: "banister" });
other.runner = { id: "mat" };
mt.MAT.place[0](other, {});
assert.equal(other.runner, null);
});
test("Ghoul Rush's Down the Hatch: off the lip the rider is spat out onto the cellar floor and stops (matFinish), the door opens, and walking out ends the round with 3 to 8 Lucky dice", () => {
const round = matRound();
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, "matLaunch").length, 1);
assert.equal(events(round, "matLaunch")[0].last, true);
assert.equal(events(round, "matFinish").length, 1);
assert.ok(round.you.x > R.finish + 2 && 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;
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 <= 8, `${end[0].dice} dice`);
assert.equal(round.dice, 1 + end[0].dice);
assert.equal(round.lives, 3);
});
test("Ghoul Rush's Down the Hatch: no random number is drawn in the room (the whole ride, jumping and shooting, on a draw that throws)", () => {
const round = matRound();
rideAt(round, 20, 0, { safe: true });
round.input.fire = true;
for (let t = 0; t < 30000; 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" || round.runner.done) break;
}
assert.ok(round.you.x > 600);
});
/* ----------------------------------------------------------- the grade */
test("Ghoul Rush's Down the Hatch's grade: three hearts earn at most one die of their share, so a perfect ride is 8 dice; shooting every piece of furniture is the acts die, and taking half the souls ('Wipe your feet') the steady one", () => {
const round = matRound();
const b = round.bonusRound;
assert.equal(b.perf.goal, R.furniture.length);
assert.equal(b.perf.total, R.ribs.length + R.lows.length + R.squeezes.length + R.furniture.length + R.rails - 1);
assert.equal(b.perf.steady, false, "no souls yet");
const mk = (perf, hearts = 3) => {
const x = makeBonus({ stats: { kills: 0 }, spec: { ride: { hearts: 3 } } });
x.hearts = hearts;
Object.assign(x.perf, { total: b.perf.total, goal: R.furniture.length }, perf);
return x;
};
assert.equal(diceFor(mk({ hits: [], acts: R.furniture.length, steady: true })), 8, "a perfect ride");
assert.equal(diceFor(mk({ hits: [], acts: 0, steady: false })), 6);
assert.equal(diceFor(mk({ hits: [], acts: 0, steady: false }, 2)), 5, "two hearts left: no hearts die");
assert.equal(diceFor(mk({ hits: ["r0", "r1", "u0", "s0", "s1", "s2", "f0", "f1", "f2", "g0", "g1", "r2", "r3", "r4", "u1", "u2", "s3"], acts: 0, steady: false }, 1)), BONUS_FLOOR);
// Half the souls taken and the die is earned.
round.candy.fill(true);
rideAt(round, 30, 0, { safe: true });
run(round, 500);
assert.equal(round.bonusRound.perf.steady, true, "souls taken");
assert.ok(round.candy.length >= 30, `${round.candy.length} souls along the throat`);
});
test("Ghoul Rush's Down the Hatch: endless lives (round.infinite) spare the hearts for every cause, through the same lose path; the Garlic shield takes a hit instead of a heart", () => {
const tries = [{ ribs: [[60, 0]] }, { lows: [[56, 62, 23.0]] }, { furniture: [[300, 0, 0]] }, { squeezes: [[200, 0]] }];
for (const t of tries) {
const r = synth({ track: FLAT, ...t });
r.infinite = true;
if (t.furniture || t.squeezes) rideAt(r, 120, 0);
until(r, () => events(r, "lose").length > 0, 6000);
assert.equal(events(r, "lose").length > 0, true, JSON.stringify(Object.keys(t)));
assert.equal(r.bonusRound.hearts, 3, JSON.stringify(Object.keys(t)));
assert.equal(r.lives, 3);
}
const hole = synth({ track: [[[0, 20], [60, 20]], [[130, 20], [400, 20]]] });
hole.infinite = true;
rideAt(hole, 30, 0);
until(hole, () => events(hole, "lose").length > 0, 3000);
assert.equal(events(hole, "lose")[0].cause, "matPlunge");
assert.equal(hole.bonusRound.hearts, 3);
const garlic = synth({ track: FLAT, ribs: [[60, 0]] });
garlic.you.garlic = true;
until(garlic, () => garlic.you.x > 70, 3000);
assert.equal(garlic.bonusRound.hearts, 3);
assert.equal(garlic.you.garlic, false, "spent");
});
/* ------------------------------------------------------ sounds and words */
test("Ghoul Rush's Down the Hatch: every event has a voice that plays once, 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(), [...mt.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 = MAT_VOICES[kind] && MAT_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: "rib", points: 150, n: 1, kind: 0 }).played;
assert.equal(played.filter((p) => p === name).length, 1, `${event} plays ${name} once`);
}
for (const [name, tone] of Object.entries(MAT_SFX.tones)) {
assert.ok(name.startsWith("ghoulMat"), name);
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 l of tone.layers) assert.ok(l.gain > 0 && l.gain <= 1, `${name}'s gain`);
}
for (const cause of mt.CAUSES) {
assert.ok(LOSE_WORDS[cause], `${cause} has words`);
assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3 && toneNames().includes(LOSE_SOUNDS[cause][0]), `${cause} has a sound`);
assert.ok(heard({ type: "lose", cause, hearts: 2 }).played.length > 0, `${cause} sounds`);
}
});
test("Ghoul Rush's Down the Hatch: the room's own names do not collide with the game's (events, causes, tones, the shared rider slot)", () => {
for (const e of mt.EVENTS) assert.ok(e.startsWith("mat"), e);
for (const c of mt.CAUSES) assert.ok(c.startsWith("mat"), c);
assert.deepEqual(Object.keys(mt.MAT).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []);
assert.equal(matRound().runner.id, "mat");
assert.equal(matRound().cart, null);
});
/* --------------------------------------------------------------- drawing */
function stubCtx() {
return new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) });
}
// A live game in Down the Hatch through the stage select's finale row, its second room.
function selectInto() {
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => stubCtx() } });
g.resize(900, 900);
g.stageSelect();
const p = g.round;
for (let i = 0; i < ghoul.SELECTABLE.length - 1; i++) ghoul.steerSelect(p, 1, 0);
ghoul.steerSelect(p, 0, 1);
assert.equal(p.select.room, 1);
g.tick(16);
ghoul.takeSelect(p);
return g;
}
test("Ghoul Rush's Down the Hatch draws: the room lit and dark, the rider on the floor, on a ledge, in the air and ducking, each thing in each state (squeezes waiting, throbbing, closing, shut and easing, furniture falling and tumbling), a crash, the finish and the cards; the stage select goes straight into it", () => {
const g = selectInto();
const r = g.round;
assert.equal(r.spec.id, "mat");
assert.equal(r.runner.line, 0);
assert.equal(r.you.y, ct.trackY(R, 0, ROOM.start));
assert.equal(r.bonusRound.hearts, 3);
r.lives = 99;
const spots = [ROOM.start + 4, R.ribs[0][0] - 10, R.lows[0][0] - 5, R.squeezes[0][0] - 14, R.furniture[0][0] - 20, R.bile[0][0] + 6, R.checks[0], ledges[0].x0 + 20, lines[0].x1 + 10, R.finish - 30];
const SQ = ["wait", "throb", "close", "shut", "ease", "done"];
const FU = ["wait", "drop", "roll", "broken", "spent"];
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.monsters.length = 0;
const top = ct.linesAt(R, x)[0] || [R.rails - 1, 20];
rideAt(r, x, top[0], { safe: true });
r.runner.squeezes = r.runner.squeezes.map((s, i) => ({ state: SQ[(i + (x | 0)) % SQ.length], t: 300, n: 1 }));
r.runner.furniture = r.runner.furniture.map((f, i) => ({ ...f, state: FU[(i + (x | 0)) % FU.length], t: 400 }));
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 = !air && x === R.lows[0][0] - 5;
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.you.safeMs = 1e9;
rideAt(r, x, top[0], { safe: true });
}
}
}
// A crash.
r.you.safeMs = 0;
rideAt(r, R.ribs[0][0] - 3, R.ribs[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");
// The finish, the won and lost cards.
const done = selectInto();
const d = done.round;
d.phase = "play";
d.runner.done = true;
d.runner.restX = R.finish + 20;
Object.assign(d.you, { x: R.finish + 30, y: floorOf(R.finish + 30), 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;
}
});
/* ------------------------------------------------------------ telegraphs */
test("Ghoul Rush's Down the Hatch telegraphs: JUMP over ribs and at each fork's ledge, DUCK under uvulas and squeezes, none for furniture (it warns by itself), words only on the first three of each kind, the same every time", () => {
const marks = telegraphMarks(R);
const answers = { rib: "JUMP", fork: "JUMP", uvula: "DUCK", squeeze: "DUCK" };
assert.equal(marks.length, R.ribs.length + ledges.length + R.lows.length + R.squeezes.length);
for (const m of marks) assert.equal(m.answer, answers[m.kind], m.kind);
const m = marks.find((q) => q.kind === "squeeze");
const alphaOf = (x) => (telegraphs(R, x).find((t) => t.kind === "squeeze" && t.lead === m.lead) || { alpha: 0 }).alpha;
assert.equal(alphaOf(m.lead - 45), 0, "not yet in view");
assert.ok(alphaOf(m.lead - 36) > 0 && alphaOf(m.lead - 36) < 1, "fading in");
assert.equal(alphaOf(m.lead - 10), 1);
assert.equal(alphaOf(m.lead + 7), 0, "gone once passed");
assert.deepEqual(telegraphs(R, m.lead - 33), telegraphs(R, m.lead - 33), "deterministic");
for (const kind of ["rib", "squeeze"]) {
const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead);
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}`);
});
}
});
/* ----------------------------------------------------------- the bots */
// A bot that rides well: it jumps 9 to 15 short of a rib, onto each fork's ledge a few units before
// it starts, over a piece of furniture tumbling at it when it is 6 to 17 short (and holds the
// blaster, which usually breaks it first), and ducks under every uvula and every squeeze. `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 = 9 + (seed % 7);
let jump = false;
if (c.line >= 0) {
const line = c.line;
const onFloor = !mt.upperLine(R, line);
for (const [x, ln] of R.ribs) if (ln === line && x - you.x > 6 && x - you.x < look && ok(x)) jump = true;
if (onFloor) for (const L of ledges) if (L.x0 - you.x > 1 && L.x0 - you.x < 6 && ok(L.x0)) jump = true;
R.furniture.forEach(([, ln], i) => {
const f = c.furniture[i];
if (ln === line && f.state === "roll" && f.x - you.x > 6 && f.x - you.x < 17 && ok(f.x)) jump = true;
});
for (const [x0, x1] of R.lows) if (you.x > x0 - 10 && you.x < x1 + 3 && ok(x0)) inp.down = true;
for (const [x] of R.squeezes) if (you.x > x - mt.SQ_W / 2 - 10 && you.x < x + mt.SQ_W / 2 + 3 && ok(x)) 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 = 60000) {
const round = matRound(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 Down the Hatch: a bot that rides well finishes the whole throat in about 30 seconds, 5 to 8 dice, a heart lost at most, past every checkpoint, never a run life", () => {
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 > 26000 && ms < 38000, `${ms} ms`);
assert.ok(b.dice >= 5 && b.dice <= 8, `${b.dice} dice`);
assert.ok(lost.length <= 1, `lost ${lost.join(",")}`);
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, `${dice.join(",")}`);
});
test("Ghoul Rush's Down the Hatch: a bot that never dodges (holding fire) loses all three hearts early, ends with 0 dice (BONUS LOST), and the run goes on: no game over, never a run life", () => {
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, 3, `lost ${lost.join(",")}`);
assert.ok(round.you.x < ROOM.length * 0.4, `out at ${round.you.x}`);
assert.equal(round.lives, 3);
assert.equal(round.over, false);
assert.equal(round.phase, "clear", "the lost card, then the next room");
}
});
test("Ghoul Rush's Down the Hatch's intro banner says the controls plainly", () => {
assert.match(R.how, /UP jump/);
assert.match(R.how, /DOWN duck/);
assert.match(R.how, /SPACE shoot/);
assert.match(R.how, /throb/);
});
+49 -28
View File
@@ -12,6 +12,7 @@ import path from "node:path";
import { fileURLToPath } from "node:url";
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
import { skipStory as storySkip } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-story.js";
import { skipEnding } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-ending.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-rush/draw/ghoul-draw.js";
import { ACCENTS } from "../src/web-console/public/palette.js";
import { humNames, toneNames } from "../src/web-console/public/tones.js";
@@ -379,7 +380,7 @@ test("Ghoul Rush: shelves are one way (jumped up through from below, landed on f
const tops = r.spec.shelves.filter(([a, b]) => x >= a && x <= b).map(([, , y]) => y);
const want = Math.max(ground, ...tops);
if (want === -Infinity) continue;
Object.assign(r.you, { x, y: 40, vy: -ghoul.FALL_MAX, state: "air", shelf: -1, drop: -1, out: 0 });
Object.assign(r.you, { x, y: 48, vy: -ghoul.FALL_MAX, state: "air", shelf: -1, drop: -1, out: 0 });
for (let k = 0; k < 500 && r.you.state === "air"; k++) ghoul.moveYou(r, 4);
assert.equal(r.you.y, want, `${r.spec.id} at ${x.toFixed(1)}`);
}
@@ -1709,7 +1710,7 @@ test("Ghoul Rush: with the time bonus run out, a zombie shambles in from the edg
test("Ghoul Rush: each stage is three rooms and a boss's, every room in one stage but the hall, and roomFor builds a room deeper into a run quicker and tougher, its boss with more hp and points, each capped", () => {
assert.equal(ghoul.ROOMS[0].id, "hall", "every run starts in the hall");
assert.equal(ghoul.ROOMS[0].boss, null);
const placed = ghoul.STAGES.flatMap((st) => st.rooms);
const placed = ghoul.SELECTABLE.flatMap((st) => st.rooms);
assert.equal(new Set(placed).size, placed.length, "no room in two stages");
// Every room but the hall is in a stage; one in none is a room forgotten.
assert.deepEqual([...placed].sort(), ghoul.ROOMS.slice(1).map((r) => r.id).sort(), "every room but the hall in a stage");
@@ -1734,9 +1735,9 @@ test("Ghoul Rush: each stage is three rooms and a boss's, every room in one stag
const far = ghoul.roomFor("ballroom", 400);
assert.ok(far.pace <= 1.4 && far.every >= 0.55 && far.tough <= 2 && far.extra <= 2);
assert.equal(far.bossHp, ghoul.roomFor("ballroom", ghoul.BOSS_DEPTH_MAX).bossHp, "boss hp stops growing");
const r = ghoulRound("foyer", 3);
const r = ghoulRound("foyer", 2);
const z = put(r, "zombie", 80);
assert.equal(z.hp, ghoul.MONSTERS.zombie.hp + 1, "three stages in, zombies take a bolt more");
assert.equal(z.hp, ghoul.MONSTERS.zombie.hp + 1, "two stages in (four steps), zombies take a bolt more");
});
test("Ghoul Rush: out of the hall, and out of each boss's room, you pick the next stage from two not yet played; left and right move the pick, a press only takes one once the offer settles, and a stage never comes again", () => {
@@ -1774,7 +1775,7 @@ test("Ghoul Rush: out of the hall, and out of each boss's room, you pick the nex
through(r2);
assert.deepEqual(r2.cleared, [want]);
assert.equal(r2.stats.stages, 1);
assert.deepEqual(events(r2, "stageClear").map((e) => [e.stage, e.n, e.of]), [[want, 1, ghoul.STAGES.length]]);
assert.deepEqual(events(r2, "stageClear").map((e) => [e.stage, e.n, e.of]), [[want, 1, ghoul.RUN_STAGES]]);
assert.equal(r2.phase, "pick");
assert.ok(!r2.offer.includes(want), "a stage cleared is never offered again");
assert.deepEqual(ghoul.stagesLeft(r2).map((st) => st.id), ghoul.STAGES.filter((st) => st.id !== want).map((st) => st.id));
@@ -1791,19 +1792,28 @@ test("Ghoul Rush: out of the hall, and out of each boss's room, you pick the nex
assert.equal(seen.size, ghoul.STAGES.length, "the offer is shuffled: any stage can come first");
});
test("Ghoul Rush: clearing every stage wins the run, and its end says so", () => {
test("Ghoul Rush: clearing RUN_STAGES stages and then the finale's rooms wins the run, and its end says so", () => {
const round = ghoul.newRound(5);
round.dice = 0;
through(round);
while (!round.over) {
while (round.cleared.length < ghoul.RUN_STAGES) {
assert.equal(round.phase, "pick");
round.phaseMs = 0;
ghoul.pickStage(round);
for (let k = 0, n = ghoul.stageById(round.stage).rooms.length; k < n; k++) through(round);
}
assert.equal(round.stage, ghoul.FINALE.id, "on to the House, with no offer");
for (const id of ghoul.FINALE.rooms) {
assert.equal(round.over, false);
assert.equal(round.spec.id, id);
through(round);
}
assert.equal(round.phase, "ending", "the ending's pages first");
skipEnding(round);
assert.equal(round.won, true);
assert.equal(round.cleared.length, ghoul.STAGES.length);
assert.deepEqual(new Set(round.cleared), new Set(ghoul.STAGES.map((st) => st.id)), "each stage once");
assert.equal(round.cleared.length, ghoul.RUN_STAGES);
assert.equal(new Set(round.cleared).size, ghoul.RUN_STAGES, "each stage once");
assert.ok(!round.cleared.includes(ghoul.FINALE.id), "the finale is no stage cleared");
assert.equal(events(round, "won").length, 1);
assert.equal(ghoul.advance(round, 16, steady), "over");
});
@@ -2104,7 +2114,8 @@ test("Ghoul Rush: every room can be finished: a route from the start to the key
const start = surfaceAt(list, base.start, ghoul.groundAt(base, base.start));
const door = surfaceAt(list, base.door, ghoul.groundAt(base, base.door));
assert.ok(start && door, `${base.id}: start and door on the ground`);
assert.ok(base.door > base.length - 14, `${base.id}: the door at the room's end`);
// The House stands over its front door until it sinks; that door is the way on.
if (base.boss !== "marrow") assert.ok(base.door > base.length - 14, `${base.id}: the door at the room's end`);
let from = start;
if (base.key) {
const key = surfaceAt(list, base.key[0], base.key[1]);
@@ -2422,7 +2433,8 @@ test("Ghoul Rush: of ten runs a sharp bot gets nearly all through the hall and t
// 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`));
// The blaster went to 80% of its old rate (FIRE_MS 124), so the Gourd's fight runs about a quarter longer: 80 s.
per.forEach((p, i) => assert.ok(p.secs >= 10 && p.secs <= (i === 4 ? 80 : 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`);
@@ -2466,10 +2478,12 @@ function takeManor(g) {
}
// Past a stage's intro card the way a player does: the minimum wait, then fire.
// Past every card up (the finale's stage card leads straight into its boss's).
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");
for (let n = 0; n < 3 && (g.round.phase === "intro" || g.round.phase === "bossintro"); n++) {
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 50; ms += 16) g.tick(16);
g.key("action");
}
}
// Starts a game with nothing waking.
@@ -2570,7 +2584,7 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows
const scores = [];
const g = ghoul.default.create({ canvas, memo, onScore: (n) => scores.push(n) });
g.resize(900, 900);
assert.ok(texts.some(([t]) => t.includes(`Best: 0 of ${ghoul.STAGES.length} stages`)), "the start screen names the record");
assert.ok(texts.some(([t]) => t.includes(`Best: 0 of ${ghoul.RUN_STAGES} stages`)), "the start screen names the record");
g.key("action");
skipStory(g);
g.round.dice = 0;
@@ -2613,7 +2627,7 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows
assert.equal(g.round.phase, "pick");
texts.length = 0;
g.tick(16);
assert.ok(texts.some(([t]) => t === `STAGE 1 OF ${ghoul.STAGES.length} CLEARED`));
assert.ok(texts.some(([t]) => t === `STAGE 1 OF ${ghoul.RUN_STAGES} CLEARED`));
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");
@@ -2628,7 +2642,7 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows
texts.length = 0;
g.resize(900, 900);
assert.ok(texts.some(([t, font]) => t === String(g.score) && /\b7px/.test(font)), "the score, big");
assert.ok(texts.some(([t]) => t.startsWith(`Cleared 1 of ${ghoul.STAGES.length} stages, out in `) && t.includes("A new record!")), "how far, and the record");
assert.ok(texts.some(([t]) => t.startsWith(`Cleared 1 of ${ghoul.RUN_STAGES} stages, out in `) && t.includes("A new record!")), "how far, and the record");
const again = ghoul.default.create({ canvas, memo: { get: () => 9, set: () => assert.fail("never lowered") } });
again.resize(900, 900);
again.key("action");
@@ -2654,7 +2668,7 @@ test("Ghoul Rush game: stageSelect() (the window's stage code) opens a practice
for (let i = 0; i < 30; i++) g.tick(16);
assert.equal(r.phase, "select", "it waits on a choice");
assert.equal(r.clock, 0, "nothing moves");
const last = ghoul.STAGES.length - 1;
const last = ghoul.SELECTABLE.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 clamps inside the list; then steer on to the Manor, whose second
@@ -2664,7 +2678,7 @@ test("Ghoul Rush game: stageSelect() (the window's stage code) opens a practice
g.key("up");
assert.equal(r.select.at, last - 2);
const st = ghoul.STAGES[0];
for (let i = 0; i < ghoul.STAGES.length; i++) g.key("up");
for (let i = 0; i < ghoul.SELECTABLE.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");
@@ -2675,7 +2689,7 @@ test("Ghoul Rush game: stageSelect() (the window's stage code) opens a practice
assert.equal(r.stage, st.id);
assert.equal(r.stageAt, st.rooms.length - 2);
assert.equal(r.spec.id, st.rooms[st.rooms.length - 2], "straight into the room picked");
r.events.push({ type: "stageClear", stage: st.id, n: 3, of: ghoul.STAGES.length });
r.events.push({ type: "stageClear", stage: st.id, n: 3, of: ghoul.RUN_STAGES });
g.tick(16);
assert.equal(saved, 0, "a practice run never sets the record");
r.score = 5000;
@@ -2700,9 +2714,14 @@ test("Ghoul Rush game: a run that clears every stage ends in a win, with a fanfa
const r = g.round;
through(r);
while (!r.over) {
// The ending's pages once the House is dead.
if (r.phase === "ending") {
skipEnding(r);
continue;
}
r.phaseMs = 0;
ghoul.pickStage(r);
for (let k = 0; k < 4; k++) through(r);
for (let k = 0; k < 4 && r.phase !== "ending" && !r.over; k++) through(r);
}
g.tick(16);
assert.equal(g.state, "over");
@@ -3028,7 +3047,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", "~SPREAD", "~RAPID", "GARLIC"]) {
for (const want of ["THE LONG HALL", `STAGE 0 OF ${ghoul.RUN_STAGES}`, "♥", "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)})`);
@@ -3048,7 +3067,7 @@ test("Ghoul Rush: the top bar names the stage (or the hall) and counts the stage
g.tick(16);
const seen = pills();
const at = seen.findIndex((p) => p.text.startsWith("♥"));
assert.deepEqual(seen.slice(0, 2).map((p) => p.text), ["THE LONG HALL", `STAGE 0 OF ${ghoul.STAGES.length}`], "the hall, nothing cleared yet");
assert.deepEqual(seen.slice(0, 2).map((p) => p.text), ["THE LONG HALL", `STAGE 0 OF ${ghoul.RUN_STAGES}`], "the hall, nothing cleared yet");
assert.equal(at, 2, `right after the stage pills (${seen.map((p) => p.text)})`);
assert.equal(seen[at].text, livesText(g.round.lives));
assert.equal(seen[at].backing, LIVES_BACK);
@@ -3251,9 +3270,9 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug
g.resize(900, 900);
g.key("action");
skipStory(g);
// Every room a run can reach: the hall and each stage's, not the retired Bog Runner.
const LIVE = 1 + ghoul.STAGES.flatMap((st) => st.rooms).length;
for (let n = 1; n <= LIVE; n++) {
// Every room the run reaches: the hall, each of its RUN_STAGES stages' and the finale's.
for (let n = 1; g.state === "running"; n++) {
assert.ok(n < 80, "the run ends");
const r = g.round;
r.lives = 99;
const bot = makeBot(ghoul, 1, ghoul.seeded(n));
@@ -3266,7 +3285,8 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug
}
assert.ok(calls.count > drawn, `room ${n} draws`);
leaveIntro(g);
if (r.boss) r.boss.state = "down";
// A fallen boss, and the House gone from in front of its door.
if (r.boss) Object.assign(r.boss, { state: "down", gone: true });
r.hasKey = true;
// Through the door, once any life lost in the run is over with.
for (let ms = 0; ms < 8000 && g.round.room === n && g.state === "running"; ms += 16) {
@@ -3278,6 +3298,7 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug
r.ask.t = ghoul.ASK_GUARD_MS;
ghoul.answerDie(r, true);
}
if (r.phase === "ending") skipEnding(r);
if (r.phase === "pick") {
const before = calls.count;
g.tick(16);
@@ -3287,7 +3308,7 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug
}
g.tick(16);
}
if (n === LIVE) break;
if (g.state !== "running") break;
leaveIntro(g);
for (let ms = 0; ms < ghoul.READY_MS + 100; ms += 16) g.tick(16);
assert.equal(g.round.room, n + 1);
+2 -2
View File
@@ -2512,10 +2512,10 @@ test("Ghoul Rush plays in the real window: its board's shape and Planny big enou
}, 5000);
});
test("the server serves the activities' scripts, golf's seventeen, Light Trails, Bug Hunt, Sunset Drive, Stack Deploy, Bumper Ring's two, Rapids Run's two, Hot Potato's two, Crossing Rush's two, Bounce Road's seven, Ghoul Rush's eighty-three, every game's sound effects and the shared pills included", () => {
test("the server serves the activities' scripts, golf's seventeen, Light Trails, Bug Hunt, Sunset Drive, Stack Deploy, Bumper Ring's two, Rapids Run's two, Hot Potato's two, Crossing Rush's two, Bounce Road's seven, Ghoul Rush's ninety-five, every game's sound effects and the shared pills included", () => {
const server = fs.readFileSync(new URL("../src/web-console/static.mjs", import.meta.url), "utf8");
const servable = server.slice(server.indexOf("const SERVABLE = new Set(["), server.indexOf("]);", server.indexOf("const SERVABLE = new Set([")));
for (const file of ["activities.js", "tones.js", "music.js", "activities/snake.js", "screens/activities.js", "activities/golf.js", "activities/golf-holes.js", "activities/golf-draw.js", "activities/golf-decor.js", "activities/golf-kit.js", "activities/golf-paint.js", "activities/golf-looks.js", "activities/golf-course-pirate.js", "activities/golf-course-cave.js", "activities/golf-course-dino.js", "activities/golf-course-candy.js", "activities/golf-course-space.js", "activities/golf-course-frost.js", "activities/golf-look-dino.js", "activities/golf-look-candy.js", "activities/golf-look-space.js", "activities/golf-look-frost.js", "activities/trails.js", "activities/bugs.js", "activities/drive.js", "activities/stack.js", "activities/bumper.js", "activities/bumper-draw.js", "activities/rapids.js", "activities/rapids-draw.js", "activities/fuse.js", "activities/fuse-draw.js", "activities/hop.js", "activities/hop-draw.js", "activities/bounce.js", "activities/bounce-draw.js", "activities/bounce-roads.js", "activities/bounce-road.js", "activities/bounce-rivals.js", "activities/bounce-scenery.js", "activities/bounce-cars.js", "activities/ghoul-rush/ghoul.js", "activities/ghoul-rush/draw/ghoul-draw.js", "activities/ghoul-rush/core/ghoul-rooms.js", "activities/ghoul-rush/stages/wing/ghoul-bones.js", "activities/ghoul-rush/stages/wing/ghoul-bones-draw.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard-draw.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds-draw.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel-draw.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium-draw.js", "activities/ghoul-rush/stages/village/ghoul-village.js", "activities/ghoul-rush/stages/village/ghoul-village-draw.js", "activities/ghoul-rush/stages/village/ghoul-village-world.js", "activities/ghoul-rush/stages/village/ghoul-village-wolf.js", "activities/ghoul-rush/stages/mine/ghoul-mine.js", "activities/ghoul-rush/stages/mine/ghoul-mine-draw.js", "activities/ghoul-rush/stages/mine/ghoul-mine-world.js", "activities/ghoul-rush/stages/mine/ghoul-mine-tommy.js", "activities/ghoul-rush/rides/cart/ghoul-cart.js", "activities/ghoul-rush/rides/cart/ghoul-cart-draw.js", "activities/ghoul-rush/rides/sled/ghoul-sled.js", "activities/ghoul-rush/rides/sled/ghoul-sled-draw.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney-draw.js", "activities/ghoul-rush/rides/banister/ghoul-banister.js", "activities/ghoul-rush/rides/banister/ghoul-banister-draw.js", "activities/ghoul-rush/rides/banister/ghoul-sfx-banister.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse-draw.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew.js", "activities/ghoul-rush/rides/pew/ghoul-pew-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew-course.js", "activities/ghoul-rush/rides/pew/ghoul-pew-world.js", "activities/ghoul-rush/rides/mower/ghoul-mower.js", "activities/ghoul-rush/rides/mower/ghoul-mower-draw.js", "activities/ghoul-rush/rides/tray/ghoul-tray.js", "activities/ghoul-rush/rides/tray/ghoul-tray-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-world.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-draw.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-world.js", "activities/ghoul-rush/arms/ghoul-flare.js", "activities/ghoul-rush/stages/bog/ghoul-bog.js", "activities/ghoul-rush/stages/bog/ghoul-bog-draw.js", "activities/ghoul-rush/draw/ghoul-picker-draw.js", "activities/ghoul-rush/core/ghoul-powers.js", "activities/ghoul-rush/arms/ghoul-arms.js", "activities/ghoul-rush/arms/ghoul-arms-draw.js", "activities/ghoul-rush/arms/ghoul-rockets.js", "activities/ghoul-rush/arms/ghoul-rockets-draw.js", "activities/ghoul-rush/arms/ghoul-pans.js", "activities/ghoul-rush/arms/ghoul-sfx-arms.js", "activities/ghoul-rush/core/ghoul-run.js", "activities/ghoul-rush/core/ghoul-dice.js", "activities/ghoul-rush/core/ghoul-dice-draw.js", "activities/ghoul-rush/story/ghoul-gameover-draw.js", "activities/ghoul-rush/story/ghoul-intros.js", "activities/ghoul-rush/story/ghoul-intro-draw.js", "activities/ghoul-rush/story/ghoul-boss-intros.js", "activities/ghoul-rush/story/ghoul-bossintro-draw.js", "activities/ghoul-rush/story/ghoul-story.js", "activities/ghoul-rush/story/ghoul-story-draw.js", "activities/ghoul-rush/story/ghoul-sfx-story.js", "activities/ghoul-rush/core/ghoul-bonus.js", "activities/ghoul-rush/core/ghoul-bonus-drLine truncated
for (const file of ["activities.js", "tones.js", "music.js", "activities/snake.js", "screens/activities.js", "activities/golf.js", "activities/golf-holes.js", "activities/golf-draw.js", "activities/golf-decor.js", "activities/golf-kit.js", "activities/golf-paint.js", "activities/golf-looks.js", "activities/golf-course-pirate.js", "activities/golf-course-cave.js", "activities/golf-course-dino.js", "activities/golf-course-candy.js", "activities/golf-course-space.js", "activities/golf-course-frost.js", "activities/golf-look-dino.js", "activities/golf-look-candy.js", "activities/golf-look-space.js", "activities/golf-look-frost.js", "activities/trails.js", "activities/bugs.js", "activities/drive.js", "activities/stack.js", "activities/bumper.js", "activities/bumper-draw.js", "activities/rapids.js", "activities/rapids-draw.js", "activities/fuse.js", "activities/fuse-draw.js", "activities/hop.js", "activities/hop-draw.js", "activities/bounce.js", "activities/bounce-draw.js", "activities/bounce-roads.js", "activities/bounce-road.js", "activities/bounce-rivals.js", "activities/bounce-scenery.js", "activities/bounce-cars.js", "activities/ghoul-rush/ghoul.js", "activities/ghoul-rush/draw/ghoul-draw.js", "activities/ghoul-rush/core/ghoul-rooms.js", "activities/ghoul-rush/stages/wing/ghoul-bones.js", "activities/ghoul-rush/stages/wing/ghoul-bones-draw.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard-draw.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds-draw.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel-draw.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium-draw.js", "activities/ghoul-rush/stages/village/ghoul-village.js", "activities/ghoul-rush/stages/village/ghoul-village-draw.js", "activities/ghoul-rush/stages/village/ghoul-village-world.js", "activities/ghoul-rush/stages/village/ghoul-village-wolf.js", "activities/ghoul-rush/stages/mine/ghoul-mine.js", "activities/ghoul-rush/stages/mine/ghoul-mine-draw.js", "activities/ghoul-rush/stages/mine/ghoul-mine-world.js", "activities/ghoul-rush/stages/mine/ghoul-mine-tommy.js", "activities/ghoul-rush/rides/cart/ghoul-cart.js", "activities/ghoul-rush/rides/cart/ghoul-cart-draw.js", "activities/ghoul-rush/rides/sled/ghoul-sled.js", "activities/ghoul-rush/rides/sled/ghoul-sled-draw.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney-draw.js", "activities/ghoul-rush/rides/banister/ghoul-banister.js", "activities/ghoul-rush/rides/banister/ghoul-banister-draw.js", "activities/ghoul-rush/rides/banister/ghoul-sfx-banister.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse-draw.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew.js", "activities/ghoul-rush/rides/pew/ghoul-pew-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew-course.js", "activities/ghoul-rush/rides/pew/ghoul-pew-world.js", "activities/ghoul-rush/rides/mower/ghoul-mower.js", "activities/ghoul-rush/rides/mower/ghoul-mower-draw.js", "activities/ghoul-rush/rides/tray/ghoul-tray.js", "activities/ghoul-rush/rides/tray/ghoul-tray-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-world.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-draw.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-world.js", "activities/ghoul-rush/arms/ghoul-flare.js", "activities/ghoul-rush/stages/bog/ghoul-bog.js", "activities/ghoul-rush/stages/bog/ghoul-bog-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-draw.js", "activities/ghoul-rush/rides/mat/ghoul-mat-room.js", "activities/ghoul-rush/rides/mat/ghoul-mat.js", "activities/ghoul-rush/rides/mat/ghoul-mat-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-dollhouse-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-room.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-pit-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart-draw.js", "activities/ghoul-rush/story/ghoul-ending.js", "activities/ghoul-rush/story/ghoul-ending-draw.js", "activities/ghoul-rush/draw/ghoul-picker-draw.js", "activities/ghoul-rush/core/ghoLine truncated
assert.ok(servable.includes(`"${file}"`), `SERVABLE includes ${file}`);
}
});
@@ -55,9 +55,11 @@ export const BONUS_READY_MS = 2400;
// A ride room that plays on after a heart (the Runaway Cart) blinks Planny safe this long.
export const BONUS_SAFE_MS = 1800;
// A fresh bonus round, for a room just entered.
// A fresh bonus round, for a room just entered: BONUS_HEARTS, or the ride's own
// `hearts` (the finale's short rides have three).
export function makeBonus(round) {
return { hearts: BONUS_HEARTS, max: BONUS_HEARTS, dice: 0, over: false, won: false, cardMs: 0, perf: { total: 0, hits: [], acts: 0, goal: 8, steady: true, kills0: round.stats.kills } };
const n = round.spec?.ride?.hearts ?? BONUS_HEARTS;
return { hearts: n, max: n, dice: 0, over: false, won: false, cardMs: 0, perf: { total: 0, hits: [], acts: 0, goal: 8, steady: true, kills0: round.stats.kills } };
}
// The dice a finish is worth: BONUS_FLOOR, plus a share of the six more by
@@ -86,7 +88,7 @@ export function endBonus(round, won, kit) {
// A room that grades itself (the dark ride) sets `perf.dice` and `perf.cardMs`.
b.dice = b.perf.dice !== undefined ? b.perf.dice : diceFor(b, round.stats.kills);
const had = round.dice;
round.dice += b.dice;
round.dice = Math.min(kit.MAX_HELD_DICE ?? Infinity, round.dice + b.dice);
points = kit.ROOM_POINTS * round.room;
kit.award(round, points);
round.stats.rooms++;
@@ -158,7 +158,7 @@ export function rollDice(round, ms, random, kit) {
// On the last heart a 2, 3 or 4 does not save him: it pays one heart, and the
// loss then goes ahead, so he comes back with that heart the usual way.
if (r.heart) {
round.lives++;
round.lives = Math.min(kit.MAX_LIVES, round.lives + 1);
round.events.push({ type: "diceHeart", face: r.face, x: r.x, y: r.y });
round.roll = null;
kit.takeLife(round, r.cause);
@@ -4,7 +4,7 @@
import { BONUS_SAFE_MS } from "./ghoul-bonus.js";
import { answerAsk, beginRoll } from "./ghoul-dice.js";
import { ARM_DROP, POWERS, applyPower as applyPowerWith, armDrop, pickPower } from "./ghoul-powers.js";
import { ARM_DROP, MAX_HELD_DICE, MAX_LIVES, POWERS, applyPower as applyPowerWith, armDrop, pickPower } from "./ghoul-powers.js";
import { FIELD_W } from "./ghoul-rooms.js";
import { BOSS_MOVERS, HAZARDS, ON_KILL, nextSerial, spawnMonster, throwBone } from "./ghoul-monsters.js";
import { footing, groundAt, landing, leftEdge, rightEdge } from "./ghoul-planny.js";
@@ -136,13 +136,17 @@ export function moveBoss(round, ms, random) {
}
}
// Damage to the boss; at none it falls and the door opens.
export function hurtBoss(round, dmg, how) {
// Damage to the boss; at none it falls and the door opens. `at` ({ x, y }),
// when given, is where the hit and the fall show (a boss hurt only through
// a part of its art, as the House is through its windows).
export function hurtBoss(round, dmg, how, at = null) {
const b = round.boss;
if (!b || b.state !== "fight") return false;
b.hp = Math.max(0, b.hp - dmg);
b.hurt = 120;
round.events.push({ type: "bossHit", kind: b.kind, x: b.x, y: b.y + b.h / 2, how, weak: how === "weak" });
const x = at ? at.x : b.x;
const y = at ? at.y : b.y + b.h / 2;
round.events.push({ type: "bossHit", kind: b.kind, x, y, how, weak: how === "weak" });
if (b.hp > 0) return true;
b.state = "down";
b.t = 0;
@@ -150,15 +154,16 @@ export function hurtBoss(round, dmg, how) {
award(round, points);
round.stats.bosses++;
round.hasKey = true;
const life = true;
round.lives++;
// A boss always gives a life, up to MAX_LIVES.
const life = round.lives < MAX_LIVES;
if (life) round.lives++;
for (const m of round.monsters) round.events.push({ type: "poof", kind: m.kind, x: m.x, y: m.y + m.h / 2 });
round.monsters.length = 0;
round.bones.length = 0;
round.waves.length = 0;
round.puddles.length = 0;
round.hazards.length = 0;
round.events.push({ type: "bossDown", kind: b.kind, x: b.x, y: b.y + b.h / 2, points, life });
round.events.push({ type: "bossDown", kind: b.kind, x, y, points, life });
return true;
}
@@ -274,7 +279,7 @@ export function struck(round, cause, m = null) {
// handed to a stage pack.
export const POWER_KIT = Object.freeze({ footing, leftEdge, rightEdge, seeded, landing, GRAVITY, FALL_MAX, PIT_Y, HIT_W, HIT_H });
// And what ghoul-dice.js needs.
export const DICE_KIT = Object.freeze({ SAFE_MS, PIT_Y, FIELD_W, footing, groundAt, leftEdge, rightEdge, takeLife, kill, give: (round, kind) => applyPowerWith(round, kind, POWER_KIT) });
export const DICE_KIT = Object.freeze({ MAX_LIVES, SAFE_MS, PIT_Y, FIELD_W, footing, groundAt, leftEdge, rightEdge, takeLife, kill, give: (round, kind) => applyPowerWith(round, kind, POWER_KIT) });
export const applyPower = (round, kind) => applyPowerWith(round, kind, POWER_KIT);
@@ -6,10 +6,11 @@ import { armBossDamage, fillBag } from "../arms/ghoul-arms.js";
import { bossIntroFor } from "../story/ghoul-boss-intros.js";
import { introFor } from "../story/ghoul-intros.js";
import { stepStory } from "../story/ghoul-story.js";
import { beginEnding, stepEnding } from "../story/ghoul-ending.js";
import { BONUS_READY_MS, endBonus as endBonusWith, makeBonus } from "./ghoul-bonus.js";
import { START_DICE, askStep, giveDiceGift, markRest, reviveSpot, rollDice } from "./ghoul-dice.js";
import { FLAP_CLEAR, TIMED, pickPower, pickups, powerHere, retryMercy } from "./ghoul-powers.js";
import { CHANDELIER_Y, FIELD_H, FIELD_W, ROOMS, STAGES, stageById } from "./ghoul-rooms.js";
import { FLAP_CLEAR, MAX_HELD_DICE, TIMED, pickPower, pickups, powerHere, retryMercy } from "./ghoul-powers.js";
import { CHANDELIER_Y, FIELD_H, FIELD_W, FINALE, ROOMS, RUN_STAGES, SELECTABLE, STAGES, stageById } from "./ghoul-rooms.js";
import { camera as cameraWith, clearRoom as clearRoomWith, horde as hordeWith, hurry as hurryWith, lockArena, newRound as newRoundWith, nextRoom as nextRoomWith, onCard, pickStage as pickStageWith, respawn as respawnWith, setupRoom as setupRoomWith, spawners as spawnersWith, stagesLeft as stagesLeftWith, steerSelect as steerSelectWith, stepIntro as stepIntroWith, takeIntro as takeIntroWith, takeSelect as takeSelectWith } from "./ghoul-run.js";
import { pressFire as pressFireWith } from "../arms/ghoul-arms.js";
import { KIT } from "./ghoul-kit.js";
@@ -27,10 +28,10 @@ export const pressFire = (round) => pressFireWith(round, KIT);
// and the helpers that set a room up, handed to its rules the way KIT is
// handed to a stage pack.
const RUN_KIT = Object.freeze({
ROOMS, STAGES, stageById, FIELD_W, CHANDELIER_Y, START_LIVES, START_DICE, TIMED, DARK_CHANCE, BONUS_START, HURRY_MS, OFFER_N, PICK_HOLD_MS,
READY_MS, BONUS_READY_MS, makeBonus, endBonus: (round, won) => endBonusWith(round, won, { award, ROOM_POINTS }), SAFE_MS, CLEAR_MS, BOSS_LOCK, ROOM_POINTS, FLAWLESS_POINTS, CAM_AT, CAM_LEAD, CAM_EASE,
ROOMS, STAGES, SELECTABLE, FINALE, RUN_STAGES, stageById, FIELD_W, CHANDELIER_Y, START_LIVES, START_DICE, TIMED, DARK_CHANCE, BONUS_START, HURRY_MS, OFFER_N, PICK_HOLD_MS,
READY_MS, BONUS_READY_MS, makeBonus, endBonus: (round, won) => endBonusWith(round, won, { award, ROOM_POINTS, MAX_HELD_DICE }), SAFE_MS, CLEAR_MS, BOSS_LOCK, ROOM_POINTS, FLAWLESS_POINTS, CAM_AT, CAM_LEAD, CAM_EASE,
SPAWN_AHEAD, DOOR_CLEAR, EMERGE_MS, CRAWL_NEAR, SPIDER_Y, GHOST_SHOW_MS, GHOST_HIDE_MS, DARK_BEHIND, MAX_MONSTERS, HORDE_ROOM, HORDE_WITH, MONSTERS,
roomFor, seeded, powerHere, pickPower, makeYou, makeBoss, groundAt, timeFor, award, clamp, variant, spawnMonster, introFor, bossIntroFor,
roomFor, seeded, powerHere, pickPower, makeYou, makeBoss, groundAt, timeFor, award, clamp, variant, spawnMonster, introFor, bossIntroFor, beginEnding,
mercy: (round) => retryMercy(round, POWER_KIT),
diceGift: (round) => giveDiceGift(round, DICE_KIT.give),
place: (round) => PLACES.forEach((f) => f(round, KIT)),
@@ -88,7 +89,8 @@ export function aimAt(round) {
export function fire(round, ms) {
round.fireMs = Math.max(0, round.fireMs - ms);
const you = round.you;
if (!round.input.fire || you.out > 0 || round.gallery || (round.runner && round.runner.id === "lantern")) {
// The Heart's HOLD FIRE (`round.flood`): fire held floods YOUR light instead of firing (its pack reads the key).
if (!round.input.fire || you.out > 0 || round.gallery || (round.runner && round.runner.id === "lantern") || round.flood) {
round.coolMs += ms;
const cooling = Math.min(ms, round.coolMs - COOL_DELAY_MS);
if (cooling > 0) round.heat = Math.max(0, round.heat - (COOL_RATE * cooling) / 1000);
@@ -477,7 +479,7 @@ function play(round, ms, random) {
}
// What a stage pack's rules may use of this file's.
Object.assign(KIT, { BOSSES, shotY, aimAt, dropItem, guarded, weakOf: (b, s, round) => (WEAK[b.kind] ? WEAK[b.kind](b, s, round, KIT) : 1), stone: (m) => Boolean(STONE[m.kind]?.(m)), strike: (round, s) => TARGETS.some((f) => f(round, s, KIT)), harmlessNow: (m) => Boolean(HARMLESS[m.kind]?.(m)), walk, towardYou, throwBone, spawnMonster, groundAt, footing, struck, hurt, hurtBoss, fling, arenaMin, arenaMax, solid, FIELD_W, CHANDELIER_Y, SHOT_Y, YOU_H, HIT_W, HIT_H, GRAVITY, FALL_MAX, PIT_Y, BONE_G, DUCK_H, lose });
Object.assign(KIT, { BOSSES, shotY, aimAt, dropItem, guarded, weakOf: (b, s, round) => (WEAK[b.kind] ? WEAK[b.kind](b, s, round, KIT) : 1), stone: (m) => Boolean(STONE[m.kind]?.(m)), strike: (round, s) => TARGETS.some((f) => f(round, s, KIT)), harmlessNow: (m) => Boolean(HARMLESS[m.kind]?.(m)), walk, towardYou, throwBone, spawnMonster, groundAt, footing, struck, hurt, hurtBoss, STAGES, stageById, armBossDamage: (round, d) => armBossDamage(round, d, KIT), fling, arenaMin, arenaMax, solid, FIELD_W, CHANDELIER_Y, SHOT_Y, YOU_H, HIT_W, HIT_H, GRAVITY, FALL_MAX, PIT_Y, BONE_G, DUCK_H, lose });
Object.freeze(KIT);
// Throws Planny: up at `v` and `dx` units across (signed) by the time he is
@@ -563,6 +565,11 @@ export function advance(round, ms, random = Math.random) {
stepStory(round, slice);
continue;
}
// The ending, once the House is dead: only its pages move (story/ghoul-ending.js).
if (round.phase === "ending") {
stepEnding(round, slice);
continue;
}
round.clock += slice;
// Asking whether to use a Lucky die for a life: nothing else moves.
if (round.phase === "ask") {
@@ -6,6 +6,10 @@
// re-exports what it always exported from here (POWERS, TIMED, powerHere,
// applyPower and the numbers), so its importers need not know.
// The most lives and Lucky dice YOU can hold: past them a 1UP or a die pays points instead.
export const MAX_LIVES = 13;
export const MAX_HELD_DICE = 13;
// Power-ups: Spread shot, Rapid fire, the Lantern (the dark pulled back far
// around you, so only ever found in a dark room), Bat wings (one more jump in the air, a flap, each time you
// leave the ground, and a fall down a pit carries you back and spends them: wingSave in ghoul.js) and the Church bell (every monster but a boss stands
@@ -154,10 +158,13 @@ export function applyPower(round, kind, kit) {
if (round.timeMs > 0) round.timeMs += HOURGLASS_MS;
else award(round, POWER_POINTS);
}
// A 1UP or a Lucky die at its cap (MAX_LIVES, MAX_HELD_DICE) pays points instead.
else if (kind === "life") {
round.lives++;
if (round.lives >= MAX_LIVES) award(round, POWER_POINTS);
else round.lives++;
} else if (kind === "die") {
round.dice++;
if (round.dice >= MAX_HELD_DICE) award(round, POWER_POINTS);
else round.dice++;
} else if (POWERS[kind].arm && !addArm(round, kind)) award(round, POWER_POINTS);
}
@@ -1,9 +1,19 @@
// Plan2Code Web Console - Ghoul Rush's rooms as data: the long hall every run starts in, then each stage's rooms (three, then a boss's), side on, left to right, with their floors, pits, shelves, candy, power-ups, monsters, key and door, and the stages themselves.
//
// Data only, no imports: ghoul.js builds each room's numbers from these, and
// Data only, no imports but the finale's room files (data too, one per piece,
// each in only once `ready`): ghoul.js builds each room's numbers from these, and
// the unit suite walks every layout to prove it can be finished (a route from
// the start to the key and on to the door, no jump wider than a jump clears).
//
import { MAT_ROOM } from "../rides/mat/ghoul-mat-room.js";
import { DOLLHOUSE_ROOM } from "../stages/marrow/ghoul-dollhouse-room.js";
import { BONESTAIR_ROOM } from "../rides/bonestair/ghoul-bonestair-room.js";
import { PIT_ROOM } from "../stages/marrow/ghoul-pit-room.js";
// The finale's rooms after the lawn, in the order they are played: each one in once its builder marks it ready.
const FINALE_PARTS = [MAT_ROOM, DOLLHOUSE_ROOM, BONESTAIR_ROOM, PIT_ROOM].filter((r) => r.ready);
// Units: the field is FIELD_W across and FIELD_H tall on screen, y counted up
// from the bottom. A room is `length` units long and the camera scrolls along
// it. Every room is laid out on the same plan:
@@ -1547,6 +1557,24 @@ export const ROOMS = freeze([
spawns: [["zombie", 44], ["crawl", 96]],
boss: "motherbog",
}),
// The Front Lawn, the finale's first kill: a storm on the hill, the manor
// on the right of the arena as a face (ghoul-marrow.js), a dead oak whose
// branches step up to each row of its windows. Always lit by the storm.
room("lawn", "The Front Lawn", "It has been waiting to see YOU out", {
length: 210,
ground: [[0, 210, 6]],
// The oak's branches, stepping up to each row of windows.
shelves: [[122, 136, 12], [150, 164, 12], [134, 150, 18], [120, 134, 24], [152, 166, 24], [136, 150, 30], [154, 168, 41]],
key: null,
door: 192,
dark: false,
candy: [[20, 8.5, 5], [60, 8.5, 5]],
items: [["garlic", 40, 6], ["stake", 80, 6]],
spawns: [["zombie", 34], ["crawl", 56], ["ghost", 74, 12], ["zombie", 92]],
boss: "marrow",
}),
// The rest of the finale, each piece's room in its own file, in once it is `ready`.
...FINALE_PARTS.map((r) => room(r.id, r.title, r.sub, r.spec)),
]);
const ROOM_IDS = new Set(ROOMS.map((r) => r.id));
@@ -1554,8 +1582,9 @@ export const roomById = (id) => ROOMS.find((r) => r.id === id) || null;
// The stages: three rooms and a boss's, in order. Every run starts in the
// hall, then you pick each next stage from two (one, once a single stage is
// left) not yet played that run; clearing every stage wins. `rooms` are ids
// in ROOMS, the last one the boss's.
// left) not yet played that run; RUN_STAGES of them cleared, the run goes on
// to the FINALE, and clearing that wins. `rooms` are ids in ROOMS, the last
// one the boss's.
function stage(id, title, sub, rooms) {
for (const r of rooms) if (!ROOM_IDS.has(r)) throw new Error(`stage ${id}: no room ${r}`);
return freeze({ id, title, sub, rooms: freeze(rooms), boss: roomById(rooms[rooms.length - 1]).boss });
@@ -1574,4 +1603,10 @@ export const STAGES = freeze([
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", "lantern", "drowning"]),
]);
export const stageById = (id) => STAGES.find((s) => s.id === id) || null;
// A run is the hall, this many stages, then the finale, however many stages exist.
export const RUN_STAGES = 6;
// The House itself, never offered by the pick: its rooms grow as each kill lands.
export const FINALE = stage("marrow", "Marrow Manor", "It knows you are home", ["lawn", ...FINALE_PARTS.map((r) => r.id)]);
// Everything the stage select offers: the stages and the finale.
export const SELECTABLE = freeze([...STAGES, FINALE]);
export const stageById = (id) => SELECTABLE.find((s) => s.id === id) || null;
@@ -74,6 +74,8 @@ export function setupRoom(round, id, kit) {
// Retry mercy counts the restarts of this room (ghoul-powers.js).
round.retries = { room: round.room, n: 0 };
round.clock = 0;
// The Heart's HOLD FIRE is off until its pack says (ghoul-marrow-heart.js).
round.flood = false;
// A bonus room plays for hearts of its own (ghoul-bonus.js).
round.bonusRound = spec.bonus ? kit.makeBonus(round) : null;
kit.place(round);
@@ -143,9 +145,10 @@ export function newRound(seed, kit) {
export const stagesLeft = (round, kit) => kit.STAGES.filter((st) => !round.cleared.includes(st.id) && st.id !== round.stage);
// Out of a room: the stage's next room, or, out of the hall or a boss's,
// the choice of what comes next (or the win, with every stage cleared).
// the choice of what comes next; RUN_STAGES cleared (or none left to offer),
// the finale; out of the finale's last room, the win.
export function nextRoom(round, random, kit) {
const { STAGES, OFFER_N, PICK_HOLD_MS, stageById } = kit;
const { OFFER_N, PICK_HOLD_MS, RUN_STAGES, FINALE, stageById } = kit;
const st = round.stage ? stageById(round.stage) : null;
if (st && round.stageAt < st.rooms.length - 1) {
round.stageAt++;
@@ -153,18 +156,18 @@ export function nextRoom(round, random, kit) {
return;
}
if (st) {
// The finale's end is the run's end, not one more stage cleared.
if (st.id === FINALE.id) {
round.stage = null;
return finish(round, kit);
}
round.cleared.push(st.id);
round.stats.stages++;
round.stage = null;
round.events.push({ type: "stageClear", stage: st.id, n: round.cleared.length, of: STAGES.length });
round.events.push({ type: "stageClear", stage: st.id, n: round.cleared.length, of: RUN_STAGES });
}
const left = stagesLeft(round, kit);
if (!left.length) {
round.won = true;
round.over = true;
round.events.push({ type: "won", stages: round.cleared.length });
return;
}
if (round.cleared.length >= RUN_STAGES || !left.length) return enterFinale(round, kit);
const pool = left.slice();
const offer = [];
while (offer.length < OFFER_N && pool.length) offer.push(pool.splice(Math.floor(random() * pool.length) % pool.length, 1)[0].id);
@@ -176,6 +179,29 @@ export function nextRoom(round, random, kit) {
round.events.push({ type: "offer", offer: offer.slice() });
}
// Into the House itself, the way a picked stage is entered but never offered:
// its card, then its first room.
function enterFinale(round, kit) {
const { FINALE, RUN_STAGES } = kit;
round.offer = null;
round.stage = FINALE.id;
round.stageAt = 0;
round.events.push({ type: "stage", stage: FINALE.id, n: RUN_STAGES, of: RUN_STAGES });
enter(round, FINALE.rooms[0], kit);
startIntro(round, kit);
}
// The House killed for good: the run is won. `n` is the record it sets: one
// past every stage, which the memo reads as the House beaten.
function finish(round, kit) {
round.winN = kit.RUN_STAGES + 1;
// The ending's pages first, when there are any (story/ghoul-ending.js); they win the run at their end.
if (kit.beginEnding(round)) return;
round.won = true;
round.over = true;
round.events.push({ type: "won", stages: round.cleared.length, n: round.winN });
}
// 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
@@ -230,6 +256,11 @@ export function stepIntro(round, 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;
// A stage that opens on its boss's room (the finale) shows the boss's card after its own.
if (round.phase === "intro" && round.spec && round.spec.boss) {
startBossIntro(round, kit);
if (round.phase === "bossintro") return true;
}
endIntro(round, kit);
return true;
}
@@ -259,7 +290,7 @@ export function steerPick(round, dir) {
// its first room. Not while the offer is still settling (PICK_HOLD_MS), so a
// fire key still held from the fight never chooses blind.
export function pickStage(round, i = round.pick, kit) {
const { STAGES, stageById } = kit;
const { RUN_STAGES, stageById } = kit;
if (round.phase !== "pick" || !round.offer || round.phaseMs > 0) return false;
const id = round.offer[i];
const st = id && stageById(id);
@@ -267,7 +298,7 @@ export function pickStage(round, i = round.pick, kit) {
round.offer = null;
round.stage = st.id;
round.stageAt = 0;
round.events.push({ type: "stage", stage: st.id, n: round.cleared.length + 1, of: STAGES.length });
round.events.push({ type: "stage", stage: st.id, n: round.cleared.length + 1, of: RUN_STAGES });
enter(round, st.rooms[0], kit);
startIntro(round, kit);
return true;
@@ -288,8 +319,8 @@ export function openSelect(round) {
export function steerSelect(round, dStage, dRoom, kit) {
const sel = round.select;
if (round.phase !== "select" || !sel) return false;
const at = Math.max(0, Math.min(kit.STAGES.length - 1, sel.at + Math.sign(dStage)));
const rooms = kit.STAGES[at].rooms.length;
const at = Math.max(0, Math.min(kit.SELECTABLE.length - 1, sel.at + Math.sign(dStage)));
const rooms = kit.SELECTABLE[at].rooms.length;
const room = Math.max(0, Math.min(rooms - 1, (at === sel.at ? sel.room : Math.min(sel.room, rooms - 1)) + Math.sign(dRoom)));
if (at === sel.at && room === sel.room) return false;
sel.at = at;
@@ -303,11 +334,11 @@ export function steerSelect(round, dStage, dRoom, kit) {
export function takeSelect(round, kit) {
const sel = round.select;
if (round.phase !== "select" || !sel) return false;
const st = kit.STAGES[sel.at];
const st = kit.SELECTABLE[sel.at];
round.select = null;
round.stage = st.id;
round.stageAt = sel.room;
round.events.push({ type: "stage", stage: st.id, n: 1, of: kit.STAGES.length });
round.events.push({ type: "stage", stage: st.id, n: 1, of: kit.RUN_STAGES });
enter(round, st.rooms[sel.room], kit);
if (!sel.room) startIntro(round, kit);
return true;
@@ -23,13 +23,19 @@ import { GROUNDS } from "../stages/grounds/ghoul-grounds.js";
import { MINE } from "../stages/mine/ghoul-mine.js";
import { SANATORIUM } from "../stages/sanatorium/ghoul-sanatorium.js";
import { VILLAGE } from "../stages/village/ghoul-village.js";
import { MARROW } from "../stages/marrow/ghoul-marrow.js";
import { EYE } from "../stages/marrow/ghoul-marrow-eye.js";
import { HEART } from "../stages/marrow/ghoul-marrow-heart.js";
import { MAT } from "../rides/mat/ghoul-mat.js";
import { BONESTAIR } from "../rides/bonestair/ghoul-bonestair.js";
import { BONES } from "../stages/wing/ghoul-bones.js";
import { FLAP_CLEAR, POWERS, TIMED, powerHere } from "./ghoul-powers.js";
import { CEILING_Y, FIELD_H, FIELD_W, FLOOR_Y, ROOMS, STAGES, roomById, stageById } from "./ghoul-rooms.js";
import { CEILING_Y, FIELD_H, FIELD_W, FINALE, FLOOR_Y, ROOMS, RUN_STAGES, SELECTABLE, STAGES, roomById, stageById } from "./ghoul-rooms.js";
import { steerPick } from "./ghoul-run.js";
export { FIELD_H, FIELD_W, FLOOR_Y, ROOMS, STAGES, roomById, stageById };
export { FIELD_H, FIELD_W, FINALE, FLOOR_Y, ROOMS, RUN_STAGES, SELECTABLE, STAGES, roomById, stageById };
export { FLAP_CLEAR, POWERS, TIMED, powerHere };
export { MAX_HELD_DICE, MAX_LIVES } from "./ghoul-powers.js";
export { INTRO_MIN_MS } from "./ghoul-run.js";
export { releaseFire };
// The stage pick, which moved to ghoul-run.js.
@@ -127,8 +133,10 @@ export const SLICE_MS = 4;
// with Rapid fire), flying SHOT_SPEED level with Planny's chest (SHOT_Y over
// his feet) until it hits something, a wall, or has gone SHOT_RANGE. Spread
// shot adds two more, SPREAD_ANGLE up and down.
export const FIRE_MS = 100;
export const RAPID_MS = 60;
// The blaster at its quickest: a bolt every FIRE_MS (about 80% of the old 100 ms rate; a whole number of
// 4 ms slices, so the rate is exact); Rapid fire keeps about 1.65 times that.
export const FIRE_MS = 124;
export const RAPID_MS = 76;
export const SHOT_SPEED = 130;
export const SHOT_RANGE = 80;
export const SHOT_Y = 2.4;
@@ -175,7 +183,7 @@ export const AIM_MAX = 0.5;
// The stage packs: each stage past the house's own two brings its monsters,
// its boss and their rules (see ghoul-graveyard.js for what a pack holds).
// Their tables join this file's own, and their rules run where its own do.
const PACKS = Object.freeze([BONES, GRAVEYARD, GROUNDS, CHAPEL, SANATORIUM, VILLAGE, MINE, ARMS, CART, SLED, GURNEY, PEW, MOWER, WAGON, HEARSE, TRAY, CARNIVAL, FROZEN_LAKE, BOG, LANTERN, RIDE, BANISTER]);
const PACKS = Object.freeze([BONES, GRAVEYARD, GROUNDS, CHAPEL, SANATORIUM, VILLAGE, MINE, ARMS, CART, SLED, GURNEY, PEW, MOWER, WAGON, HEARSE, TRAY, CARNIVAL, FROZEN_LAKE, BOG, LANTERN, RIDE, MARROW, EYE, HEART, MAT, BONESTAIR, BANISTER]);
export const fromPacks = (key) => Object.assign({}, ...PACKS.map((pk) => pk[key] || {}));
export const listPacks = (key) => PACKS.flatMap((pk) => pk[key] || []);
@@ -304,8 +312,8 @@ export const HORDE_ROOM = 4;
// The bosses, in a room's last FIELD_W. The arena locks once you are
// BOSS_LOCK into it, and the boss wakes after BOSS_INTRO_MS. Its hp grows
// BOSS_DEPTH_HP for each stage already cleared that run (up to
// BOSS_DEPTH_MAX of them); a stomp deals STOMP_DAMAGE, a shot one (two to
// BOSS_DEPTH_HP for each step of depth (two a stage already cleared that run,
// up to BOSS_DEPTH_MAX steps); a stomp deals STOMP_DAMAGE, a shot one (two to
// Rattlebones' skull).
export const BOSSES = Object.freeze({
gourd: Object.freeze({ name: "The Rotting Gourd", sub: "Watch its shadow, then run", w: 14, h: 12, hp: 65, points: 2000, color: "#d0631c" }),
@@ -315,7 +323,7 @@ export const BOSS_LOCK = 10;
export const BOSS_INTRO_MS = 1000;
export const BOSS_DEPTH_HP = 0.12;
export const BOSS_DEPTH_MAX = 12;
// Each stage cleared makes the monsters a little quicker and lets them out a
// Each step of depth makes the monsters a little quicker and lets them out a
// little sooner (see roomFor).
export const DEPTH_PACE = 0.03;
export const DEPTH_EVERY = 0.95;
@@ -528,6 +536,8 @@ export function roomFor(id, depth = 0) {
const d = Math.max(0, Math.floor(depth) || 0);
const k = `${base.id}:${d}`;
if (BUILT.has(k)) return BUILT.get(k);
// A run is RUN_STAGES stages now: each counts for two of the old ones.
const steps = d * 2;
const candy = [];
for (const [x0, y, count] of base.candy) for (let i = 0; i < count; i++) candy.push(Object.freeze({ x: x0 + i * 3, y }));
const spec = Object.freeze({
@@ -535,13 +545,13 @@ export function roomFor(id, depth = 0) {
depth: d,
base,
name: base.title,
pace: Math.min(1.4, 1 + DEPTH_PACE * d),
every: Math.max(0.55, DEPTH_EVERY ** d),
tough: Math.min(2, Math.floor(d / 3)),
pace: Math.min(1.4, 1 + DEPTH_PACE * steps),
every: Math.max(0.55, DEPTH_EVERY ** steps),
tough: Math.min(2, Math.floor(steps / 3)),
// Doors in the wall let this many more out.
extra: Math.min(2, Math.floor(d / 2)),
bossHp: base.boss ? Math.round(BOSSES[base.boss].hp * (1 + BOSS_DEPTH_HP * Math.min(d, BOSS_DEPTH_MAX))) : 0,
bossPoints: base.boss ? Math.round(BOSSES[base.boss].points * (1 + d / 4)) : 0,
extra: Math.min(2, Math.floor(steps / 2)),
bossHp: base.boss ? Math.round(BOSSES[base.boss].hp * (1 + BOSS_DEPTH_HP * Math.min(steps, BOSS_DEPTH_MAX))) : 0,
bossPoints: base.boss ? Math.round(BOSSES[base.boss].points * (1 + steps / 4)) : 0,
candyAt: Object.freeze(candy),
arena: base.boss ? base.length - FIELD_W : -1,
});
@@ -8,10 +8,11 @@ import { isWaiting, startRide } from "../rides/dark-ride/ghoul-ride.js";
import { lanternHums } from "../rides/lantern/ghoul-lantern.js";
import { BONES_WINDUP_MS } from "../stages/wing/ghoul-bones.js";
import { beginStory, pressStory, releaseStory, takeStory } from "../story/ghoul-story.js";
import { ENDING_TRACK, pressEnding, releaseEnding, takeEnding } from "../story/ghoul-ending.js";
import { heartsText } from "./ghoul-bonus.js";
import { answerAsk, steerAsk } from "./ghoul-dice.js";
import { ARM_POP_MS, PILL_WORDS, POWERS, TIMED } from "./ghoul-powers.js";
import { CEILING_Y, FIELD_H, FIELD_W, STAGES, roomById, stageById } from "./ghoul-rooms.js";
import { CEILING_Y, FIELD_H, FIELD_W, FINALE, RUN_STAGES, SELECTABLE, roomById, stageById } from "./ghoul-rooms.js";
import { onCard, openSelect, steerPick } from "./ghoul-run.js";
import { DICE_KIT } from "./ghoul-fight.js";
import { POINTERS, ghostSight, solid } from "./ghoul-monsters.js";
@@ -46,8 +47,9 @@ export function lightning(left) {
// The end screen's nudge to play again, by the most stages ever cleared.
function teaser(most) {
if (most < STAGES.length) return `Best: ${most} of ${STAGES.length} stages. Clear them all to escape.`;
return "You have escaped the house before. Can you do it again?";
if (most < RUN_STAGES) return `Best: ${most} of ${RUN_STAGES} stages. Then the House.`;
if (most === RUN_STAGES) return "Best: every stage. The House still stands.";
return "You have killed the House before. Can you do it again?";
}
// The held sounds under play (no drone under the house: every room has its
@@ -66,13 +68,17 @@ const HEART_NEAR = 16;
// layers (its melody and drums included), the clock's last seconds add
// DREAD_CLOCK, and a boss fight plays all of it. The level eases toward its
// target over about DREAD_EASE_MS, so a change never lands as a jolt.
export const ROOM_MUSIC = Object.freeze({ banister: "ghoulBanister", hall: "ghoulHall", darkride: "ghoulRideTheme", lychgate: "ghoulLychgate", graves: "ghoulGraves", mausoleums: "ghoulMausoleums", angel: "ghoulAngel", maze: "ghoulMaze", topiary: "ghoulTopiary", gazebo: "ghoulGazebo", yard: "ghoulYard", nave: "ghoulNave", tower: "ghoulTower", loft: "ghoulLoft", choir: "ghoulChoir", shaft: "ghoulShaft", tunnels: "ghoulTunnels", collapse: "ghoulCollapse", seam: "ghoulSeam", cart: "ghoulCart", midway: "ghoulMidway", mirrors: "ghoulMirrors", funhouse: "ghoulFunhouse", bigtop: "ghoulBigTop", admissions: "ghoulAdmissions", baths: "ghoulBaths", theater: "ghoulTheater", ward: "ghoulWard", street: "ghoulStreet", inn: "ghoulInn", square: "ghoulSquare", green: "ghoulGreen", foyer: "ghoulFoyer", gallery: "ghoulGallery", library: "ghoulLibrary", ballroom: "ghoulBallroom", kitchen: "ghoulKitchen", conservatory: "ghoulConservatory", attic: "ghoulAttic", crypt: "ghoulCrypt", huts: "ghoulHuts", lodge: "ghoulLodge", blackice: "ghoulBlackIce", sled: "ghoulSledRide", codeblue: "ghoulBlueRide", pew: "ghoulPewDirge", mower: "ghoulMowerRide", wagon: "ghoulWagonRide", hearse: "ghoulHearseRide", tray: "ghoulTrayRide", widow: "ghoulWidow", boardwalk: "ghoulBoardwalk", hollow: "ghoulHollow", stilts: "ghoulStilts", lantern: "ghoulLanternTheme", drowning: "ghoulDrowning" });
export const ROOM_MUSIC = Object.freeze({ banister: "ghoulBanister", hall: "ghoulHall", darkride: "ghoulRideTheme", lychgate: "ghoulLychgate", graves: "ghoulGraves", mausoleums: "ghoulMausoleums", angel: "ghoulAngel", maze: "ghoulMaze", topiary: "ghoulTopiary", gazebo: "ghoulGazebo", yard: "ghoulYard", nave: "ghoulNave", tower: "ghoulTower", loft: "ghoulLoft", choir: "ghoulChoir", shaft: "ghoulShaft", tunnels: "ghoulTunnels", collapse: "ghoulCollapse", seam: "ghoulSeam", cart: "ghoulCart", midway: "ghoulMidway", mirrors: "ghoulMirrors", funhouse: "ghoulFunhouse", bigtop: "ghoulBigTop", admissions: "ghoulAdmissions", baths: "ghoulBaths", theater: "ghoulTheater", ward: "ghoulWard", street: "ghoulStreet", inn: "ghoulInn", square: "ghoulSquare", green: "ghoulGreen", foyer: "ghoulFoyer", gallery: "ghoulGallery", library: "ghoulLibrary", ballroom: "ghoulBallroom", kitchen: "ghoulKitchen", conservatory: "ghoulConservatory", attic: "ghoulAttic", crypt: "ghoulCrypt", huts: "ghoulHuts", lodge: "ghoulLodge", blackice: "ghoulBlackIce", sled: "ghoulSledRide", codeblue: "ghoulBlueRide", pew: "ghoulPewDirge", mower: "ghoulMowerRide", wagon: "ghoulWagonRide", hearse: "ghoulHearseRide", tray: "ghoulTrayRide", widow: "ghoulWidow", boardwalk: "ghoulBoardwalk", hollow: "ghoulHollow", stilts: "ghoulStilts", lantern: "ghoulLanternTheme", drowning: "ghoulDrowning", lawn: "ghoulMarrowLawn", mat: "ghoulMarrowMat", dollhouse: "ghoulMarrowRooms", bonestair: "ghoulMarrowStair", pit: "ghoulMarrowPit" });
// The House is killed three times over (Kill I on the lawn, II through every room, III in the Pit).
export const HOUSE_KILLS = 3;
const DREAD_ROOM = 0.7;
const DREAD_CLOCK = 0.2;
const DREAD_EASE_MS = 900;
// How full the music is right now, 0 to 1: the target the music eases toward.
export function dread(round) {
// The Heart's HOLD FIRE opens the music all the way (the Pit's track turns major only at full dread).
if (round.flood) return 1;
const b = round.boss;
if (b && round.lockX >= 0 && (b.state === "fight" || b.state === "intro")) return 0.9 + 0.1 * (1 - b.hp / Math.max(1, b.max));
if (round.gallery && round.gallery.track) return 0.9;
@@ -101,7 +107,8 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
let most = 0;
let further = false;
try {
most = Math.max(0, memo ? Number(memo.get()) | 0 : 0);
// RUN_STAGES + 1 means the House has been beaten.
most = Math.min(RUN_STAGES + 1, Math.max(0, memo ? Number(memo.get()) | 0 : 0));
} catch {}
// Particles, floating words, rings, banners, the chain's big number, the
// shake and the flash, the flares of light and the stains on the floor,
@@ -163,7 +170,7 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
try {
if (memo) memo.set(most);
} catch {}
if (b) b.tag = `NEW RECORD: ${n} OF ${STAGES.length} STAGES`;
if (b) b.tag = `NEW RECORD: ${n} OF ${RUN_STAGES} STAGES`;
};
// A room's banner, named for its stage and how far into it.
@@ -222,6 +229,8 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
// Lightning now and then, the thunder with it.
fx.bolt = Math.max(0, fx.bolt - ms);
fx.nextBolt -= ms;
// A room under the ground (its look's `noLightning`, the Pit) never flashes.
if (fx.nextBolt <= 0 && lookOf(round.spec.id).noLightning) fx.nextBolt = BOLT_EVERY_MS;
if (fx.nextBolt <= 0) {
fx.bolt = BOLT_MS;
fx.nextBolt = BOLT_EVERY_MS * (0.6 + Math.random() * 0.8);
@@ -267,7 +276,7 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
// all there are.
const st = round.stage && stageById(round.stage);
hud.room = (st ? st.title : round.spec.name).toUpperCase();
hud.stage = `STAGE ${round.cleared.length} OF ${STAGES.length}`;
hud.stage = round.stage === FINALE.id ? `THE HOUSE: KILL ${houseKill()} OF ${HOUSE_KILLS}` : `STAGE ${round.cleared.length} OF ${RUN_STAGES}`;
hud.bonus = round.bonus;
hud.hearts = round.bonusRound ? heartsText(round.bonusRound) : "";
hud.time = round.timeMs > 0 ? Math.ceil(round.timeMs / 1000) : 0;
@@ -284,8 +293,11 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
return hud;
};
// In the finale, which of the House's three kills is under way: the boss rooms up to this one (at least the first).
const houseKill = () => Math.max(1, FINALE.rooms.slice(0, round.stageAt + 1).filter((id) => roomById(id)?.boss).length);
// The view ghoul-draw.js draws from: one object, refilled each frame.
const view = { g: Object.freeze({ W, H, HUD_H, PAD, FIELD_W, FIELD_H, YOU_W, YOU_H, CRASH_MS, CRUMBLE_BACK_MS, RISE_MS, SKEL_WINDUP_MS, BONES_WINDUP_MS, WAVE_H, CHANDELIER_W, CHANDELIER_SHAKE_MS, SHOT_Y, DUCK_SHOT_Y, GOURD_WAIT_MS, EMERGE_MS, PUDDLE_W, PUDDLE_MS, HOUND_CROUCH_MS, WRAITH_WIND_MS, SPIT_WINDUP_MS, CEILING_Y, ZOMBIES }), powers: POWERS, monsters: MONSTERS, bosses: BOSSES, groundAt, shelfThere, solid, ghostSight, roomFor, roomById, stages: STAGES, stageById, OFFER_N };
const view = { g: Object.freeze({ W, H, HUD_H, PAD, FIELD_W, FIELD_H, YOU_W, YOU_H, CRASH_MS, CRUMBLE_BACK_MS, RISE_MS, SKEL_WINDUP_MS, BONES_WINDUP_MS, WAVE_H, CHANDELIER_W, CHANDELIER_SHAKE_MS, SHOT_Y, DUCK_SHOT_Y, GOURD_WAIT_MS, EMERGE_MS, PUDDLE_W, PUDDLE_MS, HOUND_CROUCH_MS, WRAITH_WIND_MS, SPIT_WINDUP_MS, CEILING_Y, ZOMBIES }), powers: POWERS, monsters: MONSTERS, bosses: BOSSES, groundAt, shelfThere, solid, ghostSight, roomFor, roomById, stages: SELECTABLE, runStages: RUN_STAGES, stageById, OFFER_N };
const shakeAt = { x: 0, y: 0 };
const paint = () => {
@@ -312,9 +324,11 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
view.lightning = lightning(fx.bolt);
view.furthest = most;
view.won = round.won;
// The kill under way in the finale (the boss bar's skull pips), null elsewhere.
view.houseKill = round.stage === FINALE.id ? houseKill() : null;
// A dot per stage along the start and end screens: those cleared this
// run in their colors (or, before one, as many as the record, in gold).
view.dots = STAGES.map((_, i) => (state === "ready" ? (i < most ? GOLD : null) : round.cleared[i] || null));
view.dots = Array.from({ length: RUN_STAGES }, (_, i) => (state === "ready" ? (i < most ? GOLD : null) : round.cleared[i] || null));
view.lost = state === "over";
view.overMs = fx.clock - (fx.overAt || 0);
view.shake = null;
@@ -325,14 +339,14 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
}
view.tally = null;
view.big = null;
const record = most >= STAGES.length ? "You have escaped before" : `Best: ${most} of ${STAGES.length} stages`;
if (state === "ready") view.tally = ["Run. Shoot. Clear every stage and escape before the house gets you", `Arrows run, up jumps, hold space to fire, tap it twice to throw what you find. ${record}`];
const record = most > RUN_STAGES ? "You have killed the House" : `Best: ${most} of ${RUN_STAGES} stages`;
if (state === "ready") view.tally = [`Run. Shoot. Clear ${RUN_STAGES} stages, then kill the house`, `Arrows run, up jumps, hold space to fire, tap it twice to throw what you find. ${record}`];
else if (state === "over") {
const st = round.stats;
view.big = String(round.score);
const how = `${st.kills} ghouls (${st.headshots} headshots, ${st.stomps} stomps), best chain x${chainMult(st.bestChain)}, ${st.candy} souls.`;
if (round.won) view.tally = [`You escaped! Every stage cleared${beaten ? ". A new best!" : ""}`, how];
else view.tally = [`Cleared ${round.cleared.length} of ${STAGES.length} stages, out in ${roomName(round.spec, round.room)}${further ? ". A new record!" : ""}${beaten ? " A new best!" : ""}`, `${how} ${round.practice ? "A practice run: nothing kept." : teaser(most)}`];
if (round.won) view.tally = [`You escaped! Marrow starves${beaten ? ". A new best!" : ""}`, how];
else view.tally = [`Cleared ${round.cleared.length} of ${RUN_STAGES} stages, out in ${roomName(round.spec, round.room)}${further ? ". A new record!" : ""}${beaten ? " A new best!" : ""}`, `${how} ${round.practice ? "A practice run: nothing kept." : teaser(most)}`];
}
drawScene(ctx, view);
};
@@ -346,6 +360,7 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
inp.jump = 0;
upHeld = false;
releaseStory(round);
releaseEnding(round);
};
// A new round. A real run opens on the intro story (ghoul-story.js) and the hall is announced when it ends; the stage select skips it.
@@ -381,6 +396,11 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
hum("ghoul:story", "ghoulStoryDrone", 0.6, 1);
return;
}
// The ending plays its own track, if it has one.
if (round.phase === "ending") {
if (ENDING_TRACK) music(ENDING_TRACK, 0.7);
return;
}
const b = round.boss;
const fight = Boolean(b && round.lockX >= 0 && (b.state === "fight" || b.state === "intro"));
// The room's music, its dread eased toward where play is now.
@@ -522,6 +542,7 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
const fy = y / u - HUD_H - PAD;
if (onCard(round)) return type === "down" ? takeIntro(round) || true : true;
if (round.phase === "story") return type === "down" ? takeStory(round) || true : true;
if (round.phase === "ending") return type === "down" ? takeEnding(round) || true : true;
// Use a Lucky die? A click lights its half (Yes on the left, No on the right); a click on the lit half answers.
if (round.phase === "ask") {
if (type === "down") {
@@ -556,6 +577,8 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
if (!repeat) takeIntro(round);
} else if (state === "running" && round.phase === "story") {
pressStory(round, repeat);
} else if (state === "running" && round.phase === "ending") {
pressEnding(round, repeat);
} else if (state === "running") {
round.input.fire = true;
// The dark ride's trigger: a tap shorter than a step still fires; no weapon.
@@ -589,6 +612,11 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
if (!repeat) takeStory(round);
return true;
}
// The ending: the same, a fresh move key turns its page.
if (round.phase === "ending") {
if (!repeat) takeEnding(round);
return true;
}
// A stage's intro card: any fresh move key walks in (a repeat never does).
if (onCard(round)) {
if (!repeat) takeIntro(round);
@@ -608,6 +636,7 @@ function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onS
round.input.fire = false;
releaseFire(round);
releaseStory(round);
releaseEnding(round);
}
else if (MOVES[name]) round.input[name] = false;
if (name === "up") upHeld = false;
@@ -49,6 +49,12 @@ import { LOOKS as TRAY_LOOKS, LOSE_SOUNDS as TRAY_LOSE_SOUNDS, LOSE_WORDS as TRA
import { LOOKS as CARNIVAL_LOOKS, LOSE_SOUNDS as CARNIVAL_LOSE_SOUNDS, LOSE_WORDS as CARNIVAL_LOSE_WORDS, VOICES as CARNIVAL_VOICES, carnivalArt } from "../stages/carnival/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 "../stages/frozen/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 "../stages/bog/ghoul-bog-draw.js";
import { LOOKS as EYE_LOOKS, LOSE_SOUNDS as EYE_LOSE_SOUNDS, LOSE_WORDS as EYE_LOSE_WORDS, VOICES as EYE_VOICES, eyeArt } from "../stages/marrow/ghoul-marrow-eye-draw.js";
import { LOOKS as HEART_LOOKS, LOSE_SOUNDS as HEART_LOSE_SOUNDS, LOSE_WORDS as HEART_LOSE_WORDS, VOICES as HEART_VOICES, heartArt } from "../stages/marrow/ghoul-marrow-heart-draw.js";
import { LOOKS as MAT_LOOKS, LOSE_SOUNDS as MAT_LOSE_SOUNDS, LOSE_WORDS as MAT_LOSE_WORDS, VOICES as MAT_VOICES, matArt } from "../rides/mat/ghoul-mat-draw.js";
import { LOOKS as BONESTAIR_LOOKS, LOSE_SOUNDS as BONESTAIR_LOSE_SOUNDS, LOSE_WORDS as BONESTAIR_LOSE_WORDS, VOICES as BONESTAIR_VOICES, bonestairArt } from "../rides/bonestair/ghoul-bonestair-draw.js";
import { endingArt } from "../story/ghoul-ending-draw.js";
import { LOOKS as MARROW_LOOKS, LOSE_SOUNDS as MARROW_LOSE_SOUNDS, LOSE_WORDS as MARROW_LOSE_WORDS, VOICES as MARROW_VOICES, marrowArt } from "../stages/marrow/ghoul-marrow-draw.js";
import { LOOKS as LANTERN_LOOKS, LOSE_SOUNDS as LANTERN_LOSE_SOUNDS, LOSE_WORDS as LANTERN_LOSE_WORDS, VOICES as LANTERN_VOICES, lanternArt } from "../rides/lantern/ghoul-lantern-draw.js";
import { diceArt } from "../core/ghoul-dice-draw.js";
import { gameOverBanner } from "../story/ghoul-gameover-draw.js";
@@ -140,6 +146,11 @@ export const LOOKS = Object.freeze({
...RIDE_LOOKS,
...BOG_LOOKS,
...LANTERN_LOOKS,
...MARROW_LOOKS,
...EYE_LOOKS,
...HEART_LOOKS,
...MAT_LOOKS,
...BONESTAIR_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;
@@ -263,14 +274,17 @@ 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 = { paintDark, hudLayout, drawPower, ellipse, circle, roundRect, line, rotate, eye, hash, say, gate, label, drawBoneShape, BONE, DANGER, GOLD, FLASH, EYE_RED, EYE_PALE, EYE_AMBER };
// `bossArt(kind)` hands a pack another boss's figure (the finale's shades of the keepers YOU beat).
const HELP = { bossArt: (kind) => BOSS_ART[kind] || null, paintDark, 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), banister: banisterArt(HELP), hearse: hearseArt(HELP), codeblue: gurneyArt(HELP), pew: pewArt(HELP), lantern: lanternArt(HELP), mower: mowerArt(HELP), tray: trayArt(HELP), wagon: wagonArt(HELP), carnival: carnivalArt(HELP), frozen: frozenArt(HELP), bog: bogArt(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), lantern: lanternArt(HELP), mower: mowerArt(HELP), tray: trayArt(HELP), wagon: wagonArt(HELP), carnival: carnivalArt(HELP), frozen: frozenArt(HELP), bog: bogArt(HELP), marrow: marrowArt(HELP), dollhouse: eyeArt(HELP), pit: heartArt(HELP), mat: matArt(HELP), bonestair: bonestairArt(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 });
// The ending's pages once the House is dead (story/ghoul-ending-draw.js).
const ENDING = endingArt({ ...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);
@@ -1374,11 +1388,15 @@ function drawGourdFire(ctx, v, b) {
ctx.globalAlpha = 1;
}
// Bosses whose fall is a scene of their own (the House's retreat): no fade,
// their art decides what shows after it falls.
const LINGERS = new Set(["marrow", "marroweye", "marrowheart"]);
function drawBoss(ctx, v) {
const b = v.round.boss;
if (!b) return;
const was = ctx.globalAlpha;
if (b.state === "down") {
if (b.state === "down" && !LINGERS.has(b.kind)) {
if (b.t > 900) return;
ctx.globalAlpha = was * (1 - b.t / 900);
}
@@ -1404,6 +1422,24 @@ function drawBossBar(ctx, v) {
roundRect(ctx, x + 0.2, 4.2, (w - 0.4) * Math.max(0, b.hp / b.max), 1.2, 0.6);
ctx.fillStyle = "#a01010";
ctx.fill();
// The House's three kills as skull pips past the bar's end: done in bone, this one beating red, the rest dim.
if (v.houseKill) {
for (let i = 0; i < 3; i++) {
const px = x + w + 1.6 + i * 1.9;
const on = i + 1 === v.houseKill;
ctx.globalAlpha = i + 1 > v.houseKill ? 0.35 : 1;
ctx.fillStyle = i + 1 < v.houseKill ? BONE : on ? "#e2553f" : "#cfc4a6";
circle(ctx, px, 4.6, on ? 0.75 + 0.08 * Math.sin(v.clock / 180) : 0.7);
ctx.fill();
ctx.fillRect(px - 0.4, 4.9, 0.8, 0.55);
ctx.fillStyle = "#1a1014";
circle(ctx, px - 0.28, 4.55, 0.17);
ctx.fill();
circle(ctx, px + 0.28, 4.55, 0.17);
ctx.fill();
}
ctx.globalAlpha = 1;
}
}
/* -------------------------------------------------------------- Planny */
@@ -1767,7 +1803,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, ...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, ...LANTERN_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, ...LANTERN_LOSE_WORDS, ...MARROW_LOSE_WORDS, ...EYE_LOSE_WORDS, ...HEART_LOSE_WORDS, ...MAT_LOSE_WORDS, ...BONESTAIR_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 });
@@ -2022,7 +2058,9 @@ export function react(e, k) {
ring(e.x, e.y, GOLD, 2, 12, 700);
glow(e.x, e.y, 22, 0.9, 900);
fx.cheer = 1600;
banner(`${BOSSES[e.kind].name} is dead`, e.life ? `+${e.points}, a life back, and the door is open` : `+${e.points}, and the door is open`, GOLD, 1800);
// A boss whose fall plays out as a scene of its own gets a short banner, out of its way.
if (LINGERS.has(e.kind)) banner(`${BOSSES[e.kind].name} is dead`, `+${e.points}, and a life back`, GOLD, 650);
else banner(`${BOSSES[e.kind].name} is dead`, e.life ? `+${e.points}, a life back, and the door is open` : `+${e.points}, and the door is open`, GOLD, 1800);
} else if (e.type === "poof") {
if (gate(fx, "poofMs", 80)) tone("ghoulPoof", 0.3, vary(0.3));
burst(e.x, e.y, MONSTERS[e.kind] ? MONSTERS[e.kind].color : "#ffffff", 8, 12);
@@ -2042,6 +2080,9 @@ export function react(e, k) {
} else if (e.type === "stageClear") {
tone("fanfare", 0.4);
k.markFurthest(e.n, banner("Stage cleared", `${e.n} of ${e.of}`, GOLD, 1400));
} else if (e.type === "won") {
// The House beaten: the record goes one past every stage, with no banner (never "7 OF 6").
k.markFurthest(e.n);
} else if (e.type === "offer") {
// The next doors on offer: a toll, a groan of hinges.
tone("ghoulToll", 0.35, 1.2);
@@ -2067,7 +2108,7 @@ export function react(e, k) {
else if (e.by === "villager") say(tone, "villager", "throw", 0.4);
else if (e.kind === "barbell") { /* the strongman's own throw sound (ghoul-carnival-draw.js) */ }
else if (e.by !== "bones") tone("swoosh", 0.15, e.kind === "acid" ? 0.7 : 1.2);
} else if (!DICE.react(e, k) && !BONUS.react(e, k)) ART.react(e, k);
} else if (!DICE.react(e, k) && !BONUS.react(e, k) && !ENDING.react(e, k)) ART.react(e, k);
if (e.type === "lose" || e.type === "respawn") fx.combo = null;
}
@@ -2130,6 +2171,11 @@ export const VOICES = Object.freeze({
angel: Object.freeze({ wake: "ghoulAngelWake", weep: "ghoulAngelWeep", watch: "ghoulAngelWatch", see: "ghoulAngelSee", slam: "ghoulAngelSlam", wings: "ghoulAngelWings", hurt: "ghoulAngelHurt", die: "ghoulAngelDie" }),
...BOG_VOICES,
...LANTERN_VOICES,
...MARROW_VOICES,
...EYE_VOICES,
...HEART_VOICES,
...MAT_VOICES,
...BONESTAIR_VOICES,
});
// Plays a kind's voice for an act, if it has one, its pitch a touch varied.
function say(tone, kind, act, level) {
@@ -2177,6 +2223,11 @@ const LOSE_SOUNDS = Object.freeze({
...RIDE_LOSE_SOUNDS,
...BOG_LOSE_SOUNDS,
...LANTERN_LOSE_SOUNDS,
...MARROW_LOSE_SOUNDS,
...EYE_LOSE_SOUNDS,
...HEART_LOSE_SOUNDS,
...MAT_LOSE_SOUNDS,
...BONESTAIR_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]);
@@ -2622,6 +2673,7 @@ export function drawScene(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 === "running" || v.state === "paused") && round.phase === "ending") ENDING.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();
@@ -758,7 +758,7 @@ export function pickerArt(d) {
ctx.fillStyle = "rgba(4, 2, 6, 0.86)";
ctx.fillRect(0, 0, W, g.FIELD_H);
const done = round.cleared.length;
const total = v.stages.length;
const total = v.runStages;
const last = round.offer.length === 1;
if (done) label(ctx, `STAGE ${done} OF ${total} CLEARED`, W / 2, 3.2, 2, GOLD, "center", W - 4);
label(ctx, last ? "One way left" : done ? "Choose your way on" : "Choose your way in", W / 2, 7.4, 4, "#ffffff", "center", W - 4, true);
@@ -19,7 +19,7 @@
// firing), and down ducks on the ground or drops through a shelf. Each room's door opens once he grabs its key. A run starts in a
// long hall, then goes stage by stage (three rooms, then a boss whose fall
// opens the door), each next stage picked from two not yet played that run;
// clearing every stage wins. Every other room keeps a horde pouring in from
// six stages cleared, the House itself is the finale, and killing it wins. Every other room keeps a horde pouring in from
// the edges of the view, so standing still is never safe. Kills in quick succession build a chain that multiplies their points
// and runs out fast; a shot to the head or a stomp from above doubles a
// kill. Souls (the `candy` in the rules), power-ups (spread shot, rapid
@@ -0,0 +1,960 @@
// Plan2Code Web Console - Ghoul Rush's finale, its drawing for the finale's second ride, down The Bone Stair ahead of the collapse: LOOKS, VOICES, LOSE_WORDS, LOSE_SOUNDS and bonestairArt(d), plugged into draw/ghoul-draw.js. The shaft of a spiral stair under the House: stone walls scrolling up as YOU go down, the far side of the spiral in the gloom, treads of bones with skulls in the risers ("every step down is someone"), a rail of arm bones, a column of vertebrae at every turn of the spiral (in front of YOU), missing treads, treads that crack and give way, hanging ribcages, skeletons climbing up, bone hands at the rail, masonry with its shadow, the wall of rubble coming down behind YOU with its meter, and the last step broken off over the Pit's dark, a red pulse far below. No random numbers: everything comes from a hash or the clock.
//
// LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are plain data (the sounds live in
// ghoul-sfx-bonestair.js); bonestairArt(d) takes draw/ghoul-draw.js's helpers (`d`) and hands back
// the drawing by kind, so this file never reaches back into it. Drawn in room units, y counted
// down from the field's top (a world height `y` is drawn at FIELD_H - y). The still layers get
// only the shaft's color; the shaft, the stair and what is on it are drawn by `moving` (every
// frame, behind YOU); the columns, the ribcages, the hands, the falling blocks, the rubble, the
// glyphs and the meter by `front`. What the art reads off the rules (ghoul-bonestair.js): the
// room's `spec.ride`, `round.runner` (gap, close, done, check, flight, rot, skels, hands,
// stones), YOU (`state`, `ducking`, `x`, `y`), and its events.
import { CATCH_GAP, CLOSE_ON, GAP_MAX, HAND_GRAB_MS, HAND_H, HAND_W, HAND_WARN_MS, PILE_H, PILE_W, RIB_W, SKEL_H, SKEL_RISE_MS, STONE_MS, flightAt, seams, stairY, stoneDrop } from "./ghoul-bonestair.js";
const freeze = (o) => Object.freeze(o);
const TAU = Math.PI * 2;
const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x));
export const LOOKS = freeze({
bonestair: freeze({ pack: "bonestair", custom: true, noMoon: true, pit: "#030205", wallTop: "#120d10", wallLow: "#1e1418", paper: "#261a1c", wainscot: "#1a1214", floorTop: "#d8ccb0", floor: "#4a3e34", floorEdge: "#120c0a", shelf: "#3a2e26", shelfTop: "#c8b898", window: "#ffb070", decor: "pots", color: "#e8dcc0", dark: 0.55 }),
});
// How each kind sounds, by act (the user's picks from the sound vote, bonestair.html, in ghoul-sfx-bonestair.js).
export const VOICES = freeze({
stair: freeze({ jump: "ghoulStairJump", land: "ghoulStairLand", crash: "ghoulStairCrash", drop: "ghoulStairDrop", check: "ghoulStairCheck", turn: "ghoulStairTurn", edge: "ghoulStairEdge", finish: "ghoulStairFinish", close: "ghoulStairClose", catch: "ghoulStairCatch", rot: "ghoulStairRot" }),
stairskel: freeze({ rise: "ghoulStairRise", hit: "ghoulStairSkelHit", down: "ghoulStairSkelDown" }),
stairhand: freeze({ reach: "ghoulStairReach", grab: "ghoulStairGrab" }),
stairstone: freeze({ creak: "ghoulStairCreak", crack: "ghoulStairCrack", thud: "ghoulStairThud" }),
});
// What each of the pack's events plays: [kind, act], once.
export const EVENT_VOICE = freeze({
stairJump: ["stair", "jump"],
stairLand: ["stair", "land"],
stairCrash: ["stair", "crash"],
stairDrop: ["stair", "drop"],
stairCheck: ["stair", "check"],
stairTurn: ["stair", "turn"],
stairEdge: ["stair", "edge"],
stairFinish: ["stair", "finish"],
stairClose: ["stair", "close"],
stairCatch: ["stair", "catch"],
stairRot: ["stair", "rot"],
stairRise: ["stairskel", "rise"],
stairSkelHit: ["stairskel", "hit"],
stairSkelDown: ["stairskel", "down"],
stairReach: ["stairhand", "reach"],
stairGrab: ["stairhand", "grab"],
stairCreak: ["stairstone", "creak"],
stairCrack: ["stairstone", "crack"],
stairThud: ["stairstone", "thud"],
});
export const LOSE_WORDS = freeze({ stairGap: "Missed a step", stairGive: "The stair gave way", stairRib: "Caught in the ribs", stairSkel: "Dragged back up", stairHand: "Grabbed by the ankle", stairStone: "Flattened by masonry", stairRubble: "Buried by the house" });
export const LOSE_SOUNDS = freeze({
stairGap: ["ghoulPitFall", 0.55, 1.1],
stairGive: ["ghoulPitFall", 0.55, 0.85],
stairRib: ["crunch", 0.5, 1.1],
stairSkel: ["crunch", 0.5, 0.8],
stairHand: ["ghoulStairGrab", 0.55, 0.9],
stairStone: ["thud", 0.6, 0.7],
stairRubble: ["ghoulStairCatch", 0.6, 0.9],
});
const FW = 96;
let FH = 54;
// A tread's width, and how far the stair's body hangs under its nosings.
const TW = 3.5;
const BODY = 5.5;
const COL_W = 8;
// 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 hgrad = (c, x0, x1, stops) => grad(c.createLinearGradient && (() => c.createLinearGradient(x0, 0, x1, 0)), stops);
const rgrad = (c, x, y, r, stops) => grad(c.createRadialGradient && (() => c.createRadialGradient(x, y, 0, x, y, r)), stops);
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 CANDLE = "255,180,90";
const BONE = "#e2d6b8";
const BONE_DIM = "#a89a80";
const BONE_DARK = "#5a4c3c";
/* ------------------------------------------------------------- telegraphs */
// What to do about what is coming, as a glyph that fades in ahead of it: JUMP for missing
// treads, a hand or a pile of masonry, DUCK for a ribcage, SHOOT for a skeleton, RUN where the
// treads will give way. Everything comes from the room's `ride` fields and where YOU are.
export const TELEGRAPH_SEE = 42;
export const TELEGRAPH_FULL = 32;
export const TELEGRAPH_WORDS = 3;
export const TELEGRAPH_ALPHA = 0.74;
export const ANSWERS = freeze({ gap: "JUMP", hand: "JUMP", stone: "JUMP", rib: "DUCK", skel: "SHOOT", rot: "RUN" });
export const ANSWER_COLORS = freeze({ JUMP: "#5fe3ff", DUCK: "#ffb02e", SHOOT: "#ff6a8a", RUN: "#8aff7a" });
const marks = new WeakMap();
// Every obstacle that wants a glyph: { kind, lead (where YOU act), x (its middle), up (the
// glyph's anchor height), 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 });
};
const at = (x) => stairY(R, x) ?? 20;
for (const [x0, x1] of R.gaps) add("gap", x0 - 3, (x0 + x1) / 2, at(x0) + 7.5);
for (const [x0, x1] of R.rot) add("rot", x0, x0 + 6, at(x0) + 8);
for (const [x, under] of R.ribs) add("rib", x - RIB_W / 2 - 3, x, under + 7);
for (const [x] of R.skels) add("skel", x - 30, x - 6, at(x) + 10, TELEGRAPH_SEE + 22);
for (const [x] of R.hands) add("hand", x - 5, x, at(x) + 7);
for (const [x] of R.stones) add("stone", x - 6, x, at(x) + 8, TELEGRAPH_SEE + 10);
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 > 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 bonestairArt(d) {
const { label, GOLD } = d;
const ride = (v) => (v.spec && v.spec.ride && v.spec.ride.runner === "bonestair" ? v.spec.ride : null);
const Y = (y) => FH - y;
const mine = (v) => {
const R = ride(v);
const c = v.round && v.round.runner;
return R && c && c.id === "bonestair" ? [R, c] : [null, null];
};
// How far down the shaft x is: a flight's height for each flight before it, and the way down this one.
const depthAt = (R, x) => {
const i = flightAt(R, x);
if (i < 0) return x < R.flights[0][0] ? 0 : R.flights.length * (R.flights[0][2] - R.flights[0][3]);
return i * (R.flights[0][2] - R.flights[0][3]) + (R.flights[i][2] - (stairY(R, x) ?? 0));
};
// How near the bottom the camera is, 0 at the top of the stair and 1 over the Pit.
const nearEnd = (R, cam) => clamp((cam + FW * 0.4 - R.flights[0][0]) / (R.finish - R.flights[0][0]), 0, 1);
/* ------------------------------------------------------------- the room */
function backdrop(ctx, v, look, x0, x1) {
ctx.fillStyle = look.pit;
ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H);
}
// The cellar landing at the top (packed bone), the Pit's floor at the end (black rock).
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 = vgrad(ctx, y, y + top, [[0, "#1a0c0c"], [0.3, "#0c0606"], [1, "#020101"]]);
ctx.fillRect(a, y, b - a, top + 2);
ctx.fillStyle = "#3a1414";
ctx.fillRect(a, y, b - a, 0.25);
return;
}
// The cellar landing: packed bone like the stair's body, bones laid along its top.
ctx.fillStyle = vgrad(ctx, y, y + top, [[0, "#3a2e24"], [0.15, "#2a2018"], [1, "#0c0806"]]);
ctx.fillRect(a, y, b - a, top + 2);
for (let x = a; x + TW <= b + 0.01; x += TW) femur(ctx, x + 0.05, x + TW + 0.1, y + 0.35, 0.62, BONE);
ctx.strokeStyle = "rgba(160,140,110,0.3)";
ctx.lineWidth = 0.16;
for (let x = a + 0.8; x < b; x += 1.6) seg(ctx, x, y + 2 + rnd(Math.round(x * 3), 1) * 6, x + 1.1, y + 2.4 + rnd(Math.round(x * 3), 2) * 6);
}
function shelf() {}
/* ------------------------------------------------------------ the shaft */
// The stone walls of the shaft, their courses rising as YOU go down; the far side of the spiral
// in the gloom; dust drifting down; the Pit's red glow growing from below near the end.
function shaft(ctx, v, R, cam) {
const clock = v.clock;
const you = v.round.you;
const depth = depthAt(R, clamp(you.x, R.flights[0][0], R.finish));
const end = nearEnd(R, cam);
ctx.fillStyle = vgrad(ctx, 0, FH, [[0, "#140e12"], [0.6, "#1c1216"], [1, `rgb(${Math.round(30 + 60 * end)},${Math.round(14 + 4 * end)},${Math.round(16 + 2 * end)})`]]);
ctx.fillRect(cam - 1, 0, FW + 2, FH);
// Courses of stone, at a slow parallax across and rising with the depth.
const f = 0.3;
const rise = (depth * 0.55) % 6;
ctx.strokeStyle = "rgba(0,0,0,0.35)";
ctx.lineWidth = 0.2;
for (let row = -1; row < FH / 3 + 2; row++) {
const yy = row * 3 - rise + 6;
seg(ctx, cam - 1, yy, cam + FW + 1, yy);
const off = ((row + Math.floor((depth * 0.55) / 6) * 2) % 2) * 3;
for (let n = Math.floor((cam * f) / 6) - 1; n * 6 < cam * f + FW + 6; n++) {
const xx = n * 6 + off + cam * (1 - f);
seg(ctx, xx, yy, xx, yy + 3);
if (rnd(n * 13 + row, 7) > 0.86) {
ctx.fillStyle = "rgba(60,40,40,0.25)";
ctx.fillRect(xx + 0.3, yy + 0.3, 5.4, 2.4);
}
}
}
// The far side of the spiral: a dim stair going the other way, high and low.
ctx.fillStyle = "rgba(10,6,8,0.55)";
const f2 = 0.55;
for (let k = -1; k < 3; k++) {
const span = 120;
const bx = Math.floor((cam * f2) / span) * span + k * span + cam * (1 - f2);
const yTop = Y(40) + ((depth * 0.8) % 22) - 22 + k * 0;
for (let s = 0; s < span; s += 3) {
const yy = yTop + 22 - (s / span) * 22;
ctx.fillRect(bx + s, yy, 3.1, 1.4 + (s % 6 === 0 ? 0.4 : 0));
}
}
// Dust sifting down from the collapse above.
for (let k = 0; k < 30; k++) {
const sx = cam + ((((rnd(k, 1) * FW - cam * 0.2) % FW) + FW) % FW);
const sy = (rnd(k, 2) * FH + clock * (0.006 + rnd(k, 3) * 0.01)) % FH;
ctx.fillStyle = `rgba(200,180,160,${0.12 + 0.2 * rnd(k, 4)})`;
ctx.fillRect(sx, sy, 0.18, 0.4);
}
// Far below, the Pit: its red pulse, stronger near the end.
if (end > 0.4) {
const beat = 0.5 + 0.5 * Math.max(0, Math.sin(clock / 260)) * Math.max(0, Math.sin(clock / 130));
ctx.globalAlpha = (end - 0.4) * 1.2 * (0.55 + 0.45 * beat);
ctx.fillStyle = vgrad(ctx, FH * 0.55, FH, [[0, "rgba(160,20,20,0)"], [1, "rgba(200,30,24,0.75)"]]);
ctx.fillRect(cam - 1, FH * 0.55, FW + 2, FH * 0.45);
ctx.globalAlpha = 1;
}
}
/* ------------------------------------------------------------ the stair */
// A bone lying across (a femur, its knobbed ends), from x0 to x1 at height y (drawn), r thick.
function femur(ctx, x0, x1, y, r, col) {
ctx.fillStyle = col;
ctx.fillRect(x0 + r * 0.8, y - r * 0.55, x1 - x0 - r * 1.6, r * 1.1);
disc(ctx, x0 + r * 0.7, y - r * 0.45, r * 0.62);
disc(ctx, x0 + r * 0.7, y + r * 0.45, r * 0.62);
disc(ctx, x1 - r * 0.7, y - r * 0.45, r * 0.62);
disc(ctx, x1 - r * 0.7, y + r * 0.45, r * 0.62);
}
// A little skull, facing out of a riser: someone.
function skull(ctx, x, y, s, lit) {
ctx.fillStyle = BONE_DIM;
disc(ctx, x, y, 0.62 * s);
ctx.fillRect(x - 0.42 * s, y + 0.2 * s, 0.84 * s, 0.55 * s);
ctx.fillStyle = "#120a08";
disc(ctx, x - 0.24 * s, y + 0.05 * s, 0.17 * s);
disc(ctx, x + 0.24 * s, y + 0.05 * s, 0.17 * s);
if (lit) {
ctx.fillStyle = "rgba(255,90,60,0.8)";
disc(ctx, x - 0.24 * s, y + 0.05 * s, 0.07 * s);
disc(ctx, x + 0.24 * s, y + 0.05 * s, 0.07 * s);
}
ctx.fillRect(x - 0.06 * s, y + 0.28 * s, 0.12 * s, 0.14 * s);
}
// Whether the tread from tx to tx + TW is there: not over missing treads, nor where the stair gave way.
function treadState(R, c, tx) {
const mid = tx + TW / 2;
for (const [x0, x1] of R.gaps) if (mid > x0 && mid < x1) return { gone: true };
for (const [i, [x0, x1]] of R.rot.entries()) {
if (mid < x0 || mid > x1) continue;
const r = c.rot[i];
if (r.state === "wait") return { cracked: true, rot: i };
if (mid < r.front) return { gone: true, falling: r.front - mid };
return { cracked: true, rot: i, near: r.front > mid - 6 };
}
return {};
}
// One flight from lo to hi: the rail behind, the stringer of packed bones under it, the treads.
function flight(ctx, v, R, c, i, lo, hi) {
const [x0, x1, y0, y1] = R.flights[i];
const a = Math.max(x0, lo);
const b = Math.min(x1, hi);
if (b <= a) return;
const yAt = (x) => y0 + ((y1 - y0) * (x - x0)) / (x1 - x0);
const clock = v.clock;
// The rail: arm bones standing on every other tread, a spine along their tops.
ctx.strokeStyle = "#6a5c4a";
ctx.lineWidth = 0.34;
const k0 = Math.floor((a - x0) / TW);
for (let k = k0; x0 + k * TW < b; k++) {
const tx = x0 + k * TW;
if (k % 2) continue;
if (treadState(R, c, tx).gone) continue;
seg(ctx, tx + 0.6, Y(yAt(tx)) - 0.2, tx + 0.6, Y(yAt(tx) + 5.6));
}
ctx.strokeStyle = "#8a7a62";
ctx.lineWidth = 0.5;
seg(ctx, a, Y(yAt(a) + 5.8), b, Y(yAt(b) + 5.8));
ctx.fillStyle = "#9a8a70";
for (let x = Math.ceil(a / 1.4) * 1.4; x < b; x += 1.4) disc(ctx, x, Y(yAt(x) + 5.8), 0.28);
// The stringer: the stair's body of packed bones under the treads, to the void below.
ctx.fillStyle = "#2a2018";
poly(ctx, [[a, Y(yAt(a))], [b, Y(yAt(b))], [b, Y(yAt(b) - BODY)], [a, Y(yAt(a) - BODY)]]);
ctx.fill();
ctx.strokeStyle = "rgba(160,140,110,0.35)";
ctx.lineWidth = 0.16;
for (let x = Math.floor(a / 1.6) * 1.6; x < b; x += 1.6) {
const n = Math.round(x / 1.6);
const yy = Y(yAt(x)) + 1.4 + rnd(n, 3) * (BODY - 2);
seg(ctx, x, yy, x + 1.2, yy + (rnd(n, 4) - 0.5) * 0.8);
}
ctx.fillStyle = "rgba(0,0,0,0.6)";
poly(ctx, [[a, Y(yAt(a) - BODY + 1)], [b, Y(yAt(b) - BODY + 1)], [b, Y(yAt(b) - BODY)], [a, Y(yAt(a) - BODY)]]);
ctx.fill();
// The treads, each a bone laid across, a skull in every third riser.
for (let k = k0; x0 + k * TW < b; k++) {
const tx = x0 + k * TW;
const st = treadState(R, c, tx);
// Each tread level at the line's height under its middle, so a step down at each end.
const top = Y(yAt(Math.min(x1, tx + TW / 2)));
if (st.gone) {
// A hole in the stair, or a tread still falling where it gave way.
ctx.fillStyle = "rgba(6,4,5,0.5)";
ctx.fillRect(tx, top - 0.2, TW + 0.05, BODY + 0.4);
if (st.falling !== undefined && st.falling < 10) {
const t = st.falling / 36;
ctx.save();
ctx.translate(tx + TW / 2, top + 0.5 + 60 * t * t + st.falling * 0.3);
ctx.rotate((st.falling * 0.4 * (rnd(k, 5) - 0.5)) * 1.2);
femur(ctx, -TW / 2, TW / 2, 0, 0.62, BONE_DIM);
ctx.restore();
} else if (rnd(k, 9) > 0.6) {
ctx.strokeStyle = BONE_DARK;
ctx.lineWidth = 0.3;
seg(ctx, tx + 0.3, top + 0.2, tx + 0.6, top + 1.4 + rnd(k, 8));
}
continue;
}
const shake = st.near ? Math.sin(clock / 30 + k) * 0.15 : 0;
ctx.fillStyle = "#3a2e24";
ctx.fillRect(tx, top, TW + 0.05, 1.6);
ctx.fillStyle = "rgba(0,0,0,0.45)";
ctx.fillRect(tx + TW - 0.12, top, 0.16, 1.6);
femur(ctx, tx + 0.05, tx + TW + 0.1, top + 0.35 + shake, 0.62, st.cracked ? "#c8bc98" : BONE);
if (k % 3 === 1) skull(ctx, tx + TW / 2, top + 1.7, 1.3, k % 7 === 4);
if (st.cracked) {
ctx.strokeStyle = "#2a1a10";
ctx.lineWidth = 0.14;
seg(ctx, tx + 0.5 + rnd(k, 1), top + 0.05, tx + 0.9 + rnd(k, 2), top + 0.6);
seg(ctx, tx + 0.9 + rnd(k, 2), top + 0.6, tx + 1.3 + rnd(k, 3), top + 0.25);
// Sickly dust where it will go.
if (Math.sin(clock / 160 + k) > 0.6) {
ctx.fillStyle = "rgba(170,200,120,0.35)";
ctx.fillRect(tx + rnd(k, 6) * TW, top + 0.7 + ((clock / 40 + k * 3) % 3), 0.15, 0.3);
}
}
}
// The missing treads cut exactly where the rules have them, broken bone at each edge.
for (const [g0, g1] of R.gaps) {
if (g1 < a || g0 > b) continue;
// The shaft shows through, dimmed: the stair's body is cut away there.
ctx.save();
ctx.beginPath();
ctx.rect(g0, Y(yAt(g0) + 1.2), g1 - g0, BODY + 1.6 + yAt(g0) - yAt(g1));
ctx.clip();
shaft(ctx, v, R, Math.round(v.round.camX * 8) / 8);
ctx.restore();
ctx.fillStyle = "rgba(6,4,5,0.45)";
poly(ctx, [[g0, Y(yAt(g0) + 1)], [g1, Y(yAt(g1) + 1)], [g1, Y(yAt(g1) - BODY - 0.2)], [g0, Y(yAt(g0) - BODY - 0.2)]]);
ctx.fill();
ctx.fillStyle = BONE_DIM;
poly(ctx, [[g0 - 0.2, Y(yAt(g0) + 0.3)], [g0 + 0.7, Y(yAt(g0) - 0.1)], [g0 - 0.2, Y(yAt(g0) - 0.9)]]);
ctx.fill();
poly(ctx, [[g1 + 0.2, Y(yAt(g1) + 0.3)], [g1 - 0.7, Y(yAt(g1))], [g1 + 0.2, Y(yAt(g1) - 0.9)]]);
ctx.fill();
}
}
// A checkpoint: a candle in a skull sconce on the rail, lit once passed.
function sconce(ctx, v, x, base, passed) {
const y = Y(base + 7.4);
skull(ctx, x, y + 0.9, 1.6, false);
ctx.fillStyle = passed ? "#efe2c0" : "#8a7e68";
ctx.fillRect(x - 0.3, y - 1.6, 0.6, 1.6);
if (passed) {
const f = 0.85 + 0.15 * Math.sin(v.clock / 70 + x);
ctx.fillStyle = "#ffcf6a";
ctx.beginPath();
ctx.ellipse?.(x, y - 2.1, 0.32 * f, 0.6 * f, 0, 0, TAU);
ctx.fill();
glow(ctx, CANDLE, x, y - 2, 6, 0.32);
}
}
// A skeleton climbing up the stair at YOU (facing left), `p` of the way up out of the treads.
function skeleton(ctx, v, x, base, p, i, state, t) {
const clock = v.clock;
const y = Y(base) + (1 - p) * SKEL_H;
const climb = state === "climb" ? Math.sin(clock / 120 + i) : 0;
ctx.save();
ctx.translate(x, y);
if (state === "down") {
// Knocked apart: the bones tumbling down the stair.
const q = Math.min(1, t / 700);
ctx.globalAlpha = 1 - q;
for (let k = 0; k < 6; k++) {
ctx.save();
ctx.translate((rnd(k, i) - 0.3) * 8 * q, -2 - k * 0.6 + 10 * q * q);
ctx.rotate(q * 6 * (rnd(k, 2) - 0.5));
femur(ctx, -0.8, 0.8, 0, 0.35, BONE);
ctx.restore();
}
ctx.restore();
ctx.globalAlpha = 1;
return;
}
ctx.strokeStyle = BONE;
ctx.lineWidth = 0.34;
ctx.lineCap = "round";
// Legs, a step up and a step down.
seg(ctx, 0, -2.2, -0.8 - climb * 0.3, -1.1);
seg(ctx, -0.8 - climb * 0.3, -1.1, -0.9, 0);
seg(ctx, 0, -2.2, 0.7 + climb * 0.3, -1.2);
seg(ctx, 0.7 + climb * 0.3, -1.2, 0.8, 0);
// Spine and ribs, leaning up the stair.
seg(ctx, 0, -2.2, -0.5, -4.1);
for (let r = 0; r < 3; r++) {
const ry = -2.8 - r * 0.45;
ctx.lineWidth = 0.2;
ctx.beginPath();
ctx.ellipse?.(-0.35 - r * 0.05, ry, 0.7, 0.22, 0, 0, TAU);
ctx.stroke();
}
// Arms reaching for YOU.
ctx.lineWidth = 0.3;
seg(ctx, -0.5, -3.8, -1.9, -3.4 + climb * 0.5);
seg(ctx, -1.9, -3.4 + climb * 0.5, -2.7, -3.9 + climb * 0.3);
seg(ctx, -0.5, -3.8, -1.6, -2.9 - climb * 0.4);
seg(ctx, -1.6, -2.9 - climb * 0.4, -2.5, -2.6);
// The skull, its eyes lit.
ctx.fillStyle = BONE;
disc(ctx, -0.7, -4.7, 0.62);
ctx.fillRect(-1.05, -4.4, 0.7, 0.5);
ctx.fillStyle = "#ff4a3a";
disc(ctx, -1.0, -4.75, 0.14);
disc(ctx, -0.55, -4.75, 0.14);
ctx.restore();
glow(ctx, "255,70,50", x - 0.8, y - 4.7, 2.6, 0.35);
}
// A pile of fallen masonry on a tread.
function pile(ctx, x, base, i) {
const y = Y(base);
for (let k = 0; k < 4; k++) {
const w = 1.2 + rnd(i * 4 + k, 1) * 0.9;
const h = 0.9 + rnd(i * 4 + k, 2) * 0.6;
const px = x - PILE_W / 2 + rnd(i * 4 + k, 3) * (PILE_W - w);
const py = y - (k < 2 ? 0 : 1) * 1.1 - h;
ctx.fillStyle = k % 2 ? "#5a5050" : "#6e625a";
ctx.fillRect(px, py, w, h);
ctx.fillStyle = "rgba(255,255,255,0.12)";
ctx.fillRect(px, py, w, 0.18);
}
ctx.fillStyle = "rgba(180,170,150,0.3)";
ctx.fillRect(x - PILE_W / 2 - 0.4, y - 0.15, PILE_W + 0.8, 0.2);
}
// A block of masonry: a carved stone with a scrap of the house's wallpaper on it.
function block(ctx, x, yBottom, rot, i) {
ctx.save();
ctx.translate(x, Y(yBottom) - PILE_H / 2);
ctx.rotate(rot);
ctx.fillStyle = "#6e625a";
ctx.fillRect(-PILE_W / 2, -PILE_H / 2, PILE_W, PILE_H);
ctx.fillStyle = i % 2 ? "#4a2a3a" : "#2a3a4a";
ctx.fillRect(-PILE_W / 2, -PILE_H / 2, PILE_W * 0.45, PILE_H * 0.5);
ctx.strokeStyle = "rgba(0,0,0,0.5)";
ctx.lineWidth = 0.14;
ctx.strokeRect(-PILE_W / 2, -PILE_H / 2, PILE_W, PILE_H);
ctx.restore();
}
function moving(ctx, v, cam) {
const [R, c] = mine(v);
if (!R) return;
FH = v.g.FIELD_H;
cam = Math.round(cam * 8) / 8;
const lo = cam - 10;
const hi = cam + FW + 10;
shaft(ctx, v, R, cam);
// Skeletons still coming up from under the treads go behind them.
R.skels.forEach(([sx], i) => {
const s = c.skels[i];
if (s.state !== "rise" || s.x < lo || s.x > hi) return;
skeleton(ctx, v, s.x, stairY(R, s.x) ?? 20, 1 - Math.max(0, s.t) / SKEL_RISE_MS, i, "rise", 0);
});
R.flights.forEach((_, i) => flight(ctx, v, R, c, i, lo, hi));
// The last step, broken off over the dark.
const end = R.finish;
if (end < hi + 10) {
const y = Y(R.flights.at(-1)[3]);
// Past it, the Pit's dark: the shaft fades to black, a red pulse far down.
ctx.fillStyle = hgrad(ctx, end, end + 10, [[0, "rgba(2,1,2,0)"], [1, "rgba(2,1,2,0.86)"]]);
ctx.fillRect(end, 0, Math.max(0, hi - end) + 10, FH);
ctx.fillStyle = BONE_DIM;
poly(ctx, [[end - 0.2, y], [end + 1.4, y + 0.6], [end + 0.4, y + 1.6], [end - 0.2, y + BODY]]);
ctx.fill();
}
// The cellar landing at the top and the Pit's floor, over the shaft.
for (const [a, b, top] of v.spec.ground) if (b > lo && a < hi) ground(ctx, v, LOOKS.bonestair, a, b, top);
// Checkpoints.
R.checks.forEach((x, i) => {
if (x > lo && x < hi) sconce(ctx, v, x, stairY(R, x) ?? 20, i <= c.check);
});
// Shadows of masonry about to fall, and the piles.
R.stones.forEach(([x], i) => {
if (x < lo || x > hi) return;
const s = c.stones[i];
const base = stairY(R, x) ?? 20;
if (s.state === "warn") {
const p = clamp(1 - s.t / STONE_MS, 0, 1);
ctx.globalAlpha = 0.25 + 0.6 * p;
ctx.fillStyle = "#000000";
ctx.beginPath();
ctx.ellipse?.(x, Y(base) - 0.1, 0.8 + 1.6 * p, 0.25 + 0.3 * p, 0, 0, TAU);
ctx.fill();
ctx.globalAlpha = 1;
} else if (s.state === "pile") pile(ctx, x, base, i);
});
// Skeletons up on the stair.
R.skels.forEach(([sx], i) => {
const s = c.skels[i];
if ((s.state !== "climb" && s.state !== "down") || s.x < lo || s.x > hi) return;
const since = v.fx && v.fx.stairDown && v.fx.stairDown[i] !== undefined ? v.fx.clock - v.fx.stairDown[i] : 999;
skeleton(ctx, v, s.x, stairY(R, s.x) ?? 20, 1, i, s.state, s.state === "down" ? since : 0);
});
}
/* -------------------------------------------------------------- in front */
// The central column at a seam: vertebrae stacked floor to roof, in front of YOU.
function column(ctx, v, x) {
const l = x - COL_W / 2;
ctx.fillStyle = hgrad(ctx, l - 2, l + COL_W + 2, [[0, "rgba(0,0,0,0)"], [0.2, "#1a1210"], [0.5, "#3a2e26"], [0.8, "#1a1210"], [1, "rgba(0,0,0,0)"]]);
ctx.fillRect(l - 2, 0, COL_W + 4, FH);
for (let k = 0; k < FH / 2.6 + 1; k++) {
const y = k * 2.6;
ctx.fillStyle = k % 2 ? "#b8aa8c" : "#cbbd9c";
ctx.fillRect(l + 1.2, y + 0.2, COL_W - 2.4, 2.0);
// The side processes.
ctx.fillStyle = "#9a8c70";
poly(ctx, [[l + 1.2, y + 0.6], [l - 0.2, y + 1.0], [l + 1.2, y + 1.6]]);
ctx.fill();
poly(ctx, [[l + COL_W - 1.2, y + 0.6], [l + COL_W + 0.2, y + 1.0], [l + COL_W - 1.2, y + 1.6]]);
ctx.fill();
ctx.fillStyle = "rgba(0,0,0,0.35)";
ctx.fillRect(l + 1.2, y + 2.0, COL_W - 2.4, 0.4);
}
ctx.fillStyle = hgrad(ctx, l, l + COL_W, [[0, "rgba(0,0,0,0.45)"], [0.5, "rgba(0,0,0,0)"], [1, "rgba(0,0,0,0.55)"]]);
ctx.fillRect(l, 0, COL_W, FH);
}
// A ribcage hanging on a chain, its lowest rib at `under`.
function ribcage(ctx, v, x, under, i) {
const sway = Math.sin(v.clock / 520 + i * 1.7) * 0.25;
const bottom = Y(under);
const top = bottom - 5.2;
ctx.strokeStyle = "#5a5048";
ctx.lineWidth = 0.22;
seg(ctx, x, 0, x + sway, top);
ctx.strokeStyle = BONE;
ctx.lineWidth = 0.42;
seg(ctx, x + sway, top, x + sway, bottom - 0.4);
ctx.lineWidth = 0.3;
for (let r = 0; r < 5; r++) {
const ry = top + 0.8 + r * 0.95;
const w = RIB_W / 2 - Math.abs(r - 2.4) * 0.25;
ctx.beginPath();
ctx.moveTo(x + sway, ry);
ctx.quadraticCurveTo(x + sway - w * 1.1, ry + 0.3, x + sway - w * 0.7, ry + 1.0);
ctx.moveTo(x + sway, ry);
ctx.quadraticCurveTo(x + sway + w * 1.1, ry + 0.3, x + sway + w * 0.7, ry + 1.0);
ctx.stroke();
}
ctx.fillStyle = BONE;
ctx.fillRect(x + sway - 0.9, bottom - 0.5, 1.8, 0.5);
}
// A bone hand at the rail: its wrist up from under the tread's edge, a palm, four long fingers
// (splayed and twitching while it reaches, curled down over the tread as it grabs), outlined dark.
function hand(ctx, v, x, base, state, t, i) {
const y = Y(base);
const p = state === "reach" ? clamp(1 - t / HAND_WARN_MS, 0, 1) : 1;
const closed = state === "grab" ? clamp(1 - t / HAND_GRAB_MS, 0, 1) : state === "hold" ? 1 : 0;
glow(ctx, "190,220,255", x, y - 1.4, 6, 0.18 + 0.22 * p);
ctx.save();
// Rising from below while it reaches; up to its full height (HAND_H and a little) to grab.
ctx.translate(x, y + (1 - p) * 2.6);
ctx.lineCap = "round";
ctx.lineJoin = "round";
const top = -(HAND_H + 0.5);
const palm = [HAND_W / 2 - 0.3, top + 1.4];
for (const [w, col] of [[0.95, "rgba(10,6,8,0.85)"], [0.5, "#efe6d0"]]) {
ctx.strokeStyle = col;
ctx.lineWidth = w;
// The wrist and forearm.
seg(ctx, HAND_W / 2 + 0.7, 2.6, palm[0], palm[1]);
ctx.lineWidth = w * 0.78;
for (let f = 0; f < 4; f++) {
const twitch = state === "reach" ? Math.sin(v.clock / 70 + f * 1.3) * 0.25 : 0;
const kx = palm[0] - 0.4 - f * 0.55;
const ky = top + 0.1 + f * 0.22 + twitch;
const tx = kx - 0.9 - closed * 0.2;
const ty = ky + 0.5 + closed * 1.4;
seg(ctx, palm[0], palm[1], kx, ky);
seg(ctx, kx, ky, tx, ty);
}
// The thumb.
seg(ctx, palm[0], palm[1], palm[0] - 0.5, palm[1] + 0.9);
}
ctx.fillStyle = "#efe6d0";
disc(ctx, palm[0], palm[1], 0.55);
ctx.restore();
}
// The wall of rubble coming down the stair behind YOU, its face at x.
function rubbleWall(ctx, v, R, c, cam, face) {
const clock = v.clock;
if (face < cam - 6) return;
ctx.fillStyle = hgrad(ctx, face - 14, face + 3, [[0, "#0c0808"], [0.7, "#241a18"], [1, "rgba(36,26,24,0)"]]);
ctx.fillRect(cam - 2, 0, face - cam + 5, FH);
// Blocks tumbling down its face, beams and bones among them.
for (let k = 0; k < 26; k++) {
const speed = 0.02 + rnd(k, 1) * 0.02;
const yy = ((rnd(k, 2) * FH + clock * speed) % (FH + 8)) - 4;
const xx = face - 1 - rnd(k, 3) * 10 + Math.sin(clock / 300 + k) * 0.5;
if (xx < cam - 4) continue;
const w = 1.2 + rnd(k, 4) * 2.2;
ctx.save();
ctx.translate(xx, yy);
ctx.rotate(clock / (200 + rnd(k, 5) * 300) + k);
ctx.fillStyle = k % 5 === 0 ? "#6a4a2a" : k % 7 === 0 ? BONE_DIM : k % 2 ? "#5a5050" : "#463c3a";
if (k % 5 === 0) ctx.fillRect(-w, -0.25, w * 2, 0.5);
else ctx.fillRect(-w / 2, -w / 2, w, w * 0.8);
ctx.restore();
}
// The dust it throws ahead.
ctx.fillStyle = rgrad(ctx, face, FH * 0.6, 14, [[0, "rgba(150,130,110,0.4)"], [1, "rgba(150,130,110,0)"]]);
ctx.fillRect(face - 14, FH * 0.6 - 14, 28, 28);
const near = clamp(1 - c.gap / GAP_MAX, 0, 1);
if (near > 0.5) {
ctx.globalAlpha = (near - 0.5) * 1.2 * (0.6 + 0.4 * Math.sin(clock / 90));
ctx.fillStyle = hgrad(ctx, cam, cam + 30, [[0, "rgba(255,60,30,0.5)"], [1, "rgba(255,60,30,0)"]]);
ctx.fillRect(cam, 0, 30, FH);
ctx.globalAlpha = 1;
}
}
// A see-through glyph over an obstacle: chevrons and (for the first few) the word.
function glyph(ctx, v, t) {
const col = ANSWER_COLORS[t.answer];
const dir = t.answer === "DUCK" ? 1 : t.answer === "JUMP" ? -1 : 0;
const pulse = 0.85 + 0.15 * Math.sin(v.clock / 260 + t.lead);
const cy = Math.max(9, 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";
for (const [w, cc] of [[1.3, "rgba(4,4,16,0.8)"], [0.6, col]]) {
ctx.strokeStyle = cc;
ctx.lineWidth = w;
if (dir) {
const ay = cy + 2.6 * -dir * -1;
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();
}
} else if (t.answer === "SHOOT") {
// A crosshair.
ctx.beginPath();
ctx.arc(t.x, cy + 2.6, 1.4, 0, TAU);
ctx.stroke();
seg(ctx, t.x - 2.2, cy + 2.6, t.x + 2.2, cy + 2.6);
seg(ctx, t.x, cy + 0.4, t.x, cy + 4.8);
} else {
// RUN: chevrons pointing on down the stair.
for (let k = 0; k < 2; k++) {
const ox = t.x - 1 + k * 1.6;
ctx.beginPath();
ctx.moveTo(ox - 0.9, cy + 1.0);
ctx.lineTo(ox + 0.9, cy + 2.6);
ctx.lineTo(ox - 0.9, cy + 4.2);
ctx.stroke();
}
}
}
if (t.words) label(ctx, t.answer, t.x, cy + (dir === 1 ? -1.2 : dir === -1 ? 1.2 : -1.2), 2.3, col, "center");
ctx.restore();
}
// The collapse's meter along the top left: how near it is, red as it closes.
function meter(ctx, v, c, cam) {
// High in the shaft, over the stair's rail at its highest and over YOU.
const x = cam + 4;
const y = 2.2;
const w = 34;
const near = clamp(1 - c.gap / GAP_MAX, 0, 1);
ctx.fillStyle = "rgba(6,4,10,0.62)";
ctx.fillRect(x - 0.8, y - 0.8, w + 1.6, 2.6);
ctx.fillStyle = "#1c1618";
ctx.fillRect(x, y, w, 1);
ctx.fillStyle = near < 0.35 ? "#6ee08a" : near < 0.62 ? "#ffc23a" : "#ff4a3a";
ctx.fillRect(x, y, w * near, 1);
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 - CLOSE_ON / GAP_MAX), y - 0.2, 0.18, 1.4);
const close = c.gap < CLOSE_ON;
label(ctx, close ? "IT IS RIGHT BEHIND YOU" : "THE HOUSE IS COMING DOWN", x, y + 3.1, 1.7, close ? (Math.sin(v.clock / 110) > 0 ? "#ff6a4a" : "#ffd25a") : "#d8d0c8", "left");
// A tumbling block at the meter's tip.
ctx.save();
ctx.translate(x + w * near, y + 0.5);
ctx.rotate(v.clock / 260);
ctx.fillStyle = "#8a7e74";
ctx.fillRect(-0.7, -0.7, 1.4, 1.4);
ctx.restore();
}
function front(ctx, v) {
const [R, c] = mine(v);
if (!R) return;
FH = v.g.FIELD_H;
const round = v.round;
const cam = Math.round(round.camX * 8) / 8;
const lo = cam - 8;
const hi = cam + FW + 8;
R.ribs.forEach(([x, under], i) => {
if (x > lo - 4 && x < hi + 4) ribcage(ctx, v, x, under, i);
});
R.hands.forEach(([x], i) => {
const h = c.hands[i];
if (x < lo || x > hi || h.state === "wait" || h.state === "gone") return;
hand(ctx, v, x, stairY(R, x) ?? 20, h.state, h.t, i);
});
// Masonry on its way down.
R.stones.forEach(([x], i) => {
const s = c.stones[i];
if (s.state !== "warn" || x < lo || x > hi) return;
const base = stairY(R, x) ?? 20;
const drop = stoneDrop(s.t);
if (drop !== null) block(ctx, x, base + drop, drop * 0.05, i);
// Grit trickling from above as it works loose.
const p = clamp(1 - s.t / STONE_MS, 0, 1);
ctx.fillStyle = "rgba(200,180,150,0.6)";
for (let k = 0; k < 6; k++) {
const yy = (((v.clock * 0.03 + k * 9) % 40) / 40) * Y(base);
ctx.fillRect(x - 0.8 + rnd(k, i) * 1.6, yy, 0.18, 0.5 + p);
}
});
// The columns at every turn of the spiral, in front of YOU.
for (const s of seams(R)) if (s.x > lo - COL_W && s.x < hi + COL_W) column(ctx, v, s.x);
if (!c.done) {
for (const t of telegraphs(R, round.you.x)) glyph(ctx, v, t);
const fx = v.fx || {};
fx.stairGap = fx.stairGap === undefined ? c.gap : fx.stairGap + (c.gap - fx.stairGap) * 0.22;
rubbleWall(ctx, v, R, c, cam, round.you.x - fx.stairGap);
meter(ctx, v, c, cam);
}
// Bits from a crash, tumbling.
const bits = v.fx && v.fx.stairBits;
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.15, b.w, 0.3);
ctx.restore();
}
ctx.globalAlpha = 1;
}
}
const dim = () => 0;
/* -------------------------------------------------------------- lights */
function lights(v, add) {
const [R, c] = mine(v);
if (!R) return;
const round = v.round;
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);
R.checks.forEach((x, i) => {
if (x > lo && x < hi && i <= c.check) add(x, (stairY(R, x) ?? 20) + 9, 8, 0.6);
});
R.skels.forEach(([x], i) => {
const s = c.skels[i];
if ((s.state === "rise" || s.state === "climb") && s.x > lo && s.x < hi) add(s.x, (stairY(R, s.x) ?? 20) + 4.5, 4, 0.4);
});
}
/* -------------------------------------------------------------- events */
function gateOnce(fx, key, ms) {
if ((fx[key] || 0) > fx.clock) return false;
fx[key] = fx.clock + ms;
return true;
}
function splinter(fx, x, y, colors) {
fx.stairBits = (fx.stairBits || []).filter((b) => fx.clock - b.t0 < 1000);
for (let k = 0; k < 10; k++) fx.stairBits.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 sound 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 === "stairLand" && !gateOnce(fx, "stairLandMs", 120)) return true;
d.say(tone, voice[0], voice[1], 0.5);
switch (e.type) {
case "stairJump":
burst(e.x, e.y, "#c8bca0", 4, 6, 260);
break;
case "stairLand":
burst(e.x, e.y, "#c8bca0", e.big ? 10 : 5, 7, 320);
break;
case "stairCrash":
shake(320, 1);
flash("#ffe0c0", 200);
burst(e.x, e.y + 1, "#e2d6b8", 16, 16, 520);
splinter(fx, e.x, e.y + 1, [BONE, BONE_DIM, "#6e625a"]);
break;
case "stairDrop":
shake(260, 0.8);
burst(e.x, e.y, "#a89a80", 12, 10, 420);
float(e.x, e.y + 6, e.cause === "stairGive" ? "It gave way!" : "Mind the gap!", "#ff8a6a", 2.2);
break;
case "stairCheck":
float(e.x, e.y + 6, "Checkpoint", GOLD, 2.2);
ring(e.x, e.y + 3, "#ffd27a", 1, 8, 500);
break;
case "stairTurn":
break;
case "stairEdge":
float(e.x, e.y + 6, "Down you go!", GOLD, 2.4);
break;
case "stairFinish":
shake(300, 0.9);
flash("#801818", 260);
burst(e.x, e.y, "#3a1414", 18, 12, 560);
float(e.x, e.y + 6, "Into the dark", "#ff9a7a", 2.6);
break;
case "stairClose":
float(e.x, e.y + 7, "Faster!", "#ff8a5a", 2.2);
break;
case "stairCatch":
shake(420, 1.3);
flash("#c8b8a0", 260);
float(e.x, e.y + 7, "It caught you!", "#ff6a4a", 2.4);
break;
case "stairRot":
shake(180, 0.4);
burst(e.x, e.y, "#a8c080", 8, 6, 400);
break;
case "stairRise":
burst(e.x, e.y, "#e2d6b8", 6, 6, 360);
break;
case "stairSkelHit":
burst(e.x, e.y, BONE, 6, 8, 280);
break;
case "stairSkelDown": {
fx.stairDown = { ...(fx.stairDown || {}), [e.n]: fx.clock };
burst(e.x, e.y, BONE, 14, 13, 460);
splinter(fx, e.x, e.y, [BONE, BONE_DIM]);
float(e.x, e.y + 3, `+${e.points}`, GOLD, 2);
break;
}
case "stairReach":
burst(e.x, e.y, "#c8d8e8", 4, 4, 300);
break;
case "stairGrab":
burst(e.x, e.y + 1, BONE, 5, 5, 260);
break;
case "stairCreak":
burst(e.x, e.y + 30, "#c8b8a0", 5, 5, 600);
break;
case "stairCrack":
shake(140, 0.3);
break;
case "stairThud":
shake(240, 0.8);
burst(e.x, e.y + 0.5, "#8a7e74", 14, 10, 460);
break;
default:
break;
}
return true;
}
return freeze({
looks: LOOKS,
backdrop,
ground,
shelf,
front,
moving,
dim,
monsters: freeze({}),
bosses: freeze({}),
missiles: freeze({}),
hazards: freeze({}),
waves: freeze({}),
powers: freeze({}),
lights,
react,
});
}
@@ -0,0 +1,49 @@
// Plan2Code Web Console - Ghoul Rush's finale, the room for the finale's second ride, down The Bone Stair ahead of the collapse: data only, no imports. core/ghoul-rooms.js builds it through its room() helper and lists it in FINALE.rooms only once `ready` is true.
//
// The Bone Stair, the finale's second BONUS ROUND (see ghoul-bonestair.js and core/ghoul-bonus.js): a run, not a
// walk. After Kill II the House sinks into its cellar and a stairway of bones opens at the door. YOU run down
// an endless spiral stair of bones, about 30 seconds of it at RUN_V, with the house collapsing after YOU: 9
// flights wound round a column of vertebrae, 4 stretches of missing treads to jump, 3 stretches
// that give way under YOU (keep running), 3 hanging ribcages to duck, 4 skeletons climbing up
// at YOU (shoot them), 3 bone hands grabbing at the rail (jump them), 3 blocks of falling masonry
// with their shadows (jump the pile), 3 checkpoints, and off the last step into the Pit's dark.
// Three hearts of its own (`ride.hearts`). No candy and no pickups. The numbers are made by
// prototypes/ghoul-rush-tools/gen-bonestair.mjs.
export const BONESTAIR_ROOM = Object.freeze({
ready: true,
id: "bonestair",
title: "The Bone Stair",
sub: "Every step down is someone",
// The room's spec, in the shape room() in core/ghoul-rooms.js takes.
spec: {
length: 1294,
ground: [[0, 20, 36], [1242, 1294, 6]],
start: 8,
key: null,
door: 1284,
bonus: true,
dark: false,
candy: [],
items: [],
spawns: [],
horde: [],
ride: {
runner: "bonestair",
hearts: 3,
time: 70000,
finish: 1242,
how: "UP jump, DOWN duck, hold SPACE to shoot. Never stop: the house is coming down after YOU",
top: [0, 20, 36],
flights: [[20, 160, 36, 14], [160, 300, 36, 14], [300, 440, 36, 14], [440, 580, 36, 14], [580, 720, 36, 14], [720, 860, 36, 14], [860, 1000, 36, 14], [1000, 1140, 36, 14], [1140, 1242, 36, 20]],
gaps: [[60, 67], [476, 484], [772, 779], [1070, 1078]],
rot: [[366, 414], [746, 802], [1196, 1232]],
ribs: [[112, 25.1], [528, 25.8], [896, 33.9]],
skels: [[352], [628], [958], [1182]],
hands: [[198], [672], [1110]],
stones: [[252], [830], [1038]],
surge: [[1000, 1242, 4]],
checks: [312, 592, 872],
},
},
});
@@ -0,0 +1,650 @@
// Plan2Code Web Console - Ghoul Rush's finale, its rules for the finale's second ride, down The Bone Stair ahead of the collapse, as a pack core/ghoul-tables.js lists in PACKS. "Every step down is someone": after Kill II the House sinks into its cellar and a stairway of bones opens at the door. YOU run down an endless spiral stair made of bones while the house comes down after YOU: jump the missing treads and the piles of fallen masonry, duck the hanging ribcages, jump the bone hands that grab at the rail, shoot (or jump) the skeletons climbing up at YOU, and never stop where the treads give way. At the bottom YOU run off the last step into the Pit's dark.
//
// Modeled on the Torch Mob (rides/wagon/ghoul-wagon.js: read its header first) and, like it,
// handed a kit `k` of the game's own helpers, so this file imports nothing. Pack fields used:
// `ride` (a hook that moves YOU, so no key walks YOU), `place` (YOU put down in the room: a room
// set up or a respawn) and `target` (a bolt strikes something that is no monster: a skeleton).
// 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` "bonestair"). It plays for 3 hearts (`ride.hearts`), not 5.
//
// THE TWIST: THE COLLAPSE BEHIND YOU. A wall of rubble comes down the stair after YOU, `gap`
// units back (GAP_START at the start, never over GAP_MAX). It falls at RUBBLE_V (more in the
// `surge` spans), YOU run at RUN_V, so a clean run wins ground and everything else loses it:
// DOWN (a duck: DUCK_V) and LEFT (holding back: HOLD_V) slow YOU, a hit stumbles YOU (STUMBLE_V,
// then back up to speed) and shoves the rubble HIT_CLOSE closer, a bone hand holds YOU still for
// HELD_MS. At CATCH_GAP it has YOU: a heart (cause "stairRubble"), and it falls back to GAP_RESET.
// The treads also GIVE WAY in stretches (`rot`): once YOU are ROT_LEAD into one, it crumbles
// from its top end down after YOU at ROT_V, faster than a duck or a hold and slower than a run,
// so stopping there drops YOU through (cause "stairGive").
//
// THE SPIRAL. The stair is a run of FLIGHTS, each a straight descent; where one ends the next
// begins at the same x, high again: the stair has wound once round its central column (the art
// stands a column of vertebrae over every seam, in front of YOU). Crossing a seam lifts YOU (and
// a bolt) by the flight's height, so the field never runs out of room going down.
//
// THE ROOM (spec.ride, see rides/bonestair/ghoul-bonestair-room.js; made by
// prototypes/ghoul-rush-tools/gen-bonestair.mjs):
//
// - `flights` [x0, x1, yTop, yBottom]: each flight's line (YOUR feet ride its nosings), x
// rising, each next one starting where the last ended. `top` [x0, x1, y] is the cellar
// landing YOU start on, before the first flight. The last flight ends at `finish`, in the air
// over the Pit's floor (the room's last `ground` piece), lower: run off it and land there.
// - `gaps` [x0, x1]: MISSING TREADS (jump: run off the edge and YOU drop through, a heart,
// cause "stairGap", then YOU are put back on the treads past it).
// - `rot` [x0, x1]: treads that GIVE WAY (keep running; above).
// - `ribs` [x, y]: a HANGING RIBCAGE, RIB_W wide, its underside at y, from there up: DUCK it
// (y sits between a ducked box and a standing one along its whole width; cause "stairRib").
// - `skels` [x]: a SKELETON CLIMBING UP at YOU: once YOU are SKEL_NEAR short it pulls itself
// up over the treads (SKEL_RISE_MS), then climbs the stair toward YOU at SKEL_V, SKEL_W by
// SKEL_H: SHOOT it (SKEL_HP bolts: an act) or jump it (cause "stairSkel").
// - `hands` [x]: a BONE HAND at the rail: once YOU are HAND_NEAR short its fingers creep up
// over the tread's edge (HAND_WARN_MS), then it grabs across the tread for HAND_GRAB_MS,
// HAND_W by HAND_H: JUMP it (a grab is a heart and holds YOU HELD_MS; cause "stairHand").
// - `stones` [x]: FALLING MASONRY from the collapse: once YOU are STONE_NEAR short a shadow
// grows on the tread for STONE_MS (a creak at its start, a crack halfway: two audible steps),
// then the block lands (under it is a heart) and lies there as a pile, PILE_W by PILE_H:
// JUMP it (cause "stairStone").
// - `surge` [x0, x1, extra]: spans where the rubble falls faster. `checks`, `finish`, `time`
// (the room's clock, ms), `hearts` (3) and `how` (the controls line).
//
// YOU (`round.runner`): { id, room, v, check, done, gap, close, catches, heldMs, coyote,
// flight, rot: [{ state "wait"|"go"|"done", front }], skels: [{ state "wait"|"rise"|"climb"|
// "down"|"smashed"|"gone", t, x, hp }], hands: [{ state "wait"|"reach"|"grab"|"hold"|"gone",
// t }], stones: [{ state "wait"|"warn"|"pile"|"smashed", t, cracked }], clock, gapMs, gapSum }.
// YOU run at (you.x, you.y), facing right (`you.state` "run" on the treads, "air" off them,
// `you.ducking` ducked). Up jumps (STAIR_JUMP_V against STAIR_G: about 7 high, and longer on
// the way down the stair), COYOTE_MS of grace off an edge. A bolt flies parallel to the stair.
//
// A hit costs one of the round's three hearts (core/ghoul-bonus.js), not a life, and the run
// goes on, YOU blinking safe BONUS_SAFE_MS; the last heart gone ends the round with nothing
// ("BONUS LOST", no dice) and the run carries on into the Pit. 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 skeleton down is an act (ACTS_GOAL is every one of them). The
// steady die is the collapse kept far: the gap's average over the run at least STEADY_GAP.
//
// WHAT THE ART READS: `spec.ride` (above), `round.runner` (above), `round.you`, the events in
// EVENTS, and the helpers exported here (stairY, flightAt, seams, stoneDrop, ribUnder).
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([
"stairJump", "stairLand", "stairCrash", "stairDrop", "stairCheck", "stairTurn", "stairEdge", "stairFinish",
"stairClose", "stairCatch", "stairRot", "stairRise", "stairSkelHit", "stairSkelDown", "stairReach", "stairGrab",
"stairCreak", "stairCrack", "stairThud",
]);
// Every cause a heart can be lost to here.
export const CAUSES = freeze(["stairGap", "stairGive", "stairRib", "stairSkel", "stairHand", "stairStone", "stairRubble"]);
// Running. Speeds are units across a second, STAIR_G units a second squared.
export const RUN_V = 42;
export const DUCK_V = 30;
export const HOLD_V = 22;
export const STUMBLE_V = 24;
export const RELAX = 4;
export const STAIR_JUMP_V = 46;
export const STAIR_G = 150;
export const COYOTE_MS = 90;
export const LAND_TOL = 0.9;
// How far under the treads YOU may drop before it is a fall (the far edge of a gap is a wall).
export const FALL_DEPTH = 3.5;
// The camera sits this far behind its usual spot, so the rubble shows at the left.
export const CAM_LEAD = -12;
// How far in front of YOU YOUR shins meet a pile or a skeleton.
export const REACH = 1.5;
// The collapse behind YOU.
export const RUBBLE_V = 38;
export const GAP_START = 20;
export const GAP_MAX = 28;
export const GAP_RESET = 15;
export const CATCH_GAP = 4;
export const CLOSE_ON = 10;
export const CLOSE_OFF = 14;
export const HIT_CLOSE = 6;
export const STEADY_GAP = 17;
// Treads that give way.
export const ROT_LEAD = 4;
export const ROT_V = 36;
export const ROT_GRACE = 0.6;
// Hanging ribcages.
export const RIB_W = 5;
// Skeletons climbing up.
export const SKEL_NEAR = 66;
export const SKEL_RISE_MS = 700;
export const SKEL_V = 8;
export const SKEL_W = 2.6;
export const SKEL_H = 5;
export const SKEL_HP = 2;
export const SKEL_POINTS = 120;
// Bone hands at the rail.
export const HAND_NEAR = 56;
export const HAND_WARN_MS = 800;
export const HAND_GRAB_MS = 900;
export const HAND_W = 3;
export const HAND_H = 2.2;
export const HELD_MS = 300;
// Falling masonry.
export const STONE_NEAR = 72;
export const STONE_MS = 1300;
export const STONE_FALL_MS = 260;
export const STONE_FALL_H = 34;
export const PILE_W = 3.2;
export const PILE_H = 2.6;
const BOLT_R = 0.5;
// 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 stair */
// The flight covering x (its index), or -1 before the first and past the last.
export function flightAt(R, x) {
const F = R.flights;
if (x < F[0][0] || x > F[F.length - 1][1]) return -1;
for (let i = 0; i < F.length; i++) if (x < F[i][1] || i === F.length - 1) return i;
return F.length - 1;
}
// The height of the stair's line at x (the landing before the first flight), or null past the last.
export function stairY(R, x) {
if (R.top && x >= R.top[0] && x < R.flights[0][0]) return R.top[2];
const i = flightAt(R, x);
if (i < 0) return null;
const [x0, x1, y0, y1] = R.flights[i];
return y0 + ((y1 - y0) * (x - x0)) / (x1 - x0);
}
// The stair's slope at x (rise over run; 0 on the landing).
export function slopeAt(R, x) {
const i = flightAt(R, x);
if (i < 0) return 0;
const [x0, x1, y0, y1] = R.flights[i];
return (y1 - y0) / (x1 - x0);
}
// Each seam where the stair winds round its column: { x, rise } (how far up the next flight begins).
const SEAMS = new WeakMap();
export function seams(R) {
let s = SEAMS.get(R);
if (!s) {
s = [];
for (let i = 0; i + 1 < R.flights.length; i++) s.push(freeze({ x: R.flights[i][1], rise: R.flights[i + 1][2] - R.flights[i][3], n: i + 1 }));
s = freeze(s);
SEAMS.set(R, s);
}
return s;
}
// How far up a thing moving from x0 to x1 is lifted by the seams it crosses.
function liftBetween(R, x0, x1) {
let up = 0;
for (const s of seams(R)) if (x0 < s.x && x1 >= s.x) up += s.rise;
return up;
}
// A ribcage's underside at its x, from its row.
export const ribUnder = (rib) => rib[1];
// The surge's extra speed at x.
export function surgeAt(R, x) {
for (const [x0, x1, extra] of R.surge || []) if (x >= x0 && x <= x1) return extra;
return 0;
}
// Footing at x: the stair's line, or null over a gap, a stretch given way, or past the end.
function foot(R, c, x) {
const y = stairY(R, x);
if (y === null) return null;
for (const [x0, x1] of R.gaps) if (x > x0 && x < x1) return null;
if (c) {
for (const [i, [x0, x1]] of R.rot.entries()) {
const r = c.rot[i];
if (r.state !== "wait" && x >= x0 && x <= x1 && x < r.front) return null;
}
}
return y;
}
// Where a stone dropping on x is, `t` ms from landing (its bottom's height over the tread;
// null before it has begun to fall): the art and the rules read the same fall.
export function stoneDrop(t) {
if (t > STONE_FALL_MS) return null;
const p = Math.max(0, t) / STONE_FALL_MS;
return STONE_FALL_H * p * p;
}
/* -------------------------------------------------------------- placing */
// A fresh set of the room's things: every skeleton waiting under the treads, every hand still.
function things(R) {
return {
rot: R.rot.map(([x0]) => ({ state: "wait", front: x0 })),
skels: R.skels.map(([x]) => ({ state: "wait", t: 0, x, hp: SKEL_HP })),
hands: R.hands.map(() => ({ state: "wait", t: 0 })),
stones: R.stones.map(() => ({ state: "wait", t: 0, cracked: false })),
};
}
// YOU put down in the room: on the cellar landing at the start of the run, 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 !== "bonestair") {
if (round.runner && round.runner.id === "bonestair") round.runner = null;
return;
}
const again = round.runner && round.runner.id === "bonestair" && 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 y = stairY(R, x);
Object.assign(you, { x, y: y ?? you.y, vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 });
round.runner = { id: "bonestair", room: round.room, check, v: RUN_V, done: false, gap: GAP_START, close: false, catches: again ? round.runner.catches : 0, heldMs: 0, coyote: 0, flight: Math.max(0, flightAt(R, x)), clock: 0, gapMs: 0, gapSum: 0, from: you.y, ...things(R) };
round.camLead = CAM_LEAD;
const b = round.bonusRound;
if (b && !b.perf.total) {
b.perf.total = R.gaps.length + R.rot.length + R.ribs.length + R.skels.length + R.hands.length + R.stones.length;
b.perf.steady = true;
b.perf.goal = ACTS_GOAL(R);
}
}
// Every skeleton shot down is worth the die.
export const ACTS_GOAL = (R) => R.skels.length;
/* ------------------------------------------------------------- the run */
// After a fall that cost a heart but not the run: back onto the treads at the first solid
// footing ahead (past the gap, past a stretch that gave way), at RUN_V.
function reseat(round, c, R) {
const you = round.you;
let x = you.x;
for (let guard = 0; guard < 8; guard++) {
const g = R.gaps.find(([x0, x1]) => x > x0 - 0.5 && x < x1 + 0.5);
if (g) {
x = g[1] + 2;
continue;
}
const ri = R.rot.findIndex(([x0, x1], i) => c.rot[i].state !== "wait" && x >= x0 - 0.5 && x <= x1 + 0.5);
if (ri >= 0) {
x = R.rot[ri][1] + 2;
continue;
}
break;
}
x = Math.min(x, R.finish - 2);
const y = stairY(R, x) ?? you.y;
Object.assign(you, { x, y, vy: 0, state: "run", shelf: -1, ducking: false, coyote: 0, drop: -1 });
Object.assign(c, { v: RUN_V, coyote: 0, from: y, flight: Math.max(0, flightAt(R, x)) });
}
// The grade's steady die: the collapse kept far, the gap's average over the run 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 run's motion for one slice. Returns true once it has moved YOU (every slice of the
// run); false outside the room and once YOU are down on the Pit's floor.
function ride(round, ms, k) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "bonestair" || !c || c.id !== "bonestair" || 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 Pit's floor (set there, or past the end some other way): the run is over.
const floor = k.groundAt(round.spec, you.x);
if (you.x >= R.finish && you.vy <= 0 && you.y <= floor + 0.01) return finish(round, c, floor);
const want = inp.jump > 0;
const px = you.x;
if (you.state === "run") {
const held = c.heldMs > 0;
c.heldMs = Math.max(0, c.heldMs - ms);
const duck = Boolean(inp.down) && !want && !held;
const hold = Boolean(inp.left) && !want && !held;
you.ducking = duck;
const target = held ? 0 : duck ? DUCK_V : hold ? HOLD_V : RUN_V;
c.v = held ? 0 : c.v + (target - c.v) * Math.min(1, RELAX * dt * (target < c.v ? 2.5 : 1));
if (want && !held) {
inp.jump = 0;
you.vy = STAIR_JUMP_V;
you.state = "air";
you.ducking = false;
c.v = Math.max(c.v, DUCK_V);
c.from = you.y;
ev("stairJump", { v: c.v });
} else {
const nx = you.x + c.v * dt;
const f = foot(R, c, nx);
if (f !== null) {
you.x = nx;
you.y = f;
you.vy = 0;
you.runMs = c.v > 1 ? (you.runMs || 0) + ms : 0;
} else {
// Off an edge: a gap, treads given way, or the last step.
you.x = nx;
you.vy = slopeAt(R, Math.min(px, R.finish - 0.01)) * c.v;
you.state = "air";
you.ducking = false;
c.coyote = COYOTE_MS;
c.from = you.y;
if (nx >= R.finish) ev("stairEdge");
}
}
} else {
// In the air: the speed YOU left with.
c.coyote = Math.max(0, c.coyote - ms);
if (want && c.coyote > 0) {
inp.jump = 0;
c.coyote = 0;
you.vy = STAIR_JUMP_V;
ev("stairJump", { v: c.v });
}
let py = you.y;
you.vy = Math.max(-k.FALL_MAX, you.vy - STAIR_G * dt);
you.x += c.v * dt;
you.y += you.vy * dt;
const up = liftBetween(R, px, you.x);
you.y += up;
py += up;
you.ducking = false;
you.runMs = 0;
if (you.vy <= 0) {
const f = foot(R, c, you.x);
if (f !== null && py >= f - LAND_TOL && you.y <= f) {
you.y = f;
you.vy = 0;
you.state = "run";
ev("stairLand", { big: c.from - f >= 8 });
c.from = f;
} else if (you.x >= R.finish) {
const g = k.groundAt(round.spec, you.x);
if (g > -Infinity && you.y <= g + 0.01) return finish(round, c, 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);
// Round the column: the stair winds on, high again.
for (const s of seams(R)) {
if (px < s.x && you.x >= s.x) {
c.flight = s.n;
ev("stairTurn", { n: s.n });
}
}
// Treads that give way: the crumbling runs down after YOU.
rotting(round, c, R, ms, k);
// Under the treads: a fall through a gap, or through treads that went.
const line = stairY(R, you.x);
if (you.state === "air" && line !== null && you.y < line - FALL_DEPTH) {
const ri = R.rot.findIndex(([x0, x1], i) => c.rot[i].state !== "wait" && you.x >= x0 - 1 && you.x <= x1 + 1);
const gi = R.gaps.findIndex(([x0, x1]) => you.x > x0 - 2 && you.x < x1 + 2);
const cause = ri >= 0 && gi < 0 ? "stairGive" : "stairGap";
noteHit(round, cause === "stairGive" ? `r${ri}` : `g${gi}`);
c.gap = Math.max(CATCH_GAP + 1, c.gap - HIT_CLOSE);
ev("stairDrop", { cause });
if (k.lose(round, cause) && 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("stairCheck", { n: c.check + 1 });
}
steerShots(round, R);
round.camLead = CAM_LEAD;
if (obstacles(round, c, R, ms, k)) return true;
rubble(round, c, R, ms, k);
return true;
}
// The run is over: YOU are down on the Pit's floor, the way on is open.
function finish(round, c, g) {
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: "stairFinish", x: you.x, y: you.y });
return false;
}
// A hit that took a heart: YOU stumble and the rubble closes; the cause is noted for the grade.
function hurt(round, c, k, cause, id, extra, close = HIT_CLOSE) {
if (!k.struck(round, cause)) return false;
noteHit(round, id);
c.gap = Math.max(CATCH_GAP + 1, c.gap - close);
c.v = Math.min(c.v, STUMBLE_V);
round.events.push({ type: "stairCrash", cause, x: round.you.x, y: round.you.y, ...extra });
return true;
}
// The stretches that give way: each starts crumbling once YOU are ROT_LEAD into it, and the
// crumbling runs down it at ROT_V; treads it has passed are gone, so slower than it, YOU drop
// through.
function rotting(round, c, R, ms, k) {
const you = round.you;
R.rot.forEach(([x0, x1], i) => {
const r = c.rot[i];
if (r.state === "wait") {
if (you.x >= x0 + ROT_LEAD && you.x < x1) {
r.state = "go";
r.front = x0;
round.events.push({ type: "stairRot", x: x0, y: stairY(R, x0) ?? you.y, n: i });
}
return;
}
if (r.state !== "go") return;
r.front += ROT_V * (ms / 1000);
// Blinking safe after a heart, the crumbling waits just behind YOU.
if (you.safeMs > 0 && you.x > x0 && you.x < x1) r.front = Math.min(r.front, you.x - ROT_GRACE);
// Once it overtakes YOU the treads ahead are gone too (see foot), so YOU drop through.
if (r.front >= x1) {
r.front = x1;
r.state = "done";
}
});
}
// A bolt flies parallel to the stair under it, whatever way it was aimed (`s.off`), and winds
// round the column with it.
function steerShots(round, R) {
for (const s of round.shots) {
if (s.arm || s.free) continue;
if (s.off === undefined) s.off = s.vy;
// First seen a slice after it was fired: from where it left the blaster.
const from = s.stairX ?? s.x - (s.vx * (s.gone || 0)) / (Math.hypot(s.vx, s.vy) || 1);
s.y += liftBetween(R, from, s.x);
s.stairX = s.x;
s.vy = s.vx * slopeAt(R, s.x) + s.off;
}
}
// What YOU run into: a ribcage, a pile or a falling block, a hand, a skeleton. Returns whether
// it cost a heart.
function obstacles(round, c, R, ms, k) {
const you = round.you;
const hh = duckH(k, you);
const cx = you.x + REACH;
for (const [i, [x, under]] of R.ribs.entries()) {
if (Math.abs(you.x - x) < (RIB_W + k.HIT_W) / 2 && you.y + hh > under && hurt(round, c, k, "stairRib", `b${i}`, { what: "rib", x })) return true;
}
// Masonry: the shadow, the creak, the crack, the drop, the pile.
for (const [i, [x]] of R.stones.entries()) {
const s = c.stones[i];
const base = stairY(R, x) ?? 0;
if (s.state === "wait") {
if (x - you.x < STONE_NEAR && x - you.x > 0) {
Object.assign(s, { state: "warn", t: STONE_MS, cracked: false });
round.events.push({ type: "stairCreak", x, y: base, n: i });
}
continue;
}
if (s.state === "warn") {
s.t -= ms;
if (!s.cracked && s.t <= STONE_MS / 2) {
s.cracked = true;
round.events.push({ type: "stairCrack", x, y: base + 20, n: i });
}
const drop = stoneDrop(s.t);
if (drop !== null && Math.abs(cx - x) < (k.HIT_W + PILE_W) / 2 && you.y < base + drop + PILE_H && you.y + hh > base + drop) {
s.state = "smashed";
if (hurt(round, c, k, "stairStone", `s${i}`, { what: "stone", x })) return true;
continue;
}
if (s.t <= 0) {
s.state = "pile";
round.events.push({ type: "stairThud", x, y: base, n: i });
}
continue;
}
if (s.state === "pile" && Math.abs(cx - x) < 6 && boxHit(k, cx, you, x, base, PILE_W, PILE_H)) {
s.state = "smashed";
if (hurt(round, c, k, "stairStone", `s${i}`, { what: "stone", x })) return true;
}
}
// Hands: fingers over the edge, then the grab.
for (const [i, [x]] of R.hands.entries()) {
const h = c.hands[i];
const base = stairY(R, x) ?? 0;
if (h.state === "wait") {
if (x - you.x < HAND_NEAR && x - you.x > 2) {
Object.assign(h, { state: "reach", t: HAND_WARN_MS });
round.events.push({ type: "stairReach", x, y: base, n: i });
}
} else if (h.state === "reach") {
h.t -= ms;
if (h.t <= 0) {
Object.assign(h, { state: "grab", t: HAND_GRAB_MS });
round.events.push({ type: "stairGrab", x, y: base, n: i });
}
} else if (h.state === "grab") {
h.t -= ms;
if (boxHit(k, you.x, you, x, base, HAND_W, HAND_H) && hurt(round, c, k, "stairHand", `h${i}`, { what: "hand", x }, 0)) {
Object.assign(h, { state: "hold", t: HELD_MS });
c.heldMs = HELD_MS;
c.v = 0;
return true;
}
if (h.t <= 0) h.state = "gone";
} else if (h.state === "hold") {
h.t -= ms;
if (h.t <= 0) h.state = "gone";
}
}
// Skeletons: up over the treads, then up the stair at YOU.
for (const [i, [sx]] of R.skels.entries()) {
const s = c.skels[i];
if (s.state === "wait") {
if (sx - you.x < SKEL_NEAR && sx - you.x > 4) {
Object.assign(s, { state: "rise", t: SKEL_RISE_MS });
round.events.push({ type: "stairRise", x: sx, y: stairY(R, sx) ?? you.y, n: i });
}
continue;
}
if (s.state === "rise") {
s.t -= ms;
if (s.t <= 0) Object.assign(s, { state: "climb", t: 0 });
continue;
}
if (s.state === "climb") {
const fl = R.flights[Math.max(0, flightAt(R, sx))];
s.x = Math.max(fl[0] + 1, s.x - SKEL_V * (ms / 1000));
const y = stairY(R, s.x);
if (y !== null && boxHit(k, cx, you, s.x, y, SKEL_W, SKEL_H) && hurt(round, c, k, "stairSkel", `k${i}`, { what: "skel", x: s.x })) {
s.state = "smashed";
return true;
}
if (s.x < you.x - 30) s.state = "gone";
}
}
return false;
}
// The collapse: its gap, its warning, the grade's steady die, and a catch at CATCH_GAP.
function rubble(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 });
const moving = c.heldMs > 0 ? 0 : c.v;
c.gap = clamp(c.gap + (moving - RUBBLE_V - surgeAt(R, you.x)) * dt, 0, GAP_MAX);
if (!c.close && c.gap < CLOSE_ON) {
c.close = true;
ev("stairClose");
} else if (c.close && c.gap >= CLOSE_OFF) c.close = false;
c.gapMs += ms;
c.gapSum += c.gap * ms;
steadiness(round, c);
if (c.gap > CATCH_GAP) return;
// Blinking safe after a heart, it waits right behind YOU, to have YOU once the blink is over.
if (you.safeMs > 0) {
c.gap = CATCH_GAP;
return;
}
c.gap = GAP_RESET;
c.close = false;
c.catches++;
noteHit(round, `m${c.catches}`);
ev("stairCatch");
k.struck(round, "stairRubble");
}
/* ------------------------------------------------------------- targets */
// A bolt into a skeleton (rising or climbing): SKEL_HP of them knock it down. True when one
// took it (the bolt is spent).
function stairShot(round, s) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "bonestair" || !c || c.id !== "bonestair") return false;
for (let i = 0; i < c.skels.length; i++) {
const sk = c.skels[i];
if (sk.state !== "rise" && sk.state !== "climb") continue;
const y = stairY(R, sk.x);
if (y === null) continue;
// Rising, it is still half under the treads.
const top = y + (sk.state === "rise" ? SKEL_H * (1 - Math.max(0, sk.t) / SKEL_RISE_MS) : SKEL_H);
if (Math.abs(s.x - sk.x) > SKEL_W / 2 + BOLT_R || s.y < y - BOLT_R || s.y > top + BOLT_R) continue;
sk.hp--;
if (sk.hp > 0) round.events.push({ type: "stairSkelHit", x: sk.x, y: y + SKEL_H / 2 });
else {
sk.state = "down";
sk.t = 0;
round.score += SKEL_POINTS;
if (round.bonusRound) round.bonusRound.perf.acts++;
c.gap = Math.min(GAP_MAX, c.gap + 2);
round.events.push({ type: "stairSkelDown", x: sk.x, y: y + SKEL_H / 2, points: SKEL_POINTS, n: i });
}
return true;
}
return false;
}
export const BONESTAIR = freeze({
id: "bonestair",
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
horde: freeze({}),
ride: freeze([ride]),
place: freeze([place]),
target: stairShot,
});
@@ -0,0 +1,247 @@
// Plan2Code Web Console - ghoul: the sounds for the finale's second ride, down The Bone Stair ahead of the collapse, merged into sfx/ghoul-sfx.js; defines only.
//
// Same shape and rules as rides/wagon/ghoul-sfx-wagon.js: `tones` (a `ghoulStair<Act>` sound for the
// stair's things), built from the house's tone layers (no audio files). The user's picks from the
// sound vote (prototypes/sounds/ghoul-rush/bonestair.html). `music`
// holds ghoulMarrowStair, the user's pick (Drum chase), named in ROOM_MUSIC. No tone runs over
// 1.2 s. A name may be defined only once across tones.js and every game's file. No imports.
export const BONESTAIR_SFX = {
tones: {
// YOU on the stair: YOU run down an endless spiral of bones with the House coming down after YOU.
// Jumps: Hop and click.
ghoulStairJump: {
layers: [
{ type: "triangle", from: 380, to: 640, seconds: 0.1, attack: 0.003, gain: 0.4 },
{ type: "noise", seconds: 0.04, attack: 0.003, gain: 0.3, delay: 0.02, filter: { type: "bandpass", from: 3080, to: 2200, q: 5 } },
{ type: "triangle", from: 770, to: 550, seconds: 0.06, attack: 0.003, gain: 0.13, delay: 0.02 },
],
},
// Lands: Dry clack (in game).
ghoulStairLand: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.45, filter: { type: "bandpass", from: 2800, to: 1800, q: 5 } },
{ type: "sine", from: 180, to: 90, seconds: 0.1, attack: 0, gain: 0.4 },
],
},
// Crash: Bones snap (in game).
ghoulStairCrash: {
layers: [
{ type: "sine", from: 110, to: 40, seconds: 0.25, attack: 0, gain: 0.9 },
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 3200, to: 2200, q: 4 } },
{ type: "noise", seconds: 0.04, delay: 0.05, attack: 0, gain: 0.55, filter: { type: "bandpass", from: 2600, to: 1800, q: 4 } },
{ type: "noise", seconds: 0.04, delay: 0.1, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 3600, to: 2400, q: 4 } },
],
},
// Drops through: Falling whistle (in game).
ghoulStairDrop: {
layers: [
{ type: "sine", from: 900, to: 160, seconds: 0.7, attack: 0.02, gain: 0.32 },
{ type: "noise", seconds: 0.6, attack: 0.1, gain: 0.25, filter: { type: "lowpass", from: 2000, to: 300, q: 1 } },
],
},
// Checkpoint: Two bells.
ghoulStairCheck: {
layers: [
{ type: "sine", from: 294, to: 293, seconds: 0.6, attack: 0.003, gain: 0.45 },
{ type: "sine", from: 591, to: 588, seconds: 0.36, attack: 0.003, gain: 0.18 },
{ type: "sine", from: 440, to: 438, seconds: 0.6, attack: 0.003, gain: 0.32, delay: 0.2 },
{ type: "sine", from: 884, to: 880, seconds: 0.36, attack: 0.003, gain: 0.13, delay: 0.2 },
],
},
// Round the column: Whoosh past (in game).
ghoulStairTurn: {
layers: [
{ type: "noise", seconds: 0.35, attack: 0.12, gain: 0.28, filter: { type: "bandpass", from: 500, to: 1400, q: 2 } },
],
},
// Off the last step: Air opens (in game).
ghoulStairEdge: {
layers: [
{ type: "noise", seconds: 1.1, attack: 0.3, gain: 0.4, filter: { type: "lowpass", from: 1800, to: 200, q: 1 } },
{ type: "sine", from: 440, to: 110, seconds: 1, attack: 0.05, gain: 0.25 },
],
},
// Onto the Pit's floor: Boom and heartbeat (in game).
ghoulStairFinish: {
layers: [
{ type: "sine", from: 70, to: 32, seconds: 0.7, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.5, attack: 0, gain: 0.6, filter: { type: "lowpass", from: 300, to: 120, q: 1 } },
{ type: "sine", from: 55, to: 44, seconds: 0.18, delay: 0.7, attack: 0.01, gain: 0.7 },
{ type: "sine", from: 55, to: 44, seconds: 0.18, delay: 0.92, attack: 0.01, gain: 0.55 },
],
},
// Rubble close: Grinding roar (in game).
ghoulStairClose: {
layers: [
{ type: "brown", seconds: 0.8, attack: 0.1, gain: 0.7, filter: { type: "lowpass", from: 400, to: 900, q: 1 } },
{ type: "sawtooth", from: 55, to: 48, seconds: 0.7, attack: 0.1, gain: 0.25, filter: { type: "lowpass", from: 300, to: 300, q: 1 } },
],
},
// Caught: Landslide over YOU (in game).
ghoulStairCatch: {
layers: [
{ type: "sine", from: 80, to: 30, seconds: 0.6, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.9, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 900, to: 200, q: 1 } },
{ type: "noise", seconds: 0.08, delay: 0.1, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1500, to: 900, q: 3 } },
{ type: "noise", seconds: 0.08, delay: 0.3, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 1200, to: 700, q: 3 } },
],
},
// Treads give way: Cracking chain (in game).
ghoulStairRot: {
layers: [
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 3000, to: 2000, q: 5 } },
{ type: "noise", seconds: 0.04, delay: 0.09, attack: 0, gain: 0.45, filter: { type: "bandpass", from: 2600, to: 1700, q: 5 } },
{ type: "noise", seconds: 0.04, delay: 0.17, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 2300, to: 1500, q: 5 } },
{ type: "noise", seconds: 0.04, delay: 0.24, attack: 0, gain: 0.35, filter: { type: "bandpass", from: 2000, to: 1300, q: 5 } },
{ type: "brown", seconds: 0.5, delay: 0.1, attack: 0.1, gain: 0.35, filter: { type: "lowpass", from: 500, to: 200, q: 1 } },
],
},
// Skeleton: A skeleton pulls itself up over the treads and climbs the stair at YOU; two bolts knock it apart.
// Rises: Rattle and hiss (in game).
ghoulStairRise: {
layers: [
{ type: "noise", seconds: 0.5, attack: 0.05, gain: 0.35, filter: { type: "bandpass", from: 3200, to: 2400, q: 6 } },
{ type: "square", from: 140, to: 120, seconds: 0.45, attack: 0.02, gain: 0.08, vibrato: { rate: 28, depth: 0.3 }, filter: { type: "bandpass", from: 900, to: 700, q: 3 } },
],
},
// Hit: Crack (in game).
ghoulStairSkelHit: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 3400, to: 2600, q: 5 } },
{ type: "triangle", from: 900, to: 600, seconds: 0.08, attack: 0, gain: 0.2 },
],
},
// Knocked apart: Clattering down (in game).
ghoulStairSkelDown: {
layers: [
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 3000, to: 2200, q: 5 } },
{ type: "noise", seconds: 0.04, delay: 0.08, attack: 0, gain: 0.45, filter: { type: "bandpass", from: 2400, to: 1800, q: 5 } },
{ type: "noise", seconds: 0.04, delay: 0.15, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 2800, to: 2000, q: 5 } },
{ type: "noise", seconds: 0.04, delay: 0.24, attack: 0, gain: 0.3, filter: { type: "bandpass", from: 2100, to: 1500, q: 5 } },
{ type: "triangle", from: 660, to: 330, seconds: 0.3, attack: 0, gain: 0.15 },
],
},
// Bone hand: A hand of bones creeps up over the rail's edge and grabs across the tread at YOUR ankles.
// Reaches (the warning): Fingers tapping (in game).
ghoulStairReach: {
layers: [
{ type: "noise", seconds: 0.03, attack: 0, gain: 0.35, filter: { type: "bandpass", from: 3600, to: 3000, q: 6 } },
{ type: "noise", seconds: 0.03, delay: 0.12, attack: 0, gain: 0.35, filter: { type: "bandpass", from: 3400, to: 2800, q: 6 } },
{ type: "noise", seconds: 0.03, delay: 0.24, attack: 0, gain: 0.35, filter: { type: "bandpass", from: 3200, to: 2600, q: 6 } },
{ type: "sine", from: 200, to: 260, seconds: 0.5, attack: 0.2, gain: 0.12 },
],
},
// Grabs: Snap shut (in game).
ghoulStairGrab: {
layers: [
{ type: "noise", seconds: 0.06, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 2200, to: 1400, q: 4 } },
{ type: "sine", from: 160, to: 70, seconds: 0.18, attack: 0, gain: 0.5 },
],
},
// Falling masonry: Blocks of the House come loose overhead: a shadow, a creak, a crack, then the block lands on the stair.
// Creaks (warning one): Long creak (in game).
ghoulStairCreak: {
layers: [
{ type: "sawtooth", from: 180, to: 120, seconds: 0.6, attack: 0.08, gain: 0.18, vibrato: { rate: 14, depth: 0.12 }, filter: { type: "bandpass", from: 700, to: 500, q: 5 } },
{ type: "noise", seconds: 0.5, attack: 0.2, gain: 0.15, filter: { type: "bandpass", from: 1800, to: 1200, q: 3 } },
],
},
// Cracks (warning two): Sharp crack (in game).
ghoulStairCrack: {
layers: [
{ type: "noise", seconds: 0.07, attack: 0, gain: 0.65, filter: { type: "bandpass", from: 2400, to: 1200, q: 3 } },
{ type: "sine", from: 300, to: 120, seconds: 0.12, attack: 0, gain: 0.3 },
],
},
// Lands: Thud and grit (in game).
ghoulStairThud: {
layers: [
{ type: "sine", from: 90, to: 34, seconds: 0.35, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.3, attack: 0, gain: 0.6, filter: { type: "lowpass", from: 600, to: 200, q: 1 } },
{ type: "noise", seconds: 0.3, delay: 0.05, attack: 0.05, gain: 0.2, filter: { type: "bandpass", from: 2500, to: 1500, q: 2 } },
],
},
},
music: {
// The Bone Stair: drum chase. An action-movie chase built on the drums: a hard kick and snare drive from bar one,
// brass blasting the heartbeat (low-low, rest) with a pickup run into each new chord, and string chords stabbing
// on the off beats. The runs join in eighths in the second part and in sixteenths in the third, with crashes on
// each downbeat; near full dread a siren climbs a semitone a bar.
ghoulMarrowStair: {
bpm: 170,
rush: 14,
voices: {
drums: { kit: true, gain: 0.24 },
brass: { wave: "square", gain: 0.12, decay: 0.05, sustain: 0.6 },
stab: { wave: "sawtooth", gain: 0.06, decay: 0.02, sustain: 0.2, from: 0.1 },
runs: { wave: "sawtooth", gain: 0.07, decay: 0.03, sustain: 0.7, from: 0.2, vibrato: { rate: 6, depth: 0.006, delay: 0.1 } },
crash: { kit: true, gain: 0.08, from: 0.5 },
siren: { wave: "triangle", gain: 0.06, decay: 0.05, sustain: 0.9, from: 0.85, vibrato: { rate: 5, depth: 0.03 } },
},
patterns: {
A: {
drums:
"k . k . s . . h k . k . s . h h | k . k . s . . h k . k . s . h h | " +
"k . k . s . . h k . k . s . h h | k . k . s . . h k . k . s . h h",
brass:
"D2 . D2 . . . . . D2 . D2 . . . . . | Bb1 . Bb1 . . . . . Bb1 . Bb1 . . . . . | " +
"G1 . G1 . . . . . G1 . G1 . . . . . | A1 . A1 . . . . . A1 . A1 . C#2 E2 G2 A2",
stab:
". . D4^37 . . . D4^37 . . . D4^37 . . . D4^37 . | . . D4^4 . . . D4^4 . . . D4^4 . . . D4^4 . | " +
". . D4^5 . . . D4^5 . . . D4^5 . . . D4^5 . | . . C#4^37 . . . C#4^37 . . . C#4^37 . . . C#4^37 .",
runs:
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
crash:
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
siren:
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
},
B: {
drums:
"k h k h s h h h k h k h s h s h | k h k h s h h h k h k h s h s h | " +
"k h k h s h h h k h k h s h s h | k h k h s h h h k h k h s h s h",
brass:
"D2 . D2 . . . . . D2 . D2 . . . . . | Bb1 . Bb1 . . . . . Bb1 . Bb1 . . . . . | " +
"G1 . G1 . . . . . G1 . G1 . . . . . | A1 . A1 . . . . . A1 . A1 . C#2 E2 G2 A2",
stab:
". . D4^37 . . . D4^37 . . . D4^37 . . . D4^37 . | . . D4^4 . . . D4^4 . . . D4^4 . . . D4^4 . | " +
". . D4^5 . . . D4^5 . . . D4^5 . . . D4^5 . | . . C#4^37 . . . C#4^37 . . . C#4^37 . . . C#4^37 .",
runs:
"D6 - C6 - Bb5 - A5 - G5 - F5 - E5 - D5 - | Bb5 - A5 - G5 - F5 - E5 - D5 - C5 - Bb4 - | " +
"G5 - F5 - E5 - D5 - C#5 - Bb4 - A4 - G4 - | E5 - D5 - C#5 - Bb4 - A4 - G4 - F4 - E4 -",
crash:
"o . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
"o . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
siren:
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
},
C: {
drums:
"ks h k h s h k h ks h k h s s s s | ks h k h s h k h ks h k h s s s s | " +
"ks h k h s h k h ks h k h s s s s | ks h k h s h k h ks h k h s s s s",
brass:
"D2 . D2 . F2 . A2 . D2 . D2 . C2 . A1 . | Bb1 . Bb1 . D2 . F2 . Bb1 . Bb1 . A1 . F1 . | " +
"G1 . G1 . Bb1 . D2 . G1 . G1 . F1 . D1 . | A1 . A1 . C#2 . E2 . A1 . A1 . C#2 E2 G2 A2",
stab:
". D4^37 . D4^37 . D4^37 . D4^37 . D4^37 . D4^37 . D4^37 . D4^37 | . D4^4 . D4^4 . D4^4 . D4^4 . D4^4 . D4^4 . D4^4 . D4^4 | " +
". D4^5 . D4^5 . D4^5 . D4^5 . D4^5 . D4^5 . D4^5 . D4^5 | . C#4^37 . C#4^37 . C#4^37 . C#4^37 . C#4^37 . C#4^37 . C#4^37 . C#4^37",
runs:
"D6 C#6 Bb5 A5 G5 F5 E5 D5 C#5 Bb4 A4 G4 F4 E4 D4 C#4 | Bb5 A5 G5 F5 E5 D5 C#5 Bb4 A4 G4 F4 E4 D4 C#4 Bb3 A3 | " +
"G5 F5 E5 D5 C#5 Bb4 A4 G4 F4 E4 D4 C#4 Bb3 A3 G3 F3 | E6 D6 C#6 Bb5 A5 G5 F5 E5 D5 C#5 Bb4 A4 G4 F4 E4 D4",
crash:
"o . . . . . . . . . . . . . . . | o . . . . . . . . . . . . . . . | " +
"o . . . . . . . . . . . . . . . | o . . . . . . . o . . . . . . .",
siren:
"A5 - - - - - - - - - - - - - - - | Bb5 - - - - - - - - - - - - - - - | " +
"B5 - - - - - - - - - - - - - - - | C#6 - - - - - - - - - - - - - - -",
},
},
order: ["A", "B", "B", "C", "C"],
},
},
};
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,61 @@
// Plan2Code Web Console - Ghoul Rush's finale, the room for the finale's first ride, Down the Hatch: after the House sinks YOU step through its lone front door, and the floor is its throat. Data only, no imports. core/ghoul-rooms.js builds it through its room() helper and lists it in FINALE.rooms once `ready` is true.
//
// A ride, not a walk (see ghoul-mat.js and ghoul-bonus.js): YOU surf the WELCOME mat down the House's
// wet, ribbed gullet, about 30 seconds of it at 46 a second: eleven swallows (a descent and a ridge of
// muscle), rib bones to jump, uvula-lamps to duck, rings of muscle that squeeze down from above (duck
// when the walls throb), three bile stretches that speed YOU up, swallowed furniture to shoot or jump,
// two forks where a hole opens in the floor and YOU jump up to the gristle ledge over it, three
// checkpoints and a lip that spits YOU out onto the cellar floor where the door is. Three hearts of its
// own (`ride.hearts`). The numbers are generated by prototypes/ghoul-rush-tools/gen-mat.mjs: edit that
// and run it with --write, not this.
export const MAT_ROOM = Object.freeze({
ready: true,
id: "mat",
title: "Down the Hatch",
sub: "Wipe your feet",
// The room's spec, in the shape room() in core/ghoul-rooms.js takes.
spec: {
length: 1518,
ground: [[0, 12, 38.4], [1448, 1518, 15.8]],
start: 8,
key: null,
door: 1508,
bonus: true,
dark: false,
candy: [
[40, 40.2, 1], [52, 39, 1], [64, 37.8, 1], [76, 36.6, 1], [100, 34.2, 1], [112, 33, 1], [124, 31.8, 1], [160, 39.4, 1],
[172, 38.2, 1], [208, 34.6, 1], [220, 33.4, 1], [292, 37.4, 1], [304, 36.2, 1], [316, 35, 1], [340, 32.6, 1], [352, 31.4, 1],
[364, 30.2, 1], [376, 29, 1], [428, 42, 1], [438, 41, 1], [448, 40, 1], [458, 39, 1], [468, 38, 1], [478, 37, 1],
[488, 36, 1], [498, 35, 1], [544, 34.6, 1], [556, 33.4, 1], [616, 27.4, 1], [628, 26.2, 1], [676, 32.6, 1], [688, 31.4, 1],
[700, 30.2, 1], [736, 26.6, 1], [748, 25.4, 1], [760, 24.2, 1], [808, 30.6, 1], [844, 27, 1], [856, 25.8, 1], [868, 24.6, 1],
[892, 22.2, 1], [940, 35.6, 1], [950, 34.6, 1], [960, 33.6, 1], [970, 32.6, 1], [980, 31.6, 1], [990, 30.6, 1], [1060, 27.8, 1],
[1072, 26.6, 1], [1108, 23, 1], [1192, 25.8, 1], [1228, 22.2, 1], [1240, 21, 1], [1252, 19.8, 1], [1312, 25, 1], [1360, 20.2, 1],
[1372, 19, 1], [1396, 16.6, 1],
],
items: [],
spawns: [],
horde: [],
ride: {
runner: "mat",
hearts: 3,
rails: 3,
time: 70000,
finish: 1448,
how: "UP jump, DOWN duck, SPACE shoot. Duck when the walls throb",
track: [
[[0, 40], [30, 39], [130, 29], [158, 37.4], [258, 27.4], [286, 35.8], [386, 25.8], [414, 34.2], [444, 31.2]],
[[496, 26], [514, 24.2], [542, 32.6], [642, 22.6], [670, 31], [770, 21], [798, 29.4], [898, 19.4], [926, 27.8], [956, 24.8]],
[[1008, 19.6], [1026, 17.8], [1054, 26.2], [1154, 16.2], [1182, 24.6], [1282, 14.6], [1310, 23], [1410, 13], [1438, 20.8]],
[[422, 40.4], [512, 31.4]],
[[934, 34], [1024, 25]],
],
ribs: [[90, 0], [240, 0], [878, 1], [1089, 2], [1385, 2]],
lows: [[188, 195, 37.6], [1000, 1006, 30.6], [1267, 1274, 19.3]],
squeezes: [[326, 0], [720, 1], [823, 1], [1212, 2]],
furniture: [[597, 1, 0], [1144, 2, 1], [1345, 2, 2]],
bile: [[336, 386], [670, 770], [1054, 1154]],
checks: [380, 780, 1170],
},
},
});
@@ -0,0 +1,541 @@
// Plan2Code Web Console - Ghoul Rush's finale, its rules for the finale's first ride, Down the Hatch: after the House sinks, YOU step through its lone front door and the floor is its throat. YOU surf the WELCOME mat down a wet, ribbed gullet: jump the rib bones, duck the hanging uvula-lamps, duck the rings of muscle that squeeze down from above (the walls throb to warn), ride the bile stretches that speed YOU up, shoot or jump the swallowed furniture that drops in and tumbles at YOU, and jump to the upper rail where the throat forks over a hole. As a pack core/ghoul-tables.js lists in PACKS.
//
// Modeled on the Grand Banister (rides/banister/ghoul-banister.js: read its header first) and,
// like it, handed a kit `k` of the game's own helpers, so this file never imports the game (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 furniture). No monster, boss or hazard kind, and NO
// random number is drawn. Every event, cause and tone is prefixed `mat`.
//
// Its state is the shared bonus-ride slot `round.runner` (null in any other room), and its room
// marks itself with `ride.runner: "mat"` and `ride.hearts: 3` (the finale's rides are short: about
// 30 seconds, three hearts, ghoul-bonus.js's makeBonus reads it).
//
// THE ROOM (spec.ride, rides/mat/ghoul-mat-room.js, made by
// prototypes/ghoul-rush-tools/gen-mat.mjs):
//
// - `track`: polylines [x, y]. The first `rails` of them are the throat's FLOOR, eleven swallows
// (a descent at -0.10 and a short climb at +0.30 over a ridge of muscle, every crest a little
// lower); a gap between two of them is a HOLE where the throat forks (too wide to jump across:
// a fall below DERAIL_Y is a heart, cause "matPlunge"). The lines after those are the UPPER
// RAILS, a ledge of gristle RAIL_SEP over the floor along the length of one descent each,
// over a hole: jump up onto it (a jump lands on the highest line it comes down on) and ride it
// past the hole; off its end YOU drop back onto the floor. The last floor line ends on a lip
// rising at 0.28 (over RAMP_SLOPE, so it launches: RAMP_POP) and the floor of the House's
// cellar begins `finish` further on, lower; flying onto it ends the ride (`matFinish`).
// - `ribs` [x, line] (a rib bone arching up out of the floor, RIB_W by RIB_H: jump), `lows`
// [x0, x1, y] (a uvula hanging from the roof with a swallowed lamp at its tip: its underside
// is y, from there up to the roof, so DUCK it; y is 3.0 over the highest floor under it,
// between a ducked box and a standing one), `squeezes` [x, line] (a ring of muscle SQ_W wide:
// see below), `furniture` [x, line, kind] (kind 0 a chair, 1 a side table, 2 a mantel clock:
// see below), `bile` [x0, x1] (stretches where the mat skids on bile: the speed relaxes to
// BILE_V, not MAT_V), `checks`, `finish`, `time` (the room's clock, ms), `how` and `hearts`.
// - The ground is the front step at the start and the cellar floor at the end only.
//
// PERISTALSIS (the twist): a squeeze waits ("wait") until YOU are SQ_LEAD_MS of riding short
// of it at your speed, then THROBS SQ_WARN_MS ("throb": the walls pulse and gurgle twice, an
// event `matSqueezeThrob` with n 1 at its start and n 2 halfway), CLOSES over SQ_CLOSE_MS
// ("close": its underside comes down from SQ_OPEN to SQ_LOW over the floor, `matSqueezeClose`),
// holds SQ_HOLD_MS ("shut") and eases back up over SQ_EASE_MS ("ease"), then is "done". It is
// shut SQ_EARLY_MS before YOU reach it and long after, so a rider who ducks passes under it;
// standing, or in the air, it is a heart (cause "matSqueeze"). Nothing draws a random number: it
// runs off your approach alone.
//
// FURNITURE: what the House swallowed before YOU. Each waits until YOU are FURN_LEAD_MS of
// riding short of it at your speed, then drops from the roof FURN_DROP_MS ("drop": a shadow on the floor and a creak above,
// `matFurnDrop`), lands (`matFurnLand`) and tumbles up the throat at YOU at FURN_V for up to
// FURN_ROLL_MS ("roll"), FURN_W by FURN_H: jump it, or shoot it, FURN_HP bolts (`matFurnHit`,
// then `matFurnBreak`: an act for the grade). Meeting it is a heart (cause "matFurniture").
//
// YOU (`round.runner`): { id, room, v, line, coyote, from, left, check, done, bile, squeezes,
// furniture, sweet }. You ride at (you.x, you.y), always facing right (`you.state` "run" on the
// floor, "air" off it, `you.ducking` ducked). Speed `v` relaxes to MAT_V (BILE_V on bile, RELAX)
// and is pushed by the slope (SLOPE_G), between MAT_MIN and MAT_MAX. Up jumps at MAT_JUMP_V
// (plus the slope's own rise) against MAT_G (about 13 high, 0.75 s, 34 across at MAT_V),
// COYOTE_MS of grace after running off a line's end; down ducks. A bolt flies parallel to the
// floor under it, so the shooting is level with the throat.
//
// A hit costs one of the round's three 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
// (BONUS LOST, no dice, never a run life), and the run goes on to the next room. A plunge puts
// you back on the throat at MAT_V: on the highest line under you (the ledge over the hole you fell
// into), else on the next floor line ahead.
// Causes: "matRib", "matUvula", "matSqueeze", "matFurniture", "matPlunge". Every obstacle is a
// number for the grade (`perf.total`: ribs, lows, squeezes, furniture and holes, each id once in
// `perf.hits` if it ever cost a heart). Shooting a piece of furniture counts for `perf.acts` (the
// grade's goal is every piece of it) and FURN_POINTS. The grade's `steady` die: "Wipe your
// feet", the souls along the throat taken, at least SWEET_SHARE of them.
//
// Checkpoints are passed at their x (`matCheck`); a restart after the last heart goes back to the
// last one passed (that ends the round, as the banister's does).
//
// WHAT THE ART READS: `spec.ride` (above), `round.runner` { v, line, check, done, bile,
// squeezes: [{ state "wait"|"throb"|"close"|"shut"|"ease"|"done", t (ms left in the state) }],
// furniture: [{ state "wait"|"drop"|"roll"|"broken"|"spent", t, x, hp }] }, `round.you`
// (`state`, `vy`, `ducking`), the events in EVENTS; squeezeLow() and furnitureY() for where
// those are.
import { linesAt, linesOf, slopeOf, trackY } from "../cart/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([
"matJump", "matLand", "matLaunch", "matDuck", "matSwitch", "matCrash", "matCheck", "matFinish", "matBile",
"matSqueezeThrob", "matSqueezeClose", "matFurnDrop", "matFurnLand", "matFurnHit", "matFurnBreak",
]);
// Every way a heart goes here.
export const CAUSES = freeze(["matRib", "matUvula", "matSqueeze", "matFurniture", "matPlunge"]);
// The ride. Speeds are units across a second, MAT_G units a second squared.
export const MAT_V = 46;
export const BILE_V = 60;
export const MAT_MIN = 28;
export const MAT_MAX = 66;
export const SLOPE_G = 60;
export const RELAX = 1.5;
export const MAT_JUMP_V = 74;
export const MAT_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 RIB_W = 2.4;
export const RIB_H = 4.2;
export const SQ_W = 6;
export const SQ_OPEN = 22;
export const SQ_LOW = 3;
export const SQ_WARN_MS = 1100;
export const SQ_CLOSE_MS = 260;
export const SQ_EARLY_MS = 340;
export const SQ_LEAD_MS = SQ_WARN_MS + SQ_CLOSE_MS + SQ_EARLY_MS;
export const SQ_HOLD_MS = 1100;
export const SQ_EASE_MS = 450;
export const FURN_W = 3.2;
export const FURN_H = 3.4;
export const FURN_HP = 2;
export const FURN_LEAD_MS = 1700;
export const FURN_DROP_MS = 900;
export const FURN_DROP_H = 18;
export const FURN_V = 12;
export const FURN_ROLL_MS = 2200;
export const FURN_POINTS = 150;
const SHOT_R = 0.5;
// The "Wipe your feet" die: this share of the souls along the throat.
export const SWEET_SHARE = 0.5;
// 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 upper rails.
export const upperLine = (R, line) => line >= R.rails;
// The highest line under x, as [line, y], or null over a hole.
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.
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 rider in the air at (x, y) going up at vy and across at v lands, if he does not steer:
// { x, y, line } or null when he falls through a hole. The unit suite's measure of the forks.
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 - MAT_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;
}
// The height of squeeze `s`'s underside over the floor in its state: SQ_OPEN open, SQ_LOW shut.
export function squeezeLow(s) {
if (s.state === "close") return SQ_LOW + (SQ_OPEN - SQ_LOW) * clamp(s.t / SQ_CLOSE_MS, 0, 1);
if (s.state === "shut") return SQ_LOW;
if (s.state === "ease") return SQ_LOW + (SQ_OPEN - SQ_LOW) * (1 - clamp(s.t / SQ_EASE_MS, 0, 1));
return SQ_OPEN;
}
// How high a piece of furniture `f` is over the floor: falling while it drops (faster as it goes), 0 after.
export function furnitureLift(f) {
if (f.state !== "drop") return 0;
const p = 1 - clamp(f.t / FURN_DROP_MS, 0, 1);
return FURN_DROP_H * (1 - p * p);
}
// The floor under piece `i` of the room's furniture where it is now.
export function furnitureY(R, i, f) {
const line = R.furniture[i][1];
const L = linesOf(R)[line];
return trackY(R, line, clamp(f.x, L.x0, L.x1)) + furnitureLift(f);
}
/* -------------------------------------------------------------- placing */
// A fresh set of the room's things, each squeeze waiting and each piece of furniture up in the
// roof. What was shot stays shot (`old`, the state of an earlier try in the same room).
function things(R, old) {
return {
squeezes: R.squeezes.map(() => ({ state: "wait", t: 0 })),
furniture: R.furniture.map(([x], i) => ({ state: old && old.furniture[i] && old.furniture[i].state === "broken" ? "broken" : "wait", t: 0, x, hp: FURN_HP })),
};
}
// Put down in the room: on the mat at the front step 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;
if (!R || R.runner !== "mat") {
if (round.runner && round.runner.id === "mat") round.runner = null;
return;
}
const old = round.runner && round.runner.id === "mat" && 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: "mat", room: round.room, check, v: MAT_V, line: top ? top[0] : -1, coyote: 0, from: you.y, left: top ? top[0] : 0, done: false, bile: -1, sweet: old ? old.sweet : 0, sweetMs: 0, ...things(R, old) };
round.camLead = CAM_AHEAD;
const b = round.bonusRound;
if (b && !b.perf.total) {
b.perf.total = R.ribs.length + R.lows.length + R.squeezes.length + R.furniture.length + (R.rails - 1);
b.perf.steady = false;
b.perf.goal = R.furniture.length;
}
}
/* ------------------------------------------------------------ the ride */
// After a plunge that cost a heart but not the ride: back onto the throat nearest where you fell
// (the highest line under you, the ledge over the hole, else the next floor line ahead) at MAT_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: MAT_V, coyote: 0, from: y });
}
// The souls taken against those laid along the throat ("Wipe your feet").
function sweetness(round, c) {
c.sweet = round.candy.reduce((n, got) => n + (got ? 1 : 0), 0);
const b = round.bonusRound;
if (b) b.perf.steady = round.candy.length > 0 && c.sweet >= Math.ceil(SWEET_SHARE * round.candy.length);
}
// The bile stretch under x, or -1.
const bileAt = (R, x) => R.bile.findIndex(([x0, x1]) => x >= x0 && x < x1);
// 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 cellar floor.
function ride(round, ms, k) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "mat" || !c || c.id !== "mat" || 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 cellar 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 floor.
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;
const slick = bileAt(R, you.x);
if (slick >= 0 && slick !== c.bile) ev("matBile", { n: slick });
c.bile = slick;
if (c.line >= 0) {
// On the floor (or the gristle ledge).
const slope = slopeOf(R, c.line, you.x);
c.v = clamp(c.v + (((slick >= 0 ? BILE_V : MAT_V) - c.v) * RELAX - SLOPE_G * slope) * dt, MAT_MIN, MAT_MAX);
const duck = Boolean(inp.down) && !want;
if (duck && !you.ducking) ev("matDuck");
you.ducking = duck;
if (want) {
inp.jump = 0;
you.vy = MAT_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("matJump", { 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("matLaunch", { 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 = MAT_JUMP_V;
c.from = you.y;
ev("matJump", { v: c.v });
}
const py = you.y;
you.vy = Math.max(-k.FALL_MAX, you.vy - MAT_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";
const was = upperLine(R, c.left);
c.line = f.line;
ev("matLand", { big: c.from - f.y >= BIG_LAND });
if (upperLine(R, f.line) !== was) ev("matSwitch", { up: upperLine(R, f.line) });
c.from = f.y;
} else if (you.x >= R.finish) {
// Over the cellar 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 hole, or the face of the cellar.
if (you.y < DERAIL_Y || k.groundAt(round.spec, you.x) > you.y + 0.5) {
if (!upperLine(R, c.left)) noteHit(round, `g${c.left}`);
if (k.lose(round, "matPlunge") && 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("matCheck", { n: c.check + 1 });
}
round.camLead = CAM_AHEAD + (c.v - MAT_V) * CAM_PER_V;
c.sweetMs -= ms;
if (c.sweetMs <= 0) {
c.sweetMs = 400;
sweetness(round, c);
}
if (obstacles(round, c, R, k)) return true;
creatures(round, c, R, ms);
return true;
}
// The ride is over: the throat spits you out onto the cellar floor, the door opens.
function finish(round, c, R, g) {
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;
sweetness(round, c);
round.events.push({ type: "matFinish", x: you.x, y: you.y, big: c.from - g >= BIG_LAND });
return false;
}
// A bolt flies parallel to the floor under it, whatever way you aimed (`s.off`).
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 uvula, a squeeze, a rib, a piece of furniture. 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, "matUvula")) {
noteHit(round, `u${i}`);
round.events.push({ type: "matCrash", what: "uvula", x: you.x, y: you.y + hh });
return true;
}
}
for (const [i, [x, line]] of R.squeezes.entries()) {
const s = c.squeezes[i];
if (s.state === "wait" || s.state === "throb" || s.state === "done") continue;
if (Math.abs(you.x - x) >= (k.HIT_W + SQ_W) / 2) continue;
const floor = trackY(R, line, x);
if (floor !== null && you.y + hh > floor + squeezeLow(s) && k.struck(round, "matSqueeze")) {
noteHit(round, `s${i}`);
round.events.push({ type: "matCrash", what: "squeeze", x: you.x, y: you.y + hh });
return true;
}
}
for (const [i, [x, line]] of R.ribs.entries()) {
if (Math.abs(you.x - x) > 6) continue;
if (boxHit(k, you, x, trackY(R, line, x), RIB_W, RIB_H) && k.struck(round, "matRib")) {
noteHit(round, `r${i}`);
round.events.push({ type: "matCrash", what: "rib", x, y: you.y });
return true;
}
}
for (const [i, f] of c.furniture.entries()) {
if (f.state !== "drop" && f.state !== "roll") continue;
if (Math.abs(you.x - f.x) > 6) continue;
if (boxHit(k, you, f.x, furnitureY(R, i, f), FURN_W, FURN_H) && k.struck(round, "matFurniture")) {
noteHit(round, `f${i}`);
round.events.push({ type: "matCrash", what: "furniture", x: f.x, y: you.y, kind: R.furniture[i][2] });
Object.assign(f, { state: "spent", t: 0 });
return true;
}
}
return false;
}
// The throat's muscles wake as you come: the squeezes throb and close, the furniture drops and tumbles.
function creatures(round, c, R, ms) {
const you = round.you;
R.squeezes.forEach(([x, line], i) => {
const s = c.squeezes[i];
const y = trackY(R, line, x);
if (s.state === "wait") {
const ahead = x - SQ_W / 2 - you.x;
if (ahead > -SQ_W && ahead <= (c.v * SQ_LEAD_MS) / 1000) {
Object.assign(s, { state: "throb", t: SQ_WARN_MS, n: 1 });
round.events.push({ type: "matSqueezeThrob", x, y, n: 1 });
}
return;
}
if (s.state === "done") return;
s.t -= ms;
if (s.state === "throb" && s.n === 1 && s.t <= SQ_WARN_MS / 2) {
s.n = 2;
round.events.push({ type: "matSqueezeThrob", x, y, n: 2 });
}
if (s.t > 0) return;
if (s.state === "throb") {
Object.assign(s, { state: "close", t: SQ_CLOSE_MS });
round.events.push({ type: "matSqueezeClose", x, y });
} else if (s.state === "close") Object.assign(s, { state: "shut", t: SQ_HOLD_MS });
else if (s.state === "shut") Object.assign(s, { state: "ease", t: SQ_EASE_MS });
else Object.assign(s, { state: "done", t: 0 });
});
R.furniture.forEach(([hx, line], i) => {
const f = c.furniture[i];
const L = linesOf(R)[line];
if (f.state === "wait") {
const ahead = hx - you.x;
if (ahead > -FURN_W && ahead <= (c.v * FURN_LEAD_MS) / 1000) {
Object.assign(f, { state: "drop", t: FURN_DROP_MS });
round.events.push({ type: "matFurnDrop", x: f.x, y: trackY(R, line, hx) + FURN_DROP_H, kind: R.furniture[i][2] });
}
} else if (f.state === "drop") {
f.t -= ms;
if (f.t <= 0) {
Object.assign(f, { state: "roll", t: FURN_ROLL_MS });
round.events.push({ type: "matFurnLand", x: f.x, y: trackY(R, line, hx), kind: R.furniture[i][2] });
}
} else if (f.state === "roll") {
f.t -= ms;
f.x = Math.max(L.x0 + 1, f.x - FURN_V * (ms / 1000));
if (f.t <= 0 || f.x < you.x - 10) Object.assign(f, { state: "spent", t: 0 });
}
});
}
/* ------------------------------------------------------------- targets */
// A bolt into a piece of furniture on its way down or tumbling at you. True when one took it.
function matShot(round, s) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "mat" || !c || c.id !== "mat") 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.furniture.length; i++) {
const f = c.furniture[i];
if (f.state !== "drop" && f.state !== "roll") continue;
const y = furnitureY(R, i, f);
if (!hit(f.x, y, FURN_W, FURN_H)) continue;
f.hp--;
if (f.hp > 0) round.events.push({ type: "matFurnHit", x: f.x, y: y + FURN_H / 2, kind: R.furniture[i][2] });
else {
Object.assign(f, { state: "broken", t: 0 });
round.score += FURN_POINTS;
if (round.bonusRound) round.bonusRound.perf.acts++;
round.events.push({ type: "matFurnBreak", x: f.x, y: y + FURN_H / 2, points: FURN_POINTS, kind: R.furniture[i][2] });
}
return true;
}
return false;
}
export const MAT = freeze({
id: "mat",
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
horde: freeze({}),
ride: freeze([ride]),
place: freeze([place]),
target: matShot,
});
@@ -0,0 +1,259 @@
// Plan2Code Web Console - ghoul: the sounds for the finale's first ride, Down the Hatch (surfing the WELCOME mat down the House's throat), merged into sfx/ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-banister.js: `tones` (a `ghoulMat<Act>` sound for the ride's
// things). Built from the house tone layers only (no external audio), each tone under 1.2 s. `music`
// holds ghoulMarrowMat, the user's pick (Seasick calliope), named in ROOM_MUSIC. These
// are the user's picks from the sound vote (prototypes/sounds/ghoul-rush/mat.html). A name may be
// defined only once across tones.js and every game's file. No imports.
export const MAT_SFX = {
tones: {
// The WELCOME mat: YOU surf the WELCOME mat down the House's wet, ribbed throat: jumping ribs, ducking uvulas, hopping onto the gristle ledge, skidding on bile.
// Jumps: Spring and spit.
ghoulMatJump: {
layers: [
{ type: "sine", from: 160, to: 420, seconds: 0.14, attack: 0.003, gain: 0.6 },
{ type: "noise", seconds: 0.1, attack: 0, gain: 0.32, filter: { type: "highpass", from: 2340, to: 2340, q: 1 } },
{ type: "sine", from: 910, to: 195, seconds: 0.16, delay: 0.02, gain: 0.24 },
{ type: "brown", seconds: 0.12, attack: 0, gain: 0.2, filter: { type: "lowpass", from: 546, to: 546, q: 1 } },
],
},
// Lands: Belly flop.
ghoulMatLand: {
layers: [
{ type: "sine", from: 98, to: 46, seconds: 0.12, attack: 0.003, gain: 0.8 },
{ type: "noise", seconds: 0.09, attack: 0.003, gain: 0.5, filter: { type: "bandpass", from: 630, to: 315, q: 2 } },
{ type: "brown", seconds: 0.14, attack: 0.01, gain: 0.4, delay: 0.02, filter: { type: "lowpass", from: 350, to: 140, q: 3 } },
{ type: "noise", seconds: 0.28, attack: 0, gain: 0.45, filter: { type: "lowpass", from: 2080, to: 160, q: 1 }, delay: 0.02 },
{ type: "square", from: 112, to: 32, seconds: 0.16, attack: 0, gain: 0.25, filter: { type: "lowpass", from: 480, to: 480, q: 1 }, delay: 0.02 },
{ type: "sine", from: 720, to: 1040, seconds: 0.05, delay: 0.22, gain: 0.13 },
{ type: "sine", from: 608, to: 880, seconds: 0.05, delay: 0.36, gain: 0.09 },
],
},
// Spat out: Gulp and whoosh (in game).
ghoulMatLaunch: {
layers: [
{ type: "sine", from: 180, to: 60, seconds: 0.25, attack: 0.01, gain: 0.6 },
{ type: "noise", seconds: 0.7, attack: 0.25, gain: 0.45, delay: 0.1, filter: { type: "bandpass", from: 400, to: 2200, q: 2 } },
{ type: "sine", from: 300, to: 760, seconds: 0.45, attack: 0.1, gain: 0.3, delay: 0.15, vibrato: { rate: 7, depth: 0.05 } },
],
},
// Ducks: Quick swish.
ghoulMatDuck: {
layers: [
{ type: "noise", seconds: 0.2, attack: 0.07, gain: 0.64, filter: { type: "bandpass", from: 390, to: 2340, q: 1.5 } },
],
},
// Onto the ledge: Rubbery boing (in game).
ghoulMatSwitch: {
layers: [
{ type: "triangle", from: 260, to: 520, seconds: 0.14, attack: 0.004, gain: 0.45, vibrato: { rate: 24, depth: 0.08 } },
{ type: "sine", from: 520, to: 390, seconds: 0.16, attack: 0.004, gain: 0.25, delay: 0.1 },
],
},
// Crash: Smack, crunch, gasp (in game).
ghoulMatCrash: {
layers: [
{ type: "sine", from: 90, to: 34, seconds: 0.24, attack: 0, gain: 0.9 },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 300, to: 200, q: 1 } },
{ type: "noise", seconds: 0.08, attack: 0, gain: 0.6, delay: 0.02, filter: { type: "bandpass", from: 1600, to: 900, q: 3 } },
{ type: "noise", seconds: 0.3, attack: 0.05, gain: 0.25, delay: 0.12, filter: { type: "highpass", from: 2500, to: 1500, q: 1 } },
],
},
// Checkpoint: Lantern chime.
ghoulMatCheck: {
layers: [
{ type: "sine", from: 988, to: 985, seconds: 0.5, attack: 0.003, gain: 0.35 },
{ type: "sine", from: 1976, to: 1970, seconds: 0.3, attack: 0.003, gain: 0.12 },
],
},
// Finish: Doorstep jingle.
ghoulMatFinish: {
layers: [
{ type: "triangle", notes: [659, 784, 988, 1319], seconds: 0.9, attack: 0.01, gain: 0.5 },
{ type: "sine", from: 1319, to: 1312, seconds: 0.4, attack: 0.003, gain: 0.2, delay: 0.75, filter: { type: "lowpass", from: 1600, to: 1000, q: 1 } },
{ type: "sine", from: 2638, to: 2625, seconds: 0.24, attack: 0.003, gain: 0.07, delay: 0.75, filter: { type: "lowpass", from: 1600, to: 1000, q: 1 } },
],
},
// Onto bile: Sizzle.
ghoulMatBile: {
layers: [
{ type: "noise", seconds: 0.5, attack: 0.06, gain: 0.48, filter: { type: "highpass", from: 3120, to: 6500, q: 1 } },
{ type: "pink", seconds: 0.5, attack: 0.05, gain: 0.3, filter: { type: "bandpass", from: 4160, to: 2860, q: 2 } },
{ type: "sine", from: 572, to: 972, seconds: 0.05, delay: 0.17, attack: 0, gain: 0.14 },
{ type: "sine", from: 429, to: 730, seconds: 0.05, delay: 0.31, attack: 0, gain: 0.14 },
{ type: "sine", from: 476, to: 809, seconds: 0.05, delay: 0.32, attack: 0, gain: 0.14 },
{ type: "sine", from: 375, to: 637, seconds: 0.05, delay: 0.27, attack: 0, gain: 0.14 },
{ type: "sine", from: 927, to: 1576, seconds: 0.05, delay: 0.11, attack: 0, gain: 0.14 },
],
},
// The squeeze: A ring of muscle down the throat: the walls throb twice to warn, then it clamps down to just over a ducked head.
// Throbs: Rising rumble.
ghoulMatThrob: {
layers: [
{ type: "brown", seconds: 0.6, attack: 0.08, gain: 0.7, filter: { type: "lowpass", from: 144, to: 56, q: 1 } },
{ type: "sine", from: 38, to: 24, seconds: 0.6, attack: 0.05, gain: 0.56 },
{ type: "sine", from: 50, to: 80, seconds: 0.5, attack: 0.2, gain: 0.5 },
],
},
// Clamps shut: Gulp.
ghoulMatClose: {
layers: [
{ type: "sine", from: 140, to: 39, seconds: 0.35, attack: 0.01, gain: 0.8 },
{ type: "brown", seconds: 0.39, attack: 0.02, gain: 0.55, filter: { type: "lowpass", from: 630, to: 112, q: 5 } },
],
},
// The swallowed furniture: Chairs, side tables and mantel clocks the House swallowed before YOU: they drop from the roof and tumble up the throat at YOU. Shoot twice or jump.
// Drops: Creak and falling whistle (in game).
ghoulMatFurnDrop: {
layers: [
{ type: "sawtooth", from: 180, to: 140, seconds: 0.18, attack: 0.01, gain: 0.25, filter: { type: "lowpass", from: 900, to: 600, q: 4 } },
{ type: "sine", from: 1400, to: 500, seconds: 0.7, attack: 0.05, gain: 0.25, delay: 0.15 },
],
},
// Lands: Wooden thump on flesh (in game).
ghoulMatFurnLand: {
layers: [
{ type: "triangle", from: 160, to: 90, seconds: 0.14, attack: 0.002, gain: 0.7 },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1800, to: 1000, q: 3 } },
{ type: "brown", seconds: 0.18, attack: 0.01, gain: 0.45, delay: 0.02, filter: { type: "lowpass", from: 500, to: 200, q: 2 } },
],
},
// Hit by a bolt: Chip.
ghoulMatFurnHit: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 2880, to: 1920, q: 2 } },
{ type: "square", from: 1440, to: 480, seconds: 0.05, attack: 0, gain: 0.2 },
{ type: "noise", seconds: 0.04, delay: 0.06, attack: 0, gain: 0.35, filter: { type: "bandpass", from: 4160, to: 2880, q: 3 } },
],
},
// Breaks: Crash of kindling.
ghoulMatFurnBreak: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0.003, gain: 0.63, filter: { type: "bandpass", from: 2200, to: 1100, q: 2.5 } },
{ type: "triangle", from: 220, to: 110, seconds: 0.14, attack: 0.003, gain: 0.68 },
{ type: "sine", from: 90, to: 45, seconds: 0.2, attack: 0.003, gain: 0.45 },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 1800, to: 1200, q: 2 }, delay: 0.05 },
{ type: "square", from: 900, to: 300, seconds: 0.05, attack: 0, gain: 0.28, delay: 0.05 },
{ type: "noise", seconds: 0.04, delay: 0.11, attack: 0, gain: 0.49, filter: { type: "bandpass", from: 2600, to: 1800, q: 3 } },
{ type: "noise", seconds: 0.05, attack: 0.003, gain: 0.35, delay: 0.12, filter: { type: "bandpass", from: 3080, to: 1540, q: 2.5 } },
{ type: "triangle", from: 308, to: 154, seconds: 0.14, attack: 0.003, gain: 0.38, delay: 0.12 },
{ type: "sine", from: 126, to: 63, seconds: 0.2, attack: 0.003, gain: 0.25, delay: 0.12 },
],
},
// The ways a heart goes: Played with the crash when a heart is lost, one for each cause.
// Rib: Bone knock.
ghoulMatRib: {
layers: [
{ type: "triangle", from: 420, to: 357, seconds: 0.22, attack: 0, gain: 0.81 },
{ type: "sine", from: 1134, to: 1050, seconds: 0.12, attack: 0, gain: 0.32 },
{ type: "noise", seconds: 0.03, attack: 0, gain: 0.45, filter: { type: "bandpass", from: 1680, to: 1680, q: 2 } },
{ type: "triangle", from: 300, to: 255, seconds: 0.22, attack: 0, gain: 0.45, delay: 0.08 },
{ type: "sine", from: 810, to: 750, seconds: 0.12, attack: 0, gain: 0.18, delay: 0.08 },
{ type: "noise", seconds: 0.03, attack: 0, gain: 0.25, filter: { type: "bandpass", from: 1200, to: 1200, q: 2 }, delay: 0.08 },
],
},
// Uvula: Boing and buzz.
ghoulMatUvula: {
layers: [
{ type: "triangle", from: 200, to: 300, seconds: 0.25, attack: 0.003, gain: 0.5, vibrato: { rate: 18, depth: 0.1 } },
{ type: "square", from: 120, to: 120, seconds: 0.2, attack: 0.003, gain: 0.15, delay: 0.05, filter: { type: "lowpass", from: 800, to: 800, q: 1 } },
],
},
// Squeeze: Wheeze.
ghoulMatSqueeze: {
layers: [
{ type: "noise", seconds: 0.22, attack: 0.15, gain: 0.56, filter: { type: "bandpass", from: 990, to: 2160, q: 4 } },
{ type: "sawtooth", from: 180, to: 234, seconds: 0.2, attack: 0.14, gain: 0.2, filter: { type: "lowpass", from: 1260, to: 1260, q: 1 } },
{ type: "sine", from: 98, to: 46, seconds: 0.12, attack: 0.003, gain: 0.4 },
{ type: "noise", seconds: 0.09, attack: 0.003, gain: 0.25, filter: { type: "bandpass", from: 630, to: 315, q: 2 } },
{ type: "brown", seconds: 0.14, attack: 0.01, gain: 0.2, delay: 0.02, filter: { type: "lowpass", from: 350, to: 140, q: 3 } },
],
},
},
music: {
// Down the Hatch: seasick calliope. A band organ that has eaten something bad: two organ pipes play the waltz in
// thirds, each wobbling at a different slow rate, so the harmony swims in and out of tune like a rolling deck.
// The tuba keeps the oom-oom heartbeat. The middle part slides down chromatically at the start of each bar, a
// stomach dropping; near full dread a piccolo shrieks down the scale.
ghoulMarrowMat: {
bpm: 156,
rush: 16,
voices: {
organ: { wave: "pulse", duty: 0.5, gain: 0.09, decay: 0.05, sustain: 0.8, vibrato: { rate: 2.2, depth: 0.03 } },
organ2: { wave: "pulse", duty: 0.25, gain: 0.07, decay: 0.05, sustain: 0.8, from: 0.2, vibrato: { rate: 2.7, depth: 0.03 } },
tuba: { wave: "triangle", gain: 0.36, decay: 0.08, sustain: 0.6 },
pah: { wave: "square", gain: 0.06, decay: 0.02, sustain: 0.3, from: 0.3 },
ratchet: { kit: true, gain: 0.08, from: 0.5 },
piccolo: { wave: "sine", gain: 0.07, decay: 0.02, sustain: 0.7, from: 0.85 },
},
patterns: {
A: {
organ:
"D5 - - - A4 - - - F4 - - - | Bb4 - - - - - - - A4 - - - | " +
"C#5 - - - A4 - - - E4 - - - | G4 - - - - - - - F4 - E4 - | " +
"F4 - - - A4 - - - D5 - - - | G5 - - - - - F5 - E5 - D5 - | " +
"C#5 - - - E5 - - - A5 - - - | D5 - - - - - - - . . . .",
organ2:
"F4 - - - F4 - - - D4 - - - | G4 - - - - - - - F4 - - - | " +
"A4 - - - E4 - - - C#4 - - - | E4 - - - - - - - D4 - C#4 - | " +
"D4 - - - F4 - - - A4 - - - | Bb4 - - - - - A4 - G4 - F4 - | " +
"A4 - - - C#5 - - - E5 - - - | A4 - - - - - - - . . . .",
tuba:
"D2 - . . D2 - . . . . . . | G1 - . . G1 - . . . . . . | " +
"A1 - . . A1 - . . . . . . | A1 - . . A1 - . . . . . . | " +
"D2 - . . D2 - . . . . . . | G1 - . . G1 - . . . . . . | " +
"A1 - . . A1 - . . . . . . | D2 - . . D2 - . . . . . .",
pah:
". . . . . . . . F3^49 - . . | . . . . . . . . G3^37 - . . | " +
". . . . . . . . E3^59 - . . | . . . . . . . . E3^59 - . . | " +
". . . . . . . . F3^49 - . . | . . . . . . . . G3^37 - . . | " +
". . . . . . . . E3^59 - . . | . . . . . . . . F3^49 - . .",
ratchet:
". . . . . . . . h h . . | . . . . . . . . h h . . | " +
". . . . . . . . h h . . | . . . . . . . . h h . . | " +
". . . . . . . . h h . . | . . . . . . . . h h . . | " +
". . . . . . . . h h . . | . . . . . . . . h h . .",
piccolo:
". . . . . . . . . . . . | . . . . . . . . . . . . | " +
". . . . . . . . . . . . | . . . . . . . . . . . . | " +
". . . . . . . . . . . . | . . . . . . . . . . . . | " +
". . . . . . . . . . . . | . . . . . . . . . . . .",
},
B: {
organ:
"A5 G#5 G5 F#5 F5 - - - . . . . | D5 - - - Bb4 - - - G4 - - - | " +
"E5 Eb5 D5 C#5 C5 - - - . . . . | A4 - - - C#5 - - - E5 - - - | " +
"F5 E5 Eb5 D5 C#5 - - - . . . . | Bb4 - - - G4 - - - D5 - - - | " +
"C#5 - - - Bb4 - - - G4 - - - | A4 - - - E4 - - - C#4 - - -",
organ2:
"F5 E5 Eb5 D5 D5 - - - . . . . | Bb4 - - - G4 - - - D4 - - - | " +
"C#5 C5 B4 Bb4 A4 - - - . . . . | E4 - - - A4 - - - C#5 - - - | " +
"D5 C#5 C5 B4 A4 - - - . . . . | G4 - - - D4 - - - Bb4 - - - | " +
"E4 - - - G4 - - - E4 - - - | C#4 - - - A3 - - - E3 - - -",
tuba:
"D2 - . . D2 - . . . . . . | G1 - . . G1 - . . . . . . | " +
"A1 - . . A1 - . . . . . . | A1 - . . A1 - . . . . . . | " +
"D2 - . . D2 - . . . . . . | G1 - . . G1 - . . . . . . | " +
"A1 - . . A1 - . . . . . . | D2 - . . D2 - . . . . . .",
pah:
". . . . . . . . F3^49 - . . | . . . . . . . . G3^37 - . . | " +
". . . . . . . . E3^59 - . . | . . . . . . . . E3^59 - . . | " +
". . . . . . . . F3^49 - . . | . . . . . . . . G3^37 - . . | " +
". . . . . . . . E3^59 - . . | . . . . . . . . F3^49 - . .",
ratchet:
". . . . . . . . h h . . | . . . . . . . . h h . . | " +
". . . . . . . . h h . . | . . . . . . . . h h . . | " +
". . . . . . . . h h . . | . . . . . . . . h h . . | " +
". . . . . . . . h h . . | . . . . . . . . h h . .",
piccolo:
". . . . . . . . . . . . | . . . . . . . . . . . . | " +
". . . . . . . . . . . . | E6 D6 C#6 Bb5 A5 G5 F5 E5 D5 - - - | " +
". . . . . . . . . . . . | . . . . . . . . . . . . | " +
". . . . . . . . . . . . | A6 G6 F6 E6 D6 C#6 Bb5 A5 G5 F5 E5 C#5",
},
},
order: ["A", "B", "A"],
},
},
};
@@ -23,6 +23,12 @@ import { SLED_SFX } from "../rides/sled/ghoul-sfx-sled.js";
import { BANISTER_SFX } from "../rides/banister/ghoul-sfx-banister.js";
import { HEARSE_SFX } from "../rides/hearse/ghoul-sfx-hearse.js";
import { BOG_SFX } from "../stages/bog/ghoul-sfx-bog.js";
import { MARROW_SFX } from "../stages/marrow/ghoul-sfx-marrow.js";
import { EYE_SFX } from "../stages/marrow/ghoul-sfx-marrow-eye.js";
import { HEART_SFX } from "../stages/marrow/ghoul-sfx-marrow-heart.js";
import { MAT_SFX } from "../rides/mat/ghoul-sfx-mat.js";
import { BONESTAIR_SFX } from "../rides/bonestair/ghoul-sfx-bonestair.js";
import { ENDING_SFX } from "../story/ghoul-sfx-ending.js";
import { LANTERN_SFX } from "../rides/lantern/ghoul-sfx-lantern.js";
import { GURNEY_SFX } from "../rides/gurney/ghoul-sfx-gurney.js";
import { PEW_SFX } from "../rides/pew/ghoul-sfx-pew.js";
@@ -35,7 +41,7 @@ import { STORY_SFX } from "../story/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, HEARSE_SFX, BOG_SFX, LANTERN_SFX, GURNEY_SFX, PEW_SFX, MOWER_SFX, WAGON_SFX, TRAY_SFX, ARMS_SFX, RIDE_SFX, BANISTER_SFX, STORY_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, MARROW_SFX, EYE_SFX, HEART_SFX, MAT_SFX, BONESTAIR_SFX, ENDING_SFX, LANTERN_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
@@ -0,0 +1,29 @@
// Plan2Code Web Console - Ghoul Rush's finale, the room for the finale's second kill, Marrow, Every Room at Once (the Eye): data only, no imports. core/ghoul-rooms.js builds it through its room() helper and lists it in FINALE.rooms only once `ready` is true.
//
// A short landing (where the mat ride left YOU), then the dollhouse filling the arena
// (its last FIELD_W, 36 on): three floors, the ground at 6 and two full-width floors at
// 20 and 34 (shelves: jumped up through, dropped through with down, the fast way down),
// three rooms of 32 across each, and a stair of landings at 13 and 27 at each end, since
// a jump tops out at 12. The right end's stair stands clear of the front door at 119.5,
// which stays shut until the Eye is dead and the house has sunk (ghoul-marrow-eye.js).
// These must agree with EYE_FLOORS, EYE_ROOM_W and EYE_COLS there (the suite checks).
export const DOLLHOUSE_ROOM = Object.freeze({
ready: true,
id: "dollhouse",
title: "Every Room at Once",
sub: "Make yourself at home",
// The room's spec, in the shape room() in core/ghoul-rooms.js takes.
spec: {
length: 132,
ground: [[0, 132, 6]],
shelves: [[36, 132, 20], [36, 132, 34], [37, 43, 13], [37, 43, 27], [125, 131, 13], [125, 131, 27]],
key: null,
door: 119.5,
dark: false,
candy: [[8, 8.5, 4]],
items: [["garlic", 18, 6], ["dyn", 28, 6]],
spawns: [],
boss: "marroweye",
},
});
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,776 @@
// Plan2Code Web Console - Ghoul Rush's finale, its rules for the finale's second kill, Marrow, Every Room at Once (the Eye), as a pack core/ghoul-tables.js lists in PACKS.
//
// No imports: every rule is handed the kit `k` (see stages/marrow/ghoul-marrow.js and
// stages/bog/ghoul-bog.js for what a pack holds), and draws its randomness only from
// the `random` handed to the boss's fight.
//
// EVERY ROOM AT ONCE. The House with its front torn off: a dollhouse cutaway filling the
// arena, three floors (EYE_FLOORS) of three rooms (EYE_COLS, EYE_ROOM_W wide) with a
// stair of landings at each end. Somewhere in it the Eye opens, one room at a time:
//
// - THE EYE (`b.eye`): shut a while (EYE_SHUT_MS), then a room's lamp flares
// (EYE_FLARE_MS, a step of the flare heard at FLARE_AT) and the wallpaper splits:
// the Eye stares out for EYE_OPEN_MS, then shuts (EYE_CLOSE_MS) and moves on, never to
// the room it just left. Bolts fly level, so YOU must be on its floor: a bolt through
// its open box hurts it (`eyeShot`, the pack's target), one through it while it flares
// or shuts clanks (`bossBlock`). Its real box sits far out of reach and is always
// guarded, as the lawn's house's is. In its last phase two lamps flare and only one is true.
// - SHADES (`eyeShade`): a door in a room creaks open (EYE_DOOR_MS, an `eyeDoorway`
// hazard) and a pale shade of a keeper YOU beat this run steps out, small, with a few
// hp, gone again after SHADE_LIFE_MS, at most SHADE_CAP at once. Each has one move of
// its own (SHADE_MOVES), with a wind-up first; a new stage's boss needs a row there.
// - THE LURCH (`b.lurch`): every so often the House creaks (EYE_CREAK_MS) and lurches
// one way for EYE_LURCH_MS: YOU slide that way (EYE_PUSH, stopped at the end walls),
// and a loose dresser (`eyeDresser`) slides down YOUR floor at YOU: jump it, or shoot
// it apart.
//
// Its phase is 0 at first, 1 below two thirds of its hp, 2 below a third.
//
// THE KILL. The last hit bursts the Eye: a real boss kill (a life, the points,
// `hurtBoss`). Then `b.t` runs the scene (`retreatStep`): the wallpaper of every room
// falls away, the floors crack one after another from the top, a wet gasp (no false
// win this time: it is hurt now), and it sinks into the cellar, leaving a stairway of
// bones down through its front door. Only then can YOU reach that door (`b.gone`).
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
export const BOSSES = freeze({
marroweye: freeze({ name: "Marrow, Every Room at Once", sub: "Make yourself at home", w: 30, h: 30, hp: 110, points: 7000, color: "#e8c84a" }),
});
// The shades' monster: small and pale, a few hp (SHADE_HP, more with the room's toughness).
export const MONSTERS = freeze({
eyeShade: freeze({ name: "Shade", w: 3, h: 4.6, hp: 6, speed: 0, points: 300, stomp: false, head: false, color: "#cfe0f2" }),
});
/* ------------------------------------------------------------- the house */
// The dollhouse fills the arena: EYE_COLS rooms across, each EYE_ROOM_W wide, on the
// floors EYE_FLOORS (the room's ground, then two full-width shelves), under a ceiling
// at EYE_CEIL. A floor's slab is EYE_SLAB thick under its top.
export const EYE_COLS = 3;
export const EYE_ROOM_W = 32;
export const EYE_FLOORS = freeze([6, 20, 34]);
export const EYE_CEIL = 48;
export const EYE_SLAB = 1.6;
export const EYE_ROOMS = EYE_COLS * EYE_FLOORS.length;
// Room `i` (0 to 8, left to right along the ground floor, then up): its edges, its
// floor, the underside of the floor over it, and its middle.
export function roomBox(spec, i) {
const col = i % EYE_COLS;
const row = Math.floor(i / EYE_COLS);
const x0 = spec.arena + col * EYE_ROOM_W;
const floor = EYE_FLOORS[row];
const top = row + 1 < EYE_FLOORS.length ? EYE_FLOORS[row + 1] - EYE_SLAB : EYE_CEIL;
return { i, col, row, x0, x1: x0 + EYE_ROOM_W, floor, top, cx: x0 + EYE_ROOM_W / 2 };
}
// Which floor (0 to 2) a height stands on or over: a landing counts as the floor under it.
export const rowOf = (y) => (y >= EYE_FLOORS[2] ? 2 : y >= EYE_FLOORS[1] ? 1 : 0);
// The Eye in a room's back wall: EYE_W wide, from EYE_LO to EYE_HI over the floor, so a
// bolt from that floor, standing (2.4) or ducked (1.4), goes through it.
export const EYE_W = 5.6;
export const EYE_LO = 0.6;
export const EYE_HI = 6.2;
export const eyeAt = (spec, i) => {
const r = roomBox(spec, i);
return { x: r.cx, y: r.floor + (EYE_LO + EYE_HI) / 2 };
};
// The Eye's clock: how long it stays shut between rooms (by phase), how long a lamp
// flares first (a second step heard at FLARE_AT of it), how long it stays open (by
// phase), and how long it takes to shut.
export const EYE_SHUT_MS = freeze([1500, 1200, 1000]);
export const EYE_FLARE_MS = 1100;
export const FLARE_AT = 0.55;
export const EYE_OPEN_MS = freeze([4200, 3400, 2800]);
export const EYE_CLOSE_MS = 400;
// Below these shares of its hp it is in its second phase, then its third.
export const PHASE_HP = freeze([2 / 3, 1 / 3]);
export const phaseOf = (b) => (b.hp > b.max * PHASE_HP[0] ? 0 : b.hp > b.max * PHASE_HP[1] ? 1 : 2);
/* ------------------------------------------------------------ the shades */
// Each keeper's shade and its one move. Every boss of every stage needs a row (the
// suite checks): a shade of one without falls back to SHADE_FALLBACK.
export const SHADE_MOVES = freeze({
gourd: "hop", // a hop that sends a floor ripple each way
bones: "skull", // a thrown skull that comes back
angel: "creep", // moves only while YOU look away
keeper: "scythe", // a long low scythe sweep
choirmaster: "note", // a note fired along its floor
matron: "dash", // a dash along its floor, needle first
beast: "leap", // a leap at where YOU stand
tommy: "knock", // knocks: rocks fall one, two, three toward YOU
ringmaster: "hoop", // a hoop rolled along its floor
frostwidow: "icicles", // icicles drop from the ceiling over YOU
motherbog: "mud", // a wave of mud along its floor
});
export const SHADE_FALLBACK = "note";
// A practice round (no keepers beaten yet) still meets three.
export const PRACTICE_SHADES = freeze(["gourd", "matron", "frostwidow"]);
// The keepers whose shades this round may call up: those beaten this run.
export function shadesOf(round, k) {
const beaten = (round.cleared || []).map((id) => k.stageById(id)?.boss).filter((id) => id && id !== "marroweye");
return beaten.length ? beaten : PRACTICE_SHADES;
}
export const SHADE_HP = 6;
// A door creaks open EYE_DOOR_MS before its shade steps out; a shade fades in over
// SHADE_IN_MS and out over SHADE_OUT_MS (harmless and unhittable both ways), lives
// SHADE_LIFE_MS in all, and waits SHADE_IDLE_MS between moves (SHADE_FIRST_MS the first).
export const EYE_DOOR_MS = 900;
export const SHADE_IN_MS = 600;
export const SHADE_OUT_MS = 500;
export const SHADE_LIFE_MS = 6500;
export const SHADE_IDLE_MS = 700;
export const SHADE_FIRST_MS = 250;
export const SHADE_REST_MS = 600;
// At most this many shades (and doors about to let one out) at once, by phase; a new
// door every SHADE_EVERY_MS (by phase, less at depth); none nearer YOU than SHADE_CLEAR
// on YOUR floor. SHADE_YOUR_FLOOR is how often it comes out on YOUR floor.
export const SHADE_CAP = freeze([1, 2, 2]);
export const SHADE_EVERY_MS = freeze([4200, 3600, 3000]);
export const SHADE_FIRST_DOOR_MS = 2600;
export const SHADE_CLEAR = 16;
export const SHADE_YOUR_FLOOR = 0.6;
// Each move's wind-up: what YOU see and hear before it can hurt.
export const SHADE_WIND = freeze({ hop: 900, skull: 900, scythe: 1100, note: 900, dash: 1000, leap: 1000, knock: 1000, hoop: 900, icicles: 700, mud: 1000 });
// The moves' numbers. A floor thing (ripple, note, hoop, mud) runs along the shade's
// floor at its speed for at most its reach; a skull flies out SKULL_REACH and back at
// the height of YOUR chest (duck it); the scythe sweeps SCYTHE_W beside the shade for
// SCYTHE_LIVE_MS; the matron dashes DASH_REACH at DASH_SPEED; the beast leaps LEAP_MS
// and its landing hurts for POUNCE_MS; rocks and icicles warn ROCK_WARN_MS and
// ICICLE_WARN_MS where they will land, then fall FALL_MS; the angel creeps at
// ANGEL_SPEED while YOU face away from it.
export const RIPPLE = freeze({ w: 1.4, h: 1.6, speed: 24, reach: 60 });
export const NOTE = freeze({ w: 1.6, h: 1.8, speed: 22, reach: 70 });
export const HOOP = freeze({ w: 1.2, h: 3.4, speed: 26, reach: 70 });
export const MUD = freeze({ w: 3, h: 2.4, speed: 15, reach: 40 });
export const HOP_MS = 450;
export const HOP_UP = 5;
export const SKULL_W = 1.5;
export const SKULL_H = 1.4;
export const SKULL_UP = 2.9;
export const SKULL_SPEED = 28;
export const SKULL_REACH = 30;
export const SCYTHE_W = 13;
export const SCYTHE_H = 1.5;
export const SCYTHE_LIVE_MS = 220;
export const DASH_SPEED = 42;
export const DASH_REACH = 34;
export const LEAP_MS = 560;
export const LEAP_UP = 8;
export const POUNCE_W = 5;
export const POUNCE_H = 2;
export const POUNCE_MS = 220;
export const ROCK_W = 2.2;
export const ROCK_H = 2;
export const ROCK_STEP = 6;
export const ROCK_WARN_MS = 900;
export const ICICLE_W = 1.4;
export const ICICLE_H = 2.4;
export const ICICLE_GAP = 6;
export const ICICLE_WARN_MS = 1300;
export const FALL_MS = 260;
export const ANGEL_SPEED = 15;
/* -------------------------------------------------------------- the lurch */
// The House lurches every EYE_LURCH_EVERY_MS (by phase; the first after
// EYE_LURCH_FIRST_MS): a creak of EYE_CREAK_MS (a second at CREAK_AT of it), then
// EYE_LURCH_MS of sliding: YOU at EYE_PUSH a second (on a floor, never in the air),
// a dresser down YOUR floor at DRESSER_SPEED. A dresser takes DRESSER_HP bolts.
export const EYE_LURCH_EVERY_MS = freeze([9500, 8000, 6500]);
export const EYE_LURCH_FIRST_MS = 7000;
export const EYE_CREAK_MS = 1300;
export const CREAK_AT = 0.5;
export const EYE_LURCH_MS = 2000;
export const EYE_PUSH = 14;
export const DRESSER_W = 3.6;
export const DRESSER_H = 4.2;
export const DRESSER_SPEED = 34;
export const DRESSER_HP = 3;
export const DRESSER_CLEAR = 8;
// YOU are kept this far inside the house's end walls by a lurch.
export const WALL_PAD = 1.2;
/* --------------------------------------------------------------- the kill */
// The retreat's clock, in ms of `b.t` after the kill: the wallpaper peels, the floors
// crack from the top (CRACK_AT, one each), a wet gasp, it sinks, and it is gone.
export const PEEL_AT = 600;
export const CRACK_AT = freeze([1600, 2100, 2600]);
export const GASP_AT = 3500;
export const SINK_AT = 4700;
export const GONE_AT = 7200;
// Until it has gone YOU are kept this far short of its door.
export const DOOR_KEEP = 3.4;
/* ----------------------------------------------------------- the Eye's turn */
const shadesAlive = (round) => round.monsters.filter((m) => !m.dead && m.kind === "eyeShade").length + round.hazards.filter((h) => h.kind === "eyeDoorway").length;
// A room for the Eye other than `not` (and `also`), at random.
function pickRoom(random, not, also = -1) {
const pool = [];
for (let i = 0; i < EYE_ROOMS; i++) if (i !== not && i !== also) pool.push(i);
return pool[Math.floor(random() * pool.length) % pool.length];
}
function stepEye(round, b, ms, random) {
const e = b.eye;
const spec = round.spec;
const phase = phaseOf(b);
const at = (i) => eyeAt(spec, i);
e.ms -= ms;
if (e.state === "flare") {
// The second step of the flare, out loud.
if (!e.stepped && e.ms <= EYE_FLARE_MS * (1 - FLARE_AT)) {
e.stepped = true;
round.events.push({ type: "eyeFlareStep", kind: "marroweye", ...at(e.room), room: e.room });
}
if (e.ms > 0) return;
e.state = "open";
e.ms = EYE_OPEN_MS[phase];
e.full = e.ms;
round.events.push({ type: "eyeOpen", kind: "marroweye", ...at(e.room), room: e.room });
if (e.decoy >= 0) round.events.push({ type: "eyeDud", kind: "marroweye", ...at(e.decoy), room: e.decoy });
e.decoy = -1;
return;
}
if (e.ms > 0) return;
if (e.state === "open") {
e.state = "closing";
e.ms = EYE_CLOSE_MS;
round.events.push({ type: "eyeShut", kind: "marroweye", ...at(e.room), room: e.room });
return;
}
if (e.state === "closing") {
e.state = "shut";
e.ms = EYE_SHUT_MS[phase] / spec.pace;
e.last = e.room;
return;
}
// Shut long enough: a lamp flares where it will open (two in its last phase, one false).
e.room = b.plan >= 0 && b.plan < EYE_ROOMS && b.plan !== e.last ? b.plan : pickRoom(random, e.last);
b.plan = -1;
e.decoy = phase === 2 ? pickRoom(random, e.last, e.room) : -1;
e.state = "flare";
e.ms = EYE_FLARE_MS;
e.full = EYE_FLARE_MS;
e.stepped = false;
round.events.push({ type: "eyeFlare", kind: "marroweye", ...at(e.room), room: e.room });
if (e.decoy >= 0) round.events.push({ type: "eyeFlare", kind: "marroweye", ...at(e.decoy), room: e.decoy, decoy: true });
}
// Whether a bolt is in room `i`'s Eye box.
function inEye(spec, i, s) {
const r = roomBox(spec, i);
return Math.abs(s.x - r.cx) <= EYE_W / 2 + 0.3 && s.y >= r.floor + EYE_LO - 0.3 && s.y <= r.floor + EYE_HI + 0.3;
}
// A bolt through the house: a dresser takes it; the open Eye is hurt by it; the Eye
// flaring or shutting clanks it off. True when the bolt is spent.
function eyeShot(round, s, k) {
const spec = round.spec;
if (!spec || spec.boss !== "marroweye") return false;
for (const h of round.hazards) {
if (h.kind !== "eyeDresser" || h.dead || Math.abs(s.x - h.x) > h.w / 2 + 0.3 || s.y < h.y || s.y > h.y + h.h) continue;
h.hp -= 1;
if (h.hp <= 0) {
h.dead = true;
round.events.push({ type: "eyeDresserSmash", kind: "marroweye", x: h.x, y: h.y + h.h / 2 });
} else round.events.push({ type: "bossBlock", kind: "marroweye", x: s.x, y: s.y });
return true;
}
const b = round.boss;
if (!b || b.kind !== "marroweye" || b.state !== "fight" || !b.eye) return false;
const e = b.eye;
if (e.state === "shut" || !inEye(spec, e.room, s)) return false;
const at = eyeAt(spec, e.room);
if (e.state !== "open") {
round.events.push({ type: "bossBlock", kind: "marroweye", x: s.x, y: s.y });
return true;
}
const dmg = Math.max(1, s.arm ? k.armBossDamage(round, s.bossDmg || 1) : 1);
k.hurtBoss(round, dmg, "eye", at);
return true;
}
/* ------------------------------------------------------------ the shades */
// What YOU stand on (or are over, in the air): a floor, a landing, or the ground.
function standing(round, k) {
const you = round.you;
if (you.state === "run") return you.y;
let top = k.groundAt(round.spec, you.x);
for (const [x0, x1, y] of round.spec.shelves) if (you.x >= x0 && you.x <= x1 && y <= you.y && y > top) top = y;
return top;
}
// The underside of whatever is over a floor at height y: the next floor's slab, or the ceiling.
const ceilingOver = (y) => {
for (const f of EYE_FLOORS) if (f > y + 0.01) return f - EYE_SLAB;
return EYE_CEIL;
};
const inside = (spec, x, pad = 2) => clamp(x, spec.arena + pad, spec.length - pad);
// A door opening somewhere for a shade: on YOUR floor more often than not, at one of
// the room's doorways (its end walls and the frames between its rooms) clear of YOU.
function openDoor(round, b, random, k) {
const spec = round.spec;
const you = round.you;
const yourRow = rowOf(standing(round, k));
const row = random() < SHADE_YOUR_FLOOR ? yourRow : (yourRow + 1 + Math.floor(random() * 2)) % EYE_FLOORS.length;
const floor = EYE_FLOORS[row];
const doors = [spec.arena + 3, spec.arena + EYE_ROOM_W, spec.arena + EYE_ROOM_W * 2, spec.length - 3];
const taken = (x) => round.monsters.some((m) => m.kind === "eyeShade" && Math.abs(m.y - floor) < 1 && Math.abs(m.x - x) < 4) || round.hazards.some((h) => h.kind === "eyeDoorway" && h.y === floor && Math.abs(h.x - x) < 4);
let pool = doors.filter((x) => !taken(x) && (row !== yourRow || Math.abs(x - you.x) >= SHADE_CLEAR));
if (!pool.length) pool = doors.filter((x) => !taken(x) && Math.abs(x - you.x) >= SHADE_CLEAR / 2);
if (!pool.length) return false;
const x = pool[Math.floor(random() * pool.length) % pool.length];
const list = shadesOf(round, k);
let of = list[Math.floor(random() * list.length) % list.length];
if (of === b.lastShade && list.length > 1) of = list[(list.indexOf(of) + 1) % list.length];
if (b.planShade) {
of = b.planShade;
b.planShade = null;
}
b.lastShade = of;
round.hazards.push({ kind: "eyeDoorway", x, y: floor, w: 3, h: 5, warn: EYE_DOOR_MS, full: EYE_DOOR_MS, live: 0, of, cause: "marroweye" });
round.events.push({ type: "eyeDoor", kind: "marroweye", x, y: floor, of });
return true;
}
// A door: creaking open for its warning, then its shade steps out.
function stepDoorway(round, h, ms, k) {
h.warn = Math.max(0, h.warn - ms);
if (h.warn > 0) return true;
const hp = SHADE_HP + 2 * (round.spec.tough || 0);
const move = SHADE_MOVES[h.of] || SHADE_FALLBACK;
const dir = Math.sign(round.you.x - h.x) || -1;
k.spawnMonster(round, "eyeShade", h.x, h.y, { of: h.of, move, floor: h.y, hp, max: hp, act: "in", wait: SHADE_IN_MS, life: SHADE_LIFE_MS, dir, force: true, awake: true });
round.events.push({ type: "eyeShadeIn", kind: "eyeShade", x: h.x, y: h.y, of: h.of });
return false;
}
// A floor thing set rolling along a shade's floor toward `dir`.
const roller = (kind, def, x, y, dir) => ({ kind, x, y, w: def.w, h: def.h, dir, speed: def.speed, reach: def.reach, went: 0, warn: 0, live: 1, cause: kind });
// The wind-up of a shade's move: what YOU see (its pose, and a mark where it will
// strike) and hear before it can hurt.
function windUp(round, m, k) {
const you = round.you;
const spec = round.spec;
const wind = SHADE_WIND[m.move] || 900;
m.act = "wind";
m.wait = wind;
m.full = wind;
m.dir = Math.sign(you.x - m.x) || m.dir;
m.knocks = 0;
const ev = { type: "eyeShadeWind", kind: "eyeShade", x: m.x, y: m.floor + 3, of: m.of, move: m.move };
if (m.move === "scythe") {
round.hazards.push({ kind: "eyeScythe", x: inside(spec, m.x + m.dir * (SCYTHE_W / 2 + 1), SCYTHE_W / 2), y: m.floor, w: SCYTHE_W, h: SCYTHE_H, dir: m.dir, warn: wind, full: wind, live: 0, cause: "eyeScythe", owner: m.id });
} else if (m.move === "leap") {
m.tx = inside(spec, you.x, 3);
ev.tx = m.tx;
} else if (m.move === "icicles") {
// One over YOU and a second a step ahead, each marked on the ceiling and the floor.
const y = standing(round, k);
const ahead = Math.sign(you.vx) || you.face || 1;
const xs = [inside(spec, you.x), inside(spec, you.x + ahead * ICICLE_GAP)];
const top = ceilingOver(y);
xs.forEach((x, i) => {
const warn = wind + ICICLE_WARN_MS + i * 150;
round.hazards.push({ kind: "eyeIcicle", x, y: top - ICICLE_H, top, floor: y, w: ICICLE_W, h: ICICLE_H, warn, full: warn, fall: 0, live: 0, cause: "eyeIcicle", id: i });
});
ev.xs = xs;
ev.ty = y;
}
round.events.push(ev);
}
// One of the three knocks: a rock to fall on YOUR floor, each nearer YOU from the shade's side.
function knock(round, m, k) {
const you = round.you;
const y = standing(round, k);
const toward = Math.sign(you.x - m.x) || 1;
const x = inside(round.spec, you.x - toward * ROCK_STEP * (2 - m.knocks));
const top = ceilingOver(y);
round.hazards.push({ kind: "eyeRock", x, y: top - ROCK_H, top, floor: y, w: ROCK_W, h: ROCK_H, warn: ROCK_WARN_MS, full: ROCK_WARN_MS, fall: 0, live: 0, cause: "eyeRock", id: m.knocks });
m.knocks++;
round.events.push({ type: "eyeKnock", kind: "eyeShade", x: m.x, y: m.floor + 3, n: m.knocks, at: x, ty: y });
}
// The move itself, once its wind-up is done (a one-off: the shade rests after it), or
// a slice of one that takes a while (a hop, a dash, a leap): true while it goes on.
function strike(round, m, ms, k) {
const spec = round.spec;
const dt = ms / 1000;
const mv = m.move;
if (mv === "hop" || mv === "leap") {
if (!m.going) {
m.going = true;
m.t0 = 0;
m.x0 = m.x;
if (mv === "leap") round.events.push({ type: "eyeShadeLeap", kind: "eyeShade", x: m.x, y: m.floor + 3, tx: m.tx });
}
m.t0 += ms;
const full = mv === "hop" ? HOP_MS : LEAP_MS;
const p = Math.min(1, m.t0 / full);
if (mv === "leap") m.x = m.x0 + (m.tx - m.x0) * p;
m.y = m.floor + Math.sin(Math.PI * p) * (mv === "hop" ? HOP_UP : LEAP_UP);
if (p < 1) return true;
m.y = m.floor;
m.going = false;
if (mv === "hop") {
for (const d of [-1, 1]) round.hazards.push(roller("eyeRipple", RIPPLE, m.x + d * 1.6, m.floor, d));
round.events.push({ type: "eyeShadeSlam", kind: "eyeShade", x: m.x, y: m.floor });
} else {
round.hazards.push({ kind: "eyePounce", x: m.x, y: m.floor, w: POUNCE_W, h: POUNCE_H, warn: 0, live: POUNCE_MS, cause: "eyePounce" });
round.events.push({ type: "eyePounce", kind: "eyeShade", x: m.x, y: m.floor });
}
return false;
}
if (mv === "dash") {
if (!m.going) {
m.going = true;
m.went = 0;
round.events.push({ type: "eyeShadeDash", kind: "eyeShade", x: m.x, y: m.floor + 2, dir: m.dir });
}
const step = DASH_SPEED * dt;
const nx = m.x + m.dir * step;
m.went += step;
if (nx <= spec.arena + 2 || nx >= spec.length - 2 || m.went >= DASH_REACH) {
m.x = inside(spec, nx);
m.going = false;
return false;
}
m.x = nx;
return true;
}
if (mv === "skull") {
round.hazards.push({ kind: "eyeSkull", x: m.x + m.dir * 1.6, y: m.floor + SKULL_UP, w: SKULL_W, h: SKULL_H, dir: m.dir, went: 0, back: false, owner: m.id, home: m.x, warn: 0, live: 1, cause: "eyeSkull" });
round.events.push({ type: "eyeSkullThrow", kind: "eyeShade", x: m.x, y: m.floor + SKULL_UP, dir: m.dir });
} else if (mv === "note") {
round.hazards.push(roller("eyeNote", NOTE, m.x + m.dir * 1.8, m.floor, m.dir));
round.events.push({ type: "eyeNote", kind: "eyeShade", x: m.x, y: m.floor + 2, dir: m.dir });
} else if (mv === "hoop") {
round.hazards.push(roller("eyeHoop", HOOP, m.x + m.dir * 1.8, m.floor, m.dir));
round.events.push({ type: "eyeHoop", kind: "eyeShade", x: m.x, y: m.floor + 2, dir: m.dir });
} else if (mv === "mud") {
round.hazards.push(roller("eyeMud", MUD, m.x + m.dir * 2, m.floor, m.dir));
round.events.push({ type: "eyeMud", kind: "eyeShade", x: m.x, y: m.floor + 1, dir: m.dir });
}
// The scythe, the knocks and the icicles were set going in the wind-up.
return false;
}
// A shade's slice: fading in, then wind-up, move and rest by turns, fading out at the end of its life.
function moveShade(round, m, ms, k) {
const you = round.you;
const spec = round.spec;
m.life -= ms;
if (m.act === "out") {
m.wait -= ms;
if (m.wait <= 0) m.dead = true;
return;
}
if (m.life <= SHADE_OUT_MS && !m.going) {
m.act = "out";
m.wait = SHADE_OUT_MS;
m.y = m.floor;
round.events.push({ type: "eyeShadeOut", kind: "eyeShade", x: m.x, y: m.floor + 2, of: m.of });
return;
}
if (!m.going) m.dir = Math.sign(you.x - m.x) || m.dir;
if (m.act === "in") {
m.wait -= ms;
if (m.wait <= 0) {
m.act = m.move === "creep" ? "creep" : "idle";
m.wait = SHADE_FIRST_MS;
}
return;
}
// The angel: only while YOU face away from it does it come on, grinding.
if (m.act === "creep") {
const away = you.face !== Math.sign(m.x - you.x) && Math.abs(you.x - m.x) > 0.6;
if (away) {
if (!m.moving) round.events.push({ type: "eyeShadeGrind", kind: "eyeShade", x: m.x, y: m.floor + 2 });
m.x = inside(spec, m.x + m.dir * ANGEL_SPEED * (ms / 1000));
}
m.moving = away;
return;
}
if (m.act === "idle") {
m.wait -= ms;
if (m.wait <= 0) {
if (m.move === "creep") m.act = "creep";
else windUp(round, m, k);
}
return;
}
if (m.act === "wind") {
m.wait -= ms;
if (m.move === "knock") while (m.knocks < 3 && m.wait <= m.full * (1 - m.knocks / 3)) knock(round, m, k);
if (m.wait > 0) return;
m.act = "go";
}
if (m.act === "go") {
if (strike(round, m, ms, k)) return;
m.act = "rest";
m.wait = SHADE_REST_MS;
return;
}
if (m.act === "rest") {
m.wait -= ms;
if (m.wait <= 0) {
m.act = "idle";
m.wait = SHADE_IDLE_MS / spec.pace;
}
}
}
/* -------------------------------------------------------------- hazards */
// A floor thing rolling along: on until its reach or the house's end wall.
function stepRoller(round, h, ms) {
const step = h.speed * round.spec.pace * (ms / 1000);
h.x += h.dir * step;
h.went += step;
return h.went < h.reach && h.x > round.spec.arena + 0.5 && h.x < round.spec.length - 0.5;
}
// The skull: out at YOUR chest's height, then back to the shade that threw it (or where it stood).
function stepSkull(round, h, ms) {
const step = SKULL_SPEED * (ms / 1000);
if (!h.back) {
h.x += h.dir * step;
h.went += step;
if (h.went >= SKULL_REACH || h.x <= round.spec.arena + 1 || h.x >= round.spec.length - 1) {
h.back = true;
round.events.push({ type: "eyeSkullTurn", kind: "eyeShade", x: h.x, y: h.y });
}
return true;
}
const owner = round.monsters.find((m) => m.id === h.owner && !m.dead);
const home = owner ? owner.x : h.home;
const d = home - h.x;
if (Math.abs(d) <= step) return false;
h.x += Math.sign(d) * step;
return true;
}
// The scythe: its arc shows for `warn`, then it sweeps, live SCYTHE_LIVE_MS.
function stepScythe(round, h, ms) {
if (h.warn > 0) {
// Its shade gone (shot, faded), the sweep never comes.
if (!round.monsters.some((m) => m.id === h.owner && !m.dead)) return false;
h.warn = Math.max(0, h.warn - ms);
if (h.warn > 0) return true;
h.live = SCYTHE_LIVE_MS;
round.events.push({ type: "eyeScythe", kind: "eyeShade", x: h.x, y: h.y, dir: h.dir });
return true;
}
h.live -= ms;
return h.live > 0;
}
// A rock or an icicle: a mark where it lands for `warn`, then it falls from the ceiling.
function stepDrop(round, h, ms) {
if (h.warn > 0) {
h.warn = Math.max(0, h.warn - ms);
if (h.warn > 0) return true;
h.live = 1;
h.fall = 0;
return true;
}
h.fall += ms;
const p = Math.min(1, h.fall / FALL_MS);
h.y = h.top - h.h + (h.floor - (h.top - h.h)) * p;
if (p < 1) return true;
round.events.push({ type: h.kind === "eyeRock" ? "eyeRockLand" : "eyeIcicleLand", kind: "eyeShade", x: h.x, y: h.floor });
return false;
}
// The beast's landing: live a moment.
function stepPounce(round, h, ms) {
h.live -= ms;
return h.live > 0;
}
// A dresser: rocking at the uphill end through the creak, then sliding down the floor
// while the house leans, until it hits the far wall or the lurch is over.
function stepDresser(round, h, ms) {
if (h.dead) return false;
const b = round.boss;
if (h.warn > 0) {
h.warn = Math.max(0, h.warn - ms);
if (h.warn <= 0) h.live = 1;
return true;
}
const leaning = b && b.lurch && b.lurch.state === "go";
if (!leaning) {
round.events.push({ type: "eyeDresserCrash", kind: "marroweye", x: h.x, y: h.y + 1 });
return false;
}
h.x += h.dir * DRESSER_SPEED * (ms / 1000);
if (h.x <= round.spec.arena + DRESSER_W / 2 || h.x >= round.spec.length - DRESSER_W / 2) {
round.events.push({ type: "eyeDresserCrash", kind: "marroweye", x: h.x, y: h.y + 1 });
return false;
}
return true;
}
/* ------------------------------------------------------------- the fight */
// The lurch's turn: waiting, creaking (a dresser rocking at the uphill end of YOUR
// floor), then sliding.
function stepLurch(round, b, ms, random, k) {
const l = b.lurch;
const spec = round.spec;
const phase = phaseOf(b);
l.ms -= ms;
if (l.state === "creak") {
if (!l.stepped && l.ms <= EYE_CREAK_MS * (1 - CREAK_AT)) {
l.stepped = true;
round.events.push({ type: "eyeCreakStep", kind: "marroweye", x: (spec.arena + spec.length) / 2, y: 30, dir: l.dir });
}
if (l.ms > 0) return;
l.state = "go";
l.ms = EYE_LURCH_MS;
round.events.push({ type: "eyeLurch", kind: "marroweye", x: (spec.arena + spec.length) / 2, y: 30, dir: l.dir });
return;
}
if (l.state === "go") {
if (l.ms > 0) return;
l.state = "wait";
l.ms = EYE_LURCH_EVERY_MS[phase] / spec.pace;
return;
}
if (l.ms > 0 && !b.planLurch) return;
l.dir = b.planLurch || (random() < 0.5 ? -1 : 1);
b.planLurch = 0;
l.state = "creak";
l.ms = EYE_CREAK_MS;
l.stepped = false;
// A dresser at the uphill end of YOUR floor, unless YOU stand there: then of another floor.
const you = round.you;
const end = l.dir > 0 ? spec.arena + DRESSER_W / 2 + 0.6 : spec.length - DRESSER_W / 2 - 0.6;
let row = rowOf(standing(round, k));
if (Math.abs(you.x - end) < DRESSER_CLEAR) row = (row + 1 + Math.floor(random() * 2)) % EYE_FLOORS.length;
const rows = phase === 2 ? [row, (row + 1) % EYE_FLOORS.length] : [row];
for (const r of rows) round.hazards.push({ kind: "eyeDresser", x: end, y: EYE_FLOORS[r], w: DRESSER_W, h: DRESSER_H, dir: l.dir, hp: DRESSER_HP, warn: EYE_CREAK_MS, full: EYE_CREAK_MS, live: 0, cause: "eyeDresser" });
round.events.push({ type: "eyeCreak", kind: "marroweye", x: (spec.arena + spec.length) / 2, y: 30, dir: l.dir });
}
function moveEye(round, b, ms, random, k) {
const spec = round.spec;
if (!b.eye) {
b.eye = { state: "shut", ms: 700, room: -1, last: -1, decoy: -1, full: 1, stepped: false };
b.lurch = { state: "wait", ms: EYE_LURCH_FIRST_MS / spec.pace, dir: 1, stepped: false };
b.shadeMs = SHADE_FIRST_DOOR_MS;
b.plan = b.plan ?? -1;
}
stepEye(round, b, ms, random);
stepLurch(round, b, ms, random, k);
const phase = phaseOf(b);
b.shadeMs -= ms;
if ((b.shadeMs <= 0 || b.planShade) && shadesAlive(round) < SHADE_CAP[phase]) {
if (openDoor(round, b, random, k)) b.shadeMs = SHADE_EVERY_MS[phase] / spec.pace;
else b.shadeMs = 500;
}
}
/* --------------------------------------------------------- the stage's tick */
function retreatStep(round, b) {
const spec = round.spec;
const mid = (spec.arena + spec.length) / 2;
const stamp = (key, at, type, extra = {}) => {
if (b[key] || b.t < at) return;
b[key] = true;
round.events.push({ type, kind: "marroweye", x: mid, y: 26, ...extra });
};
stamp("burst", 0, "eyeBurst", b.eye && b.eye.room >= 0 ? eyeAt(spec, b.eye.room) : {});
stamp("peeled", PEEL_AT, "eyePeel");
CRACK_AT.forEach((at, n) => stamp(`cracked${n}`, at, "eyeCrack", { n, y: EYE_FLOORS[EYE_FLOORS.length - 1 - n] }));
stamp("gasped", GASP_AT, "eyeGasp");
stamp("sinking", SINK_AT, "eyeSink");
if (b.t >= GONE_AT && !b.gone) {
b.gone = true;
round.events.push({ type: "eyeGone", kind: "marroweye", x: spec.door, y: EYE_FLOORS[0] + 6 });
}
}
// Its box out of everything's way (only its Eye can be hurt, through eyeShot), the
// lurch pushing YOU while YOU stand, the retreat's beats, and YOU kept off its door
// until it has gone.
function eyeTick(round, ms) {
const b = round.boss;
if (!b || b.kind !== "marroweye") return;
const spec = round.spec;
if (!b.placed) {
b.placed = true;
b.x = spec.length - 0.75;
b.y = 60;
b.w = 1.5;
b.h = 2;
}
const you = round.you;
const l = b.lurch;
// How far the house leans, -1 to 1, for the art: easing in through the creak, full while it slides.
if (l && b.state === "fight") {
const target = l.state === "go" ? l.dir : l.state === "creak" ? l.dir * 0.25 * (1 - l.ms / EYE_CREAK_MS) : 0;
b.tilt = (b.tilt || 0) + (target - (b.tilt || 0)) * Math.min(1, ms / 140);
if (l.state === "go" && you.state === "run" && round.phase === "play" && !(you.out > 0)) {
you.x = clamp(you.x + l.dir * EYE_PUSH * (ms / 1000), spec.arena + WALL_PAD, spec.length - WALL_PAD);
}
} else b.tilt = (b.tilt || 0) * Math.max(0, 1 - ms / 200);
if (b.state === "down") retreatStep(round, b);
if (b.state === "down" && !b.gone && you.x > spec.door - DOOR_KEEP) {
you.x = spec.door - DOOR_KEEP;
if (you.vx > 0) you.vx = 0;
}
}
export const EYE = freeze({
id: "dollhouse",
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
swoops: freeze({}),
// A shade fading in or out can neither be hit nor hurt.
solid: freeze({ eyeShade: (m) => m.act !== "in" && m.act !== "out" }),
move: freeze({ eyeShade: moveShade }),
kill: freeze({}),
horde: freeze({}),
tick: freeze([eyeTick]),
target: eyeShot,
bosses: BOSSES,
boss: freeze({ marroweye: moveEye }),
// Only its open Eye can be hurt (eyeShot): anything else glances off.
guard: freeze({ marroweye: () => true }),
cause: freeze({ marroweye: () => "marroweye" }),
hazards: freeze({
eyeDoorway: stepDoorway,
eyeRipple: stepRoller,
eyeNote: stepRoller,
eyeHoop: stepRoller,
eyeMud: stepRoller,
eyeSkull: stepSkull,
eyeScythe: stepScythe,
eyeRock: stepDrop,
eyeIcicle: stepDrop,
eyePounce: stepPounce,
eyeDresser: stepDresser,
}),
});
@@ -0,0 +1,571 @@
// Plan2Code Web Console - Ghoul Rush's finale, its rules for the third kill, The Heart of Marrow in the Pit, as a pack core/ghoul-tables.js lists in PACKS: the beat and its shockwaves, the ribs that part between beats, the roots, the grabs, the clots and the falling rock, the beat stopping dead, and the HOLD FIRE flood that ends the House.
//
// No imports: every rule is handed the kit `k` (see stages/marrow/ghoul-marrow.js and
// stages/bog/ghoul-bog.js for what a pack holds), and randomness only through the
// `random` a boss's mover is handed.
//
// THE PIT. Absolute dark, the House's true basement. The heart stands in the middle of
// the arena on a plinth of roots (`HEART_X`), its feet below the floor line, with a pit
// on each side of it: YOU fight from the floor and the stone ledges on its left, and a
// fall down either pit costs a life (Bat wings catch one). The heart's box is the plinth
// itself, so YOU never stand beside it while it lives.
//
// THE BEAT is the fight, on the boss's own clock (never the music's). A beat is a double
// thump: the "lub" (the heart squeezes, the room flashes red), then DUB_MS later the "dub"
// sends a shockwave out along the floor each way from the lips of the pits (`heartBeat`,
// jump it). The beat comes every BEAT_MS_MAX at full hp, quickening to BEAT_MS_MIN as
// its hp falls. Between beats THE RIBS PART: from OPEN_AT after a lub, for a share of the
// beat (OPEN_SHARE_MAX at full hp narrowing to OPEN_SHARE_MIN), `b.open` is true and a
// bolt into it counts; while they are shut a bolt clanks off (`guard`).
//
// Between beats it picks a move by weight (never one three times running), each with an
// early warning seen and heard, in two steps for the ones that come up under YOU:
//
// - ROOTS (`roots`): the floor cracks and glows where YOU stand and a step either side,
// creaks, cracks again, then roots burst up (`heartRoot`). Step between or climb.
// - GRAB (`grab`, only while YOU stand on a ledge): roots curl over YOUR ledge's edges,
// tense, then whip across its whole top (`heartGrab`). Drop off or jump away.
// - CLOTS (`clots`): the pipes along the roof bulge over YOU (a shadow below, a gurgle),
// then black clots fall through everything to the floor (`heartClot`). Step aside.
// - QUAKE (`quake`, below a quarter): the room shakes and chunks of the roof come down
// where their shadows show (`heartChunk`).
//
// Below half, every few beats THE BEAT STOPS DEAD: silence, the red gone, the heart
// swelling (a groan SWELL_MS before the end is its warning), then a huge double wave
// (`heartBig`, two each way BIG_GAP_MS apart) and a long open gasp after it.
//
// THE FINAL BLOW. No bolt takes its last hp: it holds at 1, and then THE HOLD begins
// (`startHold`): the ribs lock open, every root goes limp, HOLD FIRE. `round.flood` is set,
// so the blaster fires nothing and cools (core/ghoul-play.js), and while fire is held a
// meter fills over HOLD_FILL_MS (letting go drains it over HOLD_DRAIN_MS) as YOUR beam
// grows into a flood. Weak beats still come every HOLD_BEAT_MS, each a slow ripple of its
// own (`round.heart.waves`, never the field's): one that reaches YOU only knocks the meter
// back. Full: the screen goes white, the heart stops, one last thump at LAST_AT, silence,
// and at FALL_AT `k.hurtBoss` gives the ordinary fall (a life, the points, the key).
// DAYLIGHT_AT after the fall a shaft of daylight comes down to the room's door, a door of
// light (`b.gone`); until then the door stays shut. There is no retreat: it lingers dead.
//
// A respawn makes a new boss object with only its hp kept, so the hold lives on
// `round.heart`, keyed by `round.room`.
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
export const BOSSES = freeze({
marrowheart: freeze({ name: "The Heart of Marrow", sub: "Far below it all, still beating", w: 34, h: 40, hp: 85, points: 9000, color: "#d0283c" }),
});
// Where it stands, and its real box (the plinth of roots between the two pits): BOSSES'
// w and h size the intro card's spotlight to the whole heart instead.
export const HEART_X = 132;
export const HEART_BOX_W = 16;
export const HEART_BOX_H = 26;
// The lips of the pits either side of the heart, where its waves start.
export const LEFT_LIP = 118;
export const RIGHT_LIP = 146;
// The beat: its interval from full hp to none, the dub after the lub, when the ribs part
// after a lub and for what share of the beat, by hp from full to none.
export const BEAT_MS_MAX = 1500;
export const BEAT_MS_MIN = 750;
export const DUB_MS = 300;
export const OPEN_AT = 380;
export const OPEN_SHARE_MAX = 0.4;
export const OPEN_SHARE_MIN = 0.25;
// The heart swells this long before a lub (the art's warning).
export const SWELL_LEAD_MS = 420;
// The first beat after it wakes, this long into the fight.
export const FIRST_BEAT_MS = 700;
export const beatFor = (share) => Math.round(BEAT_MS_MIN + (BEAT_MS_MAX - BEAT_MS_MIN) * clamp(share, 0, 1));
export const openFor = (share) => OPEN_SHARE_MIN + (OPEN_SHARE_MAX - OPEN_SHARE_MIN) * clamp(share, 0, 1);
// Its phase by hp share: 0, then 1 at or below half (the beat stops dead), 2 at or below a quarter (the quake).
export const PHASE_AT = freeze([0.5, 0.25]);
export const phaseFor = (share) => (share <= PHASE_AT[1] ? 2 : share <= PHASE_AT[0] ? 1 : 0);
// The beat stopping dead (phase 1 on): every STOP_EVERY beats or so (a spread of
// STOP_SPREAD more), silent STOP_MS, its swell heard SWELL_MS before the end, then the big
// wave and its echo BIG_GAP_MS later, and the ribs open GASP times as long after it.
export const STOP_EVERY = 6;
export const STOP_SPREAD = 3;
export const STOP_MS = 1800;
export const SWELL_MS = 800;
export const BIG_GAP_MS = 320;
export const GASP = 1.8;
// The moves: a wait between (shorter by phase, quicker with the room's pace).
export const IDLE_MS = 1700;
export const IDLE_JITTER = 0.25;
export const PHASE_PACE = freeze([1, 0.85, 0.72]);
// Roots: each warns ROOT_WARN_MS (the later ones ROOT_STAGGER_MS after), creaking at the
// start and cracking at ROOT_CRACK of it, then stands ROOT_UP_MS, ROOT_W by ROOT_H.
export const ROOT_WARN_MS = 1100;
export const ROOT_CRACK = 0.55;
export const ROOT_STAGGER_MS = 140;
export const ROOT_UP_MS = 650;
export const ROOT_W = 2.6;
export const ROOT_H = 6.5;
export const ROOT_GAP = 7;
export const ROOT_N = freeze([2, 3, 3]);
// The grab: roots curl over YOUR ledge GRAB_WARN_MS (tensing at GRAB_TENSE of it), then
// whip across its top GRAB_LIVE_MS, GRAB_H high.
export const GRAB_WARN_MS = 1150;
export const GRAB_TENSE = 0.55;
export const GRAB_LIVE_MS = 650;
export const GRAB_H = 3.4;
// Clots: a bulge on the pipe over YOU for CLOT_WARN_MS (the later ones CLOT_STAGGER_MS
// after), then a fall from CLOT_TOP to the floor in CLOT_FALL_MS, through ledges.
export const CLOT_WARN_MS = 1000;
export const CLOT_STAGGER_MS = 150;
export const CLOT_FALL_MS = 380;
export const CLOT_TOP = 46;
export const CLOT_W = 2.6;
export const CLOT_H = 2.2;
export const CLOT_GAP = 6;
export const CLOT_N = freeze([1, 2, 3]);
// The quake: CHUNK_N chunks of roof, each warning CHUNK_WARN_MS (staggered), falling from CHUNK_TOP.
export const CHUNK_WARN_MS = 950;
export const CHUNK_STAGGER_MS = 180;
export const CHUNK_FALL_MS = 420;
export const CHUNK_TOP = 52;
export const CHUNK_W = 3.2;
export const CHUNK_H = 2.6;
export const CHUNK_N = 3;
// Each move's weight by phase; `grab` only while YOU are on a ledge (and then it is likeliest).
export const WEIGHTS = freeze({
roots: freeze([3, 3, 3]),
clots: freeze([3, 3, 2.5]),
grab: freeze([4, 4, 4]),
quake: freeze([0, 0, 3]),
});
// The hold: the meter's fill and drain, the knock a ripple takes off it, the weak beat
// and its slow ripple (HOLD_WAVE_H high, as a shockwave), and the flood's words at each quarter.
export const HOLD_FILL_MS = 4000;
export const HOLD_DRAIN_MS = 9000;
export const HOLD_KNOCK = 0.18;
export const HOLD_BEAT_MS = 1500;
export const HOLD_WAVE_SPEED = 24;
export const HOLD_WAVE_H = 2.2;
export const FLOOD_STEPS = freeze([0.25, 0.5, 0.75]);
// The end, from the meter full: the white, the last thump, the fall; then after the fall,
// the daylight and its door.
export const WHITE_IN_MS = 260;
export const WHITE_HOLD_MS = 1500;
export const LAST_AT = 900;
export const FALL_AT = 2100;
export const WHITE_OUT_MS = 1300;
export const DAYLIGHT_AT = 1800;
/* ------------------------------------------------------------ state */
// The heart's fight for this room, kept across a life lost.
export function heartOf(round) {
if (!round.heart || round.heart.room !== round.room) round.heart = { room: round.room, hold: false, meter: 0, beatMs: 0, waves: [], step: 0, final: false, endT: 0, last: false };
return round.heart;
}
const live = (round) => (round.heart && round.heart.room === round.room ? round.heart : null);
// How white the screen is, 0 to 1: up as the meter fills, held, then fading after the fall.
export function whiteOf(round) {
const h = live(round);
const b = round.boss;
if (!h || !h.final || !b || b.kind !== "marrowheart") return 0;
// One clock from the meter full: the hold's own until the fall, then the fall's.
const t = b.state === "down" ? FALL_AT + (b.t || 0) : h.endT;
if (t < WHITE_IN_MS) return t / WHITE_IN_MS;
if (t < WHITE_HOLD_MS) return 1;
return clamp(1 - (t - WHITE_HOLD_MS) / WHITE_OUT_MS, 0, 1);
}
// The hp share the beat and the ribs go by.
const shareOf = (b) => (b.max > 0 ? b.hp / b.max : 1);
// The floor or ledge YOU stand on (or are over in the air): its height and shelf index.
function standing(round, k) {
const you = round.you;
if (you.state === "run") return { y: you.y, shelf: you.shelf };
let top = k.groundAt(round.spec, you.x);
let shelf = -1;
round.spec.shelves.forEach(([x0, x1, y], i) => {
if (you.x >= x0 && you.x <= x1 && y <= you.y && y > top) {
top = y;
shelf = i;
}
});
return { y: top, shelf };
}
// Where a thing on the floor may go: the left floor of the arena, clear of the pit's lip.
const floorRange = (spec, x) => clamp(x, spec.arena + 3, LEFT_LIP - 1.6);
/* ------------------------------------------------------------ the moves */
// Its next move by weight: never a third time running, `grab` only on a ledge, `quake`
// only below a quarter. `b.plan` forces one (tests).
export function pickMove(b, phase, random, ledge = false) {
let pick = null;
if (b.plan) {
pick = b.plan;
b.plan = null;
} else {
const w = {};
for (const [n, by] of Object.entries(WEIGHTS)) {
let v = by[phase];
if (n === "grab" && !ledge) v = 0;
if (n === b.last) v *= b.streak >= 2 ? 0 : 0.4;
if (v > 0) w[n] = v;
}
const names = Object.keys(w);
let r = random() * names.reduce((sum, n) => sum + w[n], 0);
pick = names[0] || "roots";
for (const n of names) {
pick = n;
if ((r -= w[n]) < 0) break;
}
}
b.streak = pick === b.last ? (b.streak || 1) + 1 : 1;
b.last = pick;
return pick;
}
function startMove(round, b, move, phase, random, k) {
const spec = round.spec;
const you = round.you;
const ahead = Math.sign(you.vx) || you.face || 1;
const ev = (type, extra = {}) => round.events.push({ type, kind: "marrowheart", x: HEART_X, y: b.y + 20, ...extra });
b.act = move;
if (move === "roots") {
const offs = [0, ahead, -ahead].slice(0, ROOT_N[phase]);
const xs = [];
offs.forEach((o, i) => {
const x = floorRange(spec, you.x + o * ROOT_GAP);
if (xs.some((q) => Math.abs(q - x) < ROOT_W + 1)) return;
xs.push(x);
const warn = ROOT_WARN_MS + i * ROOT_STAGGER_MS;
round.hazards.push({ kind: "heartRoot", x, y: k.groundAt(spec, x), w: ROOT_W, h: ROOT_H, warn, full: warn, live: 0, cause: "heartRoot", id: i });
});
b.wait = ROOT_WARN_MS + ROOT_STAGGER_MS * Math.max(0, xs.length - 1) + ROOT_UP_MS;
ev("heartRootWind", { xs, y: k.groundAt(spec, xs[0] ?? you.x) });
} else if (move === "grab") {
const at = standing(round, k);
const s = spec.shelves[at.shelf];
if (!s) return startMove(round, b, "roots", phase, random, k);
const x = (s[0] + s[1]) / 2;
round.hazards.push({ kind: "heartGrab", x, y: s[2], w: s[1] - s[0] + 0.6, h: GRAB_H, warn: GRAB_WARN_MS, full: GRAB_WARN_MS, live: 0, cause: "heartGrab", shelf: at.shelf, x0: s[0], x1: s[1] });
b.wait = GRAB_WARN_MS + GRAB_LIVE_MS;
ev("heartGrabWind", { x, y: s[2] });
} else if (move === "clots") {
const offs = [0, ahead, -ahead].slice(0, CLOT_N[phase]);
const xs = [];
const floor = k.groundAt(spec, floorRange(spec, you.x));
offs.forEach((o, i) => {
const x = floorRange(spec, you.x + o * CLOT_GAP);
if (xs.some((q) => Math.abs(q - x) < CLOT_W + 1)) return;
xs.push(x);
const warn = CLOT_WARN_MS + i * CLOT_STAGGER_MS;
round.hazards.push({ kind: "heartClot", x, y: CLOT_TOP, w: CLOT_W, h: CLOT_H, floor, top: CLOT_TOP, fallMs: CLOT_FALL_MS, warn, full: warn, fall: 0, live: 0, cause: "heartClot", id: i });
});
b.wait = CLOT_WARN_MS + CLOT_STAGGER_MS * Math.max(0, xs.length - 1) + CLOT_FALL_MS;
ev("heartClotWind", { xs, y: CLOT_TOP });
} else if (move === "quake") {
// One where YOU stand, the rest anywhere on the floor, never on top of each other.
const xs = [floorRange(spec, you.x)];
for (let i = 1, tries = 0; i < CHUNK_N && tries < 20; tries++) {
const x = floorRange(spec, spec.arena + 3 + random() * (LEFT_LIP - spec.arena - 4));
if (xs.some((q) => Math.abs(q - x) < CHUNK_W + 2)) continue;
xs.push(x);
i++;
}
xs.forEach((x, i) => {
const warn = CHUNK_WARN_MS + i * CHUNK_STAGGER_MS;
round.hazards.push({ kind: "heartChunk", x, y: CHUNK_TOP, w: CHUNK_W, h: CHUNK_H, floor: k.groundAt(spec, x), top: CHUNK_TOP, fallMs: CHUNK_FALL_MS, warn, full: warn, fall: 0, live: 0, cause: "heartChunk", id: i });
});
b.wait = CHUNK_WARN_MS + CHUNK_STAGGER_MS * (xs.length - 1) + CHUNK_FALL_MS;
ev("heartQuake", { xs, y: b.y });
}
}
// A wave out of each pit's lip: the left one runs at YOU, the right one off to the end.
function beatWaves(round, b, kind) {
round.waves.push({ x: LEFT_LIP - 0.5, y: b.y, dir: -1, life: 6000, kind, cause: kind });
round.waves.push({ x: RIGHT_LIP + 0.5, y: b.y, dir: 1, life: 6000, kind, cause: kind });
}
/* ------------------------------------------------------------ the hold */
// Its last hp: the ribs lock open, the roots go limp, HOLD FIRE.
export function startHold(round, b) {
const h = heartOf(round);
if (h.hold) return;
Object.assign(h, { hold: true, meter: 0, beatMs: 0, waves: [], step: 0, final: false, endT: 0, last: false });
b.hp = Math.max(1, Math.min(b.hp, 1));
b.open = true;
round.hazards.length = 0;
round.waves.length = 0;
round.flood = true;
round.events.push({ type: "heartHold", kind: "marrowheart", x: HEART_X, y: b.y + 20 });
}
function stepHold(round, b, h, ms, k) {
const you = round.you;
b.open = true;
b.act = "hold";
if (h.final) {
h.endT += ms;
if (!h.last && h.endT >= LAST_AT) {
h.last = true;
round.events.push({ type: "heartLast", kind: "marrowheart", x: HEART_X, y: b.y + 20 });
}
if (h.endT >= FALL_AT) k.hurtBoss(round, b.hp, "shot", { x: HEART_X, y: b.y + 20 });
return;
}
// The weak beat, and its slow ripple out of the left pit.
h.beatMs += ms;
if (h.beatMs >= HOLD_BEAT_MS) {
h.beatMs -= HOLD_BEAT_MS;
h.waves.push({ x: LEFT_LIP - 0.5, y: b.y, dir: -1 });
round.events.push({ type: "heartWeakBeat", kind: "marrowheart", x: HEART_X, y: b.y + 20 });
}
const dt = ms / 1000;
let n = 0;
for (const w of h.waves) {
w.x += w.dir * HOLD_WAVE_SPEED * dt;
if (you.out <= 0 && Math.abs(w.x - you.x) < 1.4 && you.y < w.y + HOLD_WAVE_H) {
h.meter = Math.max(0, h.meter - HOLD_KNOCK);
round.events.push({ type: "heartKnock", kind: "marrowheart", x: you.x, y: you.y + 2, meter: h.meter });
continue;
}
if (w.x > round.spec.arena - 2) h.waves[n++] = w;
}
h.waves.length = n;
const held = round.input.fire && you.out <= 0;
h.meter = clamp(h.meter + (held ? ms / HOLD_FILL_MS : -ms / HOLD_DRAIN_MS), 0, 1);
// The flood swells out loud at each quarter, a step higher each time it climbs past one.
while (h.step < FLOOD_STEPS.length && h.meter >= FLOOD_STEPS[h.step]) {
h.step++;
round.events.push({ type: "heartFlood", kind: "marrowheart", x: you.x, y: you.y + 3, n: h.step });
}
while (h.step > 0 && h.meter < FLOOD_STEPS[h.step - 1] - 0.08) h.step--;
if (h.meter >= 1) {
h.final = true;
h.endT = 0;
h.waves.length = 0;
round.events.push({ type: "heartWhite", kind: "marrowheart", x: HEART_X, y: b.y + 20 });
}
}
/* ------------------------------------------------------------ the fight */
function moveHeart(round, b, ms, random, k) {
const h = heartOf(round);
if (h.hold) return stepHold(round, b, h, ms, k);
const spec = round.spec;
const share = shareOf(b);
const phase = phaseFor(share);
const ev = (type, extra = {}) => round.events.push({ type, kind: "marrowheart", x: HEART_X, y: b.y + 20, ...extra });
if (!b.beatT) {
b.beatT = beatFor(share);
b.beatMs = b.beatT - FIRST_BEAT_MS;
b.beats = 0;
b.stopAt = STOP_EVERY + Math.floor(random() * (STOP_SPREAD + 1));
b.act = "idle";
b.wait = IDLE_MS;
b.dubbed = true;
b.opened = true;
}
// The beat stopped dead: silence, the swell, then the big wave and its echo.
if (b.stopMs > 0) {
b.open = false;
b.stopMs -= ms;
if (!b.swelled && b.stopMs <= SWELL_MS) {
b.swelled = true;
ev("heartSwell");
}
if (b.stopMs > 0) return;
b.stopMs = 0;
beatWaves(round, b, "heartBig");
ev("heartSlam", { x: LEFT_LIP, y: b.y });
b.echo = BIG_GAP_MS;
b.gasp = true;
b.beatMs = DUB_MS;
b.beatT = beatFor(share);
b.dubbed = true;
b.opened = false;
return;
}
if (b.echo > 0 && (b.echo -= ms) <= 0) {
b.echo = 0;
beatWaves(round, b, "heartBig");
ev("heartSlam", { x: LEFT_LIP, y: b.y, echo: true });
}
b.beatMs += ms;
if (b.beatMs >= b.beatT) {
b.beatMs -= b.beatT;
b.beats++;
// Below half, now and then the beat that was due never comes.
if (phase >= 1 && b.beats >= b.stopAt) {
b.beats = 0;
b.stopAt = STOP_EVERY + Math.floor(random() * (STOP_SPREAD + 1));
b.stopMs = STOP_MS;
b.swelled = false;
b.open = false;
b.beatMs = 0;
ev("heartStop");
return;
}
b.beatT = beatFor(share);
b.dubbed = false;
b.opened = false;
b.gasp = false;
ev("heartBeat", { t: b.beatT });
}
if (!b.dubbed && b.beatMs >= DUB_MS) {
b.dubbed = true;
beatWaves(round, b, "heartBeat");
ev("heartWave", { x: LEFT_LIP, y: b.y });
}
const span = openFor(share) * b.beatT * (b.gasp ? GASP : 1);
b.open = b.beatMs >= OPEN_AT && b.beatMs < OPEN_AT + span;
if (b.open && !b.opened) {
b.opened = true;
ev("heartOpen");
}
// How near the next lub is, 0 to 1 over SWELL_LEAD_MS (the art's swell).
b.swell = clamp(1 - (b.beatT - b.beatMs) / SWELL_LEAD_MS, 0, 1);
// The moves, between the beats.
b.wait -= ms;
if (b.wait > 0) return;
const wait = (v) => (v * PHASE_PACE[phase]) / spec.pace;
if (b.act === "idle") {
const at = standing(round, k);
startMove(round, b, pickMove(b, phase, random, at.shelf >= 0), phase, random, k);
b.attacks = (b.attacks || 0) + 1;
return;
}
b.act = "idle";
b.wait = wait(IDLE_MS * (1 - IDLE_JITTER + 2 * IDLE_JITTER * random()));
}
/* -------------------------------------------------------------- hazards */
// A root: the floor cracking for `warn` (a second crack at ROOT_CRACK of it), then up.
function stepRoot(round, h, ms) {
if (h.warn > 0) {
h.warn = Math.max(0, h.warn - ms);
if (!h.cracked && 1 - h.warn / (h.full || 1) >= ROOT_CRACK) {
h.cracked = true;
if (!h.id) round.events.push({ type: "heartRootCrack", kind: "marrowheart", x: h.x, y: h.y });
}
if (h.warn > 0) return true;
h.live = ROOT_UP_MS;
round.events.push({ type: "heartRootUp", kind: "marrowheart", x: h.x, y: h.y });
return true;
}
h.live -= ms;
return h.live > 0;
}
// A grab: roots curling over the ledge for `warn` (tensing at GRAB_TENSE), then across it.
function stepGrab(round, h, ms) {
if (h.warn > 0) {
h.warn = Math.max(0, h.warn - ms);
if (!h.tensed && 1 - h.warn / (h.full || 1) >= GRAB_TENSE) {
h.tensed = true;
round.events.push({ type: "heartGrabTense", kind: "marrowheart", x: h.x, y: h.y });
}
if (h.warn > 0) return true;
h.live = GRAB_LIVE_MS;
round.events.push({ type: "heartGrabLash", kind: "marrowheart", x: h.x, y: h.y });
return true;
}
h.live -= ms;
return h.live > 0;
}
// A clot or a chunk of roof: its shadow for `warn`, then falling through everything to the floor.
function stepFall(round, h, ms) {
if (h.warn > 0) {
h.warn = Math.max(0, h.warn - ms);
if (h.warn > 0) return true;
h.live = 1;
h.fall = 0;
return true;
}
h.fall += ms;
const p = Math.min(1, h.fall / h.fallMs);
h.y = h.top + (h.floor - h.top) * p * p;
if (p < 1) return true;
round.events.push({ type: h.kind === "heartClot" ? "heartClotLand" : "heartChunkLand", kind: "marrowheart", x: h.x, y: h.floor });
return false;
}
/* --------------------------------------------------------- the stage's tick */
// The heart in its place and its box the plinth; the hold's flood on while it holds; after
// the fall, the door shut until the daylight comes down to it.
function heartTick(round, ms, k) {
const b = round.boss;
if (!b || b.kind !== "marrowheart") return;
const spec = round.spec;
const h = heartOf(round);
if (!b.placed) {
b.placed = true;
b.x = HEART_X;
b.y = k.groundAt(spec, HEART_X);
b.w = HEART_BOX_W;
b.h = HEART_BOX_H;
// A weapon's hit that could take its last hp at once glances off below this (guard).
const base = BOSSES.marrowheart.hp;
b.reserve = Math.ceil((10 * spec.bossHp) / base) + 1;
if (h.hold) {
b.hp = 1;
b.open = true;
}
}
round.flood = h.hold && b.state !== "down";
if (b.state !== "down") return;
if (!b.gone && b.t >= DAYLIGHT_AT) {
b.gone = true;
round.events.push({ type: "heartDaylight", kind: "marrowheart", x: spec.door, y: k.groundAt(spec, spec.door) + 8 });
}
round.hasKey = !!b.gone;
}
// A bolt (or a thrown weapon) into the heart: while the ribs are open it counts, never past
// its last hp, and that last hp begins the hold; while shut it falls to the guard, a clank.
const touchBox = (x, y, r, bx, by, w, h) => Math.hypot(x - clamp(x, bx - w / 2, bx + w / 2), y - clamp(y, by, by + h)) < r;
function heartShot(round, s, k) {
const b = round.boss;
if (!b || b.kind !== "marrowheart" || b.state !== "fight" || !b.placed) return false;
if (!touchBox(s.x, s.y, 0.5, b.x, b.y, b.w, b.h)) return false;
if (!b.open || (round.heart && round.heart.hold)) return false;
const dmg = s.arm ? k.armBossDamage(round, s.bossDmg || 1) : s.dmg || 1;
const d = Math.min(dmg, b.hp - 1);
if (d > 0) k.hurtBoss(round, d, "shot", { x: s.x, y: s.y });
if (b.hp <= 1) startHold(round, b);
return true;
}
export const HEART = freeze({
id: "pit",
monsters: freeze({}),
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
swoops: freeze({}),
solid: freeze({}),
move: freeze({}),
kill: freeze({}),
horde: freeze({}),
tick: freeze([heartTick]),
target: heartShot,
bosses: BOSSES,
boss: freeze({ marrowheart: moveHeart }),
// Shut ribs clank; so does any weapon's blow late in the fight (it could skip the hold) and everything in the hold.
guard: freeze({ marrowheart: (b) => !b.open || b.hp <= (b.reserve || 0) || b.act === "hold" }),
cause: freeze({ marrowheart: () => "marrowheart" }),
hazards: freeze({ heartRoot: stepRoot, heartGrab: stepGrab, heartClot: stepFall, heartChunk: stepFall }),
});
@@ -29,6 +29,15 @@
// - STOMP (`stomp`, furious only): it rears and comes down: a shockwave to jump
// and slates after it.
//
// Two more come only while YOU are up in the oak (`high`), where the floor's moves
// cannot reach, so the branches are never a safe seat:
//
// - LIGHTNING (`lightning`): the storm gathers over YOUR branch (a glow where YOU
// stand, one more a step ahead from the second phase) and charges up, loud and
// bright, a step at each CHARGE_AT, then a bolt strikes down to it. Step along, or drop.
// - CROWS (`crows`): the door opens and crows burst out of its mouth, climb, and dive
// at YOUR chest (the Graveyard's carrion crows), at most CROWS_CAP of its own.
//
// Its phase is 0 at first, 1 with PHASE_OUT[0] windows out, 2 with PHASE_OUT[1].
//
// THE RETREAT. The last window out is a real boss kill (a life, the points,
@@ -41,7 +50,7 @@ const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
export const BOSSES = freeze({
marrow: freeze({ name: "Marrow", sub: "The house itself", w: 36, h: 44, hp: 90, points: 6000, color: "#c8a04a" }),
marrow: freeze({ name: "Marrow", sub: "The house itself", w: 36, h: 44, hp: 110, points: 6000, color: "#c8a04a" }),
});
// The house's place: its left edge HOUSE_BACK short of the room's end, YOU kept
@@ -118,9 +127,24 @@ export const DOORMEN_CAP = 2;
export const STOMP_WIND_MS = 950;
export const STOMP_LIFT = 2.4;
export const STOMP_REST_MS = 1300;
// Lightning: the storm gathers LIGHTNING_WIND_MS, each glow warns LIGHTNING_WARN_MS (the
// second LIGHTNING_STAGGER_MS after), and the bolt is live LIGHTNING_LIVE_MS, LIGHTNING_W
// wide, from the branch up to the sky; the second LIGHTNING_GAP ahead of YOU.
// While a glow warns it charges up out loud, a step at each of CHARGE_AT (shares of its warning).
export const LIGHTNING_WIND_MS = 300;
export const LIGHTNING_WARN_MS = 1500;
export const CHARGE_AT = freeze([0.35, 0.7]);
export const LIGHTNING_STAGGER_MS = 220;
export const LIGHTNING_LIVE_MS = 240;
export const LIGHTNING_W = 3;
export const LIGHTNING_GAP = 6;
// Crows: the door opens CROWS_WIND_MS, then CROWS_N by phase fly out, at most CROWS_CAP of its own alive.
export const CROWS_WIND_MS = 650;
export const CROWS_N = freeze([2, 2, 3]);
export const CROWS_CAP = 3;
// How many picks a move sits out after it is used.
export const COOLDOWN = freeze({ doormen: 4, stomp: 2, bricks: 1 });
// Each move's weight by phase.
export const COOLDOWN = freeze({ doormen: 4, stomp: 2, bricks: 1, crows: 2 });
// Each move's weight by phase. HIGH_WEIGHTS are added only while YOU are up in the oak.
export const WEIGHTS = freeze({
shingles: freeze([3, 2.5, 2.5]),
carpet: freeze([3, 2.5, 2.5]),
@@ -129,6 +153,15 @@ export const WEIGHTS = freeze({
doormen: freeze([0, 1.6, 1.6]),
stomp: freeze([0, 0, 3]),
});
export const HIGH_WEIGHTS = freeze({
lightning: freeze([3, 3.5, 4]),
crows: freeze([2, 2.5, 3]),
});
// Whether YOU are up in the oak: standing on a branch, or in the air well over the lawn.
export const isHigh = (round) => {
const you = round.you;
return you.state === "run" ? you.shelf >= 0 : you.y > round.spec.ground[0][2] + 8;
};
// The retreat's clock, in ms of `b.t` after the kill.
export const FALSE_AT = 1400;
@@ -176,23 +209,25 @@ function changeLights(round, b, random) {
// A bolt across the front of the house: it strikes the first lit window at its
// height (the one nearest where it is), or flies on over the shutters. Returns
// true when it has hit one.
// true when it has hit one, or has gone past the house without.
function windowShot(round, s, k) {
const b = round.boss;
if (!b || b.kind !== "marrow" || b.state !== "fight" || !round.marrow) return false;
const cx = houseCenter(round.spec);
// Past the house's far wall a bolt that found no window is spent, quietly.
if (s.x >= cx + HOUSE_W / 2) return true;
for (const w of round.marrow.windows) {
if (w.state !== "lit" || Math.abs(s.x - (cx + w.dx)) > WINDOW_W / 2 + 0.3) continue;
if (Math.abs(s.y - (b.y + w.up + WINDOW_H / 2)) > WINDOW_H / 2 + 0.3) continue;
const dmg = Math.min(w.hp, Math.max(1, s.arm ? k.armBossDamage(round, s.bossDmg || 1) : 1));
w.hp -= dmg;
const out = w.hp <= 0;
if (out) {
const at = { x: cx + w.dx, y: b.y + w.up + WINDOW_H / 2 };
if (w.hp <= 0) {
w.state = "out";
b.relight = RELIGHT_MS;
round.events.push({ type: "marrowWindowOut", kind: "marrow", x: cx + w.dx, y: b.y + w.up + WINDOW_H / 2, left: round.marrow.windows.filter((q) => q.state !== "out").length });
round.events.push({ type: "marrowWindowOut", kind: "marrow", x: at.x, y: at.y, left: round.marrow.windows.filter((q) => q.state !== "out").length });
}
k.hurtBoss(round, dmg, "weak");
k.hurtBoss(round, dmg, "window", at);
return true;
}
return false;
@@ -202,8 +237,9 @@ function windowShot(round, s, k) {
// Its next move: the carpet to open, then a weighted pick by phase that favors
// a change (a third time running is out), the slow moves sitting out COOLDOWN
// picks, the doormen only under their cap. `b.plan` forces one (tests).
export function pickMove(b, phase, random, adds = 0) {
// picks, the doormen and crows only under their caps, the lightning and the crows
// only while YOU are `high` in the oak. `b.plan` forces one (tests).
export function pickMove(b, phase, random, adds = 0, high = false, crows = 0) {
let pick = null;
if (b.plan) {
pick = b.plan;
@@ -211,10 +247,12 @@ export function pickMove(b, phase, random, adds = 0) {
} else if (!b.picks) pick = "carpet";
else {
const w = {};
for (const [n, by] of Object.entries(WEIGHTS)) {
for (const [n, by] of Object.entries({ ...WEIGHTS, ...HIGH_WEIGHTS })) {
let v = by[phase];
if (HIGH_WEIGHTS[n] && !high) v = 0;
if (b.cool && b.cool[n] > b.picks) v = 0;
if (n === "doormen" && adds >= DOORMEN_CAP) v = 0;
if (n === "crows" && crows >= CROWS_CAP) v = 0;
if (n === b.last) v *= b.streak >= 2 ? 0 : 0.35;
if (v > 0) w[n] = v;
}
@@ -297,9 +335,37 @@ function startMove(round, b, move, k, wait) {
b.wait = STOMP_WIND_MS;
b.windFull = STOMP_WIND_MS;
ev("marrowRear", { y: b.y + 20 });
} else if (move === "lightning") {
// A glow where YOU stand, and from the second phase one a step ahead: each bolt comes down to that height.
const y = standing(round, k);
const ahead = Math.sign(you.vx) || you.face || 1;
const xs = [you.x];
if (phase >= 1) xs.push(lawnRange(spec, you.x + ahead * LIGHTNING_GAP));
xs.forEach((x, i) => {
const warn = LIGHTNING_WIND_MS + LIGHTNING_WARN_MS + i * LIGHTNING_STAGGER_MS;
round.hazards.push({ kind: "marrowBolt", x, y, w: LIGHTNING_W, h: 60, warn, full: warn, live: 0, cause: "marrowBolt", id: i });
});
b.act = "storm";
b.wait = LIGHTNING_WIND_MS + LIGHTNING_WARN_MS + LIGHTNING_STAGGER_MS * (xs.length - 1) + LIGHTNING_LIVE_MS;
ev("marrowStorm", { xs, y });
} else if (move === "crows") {
b.act = "crowsWind";
b.wait = wait(CROWS_WIND_MS);
ev("marrowDoor");
}
}
// The height of what YOU stand on (or are over, in the air): a branch, or the lawn.
function standing(round, k) {
const you = round.you;
if (you.state === "run") return you.y;
let top = k.groundAt(round.spec, you.x);
for (const [x0, x1, y] of round.spec.shelves) if (you.x >= x0 && you.x <= x1 && y <= you.y && y > top) top = y;
return top;
}
const crowsAlive = (round) => round.monsters.filter((m) => !m.dead && m.houseCrow).length;
// Where a brick lands: on the surface under `x` at YOUR height when one is there, else the ground.
function brickSpot(round, x, k) {
const spec = round.spec;
@@ -330,11 +396,11 @@ function moveMarrow(round, b, ms, random, k) {
}
if (b.litMs <= 0) changeLights(round, b, random);
// The door stays open through a wind-up and its rest.
b.mouth = b.act === "carpetWind" || b.act === "doormenWind" || b.act === "carpetRest";
b.mouth = b.act === "carpetWind" || b.act === "doormenWind" || b.act === "carpetRest" || b.act === "crowsWind";
b.lift = b.act === "stompWind" ? STOMP_LIFT * (1 - Math.max(0, b.wait) / b.windFull) : 0;
if (b.act === "idle") {
if (b.wait > 0) return;
const move = pickMove(b, phase, random, doormenAlive(round));
const move = pickMove(b, phase, random, doormenAlive(round), isHigh(round), crowsAlive(round));
b.attacks++;
startMove(round, b, move, k, wait);
return;
@@ -389,6 +455,15 @@ function moveMarrow(round, b, ms, random, k) {
b.wait = idle();
return;
}
if (b.act === "crowsWind") {
// Out of its mouth, climbing a moment before each dives at YOU.
const n = Math.min(CROWS_N[phase], CROWS_CAP - crowsAlive(round));
for (let i = 0; i < n; i++) k.spawnMonster(round, "crow", houseLeft(spec) - 1 - i * 1.5, b.y + 4 + i, { houseCrow: true, force: true, act: "climb", wait: 350 + i * 300, vy: 14, vx: -10 - i * 4, awake: true });
round.events.push({ type: "marrowCrows", kind: "marrow", x: houseLeft(spec), y: b.y + 5, n });
b.act = "idle";
b.wait = idle();
return;
}
if (b.act === "stompWind") {
const x = houseLeft(spec) - 0.5;
round.waves.push({ x, y: b.y, dir: -1, life: 6000, kind: "marrowQuake", cause: "marrowQuake" });
@@ -398,7 +473,7 @@ function moveMarrow(round, b, ms, random, k) {
b.wait = wait(STOMP_REST_MS);
return;
}
if (b.act === "roof" || b.act === "pickets" || b.act === "stompRest") {
if (b.act === "roof" || b.act === "pickets" || b.act === "stompRest" || b.act === "storm") {
b.act = "idle";
b.wait = idle();
}
@@ -449,6 +524,26 @@ function stepBrick(round, h, ms) {
return h.live > 0;
}
// A bolt of lightning: a glow on the branch for `warn`, then the strike, live LIGHTNING_LIVE_MS.
function stepBolt(round, h, ms) {
if (h.warn > 0) {
h.warn = Math.max(0, h.warn - ms);
// The charge building, out loud, a step at each mark (the first bolt's only, so a pair is one sound).
const p = 1 - h.warn / (h.full || 1);
h.charged = h.charged || 0;
while (h.charged < CHARGE_AT.length && p >= CHARGE_AT[h.charged]) {
h.charged++;
if (!h.id) round.events.push({ type: "marrowCharge", kind: "marrow", x: h.x, y: h.y, n: h.charged });
}
if (h.warn > 0) return true;
h.live = LIGHTNING_LIVE_MS;
round.events.push({ type: "marrowStrike", kind: "marrow", x: h.x, y: h.y });
return true;
}
h.live -= ms;
return h.live > 0;
}
/* --------------------------------------------------------- the stage's tick */
// The house in its place, its box out of the way (only the windows can be hit), YOU
@@ -515,5 +610,5 @@ export const MARROW = freeze({
// Only its windows can be hurt (windowShot): anything else glances off.
guard: freeze({ marrow: () => true }),
cause: freeze({ marrow: () => "marrow" }),
hazards: freeze({ marrowShingle: stepShingle, marrowPicket: stepPicket, marrowBrick: stepBrick }),
hazards: freeze({ marrowShingle: stepShingle, marrowPicket: stepPicket, marrowBrick: stepBrick, marrowBolt: stepBolt }),
});
@@ -0,0 +1,28 @@
// Plan2Code Web Console - Ghoul Rush's finale, the room for the finale's third kill, The Heart of Marrow in the Pit: data only, no imports. core/ghoul-rooms.js builds it through its room() helper and lists it in FINALE.rooms once `ready` is true.
//
// The House's true basement, always dark: a short walk in from where the Bone Stair
// drops YOU, then the arena (its last 96 units). The heart stands on a plinth of roots
// between two pits (118 to 124 and 140 to 146; its rules are in ghoul-marrow-heart.js),
// with the floor and three stone ledges on its left to fight from. The door at the end
// is shut until the daylight comes down to it after the heart has stopped.
export const PIT_ROOM = Object.freeze({
ready: true,
id: "pit",
title: "The Pit",
sub: "It has never once skipped a beat",
// The room's spec, in the shape room() in core/ghoul-rooms.js takes.
spec: {
length: 160,
ground: [[0, 118, 6], [124, 140, 6], [146, 160, 6]],
// Stone ledges up the left of the arena, hung with roots.
shelves: [[80, 90, 13], [94, 104, 19], [106, 114, 13]],
key: null,
door: 154,
dark: true,
candy: [[16, 8.5, 5], [40, 8.5, 5]],
items: [["wings", 28, 6], ["garlic", 52, 6]],
spawns: [],
boss: "marrowheart",
},
});
@@ -0,0 +1,478 @@
// Plan2Code Web Console - ghoul: the sounds for the finale's second kill, Marrow, Every Room at Once (the Eye), merged into sfx/ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-marrow.js: `tones` (the Eye's `ghoulEye<Act>` and its
// shades' `ghoulEyeShade<Act>` sounds, none over 1.2 s with its delay). `music` holds
// ghoulMarrowRooms, the user's pick (Carousel off its axis), named in ROOM_MUSIC. The House is still wood and
// pipes, now from the inside: floorboards, a lamp's buzz, wet paper tearing, a music box
// gone wrong; its shades are breath and cold glass. The user's picks from the sound vote
// (prototypes/sounds/ghoul-rush/eye.html). A name may be defined only once
// across tones.js and every game's file. No imports.
export const EYE_SFX = {
tones: {
// Marrow, Every Room at Once: The House with its front torn off, a dollhouse of nine rooms: a lamp flares, the wallpaper splits and the Eye stares out; it lurches the whole house, calls up shades of the keepers YOU beat, and dies in a heap of peeled paper and cracked floors.
// Wakes: Timbers and a music box.
ghoulEyeWake: {
layers: [
{ type: "sawtooth", from: 75, to: 55, seconds: 1.1, attack: 0.03, gain: 0.6, filter: { type: "bandpass", from: 400, to: 300, q: 6 }, vibrato: { rate: 16, depth: 0.1 } },
{ type: "brown", seconds: 1.1, attack: 0.05, gain: 0.3, filter: { type: "lowpass", from: 120, to: 70, q: 1 } },
{ type: "triangle", from: 1568, to: 1537, seconds: 0.22, attack: 0.003, gain: 0.3, delay: 0.1 },
{ type: "triangle", from: 1319, to: 1293, seconds: 0.22, attack: 0.003, gain: 0.3, delay: 0.34 },
{ type: "triangle", from: 1047, to: 1026, seconds: 0.22, attack: 0.003, gain: 0.3, delay: 0.58 },
],
},
// Hit in the Eye: Wet tick.
ghoulEyeHurt: {
layers: [
{ type: "sine", from: 900, to: 520, seconds: 0.07, attack: 0.003, gain: 0.6 },
{ type: "noise", seconds: 0.06, attack: 0.003, gain: 0.4, filter: { type: "bandpass", from: 1800, to: 900, q: 2 } },
],
},
// Dies: Hinge shriek, timber.
ghoulEyeDie: {
layers: [
{ type: "sawtooth", from: 700, to: 420, seconds: 0.8, attack: 0.03, gain: 0.4, vibrato: { rate: 12, depth: 0.04 }, filter: { type: "bandpass", from: 1400, to: 1680, q: 4 } },
{ type: "sawtooth", from: 1050, to: 630, seconds: 0.72, attack: 0.04, gain: 0.18, filter: { type: "bandpass", from: 2100, to: 2100, q: 5 } },
{ type: "noise", seconds: 0.64, attack: 0.03, gain: 0.15, filter: { type: "highpass", from: 3000, to: 3000, q: 1 } },
{ type: "sawtooth", from: 75, to: 55, seconds: 1, attack: 0.03, gain: 0.6, delay: 0.1, filter: { type: "bandpass", from: 400, to: 300, q: 6 }, vibrato: { rate: 16, depth: 0.1 } },
{ type: "brown", seconds: 1, attack: 0.05, gain: 0.3, delay: 0.1, filter: { type: "lowpass", from: 120, to: 70, q: 1 } },
{ type: "sine", from: 66, to: 24, seconds: 0.25, attack: 0, gain: 1, delay: 0.4 },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 192, to: 192, q: 1 }, delay: 0.4 },
],
},
// A lamp flares: Swelling buzz.
ghoulEyeFlare: {
layers: [
{ type: "sawtooth", from: 120, to: 120, seconds: 0.7, attack: 0.27999999999999997, gain: 0.4, filter: { type: "bandpass", from: 900, to: 2200, q: 4 }, vibrato: { rate: 30, depth: 0.03 } },
{ type: "sine", from: 1800, to: 2600, seconds: 0.56, attack: 0.21, gain: 0.15, delay: 0.05 },
],
},
// The flare's second step: Buzz jump, creak.
ghoulEyeFlareStep: {
layers: [
{ type: "square", from: 240, to: 250, seconds: 0.25, attack: 0.003, gain: 0.4, filter: { type: "bandpass", from: 1400, to: 1800, q: 6 } },
{ type: "sawtooth", from: 180, to: 132, seconds: 0.3, attack: 0.03, gain: 0.36, filter: { type: "bandpass", from: 960, to: 720, q: 6 }, vibrato: { rate: 16, depth: 0.1 } },
{ type: "brown", seconds: 0.3, attack: 0.05, gain: 0.18, filter: { type: "lowpass", from: 288, to: 168, q: 1 } },
],
},
// The Eye opens: Moist pop.
ghoulEyeOpen: {
layers: [
{ type: "noise", seconds: 0.5, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 6720, to: 240, q: 1 } },
{ type: "sine", from: 256, to: 56, seconds: 0.4, attack: 0, gain: 0.45 },
{ type: "brown", seconds: 0.6, attack: 0.01, gain: 0.35, filter: { type: "lowpass", from: 640, to: 640, q: 1 } },
{ type: "sine", from: 200, to: 380, seconds: 0.2, attack: 0.003, gain: 0.4, delay: 0.1 },
],
},
// The Eye shuts: Click shut.
ghoulEyeShut: {
layers: [
{ type: "triangle", from: 260, to: 221, seconds: 0.22, attack: 0, gain: 0.45 },
{ type: "sine", from: 702, to: 650, seconds: 0.12, attack: 0, gain: 0.18 },
{ type: "noise", seconds: 0.03, attack: 0, gain: 0.25, filter: { type: "bandpass", from: 1040, to: 1040, q: 2 } },
],
},
// A false lamp pops: Pop.
ghoulEyeDud: {
layers: [
{ type: "noise", seconds: 0.1, attack: 0, gain: 0.4, filter: { type: "highpass", from: 2520, to: 2520, q: 1 } },
{ type: "sine", from: 980, to: 210, seconds: 0.16, delay: 0.02, gain: 0.3 },
{ type: "brown", seconds: 0.12, attack: 0, gain: 0.25, filter: { type: "lowpass", from: 588, to: 588, q: 1 } },
],
},
// A door opens: Long creak.
ghoulEyeDoor: {
layers: [
{ type: "sawtooth", from: 300, to: 420, seconds: 0.6, attack: 0.03, gain: 0.6, filter: { type: "bandpass", from: 1600, to: 1200, q: 6 }, vibrato: { rate: 26, depth: 0.1 } },
{ type: "brown", seconds: 0.6, attack: 0.05, gain: 0.3, filter: { type: "lowpass", from: 480, to: 280, q: 1 } },
{ type: "sawtooth", from: 180, to: 132, seconds: 0.4, attack: 0.03, gain: 0.3, delay: 0.4, filter: { type: "bandpass", from: 960, to: 720, q: 6 }, vibrato: { rate: 16, depth: 0.1 } },
{ type: "brown", seconds: 0.4, attack: 0.05, gain: 0.15, delay: 0.4, filter: { type: "lowpass", from: 288, to: 168, q: 1 } },
],
},
// The house creaks: Long timber groan.
ghoulEyeCreak: {
layers: [
{ type: "sawtooth", from: 90, to: 66, seconds: 1, attack: 0.03, gain: 0.6, filter: { type: "bandpass", from: 480, to: 360, q: 6 }, vibrato: { rate: 9, depth: 0.1 } },
{ type: "brown", seconds: 1, attack: 0.05, gain: 0.3, filter: { type: "lowpass", from: 144, to: 84, q: 1 } },
{ type: "sawtooth", from: 135, to: 99, seconds: 0.8, attack: 0.03, gain: 0.3, delay: 0.2, filter: { type: "bandpass", from: 720, to: 540, q: 6 }, vibrato: { rate: 16, depth: 0.1 } },
{ type: "brown", seconds: 0.8, attack: 0.05, gain: 0.15, delay: 0.2, filter: { type: "lowpass", from: 216, to: 126, q: 1 } },
],
},
// The creak's second step: Joist crack.
ghoulEyeCreakStep: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 1, filter: { type: "bandpass", from: 1080, to: 720, q: 2 } },
{ type: "square", from: 540, to: 180, seconds: 0.05, attack: 0, gain: 0.4 },
{ type: "noise", seconds: 0.04, delay: 0.06, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 1560, to: 1080, q: 3 } },
{ type: "sawtooth", from: 105, to: 77, seconds: 0.45, attack: 0.03, gain: 0.6, delay: 0.03, filter: { type: "bandpass", from: 560, to: 420, q: 6 }, vibrato: { rate: 16, depth: 0.1 } },
{ type: "brown", seconds: 0.45, attack: 0.05, gain: 0.3, delay: 0.03, filter: { type: "lowpass", from: 168, to: 98, q: 1 } },
],
},
// It lurches: Deep shift.
ghoulEyeLurch: {
layers: [
{ type: "sine", from: 70, to: 38, seconds: 0.7, attack: 0.003, gain: 0.8 },
{ type: "brown", seconds: 1.1, attack: 0.003, gain: 0.6, filter: { type: "lowpass", from: 600, to: 120, q: 1 } },
{ type: "noise", seconds: 0.9, attack: 0.1, gain: 0.25, delay: 0.1, filter: { type: "bandpass", from: 500, to: 1200, q: 2 } },
],
},
// A dresser hits the wall: Wood crash.
ghoulEyeCrash: {
layers: [
{ type: "noise", seconds: 0.25, attack: 0.003, gain: 0.6, filter: { type: "lowpass", from: 2400, to: 500, q: 1 } },
{ type: "sine", from: 132, to: 48, seconds: 0.25, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 384, to: 384, q: 1 } },
],
},
// A dresser shot apart: Splinters and tinkle.
ghoulEyeSmash: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0.003, gain: 0.6, filter: { type: "bandpass", from: 1600, to: 600, q: 1.5 } },
{ type: "sine", from: 3100, to: 2900, seconds: 0.25, attack: 0.003, gain: 0.15, delay: 0.05 },
{ type: "sine", from: 4300, to: 4000, seconds: 0.18, attack: 0.003, gain: 0.11, delay: 0.1 },
{ type: "noise", seconds: 0.2, attack: 0.003, gain: 0.24, delay: 0.05, filter: { type: "highpass", from: 4000, to: 2400, q: 1 } },
{ type: "sine", from: 120, to: 70, seconds: 0.25, attack: 0.003, gain: 0.45 },
],
},
// The Eye bursts: Big wet pop.
ghoulEyeBurst: {
layers: [
{ type: "noise", seconds: 0.5, attack: 0, gain: 1, filter: { type: "lowpass", from: 3780, to: 135, q: 1 } },
{ type: "sine", from: 144, to: 32, seconds: 0.4, attack: 0, gain: 0.9 },
{ type: "brown", seconds: 0.6, attack: 0.01, gain: 0.7, filter: { type: "lowpass", from: 360, to: 360, q: 1 } },
{ type: "noise", seconds: 0.28, attack: 0, gain: 0.54, filter: { type: "lowpass", from: 1820, to: 140, q: 1 }, delay: 0.05 },
{ 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.05 },
{ type: "sine", from: 630, to: 910, seconds: 0.05, delay: 0.25, gain: 0.15 },
{ type: "sine", from: 532, to: 770, seconds: 0.05, delay: 0.39, gain: 0.11 },
],
},
// The paper peels: Long tearing.
ghoulEyePeel: {
layers: [
{ type: "noise", seconds: 1, attack: 0.01, gain: 0.48, filter: { type: "bandpass", from: 3000, to: 900, q: 1.5 } },
{ type: "pink", seconds: 0.8, attack: 0.02, gain: 0.24, delay: 0.04, filter: { type: "bandpass", from: 1600, to: 700, q: 3 } },
{ type: "noise", seconds: 0.9, attack: 0.01, gain: 0.3, delay: 0.15, filter: { type: "bandpass", from: 2100, to: 630, q: 1.5 } },
{ type: "pink", seconds: 0.72, attack: 0.02, gain: 0.15, delay: 0.19, filter: { type: "bandpass", from: 1120, to: 490, q: 3 } },
],
},
// A floor cracks: Crack and rumble.
ghoulEyeCrack: {
layers: [
{ type: "noise", seconds: 0.12, attack: 0.003, gain: 0.7, filter: { type: "bandpass", from: 2200, to: 1000, q: 2 } },
{ type: "sine", from: 120, to: 45, seconds: 0.5, attack: 0.003, gain: 0.6 },
{ type: "brown", seconds: 0.7, attack: 0.003, gain: 0.45, delay: 0.05, filter: { type: "lowpass", from: 500, to: 100, q: 1 } },
],
},
// The wet gasp: Breath through pipes.
ghoulEyeGasp: {
layers: [
{ type: "pink", seconds: 1, attack: 0.25, gain: 0.55, filter: { type: "bandpass", from: 300, to: 900, q: 3 } },
{ type: "sawtooth", from: 85, to: 55, seconds: 1, attack: 0.2, gain: 0.3, delay: 0.1, filter: { type: "lowpass", from: 500, to: 250, q: 3 }, vibrato: { rate: 7, depth: 0.12 } },
],
},
// It sinks: Long rumble.
ghoulEyeSink: {
layers: [
{ type: "brown", seconds: 1.15, attack: 0.08, gain: 1, filter: { type: "lowpass", from: 180, to: 70, q: 1 } },
{ type: "sine", from: 48, to: 30, seconds: 1.15, attack: 0.05, gain: 0.8 },
{ type: "sawtooth", from: 70, to: 42, seconds: 1, attack: 0.2, gain: 0.25, delay: 0.1, filter: { type: "lowpass", from: 300, to: 150, q: 2 }, vibrato: { rate: 5, depth: 0.08 } },
],
},
// Gone: the stair of bones: Bone steps, hollow knock.
ghoulEyeGone: {
layers: [
{ type: "triangle", from: 520, to: 442, seconds: 0.22, attack: 0, gain: 0.36 },
{ type: "sine", from: 1404, to: 1300, seconds: 0.12, attack: 0, gain: 0.14 },
{ type: "noise", seconds: 0.03, attack: 0, gain: 0.2, filter: { type: "bandpass", from: 2080, to: 2080, q: 2 } },
{ type: "triangle", from: 470, to: 400, seconds: 0.22, attack: 0, gain: 0.36, delay: 0.12 },
{ type: "sine", from: 1269, to: 1175, seconds: 0.12, attack: 0, gain: 0.14, delay: 0.12 },
{ type: "noise", seconds: 0.03, attack: 0, gain: 0.2, filter: { type: "bandpass", from: 1880, to: 1880, q: 2 }, delay: 0.12 },
{ type: "triangle", from: 420, to: 357, seconds: 0.22, attack: 0, gain: 0.36, delay: 0.24 },
{ type: "sine", from: 1134, to: 1050, seconds: 0.12, attack: 0, gain: 0.14, delay: 0.24 },
{ type: "noise", seconds: 0.03, attack: 0, gain: 0.2, filter: { type: "bandpass", from: 1680, to: 1680, q: 2 }, delay: 0.24 },
{ type: "sine", from: 98, to: 92, seconds: 0.8, attack: 0.05, gain: 0.45, delay: 0.35 },
],
},
// Shades of the keepers: Pale, see-through ghosts of the bosses YOU beat this run step out of the house's doors, each with one move of its own (a hop, a skull, a scythe, a note, a dash, a leap, knocks, a hoop, icicles, mud).
// Steps out: Cold breath, hum.
ghoulEyeShadeIn: {
layers: [
{ type: "pink", seconds: 0.6, attack: 0.25, gain: 0.8, filter: { type: "bandpass", from: 560, to: 2080, q: 5 } },
{ type: "noise", seconds: 0.42, delay: 0.24, attack: 0.1, gain: 0.5, filter: { type: "bandpass", from: 2080, to: 720, q: 8 } },
{ type: "sine", from: 330, to: 311, seconds: 0.7, attack: 0.2, gain: 0.3, delay: 0.1, vibrato: { rate: 5, depth: 0.03 } },
],
},
// Fades away: Falling tone.
ghoulEyeShadeOut: {
layers: [
{ type: "sine", from: 311, to: 220, seconds: 0.5, attack: 0.05, gain: 0.4 },
{ type: "pink", seconds: 0.4, attack: 0.05, gain: 0.3, filter: { type: "bandpass", from: 900, to: 400, q: 3 } },
],
},
// Winds up: Rising inhale.
ghoulEyeShadeWind: {
layers: [
{ type: "pink", seconds: 0.7, attack: 0.4, gain: 0.5, filter: { type: "bandpass", from: 500, to: 1800, q: 4 } },
{ type: "sine", from: 260, to: 520, seconds: 0.7, attack: 0.4, gain: 0.3 },
],
},
// Hit: Hiss through glass.
ghoulEyeShadeHurt: {
layers: [
{ type: "noise", seconds: 0.08, attack: 0.003, gain: 0.4, filter: { type: "highpass", from: 3000, to: 2000, q: 1 } },
{ type: "sine", from: 1200, to: 900, seconds: 0.1, attack: 0.003, gain: 0.3 },
],
},
// Laid to rest: Sigh rising away.
ghoulEyeShadeDie: {
layers: [
{ type: "sine", from: 400, to: 1200, seconds: 0.6, attack: 0.02, gain: 0.4, vibrato: { rate: 6, depth: 0.04 } },
{ type: "pink", seconds: 0.6, attack: 0.05, gain: 0.3, filter: { type: "bandpass", from: 800, to: 2400, q: 2 } },
],
},
// Gourd lands: Hollow thump.
ghoulEyeShadeSlam: {
layers: [
{ type: "sine", from: 154, to: 56, seconds: 0.25, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 448, to: 448, q: 1 } },
{ type: "noise", seconds: 0.1, attack: 0.003, gain: 0.3, filter: { type: "lowpass", from: 900, to: 400, q: 1 } },
],
},
// Skull thrown: Whirr.
ghoulEyeShadeThrow: {
layers: [
{ type: "noise", seconds: 0.35, attack: 0.03, gain: 0.4, filter: { type: "bandpass", from: 1400, to: 2200, q: 6 } },
],
},
// Angel moves: Stone grind.
ghoulEyeShadeGrind: {
layers: [
{ type: "brown", seconds: 0.5, attack: 0.05, gain: 0.5, filter: { type: "bandpass", from: 300, to: 500, q: 3 } },
{ type: "noise", seconds: 0.4, attack: 0.05, gain: 0.2, filter: { type: "bandpass", from: 900, to: 700, q: 4 } },
],
},
// Scythe sweeps: Long swish.
ghoulEyeShadeScythe: {
layers: [
{ type: "noise", seconds: 0.35, attack: 0.05, gain: 0.5, filter: { type: "bandpass", from: 800, to: 3200, q: 3 } },
{ type: "sine", from: 2400, to: 1600, seconds: 0.2, attack: 0.003, gain: 0.12, delay: 0.15 },
],
},
// A note fired: Pure choir tone.
ghoulEyeShadeNote: {
layers: [
{ type: "sine", from: 523, to: 523, seconds: 0.5, attack: 0.05, gain: 0.4, vibrato: { rate: 6, depth: 0.02 } },
{ type: "triangle", from: 1046, to: 1046, seconds: 0.4, attack: 0.05, gain: 0.15 },
],
},
// Matron dashes: Swoosh and glint.
ghoulEyeShadeDash: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0.02, gain: 0.5, filter: { type: "bandpass", from: 2000, to: 600, q: 3 } },
{ type: "sine", from: 3500, to: 3300, seconds: 0.12, attack: 0.003, gain: 0.2 },
],
},
// Beast leaps: Snarl.
ghoulEyeShadeLeap: {
layers: [
{ type: "sawtooth", from: 140, to: 220, seconds: 0.35, attack: 0.02, gain: 0.4, filter: { type: "lowpass", from: 900, to: 1400, q: 3 }, vibrato: { rate: 30, depth: 0.12 } },
{ type: "noise", seconds: 0.3, attack: 0.03, gain: 0.3, filter: { type: "bandpass", from: 800, to: 1200, q: 3 } },
],
},
// Beast lands: Thump.
ghoulEyeShadePounce: {
layers: [
{ type: "sine", from: 121, to: 44, seconds: 0.25, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 352, to: 352, q: 1 } },
{ type: "noise", seconds: 0.15, attack: 0.003, gain: 0.4, filter: { type: "lowpass", from: 1200, to: 400, q: 1 } },
],
},
// Knocks: Wall knock.
ghoulEyeShadeKnock: {
layers: [
{ type: "sine", from: 200, to: 120, seconds: 0.12, attack: 0.003, gain: 0.6 },
{ type: "noise", seconds: 0.05, attack: 0.003, gain: 0.3, filter: { type: "bandpass", from: 1200, to: 800, q: 3 } },
],
},
// A rock lands: Rock thud.
ghoulEyeShadeRock: {
layers: [
{ type: "noise", seconds: 0.18, attack: 0.003, gain: 0.5, filter: { type: "lowpass", from: 1600, to: 400, q: 1 } },
{ type: "sine", from: 110, to: 60, seconds: 0.22, attack: 0.003, gain: 0.5 },
],
},
// Hoop rolled: Rattling spin.
ghoulEyeShadeHoop: {
layers: [
{ type: "square", from: 400, to: 380, seconds: 0.04, attack: 0.003, gain: 0.25, filter: { type: "bandpass", from: 1200, to: 1100, q: 4 } },
{ type: "square", from: 420, to: 400, seconds: 0.04, attack: 0.003, gain: 0.25, delay: 0.09, filter: { type: "bandpass", from: 1250, to: 1150, q: 4 } },
{ type: "square", from: 440, to: 420, seconds: 0.04, attack: 0.003, gain: 0.25, delay: 0.18, filter: { type: "bandpass", from: 1300, to: 1200, q: 4 } },
{ type: "triangle", from: 660, to: 700, seconds: 0.3, attack: 0.02, gain: 0.2 },
],
},
// Icicle shatters: Ice shatter.
ghoulEyeShadeIcicle: {
layers: [
{ type: "sine", from: 2790, to: 2610, seconds: 0.25, attack: 0.003, gain: 0.25 },
{ type: "sine", from: 3870, to: 3600, seconds: 0.18, attack: 0.003, gain: 0.18, delay: 0.05 },
{ type: "noise", seconds: 0.2, attack: 0.003, gain: 0.4, filter: { type: "highpass", from: 3600, to: 2160, q: 1 } },
],
},
// Mud wave: Gloop.
ghoulEyeShadeMud: {
layers: [
{ type: "sine", from: 240, to: 60, seconds: 0.45, attack: 0.02, gain: 0.55 },
{ type: "brown", seconds: 0.5, attack: 0.04, gain: 0.5, filter: { type: "lowpass", from: 700, to: 110, q: 1 } },
],
},
},
music: {
// Every Room at Once: carousel off its axis. The most driving one: a wobbling calliope races the stages' tunes
// round a carousel (carnival, howl, lullaby, frozen lake, hymn, the bog's toll and the mine's figure), wrong
// notes and all, over an oom-pah of bass and chord stabs. The kick plays the heartbeat on every bar, two thumps
// before the snare. A steam whistle doubles the tune at 90%, cymbals near full dread.
ghoulMarrowRooms: {
bpm: 120,
rush: 16,
voices: {
calliope: { wave: "pulse", duty: 0.25, gain: 0.07, decay: 0.05, sustain: 0.7, vibrato: { rate: 7, depth: 0.025, delay: 0 } },
oom: { wave: "triangle", gain: 0.3, decay: 0.04, sustain: 0.4 },
pah: { wave: "square", gain: 0.03, decay: 0.03, sustain: 0.3 },
kit: { kit: true, gain: 0.2 },
whistle: { wave: "sine", gain: 0.06, decay: 0.1, sustain: 0.8, from: 0.9, vibrato: { rate: 8, depth: 0.015, delay: 0 } },
cym: { kit: true, gain: 0.12, from: 0.95 },
},
patterns: {
C: {
calliope:
"D5 - - - F5 - - - A5 - - - - - - - | Bb5 - - - A5 - - - G#5 - - - G#5 - - - | " +
"G5 - - - F5 - . . D5 - - - - - - - | Eb5 - - - - - - - - - - - . . . .",
oom:
"D2 . . . A2 . . . D2 . . . A2 . . . | Bb2 . . . F2 . . . Bb2 . . . F2 . . . | " +
"G2 . . . D2 . . . G2 . . . D2 . . . | A2 . . . E2 . . . A2 . . . E2 . . .",
pah:
". . D3^037 . . . D3^037 . . . D3^037 . . . D3^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 .",
kit:
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . . | " +
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . .",
whistle:
"D6 - - - F6 - - - A6 - - - - - - - | Bb6 - - - A6 - - - Ab6 - - - Ab6 - - - | " +
"G6 - - - F6 - . . D6 - - - - - - - | Eb6 - - - - - - - - - - - . . . .",
cym:
"o . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
},
V: {
calliope:
"A4 - - - D5 - - - C5 - - - - - - - | F5 - - - E5 - - - D5 - - - . . . . | " +
"A4 - - - D5 - - - F#5 - - - - - - - | E5 - - - C5 - - - . . . . . . . .",
oom:
"D2 . . . A2 . . . D2 . . . A2 . . . | Bb2 . . . F2 . . . Bb2 . . . F2 . . . | " +
"D2 . . . A2 . . . D2 . . . A2 . . . | A2 . . . E2 . . . A2 . . . E2 . . .",
pah:
". . D3^037 . . . D3^037 . . . D3^037 . . . D3^037 . | . . Bb3^047 . . . Bb3^047 . . . Bb3^047 . . . Bb3^047 . | " +
". . D3^037 . . . D3^037 . . . D3^037 . . . D3^037 . | . . A3^047 . . . A3^047 . . . A3^047 . . . A3^047 .",
kit:
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . . | " +
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . .",
whistle:
"A5 - - - D6 - - - C6 - - - - - - - | F6 - - - E6 - - - D6 - - - . . . . | " +
"A5 - - - D6 - - - Gb6 - - - - - - - | E6 - - - C6 - - - . . . . . . . .",
cym:
"o . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
},
S: {
calliope:
"D5 - - - F5 - - - E5 - - - D5 - - - | A5 - - - G5 - - - F5 - - - E5 - - - | " +
"D5 - - - F5 - - - A5 - - - G5 - - - | F5 - - - E5 - - - Eb5 - - - D5 - - -",
oom:
"D2 . . . A2 . . . D2 . . . A2 . . . | A2 . . . E2 . . . A2 . . . E2 . . . | " +
"D2 . . . A2 . . . D2 . . . A2 . . . | A2 . . . E2 . . . A2 . . . E2 . . .",
pah:
". . D3^037 . . . D3^037 . . . D3^037 . . . D3^037 . | . . A3^047 . . . A3^047 . . . A3^047 . . . A3^047 . | " +
". . D3^037 . . . D3^037 . . . D3^037 . . . D3^037 . | . . A3^047 . . . A3^047 . . . A3^047 . . . A3^047 .",
kit:
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . . | " +
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . .",
whistle:
"D6 - - - F6 - - - E6 - - - D6 - - - | A6 - - - G6 - - - F6 - - - E6 - - - | " +
"D6 - - - F6 - - - A6 - - - G6 - - - | F6 - - - E6 - - - Eb6 - - - D6 - - -",
cym:
"o . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
},
F: {
calliope:
"D5 - - - F5 - - - A5 - - - - - - - | G5 - - - Gb5 - - - E5 - - - - - - - | " +
"F5 - - - D5 - - - B4 - - - - - - - | C5 - - - - - - - Db5 - - - - - - -",
oom:
"D2 . . . A2 . . . D2 . . . A2 . . . | C2 . . . G2 . . . C2 . . . G2 . . . | " +
"Bb2 . . . F2 . . . Bb2 . . . F2 . . . | A2 . . . E2 . . . A2 . . . E2 . . .",
pah:
". . D3^037 . . . D3^037 . . . D3^037 . . . D3^037 . | . . C3^047 . . . C3^047 . . . C3^047 . . . C3^047 . | " +
". . Bb3^047 . . . Bb3^047 . . . Bb3^047 . . . Bb3^047 . | . . A3^047 . . . A3^047 . . . A3^047 . . . A3^047 .",
kit:
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . . | " +
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . .",
whistle:
"D6 - - - F6 - - - A6 - - - - - - - | G6 - - - Gb6 - - - E6 - - - - - - - | " +
"F6 - - - D6 - - - B5 - - - - - - - | C6 - - - - - - - Db6 - - - - - - -",
cym:
"o . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
},
P: {
calliope:
"D5 - - - F5 - - - G5 - - - F5 - - - | A5 - - - G5 - - - F5 - - - Eb5 - - - | " +
"F5 - - - G5 - - - A5 - - - Bb5 - - - | Bb5 - - - A5 - - - Ab5 - - - - - - -",
oom:
"D2 . . . A2 . . . D2 . . . A2 . . . | Eb2 . . . Bb2 . . . Eb2 . . . Bb2 . . . | " +
"Bb2 . . . F2 . . . Bb2 . . . F2 . . . | A2 . . . E2 . . . A2 . . . E2 . . .",
pah:
". . D3^037 . . . D3^037 . . . D3^037 . . . D3^037 . | . . Eb3^047 . . . Eb3^047 . . . Eb3^047 . . . Eb3^047 . | " +
". . Bb3^047 . . . Bb3^047 . . . Bb3^047 . . . Bb3^047 . | . . A3^047 . . . A3^047 . . . A3^047 . . . A3^047 .",
kit:
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . . | " +
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . .",
whistle:
"D6 - - - F6 - - - G6 - - - F6 - - - | A6 - - - G6 - - - F6 - - - Eb6 - - - | " +
"F6 - - - G6 - - - A6 - - - Bb6 - - - | Bb6 - - - A6 - - - Ab6 - - - - - - -",
cym:
"o . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
},
B: {
calliope:
"D5 - - - - - - - - - - - - - - - | A5 - - - F5 - - - D5 - - - Eb5 - - -",
oom:
"D2 . . . A2 . . . D2 . . . A2 . . . | D2 . . . A2 . . . D2 . . . A2 . . .",
pah:
". . D3^037 . . . D3^037 . . . D3^037 . . . D3^037 . | . . D3^037 . . . D3^037 . . . D3^037 . . . D3^037 .",
kit:
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . .",
whistle:
"D6 - - - - - - - - - - - - - - - | A6 - - - F6 - - - D6 - - - Eb6 - - -",
cym:
"o . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
},
M: {
calliope:
"D4 . D4 . . . D4 . . . . . . . . . | D5 - - - F5 - - - E5 - - - A4 - - -",
oom:
"D2 . . . A2 . . . D2 . . . A2 . . . | D2 . . . A2 . . . D2 . . . A2 . . .",
pah:
". . D3^037 . . . D3^037 . . . D3^037 . . . D3^037 . | . . D3^037 . . . D3^037 . . . D3^037 . . . D3^037 .",
kit:
"k . k . s . . . . . . . s . . . | k . k . s . . . . . . . s . . .",
whistle:
"D5 . D5 . . . D5 . . . . . . . . . | D6 - - - F6 - - - E6 - - - A5 - - -",
cym:
"o . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
},
},
order: ["C", "V", "S", "B", "F", "P", "M"],
},
},
};
@@ -0,0 +1,367 @@
// Plan2Code Web Console - ghoul: the sounds for the finale's third kill, The Heart of Marrow in the Pit, merged into sfx/ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-marrow.js: `tones` (the heart's `ghoulHeart<Act>`
// sounds, none over 1.2 s with its delay). `music` holds ghoulMarrowPit, the
// user's pick (Strings in the dark). The heart is two real thumps, felt more than heard, then the speakers
// strain; the roots are wood and wet earth, the pipes iron and gurgling; the HOLD FIRE
// flood is a rising tone in parts that never quite resolves until the last thump. These
// are the user's picks from the sound vote (prototypes/sounds/ghoul-rush/heart.html).
// A name may be defined only once across tones.js and every game's file. No imports.
export const HEART_SFX = {
tones: {
// The Heart of Marrow: the House's own heart, huge in the dark of the Pit.
// Wakes: Three slow thumps.
ghoulHeartWake: {
layers: [
{ type: "sine", from: 66, to: 32, seconds: 0.3, attack: 0.006, gain: 0.95 },
{ type: "brown", seconds: 0.24, attack: 0.003, gain: 0.55, filter: { type: "lowpass", from: 240, to: 70, q: 1 } },
{ type: "sine", from: 66, to: 32, seconds: 0.3, attack: 0.006, gain: 0.95, delay: 0.38 },
{ type: "brown", seconds: 0.24, attack: 0.003, gain: 0.55, delay: 0.38, filter: { type: "lowpass", from: 240, to: 70, q: 1 } },
{ type: "sine", from: 66, to: 32, seconds: 0.36, attack: 0.006, gain: 0.95, delay: 0.76 },
{ type: "brown", seconds: 0.29, attack: 0.003, gain: 0.55, delay: 0.76, filter: { type: "lowpass", from: 240, to: 70, q: 1 } },
],
},
// Hit: a wet slap into muscle (plays often, so it stays short).
ghoulHeartHurt: {
layers: [
{ type: "noise", seconds: 0.07, attack: 0, gain: 0.45, filter: { type: "bandpass", from: 900, to: 400, q: 1.5 } },
{ type: "sine", from: 140, to: 70, seconds: 0.12, attack: 0.002, gain: 0.55 },
],
},
// Dies: Deflating.
ghoulHeartDie: {
layers: [
{ type: "noise", seconds: 1.1, attack: 0.06, gain: 0.48, filter: { type: "highpass", from: 1200, to: 2500, q: 1 } },
{ type: "pink", seconds: 1.1, attack: 0.05, gain: 0.3, filter: { type: "bandpass", from: 1600, to: 1100, q: 2 } },
{ type: "sine", from: 80, to: 30, seconds: 1, attack: 0.004, gain: 0.6 },
],
},
// Beats: Lub-dub, muffled.
ghoulHeartBeat: {
layers: [
{ type: "sine", from: 58, to: 34, seconds: 0.2, attack: 0.004, gain: 0.9 },
{ type: "sine", from: 54, to: 30, seconds: 0.26, attack: 0.004, gain: 0.9, delay: 0.3 },
],
},
// The ribs part: a wet creak of bone opening, the cue to fire.
ghoulHeartOpen: {
layers: [
{ type: "sawtooth", from: 240, to: 340, seconds: 0.16, attack: 0.02, gain: 0.3, vibrato: { rate: 30, depth: 0.08 }, filter: { type: "bandpass", from: 1200, to: 1600, q: 5 } },
{ type: "noise", seconds: 0.1, delay: 0.05, attack: 0.01, gain: 0.25, filter: { type: "bandpass", from: 1800, to: 2600, q: 2 } },
],
},
// Roots wind up: a low creak of wood under the floor and earth shifting.
ghoulHeartRootWind: {
layers: [
{ type: "sawtooth", from: 90, to: 70, seconds: 0.6, attack: 0.08, gain: 0.45, vibrato: { rate: 14, depth: 0.1 }, filter: { type: "bandpass", from: 500, to: 300, q: 6 } },
{ type: "brown", seconds: 0.7, attack: 0.15, gain: 0.5, filter: { type: "lowpass", from: 300, to: 160, q: 1 } },
],
},
// Roots crack: the second warning, the floor splitting.
ghoulHeartRootCrack: {
layers: [
{ type: "noise", seconds: 0.1, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 1400, to: 600, q: 1.5 } },
{ type: "square", from: 160, to: 90, seconds: 0.12, attack: 0, gain: 0.3, filter: { type: "lowpass", from: 900, to: 300, q: 1 } },
{ type: "noise", seconds: 0.08, delay: 0.12, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 1100, to: 500, q: 1.5 } },
],
},
// Roots burst up: a tearing of earth and a thick whip.
ghoulHeartRootUp: {
layers: [
{ type: "noise", seconds: 0.25, attack: 0.005, gain: 0.6, filter: { type: "bandpass", from: 600, to: 2200, q: 1 } },
{ type: "sine", from: 90, to: 220, seconds: 0.18, attack: 0.005, gain: 0.5 },
{ type: "brown", seconds: 0.3, attack: 0.005, gain: 0.5, filter: { type: "lowpass", from: 400, to: 120, q: 1 } },
],
},
// A grab winds up: roots slithering over stone, a creak.
ghoulHeartGrabWind: {
layers: [
{ type: "pink", seconds: 0.6, attack: 0.15, gain: 0.4, filter: { type: "bandpass", from: 900, to: 1600, q: 2 } },
{ type: "sawtooth", from: 130, to: 110, seconds: 0.5, delay: 0.1, attack: 0.08, gain: 0.35, vibrato: { rate: 18, depth: 0.1 }, filter: { type: "bandpass", from: 700, to: 500, q: 6 } },
],
},
// A grab tenses: wood drawn tight, rising.
ghoulHeartGrabTense: {
layers: [
{ type: "sawtooth", from: 150, to: 260, seconds: 0.4, attack: 0.05, gain: 0.4, vibrato: { rate: 22, depth: 0.07 }, filter: { type: "bandpass", from: 800, to: 1300, q: 7 } },
{ type: "noise", seconds: 0.3, delay: 0.1, attack: 0.1, gain: 0.25, filter: { type: "bandpass", from: 1500, to: 2400, q: 3 } },
],
},
// A grab lashes: a crack of a whip across the ledge.
ghoulHeartGrabLash: {
layers: [
{ type: "noise", seconds: 0.18, attack: 0, gain: 0.7, filter: { type: "highpass", from: 1800, to: 900, q: 1 } },
{ type: "sine", from: 400, to: 120, seconds: 0.14, attack: 0, gain: 0.45 },
],
},
// Clots wind up: the pipes over YOU gurgle and swell.
ghoulHeartClotWind: {
layers: [
{ type: "sine", from: 180, to: 120, seconds: 0.18, attack: 0.02, gain: 0.45, vibrato: { rate: 18, depth: 0.15 } },
{ type: "sine", from: 220, to: 140, seconds: 0.2, delay: 0.22, attack: 0.02, gain: 0.45, vibrato: { rate: 16, depth: 0.15 } },
{ type: "brown", seconds: 0.6, attack: 0.1, gain: 0.35, filter: { type: "bandpass", from: 300, to: 500, q: 3 } },
{ type: "square", from: 62, to: 62, seconds: 0.5, delay: 0.1, attack: 0.1, gain: 0.15, filter: { type: "lowpass", from: 200, to: 160, q: 1 } },
],
},
// A clot lands: a thick wet splat.
ghoulHeartClotLand: {
layers: [
{ type: "noise", seconds: 0.14, attack: 0, gain: 0.55, filter: { type: "lowpass", from: 1400, to: 300, q: 1 } },
{ type: "sine", from: 130, to: 55, seconds: 0.16, attack: 0.002, gain: 0.6 },
],
},
// The quake: the whole Pit rumbling, stone grinding.
ghoulHeartQuake: {
layers: [
{ type: "brown", seconds: 1.1, attack: 0.1, gain: 0.85, filter: { type: "lowpass", from: 200, to: 90, q: 1 } },
{ type: "sawtooth", from: 41, to: 36, seconds: 1.0, attack: 0.15, gain: 0.3, filter: { type: "lowpass", from: 180, to: 120, q: 1 } },
{ type: "noise", seconds: 0.8, delay: 0.2, attack: 0.2, gain: 0.25, filter: { type: "bandpass", from: 500, to: 300, q: 1 } },
],
},
// A chunk of roof lands: stone smashing on stone.
ghoulHeartChunk: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 2400, to: 400, q: 1 } },
{ type: "sine", from: 90, to: 40, seconds: 0.25, attack: 0, gain: 0.7 },
],
},
// The beat stops dead: a sharp catch, then nothing.
ghoulHeartStop: {
layers: [
{ type: "sine", from: 70, to: 50, seconds: 0.12, attack: 0.004, gain: 0.7 },
{ type: "noise", seconds: 0.06, delay: 0.02, attack: 0, gain: 0.25, filter: { type: "bandpass", from: 1200, to: 800, q: 2 } },
],
},
// The swell: a long rising groan of strained muscle before the big wave.
ghoulHeartSwell: {
layers: [
{ type: "sawtooth", from: 45, to: 90, seconds: 0.8, attack: 0.3, gain: 0.5, vibrato: { rate: 7, depth: 0.05 }, filter: { type: "lowpass", from: 200, to: 700, q: 3 } },
{ type: "brown", seconds: 0.8, attack: 0.4, gain: 0.6, filter: { type: "lowpass", from: 150, to: 400, q: 1 } },
],
},
// Big wave: Boom.
ghoulHeartSlam: {
layers: [
{ type: "sine", from: 53, to: 26, seconds: 0.5, attack: 0.006, gain: 0.95 },
{ type: "brown", seconds: 0.4, attack: 0.003, gain: 0.55, filter: { type: "lowpass", from: 192, to: 56, q: 1 } },
{ type: "brown", seconds: 0.6, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 180, to: 70, q: 1 } },
{ type: "sine", from: 48, to: 30, seconds: 0.6, attack: 0.05, gain: 0.48 },
],
},
// In the hold, a weak beat: soft, slow, failing.
ghoulHeartWeakBeat: {
layers: [
{ type: "sine", from: 56, to: 32, seconds: 0.22, attack: 0.01, gain: 0.55 },
{ type: "sine", from: 50, to: 30, seconds: 0.26, delay: 0.38, attack: 0.01, gain: 0.45 },
],
},
// A ripple reaches YOU in the hold: the light knocked back, a dull thud and a flutter.
ghoulHeartKnock: {
layers: [
{ type: "sine", from: 120, to: 60, seconds: 0.15, attack: 0.002, gain: 0.6 },
{ type: "triangle", from: 880, to: 520, seconds: 0.25, attack: 0.01, gain: 0.3 },
],
},
// The flood rising, one part a quarter (played higher each time): never quite resolving.
ghoulHeartFlood: {
layers: [
{ type: "triangle", from: 293.7, to: 311, seconds: 0.9, attack: 0.2, gain: 0.45, vibrato: { rate: 5, depth: 0.01 } },
{ type: "triangle", from: 440, to: 466, seconds: 0.9, delay: 0.05, attack: 0.25, gain: 0.35 },
{ type: "sine", from: 587, to: 622, seconds: 0.85, delay: 0.1, attack: 0.3, gain: 0.3 },
{ type: "pink", seconds: 0.9, attack: 0.3, gain: 0.15, filter: { type: "highpass", from: 3000, to: 5000, q: 1 } },
],
},
// The white: the light floods everything, a bright chord at last resolved.
ghoulHeartWhite: {
layers: [
{ type: "triangle", from: 293.7, to: 293.7, seconds: 1.1, attack: 0.05, gain: 0.5 },
{ type: "triangle", from: 370, to: 370, seconds: 1.1, attack: 0.08, gain: 0.4 },
{ type: "sine", from: 440, to: 440, seconds: 1.1, attack: 0.1, gain: 0.4 },
{ type: "sine", from: 587.3, to: 587.3, seconds: 1.0, delay: 0.1, attack: 0.15, gain: 0.3 },
{ type: "noise", seconds: 0.6, attack: 0.002, gain: 0.3, filter: { type: "highpass", from: 4000, to: 7000, q: 1 } },
],
},
// The last thump: one, enormous, and then silence.
ghoulHeartLast: {
layers: [
{ type: "sine", from: 64, to: 22, seconds: 0.9, attack: 0.005, gain: 1 },
{ type: "brown", seconds: 0.7, attack: 0.003, gain: 0.85, filter: { type: "lowpass", from: 300, to: 50, q: 1 } },
{ type: "noise", seconds: 0.12, attack: 0.002, gain: 0.25, filter: { type: "lowpass", from: 800, to: 200, q: 1 } },
],
},
// Daylight: a soft high shimmer far above, and a warm open fifth.
ghoulHeartDaylight: {
layers: [
{ type: "sine", from: 587.3, to: 587.3, seconds: 1.1, attack: 0.4, gain: 0.35 },
{ type: "sine", from: 880, to: 880, seconds: 1.0, delay: 0.1, attack: 0.4, gain: 0.3 },
{ type: "triangle", from: 1174.7, to: 1174.7, seconds: 0.9, delay: 0.2, attack: 0.3, gain: 0.2, vibrato: { rate: 6, depth: 0.004 } },
{ type: "pink", seconds: 1.0, attack: 0.5, gain: 0.12, filter: { type: "highpass", from: 5000, to: 7000, q: 1 } },
],
},
},
music: {
// The Pit: strings in the dark. A horror-film string section: low cellos grind the root against the half step
// below in sixteenths, turning to the flat second every second bar, while basses pluck the heartbeat twice a bar
// over a deep boom. Violas tremble on the fifth from 30% and sag to the tritone; from 60% violins stab high
// octaves that end in a shriek of half steps. Once a loop the grinding stops for one held breath. A choir and a
// high shiver at 90%; at full dread it all opens into D major.
ghoulMarrowPit: {
bpm: 100,
rush: 16,
voices: {
heart: { wave: "triangle", gain: 0.42, decay: 0.05, sustain: 0.25 },
celli: { wave: "sawtooth", gain: 0.05, decay: 0.04, sustain: 0.6 },
boom: { kit: true, gain: 0.26, from: 0.2 },
violas: { wave: "pulse", duty: 0.125, gain: 0.03, decay: 0.02, sustain: 0.6, from: 0.3 },
stabs: { wave: "sawtooth", gain: 0.045, decay: 0.03, sustain: 0.25, from: 0.6 },
shiver: { wave: "pulse", duty: 0.125, gain: 0.014, decay: 0.02, sustain: 0.5, from: 0.9 },
choirLo: { wave: "triangle", gain: 0.05, decay: 1.2, sustain: 2.5, from: 0.9, vibrato: { rate: 4.5, depth: 0.008, delay: 0.3 } },
choirHi: { wave: "triangle", gain: 0.04, decay: 1.2, sustain: 2.5, from: 0.9, vibrato: { rate: 4.5, depth: 0.008, delay: 0.3 } },
fanfare: { wave: "sawtooth", gain: 0.06, decay: 0.12, sustain: 0.85, from: 0.995, vibrato: { rate: 5.5, depth: 0.006, delay: 0.15 } },
sunThird: { wave: "triangle", gain: 0.14, decay: 0.4, sustain: 1, from: 0.995, vibrato: { rate: 5, depth: 0.006, delay: 0.3 } },
sunTop: { wave: "triangle", gain: 0.1, decay: 0.4, sustain: 1, from: 0.995, vibrato: { rate: 4.5, depth: 0.006, delay: 0.3 } },
bells: { wave: "sine", gain: 0.1, decay: 0.3, sustain: 0.3, from: 0.995 },
},
patterns: {
A: {
heart:
"D2 . A1 . . . . . D2 . A1 . . . . . | D2 . A1 . . . . . D2 . A1 . . . . . | " +
"Bb1 . F1 . . . . . Bb1 . F1 . . . . . | A1 . E1 . . . . . A1 . E1 . . . . .",
celli:
"D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 | D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 Eb3 D3 Eb3 D3 | " +
"Bb2 A2 Bb2 A2 Bb2 A2 Bb2 A2 Bb2 A2 Bb2 A2 Bb2 A2 Bb2 A2 | A2 G2 A2 G2 A2 G2 A2 G2 A2 G2 A2 G2 Bb2 A2 Bb2 A2",
violas:
"A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 | A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 Ab4 Ab4 Ab4 Ab4 | " +
"F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 | E4 E4 E4 E4 E4 E4 E4 E4 E4 E4 E4 E4 Eb4 Eb4 Eb4 Eb4",
boom:
"k . k . . . . . k . k . . . . . | k . k . . . . . k . k . o . . . | " +
"k . k . . . . . k . k . . . . . | k . k . . . . . k . k . o . . .",
stabs:
". . . . . . D6 . . . . . . . D6 . | . . . . . . D6 . . . . . D6 Eb6 D6 Eb6 | " +
". . . . . . Bb5 . . . . . . . Bb5 . | . . . . . . A5 . . . . . A5 Bb5 A5 Bb5",
shiver:
"D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 | D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 | " +
"Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 | A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6",
choirLo:
"D3 - - - - - - - - - - - - - - - | D3 - - - - - - - - - - - - - - - | " +
"Bb3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -",
choirHi:
"A3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - - | " +
"F3 - - - - - - - - - - - - - - - | E3 - - - - - - - - - - - - - - -",
fanfare:
"D5 . A4 . . . D5 - F#5 - - - A5 - - - | D5 . A4 . . . D5 - F#5 - - - . . . . | " +
"Bb4 . F4 . . . Bb4 - D5 - - - F5 - - - | A4 . E4 . . . A4 - C#5 - - - . . . .",
sunThird:
"F#4 - - - - - - - - - - - - - - - | F#4 - - - - - - - - - - - . . . . | " +
"D4 - - - - - - - - - - - - - - - | C#4 - - - - - - - - - - - . . . .",
sunTop:
"D5 - - - - - - - - - - - - - - - | D5 - - - - - - - - - - - . . . . | " +
"F4 - - - - - - - - - - - - - - - | E4 - - - - - - - - - - - . . . .",
bells:
"D6 . . . F#6 . . . A6 . . . D7 . . . | D6 . . . F#6 . . . A6 . . . . . . . | " +
"Bb5 . . . D6 . . . F6 . . . Bb6 . . . | A5 . . . C#6 . . . E6 . . . . . . .",
},
B: {
heart:
"D2 . A1 . . . . . D2 . A1 . . . . . | D2 . A1 . . . . . D2 . A1 . . . . . | " +
"C2 . G1 . . . . . C2 . G1 . . . . . | A1 . E1 . . . . . A1 . E1 . . . . .",
celli:
"D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 | D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 Eb3 D3 Eb3 D3 | " +
"C3 B2 C3 B2 C3 B2 C3 B2 C3 B2 C3 B2 C3 B2 C3 B2 | A2 G2 A2 G2 A2 G2 A2 G2 A2 G2 A2 G2 Bb2 A2 Bb2 A2",
violas:
"A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 | A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 Ab4 Ab4 Ab4 Ab4 | " +
"G4 G4 G4 G4 G4 G4 G4 G4 G4 G4 G4 G4 G4 G4 G4 G4 | E4 E4 E4 E4 E4 E4 E4 E4 E4 E4 E4 E4 Eb4 Eb4 Eb4 Eb4",
boom:
"k . k . . . . . k . k . . . . . | k . k . . . . . k . k . o . . . | " +
"k . k . . . . . k . k . . . . . | k . k . . . . . k . k . o . . .",
stabs:
". . . . . . D6 . . . . . . . D6 . | . . . . . . D6 . . . . . D6 Eb6 D6 Eb6 | " +
". . . . . . C6 . . . . . . . C6 . | . . . . . . A5 . . . . . A5 Bb5 A5 Bb5",
shiver:
"D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 | D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 | " +
"C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 | A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6 A6",
choirLo:
"D3 - - - - - - - - - - - - - - - | D3 - - - - - - - - - - - - - - - | " +
"C3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -",
choirHi:
"A3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - - | " +
"G3 - - - - - - - - - - - - - - - | E3 - - - - - - - - - - - - - - -",
fanfare:
"D5 . A4 . . . D5 - F#5 - - - A5 - - - | D5 . A4 . . . D5 - F#5 - - - . . . . | " +
"C5 . G4 . . . C5 - E5 - - - G5 - - - | A4 . E4 . . . A4 - C#5 - - - . . . .",
sunThird:
"F#4 - - - - - - - - - - - - - - - | F#4 - - - - - - - - - - - . . . . | " +
"E4 - - - - - - - - - - - - - - - | C#4 - - - - - - - - - - - . . . .",
sunTop:
"D5 - - - - - - - - - - - - - - - | D5 - - - - - - - - - - - . . . . | " +
"G4 - - - - - - - - - - - - - - - | E4 - - - - - - - - - - - . . . .",
bells:
"D6 . . . F#6 . . . A6 . . . D7 . . . | D6 . . . F#6 . . . A6 . . . . . . . | " +
"C6 . . . E6 . . . G6 . . . C7 . . . | A5 . . . C#6 . . . E6 . . . . . . .",
},
C: {
heart:
"Bb1 . F1 . . . . . Bb1 . F1 . . . . . | C2 . G1 . . . . . C2 . G1 . . . . . | " +
"D2 . A1 . . . . . D2 . A1 . . . . . | D2 . A1 . . . . . D2 . A1 . . . . .",
celli:
"Bb2 A2 Bb2 A2 Bb2 A2 Bb2 A2 Bb2 A2 Bb2 A2 Bb2 A2 Bb2 A2 | C3 B2 C3 B2 C3 B2 C3 B2 C3 B2 C3 B2 Db3 C3 Db3 C3 | " +
"D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 | D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 D3 Db3 Eb3 D3 Eb3 D3",
violas:
"F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 | G4 G4 G4 G4 G4 G4 G4 G4 G4 G4 G4 G4 Gb4 Gb4 Gb4 Gb4 | " +
"A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 | A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 Ab4 Ab4 Ab4 Ab4",
boom:
"k . k . . . . . k . k . . . . . | k . k . . . . . k . k . o . . . | " +
"k . k . . . . . k . k . . . . . | k . k . . . . . k . k . o . . .",
stabs:
". . . . . . Bb5 . . . . . . . Bb5 . | . . . . . . C6 . . . . . C6 Db6 C6 Db6 | " +
". . . . . . D6 . . . . . . . D6 . | . . . . . . D6 . . . . . D6 Eb6 D6 Eb6",
shiver:
"Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 Bb6 | C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 C6 | " +
"D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 | D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6 D6",
choirLo:
"Bb3 - - - - - - - - - - - - - - - | C3 - - - - - - - - - - - - - - - | " +
"D3 - - - - - - - - - - - - - - - | D3 - - - - - - - - - - - - - - -",
choirHi:
"F3 - - - - - - - - - - - - - - - | G3 - - - - - - - - - - - - - - - | " +
"A3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -",
fanfare:
"Bb4 . F4 . . . Bb4 - D5 - - - F5 - - - | C5 . G4 . . . C5 - E5 - - - . . . . | " +
"D5 . A4 . . . D5 - F#5 - - - A5 - - - | D5 . A4 . . . D5 - F#5 - - - . . . .",
sunThird:
"D4 - - - - - - - - - - - - - - - | E4 - - - - - - - - - - - . . . . | " +
"F#4 - - - - - - - - - - - - - - - | F#4 - - - - - - - - - - - . . . .",
sunTop:
"F4 - - - - - - - - - - - - - - - | G4 - - - - - - - - - - - . . . . | " +
"D5 - - - - - - - - - - - - - - - | D5 - - - - - - - - - - - . . . .",
bells:
"Bb5 . . . D6 . . . F6 . . . Bb6 . . . | C6 . . . E6 . . . G6 . . . . . . . | " +
"D6 . . . F#6 . . . A6 . . . D7 . . . | D6 . . . F#6 . . . A6 . . . . . . .",
},
X: {
heart:
"D2 . A1 . . . . . D2 . A1 . . . . . | D2 . A1 . . . . . D2 . A1 . . . . .",
violas:
"A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 | A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 A4 Ab4 Ab4 Ab4 Ab4",
celli:
". . . . . . . . . . . . . . . . | . . . . . . . . D3 Db3 D3 Db3 Eb3 D3 Eb3 D3",
boom:
"k . k . . . . . k . k . . . . . | k . k . . . . . k k k k k k k k",
choirLo:
"D3 - - - - - - - - - - - - - - - | D3 - - - - - - - - - - - - - - -",
choirHi:
"A3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -",
fanfare:
"D5 . A4 . . . D5 - F#5 - - - A5 - - - | D5 . A4 . . . D5 - F#5 - - - . . . .",
sunThird:
"F#4 - - - - - - - - - - - - - - - | F#4 - - - - - - - - - - - . . . .",
sunTop:
"D5 - - - - - - - - - - - - - - - | D5 - - - - - - - - - - - . . . .",
bells:
"D6 . . . F#6 . . . A6 . . . D7 . . . | D6 . . . F#6 . . . A6 . . . . . . .",
},
},
order: ["A", "B", "A", "C", "X"],
},
},
};
@@ -0,0 +1,399 @@
// Plan2Code Web Console - ghoul: Marrow's own sound effects, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-bog.js: `tones` (the finale boss's `ghoulMarrow<Act>`
// sounds, none over 1.2 s with its delay). `music` holds ghoulMarrowLawn, the user's pick (Storm toccata).
// The House's voice is wood and pipes, every sound a building rather than a throat: creaks,
// hinges dropped in pitch, floorboards, glass, a pipe organ's lowest note, wind in a chimney.
// These are the user's picks from the sound vote (marrow.html). A name may be defined only
// once across tones.js and every game's file. No imports.
export const MARROW_SFX = {
tones: {
// Marrow, the House: The house itself, Kill I on the Front Lawn: its windows are its eyes, its door a mouth and its pickets teeth; shoot every window out. Its voice is wood and pipes, a building, not a throat.
// Wakes: Organ chord swells.
ghoulMarrowWake: {
layers: [
{ type: "square", from: 33, to: 33, seconds: 1.15, attack: 0.45, gain: 0.27, filter: { type: "lowpass", from: 229, to: 131, q: 1 } },
{ type: "sine", from: 65, to: 65, seconds: 1.15, attack: 0.45, gain: 0.23 },
{ type: "square", from: 49, to: 49, seconds: 1.15, attack: 0.45, gain: 0.27, filter: { type: "lowpass", from: 343, to: 196, q: 1 } },
{ type: "sine", from: 98, to: 98, seconds: 1.15, attack: 0.45, gain: 0.23 },
{ type: "square", from: 65, to: 65, seconds: 1.15, attack: 0.45, gain: 0.27, filter: { type: "lowpass", from: 458, to: 262, q: 1 } },
{ type: "sine", from: 131, to: 131, seconds: 1.15, attack: 0.45, gain: 0.23 },
{ type: "pink", seconds: 0.3, attack: 0.04, gain: 0.14, filter: { type: "bandpass", from: 327, to: 229, q: 4 } },
{ type: "sawtooth", from: 50, to: 94, seconds: 0.8, attack: 0.04, gain: 0.3, delay: 0.3, vibrato: { rate: 16, depth: 0.12 }, filter: { type: "bandpass", from: 336, to: 630, q: 7 } },
{ type: "sawtooth", from: 34, to: 64, seconds: 0.8, attack: 0.06, gain: 0.15, delay: 0.33, vibrato: { rate: 11.2, depth: 0.08 }, filter: { type: "lowpass", from: 350, to: 280, q: 2 } },
],
},
// Hit: Draft: glass tick, wooden creak.
ghoulMarrowHurt: {
layers: [
{ type: "sine", from: 3520, to: 3300, seconds: 0.06, attack: 0, gain: 0.25 },
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.3, filter: { type: "highpass", from: 4200, to: 3600, q: 1 } },
{ type: "sawtooth", from: 180, to: 140, seconds: 0.22, delay: 0.03, attack: 0.02, gain: 0.3, vibrato: { rate: 24, depth: 0.08 }, filter: { type: "bandpass", from: 900, to: 600, q: 7 } },
],
},
// Dies: Organ falls apart.
ghoulMarrowDie: {
layers: [
{ type: "square", from: 65, to: 33, seconds: 1.15, attack: 0.03, gain: 0.3, filter: { type: "lowpass", from: 458, to: 262, q: 1 } },
{ type: "sine", from: 131, to: 65, seconds: 1.15, attack: 0.03, gain: 0.25 },
{ type: "square", from: 78, to: 39, seconds: 1.15, attack: 0.03, gain: 0.3, filter: { type: "lowpass", from: 545, to: 311, q: 1 } },
{ type: "sine", from: 156, to: 78, seconds: 1.15, attack: 0.03, gain: 0.25 },
{ type: "square", from: 98, to: 49, seconds: 1.15, attack: 0.03, gain: 0.3, filter: { type: "lowpass", from: 686, to: 392, q: 1 } },
{ type: "sine", from: 196, to: 98, seconds: 1.15, attack: 0.03, gain: 0.25 },
{ type: "pink", seconds: 0.3, attack: 0.04, gain: 0.15, filter: { type: "bandpass", from: 654, to: 458, q: 4 } },
{ type: "brown", seconds: 1.1, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 180, to: 70, q: 1 } },
{ type: "sine", from: 48, to: 30, seconds: 1.1, attack: 0.05, gain: 0.48 },
{ type: "noise", seconds: 0.05, attack: 0.003, gain: 0.54, filter: { type: "bandpass", from: 3600, to: 2400, q: 1.5 } },
{ type: "noise", seconds: 0.4, attack: 0.003, gain: 0.3, filter: { type: "highpass", from: 6500, to: 3500, q: 1 } },
{ type: "sine", from: 4453, to: 4320, seconds: 0.07, attack: 0.003, gain: 0.12, delay: 0.21 },
],
},
// Roof shakes: Slates chattering.
ghoulMarrowRoof: {
layers: [
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 1332, to: 1066, q: 6 } },
{ type: "square", from: 408, to: 307, seconds: 0.02, gain: 0.3 },
{ type: "noise", seconds: 0.04, delay: 0.1, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 1818, to: 1455, q: 6 } },
{ type: "noise", seconds: 0.04, delay: 0.16, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 1681, to: 1345, q: 6 } },
{ type: "noise", seconds: 0.04, delay: 0.23, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 1806, to: 1445, q: 6 } },
{ type: "noise", seconds: 0.04, delay: 0.32, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 1363, to: 1091, q: 6 } },
{ type: "square", from: 362, to: 313, seconds: 0.02, delay: 0.32, gain: 0.3 },
{ type: "noise", seconds: 0.04, delay: 0.38, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 1788, to: 1431, q: 6 } },
{ type: "noise", seconds: 0.04, delay: 0.45, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 1696, to: 1357, q: 6 } },
{ type: "brown", seconds: 0.7, attack: 0.08, gain: 0.4, filter: { type: "lowpass", from: 180, to: 70, q: 1 } },
{ type: "sine", from: 48, to: 30, seconds: 0.7, attack: 0.05, gain: 0.32 },
],
},
// Front door opens: Draft: huge hinge creak three octaves down.
ghoulMarrowDoor: {
layers: [
{ type: "sawtooth", from: 60, to: 95, seconds: 0.95, attack: 0.08, gain: 0.7, vibrato: { rate: 14, depth: 0.12 }, filter: { type: "bandpass", from: 300, to: 500, q: 8 } },
{ type: "sawtooth", from: 45, to: 72, seconds: 0.95, attack: 0.1, gain: 0.4, vibrato: { rate: 9, depth: 0.1 }, filter: { type: "lowpass", from: 400, to: 500, q: 3 } },
{ type: "brown", seconds: 0.9, attack: 0.1, gain: 0.3, filter: { type: "lowpass", from: 160, to: 120, q: 1 } },
{ type: "sine", from: 70, to: 40, seconds: 0.2, delay: 0.95, attack: 0, gain: 0.5 },
],
},
// Carpet rolls out: Rug unrolling flaps.
ghoulMarrowCarpet: {
layers: [
{ type: "sine", from: 88, to: 32, seconds: 0.25, attack: 0, gain: 0.8 },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.64, filter: { type: "lowpass", from: 256, to: 256, q: 1 } },
{ type: "pink", seconds: 0.07, delay: 0.1, attack: 0.01, gain: 0.63, filter: { type: "bandpass", from: 420, to: 182, q: 1 } },
{ type: "pink", seconds: 0.07, delay: 0.2, attack: 0.01, gain: 0.42, filter: { type: "bandpass", from: 420, to: 182, q: 1 } },
{ type: "pink", seconds: 0.07, delay: 0.3, attack: 0.01, gain: 0.63, filter: { type: "bandpass", from: 420, to: 182, q: 1 } },
{ type: "pink", seconds: 0.07, delay: 0.4, attack: 0.01, gain: 0.42, filter: { type: "bandpass", from: 420, to: 182, q: 1 } },
{ type: "pink", seconds: 0.07, delay: 0.5, attack: 0.01, gain: 0.63, filter: { type: "bandpass", from: 420, to: 182, q: 1 } },
{ type: "pink", seconds: 0.07, delay: 0.6, attack: 0.01, gain: 0.42, filter: { type: "bandpass", from: 420, to: 182, q: 1 } },
],
},
// Slate lands: Draft: clay crack and thud.
ghoulMarrowShingle: {
layers: [
{ type: "noise", seconds: 0.07, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 2400, to: 1400, q: 2 } },
{ type: "triangle", from: 900, to: 600, seconds: 0.06, attack: 0, gain: 0.25 },
{ type: "sine", from: 140, to: 60, seconds: 0.14, attack: 0, gain: 0.6 },
{ type: "brown", seconds: 0.12, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 500, to: 150, q: 1 } },
],
},
// Lawn ripples: Draft: soil crackle and low rumble.
ghoulMarrowPicketWind: {
layers: [
{ type: "brown", seconds: 0.8, attack: 0.2, gain: 0.7, filter: { type: "lowpass", from: 120, to: 260, q: 1 } },
{ type: "sine", from: 38, to: 48, seconds: 0.8, attack: 0.2, gain: 0.5, vibrato: { rate: 6, depth: 0.1 } },
{ type: "noise", seconds: 0.7, delay: 0.1, attack: 0.15, gain: 0.25, filter: { type: "bandpass", from: 1600, to: 2600, q: 2 } },
],
},
// Picket bursts up: Stake thrust.
ghoulMarrowPicketUp: {
layers: [
{ type: "noise", seconds: 0.08, attack: 0.05, gain: 0.6, filter: { type: "bandpass", from: 600, to: 2400, q: 2 } },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.8, filter: { type: "bandpass", from: 1440, to: 960, q: 2 }, delay: 0.07 },
{ type: "square", from: 720, to: 240, seconds: 0.05, attack: 0, gain: 0.32, delay: 0.07 },
{ type: "noise", seconds: 0.04, delay: 0.13, attack: 0, gain: 0.56, filter: { type: "bandpass", from: 2080, to: 1440, q: 3 } },
],
},
// Chimney coughs: Organ splutter.
ghoulMarrowCough: {
layers: [
{ type: "square", from: 60, to: 50, seconds: 0.08, attack: 0.003, gain: 0.5, filter: { type: "lowpass", from: 500, to: 300, q: 3 } },
{ type: "square", from: 55, to: 45, seconds: 0.08, attack: 0.003, gain: 0.5, delay: 0.1, filter: { type: "lowpass", from: 500, to: 300, q: 3 } },
{ type: "square", from: 50, to: 40, seconds: 0.08, attack: 0.003, gain: 0.5, delay: 0.2, filter: { type: "lowpass", from: 500, to: 300, q: 3 } },
{ type: "square", from: 45, to: 35, seconds: 0.08, attack: 0.003, gain: 0.5, delay: 0.34, filter: { type: "lowpass", from: 500, to: 300, q: 3 } },
{ type: "pink", seconds: 0.4, attack: 0.05, gain: 0.5, filter: { type: "bandpass", from: 500, to: 250, q: 5 } },
],
},
// Brick lands: Brick cracks.
ghoulMarrowBrick: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 990, to: 660, q: 2 } },
{ type: "square", from: 495, to: 165, 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: 1430, to: 990, q: 3 } },
{ type: "sine", from: 99, to: 36, seconds: 0.25, attack: 0, gain: 0.8 },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.64, filter: { type: "lowpass", from: 288, to: 288, q: 1 } },
],
},
// The dead shamble out: Doorbell, creak.
ghoulMarrowDoormen: {
layers: [
{ type: "sine", from: 659, to: 659, seconds: 0.4, attack: 0.003, gain: 0.5 },
{ type: "sine", from: 523, to: 523, seconds: 0.6, attack: 0.003, gain: 0.5, delay: 0.35 },
{ type: "sine", from: 1318, to: 1318, seconds: 0.2, attack: 0.003, gain: 0.12 },
{ type: "sawtooth", from: 97, to: 61, seconds: 0.4, attack: 0.04, gain: 0.36, delay: 0.7, vibrato: { rate: 16, depth: 0.12 }, filter: { type: "bandpass", from: 648, to: 405, q: 7 } },
{ type: "sawtooth", from: 66, to: 41, seconds: 0.4, attack: 0.06, gain: 0.18, delay: 0.73, vibrato: { rate: 11.2, depth: 0.08 }, filter: { type: "lowpass", from: 450, to: 360, q: 2 } },
],
},
// Rears up: Draft: long rising creak of timbers.
ghoulMarrowRear: {
layers: [
{ type: "sawtooth", from: 70, to: 160, seconds: 1, attack: 0.1, gain: 0.6, vibrato: { rate: 16, depth: 0.1 }, filter: { type: "bandpass", from: 400, to: 900, q: 7 } },
{ type: "sawtooth", from: 50, to: 110, seconds: 1, delay: 0.1, attack: 0.15, gain: 0.35, vibrato: { rate: 11, depth: 0.08 }, filter: { type: "lowpass", from: 400, to: 800, q: 2 } },
{ type: "brown", seconds: 1, attack: 0.3, gain: 0.35, filter: { type: "lowpass", from: 140, to: 260, q: 1 } },
],
},
// Comes down: Boom and rattling panes.
ghoulMarrowStomp: {
layers: [
{ type: "sine", from: 55, to: 20, seconds: 0.25, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 160, to: 160, q: 1 } },
{ 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.05, attack: 0.003, gain: 0.32, delay: 0.05, filter: { type: "bandpass", from: 2880, to: 1920, q: 1.5 } },
{ type: "noise", seconds: 0.4, attack: 0.003, gain: 0.18, delay: 0.05, filter: { type: "highpass", from: 5200, to: 2800, q: 1 } },
{ type: "sine", from: 2655, to: 2575, seconds: 0.11, attack: 0.003, gain: 0.07, delay: 0.31 },
{ type: "sine", from: 2455, to: 2382, seconds: 0.1, attack: 0.003, gain: 0.06, delay: 0.1 },
{ type: "sine", from: 3075, to: 2983, seconds: 0.11, attack: 0.003, gain: 0.05, delay: 0.14 },
{ type: "sine", from: 3322, to: 3223, seconds: 0.07, attack: 0.003, gain: 0.05, delay: 0.3 },
],
},
// A window lights: Draft: soft glassy chime and hum.
ghoulMarrowLight: {
layers: [
{ type: "sine", from: 1568, to: 1568, seconds: 0.5, attack: 0.02, gain: 0.18 },
{ type: "sine", from: 2349, to: 2349, seconds: 0.35, delay: 0.04, attack: 0.02, gain: 0.1 },
{ type: "triangle", from: 120, to: 120, seconds: 0.45, attack: 0.05, gain: 0.15, vibrato: { rate: 13, depth: 0.03 } },
],
},
// Window shot out: Draft: glass shatter, then a falling sigh.
ghoulMarrowWindowOut: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.8, filter: { type: "bandpass", from: 3500, to: 2500, q: 1.5 } },
{ type: "sine", from: 60, to: 35, seconds: 0.08, attack: 0, gain: 0.4 },
{ type: "noise", seconds: 0.45, attack: 0, gain: 0.55, filter: { type: "highpass", from: 6000, to: 3500, q: 1 } },
{ type: "sine", from: 3136, to: 3050, seconds: 0.12, delay: 0.02, attack: 0, gain: 0.18 },
{ type: "sine", from: 4186, to: 4100, seconds: 0.09, delay: 0.06, attack: 0, gain: 0.14 },
{ type: "sine", from: 2637, to: 2580, seconds: 0.1, delay: 0.11, attack: 0, gain: 0.14 },
{ type: "sine", from: 3729, to: 3650, seconds: 0.07, delay: 0.17, attack: 0, gain: 0.11 },
{ type: "sine", from: 4699, to: 4600, seconds: 0.06, delay: 0.24, attack: 0, gain: 0.08 },
{ type: "sine", from: 2960, to: 2900, seconds: 0.06, delay: 0.32, attack: 0, gain: 0.06 },
{ type: "pink", seconds: 0.7, delay: 0.3, attack: 0.12, gain: 0.4, filter: { type: "bandpass", from: 1200, to: 250, q: 2 } },
{ type: "sawtooth", from: 220, to: 90, seconds: 0.7, delay: 0.32, attack: 0.12, gain: 0.15, filter: { type: "lowpass", from: 700, to: 250, q: 3 } },
],
},
// Every window black: Organ sinks.
ghoulMarrowSag: {
layers: [
{ type: "square", from: 49, to: 29, seconds: 1.15, attack: 0.1, gain: 0.27, filter: { type: "lowpass", from: 343, to: 196, q: 1 } },
{ type: "sine", from: 98, to: 59, seconds: 1.15, attack: 0.1, gain: 0.23 },
{ type: "square", from: 58, to: 35, seconds: 1.15, attack: 0.1, gain: 0.27, filter: { type: "lowpass", from: 408, to: 233, q: 1 } },
{ type: "sine", from: 117, to: 70, seconds: 1.15, attack: 0.1, gain: 0.23 },
{ type: "square", from: 73, to: 44, seconds: 1.15, attack: 0.1, gain: 0.27, filter: { type: "lowpass", from: 514, to: 294, q: 1 } },
{ type: "sine", from: 147, to: 88, seconds: 1.15, attack: 0.1, gain: 0.23 },
{ type: "pink", seconds: 0.3, attack: 0.04, gain: 0.14, filter: { type: "bandpass", from: 490, to: 343, q: 4 } },
],
},
// A false victory: Draft: little brass fanfare in a major key.
ghoulMarrowFalseWin: {
layers: [
{ type: "sawtooth", from: 392, to: 392, seconds: 0.14, attack: 0.02, gain: 0.35, filter: { type: "lowpass", from: 2200, to: 1600, q: 1 } },
{ type: "sawtooth", from: 392, to: 392, seconds: 0.14, delay: 0.16, attack: 0.02, gain: 0.35, filter: { type: "lowpass", from: 2200, to: 1600, q: 1 } },
{ type: "sawtooth", from: 523, to: 523, seconds: 0.2, delay: 0.32, attack: 0.02, gain: 0.35, filter: { type: "lowpass", from: 2400, to: 1600, q: 1 } },
{ type: "sawtooth", from: 659, to: 659, seconds: 0.2, delay: 0.54, attack: 0.02, gain: 0.35, filter: { type: "lowpass", from: 2400, to: 1600, q: 1 } },
{ type: "sawtooth", from: 784, to: 784, seconds: 0.42, delay: 0.76, attack: 0.03, gain: 0.35, vibrato: { rate: 6, depth: 0.01 }, filter: { type: "lowpass", from: 2600, to: 1400, q: 1 } },
{ type: "sawtooth", from: 523, to: 523, seconds: 0.42, delay: 0.76, attack: 0.03, gain: 0.25, filter: { type: "lowpass", from: 2000, to: 1200, q: 1 } },
{ type: "sine", from: 131, to: 131, seconds: 0.42, delay: 0.76, attack: 0.03, gain: 0.3 },
],
},
// The House laughs: Draft: slow breath through broken windows, shutters clapping.
ghoulMarrowLaugh: {
layers: [
{ type: "pink", seconds: 1.15, attack: 0.3, gain: 0.5, filter: { type: "bandpass", from: 400, to: 900, q: 4 } },
{ type: "noise", seconds: 1.1, attack: 0.3, gain: 0.2, filter: { type: "bandpass", from: 1600, to: 1100, q: 6 } },
{ type: "square", from: 160, to: 140, seconds: 0.04, delay: 0.2, attack: 0, gain: 0.35, filter: { type: "lowpass", from: 900, to: 500, q: 2 } },
{ type: "square", from: 150, to: 130, seconds: 0.04, delay: 0.38, attack: 0, gain: 0.35, filter: { type: "lowpass", from: 900, to: 500, q: 2 } },
{ type: "square", from: 140, to: 120, seconds: 0.04, delay: 0.56, attack: 0, gain: 0.32, filter: { type: "lowpass", from: 900, to: 500, q: 2 } },
{ type: "square", from: 130, to: 110, seconds: 0.04, delay: 0.74, attack: 0, gain: 0.28, filter: { type: "lowpass", from: 900, to: 500, q: 2 } },
{ type: "square", from: 120, to: 100, seconds: 0.04, delay: 0.92, attack: 0, gain: 0.24, filter: { type: "lowpass", from: 900, to: 500, q: 2 } },
{ type: "triangle", from: 98, to: 82, seconds: 1.1, attack: 0.3, gain: 0.2, vibrato: { rate: 5, depth: 0.06 } },
],
},
// Sinks into the ground: Draft: long low rumble and grinding.
ghoulMarrowSink: {
layers: [
{ type: "brown", seconds: 1.2, attack: 0.15, gain: 0.9, filter: { type: "lowpass", from: 300, to: 90, q: 1 } },
{ type: "sine", from: 45, to: 28, seconds: 1.2, attack: 0.15, gain: 0.7 },
{ type: "sawtooth", from: 40, to: 30, seconds: 1.1, delay: 0.05, attack: 0.2, gain: 0.4, vibrato: { rate: 17, depth: 0.2 }, filter: { type: "bandpass", from: 400, to: 200, q: 3 } },
{ type: "noise", seconds: 1, delay: 0.1, attack: 0.2, gain: 0.25, filter: { type: "bandpass", from: 900, to: 400, q: 2 } },
],
},
// Gone: Draft: deep thud and hollow wind.
ghoulMarrowGone: {
layers: [
{ type: "sine", from: 60, to: 26, seconds: 0.6, attack: 0, gain: 0.9 },
{ type: "brown", seconds: 0.4, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 700, to: 80, q: 1 } },
{ type: "pink", seconds: 0.9, delay: 0.25, attack: 0.3, gain: 0.35, filter: { type: "bandpass", from: 350, to: 600, q: 8 } },
{ type: "sine", from: 220, to: 196, seconds: 0.8, delay: 0.35, attack: 0.3, gain: 0.08, vibrato: { rate: 2, depth: 0.03 } },
],
},
// Storm gathers: Draft: thunder roll, static, rising hum.
ghoulMarrowStorm: {
layers: [
{ type: "brown", seconds: 1.2, attack: 0.25, gain: 0.7, filter: { type: "lowpass", from: 180, to: 320, q: 1 } },
{ type: "sine", from: 42, to: 55, seconds: 1.1, attack: 0.3, gain: 0.45 },
{ type: "noise", seconds: 0.9, attack: 0.4, gain: 0.35, filter: { type: "highpass", from: 2400, to: 5200, q: 1 } },
{ type: "sawtooth", from: 60, to: 120, seconds: 0.9, attack: 0.3, gain: 0.18, vibrato: { rate: 23, depth: 0.15 }, filter: { type: "lowpass", from: 500, to: 1400, q: 4 } },
{ type: "square", from: 2200, to: 2600, seconds: 0.03, delay: 0.35, attack: 0, gain: 0.08 },
{ type: "square", from: 2600, to: 3000, seconds: 0.03, delay: 0.6, attack: 0, gain: 0.1 },
{ type: "square", from: 3000, to: 3400, seconds: 0.03, delay: 0.78, attack: 0, gain: 0.12 },
],
},
// Charge builds: Draft: fizzing crackle and a whine climbing.
ghoulMarrowCharge: {
layers: [
{ type: "sine", from: 700, to: 2400, seconds: 0.5, attack: 0.05, gain: 0.22 },
{ type: "square", from: 350, to: 1200, seconds: 0.45, attack: 0.05, gain: 0.08, filter: { type: "lowpass", from: 1500, to: 4000, q: 2 } },
{ type: "noise", seconds: 0.5, attack: 0.1, gain: 0.3, filter: { type: "bandpass", from: 3000, to: 6000, q: 2 } },
{ type: "noise", seconds: 0.02, delay: 0.12, attack: 0, gain: 0.35, filter: { type: "highpass", from: 3000, to: 3000, q: 1 } },
{ type: "noise", seconds: 0.02, delay: 0.27, attack: 0, gain: 0.4, filter: { type: "highpass", from: 3000, to: 3000, q: 1 } },
{ type: "noise", seconds: 0.02, delay: 0.38, attack: 0, gain: 0.45, filter: { type: "highpass", from: 3000, to: 3000, q: 1 } },
],
},
// Bolt strikes: Draft: sharp crack, wood split, thunder on top.
ghoulMarrowStrike: {
layers: [
{ type: "noise", seconds: 0.08, attack: 0, gain: 0.9, filter: { type: "highpass", from: 1800, to: 900, q: 1 } },
{ type: "square", from: 900, to: 120, seconds: 0.09, attack: 0, gain: 0.3 },
{ type: "noise", seconds: 0.12, delay: 0.04, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1400, to: 600, q: 3 } },
{ type: "brown", seconds: 1, delay: 0.05, attack: 0.02, gain: 0.85, filter: { type: "lowpass", from: 600, to: 90, q: 1 } },
{ type: "sine", from: 70, to: 32, seconds: 0.9, delay: 0.05, attack: 0, gain: 0.6 },
],
},
// Crows burst out: Draft: door thump, rush of wings, harsh caws.
ghoulMarrowCrows: {
layers: [
{ type: "sine", from: 90, to: 50, seconds: 0.18, attack: 0, gain: 0.5 },
{ type: "noise", seconds: 0.6, delay: 0.05, attack: 0.05, gain: 0.4, filter: { type: "bandpass", from: 900, to: 1600, q: 1.5 } },
{ type: "sawtooth", from: 820, to: 560, seconds: 0.16, delay: 0.12, attack: 0.01, gain: 0.22, filter: { type: "bandpass", from: 1200, to: 900, q: 4 } },
{ type: "sawtooth", from: 760, to: 520, seconds: 0.18, delay: 0.36, attack: 0.01, gain: 0.2, filter: { type: "bandpass", from: 1100, to: 800, q: 4 } },
{ type: "sawtooth", from: 880, to: 600, seconds: 0.15, delay: 0.58, attack: 0.01, gain: 0.16, filter: { type: "bandpass", from: 1300, to: 900, q: 4 } },
],
},
},
music: {
// The Front Lawn: storm toccata. A Bach-style organ toccata that never stops: a running sixteenth figure through
// every chord, leaping up an octave and back, over a long pedal and the storm. The heartbeat is a timpani thump
// at each bar, lost in the run. A second manual sings the theme from 80%; a kick and choir join near full dread.
ghoulMarrowLawn: {
bpm: 96,
rush: 10,
voices: {
manual: { wave: "pulse", duty: 0.25, gain: 0.06, decay: 0.03, sustain: 0.5 },
pedal: { wave: "triangle", gain: 0.4, decay: 0.1, sustain: 0.9 },
tim: { wave: "triangle", gain: 0.3, decay: 0.04, sustain: 0.25, from: 0.2 },
thunder: { kit: true, gain: 0.3 },
kick: { kit: true, gain: 0.25, from: 0.7 },
lead: { wave: "pulse", duty: 0.5, gain: 0.05, decay: 0.2, sustain: 1, from: 0.8 },
choir: { wave: "triangle", gain: 0.07, decay: 0.3, sustain: 1, from: 0.95, vibrato: { rate: 5, depth: 0.008, delay: 0.2 } },
},
patterns: {
I: {
manual:
"A4 D5 F5 D5 A4 D5 F5 D5 A5 D6 F6 D6 A4 D5 F5 D5 | A4 D5 F5 D5 A4 D5 F5 D5 A5 D6 F6 D6 A4 D5 F5 D5 | " +
"F4 Bb4 D5 Bb4 F4 Bb4 D5 Bb4 F5 Bb5 D6 Bb5 F4 Bb4 D5 Bb4 | E4 A4 C#5 A4 E4 A4 C#5 A4 E5 A5 Db6 A5 E4 A4 C#5 A4",
pedal:
"D2 - - - - - - - - - - - - - - - | D2 - - - - - - - - - - - - - - - | " +
"Bb2 - - - - - - - - - - - - - - - | A2 - - - - - - - - - - - - - - -",
tim:
"D2 - A1 - . . . . . . . . . . . . | D2 - A1 - . . . . . . . . . . . . | " +
"D2 - A1 - . . . . . . . . . . . . | D2 - A1 - . . . . A1 A1 A1 A1 A1 A1 A1 A1",
thunder:
"ko . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . o . . . . . | . . . . . . . . . . . . . . . .",
kick:
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . . | " +
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . .",
},
A: {
manual:
"A4 D5 F5 D5 A4 D5 F5 D5 A5 D6 F6 D6 A4 D5 F5 D5 | F4 Bb4 D5 Bb4 F4 Bb4 D5 Bb4 F5 Bb5 D6 Bb5 F4 Bb4 D5 Bb4 | " +
"G4 C5 E5 C5 G4 C5 E5 C5 G5 C6 E6 C6 G4 C5 E5 C5 | E4 A4 C#5 A4 E4 A4 C#5 A4 E5 A5 Db6 A5 E4 A4 C#5 A4",
pedal:
"D2 - - - - - - - - - - - - - - - | Bb2 - - - - - - - - - - - - - - - | " +
"C2 - - - - - - - - - - - - - - - | A2 - - - - - - - - - - - - - - -",
tim:
"D2 - A1 - . . . . . . . . . . . . | D2 - A1 - . . . . . . . . . . . . | " +
"D2 - A1 - . . . . . . . . . . . . | D2 - A1 - . . . . A1 A1 A1 A1 A1 A1 A1 A1",
thunder:
"ko . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . o . . . . . | . . . . . . . . . . . . . . . .",
kick:
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . . | " +
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . .",
lead:
"D5 - - - A4 - - - F5 - - - - - E5 - | D5 - - - - - - - C5 - - - Bb4 - - - | " +
"C5 - - - E5 - - - G5 - - - - - F5 - | E5 - - - - - - - - - - - C#5 - - -",
choir:
"A5 - - - - - - - - - - - - - - - | F5 - - - - - - - - - - - - - - - | " +
"G5 - - - - - - - - - - - - - - - | E5 - - - - - - - - - - - - - - -",
},
B: {
manual:
"A4 D5 F5 D5 A4 D5 F5 D5 A5 D6 F6 D6 A4 D5 F5 D5 | D4 G4 Bb4 G4 D4 G4 Bb4 G4 D5 G5 Bb5 G5 D4 G4 Bb4 G4 | " +
"F4 Bb4 D5 Bb4 F4 Bb4 D5 Bb4 F5 Bb5 D6 Bb5 F4 Bb4 D5 Bb4 | E4 A4 C#5 A4 E4 A4 C#5 A4 E5 A5 Db6 A5 E4 A4 C#5 A4",
pedal:
"D2 - - - - - - - - - - - - - - - | G2 - - - - - - - - - - - - - - - | " +
"Bb2 - - - - - - - - - - - - - - - | A2 - - - - - - - - - - - - - - -",
tim:
"D2 - A1 - . . . . . . . . . . . . | D2 - A1 - . . . . . . . . . . . . | " +
"D2 - A1 - . . . . . . . . . . . . | D2 - A1 - . . . . A1 A1 A1 A1 A1 A1 A1 A1",
thunder:
"ko . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . o . . . . . | . . . . . . . . . . . . . . . .",
kick:
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . . | " +
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . .",
lead:
"A5 - - - - - G5 - F5 - - - E5 - - - | D5 - - - - - Bb4 - G4 - - - - - - - | " +
"F5 - - - D5 - - - Bb4 - - - D5 - - - | E5 - - - C#5 - - - A4 - - - - - - -",
choir:
"A5 - - - - - - - - - - - - - - - | D5 - - - - - - - - - - - - - - - | " +
"F5 - - - - - - - - - - - - - - - | E5 - - - - - - - - - - - - - - -",
},
C: {
manual:
"F4 Bb4 D5 Bb4 F4 Bb4 D5 Bb4 F5 Bb5 D6 Bb5 F4 Bb4 D5 Bb4 | G4 C5 E5 C5 G4 C5 E5 C5 G5 C6 E6 C6 G4 C5 E5 C5 | " +
"A4 D5 F5 D5 A4 D5 F5 D5 A5 D6 F6 D6 A4 D5 F5 D5 | E4 A4 C#5 A4 E4 A4 C#5 A4 E5 A5 Db6 A5 E4 A4 C#5 A4",
pedal:
"Bb2 - - - - - - - - - - - - - - - | C2 - - - - - - - - - - - - - - - | " +
"D2 - - - - - - - - - - - - - - - | A2 - - - - - - - - - - - - - - -",
tim:
"D2 - A1 - . . . . . . . . . . . . | D2 - A1 - . . . . . . . . . . . . | " +
"D2 - A1 - . . . . . . . . . . . . | D2 - A1 - . . . . A1 A1 A1 A1 A1 A1 A1 A1",
thunder:
"ko . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . o . . . . . | . . . . . . . . . . . . . . . .",
kick:
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . . | " +
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . .",
lead:
"F5 - - - Bb5 - - - D6 - - - - - - - | E6 - - - - - C6 - G5 - - - - - - - | " +
"F6 - - - - - - - A5 - - - D6 - - - | C#6 - - - - - - - E5 - - - A5 - - -",
choir:
"F5 - - - - - - - - - - - - - - - | G5 - - - - - - - - - - - - - - - | " +
"A5 - - - - - - - - - - - - - - - | E5 - - - - - - - - - - - - - - -",
},
},
order: ["I", "A", "B", "A", "C"],
},
},
};
@@ -25,6 +25,9 @@ export const BOSS_INTROS = freeze({
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"),
marrow: entry("Marrow", "It has been expecting YOU"),
marroweye: entry("Marrow, Every Room at Once", "Make yourself at home"),
marrowheart: entry("The Heart of Marrow", "It has never once skipped a beat"),
});
// The card for a boss id, or null for a boss with none.
@@ -0,0 +1,573 @@
// Plan2Code Web Console - Ghoul Rush's ending, drawn: four animated scenes (the house from the hill as its windows go out one by one, the road unfolding at dawn while YOU walk, the cottage it was once in the morning sun, the mailbox's FINAL NOTICE in close-up) in canvas shapes, with the page's heading, its lines typing out, the hints and the skip bar over them, the same layout as the intro story's pages.
//
// draw/ghoul-draw.js plugs it in: endingArt(d) takes its drawing helpers
// (`d`: label, GOLD, BONE, ...) and hands back { card(ctx, v), react(e, k) }.
// `card` is drawn over the whole field while `round.phase === "ending"` (also
// while paused); `round.ending.ms` is the page's clock, so a pause holds every
// animation. `react` answers only the ending's own events (a page turning);
// its timed sounds go out as the story's `storyTone`, which the game already
// plays. The words, colors and timings live in ghoul-ending.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. Nothing here uses
// Math.random(): anything that moves follows the clock or `rnd`.
import { dot, faint, poly, rnd, stroke } from "./ghoul-intro-draw.js";
import { CHAR_MS, CLICK_OFF_MS, FLAG_MS, GAG_MS, LAST_HINT, LIGHTS_OUT, PAGES, REVEAL_AT_MS, SKIP_HINT, SKIP_HOLD_MS, SLIDE_MS, STAMP_MS, UNFOLD_MS, ENDING_HINT, lineAt, shown, turnable, typed } from "./ghoul-ending.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 ell = (ctx, x, y, rx, ry, fill) => {
ctx.beginPath();
ctx.ellipse(x, y, Math.max(0.05, rx), Math.max(0.05, ry), 0, 0, TAU);
ctx.fillStyle = fill;
ctx.fill();
};
const turn = (ctx, a) => {
if (typeof ctx.rotate === "function") ctx.rotate(a);
};
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 from `top` down to `low`, `n` of them.
function bands(ctx, top, low, n = 8, to = SCENE_H) {
for (let i = 0; i < n; i++) rect(ctx, 0, (i * to) / n, W, to / n + 0.1, mix(top, low, i / (n - 1)));
}
function stars(ctx, t, n, maxY, alpha = 1, color = "#ffffff") {
for (let i = 0; i < n; i++) faint(ctx, alpha * (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));
}
// A rolling hill line filled down to `to`.
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 hill's top: flat under what stands on it, then rounded shoulders easing down. Draw it after the house.
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);
}
// A soft round cloud of three puffs, `s` its size.
function cloud(ctx, x, y, s, color) {
ell(ctx, x, y, 4 * s, 1.3 * s, color);
circle(ctx, x - 1.6 * s, y - 0.7 * s, 1.5 * s, color);
circle(ctx, x + 0.8 * s, y - 1.1 * s, 1.9 * s, color);
circle(ctx, x + 2.6 * s, y - 0.4 * s, 1.2 * s, color);
}
// A bird far off: a little flapping V.
function bird(ctx, x, y, s, t, i, color = "#2a2a3a") {
const f = Math.sin(t / 120 + i * 1.7) * 0.9;
stroke(ctx, x - 1.2 * s, y - 0.5 * s + f * 0.5 * s, x, y, color, 0.22 * s);
stroke(ctx, x, y, x + 1.2 * s, y - 0.5 * s + f * 0.5 * s, color, 0.22 * s);
}
// A mix of two #rrggbb colors, `k` of the way from a to b, as #rrggbb (so a mix can be mixed again).
function 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 `#${pa.map((v, i) => Math.round(v + (pb[i] - v) * clamp(k)).toString(16).padStart(2, "0")).join("")}`;
}
// The house in silhouette, the same as the intro story draws it (so YOU know it at once): its feet at (x, y), `s` times its size, about 34 units wide and 25 tall at s 1, ten windows (`win(i)` -> { c, a }, or null for a dark one).
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]];
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);
rr(4.8, -22, 2.4, Math.max(roofAt(4.8), roofAt(7.2)) + 23.5, body);
rr(4.4, -22.5, 3.2, 0.8, body);
rr(-11.5, -17.2, 9, 0.4, o.trim || "#1a1228");
rr(-16.5, -1.5, 35, 1.5, o.stone || "#1b1530");
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, o.dark || "#05030a");
return;
}
faint(ctx, w.a * 0.14, () => rr(dx - 0.7, dy - 0.7, 3.4, 4, 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);
});
rr(-1.7, -4.8, 3.4, 4.8, o.dark || "#050308");
circle(ctx, x, y - 4.8 * s, 1.7 * s, o.dark || "#050308");
}
// YOU, facing `face` (1 right, -1 left), feet at (x, y), `s` times the 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 lens's glow), wave (the free arm up), sweat (a drop by the head, 0..1).
function hero(ctx, x, y, s, face, o = {}) {
const t = o.t || 0;
const stepA = o.walk ? Math.sin(t / 130) : 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";
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);
ell(ctx, fx + 0.15, -0.18, 0.6, 0.32, "#cfc4a6");
}
stroke(ctx, -1.6, -2.7, -2.2 - (o.wave ? 0.4 : 0), o.wave ? -5.2 + Math.sin(t / 160) * 0.4 : -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", Math.sin(t / 900) * 0.15);
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, or let down by YOUR side once it is off.
if (o.down) {
stroke(ctx, 1.6, -2.6, 1.9, -1.5, "#cfc4a6", 0.32);
rect(ctx, 1.6, -1.6, 0.7, 1.4, "#4a4f5a");
} else {
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");
}
if (o.sweat > 0) faint(ctx, o.sweat, () => {
poly(ctx, [[-2.1, -4.9], [-2.5, -4.1], [-1.7, -4.1]], "#9fd8ff");
circle(ctx, -2.1, -4.05, 0.4, "#9fd8ff");
});
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`, `len` units long (negative points left), `spread` wide at the far end, `tilt` down.
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));
}
}
/* ------------------------------------------------------------- scenes */
// How lit window `i` is at `t` on LIGHTS OUT: 1 before its time, fading over a moment after (null once out).
const OUT_FADE_MS = 320;
const outAt = Object.fromEntries(LIGHTS_OUT.map(([i, ms]) => [i, ms]));
const LAST_OUT = LIGHTS_OUT[LIGHTS_OUT.length - 1][1];
export function windowLit(i, t) {
const at = outAt[i];
if (at === undefined) return 1;
return clamp(1 - (t - at) / OUT_FADE_MS);
}
// How far the road is flat on THE ROAD: segment `i` of `n` (0 nearest YOU) flops flat in turn, the far end first.
const ROAD_SEGS = 11;
const SEG_MS = 230;
export function roadFlat(i, t) {
return smooth((t - UNFOLD_MS - (ROAD_SEGS - 1 - i) * SEG_MS) / 360);
}
// When the last segment (at YOUR feet) is flat and YOU set off.
const WALK_AT = UNFOLD_MS + ROAD_SEGS * SEG_MS + 200;
const SCENES = {
// LIGHTS OUT: the house from the hill at night, every window lit; they go out one by one to a falling tone each, until only the attic's is left, a long breath, then that one too. As the house goes dark the stars come out, and YOU, small on the near hill, let the flashlight drop.
lights(ctx, p) {
const { t, pal } = p;
bands(ctx, "#05040f", "#1e1a44", 8);
const left = LIGHTS_OUT.filter(([i]) => windowLit(i, t) > 0).length;
const dark = 1 - left / LIGHTS_OUT.length;
const after = smooth((t - LAST_OUT) / 1500);
stars(ctx, t, 60, 20, 0.25 + 0.75 * Math.max(dark, after));
// A thin moon, low.
circle(ctx, 18, 7, 2.2, "#e8e4ff");
circle(ctx, 19, 6.4, 2, mix("#05040f", "#1e1a44", 0.2));
faint(ctx, 0.06, () => circle(ctx, 18, 7, 4.5, "#e8e4ff"));
hills(ctx, 24, 1.6, "#0b0920", 0, 2);
// The house, its windows going out; the glow over it fading with them.
house(ctx, 60, 24, 0.82, { t, body: "#07050f", win: (i) => {
const k = windowLit(i, t);
if (!(k > 0)) return null;
// The very last, on its own: it holds steadier, like an eye left open.
return { c: i === 9 ? "#ffe08a" : "#ffc15a", a: k * (left === 1 ? 0.95 : flick(i, t)) };
} });
// A puff of smoke from each window that goes out.
for (const [i, at] of LIGHTS_OUT) {
const q = (t - at) / 1100;
if (q < 0 || q > 1) continue;
const [dx, dy] = WINS[i];
faint(ctx, 0.2 * (1 - q), () => circle(ctx, 60 + (dx + 1) * 0.82 + Math.sin(q * 6 + i) * 0.4, 24 + dy * 0.82 - q * 3.5, 0.4 + q * 0.8, "#8a86a8"));
}
knoll(ctx, 60.5, 24, 15, 24, 6, "#06050f");
tufts(ctx, 46, 75, 24, "#030208", t);
// The near hill, YOU on it, watching.
poly(ctx, [[0, SCENE_H], [0, 27], [10, 26.2], [22, 26.6], [34, 28.5], [44, SCENE_H]], "#040309");
tufts(ctx, 1, 33, 26.6, "#020105", t);
const lens = hero(ctx, 15, 26.4, 1.1, 1, { t, down: t > LAST_OUT + 600 });
if (t <= LAST_OUT + 600) beam(ctx, lens, 9, 1.4, 0.35 * (1 - smooth((t - LAST_OUT) / 600)), "#fff3b0", 2.6);
// The very end: a breath of the house sagging down into its hill.
if (after > 0) faint(ctx, 0.15 * after, () => rect(ctx, 0, 0, W, SCENE_H, "#05040f"));
},
// THE ROAD: dawn. The road out of the valley lies folded up like a napkin; it unfolds, segment by segment, from the far end toward YOU, creasing flat; then YOU walk it, toward the sunrise, the dark house far behind on its hill, and YOUR flashlight clicks off.
road(ctx, p) {
const { t, pal } = p;
const dawn = smooth(t / 6000);
bands(ctx, mix(pal.sky, "#4a3a6e", dawn), mix("#d9805a", "#ffb37a", dawn), 9, 27);
stars(ctx, t, 20, 10, 0.5 * (1 - dawn));
// The sun coming up over the far hills at the right.
const sunY = 25 - dawn * 5;
faint(ctx, 0.18, () => circle(ctx, 80, sunY, 9, "#ffd08a"));
faint(ctx, 0.25, () => circle(ctx, 80, sunY, 6, "#ffe0a0"));
circle(ctx, 80, sunY, 3.6, "#fff0c0");
for (let i = 0; i < 3; i++) faint(ctx, 0.5, () => cloud(ctx, ((i * 37 + t / 260) % (W + 20)) - 10, 6 + i * 3.4, 0.8 + (i % 2) * 0.3, mix("#6a4a7a", "#ffc8a0", dawn * 0.8)));
hills(ctx, 24, 1.8, mix("#2a1e3a", "#5a4060", dawn), 0, 4);
// The house far behind at the left, dark on its hill, not a window lit.
house(ctx, 12, 22.4, 0.3, { body: mix("#120c1e", "#3a2c40", dawn), stone: "#2a1f34", win: () => null });
knoll(ctx, 12.2, 22.4, 5.5, 14, 5, mix("#1e162c", "#4a3650", dawn));
hills(ctx, 27, 1.2, mix("#1c1428", "#3a2c3e", dawn), 30, 7);
rect(ctx, 0, 28, W, SCENE_H - 28, mix(pal.ground, "#3a2c34", dawn));
// The road along the ground: each segment folded up in a pleat until its turn, then flat, its creases still faintly showing.
const segW = W / ROAD_SEGS;
for (let i = 0; i < ROAD_SEGS; i++) {
const x0 = i * segW;
const flat = roadFlat(i, t);
const h = (1 - flat) * 5;
const up = i % 2;
const top0 = 29.2 - (up ? h : h * 0.25);
const top1 = 29.2 - (up ? h * 0.25 : h);
poly(ctx, [[x0, 31], [x0 + segW, 31], [x0 + segW, top1], [x0, top0]], up ? "#4a4258" : "#3c354a");
if (flat < 1) faint(ctx, 0.5 * (1 - flat), () => stroke(ctx, x0, top0, x0 + segW, top1, "#b8aac8", 0.18));
faint(ctx, 0.25, () => rect(ctx, x0 - 0.06, 29.2, 0.12, 1.8, "#a898b8"));
// The middle line, painted on, which only reads once a segment lies flat.
if (flat > 0.9) rect(ctx, x0 + segW * 0.3, 30, segW * 0.4, 0.25, "#d8c890");
}
// A puff of dust as each segment slaps down.
for (let i = 0; i < ROAD_SEGS; i++) {
const at = UNFOLD_MS + (ROAD_SEGS - 1 - i) * SEG_MS + 300;
const q = (t - at) / 600;
if (q < 0 || q > 1) continue;
faint(ctx, 0.3 * (1 - q), () => ell(ctx, (i + 0.5) * segW, 30.6 - q, 1.5 + q * 2, 0.5 + q * 0.4, "#c8b8c8"));
}
// YOU: waiting at the left until the road reaches YOUR feet, then walking.
const walk = Math.max(0, t - WALK_AT);
const x = 10 + Math.min(52, walk / 120);
const off = t >= CLICK_OFF_MS;
const lens = hero(ctx, x, 29.6, 1.25, 1, { t, walk: walk > 0, down: off });
if (!off) beam(ctx, lens, 14, 1.8, 0.4 * (1 - dawn * 0.5), "#fff3b0", 0.6);
// A bird crossing the dawn.
if (t > 2400) bird(ctx, ((t - 2400) / 40) % (W + 10) - 5, 9 + Math.sin(t / 700) * 1.5, 1, t, 0);
},
// MORNING: broad day. The House is only a small, sagging, empty cottage on its hill in the sun: a bowed roof with shingles missing, a crooked chimney, a door hanging open, one boarded window, ivy and daisies; clouds drift, birds wheel, one hops along the ridge; YOU stand by the gate, the flashlight off at YOUR side.
morning(ctx, p) {
const { t, pal } = p;
bands(ctx, "#5aa6e0", pal.sky, 8, 27);
faint(ctx, 0.2, () => circle(ctx, 82, 6, 7, "#fff3b0"));
circle(ctx, 82, 6, 3.4, "#fff6cc");
for (let i = 0; i < 4; i++) cloud(ctx, ((i * 29 + t / 300) % (W + 24)) - 12, 5 + (i % 3) * 3, 0.9 + (i % 2) * 0.4, "#f4f8ff");
hills(ctx, 25, 1.5, "#7cb46a", 0, 3);
rect(ctx, 0, 27, W, SCENE_H - 27, pal.ground);
knoll(ctx, 52, 25, 12, 16, 3, "#5d9a4c");
// The cottage: a low box, a roof that sags in the middle.
const cx = 52;
const gy = 25;
const wall = "#a89884";
const sag = 0.9 + 0.08 * Math.sin(t / 1600);
rect(ctx, cx - 10, gy - 8, 20, 8, wall);
for (let k = 0; k < 6; k++) rect(ctx, cx - 10, gy - 8 + k * 1.35, 20, 0.12, "#8e7e6c");
poly(ctx, [[cx - 11.5, gy - 8], [cx - 6, gy - 14.5], [cx, gy - 14.5 + sag * 1.6], [cx + 6, gy - 14.5], [cx + 11.5, gy - 8]], "#6a4a3a");
// Shingles in rows, a few missing, kept inside the roof's outline.
ctx.save();
ctx.beginPath();
ctx.moveTo(cx - 11.5, gy - 8);
ctx.lineTo(cx - 6, gy - 14.5);
ctx.lineTo(cx, gy - 14.5 + sag * 1.6);
ctx.lineTo(cx + 6, gy - 14.5);
ctx.lineTo(cx + 11.5, gy - 8);
ctx.closePath();
ctx.clip();
for (let r = 0; r < 5; r++) {
for (let k = 0; k < 9; k++) {
if (rnd(r * 9 + k, 3) < 0.18) continue;
const sx = cx - 9.5 + k * 2.2 + (r % 2) * 1.1;
const sy = gy - 9.2 - r * 1.4 + (Math.abs(sx - cx) < 6 ? sag * 1.6 * (1 - Math.abs(sx - cx) / 6) * (r / 4) : 0);
rect(ctx, sx, sy, 1.9, 0.35, "#553a2e");
}
}
ctx.restore();
// The chimney, crooked, with no smoke at all.
ctx.save();
ctx.translate(cx + 5.5, gy - 14.2);
turn(ctx, 0.12);
rect(ctx, -0.9, -3.2, 1.8, 3.4, "#8a5a48");
rect(ctx, -1.1, -3.5, 2.2, 0.5, "#6a4436");
ctx.restore();
// The door hanging open, the dark inside just dark.
rect(ctx, cx - 1.4, gy - 4.8, 2.8, 4.8, "#2a201c");
poly(ctx, [[cx + 1.4, gy - 4.8], [cx + 2.8, gy - 4.3], [cx + 2.8, gy - 0.3], [cx + 1.4, gy]], "#7a5a3e");
// A window with its shutter hanging, and one boarded up.
rect(ctx, cx - 7.5, gy - 6, 2.6, 2.4, "#3a4a5a");
rect(ctx, cx - 6.3, gy - 6, 0.2, 2.4, wall);
poly(ctx, [[cx - 4.9, gy - 6], [cx - 3.6, gy - 5.6], [cx - 3.9, gy - 3.4], [cx - 4.9, gy - 3.6]], "#5a7a5a");
rect(ctx, cx + 4.6, gy - 6, 2.6, 2.4, "#3a4a5a");
for (const [a, oy] of [[0.25, -5.6], [-0.2, -4.4]]) {
ctx.save();
ctx.translate(cx + 5.9, gy + oy);
turn(ctx, a);
rect(ctx, -1.8, -0.3, 3.6, 0.6, "#9a7a56");
ctx.restore();
}
// Ivy up the left wall, daisies along the front.
for (let k = 0; k < 14; k++) circle(ctx, cx - 9.6 + Math.sin(k * 1.3) * 0.6, gy - 0.5 - k * 0.55, 0.45, k % 2 ? "#3f7a3a" : "#4f8f44");
for (let k = 0; k < 10; k++) {
const fx = cx - 10 + k * 2.2 + rnd(k, 5);
const sway = Math.sin(t / 500 + k) * 0.2;
stroke(ctx, fx, gy + 0.6, fx + sway, gy - 0.6, "#3a6a2e", 0.12);
circle(ctx, fx + sway, gy - 0.7, 0.32, "#ffffff");
circle(ctx, fx + sway, gy - 0.7, 0.12, "#ffd34d");
}
tufts(ctx, 36, 70, gy, "#4a8a3a", t);
// A bird hopping along the ridge, and two more wheeling over.
const hop = Math.abs(Math.sin(t / 260)) * 0.6;
const rx = cx - 4 + ((t / 900) % 8);
ell(ctx, rx, gy - 14.9 + sag * 1.6 * (1 - Math.abs(rx - cx) / 6) - hop, 0.6, 0.4, "#3a3a4a");
circle(ctx, rx + 0.5, gy - 15.3 + sag * 1.6 * (1 - Math.abs(rx - cx) / 6) - hop, 0.3, "#3a3a4a");
for (let i = 0; i < 2; i++) bird(ctx, 30 + Math.cos(t / 1400 + i * 3) * 14, 8 + Math.sin(t / 900 + i) * 2.5, 1, t, i + 1);
// The picket fence, a few pickets gone, and YOU by the gate.
for (let x = 4; x < W; x += 2.4) {
if (x > 20 && x < 27) continue;
if (rnd(x, 9) < 0.12) continue;
rect(ctx, x, 27.6, 0.6, 3.4, "#ece4d4");
poly(ctx, [[x - 0.1, 27.6], [x + 0.3, 26.9], [x + 0.7, 27.6]], "#ece4d4");
}
rect(ctx, 0, 28.6, 20, 0.4, "#ddd4c0");
rect(ctx, 27, 28.6, W - 27, 0.4, "#ddd4c0");
hero(ctx, 23.5, 31.4, 1.2, 1, { t, down: true });
},
// FINAL NOTICE: the lawn's stuffed mailbox in close-up, in the sun, letters bursting from its mouth. The flag drops with a clack; a last envelope slides out on top of the pile; FINAL NOTICE thumps onto it in red; YOU, at the right, look at it and break into a sweat.
notice(ctx, p) {
const { t, pal } = p;
bands(ctx, "#78b8e8", pal.sky, 6, 22);
cloud(ctx, ((t / 340) % (W + 20)) - 10, 6, 1.1, "#f4f8ff");
cloud(ctx, ((t / 340 + 55) % (W + 20)) - 10, 10, 0.8, "#f4f8ff");
hills(ctx, 21, 1, "#86bc72", 0, 5);
// The cottage, small and far off behind.
rect(ctx, 14, 16.5, 7, 3.5, "#a89884");
poly(ctx, [[13.4, 16.5], [15.5, 14.2], [17.5, 14.9], [19.5, 14.2], [21.6, 16.5]], "#6a4a3a");
rect(ctx, 0, 22, W, SCENE_H - 22, pal.ground);
tufts(ctx, 0, W, 22, "#3a6a2e", t);
// The post.
rect(ctx, 47, 20, 3, 14, "#5a4030");
rect(ctx, 40, 19.4, 17, 1.4, "#4a3426");
// Letters fallen in the grass.
for (let k = 0; k < 5; k++) {
ctx.save();
ctx.translate(30 + k * 5 + rnd(k, 2) * 2, 30.5 + rnd(k, 4));
turn(ctx, (rnd(k, 6) - 0.5) * 0.9);
rect(ctx, -1.6, -0.9, 3.2, 1.8, k % 2 ? "#ece4cc" : "#d8cca8");
ctx.restore();
}
// The box: a rounded tin tunnel, rusting, its mouth to the left.
const bx = 36;
const by = 9;
const bw = 24;
const bh = 10.4;
ctx.beginPath();
ctx.moveTo(bx, by + bh);
ctx.lineTo(bx, by + bh * 0.45);
ctx.arc(bx + bh * 0.45, by + bh * 0.45, bh * 0.45, Math.PI, Math.PI * 1.5);
ctx.lineTo(bx + bw - bh * 0.45, by);
ctx.arc(bx + bw - bh * 0.45, by + bh * 0.45, bh * 0.45, Math.PI * 1.5, 0);
ctx.lineTo(bx + bw, by + bh);
ctx.closePath();
ctx.fillStyle = "#7a7682";
ctx.fill();
rect(ctx, bx + 3, by + 0.6, bw - 6, 1, "#9a96a2");
faint(ctx, 0.6, () => ell(ctx, bx + 15, by + 7, 3.2, 1.2, "#8a4a2a"));
faint(ctx, 0.5, () => ell(ctx, bx + 7, by + 8.6, 1.6, 0.6, "#8a4a2a"));
rect(ctx, bx - 0.5, by + 1.2, 0.8, bh - 1.2, "#3a363e");
// The bundle bursting out of its mouth.
for (let k = 0; k < 7; k++) {
ctx.save();
ctx.translate(bx - 1, by + 2.4 + k * 1.1);
turn(ctx, -0.4 + k * 0.13 + (rnd(k, 3) - 0.5) * 0.2);
rect(ctx, -5 - (k % 3) * 0.6, -1, 6.5, 2, k % 2 ? "#ece4cc" : "#d4c8a2");
ctx.strokeStyle = "#8a8070";
ctx.lineWidth = 0.12;
ctx.strokeRect(-5 - (k % 3) * 0.6, -1, 6.5, 2);
ctx.restore();
}
// The flag at the right side: up, then down with a clack and a bounce.
const drop = t < FLAG_MS ? 0 : clamp((t - FLAG_MS) / 160);
const bounce = t < FLAG_MS + 160 ? 0 : Math.sin(clamp((t - FLAG_MS - 160) / 500) * Math.PI * 2) * 0.18 * (1 - clamp((t - FLAG_MS - 160) / 500));
const ang = -Math.PI / 2 + drop * (Math.PI / 2) + bounce;
ctx.save();
ctx.translate(bx + bw - 3, by + 6);
turn(ctx, ang);
rect(ctx, 0, -0.35, 7, 0.7, "#c03030");
rect(ctx, 5, -0.35, 2.4, 2.2, "#d84040");
ctx.restore();
circle(ctx, bx + bw - 3, by + 6, 0.5, "#3a363e");
// The last envelope sliding out on top, then the stamp.
const slide = smooth((t - SLIDE_MS) / 700);
if (slide > 0) {
ctx.save();
// It comes out of the box's mouth: nothing of it shows inside the tin.
ctx.beginPath();
ctx.rect(0, 0, bx + 0.3, SCENE_H);
ctx.clip();
ctx.translate(bx + 5.5 - slide * 11, by + 2.4 - slide * 1.6);
turn(ctx, -0.16 * slide);
rect(ctx, -6, -2, 12, 4, "#f6f0dc");
ctx.strokeStyle = "#8a8070";
ctx.lineWidth = 0.14;
ctx.strokeRect(-6, -2, 12, 4);
poly(ctx, [[-6, -2], [0, 0.4], [6, -2]], "#e6dcc0");
const pop = t < STAMP_MS ? 0 : clamp((t - STAMP_MS) / 140);
if (pop > 0) {
const k = 1 + (1 - pop) * 0.8;
ctx.save();
turn(ctx, -0.08);
ctx.scale(k, k);
ctx.strokeStyle = "#d42020";
ctx.lineWidth = 0.3;
ctx.strokeRect(-5.3, -1.4, 10.6, 2.8);
ctx.font = "900 1.8px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#d42020";
ctx.fillText("FINAL NOTICE", 0, 0.05, 10);
ctx.restore();
}
ctx.restore();
}
// YOU at the right, looking at it, and then the sweat.
const sweat = smooth((t - GAG_MS - 200) / 300);
hero(ctx, 80, 31.6, 2.4, -1, { t, down: true, sweat });
if (t >= STAMP_MS && t < STAMP_MS + 220) faint(ctx, 0.25 * (1 - (t - STAMP_MS) / 220), () => rect(ctx, 0, 0, W, SCENE_H, "#ffffff"));
},
};
/* --------------------------------------------------------------- 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 endingArt(d) {
const { label, GOLD, BONE } = d;
function card(ctx, v) {
const { round } = v;
const s = round.ending;
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();
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));
// A small shake as the stamp lands.
const shake = pg.scene === "notice" && t >= STAMP_MS && t < STAMP_MS + 180 ? Math.sin(t / 12) * 0.35 * (1 - (t - STAMP_MS) / 180) : 0;
if (shake) ctx.translate(shake, 0);
SCENES[pg.scene](ctx, { t, pal: pg.pal, line, full: s.full || done, label, grow });
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.
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.
typed(pg, n).forEach((text, i) => {
if (!text) return;
const full = pg.lines[i];
label(ctx, "", 0, 0, TEXT_SIZE, BONE, "left");
const x0 = W / 2 - widthOf(ctx, full, TEXT_SIZE) / 2;
const y = SCENE_H + 6.7 + i * 3.35;
label(ctx, text, x0, y, TEXT_SIZE, BONE, "left", W - 4);
if (i === line && !done) {
const w = widthOf(ctx, text, 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.45)"));
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 (turnable(s)) {
const last = s.page === PAGES.length - 1;
faint(ctx, 0.55 + 0.45 * Math.sin(t / 260), () => label(ctx, last ? LAST_HINT : ENDING_HINT, W / 2, H - 1.5, 1.6, pg.pal.glow, "center", W - 6));
}
// A slow fade up from black as each page opens (slower on the first, out of the fight).
const fade = s.page === 0 ? 900 : 500;
if (t < fade) faint(ctx, 1 - t / fade, () => rect(ctx, 0, 0, W, H, "#000"));
ctx.restore();
ctx.globalAlpha = 1;
}
// The ending's own events: a page turning rustles (the first opens in silence, under the hush).
function react(e, k) {
if (e.type !== "endingPage") return false;
if (e.page) k.tone("ghoulStoryPage", 0.3);
return true;
}
return Object.freeze({ card, react });
}
@@ -0,0 +1,206 @@
// Plan2Code Web Console - Ghoul Rush's ending: four short pages shown once the House is dead, before the end screen (the lights going out, the road home, the cottage by daylight, the mailbox's FINAL NOTICE), the words as data and the rules (lockout, reveal, skip) as plain functions over a round, the same shape as ghoul-story.js. ghoul-ending-draw.js draws the scenes; ghoul-sfx-ending.js has the sounds and the track; scripts/test-web-console-activities-ghoul-ending.mjs checks it all.
//
// The contract core/ghoul-run.js, core/ghoul-play.js and core/ghoul-window.js keep with this file:
// - beginEnding(round): open the ending (phase "ending"); false when there is none.
// - stepEnding(round, ms): one slice of it.
// - takeEnding(round): a press (a move key, fire or a click) turns the page; false when it does not count.
// - pressEnding(round, repeat), releaseEnding(round): fire pressed (held long enough, it skips) and let go.
// - skipEnding(round): all of it at once.
// - ENDING_TRACK: the music to play under it (null for none).
// Ending it must set round.won = true and round.over = true and push { type: "won", stages: round.cleared.length, n: round.winN }.
//
// Rules for the text, as the intro story's: 2 to 4 lines a page, each at most
// MAX_LINE characters, always YOU, no digits, no em dash, US English. Each page
// pays off something the story planted: every window going dark, the road that
// folded "like a napkin", the cottage it "was once", the bill nobody has paid.
//
// The phase `ending` (round.phase): round.ending = { page, ms, full, arm, hold,
// cue, shown, back }, the same fields as round.story, and `back`, the phase the
// round was in when the ending opened (put back when it ends, so the end screen
// draws the room as it always did).
export const MAX_LINE = 60;
// A press counts only after a page has been up this long. Longer than the story's: YOU come here straight from a fight, maybe still mashing keys.
export const ENDING_LOCK_MS = 900;
export const RELOCK_MS = 200;
// Fire held this long skips the whole ending.
export const SKIP_HOLD_MS = 1000;
// The typing, slower and calmer than the story's.
export const REVEAL_AT_MS = 600;
export const CHAR_MS = 30;
export const ENDING_HINT = "Press any move key or fire to go on";
export const LAST_HINT = "Press any move key or fire to finish";
export const SKIP_HINT = "Hold fire to skip";
export const ENDING_TRACK = "ghoulMarrowEnding";
const freeze = Object.freeze;
// `wait`: the page will not turn before this many ms, so its scene plays out (the last window, the click, the gag) however fast YOU read.
const page = (id, scene, chapter, pal, lines, cues, wait = 0) => freeze({ id, scene, chapter, pal: freeze(pal), lines: freeze(lines), cues: freeze(cues.map((c) => freeze(c))), wait });
// LIGHTS OUT: the house's windows (the drawing's ten, by index) going out one
// by one, [window, ms]; the last, the attic's, after a long breath. Each has its
// own falling tone, lower as the house darkens.
export const LIGHTS_OUT = freeze([[4, 900], [8, 1250], [1, 1600], [6, 1950], [2, 2300], [7, 2650], [0, 3000], [5, 3300], [3, 3600], [9, 4700]].map((w) => freeze(w)));
const outCues = LIGHTS_OUT.map(([, ms], i) => (i === LIGHTS_OUT.length - 1 ? [ms, "ghoulEndingLast", 0.55, 1] : [ms, "ghoulEndingWindow", 0.4, 1.25 - i * 0.06]));
// THE ROAD: when the road starts to unfold, and when YOUR flashlight clicks off.
export const UNFOLD_MS = 700;
export const CLICK_OFF_MS = 3900;
// FINAL NOTICE: the flag drops, the last envelope slides out, its stamp lands.
export const FLAG_MS = 1000;
export const SLIDE_MS = 1700;
export const STAMP_MS = 2900;
export const GAG_MS = 3850;
export const PAGES = freeze([
page("lights", "lights", "LIGHTS OUT", { sky: "#0d0b22", ground: "#05040c", a: "#ffe6a8", glow: "#ffc15a" }, [
"One window. Then another. Then all of them, at last.",
"Marrow has eaten its last fright. YOU were not on the menu.",
], [[0, "ghoulEndingHush", 0.4, 1], ...outCues, [5000, "ghoulStoryWind", 0.2, 0.7]], 5300),
page("road", "road", "THE ROAD", { sky: "#2a2244", ground: "#14101e", a: "#ffd9b0", glow: "#ff9e6a" }, [
"The road unfolds, flat and honest, and goes somewhere.",
"YOU walk. Nothing herds YOU now. Your flashlight clicks off.",
], [[UNFOLD_MS, "ghoulEndingFold", 0.35, 1], [UNFOLD_MS + 900, "ghoulEndingFold", 0.3, 1.15], [UNFOLD_MS + 1800, "ghoulEndingFold", 0.25, 1.3], [2600, "ghoulEndingBird", 0.25, 1], [CLICK_OFF_MS, "ghoulEndingClickOff", 0.45, 1]], 4400),
page("morning", "morning", "MORNING", { sky: "#8fc4ea", ground: "#3d6b34", a: "#fff4c2", glow: "#ffd34d" }, [
"By daylight YOU see it plain: a cottage with a bad roof.",
"It was a cottage once, before it got a taste for it.",
], [[300, "ghoulEndingBird", 0.3, 1], [1500, "ghoulEndingBird", 0.25, 1.2], [2700, "ghoulEndingSettle", 0.3, 1], [3900, "ghoulEndingBird", 0.25, 0.9]]),
page("notice", "notice", "FINAL NOTICE", { sky: "#a9d3ef", ground: "#4a7a3a", a: "#ffe0e0", glow: "#ef4444" }, [
"YOU stop at the mailbox. A century of unpaid bills.",
"On top: FINAL NOTICE. Somebody is going to be very upset.",
], [[FLAG_MS, "ghoulEndingFlag", 0.45, 1], [SLIDE_MS, "ghoulEndingPaper", 0.35, 1], [STAMP_MS, "ghoulEndingStamp", 0.55, 1], [GAG_MS, "ghoulEndingGag", 0.45, 1]], 4500),
]);
// 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(ENDING_LOCK_MS, s.arm);
// Whether a press would do something now: finish the typing, or turn the page once its scene has played out.
export const turnable = (s) => ready(s) && (!(s.full || s.ms >= revealEnd(PAGES[s.page])) || s.ms >= PAGES[s.page].wait);
/* ------------------------------------------------------------ the phase */
function showPage(round, at) {
const s = round.ending;
s.page = at;
s.ms = 0;
s.full = false;
s.arm = 0;
s.cue = 0;
s.shown = 0;
round.events.push({ type: "endingPage", page: at });
}
// Opens the ending on its first page: nothing else moves until it ends.
export function beginEnding(round) {
if (!PAGES.length) return false;
const back = round.phase;
round.phase = "ending";
round.phaseMs = 0;
const inp = round.input;
inp.left = inp.right = inp.up = inp.down = inp.fire = false;
inp.jump = 0;
round.ending = { page: 0, ms: 0, full: false, arm: 0, hold: -1, cue: 0, shown: 0, back };
round.events.push({ type: "endingPage", page: 0 });
return true;
}
// The last page turned (or the whole ending skipped): the run is won, once.
function endEnding(round) {
const s = round.ending;
if (!s) return;
round.ending = null;
round.phase = s.back;
round.phaseMs = 0;
round.won = true;
round.over = true;
round.events.push({ type: "won", stages: round.cleared.length, n: round.winN });
}
// One slice of the ending: the page's clock, its sounds and typing blips, and a fire key held long enough to skip it all.
export function stepEnding(round, ms) {
const s = round.ending;
if (round.phase !== "ending" || !s) return;
const pg = PAGES[s.page];
if (s.hold >= 0) {
s.hold += ms;
if (s.hold >= SKIP_HOLD_MS) {
endEnding(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 fourth character typed: quieter than the story's.
const now = shown(pg, s.ms, s.full);
if (!s.full && Math.floor(now / 4) > Math.floor(s.shown / 4)) round.events.push({ type: "storyTone", name: "tickSoft", vol: 0.07, rate: 1.3 });
s.shown = now;
}
// A press (a move key, fire or a click): finishes the typing first, then turns the page, and the last page wins the run. False when it does not count (too soon, or not in the ending).
export function takeEnding(round) {
const s = round.ending;
if (round.phase !== "ending" || !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.ms < pg.wait) return false;
if (s.page + 1 >= PAGES.length) endEnding(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 pressEnding(round, repeat) {
const s = round.ending;
if (round.phase !== "ending" || !s || repeat) return false;
s.hold = 0;
takeEnding(round);
return true;
}
// Fire let go: the skip's clock stops.
export function releaseEnding(round) {
if (round.ending) round.ending.hold = -1;
}
// The whole ending at once.
export function skipEnding(round) {
if (round.phase !== "ending" || !round.ending) return false;
endEnding(round);
return true;
}
@@ -240,6 +240,25 @@ const FLOURISH = {
});
}
},
// The finale: rain slanting down over a row of lit windows along the bottom, winking out one by one and coming back.
marrow(ctx, t, pal, W, H) {
for (let i = 0; i < 40; i++) {
const x = ((rnd(i) * (W + 12) + t / 18) % (W + 12)) - 6;
const y = ((t / 7 + rnd(i, 1) * H * 2) % (H + 6)) - 3;
faint(ctx, 0.35, () => stroke(ctx, x, y, x - 0.9, y + 2.6, pal.a, 0.12));
}
const n = 9;
const out = Math.floor((t / 650) % (n + 4));
for (let i = 0; i < n; i++) {
const x = 6 + i * ((W - 12) / (n - 1));
ctx.fillStyle = "rgba(10, 6, 12, 0.92)";
ctx.fillRect(x - 2.6, H - 7, 5.2, 7);
const lit = i >= out;
ctx.fillStyle = lit ? pal.glow : "rgba(16, 12, 20, 0.95)";
ctx.fillRect(x - 1.5, H - 5.8, 3, 3.4);
if (lit) faint(ctx, 0.25 + 0.1 * Math.sin(t / 160 + i), () => dot(ctx, x, H - 4.1, 3.2, pal.glow));
}
},
// 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);
@@ -1,4 +1,4 @@
// 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.
// 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 SELECTABLE (the stages and the finale) 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),
@@ -79,6 +79,12 @@ export const INTROS = freeze({
"Chase the pretty lights and they will lead YOU under.",
"The mud holds what it catches. Do not let it hold YOU.",
]),
marrow: intro("Marrow Manor", "#f3d27a", "#7a2e12", "#c8a04a", "It knows you are home", "Marrow", [
"Every door YOU picked led here. YOU are back on the lawn.",
"No more keepers. No more copies. Just the house itself.",
"It has been eating fright for longer than the valley stood.",
"Tonight it is hungry, and YOU are the only guest left.",
]),
});
// The card for a stage id, or null for an id with none (the hall is no stage and has no card).
@@ -0,0 +1,236 @@
// Plan2Code Web Console - ghoul: the ending's sounds and music, merged into sfx/ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-story.js: `tones` (one-shots named in the
// pages' `cues` in ghoul-ending.js: a hush, a window going out and the last
// one, the road unfolding, a bird at dawn, the flashlight clicking off, the
// cottage settling, the mailbox's flag, an envelope, the FINAL NOTICE stamp
// and the gag's sad horn) and `music` (ghoulMarrowEnding, the track under the
// whole ending, the user's pick: eighties horror end credits). The tones are
// the user's picks from the sound vote (prototypes/sounds/ghoul-rush/ending.html).
// 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 ENDING_SFX = {
tones: {
// LIGHTS OUT: The house from the hill: every window goes out, one by one, to a falling tone each, then the last.
// The ending opens: Low warm chord (option 4).
ghoulEndingHush: {
layers: [
{ type: "sine", from: 147, to: 147, seconds: 1.15, attack: 0.3, gain: 0.14 },
{ type: "sine", from: 220, to: 220, seconds: 1.15, attack: 0.3, gain: 0.108 },
{ type: "sine", from: 294, to: 293, seconds: 1.15, attack: 0.3, gain: 0.088 },
{ type: "sine", from: 370, to: 369, seconds: 1.15, attack: 0.3, gain: 0.074 },
],
},
// A window goes out: Click and soft fall (option 1).
ghoulEndingWindow: {
layers: [
{ type: "noise", seconds: 0.03, attack: 0, gain: 0.18, filter: { type: "bandpass", from: 2600, to: 1800, q: 4 } },
{ type: "sine", from: 880, to: 440, seconds: 0.7, attack: 0.01, gain: 0.22, delay: 0.02 },
{ type: "triangle", from: 1320, to: 660, seconds: 0.5, attack: 0.01, gain: 0.06, delay: 0.02 },
],
},
// The last window: Long fall, warm chord (option 1).
ghoulEndingLast: {
layers: [
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.2, filter: { type: "bandpass", from: 2000, to: 1400, q: 4 } },
{ type: "sine", from: 587, to: 147, seconds: 1.15, attack: 0.02, gain: 0.3, delay: 0.03 },
{ type: "sine", from: 294, to: 293, seconds: 1.09, attack: 0.3, gain: 0.12, delay: 0.1 },
{ type: "sine", from: 440, to: 439, seconds: 1, attack: 0.3, gain: 0.08, delay: 0.15 },
{ type: "sine", from: 370, to: 369, seconds: 1, attack: 0.3, gain: 0.07, delay: 0.2 },
],
},
// THE ROAD: Dawn: the road unfolds out of the valley, creasing flat like a napkin; YOU walk; the flashlight clicks off.
// The road unfolds: Paper shaken out (option 1).
ghoulEndingFold: {
layers: [
{ type: "noise", seconds: 0.35, attack: 0.08, gain: 0.22, filter: { type: "bandpass", from: 900, to: 3200, q: 1.1 } },
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.2, delay: 0.3, filter: { type: "highpass", from: 2500, to: 3500, q: 1 } },
{ type: "sine", from: 180, to: 120, seconds: 0.2, attack: 0.01, gain: 0.12, delay: 0.3 },
],
},
// A bird: Two chirps and a trill (option 1).
ghoulEndingBird: {
layers: [
{ type: "sine", from: 2600, to: 3400, seconds: 0.08, attack: 0.005, gain: 0.14 },
{ type: "sine", from: 2800, to: 3600, seconds: 0.08, attack: 0.005, gain: 0.12, delay: 0.14 },
{ type: "sine", from: 3200, to: 2600, seconds: 0.3, attack: 0.01, gain: 0.08, delay: 0.32, vibrato: { rate: 26, depth: 0.05 } },
],
},
// The flashlight clicks off: Switch and settle (option 1).
ghoulEndingClickOff: {
layers: [
{ type: "square", from: 1100, to: 700, seconds: 0.016, attack: 0, gain: 0.25 },
{ type: "noise", seconds: 0.025, attack: 0, gain: 0.22, delay: 0.015, filter: { type: "highpass", from: 3000, to: 3500, q: 1 } },
{ type: "triangle", from: 900, to: 300, seconds: 0.4, attack: 0.01, gain: 0.08, delay: 0.04 },
],
},
// MORNING: Broad day: the House is only a small sagging cottage in the sun, birds on the roof.
// The cottage settles: Easy creak (option 1).
ghoulEndingSettle: {
layers: [
{ type: "sawtooth", from: 200, to: 170, seconds: 0.6, attack: 0.1, gain: 0.06, filter: { type: "bandpass", from: 900, to: 700, q: 6 }, vibrato: { rate: 9, depth: 0.04 } },
{ type: "brown", seconds: 0.4, attack: 0.05, gain: 0.25, filter: { type: "lowpass", from: 300, to: 150, q: 1 } },
],
},
// FINAL NOTICE: The stuffed mailbox in close-up: the flag drops, a last envelope slides out, FINAL NOTICE stamped on it.
// The flag drops: Tin clack and rattle (option 1).
ghoulEndingFlag: {
layers: [
{ type: "square", from: 620, to: 540, seconds: 0.05, attack: 0, gain: 0.16, filter: { type: "bandpass", from: 1800, to: 1400, q: 3 } },
{ type: "noise", seconds: 0.06, attack: 0, gain: 0.25, filter: { type: "bandpass", from: 3000, to: 2200, q: 4 } },
{ type: "triangle", from: 780, to: 760, seconds: 0.25, attack: 0.002, gain: 0.08, delay: 0.05 },
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.12, delay: 0.12, filter: { type: "bandpass", from: 2800, to: 2000, q: 4 } },
],
},
// An envelope slides out: Paper slide (option 1).
ghoulEndingPaper: {
layers: [
{ type: "noise", seconds: 0.45, attack: 0.1, gain: 0.18, filter: { type: "bandpass", from: 2400, to: 4200, q: 1.5 } },
{ type: "pink", seconds: 0.3, attack: 0.05, gain: 0.12, delay: 0.1, filter: { type: "highpass", from: 1500, to: 2500, q: 1 } },
],
},
// FINAL NOTICE is stamped: Rubber stamp thump (option 1).
ghoulEndingStamp: {
layers: [
{ type: "sine", from: 140, to: 60, seconds: 0.18, attack: 0.002, gain: 0.6 },
{ type: "noise", seconds: 0.06, attack: 0, gain: 0.35, filter: { type: "lowpass", from: 1600, to: 500, q: 1 } },
{ type: "brown", seconds: 0.15, attack: 0.002, gain: 0.4, filter: { type: "lowpass", from: 400, to: 120, q: 1 } },
],
},
// The gag lands: Wah wah wah waaah (option 2).
ghoulEndingGag: {
layers: [
{ type: "sawtooth", from: 330, to: 330, seconds: 0.22, attack: 0.03, gain: 0.13, filter: { type: "lowpass", from: 900, to: 700, q: 2 } },
{ type: "sawtooth", from: 311, to: 311, seconds: 0.22, attack: 0.03, gain: 0.13, delay: 0.25, filter: { type: "lowpass", from: 900, to: 700, q: 2 } },
{ type: "sawtooth", from: 294, to: 294, seconds: 0.22, attack: 0.03, gain: 0.13, delay: 0.5, filter: { type: "lowpass", from: 900, to: 700, q: 2 } },
{ type: "sawtooth", from: 277, to: 247, seconds: 0.45, attack: 0.03, gain: 0.13, delay: 0.75, filter: { type: "lowpass", from: 900, to: 500, q: 2 }, vibrato: { rate: 6, depth: 0.03 } },
],
},
},
music: {
// The ending: eighties horror end credits. The credits roll like an old VHS horror film's: a pulsing synth
// arpeggio in D minor, a wide pad, a driving bass in eighths and a lonely sawtooth lead. A faint kick plays the
// House's heartbeat, two thumps and a rest, slowing until it stops, and the theme rises through one D major bar
// like sunrise. Then the arpeggio cuts off mid-bar, the heart kicks twice in the quiet, and the lead's last note
// slides a half step off.
ghoulMarrowEnding: {
bpm: 112,
voices: {
arp: { wave: "pulse", duty: 0.125, gain: 0.03, decay: 0.02, sustain: 0.3 },
padLo: { wave: "sawtooth", gain: 0.012, decay: 0.6, sustain: 1 },
padMid: { wave: "sawtooth", gain: 0.011, decay: 0.6, sustain: 1, from: 0.2 },
padHi: { wave: "sawtooth", gain: 0.01, decay: 0.6, sustain: 1, from: 0.3 },
bass: { wave: "triangle", gain: 0.28, decay: 0.04, sustain: 0.4 },
lead: { wave: "sawtooth", gain: 0.045, decay: 0.1, sustain: 0.8, from: 0.3, vibrato: { rate: 5, depth: 0.008, delay: 0.25 } },
heart: { kit: true, gain: 0.24 },
hat: { kit: true, gain: 0.04, from: 0.5 },
},
patterns: {
I: {
arp:
"D4 F4 A4 D5 D4 F4 A4 D5 D4 F4 A4 D5 D4 F4 A4 D5 | D4 F4 A4 D5 D4 F4 A4 D5 D4 F4 A4 D5 D4 F4 A4 D5",
padLo:
"A3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -",
padMid:
"D4 - - - - - - - - - - - - - - - | D4 - - - - - - - - - - - - - - -",
padHi:
"F4 - - - - - - - - - - - - - - - | F4 - - - - - - - - - - - - - - -",
bass:
"D2 . D2 . D2 . D2 . D2 . D2 . D2 . D2 . | D2 . D2 . D2 . D2 . D2 . D2 . D2 . D2 .",
lead:
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
heart:
"k . k . . . . . . . . . . . . . | k . k . . . . . . . . . . . . .",
hat:
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
},
A: {
arp:
"D4 F4 A4 D5 D4 F4 A4 D5 D4 F4 A4 D5 D4 F4 A4 D5 | D4 F4 Bb4 D5 D4 F4 Bb4 D5 D4 F4 Bb4 D5 D4 F4 Bb4 D5 | " +
"F4 A4 C5 F5 F4 A4 C5 F5 F4 A4 C5 F5 F4 A4 C5 F5 | E4 G4 C5 E5 E4 G4 C5 E5 E4 G4 C5 E5 E4 G4 C5 E5 | " +
"D4 F4 A4 D5 D4 F4 A4 D5 D4 F4 A4 D5 D4 F4 A4 D5 | D4 F4 Bb4 D5 D4 F4 Bb4 D5 D4 F4 Bb4 D5 D4 F4 Bb4 D5 | " +
"D4 G4 Bb4 D5 D4 G4 Bb4 D5 D4 G4 Bb4 D5 D4 G4 Bb4 D5 | E4 A4 C#5 E5 E4 A4 C#5 E5 E4 A4 C#5 E5 E4 A4 C#5 E5",
padLo:
"A3 - - - - - - - - - - - - - - - | Bb3 - - - - - - - - - - - - - - - | " +
"A3 - - - - - - - - - - - - - - - | C4 - - - - - - - - - - - - - - - | " +
"A3 - - - - - - - - - - - - - - - | Bb3 - - - - - - - - - - - - - - - | " +
"Bb3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -",
padMid:
"D4 - - - - - - - - - - - - - - - | D4 - - - - - - - - - - - - - - - | " +
"C4 - - - - - - - - - - - - - - - | E4 - - - - - - - - - - - - - - - | " +
"D4 - - - - - - - - - - - - - - - | D4 - - - - - - - - - - - - - - - | " +
"D4 - - - - - - - - - - - - - - - | C#4 - - - - - - - - - - - - - - -",
padHi:
"F4 - - - - - - - - - - - - - - - | F4 - - - - - - - - - - - - - - - | " +
"F4 - - - - - - - - - - - - - - - | G4 - - - - - - - - - - - - - - - | " +
"F4 - - - - - - - - - - - - - - - | F4 - - - - - - - - - - - - - - - | " +
"G4 - - - - - - - - - - - - - - - | E4 - - - - - - - - - - - - - - -",
bass:
"D2 . D2 . D2 . D2 . D2 . D2 . D2 . D2 . | Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . | " +
"F2 . F2 . F2 . F2 . F2 . F2 . F2 . F2 . | C3 . C3 . C3 . C3 . C3 . C3 . C3 . C3 . | " +
"D2 . D2 . D2 . D2 . D2 . D2 . D2 . D2 . | Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . | " +
"G2 . G2 . G2 . G2 . G2 . G2 . G2 . G2 . | A2 . A2 . A2 . A2 . A2 . A2 . A2 . A2 .",
lead:
"D5 - - - - - - - F5 - - - A5 - - - | Bb5 - - - - - - - A5 - - - F5 - - - | " +
"A5 - - - - - - - C6 - - - A5 - - - | G5 - - - - - - - - - - - E5 - - - | " +
"D6 - - - - - - - C6 - - - A5 - - - | Bb5 - - - - - - - D6 - - - F6 - - - | " +
"G6 - - - - - - - F6 - - - D6 - - - | E6 - - - - - - - C#6 - - - A5 - - -",
heart:
"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 . h . h . h . h . h . h . h | . h . h . h . h . h . h . h . h | " +
". h . h . h . h . h . h . h . h | . h . h . h . h . h . h . h . h | " +
". h . h . h . h . h . h . h . h | . h . h . h . h . h . h . h . h",
},
B: {
arp:
"D4 F4 Bb4 D5 D4 F4 Bb4 D5 D4 F4 Bb4 D5 D4 F4 Bb4 D5 | E4 G4 C5 E5 E4 G4 C5 E5 E4 G4 C5 E5 E4 G4 C5 E5 | " +
"E4 A4 C5 E5 E4 A4 C5 E5 E4 A4 C5 E5 E4 A4 C5 E5 | D4 F4 A4 D5 D4 F4 A4 D5 D4 F4 A4 D5 D4 F4 A4 D5 | " +
"D4 G4 Bb4 D5 D4 G4 Bb4 D5 D4 G4 Bb4 D5 D4 G4 Bb4 D5 | E4 G4 C5 E5 E4 G4 C5 E5 E4 G4 C5 E5 E4 G4 C5 E5 | " +
"D4 F#4 A4 D5 D4 F#4 A4 D5 D4 F#4 A4 D5 D4 F#4 A4 D5 | D4 F4 A4 D5 D4 F4 A4 D5 . . . . . . . .",
padLo:
"Bb3 - - - - - - - - - - - - - - - | C4 - - - - - - - - - - - - - - - | " +
"A3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - - | " +
"Bb3 - - - - - - - - - - - - - - - | C4 - - - - - - - - - - - - - - - | " +
"A3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -",
padMid:
"D4 - - - - - - - - - - - - - - - | E4 - - - - - - - - - - - - - - - | " +
"C4 - - - - - - - - - - - - - - - | D4 - - - - - - - - - - - - - - - | " +
"D4 - - - - - - - - - - - - - - - | E4 - - - - - - - - - - - - - - - | " +
"D4 - - - - - - - - - - - - - - - | D4 - - - - - - - - - - - - - - -",
padHi:
"F4 - - - - - - - - - - - - - - - | G4 - - - - - - - - - - - - - - - | " +
"E4 - - - - - - - - - - - - - - - | F4 - - - - - - - - - - - - - - - | " +
"G4 - - - - - - - - - - - - - - - | G4 - - - - - - - - - - - - - - - | " +
"F#4 - - - - - - - - - - - - - - - | F4 - - - - - - - - - - - - - - -",
bass:
"Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . Bb2 . | C3 . C3 . C3 . C3 . C3 . C3 . C3 . C3 . | " +
"A2 . A2 . A2 . A2 . A2 . A2 . A2 . A2 . | D2 . D2 . D2 . D2 . D2 . D2 . D2 . D2 . | " +
"G2 . G2 . G2 . G2 . G2 . G2 . G2 . G2 . | C3 . C3 . C3 . C3 . C3 . C3 . C3 . C3 . | " +
"D2 . D2 . D2 . D2 . D2 . D2 . D2 . D2 . | D2 - - - - - - - . . . . . . . .",
lead:
"F5 - - - - - - - D5 - - - F5 - - - | G5 - - - - - - - E5 - - - G5 - - - | " +
"A5 - - - - - - - C6 - - - E6 - - - | D6 - - - - - - - - - - - . . . . | " +
"Bb5 - - - - - - - D6 - - - G6 - - - | G6 - - - - - - - E6 - - - C6 - - - | " +
"F#6 - - - - - - - A6 - - - F#6 - - - | F6 - - - - - - - . . . . Eb6 - - -",
heart:
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . k . . . k . . .",
hat:
". h . h . h . h . h . h . h . h | . h . h . h . h . h . h . h . h | " +
". h . h . h . h . h . h . h . h | . h . h . h . h . h . h . h . h | " +
". h . h . h . h . h . h . h . h | . h . h . h . h . h . h . h . h | " +
". h . h . h . h . h . h . h . h | . . . . . . . . . . . . . . . .",
},
},
order: ["I", "A", "B"],
},
},
};
@@ -86,7 +86,7 @@ export const PAGES = freeze([
], [[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.",
"Far below, its heart is still beating. Go and stop it.",
"Switch on YOUR light. Let it flinch again.",
], [[0, "ghoulStoryCreak", 0.4, 1], [2300, "ghoulStoryBeat", 0.5, 1], [3900, "ghoulStoryBegin", 0.8, 1]]),
]);
+22
View File
@@ -180,6 +180,22 @@ export const SERVABLE = new Set([
"activities/ghoul-rush/arms/ghoul-flare.js",
"activities/ghoul-rush/stages/bog/ghoul-bog.js",
"activities/ghoul-rush/stages/bog/ghoul-bog-draw.js",
"activities/ghoul-rush/stages/marrow/ghoul-marrow.js",
"activities/ghoul-rush/stages/marrow/ghoul-marrow-draw.js",
"activities/ghoul-rush/rides/mat/ghoul-mat-room.js",
"activities/ghoul-rush/rides/mat/ghoul-mat.js",
"activities/ghoul-rush/rides/mat/ghoul-mat-draw.js",
"activities/ghoul-rush/stages/marrow/ghoul-dollhouse-room.js",
"activities/ghoul-rush/stages/marrow/ghoul-marrow-eye.js",
"activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js",
"activities/ghoul-rush/rides/bonestair/ghoul-bonestair-room.js",
"activities/ghoul-rush/rides/bonestair/ghoul-bonestair.js",
"activities/ghoul-rush/rides/bonestair/ghoul-bonestair-draw.js",
"activities/ghoul-rush/stages/marrow/ghoul-pit-room.js",
"activities/ghoul-rush/stages/marrow/ghoul-marrow-heart.js",
"activities/ghoul-rush/stages/marrow/ghoul-marrow-heart-draw.js",
"activities/ghoul-rush/story/ghoul-ending.js",
"activities/ghoul-rush/story/ghoul-ending-draw.js",
"activities/ghoul-rush/draw/ghoul-picker-draw.js",
"activities/ghoul-rush/core/ghoul-powers.js",
"activities/ghoul-rush/arms/ghoul-arms.js",
@@ -226,6 +242,12 @@ export const SERVABLE = new Set([
"activities/ghoul-rush/rides/banister/ghoul-sfx-banister.js",
"activities/ghoul-rush/rides/hearse/ghoul-sfx-hearse.js",
"activities/ghoul-rush/stages/bog/ghoul-sfx-bog.js",
"activities/ghoul-rush/stages/marrow/ghoul-sfx-marrow.js",
"activities/ghoul-rush/stages/marrow/ghoul-sfx-marrow-eye.js",
"activities/ghoul-rush/stages/marrow/ghoul-sfx-marrow-heart.js",
"activities/ghoul-rush/rides/mat/ghoul-sfx-mat.js",
"activities/ghoul-rush/rides/bonestair/ghoul-sfx-bonestair.js",
"activities/ghoul-rush/story/ghoul-sfx-ending.js",
"activities/ghoul-rush/rides/wagon/ghoul-sfx-wagon.js",
"activities/ghoul-rush/rides/gurney/ghoul-sfx-gurney.js",
"activities/ghoul-rush/rides/pew/ghoul-sfx-pew.js",