Add Ghoul Rush's new stages (bog, hearse, pew, wagon and more) with their intros and suites

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-03 04:08:02 -08:00
1 parent c1e32b8aca
commit d016ba862a
78 files changed
+30982 -145

No files matched your search

@@ -63,12 +63,14 @@ export const ARM_GAP_MS = 220;
export const ARM_BOSS_SHARE = 0.35;
// Dynamite: a throw leaves at DYN_VX across and DYN_VY up, blows up DYN_FUSE_MS
// after it leaves; the blast is BLAST_W wide, BLAST_UP over the stick and
// after it leaves, or at once when a monster stands within DYN_PROX of it once it has
// landed; the blast is BLAST_W wide, BLAST_UP over the stick and
// BLAST_DOWN under it, shows BLAST_MS, does BLAST_DAMAGE to a monster (and breaks
// stone) and DYN_BOSS_DMG to a boss.
export const DYN_VX = 30;
export const DYN_VY = 38;
export const DYN_FUSE_MS = 1000;
export const DYN_PROX = 1;
export const BLAST_W = 22;
export const BLAST_UP = 9;
export const BLAST_DOWN = 3;
@@ -79,6 +81,12 @@ export const DYN_BOSS_DMG = 8;
export const STAKE_SPEED = 96;
export const STAKE_DMG = 12;
export const STAKE_BOSS = 8;
// The Harpoon: the same straight pierce, heavier and slower, and the only
// bolt that reaches a lurker's eyes under the water (Gallows Bog, see
// `target` in ghoul-bog.js).
export const HARPOON_SPEED = 84;
export const HARPOON_DMG = 14;
export const HARPOON_BOSS = 8;
// The Bottle Rocket: three at once, ahead, up and behind (ghoul-rockets.js).
export * from "./ghoul-rockets.js";
// The Hedge Sickle: SICKLE_OUT out and back, SICKLE_DMG a pass.
@@ -342,6 +350,7 @@ const USES = freeze({
flash: (round, k) => lobPod(round, k, "flash", true),
pie: lobPie,
flare: (round, k) => useFlare(round, k, lobVx(round, k, FLARE_VY, FLARE_VX)),
harpoon: (round, k) => armShot(round, k, "harpoon", HARPOON_SPEED, { dmg: HARPOON_DMG, bossDmg: HARPOON_BOSS, pierce: true }),
trap: (round) => {
const you = round.you;
// Five at once, TRAP_GAP apart: two behind, one at his feet, two ahead.
@@ -434,7 +443,9 @@ function stepStick(round, h, ms, k) {
h.fuse -= ms;
h.spin += (ms / 1000) * 14;
if (!h.rest && !flyDown(round, h, ms, k)) return false;
if (h.fuse > 0) return true;
// Landed: it also goes off at once when a monster comes within DYN_PROX of it.
const near = h.rest && round.monsters.some((m) => !m.dead && (k.solid(m) || k.stone(m)) && Math.max(0, Math.abs(m.x - h.x) - m.w / 2) <= DYN_PROX && h.y >= m.y - DYN_PROX && h.y <= m.y + m.h + DYN_PROX);
if (h.fuse > 0 && !near) return true;
blast(round, h, k);
return false;
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,520 @@
// Plan2Code Web Console - Ghoul Rush's Grand Banister, its rules: the Manor's bonus round. YOU slide down the grand staircase's endless polished banister, from the attic landing to the foyer, in one long dizzying descent: jump the vases and candlesticks on the rail, duck the hanging portrait frames and the swinging chandeliers (time them by their pendulum), jump the breaks between the landings, shoot or jump the ghostly butlers that lunge with their silver trays, and shoot the cobwebs. As a stage pack that ghoul.js plugs in.
//
// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it,
// handed a kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js (it
// borrows the cart's track helpers). Pack fields used: `ride` (a hook that moves YOU, so
// no key walks you), `place` (put down in a room: a room set up or a respawn) and `target`
// (a bolt strikes something that is no monster: the butlers and the cobwebs). No monster,
// boss or hazard kind, so nothing to merge by name, and NO random number is drawn.
//
// Its state is the shared bonus-ride slot `round.runner` (null in any other room; see
// the "runner" lines in ghoul.js and ghoul-cart.js), and its room marks itself with
// `ride.runner: "banister"`.
//
// THE ROOM (spec.ride, see ghoul-rooms.js):
//
// - `track`: polylines [x, y] the rail runs along. The first `rails` of them are the
// HANDRAIL (the upper rail), 20 flights of stairs: descents (slope -0.10 to -0.11) each
// followed by a short climb (+0.29 to +0.31, the newel at the landing: the rail sweeps up
// and over it), every crest a little lower than the last; a gap between two of them is a
// BREAK in the banister (jump it, as the sled does its cracks: the rail flies on along its
// last slope, a fall below DERAIL_Y is a heart, cause "plunge"). The lines after those are
// the brass UNDER-RAILS, RAIL_SEP (7) under the handrail along the length of one descent
// each (the split track): it begins and ends where the descent does, and ends in the air:
// jump up off its end (the handrail is above and catches you) or it is a plunge.
// The hill ends on a lip rising at 0.277 (over RAMP_SLOPE, so it launches: RAMP_POP) and
// the foyer floor begins `finish` further on, lower; flying onto it ends the ride.
// - Which rail: a jump lands on the HIGHEST rail under you (the handrail). HOLD DOWN in the
// air (a jump with DOWN held, a DIVE) to fall through it onto the under-rail where there is
// one; up from the under-rail jumps back up to the handrail.
// - `props` [x, line, kind] (kind 0 a vase, VASE_W by VASE_H, kind 1 a candlestick,
// CANDLE_W by CANDLE_H: jump), `lows` [x0, x1, y] (a hanging portrait frame, its
// underside y, from there up to the roof: DUCK it; y is 3.0 over the highest handrail
// under it, between a ducked box and a standing one), `swings` [x, line, amp, period ms,
// phase ms] (a chandelier on a chain from the roof, swinging amp each way of x on a
// pendulum of that period: see swingAt. Its bob is SWING_BOB_W wide and hangs from
// SWING_LOW over the handrail under it at the middle of its swing to SWING_LOW +
// SWING_RISE at the ends of it, and the chain makes the whole of it a wall from there up to
// the roof: DUCK it, but only while the bob is above a ducked head; at the middle of its
// swing it hangs lower than a ducked box and no ducking helps, so you pass it while it is
// out at the end of its arc, or take the under-rail, which is under it), `butlers` [x,
// line] (a ghostly butler waits; when you are BUTLER_NEAR short of it it bows BUTLER_WARN_MS,
// then lunges up the rail at you at BUTLER_V for up to BUTLER_LUNGE_MS, BUTLER_W by
// BUTLER_H: jump it, or shoot it, BUTLER_HP bolts), `webs` [x, line] (a cobweb across the
// rail: shoot it for points; riding through only tears it), `checks`, `finish` and
// `time` (the room's clock, ms).
// - The ground is the attic landing at the start and the foyer floor at the end only.
//
// YOU (`round.runner`): { id, v, line, coyote, from, left, check, done, clock, dive,
// butlers, webs }. You ride at (you.x, you.y), always facing right (`you.state` "run" on
// the rail, "air" off it, `you.ducking` ducked on it). Speed `v` relaxes to BAN_V (RELAX)
// and is pushed by the slope (SLOPE_G), between BAN_MIN and BAN_MAX; RIGHT leans (LEAN_ACC)
// and LEFT brakes (BRAKE_ACC) on the rail, which is how you time a chandelier. Up jumps at
// BAN_JUMP_V (plus the slope's own rise) against BAN_G (about 13 high, 0.75 s, 34 across at
// BAN_V), COYOTE_MS of grace after running off a line's end; down ducks (on the rail) or
// dives (in the air). `clock` is the pendulums' time in ms: it only runs while you ride.
// A bolt flies parallel to the rail under it, so the shooting is level with the stairs.
//
// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the ride
// rolls on, you blinking safe BONUS_SAFE_MS; the last heart gone ends the round with nothing,
// at once. A derail puts you back on the handrail (the highest line under you, else the next
// ahead) at BAN_V. Causes: "vase", "candle", "frame", "swing", "butler", "plunge". Every
// obstacle is a number for the grade (`perf.total`: props, lows, swings, butlers and breaks,
// each id once in `perf.hits` if it ever cost a heart). Shooting a butler or a web counts for
// `perf.acts` (the grade's goal is ACTS_GOAL) and the points below. The grade's `steady` die
// is a smooth slide: braking for no more than STEADY_BRAKE_MS in all.
//
// WHAT THE ART READS: `spec.ride` (above), `round.runner` { v, line, check, done, left, clock,
// butlers: [{ state "wait"|"warn"|"lunge"|"broken"|"spent", t, x }], webs: ["up"|"torn"|"shot"] },
// `round.you` (`state`, `vy`, `ducking`), the events in EVENTS.
import { linesAt, linesOf, slopeOf, trackY } from "./ghoul-cart.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
export const MONSTERS = freeze({});
// Every event this pack puts on the field, for the art and the sounds to answer.
export const EVENTS = freeze([
"banJump", "banLand", "banLaunch", "banDuck", "banSwitch", "banCrash", "banCheck", "banFinish",
"banButlerWarn", "banButlerLunge", "banButlerHit", "banButlerBreak", "banWebTear", "banWebShot",
]);
// The ride. Speeds are units across a second, BAN_G units a second squared.
export const BAN_V = 46;
export const BAN_MIN = 28;
export const BAN_MAX = 64;
export const SLOPE_G = 60;
export const RELAX = 1.5;
export const LEAN_ACC = 14;
export const BRAKE_ACC = 36;
export const BAN_JUMP_V = 74;
export const BAN_G = 200;
export const COYOTE_MS = 100;
export const RAMP_SLOPE = 0.25;
export const RAMP_POP = 30;
export const LAND_TOL = 0.9;
export const BIG_LAND = 8;
export const DERAIL_Y = 3;
export const CAM_AHEAD = 10;
export const CAM_PER_V = 0.25;
export const RAIL_SEP = 7;
// Obstacles.
export const VASE_W = 2.6;
export const VASE_H = 3.4;
export const CANDLE_W = 1.6;
export const CANDLE_H = 5.4;
export const SWING_BOB_W = 4.4;
export const SWING_LOW = 2.2;
export const SWING_RISE = 3;
export const BUTLER_W = 2.6;
export const BUTLER_H = 5;
export const BUTLER_HP = 2;
export const BUTLER_NEAR = 44;
export const BUTLER_WARN_MS = 500;
export const BUTLER_V = 14;
export const BUTLER_LUNGE_MS = 1400;
export const WEB_W = 3.2;
export const WEB_LO = 0.6;
export const WEB_HI = 5.6;
export const BUTLER_POINTS = 150;
export const WEB_POINTS = 50;
const SHOT_R = 0.5;
// The shots at things (butlers, webs) worth a die, and the braking a smooth slide allows.
export const ACTS_GOAL = 8;
export const STEADY_BRAKE_MS = 3000;
// Notes for a bonus round that obstacle `id` cost a heart (once each).
function noteHit(round, id) {
const b = round.bonusRound;
if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id);
}
const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H);
const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0;
// Whether line `line` is one of the brass under-rails.
export const lowerLine = (R, line) => line >= R.rails;
// The highest line under x, as [line, y], or null over a break.
const topAt = (R, x) => linesAt(R, x)[0] || null;
// The line a rider falling from `py` to `y` at `x` lands on: the highest he crossed going
// down, or, diving, the lowest line under him (he falls through a rail with another below it).
function landOn(R, x, py, y, dive) {
const under = linesAt(R, x);
for (let i = 0; i < under.length; i++) {
const [line, ly] = under[i];
if (!(py >= ly - LAND_TOL && y <= ly)) continue;
if (dive && i + 1 < under.length && under[i + 1][1] < ly - 1) continue;
return { line, y: ly };
}
return null;
}
// Where a rider in the air at (x, y) going up at vy and across at v lands, if he does not
// steer (diving, or not): { x, y, line } or null when he derails. The unit suite's measure of
// which breaks a jump clears and which rail a dive lands on.
export function flight(R, x, y, vy, v, dive = false) {
const dt = 0.004;
for (let t = 0; t < 5; t += dt) {
const py = y;
vy = Math.max(-120, vy - BAN_G * dt);
x += v * dt;
y += vy * dt;
if (vy <= 0) {
const f = landOn(R, x, py, y, dive);
if (f) return { x, y: f.y, line: f.line };
}
if (y < DERAIL_Y) return null;
}
return null;
}
// Chandelier `i` of the room at `t` ms: { x, u (-1 to 1, where it is on its arc), bottom (its
// underside) }. A pendulum: a sine, hanging lowest at the middle (u 0) and rising toward
// the ends, over the handrail directly under it.
export function swingAt(R, i, t) {
const [cx, line, amp, period, phase] = R.swings[i];
const u = Math.sin((2 * Math.PI * (t + phase)) / period);
const x = cx + amp * u;
const L = linesOf(R)[line];
return { x, u, bottom: trackY(R, line, clamp(x, L.x0, L.x1)) + SWING_LOW + SWING_RISE * u * u };
}
/* -------------------------------------------------------------- placing */
// A fresh set of the room's things, each butler waiting and each web up. What was shot stays
// shot (`old`, the state of an earlier try in the same room).
function things(R, old) {
return {
butlers: R.butlers.map(([x], i) => ({ state: old && old.butlers[i].state === "broken" ? "broken" : "wait", t: 0, x, hp: BUTLER_HP })),
webs: R.webs.map((w, i) => (old && old.webs[i] === "shot" ? "shot" : "up")),
};
}
// Put down in the room: on the handrail at the start of a ride, or at the last checkpoint
// passed after the last heart (the same room).
function place(round) {
const R = round.spec.ride;
// (The Cart's `place` runs first and has already zeroed `round.camLead`: another room's lead is not ours to touch.)
if (!R || R.runner !== "banister") {
if (round.runner && round.runner.id === "banister") round.runner = null;
return;
}
const old = round.runner && round.runner.id === "banister" && round.runner.room === round.room ? round.runner : null;
const check = old ? old.check : -1;
const you = round.you;
const x = check >= 0 ? R.checks[check] : round.spec.start;
const top = topAt(R, x);
Object.assign(you, { x, y: top ? top[1] : you.y, vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 });
round.runner = { id: "banister", room: round.room, check, v: BAN_V, line: top ? top[0] : -1, coyote: 0, from: you.y, left: top ? top[0] : 0, done: false, clock: old ? old.clock : 0, dive: false, ...things(R, old) };
round.camLead = CAM_AHEAD;
const b = round.bonusRound;
if (b && !b.perf.total) {
b.perf.total = R.props.length + R.lows.length + R.swings.length + R.butlers.length + (R.rails - 1);
b.perf.steady = true;
b.perf.goal = ACTS_GOAL;
}
}
/* ------------------------------------------------------------ the ride */
// After a derail that cost a heart but not the ride: you and the rail go back onto the line
// nearest where you fell (the highest line under you, else the next one ahead) at BAN_V.
function reseat(round, c, R) {
const you = round.you;
const under = topAt(R, you.x);
let line;
let x;
let y;
if (under) {
[line, y] = under;
x = you.x;
} else {
const ahead = linesOf(R)
.map((L, i) => ({ i, x0: L.x0 }))
.filter((L) => L.x0 > you.x && L.i < R.rails)
.sort((a, b) => a.x0 - b.x0)[0];
line = ahead ? ahead.i : R.rails - 1;
x = ahead ? ahead.x0 + 2 : R.finish - 2;
y = trackY(R, line, x) ?? you.y;
}
Object.assign(you, { x, y, vy: 0, state: "run", shelf: -1, ducking: false, coyote: 0, drop: -1 });
Object.assign(c, { line, v: BAN_V, coyote: 0, from: y });
}
// The ride for one slice. Returns true once it has moved you (every slice of a ride); false
// outside a ride and once you have stepped out onto the foyer floor.
function ride(round, ms, k) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "banister" || !c || c.id !== "banister" || c.done) return false;
const you = round.you;
const inp = round.input;
const dt = ms / 1000;
const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra });
c.clock += ms;
// Already down on the foyer floor (set there, or past the lip some other way): the ride is over.
if (you.x >= R.finish && you.vy <= 0 && you.y <= k.groundAt(round.spec, you.x) + 0.01) return finish(round, c, R, k.groundAt(round.spec, you.x), k);
// A stomp's bounce (or anything else) lifts you off the rail.
if (you.state === "air" && c.line >= 0) {
c.left = c.line;
c.line = -1;
c.coyote = 0;
c.from = you.y;
}
steerShots(round, R);
const want = inp.jump > 0;
if (c.line >= 0) {
// On the rail.
const slope = slopeOf(R, c.line, you.x);
let a = (BAN_V - c.v) * RELAX - SLOPE_G * slope;
if (inp.right) a += LEAN_ACC;
if (inp.left) a -= BRAKE_ACC;
c.v = clamp(c.v + a * dt, BAN_MIN, BAN_MAX);
// Braking is a bonus round's one thing not to do much of: too much is no smooth slide.
if (inp.left && round.bonusRound && (round.bonusRound.perf.brakeMs = (round.bonusRound.perf.brakeMs || 0) + ms) > STEADY_BRAKE_MS) round.bonusRound.perf.steady = false;
const duck = Boolean(inp.down) && !want;
if (duck && !you.ducking) ev("banDuck");
you.ducking = duck;
if (want) {
inp.jump = 0;
you.vy = BAN_JUMP_V + slope * c.v;
Object.assign(c, { left: c.line, line: -1, coyote: 0, from: you.y });
you.state = "air";
you.ducking = false;
ev("banJump", { v: c.v });
} else {
const L = linesOf(R)[c.line];
const nx = you.x + c.v * dt;
you.state = "run";
you.vy = 0;
if (nx >= L.x1) {
// Off the end of the line, on along its last slope.
const end = L.pts[L.pts.length - 1];
const rise = slopeOf(R, c.line, L.x1);
you.x = L.x1;
you.y = end[1];
const ramp = rise >= RAMP_SLOPE;
you.vy = rise * c.v + (ramp ? RAMP_POP : 0);
Object.assign(c, { left: c.line, line: -1, coyote: COYOTE_MS, from: you.y });
you.state = "air";
you.ducking = false;
if (ramp) ev("banLaunch", { v: c.v, last: c.left === R.rails - 1 });
} else {
you.x = nx;
you.y = trackY(R, c.line, nx);
}
}
} else {
// In the air.
c.coyote = Math.max(0, c.coyote - ms);
if (want && c.coyote > 0) {
inp.jump = 0;
c.coyote = 0;
you.vy = BAN_JUMP_V;
c.from = you.y;
ev("banJump", { v: c.v });
}
c.dive = Boolean(inp.down);
const py = you.y;
you.vy = Math.max(-k.FALL_MAX, you.vy - BAN_G * dt);
you.x += c.v * dt;
you.y += you.vy * dt;
you.ducking = false;
you.state = "air";
if (you.vy <= 0) {
const f = landOn(R, you.x, py, you.y, c.dive);
if (f) {
you.y = f.y;
you.vy = 0;
you.state = "run";
const was = lowerLine(R, c.left);
c.line = f.line;
ev("banLand", { big: c.from - f.y >= BIG_LAND });
if (lowerLine(R, f.line) !== was) ev("banSwitch", { lower: lowerLine(R, f.line) });
c.from = f.y;
} else if (you.x >= R.finish) {
// Over the foyer floor at the end: down onto it, and the ride is over.
const g = k.groundAt(round.spec, you.x);
if (g > -Infinity && you.y <= g + 0.01) return finish(round, c, R, g, k);
}
}
}
// A press nothing took waits a moment for a landing, then goes.
if (want && inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms);
// Past the end of the world: a break, the end of an under-rail, or the face of the foyer.
if (you.y < DERAIL_Y || k.groundAt(round.spec, you.x) > you.y + 0.5) {
if (!lowerLine(R, c.left)) noteHit(round, `g${c.left}`);
if (k.lose(round, "plunge") && round.phase === "play") reseat(round, c, R);
return true;
}
while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) {
c.check++;
ev("banCheck", { n: c.check + 1 });
}
round.camLead = CAM_AHEAD + (c.v - BAN_V) * CAM_PER_V;
if (obstacles(round, c, R, k)) return true;
creatures(round, c, R, ms);
return true;
}
// The ride is over: the banister ends, the door opens, you walk out across the foyer.
function finish(round, c, R, g, k) {
const you = round.you;
c.done = true;
c.restX = you.x;
Object.assign(you, { y: g, vy: 0, state: "run", shelf: -1, ducking: false });
round.hasKey = true;
round.camLead = 0;
round.events.push({ type: "banFinish", x: you.x, y: you.y, big: c.from - g >= BIG_LAND });
return false;
}
// A bolt flies parallel to the rail under it, whatever way you aimed (`s.off`): the stairs are
// steep, and a level bolt would sail over everything on a descent.
function steerShots(round, R) {
for (const s of round.shots) {
if (s.arm || s.free) continue;
if (s.off === undefined) s.off = s.vy;
const top = topAt(R, s.x);
if (top) s.sl = slopeOf(R, top[0], s.x);
s.vy = s.vx * (s.sl ?? 0) + s.off;
}
}
// What you run into: a prop, a hanging frame, a chandelier, a butler. Returns whether it
// cost a heart. A web only tears.
function obstacles(round, c, R, k) {
const you = round.you;
const hh = duckH(k, you);
for (const [i, [x0, x1, y]] of R.lows.entries()) {
if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > y && k.struck(round, "frame")) {
noteHit(round, `f${i}`);
round.events.push({ type: "banCrash", what: "frame", x: you.x, y: you.y + hh });
return true;
}
}
for (let i = 0; i < R.swings.length; i++) {
const [cx, , amp] = R.swings[i];
if (Math.abs(you.x - cx) > amp + SWING_BOB_W + 2) continue;
const s = swingAt(R, i, c.clock);
if (Math.abs(you.x - s.x) < (SWING_BOB_W + k.HIT_W) / 2 && you.y + hh > s.bottom && k.struck(round, "swing")) {
noteHit(round, `w${i}`);
round.events.push({ type: "banCrash", what: "swing", x: s.x, y: s.bottom });
return true;
}
}
for (const [i, [x, line, kind]] of R.props.entries()) {
if (Math.abs(you.x - x) > 6) continue;
const cause = kind ? "candle" : "vase";
if (boxHit(k, you, x, trackY(R, line, x), kind ? CANDLE_W : VASE_W, kind ? CANDLE_H : VASE_H) && k.struck(round, cause)) {
noteHit(round, `p${i}`);
round.events.push({ type: "banCrash", what: cause, x, y: you.y });
return true;
}
}
for (const [i, b] of c.butlers.entries()) {
if (b.state !== "warn" && b.state !== "lunge") continue;
if (Math.abs(you.x - b.x) > 6) continue;
const y = trackY(R, R.butlers[i][1], clamp(b.x, linesOf(R)[R.butlers[i][1]].x0, linesOf(R)[R.butlers[i][1]].x1));
if (boxHit(k, you, b.x, y, BUTLER_W, BUTLER_H) && k.struck(round, "butler")) {
noteHit(round, `b${i}`);
round.events.push({ type: "banCrash", what: "butler", x: b.x, y: you.y });
Object.assign(b, { state: "spent", t: 0 });
return true;
}
}
R.webs.forEach(([x, line], i) => {
if (c.webs[i] !== "up" || Math.abs(you.x - x) > 4) return;
const y = trackY(R, line, x);
if (y !== null && Math.abs(you.x - x) < (k.HIT_W + WEB_W) / 2 && you.y < y + WEB_HI && you.y + hh > y + WEB_LO) {
c.webs[i] = "torn";
round.events.push({ type: "banWebTear", x, y: y + 3 });
}
});
return false;
}
// The butlers wake when you come near, bow, and lunge up the rail at you.
function creatures(round, c, R, ms) {
const you = round.you;
R.butlers.forEach(([hx, line], i) => {
const b = c.butlers[i];
const L = linesOf(R)[line];
const y = () => trackY(R, line, clamp(b.x, L.x0, L.x1));
if (b.state === "wait") {
const ahead = hx - you.x;
if (ahead < BUTLER_NEAR && ahead > -BUTLER_W) {
Object.assign(b, { state: "warn", t: BUTLER_WARN_MS });
round.events.push({ type: "banButlerWarn", x: b.x, y: y() });
}
} else if (b.state === "warn") {
b.t -= ms;
if (b.t <= 0) {
Object.assign(b, { state: "lunge", t: BUTLER_LUNGE_MS });
round.events.push({ type: "banButlerLunge", x: b.x, y: y() });
}
} else if (b.state === "lunge") {
b.t -= ms;
b.x = Math.max(L.x0 + 1, b.x - BUTLER_V * (ms / 1000));
if (b.t <= 0 || b.x < you.x - 10) Object.assign(b, { state: "spent", t: 0 });
}
});
}
/* ------------------------------------------------------------- targets */
// A bolt into something to shoot: a butler on the move, a cobweb. True when one took it.
function banisterShot(round, s) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "banister" || !c || c.id !== "banister") return false;
const hit = (x, y0, w, h) => Math.abs(s.x - x) <= w / 2 + SHOT_R && s.y >= y0 - SHOT_R && s.y <= y0 + h + SHOT_R;
const score = (n) => {
round.score += n;
if (round.bonusRound) round.bonusRound.perf.acts++;
};
for (let i = 0; i < R.butlers.length; i++) {
const b = c.butlers[i];
if (b.state !== "warn" && b.state !== "lunge") continue;
const L = linesOf(R)[R.butlers[i][1]];
const y = trackY(R, R.butlers[i][1], clamp(b.x, L.x0, L.x1));
if (!hit(b.x, y, BUTLER_W, BUTLER_H)) continue;
b.hp--;
if (b.hp > 0) round.events.push({ type: "banButlerHit", x: b.x, y: y + BUTLER_H / 2 });
else {
Object.assign(b, { state: "broken", t: 0 });
score(BUTLER_POINTS);
round.events.push({ type: "banButlerBreak", x: b.x, y: y + BUTLER_H / 2, points: BUTLER_POINTS });
}
return true;
}
for (let i = 0; i < R.webs.length; i++) {
if (c.webs[i] !== "up") continue;
const [x, line] = R.webs[i];
const y = trackY(R, line, x);
if (y === null || !hit(x, y + WEB_LO, WEB_W, WEB_HI - WEB_LO)) continue;
c.webs[i] = "shot";
score(WEB_POINTS);
round.events.push({ type: "banWebShot", x, y: y + 3, points: WEB_POINTS });
return true;
}
return false;
}
export const BANISTER = freeze({
id: "banister",
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
horde: freeze({}),
ride: freeze([ride]),
place: freeze([place]),
target: banisterShot,
});
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,496 @@
// Plan2Code Web Console - Ghoul Rush's Gallows Bog stage, its rules: the monsters that haunt it (a lurker's eyes in the water, a drifting leech swarm, a will-o'-wisp whose light lures the rest toward you, and a bog body risen from the muck) and its boss, Old Mother Bog, as a stage pack that ghoul.js plugs in.
//
// No imports: ghoul.js hands every rule here a kit `k` of its own helpers
// (walk, throwBone, spawnMonster, groundAt, struck, hurt and the numbers they
// need), so this file never reaches back into it. A pack is plain data and
// functions:
//
// - `monsters`: each kind's numbers, as in ghoul.js's MONSTERS (`perch`: its
// spawn names the height it waits at; `flies`: a horde one comes in high).
// - `walkers`, `zombies`: kinds that join ghoul.js's sets of the same names
// (a bog body is a zombie in every way but how it rises).
// - `act`: what a kind starts out doing; `solid`: whether one can hurt and be
// hit just now; `swoops`: whether a kind is diving low enough to duck
// under; `unseen`: kinds out of sight just now, so shots go through and a
// touch does nothing; `harmless`: kinds that never hurt by touch (the leech
// latches instead); `move`: one slice of a kind's moving; `kill`: what a
// death leaves; `horde`: what a kind comes in from the edge with.
// - `tick`: the stage's own twist, run each slice (the wisp's lure).
// - `shot`: what a bolt that hit a monster does besides its damage (a bright
// wisp is shot out, never hit); `target`: what else a bolt can strike (a
// harpoon finds a lurker's eyes under the water).
// - `bosses`, `boss` (one slice of a boss's fight), `guard` (true while
// shots and stomps glance off), `weak` (the damage multiplier of a shot
// that has just hit), `cause` (what its touch is called) and `hazards` (by
// kind, one slice of something it left on the field).
//
// A lurker is two eyes at the waterline until you cross it: then it snaps
// out of the water, solid and lunging, and sinks back. A leech swarm drifts
// through the wet spans toward you and latches on contact, one heart and it
// drops off. A wisp is a drifting light: near it the dead pull toward you a
// step quicker (the lure), until a bolt puts it out and it rekindles
// somewhere else. A bog body rises out of the mud and walks.
//
// Old Mother Bog drifts along her planks keeping her distance, winds up and
// sends a low wave of mud down the boards to jump, or spits from her
// cauldron to where you stand, leaving a muck patch that burns. The
// cauldron opens late in her rests: a shot into her then counts triple. At
// half her hp she goes under, bubbles show where she comes back up, and she
// fights on with shorter waits and a second patch aimed ahead of your feet.
const freeze = (o) => Object.freeze(o);
export const MONSTERS = freeze({
lurker: freeze({ name: "Lurker", w: 3.4, h: 2.6, hp: 3, speed: 16, points: 150, stomp: true, head: false, color: "#2a3a18" }),
leech: freeze({ name: "Leech Swarm", w: 3, h: 1.8, hp: 2, speed: 9, points: 90, stomp: true, head: false, color: "#3d2a24" }),
wisp: freeze({ name: "Will-o'-Wisp", w: 1.6, h: 1.6, hp: 1, speed: 12, points: 70, stomp: false, head: false, perch: true, flies: true, color: "#9adfc0" }),
bogbody: freeze({ name: "Bog Body", w: 3, h: 5, hp: 4, speed: 7, lurch: 14, points: 120, stomp: true, head: true, color: "#4a3a22" }),
});
export const BOSSES = freeze({
motherbog: freeze({ name: "Old Mother Bog", sub: "Keep to the planks, she owns the water", w: 7, h: 10, hp: 95, points: 3000, color: "#5a4a2a" }),
});
// A lurker's eyes snap when you are within SNAP_RANGE across (and SNAP_HIGH
// up or down): it lunges at SNAP_V for SNAP_MS, then sinks for LURKER_SINK_MS
// back to eyes.
export const SNAP_RANGE = 9;
export const SNAP_HIGH = 5;
export const SNAP_V = 34;
export const SNAP_MS = 900;
export const LURKER_SINK_MS = 500;
// A latched leech swarm costs one heart, then it drops off for
// LEECH_DROP_MS and cannot latch again for LEECH_AGAIN_MS.
export const LEECH_DROP_MS = 350;
export const LEECH_AGAIN_MS = 1400;
// A bog body takes BOG_RISE_MS to climb out of the mud (one out of the
// horde's edge, or out of a door, is already up), then lurches like a zombie
// inside LURCH_RANGE.
export const BOG_RISE_MS = 600;
const LURCH_RANGE = 20;
// A wisp put out stays dim for WISP_RELIGHT_MS, then glows at its seeded
// spot for WISP_REKINDLE_MS before it burns bright again. While it is
// bright, every monster within WISP_LURE of it is pulled toward you and
// runs at WISP_HASTE times its speed.
export const WISP_RELIGHT_MS = 6000;
export const WISP_REKINDLE_MS = 600;
export const WISP_LURE = 10;
export const WISP_HASTE = 1.2;
const LURE_HOLD_MS = 120;
// Old Mother Bog keeps MOTHER_KEEP of plank between you, drifting at
// MOTHER_WALK. Between moves she idles MOTHER_IDLE_MS; the mud wave winds up
// MOTHER_WIND_MS and rests MOTHER_REST_MS after, its cauldron open for the
// last MOTHER_OPEN_MS; the spit winds up SPIT_WIND_MS and lands MUCK_LAND_MS
// later, a patch MUCK_W wide and MUCK_H high burning for MUCK_MS. At
// MOTHER_RAGE of her hp she sinks for MOTHER_SINK_MS, bubbles for
// BUBBLE_MS where she will surface, and rises over RESURFACE_MS near you
// (RESURFACE_NEAR or further); after it her waits are MOTHER_QUICK times as
// long and the spit also lands a patch MUCK_LEAD ahead of where you run.
export const MOTHER_KEEP = 14;
export const MOTHER_WALK = 6;
export const MOTHER_IDLE_MS = 1400;
export const MOTHER_WIND_MS = 600;
export const MOTHER_REST_MS = 1500;
export const MOTHER_OPEN_MS = 540;
export const SPIT_WIND_MS = 550;
export const MUCK_LAND_MS = 750;
export const MUCK_MS = 3000;
export const MUCK_W = 5;
export const MUCK_H = 3;
export const MUCK_LEAD = 11;
export const MOTHER_RAGE = 0.5;
export const MOTHER_QUICK = 0.7;
export const MOTHER_SINK_MS = 600;
export const BUBBLE_MS = 700;
export const RESURFACE_MS = 450;
const RESURFACE_NEAR = 14;
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
/* ------------------------------------------------------------ monsters */
// Two eyes at the waterline: unseen till you cross it, then a snap out of
// the water, solid and lunging, and a sink back to eyes.
function moveLurker(round, m, ms, k) {
const you = round.you;
const dt = ms / 1000;
if (m.act === "snap") {
m.wait = Math.max(0, m.wait - ms);
k.walk(round, m, k.towardYou(round, m), SNAP_V * round.spec.pace, dt);
if (m.wait) return;
m.act = "sink";
m.wait = LURKER_SINK_MS;
round.events.push({ type: "lurkerSink", kind: m.kind, x: m.x, y: m.y });
return;
}
if (m.act === "sink") {
m.wait = Math.max(0, m.wait - ms);
if (m.wait) return;
m.act = "eyes";
return;
}
m.dir = k.towardYou(round, m);
if (Math.abs(you.x - m.x) < SNAP_RANGE && Math.abs(you.y - m.y) < SNAP_HIGH && you.out <= 0) {
m.act = "snap";
m.wait = SNAP_MS;
round.events.push({ type: "lurkerSnap", kind: m.kind, x: m.x, y: m.y + 1, dir: m.dir });
}
}
// Drifting along its floor toward you; contact is a latch (one heart, cause
// `leeches`, then it drops off and drifts again once it can).
function moveLeech(round, m, ms, k) {
const you = round.you;
const spec = round.spec;
const dt = ms / 1000;
m.latchIn = Math.max(0, (m.latchIn || 0) - ms);
if (m.act === "drop") {
m.wait = Math.max(0, m.wait - ms);
if (m.wait) return;
m.act = "drift";
return;
}
const hitH = you.ducking ? k.DUCK_H : k.HIT_H;
const touch = Math.abs(you.x - m.x) < (k.HIT_W + m.w * 0.8) / 2 && you.y < m.y + m.h * 0.9 && you.y + hitH > m.y + m.h * 0.1;
if (touch && !(m.latchIn > 0) && you.out <= 0) {
m.act = "drop";
m.wait = LEECH_DROP_MS;
m.latchIn = LEECH_AGAIN_MS;
round.events.push({ type: "leechLatch", kind: m.kind, x: m.x, y: m.y });
k.struck(round, "leeches");
return;
}
const dir = k.towardYou(round, m);
k.walk(round, m, dir, MONSTERS.leech.speed * spec.pace, dt);
m.dir = dir;
}
// A mud-caked riser: it climbs out of the muck (harmless till up, the
// zombie rule), then shambles and lurches like one. A horde one, or one out
// of a door, is already up.
function moveBogbody(round, m, ms, k) {
const you = round.you;
if (m.act === "rise") {
if (m.horde) {
m.act = "walk";
} else {
if (!(m.rise > 0)) {
m.rise = BOG_RISE_MS;
round.events.push({ type: "bogRise", kind: m.kind, x: m.x, y: m.y });
}
m.rise = Math.max(0, m.rise - ms);
if (!m.rise) m.act = "walk";
return;
}
}
const near = Math.abs(you.x - m.x) < LURCH_RANGE && Math.abs(you.y - m.y) < 6;
k.walk(round, m, k.towardYou(round, m), (near ? MONSTERS.bogbody.lurch : MONSTERS.bogbody.speed) * round.spec.pace, ms / 1000);
m.lurching = near;
}
// A drifting light: while bright it wanders toward your chest (its dips are
// duckable), while dim it sinks and waits out its relight, and while
// rekindling it glows where it will burn again.
function moveWisp(round, m, ms, k) {
const you = round.you;
const spec = round.spec;
const dt = ms / 1000;
if (m.act === "dim") {
m.wait = Math.max(0, m.wait - ms);
const floor = k.groundAt(spec, m.x);
if (Number.isFinite(floor)) m.y = Math.max(floor + 0.6, m.y - 18 * dt);
if (m.wait) return;
if (m.relight) {
m.x = m.relight.x;
m.y = m.relight.y;
}
m.act = "rekindle";
m.wait = WISP_REKINDLE_MS;
round.events.push({ type: "wispRelight", kind: m.kind, x: m.x, y: m.y });
return;
}
if (m.act === "rekindle") {
m.wait = Math.max(0, m.wait - ms);
if (m.wait) return;
m.act = "bright";
round.events.push({ type: "wispOn", kind: m.kind, x: m.x, y: m.y });
return;
}
const speed = MONSTERS.wisp.speed * spec.pace;
const ty = you.y + k.SHOT_Y - m.h / 2;
const dx = you.x - m.x;
const dy = ty - m.y;
const d = Math.hypot(dx, dy) || 1;
m.x += (dx / d) * speed * dt;
m.y += (dy / d) * speed * dt;
m.y += Math.sin(m.t / 190 + m.id) * 4 * dt;
m.dir = Math.sign(dx) || m.dir;
m.y = Math.max(k.groundAt(spec, m.x) + 0.6, Math.min(k.CHANDELIER_Y, m.y));
}
// A bolt puts a bright wisp out (never hurt: it is light), starting its
// rekindle clock and seeding the spot it will burn again from its id.
function wispShot(round, m, s, k) {
if (m.kind !== "wisp" || m.act !== "bright") return 1;
m.act = "dim";
m.wait = WISP_RELIGHT_MS;
m.vx = 0;
m.vy = 0;
const spec = round.spec;
const rx = clamp(m.x + (((m.id * 37) % 23) - 11), 4, spec.length - 4);
m.relight = { x: rx, y: Math.min(k.CHANDELIER_Y, Math.max(k.groundAt(spec, rx) + 7, 10)) };
round.events.push({ type: "wispOut", kind: m.kind, x: m.x, y: m.y + m.h / 2 });
return 0;
}
// A dispersed swarm is told so (its voice lands with the art).
function leechDies(round, m) {
round.events.push({ type: "leechDie", kind: m.kind, x: m.x, y: m.y + m.h / 2 });
}
/* --------------------------------------------------------- the wisp lure */
// The stage's twist, run each slice: the dead inside a bright wisp's light
// are pulled toward you and run quicker, till the wisp dims or they drift
// out of it. In another stage's room it never touches `lure` or `hasteMs`:
// those fields are another pack's there (the grounds' moth call).
function bogTick(round, ms) {
if (round.stage !== "bog") return;
const wisps = [];
for (const w of round.monsters) if (!w.dead && w.kind === "wisp" && w.act === "bright") wisps.push(w);
for (const m of round.monsters) {
if (m.dead || m.kind === "wisp") continue;
let near = false;
for (const w of wisps) {
if (Math.hypot(m.x - w.x, m.y - w.y) <= WISP_LURE) {
near = true;
break;
}
}
if (near) {
if (!(m.lure > 0)) round.events.push({ type: "wispLure", kind: m.kind, x: m.x, y: m.y + m.h });
m.lure = LURE_HOLD_MS;
m.hasteMs = LURE_HOLD_MS;
m.haste = WISP_HASTE;
} else if (m.lure > 0) {
m.lure = 0;
m.hasteMs = 0;
m.haste = 1;
}
}
}
/* ------------------------------------------------------------ the hag */
const motherWait = (round, b, v) => (v * (b.raged ? MOTHER_QUICK : 1)) / round.spec.pace;
// The plank nearest `x` within reach, as { x, y }, or null over open water.
function plankAt(spec, x, k) {
for (const d of [0, 2, -2, 4, -4, 6, -6]) {
const g = k.groundAt(spec, x + d);
if (Number.isFinite(g)) return { x: x + d, y: g };
}
return null;
}
function moveMother(round, b, ms, random, k) {
const you = round.you;
const spec = round.spec;
const dt = ms / 1000;
const wait = (v) => motherWait(round, b, v);
if (!b.act) {
b.act = "idle";
b.wait = wait(MOTHER_IDLE_MS);
}
b.wait -= ms;
if (b.act !== "sink" && b.act !== "under" && b.act !== "resurface") b.dir = Math.sign(you.x - b.x) || b.dir;
// At half her hp she goes under once, and comes back up meaner.
if (!b.sank && b.hp <= b.max * MOTHER_RAGE) {
b.sank = true;
b.raged = true;
b.home = b.y;
b.act = "sink";
b.wait = MOTHER_SINK_MS;
b.hidden = true;
// Down at once: a box she slides through you with while nothing can hurt
// her is a hit you could not answer.
b.y = b.home - (b.h + 4);
round.events.push({ type: "motherSink", kind: b.kind, x: b.x, y: b.home });
return;
}
// The cauldron opens late in a rest: a shot then counts triple (see `weak`).
const open = b.act === "rest" && b.wait <= MOTHER_OPEN_MS;
if (open && !b.lit) round.events.push({ type: "cauldronOpen", kind: b.kind, x: b.x + b.dir * b.w * 0.3, y: b.y + b.h * 0.35 });
b.lit = open;
if (b.act === "idle") {
// She drifts to keep about MOTHER_KEEP of plank between her and you,
// never stepping off the boards onto open water.
const side = Math.sign(b.x - you.x) || 1;
const goal = clamp(you.x + side * MOTHER_KEEP, k.arenaMin(round, b), k.arenaMax(round, b));
if (Math.abs(goal - b.x) > 1 && k.groundAt(spec, goal) === b.y) {
const nx = b.x + Math.sign(goal - b.x) * MOTHER_WALK * spec.pace * dt;
if (k.groundAt(spec, nx) === b.y) b.x = nx;
}
if (b.wait > 0) return;
// The mud wave and the cauldron in turn.
b.attacks++;
if (b.attacks % 2) {
b.act = "wind";
b.wait = wait(MOTHER_WIND_MS);
round.events.push({ type: "motherWind", kind: b.kind, x: b.x, y: b.y + b.h * 0.6, dir: b.dir });
} else {
b.act = "throwWind";
b.wait = wait(SPIT_WIND_MS);
round.events.push({ type: "spitWind", kind: b.kind, x: b.x + b.dir * b.w * 0.3, y: b.y + b.h * 0.55, dir: b.dir });
}
return;
}
if (b.act === "wind") {
if (b.wait > 0) return;
const floor = k.groundAt(spec, b.x);
round.waves.push({ x: b.x + b.dir * (b.w / 2), y: floor, dir: b.dir, life: 6000, kind: "mudwave", cause: "mudwave" });
round.events.push({ type: "mudWave", kind: b.kind, x: b.x + b.dir * (b.w / 2), y: floor, dir: b.dir });
b.act = "rest";
b.wait = wait(MOTHER_REST_MS);
return;
}
if (b.act === "throwWind") {
if (b.wait > 0) return;
const sx = b.x + b.dir * b.w * 0.35;
const sy = b.y + b.h * 0.55;
const at = { type: "cauldronSpit", kind: b.kind, x: sx, y: sy };
const x = clamp(you.x, spec.arena + 2, spec.length - 2);
const spot = plankAt(spec, x, k);
if (spot) {
round.hazards.push({ kind: "muck", x: spot.x, y: spot.y, w: MUCK_W, h: MUCK_H, warn: MUCK_LAND_MS, live: 0, cause: "muck", sx, sy });
Object.assign(at, { tx: spot.x, ty: spot.y });
}
// Meaner: a second patch lands ahead of where you run.
if (b.raged) {
let ahead = (Math.sign(you.vx) || you.face || 1) * MUCK_LEAD;
let x2 = clamp(x + ahead, spec.arena + 2, spec.length - 2);
if (Math.abs(x2 - x) < MUCK_W) x2 = clamp(x - ahead, spec.arena + 2, spec.length - 2);
const spot2 = plankAt(spec, x2, k);
if (spot2 && (!spot || spot2.x !== spot.x)) {
round.hazards.push({ kind: "muck", x: spot2.x, y: spot2.y, w: MUCK_W, h: MUCK_H, warn: MUCK_LAND_MS, live: 0, cause: "muck", sx, sy });
Object.assign(at, { tx2: spot2.x, ty2: spot2.y });
}
}
round.events.push(at);
b.act = "idle";
b.wait = wait(MOTHER_REST_MS);
return;
}
if (b.act === "rest") {
if (b.wait > 0) return;
b.act = "idle";
b.wait = wait(MOTHER_IDLE_MS);
return;
}
if (b.act === "sink") {
if (b.wait > 0) return;
// Where she comes back up: on a plank near you, never on top of you.
const lo = spec.arena + 4 + b.w / 2;
const hi = spec.length - 4 - b.w / 2;
let spot = null;
for (const d of [RESURFACE_NEAR, -RESURFACE_NEAR, RESURFACE_NEAR * 1.7, -RESURFACE_NEAR * 1.7, RESURFACE_NEAR * 2.4, -RESURFACE_NEAR * 2.4]) {
const x = clamp(you.x + d, lo, hi);
if (Math.abs(x - you.x) >= 6 && k.groundAt(spec, x) === b.home) {
spot = x;
break;
}
}
if (spot === null) for (const d of [0, 8, -8]) {
const x = clamp(b.x + d, lo, hi);
if (Math.abs(x - you.x) >= 6 && k.groundAt(spec, x) === b.home) {
spot = x;
break;
}
}
b.sinkX = spot ?? clamp(b.x, lo, hi);
b.act = "under";
b.wait = BUBBLE_MS;
round.events.push({ type: "motherBubble", kind: b.kind, x: b.sinkX, y: b.home });
return;
}
if (b.act === "under") {
if (b.wait > 0) return;
// Up at once where the bubbles showed, touchable and hittable again.
b.x = b.sinkX;
b.y = b.home;
b.hidden = false;
b.act = "resurface";
b.wait = RESURFACE_MS;
round.events.push({ type: "motherRise", kind: b.kind, x: b.x, y: b.home });
return;
}
if (b.act === "resurface") {
if (b.wait > 0) return;
b.act = "rest";
b.wait = wait(MOTHER_REST_MS);
return;
}
}
// A muck patch: a glob in the air for `warn`, then burning for MUCK_MS
// where it came down. Returns whether it is still on the field.
function stepMuck(round, h, ms) {
if (h.warn > 0) {
h.warn = Math.max(0, h.warn - ms);
if (h.warn > 0) return true;
h.live = MUCK_MS;
round.events.push({ type: "muckLand", x: h.x, y: h.y });
return true;
}
h.live -= ms;
return h.live > 0;
}
// A harpoon is the one bolt that reaches a lurker's eyes under the water:
// every other shot goes through them (they are `unseen`).
function harpoonShot(round, s, k) {
if (s.arm !== "harpoon") return false;
for (const m of round.monsters) {
if (m.dead || m.kind !== "lurker" || !m.unseen || (s.hit || []).includes(m.id)) continue;
if (Math.abs(s.x - m.x) > m.w / 2 + 0.5 || s.y < m.y - 0.5 || s.y > m.y + m.h + 0.5) continue;
s.hit = [...(s.hit || []), m.id];
k.hurt(round, m, s.dmg || 1, "harpoon");
round.events.push({ type: "harpoonHit", kind: m.kind, x: s.x, y: s.y });
}
return false;
}
export const BOG = freeze({
id: "bog",
monsters: MONSTERS,
walkers: freeze(["lurker", "leech"]),
zombies: freeze(["bogbody"]),
stackers: freeze(["bogbody"]),
climbers: freeze(["bogbody"]),
act: freeze({ lurker: "eyes", leech: "drift", wisp: "bright", bogbody: "rise" }),
swoops: freeze({ wisp: (m) => m.act === "bright" }),
// A lurker can hurt and be hit only while it is snapping; a dim or
// rekindling wisp can do neither.
solid: freeze({
lurker: (m) => m.act === "snap",
wisp: (m) => m.act === "bright",
}),
// A lurker's eyes are never solid: a stomp or a bolt passes over them.
unseen: freeze({ lurker: (round, m) => m.act !== "snap" }),
// The swarm never hurts by touch: it latches instead (see moveLeech).
harmless: freeze({ leech: () => true }),
move: freeze({ lurker: moveLurker, leech: moveLeech, wisp: moveWisp, bogbody: moveBogbody }),
kill: freeze({ leech: leechDies }),
horde: freeze({}),
tick: freeze([bogTick]),
shot: wispShot,
target: harpoonShot,
bosses: BOSSES,
boss: freeze({ motherbog: moveMother }),
// She is gone while she is under: shots and stomps meet only water.
guard: freeze({ motherbog: (b) => Boolean(b.hidden) }),
// A shot into the open cauldron counts triple.
weak: freeze({ motherbog: (b) => (b.lit ? 3 : 1) }),
cause: freeze({ motherbog: () => "motherbog" }),
hazards: freeze({ muck: stepMuck }),
});
@@ -0,0 +1,949 @@
// Plan2Code Web Console - Ghoul Rush's Bog Runner, its drawing: a fan-boat skim down a black channel through the night swamp. A pale low moon and a few stars, drowned cypress trees that scroll by at their own speeds, mist, the black water of the channel in front and the raised mud flats behind it (joined by a mud ramp at each bank), sunken snags, cypress knees, moss veils and low limbs, the hag's charms hanging on strings, gas pockets bubbling up, the fan boat with its caged propeller and the leech swarm that boils in its wake.
//
// ghoul-draw.js plugs it in. LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are plain
// data (the voices are the room's own tones, in ghoul-sfx-bogboat.js); bogboatArt(d) takes
// ghoul-draw.js's drawing helpers (`d`) and hands back the drawing by kind, so this file never
// reaches back into it. Drawn in room units, the way ghoul-draw.js draws: y counted down from
// the field's top, so a world height `y` is drawn at `FIELD_H - y`. The still layers are only
// the sky's color: the world is drawn by `moving` (every frame, over them; no cached layers, no
// random numbers: everything comes from a hash), the lows, the bow, the mist, the signs and the
// two gauges in front of Planny by `front`. What the art reads off the rules (ghoul-bogboat.js):
//
// - the room: `spec.ride` ({ banks, snags, knees, veils, limbs, props, gas, checks, finish }),
// the flat floor in `spec.ground`.
// - `round.runner` (id "bogboat"; null in any other room): `lane`, `from`, `swMs`, `h`, `air`,
// `v`, `gap`, `panic`, `clog`, `stall`, `done`, `restX`, `check`, `props` [{ state "up" |
// "broken" }], `gas` [{ state "up" | "burst" | "spent", t }].
// - Planny: `you.x`, `you.y`, `you.vy`, `you.ducking`.
// - events leave short-lived bits in the view's `fx` (`bogboatBits`, `bogboatLand`).
import { CLOG_MAX, CLOG_WARN, GAP_MAX, GAS_BURST_MS, GAS_H, GAS_UP, GAS_W, KNEE_W, LANE_Y, LOW_Y, PANIC_ON, PROP_H, PROP_UP, SNAG_W, WAKE_CATCH, baseOf, laneNow } from "./ghoul-bogboat.js";
const freeze = (o) => Object.freeze(o);
const TAU = Math.PI * 2;
const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x));
const water = (o) => freeze({ pack: "bogboat", custom: true, noMoon: true, pit: "#010303", ...o });
export const LOOKS = freeze({
bogboat: water({ wallTop: "#04080c", wallLow: "#0d1a22", paper: "#16262e", wainscot: "#0a1216", floorTop: "#2c3a3e", floor: "#182226", floorEdge: "#060a0c", shelf: "#242c28", shelfTop: "#3c4a42", window: "#bcd6d0", decor: "plants", color: "#8aa8b4", dark: 0.5 }),
});
// How each new kind sounds, by act (the room's own tones, ghoul-sfx-bogboat.js).
export const VOICES = freeze({
bogboat: freeze({ jump: "ghoulBogboatJump", land: "ghoulBogboatLand", duck: "ghoulBogboatDuck", switch: "ghoulBogboatSwitch", crash: "ghoulBogboatCrash", check: "ghoulBogboatCheck", finish: "ghoulBogboatFinish" }),
bogboatwake: freeze({ panic: "ghoulBogboatPanic", catch: "ghoulBogboatCatch" }),
bogboatfan: freeze({ clog: "ghoulBogboatClog", stall: "ghoulBogboatStall" }),
bogboatshot: freeze({ gas: "ghoulBogboatGas", prop: "ghoulBogboatProp" }),
});
// What each of the pack's events plays: [kind, act], once.
export const EVENT_VOICE = freeze({
bogboatJump: ["bogboat", "jump"],
bogboatLand: ["bogboat", "land"],
bogboatDuck: ["bogboat", "duck"],
bogboatSwitch: ["bogboat", "switch"],
bogboatCrash: ["bogboat", "crash"],
bogboatCheck: ["bogboat", "check"],
bogboatFinish: ["bogboat", "finish"],
bogboatPanic: ["bogboatwake", "panic"],
bogboatCatch: ["bogboatwake", "catch"],
bogboatClog: ["bogboatfan", "clog"],
bogboatStall: ["bogboatfan", "stall"],
bogboatGas: ["bogboatshot", "gas"],
bogboatProp: ["bogboatshot", "prop"],
});
export const LOSE_WORDS = freeze({ snag: "Ran onto a snag", knee: "Hit the cypress knees", veil: "Tangled in moss", limb: "Ducked too late", wake: "Swarmed" });
export const LOSE_SOUNDS = freeze({
snag: ["smash", 0.6, 0.7],
knee: ["clank", 0.5, 0.6],
veil: ["squish", 0.45, 0.8],
limb: ["clank", 0.5, 0.8],
wake: ["squish", 0.5, 0.7],
});
const FW = 96;
const WATER_Y = LANE_Y[0];
const FLATS_Y = LANE_Y[1];
let FH = 54;
const MOSS = "#3a5a34";
const MOSS_D = "#223a22";
const MUD = "#3a2d1c";
const MUD_D = "#1c150c";
const MUD_LIT = "#6a5632";
const WOOD = "#3a2e1e";
const WOOD_D = "#1e160e";
const HULL = "#2e3a3a";
const HULL_LIT = "#52666a";
const RUST = "#7a3a1e";
const SWARM = "#1a1210";
const GAS = "#c8f06a";
const BONE = "#d8d0b8";
// A number in 0..1 from two integers, the same every time (no random draws).
const rnd = (a, b = 0) => {
let h = Math.imul((a | 0) + 0x9e37, 0x85ebca6b) ^ Math.imul((b | 0) + 0x7f4a, 0xc2b2ae35);
h ^= h >>> 13;
h = Math.imul(h, 0x5bd1e995);
h ^= h >>> 15;
return (h >>> 0) / 4294967296;
};
const poly = (c, pts) => {
c.beginPath();
pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y)));
c.closePath();
};
const seg = (c, x0, y0, x1, y1) => {
c.beginPath();
c.moveTo(x0, y0);
c.lineTo(x1, y1);
c.stroke();
};
const disc = (c, x, y, r) => {
c.beginPath();
c.arc(x, y, r, 0, TAU);
c.fill();
};
const grad = (make, stops) => {
const g = make ? make() : null;
if (!g || typeof g.addColorStop !== "function") return stops[stops.length >> 1][1];
for (const [o, col] of stops) g.addColorStop(o, col);
return g;
};
const vgrad = (c, y0, y1, stops) => grad(c.createLinearGradient && (() => c.createLinearGradient(0, y0, 0, y1)), stops);
const rgrad = (c, x, y, r, stops) => grad(c.createRadialGradient && (() => c.createRadialGradient(x, y, 0, x, y, r)), stops);
const Y = (y) => FH - y;
// A soft glow: a radial gradient, a flat disc where the canvas cannot do one.
function halo(ctx, x, y, r, color, alpha) {
ctx.globalAlpha = alpha;
ctx.fillStyle = rgrad(ctx, x, y, r, [[0, color], [1, "rgba(0,0,0,0)"]]);
ctx.fillRect(x - r, y - r, r * 2, r * 2);
ctx.globalAlpha = 1;
}
/* ------------------------------------------------------------- telegraphs */
// What to do about each obstacle, shown as a glyph that fades in ahead of it, for the lane the
// boat is in: JUMP (an arrow up, cyan) over snags and cypress knees, DUCK (an arrow down, amber)
// under moss veils and limbs, SHOOT (a crosshair, red) at the first gas pockets. Everything comes
// from the room's `ride` fields and where the boat is (no random numbers, no rules).
export const TELEGRAPH_SEE = 40;
export const TELEGRAPH_FULL = 30;
export const TELEGRAPH_WORDS = 3;
export const TELEGRAPH_ALPHA = 0.78;
export const SHOOT_GLYPHS = 4;
export const ANSWERS = freeze({ snag: "JUMP", knee: "JUMP", veil: "DUCK", limb: "DUCK", gas: "SHOOT" });
export const ANSWER_COLORS = freeze({ JUMP: "#5fe3ff", DUCK: "#ffb02e", SHOOT: "#ff6a6a" });
const marks = new WeakMap();
// Every obstacle that wants a glyph: { kind, lane, lead (where it begins), x (its middle), up (height of
// the glyph's anchor), n (which of its kind), answer }, in the room's order. Only the first SHOOT_GLYPHS
// gas pockets of the ride are marked: the lesson, then the player knows.
export function telegraphMarks(R) {
if (marks.has(R)) return marks.get(R);
const out = [];
const count = {};
const add = (kind, lane, lead, x, up) => {
const n = count[kind] || 0;
count[kind] = n + 1;
out.push({ kind, lane, lead, x, up: LANE_Y[lane] + up, n, answer: ANSWERS[kind] });
};
for (const [x, lane] of R.snags) add("snag", lane, x - 3, x, 7.6);
for (const [x, lane] of R.knees) add("knee", lane, x - 3.4, x, 6.2);
for (const [x0, x1, lane] of R.veils) add("veil", lane, x0 - 3.2, (x0 + x1) / 2, 7.4);
for (const [x0, x1, lane] of R.limbs) add("limb", lane, x0 - 3.2, (x0 + x1) / 2, 7.4);
for (const [x, lane] of R.gas) add("gas", lane, x - 2, x, 8);
out.sort((p, q) => p.lead - q.lead);
marks.set(R, out.filter((m) => m.kind !== "gas" || m.n < SHOOT_GLYPHS));
return marks.get(R);
}
// The glyphs showing with the boat at `x` in `lane`: { ...mark, alpha (0..1, before the pulse), words }.
export function telegraphs(R, x, lane) {
const out = [];
for (const m of telegraphMarks(R)) {
if (m.lane !== lane) continue;
const d = m.lead - x;
if (d > TELEGRAPH_SEE || d < -6) continue;
const alpha = Math.min(clamp((TELEGRAPH_SEE - d) / (TELEGRAPH_SEE - TELEGRAPH_FULL), 0, 1), clamp((d + 4) / 6, 0, 1));
if (alpha > 0.01) out.push({ ...m, alpha, words: m.n < TELEGRAPH_WORDS });
}
return out;
}
/* --------------------------------------------------------------------- art */
export function bogboatArt(d) {
const { ellipse, say, label, GOLD } = d;
const ride = (v) => (v.spec && v.spec.ride && v.spec.ride.runner === "bogboat" ? v.spec.ride : null);
const runner = (v) => (v.round && v.round.runner && v.round.runner.id === "bogboat" ? v.round.runner : null);
// The still layers get only the sky's color; `moving` draws the world.
function backdrop(ctx, v, look, x0, x1) {
ctx.fillStyle = look.wallLow;
ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H);
}
function ground() {}
function shelf() {}
/* ---------------------------------------------------------- the sky and far scenery */
function sky(ctx, v, cam) {
ctx.fillStyle = vgrad(ctx, 0, FH, [[0, "#03070a"], [0.55, "#0c1a20"], [1, "#1c3036"]]);
ctx.fillRect(cam - 1, 0, FW + 2, FH);
for (let k = 0; k < 34; k++) {
const x = cam + ((((rnd(k, 1) * FW - cam * 0.02) % FW) + FW) % FW);
ctx.globalAlpha = 0.18 + 0.4 * rnd(k, 3) * (0.7 + 0.3 * Math.sin(v.clock / 600 + k));
ctx.fillStyle = "#cfe2dc";
ctx.fillRect(x, rnd(k, 2) * 24, 0.2, 0.2);
}
ctx.globalAlpha = 1;
// The moon: low, pale green and smeared by mist, riding with the view.
const mx = cam + 68;
halo(ctx, mx, 11, 15, "rgba(170,215,200,0.5)", 0.5);
ctx.fillStyle = "#d4ece4";
disc(ctx, mx, 11, 3.8);
ctx.fillStyle = "rgba(120,160,150,0.45)";
disc(ctx, mx - 1.1, 10.4, 0.9);
disc(ctx, mx + 1, 12, 0.6);
ctx.fillStyle = "rgba(10,22,26,0.5)";
for (let k = 0; k < 3; k++) ellipse(ctx, cam + ((((rnd(k, 9) * 140 - v.clock / 110 - cam * 0.05) % 140) + 140) % 140) - 20, 9 + k * 2.6, 12 + rnd(k, 4) * 6, 0.55);
ctx.fill();
}
// Drowned cypresses at a slow parallax: a trunk, flared foot, a few bare limbs and a hanging rag of moss.
function trees(ctx, cam, par, base, scale, color, seed) {
const u0 = cam * par;
const gap = 17;
for (let slot = Math.floor((u0 - 6) / gap); slot <= Math.floor((u0 + FW + 8) / gap); slot++) {
const r = rnd(slot, seed);
if (r < 0.18) continue;
const x = cam + (slot * gap - u0) + r * 7;
const h = (9 + rnd(slot, seed + 1) * 9) * scale;
ctx.fillStyle = color;
ctx.strokeStyle = color;
poly(ctx, [[x - 1.1 * scale, base], [x - 0.35 * scale, base - h], [x + 0.35 * scale, base - h], [x + 1.1 * scale, base]]);
ctx.fill();
ctx.lineWidth = 0.3 * scale;
for (let k = 0; k < 3; k++) {
const dir = (k + slot) % 2 ? 1 : -1;
seg(ctx, x, base - h * (0.5 + k * 0.17), x + dir * (2.6 - k * 0.5) * scale, base - h * (0.6 + k * 0.17));
}
ctx.lineWidth = 0.16 * scale;
for (let k = 0; k < 3; k++) seg(ctx, x + (k - 1) * 0.9 * scale, base - h * 0.62, x + (k - 1) * 0.95 * scale, base - h * 0.62 + (2 + rnd(slot, k + 5) * 2) * scale);
}
}
// Mist: low soft bands drifting along the water.
function mist(ctx, v, cam, alpha) {
for (let k = 0; k < 5; k++) {
const x = cam + ((((rnd(k, 21) * FW * 1.4 - v.clock / (900 + k * 150) - cam * 0.1) % (FW * 1.4)) + FW * 1.4) % (FW * 1.4)) - 14;
ctx.globalAlpha = alpha * (0.6 + 0.4 * rnd(k, 22));
ctx.fillStyle = "#9cb8b0";
ellipse(ctx, x, Y(WATER_Y + 1.2 + k * 1.6), 16 + rnd(k, 23) * 8, 1.1 + k * 0.25);
ctx.fill();
}
ctx.globalAlpha = 1;
}
/* -------------------------------------------------------------- the water and the flats */
// The channel: black water with the moon's sheen sliding by and the raised mud flats behind it.
function channel(ctx, v, cam, R) {
const top = Y(WATER_Y);
ctx.fillStyle = vgrad(ctx, top, FH, [[0, "#0c1e22"], [0.25, "#061014"], [1, "#020608"]]);
ctx.fillRect(cam - 1, top, FW + 2, WATER_Y + 1);
ctx.fillStyle = "rgba(150,200,190,0.16)";
for (let k = Math.floor(cam / 3.2); k < Math.floor((cam + FW) / 3.2) + 1; k++) {
if (rnd(k, 31) < 0.4) continue;
ctx.fillRect(k * 3.2 + Math.sin(v.clock / 700 + k) * 0.6, top + 0.5 + rnd(k, 34) * 6, 0.9 + rnd(k, 35) * 1.6, 0.18);
}
// The flats: a raised terrace of mud behind the channel, gleaming, reeds along its top.
const fy = Y(FLATS_Y);
ctx.fillStyle = vgrad(ctx, fy, top, [[0, MUD_LIT], [0.1, MUD], [1, MUD_D]]);
ctx.fillRect(cam - 1, fy, FW + 2, top - fy + 0.1);
ctx.fillStyle = "rgba(180,170,120,0.22)";
for (let k = Math.floor(cam / 4); k < Math.floor((cam + FW) / 4) + 1; k++) ctx.fillRect(k * 4 + rnd(k, 41) * 2, fy + 0.5 + rnd(k, 42) * 3.4, 1.6 + rnd(k, 43), 0.2);
ctx.fillStyle = "#4a5a34";
ctx.fillRect(cam - 1, fy, FW + 2, 0.35);
ctx.strokeStyle = "#5a6a3a";
ctx.lineWidth = 0.14;
for (let k = Math.floor(cam / 2.2); k < Math.floor((cam + FW) / 2.2) + 1; k++) {
if (rnd(k, 44) < 0.4) continue;
const h = 1.4 + rnd(k, 45) * 1.6;
seg(ctx, k * 2.2, fy + 0.2, k * 2.2 + Math.sin(v.clock / 900 + k) * 0.3, fy - h);
}
ctx.fillStyle = "#14201c";
ctx.fillRect(cam - 1, top - 0.9, FW + 2, 0.9);
ctx.fillStyle = "#2c4a44";
ctx.fillRect(cam - 1, top - 0.9, FW + 2, 0.18);
// At each bank the edge is a mud ramp, with chevrons pointing up it.
for (const [a, b] of R.banks) {
if (b < cam - 4 || a > cam + FW + 4) continue;
ctx.fillStyle = "#2a2012";
poly(ctx, [[a, top], [a, fy], [b, fy]]);
ctx.fill();
ctx.strokeStyle = "#6a5632";
ctx.lineWidth = 0.35;
seg(ctx, a, top, b, fy);
ctx.strokeStyle = "rgba(200,230,170,0.55)";
ctx.lineWidth = 0.22;
for (let k = 0; k < 3; k++) {
const cx = a + 3 + k * 4.2;
const cy = top - ((cx - a) / (b - a)) * (top - fy) - 0.6;
ctx.beginPath();
ctx.moveTo(cx - 0.8, cy + 0.6);
ctx.lineTo(cx, cy);
ctx.lineTo(cx - 0.8, cy - 0.6);
ctx.stroke();
}
}
}
// A bank's posts: a leaning stake with a dim green lantern at each end of the ramp.
function bankPosts(ctx, v, a, b) {
for (const [px, lit] of [[a - 0.4, 1], [b + 0.4, 0]]) {
ctx.fillStyle = WOOD;
ctx.fillRect(px - 0.4, Y(WATER_Y + 4.4), 0.8, 4.4);
ctx.fillStyle = "#7dffa0";
ctx.globalAlpha = 0.65 + 0.25 * Math.sin(v.clock / 330 + lit);
disc(ctx, px, Y(WATER_Y + 5.1), 0.5);
ctx.globalAlpha = 1;
halo(ctx, px, Y(WATER_Y + 5.1), 4, "rgba(125,255,160,0.8)", 0.3);
}
}
/* ---------------------------------------------------------------- the things */
// A sunken snag: a rotting log lying across the lane, a broken stub up, weed on it.
function snag(ctx, x, lane, i) {
const y = Y(LANE_Y[lane]);
ctx.save();
ctx.translate(x, y);
ctx.fillStyle = "rgba(0,0,0,0.35)";
ellipse(ctx, 0, 0.05, SNAG_W * 0.9, 0.3);
ctx.fill();
ctx.fillStyle = WOOD;
poly(ctx, [[-1.7, 0], [-1.5, -1.2], [-0.4, -1.5], [0.6, -3.8], [1.3, -3.9], [1.4, -1.6], [1.8, -1.0], [1.7, 0]]);
ctx.fill();
ctx.fillStyle = WOOD_D;
ctx.fillRect(-1.7, -0.5, 3.4, 0.5);
ctx.fillStyle = "#5a4a32";
ctx.fillRect(0.7, -3.8, 0.35, 2.4);
ctx.strokeStyle = MOSS;
ctx.lineWidth = 0.14;
for (let k = 0; k < 3; k++) seg(ctx, -1.2 + k * 1.1, -1.3, -1.2 + k * 1.1 + Math.sin(i + k) * 0.4, -2.3 - rnd(i, k) * 0.6);
ctx.restore();
}
// Cypress knees: three gray cones breaking the surface, wet at the foot.
function knees(ctx, x, lane, i) {
const y = Y(LANE_Y[lane]);
ctx.save();
ctx.translate(x, y);
ctx.fillStyle = "rgba(0,0,0,0.35)";
ellipse(ctx, 0, 0.05, KNEE_W * 0.6, 0.3);
ctx.fill();
[[-1.6, 1.7, 1.2], [0, 2.4, 1.5], [1.7, 1.5, 1.1]].forEach(([dx, h, w], k) => {
ctx.fillStyle = k % 2 ? "#5a5a48" : "#4a4a3a";
poly(ctx, [[dx - w / 2, 0], [dx - w * 0.15, -h], [dx + w * 0.15, -h * 0.95], [dx + w / 2, 0]]);
ctx.fill();
ctx.fillStyle = "rgba(180,200,190,0.18)";
ctx.fillRect(dx - w / 2, -0.3, w, 0.3);
});
ctx.restore();
}
// A curtain of moss hung from a cypress limb: its underside LOW_Y over the lane.
function veil(ctx, v, x0, x1, lane, i) {
const under = Y(LANE_Y[lane]) - LOW_Y;
const tx = x1 + 3;
ctx.lineCap = "round";
ctx.strokeStyle = "#0e0a06";
ctx.lineWidth = 0.9;
ctx.beginPath();
ctx.moveTo(tx, FH + 1);
ctx.quadraticCurveTo(tx + 0.5, under + 6, tx - 0.3, under - 3);
ctx.stroke();
ctx.lineWidth = 0.7;
seg(ctx, tx - 0.2, under - 1.8, x0 - 2, under - 1.2);
ctx.lineCap = "butt";
for (let k = 0; k < 11; k++) {
const hx = x0 - 1.5 + (k * (x1 - x0 + 3)) / 10;
const len = 1.0 + rnd(i * 13 + k, 2) * 2.2;
const sway = Math.sin(v.clock / 520 + hx) * 0.35;
ctx.strokeStyle = k % 2 ? MOSS : MOSS_D;
ctx.lineWidth = 0.3;
seg(ctx, hx, under - 1.2, hx + sway, under + len);
}
}
// A low cypress limb: twisted, bare, with a few moss rags.
function limb(ctx, v, x0, x1, lane, i) {
const under = Y(LANE_Y[lane]) - LOW_Y;
const tx = x1 + 3.4;
ctx.lineCap = "round";
for (const [col, extra] of [["rgba(150,190,180,0.35)", 0.3], ["#0e0a06", 0]]) {
ctx.strokeStyle = col;
ctx.lineWidth = 0.8 + extra;
ctx.beginPath();
ctx.moveTo(tx, FH + 1);
ctx.quadraticCurveTo(tx + 0.6, under + 6, tx - 0.4, under - 2.4);
ctx.stroke();
ctx.lineWidth = 0.95 + extra;
ctx.beginPath();
ctx.moveTo(tx - 0.2, under - 1);
ctx.quadraticCurveTo(x1 - 1, under - 1.8, x0 - 2.4, under - 0.5);
ctx.stroke();
}
ctx.strokeStyle = "#0e0a06";
ctx.lineWidth = 0.4;
seg(ctx, x0 + 1.2, under - 0.8, x0 - 0.2, under + 0.6);
ctx.lineCap = "butt";
for (let k = 0; k < 4; k++) {
const hx = x0 - 1.4 + k * ((x1 - x0 + 3) / 3);
ctx.strokeStyle = k % 2 ? MOSS : MOSS_D;
ctx.lineWidth = 0.22;
seg(ctx, hx, under - 0.3, hx + Math.sin(v.clock / 480 + hx) * 0.25, under + 0.8 + rnd(i * 7 + k, 3) * 1.4);
}
}
// One of the hag's charms on a string from a bent pole: a skull (kind 0) or a blue bottle (kind 1).
function prop(ctx, v, x, lane, kind, p, i) {
const base = Y(LANE_Y[lane]);
const sway = Math.sin(v.clock / 600 + i * 1.7) * 0.45;
const top = base - PROP_UP - PROP_H - 3.2;
ctx.strokeStyle = WOOD;
ctx.lineWidth = 0.3;
seg(ctx, x + 3, base + 0.4, x + 3, top);
seg(ctx, x + 3, top, x + sway * 0.3, top - 0.4);
ctx.strokeStyle = "#8a7a5a";
ctx.lineWidth = 0.1;
seg(ctx, x + sway * 0.3, top - 0.4, x + sway, base - PROP_UP - PROP_H - 0.2);
if (p.state === "broken") return;
const cy = base - PROP_UP - PROP_H / 2;
if (kind === 0) {
ctx.fillStyle = BONE;
disc(ctx, x + sway, cy - 0.2, 1.05);
ctx.fillRect(x + sway - 0.6, cy + 0.6, 1.2, 0.8);
ctx.fillStyle = "#14100c";
ctx.fillRect(x + sway - 0.55, cy - 0.45, 0.4, 0.45);
ctx.fillRect(x + sway + 0.15, cy - 0.45, 0.4, 0.45);
} else {
ctx.fillStyle = "#4a8cc8";
poly(ctx, [[x + sway - 0.4, cy - 1.2], [x + sway + 0.4, cy - 1.2], [x + sway + 0.4, cy - 0.4], [x + sway + 1.0, cy + 0.2], [x + sway + 1.0, cy + 1.2], [x + sway - 1.0, cy + 1.2], [x + sway - 1.0, cy + 0.2], [x + sway - 0.4, cy - 0.4]]);
ctx.fill();
ctx.fillStyle = "rgba(255,255,255,0.45)";
ctx.fillRect(x + sway - 0.7, cy + 0.1, 0.25, 0.9);
}
halo(ctx, x + sway, cy, 3, "rgba(190,230,255,0.8)", 0.22);
}
// A gas pocket: a cluster of sickly bubbles rising over the lane; once shot, a cloud that spreads and thins.
function gasPocket(ctx, v, x, lane, g, i) {
const cy = Y(LANE_Y[lane] + GAS_UP + GAS_H / 2);
if (g.state === "spent") return;
if (g.state === "burst") {
const p = 1 - g.t / GAS_BURST_MS;
ctx.fillStyle = GAS;
for (let k = 0; k < 9; k++) {
ctx.globalAlpha = (1 - p) * 0.42;
disc(ctx, x + (rnd(k, 51) - 0.5) * (3 + p * 11), cy + (rnd(k, 52) - 0.6) * (2 + p * 4), 1.2 + p * 2.2);
}
ctx.globalAlpha = 1;
return;
}
halo(ctx, x, cy, 4.4, "rgba(200,240,100,0.9)", 0.3 + 0.1 * Math.sin(v.clock / 260 + i));
for (let k = 0; k < 6; k++) {
const ph = ((v.clock / 1300 + rnd(i, k + 60)) % 1);
const bx = x + (rnd(i * 5 + k, 53) - 0.5) * GAS_W * 0.8;
const by = cy + GAS_H * 0.5 - ph * GAS_H;
ctx.globalAlpha = 0.85 * Math.sin(ph * Math.PI);
ctx.strokeStyle = GAS;
ctx.lineWidth = 0.14;
ctx.beginPath();
ctx.arc(bx, by, 0.5 + rnd(i * 3 + k, 54) * 0.7, 0, TAU);
ctx.stroke();
}
ctx.globalAlpha = 1;
}
// A checkpoint: a stake across the channel with a black pennant and a gold star, lit once passed.
function checkpoint(ctx, v, x, passed) {
const top = Y(30);
ctx.fillStyle = WOOD;
ctx.fillRect(x - 0.3, top, 0.6, Y(WATER_Y) - top);
ctx.fillStyle = passed ? "#244a30" : "#10181a";
poly(ctx, [[x + 0.3, top + 0.4], [x + 6, top + 0.4 + Math.sin(v.clock / 300) * 0.3], [x + 5, top + 3.4], [x + 6, top + 6.2], [x + 0.3, top + 6.2]]);
ctx.fill();
ctx.fillStyle = passed ? "#7dffa0" : GOLD;
const sx = x + 3;
const sy = top + 3.2;
ctx.beginPath();
for (let k = 0; k < 10; k++) {
const r = k % 2 ? 0.5 : 1.3;
ctx.lineTo(sx + Math.sin((k * Math.PI) / 5) * r, sy - Math.cos((k * Math.PI) / 5) * r);
}
ctx.closePath();
ctx.fill();
halo(ctx, sx, sy, 5, passed ? "rgba(125,255,160,0.8)" : "rgba(255,210,90,0.8)", 0.3);
}
// The landing at the end of the channel: a plank pier on stilts with two lantern posts and the stilt shack's door.
function landing(ctx, v, x) {
const gy = Y(WATER_Y);
ctx.fillStyle = WOOD;
ctx.fillRect(x - 12, gy - 0.9, 28, 0.9);
ctx.fillStyle = WOOD_D;
for (let k = -3; k <= 3; k++) ctx.fillRect(x + k * 4, gy, 0.7, 4);
for (const px of [x - 6, x + 8]) {
ctx.fillStyle = WOOD;
ctx.fillRect(px - 0.4, gy - 8, 0.8, 7.1);
ctx.fillStyle = "#ffcf5a";
ctx.globalAlpha = 0.8 + 0.15 * Math.sin(v.clock / 200 + px);
disc(ctx, px, gy - 8.6, 0.7);
ctx.globalAlpha = 1;
halo(ctx, px, gy - 8.6, 6, "rgba(255,200,90,0.9)", 0.35);
}
ctx.fillStyle = "#1c150c";
ctx.fillRect(x + 1, gy - 12, 6, 11.1);
ctx.fillStyle = "#6a4a28";
ctx.fillRect(x + 2.2, gy - 9.6, 3.6, 8.7);
ctx.fillStyle = "#ffcf5a";
ctx.fillRect(x + 4.8, gy - 5, 0.5, 0.5);
poly(ctx, [[x, gy - 12], [x + 4, gy - 15.4], [x + 8, gy - 12]]);
ctx.fillStyle = "#2a2012";
ctx.fill();
}
/* ------------------------------------------------------------------ the swarm */
// The leech swarm boiling in the wake: dark blobs and flicking tails just under the surface, `gap` units
// behind the boat, thicker and higher the closer it is, red eyes once it is close.
function swarm(ctx, v, c, x, base) {
const near = clamp(1 - (c.gap - WAKE_CATCH) / (GAP_MAX - WAKE_CATCH), 0, 1);
const sx = x - c.gap;
const n = 9 + Math.round(near * 16);
const boil = c.panic ? 1 : 0.35;
ctx.fillStyle = SWARM;
for (let k = 0; k < n; k++) {
const wob = Math.sin(v.clock / (110 + k * 17) + k * 2.3);
const bx = sx + (rnd(k, 71) - 0.5) * (6 + near * 10) + wob * 0.9 * boil;
const by = base + 0.6 - Math.abs(Math.sin(v.clock / (170 + k * 23) + k)) * (0.8 + near * 2.2) * boil;
ellipse(ctx, bx, by, 1.3 + rnd(k, 72) * 1.1, 0.55 + rnd(k, 73) * 0.4);
ctx.fill();
if (c.panic && k % 3 === 0) {
ctx.fillStyle = "#ff4a3a";
ctx.fillRect(bx + 0.3, by - 0.3, 0.32, 0.32);
ctx.fillStyle = SWARM;
}
}
ctx.strokeStyle = "rgba(150,200,190,0.5)";
ctx.lineWidth = 0.14;
for (let k = 0; k < 4; k++) {
const p = (v.clock / 600 + k / 4) % 1;
ctx.globalAlpha = (1 - p) * (0.3 + near * 0.4);
ctx.beginPath();
ctx.arc(sx + (k - 1.5) * 1.8, base + 0.2, 0.6 + p * 2.2, Math.PI, TAU);
ctx.stroke();
}
ctx.globalAlpha = 1;
}
/* --------------------------------------------------------------------- the boat */
// The boat's transform: at Planny's feet (the water under it), tilted nose up on the way up, a gentle bob.
function place(ctx, v, c, fn) {
const you = v.round.you;
const x = c.done ? c.restX : you.x;
const y = c.done ? WATER_Y : you.y;
const tilt = c.air ? clamp(c.vy / 320, -0.16, 0.16) : 0;
const bob = !c.done && !c.air ? Math.sin(v.clock / 260) * 0.12 : 0;
ctx.save();
ctx.translate(x, Y(y) + bob);
ctx.rotate(-tilt);
fn(x);
ctx.restore();
}
// The back: the hull, the fan's cage on its mast with the blades turning, the spray it throws, the lantern.
function boatBack(ctx, v, c, x) {
const speed = clamp(c.v / 40, 0, 1.2);
// The spray and the wake behind the stern.
if (!c.done) {
for (let k = 0; k < 7; k++) {
const p = (v.clock / 480 + k / 7) % 1;
ctx.fillStyle = `rgba(190,225,215,${(1 - p) * 0.42 * speed})`;
disc(ctx, -9.5 - p * 8 * speed - 1, 0.1 - Math.sin(p * Math.PI) * (1 + speed * 1.4), 0.3 + p * 0.8);
}
ctx.strokeStyle = "rgba(190,225,215,0.35)";
ctx.lineWidth = 0.16;
seg(ctx, -8, 0.15, -8 - 12 * speed, 0.3);
seg(ctx, -7, 0.55, -7 - 8 * speed, 0.7);
}
ctx.fillStyle = "rgba(0,0,0,0.35)";
ellipse(ctx, -2, 0.1, 8, 0.4);
ctx.fill();
// The flat hull: a long dark tub with a rusted patch and a pale gunwale line.
ctx.fillStyle = HULL;
poly(ctx, [[-8.6, -0.1], [-8.6, -2.1], [-7.2, -2.7], [4.6, -2.7], [6.2, -1.9], [6.4, -0.1]]);
ctx.fill();
ctx.fillStyle = "#1c2626";
ctx.fillRect(-8.6, -0.7, 15, 0.7);
ctx.fillStyle = RUST;
ctx.fillRect(-3.8, -2.0, 2.1, 0.9);
ctx.fillStyle = HULL_LIT;
ctx.fillRect(-7.2, -2.8, 11.8, 0.3);
// The fan's mast and cage at the stern, the blades a flicker of spokes.
ctx.fillStyle = "#2a3030";
ctx.fillRect(-8.4, -7.4, 0.8, 4.8);
ctx.fillRect(-9.2, -2.9, 2.4, 0.5);
ctx.strokeStyle = "#7a8a86";
ctx.lineWidth = 0.14;
ctx.beginPath();
ctx.arc(-8, -6.1, 2.4, 0, TAU);
ctx.stroke();
const a = c.done || c.stall > 0 ? 0 : v.clock / 28;
ctx.lineWidth = 0.22;
for (let k = 0; k < 3; k++) seg(ctx, -8, -6.1, -8 + Math.cos(a + (k * TAU) / 3) * 2.2 * 0.3, -6.1 + Math.sin(a + (k * TAU) / 3) * 2.2);
ctx.fillStyle = "#4a5a58";
disc(ctx, -8, -6.1, 0.35);
if (c.stall > 0 && !c.done) {
ctx.fillStyle = MUD;
disc(ctx, -8, -6.1, 1.1);
ctx.fillStyle = "rgba(60,46,28,0.7)";
disc(ctx, -9.2, -4.6, 0.7);
}
// A lantern on a post at the bow, glowing.
ctx.fillStyle = "#2a3030";
ctx.fillRect(5.2, -4.8, 0.4, 2.2);
ctx.fillStyle = "#e8ffb0";
disc(ctx, 5.4, -5.1, 0.6);
halo(ctx, 5.4, -5.1, 7, "rgba(210,255,150,0.9)", 0.4);
}
// The front: the gunwale over Planny's legs and the low windshield.
function boatFront(ctx) {
ctx.fillStyle = HULL;
poly(ctx, [[-2.6, -0.4], [4.4, -0.4], [4.4, -2.1], [3.6, -2.4], [-2.6, -2.4]]);
ctx.fill();
ctx.fillStyle = HULL_LIT;
ctx.fillRect(-2.5, -2.45, 6.1, 0.22);
ctx.fillStyle = "#1c2626";
ctx.fillRect(-2.6, -0.9, 7, 0.5);
ctx.strokeStyle = "#7a8a86";
ctx.lineWidth = 0.22;
seg(ctx, 3.6, -2.4, 3.2, -4.4);
ctx.fillStyle = "rgba(150,200,210,0.2)";
poly(ctx, [[3.4, -2.5], [3.1, -4.2], [2.2, -4.2], [2.5, -2.5]]);
ctx.fill();
}
/* ----------------------------------------------------------------- mist and signs */
// A see-through glyph over an obstacle: chevrons or a crosshair, and (for the first few) the word.
function glyph(ctx, v, t) {
const col = ANSWER_COLORS[t.answer];
const pulse = 0.85 + 0.15 * Math.sin(v.clock / 260 + t.lead);
const cy = Math.min(FH - 7, FH - t.up) + Math.sin(v.clock / 260 + t.lead) * 0.35;
ctx.save();
ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA;
ctx.lineCap = "round";
ctx.lineJoin = "round";
if (t.answer === "SHOOT") {
for (const [w, c] of [[1.2, "rgba(2,8,10,0.8)"], [0.5, col]]) {
ctx.strokeStyle = c;
ctx.lineWidth = w;
ctx.beginPath();
ctx.arc(t.x, cy - 1.2, 1.5, 0, TAU);
ctx.stroke();
seg(ctx, t.x - 2.4, cy - 1.2, t.x - 0.6, cy - 1.2);
seg(ctx, t.x + 0.6, cy - 1.2, t.x + 2.4, cy - 1.2);
seg(ctx, t.x, cy - 3.6, t.x, cy - 1.8);
seg(ctx, t.x, cy - 0.6, t.x, cy + 1.2);
}
if (t.words) label(ctx, "SHOOT", t.x, cy + 2.4, 2.1, col, "center");
} else {
const up = t.answer === "JUMP";
const dir = up ? -1 : 1;
const ay = cy + (up ? -2.6 : 2.6);
for (const [w, c] of [[1.3, "rgba(2,8,10,0.8)"], [0.6, col]]) {
ctx.strokeStyle = c;
ctx.lineWidth = w;
for (let k = 0; k < 2; k++) {
const oy = ay + (k - 0.5) * 1.5 * dir - dir * 0.2;
ctx.beginPath();
ctx.moveTo(t.x - 1.7, oy - dir * 0.9);
ctx.lineTo(t.x, oy + dir * 0.9);
ctx.lineTo(t.x + 1.7, oy - dir * 0.9);
ctx.stroke();
}
}
if (t.words) label(ctx, t.answer, t.x, cy + (up ? 1.2 : -1.2), 2.3, col, "center");
}
ctx.restore();
}
// The wake meter across the top (the swarm at one end, the boat at the other, red as they close,
// THEY ARE CLOSE inside PANIC_ON) and the fan's clog gauge beside it.
function gauges(ctx, v, c, cam) {
const x = cam + 2.4;
const y = 3.2;
const W = 34;
const p = clamp((c.gap - WAKE_CATCH) / (GAP_MAX - WAKE_CATCH), 0, 1);
ctx.fillStyle = "rgba(2,8,10,0.72)";
ctx.fillRect(x - 0.6, y - 1, W + 1.2, 8.2);
ctx.fillStyle = "#16222a";
ctx.fillRect(x + 6, y + 0.2, W - 12, 1.7);
const close = c.gap < PANIC_ON;
const pulse = close ? 0.65 + 0.35 * Math.sin(v.clock / 110) : 1;
ctx.globalAlpha = pulse;
ctx.fillStyle = close ? "#ff4a3a" : p < 0.55 ? "#ffb02e" : "#7dffa0";
ctx.fillRect(x + 6, y + 0.2, (W - 12) * p, 1.7);
ctx.globalAlpha = 1;
ctx.fillStyle = SWARM;
ellipse(ctx, x + 2.4, y + 1.1, 1.6, 0.75);
ctx.fill();
if (close) {
ctx.fillStyle = "#ff4a3a";
ctx.fillRect(x + 2.9, y + 0.7, 0.3, 0.3);
}
ctx.fillStyle = HULL_LIT;
poly(ctx, [[x + W - 5, y + 1.8], [x + W - 4.4, y + 0.5], [x + W - 1.4, y + 0.5], [x + W - 0.6, y + 1.8]]);
ctx.fill();
label(ctx, close ? "THEY ARE CLOSE" : "WAKE", x + 6, y + 4, 1.5, close ? "#ff6a6a" : "#bcd6d0", "left");
// The clog gauge.
const q = c.clog / CLOG_MAX;
const hot = c.clog >= CLOG_WARN || c.stall > 0;
ctx.fillStyle = "#16222a";
ctx.fillRect(x + 6, y + 5.3, W - 12, 1.3);
ctx.globalAlpha = hot ? 0.6 + 0.4 * Math.sin(v.clock / 100) : 1;
ctx.fillStyle = hot ? "#ff5a3a" : q > 0.4 ? "#ffb02e" : "#9ac8b8";
ctx.fillRect(x + 6, y + 5.3, (W - 12) * q, 1.3);
ctx.globalAlpha = 1;
label(ctx, c.stall > 0 ? "STALLED" : "FAN", x, y + 6.6, 1.3, c.stall > 0 ? "#ff6a6a" : "#bcd6d0", "left");
}
/* ------------------------------------------------------------------- the room */
const lanePass = (ctx, v, R, c, cam, lane) => {
const lo = cam - 12;
const hi = cam + FW + 12;
R.snags.forEach(([x, l], i) => {
if (l === lane && x > lo && x < hi) snag(ctx, x, l, i);
});
R.knees.forEach(([x, l], i) => {
if (l === lane && x > lo && x < hi) knees(ctx, x, l, i);
});
R.props.forEach(([x, l, kind], i) => {
if (l === lane && x > lo && x < hi) prop(ctx, v, x, l, kind, c.props[i], i);
});
R.gas.forEach(([x, l], i) => {
if (l === lane && x > lo && x < hi) gasPocket(ctx, v, x, l, c.gas[i], i);
});
};
// The whole world, over the still layers: sky, trees, water and flats, the things by lane, the boat, the swarm.
function moving(ctx, v, cam) {
const R = ride(v);
const c = runner(v);
if (!R || !c) return;
FH = v.g.FIELD_H;
sky(ctx, v, cam);
trees(ctx, cam, 0.14, Y(FLATS_Y + 1), 0.8, "#0a161a", 3);
trees(ctx, cam, 0.3, Y(FLATS_Y + 0.6), 1.15, "#0e1e22", 7);
mist(ctx, v, cam, 0.16);
channel(ctx, v, cam, R);
R.banks.forEach(([a, b]) => {
if (b > cam - 4 && a < cam + FW + 4) bankPosts(ctx, v, a, b);
});
R.checks.forEach((x, i) => {
if (x > cam - 8 && x < cam + FW + 8) checkpoint(ctx, v, x, i <= c.check);
});
if (R.finish > cam - 20 && R.finish < cam + FW + 20) landing(ctx, v, R.finish + 16);
const here = laneNow(c);
const inWater = c.done || here === 0;
lanePass(ctx, v, R, c, cam, 1);
if (!inWater) swarm(ctx, v, c, v.round.you.x, Y(baseOf(c)));
if (!inWater) place(ctx, v, c, (x) => boatBack(ctx, v, c, x));
lanePass(ctx, v, R, c, cam, 0);
if (inWater && !c.done) swarm(ctx, v, c, v.round.you.x, Y(baseOf(c)));
if (inWater) place(ctx, v, c, (x) => boatBack(ctx, v, c, x));
// A landing's splash.
const fx = v.fx;
const land = fx && fx.bogboatLand !== undefined ? fx.clock - fx.bogboatLand.t0 : 1e9;
if (land < 380) {
const p = land / 380;
ctx.fillStyle = `rgba(170,210,200,${(1 - p) * 0.7})`;
for (let k = 0; k < 8; k++) disc(ctx, v.round.you.x + (k - 3.5) * 1.1 * (0.6 + p * 1.5), Y(baseOf(c)) - 0.3 - p * (0.8 + rnd(k, 4) * 1.4), 0.3 + p * 0.3);
}
}
// In front of Planny: the gunwale, the lows (veils and limbs), the splinters, the mist, the signs, the gauges.
function front(ctx, v) {
const R = ride(v);
const c = runner(v);
if (!R || !c) return;
FH = v.g.FIELD_H;
const round = v.round;
const cam = Math.round(round.camX * 8) / 8;
place(ctx, v, c, () => boatFront(ctx));
R.veils.forEach(([x0, x1, lane], i) => {
if (x1 >= cam - 10 && x0 <= cam + FW + 10) veil(ctx, v, x0, x1, lane, i);
});
R.limbs.forEach(([x0, x1, lane], i) => {
if (x1 >= cam - 10 && x0 <= cam + FW + 10) limb(ctx, v, x0, x1, lane, i);
});
mist(ctx, v, cam, 0.12);
if (!c.done) for (const t of telegraphs(R, round.you.x, laneNow(c))) glyph(ctx, v, t);
const bits = v.fx && v.fx.bogboatBits;
if (bits) {
for (const b of bits) {
const t = (v.fx.clock - b.t0) / 1000;
if (t < 0 || t > 0.9) continue;
ctx.save();
ctx.translate(b.x + b.vx * t, FH - (b.y + b.vy * t - 30 * t * t));
ctx.rotate(b.rot + b.vr * t);
ctx.globalAlpha = clamp(1.6 - t * 1.6, 0, 1);
ctx.fillStyle = b.c;
ctx.fillRect(-b.w / 2, -0.12, b.w, 0.24);
ctx.restore();
}
ctx.globalAlpha = 1;
}
gauges(ctx, v, c, cam);
}
const dim = () => 0;
/* -------------------------------------------------------------- lights */
function lights(v, add) {
const R = ride(v);
const c = runner(v);
if (!R || !c) return;
const round = v.round;
const you = round.you;
const lo = round.camX - 10;
const hi = round.camX + FW + 10;
// The bow lantern's pool on the water ahead and its warmth over the boat.
add(you.x + 6, you.y + 2.4, 14, 0.7);
add(you.x - 3, you.y + 3, 8, 0.4);
R.checks.forEach((x, i) => {
if (x > lo && x < hi) add(x + 3, 26, 9, i <= c.check ? 0.55 : 0.4);
});
R.banks.forEach(([a, b]) => {
if (b > lo && a < hi) {
add(a - 0.4, WATER_Y + 5, 5, 0.35);
add(b + 0.4, WATER_Y + 5, 5, 0.35);
}
});
R.gas.forEach(([x, lane], i) => {
if (x > lo && x < hi && c.gas[i].state === "up") add(x, LANE_Y[lane] + GAS_UP + 1.6, 5, 0.4);
});
if (R.finish > lo - 20 && R.finish < hi) add(R.finish + 16, 18, 14, 0.6);
}
/* -------------------------------------------------------------- events */
// A throttle on a repeating cue.
function gateOnce(fx, key, ms) {
if ((fx[key] || 0) > fx.clock) return false;
fx[key] = fx.clock + ms;
return true;
}
// Splinters of wood and weed flying out of a spot.
function splinter(fx, x, y, colors) {
fx.bogboatBits = (fx.bogboatBits || []).filter((b) => fx.clock - b.t0 < 1000);
for (let k = 0; k < 9; k++) fx.bogboatBits.push({ x, y, t0: fx.clock, vx: (rnd(k, 1) - 0.5) * 22, vy: 8 + rnd(k, 2) * 14, rot: rnd(k, 3) * TAU, vr: (rnd(k, 4) - 0.5) * 22, w: 0.5 + rnd(k, 5) * 0.9, c: colors[k % colors.length] });
}
// What the pack's events look and sound like; true when the event is its own. Each of its
// sounds plays once, from EVENT_VOICE.
function react(e, k) {
const { shake, flash, burst, float, ring, fx } = k;
const voice = EVENT_VOICE[e.type];
if (!voice) return false;
if (e.type === "bogboatDuck" && !gateOnce(fx, "bogboatDuckMs", 160)) return true;
say(k.tone, voice[0], voice[1], 0.5);
const SPRAY = "#9cc4b8";
switch (e.type) {
case "bogboatJump":
burst(e.x, e.y, SPRAY, 5, 7, 300);
break;
case "bogboatLand":
fx.bogboatLand = { t0: fx.clock, big: Boolean(e.big) };
burst(e.x, e.y, SPRAY, e.big ? 14 : 6, e.big ? 12 : 8, 360);
if (e.big) shake(180, 0.45);
break;
case "bogboatSwitch":
burst(e.x, e.y, MUD_LIT, 6, 8, 320);
float(e.x, e.y + 6, e.to ? "Flats" : "Channel", "#7dffa0", 2);
break;
case "bogboatCrash":
shake(320, 1);
flash("#b8e0d0", 200);
burst(e.x, e.y + 1, e.what === "veil" ? MOSS : "#6a5a3a", 18, 17, 520);
burst(e.x, e.y + 1, SPRAY, 8, 14, 360);
splinter(fx, e.x, e.y + 2, e.what === "veil" ? [MOSS, MOSS_D] : ["#2a1e14", "#4a3c28", "#5a5a48"]);
break;
case "bogboatCheck":
float(e.x, e.y + 5, "Checkpoint", GOLD, 2.2);
ring(e.x, e.y + 3, "#7dffa0", 1, 8, 500);
break;
case "bogboatFinish":
shake(240, 0.6);
burst(e.x, e.y, SPRAY, 14, 13, 560);
float(e.x, e.y + 6, "Made it!", GOLD, 2.6);
break;
case "bogboatPanic":
flash("#102018", 220);
float(e.x, e.y + 8, "They are close!", "#ff6a6a", 2.4);
break;
case "bogboatCatch":
shake(300, 0.9);
flash("#3a0a0a", 240);
burst(e.x - 8, e.y, SWARM, 14, 12, 460);
float(e.x, e.y + 7, "Swarmed!", "#ff6a6a", 2.4);
break;
case "bogboatClog":
float(e.x, e.y + 8, "The fan is clogging", "#ffb02e", 2.2);
break;
case "bogboatStall":
shake(200, 0.5);
burst(e.x - 8, e.y + 3, MUD, 10, 9, 420);
float(e.x, e.y + 8, "Stalled!", "#ff6a6a", 2.4);
break;
case "bogboatGas":
flash("#e8ff9a", 140);
burst(e.x, e.y, GAS, 14, 13, 520);
ring(e.x, e.y, GAS, 1, 9, 420);
float(e.x, e.y + 3, `+${e.points}`, GOLD, 2);
break;
case "bogboatProp":
burst(e.x, e.y, e.kind ? "#4a8cc8" : BONE, 12, 12, 440);
splinter(fx, e.x, e.y, e.kind ? ["#4a8cc8", "#9cd0ff"] : [BONE, "#8a7a5a"]);
float(e.x, e.y + 3, `+${e.points}`, GOLD, 2);
break;
default:
break;
}
return true;
}
return freeze({
looks: LOOKS,
backdrop,
ground,
shelf,
front,
moving,
dim,
monsters: freeze({}),
bosses: freeze({}),
missiles: freeze({}),
hazards: freeze({}),
powers: freeze({}),
lights,
react,
});
}
@@ -0,0 +1,420 @@
// Plan2Code Web Console - Ghoul Rush's Bog Runner, its rules: Gallows Bog's bonus round. YOU skim a fan boat down a black channel through the swamp at night, with something swimming in your wake: jump the sunken snags and cypress knees, duck the moss veils and low limbs, shoot the hag's charms for points and the gas pockets for a cover burst, and switch between the open channel and the mud flats at the banks, as a stage pack that ghoul.js plugs in.
//
// Modeled on the Midnight Hearse (ghoul-hearse.js: read its header first) for the lanes and
// on the Torch Mob (ghoul-wagon.js) for the pursuit meter, and, like them, handed a kit `k`
// of ghoul.js's own helpers, so this file never imports ghoul.js. Pack fields used: `ride`
// (a hook that moves Planny himself, so no key walks him), `place` (Planny put down in a
// room: a room set up or a respawn) and `target` (a bolt strikes something that is no
// monster: a charm, a gas pocket). It adds no monster, boss or hazard kind, so there is
// nothing to merge by name, and it draws NO random number. Its state is `round.runner`
// (the shared slot for a rolling bonus ride, with `id: "bogboat"`; null in any other room)
// and the room's `ride.runner` is "bogboat". Every event it puts on the field starts with
// `bogboat`.
//
// THE TWIST: THE WAKE. A swarm of leeches boils up in the fan's wake, `gap` units back
// (GAP_START at the start, never over GAP_MAX). It swims at WAKE_V, the boat at its own
// speed: clean riding on open water (BOGBOAT_V) wins ground and everything else loses it:
// DOWN held (an ease of the throttle, and a duck) holds the boat at EASE_V, the mud flats
// slow it (FLATS_V, and FLATS_EASE_V when eased), a fan stalled in the mud stops it dead,
// and a hit shoves the swarm HIT_CLOSE closer. A gas pocket shot pushes it back GAS_PUSH.
// Inside PANIC_ON the swarm boils (the art shows it and the wake meter reads THEY ARE
// CLOSE) until PANIC_OFF. At WAKE_CATCH it has you: a heart (cause "wake"), and it falls
// back to WAKE_FALLBACK.
//
// THE ROOM (spec.ride, see ghoul-rooms.js): the ground is one flat floor under the water;
// there are two LANES, the open channel (lane 0, LANE_Y[0]) and the mud flats beside it
// (lane 1, LANE_Y[1], a raised bank), and every obstacle stands in one of them, [x, lane,
// ...]:
//
// - `banks` [x0, x1]: the banks, where the channel's edge shelves down into the flats;
// inside one, LEFT puts the boat in the channel and RIGHT on the flats (SWITCH_MS to
// hop the shelf). The art draws them as mud ramps. Nothing stands in a lane near one.
// - `snags` [x, lane]: a sunken log, SNAG_W by SNAG_H: jump (cause "snag").
// - `knees` [x, lane]: a cluster of cypress knees, KNEE_W by KNEE_H: jump (cause "knee").
// - `veils` [x0, x1, lane]: a curtain of moss, its underside LOW_Y over the lane: duck
// (cause "veil").
// - `limbs` [x0, x1, lane]: a low cypress limb, its underside LOW_Y over the lane: duck
// (cause "limb").
// - `props` [x, lane, kind]: one of the hag's charms (kind 0 a skull on a string, kind 1
// a blue bottle) hung at chest height. It never hurts; shoot it (one bolt) for
// PROP_POINTS and an act.
// - `gas` [x, lane]: a pocket of marsh gas bubbling up. It never hurts; shoot it for
// GAS_POINTS, an act and a cover burst that pushes the wake back GAS_PUSH.
// - `checks` (x positions of the checkpoints), `finish` (where the ride ends: the boat
// cuts its fan and Planny steps out to the door) and `time` (the room's clock, ms).
//
// THE BOAT (`round.runner`): { id, room, check, lane (where it is bound), from (the lane
// it left), swMs (switch time left), h (height over the lane), air, vy, v, gap, panic,
// clog, stall, faced, props, gas, done, restX, ... }. It runs at the speed its lane and
// throttle ask (eased toward it at RELAX a second); UP jumps at JUMP_V against GRAVITY
// (about 13 high, 0.75 s), DOWN ducks and eases; a switch cannot be made in the air and a
// jump or a duck cannot be made in one. A bolt flies level.
//
// THE CLOG: on the flats the fan sucks mud: the `clog` gauge rises CLOG_RISE a second at
// full throttle and cools CLOG_COOL a second eased (and on the channel). At CLOG_WARN the
// art flashes it; at CLOG_MAX the fan STALLS for STALL_MS (the boat coasts to a stop and
// the wake gains), then starts again at CLOG_RESTART.
//
// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the boat
// rolls on, Planny blinking safe BONUS_SAFE_MS; the last heart gone ends the round with
// nothing, at once. Causes: "snag", "knee", "veil", "limb", "wake". The grade's
// `perf.total` is the obstacles the boat FACED (passed in their lane; a lane switched away
// from is dodged and not counted, a catch adds one of its own), each id once in
// `perf.hits` if it ever cost a heart. Shooting a charm or a gas pocket counts for
// `perf.acts` (the goal is ACTS_GOAL, 8 of them) and the points below. The steady die is a
// swarm that never boiled (the wake never reached PANIC_ON).
//
// Checkpoints are passed at their x (`bogboatCheck`); a restart after the last heart goes
// back to the last one passed (that ends the round, as the sled's does).
//
// WHAT THE ART READS: `spec.ride` (above), `round.runner` { lane, from, swMs, h, air, v,
// gap, panic, clog, stall, done, restX, check, props: [{ state "up"|"broken" }], gas: [{
// state "up"|"burst"|"spent", t }] }, `round.you` (`state`, `vy`, `ducking`), the events in
// EVENTS.
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
export const MONSTERS = freeze({});
// Every event this pack puts on the field, for the art and the sounds to answer.
export const EVENTS = freeze([
"bogboatJump", "bogboatLand", "bogboatDuck", "bogboatSwitch", "bogboatCrash", "bogboatCheck", "bogboatFinish",
"bogboatPanic", "bogboatCatch", "bogboatClog", "bogboatStall", "bogboatGas", "bogboatProp",
]);
// The boat. Speeds are units across a second, GRAVITY units a second squared.
export const BOGBOAT_V = 40;
export const EASE_V = 24;
export const FLATS_V = 28;
export const FLATS_EASE_V = 22;
export const RELAX = 5;
export const JUMP_V = 74;
export const GRAVITY = 200;
export const BIG_LAND = 9;
export const LANE_Y = freeze([9, 15]);
export const SWITCH_MS = 360;
export const SWITCH_HOP = 1.6;
export const CAM_AHEAD = 12;
// Obstacles.
export const SNAG_W = 3.2;
export const SNAG_H = 3.8;
export const KNEE_W = 4.6;
export const KNEE_H = 2.4;
export const LOW_Y = 3.0;
export const PROP_W = 2.2;
export const PROP_H = 2.4;
export const PROP_UP = 1.6;
export const GAS_W = 3.6;
export const GAS_H = 3.2;
export const GAS_UP = 1.2;
export const GAS_BURST_MS = 700;
export const PROP_POINTS = 60;
export const GAS_POINTS = 90;
const SHOT_R = 0.5;
// The wake.
export const WAKE_V = 28;
export const GAP_START = 28;
export const GAP_MAX = 36;
export const WAKE_CATCH = 8;
export const WAKE_FALLBACK = 24;
export const PANIC_ON = 18;
export const PANIC_OFF = 22;
export const HIT_CLOSE = 8;
export const GAS_PUSH = 8;
// The clog.
export const CLOG_MAX = 100;
export const CLOG_WARN = 70;
export const CLOG_RISE = 30;
export const CLOG_COOL = 40;
export const CLOG_RESTART = 35;
export const STALL_MS = 1400;
// The shots at things (charms, gas pockets) worth a die.
export const ACTS_GOAL = 8;
const mine = (round) => (round.runner && round.runner.id === "bogboat" ? round.runner : null);
const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H);
const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0;
const smooth = (p) => p * p * (3 - 2 * p);
// The lane the boat counts as being in: the one it left until half way through a switch.
export const laneNow = (c) => (c.swMs > 0 && 1 - c.swMs / SWITCH_MS < 0.5 ? c.from : c.lane);
// The height of the water under the boat (its lane's, eased across a switch, with a little hop).
export function baseOf(c) {
if (c.swMs <= 0) return LANE_Y[c.lane];
const p = 1 - c.swMs / SWITCH_MS;
return LANE_Y[c.from] + (LANE_Y[c.lane] - LANE_Y[c.from]) * smooth(p) + Math.sin(p * Math.PI) * SWITCH_HOP;
}
// Notes for a bonus round that obstacle `id` was faced (counted for the grade) and, with
// `cost`, that it cost a heart (once each).
function face(round, c, id, cost = false) {
const b = round.bonusRound;
if (!b) return;
if (!c.faced[id]) {
c.faced[id] = true;
b.perf.total++;
}
if (cost && !b.perf.hits.includes(id)) b.perf.hits.push(id);
}
/* -------------------------------------------------------------- placing */
// A fresh set of the room's things, each charm hanging and each pocket full. What was shot
// stays shot (`old`, the boat of an earlier try in the same room).
function things(R, old) {
const was = (list, i, state) => (old && old[list] && old[list][i] && old[list][i].state === state ? state : null);
return {
props: R.props.map((p, i) => ({ state: was("props", i, "broken") || "up" })),
gas: R.gas.map((g, i) => ({ state: was("gas", i, "spent") || was("gas", i, "burst") ? "spent" : "up", t: 0 })),
};
}
// Planny put down in the room: at the helm at the start of a ride, or at the last
// checkpoint passed after the last heart (the same room).
function place(round, k) {
const R = round.spec.ride;
// (The Cart's `place` runs first, leaves a ride with a `runner` alone and has already zeroed `round.camLead`.)
if (!R || R.runner !== "bogboat") {
if (mine(round)) round.runner = null;
return;
}
const old = mine(round);
const again = old && old.room === round.room;
const check = again ? old.check : -1;
const you = round.you;
const x = check >= 0 ? R.checks[check] : round.spec.start;
Object.assign(you, { x, y: LANE_Y[0], vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 });
round.runner = {
id: "bogboat", room: round.room, check, lane: 0, from: 0, swMs: 0, h: 0, vy: 0, air: false, peak: 0, v: BOGBOAT_V,
gap: GAP_START, panic: false, panicked: again ? old.panicked : false, clog: 0, warned: false, stall: 0,
faced: again ? old.faced : {}, catches: again ? old.catches : 0, done: false, restX: 0, ...things(R, again ? old : null),
};
round.camLead = CAM_AHEAD;
const b = round.bonusRound;
if (b) {
b.perf.goal = ACTS_GOAL;
if (!again) b.perf.total = 0;
if (round.runner.panicked) b.perf.steady = false;
}
}
/* ------------------------------------------------------------ the ride */
// The boat's motion for one slice. Returns true once it has moved Planny (every slice of
// a ride); false outside a ride and once he has stepped out.
function ride(round, ms, k) {
const R = round.spec.ride;
const c = mine(round);
if (!R || R.runner !== "bogboat" || !c || c.done) return false;
const you = round.you;
const inp = round.input;
const dt = ms / 1000;
const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra });
if (you.x >= R.finish) return finish(round, c, R, k);
// The throttle: the lane and DOWN set the speed it eases toward, a stalled fan none.
const ease = Boolean(inp.down) && !c.air;
const flats = c.lane === 1;
const target = c.stall > 0 ? 0 : flats ? (ease ? FLATS_EASE_V : FLATS_V) : ease ? EASE_V : BOGBOAT_V;
c.v = c.stall > 0 && c.v < 0.5 ? 0 : c.v + (target - c.v) * Math.min(1, RELAX * dt);
you.x += c.v * dt;
// The banks: LEFT is the channel, RIGHT the flats.
const want = inp.left && !inp.right ? 0 : inp.right && !inp.left ? 1 : -1;
const bank = R.banks.some(([a, b]) => you.x >= a && you.x <= b);
if (bank && !c.air && c.swMs <= 0 && want >= 0 && want !== c.lane) startSwitch(c, want, ev, you);
if (c.swMs > 0) {
c.swMs = Math.max(0, c.swMs - ms);
you.ducking = false;
you.state = "run";
you.vy = 0;
} else {
// On the water: jump, duck, or in the air.
const jump = inp.jump > 0;
if (!c.air && jump) {
inp.jump = 0;
c.air = true;
c.h = 0.001;
c.vy = JUMP_V;
c.peak = 0;
you.ducking = false;
ev("bogboatJump");
} else if (!c.air) {
const duck = Boolean(inp.down);
if (duck && !you.ducking) ev("bogboatDuck");
you.ducking = duck;
}
if (c.air) {
c.vy -= GRAVITY * dt;
c.h += c.vy * dt;
c.peak = Math.max(c.peak, c.h);
you.ducking = false;
if (c.h <= 0) {
ev("bogboatLand", { big: c.peak >= BIG_LAND });
Object.assign(c, { air: false, h: 0, vy: 0 });
}
}
you.state = c.air ? "air" : "run";
you.vy = c.air ? c.vy : 0;
}
you.y = baseOf(c) + (c.swMs > 0 ? 0 : c.h);
// A press nothing took waits a moment for a landing, then goes.
if (inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms);
while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) {
c.check++;
ev("bogboatCheck", { n: c.check + 1 });
}
round.camLead = CAM_AHEAD;
clogging(round, c, ms, ev, ease);
if (obstacles(round, c, R, k)) return true;
wake(round, c, ms, ev, k);
return true;
}
function startSwitch(c, to, ev, you) {
Object.assign(c, { from: c.lane, lane: to, swMs: SWITCH_MS, air: false, h: 0, vy: 0 });
ev("bogboatSwitch", { to, y: LANE_Y[to], x: you.x });
}
// The ride is over: the boat cuts its fan at the finish, the door opens, Planny steps out.
function finish(round, c, R, k) {
const you = round.you;
c.done = true;
c.restX = you.x;
Object.assign(c, { air: false, h: 0, vy: 0, swMs: 0 });
Object.assign(you, { y: k.groundAt(round.spec, you.x), vy: 0, state: "run", shelf: -1, ducking: false });
round.hasKey = true;
round.camLead = 0;
round.events.push({ type: "bogboatFinish", x: you.x, y: you.y });
return false;
}
// The fan on the flats: mud clogs it while it runs full, an ease or open water clears it,
// and a clogged fan stalls the boat for STALL_MS.
function clogging(round, c, ms, ev, ease) {
const dt = ms / 1000;
if (c.stall > 0) {
c.stall -= ms;
if (c.stall <= 0) Object.assign(c, { stall: 0, clog: CLOG_RESTART, warned: false });
return;
}
const flats = laneNow(c) === 1 && c.swMs <= 0;
c.clog = clamp(c.clog + (flats && !ease ? CLOG_RISE : -CLOG_COOL) * dt, 0, CLOG_MAX);
if (c.clog >= CLOG_WARN && !c.warned) {
c.warned = true;
ev("bogboatClog");
} else if (c.clog < CLOG_WARN - 15) c.warned = false;
if (c.clog >= CLOG_MAX) {
c.stall = STALL_MS;
ev("bogboatStall");
}
}
// A heart lost on obstacle `id`: it was faced and cost, the wake closes, and the crash is
// an event. Returns true.
function cost(round, c, id, what, x) {
face(round, c, id, true);
c.gap = Math.max(WAKE_CATCH + 1, c.gap - HIT_CLOSE);
round.events.push({ type: "bogboatCrash", what, x, y: round.you.y });
return true;
}
// What the boat runs into: a snag, cypress knees, a moss veil or a limb. Returns whether it
// cost a heart. (Nothing counts while it hops between lanes: the banks keep their
// neighborhood clear.)
function obstacles(round, c, R, k) {
const you = round.you;
if (c.swMs > 0) return false;
const lane = c.lane;
const base = LANE_Y[lane];
const hh = duckH(k, you);
const seen = (id, x) => {
if (you.x >= x && !c.faced[id]) face(round, c, id);
};
for (const [i, [x, l]] of R.snags.entries()) {
if (l !== lane) continue;
seen(`s${i}`, x);
if (Math.abs(you.x - x) <= 6 && boxHit(k, you, x, base, SNAG_W, SNAG_H) && k.struck(round, "snag")) return cost(round, c, `s${i}`, "snag", x);
}
for (const [i, [x, l]] of R.knees.entries()) {
if (l !== lane) continue;
seen(`k${i}`, x);
if (Math.abs(you.x - x) <= 6 && boxHit(k, you, x, base, KNEE_W, KNEE_H) && k.struck(round, "knee")) return cost(round, c, `k${i}`, "knee", x);
}
for (const [list, key, cause, what] of [[R.veils, "v", "veil", "veil"], [R.limbs, "l", "limb", "limb"]]) {
for (const [i, [x0, x1, l]] of list.entries()) {
if (l !== lane) continue;
seen(`${key}${i}`, (x0 + x1) / 2);
if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > base + LOW_Y && k.struck(round, cause)) return cost(round, c, `${key}${i}`, what, you.x);
}
}
return false;
}
// The wake: its gap, the panic, the grade's steady die, and a catch at WAKE_CATCH.
function wake(round, c, ms, ev, k) {
const dt = ms / 1000;
c.gap = clamp(c.gap + (c.v - WAKE_V) * dt, 0, GAP_MAX);
if (!c.panic && c.gap < PANIC_ON) {
c.panic = true;
c.panicked = true;
if (round.bonusRound) round.bonusRound.perf.steady = false;
ev("bogboatPanic");
} else if (c.panic && c.gap >= PANIC_OFF) c.panic = false;
for (const g of c.gas) if (g.state === "burst" && (g.t -= ms) <= 0) g.state = "spent";
if (c.gap > WAKE_CATCH) return;
c.gap = WAKE_FALLBACK;
c.panic = false;
c.catches++;
face(round, c, `w${c.catches}`, true);
ev("bogboatCatch");
k.struck(round, "wake");
}
/* ------------------------------------------------------------- targets */
// A bolt into something to shoot: a charm, a gas pocket. True when one took it (the bolt is
// spent).
function bogboatShot(round, s) {
const R = round.spec.ride;
const c = mine(round);
if (!R || R.runner !== "bogboat" || !c) return false;
const hit = (x, y0, w, h) => Math.abs(s.x - x) <= w / 2 + SHOT_R && s.y >= y0 - SHOT_R && s.y <= y0 + h + SHOT_R;
const score = (n) => {
round.score += n;
if (round.bonusRound) round.bonusRound.perf.acts++;
};
for (let i = 0; i < R.gas.length; i++) {
const g = c.gas[i];
const [x, lane] = R.gas[i];
if (g.state !== "up" || !hit(x, LANE_Y[lane] + GAS_UP, GAS_W, GAS_H)) continue;
Object.assign(g, { state: "burst", t: GAS_BURST_MS });
c.gap = Math.min(GAP_MAX, c.gap + GAS_PUSH);
score(GAS_POINTS);
round.events.push({ type: "bogboatGas", x, y: LANE_Y[lane] + GAS_UP + GAS_H / 2, points: GAS_POINTS });
return true;
}
for (let i = 0; i < R.props.length; i++) {
const p = c.props[i];
const [x, lane, kind] = R.props[i];
if (p.state !== "up" || !hit(x, LANE_Y[lane] + PROP_UP, PROP_W, PROP_H)) continue;
p.state = "broken";
score(PROP_POINTS);
round.events.push({ type: "bogboatProp", x, y: LANE_Y[lane] + PROP_UP + PROP_H / 2, kind, points: PROP_POINTS });
return true;
}
return false;
}
export const BOGBOAT = freeze({
id: "bogboat",
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
horde: freeze({}),
ride: freeze([ride]),
place: freeze([place]),
target: bogboatShot,
});
@@ -0,0 +1,31 @@
// Plan2Code Web Console - Ghoul Rush's boss intro cards, the words: per boss id, the boss's name and a one-line epithet. ghoul-bossintro-draw.js draws the card; scripts/test-web-console-activities-ghoul-bossintro.mjs makes sure every boss room has an entry.
//
// Rules (see "Boss intro screens" in prototypes/Ghoul-Rush-TODO.md):
// `name` must equal the boss's `name` in its stage pack's `bosses` table (the
// Gourd's is in BOSSES in ghoul.js); `epithet` is a short menacing tagline,
// at most MAX_EPITHET characters, US English, no em dash, never the hero's
// name (if it addresses the player at all, it is YOU). `accent` is optional:
// the color of the name and the spotlight's rim (the boss's own color by default).
// The card's backdrop uses the stage's palette from ghoul-intros.js.
export const MAX_EPITHET = 44;
const freeze = Object.freeze;
const entry = (name, epithet, accent = null) => freeze({ name, epithet, accent });
export const BOSS_INTROS = freeze({
gourd: entry("The Rotting Gourd", "Harvest time is over"),
bones: entry("Old Rattlebones", "At your service. Forever."),
angel: entry("Mother Mourning", "She has been waiting for YOU"),
keeper: entry("The Groundskeeper", "Everything gets trimmed"),
choirmaster: entry("The Choirmaster", "One more voice for the choir"),
matron: entry("The Night Matron", "Lights out, dear"),
beast: entry("The Beast of Hollow End", "The moon is full tonight"),
tommy: entry("The Tommyknocker", "Knock knock. Nobody is home"),
ringmaster: entry("The Ringmaster", "The show must go on"),
frostwidow: entry("The Frost Widow", "Cold hands, colder heart"),
motherbog: entry("Old Mother Bog", "Dinner climbed in on its own"),
});
// The card for a boss id, or null for a boss with none.
export const bossIntroFor = (id) => BOSS_INTROS[id] || null;
@@ -0,0 +1,256 @@
// Plan2Code Web Console - Ghoul Rush's boss intro card: a full-field "BOSS FIGHT" card shown when a boss room is entered, before the fight. A big title whose letters slam in one by one (red and orange glow, the whole card shaking at each landing, a heartbeat pulsing under it), the boss itself drawn from its own art at a big scale, spotlit on a dark backdrop in the stage's palette, its name big beneath it, a one-line epithet and a pulsing hint to press a key.
//
// ghoul-draw.js plugs it in, the way it plugs in ghoul-intro-draw.js:
// bossIntroArt(d) takes its drawing helpers (`d`: label, circle, BOSS_ART,
// drawGourdFire, GOLD, BONE) and hands back `(ctx, v)`, drawn over the whole
// field while `round.phase === "bossintro"` (also while paused). `round.introMs`
// is how long the card has been up (it stops with the game). The words live in
// ghoul-boss-intros.js, the colors in the stage's palette in ghoul-intros.js.
// The boss is drawn through the same fake boss the stage pick uses
// (ghoul-picker-draw.js); an art that throws or is missing falls back to a
// big dark silhouette with glowing eyes. Field units (96 by 54).
import { INTRO_MIN_MS } from "./ghoul-run.js";
import { introFor } from "./ghoul-intros.js";
import { bossIntroFor } from "./ghoul-boss-intros.js";
import { REACH } from "./ghoul-picker-draw.js";
export const BOSS_HINT = "Press any move key or fire to start the fight";
export const BOSS_TITLE = "BOSS FIGHT";
const TAU = Math.PI * 2;
const SLAM_MS = 190;
const STAGGER_MS = 95;
const START_MS = 200;
const FLOOR_Y = 38.5;
const MAX_H = 25;
const MAX_W = 40;
// How far a boss's art reaches past its box (the stage pick's table, plus the Gourd's stem and the Ringmaster's hat and puppet), and how far its picture is nudged to sit in the middle of the card.
const REACH_BY = Object.freeze({ ...REACH, gourd: 1.2, ringmaster: 1.4 });
const NUDGE = Object.freeze({ ringmaster: 14 });
const FALLBACK = Object.freeze({ a: "#ffb347", b: "#c2410c", glow: "#ff8a1f" });
const rnd = (i, salt = 0) => {
const x = Math.sin(i * 12.9898 + salt * 78.233) * 43758.5453;
return x - Math.floor(x);
};
// A color eased toward white by `amount`, so a dark boss color still reads on the dark card (anything but #rrggbb is left alone).
export function lift(color, amount = 0.35) {
const m = /^#([0-9a-f]{6})$/i.exec(color || "");
if (!m) return color;
const n = parseInt(m[1], 16);
const mix = (c) => Math.round(c + (255 - c) * amount);
return `rgb(${mix((n >> 16) & 255)}, ${mix((n >> 8) & 255)}, ${mix(n & 255)})`;
}
const clamp01 = (x) => Math.min(1, Math.max(0, x));
const dot = (ctx, x, y, r, fill) => {
ctx.beginPath();
ctx.arc(x, y, Math.max(0.05, r), 0, TAU);
ctx.fillStyle = fill;
ctx.fill();
};
// The ms at which letter `i` of the title lands.
export const landAt = (i) => START_MS + i * STAGGER_MS + SLAM_MS;
// The card's shake at `t` ms: a decaying jolt from each letter that just landed, a faint one with each heartbeat.
export function shakeAt(t) {
let amp = 0;
[...BOSS_TITLE].forEach((ch, i) => {
const dt = t - landAt(i);
if (ch !== " " && dt >= 0 && dt < 260) amp += 0.9 * (1 - dt / 260);
});
const beat = (t % 1000) / 1000;
if (t > 1200 && beat < 0.08) amp += 0.18;
return amp;
}
// The heartbeat's pulse in [0, 1]: two thumps a second apart.
export const beatAt = (t) => {
const p = (t % 1000) / 1000;
return Math.max(Math.exp(-p * 18), 0.7 * Math.exp(-Math.abs(p - 0.2) * 22));
};
export function bossIntroArt(d) {
const { label, circle, BOSS_ART, drawGourdFire, GOLD, BONE } = d;
// The boss standing on its mark, from its real art; false when the art is missing or throws.
function drawBossPicture(ctx, v, id, t, x, floorY) {
const def = v.bosses[id];
const art = BOSS_ART[id];
if (!def) return false;
const k = Math.min(MAX_H / (def.h * (REACH_BY[id] || 1)), MAX_W / def.w);
const pic = { g: { FIELD_H: 0 }, clock: 1000 + t, spec: null, groundAt: () => 0, eyes: [] };
const b = { kind: id, x: 0, y: 0, w: def.w, h: def.h, hurt: 0, dir: -1, wait: Infinity, landX: 0, windup: 0, act: "", state: "fight", t: 0, hp: 1, max: 1, lit: true };
const breathe = 1 + 0.018 * Math.sin(t / 430);
ctx.save();
ctx.translate(x, floorY);
ctx.rotate(0.012 * Math.sin(t / 1100));
ctx.scale(k * breathe, k * (1 + (breathe - 1) * 1.6));
let ok = false;
try {
if (typeof art === "function") {
art(ctx, pic, b);
if (id === "gourd" && typeof drawGourdFire === "function") drawGourdFire(ctx, pic, b);
ok = true;
}
} catch (e) {
ok = false;
}
if (ok) {
const e = pic.eyes || [];
const pulse = 0.8 + 0.2 * Math.sin(t / 160);
for (let i = 0; i + 3 < e.length; i += 4) {
ctx.fillStyle = e[i + 3];
ctx.globalAlpha = 0.22 * pulse;
circle(ctx, e[i], e[i + 1], e[i + 2] * 2.8);
ctx.fill();
ctx.globalAlpha = 1;
circle(ctx, e[i], e[i + 1], e[i + 2]);
ctx.fill();
}
} else {
// A big dark shape with two eyes, so the card never has a hole in it.
ctx.fillStyle = "#020104";
ctx.beginPath();
ctx.ellipse(0, -def.h / 2, def.w / 2, def.h / 2, 0, 0, TAU);
ctx.fill();
dot(ctx, -def.w * 0.14, -def.h * 0.64, 0.5, "#ff3b1f");
dot(ctx, def.w * 0.14, -def.h * 0.64, 0.5, "#ff3b1f");
}
ctx.restore();
return ok;
}
return function bossIntroCard(ctx, v) {
const { g, round } = v;
const id = round.spec && round.spec.boss;
const info = bossIntroFor(id);
if (!info) return;
const stage = introFor(round.stage);
const pal = (stage && stage.palette) || FALLBACK;
const def = v.bosses[id] || {};
const accent = info.accent || def.color || BONE;
const t = round.introMs || 0;
const W = g.FIELD_W;
const H = g.FIELD_H;
const fade = Math.min(1, t / 260);
const beat = beatAt(t);
const amp = shakeAt(t);
const n = Math.floor(t / 45);
ctx.save();
ctx.translate((rnd(n, 1) - 0.5) * amp, (rnd(n, 2) - 0.5) * amp);
ctx.globalAlpha = fade;
ctx.fillStyle = "#050308";
ctx.fillRect(-2, -2, W + 4, H + 4);
// The stage's color rising from the floor, a red wash that thumps with the heart.
for (let i = 0; i < 6; i++) {
ctx.globalAlpha = fade * (0.05 + 0.018 * (5 - i));
ctx.fillStyle = pal.b;
ctx.fillRect(-2, H - (i + 1) * (H / 6), W + 4, H / 6);
}
ctx.globalAlpha = fade * (0.06 + 0.1 * beat);
ctx.fillStyle = "#b0120a";
ctx.fillRect(-2, -2, W + 4, H + 4);
// The spotlight: a cone from above and a pool of light on the floor.
const cx = W / 2;
ctx.globalAlpha = fade * (0.12 + 0.03 * Math.sin(t / 700) + 0.03 * beat);
ctx.fillStyle = pal.glow;
ctx.beginPath();
ctx.moveTo(cx - 4, 12);
ctx.lineTo(cx + 4, 12);
ctx.lineTo(cx + 22, FLOOR_Y + 1);
ctx.lineTo(cx - 22, FLOOR_Y + 1);
ctx.fill();
ctx.globalAlpha = fade * 0.18;
ctx.beginPath();
ctx.ellipse(cx, FLOOR_Y, 24, 3.2, 0, 0, TAU);
ctx.fill();
ctx.globalAlpha = fade * 0.3;
ctx.beginPath();
ctx.ellipse(cx, FLOOR_Y, 15, 1.9, 0, 0, TAU);
ctx.fill();
// The floor, dark.
ctx.globalAlpha = fade;
ctx.fillStyle = "#08050b";
ctx.fillRect(-2, FLOOR_Y + 0.4, W + 4, H - FLOOR_Y);
ctx.fillStyle = pal.b;
ctx.globalAlpha = fade * 0.5;
ctx.fillRect(-2, FLOOR_Y + 0.2, W + 4, 0.35);
// Embers drifting up.
for (let i = 0; i < 26; i++) {
const p = (t / 4200 + rnd(i)) % 1;
ctx.globalAlpha = fade * (1 - p) * 0.8;
dot(ctx, rnd(i, 1) * W + Math.sin(t / 700 + i) * 1.6, FLOOR_Y + 3 - p * (FLOOR_Y + 3), 0.18 + rnd(i, 2) * 0.22, i % 3 ? "#ff7a1a" : "#ffd27a");
}
// The boss steps out of the dark.
const rise = clamp01((t - 500) / 900);
ctx.globalAlpha = fade * rise;
drawBossPicture(ctx, v, id, t, cx + (NUDGE[id] || 0), FLOOR_Y);
// The spotlight's glare over it, so it stands lit, not just in front of a light.
ctx.globalCompositeOperation = "lighter";
ctx.fillStyle = pal.glow;
for (const s of [1, 0.78, 0.56]) {
ctx.globalAlpha = fade * rise * (0.035 + 0.01 * beat);
ctx.beginPath();
ctx.ellipse(cx, FLOOR_Y - 12, 17 * s, 17 * s, 0, 0, TAU);
ctx.fill();
}
ctx.globalCompositeOperation = "source-over";
ctx.globalAlpha = fade;
// The title, one letter at a time, each slamming down from big and white-hot.
const chars = [...BOSS_TITLE];
const em = chars.reduce((s, ch) => s + (ch === " " ? 0.4 : 0.68), 0);
const size = Math.min(10, 86 / em);
let x = cx - (em * size) / 2;
chars.forEach((ch, i) => {
const w = (ch === " " ? 0.4 : 0.68) * size;
const lx = x + w / 2;
x += w;
if (ch === " ") return;
const at = t - START_MS - i * STAGGER_MS;
if (at <= 0) return;
const p = clamp01(at / SLAM_MS);
const sc = 1 + 2.2 * (1 - p) * (1 - p);
const landed = p >= 1;
const ly = 7.2 + (landed ? 0 : -(1 - p) * 2);
ctx.globalAlpha = fade * (0.35 + 0.65 * p);
if (landed) {
ctx.globalAlpha = fade * (0.3 + 0.2 * Math.sin(t / 220 - i * 0.7) + 0.2 * beat);
label(ctx, ch, lx, ly, size * 1.16, "#ff6a00", "center");
ctx.globalAlpha = fade;
}
label(ctx, ch, lx + 0.35, ly + 0.55, size * sc, "rgba(0, 0, 0, 0.7)", "center");
label(ctx, ch, lx, ly, size * sc, i % 2 ? "#ff3b1f" : "#ff7a1a", "center");
if (landed) {
// A white-hot flash as it lands.
const dt = at - SLAM_MS;
if (dt < 120) {
ctx.globalAlpha = fade * (1 - dt / 120) * 0.9;
label(ctx, ch, lx, ly, size, "#ffffff", "center");
}
ctx.globalAlpha = fade;
}
});
// The name, big, then the epithet.
const nameP = clamp01((t - 1300) / 450);
ctx.globalAlpha = fade * nameP;
const nameSize = Math.min(5, 84 / (info.name.length * 0.62));
label(ctx, info.name.toUpperCase(), cx, 43.3 + (1 - nameP) * 1.4, nameSize * 1.06, "rgba(0, 0, 0, 0.8)", "center", W - 6, true);
label(ctx, info.name.toUpperCase(), cx, 43.1 + (1 - nameP) * 1.4, nameSize, lift(accent), "center", W - 6, true);
const epP = clamp01((t - 1750) / 450);
ctx.globalAlpha = fade * epP;
label(ctx, info.epithet, cx, 47.6 + (1 - epP) * 1.0, 2.3, BONE, "center", W - 8, true);
// The hint, pulsing once a key is let through (the card waits for it as long as YOU like).
if (t >= INTRO_MIN_MS) {
ctx.globalAlpha = fade * (0.8 + 0.2 * Math.sin(t / 260));
label(ctx, BOSS_HINT, cx, 51.6, 1.9, pal.glow || GOLD, "center", W - 6);
}
// A frame that flushes red with each beat.
ctx.globalAlpha = fade * (0.55 + 0.45 * beat);
ctx.strokeStyle = "#ff4a1c";
ctx.lineWidth = 0.45;
ctx.strokeRect(1.2, 1.2, W - 2.4, H - 2.4);
ctx.restore();
ctx.globalAlpha = 1;
};
}
@@ -228,7 +228,7 @@ const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2
function place(round, k) {
const R = round.spec.ride;
round.camLead = 0;
if (!R || R.gallery || R.sled) {
if (!R || R.gallery || R.sled || R.runner) {
round.cart = null;
return;
}
@@ -11,7 +11,7 @@
// face the way they look, y counted up from the feet. Each function says
// what it draws and what in the rules (ghoul-chapel.js) it follows.
import { CENSER_WIND_MS, CUE_MS, GAPS, HASTE_RANGE, PIPE_AT, PIPE_H, PIPE_W, ROW_GAP, SMOKE_MS } from "./ghoul-chapel.js";
import { CENSER_WIND_MS, CUE_MS, GAPS, HASTE_RANGE, PIPE_AT, PIPE_DROP_MS, PIPE_H, PIPE_W, ROW_GAP, SMOKE_MS } from "./ghoul-chapel.js";
const freeze = (o) => Object.freeze(o);
const TAU = Math.PI * 2;
@@ -76,6 +76,8 @@ const PIPE_DULL_LIT = "#a39d8c";
const PIPE_DARK = "#2e2b24";
const PIPE_LIT = "#f2d878";
const NOTE_COLOR = "#f4ead0";
const NOTE_FAST = "#ff9a6a";
const NOTE_SLOW = "#9fd0ff";
const INK = "#0e0a14";
const HOLY = "#9fd8ff";
const GHOSTLY = "#c9d6f2";
@@ -1927,14 +1929,17 @@ export function chapelArt(d) {
}
// A note of the Choirmaster's, a big black eighth note edged in light so it
// reads on any wall, a short tail of staff behind it; and, once per column,
// a gold bracket on the staff where the column has its gap.
// reads on any wall, a tail of staff behind it; and, once per column, a gold
// bracket on the staff where the column has its gap. A fast column has a hot
// edge and a long tail, a slow one a cold edge and a short tail.
function note(ctx, v, h) {
const cx = h.x;
const cy = v.g.FIELD_H - h.y - h.h / 2;
ctx.strokeStyle = rgba("#f0c860", 0.28);
const pace = h.pace ?? 1;
const edge = pace > 1.2 ? NOTE_FAST : pace < 0.9 ? NOTE_SLOW : NOTE_COLOR;
ctx.strokeStyle = rgba(pace > 1.2 ? NOTE_FAST : "#f0c860", 0.28);
ctx.lineWidth = 0.16;
line(ctx, cx + 0.4, cy, cx + 9, cy);
line(ctx, cx + 0.4, cy, cx + 0.4 + 8.6 * pace, cy);
const mates = v.round.hazards.filter((o) => o.kind === "note" && Math.abs(o.x - h.x) < 0.2);
const first = mates.reduce((lo, o) => (o.row < lo.row ? o : lo), mates[0]);
if (first === h) {
@@ -1958,24 +1963,36 @@ export function chapelArt(d) {
}
}
// The note: a pale edge, then the black.
for (const [c, s] of [[NOTE_COLOR, 1.38], [INK, 1.2]]) noteGlyph(ctx, cx, cy + 0.5, s, c);
for (const [c, s] of [[edge, 1.38], [INK, 1.2]]) noteGlyph(ctx, cx, cy + 0.5, s, c);
ctx.fillStyle = "rgba(255, 255, 255, 0.35)";
ellipse(ctx, cx - 0.2, cy + 0.3, 0.3, 0.14, -0.45);
ctx.fill();
eye(v, cx + 0.4, cy - 0.6, 0.16, "#ffe9a0");
}
// A fresh pipe falling from over the field onto the dead one it replaces,
// gathering speed as it comes.
function fallingPipe(ctx, v, p) {
pipe(ctx, v, p, false, false);
const fallen = 1 - Math.min(1, p.dropMs / PIPE_DROP_MS);
ctx.save();
ctx.translate(0, -v.g.FIELD_H * (1 - fallen * fallen));
pipe(ctx, v, p, true, false);
ctx.restore();
}
/* -------------------------------------------------------- Choirmaster */
// One organ pipe standing on the floor at `p.x`, tall and brass. Sounding
// it shakes, glows, breathes puffs and sound from its mouth and sends notes
// up, with an hp sign hung over it once it has been hit; silenced it is
// dark, dented and cracked, its top bent, its mouth sooty and cold.
function pipe(ctx, v, p, on, hurt) {
// dark, dented and cracked, its top bent, its mouth sooty and cold, and it
// rattles (`stir`) when the next column will bring the pipes back.
function pipe(ctx, v, p, on, hurt, stir) {
const w = p.w;
const t = v.clock;
const fy = v.g.FIELD_H - p.y;
const x = p.x + (on ? Math.sin(t / 15 + p.i * 2) * 0.09 : 0);
const x = p.x + (on ? Math.sin(t / 15 + p.i * 2) * 0.09 : stir ? Math.sin(t / 22 + p.i * 2) * 0.22 : 0);
const top = fy - p.h;
const mouth = fy - 1.9 - (p.h - 1.9) * 0.2;
const was = ctx.globalAlpha;
@@ -2117,7 +2134,10 @@ export function chapelArt(d) {
const was = ctx.globalAlpha;
if (v.spec) {
const pipes = b.pipes || PIPE_AT.map((dx, i) => ({ i, x: v.spec.arena + dx, y: b.y, w: PIPE_W, h: PIPE_H[i], hp: 1, max: 1, on: true, hurt: 0 }));
for (const p of pipes) pipe(ctx, v, p, p.on, p.hurt > 0);
for (const p of pipes) {
if (p.dropMs > 0) fallingPipe(ctx, v, p);
else pipe(ctx, v, p, p.on, p.hurt > 0, b.quiet === 1);
}
}
const sounding = Boolean(v.spec) && (!b.pipes || b.pipes.some((p) => p.on));
const open = Boolean(v.spec) && Boolean(b.pipes) && !sounding;
@@ -2396,7 +2416,7 @@ export function chapelArt(d) {
if (b && b.kind === "choirmaster" && b.state !== "down") {
add(b.x, b.y + b.h * 0.55, 8, 0.45);
if (b.act === "cue") add(b.x - 2, b.y + b.h + 1, 7, 0.7);
if (b.pipes) for (const p of b.pipes) if (p.on) add(p.x, p.y + p.h * 0.6, 6.5, 0.5);
if (b.pipes) for (const p of b.pipes) if (p.on && !(p.dropMs > 0)) add(p.x, p.y + p.h * 0.6, 6.5, 0.5);
}
}
@@ -2461,7 +2481,11 @@ export function chapelArt(d) {
} else if (e.type === "pipeSound") {
say(tone, e.kind, "pipeSound", 0.5);
glow(e.x, e.y, 8, 0.6, 400);
burst(e.x, 6, PIPE_DULL, 10, 12, 350);
shake(160, 0.5);
float(e.x, e.y + 6, "It sounds again!", DANGER, 2.2);
} else if (e.type === "pipesStir") {
float(e.x, e.y + 6, "The pipes stir!", DANGER, 2.4);
} else if (e.type === "choirOpen") {
say(tone, e.kind, "open", 0.6);
flash("#bfe8ff", 300);
@@ -2470,7 +2494,7 @@ export function chapelArt(d) {
say(tone, e.kind, "rage", 0.8);
flash("#c0303a", 400);
shake(400, 0.8);
k.banner("The hymn quickens", "The pipes will sound again", "#e86a78", 1600);
k.banner("The hymn quickens", "Faster notes, closer together", "#e86a78", 1600);
} else if (e.type === "notesCue") {
say(tone, e.kind, "cue", 0.45);
glow(e.x, e.y, 5, 0.6, CUE_MS);
@@ -49,9 +49,13 @@
// columns of notes (`note` hazards) that fly along the room at the heights of
// the lines of a staff, each column missing one note: be at the gap's height
// when it passes (the floor for the lowest gap, a board for each higher one).
// He raises his baton first (`cue`). At half his hp (`rage`) silenced pipes
// sound again one at a time, the notes come faster and now and then two
// columns come close together.
// He raises his baton first (`cue`). Each column flies at a speed of its own,
// some far faster than others, and never so fast that it catches the column
// ahead (you always get time between two gaps). Once all four pipes are silent
// he is open for PIPES_BACK columns, then fresh pipes drop in from the roof at
// full hp and he is guarded until you silence them again. At half his hp
// (`rage`) the notes come faster and now and then two columns come close
// together.
const freeze = (o) => Object.freeze(o);
@@ -118,10 +122,15 @@ export const HOLY_GHOSTS = freeze(["ghost", "chorister", "wraith"]);
// tall, each PIPE_HP of hp; a sounding one spews a ghost every PIPE_SPEW_MS or
// so. His columns are made of notes NOTE across at the heights ROWS over the
// floor (a staff's five lines, ROW_GAP apart), one of the first GAPS rows
// missing; one flies NOTE_V a second (NOTE_V_RAGE at half hp), a column every
// COLUMN_MS (COLUMN_RAGE_MS), his baton up CUE_MS first. At half his hp
// (RAGE) a silenced pipe sounds again every RESOUND_MS, and PAIR_CHANCE of the
// columns have a second PAIR_MS behind, its gap next to the first's.
// missing; a column flies at NOTE_V a second (NOTE_V_RAGE at half hp) times one
// of NOTE_PACE, drawn afresh for each column, but slowed if it would reach the
// arena's far end less than NOTE_SEP_MS behind the column ahead. A column comes
// every COLUMN_MS (COLUMN_RAGE_MS), his baton up CUE_MS first. At half his hp
// (RAGE) PAIR_CHANCE of the columns have a second PAIR_MS behind, as fast as
// the first, its gap next to the first's. With every pipe silent, the
// PIPES_BACK'th column (a pair is one) brings them all back: each falls for
// PIPE_DROP_MS, PIPE_DROP_STAGGER_MS after the one before, and cannot be shot
// until it lands.
export const BOSSES = freeze({
choirmaster: freeze({ name: "The Choirmaster", sub: "Silence the pipes one by one", w: 8, h: 17, hp: 100, points: 3500, color: "#d8b0b8" }),
});
@@ -140,6 +149,8 @@ export const ROWS = freeze([0, 1, 2, 3, 4].map((i) => ROW_0 + i * ROW_GAP));
export const GAPS = 4;
export const NOTE_V = 22;
export const NOTE_V_RAGE = 28;
export const NOTE_PACE = freeze([0.55, 0.8, 1, 1.35, 1.75]);
export const NOTE_SEP_MS = 1500;
export const IDLE_MS = 1400;
export const CUE_MS = 700;
export const COLUMN_MS = 3200;
@@ -147,7 +158,9 @@ export const COLUMN_RAGE_MS = 2300;
export const PAIR_MS = 1100;
export const PAIR_CHANCE = 0.4;
export const RAGE = 0.5;
export const RESOUND_MS = 6000;
export const PIPES_BACK = 4;
export const PIPE_DROP_MS = 600;
export const PIPE_DROP_STAGGER_MS = 150;
const SHOT_R = 0.5;
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
@@ -398,7 +411,7 @@ function pipeShot(round, s, k) {
const b = round.boss;
if (!b || b.kind !== "choirmaster" || b.state !== "fight" || !b.pipes) return false;
for (const p of b.pipes) {
if (!p.on || Math.abs(s.x - p.x) > p.w / 2 + SHOT_R || s.y < p.y - SHOT_R || s.y > p.y + p.h) continue;
if (!p.on || p.dropMs > 0 || Math.abs(s.x - p.x) > p.w / 2 + SHOT_R || s.y < p.y - SHOT_R || s.y > p.y + p.h) continue;
// A thrown weapon strikes harder than a bolt (ghoul-arms.js).
p.hp = Math.max(0, p.hp - (s.pipeDmg || 1));
p.hurt = 120;
@@ -413,15 +426,46 @@ function pipeShot(round, s, k) {
return false;
}
// Where a note leaves the field, past the arena's far end.
const noteEnd = (round) => round.spec.arena - 6;
// The speed of a new column from `x`: drawn from NOTE_PACE, then held down so
// it reaches the arena's far end NOTE_SEP_MS or more behind the last column
// still flying. It starts behind that column, so it is that far behind or
// further at every spot on the way.
function columnSpeed(round, base, x, random) {
const v = base * NOTE_PACE[Math.floor(random() * NOTE_PACE.length) % NOTE_PACE.length];
const end = noteEnd(round);
let ahead = 0;
for (const h of round.hazards) if (h.kind === "note" && h.v > 0) ahead = Math.max(ahead, (h.x - end) / h.v);
return Math.min(v, (x - end) / (ahead + NOTE_SEP_MS / 1000));
}
// A column of notes at the staff over the floor under him, row `gap` left out.
function launch(round, b, gap, k, pair) {
// A pair's second column keeps the first's speed, and with it the gap between.
function launch(round, b, gap, k, pair, random) {
const base = k.groundAt(round.spec, b.x);
const x = b.x - b.w / 2 - 1;
const v = (rage(b) ? NOTE_V_RAGE : NOTE_V) * round.spec.pace;
const usual = (rage(b) ? NOTE_V_RAGE : NOTE_V) * round.spec.pace;
const v = pair ? b.noteV : columnSpeed(round, usual, x, random);
b.noteV = v;
ROWS.forEach((row, i) => {
if (i !== gap) round.hazards.push({ kind: "note", x, y: base + row - NOTE / 2, w: NOTE, h: NOTE, row: i, v, live: 1, life: 7000, cause: "note" });
if (i !== gap) round.hazards.push({ kind: "note", x, y: base + row - NOTE / 2, w: NOTE, h: NOTE, row: i, v, pace: v / usual, live: 1, life: 12000, cause: "note" });
});
round.events.push({ type: "notes", kind: b.kind, x, y: base, gap, pair, rows: ROWS.length });
round.events.push({ type: "notes", kind: b.kind, x, y: base, gap, pair, v, rows: ROWS.length });
}
// A column (or a pair) is away. While every pipe is silent it counts toward
// their return: the last but one warns you, the last drops them in.
function columnDone(round, b) {
b.act = "idle";
b.wait = (rage(b) ? COLUMN_RAGE_MS : COLUMN_MS) / round.spec.pace;
if (b.quiet === null) return;
b.quiet -= 1;
if (b.quiet === 1) round.events.push({ type: "pipesStir", kind: b.kind, x: b.x, y: b.y + b.h * 0.6 });
if (b.quiet > 0) return;
b.pipes.forEach((p, i) => Object.assign(p, { on: true, hp: p.max, hurt: 0, dropMs: PIPE_DROP_MS + i * PIPE_DROP_STAGGER_MS, spewIn: PIPE_SPEW_MS * 0.5 }));
b.quiet = null;
}
// The gap next to `gap`, one step up or down, whichever is on the staff.
@@ -446,20 +490,27 @@ function moveChoirmaster(round, b, ms, random, k) {
b.pipes = makePipes(round, k);
b.act = "glide";
b.wait = 0;
b.resoundIn = RESOUND_MS;
b.quiet = null;
}
b.dir = -1;
if (!b.raged && rage(b)) {
b.raged = true;
b.resoundIn = RESOUND_MS;
round.events.push({ type: "choirRage", kind: b.kind, x: b.x, y: b.y + b.h / 2 });
}
// The pipes: a sounding one spews a ghost now and then; in a rage the
// silent ones sound again, one every RESOUND_MS.
// Columns left before the pipes come back, counted only while all are silent.
if (b.pipes.some((p) => p.on)) b.quiet = null;
else b.quiet ??= PIPES_BACK;
// The pipes: one on its way down lands, one sounding spews a ghost now and
// then.
const ghosts = () => round.monsters.filter((m) => !m.dead && m.kind === "ghost").length;
for (const p of b.pipes) {
p.hurt = Math.max(0, p.hurt - ms);
if (!p.on) continue;
if (p.dropMs > 0) {
p.dropMs = Math.max(0, p.dropMs - ms);
if (!p.dropMs) round.events.push({ type: "pipeSound", kind: b.kind, x: p.x, y: p.y + p.h / 2, pipe: p.i });
continue;
}
p.spewIn -= ms * pace;
if (p.spewIn > 0) continue;
if (ghosts() >= GHOST_CAP) {
@@ -470,16 +521,6 @@ function moveChoirmaster(round, b, ms, random, k) {
k.spawnMonster(round, "ghost", p.x, p.y + p.h * 0.75, { force: true, phase: (p.x * 97) % 3100 });
round.events.push({ type: "pipeSpew", kind: b.kind, x: p.x, y: p.y + p.h * 0.75, pipe: p.i });
}
if (b.raged) {
const silent = b.pipes.filter((p) => !p.on);
if (!silent.length) b.resoundIn = RESOUND_MS;
else if ((b.resoundIn -= ms) <= 0) {
b.resoundIn = RESOUND_MS;
const p = silent[Math.floor(random() * silent.length) % silent.length];
Object.assign(p, { on: true, hp: p.max, spewIn: PIPE_SPEW_MS * 0.5 });
round.events.push({ type: "pipeSound", kind: b.kind, x: p.x, y: p.y + p.h / 2, pipe: p.i });
}
}
if (b.act === "glide") {
const home = spec.length - HOME_FROM_END;
const step = GLIDE_V * dt;
@@ -500,20 +541,16 @@ function moveChoirmaster(round, b, ms, random, k) {
b.wait = CUE_MS / pace;
round.events.push({ type: "notesCue", kind: b.kind, x: b.x - b.w / 2, y: b.y + b.h * 0.75, gap, second: b.second });
} else if (b.act === "cue") {
launch(round, b, b.gap, k, false);
launch(round, b, b.gap, k, false, random);
if (b.second !== null) {
b.act = "pair";
b.wait = PAIR_MS / pace;
} else {
b.act = "idle";
b.wait = (rage(b) ? COLUMN_RAGE_MS : COLUMN_MS) / pace;
}
} else columnDone(round, b);
} else if (b.act === "pair") {
b.gap = b.second;
launch(round, b, b.second, k, true);
launch(round, b, b.second, k, true, random);
b.second = null;
b.act = "idle";
b.wait = (rage(b) ? COLUMN_RAGE_MS : COLUMN_MS) / pace;
columnDone(round, b);
}
}
@@ -521,7 +558,7 @@ function moveChoirmaster(round, b, ms, random, k) {
function stepNote(round, h, ms) {
h.x -= h.v * (ms / 1000);
h.life -= ms;
return h.life > 0 && h.x > round.spec.arena - 6;
return h.life > 0 && h.x > noteEnd(round);
}
export const CHAPEL = freeze({
@@ -6,7 +6,7 @@
// file never reaches back into it. Everything is drawn in field units, y
// counted down from the field's top.
import { DICE_FACES, TUMBLE_MS } from "./ghoul-dice.js";
import { DICE_FACES, LEAD_MS, TUMBLE_MS } from "./ghoul-dice.js";
const BODY = "#f4f1e8";
const EDGE = "#8f8a7d";
@@ -27,6 +27,8 @@ const PIPS = Object.freeze([
// The panel the big die rolls on, and the die in it.
const PANEL_W = 44;
const PANEL_H = 40;
// The least gap between the panel and the field's edge.
const MARGIN = 1.5;
const DIE_SIZE = 15;
// Candidate spots for the panel's middle, tried in order: the field's middle
// first, then to either side; a row high on the field and one low.
@@ -37,7 +39,7 @@ const WORD = "LUCKY-SAVE";
const LUCKY_MS = 2800;
export function diceArt(d) {
const { circle, roundRect, rotate, label, GOLD, DANGER } = d;
const { circle, roundRect, rotate, label, GOLD, DANGER, hudLayout } = d;
// A die of side `s` at (x, y), turned `angle`, showing `face`; `ink` is its
// pips' color (a saving face is gold).
@@ -75,7 +77,20 @@ export function diceArt(d) {
// Where the panel's middle goes, as far from Planny's spot as the field
// lets it: the first candidate that does not touch him.
// How much the panel is scaled to fit inside the field with a margin.
function panelFit(g) {
return Math.min(1, (g.FIELD_H - 2 * MARGIN) / PANEL_H, (g.FIELD_W - 2 * MARGIN) / PANEL_W);
}
function panelAt(v, roll) {
const at = panelSpot(v, roll);
const { g } = v;
const hw = (PANEL_W * panelFit(g)) / 2;
const hh = (PANEL_H * panelFit(g)) / 2;
return { x: Math.min(g.FIELD_W - hw - MARGIN, Math.max(hw + MARGIN, at.x)), y: Math.min(g.FIELD_H - hh - MARGIN, Math.max(hh + MARGIN, at.y)) };
}
function panelSpot(v, roll) {
const { g, round } = v;
const cam = Math.round(round.camX * 8) / 8;
const sx = roll.x - cam;
@@ -95,12 +110,60 @@ export function diceArt(d) {
return first;
}
// Where the die's pill sits in the HUD strip, in field units (the strip is
// above the field, so y is negative); the strip's right end when it is not shown.
function hudDiceSpot(v) {
const { g, round } = v;
for (const p of hudLayout(v.pillH, g.W, round.infinite ? Infinity : round.lives, v.hud, g.HUD_H)) {
if (typeof p.text === "string" && p.text.startsWith("DICE")) return { x: p.x + p.w / 2 - g.PAD, y: p.y + p.h / 2 - g.HUD_H };
}
return { x: g.W - g.PAD * 2 - 8, y: -g.HUD_H / 2 };
}
// The die in hand while the round holds to roll: tumbling in from above,
// landing on its face with a pop, and a line saying where it stands.
function roll(ctx, v) {
const r = v.round.roll;
if (!r) return;
const { x, y } = panelAt(v, r);
// The whole panel shrinks to fit a small field, and sits inside it, so no edge is cut off.
const fit = panelFit(v.g);
ctx.save();
ctx.translate(x, y);
ctx.scale(fit, fit);
ctx.translate(-x, -y);
rollIn(ctx, v, r, x, y, fit);
ctx.restore();
}
function rollIn(ctx, v, r, x, y, fit) {
// The lead-in: the panel grows out of the die, which flies up from its pill in the HUD.
if (r.t < LEAD_MS) {
const e = 1 - (1 - r.t / LEAD_MS) ** 3;
const spot = hudDiceSpot(v);
// The HUD spot, in the shrunk panel's own space.
const from = { x: x + (spot.x - x) / fit, y: y + (spot.y - y) / fit };
const s = 0.12 + 0.88 * e;
ctx.save();
ctx.globalAlpha = e;
ctx.translate(x, y);
ctx.scale(s, s);
ctx.translate(-x, -y);
ctx.fillStyle = "rgba(0, 0, 0, 0.62)";
roundRect(ctx, x - PANEL_W / 2, y - PANEL_H / 2, PANEL_W, PANEL_H, 2.5);
ctx.fill();
ctx.strokeStyle = "rgba(255, 255, 255, 0.35)";
ctx.lineWidth = 0.3;
ctx.stroke();
ctx.restore();
const gx = from.x + (x - from.x) * e;
const gy = from.y + (y - 6 - from.y) * e;
ctx.fillStyle = "rgba(244, 241, 232, 0.25)";
circle(ctx, gx, gy, (3 + DIE_SIZE * 0.6 * e));
ctx.fill();
die(ctx, gx, gy, 3 + (DIE_SIZE - 3) * e, 1 + (Math.floor(r.t / 60) * 5) % 6, (1 - e) * 9);
return;
}
const lucky = r.landed && (!!DICE_FACES[r.face].revive || !!r.heart);
ctx.fillStyle = "rgba(0, 0, 0, 0.62)";
roundRect(ctx, x - PANEL_W / 2, y - PANEL_H / 2, PANEL_W, PANEL_H, 2.5);
@@ -127,10 +190,10 @@ export function diceArt(d) {
ctx.globalAlpha = 1;
}
} else {
const p = r.t / TUMBLE_MS;
const p = (r.t - LEAD_MS) / (TUMBLE_MS - LEAD_MS);
face = 1 + (Math.floor(r.t / 70) * 5) % 6;
angle = (1 - p) ** 1.5 * 12;
dy = Math.abs(Math.sin(r.t / 105)) * -2.5 * (1 - p) - 3.5 * (1 - Math.min(1, r.t / 220)) ** 2;
dy = Math.abs(Math.sin(r.t / 105)) * -2.5 * (1 - p) - 3.5 * (1 - Math.min(1, (r.t - LEAD_MS) / 220)) ** 2;
}
die(ctx, x, at + dy, size, face, angle, lucky ? "#b8860b" : INK);
let text = "A 4 or better saves you";
@@ -154,7 +217,7 @@ export function diceArt(d) {
function react(e, k) {
const { tone, burst, float, ring, flash, glow, shake, banner, fx, powers: POWERS } = k;
if (e.type === "diceStart") {
tone("whoosh", 0.3, 0.6);
tone("ghoulDiceDrone", 0.6);
tone("heartbeat", 0.45);
ring(e.x, e.y + 2.5, BODY, 2, 8, 500);
} else if (e.type === "diceRoll") {
@@ -35,8 +35,10 @@ export const DICE_FACES = Object.freeze({
5: Object.freeze({ revive: true, give: Object.freeze(["life"]), line: "Back to life, +1 heart!", word: "+1 heart!" }),
6: Object.freeze({ revive: true, give: Object.freeze(["life", "garlic"]), line: "Back to life, +1 heart + Garlic!", word: "+1 heart + Garlic!" }),
});
export const ROLL_MS = 3200;
export const TUMBLE_MS = 600;
// The lead-in: the screen holds under a drone while a die flies from the HUD to the middle and grows into the panel.
export const LEAD_MS = 800;
export const TUMBLE_MS = LEAD_MS + 600;
export const ROLL_MS = LEAD_MS + 3200;
// The clock a saved time-up gets back.
export const SAVED_TIME_MS = 15000;
// The most a pit's revive spot may move along the ground to stand clear of
@@ -93,7 +95,6 @@ export function beginRoll(round, cause, kit) {
round.phaseMs = 0;
round.input.jump = 0;
round.events.push({ type: "diceStart", cause, n: round.dice, x: at.x, y: at.y });
round.events.push({ type: "diceRoll", n: round.dice, x: at.x, y: at.y });
return true;
}
@@ -105,7 +106,10 @@ export const heartFace = (round, face) => !round.bonusRound && round.lives <= 1
// (`kit.takeLife`), leaving its gift, if any, for the respawn.
export function rollDice(round, ms, random, kit) {
const r = round.roll;
const was = r.t;
r.t += ms;
// The die leaves the HUD: the drone plays through the lead-in, and the rattle starts when it arrives.
if (was < LEAD_MS && r.t >= LEAD_MS) round.events.push({ type: "diceRoll", n: round.dice, x: r.x, y: r.y });
if (!r.landed && r.t >= TUMBLE_MS) {
r.landed = true;
r.face = 1 + Math.min(5, Math.floor(random() * 6));
+127 -5
View File
@@ -38,16 +38,28 @@ import { LOOKS as SANATORIUM_LOOKS, LOSE_SOUNDS as SANATORIUM_LOSE_SOUNDS, LOSE_
import { LOOKS as VILLAGE_LOOKS, LOSE_SOUNDS as VILLAGE_LOSE_SOUNDS, LOSE_WORDS as VILLAGE_LOSE_WORDS, VOICES as VILLAGE_VOICES, villageArt } from "./ghoul-village-draw.js";
import { LOOKS as MINE_LOOKS, LOSE_SOUNDS as MINE_LOSE_SOUNDS, LOSE_WORDS as MINE_LOSE_WORDS, VOICES as MINE_VOICES, mineArt } from "./ghoul-mine-draw.js";
import { LOOKS as CART_LOOKS, LOSE_SOUNDS as CART_LOSE_SOUNDS, LOSE_WORDS as CART_LOSE_WORDS, VOICES as CART_VOICES, cartArt } from "./ghoul-cart-draw.js";
import { LOOKS as WAGON_LOOKS, LOSE_SOUNDS as WAGON_LOSE_SOUNDS, LOSE_WORDS as WAGON_LOSE_WORDS, VOICES as WAGON_VOICES, wagonArt } from "./ghoul-wagon-draw.js";
import { LOOKS as SLED_LOOKS, LOSE_SOUNDS as SLED_LOSE_SOUNDS, LOSE_WORDS as SLED_LOSE_WORDS, VOICES as SLED_VOICES, sledArt } from "./ghoul-sled-draw.js";
import { LOOKS as BANISTER_LOOKS, LOSE_SOUNDS as BANISTER_LOSE_SOUNDS, LOSE_WORDS as BANISTER_LOSE_WORDS, VOICES as BANISTER_VOICES, banisterArt } from "./ghoul-banister-draw.js";
import { LOOKS as HEARSE_LOOKS, LOSE_SOUNDS as HEARSE_LOSE_SOUNDS, LOSE_WORDS as HEARSE_LOSE_WORDS, VOICES as HEARSE_VOICES, hearseArt } from "./ghoul-hearse-draw.js";
import { LOOKS as GURNEY_LOOKS, LOSE_SOUNDS as GURNEY_LOSE_SOUNDS, LOSE_WORDS as GURNEY_LOSE_WORDS, VOICES as GURNEY_VOICES, gurneyArt } from "./ghoul-gurney-draw.js";
import { LOOKS as PEW_LOOKS, LOSE_SOUNDS as PEW_LOSE_SOUNDS, LOSE_WORDS as PEW_LOSE_WORDS, VOICES as PEW_VOICES, pewArt } from "./ghoul-pew-draw.js";
import { LOOKS as MOWER_LOOKS, LOSE_SOUNDS as MOWER_LOSE_SOUNDS, LOSE_WORDS as MOWER_LOSE_WORDS, VOICES as MOWER_VOICES, mowerArt } from "./ghoul-mower-draw.js";
import { LOOKS as TRAY_LOOKS, LOSE_SOUNDS as TRAY_LOSE_SOUNDS, LOSE_WORDS as TRAY_LOSE_WORDS, VOICES as TRAY_VOICES, trayArt } from "./ghoul-tray-draw.js";
import { LOOKS as CARNIVAL_LOOKS, LOSE_SOUNDS as CARNIVAL_LOSE_SOUNDS, LOSE_WORDS as CARNIVAL_LOSE_WORDS, VOICES as CARNIVAL_VOICES, carnivalArt } from "./ghoul-carnival-draw.js";
import { LOOKS as FROZEN_LOOKS, LOSE_SOUNDS as FROZEN_LOSE_SOUNDS, LOSE_WORDS as FROZEN_LOSE_WORDS, VOICES as FROZEN_VOICES, frozenArt } from "./ghoul-frozen-draw.js";
import { LOOKS as BOG_LOOKS, LOSE_SOUNDS as BOG_LOSE_SOUNDS, LOSE_WORDS as BOG_LOSE_WORDS, VOICES as BOG_VOICES, bogArt } from "./ghoul-bog-draw.js";
import { LOOKS as BOGBOAT_LOOKS, LOSE_SOUNDS as BOGBOAT_LOSE_SOUNDS, LOSE_WORDS as BOGBOAT_LOSE_WORDS, VOICES as BOGBOAT_VOICES, bogboatArt } from "./ghoul-bogboat-draw.js";
import { diceArt } from "./ghoul-dice-draw.js";
import { gameOverBanner } from "./ghoul-gameover-draw.js";
import { introArt } from "./ghoul-intro-draw.js";
import { storyArt } from "./ghoul-story-draw.js";
import { bonusArt } from "./ghoul-bonus-draw.js";
import { LOOKS as RIDE_LOOKS, LOSE_SOUNDS as RIDE_LOSE_SOUNDS, LOSE_WORDS as RIDE_LOSE_WORDS, VOICES as RIDE_VOICES, react as rideReact } from "./ghoul-ride-voices.js";
import { rideArt } from "./ghoul-ride-draw.js";
import { armsArt } from "./ghoul-arms-draw.js";
import { pickerArt } from "./ghoul-picker-draw.js";
import { bossIntroArt } from "./ghoul-bossintro-draw.js";
import { monsterArt } from "./ghoul-monsters-draw.js";
const FALLBACK_COLORS = Object.freeze({ board: "#ffffff", line: "#e4ddd1", you: "#206cc3", ink: "#1d1a17" });
@@ -116,9 +128,18 @@ export const LOOKS = Object.freeze({
...MINE_LOOKS,
...CART_LOOKS,
...SLED_LOOKS,
...BANISTER_LOOKS,
...HEARSE_LOOKS,
...GURNEY_LOOKS,
...PEW_LOOKS,
...MOWER_LOOKS,
...TRAY_LOOKS,
...WAGON_LOOKS,
...CARNIVAL_LOOKS,
...FROZEN_LOOKS,
...RIDE_LOOKS,
...BOG_LOOKS,
...BOGBOAT_LOOKS,
crypt: Object.freeze({ wallTop: "#0a0b0e", wallLow: "#1b1e25", paper: "#262a33", wainscot: "#14161b", floorTop: "#43474f", floor: "#22252b", floorEdge: "#0a0b0d", shelf: "#30343c", shelfTop: "#4a4f58", pit: "#010102", window: "#b4bfd1", decor: "tombs", color: "#b4bfd1", dark: 0.9 }),
});
export const lookOf = (id) => LOOKS[id] || LOOKS.foyer;
@@ -242,12 +263,14 @@ const { drawZombie, drawZombieKin, drawHuntsman, drawCrawler, drawBat, drawGhost
// backdrops (a look's `pack` names whose, the Graveyard's by default), graves,
// monsters, bosses, missiles, hazards, waves, power-up badges and lights by
// kind, and what their events look and sound like.
const HELP = { drawPower, ellipse, circle, roundRect, line, rotate, eye, hash, say, gate, label, drawBoneShape, BONE, DANGER, GOLD, FLASH, EYE_RED, EYE_PALE, EYE_AMBER };
const HELP = { hudLayout, drawPower, ellipse, circle, roundRect, line, rotate, eye, hash, say, gate, label, drawBoneShape, BONE, DANGER, GOLD, FLASH, EYE_RED, EYE_PALE, EYE_AMBER };
const ARMS_ART = armsArt(HELP);
const PACK_ART = { arms: ARMS_ART, bones: boneArt(HELP), graveyard: graveyardArt(HELP), grounds: groundsArt(HELP), chapel: chapelArt(HELP), sanatorium: sanatoriumArt(HELP), village: villageArt(HELP), mine: mineArt(HELP), cart: cartArt(HELP), sled: sledArt(HELP), carnival: carnivalArt(HELP), frozen: frozenArt(HELP), ride: { backdrop() {}, lights() {}, react: rideReact } };
const PACK_ART = { arms: ARMS_ART, bones: boneArt(HELP), graveyard: graveyardArt(HELP), grounds: groundsArt(HELP), chapel: chapelArt(HELP), sanatorium: sanatoriumArt(HELP), village: villageArt(HELP), mine: mineArt(HELP), cart: cartArt(HELP), sled: sledArt(HELP), banister: banisterArt(HELP), hearse: hearseArt(HELP), codeblue: gurneyArt(HELP), pew: pewArt(HELP), mower: mowerArt(HELP), tray: trayArt(HELP), wagon: wagonArt(HELP), carnival: carnivalArt(HELP), frozen: frozenArt(HELP), bog: bogArt(HELP), bogboat: bogboatArt(HELP), ride: { backdrop() {}, lights() {}, react: rideReact } };
const packs = Object.values(PACK_ART);
const DICE = diceArt(HELP);
const OVER_BANNER = gameOverBanner(HELP);
const INTRO_CARD = introArt(HELP);
const STORY_CARD = storyArt({ ...HELP, LOOKS });
const BONUS = bonusArt(HELP, DICE.die);
// The Carnival's dark ride draws the whole field itself (ghoul-ride-draw.js).
const RIDE = rideArt(HELP, DICE.die);
@@ -1723,7 +1746,7 @@ function drawGlowing(ctx, v) {
/* ------------------------------------------------------------ feedback */
const KILL_WORDS = Object.freeze({ head: "Headshot!", stomp: "Crunch!", crush: "Flattened!", garlic: "Garlic!" });
const LOSE_WORDS = Object.freeze({ time: "Out of time", pit: "Into the dark", bone: "Skull cracked", chandelier: "Crushed", acid: "Burned alive", wave: "Thrown down", ...BONES_LOSE_WORDS, ...GROUNDS_LOSE_WORDS, ...CHAPEL_LOSE_WORDS, ...SANATORIUM_LOSE_WORDS, ...VILLAGE_LOSE_WORDS, ...MINE_LOSE_WORDS, ...CART_LOSE_WORDS, ...SLED_LOSE_WORDS, ...CARNIVAL_LOSE_WORDS, ...FROZEN_LOSE_WORDS,...RIDE_LOSE_WORDS, hound: "Mauled", spider: "Bitten", wraith: "Taken", hands: "Dragged under", mourner: "Mourned", robber: "Buried alive", crow: "Pecked", legs: "Kicked down", stone: "Struck by a headstone", fist: "Crushed by stone", angel: "Turned to stone" });
const LOSE_WORDS = Object.freeze({ time: "Out of time", pit: "Into the dark", bone: "Skull cracked", chandelier: "Crushed", acid: "Burned alive", wave: "Thrown down", ...BONES_LOSE_WORDS, ...BANISTER_LOSE_WORDS, ...GROUNDS_LOSE_WORDS, ...CHAPEL_LOSE_WORDS, ...SANATORIUM_LOSE_WORDS, ...VILLAGE_LOSE_WORDS, ...MINE_LOSE_WORDS, ...CART_LOSE_WORDS, ...SLED_LOSE_WORDS, ...HEARSE_LOSE_WORDS, ...GURNEY_LOSE_WORDS, ...PEW_LOSE_WORDS, ...MOWER_LOSE_WORDS, ...TRAY_LOSE_WORDS, ...WAGON_LOSE_WORDS, ...CARNIVAL_LOSE_WORDS, ...FROZEN_LOSE_WORDS,...RIDE_LOSE_WORDS, ...BOG_LOSE_WORDS, ...BOGBOAT_LOSE_WORDS, hound: "Mauled", spider: "Bitten", wraith: "Taken", hands: "Dragged under", mourner: "Mourned", robber: "Buried alive", crow: "Pecked", legs: "Kicked down", stone: "Struck by a headstone", fist: "Crushed by stone", angel: "Turned to stone" });
// What spills from each kind when it dies, and whether it leaves a stain.
const STAINS = Object.freeze({ ghost: false, wraith: false, skeleton: false, bat: true });
@@ -1857,6 +1880,11 @@ export function react(e, k) {
burst(e.x, e.y, GOLD, 16, 14);
ring(e.x, e.y, GOLD, 1, 7, 500);
banner("The key", "Now find the door. Fast", GOLD, 1100);
} else if (e.type === "keyDark") {
tone("ghoulLightsOut", 0.6);
flash("#000000", 200);
shake(160, 0.3);
float(e.x, e.y + 5, "The lights go out!", DANGER, 2.4);
} else if (e.type === "garlic") {
tone("shield");
tone("ghoulGarlicPop", 0.55);
@@ -1961,7 +1989,7 @@ export function react(e, k) {
}
burst(e.x, e.y, e.how === "head" ? BONE : BLOOD, 4, 10, 260);
if (e.how === "head") float(e.x, e.y + 6, "Skull!", GOLD, 2);
else if (e.weak) float(e.x, e.y + 4, e.kind === "keeper" ? "Lantern!" : "Double!", GOLD, 2);
else if (e.weak) float(e.x, e.y + 4, e.kind === "keeper" ? "Lantern!" : e.kind === "motherbog" ? "Triple!" : "Double!", GOLD, 2);
} else if (e.type === "bossDown") {
tone("explode", 0.9, 0.8);
say(tone, e.kind, "die", 0.8);
@@ -1998,6 +2026,12 @@ export function react(e, k) {
tone("ghoulToll", 0.35, 1.2);
tone("doorCreak", 0.3, 0.7);
} else if (e.type === "pickMove") tone("tickSoft", 0.3, 1.2);
else if (e.type === "intro") tone("ghoulStageIntro", 0.6);
else if (e.type === "bossIntro") tone("ghoulBossIntro", 0.75);
// The intro story (ghoul-story.js): a page turns, a timed sound, the last page opens the hall.
else if (e.type === "storyPage") e.page && tone("ghoulStoryPage", 0.3);
else if (e.type === "storyTone") tone(e.name, e.vol, e.rate);
else if (e.type === "storyEnd") flash("#fff3c4", 320);
else if (e.type === "stage") {
tone("doorUnlock", 0.5);
tone("ghoulThunder", 0.4, 0.9);
@@ -2062,10 +2096,19 @@ export const VOICES = Object.freeze({
...MINE_VOICES,
...CART_VOICES,
...SLED_VOICES,
...BANISTER_VOICES,
...HEARSE_VOICES,
...GURNEY_VOICES,
...PEW_VOICES,
...MOWER_VOICES,
...TRAY_VOICES,
...WAGON_VOICES,
...CARNIVAL_VOICES,
...FROZEN_VOICES,
...RIDE_VOICES,
angel: Object.freeze({ wake: "ghoulAngelWake", weep: "ghoulAngelWeep", watch: "ghoulAngelWatch", see: "ghoulAngelSee", slam: "ghoulAngelSlam", wings: "ghoulAngelWings", hurt: "ghoulAngelHurt", die: "ghoulAngelDie" }),
...BOG_VOICES,
...BOGBOAT_VOICES,
});
// Plays a kind's voice for an act, if it has one, its pitch a touch varied.
function say(tone, kind, act, level) {
@@ -2103,7 +2146,16 @@ const LOSE_SOUNDS = Object.freeze({
...FROZEN_LOSE_SOUNDS,
...CART_LOSE_SOUNDS,
...SLED_LOSE_SOUNDS,
...BANISTER_LOSE_SOUNDS,
...HEARSE_LOSE_SOUNDS,
...GURNEY_LOSE_SOUNDS,
...PEW_LOSE_SOUNDS,
...MOWER_LOSE_SOUNDS,
...TRAY_LOSE_SOUNDS,
...WAGON_LOSE_SOUNDS,
...RIDE_LOSE_SOUNDS,
...BOG_LOSE_SOUNDS,
...BOGBOAT_LOSE_SOUNDS,
});
// The door's boom in each of the eight rooms, the Crypt deepest.
const ROOM_PITCH = Object.freeze([1, 1.1, 0.95, 1.2, 1.05, 1.15, 0.9, 0.75]);
@@ -2188,7 +2240,10 @@ function layPills(h, W, lives, hud, stripH) {
if (hud.hearts) put(hud.hearts, GOLD);
else put(`BONUS ${hud.bonus}`, hud.bonus > 0 ? GOLD : DANGER);
if (hud.chain > 1) put(`CHAIN x${hud.chain}`, GOLD, hud.chainFill);
if (hud.key) put("KEY", GOLD);
if (hud.key) {
out.push({ x, y, w: h * 1.5, h, key: hud.key, color: GOLD });
x += h * 1.5 + gap;
}
for (const e of hud.effects) put(e.text, e.color, e.fill);
if (gw) out.push({ x: W - edge - gw, y: y0, w: gw, h, gauge: true });
if (aw) out.push({ x: W - edge - (gw ? gw + gap : 0) - aw, y: y0, w: aw, h, arm: true, text: hud.arm.text });
@@ -2213,10 +2268,47 @@ function drawPills(ctx, v) {
for (const p of hudLayout(v.pillH, g.W, v.round.infinite ? Infinity : v.round.lives, v.hud, g.HUD_H)) {
if (p.gauge) drawGauge(ctx, p.x, p.y, p.w, p.h, v.hud.gauge, v.clock);
else if (p.arm) ART.armPill(ctx, p, v, SANS);
else if (p.key) drawKeyPill(ctx, p, v.clock);
else pill(ctx, p.x, p.y, p.h, p.text, p.color, p.fill);
}
}
// The room's key in the strip: a gold key on a pill once it is found, a dotted
// outline of one (dim, waiting) until then.
function drawKeyPill(ctx, p, clock) {
const { x, y, w, h } = p;
const have = p.key === "have";
ctx.fillStyle = PILL;
roundRect(ctx, x, y, w, h, h / 2);
ctx.fill();
ctx.save();
ctx.translate(x + w / 2, y + h * 0.52);
const u = h * 0.34;
ctx.rotate(-0.6);
ctx.beginPath();
ctx.arc(-u * 1.05, 0, u * 0.7, 0, Math.PI * 2);
ctx.moveTo(-u * 0.35, 0);
ctx.lineTo(u * 1.35, 0);
ctx.moveTo(u * 0.85, 0);
ctx.lineTo(u * 0.85, u * 0.7);
ctx.moveTo(u * 1.35, 0);
ctx.lineTo(u * 1.35, u * 0.7);
ctx.lineCap = "round";
ctx.lineJoin = "round";
if (have) {
ctx.strokeStyle = GOLD;
ctx.lineWidth = u * 0.5;
ctx.stroke();
} else {
ctx.globalAlpha = 0.5 + 0.12 * Math.sin(clock / 400);
ctx.strokeStyle = "#ffffff";
ctx.lineWidth = u * 0.34;
ctx.setLineDash([u * 0.45, u * 0.55]);
ctx.stroke();
}
ctx.restore();
}
// The blaster's gauge: LIGHT on the pill's dark backing, then a bar that
// fills as the blaster heats and empties as it cools, with a notch where the
// bolts start to slow and the stretch past it tinted red. Past the notch the
@@ -2313,6 +2405,7 @@ function drawTally(ctx, v, lines) {
// The choice of stage, the stage select and each stage's color (ghoul-picker-draw.js).
const { drawPicker, drawSelect, stageColor } = pickerArt({ lookOf, label, roundRect, circle, BOSS_ART, drawGourdFire, GOLD });
const BOSS_CARD = bossIntroArt({ label, circle, BOSS_ART, drawGourdFire, GOLD, BONE });
/* --------------------------------------------------------------- scene */
@@ -2380,6 +2473,32 @@ export function drawScene(ctx, v) {
ctx.restore();
return;
}
// Holy Roller is an endless-runner drawn whole by its own art (ghoul-pew-draw.js): the nave in pseudo-3D from behind the
// pew. The hearts, the flash, the banner, the cards and the HUD pills go over it as they do over the dark ride.
if (round.runner && round.runner.id === "pew") {
PACK_ART.pew.field(ctx, v);
for (const f of v.fx.floats) {
ctx.globalAlpha = Math.min(1, (f.life / f.max) * 1.6);
const at = labelSpot(f.text, f.x, Y(f.y) - f.rise, f.size, g.FIELD_W, g.FIELD_H);
label(ctx, f.text, at.x, at.y, f.size, f.color, "center", at.max);
}
ctx.globalAlpha = 1;
if (round.bonusRound && (v.state === "running" || v.state === "paused")) drawBonusHearts(ctx, v);
if (v.flash) {
ctx.globalAlpha = 0.24 * (v.flash.life / v.flash.max);
ctx.fillStyle = v.flash.color;
ctx.fillRect(0, 0, g.FIELD_W, g.FIELD_H);
ctx.globalAlpha = 1;
}
if (v.state === "running" && round.phase === "clear") BONUS.card(ctx, v);
if (v.state === "running" && v.banner && round.phase !== "pick" && round.phase !== "select" && round.phase !== "roll") drawBanner(ctx, v, v.banner);
if (v.state === "running" && v.fx.lucky) DICE.lucky(ctx, v);
ctx.restore();
ctx.translate(-g.PAD, -g.HUD_H);
drawPills(ctx, v);
ctx.restore();
return;
}
const cam = Math.round(round.camX * 8) / 8;
if (v.shake) ctx.translate(v.shake.x, v.shake.y);
ctx.translate(-cam, 0);
@@ -2478,6 +2597,9 @@ export function drawScene(ctx, v) {
if (v.state === "running" && v.fx.lucky) DICE.lucky(ctx, v);
if ((v.state === "running" || v.state === "paused") && round.phase === "pick" && round.offer) drawPicker(ctx, v);
if ((v.state === "running" || v.state === "paused") && round.phase === "select" && round.select) drawSelect(ctx, v);
if ((v.state === "running" || v.state === "paused") && round.phase === "intro") INTRO_CARD(ctx, v);
if ((v.state === "running" || v.state === "paused") && round.phase === "bossintro") BOSS_CARD(ctx, v);
if ((v.state === "running" || v.state === "paused") && round.phase === "story") STORY_CARD(ctx, v);
if (v.state === "over" && v.lost && !v.won) OVER_BANNER(ctx, v);
if (v.tally) drawTally(ctx, v, v.tally);
ctx.restore();
@@ -80,6 +80,7 @@ export const EVENT_VOICE = freeze({
veilMelt: ["frostwidow", "melt"],
veilUp: ["frostwidow", "up"],
barrelKick: ["frostwidow", "kick"],
barrelKnock: ["frostwidow", "kick"],
barrelBurst: ["frostwidow", "burst"],
blizzard: ["frostwidow", "gust"],
blizzardBlow: ["frostwidow", "blow"],
@@ -1387,6 +1388,10 @@ export function frozenArt(d) {
burst(e.x, e.y + 1.7, "#ff8a1a", 6, 6, 260);
ring(e.x, e.y + 1.7, "#ff8a1a", 1, 4, 300);
break;
case "barrelKnock":
shake(60, 0.15);
burst(e.x, e.y + 1.7, "#ffb050", 3 + e.n, 8, 220);
break;
case "barrelKick":
shake(80, 0.25);
burst(e.x, e.y + 1.7, "#ffb050", 8, 12, 300);
@@ -147,7 +147,7 @@ export const BOSSES = freeze({
export const EVENTS = freeze([
"iceCrack", "iceBreak", "iceBack", "handWarn", "handUp", "shadeShow", "shadeWind", "shadeLunge", "shatter", "frozenMelt",
"iceWraithWake", "iceWraithWind", "iceWraithDive", "freezeHit",
"widowDrop", "widowRise", "widowRage", "veilMelt", "veilDown", "veilUp", "barrelPlace", "barrelKick", "barrelBurst",
"widowDrop", "widowRise", "widowRage", "veilMelt", "veilDown", "veilUp", "barrelPlace", "barrelKick", "barrelKnock", "barrelBurst",
"blizzard", "blizzardBlow", "blizzardEnd", "spikeWarn", "spikeUp", "webWind", "webShot", "webLand", "wraithCall",
]);
@@ -226,18 +226,20 @@ export const FREEZE_MS = 700;
// The Frost Widow.
export const HANG_OVER = 20;
export const HANG_V = 12;
export const HANG_V = 10;
export const FIRST_HANG_MS = 4200;
export const HANG_MS = 5200;
export const DROP_MS = 700;
export const RISE_MS = 800;
export const LOW_MS = 9000;
export const LOW_V = 5;
export const LOW_V = 4;
export const LOW_KEEP = 14;
export const LAND_AWAY = 24;
export const LAND_AWAY = 32;
export const WIDOW_RAGE = 0.5;
export const RAGE_QUICK = 0.75;
export const WRAITH_CAP = 2;
export const WRAITH_CAP = 1;
// After a call, no wraith is called again for this long (ms): the rage's first one, then one every so often.
export const WRAITH_GAP_MS = 20000;
// A called wraith hovers this long (ms) before its first shriek, so it can be shot first.
export const WRAITH_CALL_MS = 1600;
// The veil, the heart and the mouth.
@@ -255,6 +257,8 @@ export const BARREL_V = 34;
export const BARREL_LIFE_MS = 5000;
export const BARREL_DMG = 3;
export const BARREL_BOSS = 3;
// A still barrel shrugs off a stray bolt: it takes this many bolts to topple it (a thrown weapon kicks it at once).
export const BARREL_HITS = 4;
// The blizzard.
export const BLIZZARD_FIRST_MS = 7000;
export const BLIZZARD_EVERY_MS = 12000;
@@ -265,8 +269,8 @@ export const BLIZZARD_COVER = 0.5;
export const COVER_NEAR = 5;
// The spikes.
export const SPIKE_FIRST_MS = 2200;
export const SPIKE_EVERY_MS = 2800;
export const SPIKE_LOW_MS = 3400;
export const SPIKE_EVERY_MS = 3600;
export const SPIKE_LOW_MS = 4400;
export const SPIKE_WARN_MS = 800;
export const SPIKE_UP_MS = 1000;
export const SPIKE_W = 4;
@@ -779,6 +783,8 @@ function target(round, s) {
if (h.kind === "webGlob") {
h.life = 0;
round.events.push({ type: "webLand", x: h.x, y: h.y, shot: true });
} else if (!s.arm && (h.knocks = (h.knocks || 0) + 1) < BARREL_HITS) {
round.events.push({ type: "barrelKnock", x: h.x, y: h.y, n: h.knocks });
} else {
h.state = "roll";
h.vx = (Math.sign(s.vx) || 1) * BARREL_V;
@@ -793,12 +799,14 @@ function target(round, s) {
// Up to WRAITH_CAP ice wraiths come in from the arena's edges.
function callWraiths(round, b, k) {
const spec = round.spec;
if (round.clock < (b.wraithAt || 0)) return;
let alive = round.monsters.filter((m) => m.kind === "icewraith" && !m.dead).length;
for (const [x, side] of [[spec.arena + 6, 1], [spec.length - 6, -1]]) {
if (alive >= WRAITH_CAP) break;
const y = b.floor + 22;
if (k.spawnMonster(round, "icewraith", x, y, { act: "hover", wait: WRAITH_CALL_MS, home: y, dir: -side, force: true })) {
alive++;
b.wraithAt = round.clock + WRAITH_GAP_MS;
round.events.push({ type: "wraithCall", kind: b.kind, x, y });
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,586 @@
// Plan2Code Web Console - Ghoul Rush's Code Blue, its rules: Blackmoor Sanatorium's bonus round. YOU lie strapped to a runaway hospital gurney that flies down the sanatorium's endless corridors and ramps, wheels squealing: jump the wheelchairs, IV stands and elevator shafts, duck the hanging surgical lamps and swinging doors, shoot the orderlies who lunge from doorways, while the lights go out in timed waves, as a stage pack that ghoul.js plugs in.
//
// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it, handed a
// kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js (it borrows the
// cart's track helpers). Pack fields used: `ride` (a hook that moves Planny himself, so no
// key walks him), `place` (Planny put down in a room: a room set up or a respawn) and
// `target` (a bolt strikes something that is no monster: the orderlies and the surge
// lamps). It adds no monster, boss or hazard kind and draws NO random number.
//
// THE SLOT: the ride's state lives in `round.runner` (the shared slot for a rolling bonus
// ride, null in any other room), marked `pack: "codeblue"`; the room's ride spec has
// `runner: "codeblue"`, which the Cart's `place` knows to leave alone. Another ride's
// `place` could null the slot in this room, so a copy is kept (BACK) and put back.
//
// THE ROOM (spec.ride, see ghoul-rooms.js):
//
// - `track`: polylines [x, y] the gurney rolls along, one per corridor; a gap between two
// lines is an ELEVATOR SHAFT (jump it; a fall below DERAIL_Y is a heart, cause
// "elevator"). Corridors are flat with ramps (slope up to 0.22) between floors; the
// last line ends on a loading ramp rising over RAMP_SLOPE, which launches the gurney
// out of the ambulance doors onto the bay (`finish` is where the bay begins).
// - `chairs` [x, line] (a wheelchair, CHAIR_W by CHAIR_H, jump: it starts rolling at you
// CHAIR_V when the gurney is CHAIR_NEAR short of it, at most CHAIR_MAX), `stands` [x, line]
// (an IV stand, STAND_W by STAND_H, jump), `lows` [x0, x1, y, kind] (a hanging surgical
// lamp, kind 0, or a swinging door, kind 1: its underside is y, 3.0 over the track, so
// DUCK it), `orderlies` [x, line] (an orderly in a doorway: the door shivers
// ORDERLY_WARN_MS when the gurney is ORDERLY_NEAR short, then he lunges onto the track
// ORDERLY_UP_MS, ORDERLY_W by ORDERLY_H: jump it, or shoot it, ORDERLY_HP bolts),
// `lamps` [x, line] (the surge lamp of wave i: see below), `waves` [x0, x1] (the span
// of each blackout), `checks` (x positions of the checkpoints), `finish`, `time` (the
// room's clock, ms) and `how` (the controls line).
// - The ground is the start's floor and the ambulance bay at the end only.
//
// THE TWIST, LIGHTS OUT: the lights go out in waves. WARN_UNITS (84) before a wave's x0 the
// corridor flickers and buzzes and a countdown (3, 2, 1, one number every TICK_UNITS)
// runs; from x0 to x1 it is pitch black, only the flashlight cone, the dying emergency
// strips and a faint glow on what is near show. Wave i has a surge lamp, SURGE_BACK
// before x0, hung SURGE_LO to SURGE_HI over the track: a bolt fired from the air (a hop
// while holding fire) hits it, it shorts out harmlessly, and that blackout is called off
// (`waves[i].off`): the section stays lit. A heartbeat monitor runs across the top: it
// beeps every BEAT_MS[hearts] and flatlines at the last heart (FLAT_MS).
//
// THE GURNEY (`round.runner`): { pack, room, check, v, line, coyote, from, left, done,
// wave (the wave in its countdown or dark, else -1), phase ("lit" | "warn" | "dark"), n
// (the countdown number), dark (0..1), waves: [{ off, hit }], hitWaves, beatMs, pulse, every
// (the beat's length in ms), flat,
// orderlies, chairs, lamps }. Planny rides at (you.x, you.y), always facing right (`you.state`
// "run" on the floor, "air" off it, `you.ducking` ducked). Speed `v` relaxes to GURNEY_V
// (RELAX) and is pushed by the slope (SLOPE_G), between GURNEY_MIN and GURNEY_MAX. Up
// jumps at JUMP_V (plus the slope's own rise) against GRAV (about 13 high, 0.75 s),
// COYOTE_MS of grace after running off a line's end; down ducks. A bolt flies parallel
// to the track under it (`s.off` keeps what he aimed).
//
// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the gurney
// rolls on, Planny blinking safe BONUS_SAFE_MS; the last heart gone ends the round with
// nothing, at once. A derail puts him back on the track at GURNEY_V. Causes: "wheelchair",
// "ivstand", "overhead" (a lamp or a door), "lunged" (an orderly), "elevator" (a fall).
// Every obstacle is a number for the grade (`perf.total`: chairs, stands, lows, orderlies
// and shafts, each id once in `perf.hits` if it ever cost a heart). Shooting an orderly or
// a surge lamp counts for `perf.acts` (the goal is ACTS_GOAL) and the points below. The
// grade's `steady` die rewards clean dark stretches: it holds while at most WAVE_SLACK
// blackouts (countdown and dark) have cost a heart; a wave called off is a clean one.
//
// WHAT THE ART READS: `spec.ride` (above), `round.runner` { v, line, check, done, wave,
// phase, n, dark, waves, pulse, orderlies: [{ state "door"|"warn"|"up"|"sink"|"broken"|
// "spent", t }], chairs: [{ x, rolling }], lamps: [broken] }, `round.bonusRound.hearts`,
// `round.you` (`state`, `vy`, `ducking`), the events in EVENTS.
import { linesAt, linesOf, slopeOf, trackY } from "./ghoul-cart.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
export const ID = "codeblue";
export const MONSTERS = freeze({});
// Every event this pack puts on the field, for the art and the sounds to answer.
export const EVENTS = freeze([
"blueJump", "blueLand", "blueLaunch", "blueDuck", "blueCrash", "blueCheck", "blueFinish",
"blueWarn", "blueDark", "blueLit", "blueBeat", "blueChair",
"blueOrderlyWarn", "blueOrderlyUp", "blueOrderlyHit", "blueOrderlyBreak", "blueLamp",
]);
// The gurney. Speeds are units across a second, GRAV units a second squared.
export const GURNEY_V = 48;
export const GURNEY_MIN = 36;
export const GURNEY_MAX = 60;
export const SLOPE_G = 40;
export const RELAX = 1.5;
export const JUMP_V = 74;
export const GRAV = 200;
export const COYOTE_MS = 100;
export const RAMP_SLOPE = 0.25;
export const RAMP_POP = 30;
export const LAND_TOL = 0.9;
export const BIG_LAND = 8;
export const DERAIL_Y = 3;
export const CAM_AHEAD = 10;
export const CAM_PER_V = 0.25;
// Obstacles.
export const CHAIR_W = 3.4;
export const CHAIR_H = 3.6;
export const CHAIR_NEAR = 64;
export const CHAIR_V = 12;
export const CHAIR_MAX = 18;
export const STAND_W = 1.8;
export const STAND_H = 6.2;
export const ORDERLY_W = 2.6;
export const ORDERLY_H = 5.4;
export const ORDERLY_HP = 2;
export const ORDERLY_NEAR = 40;
export const ORDERLY_WARN_MS = 450;
export const ORDERLY_UP_MS = 1600;
export const ORDERLY_SINK_MS = 300;
export const ORDERLY_POINTS = 100;
// The surge lamp: hung high, so a bolt from the air hits it, and the points.
export const LAMP_W = 2.6;
export const SURGE_LO = 3.8;
export const SURGE_HI = 11;
export const SURGE_BACK = 70;
export const LAMP_POINTS = 150;
const SHOT_R = 0.5;
// The lights-out rhythm: the countdown's length and tick, and how fast the dark falls and lifts.
export const WARN_UNITS = 84;
export const TICK_UNITS = 28;
export const FADE_IN = 8;
export const FADE_OUT = 14;
// The heartbeat monitor: a beat every so many ms by hearts left, and the flat tone's repeat at the last.
export const BEAT_MS = freeze({ 5: 1000, 4: 780, 3: 600, 2: 440 });
export const FLAT_MS = 1600;
// The clean dark stretches die: at most this many blackouts may cost a heart.
export const WAVE_SLACK = 1;
// The shots at things (orderlies, surge lamps) worth a die.
export const ACTS_GOAL = 8;
// Notes for a bonus round that obstacle `id` cost a heart (once each), and for the grade
// that the blackout it happened in (if any) was not clean.
function noteHit(round, c, id) {
const b = round.bonusRound;
if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id);
const w = c ? c.wave : -1;
if (c && w >= 0 && c.waves[w] && !c.waves[w].hit) {
c.waves[w].hit = true;
c.hitWaves++;
if (b) b.perf.steady = c.hitWaves <= WAVE_SLACK;
}
}
const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H);
const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0;
// The highest line under x, as [line, y], or null over a shaft.
const topAt = (R, x) => linesAt(R, x)[0] || null;
// The highest line the gurney, falling from `py` to `y` at `x`, crossed going down.
function landOn(R, x, py, y) {
for (const [line, ly] of linesAt(R, x)) if (py >= ly - LAND_TOL && y <= ly) return { line, y: ly };
return null;
}
// Where a gurney in the air at (x, y) going up at vy and across at v lands, if it does
// not steer: { x, y, line } or null when it derails. The unit suite's measure of which
// shafts a jump clears.
export function flight(R, x, y, vy, v) {
const dt = 0.004;
for (let t = 0; t < 5; t += dt) {
const py = y;
vy = Math.max(-120, vy - GRAV * dt);
x += v * dt;
y += vy * dt;
if (vy <= 0) {
const f = landOn(R, x, py, y);
if (f) return { x, y: f.y, line: f.line };
}
if (y < DERAIL_Y) return null;
}
return null;
}
// The lights at x: { i, phase, n, dark }. `waves` is the runner's list (a wave called
// off is skipped). The countdown is 3, 2, 1 (n), one number every TICK_UNITS; the dark
// falls over FADE_IN from x0 and lifts over FADE_OUT before x1.
export function lightsAt(R, x, waves) {
for (let i = 0; i < R.waves.length; i++) {
const [x0, x1] = R.waves[i];
if (waves && waves[i] && waves[i].off) continue;
if (x >= x0 - WARN_UNITS && x < x0) return { i, phase: "warn", n: Math.ceil((x0 - x) / TICK_UNITS), dark: 0 };
if (x >= x0 && x < x1) return { i, phase: "dark", n: 0, dark: Math.min(1, (x - x0) / FADE_IN + 0.15, (x1 - x) / FADE_OUT) };
}
return { i: -1, phase: "lit", n: 0, dark: 0 };
}
/* -------------------------------------------------------------- placing */
// The copy of a ride's state that another pack's `place` cannot take away.
const BACK = new WeakMap();
// This ride's state, put back in the shared slot if something cleared it; null elsewhere.
function mine(round) {
const c = round.runner;
if (c && c.pack === ID) return c;
const back = BACK.get(round);
if (back && back.room === round.room && round.spec.ride && round.spec.ride.runner === ID) {
round.runner = back;
return back;
}
return null;
}
// A fresh set of the room's things, each orderly in his doorway and each chair where it
// stood. What was shot stays shot (`old`, the state of an earlier try in the same room).
function things(R, old) {
const was = (list, i, state) => (old && old[list] && old[list][i] && old[list][i].state === state ? state : null);
return {
orderlies: R.orderlies.map((o, i) => ({ state: was("orderlies", i, "broken") || "door", t: 0, hp: ORDERLY_HP })),
chairs: R.chairs.map(([x]) => ({ x, rolling: false, rolled: 0 })),
lamps: R.lamps.map((l, i) => Boolean(old && old.lamps[i])),
waves: R.waves.map((w, i) => ({ off: Boolean(old && old.waves[i].off), hit: Boolean(old && old.waves[i].hit) })),
};
}
// Planny put down in the room: on the gurney at the start of a ride, or at the last
// checkpoint passed after the last heart (the same room).
function place(round, k) {
const R = round.spec.ride;
// (The Cart's `place` runs first and has already zeroed `round.camLead`: another room's lead is not ours to touch.)
if (!R || R.runner !== ID) {
if (round.runner && round.runner.pack === ID) round.runner = null;
BACK.delete(round);
return;
}
const old = mine(round);
const again = Boolean(old && old.room === round.room);
const check = again ? old.check : -1;
const you = round.you;
const x = check >= 0 ? R.checks[check] : round.spec.start;
const top = topAt(R, x);
Object.assign(you, { x, y: top ? top[1] : you.y, vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 });
const c = { pack: ID, room: round.room, check, v: GURNEY_V, line: top ? top[0] : -1, coyote: 0, from: you.y, left: top ? top[0] : 0, done: false, wave: -1, phase: "lit", n: 0, dark: 0, hitWaves: again ? old.hitWaves : 0, beatMs: 0, pulse: 0, every: BEAT_MS[5], flat: false, ...things(R, again ? old : null) };
round.runner = c;
BACK.set(round, c);
round.camLead = CAM_AHEAD;
const b = round.bonusRound;
if (b && !b.perf.total) {
b.perf.total = R.chairs.length + R.stands.length + R.lows.length + R.orderlies.length + (R.track.length - 1);
b.perf.steady = true;
b.perf.goal = ACTS_GOAL;
}
}
/* ------------------------------------------------------------ the ride */
// After a derail that cost a heart but not the ride: Planny and the gurney go back onto
// the track nearest where they fell (the highest line under him, else the next one
// ahead) at GURNEY_V. He blinks safe (ghoul.js's takeLife).
function reseat(round, c, R) {
const you = round.you;
const under = topAt(R, you.x);
let line;
let x;
let y;
if (under) {
[line, y] = under;
x = you.x;
} else {
const ahead = linesOf(R)
.map((L, i) => ({ i, x0: L.x0 }))
.filter((L) => L.x0 > you.x)
.sort((a, b) => a.x0 - b.x0)[0];
line = ahead ? ahead.i : linesOf(R).length - 1;
x = ahead ? ahead.x0 + 2 : R.finish - 2;
y = trackY(R, line, x) ?? you.y;
}
Object.assign(you, { x, y, vy: 0, state: "run", shelf: -1, ducking: false, coyote: 0, drop: -1 });
Object.assign(c, { line, v: GURNEY_V, coyote: 0, from: y });
}
// The gurney's motion for one slice. Returns true once it has moved Planny (every slice
// of a ride); false outside a ride and once he has stepped out onto the ambulance bay.
function ride(round, ms, k) {
const R = round.spec.ride;
if (!R || R.runner !== ID) return false;
const c = mine(round);
if (!c || c.done) return false;
const you = round.you;
const inp = round.input;
const dt = ms / 1000;
const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra });
// Already down on the bay (set there, or past the lip some other way): the ride is over.
if (you.x >= R.finish && you.vy <= 0 && you.y <= k.groundAt(round.spec, you.x) + 0.01) return finish(round, c, R, k.groundAt(round.spec, you.x));
// A stomp's bounce (or anything else) lifts the gurney off its line.
if (you.state === "air" && c.line >= 0) {
c.left = c.line;
c.line = -1;
c.coyote = 0;
c.from = you.y;
}
steerShots(round, R);
const want = inp.jump > 0;
if (c.line >= 0) {
// On the floor.
const slope = slopeOf(R, c.line, you.x);
c.v = clamp(c.v + ((GURNEY_V - c.v) * RELAX - SLOPE_G * slope) * dt, GURNEY_MIN, GURNEY_MAX);
const duck = Boolean(inp.down) && !want;
if (duck && !you.ducking) ev("blueDuck");
you.ducking = duck;
if (want) {
inp.jump = 0;
you.vy = JUMP_V + slope * c.v;
Object.assign(c, { left: c.line, line: -1, coyote: 0, from: you.y });
you.state = "air";
you.ducking = false;
ev("blueJump", { v: c.v });
} else {
const L = linesOf(R)[c.line];
const nx = you.x + c.v * dt;
you.state = "run";
you.vy = 0;
if (nx >= L.x1) {
// Off the end of the line, on along its last slope.
const end = L.pts[L.pts.length - 1];
const rise = slopeOf(R, c.line, L.x1);
you.x = L.x1;
you.y = end[1];
const ramp = rise >= RAMP_SLOPE;
you.vy = rise * c.v + (ramp ? RAMP_POP : 0);
Object.assign(c, { left: c.line, line: -1, coyote: COYOTE_MS, from: you.y });
you.state = "air";
you.ducking = false;
if (ramp) ev("blueLaunch", { v: c.v, last: c.left === linesOf(R).length - 1 });
} else {
you.x = nx;
you.y = trackY(R, c.line, nx);
}
}
} else {
// In the air.
c.coyote = Math.max(0, c.coyote - ms);
if (want && c.coyote > 0) {
inp.jump = 0;
c.coyote = 0;
you.vy = JUMP_V;
c.from = you.y;
ev("blueJump", { v: c.v });
}
const py = you.y;
you.vy = Math.max(-k.FALL_MAX, you.vy - GRAV * dt);
you.x += c.v * dt;
you.y += you.vy * dt;
you.ducking = false;
you.state = "air";
if (you.vy <= 0) {
const f = landOn(R, you.x, py, you.y);
if (f) {
you.y = f.y;
you.vy = 0;
you.state = "run";
c.line = f.line;
ev("blueLand", { big: c.from - f.y >= BIG_LAND });
c.from = f.y;
} else if (you.x >= R.finish) {
// Over the bay at the end: down onto it, and the ride is over.
const g = k.groundAt(round.spec, you.x);
if (g > -Infinity && you.y <= g + 0.01) return finish(round, c, R, g);
}
}
}
// A press nothing took waits a moment for a landing, then goes.
if (want && inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms);
// Past the end of the world: a shaft, or the face of the bay.
if (you.y < DERAIL_Y || k.groundAt(round.spec, you.x) > you.y + 0.5) {
noteHit(round, c, `k${c.left}`);
if (k.lose(round, "elevator") && round.phase === "play") reseat(round, c, R);
return true;
}
while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) {
c.check++;
ev("blueCheck", { n: c.check + 1 });
}
round.camLead = CAM_AHEAD + (c.v - GURNEY_V) * CAM_PER_V;
blackout(round, c, R);
heartbeat(round, c, ms);
if (obstacles(round, c, R, k)) return true;
creatures(round, c, R, ms);
return true;
}
// The ride is over: the gurney halts on the bay, the door opens, Planny walks out.
function finish(round, c, R, g) {
const you = round.you;
c.done = true;
c.restX = you.x;
c.wave = -1;
c.phase = "lit";
c.n = 0;
c.dark = 0;
Object.assign(you, { y: g, vy: 0, state: "run", shelf: -1, ducking: false });
round.hasKey = true;
round.camLead = 0;
round.events.push({ type: "blueFinish", x: you.x, y: you.y, big: c.from - g >= BIG_LAND });
return false;
}
// A bolt flies parallel to the track under it, whatever way he aimed (`s.off`): the
// floor rises and falls, and a level bolt would miss a surge lamp or a lunging orderly on a ramp.
function steerShots(round, R) {
for (const s of round.shots) {
if (s.arm || s.free) continue;
if (s.off === undefined) s.off = s.vy;
const top = topAt(R, s.x);
if (top) s.sl = slopeOf(R, top[0], s.x);
s.vy = s.vx * (s.sl ?? 0) + s.off;
}
}
/* ------------------------------------------------------ the lights, the beat */
// The blackout's state for where the gurney is: the countdown's ticks, the dark falling
// and lifting, each an event for the sounds and the art.
function blackout(round, c, R) {
const you = round.you;
const now = lightsAt(R, you.x, c.waves);
const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra });
if (now.phase === "warn" && (c.phase !== "warn" || c.n !== now.n)) ev("blueWarn", { n: now.n, wave: now.i });
if (now.phase === "dark" && c.phase !== "dark") ev("blueDark", { wave: now.i });
if (now.phase === "lit" && c.phase === "dark") ev("blueLit", { wave: c.wave });
if (now.phase === "warn" && c.phase === "dark") ev("blueLit", { wave: c.wave });
c.wave = now.i;
c.phase = now.phase;
c.n = now.n;
c.dark = now.dark;
}
// The heartbeat monitor: a beat every BEAT_MS[hearts] ms, quicker the fewer hearts are left,
// and a flat tone at the last heart. `pulse` (0..1) is where the sweep is in its beat.
function heartbeat(round, c, ms) {
const b = round.bonusRound;
const hearts = b ? b.hearts : 5;
const flat = hearts <= 1;
const every = flat ? FLAT_MS : BEAT_MS[clamp(hearts, 2, 5)];
c.beatMs += ms;
if (c.beatMs >= every) {
c.beatMs -= every;
round.events.push({ type: "blueBeat", x: round.you.x, y: round.you.y, flat, hearts, bpm: Math.round(60000 / every) });
}
c.every = every;
c.flat = flat;
c.pulse = Math.min(1, c.beatMs / every);
}
/* ----------------------------------------------------------- obstacles */
// What the gurney runs into: a wheelchair, an IV stand, a lamp or a door overhead, an
// orderly. Returns whether it cost a heart.
function obstacles(round, c, R, k) {
const you = round.you;
const hh = duckH(k, you);
for (const [i, [x0, x1, y]] of R.lows.entries()) {
if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > y && k.struck(round, "overhead")) {
noteHit(round, c, `l${i}`);
round.events.push({ type: "blueCrash", what: "low", x: you.x, y: you.y + hh });
return true;
}
}
for (const [i, [, line]] of R.chairs.entries()) {
const x = c.chairs[i].x;
if (Math.abs(you.x - x) > 6) continue;
if (boxHit(k, you, x, trackY(R, line, x), CHAIR_W, CHAIR_H) && k.struck(round, "wheelchair")) {
noteHit(round, c, `c${i}`);
round.events.push({ type: "blueCrash", what: "chair", x, y: you.y });
return true;
}
}
for (const [i, [x, line]] of R.stands.entries()) {
if (Math.abs(you.x - x) > 6) continue;
if (boxHit(k, you, x, trackY(R, line, x), STAND_W, STAND_H) && k.struck(round, "ivstand")) {
noteHit(round, c, `s${i}`);
round.events.push({ type: "blueCrash", what: "stand", x, y: you.y });
return true;
}
}
for (const [i, [x, line]] of R.orderlies.entries()) {
const o = c.orderlies[i];
if (o.state !== "up" || Math.abs(you.x - x) > 5) continue;
if (boxHit(k, you, x, trackY(R, line, x), ORDERLY_W, ORDERLY_H) && k.struck(round, "lunged")) {
noteHit(round, c, `o${i}`);
round.events.push({ type: "blueCrash", what: "orderly", x, y: you.y });
Object.assign(o, { state: "sink", t: ORDERLY_SINK_MS });
return true;
}
}
return false;
}
// The wheelchairs set rolling at the gurney, and the orderlies' doors that burst open, when it comes near.
function creatures(round, c, R, ms) {
const you = round.you;
const dt = ms / 1000;
R.chairs.forEach(([x0, line], i) => {
const ch = c.chairs[i];
if (!ch.rolling) {
const ahead = ch.x - you.x;
if (ahead < CHAIR_NEAR && ahead > -CHAIR_W) {
ch.rolling = true;
round.events.push({ type: "blueChair", x: ch.x, y: trackY(R, line, ch.x) });
}
} else {
ch.rolled = Math.min(CHAIR_MAX, ch.rolled + CHAIR_V * dt);
ch.x = x0 - ch.rolled;
}
});
R.orderlies.forEach(([x, line], i) => {
const o = c.orderlies[i];
const y = trackY(R, line, x);
if (o.state === "door") {
const ahead = x - you.x;
if (ahead < ORDERLY_NEAR && ahead > -ORDERLY_W) {
Object.assign(o, { state: "warn", t: ORDERLY_WARN_MS });
round.events.push({ type: "blueOrderlyWarn", x, y });
}
} else if (o.state === "warn" || o.state === "up" || o.state === "sink") {
o.t -= ms;
if (o.t > 0) return;
if (o.state === "warn") {
Object.assign(o, { state: "up", t: ORDERLY_UP_MS });
round.events.push({ type: "blueOrderlyUp", x, y });
} else if (o.state === "up") Object.assign(o, { state: "sink", t: ORDERLY_SINK_MS });
else Object.assign(o, { state: "spent", t: 0 });
}
});
}
/* ------------------------------------------------------------- targets */
// A bolt into something to shoot: an orderly lunging from his doorway, a surge lamp. True
// when one took it (the bolt is spent). A lamp shorted out calls its blackout off.
function gurneyShot(round, s) {
const R = round.spec.ride;
if (!R || R.runner !== ID) return false;
const c = mine(round);
if (!c) return false;
const hit = (x, y0, w, h) => Math.abs(s.x - x) <= w / 2 + SHOT_R && s.y >= y0 - SHOT_R && s.y <= y0 + h + SHOT_R;
const score = (n) => {
round.score += n;
if (round.bonusRound) round.bonusRound.perf.acts++;
};
for (let i = 0; i < R.orderlies.length; i++) {
const o = c.orderlies[i];
const [x, line] = R.orderlies[i];
const y = trackY(R, line, x);
if (o.state !== "up" || !hit(x, y, ORDERLY_W, ORDERLY_H)) continue;
o.hp--;
if (o.hp > 0) round.events.push({ type: "blueOrderlyHit", x, y: y + ORDERLY_H / 2 });
else {
Object.assign(o, { state: "broken", t: 0 });
score(ORDERLY_POINTS);
round.events.push({ type: "blueOrderlyBreak", x, y: y + ORDERLY_H / 2, points: ORDERLY_POINTS });
}
return true;
}
for (let i = 0; i < R.lamps.length; i++) {
if (c.lamps[i]) continue;
const [x, line] = R.lamps[i];
const y = trackY(R, line, x);
if (!hit(x, y + SURGE_LO, LAMP_W, SURGE_HI - SURGE_LO)) continue;
c.lamps[i] = true;
c.waves[i].off = true;
score(LAMP_POINTS);
round.events.push({ type: "blueLamp", x, y: y + (SURGE_LO + SURGE_HI) / 2, points: LAMP_POINTS, wave: i });
return true;
}
return false;
}
export const GURNEY = freeze({
id: ID,
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
horde: freeze({}),
ride: freeze([ride]),
place: freeze([place]),
target: gurneyShot,
});
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,503 @@
// Plan2Code Web Console - Ghoul Rush's Midnight Hearse, its rules: the Graveyard's bonus round. YOU hijack a runaway black hearse, horse-less and haunted, and tear along the cemetery road at night with the coffins rattling in the back: jump the open graves, headstones and fallen crosses, duck the low branches and the lychgate arch, shoot the grasping hands and the carrion crows, switch between the road and the grass verge at the lane gates, and keep the lamp lit. As a stage pack that ghoul.js plugs in.
//
// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it, handed a
// kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js. Pack fields used:
// `ride` (a hook that moves Planny himself, so no key walks him), `place` (Planny put
// down in a room: a room set up or a respawn) and `target` (a bolt strikes something that
// is no monster: the hands, the crows and the ghouls out of the coffins). It adds no
// monster, boss or hazard kind, so there is nothing to merge by name, and it draws NO
// random number. Its state is `round.runner` (the shared slot for a rolling bonus ride,
// with `id: "hearse"`; null in any other room) and the room's `ride.runner` is "hearse".
//
// THE ROOM (spec.ride, see ghoul-rooms.js): the ground is one flat road; there are two
// LANES, the road (lane 0, LANE_Y[0]) and the grass verge beside it (lane 1, LANE_Y[1],
// a raised bank), and every obstacle stands in one of them, [x, lane, ...]:
//
// - `graves` [x, lane]: an open grave, GRAVE_W wide (jump it, or fall in: cause "grave").
// - `stones` [x, lane, kind]: kind 0 a leaning headstone (STONE_W by STONE_H, cause "tomb"),
// kind 1 a fallen cross (CROSS_W by CROSS_H, cause "cross"); jump.
// - `lows` [x0, x1, lane, kind]: a low branch (kind 0) or the lychgate arch (kind 1); its
// underside is LOW_Y over the lane, so DUCK it (cause "branch").
// - `hands` [x, lane]: a hand grasping out of a grave mound; stirs when the hearse is
// HAND_NEAR short, shivers HAND_WARN_MS, reaches HAND_UP_MS (HAND_W by HAND_H): jump it
// or shoot it (HAND_HP bolts; cause "grasp").
// - `crows` [x, lane, h]: a carrion crow perched at x; when the hearse is CROW_NEAR short
// it takes wing and flies back at the hearse at CROW_V, CROW_W by CROW_H, its underside
// `h` over the lane (h over a ducked box, under a standing one): duck it, jump it, or
// shoot it, one bolt (cause "crow"). Its x is where it perches: it meets the hearse
// about CROW_NEAR * V / (V + CROW_V) short of that.
// - `blocks` [x0, x1, lane]: a stretch of the lane that is closed (a fallen oak across the
// road, a hedge wall on the verge): the hearse cannot get through. Go round by the lane
// gate before it, or smash in (cause "wreck", a heart) and be thrown into the other lane.
// - `gates` [x0, x1]: the lane gates; inside one, LEFT puts the hearse on the road and RIGHT
// on the verge (SWITCH_MS to hop the curb). Nothing stands in a lane near a gate.
// - `lanterns` [x, lane]: a hanging lantern the hearse takes by passing it (not ducking is
// no matter, a jump over it is: LANTERN_TOP) for LANTERN_GAIN of lamp.
// - `fog` [x0, x1]: a fog bank: the lamp burns faster in it and the art draws it thick.
// - `checks` (x positions of the checkpoints), `finish` (where the ride ends: the hearse
// brakes and Planny walks out to the door) and `time` (the room's clock, ms).
//
// THE HEARSE (`round.runner`): { id, room, check, lane (where it is bound), from (the lane
// it left), swMs (switch time left), h (height over the lane), air, v, lamp, out, broken,
// coffins, lit, hands, crows, sitters, faced, done, restX }. It runs at HEARSE_V whatever
// is pressed; up jumps at JUMP_V against GRAVITY (about 13 high, 0.75 s, 31 across); down
// ducks; a switch cannot be made in the air and a jump or a duck cannot be made in one.
// A bolt flies level.
//
// THE LAMP: it starts at LAMP_MAX, burns down LAMP_DRAIN a second (and LAMP_FOG more in
// the fog), and each lantern gives LANTERN_GAIN. At nothing it goes OUT (`out`,
// `broken`): the night closes in (the art dims the room and the signs fade) until the
// next lantern. A lamp that never went out is the grade's `steady` die.
//
// THE COFFINS: five in the back (COFFINS). Each hit that costs a heart throws one out
// ahead: it lands SIT_AHEAD on in the lane the hearse is in, the lid pops and a ghoul
// sits up; shoot it for SIT_POINTS (it never hurts; it ducks back down as the hearse
// reaches it or after SIT_MS). A hearse with none left throws no more.
//
// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the
// hearse rolls on, Planny blinking safe BONUS_SAFE_MS; the last heart gone ends the round
// with nothing, at once. Causes: "grave", "tomb", "cross", "branch", "grasp", "crow",
// "wreck". The grade's `perf.total` is the obstacles the hearse FACED (passed in their
// lane; a lane switched away from is dodged and not counted), each id once in
// `perf.hits` if it ever cost a heart. Shooting a hand, a crow or a sitter counts for
// `perf.acts` (the goal is ACTS_GOAL, 8 of them) and the points below.
//
// Checkpoints are passed at their x (`hearseCheck`); a restart after the last heart goes
// back to the last one passed (that ends the round, as the sled's does).
//
// WHAT THE ART READS: `spec.ride` (above), `round.runner` { lane, from, swMs, h, air, lamp,
// out, fog, coffins, lit, done, restX, check, hands: [{ state "mound"|"warn"|"up"|"sink"|
// "broken"|"spent", t }], crows: [{ state "perch"|"fly"|"gone"|"broken", x }], sitters: [{
// x, ox, lane, state "fly"|"sit"|"hid"|"broken", t }] }, `round.you` (`state`, `vy`,
// `ducking`), the events in EVENTS.
const freeze = (o) => Object.freeze(o);
export const MONSTERS = freeze({});
// Every event this pack puts on the field, for the art and the sounds to answer.
export const EVENTS = freeze([
"hearseJump", "hearseLand", "hearseDuck", "hearseSwitch", "hearseCrash", "hearseCheck", "hearseFinish",
"hearseHandWarn", "hearseHandUp", "hearseHandHit", "hearseHandBreak", "hearseCrowWake", "hearseCrowHit",
"hearseLantern", "hearseLampOut", "hearseLampLit", "hearseCoffin", "hearseSitUp", "hearseSitHit",
]);
// The hearse. Speeds are units across a second, GRAVITY units a second squared.
export const HEARSE_V = 42;
export const JUMP_V = 74;
export const GRAVITY = 200;
export const BIG_LAND = 9;
export const LANE_Y = freeze([9, 15]);
export const SWITCH_MS = 360;
export const SWITCH_HOP = 1.6;
export const CAM_AHEAD = 12;
// Obstacles.
export const GRAVE_W = 10;
export const GRAVE_DEEP = 1.2;
export const STONE_W = 2.6;
export const STONE_H = 4.4;
export const CROSS_W = 5.4;
export const CROSS_H = 1.8;
export const LOW_Y = 3.0;
export const HAND_W = 2.6;
export const HAND_H = 3.6;
export const HAND_HP = 2;
export const HAND_NEAR = 34;
export const HAND_WARN_MS = 450;
export const HAND_UP_MS = 1600;
export const HAND_SINK_MS = 300;
export const CROW_W = 2.2;
export const CROW_H = 1.6;
export const CROW_NEAR = 56;
export const CROW_V = 18;
// Points for what is shot.
export const HAND_POINTS = 100;
export const CROW_POINTS = 80;
export const SIT_POINTS = 150;
export const LANTERN_POINTS = 25;
const SHOT_R = 0.5;
// The lamp.
export const LAMP_MAX = 100;
export const LAMP_DRAIN = 2.2;
export const LAMP_FOG = 2;
export const LANTERN_GAIN = 22;
export const LANTERN_R = 2.2;
export const LANTERN_TOP = 7;
// The coffins in the back, and the ghoul out of each.
export const COFFINS = 5;
export const FLY_MS = 600;
export const SIT_AHEAD = 56;
export const SIT_MS = 3000;
export const SIT_RISE_MS = 250;
export const SIT_W = 2.8;
export const SIT_H = 4.4;
// The shots at things (hands, crows, sitters) worth a die.
export const ACTS_GOAL = 8;
const mine = (round) => (round.runner && round.runner.id === "hearse" ? round.runner : null);
const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H);
const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0;
const smooth = (p) => p * p * (3 - 2 * p);
// The lane the hearse counts as being in: the one it left until half way through a switch.
export const laneNow = (c) => (c.swMs > 0 && 1 - c.swMs / SWITCH_MS < 0.5 ? c.from : c.lane);
// The height of the road under the hearse (its lane's, eased across a switch, with a little hop).
export function baseOf(c) {
if (c.swMs <= 0) return LANE_Y[c.lane];
const p = 1 - c.swMs / SWITCH_MS;
return LANE_Y[c.from] + (LANE_Y[c.lane] - LANE_Y[c.from]) * smooth(p) + Math.sin(p * Math.PI) * SWITCH_HOP;
}
// Notes for a bonus round that obstacle `id` was faced (counted for the grade) and, with
// `cost`, that it cost a heart (once each).
function face(round, c, id, cost = false) {
const b = round.bonusRound;
if (!b) return;
if (!c.faced[id]) {
c.faced[id] = true;
b.perf.total++;
}
if (cost && !b.perf.hits.includes(id)) b.perf.hits.push(id);
}
/* -------------------------------------------------------------- placing */
// A fresh set of the room's things, each hand in its mound and each crow perched. What was
// shot stays shot, and a lantern taken stays taken (`old`, the hearse of an earlier try in
// the same room).
function things(R, old) {
const was = (list, i, state) => (old && old[list] && old[list][i] && old[list][i].state === state ? state : null);
return {
hands: R.hands.map((h, i) => ({ state: was("hands", i, "broken") || "mound", t: 0, hp: HAND_HP })),
crows: R.crows.map(([x], i) => ({ state: was("crows", i, "broken") || "perch", x })),
lit: R.lanterns.map((l, i) => Boolean(old && old.lit[i])),
};
}
// Planny put down in the room: at the wheel at the start of a ride, or at the last
// checkpoint passed after the last heart (the same room).
function place(round, k) {
const R = round.spec.ride;
// (The Cart's `place` runs first, leaves a ride with a `runner` alone and has already zeroed `round.camLead`.)
if (!R || R.runner !== "hearse") {
if (mine(round)) round.runner = null;
return;
}
const old = mine(round);
const again = old && old.room === round.room;
const check = again ? old.check : -1;
const you = round.you;
const x = check >= 0 ? R.checks[check] : round.spec.start;
Object.assign(you, { x, y: LANE_Y[0], vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 });
round.runner = {
id: "hearse", room: round.room, check, lane: 0, from: 0, swMs: 0, h: 0, air: false, peak: 0, v: HEARSE_V,
lamp: again ? old.lamp : LAMP_MAX, out: false, broken: again ? old.broken : false, fog: false, coffins: again ? old.coffins : COFFINS,
sitters: [], faced: again ? old.faced : {}, wasDown: false, done: false, restX: 0, ...things(R, again ? old : null),
};
round.camLead = CAM_AHEAD;
const b = round.bonusRound;
if (b) {
b.perf.goal = ACTS_GOAL;
if (!again) b.perf.total = 0;
}
if (b && round.runner.broken) b.perf.steady = false;
}
/* ------------------------------------------------------------ the ride */
// The hearse's motion for one slice. Returns true once it has moved Planny (every slice of
// a ride); false outside a ride and once he has stepped out.
function ride(round, ms, k) {
const R = round.spec.ride;
const c = mine(round);
if (!R || R.runner !== "hearse" || !c || c.done) return false;
const you = round.you;
const inp = round.input;
const dt = ms / 1000;
const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra });
if (you.x >= R.finish) return finish(round, c, R, k);
you.x += HEARSE_V * dt;
// The lane gates: LEFT is the road, RIGHT the verge.
const want = inp.left && !inp.right ? 0 : inp.right && !inp.left ? 1 : -1;
const gate = R.gates.some(([a, b]) => you.x >= a && you.x <= b);
if (gate && !c.air && c.swMs <= 0 && want >= 0 && want !== c.lane) startSwitch(c, want, ev, you);
if (c.swMs > 0) {
c.swMs = Math.max(0, c.swMs - ms);
you.ducking = false;
you.state = "run";
you.vy = 0;
} else {
// On the road: jump, duck, or in the air.
const jump = inp.jump > 0;
if (!c.air && jump) {
inp.jump = 0;
c.air = true;
c.h = 0.001;
c.vy = JUMP_V;
c.peak = 0;
you.ducking = false;
ev("hearseJump");
} else if (!c.air) {
const duck = Boolean(inp.down);
if (duck && !you.ducking) ev("hearseDuck");
you.ducking = duck;
}
if (c.air) {
c.vy -= GRAVITY * dt;
c.h += c.vy * dt;
c.peak = Math.max(c.peak, c.h);
you.ducking = false;
if (c.h <= 0) {
ev("hearseLand", { big: c.peak >= BIG_LAND });
Object.assign(c, { air: false, h: 0, vy: 0 });
}
}
you.state = c.air ? "air" : "run";
you.vy = c.air ? c.vy : 0;
}
you.y = baseOf(c) + (c.swMs > 0 ? 0 : c.h);
// A press nothing took waits a moment for a landing, then goes.
if (inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms);
while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) {
c.check++;
ev("hearseCheck", { n: c.check + 1 });
}
round.camLead = CAM_AHEAD;
lamp(round, c, R, ms, ev);
if (obstacles(round, c, R, k)) return true;
creatures(round, c, R, ms);
return true;
}
function startSwitch(c, to, ev, you) {
Object.assign(c, { from: c.lane, lane: to, swMs: SWITCH_MS, air: false, h: 0, vy: 0 });
ev("hearseSwitch", { to, y: LANE_Y[to], x: you.x });
}
// The ride is over: the hearse brakes at the finish, the door opens, Planny walks out.
function finish(round, c, R, k) {
const you = round.you;
c.done = true;
c.restX = you.x;
Object.assign(c, { air: false, h: 0, vy: 0, swMs: 0 });
Object.assign(you, { y: k.groundAt(round.spec, you.x), vy: 0, state: "run", shelf: -1, ducking: false });
round.hasKey = true;
round.camLead = 0;
round.events.push({ type: "hearseFinish", x: you.x, y: you.y });
return false;
}
// The lamp burns down (faster in the fog), a lantern passed gives it back, and one that
// goes out leaves the night closed in until the next.
function lamp(round, c, R, ms, ev) {
const you = round.you;
const dt = ms / 1000;
const b = round.bonusRound;
c.fog = R.fog.some(([a, z]) => you.x >= a && you.x <= z);
c.lamp = Math.max(0, c.lamp - (LAMP_DRAIN + (c.fog ? LAMP_FOG : 0)) * dt);
if (c.lamp <= 0 && !c.out) {
c.out = true;
c.broken = true;
if (b) b.perf.steady = false;
ev("hearseLampOut");
}
const lane = laneNow(c);
R.lanterns.forEach(([x, l], i) => {
if (c.lit[i] || l !== lane || Math.abs(you.x - x) > LANTERN_R || you.y > LANE_Y[l] + LANTERN_TOP) return;
c.lit[i] = true;
c.lamp = Math.min(LAMP_MAX, c.lamp + LANTERN_GAIN);
round.score += LANTERN_POINTS;
ev("hearseLantern", { x, y: LANE_Y[l] + 3.4, points: LANTERN_POINTS });
if (c.out) {
c.out = false;
ev("hearseLampLit");
}
});
}
// A heart lost on obstacle `id`: it was faced and cost, a coffin flies out ahead, and the
// crash is an event. Returns true.
function cost(round, c, id, what, x) {
face(round, c, id, true);
round.events.push({ type: "hearseCrash", what, x, y: round.you.y });
if (c.coffins > 0) {
c.coffins--;
const lane = laneNow(c);
const tx = round.you.x + SIT_AHEAD;
c.sitters.push({ x: tx, ox: round.you.x, lane, state: "fly", t: FLY_MS });
round.events.push({ type: "hearseCoffin", x: round.you.x - 4, y: round.you.y + 3, tx, lane, left: c.coffins });
}
return true;
}
// What the hearse runs into: a grave, a headstone or a cross, a low branch or the arch, a
// hand, a crow, a closed stretch. Returns whether it cost a heart. (Nothing counts while it
// hops between lanes: the lanes' gates keep their neighborhood clear.)
function obstacles(round, c, R, k) {
const you = round.you;
if (c.swMs > 0) return false;
const lane = c.lane;
const base = LANE_Y[lane];
const hh = duckH(k, you);
const seen = (id, x) => {
if (you.x >= x && !c.faced[id]) face(round, c, id);
};
for (const [i, [x, l]] of R.graves.entries()) {
if (l !== lane) continue;
seen(`g${i}`, x);
if (Math.abs(you.x - x) < GRAVE_W / 2 - 1 && you.y < base + GRAVE_DEEP && k.struck(round, "grave")) return cost(round, c, `g${i}`, "grave", x);
}
for (const [i, [x, l, kind]] of R.stones.entries()) {
if (l !== lane) continue;
seen(`s${i}`, x);
if (Math.abs(you.x - x) > 6) continue;
if (boxHit(k, you, x, base, kind ? CROSS_W : STONE_W, kind ? CROSS_H : STONE_H) && k.struck(round, kind ? "cross" : "tomb")) return cost(round, c, `s${i}`, kind ? "cross" : "stone", x);
}
for (const [i, [x0, x1, l]] of R.lows.entries()) {
if (l !== lane) continue;
seen(`l${i}`, (x0 + x1) / 2);
if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > base + LOW_Y && k.struck(round, "branch")) return cost(round, c, `l${i}`, "low", you.x);
}
for (const [i, [x, l]] of R.hands.entries()) {
const h = c.hands[i];
if (l !== lane) continue;
seen(`h${i}`, x);
if (h.state !== "up" || Math.abs(you.x - x) > 5) continue;
if (boxHit(k, you, x, base, HAND_W, HAND_H) && k.struck(round, "grasp")) {
Object.assign(h, { state: "sink", t: HAND_SINK_MS });
return cost(round, c, `h${i}`, "hand", x);
}
}
for (const [i, [, l, up]] of R.crows.entries()) {
const w = c.crows[i];
if (l !== lane || w.state !== "fly") continue;
seen(`c${i}`, w.x);
if (boxHit(k, you, w.x, base + up, CROW_W, CROW_H) && k.struck(round, "crow")) {
w.state = "gone";
return cost(round, c, `c${i}`, "crow", w.x);
}
}
for (const [i, [x0, x1, l]] of R.blocks.entries()) {
if (l !== lane) continue;
face(round, c, `b${i}`);
if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2) {
// Thrown across into the other lane, a heart lighter (unless safe a moment).
const hit = k.struck(round, "wreck");
startSwitch(c, 1 - lane, (type, extra) => round.events.push({ type, x: you.x, y: you.y, ...extra }), you);
if (hit) return cost(round, c, `b${i}`, "wreck", you.x);
return false;
}
}
return false;
}
// The hands in their mounds, the crows on their perches and the ghouls out of the coffins wake
// as the hearse comes near.
function creatures(round, c, R, ms) {
const you = round.you;
const dt = ms / 1000;
R.hands.forEach(([x, lane], i) => {
const h = c.hands[i];
const y = LANE_Y[lane];
if (h.state === "mound") {
const ahead = x - you.x;
if (ahead < HAND_NEAR && ahead > -HAND_W) {
Object.assign(h, { state: "warn", t: HAND_WARN_MS });
round.events.push({ type: "hearseHandWarn", x, y });
}
} else if (h.state === "warn" || h.state === "up" || h.state === "sink") {
h.t -= ms;
if (h.t > 0) return;
if (h.state === "warn") {
Object.assign(h, { state: "up", t: HAND_UP_MS });
round.events.push({ type: "hearseHandUp", x, y });
} else if (h.state === "up") Object.assign(h, { state: "sink", t: HAND_SINK_MS });
else Object.assign(h, { state: "spent", t: 0 });
}
});
R.crows.forEach(([x, lane, up], i) => {
const w = c.crows[i];
if (w.state === "perch") {
if (x - you.x < CROW_NEAR && x - you.x > -CROW_W) {
w.state = "fly";
round.events.push({ type: "hearseCrowWake", x, y: LANE_Y[lane] + up });
}
} else if (w.state === "fly") {
w.x -= CROW_V * dt;
if (w.x < you.x - 16) w.state = "gone";
}
});
for (const s of c.sitters) {
if (s.state === "fly") {
s.t -= ms;
if (s.t <= 0) {
Object.assign(s, { state: "sit", t: SIT_MS });
round.events.push({ type: "hearseSitUp", x: s.x, y: LANE_Y[s.lane] });
}
} else if (s.state === "sit") {
s.t -= ms;
if (s.t <= 0 || you.x > s.x - 3) s.state = "hid";
}
}
}
/* ------------------------------------------------------------- targets */
// A bolt into something to shoot: a hand reaching out, a crow, a ghoul sat up out of a
// coffin. True when one took it (the bolt is spent).
function hearseShot(round, s) {
const R = round.spec.ride;
const c = mine(round);
if (!R || R.runner !== "hearse" || !c) return false;
const hit = (x, y0, w, h) => Math.abs(s.x - x) <= w / 2 + SHOT_R && s.y >= y0 - SHOT_R && s.y <= y0 + h + SHOT_R;
const score = (n) => {
round.score += n;
if (round.bonusRound) round.bonusRound.perf.acts++;
};
for (let i = 0; i < R.hands.length; i++) {
const h = c.hands[i];
const [x, lane] = R.hands[i];
const y = LANE_Y[lane];
if (h.state !== "up" || !hit(x, y, HAND_W, HAND_H)) continue;
h.hp--;
if (h.hp > 0) round.events.push({ type: "hearseHandHit", x, y: y + HAND_H / 2 });
else {
Object.assign(h, { state: "broken", t: 0 });
score(HAND_POINTS);
round.events.push({ type: "hearseHandBreak", x, y: y + HAND_H / 2, points: HAND_POINTS });
}
return true;
}
for (let i = 0; i < R.crows.length; i++) {
const w = c.crows[i];
const [, lane, up] = R.crows[i];
if ((w.state !== "fly" && w.state !== "perch") || !hit(w.x, LANE_Y[lane] + up, CROW_W, CROW_H)) continue;
w.state = "broken";
score(CROW_POINTS);
round.events.push({ type: "hearseCrowHit", x: w.x, y: LANE_Y[lane] + up + CROW_H / 2, points: CROW_POINTS });
return true;
}
for (const p of c.sitters) {
if (p.state !== "sit" || SIT_MS - p.t < SIT_RISE_MS || !hit(p.x, LANE_Y[p.lane], SIT_W, SIT_H)) continue;
p.state = "broken";
score(SIT_POINTS);
round.events.push({ type: "hearseSitHit", x: p.x, y: LANE_Y[p.lane] + SIT_H / 2, points: SIT_POINTS });
return true;
}
return false;
}
export const HEARSE = freeze({
id: "hearse",
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
horde: freeze({}),
ride: freeze([ride]),
place: freeze([place]),
target: hearseShot,
});
@@ -0,0 +1,336 @@
// Plan2Code Web Console - Ghoul Rush's stage intro card: a full-field title card with the stage's name in big colored letters dropping in one by one and then glowing, a small themed flourish drawn with canvas shapes (frost crystals, bunting, pickaxe sparks, drifting leaves, candle flames, ...), a few lines of flavor text fading in, the boss's name and a hint to press a key.
//
// ghoul-draw.js plugs it in, the way it plugs in ghoul-gameover-draw.js:
// introArt(d) takes its drawing helpers (`d`: label, GOLD, BONE) and hands back
// `(ctx, v)`, drawn over the whole field while `round.phase === "intro"` (also
// while paused). `round.introMs` is how long the card has been up (it stops with
// the game, so a pause holds the animation). The words and colors live in
// ghoul-intros.js. Field units (96 by 54), y counted down from the field's top.
import { INTRO_MIN_MS } from "./ghoul-run.js";
import { introFor } from "./ghoul-intros.js";
export const INTRO_HINT = "Press any move key or fire to enter";
export const TITLE_SIZE = 5.6;
export const LINE_SIZE = 2.3;
const DROP_MS = 520;
const STAGGER_MS = 70;
const TAU = Math.PI * 2;
// How wide a letter runs, in ems: narrow, wide, and the rest.
const advance = (ch) => (" .,:;'!iIjl".includes(ch) ? 0.36 : "mwMW".includes(ch) ? 0.95 : 0.66);
// The title's letters: x offsets from its middle, and the size that keeps it inside `max` units.
export function titleLayout(title, max = 88) {
const em = [...title].reduce((s, ch) => s + advance(ch), 0);
const size = Math.min(TITLE_SIZE, max / em);
let x = -(em * size) / 2;
const xs = [...title].map((ch) => {
const at = x + (advance(ch) * size) / 2;
x += advance(ch) * size;
return at;
});
return { size, xs };
}
// A letter's height above its rest `t` ms after it began to fall: 1 high up, 0 at rest, one small bounce.
export function dropAt(t) {
if (t <= 0) return 1;
if (t >= DROP_MS) return 0;
const p = t / DROP_MS;
if (p < 0.6) return 1 - (p / 0.6) ** 2;
return Math.sin(((p - 0.6) / 0.4) * Math.PI) * 0.14;
}
// A steady pseudo-random number in [0, 1) for item `i` and a salt.
export const rnd = (i, salt = 0) => {
const x = Math.sin(i * 12.9898 + salt * 78.233) * 43758.5453;
return x - Math.floor(x);
};
export const poly = (ctx, pts, fill) => {
ctx.beginPath();
pts.forEach(([x, y], i) => (i ? ctx.lineTo(x, y) : ctx.moveTo(x, y)));
ctx.closePath();
ctx.fillStyle = fill;
ctx.fill();
};
export const dot = (ctx, x, y, r, fill) => {
ctx.beginPath();
ctx.arc(x, y, Math.max(0.05, r), 0, TAU);
ctx.fillStyle = fill;
ctx.fill();
};
export const stroke = (ctx, x1, y1, x2, y2, color, w) => {
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.strokeStyle = color;
ctx.lineWidth = w;
ctx.stroke();
};
// Draws `fn` at `alpha` times the alpha it was called with.
export const faint = (ctx, alpha, fn) => {
const was = ctx.globalAlpha;
ctx.globalAlpha = was * Math.max(0, Math.min(1, alpha));
fn();
ctx.globalAlpha = was;
};
// A flame: a teardrop of height h at (x, y), wavering.
export const flame = (ctx, x, y, h, t, i, color) => {
const sway = Math.sin(t / 120 + i * 2) * h * 0.18;
const hh = h * (0.9 + 0.1 * Math.sin(t / 90 + i));
ctx.beginPath();
ctx.moveTo(x, y);
ctx.quadraticCurveTo(x - h * 0.45, y - hh * 0.4, x + sway, y - hh);
ctx.quadraticCurveTo(x + h * 0.45, y - hh * 0.4, x, y);
ctx.fillStyle = color;
ctx.fill();
};
// A frost crystal: three crossing arms and a diamond heart.
const flake = (ctx, x, y, r, rot, color) => {
for (let k = 0; k < 3; k++) {
const a = rot + (k * Math.PI) / 3;
stroke(ctx, x - Math.cos(a) * r, y - Math.sin(a) * r, x + Math.cos(a) * r, y + Math.sin(a) * r, color, Math.max(0.12, r * 0.14));
}
poly(ctx, [[x, y - r * 0.5], [x + r * 0.3, y], [x, y + r * 0.5], [x - r * 0.3, y]], color);
};
// Each stage's flourish: (ctx, t, pal, W, H) drawn behind the words.
const FLOURISH = {
// Bats crossing the sky.
manor(ctx, t, pal, W) {
for (let i = 0; i < 4; i++) {
const x = ((t / 30 + i * 31) % (W + 16)) - 8;
const y = 6 + i * 9 + Math.sin(t / 400 + i) * 2;
const f = Math.sin(t / 80 + i) * 1.6;
poly(ctx, [[x, y], [x - 3, y - 1.6 + f], [x - 1.4, y + 0.4], [x, y + 0.8], [x + 1.4, y + 0.4], [x + 3, y - 1.6 + f]], pal.glow);
}
},
// Dust in the lamplight and a spider on a thread.
wing(ctx, t, pal, W, H) {
for (let i = 0; i < 26; i++) dot(ctx, rnd(i) * W + Math.sin(t / 900 + i) * 2, H - ((t / 40 + rnd(i, 1) * H) % H), 0.2 + rnd(i, 2) * 0.35, pal.glow);
const drop = 8 + Math.sin(t / 700) * 3;
stroke(ctx, W - 10, 0, W - 10, drop, pal.glow, 0.15);
dot(ctx, W - 10, drop + 0.8, 0.9, pal.a);
},
// Headstones in a rolling mist.
graveyard(ctx, t, pal, W, H) {
for (let i = 0; i < 6; i++) {
const x = 7 + i * 16 + (i % 2) * 3;
const h = 5 + (i % 3) * 1.8;
ctx.fillStyle = "rgba(10, 18, 14, 0.9)";
ctx.fillRect(x - 2, H - h, 4, h);
ctx.beginPath();
ctx.arc(x, H - h, 2, Math.PI, 0);
ctx.fill();
}
for (let i = 0; i < 5; i++) {
faint(ctx, 0.35, () => {
ctx.beginPath();
ctx.ellipse(((t / 90 + i * 23) % (W + 30)) - 15, H - 2.2 - (i % 2), 14, 1.8, 0, 0, TAU);
ctx.fillStyle = pal.glow;
ctx.fill();
});
}
},
// Leaves drifting down.
grounds(ctx, t, pal, W, H) {
for (let i = 0; i < 16; i++) {
const y = ((t / 28 + rnd(i) * H * 2) % (H + 6)) - 3;
const x = rnd(i, 1) * W + Math.sin(t / 600 + i * 1.7) * 4;
ctx.beginPath();
ctx.ellipse(x, y, 1.1, 0.55, t / 500 + i, 0, TAU);
ctx.fillStyle = i % 3 ? pal.a : pal.glow;
ctx.fill();
}
},
// Candles in two rows with wavering flames.
chapel(ctx, t, pal, W, H) {
for (let i = 0; i < 8; i++) {
const x = i < 4 ? 4 + i * 3.4 : W - 4 - (i - 4) * 3.4;
const h = 5 + (i % 3) * 1.5;
ctx.fillStyle = "#efe6cf";
ctx.fillRect(x - 0.7, H - h, 1.4, h);
flame(ctx, x, H - h, 2.6, t, i, pal.glow);
flame(ctx, x, H - h - 0.1, 1.4, t + 40, i, "#fff3c4");
}
},
// A heartbeat that runs across the bottom, and a blinking cross.
sanatorium(ctx, t, pal, W, H) {
ctx.beginPath();
for (let x = 0; x <= W; x += 0.8) {
const p = (((x + t / 22) % 40) + 40) % 40;
const y = p > 14 && p < 15 ? -5 : p >= 15 && p < 16.5 ? 3 : p >= 16.5 && p < 17.5 ? -1 : 0;
if (x) ctx.lineTo(x, H - 4 + y);
else ctx.moveTo(x, H - 4 + y);
}
ctx.strokeStyle = pal.glow;
ctx.lineWidth = 0.35;
ctx.stroke();
if (Math.sin(t / 700) > -0.2) {
ctx.fillStyle = pal.glow;
ctx.fillRect(W - 9, 3, 3, 1);
ctx.fillRect(W - 8, 2, 1, 3);
}
},
// A crescent moon and windows that blink.
village(ctx, t, pal, W, H) {
dot(ctx, W - 14, 11, 4.5, pal.glow);
dot(ctx, W - 12.4, 10, 4.2, "#0e0c28");
for (let i = 0; i < 9; i++) {
const lit = Math.sin(t / 900 + i * 2.3) > -0.4;
ctx.fillStyle = "rgba(8, 6, 24, 0.9)";
ctx.fillRect(3 + i * 10.4, H - 6, 6, 6);
ctx.fillStyle = lit ? pal.glow : "rgba(40, 40, 80, 0.8)";
ctx.fillRect(4.6 + i * 10.4, H - 4.6, 2.8, 2.4);
}
},
// Sparks flying off a pickaxe's strike, low at both sides.
mine(ctx, t, pal, W, H) {
for (const side of [0, 1]) {
const bx = side ? W - 7 : 7;
stroke(ctx, bx - 3, H - 3, bx + 3, H - 9, "#8a6a42", 0.6);
stroke(ctx, bx - 3.5, H - 8, bx + 3.5, H - 9.5, "#cfd5da", 0.9);
for (let i = 0; i < 12; i++) {
const p = (t / 700 + rnd(i, side)) % 1;
const a = -Math.PI * (0.15 + 0.7 * rnd(i, 3 + side));
const sp = 7 + rnd(i, 5) * 8;
faint(ctx, 1 - p, () => dot(ctx, bx + Math.cos(a) * sp * p, H - 8 + Math.sin(a) * sp * p + 24 * p * p, 0.35, i % 2 ? pal.glow : "#fff3c4"));
}
}
},
// Bunting along the top, swaying, with bulbs.
carnival(ctx, t, pal) {
const cols = [pal.a, pal.glow, "#fde047", pal.b];
for (let row = 0; row < 2; row++) {
for (let i = 0; i < 12; i++) {
const x = 4 + i * 8;
const sag = Math.sin((i / 11) * Math.PI) * (3 + row * 2.5) + row * 3;
const sw = Math.sin(t / 400 + i + row) * 0.5;
poly(ctx, [[x - 2, sag], [x + 2, sag], [x + sw, sag + 4]], cols[(i + row) % 4]);
dot(ctx, x, sag - 0.3, 0.3 + 0.15 * Math.sin(t / 150 + i), "#fffbe8");
}
}
},
// Frost crystals falling and twinkling.
frozen(ctx, t, pal, W, H) {
for (let i = 0; i < 14; i++) {
const y = ((t / 40 + rnd(i) * H * 2) % (H + 8)) - 4;
const x = rnd(i, 1) * W + Math.sin(t / 800 + i) * 3;
faint(ctx, 0.5 + 0.5 * Math.sin(t / 220 + i * 1.9) ** 2, () => flake(ctx, x, y, 0.8 + rnd(i, 2) * 1.6, t / 1500 + i, pal.glow));
}
},
// Wisp motes drifting over rising mud bubbles.
bog(ctx, t, pal, W, H) {
for (let i = 0; i < 7; i++) {
const x = ((rnd(i, 4) * W + t / 60 + Math.sin(t / 700 + i) * 6) % (W + 8)) - 4;
const y = H * 0.25 + rnd(i, 5) * H * 0.5 + Math.sin(t / 500 + i * 1.7) * 3;
faint(ctx, 0.5 + 0.5 * Math.sin(t / 300 + i * 2.1), () => dot(ctx, x, y, 0.7 + rnd(i, 6) * 0.6, pal.glow));
}
for (let i = 0; i < 6; i++) {
const p = (t / 1600 + rnd(i, 7)) % 1;
const x = 8 + rnd(i, 8) * (W - 16);
faint(ctx, 1 - p, () => {
ctx.beginPath();
ctx.arc(x, H - 3 - p * 10, 0.5 + p * 0.8, 0, TAU);
ctx.strokeStyle = pal.a;
ctx.lineWidth = 0.2;
ctx.stroke();
});
}
},
// The hall: dust and a flickering torch at each end.
hall(ctx, t, pal, W, H) {
for (let i = 0; i < 18; i++) dot(ctx, rnd(i) * W, H - ((t / 45 + rnd(i, 1) * H) % H), 0.25, pal.glow);
for (const x of [5, W - 5]) {
ctx.fillStyle = "#3a2a18";
ctx.fillRect(x - 0.5, H - 8, 1, 5);
flame(ctx, x, H - 8, 3.2, t, x, pal.glow);
}
},
};
export function introArt(d) {
const { label, GOLD, BONE } = d;
return function introCard(ctx, v) {
const { g, round } = v;
const info = introFor(round.stage);
if (!info) return;
const t = round.introMs || 0;
const W = g.FIELD_W;
const H = g.FIELD_H;
const pal = info.palette;
const fade = Math.min(1, t / 320);
ctx.save();
ctx.globalAlpha = fade * 0.97;
ctx.fillStyle = "#07050c";
ctx.fillRect(0, 0, W, H);
// Bands of the stage's color rising from the floor, a glow behind the title.
for (let i = 0; i < 8; i++) {
ctx.globalAlpha = fade * (0.05 + 0.02 * (7 - i));
ctx.fillStyle = pal.b;
ctx.fillRect(0, H - (i + 1) * (H / 8), W, H / 8);
}
ctx.globalAlpha = fade * (0.1 + 0.04 * Math.sin(t / 500));
ctx.beginPath();
ctx.ellipse(W / 2, 16, 38, 11, 0, 0, TAU);
ctx.fillStyle = pal.glow;
ctx.fill();
ctx.globalAlpha = fade;
(FLOURISH[round.stage] || FLOURISH.hall)(ctx, t, pal, W, H);
ctx.globalAlpha = fade;
// A frame in the stage's color.
ctx.strokeStyle = pal.glow;
ctx.lineWidth = 0.4;
ctx.strokeRect(1.2, 1.2, W - 2.4, H - 2.4);
// The kicker, then the title letter by letter.
label(ctx, info.kicker.toUpperCase(), W / 2, 6, 1.9, BONE, "center", W - 8);
const { size, xs } = titleLayout(info.title);
const chars = [...info.title];
for (let i = 0; i < chars.length; i++) {
if (chars[i] === " ") continue;
const at = t - 200 - i * STAGGER_MS;
const landed = at >= DROP_MS;
const x = W / 2 + xs[i];
const y = 15 - dropAt(at) * 20 + (landed ? Math.sin(t / 260 - i * 0.6) * size * 0.05 : 0);
ctx.globalAlpha = fade * Math.min(1, Math.max(0, at / 80 + 0.2));
// The glow breathes under each landed letter.
if (landed) {
ctx.globalAlpha = fade * (0.25 + 0.2 * Math.sin(t / 300 - i * 0.5));
label(ctx, chars[i], x, y, size * 1.12, pal.glow, "center");
ctx.globalAlpha = fade;
}
label(ctx, chars[i], x + 0.3, y + 0.5, size, "rgba(0, 0, 0, 0.65)", "center");
label(ctx, chars[i], x, y, size, i % 2 ? pal.b : pal.a, "center");
// A lighter top edge once landed.
if (landed) {
ctx.globalAlpha = fade * 0.55;
label(ctx, chars[i], x, y - size * 0.06, size * 0.94, pal.a, "center");
ctx.globalAlpha = fade;
}
}
// A divider, then the flavor lines fading up one at a time.
const lineAt = 1000;
ctx.globalAlpha = fade * Math.min(1, Math.max(0, (t - 800) / 400));
stroke(ctx, W / 2 - 20, 22, W / 2 + 20, 22, pal.glow, 0.3);
dot(ctx, W / 2, 22, 0.8 + 0.2 * Math.sin(t / 250), pal.glow);
info.lines.forEach((line, i) => {
const p = Math.min(1, Math.max(0, (t - lineAt - i * 550) / 450));
ctx.globalAlpha = fade * p;
label(ctx, line, W / 2, 27.5 + i * 4.4 + (1 - p) * 1.2, LINE_SIZE, BONE, "center", W - 4);
});
if (info.boss) {
const p = Math.min(1, Math.max(0, (t - lineAt - info.lines.length * 550) / 450));
ctx.globalAlpha = fade * p;
label(ctx, `BOSS: ${info.boss.toUpperCase()}`, W / 2, 46.5, 2, GOLD, "center", W - 8);
}
// The hint, pulsing once a key is let through (the card waits for it as long as YOU like).
if (t >= INTRO_MIN_MS) {
ctx.globalAlpha = fade * (0.55 + 0.45 * Math.sin(t / 260));
label(ctx, INTRO_HINT, W / 2, 51.2, 1.9, pal.glow, "center");
}
ctx.restore();
ctx.globalAlpha = 1;
};
}
@@ -0,0 +1,85 @@
// Plan2Code Web Console - Ghoul Rush's stage intro cards, the words and colors: per stage id, the title, a palette, a kicker line, 3 or 4 lines of flavor text and the boss's name. ghoul-intro-draw.js draws them; scripts/test-web-console-activities-ghoul-intro.mjs makes sure every stage in STAGES has one.
//
// Rules for the text (see "Stage intro screens" in prototypes/Ghoul-Rush-TODO.md):
// 3 or 4 lines, each at most MAX_LINE characters (the card is 96 units wide),
// always addressed to YOU (never the hero's name), no em dash, US English,
// spooky-fun and a little menacing, naming the boss and what it has done.
// The palette: `a` the title's top color, `b` its bottom color, `glow` the
// halo and the flourish's color.
export const MAX_LINE = 60;
const freeze = Object.freeze;
const intro = (title, a, b, glow, kicker, boss, lines) => freeze({ title, palette: freeze({ a, b, glow }), kicker, boss, lines: freeze(lines) });
export const INTROS = freeze({
manor: intro("The Manor", "#ffb347", "#c2410c", "#ff8a1f", "Where the screaming started", "The Rotting Gourd", [
"The Manor has stood empty for a century. It is not empty.",
"The Rotting Gourd grows in the cellar and has gone sour.",
"It ate the last owners, the staff and the dinner guests.",
"YOU are next on the menu. Squash it before it squashes YOU.",
]),
wing: intro("The East Wing", "#e9d5ff", "#7c3aed", "#c084fc", "The servants never left", "Old Rattlebones", [
"The staff kept working long after they stopped breathing.",
"Old Rattlebones, the butler, still keeps the house tidy.",
"He keeps the guests too. They are all in the crypt.",
"Do not let him show YOU in. YOU would never be shown out.",
]),
graveyard: intro("The Graveyard", "#d1fae5", "#4b6a5a", "#9fe6c4", "Everyone here was buried in a hurry", "Mother Mourning", [
"Nobody here was buried with proper paperwork, or manners.",
"Mother Mourning weeps at every grave. Count them: all hers.",
"She turns around when YOU move, and so do the headstones.",
"Dry her tears for good. YOU have the only handkerchief.",
]),
grounds: intro("The Grounds", "#bef264", "#b45309", "#facc15", "The gardener never stopped working", "The Groundskeeper", [
"The hedges are trimmed. So is the lawn. So were the guests.",
"The Groundskeeper walks his rounds with shears and lantern.",
"He has been pruning the village since before it had a name.",
"Stay out of his flower beds. YOU would make fine compost.",
]),
chapel: intro("The Chapel", "#fde68a", "#be123c", "#fb923c", "Service is still in session", "The Choirmaster", [
"The bell tolls hourly, and no one is left to pull the rope.",
"The Choirmaster drills his pipes until they scream in tune.",
"He needs one more voice, and he has YOU in mind.",
"Silence the organ before YOU are asked to sing.",
]),
sanatorium: intro("Blackmoor Sanatorium", "#a7f3d0", "#0f766e", "#5eead4", "Visiting hours ended in 1912", "The Night Matron", [
"The patients never checked out, and the lights flicker.",
"The Night Matron makes rounds with a lantern and a needle.",
"She has cured every ward of everything, including breathing.",
"Bedtime for YOU, she says. YOU do not intend to nap.",
]),
village: intro("Hollow End Village", "#c4b5fd", "#312e81", "#a5b4fc", "Every curtain twitches as you pass", "The Beast of Hollow End", [
"Every lock is bolted and every shutter nailed. Not for YOU.",
"The Beast of Hollow End prowls the rooftops after dark.",
"It took the baker, the blacksmith and the bell ringer.",
"The moon is full tonight. YOU are the only one outside.",
]),
mine: intro("The Deep Seam Mine", "#fdba74", "#7c2d12", "#fbbf24", "They are still knocking", "The Tommyknocker", [
"The miners went down for coal and never came back up.",
"The Tommyknocker taps on the timbers, and the roof listens.",
"Follow the knocking and it leads YOU to a dead end.",
"Bring a light, a steady aim and a very good excuse.",
]),
carnival: intro("The Midnight Carnival", "#fda4af", "#7e22ce", "#f472b6", "Every game is rigged in its favor", "The Ringmaster", [
"Step right up! The tickets are free, the exits are not.",
"The Ringmaster pulls the strings, and the whole town dances.",
"He has been cutting new puppets since the carnival opened.",
"YOU are in the crowd, so YOU are in the show. Take a bow.",
]),
frozen: intro("The Frozen Lake", "#bae6fd", "#1d4ed8", "#e0f2fe", "The ice remembers who fell through", "The Frost Widow", [
"The lake froze solid overnight, with the swimmers inside.",
"The Frost Widow spins her veil from snow and slow breath.",
"She keeps every one who fell through. YOU are on thin ice.",
"Melt her heart, if she has one. Watch YOUR step, and toes.",
]),
bog: intro("Gallows Bog", "#d6ee9c", "#44521c", "#9fd06b", "The mud does not like to let go", "Old Mother Bog", [
"The boardwalk sank years ago. The walkers never left.",
"Old Mother Bog stirs her pot under the black water.",
"Chase the pretty lights and they will lead YOU under.",
"The mud holds what it catches. Do not let it hold YOU.",
]),
});
// The card for a stage id, or null for an id with none (the hall is no stage and has no card).
export const introFor = (id) => INTROS[id] || null;
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,547 @@
// Plan2Code Web Console - Ghoul Rush's Gardener's Revenge, its rules: the Grounds' bonus round. YOU ride the gardener's rusty, haunted ride-on mower down a long straight run through the overgrown estate lawn at night: jump the gnomes, barrows, flowerpots, ponds and ha-ha ditches, duck the hedge arches and the clothes lines of ghostly gloves, shoot the snapping topiary beasts, and MOW: hold fire and the blades come down, cutting the tall grass, the weeds and the thorn hedges just ahead. As a stage pack that ghoul.js plugs in.
//
// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it, handed a
// kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js (it borrows the
// cart's track helpers). Pack fields used: `ride` (a hook that moves Planny himself, so no
// key walks him), `place` (Planny put down in a room: a room set up or a respawn) and
// `target` (a bolt strikes something that is no monster: the topiary beasts). It adds no
// monster, boss or hazard kind and it draws NO random number. Its state is the shared
// bonus-ride slot `round.runner` (id "mower"; null in any other room), the room marks its
// ride `runner: "mower"` (the cart's `place` leaves such a room alone).
//
// THE ROOM (spec.ride, see ghoul-rooms.js):
//
// - `track`: polylines [x, y] the mower rolls along, all flat at one height; a gap between
// two lines is a POND or a HA-HA DITCH (`gaps`: per gap, 0 a pond, 1 a ditch; jump it, or
// the mower drops in: a heart, cause "pond" or "ditch"). The last line ends at `finish`,
// where the lawn's end (the ground) begins at the same height: rolling onto it ends the ride.
// - `junk` [x, kind] (a garden gnome, a wheelbarrow or a flowerpot, JUNK: jump it), `lows`
// [x0, x1, y, kind] (a hedge arch, kind 0, or a clothes line of ghostly gloves, kind 1: its
// underside is y, from there up to the roof, so DUCK it; y is 3.0 over the lawn, between a
// ducked box and a standing one), `hedges` [x] (a thorn hedge across the lane, THORN_W by
// THORN_H: MOW it, or jump it), `beasts` [x] (a snapping topiary beast: it shivers
// BEAST_WARN_MS when the mower is BEAST_NEAR short of it, then lunges into the lane
// BEAST_UP_MS, BEAST_W by BEAST_H: shoot it, BEAST_HP bolts, or jump it), `grass` [x0, x1]
// (tall grass, one cell a unit, mown by the blades), `weeds` [x] (a weed patch with a
// flower, WEED_CELLS cells), `checks` (x positions of the checkpoints), `finish`, `time`
// (the room's clock, ms) and `how` (the controls line).
//
// THE MOWER (`round.runner`): { id, room, check, v, line, coyote, from, left, done, heat,
// jam, blade, bogMs, cut, cells, lawn, grass, hedges, weeds, beasts, ... }. Planny rides
// at (you.x, you.y), always facing right (`you.state` "run" on the lawn, "air" off it,
// `you.ducking` ducked). Speed `v` is MOWER_V, bogging down BOG slower for BOG_MS after a
// cut (nothing else changes it: it is a ride). Up jumps at MOWER_JUMP_V against MOWER_G
// (about 11 high, 0.7 s, 22 across at MOWER_V), COYOTE_MS of grace after running off a line's
// end; down ducks.
//
// THE BLADES: while fire is held and the blades are not jammed they are down (`blade`) and cut
// everything in the zone from the mower's front to BLADE_REACH ahead of it: every grass cell
// (GRASS_POINTS each), every weed patch (WEED_POINTS, an act) and every thorn hedge
// (HEDGE_POINTS, an act). Holding fire heats them (`heat` 0 to 1, HEAT_UP a second; they
// cool COOL a second while let go); full heat JAMS them for JAM_MS (no cutting, smoke), after
// which they restart at JAM_RESUME. So the player pulses them. The bolts fly all the time
// fire is held, as always. `lawn` is the share of the room's cells cut (grass cells plus
// WEED_CELLS a weed patch): the grade's `steady` die is lawn at least LAWN_GOAL.
//
// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the mower rolls
// on, Planny blinking safe BONUS_SAFE_MS; the last heart gone ends the round with nothing, at
// once. A fall puts him back on the lawn ahead at MOWER_V. Causes: "gnome", "barrow", "pot",
// "arch", "line", "thorns", "snap", "pond", "ditch". Every obstacle is a number for the grade
// (`perf.total`: junk, lows, hedges, beasts and gaps, each id once in `perf.hits` if it ever
// cost a heart); cutting a hedge or a weed patch, or shooting a beast, counts for `perf.acts`
// (the grade's goal is ACTS_GOAL).
//
// Checkpoints are passed at their x (`mowerCheck`); a restart after the last heart goes back to the
// last one passed (that ends the round, as the sled's does).
//
// WHAT THE ART READS: `spec.ride` (above), `round.runner` { v, line, check, done, left, heat,
// jam, blade, lawn, cut, grass: [[cut cells]], hedges: [cut], weeds: [cut], beasts: [{ state
// "idle"|"warn"|"snap"|"sink"|"spent"|"broken", t }] }, `round.you` (`state`, `vy`, `ducking`),
// the events in EVENTS.
import { linesAt, linesOf, trackY } from "./ghoul-cart.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
export const MONSTERS = freeze({});
// Every event this pack puts on the field, for the art and the sounds to answer.
export const EVENTS = freeze([
"mowerJump", "mowerLand", "mowerDuck", "mowerCrash", "mowerCheck", "mowerFinish",
"mowerGrass", "mowerHedge", "mowerWeed", "mowerJam",
"mowerBeastWarn", "mowerBeastSnap", "mowerBeastHit", "mowerBeastBreak",
]);
// The mower. Speeds are units across a second, MOWER_G units a second squared.
export const MOWER_V = 32;
export const BOG = 4;
export const BOG_MS = 220;
export const RELAX = 3;
export const MOWER_JUMP_V = 66;
export const MOWER_G = 190;
export const COYOTE_MS = 100;
export const LAND_TOL = 0.9;
export const BIG_LAND = 5;
export const DERAIL_DROP = 7;
export const CAM_AHEAD = 10;
// The blades.
export const BLADE_REACH = 9;
export const BLADE_NEAR = 0;
export const HEAT_UP = 0.75;
export const COOL = 0.5;
export const JAM_MS = 1800;
export const JAM_RESUME = 0.3;
export const GRASS_POINTS = 4;
export const WEED_POINTS = 40;
export const HEDGE_POINTS = 80;
export const WEED_CELLS = 3;
export const WEED_W = 2.2;
export const LAWN_GOAL = 0.6;
// Obstacles: a gnome, a wheelbarrow, a flowerpot (jump), a thorn hedge (mow or jump).
export const JUNK = freeze([
freeze({ name: "gnome", w: 2.4, h: 4.2 }),
freeze({ name: "barrow", w: 5.2, h: 3 }),
freeze({ name: "pot", w: 2.2, h: 3.6 }),
]);
export const THORN_W = 3.4;
export const THORN_H = 3.8;
// The snapping topiary beast: wakes, lunges into the lane, and the shots at it.
export const BEAST_W = 3.4;
export const BEAST_H = 4.6;
export const BEAST_HP = 2;
export const BEAST_NEAR = 36;
export const BEAST_WARN_MS = 450;
export const BEAST_UP_MS = 1400;
export const BEAST_SINK_MS = 300;
export const BEAST_POINTS = 150;
const SHOT_R = 0.5;
// The shots and cuts (a hedge, a weed patch, a beast) worth a die.
export const ACTS_GOAL = 14;
// Notes for a bonus round that obstacle `id` cost a heart (once each).
function noteHit(round, id) {
const b = round.bonusRound;
if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id);
}
const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H);
const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0;
// The highest line under x, as [line, y], or null over a gap.
const topAt = (R, x) => linesAt(R, x)[0] || null;
// The highest line the mower, falling from `py` to `y` at `x`, crossed going down.
function landOn(R, x, py, y) {
for (const [line, ly] of linesAt(R, x)) if (py >= ly - LAND_TOL && y <= ly) return { line, y: ly };
return null;
}
// Where a mower in the air at (x, y) going up at vy and across at v lands, if it does not
// steer: { x, y, line } or null when it drops. The unit suite's measure of which gaps a jump clears.
export function flight(R, x, y, vy, v) {
const dt = 0.004;
const floor = y - DERAIL_DROP;
for (let t = 0; t < 5; t += dt) {
const py = y;
vy = Math.max(-120, vy - MOWER_G * dt);
x += v * dt;
y += vy * dt;
if (vy <= 0) {
const f = landOn(R, x, py, y);
if (f) return { x, y: f.y, line: f.line };
}
if (y < floor) return null;
}
return null;
}
// The cells of a stretch of tall grass: one a unit.
export const cellsOf = (g) => Math.max(1, Math.ceil(g[1] - g[0]));
// The room's cells in all, the lawn's whole, and how many of them are cut so far in a runner.
export const totalCells = (R) => R.grass.reduce((n, g) => n + cellsOf(g), 0) + R.weeds.length * WEED_CELLS;
/* -------------------------------------------------------------- placing */
// A fresh set of the room's things, each beast asleep. What was cut or shot stays so (`old`,
// the runner of an earlier try in the same room).
function things(R, old) {
const same = Boolean(old && old.id === "mower" && old.grass.length === R.grass.length && old.hedges.length === R.hedges.length && old.weeds.length === R.weeds.length && old.beasts.length === R.beasts.length);
return {
grass: R.grass.map((g, i) => (same && old.grass[i].length === cellsOf(g) ? old.grass[i].slice() : new Array(cellsOf(g)).fill(false))),
hedges: R.hedges.map((_, i) => Boolean(same && old.hedges[i])),
weeds: R.weeds.map((_, i) => Boolean(same && old.weeds[i])),
beasts: R.beasts.map((_, i) => ({ state: same && old.beasts[i].state === "broken" ? "broken" : "idle", t: 0, hp: BEAST_HP })),
};
}
// How many cells are cut, from the lists.
function cutCells(c) {
return c.grass.reduce((n, g) => n + g.filter(Boolean).length, 0) + c.weeds.filter(Boolean).length * WEED_CELLS;
}
// Planny put down in the room: on the mower at the start of a ride, or at the last
// checkpoint passed after the last heart (the same room).
function place(round, k) {
const R = round.spec.ride;
// (The Cart's `place` runs first and has already zeroed `round.camLead`: another room's lead is not ours to touch.)
if (!R || R.runner !== "mower") {
if (round.runner && round.runner.id === "mower") round.runner = null;
return;
}
const again = round.runner && round.runner.id === "mower" && round.runner.room === round.room;
const check = again ? round.runner.check : -1;
const you = round.you;
const x = check >= 0 ? R.checks[check] : round.spec.start;
const top = topAt(R, x);
Object.assign(you, { x, y: top ? top[1] : you.y, vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 });
const t = things(R, again ? round.runner : null);
const cells = totalCells(R);
round.runner = { id: "mower", room: round.room, check, v: MOWER_V, line: top ? top[0] : -1, coyote: 0, from: you.y, left: top ? top[0] : 0, done: false, heat: 0, jam: 0, blade: false, bogMs: 0, cells, cut: 0, lawn: 0, ...t };
round.runner.cut = cutCells(round.runner);
round.runner.lawn = cells ? round.runner.cut / cells : 0;
round.camLead = CAM_AHEAD;
const b = round.bonusRound;
if (b && !b.perf.total) {
b.perf.total = R.junk.length + R.lows.length + R.hedges.length + R.beasts.length + (R.track.length - 1);
b.perf.steady = false;
b.perf.goal = ACTS_GOAL;
}
}
/* ------------------------------------------------------------ the ride */
// After a fall that cost a heart but not the ride: Planny and the mower go back onto the
// lawn nearest where they fell (the line under him, else the next one ahead) at MOWER_V. He
// blinks safe (ghoul.js's takeLife).
function reseat(round, c, R) {
const you = round.you;
const under = topAt(R, you.x);
let line;
let x;
let y;
if (under) {
[line, y] = under;
x = you.x;
} else {
const ahead = linesOf(R)
.map((L, i) => ({ i, x0: L.x0 }))
.filter((L) => L.x0 > you.x)
.sort((a, b) => a.x0 - b.x0)[0];
line = ahead ? ahead.i : linesOf(R).length - 1;
x = ahead ? ahead.x0 + 2 : R.finish - 2;
y = trackY(R, line, x) ?? you.y;
}
Object.assign(you, { x, y, vy: 0, state: "run", shelf: -1, ducking: false, coyote: 0, drop: -1 });
Object.assign(c, { line, v: MOWER_V, coyote: 0, from: y });
}
// The mower's motion for one slice. Returns true once it has moved Planny (every slice of a
// ride); false outside a ride and once he has stepped out onto the lawn's end.
function ride(round, ms, k) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "mower" || !c || c.id !== "mower" || c.done) return false;
const you = round.you;
const inp = round.input;
const dt = ms / 1000;
const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra });
// Already down on the lawn's end (set there, or rolled on by some other way): the ride is over.
if (you.x >= R.finish && you.vy <= 0 && you.y <= k.groundAt(round.spec, you.x) + 0.01) return finish(round, c, k);
// A stomp's bounce (or anything else) lifts the mower off its line.
if (you.state === "air" && c.line >= 0) {
c.left = c.line;
c.line = -1;
c.coyote = 0;
c.from = you.y;
}
const want = inp.jump > 0;
const target = MOWER_V - (c.bogMs > 0 ? BOG : 0);
c.bogMs = Math.max(0, c.bogMs - ms);
c.v += (target - c.v) * Math.min(1, RELAX * dt);
if (c.line >= 0) {
// On the lawn.
const duck = Boolean(inp.down) && !want;
if (duck && !you.ducking) ev("mowerDuck");
you.ducking = duck;
if (want) {
inp.jump = 0;
you.vy = MOWER_JUMP_V;
Object.assign(c, { left: c.line, line: -1, coyote: 0, from: you.y });
you.state = "air";
you.ducking = false;
ev("mowerJump", { v: c.v });
} else {
const L = linesOf(R)[c.line];
const nx = you.x + c.v * dt;
you.state = "run";
you.vy = 0;
if (nx >= L.x1) {
// Off the end of the line: into a gap, or onto the lawn's end.
you.x = L.x1;
you.y = L.pts[L.pts.length - 1][1];
Object.assign(c, { left: c.line, line: -1, coyote: COYOTE_MS, from: you.y });
you.state = "air";
you.ducking = false;
you.vy = 0;
} else {
you.x = nx;
you.y = trackY(R, c.line, nx);
}
}
} else {
// In the air.
c.coyote = Math.max(0, c.coyote - ms);
if (want && c.coyote > 0) {
inp.jump = 0;
c.coyote = 0;
you.vy = MOWER_JUMP_V;
c.from = you.y;
ev("mowerJump", { v: c.v });
}
const py = you.y;
you.vy = Math.max(-k.FALL_MAX, you.vy - MOWER_G * dt);
you.x += c.v * dt;
you.y += you.vy * dt;
you.ducking = false;
you.state = "air";
if (you.vy <= 0) {
const f = landOn(R, you.x, py, you.y);
if (f) {
you.y = f.y;
you.vy = 0;
you.state = "run";
c.line = f.line;
ev("mowerLand", { big: c.from - f.y >= BIG_LAND || c.from - f.y <= -BIG_LAND });
c.from = f.y;
} else if (you.x >= R.finish) {
// Over the lawn's end: down onto it, and the ride is over.
const g = k.groundAt(round.spec, you.x);
if (g > -Infinity && you.y <= g + 0.01) return finish(round, c, k, g);
}
}
}
// A press nothing took waits a moment for a landing, then goes.
if (want && inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms);
// Into a gap: a pond or a ditch.
const base = R.track[0][0][1];
if (you.y < base - DERAIL_DROP || k.groundAt(round.spec, you.x) > you.y + 0.5) {
noteHit(round, `g${c.left}`);
const kind = R.gaps[Math.min(R.gaps.length - 1, Math.max(0, c.left))];
const hit = { type: "mowerCrash", what: kind ? "ditch" : "pond", x: you.x, y: you.y };
if (k.lose(round, kind ? "ditch" : "pond")) {
round.events.push(hit);
if (round.phase === "play") reseat(round, c, R);
}
return true;
}
while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) {
c.check++;
ev("mowerCheck", { n: c.check + 1 });
}
round.camLead = CAM_AHEAD + (c.v - MOWER_V) * 0.25;
mow(round, c, R, ms);
if (obstacles(round, c, R, k)) return true;
creatures(round, c, R, ms);
return true;
}
// The ride is over: the mower coughs to a halt on the lawn's end, the door opens, Planny walks out.
function finish(round, c, k, g = k.groundAt(round.spec, round.you.x)) {
const you = round.you;
c.done = true;
c.restX = you.x;
c.blade = false;
Object.assign(you, { y: g, vy: 0, state: "run", shelf: -1, ducking: false });
round.hasKey = true;
round.camLead = 0;
grade(round, c);
round.events.push({ type: "mowerFinish", x: you.x, y: you.y, big: false });
return false;
}
// The grade's steady die: the lawn cut reaches LAWN_GOAL.
function grade(round, c) {
c.lawn = c.cells ? c.cut / c.cells : 0;
const b = round.bonusRound;
if (b) b.perf.steady = c.lawn >= LAWN_GOAL;
}
/* ------------------------------------------------------------- the blades */
// The blades for one slice: heat, jam, and what they cut in the zone ahead.
function mow(round, c, R, ms) {
const you = round.you;
const dt = ms / 1000;
const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra });
if (c.jam > 0) {
c.jam = Math.max(0, c.jam - ms);
c.blade = false;
c.heat = c.jam > 0 ? JAM_RESUME + ((1 - JAM_RESUME) * c.jam) / JAM_MS : JAM_RESUME;
} else if (round.input.fire) {
c.blade = true;
c.heat = Math.min(1, c.heat + HEAT_UP * dt);
if (c.heat >= 1) {
c.blade = false;
c.jam = JAM_MS;
ev("mowerJam");
}
} else {
c.blade = false;
c.heat = Math.max(0, c.heat - COOL * dt);
}
if (c.blade) {
const z0 = you.x + BLADE_NEAR;
const z1 = you.x + BLADE_REACH;
let cells = 0;
R.grass.forEach((g, i) => {
if (g[1] < z0 || g[0] > z1) return;
const row = c.grass[i];
for (let j = Math.max(0, Math.floor(z0 - g[0])); j < row.length && g[0] + j < z1; j++) {
const cx = g[0] + j + 0.5;
if (!row[j] && cx >= z0 && cx <= z1) {
row[j] = true;
cells++;
}
}
});
if (cells) {
c.cut += cells;
round.score += cells * GRASS_POINTS;
ev("mowerGrass", { n: cells, points: cells * GRASS_POINTS, tx: you.x + BLADE_REACH * 0.6 });
}
let bog = cells > 0;
R.hedges.forEach((x, i) => {
if (c.hedges[i] || x + THORN_W / 2 < z0 || x - THORN_W / 2 > z1) return;
c.hedges[i] = true;
bog = true;
round.score += HEDGE_POINTS;
if (round.bonusRound) round.bonusRound.perf.acts++;
ev("mowerHedge", { x, y: trackY(R, c.line >= 0 ? c.line : c.left, x) ?? you.y, points: HEDGE_POINTS });
});
R.weeds.forEach((x, i) => {
if (c.weeds[i] || x + WEED_W / 2 < z0 || x - WEED_W / 2 > z1) return;
c.weeds[i] = true;
c.cut += WEED_CELLS;
round.score += WEED_POINTS;
if (round.bonusRound) round.bonusRound.perf.acts++;
ev("mowerWeed", { x, y: trackY(R, c.line >= 0 ? c.line : c.left, x) ?? you.y, points: WEED_POINTS });
});
if (bog) c.bogMs = BOG_MS;
}
grade(round, c);
}
/* ------------------------------------------------------------ obstacles */
// What the mower runs into: junk, a low arch or line, an uncut thorn hedge, a beast's lunge.
// Returns whether it cost a heart.
function obstacles(round, c, R, k) {
const you = round.you;
const hh = duckH(k, you);
for (const [i, [x0, x1, y, kind]] of R.lows.entries()) {
if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > y && k.struck(round, kind ? "line" : "arch")) {
noteHit(round, `l${i}`);
round.events.push({ type: "mowerCrash", what: "low", x: you.x, y: you.y + hh });
return true;
}
}
for (const [i, [x, kind]] of R.junk.entries()) {
if (Math.abs(you.x - x) > 6) continue;
const J = JUNK[kind];
if (boxHit(k, you, x, trackY(R, lineAt(R, x), x) ?? you.y, J.w, J.h) && k.struck(round, J.name)) {
noteHit(round, `j${i}`);
round.events.push({ type: "mowerCrash", what: J.name, x, y: you.y });
return true;
}
}
for (const [i, x] of R.hedges.entries()) {
if (c.hedges[i] || Math.abs(you.x - x) > 6) continue;
if (boxHit(k, you, x, trackY(R, lineAt(R, x), x) ?? you.y, THORN_W, THORN_H) && k.struck(round, "thorns")) {
noteHit(round, `h${i}`);
round.events.push({ type: "mowerCrash", what: "thorns", x, y: you.y });
return true;
}
}
for (const [i, x] of R.beasts.entries()) {
const b = c.beasts[i];
if (b.state !== "snap" || Math.abs(you.x - x) > 5) continue;
if (boxHit(k, you, x, trackY(R, lineAt(R, x), x) ?? you.y, BEAST_W, BEAST_H) && k.struck(round, "snap")) {
noteHit(round, `b${i}`);
round.events.push({ type: "mowerCrash", what: "snap", x, y: you.y });
Object.assign(b, { state: "sink", t: BEAST_SINK_MS });
return true;
}
}
return false;
}
// The line a thing at x stands on (the one under it).
const lineAt = (R, x) => {
const top = topAt(R, x);
return top ? top[0] : 0;
};
// The topiary beasts wake when the mower comes near: a shiver, then a lunge, then back to a bush.
function creatures(round, c, R, ms) {
const you = round.you;
R.beasts.forEach((x, i) => {
const b = c.beasts[i];
const y = trackY(R, lineAt(R, x), x) ?? you.y;
if (b.state === "idle") {
const ahead = x - you.x;
if (ahead < BEAST_NEAR && ahead > -BEAST_W) {
Object.assign(b, { state: "warn", t: BEAST_WARN_MS });
round.events.push({ type: "mowerBeastWarn", x, y });
}
} else if (b.state === "warn" || b.state === "snap" || b.state === "sink") {
b.t -= ms;
if (b.t > 0) return;
if (b.state === "warn") {
Object.assign(b, { state: "snap", t: BEAST_UP_MS });
round.events.push({ type: "mowerBeastSnap", x, y });
} else if (b.state === "snap") Object.assign(b, { state: "sink", t: BEAST_SINK_MS });
else Object.assign(b, { state: "spent", t: 0 });
}
});
}
/* ------------------------------------------------------------- targets */
// A bolt into something to shoot: a topiary beast lunging into the lane. True when one took it
// (the bolt is spent).
function mowerShot(round, s) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "mower" || !c || c.id !== "mower") return false;
for (let i = 0; i < R.beasts.length; i++) {
const b = c.beasts[i];
const x = R.beasts[i];
const y = trackY(R, lineAt(R, x), x) ?? 0;
if (b.state !== "snap" || Math.abs(s.x - x) > BEAST_W / 2 + SHOT_R || s.y < y - SHOT_R || s.y > y + BEAST_H + SHOT_R) continue;
b.hp--;
if (b.hp > 0) round.events.push({ type: "mowerBeastHit", x, y: y + BEAST_H / 2 });
else {
Object.assign(b, { state: "broken", t: 0 });
round.score += BEAST_POINTS;
if (round.bonusRound) round.bonusRound.perf.acts++;
round.events.push({ type: "mowerBeastBreak", x, y: y + BEAST_H / 2, points: BEAST_POINTS });
}
return true;
}
return false;
}
export const MOWER = freeze({
id: "mower",
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
horde: freeze({}),
ride: freeze([ride]),
place: freeze([place]),
target: mowerShot,
});
@@ -0,0 +1,140 @@
// Plan2Code Web Console - Ghoul Rush's Holy Roller, its course: the fixed, seeded run down the Chapel's nave, laid out by TIME and turned into distance. No imports, no random numbers.
//
// The ride speeds up with the distance it has covered (speedAt: V0 at the start, climbing by ACC every
// second), so a second of ride time is a place (xAt). The course is written in seconds, a row of up to three
// things across the three lanes at a time, and every gap between two rows is long enough for a player to
// answer the first and get to the second (the tests walk the whole course to prove a safe path exists
// at every moment). Nothing here draws a random number: the same course every time.
//
// Output (all frozen), x being distance down the aisle and `lane` 0 (left), 1 (middle) or 2 (right):
// - `items`: [x, lane, kind, len] for every thing in the way, sorted by x. `x` is the thing's near
// edge and `len` how deep it runs (0 for the kind's own depth, see KINDS in ghoul-pew.js). Kinds:
// "pillar", "confessional", "pewx" (SWITCH), "kneeler", "stand", "cracks", "hatch" (JUMP), "censer",
// "banner", "beam" (SLIDE), "garg" (SHOOT or switch) and "bell" (a rope: SHOOT, harmless).
// - `souls`: [x, lane, h, type] wax souls (type 0) and halos (type 1, a magnet) with their height.
// - `checks`: the checkpoints' x; `finish`: where the ride ends; `rows`: [x, [kinds...]] for the art/tests.
export const PEW_START = 8;
export const V0 = 34;
export const ACC = 0.7;
export const V_MAX = 84;
export const RIDE_S = 66;
// Where the ride is `t` seconds in, and how fast it rolls at distance `x`.
export const xAt = (t) => PEW_START + V0 * t + (ACC * t * t) / 2;
export const speedAt = (x) => Math.min(V_MAX, Math.sqrt(V0 * V0 + 2 * ACC * Math.max(0, x - PEW_START)));
const r1 = (n) => Math.round(n * 10) / 10;
const SOUL_STEP = 0.14;
function build() {
const items = [];
const souls = [];
const rows = [];
const it = (t, lane, kind, len = 0) => items.push([r1(xAt(t)), lane, kind, len]);
const row = (t, kinds) => {
kinds.forEach((kind, lane) => kind && it(t, lane, kind, kind === "cracks" ? 7 : 0));
rows.push([r1(xAt(t)), kinds]);
};
const line = (t0, t1, lane, h = 1.5) => {
for (let t = t0; t <= t1 + 1e-9; t += SOUL_STEP) souls.push([r1(xAt(t)), lane, h, 0]);
};
// Souls rising over a jump and coming down again, centered at time t.
const arc = (t, lane, peak = 4.4, half = 0.42) => {
for (let u = -half; u <= half + 1e-9; u += SOUL_STEP) souls.push([r1(xAt(t + u + 0.1)), lane, 1.4 + peak * (1 - (u / half) ** 2), 0]);
};
const halo = (t, lane) => souls.push([r1(xAt(t)), lane, 2.4, 1]);
const [K, X, P, C, B, I, M, S, H, G, R, CR] = ["kneeler", "pewx", "pillar", "confessional", "banner", "censer", "beam", "stand", "hatch", "garg", "bell", "cracks"];
const _ = null;
// Act one: each answer on its own. JUMP, SWITCH, SLIDE, SWITCH again, a row that asks for all three, SHOOT.
row(3.4, [K, K, K]);
arc(3.4, 1);
row(6, [X, X, _]);
line(5.5, 6.6, 2);
row(8.5, [B, B, B]);
line(8.1, 8.9, 0, 0.9);
line(8.1, 8.9, 2, 0.9);
row(11, [_, C, C]);
line(10.4, 11.8, 0);
row(13.4, [P, K, I]);
arc(13.4, 1);
line(13, 13.8, 2, 0.9);
row(15.8, [_, G, _]);
line(15.2, 16.2, 0);
line(15.2, 16.2, 2);
// Act two: a bell rope that clears the gargoyles after it, staggered switching, jump-then-slide.
it(18.2, 0, R);
row(20.8, [G, G, _]);
line(20.2, 21.4, 2);
halo(22.2, 2);
row(23, [X, _, X]);
line(22.6, 23.4, 1);
row(24.6, [_, X, X]);
line(24.3, 24.9, 0);
row(26.2, [X, X, _]);
line(25.9, 26.5, 2);
row(28.2, [K, K, K]);
arc(28.2, 0);
arc(28.2, 1);
arc(28.2, 2);
row(29.6, [B, B, B]);
line(29.3, 29.9, 1, 0.9);
row(31.4, [H, CR, H]);
arc(31.4, 0);
arc(31.4, 2);
row(33.4, [I, P, I]);
line(33, 33.8, 0, 0.9);
line(33, 33.8, 2, 0.9);
halo(34.6, 0);
line(35, 36, 0);
line(35, 36, 1);
line(35, 36, 2);
row(37, [M, M, M]);
line(36.7, 37.5, 1, 0.9);
row(38.8, [C, _, C]);
line(38.4, 39.4, 1);
row(40.4, [S, K, S]);
arc(40.4, 1);
// Act three: faster and closer. Mixed rows, a second bell, gargoyles on both flanks.
it(42, 1, R);
row(44, [_, G, G]);
line(43.6, 44.6, 0);
row(45.6, [P, _, B]);
line(45.2, 46, 1);
row(47, [K, B, K]);
arc(47, 0);
arc(47, 2);
row(48.4, [_, C, _]);
line(48, 48.8, 0);
line(48, 48.8, 2);
row(49.8, [X, _, _]);
line(49.4, 50.2, 2);
row(51.2, [H, H, H]);
arc(51.2, 1);
row(52.6, [B, B, B]);
line(52.3, 52.9, 0, 0.9);
halo(53.8, 2);
row(54.6, [P, P, _]);
line(54.2, 55, 2);
row(56, [_, P, P]);
line(55.6, 56.4, 0);
row(57.4, [G, _, G]);
line(57, 57.8, 1);
row(59, [I, K, I]);
arc(59, 1);
row(60.6, [P, _, P]);
line(60.2, 61, 1);
row(62, [M, M, M]);
line(61.7, 62.5, 1, 0.9);
row(63.5, [_, P, _]);
line(63.1, 63.9, 0);
line(63.1, 63.9, 2);
line(64.4, 65.4, 1, 2);
items.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
souls.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
return { items, souls, rows, checks: [16.5, 31, 46, 58].map((t) => r1(xAt(t))), finish: r1(xAt(RIDE_S)) };
}
const deep = (v) => (Array.isArray(v) ? Object.freeze(v.map(deep)) : v);
export const COURSE = Object.freeze(Object.fromEntries(Object.entries(build()).map(([k, v]) => [k, deep(v)])));
@@ -0,0 +1,249 @@
// Plan2Code Web Console - Ghoul Rush's Holy Roller, its drawing: the Chapel's runaway pew seen from behind, an endless-runner down the nave in three lanes. The whole field is drawn by this ride's own art (`field`, in pseudo-3D by ghoul-pew-world.js) the way the Carnival's dark ride draws its gallery; ghoul-draw.js hands it the frame and then draws the hearts, the cards, the banner and the HUD pills on top.
//
// ghoul-draw.js plugs it in. LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are plain data;
// pewArt(d) takes ghoul-draw.js's drawing helpers (`d`) and hands back the pack the usual way plus `field`, so
// this file never reaches back into it (it reads only the rules' numbers from ghoul-pew.js). Everything of
// the ride's own is read off `round.runner` (see ghoul-pew.js) and the room's `ride`; the events leave
// short-lived bits in the view's `fx` (floats, bursts and rings in field units, y counted up from the field's bottom).
import { SOUL_SHARE, V0, V_MAX, soulShare, soulTotal } from "./ghoul-pew.js";
import { HOR, LW, worldArt } from "./ghoul-pew-world.js";
const freeze = (o) => Object.freeze(o);
const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x));
const look = (o) => freeze({ pack: "pew", custom: true, noMoon: true, pit: "#07040c", ...o });
export const LOOKS = freeze({
pew: look({ wallTop: "#0c0816", wallLow: "#1c1230", paper: "#2a1c40", wainscot: "#1a1020", floorTop: "#6a6070", floor: "#2e2834", floorEdge: "#0c0a10", shelf: "#4a3220", shelfTop: "#8a6440", window: "#d8a0f0", decor: "pews", color: "#f0c870", dark: 0.3 }),
});
// How each new kind sounds, by act (the sounds in ghoul-sfx-pew.js).
export const VOICES = freeze({
pew: freeze({
lane: "ghoulPewLane", bump: "ghoulPewBump", jump: "ghoulPewJump", land: "ghoulPewLand", slide: "ghoulPewSlide", dive: "ghoulPewDive",
soul: "ghoulPewSoul", halo: "ghoulPewHalo", crash: "ghoulPewCrash", check: "ghoulPewCheck", finish: "ghoulPewFinish", speed: "ghoulPewSpeed",
}),
pewgarg: freeze({ warn: "ghoulPewGargWarn", drop: "ghoulPewGargDrop", chip: "ghoulPewGargChip", hit: "ghoulPewGargHit" }),
pewbell: freeze({ ring: "ghoulPewBell" }),
});
// What each of the pack's events plays: [kind, act], once.
export const EVENT_VOICE = freeze({
pewLane: ["pew", "lane"],
pewBump: ["pew", "bump"],
pewJump: ["pew", "jump"],
pewLand: ["pew", "land"],
pewSlide: ["pew", "slide"],
pewDive: ["pew", "dive"],
pewSoul: ["pew", "soul"],
pewHalo: ["pew", "halo"],
pewCrash: ["pew", "crash"],
pewCheck: ["pew", "check"],
pewFinish: ["pew", "finish"],
pewSpeed: ["pew", "speed"],
pewGargWarn: ["pewgarg", "warn"],
pewGargDrop: ["pewgarg", "drop"],
pewGargChip: ["pewgarg", "chip"],
pewGargHit: ["pewgarg", "hit"],
pewBell: ["pewbell", "ring"],
});
export const LOSE_WORDS = freeze({
pewPillar: "Ran into a pillar", pewConfessional: "Into a confessional", pewCrosswise: "Crashed into a pew", pewKneeler: "Tripped on a kneeler",
pewCandle: "Hit a candle stand", pewFlagstone: "Cracked on a flagstone", pewHatch: "Fell down a crypt hatch", pewCenser: "Censer to the head",
pewBanner: "Banner to the face", pewBeam: "Struck by a beam", pewGargoyle: "Flattened by a gargoyle",
});
export const LOSE_SOUNDS = freeze({
pewPillar: ["thud", 0.55, 0.8],
pewConfessional: ["thud", 0.5, 0.9],
pewCrosswise: ["thud", 0.5, 1],
pewKneeler: ["thud", 0.5, 1.1],
pewCandle: ["clank", 0.5, 1.1],
pewFlagstone: ["ghoulRockLand", 0.5, 0.9],
pewHatch: ["ghoulPitFall", 0.55, 1],
pewCenser: ["clank", 0.5, 0.8],
pewBanner: ["thud", 0.4, 1.2],
pewBeam: ["smash", 0.5, 0.8],
pewGargoyle: ["crunch", 0.55, 0.7],
});
// The progress track along the field's top: the ride, its checkpoints and where the pew is.
export const BAR = freeze({ x0: 22, x1: 74, y: 3 });
export function pewArt(d) {
const { label, GOLD, say } = d;
const world = worldArt(d);
const pewOf = (round) => (round && round.runner && round.runner.id === "pew" ? round.runner : null);
// The still layers never draw this room (the field is the ride's), so they only get the nave's dark.
function backdrop(ctx, v, lk, x0, x1) {
ctx.fillStyle = lk.wallLow;
ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H);
}
const ground = () => {};
const shelf = () => {};
const lights = () => {};
const dim = () => 0;
/* ----------------------------------------------------------- the frame */
// The whole field: the nave in pseudo-3D, the ride's own HUD strip, then the effects the events left.
function field(ctx, v) {
const { round, g } = v;
const c = pewOf(round);
if (!c) return;
const R = round.spec.ride;
const you = round.you;
ctx.save();
if (v.shake) ctx.translate(v.shake.x * 0.6, v.shake.y * 0.6);
world.paint(ctx, v);
ctx.restore();
const Y = (y) => g.FIELD_H - y;
// The progress track with its checkpoints and the pew on it.
const { x0, x1, y } = BAR;
const p = clamp((you.x - round.spec.start) / (R.finish - round.spec.start), 0, 1);
ctx.globalAlpha = 0.6;
ctx.fillStyle = "#05060f";
ctx.fillRect(x0 - 0.6, y - 0.9, x1 - x0 + 1.2, 1.8);
ctx.globalAlpha = 1;
const speedK = clamp((c.v - V0) / (V_MAX - V0), 0, 1);
ctx.fillStyle = speedK > 0.66 ? "#ff8a4a" : speedK > 0.33 ? "#ffd36a" : "#7fd0ff";
ctx.fillRect(x0, y - 0.45, (x1 - x0) * p, 0.9);
for (const cx of R.checks) {
const k = (cx - round.spec.start) / (R.finish - round.spec.start);
ctx.fillStyle = cx <= you.x ? "#7dffa0" : "#cdbfe6";
ctx.fillRect(x0 + (x1 - x0) * k - 0.15, y - 1.1, 0.3, 2.2);
}
ctx.fillStyle = GOLD;
ctx.beginPath();
ctx.arc(x0 + (x1 - x0) * p, y, 0.9, 0, Math.PI * 2);
ctx.fill();
// Souls on the left, the combo on the right.
label(ctx, `SOULS ${c.got}/${soulTotal(R)}`, 3, 6.2, 2, soulShare(R, c) >= SOUL_SHARE ? "#7dffa0" : "#f0e8d8", "left");
if (c.combo > 1) {
const pop = 1 + Math.max(0, 1 - (v.fx.clock - (v.fx.pewPop || -1e4)) / 220) * 0.3;
label(ctx, `x${c.mult} ${c.combo} IN A ROW`, g.FIELD_W - 3, 6.4, 2.1 * pop, c.mult > 1 ? GOLD : "#f0e8d8", "right");
}
if (c.magnet > 0) label(ctx, "HALO", g.FIELD_W - 3, 9.6, 1.7, "#ffd75a", "right");
// Floats, bursts and rings that events left (field units, y up).
for (const q of v.fx.parts) {
ctx.globalAlpha = Math.max(0, q.life / q.max);
ctx.fillStyle = q.color;
ctx.fillRect(q.x - q.size / 2, Y(q.y) - q.size / 2, q.size, q.size);
}
for (const r of v.fx.rings) {
const k = 1 - r.life / r.max;
ctx.globalAlpha = (1 - k) * 0.8;
ctx.strokeStyle = r.color;
ctx.lineWidth = 0.5 * (1 - k) + 0.15;
ctx.beginPath();
ctx.arc(r.x, Y(r.y), r.r0 + k * r.grow, 0, Math.PI * 2);
ctx.stroke();
}
ctx.globalAlpha = 1;
}
/* -------------------------------------------------------------- events */
// A throttle on a repeating cue.
function gateOnce(fx, key, ms) {
if ((fx[key] || 0) > fx.clock) return false;
fx[key] = fx.clock + ms;
return true;
}
// Where the pew is on the screen (x) and a height over its feet (y up from the field's bottom).
const heroX = (lane) => 48 + (lane - 1) * 0.45 * LW;
// What the pack's events look and sound like; true when the event is its own. Each of its
// sounds plays once, from EVENT_VOICE (a soul's tick climbs with the combo).
function react(e, k) {
const { tone, shake, flash, burst, float, ring, fx } = k;
const voice = EVENT_VOICE[e.type];
if (!voice) return false;
if ((e.type === "pewSlide" || e.type === "pewLane") && !gateOnce(fx, `${e.type}Ms`, 90)) return true;
if (e.type === "pewSoul") tone(VOICES.pew.soul, 0.28, 1 + 0.05 * Math.min(12, (e.combo || 1) - 1) + 0.12 * ((e.mult || 1) - 1));
else say(tone, voice[0], voice[1], e.type === "pewSpeed" ? 0.4 : 0.5);
const x = heroX(e.lane === undefined ? 1 : e.lane);
const fy = 54 - 36;
switch (e.type) {
case "pewJump":
burst(x, 54 - 6, "#b89a78", 5, 7, 300);
break;
case "pewLand":
burst(x, 54 - 7, "#b0a4b8", e.big ? 14 : 6, e.big ? 12 : 8, 360);
if (e.big) shake(180, 0.5);
break;
case "pewBump":
shake(160, 0.5);
burst(x + (e.dir || 0) * 5, 54 - 14, "#cfd2e6", 5, 6, 260);
break;
case "pewSoul":
burst(heroX(e.lane), fy - (e.h || 1.5) * 2, "#ffd36a", 2, 5, 240);
if (e.up) {
fx.pewPop = fx.clock;
ring(48, 54 - 22, "#ffd36a", 1, 9, 500);
float(48, 54 - 14, `Combo x${e.mult}`, GOLD, 2.6);
}
break;
case "pewHalo":
ring(48, 54 - 24, "#ffd75a", 1, 14, 600);
float(48, 54 - 16, "Halo!", GOLD, 2.6);
break;
case "pewCrash":
shake(340, 1);
flash("#ffe0a8", 220);
burst(x, 54 - 16, e.what === "garg" ? "#8a96bc" : "#8a5a36", 18, 17, 520);
if (e.lost > 5) float(48, 54 - 16, "Combo lost", "#cdbfe6", 2);
break;
case "pewCheck":
float(48, 54 - 34, "Checkpoint", GOLD, 2.4);
ring(48, 54 - 30, "#7dffa0", 1, 10, 500);
break;
case "pewFinish":
shake(260, 0.7);
burst(48, 54 - 24, "#ffd36a", 24, 14, 600);
float(48, 54 - 30, e.share >= SOUL_SHARE ? "Amen! A full choir" : "Amen!", GOLD, 2.8);
break;
case "pewSpeed":
ring(48, 54 - HOR, "#9ab0ff", 4, 40, 520);
float(48, 54 - 40, "Faster!", "#ffb02e", 2.2);
break;
case "pewGargWarn":
shake(120, 0.25);
break;
case "pewGargDrop":
shake(200, 0.55);
burst(heroX(e.lane), 54 - 22, "#8a96bc", 10, 9, 420);
break;
case "pewGargChip":
burst(heroX(e.lane), 54 - 24, "#8a96bc", 6, 8, 300);
break;
case "pewGargHit":
burst(heroX(e.lane), 54 - 24, "#8a96bc", 14, 14, 480);
float(heroX(e.lane), 54 - 28, `+${e.points}`, GOLD, 2.2);
break;
case "pewBell":
ring(heroX(e.lane), 54 - 26, "#ffd36a", 1, 14, 700);
float(48, 54 - 30, e.stunned > 0 ? `+${e.points} Stunned!` : `+${e.points}`, GOLD, 2.4);
break;
default:
break;
}
return true;
}
return freeze({
looks: LOOKS,
backdrop,
ground,
shelf,
dim,
monsters: freeze({}),
bosses: freeze({}),
missiles: freeze({}),
hazards: freeze({}),
powers: freeze({}),
lights,
react,
field,
});
}
@@ -0,0 +1,947 @@
// Plan2Code Web Console - Ghoul Rush's Holy Roller, its world: the nave seen from behind the pew, in pseudo-3D. Drawn by ghoul-pew-draw.js's `field`; reads the rules in ghoul-pew.js, draws no random number (every scatter is a hash).
//
// THE PROJECTION (reusable for any "run into the screen" view, field units, the field being 96 wide and 54 high):
// a point is (l, dz, h): `l` across the aisle in lanes (0 the middle lane, +1 the right one), `dz` how far down the
// aisle ahead of the pew (negative once passed), `h` its height. With scale = NEAR / (NEAR + dz) it lands at
// x = VPX + (l - camL) * LW * scale, y = HOR + (GY0 - HOR) * scale - h * HS * scale
// so the horizon (dz infinite) is the vanishing point (VPX, HOR) and the pew (dz 0) stands at scale 1 on the floor line GY0.
// The camera slides a little with the pew's lane (camL). The scene goes far to near in CELL-deep cells anchored to the world
// (so they scroll), each with its floor tiles, wall, window and its light, pews and pillar with a rib over the aisle, then the
// things standing in the cell; fog is the cell's alpha going to nothing over FADE_D. The art of the things is in `thing`.
import { BUMP_MS, KINDS, LOW_Y, V0, V_MAX, cuesOf, gargRise } from "./ghoul-pew.js";
const TAU = Math.PI * 2;
const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x));
export const VPX = 48;
export const HOR = 19;
export const GY0 = 46;
export const NEAR = 26;
export const LW = 14.5;
export const HS = 2.1;
export const CELL = 16;
export const TILE = 8;
export const SEE = 290;
export const FADE_D = 250;
export const BPM = 132;
export const BEAT_MS = 60000 / BPM;
export const ANSWER_COLORS = Object.freeze({ JUMP: "#5fe3ff", SLIDE: "#ffb02e", SWITCH: "#ff5a6a", SHOOT: "#ff8a4a" });
const GLASS = Object.freeze(["216,50,60", "60,111,224", "240,180,58", "63,181,106", "166,90,216"]);
const WALL_L = 5.8;
// A number in 0..1 from two integers, the same every time (no random draws).
export const rnd = (a, b = 0) => {
let h = Math.imul((a | 0) + 0x9e37, 0x85ebca6b) ^ Math.imul((b | 0) + 0x7f4a, 0xc2b2ae35);
h ^= h >>> 13;
h = Math.imul(h, 0x5bd1e995);
h ^= h >>> 15;
return (h >>> 0) / 4294967296;
};
const grad = (make, stops) => {
const g = make ? make() : null;
if (!g || typeof g.addColorStop !== "function") return stops[stops.length >> 1][1];
for (const [o, col] of stops) g.addColorStop(o, col);
return g;
};
const vgrad = (c, y0, y1, stops) => grad(c.createLinearGradient && (() => c.createLinearGradient(0, y0, 0, y1)), stops);
const rgrad = (c, x, y, r, stops) => grad(c.createRadialGradient && (() => c.createRadialGradient(x, y, 0, x, y, r)), stops);
const quad = (c, a, b, e, f) => {
c.beginPath();
c.moveTo(a[0], a[1]);
c.lineTo(b[0], b[1]);
c.lineTo(e[0], e[1]);
c.lineTo(f[0], f[1]);
c.closePath();
};
const seg = (c, a, b) => {
c.beginPath();
c.moveTo(a[0], a[1]);
c.lineTo(b[0], b[1]);
c.stroke();
};
const disc = (c, x, y, r) => {
c.beginPath();
c.arc(x, y, Math.max(0.01, r), 0, TAU);
c.fill();
};
// The beat: 1 on the organ's stroke, falling away.
export const pulse = (clock) => Math.exp(-((clock % BEAT_MS) / BEAT_MS) * 4.5);
// How much of a thing `dz` ahead the fog leaves.
export const fog = (dz) => (dz < 120 ? 1 : clamp(1 - (dz - 120) / (FADE_D - 120), 0, 1));
export function worldArt(d) {
const { label, circle } = d;
let camL = 0;
let FW = 96;
let FH = 54;
let clock = 0;
let beat = 0;
// Where (l, dz, h) lands: [x, y, scale].
// (The view narrows a little as the ride speeds up: `near` falls from NEAR.)
let near = NEAR;
const sc = (dz) => near / (near + Math.max(dz, -near * 0.55));
const P = (l, dz, h = 0) => {
const s = sc(dz);
return [VPX + (l - camL) * LW * s, HOR + (GY0 - HOR) * s - h * HS * s, s];
};
// A box from lateral l0..l1, near depth z0 to far z1, height h0..h1: the faces the camera sees.
function box(ctx, l0, l1, z0, z1, h0, h1, c) {
const eye = (GY0 - HOR) / HS;
const n = [P(l0, z0, h0), P(l1, z0, h0), P(l1, z0, h1), P(l0, z0, h1)];
if (c.side) {
const left = l1 <= camL;
const l = left ? l1 : l0;
if (left || l0 >= camL) {
quad(ctx, P(l, z0, h0), P(l, z1, h0), P(l, z1, h1), P(l, z0, h1));
ctx.fillStyle = c.side;
ctx.fill();
}
}
if (c.top && h1 < eye) {
quad(ctx, P(l0, z0, h1), P(l1, z0, h1), P(l1, z1, h1), P(l0, z1, h1));
ctx.fillStyle = c.top;
ctx.fill();
}
quad(ctx, n[0], n[1], n[2], n[3]);
ctx.fillStyle = c.front;
ctx.fill();
return n;
}
// A wall-plane (or floor) quad between two corners at depths za..zb.
const wall = (ctx, l, za, zb, h0, h1, fill) => {
quad(ctx, P(l, za, h0), P(l, zb, h0), P(l, zb, h1), P(l, za, h1));
ctx.fillStyle = fill;
ctx.fill();
};
const floor = (ctx, l0, l1, za, zb, fill) => {
quad(ctx, P(l0, za, 0), P(l1, za, 0), P(l1, zb, 0), P(l0, zb, 0));
ctx.fillStyle = fill;
ctx.fill();
};
const glow = (ctx, x, y, r, rgb, a) => {
if (a <= 0.01 || r < 0.2) return;
ctx.globalAlpha = a;
ctx.fillStyle = rgrad(ctx, x, y, r, [[0, `rgba(${rgb},0.9)`], [0.4, `rgba(${rgb},0.35)`], [1, `rgba(${rgb},0)`]]);
ctx.fillRect(x - r, y - r, r * 2, r * 2);
};
/* ------------------------------------------------------------ the room */
// The vault, the far altar's glow and the floor's base.
function backdrop(ctx) {
ctx.fillStyle = vgrad(ctx, 0, HOR + 8, [[0, "#070a18"], [0.7, "#141a38"], [1, "#2a3052"]]);
ctx.fillRect(0, 0, FW, FH);
ctx.fillStyle = vgrad(ctx, HOR, FH, [[0, "#242a4a"], [0.5, "#161a30"], [1, "#0c0e1c"]]);
ctx.fillRect(0, HOR, FW, FH - HOR);
// The altar at the end of the nave: a rose window and its warm blaze.
const a = 0.75 + 0.25 * beat;
glow(ctx, VPX, HOR - 1, 34, "255,196,120", 0.55 * a);
glow(ctx, VPX, HOR - 1, 14, "255,236,190", 0.9 * a);
ctx.globalAlpha = 1;
ctx.fillStyle = "#1b1a2c";
ctx.fillRect(VPX - 3, HOR - 3.4, 6, 3.4);
ctx.fillStyle = "#ffe7a8";
ctx.fillRect(VPX - 0.25, HOR - 3.4, 0.5, 2.2);
ctx.fillRect(VPX - 1, HOR - 2.7, 2, 0.4);
ctx.fillStyle = `rgba(255,214,130,${0.7 + 0.3 * beat})`;
for (const k of [-2.2, -1.2, 1.2, 2.2]) disc(ctx, VPX + k, HOR - 3.8, 0.35);
}
function cell(ctx, you, c, j) {
const z0 = j * CELL - you.x;
const f = fog(z0);
if (f <= 0.02) return;
ctx.globalAlpha = f;
const warm = "255,190,110";
// Floor: two tiles, flagstone then carpet.
for (let t = 0; t < 2; t++) {
const za = z0 + t * TILE;
const zb = za + TILE;
const alt = (j * 2 + t) % 2;
floor(ctx, -WALL_L, WALL_L, za, zb, alt ? "#2b3150" : "#252a46");
floor(ctx, -2.65, 2.65, za, zb, alt ? "#3a4166" : "#333a5e");
floor(ctx, -1.5, 1.5, za, zb, alt ? "#6b1c2e" : "#5c1727");
// Tile joints and the carpet's gold edge and lane stitching.
ctx.strokeStyle = "rgba(8,10,24,0.55)";
ctx.lineWidth = 0.22 * sc(za);
seg(ctx, P(-2.65, za), P(2.65, za));
}
ctx.strokeStyle = "rgba(231,180,76,0.75)";
ctx.lineWidth = Math.max(0.12, 0.34 * sc(z0));
seg(ctx, P(-1.5, z0), P(-1.5, z0 + CELL));
seg(ctx, P(1.5, z0), P(1.5, z0 + CELL));
ctx.strokeStyle = "rgba(231,180,76,0.32)";
ctx.lineWidth = Math.max(0.1, 0.22 * sc(z0));
for (const l of [-0.5, 0.5]) {
ctx.beginPath();
for (let k = 0; k < 4; k++) {
const a = P(l, z0 + k * 4);
const b = P(l, z0 + k * 4 + 2.6);
ctx.moveTo(a[0], a[1]);
ctx.lineTo(b[0], b[1]);
}
ctx.stroke();
}
for (const side of [-1, 1]) {
const wl = side * WALL_L;
// The wall, its wainscot and cornice, and the clerestory's lancet window with its light.
wall(ctx, wl, z0, z0 + CELL, 0, 44, side < 0 ? "#222844" : "#262c4a");
wall(ctx, wl, z0, z0 + CELL, 0, 5.5, "#161a30");
box(ctx, side < 0 ? -WALL_L : WALL_L - 0.55, side < 0 ? -WALL_L + 0.55 : WALL_L, z0, z0 + CELL, 13.2, 14.4, { front: "#59629a", side: "#6f7ab0", top: "#8a96c4" });
// The slim shaft that carries a rib up the wall.
box(ctx, side < 0 ? -WALL_L : WALL_L - 0.5, side < 0 ? -WALL_L + 0.5 : WALL_L, z0, z0 + 2, 14.4, 32, { front: "#4b5480", side: "#6a76a6" });
const gi = Math.abs(j * 3 + (side > 0 ? 1 : 0)) % GLASS.length;
const rgb = GLASS[(gi + (side > 0 ? 2 : 0)) % GLASS.length];
const lit = 0.6 + 0.35 * beat;
const w = [
[z0 + 4, 16.5],
[z0 + 12, 16.5],
[z0 + 12, 27],
[z0 + 8, 32],
[z0 + 4, 27],
];
ctx.beginPath();
w.forEach(([z, h], i) => {
const p = P(wl, z, h);
if (i) ctx.lineTo(p[0], p[1]);
else ctx.moveTo(p[0], p[1]);
});
ctx.closePath();
ctx.fillStyle = "#0d1020";
ctx.fill();
ctx.fillStyle = `rgba(${rgb},${lit})`;
ctx.fill();
ctx.strokeStyle = "rgba(10,12,28,0.85)";
ctx.lineWidth = Math.max(0.08, 0.26 * sc(z0 + 8));
ctx.stroke();
seg(ctx, P(wl, z0 + 8, 16.5), P(wl, z0 + 8, 32));
seg(ctx, P(wl, z0 + 4, 22), P(wl, z0 + 12, 22));
// God rays: a slanted shaft from the window to a patch on the floor, in the glass's color.
ctx.globalCompositeOperation = "lighter";
const patch = side * 0.8;
quad(ctx, P(wl, z0 + 4, 16.5), P(wl, z0 + 12, 16.5), P(patch, z0 + 14, 0), P(patch + side * 2.1, z0 + 5, 0));
ctx.fillStyle = `rgba(${rgb},${0.05 + 0.04 * beat})`;
ctx.fill();
quad(ctx, P(patch + side * 2.1, z0 + 5, 0), P(patch, z0 + 14, 0), P(patch - side * 0.9, z0 + 15, 0), P(patch + side * 1.3, z0 + 6, 0));
ctx.fillStyle = `rgba(${rgb},${0.1 + 0.07 * beat})`;
ctx.fill();
ctx.globalCompositeOperation = "source-over";
// The pews along the aisle: seat and back.
const l0 = side < 0 ? -4.2 : 3.1;
const l1 = side < 0 ? -3.1 : 4.2;
for (let k = 0; k < 2; k++) {
const za = z0 + 8 * k + 0.8;
const tint = (j + k) % 2;
box(ctx, l0, l1, za, za + 6.4, 0, 1.7, { front: tint ? "#4a2c1a" : "#42261a", side: tint ? "#6a4128" : "#5e3a24", top: "#8a5a36" });
const b0 = side < 0 ? l0 : l1 - 0.35;
const b1 = side < 0 ? l0 + 0.35 : l1;
box(ctx, b0, b1, za, za + 6.4, 1.7, 4.2, { front: "#3a2114", side: "#5a361f", top: "#7a4c2c" });
}
// The pillar, with a sconce on it, and the rib across the vault.
const pl = side * 4.75;
const stone = { front: "#4b5480", side: "#6a76a6", top: "#7e8ab8" };
const cap = { front: "#59629a", side: "#77839f", top: "#8a96bc" };
box(ctx, pl - 0.55, pl + 0.55, z0, z0 + 2.4, 0, 13, stone);
box(ctx, pl - 0.8, pl + 0.8, z0 - 0.2, z0 + 2.6, 0, 1.6, cap);
box(ctx, pl - 0.8, pl + 0.8, z0 - 0.2, z0 + 2.6, 11.6, 13.2, cap);
const sp = P(pl - side * 0.6, z0 + 0.3, 8);
glow(ctx, sp[0], sp[1], 9 * sp[2] + 0.5, warm, 0.5 * f * (0.8 + 0.2 * beat));
ctx.globalAlpha = f;
ctx.fillStyle = "#ffd890";
disc(ctx, sp[0], sp[1], 0.4 * sp[2] + 0.1);
if (side > 0) {
ctx.strokeStyle = "#59629a";
ctx.lineWidth = Math.max(0.2, 1.0 * sc(z0));
const a = P(-5.4, z0 + 1, 32);
const b = P(5.4, z0 + 1, 32);
const m = P(0, z0 + 1, 45);
ctx.beginPath();
ctx.moveTo(a[0], a[1]);
ctx.quadraticCurveTo(m[0], m[1] - 2 * m[2] * HS, b[0], b[1]);
ctx.stroke();
}
}
ctx.globalAlpha = 1;
}
/* ----------------------------------------------------------- the things */
// A telegraph glyph over a thing: a colored mark, with its word on the first few.
function glyph(ctx, kind, answer, l, dz, h, words, extra) {
if (dz > 130 || dz < -6) return;
const p = P(l, dz, h);
const s = p[2];
const col = ANSWER_COLORS[answer];
const a = clamp((130 - dz) / 50, 0, 1) * (dz < 0 ? clamp(1 + dz / 6, 0, 1) : 1) * (0.72 + 0.28 * Math.sin(clock / 130));
if (a < 0.03) return;
ctx.globalAlpha = a;
ctx.strokeStyle = col;
ctx.fillStyle = col;
ctx.lineWidth = Math.max(0.3, 0.7 * s);
ctx.lineCap = "round";
ctx.lineJoin = "round";
const r = Math.max(0.7, 2.3 * s);
const x = p[0];
const y = p[1];
if (answer === "JUMP") {
ctx.beginPath();
ctx.moveTo(x - r, y + r * 0.5);
ctx.lineTo(x, y - r * 0.6);
ctx.lineTo(x + r, y + r * 0.5);
ctx.moveTo(x - r, y + r * 1.5);
ctx.lineTo(x, y + r * 0.4);
ctx.lineTo(x + r, y + r * 1.5);
ctx.stroke();
} else if (answer === "SLIDE") {
ctx.beginPath();
ctx.moveTo(x - r, y - r * 0.5);
ctx.lineTo(x, y + r * 0.6);
ctx.lineTo(x + r, y - r * 0.5);
ctx.moveTo(x - r, y - r * 1.5);
ctx.lineTo(x, y - r * 0.4);
ctx.lineTo(x + r, y - r * 1.5);
ctx.stroke();
} else if (answer === "SHOOT") {
circle(ctx, x, y, r);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(x - r * 1.5, y);
ctx.lineTo(x + r * 1.5, y);
ctx.moveTo(x, y - r * 1.5);
ctx.lineTo(x, y + r * 1.5);
ctx.stroke();
} else {
// SWITCH: an arrow toward each free lane beside it.
for (const dir of extra) {
ctx.beginPath();
ctx.moveTo(x + dir * r * 0.4, y - r * 0.9);
ctx.lineTo(x + dir * r * 1.6, y);
ctx.lineTo(x + dir * r * 0.4, y + r * 0.9);
ctx.moveTo(x - dir * r * 0.6, y);
ctx.lineTo(x + dir * r * 1.6, y);
ctx.stroke();
}
}
if (words && s > 0.2) label(ctx, answer === "SWITCH" ? "MOVE" : answer, x, y - r * 2.1, clamp(2.8 * s, 1.2, 2.6), col, "center", 20);
ctx.globalAlpha = 1;
}
const trim = (ctx, pts, col, w) => {
ctx.strokeStyle = col;
ctx.lineWidth = w;
ctx.beginPath();
pts.forEach((p, i) => (i ? ctx.lineTo(p[0], p[1]) : ctx.moveTo(p[0], p[1])));
ctx.stroke();
};
// Red and white hazard stripes across a block's foot: the "go round me" mark.
function hazard(ctx, l0, l1, z, h) {
const n = 6;
for (let k = 0; k < n; k++) {
const a = l0 + ((l1 - l0) * k) / n;
const b = l0 + ((l1 - l0) * (k + 1)) / n;
const lo = P(a, z, 0.2);
const hi = P(b, z, h);
ctx.fillStyle = k % 2 ? "#e8e0d0" : "#d6303c";
ctx.beginPath();
ctx.moveTo(lo[0], lo[1]);
ctx.lineTo(P(b, z, 0.2)[0], P(b, z, 0.2)[1]);
ctx.lineTo(hi[0], hi[1]);
ctx.lineTo(P(a, z, h)[0], P(a, z, h)[1]);
ctx.closePath();
ctx.fill();
}
}
function thing(ctx, you, c, q, openSides, words) {
const k = KINDS[q.kind];
const z0 = q.x - you.x;
const z1 = q.end - you.x;
const f = fog(z0);
if (f <= 0.02 || z1 < -9) return;
const l = q.lane - 1;
ctx.globalAlpha = f;
const col = ANSWER_COLORS[k.answer];
const wide = 0.42;
let top = 0;
// The mark on the floor ahead of it, in its answer's color.
if (k.answer !== "SHOOT" || q.kind === "garg") {
ctx.globalAlpha = f * 0.3;
floor(ctx, l - 0.47, l + 0.47, z0 - 5, z0 - 3.2, col);
ctx.globalAlpha = f;
}
switch (q.kind) {
case "pillar": {
box(ctx, l - wide, l + wide, z0, z1, 0, 9, { front: "#7b86b4", side: "#59638f", top: "#a0aad0" });
hazard(ctx, l - wide, l + wide, z0, 1.6);
ctx.strokeStyle = "rgba(30,36,70,0.5)";
ctx.lineWidth = Math.max(0.1, 0.2 * sc(z0));
for (const o of [-0.25, 0, 0.25]) seg(ctx, P(l + o, z0, 1.7), P(l + o, z0, 8.6));
top = 11;
break;
}
case "confessional": {
box(ctx, l - wide, l + wide, z0, z1, 0, 8.5, { front: "#4a2a1a", side: "#6a3c26", top: "#8a5636" });
const a = P(l - 0.3, z0, 6.4);
const b = P(l + 0.3, z0, 3.4);
ctx.fillStyle = "#14090a";
ctx.fillRect(a[0], a[1], b[0] - a[0], b[1] - a[1]);
ctx.strokeStyle = "#a07a46";
ctx.lineWidth = Math.max(0.1, 0.22 * sc(z0));
ctx.strokeRect(a[0], a[1], b[0] - a[0], b[1] - a[1]);
hazard(ctx, l - wide, l + wide, z0, 1.6);
top = 10.5;
break;
}
case "pewx": {
box(ctx, l - wide - 0.03, l + wide + 0.03, z0, z1, 0, 2.6, { front: "#4a2c1a", side: "#6a4128", top: "#8a5a36" });
box(ctx, l - wide - 0.03, l + wide + 0.03, z0 + 0.2, z1, 2.6, 5.6, { front: "#3a2114", side: "#5a361f", top: "#7a4c2c" });
hazard(ctx, l - wide, l + wide, z0, 1.4);
top = 7.5;
break;
}
case "kneeler": {
box(ctx, l - wide, l + wide, z0, z1, 0, 1.3, { front: "#3a2114", side: "#5a361f", top: "#7a4c2c" });
box(ctx, l - wide + 0.04, l + wide - 0.04, z0, z1, 1.3, k.h, { front: "#a8283c", side: "#7c1a2c", top: "#d04a5c" });
trim(ctx, [P(l - wide, z0, k.h), P(l + wide, z0, k.h)], col, Math.max(0.2, 0.55 * sc(z0)));
top = k.h + 2.4;
break;
}
case "stand": {
box(ctx, l - 0.28, l + 0.28, z0, z1, 0, 0.9, { front: "#2a2a38", side: "#3c3c50", top: "#58586e" });
ctx.strokeStyle = "#2c2c3c";
ctx.lineWidth = Math.max(0.2, 0.5 * sc(z0));
seg(ctx, P(l, z0 + 1, 0.8), P(l, z0 + 1, 3));
box(ctx, l - 0.4, l + 0.4, z0, z1, 2.8, 3.4, { front: "#6a6a82", side: "#4a4a60", top: "#9a9ab4" });
for (const o of [-0.26, 0, 0.26]) {
const p = P(l + o, z0 + 1, 4.2);
glow(ctx, p[0], p[1], 3.8 * p[2] + 0.3, "255,190,100", 0.7 * f);
ctx.globalAlpha = f;
ctx.fillStyle = "#fff0b8";
ctx.beginPath();
ctx.ellipse(p[0], p[1], Math.max(0.1, 0.4 * p[2]), Math.max(0.12, 0.8 * p[2]), 0, 0, TAU);
ctx.fill();
ctx.fillStyle = "#f4efe0";
const w = P(l + o, z0 + 1, 3.4);
ctx.fillRect(w[0] - 0.25 * w[2], w[1], 0.5 * w[2], Math.max(0.2, p[1] - w[1]) * -1);
}
trim(ctx, [P(l - 0.4, z0, 3.4), P(l + 0.4, z0, 3.4)], col, Math.max(0.2, 0.55 * sc(z0)));
top = 6.4;
break;
}
case "cracks":
case "hatch": {
const hatch = q.kind === "hatch";
floor(ctx, l - 0.46, l + 0.46, z0, z1, hatch ? "#05060c" : "#4a5074");
if (hatch) {
box(ctx, l - 0.46, l + 0.46, z1 - 0.7, z1, 0, 2.3, { front: "#6a7090", side: "#4a5074", top: "#8a90b0" });
ctx.globalCompositeOperation = "lighter";
floor(ctx, l - 0.3, l + 0.3, z0 + 1, z1 - 1, "rgba(120,255,160,0.1)");
ctx.globalCompositeOperation = "source-over";
} else {
ctx.strokeStyle = "#12142a";
ctx.lineWidth = Math.max(0.12, 0.34 * sc(z0));
for (let m = 0; m < 3; m++) {
ctx.beginPath();
for (let n = 0; n <= 6; n++) {
const pp = P(l - 0.4 + m * 0.4 + (n % 2 ? 0.1 : -0.1), z0 + (n * (z1 - z0)) / 6, 0.05);
if (n) ctx.lineTo(pp[0], pp[1]);
else ctx.moveTo(pp[0], pp[1]);
}
ctx.stroke();
}
box(ctx, l - 0.4, l - 0.2, z0 + 1.2, z0 + 2.4, 0, 0.8, { front: "#7a82a8", side: "#5a628a", top: "#9aa2c8" });
box(ctx, l + 0.1, l + 0.3, z1 - 2.6, z1 - 1.4, 0, 0.7, { front: "#7a82a8", side: "#5a628a", top: "#9aa2c8" });
}
trim(ctx, [P(l - 0.46, z0, 0), P(l + 0.46, z0, 0)], col, Math.max(0.25, 0.7 * sc(z0)));
trim(ctx, [P(l - 0.46, z1, 0), P(l + 0.46, z1, 0)], col, Math.max(0.2, 0.5 * sc(z1)));
top = 3.4;
break;
}
case "censer": {
const sway = Math.sin(clock / 380 + q.i * 1.7) * 0.22;
const hang = P(l, z0 + 1, 34);
const ball = P(l + sway, z0 + 1, LOW_Y + 1.3);
ctx.strokeStyle = "#8a7a52";
ctx.lineWidth = Math.max(0.15, 0.4 * ball[2]);
seg(ctx, hang, ball);
ctx.fillStyle = "#c79a3a";
disc(ctx, ball[0], ball[1], 1.6 * HS * ball[2] * 0.5 + 0.2);
ctx.fillStyle = "#6a4a14";
disc(ctx, ball[0], ball[1] + 0.2 * ball[2], 0.7 * HS * ball[2] * 0.5);
ctx.globalAlpha = f * 0.35;
ctx.fillStyle = "#cfd2e6";
for (let m = 0; m < 3; m++) disc(ctx, ball[0] + Math.sin(clock / 260 + m * 2) * 0.6 * ball[2], ball[1] - (1.6 + m * 1.4) * ball[2] * HS * 0.5, (0.5 + m * 0.3) * ball[2]);
ctx.globalAlpha = f;
trim(ctx, [P(l - 0.4, z0, LOW_Y), P(l + 0.4, z0, LOW_Y)], col, Math.max(0.2, 0.55 * sc(z0)));
top = 8;
break;
}
case "banner": {
const a = P(l - 0.44, z0, 15);
const b = P(l + 0.44, z0, 15);
const lo0 = P(l - 0.44, z0, LOW_Y);
const lo1 = P(l + 0.44, z0, LOW_Y);
const tail = P(l, z0, LOW_Y - 0.9);
ctx.fillStyle = "#5c1a6a";
ctx.beginPath();
ctx.moveTo(a[0], a[1]);
ctx.lineTo(b[0], b[1]);
ctx.lineTo(lo1[0], lo1[1]);
ctx.lineTo(tail[0], tail[1]);
ctx.lineTo(lo0[0], lo0[1]);
ctx.closePath();
ctx.fill();
ctx.strokeStyle = "#e0b04a";
ctx.lineWidth = Math.max(0.12, 0.3 * sc(z0));
ctx.stroke();
const cx = P(l, z0, 8.5);
ctx.strokeStyle = "#f0d078";
ctx.lineWidth = Math.max(0.2, 0.6 * cx[2]);
seg(ctx, P(l, z0, 11), P(l, z0, 5.6));
seg(ctx, P(l - 0.22, z0, 9.2), P(l + 0.22, z0, 9.2));
trim(ctx, [lo0, tail, lo1], col, Math.max(0.2, 0.6 * sc(z0)));
top = 17;
break;
}
case "beam": {
for (const o of [-0.4, 0.4]) {
ctx.strokeStyle = "#8a7a52";
ctx.lineWidth = Math.max(0.12, 0.3 * sc(z0));
seg(ctx, P(l + o, z0 + 1, 5.2), P(l + o, z0 + 1, 34));
}
box(ctx, l - 0.5, l + 0.5, z0, z1, LOW_Y, 5.2, { front: "#6a4128", side: "#4a2c1a", top: "#8a5a36" });
trim(ctx, [P(l - 0.5, z0, LOW_Y), P(l + 0.5, z0, LOW_Y)], col, Math.max(0.25, 0.7 * sc(z0)));
top = 8;
break;
}
case "garg":
gargoyle(ctx, you, c, q, z0, f, col);
top = ["stun", "broken"].includes(c.gargs[q.i].state) ? 0 : (c.gargs[q.i].state === "perch" || c.gargs[q.i].state === "warn" ? 17 : 11);
break;
case "bell":
bell(ctx, c, q, z0, f);
top = 0;
break;
default:
break;
}
// Its glyph, for what to do about it.
if (top) {
const free = [];
if (k.answer === "SWITCH") for (const dir of [-1, 1]) if (q.lane + dir >= 0 && q.lane + dir <= 2 && !openSides.some((o) => o === q.lane + dir)) free.push(dir);
glyph(ctx, q.kind, k.answer, l, z0 + 1, top, words, free);
}
ctx.globalAlpha = 1;
}
// A gargoyle: perched in the arch above its lane, shuddering, dropping, standing, dazed or broken.
function gargoyle(ctx, you, c, q, z0, f, col) {
const g = c.gargs[q.i];
const l = q.lane - 1;
const rise = gargRise(g);
const shake = g.state === "warn" ? Math.sin(clock / 22) * 0.18 : 0;
const p = P(l + shake, z0 + 1.5, rise * 1.2 + (g.state === "perch" || g.state === "warn" ? 11 : 0));
const s = p[2] * HS * 1.4;
const x = p[0];
const y = p[1];
if (g.state === "broken") {
ctx.fillStyle = "#59638f";
for (const [ox, oy, r] of [[-0.6, 0, 0.5], [0.4, 0.05, 0.6], [0, -0.3, 0.4]]) disc(ctx, x + ox * s * 1.3, y + oy * s, r * s * 0.8);
return;
}
// The shadow it will fall on.
if (g.state === "perch" || g.state === "warn" || g.state === "drop") {
const fl = P(l, z0 + 1.5, 0);
ctx.globalAlpha = f * (g.state === "perch" ? 0.18 : 0.45);
ctx.fillStyle = col;
ctx.beginPath();
ctx.ellipse(fl[0], fl[1], 4.4 * fl[2], 1.3 * fl[2], 0, 0, TAU);
ctx.fill();
ctx.globalAlpha = f;
}
const dazed = g.state === "stun";
ctx.fillStyle = dazed ? "#7a84b0" : "#6f7aa8";
ctx.strokeStyle = "#232a4a";
ctx.lineWidth = Math.max(0.12, 0.3 * s);
// Wings.
for (const sd of [-1, 1]) {
ctx.beginPath();
ctx.moveTo(x + sd * s * 0.9, y - s * 2.6);
ctx.lineTo(x + sd * s * 3.5, y - s * (dazed ? 2.2 : 4.4));
ctx.lineTo(x + sd * s * 3.0, y - s * 1.0);
ctx.lineTo(x + sd * s * 1.0, y - s * 1.2);
ctx.closePath();
ctx.fill();
ctx.stroke();
}
// Body, head and horns.
roundish(ctx, x, y - s * 1.6, s * 1.6, s * 2.1);
ctx.fillStyle = dazed ? "#8a94c0" : "#8490c0";
disc(ctx, x, y - s * 3.5, s * 1.15);
ctx.fillStyle = "#59638f";
for (const sd of [-1, 1]) {
ctx.beginPath();
ctx.moveTo(x + sd * s * 0.6, y - s * 4.3);
ctx.lineTo(x + sd * s * 1.1, y - s * 5.6);
ctx.lineTo(x + sd * s * 1.2, y - s * 4.1);
ctx.fill();
}
const eye = dazed ? "#9ab0ff" : g.state === "perch" ? "#80402c" : "#ff4a30";
ctx.fillStyle = eye;
for (const sd of [-1, 1]) disc(ctx, x + sd * s * 0.45, y - s * 3.6, s * 0.22);
if (!dazed && (g.state === "stand" || g.state === "drop")) {
glow(ctx, x, y - s * 3.5, 4.5 * s, "255,70,40", 0.45 * f);
ctx.globalAlpha = f;
if (g.hp < 2) {
ctx.strokeStyle = "#10142a";
ctx.lineWidth = Math.max(0.1, 0.25 * s);
seg(ctx, [x - s * 0.5, y - s * 2.6], [x + s * 0.3, y - s * 0.9]);
}
}
if (dazed) {
ctx.fillStyle = "#ffe48a";
for (let m = 0; m < 3; m++) disc(ctx, x + Math.cos(clock / 200 + m * 2.1) * s * 1.6, y - s * 5.2 + Math.sin(clock / 200 + m * 2.1) * s * 0.4, s * 0.28);
}
}
function roundish(ctx, x, y, rx, ry) {
ctx.beginPath();
ctx.ellipse(x, y, Math.max(0.05, rx), Math.max(0.05, ry), 0, 0, TAU);
ctx.fill();
ctx.stroke();
}
// A bell rope: from the vault down to a tassel, the bell up in the dark; rung, it swings.
function bell(ctx, c, q, z0, f) {
const rung = c.bells[q.i];
const l = q.lane - 1;
const sw = rung ? Math.sin(clock / 90) * 0.18 : 0;
const top = P(l, z0, 34);
const bot = P(l + sw, z0, 5.6);
ctx.strokeStyle = "#b9a374";
ctx.lineWidth = Math.max(0.3, 1.0 * bot[2]);
seg(ctx, top, bot);
ctx.fillStyle = "#d9b45a";
disc(ctx, bot[0], bot[1], Math.max(0.4, 0.9 * bot[2]));
const b = P(l + sw * 2, z0, 14);
ctx.fillStyle = rung ? "#ffe9a0" : "#c79a3a";
ctx.beginPath();
ctx.moveTo(b[0] - 1.5 * b[2] * HS * 0.8, b[1] + 1.2 * b[2] * HS * 0.8);
ctx.quadraticCurveTo(b[0] - 1.2 * b[2] * HS * 0.8, b[1] - 1.8 * b[2] * HS * 0.8, b[0], b[1] - 1.8 * b[2] * HS * 0.8);
ctx.quadraticCurveTo(b[0] + 1.2 * b[2] * HS * 0.8, b[1] - 1.8 * b[2] * HS * 0.8, b[0] + 1.5 * b[2] * HS * 0.8, b[1] + 1.2 * b[2] * HS * 0.8);
ctx.closePath();
ctx.fill();
if (rung) glow(ctx, b[0], b[1], 7 * b[2] + 1, "255,226,140", 0.6 * f);
ctx.globalAlpha = f;
trim(ctx, [P(l - 0.3, z0, 6), P(l + 0.3, z0, 6)], ANSWER_COLORS.SHOOT, 0.3);
if (!rung) glyph(ctx, "bell", "SHOOT", l, z0, 10.5, true, []);
}
/* --------------------------------------------------------------- souls */
// A wax soul: a golden candle flame with a white core; a halo, a gold ring that draws souls in.
function soul(ctx, c, you, s, i) {
const [sx, lane, h, type] = s;
let dz = sx - you.x;
const f = fog(dz);
if (f <= 0.02 || dz < -7) return;
let l = lane - 1;
let hh = h;
if (c.magnet > 0 && dz < 26) {
const k = clamp(1 - dz / 26, 0, 1) ** 2;
l += (c.lane - 1 - l) * k;
hh += (c.h + 2.2 - hh) * k;
dz *= 1 - k * 0.5;
}
const p = P(l, dz, hh + Math.sin(clock / 260 + i) * 0.25);
const r = p[2] * HS;
ctx.globalAlpha = f;
if (type === 1) {
glow(ctx, p[0], p[1], 6 * r + 1, "255,220,120", 0.7 * f);
ctx.globalAlpha = f;
ctx.strokeStyle = "#ffd75a";
ctx.lineWidth = Math.max(0.2, 0.55 * r);
ctx.beginPath();
ctx.ellipse(p[0], p[1], 1.5 * r, 0.55 * r, 0, 0, TAU);
ctx.stroke();
ctx.beginPath();
ctx.ellipse(p[0], p[1] - 0.2 * r, 1.1 * r, 0.4 * r, 0, 0, TAU);
ctx.stroke();
ctx.fillStyle = "#fff4c0";
disc(ctx, p[0], p[1] + 1.1 * r, 0.55 * r);
return;
}
glow(ctx, p[0], p[1], 2.8 * r + 0.4, "255,190,70", 0.55 * f);
ctx.globalAlpha = f;
const w = Math.max(0.18, 0.55 * r);
ctx.fillStyle = "#ffbc3a";
ctx.beginPath();
ctx.moveTo(p[0], p[1] - 1.3 * r);
ctx.quadraticCurveTo(p[0] + w * 1.5, p[1] + 0.1 * r, p[0], p[1] + 0.9 * r);
ctx.quadraticCurveTo(p[0] - w * 1.5, p[1] + 0.1 * r, p[0], p[1] - 1.3 * r);
ctx.fill();
ctx.fillStyle = "#fff6d0";
ctx.beginPath();
ctx.ellipse(p[0], p[1] + 0.25 * r, w * 0.55, 0.55 * r, 0, 0, TAU);
ctx.fill();
}
/* ------------------------------------------------------------- the pew */
// A bolt flying down its lane.
function bolt(ctx, you, s) {
const dz = s.x - you.x;
if (dz < -4 || dz > 120) return;
const lane = s.lane === undefined ? 1 : s.lane;
const p = P(lane - 1, dz, 2.4);
const q = P(lane - 1, dz - 6, 2.4);
ctx.globalAlpha = 1;
ctx.strokeStyle = "rgba(255,244,170,0.55)";
ctx.lineWidth = Math.max(0.3, 1.1 * p[2]);
ctx.lineCap = "round";
seg(ctx, p, q);
glow(ctx, p[0], p[1], 4 * p[2] + 0.5, "255,240,150", 0.8);
ctx.globalAlpha = 1;
ctx.fillStyle = "#fffbe0";
disc(ctx, p[0], p[1], Math.max(0.3, 0.7 * p[2]));
}
// The pew and YOU on it from behind: runners with sparks, the backrest ahead, the seat, the rear panel, then YOU,
// a little blue square with stick arms, the flashlight out in front and its beam down the aisle.
function hero(ctx, v, you, c) {
const lean = c.lean;
const hx = P(c.lane - 1, 0, 0)[0];
const lift = c.h * HS;
const gy = GY0;
const slide = c.slide > 0 && c.h <= 0;
const speedK = clamp((c.v - V0) / (V_MAX - V0), 0, 1);
const bob = c.h > 0 ? 0 : Math.sin(clock / 55) * 0.18 * (0.5 + speedK);
const bump = c.bump > 0 ? Math.sin(clock / 18) * 0.5 * (c.bump / BUMP_MS) : 0;
const x = hx + bump;
const y = gy - lift + bob;
const blink = you.safeMs > 0 && Math.floor(v.clock / 90) % 2 === 0;
// Shadow on the floor.
ctx.globalAlpha = 0.4 / (1 + c.h * 0.12);
ctx.fillStyle = "#04050c";
ctx.beginPath();
ctx.ellipse(hx, gy + 0.9, 6.2 / (1 + c.h * 0.05), 1.6, 0, 0, TAU);
ctx.fill();
ctx.globalAlpha = blink ? 0.45 : 1;
ctx.save();
ctx.translate(x, y);
ctx.rotate(lean * 0.17 + (c.h > 0 ? clamp(c.vh / 260, -0.1, 0.1) : 0));
// Beam of the flashlight, drawn first so everything of the pew is over it.
ctx.globalCompositeOperation = "lighter";
const beam = ctx.createLinearGradient ? ctx.createLinearGradient(0, -7, 0, -26) : null;
if (beam && beam.addColorStop) {
beam.addColorStop(0, "rgba(255,236,170,0.5)");
beam.addColorStop(1, "rgba(255,236,170,0)");
}
ctx.fillStyle = beam || "rgba(255,236,170,0.2)";
ctx.beginPath();
ctx.moveTo(3.4, -7);
ctx.lineTo(1.5, -26);
ctx.lineTo(13, -26);
ctx.closePath();
ctx.fill();
ctx.globalCompositeOperation = "source-over";
// Runners and sparks.
ctx.fillStyle = "#2a1a10";
ctx.fillRect(-4.7, -0.9, 9.4, 0.9);
if (c.h <= 0) {
ctx.fillStyle = "#ffd36a";
for (let k = 0; k < 2 + Math.floor(speedK * 5); k++) {
const t = (clock / 120 + k * 0.37) % 1;
const sx = (k % 2 ? 1 : -1) * (3.5 + rnd(k, 3) * 1.2);
disc(ctx, sx + (k % 2 ? 1 : -1) * t * 2, -0.3 - t * 2.2, 0.28 * (1 - t));
}
}
const sq = slide ? 0.55 : 1;
// Backrest (ahead of him, seen from behind), the seat, the rear panel.
ctx.fillStyle = "#3a2114";
ctx.fillRect(-5.2, -8.2 * sq - 1, 10.4, 3.1 * sq);
ctx.fillStyle = "#7a4c2c";
ctx.fillRect(-5.2, -8.2 * sq - 1, 10.4, 0.6);
ctx.fillStyle = "#6a4128";
ctx.fillRect(-4.6, -3.2, 9.2, 0.8);
ctx.fillStyle = "#4a2c1a";
ctx.beginPath();
ctx.moveTo(-4.8, -0.9);
ctx.lineTo(4.8, -0.9);
ctx.lineTo(4.8, -3.1);
ctx.quadraticCurveTo(0, -4.2, -4.8, -3.1);
ctx.closePath();
ctx.fill();
ctx.strokeStyle = "#8a5a36";
ctx.lineWidth = 0.22;
ctx.stroke();
ctx.fillStyle = "#c9a24a";
disc(ctx, 0, -2.1, 0.45);
// YOU: legs, arms, the blue square back, the flashlight in the right hand.
const ink = (v.colors && v.colors.ink) || "#1d1a17";
const body = (v.colors && v.colors.you) || "#206cc3";
ctx.save();
ctx.translate(0, -3.2);
ctx.scale(1, sq);
ctx.strokeStyle = ink;
ctx.lineWidth = 0.4;
ctx.lineCap = "round";
const step = Math.sin(clock / 70) * 0.25 * (c.h > 0 ? 0 : 1);
seg(ctx, [-1.1, -1.2], [-1.4 + step, 0]);
seg(ctx, [1.1, -1.2], [1.4 - step, 0]);
ctx.fillStyle = ink;
ctx.beginPath();
ctx.ellipse(-1.5 + step, 0.1, 0.8, 0.4, 0, 0, TAU);
ctx.ellipse(1.5 - step, 0.1, 0.8, 0.4, 0, 0, TAU);
ctx.fill();
ctx.fillStyle = body;
ctx.strokeStyle = ink;
ctx.lineWidth = 0.35;
ctx.fillRect(-3, -7.6, 6, 6.4);
ctx.strokeRect(-3, -7.6, 6, 6.4);
ctx.fillStyle = "rgba(255,255,255,0.18)";
ctx.fillRect(-2.6, -7.2, 1.4, 5.6);
ctx.fillStyle = ink;
ctx.fillRect(-1.2, -9.0, 2.4, 1.4);
// Arms out ahead, bracing, the light in the right hand.
ctx.lineWidth = 0.45;
seg(ctx, [-3, -5.6], [-4.3, -7.4 + step]);
seg(ctx, [3, -5.6], [4.2, -8.6]);
ctx.fillStyle = "#e8e4d4";
ctx.fillRect(3.4, -10.2, 1.6, 2);
ctx.fillStyle = "#fff4c0";
disc(ctx, 4.2, -10.4, 0.8);
ctx.restore();
ctx.restore();
ctx.globalAlpha = 1;
// Garlic and the halo's ring around him.
if (c.magnet > 0) {
ctx.strokeStyle = "rgba(255,215,90,0.8)";
ctx.lineWidth = 0.35;
ctx.beginPath();
ctx.ellipse(hx, y - 5, 8 + Math.sin(clock / 120) * 0.6, 7, 0, 0, TAU);
ctx.stroke();
}
}
/* ----------------------------------------------------------- the frame */
// Dust in the shafts, and the speed: streaks and a vignette that rise with the ride's pace.
function air(ctx, you, c) {
ctx.fillStyle = "#ffdca0";
for (let i = 0; i < 46; i++) {
const zz = ((rnd(i, 1) * SEE - you.x * 0.9) % SEE + SEE) % SEE;
const l = (rnd(i, 2) - 0.5) * 8;
const h = 1 + rnd(i, 3) * 20;
const p = P(l + Math.sin(clock / 1700 + i) * 0.2, zz, h + Math.cos(clock / 1300 + i * 2) * 0.3);
ctx.globalAlpha = fog(zz) * (0.1 + 0.3 * rnd(i, 4)) * (0.6 + 0.4 * beat);
disc(ctx, p[0], p[1], Math.max(0.08, 0.28 * p[2]));
}
const k = clamp((c.v - V0) / (V_MAX - V0), 0, 1);
ctx.globalAlpha = 1;
// Streaks from the vanishing point, longer and brighter the faster it goes.
ctx.lineCap = "round";
for (let i = 0; i < 26; i++) {
const a = rnd(i, 7) * TAU;
const run = (you.x * 0.02 * (0.5 + rnd(i, 8)) + rnd(i, 9)) % 1;
const r0 = 14 + run * run * 66;
const r1 = r0 + 3 + k * 22 * run;
ctx.strokeStyle = `rgba(200,220,255,${(0.1 + 0.6 * k) * run})`;
ctx.lineWidth = 0.15 + 0.5 * run;
ctx.beginPath();
ctx.moveTo(VPX + Math.cos(a) * r0 * 1.5, HOR + 8 + Math.sin(a) * r0 * 0.75);
ctx.lineTo(VPX + Math.cos(a) * r1 * 1.5, HOR + 8 + Math.sin(a) * r1 * 0.75);
ctx.stroke();
}
ctx.fillStyle = rgrad(ctx, VPX, 30, 76, [[0.45, "rgba(3,4,14,0)"], [1, `rgba(3,4,14,${0.3 + 0.4 * k})`]]);
ctx.fillRect(0, 0, FW, FH);
}
function paint(ctx, v) {
const { round } = v;
const c = round.runner;
const you = round.you;
FW = v.g.FIELD_W;
FH = v.g.FIELD_H;
clock = v.fx && typeof v.fx.clock === "number" ? v.fx.clock : v.clock || 0;
beat = pulse(clock);
camL = (c.lane - 1) * 0.55;
near = NEAR - 6 * clamp((c.v - V0) / (V_MAX - V0), 0, 1);
const R = round.spec.ride;
backdrop(ctx);
const j1 = Math.floor((you.x + SEE) / CELL);
const j0 = Math.floor((you.x - 10) / CELL);
const cues = cuesOf(R);
const flank = new Map();
// Which lanes of a block's row stay open, for the arrows.
for (const q of cues) {
if (KINDS[q.kind].answer !== "SWITCH") continue;
const key = Math.round(q.x);
if (!flank.has(key)) flank.set(key, []);
flank.get(key).push(q.lane);
}
// The things and souls bucketed by the cell their near end stands in, drawn far to near.
const lo = (list, get, x) => {
let a = 0;
let b = list.length;
while (a < b) {
const m = (a + b) >> 1;
if (get(list[m]) < x) a = m + 1;
else b = m;
}
return a;
};
const first = lo(cues, (q) => q.x, you.x - 12);
const sFirst = lo(R.souls, (s) => s[0], you.x - 8);
const after = [];
// The cues to draw, in order of depth, with the nearest (already passed) after the hero.
const draw = [];
for (let i = first; i < cues.length && cues[i].x < you.x + SEE; i++) draw.push(cues[i]);
for (let i = Math.max(0, first - 8); i < first; i++) if (cues[i].end > you.x - 10) draw.push(cues[i]);
draw.sort((a, b) => b.x - a.x);
// Count the "words" in order of approach, nearest first.
const order = {};
for (const q of cues) {
const a = KINDS[q.kind].answer;
order[q.id] = ((order[a] = (order[a] || 0) + 1) <= 3);
}
let di = 0;
let si = Math.min(R.souls.length, sFirst + 400);
// Souls to draw, nearest first.
while (si > sFirst && R.souls[si - 1][0] > you.x + SEE) si--;
const soulsNear = [];
for (let j = j1; j >= j0; j--) {
cell(ctx, you, c, j);
const zEnd = j * CELL;
// Things and souls whose near end lies from this cell's start to the next one's.
while (di < draw.length && draw[di].x >= zEnd) {
const q = draw[di++];
if ((q.x + q.end) / 2 < you.x - 1) after.push(q);
else thing(ctx, you, c, q, flank.get(Math.round(q.x)) || [], order[q.id]);
}
while (si > sFirst && R.souls[si - 1][0] >= zEnd) {
si--;
if (c.souls[si] === 0) soulsNear.push(si);
}
// Draw this cell's souls (far end first) now.
while (soulsNear.length) {
const n = soulsNear.shift();
soul(ctx, c, you, R.souls[n], n);
}
}
while (di < draw.length) {
const q = draw[di++];
if ((q.x + q.end) / 2 < you.x - 1) after.push(q);
else thing(ctx, you, c, q, flank.get(Math.round(q.x)) || [], order[q.id]);
}
for (const s of round.shots) if (!s.arm && !s.free) bolt(ctx, you, s);
hero(ctx, v, you, c);
for (const q of after) thing(ctx, you, c, q, flank.get(Math.round(q.x)) || [], false);
air(ctx, you, c);
ctx.globalAlpha = 1;
}
return { paint };
}
@@ -0,0 +1,475 @@
// Plan2Code Web Console - Ghoul Rush's Holy Roller, its rules: the Chapel's bonus round. YOU surf a runaway church pew down the nave's aisle, seen from behind, in three lanes that speed up the whole way: change lane, jump the kneelers, candle stands, flagstone cracks and crypt hatches, slide under the censers, banners and fallen beams, shoot the gargoyles that drop from the arches (or ring a bell rope to stun them), and gather the wax souls for a combo. A stage pack that ghoul.js plugs in.
//
// An endless-runner (a Subway Surfers) rather than a side-view ride, so it is handed a kit `k` of
// ghoul.js's own helpers like the Coffin Sled (ghoul-sled.js) but never imports ghoul.js. Pack fields
// used: `ride` (a hook that moves Planny himself, so no key walks him), `place` (Planny put down in a
// room: a room set up or a respawn) and `target` (a bolt strikes something that is no monster: a
// gargoyle or a bell rope). It adds no monster, boss or hazard kind, and it draws NO random number.
// Its state lives in the shared ride slot `round.runner` (`id` "pew"), and its room says `runner: "pew"`.
//
// THE FIELD IS THE ART'S ALONE: ghoul-draw.js hands the whole field to pewArt's `field` (a pseudo-3D
// view down the aisle from behind the pew), so Planny's (x, y) here is only the distance run (`you.x`) and
// the floor under it; the lane and height are the pew's own (`c.lane`, `c.h`).
//
// THE COURSE (spec.ride, built by ghoul-pew-course.js, written in seconds and laid by the ramp):
//
// - `items`: [x, lane, kind, len] (see KINDS: SWITCH the lane for a block, JUMP a low thing, SLIDE under
// a high one, SHOOT a gargoyle or a bell rope); `souls`: [x, lane, h, type] (type 1 a halo, a magnet);
// `checks` and `finish` (the distance where the ride ends) and `time` (the clock, ms) and `how`.
// - The ride speeds up with the distance covered, from V0 to about 80 over RIDE_S (speedAt): a clear
// ramp, so a run is about 66 s whatever you do. The art reads `c.v` for its speed lines and vignette.
//
// THE PEW (`round.runner`, null in any other room): { id, room, v, lane (a float, 0 to 2, sliding
// to `laneTo`), lean, h (height over the aisle), vh, slide (ms left), dive, bump, check, done,
// souls (0 open, 1 taken, 2 missed), got, combo, best, mult, comboMs, magnet, gargs, bells, hit, ... }.
// LEFT and RIGHT (a press) change lane (LANE_RATE lanes a second; a press at an edge lane bumps the
// wall, `pewBump`), UP jumps (JUMP_V against JUMP_G, about 6 high and two thirds of a second), DOWN slides
// for SLIDE_MS (in the air it fast-falls and slides on landing), hold fire to shoot straight down the lane.
//
// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life, and the pew rolls on: it is
// shoved to the nearest calm lane and blinks safe for BONUS_SAFE_MS; the last heart gone ends the round
// with nothing, at once. A counted hit breaks the combo. Causes (the game shares them, all prefixed):
// see KINDS. A gargoyle shot (two bolts) or stunned by a bell, a bell rung and the souls taken are
// the grade's: `perf.total` obstacles, `perf.hits` the ids that cost a heart, `perf.acts` against
// ACTS_GOAL, and `perf.steady` once SOUL_SHARE of the souls laid out are taken.
//
// WHAT THE ART READS: `spec.ride`, `round.runner` (above; gargs: [{ state "perch"|"warn"|"drop"|"stand"|
// "stun"|"broken", t, hp }], bells: [rung]), `round.you` (`x`, `safeMs`), `round.shots` ({ x, lane }), the
// events in EVENTS.
import { ACC, COURSE, PEW_START, RIDE_S, V0, V_MAX, speedAt, xAt } from "./ghoul-pew-course.js";
export { ACC, COURSE, PEW_START, RIDE_S, V0, V_MAX, speedAt, xAt };
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
export const MONSTERS = freeze({});
// Every event this pack puts on the field, for the art and the sounds to answer.
export const EVENTS = freeze([
"pewLane", "pewBump", "pewJump", "pewLand", "pewSlide", "pewDive", "pewSoul", "pewHalo", "pewCrash", "pewCheck", "pewFinish",
"pewGargWarn", "pewGargDrop", "pewGargChip", "pewGargHit", "pewBell", "pewSpeed",
]);
// The pew. Speeds are units down the aisle a second.
export const LANES = 3;
export const LANE_RATE = 6.5;
export const LANE_HIT = 0.5;
export const HIT_Z = 1.1;
export const JUMP_V = 36;
export const JUMP_G = 110;
export const FAST_FALL = -62;
export const STAND_H = 4.4;
export const SLIDE_H = 2;
export const SLIDE_MS = 700;
export const BUMP_MS = 180;
// The speeds at which the organ swells: the ride is picking up.
export const SWELLS = freeze([44, 54, 64, 74]);
// The things. `d` the depth of one (a row of cracks says its own), `h` the height of a low one
// (clear it with your feet over `h`), `low` the underside of a high one over the aisle.
export const LOW_Y = 2.8;
export const KINDS = freeze({
pillar: freeze({ answer: "SWITCH", d: 3.2, cause: "pewPillar" }),
confessional: freeze({ answer: "SWITCH", d: 7, cause: "pewConfessional" }),
pewx: freeze({ answer: "SWITCH", d: 3.6, cause: "pewCrosswise" }),
kneeler: freeze({ answer: "JUMP", d: 3.2, h: 2, cause: "pewKneeler" }),
stand: freeze({ answer: "JUMP", d: 2.2, h: 3.4, cause: "pewCandle" }),
cracks: freeze({ answer: "JUMP", d: 7, h: 0.8, cause: "pewFlagstone" }),
hatch: freeze({ answer: "JUMP", d: 5.5, h: 0.8, cause: "pewHatch" }),
censer: freeze({ answer: "SLIDE", d: 2.6, low: LOW_Y, cause: "pewCenser" }),
banner: freeze({ answer: "SLIDE", d: 1.8, low: LOW_Y, cause: "pewBanner" }),
beam: freeze({ answer: "SLIDE", d: 3, low: LOW_Y, cause: "pewBeam" }),
garg: freeze({ answer: "SHOOT", d: 3, h: 5, cause: "pewGargoyle" }),
bell: freeze({ answer: "SHOOT", d: 1.6, cause: "" }),
});
// The gargoyles: wake GARG_LEAD_S seconds short, shudder, drop from GARG_PERCH up, take GARG_HP bolts.
export const GARG_LEAD_S = 1.55;
export const GARG_WARN_MS = 600;
export const GARG_DROP_MS = 260;
export const GARG_PERCH = 14;
export const GARG_HP = 2;
export const GARG_POINTS = 150;
// A bell rung stuns every gargoyle still ahead of the pew within BELL_S seconds of the ride beyond the bell's rope.
export const BELL_S = 3.4;
export const BELL_POINTS = 100;
// The wax souls: a combo of COMBO_STEP in a row adds one to the multiplier (to MULT_MAX), COMBO_MS to the next.
export const SOUL_POINTS = 10;
export const HALO_POINTS = 50;
export const COMBO_STEP = 8;
export const MULT_MAX = 5;
export const COMBO_MS = 2200;
export const MAG_MS = 4500;
export const MAG_Z = 26;
export const SOUL_SHARE = 0.6;
// The shots at things (gargoyles shot or stunned, bells rung) worth a die.
export const ACTS_GOAL = 6;
export const multOf = (n) => Math.min(MULT_MAX, 1 + Math.floor(n / COMBO_STEP));
// Notes for a bonus round that cue `id` cost a heart (once each).
function noteHit(round, id) {
const b = round.bonusRound;
if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id);
}
// Every thing in the course as a cue, by x: { id, kind, i (among its kind), x, lane, len, end, answer }. Built once.
const CUES = new WeakMap();
export function cuesOf(R) {
let cues = CUES.get(R);
if (!cues) {
const seen = {};
cues = R.items.map(([x, lane, kind, len]) => {
const i = seen[kind] || 0;
seen[kind] = i + 1;
const d = len || KINDS[kind].d;
return freeze({ id: `${kind}${i}`, kind, i, x, lane, len: d, end: x + d, answer: KINDS[kind].answer });
});
CUES.set(R, freeze(cues));
cues = CUES.get(R);
}
return cues;
}
// The cues that count for the grade (the bells are only for shooting).
export const countedOf = (R) => cuesOf(R).filter((q) => q.kind !== "bell");
export const gargsOf = (R) => cuesOf(R).filter((q) => q.kind === "garg");
export const bellsOf = (R) => cuesOf(R).filter((q) => q.kind === "bell");
export const soulTotal = (R) => R.souls.filter((s) => s[3] === 0).length;
/* -------------------------------------------------------------- placing */
// A fresh set of the course's creatures: each gargoyle perched, each bell hanging. What was shot,
// stunned or rung stays so (`old`, the pew of an earlier try in the same room).
function things(R, old) {
const keep = (s) => s === "broken" || s === "stun";
return {
gargs: gargsOf(R).map((q, i) => ({ state: old && old.gargs[i] && keep(old.gargs[i].state) ? old.gargs[i].state : "perch", t: 0, hp: GARG_HP })),
bells: bellsOf(R).map((q, i) => Boolean(old && old.bells[i])),
souls: old ? old.souls : R.souls.map(() => 0),
};
}
// Planny put down in the room: on the pew at the start of a ride, or at the last checkpoint
// passed (the same room).
function place(round, k) {
const R = round.spec.ride;
if (!R || R.runner !== "pew") {
// (Another ride's state in the shared slot is not ours to touch.)
if (round.runner && round.runner.id === "pew") round.runner = null;
return;
}
const again = round.runner && round.runner.id === "pew" && round.runner.room === round.room;
const old = again ? round.runner : null;
const check = again ? round.runner.check : -1;
const x = check >= 0 ? R.checks[check] : round.spec.start;
const set = things(R, old);
Object.assign(round.you, { x, y: k.groundAt(round.spec, x), vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 });
// Souls laid before the checkpoint are behind us now.
const next = R.souls.findIndex((s, i) => s[0] >= x - 1 || (set.souls[i] = set.souls[i] || 2, false));
round.runner = {
id: "pew", room: round.room, check, v: speedAt(x), lane: 1, laneTo: 1, lean: 0, h: 0, vh: 0, slide: 0, dive: false, bump: 0, bumpDir: 0,
hl: false, hr: false, hd: false, done: false, swell: SWELLS.findIndex((s) => s > speedAt(x)) < 0 ? SWELLS.length : SWELLS.findIndex((s) => s > speedAt(x)),
got: old ? old.got : 0, combo: 0, best: old ? old.best : 0, mult: 1, comboMs: 0, magnet: 0, sNext: next < 0 ? R.souls.length : next, hit: {}, shove: 0,
...set,
};
const b = round.bonusRound;
if (b && !b.perf.total) {
b.perf.total = countedOf(R).length;
b.perf.steady = false;
b.perf.goal = ACTS_GOAL;
}
}
/* ------------------------------------------------------------ the ride */
// The pew's motion for one slice. Returns true once it has moved Planny (every slice of a ride);
// false once the ride is over.
function ride(round, ms, k) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "pew" || !c || c.id !== "pew" || c.done) return false;
const you = round.you;
const inp = round.input;
const dt = ms / 1000;
const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, lane: c.lane, h: c.h, ...extra });
c.v = speedAt(you.x);
while (c.swell < SWELLS.length && c.v >= SWELLS[c.swell]) ev("pewSpeed", { n: c.swell++, v: c.v });
steerShots(round, c);
// Lanes: a press (not a held key) moves one lane; at the edge it bumps the wall.
const left = Boolean(inp.left);
const right = Boolean(inp.right);
for (const [now, was, dir] of [[left, c.hl, -1], [right, c.hr, 1]]) {
if (!now || was) continue;
const to = c.laneTo + dir;
if (to < 0 || to >= LANES) {
c.bump = BUMP_MS;
c.bumpDir = dir;
ev("pewBump", { dir });
} else {
c.laneTo = to;
ev("pewLane", { dir, to });
}
}
c.hl = left;
c.hr = right;
const dl = c.laneTo - c.lane;
const step = LANE_RATE * dt;
c.lane = Math.abs(dl) <= step ? c.laneTo : c.lane + Math.sign(dl) * step;
c.lean += (clamp(c.laneTo - c.lane, -1, 1) - c.lean) * Math.min(1, dt * 16);
c.bump = Math.max(0, c.bump - ms);
// Jump and slide.
const ground = c.h <= 0 && c.vh <= 0;
if (inp.jump > 0 && ground) {
inp.jump = 0;
c.vh = JUMP_V;
c.h = 0.001;
c.slide = 0;
ev("pewJump");
} else if (inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms);
const down = Boolean(inp.down);
if (down && !c.hd) {
if (c.h <= 0 && c.vh <= 0) {
if (c.slide <= 0) ev("pewSlide");
c.slide = SLIDE_MS;
} else if (!c.dive) {
c.dive = true;
c.vh = Math.min(c.vh, FAST_FALL);
ev("pewDive");
}
}
c.hd = down;
c.slide = Math.max(0, c.slide - ms);
if (c.h > 0 || c.vh > 0) {
c.vh = Math.max(-120, c.vh - JUMP_G * dt);
c.h += c.vh * dt;
if (c.h <= 0) {
ev("pewLand", { big: c.vh < -45 });
c.h = 0;
c.vh = 0;
if (c.dive) {
c.slide = SLIDE_MS;
ev("pewSlide");
}
c.dive = false;
}
}
you.x += c.v * dt;
Object.assign(you, { y: k.groundAt(round.spec, you.x), vy: c.vh, state: c.h > 0 ? "air" : "run", ducking: c.slide > 0, face: 1 });
if (you.x >= R.finish) return finish(round, c, R, k);
while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) {
c.check++;
ev("pewCheck", { n: c.check + 1 });
}
obstacles(round, c, R, k);
creatures(round, c, R, ms);
souls(round, c, R, ms);
return true;
}
// The ride is over: Planny steps to the door, which the next slice walks through, and the card shows.
function finish(round, c, R, k) {
const you = round.you;
c.done = true;
round.hasKey = true;
Object.assign(you, { x: round.spec.door, y: k.groundAt(round.spec, round.spec.door), vy: 0, state: "run", ducking: false });
const b = round.bonusRound;
const share = soulShare(R, c);
if (b) b.perf.steady = share >= SOUL_SHARE;
round.events.push({ type: "pewFinish", x: you.x, y: you.y, share, best: c.best, got: c.got });
return true;
}
export const soulShare = (R, c) => c.got / Math.max(1, soulTotal(R));
// A bolt flies straight down its lane, level: the lane is the pew's at the moment it is fired.
function steerShots(round, c) {
for (const s of round.shots) {
if (s.arm || s.free) continue;
if (s.lane === undefined) s.lane = clamp(Math.round(c.lane), 0, LANES - 1);
s.vy = 0;
s.y = round.you.y + 2.4;
}
}
// Whether the pew, in its lane and at its height, is in a cue's way right now.
export function touching(c, q, x) {
const kind = KINDS[q.kind];
if (q.kind === "bell" || Math.abs(c.lane - q.lane) >= LANE_HIT) return false;
if (x < q.x - HIT_Z || x > q.end + HIT_Z) return false;
if (kind.answer === "SWITCH") return true;
if (kind.answer === "JUMP") return c.h < kind.h;
if (kind.answer === "SLIDE") return !(c.slide > 0 && c.h < 0.5);
const g = c.gargs[q.i];
return g.state === "stand" || (g.state === "drop" && g.t <= GARG_DROP_MS * 0.3);
}
// The lane nearest `from` with nothing in the way a moment before and after `x`.
export function calmLane(R, c, x, from) {
const gone = (q) => q.kind === "garg" && (c.gargs[q.i].state === "broken" || c.gargs[q.i].state === "stun");
const open = (lane) => !cuesOf(R).some((q) => q.lane === lane && q.kind !== "bell" && q.end > x - 4 && q.x < x + 14 && !gone(q));
const order = [0, 1, 2].sort((a, b) => Math.abs(a - from) - Math.abs(b - from) || a - b);
return order.find(open) ?? Math.round(from);
}
// What the pew runs into. A counted hit shoves it to a calm lane; it does the heart's cost through k.struck.
function obstacles(round, c, R, k) {
const you = round.you;
for (const q of cuesOf(R)) {
if (q.x > you.x + 8) break;
if (q.end < you.x - 8 || c.hit[q.id]) continue;
if (!touching(c, q, you.x)) continue;
if (!k.struck(round, KINDS[q.kind].cause)) continue;
c.hit[q.id] = true;
const lost = c.combo;
c.combo = 0;
c.mult = 1;
c.comboMs = 0;
noteHit(round, q.id);
c.laneTo = calmLane(R, c, you.x, c.lane);
c.vh = Math.min(c.vh, 0);
round.events.push({ type: "pewCrash", what: q.kind, id: q.id, x: you.x, y: you.y, lane: q.lane, h: c.h, lost });
return;
}
}
// The gargoyles in the arches wake when the pew comes near: shudder, drop, then stand in the lane.
function creatures(round, c, R, ms) {
const you = round.you;
gargsOf(R).forEach((q, i) => {
const g = c.gargs[i];
if (g.state === "perch") {
if ((q.x - you.x) / c.v < GARG_LEAD_S && q.end > you.x) {
Object.assign(g, { state: "warn", t: GARG_WARN_MS });
round.events.push({ type: "pewGargWarn", x: q.x, y: you.y, lane: q.lane });
}
} else if (g.state === "warn" || g.state === "drop") {
g.t -= ms;
if (g.t > 0) return;
if (g.state === "warn") Object.assign(g, { state: "drop", t: GARG_DROP_MS });
else {
Object.assign(g, { state: "stand", t: 0 });
round.events.push({ type: "pewGargDrop", x: q.x, y: you.y, lane: q.lane });
}
}
});
}
// The wax souls: taken in passing (lane and height), or pulled in by a halo's magnet.
function souls(round, c, R, ms) {
const you = round.you;
const S = R.souls;
c.magnet = Math.max(0, c.magnet - ms);
c.comboMs = Math.max(0, c.comboMs - ms);
if (!c.comboMs && c.combo) {
c.combo = 0;
c.mult = 1;
}
const body = c.slide > 0 ? SLIDE_H : STAND_H;
const reach = c.magnet > 0 ? MAG_Z : 1;
for (let i = c.sNext; i < S.length && S[i][0] <= you.x + reach; i++) {
if (c.souls[i] !== 0) continue;
const [sx, lane, h, type] = S[i];
const pulled = c.magnet > 0 && Math.abs(lane - c.lane) <= 1.05 && sx - you.x <= MAG_Z;
const met = sx <= you.x + 1;
if (!pulled && !met) continue;
const hit = pulled || (Math.abs(lane - c.lane) < 0.6 && h >= c.h - 0.8 && h <= c.h + body + 0.8);
if (!hit) {
c.souls[i] = 2;
continue;
}
c.souls[i] = 1;
if (type === 1) {
c.magnet = MAG_MS;
round.score += HALO_POINTS;
round.events.push({ type: "pewHalo", x: sx, y: you.y, lane, h, points: HALO_POINTS });
continue;
}
c.got++;
c.combo++;
c.best = Math.max(c.best, c.combo);
c.comboMs = COMBO_MS;
const was = c.mult;
c.mult = multOf(c.combo);
round.score += SOUL_POINTS * c.mult;
round.events.push({ type: "pewSoul", x: sx, y: you.y, lane, h, combo: c.combo, mult: c.mult, up: c.mult > was });
const b = round.bonusRound;
if (b) b.perf.steady = soulShare(R, c) >= SOUL_SHARE;
}
while (c.sNext < S.length && (c.souls[c.sNext] !== 0 || S[c.sNext][0] < you.x - 2)) {
if (c.souls[c.sNext] === 0) c.souls[c.sNext] = 2;
c.sNext++;
}
}
/* ------------------------------------------------------------- targets */
// How high a gargoyle is over the aisle: GARG_PERCH perched, falling as it drops, 0 standing.
export function gargRise(g) {
if (g.state === "drop") return GARG_PERCH * clamp(g.t / GARG_DROP_MS, 0, 1);
return g.state === "stand" || g.state === "stun" || g.state === "broken" ? 0 : GARG_PERCH;
}
// A bolt into something to shoot: a gargoyle falling or standing, a bell rope. True when one took it.
function pewShot(round, s) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "pew" || !c || c.id !== "pew") return false;
if (s.lane === undefined) s.lane = clamp(Math.round(c.lane), 0, LANES - 1);
const x0 = s.q === undefined ? s.x - 3 : s.q;
s.q = s.x;
const lo = Math.min(x0, s.x) - 0.6;
const hi = Math.max(x0, s.x) + 0.6;
const over = (q) => q.lane === s.lane && q.end >= lo && q.x <= hi;
const award = (n) => {
round.score += n * c.mult;
if (round.bonusRound) round.bonusRound.perf.acts++;
};
const gs = gargsOf(R);
for (let i = 0; i < gs.length; i++) {
const g = c.gargs[i];
if ((g.state !== "drop" && g.state !== "stand") || !over(gs[i])) continue;
const q = gs[i];
if (--g.hp > 0) {
round.events.push({ type: "pewGargChip", x: q.x, y: round.you.y, lane: q.lane, hp: g.hp });
return true;
}
Object.assign(g, { state: "broken", t: 0 });
award(GARG_POINTS);
round.events.push({ type: "pewGargHit", x: q.x, y: round.you.y, lane: q.lane, points: GARG_POINTS * c.mult });
return true;
}
const bs = bellsOf(R);
for (let i = 0; i < bs.length; i++) {
if (c.bells[i] || !over(bs[i])) continue;
const q = bs[i];
c.bells[i] = true;
// Every gargoyle still to come (or standing), up to BELL_S seconds of ride beyond the rope, is stunned.
let stunned = 0;
gs.forEach((gq, j) => {
const g = c.gargs[j];
if (g.state !== "broken" && g.state !== "stun" && gq.end > round.you.x && gq.x <= q.x + c.v * BELL_S) {
Object.assign(g, { state: "stun", t: 0 });
stunned++;
}
});
award(BELL_POINTS);
if (round.bonusRound) round.bonusRound.perf.acts += stunned;
round.events.push({ type: "pewBell", x: q.x, y: round.you.y, lane: q.lane, points: BELL_POINTS * c.mult, stunned });
return true;
}
return false;
}
export const PEW = freeze({
id: "pew",
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
horde: freeze({}),
ride: freeze([ride]),
place: freeze([place]),
target: pewShot,
});
@@ -7,7 +7,7 @@
// How much taller than its box a boss is drawn (the Groundskeeper's hat and
// scythe rise past his head), so the picture leaves room for it.
const REACH = Object.freeze({ keeper: 1.15, choirmaster: 1.1, matron: 1.05, beast: 1.38, frostwidow: 1.0 });
export const REACH = Object.freeze({ keeper: 1.15, choirmaster: 1.1, matron: 1.05, beast: 1.38, frostwidow: 1.0 });
export function pickerArt(d) {
const { lookOf, label, roundRect, circle, BOSS_ART, drawGourdFire, GOLD } = d;
@@ -58,6 +58,8 @@ export const POWERS = Object.freeze({
floss: Object.freeze({ name: "Cotton Candy", blurb: "Sticky bolts slow what they hit", color: "#ff9ad5", ms: 10000, weight: 3, stage: "carnival" }),
// Found only in The Frozen Lake: no sliding on the ice, no freezing, and thin ice you stand on cracks at half speed.
cocoa: Object.freeze({ name: "Hot Cocoa", blurb: "No sliding, no freezing", color: "#c8793a", ms: 10000, weight: 3, stage: "frozen" }),
// Found only in Gallows Bog: the sinking mud never slows or holds you.
boots: Object.freeze({ name: "Stilt Boots", blurb: "The mud lets you go", color: "#b08d4f", ms: 10000, weight: 3, stage: "bog" }),
// The secondary weapons, used by tapping fire twice (ghoul-arms.js has what each one does and ghoul-arms-draw.js how it looks).
// Each is a bundle of `sticks` going into the bag up to `max`. Weight 0: pickPower never picks one, so they come
// from a room's `items` and from their own band of a kill's drop roll (armDrop). No `stage`: common, anywhere.
@@ -74,10 +76,11 @@ export const POWERS = Object.freeze({
pie: Object.freeze({ name: "Custard Pie", blurb: "Splat and stun a crowd", color: "#f5e6a8", weight: 0, arm: true, sticks: 2, max: 4, stage: "carnival" }),
trap: Object.freeze({ name: "Silver Bear Trap", blurb: "Set at your feet, it snaps", color: "#d0dcea", weight: 0, arm: true, sticks: 2, max: 3, stage: "village" }),
flare: Object.freeze({ name: "Road Flare", blurb: "Burns a patch, melts the veil", color: "#ff4a2e", weight: 0, arm: true, sticks: 2, max: 4, stage: "frozen" }),
harpoon: Object.freeze({ name: "Harpoon", blurb: "Pierces, reaches under water", color: "#7fa8b0", weight: 0, arm: true, sticks: 2, max: 4, stage: "bog" }),
});
const POWER_ORDER = Object.freeze(Object.keys(POWERS));
// The word on a timed power-up's pill.
export const PILL_WORDS = Object.freeze({ spread: "SPREAD", rapid: "RAPID", lantern: "LANTERN", wings: "WINGS", bell: "BELL", silver: "SILVER", shears: "SHEARS", holy: "HOLY", salts: "SALTS", saw: "SAW", bane: "BANE", hat: "HARD HAT", floss: "FLOSS", cocoa: "COCOA" });
export const PILL_WORDS = Object.freeze({ spread: "SPREAD", rapid: "RAPID", lantern: "LANTERN", wings: "WINGS", bell: "BELL", silver: "SILVER", shears: "SHEARS", holy: "HOLY", salts: "SALTS", saw: "SAW", bane: "BANE", hat: "HARD HAT", floss: "FLOSS", cocoa: "COCOA", boots: "BOOTS" });
// The power-ups that run on a timer, in the order their pills show.
export const TIMED = Object.freeze(POWER_ORDER.filter((k) => POWERS[k].ms));
// Bat wings never flap with a surface this close under a fall.
@@ -85,7 +88,7 @@ export const FLAP_CLEAR = 4;
export const HOURGLASS_MS = 20000;
// Each stage's own weapon (the Mine's own is Dynamite).
export const STAGE_ARMS = Object.freeze({ manor: "ball", wing: "skillet", graveyard: "salt", grounds: "sickle", chapel: "fork", sanatorium: "flash", village: "trap", mine: "dyn", carnival: "pie", frozen: "flare" });
export const STAGE_ARMS = Object.freeze({ manor: "ball", wing: "skillet", graveyard: "salt", grounds: "sickle", chapel: "fork", sanatorium: "flash", village: "trap", mine: "dyn", carnival: "pie", frozen: "flare", bog: "harpoon" });
// A kill's drop roll (ghoul.js) goes to a weapon in a band of ARM_DROP past the
// power-ups and candy, no extra draw, so it shifts no other roll: about one every
// two rooms. Where in the band it fell picks which: the stage's own first
@@ -210,6 +213,10 @@ export function pickups(round, ms, kit) {
if (spec.key && !round.hasKey && near(spec.key[0], spec.key[1] + 1.6, 1.2)) {
round.hasKey = true;
round.events.push({ type: "key", x: spec.key[0], y: spec.key[1] + 1.6 });
if (spec.darkOnKey) {
round.dark = true;
round.events.push({ type: "keyDark", x: spec.key[0], y: spec.key[1] + 1.6 });
}
}
}
@@ -275,7 +282,7 @@ export function mercyKind(round, n, kit) {
export function mercySpot(round, kit) {
const { spec, you } = round;
const dir = you.face >= 0 ? 1 : -1;
const bad = (x) => [...(spec.belts || []), ...(spec.water || [])].some((s) => x >= s[0] - 1 && x <= s[1] + 1);
const bad = (x) => [...(spec.belts || []), ...(spec.water || []), ...(spec.mud || [])].some((s) => x >= s[0] - 1 && x <= s[1] + 1);
const firm = (x) => {
const s = kit.footing(round, x, you.y);
return s && (s.shelf < 0 || spec.shelves[s.shelf][3] !== "crumble") ? s : null;
@@ -47,6 +47,7 @@
// - `chandeliers`: the x of each one; it shakes and drops when you run under.
// - `boss`: null, or the boss that waits at the room's end ("gourd",
// "bones" or a stage pack's), whose arena is the last FIELD_W of the room.
// - `darkOnKey`: the room's lights go out for good when you take its key.
// - `toll`: the bell's period in ms, for a room where the bell tolls (the
// Chapel's tower and choir): about every `toll` it swings, then rings and
// freezes everything on screen for a second, you included.
@@ -65,6 +66,10 @@
// lower (ghoul.js), and blind crawlers hear his steps from further.
// The Mine's cage lifts are spawn rows too: ["cage", x, lowest y, highest y]
// (the cage's bottom), a floor board Planny rides up and down.
// - `mud`: [x0, x1] spans of the floor that are sinking mud (Gallows Bog): on
// the floor in one Planny keeps sinking while he stands, his run and his
// jump sagging the longer he stays (ghoul.js, `mudAt`, `you.mudMs`); dry
// floor or the air lets him go again. Keep a span on flat floor.
// - `belts`: [x0, x1, speed] stretches of the floor that are conveyor belts (the
// Carnival's funhouse): standing on the floor in one, Planny is carried along at
// `speed` units a second (positive runs right), on top of his own running, never
@@ -97,12 +102,49 @@
// `hands` [x, line] (a hand that reaches out of the snow: jump or shoot), `icicles` and `pops` [x, line] (shoot: a hanging
// cluster, a ghoul that pops up), `finish` (where the snowbank at the end begins; the last line ends in a lip that
// launches the sled onto it) and `how` (the controls line); no `beams`, `rubble`, `crates`, `stop` or `surge`.
// - `ride.runner`: "banister" for the Manor's Grand Banister (ghoul-banister.js): the same `track` (the first `rails` lines are the handrail,
// the rest brass under-rails beside it: the split track), `checks` and `time`, with `props` [x, line, kind] (a vase, kind 0, or a
// candlestick, kind 1: jump), `lows` [x0, x1, y] (a hanging portrait frame: duck), `swings` [x, line, amp, period ms, phase ms] (a
// chandelier on a pendulum: duck it while its bob is high, or take the under-rail), `butlers` [x, line] (lunge with a tray: jump
// or shoot), `webs` [x, line] (shoot), `finish` (where the foyer floor at the end begins) and `how`. State: `round.runner`.
// - `ride.runner`: "tray" for the East Wing's Servants' Back Stairs (ghoul-tray.js): the same `track`, `checks` and `time`, with
// `pots` [x, line, kind] (a rolling pot, kind 0, or a drop of cutlery, kind 1: jump), `lows` [x0, x1, y, kind] (duck: a swinging ham,
// kind 0, or hanging pans, kind 1, its underside y), `cooks` [x, line] (a spectral cook who flings a dish: jump it or shoot the cook),
// `domes` and `plates` [x, line, lift] (courses: run through a dome, shoot a plate), `grease` [x0, x1] (flat stretches where the
// tray speeds up), `finish` (the dining table at the end) and `how`; the room's `candy` are the cherries. The tray's state is
// `round.runner` (ghoul.js keeps that slot for a rolling bonus ride).
// - `ride.runner: "mower"`: the Grounds' Gardener's Revenge (ghoul-mower.js): a flat `track` whose gaps are ponds and ha-ha
// ditches (`gaps`: 0 a pond, 1 a ditch; jump), `junk` [x, kind] (gnome, wheelbarrow, flowerpot: jump), `lows` [x0, x1, y, kind]
// (a hedge arch, or a clothes line of gloves: duck), `hedges` [x] (thorn hedges: mow or jump), `beasts` [x] (snapping topiary:
// shoot or jump), `grass` [x0, x1] and `weeds` [x] (mow targets for the lawn-cut grade), `checks`, `finish` (where the lawn's
// end, the ground, begins), `time` and `how`. State: `round.runner`.
// - `ride.runner`: "pew" for the Chapel's Holy Roller (ghoul-pew.js): no `track`, an endless-runner in three lanes: `items` [x, lane, kind, len]
// (kinds: pillar, confessional, pewx to switch; kneeler, stand, cracks, hatch to jump; censer, banner, beam to slide; garg and bell to shoot),
// `souls` [x, lane, h, type] (wax souls and halos), `checks`, `finish` (the distance where the ride ends), `time` and `how`; built by
// ghoul-pew-course.js. State: `round.runner`.
// - `ride.runner`: "hearse" for the Graveyard's Midnight Hearse (ghoul-hearse.js): no `track`, a flat road of two lanes (0 the road,
// 1 the verge), every thing [x, lane, ...] (`graves`, `stones` [x, lane, kind], `lows` [x0, x1, lane, kind], `hands`, `crows`
// [x, lane, h], `blocks` [x0, x1, lane]), the lane `gates` [x0, x1], `lanterns` [x, lane], `fog` [x0, x1], `checks`, `finish`,
// `time` and `how`. State: `round.runner`.
// - `ride.runner`: "codeblue" for Blackmoor Sanatorium's Code Blue (ghoul-gurney.js): the same `track` (the gaps are elevator shafts), `checks` and
// `time`, with `chairs` [x, line] (a wheelchair that rolls at you: jump), `stands` [x, line] (an IV stand: jump), `lows` [x0, x1, y, kind]
// (duck: a hanging surgical lamp, kind 0, or swinging doors, kind 1, its underside y), `orderlies` [x, line] (lunge from a doorway: jump or
// shoot), `lamps` [x, line] (wave i's surge lamp, hung high: shoot it from the air and that blackout is called off), `waves` [x0, x1]
// (the lights-out spans, each with a flicker and a 3, 2, 1 before x0), `finish` (where the ambulance bay begins) and `how`.
// State: `round.runner`.
// - `ride.gallery`: true for the Carnival's dark ride (a shooting gallery, not a track: `time` the clock in ms, `ready` the
// intro's ms, `how` the controls line of its banner; see ghoul-ride.js).
// - `bonus`: true for a bonus room (the Runaway Cart, the dark ride, the Coffin Sled): it plays for 5 hearts of its own, pays
// - `ride.runner: "wagon"`: Hollow End Village's Torch Mob (ghoul-wagon.js): the same `track` (the gaps are ditches and the collapsed bridge, the
// ramp before it launches), `checks`, `time`, `finish` and `how`, with `blocks` [x, line, kind] (a barrel, kind 0, or a crate, kind 1: jump),
// `lows` [x0, x1, y, kind] (a washing line, kind 0, or an inn sign, kind 1: duck), `throwers` [x, line, kind] (a villager hurling a pitchfork,
// kind 0, duck, or a torch, kind 1, jump; both can be shot), `horses` [x, line] (a spooked horse: jump or shoot), `surge` [x0, x1, extra]
// (spans where the mob runs faster), `bridge` [x0, x1] (for the art). The mob behind (the gap) is the twist. State: `round.runner`.
// - `bonus`: true for a bonus room (the Runaway Cart, the dark ride, the Coffin Sled, Holy Roller, Code Blue, the Torch Mob): it plays for 5 hearts of its own, pays
// Lucky Dice for a finish and costs the run nothing (ghoul-bonus.js).
// - `dark`: true for a room always dark, false for one always lit; left out,
// each time it is entered it is dark DARK_CHANCE of the time (ghoul.js).
import { COURSE } from "./ghoul-pew-course.js";
export const FIELD_W = 96;
export const FIELD_H = 54;
@@ -137,11 +179,13 @@ function room(id, title, sub, spec) {
horde: freeze(spec.horde || []),
hordeMs: spec.hordeMs || 0,
dark: spec.dark ?? null,
darkOnKey: Boolean(spec.darkOnKey),
toll: spec.toll || 0,
flicker: spec.flicker || 0,
moon: spec.moon || 0,
rocks: spec.rocks || 0,
water: list(spec.water || []),
mud: list(spec.mud || []),
belts: list(spec.belts || []),
ice: list(spec.ice || []),
thin: list(spec.thin || []),
@@ -151,7 +195,7 @@ function room(id, title, sub, spec) {
export const ROOMS = freeze([
// Every run starts here: a long, easy walk with only zombies, then the
// first choice of stage.
// first choice of stage. Always lit, until you take the key.
room("hall", "The Long Hall", "Every door but one is locked", {
length: 540,
ground: [[0, 180, 6], [180, 186, 8.5], [186, 300, 11], [300, 306, 8.5], [306, 540, 6]],
@@ -164,6 +208,8 @@ export const ROOMS = freeze([
spawns: [["zombie", 80], ["zombie", 150], ["zombie", 220], ["door", 280, 2, 2200], ["zombie", 350], ["zombie", 430], ["door", 470, 2, 2200], ["zombie", 505]],
horde: ["zombie"],
hordeMs: 3400,
dark: false,
darkOnKey: true,
}),
// Zombies and the first hounds: run, shoot, climb the stairs, jump for the key.
room("foyer", "Foyer", "The front door locked behind you", {
@@ -208,6 +254,97 @@ export const ROOMS = freeze([
horde: ["zombie", "hound", "bat"],
hordeMs: 2300,
}),
// The Grand Banister, the Manor's BONUS ROUND (see ghoul-banister.js and ghoul-bonus.js): a ride, not a
// walk. YOU slide down the grand staircase's endless polished banister from the attic landing to the
// foyer, about 65 seconds of it at 46 a second: twenty flights of stairs (each a long descent and a
// short climb over the newel at the landing), seven breaks in the rail to jump, vases and candlesticks
// to jump, hanging portrait frames and swinging chandeliers to duck (the chandeliers on a timed
// pendulum: time them, or take the brass under-rail beneath them), ghostly butlers lunging with
// silver trays and cobwebs to shoot, eight places where a lower rail runs beside the handrail (jump
// and hold DOWN to dive onto it), seven checkpoints and a jump off the end of the rail (the lip) onto
// the foyer floor where the door is. Five hearts of its own. The numbers are generated.
room("banister", "The Grand Banister", "Please keep your hands and ghosts inside the rail", {
length: 3006,
ground: [[0, 30, 35.9], [2928, 3006, 10]],
start: 8,
key: null,
door: 2996,
bonus: true,
dark: false,
candy: [
[30, 39.2, 1], [44, 38.7, 1], [58, 38.2, 1], [72, 37.6, 1], [86, 36.2, 1], [100, 34.8, 1], [114, 33.4, 1], [128, 31.9, 1],
[142, 30.5, 1], [156, 29.1, 1], [170, 27.7, 1], [184, 29.5, 1], [198, 33.6, 1], [212, 36.9, 1], [220, 29.1, 1], [226, 35.5, 1],
[231, 28, 1], [240, 34.1, 1], [242, 26.9, 1], [253, 25.8, 1], [254, 32.7, 1], [264, 24.7, 1], [268, 31.3, 1], [275, 23.6, 1],
[282, 29.9, 1], [286, 22.5, 1], [296, 28.5, 1], [297, 21.4, 1], [308, 20.3, 1], [310, 27.1, 1], [324, 26.9, 1], [338, 31, 1],
[352, 35, 1], [366, 35.6, 1], [380, 34.1, 1], [394, 32.6, 1], [408, 31.1, 1], [413.7, 33.7, 1], [417.7, 35.3, 1], [421.7, 33.7, 1],
[436, 28.2, 1], [450, 26.7, 1], [464, 28.2, 1], [478, 32.5, 1], [492, 35.6, 1], [499, 27.9, 1], [506, 34.2, 1], [510, 26.8, 1],
[520, 32.8, 1], [521, 25.7, 1], [532, 24.6, 1], [534, 31.4, 1], [543, 23.5, 1], [548, 29.9, 1], [554, 22.3, 1], [562, 28.5, 1],
[565, 21.2, 1], [576, 27.1, 1], [576, 20.1, 1], [587, 19, 1], [590, 25.7, 1], [604, 24.7, 1], [618, 28.9, 1], [632, 33.2, 1],
[646, 34.6, 1], [649, 27.2, 1], [660, 33.1, 1], [660, 26.1, 1], [671, 24.9, 1], [674, 31.6, 1], [682, 23.8, 1], [688, 30.1, 1],
[693, 22.6, 1], [702, 28.7, 1], [704, 21.5, 1], [715, 20.3, 1], [716, 27.2, 1], [726, 19.1, 1], [730, 25.7, 1], [737, 18, 1],
[744, 24.2, 1], [758, 25.3, 1], [772, 29.6, 1], [786, 34, 1], [800, 33.3, 1], [814, 31.8, 1], [828, 30.2, 1], [842, 28.7, 1],
[849.5, 31.1, 1], [853.5, 32.7, 1], [857.5, 31.1, 1], [870, 25.7, 1], [884, 24.2, 1], [898, 25.9, 1], [912, 30.1, 1], [926, 33.5, 1],
[934, 25.6, 1], [940, 32, 1], [945, 24.4, 1], [954, 30.5, 1], [956, 23.3, 1], [967, 22.1, 1], [968, 29, 1], [978, 20.9, 1],
[982, 27.5, 1], [989, 19.7, 1], [996, 25.9, 1], [1000, 18.5, 1], [1010, 24.4, 1], [1011, 17.3, 1], [1024, 22.9, 1], [1038, 25.5, 1],
[1052, 29.6, 1], [1066, 33, 1], [1074, 25.1, 1], [1080, 31.4, 1], [1085, 23.9, 1], [1094, 29.9, 1], [1096, 22.7, 1], [1107, 21.5, 1],
[1108, 28.4, 1], [1118, 20.3, 1], [1122, 26.8, 1], [1129, 19.1, 1], [1136, 25.3, 1], [1140, 17.9, 1], [1150, 23.8, 1], [1151, 16.7, 1],
[1162, 15.4, 1], [1164, 22.2, 1], [1178, 21.1, 1], [1192, 25.3, 1], [1206, 29.5, 1], [1220, 32.1, 1], [1234, 30.7, 1], [1248, 29.2, 1],
[1262, 27.8, 1], [1275.9, 29.6, 1], [1279.9, 31.2, 1], [1283.9, 29.6, 1], [1290, 25, 1], [1304, 23.5, 1], [1318, 22.5, 1], [1332, 26.8, 1],
[1346, 31.2, 1], [1358, 23.8, 1], [1360, 30.6, 1], [1369, 22.7, 1], [1374, 29.2, 1], [1380, 21.6, 1], [1388, 27.8, 1], [1391, 20.5, 1],
[1402, 26.4, 1], [1402, 19.4, 1], [1413, 18.2, 1], [1416, 24.9, 1], [1424, 17.1, 1], [1430, 23.5, 1], [1435, 16, 1], [1444, 22.1, 1],
[1446, 14.9, 1], [1458, 20.7, 1], [1472, 24, 1], [1486, 28, 1], [1500, 30.9, 1], [1507, 23.1, 1], [1514, 29.4, 1], [1518, 22, 1],
[1528, 27.9, 1], [1529, 20.8, 1], [1540, 19.7, 1], [1542, 26.5, 1], [1551, 18.5, 1], [1556, 25, 1], [1562, 17.3, 1], [1570, 23.5, 1],
[1573, 16.2, 1], [1584, 22, 1], [1584, 15, 1], [1595, 13.9, 1], [1598, 20.5, 1], [1612, 21.1, 1], [1626, 25.4, 1], [1640, 29.7, 1],
[1654, 29.4, 1], [1668, 27.9, 1], [1682, 26.4, 1], [1692.2, 28.5, 1], [1696.2, 30.1, 1], [1700.2, 28.5, 1], [1710, 23.4, 1], [1724, 21.9, 1],
[1738, 20.4, 1], [1752, 21.8, 1], [1766, 26, 1], [1780, 29.8, 1], [1789, 21.9, 1], [1794, 28.4, 1], [1800, 20.8, 1], [1808, 26.9, 1],
[1811, 19.6, 1], [1822, 25.5, 1], [1822, 18.5, 1], [1833, 17.4, 1], [1836, 24.1, 1], [1844, 16.3, 1], [1850, 22.7, 1], [1855, 15.2, 1],
[1864, 21.2, 1], [1866, 14, 1], [1878, 19.8, 1], [1892, 22.7, 1], [1906, 26.8, 1], [1920, 28.6, 1], [1934, 27.1, 1], [1948, 25.6, 1],
[1962, 24.1, 1], [1976, 22.6, 1], [1990, 21.1, 1], [2004, 19.7, 1], [2018, 19.4, 1], [2032, 23.5, 1], [2046, 27.5, 1], [2060, 27.6, 1],
[2074, 26.1, 1], [2088, 24.6, 1], [2097.3, 26.7, 1], [2101.3, 28.3, 1], [2105.3, 26.7, 1], [2116, 21.5, 1], [2130, 20, 1], [2144, 18.5, 1],
[2158, 17.8, 1], [2172, 21.9, 1], [2186, 26, 1], [2200, 27.4, 1], [2214, 25.9, 1], [2228, 24.5, 1], [2242, 23, 1], [2256, 21.6, 1],
[2270, 20.1, 1], [2284, 18.7, 1], [2298, 17.2, 1], [2312, 17.4, 1], [2326, 21.6, 1], [2340, 25.8, 1], [2354, 26.4, 1], [2368, 25, 1],
[2382, 23.6, 1], [2396, 22.2, 1], [2410, 20.7, 1], [2424, 19.3, 1], [2438, 17.9, 1], [2452, 16.5, 1], [2466, 18.7, 1], [2480, 22.8, 1],
[2494, 26.6, 1], [2508, 25, 1], [2522, 23.5, 1], [2536, 22, 1], [2548.2, 23.8, 1], [2552.2, 25.4, 1], [2556.2, 23.8, 1], [2564, 18.9, 1],
[2578, 17.3, 1], [2592, 15.8, 1], [2606, 15.9, 1], [2620, 20.2, 1], [2634, 24.5, 1], [2648, 25.1, 1], [2662, 23.6, 1], [2676, 22.1, 1],
[2690, 20.6, 1], [2704, 19.1, 1], [2718, 17.7, 1], [2732, 16.2, 1], [2746, 14.7, 1], [2760, 17.7, 1], [2774, 21.8, 1], [2788, 25.2, 1],
[2802, 23.7, 1], [2816, 22.3, 1], [2830, 20.8, 1], [2844, 19.3, 1], [2846.1, 22.3, 1], [2850.1, 23.9, 1], [2854.1, 22.3, 1], [2858, 17.9, 1],
[2872, 16.4, 1], [2886, 14.9, 1], [2900, 16.5, 1], [2914, 20.4, 1],
],
items: [],
spawns: [],
horde: [],
ride: {
runner: "banister",
rails: 8,
time: 110000,
finish: 2928,
how: "UP jump, DOWN duck (in the air: dive), LEFT brake, SPACE shoot",
track: [
[[0, 37.5], [70, 35.1], [176, 24.4], [210, 34.4], [321, 23.3], [357, 33.8], [410.2, 28.2]],
[[425.2, 26.6], [457, 23.3], [489, 33.2], [603, 21.7], [639, 32.6], [752, 20.7], [788, 31.9], [847, 25.5]],
[[860, 24.1], [890, 20.8], [924, 31], [1028, 19.8], [1064, 30.5], [1177, 18.1], [1216, 29.8], [1273.9, 23.9]],
[[1285.9, 22.7], [1317, 19.5], [1348, 29.1], [1460, 17.8], [1497, 28.5], [1607, 16.9], [1643, 27.9], [1688.7, 23]],
[[1703.7, 21.4], [1745, 17], [1779, 27.2], [1881, 16.8], [1914, 26.5], [2015, 15.8], [2050, 26], [2094.8, 21.1]],
[[2107.8, 19.7], [2156, 14.5], [2193, 25.4], [2308, 13.5], [2345, 24.6], [2457, 13.3], [2493, 24], [2544.7, 18.3]],
[[2559.7, 16.7], [2602, 12], [2639, 23.3], [2749, 11.7], [2786, 22.7], [2844.1, 16.6]],
[[2856.1, 15.4], [2892, 11.6], [2918, 18.8]],
[[210, 27.4], [321, 16.3]],
[[489, 26.2], [603, 14.7]],
[[639, 25.6], [752, 13.7]],
[[924, 24], [1028, 12.8]],
[[1064, 23.5], [1177, 11.1]],
[[1348, 22.1], [1460, 10.8]],
[[1497, 21.5], [1607, 9.9]],
[[1779, 20.2], [1881, 9.8]],
],
props: [[162, 0, 0], [287, 0, 1], [714, 10, 1], [1209, 2, 0], [1239, 2, 1], [1575, 14, 1], [1731, 4, 0], [1911, 4, 1], [2065, 4, 0], [2237, 5, 1], [2388, 5, 0], [2587, 6, 0]],
lows: [[236, 243, 35], [665, 672, 33.1], [1524, 1531, 28.9], [1807, 1814, 27.5], [2148, 2155, 18.6], [2430, 2437, 19.2]],
swings: [[530, 1, 9, 2400, 1088], [966, 2, 9, 2500, 1588], [1104, 2, 9, 2500, 1497], [1389, 3, 9, 2800, 624], [1969, 4, 9, 2700, 690], [2293, 5, 9, 2600, 973], [2683, 6, 9, 2600, 1273]],
butlers: [[361, 0], [793, 1], [1648, 3], [2036, 4], [2209, 5], [2360, 5], [2491, 5], [2625, 6]],
webs: [[302, 8], [466, 1], [738, 1], [888, 2], [1300, 3], [1602, 3], [2253, 5], [2645, 6]],
checks: [388, 734, 1123, 1442, 1819, 2169, 2519],
},
}),
// The first boss.
room("ballroom", "Ballroom", "The music stopped years ago. The dancing did not", {
length: 200,
@@ -268,6 +405,99 @@ export const ROOMS = freeze([
horde: ["zombie", "hound", "bat"],
hordeMs: 2000,
}),
// The Servants' Back Stairs, the East Wing's BONUS ROUND (see ghoul-tray.js and ghoul-bonus.js): a ride, not a
// walk. YOU ride a silver serving tray down the cramped back stairs and through the steamy basement kitchens,
// about a minute of it at 44 a second (faster on the greased stretches): 18 laps of a climb onto a pantry shelf, a flat run along it and
// a flight of stairs down, with a gap between two flights each time; rolling pots and drops of cutlery to jump,
// swinging hams and hanging copper pans to duck, spectral cooks who fling dishes (jump them or shoot the cook),
// silver domes to run through and flying plates to shoot (seven of them is a full seven course meal), cherries
// along the way, eight checkpoints, and a launch off the end of the last shelf (the lip) onto the dining table where
// the door is. Five hearts of its own. The numbers are generated.
room("tray", "Last Orders", "Dinner is served. You are dinner", {
length: 3176,
ground: [[0, 30, 28.6], [3086, 3176, 21.8]],
start: 8,
key: null,
door: 3166,
bonus: true,
dark: false,
candy: [
[20, 32.6, 1], [34, 32.6, 1], [41, 32.1, 1], [46, 34.7, 1], [51, 32.1, 1], [62, 28.2, 1], [76, 25.8, 1],
[95, 24.3, 1], [99, 26.3, 1], [103, 24.3, 1], [104, 21, 1], [118, 24.9, 1], [132, 28.8, 1], [146, 32.2, 1],
[157, 33.4, 1], [162, 36, 1], [167, 33.4, 1], [174, 32.2, 1], [188, 32.2, 1], [202, 32.2, 1], [230, 29.5, 1],
[244, 27.1, 1], [258, 24.8, 1], [273, 24, 1], [277, 26, 1], [281, 24, 1], [286, 21.8, 1], [300, 25.7, 1],
[314, 29.7, 1], [328, 31.9, 1], [342, 31.9, 1], [347, 33.1, 1], [352, 35.7, 1], [357, 33.1, 1], [370, 31.9, 1],
[384, 31.9, 1], [398, 30.9, 1], [412, 28.5, 1], [426, 26.1, 1], [440, 23.7, 1], [451, 23.5, 1], [455, 25.5, 1],
[459, 23.5, 1], [468, 22.5, 1], [482, 26.5, 1], [496, 30.4, 1], [524, 31.5, 1], [538, 31.5, 1], [552, 31.5, 1],
[555, 32.7, 1], [560, 35.3, 1], [565, 32.7, 1], [580, 29.8, 1], [583, 29.7, 1], [588, 32.3, 1], [593, 29.7, 1],
[608, 25.1, 1], [629, 23.3, 1], [633, 25.3, 1], [637, 23.3, 1], [650, 23.4, 1], [664, 27.3, 1], [678, 31.2, 1],
[685, 32.4, 1], [690, 35, 1], [695, 32.4, 1], [706, 31.2, 1], [720, 31.2, 1], [734, 31.2, 1], [748, 31.2, 1],
[776, 26.4, 1], [790, 24, 1], [807, 22.9, 1], [811, 24.9, 1], [815, 22.9, 1], [818, 20.2, 1], [832, 24.1, 1],
[846, 28, 1], [860, 30.8, 1], [874, 30.8, 1], [902, 30.8, 1], [916, 30.8, 1], [930, 30.1, 1], [944, 27.7, 1],
[958, 25.3, 1], [972, 22.9, 1], [985, 22.5, 1], [989, 24.5, 1], [993, 22.5, 1], [1000, 20.9, 1], [1014, 24.8, 1],
[1028, 28.7, 1], [1042, 30.4, 1], [1045, 31.6, 1], [1050, 34.2, 1], [1055, 31.6, 1], [1070, 30.4, 1], [1084, 30.4, 1],
[1112, 29, 1], [1126, 26.7, 1], [1140, 24.3, 1], [1154, 22, 1], [1163, 22.2, 1], [1167, 24.2, 1], [1171, 22.2, 1],
[1182, 21.7, 1], [1196, 25.6, 1], [1210, 29.5, 1], [1238, 30.1, 1], [1252, 30.1, 1], [1266, 30.1, 1], [1280, 30.1, 1],
[1308, 25.7, 1], [1322, 23.3, 1], [1341, 21.8, 1], [1345, 23.8, 1], [1349, 21.8, 1], [1350, 18.5, 1], [1364, 22.4, 1],
[1378, 26.3, 1], [1392, 29.7, 1], [1406, 29.7, 1], [1415, 30.9, 1], [1420, 33.5, 1], [1425, 30.9, 1], [1434, 29.7, 1],
[1448, 29.7, 1], [1462, 29.4, 1], [1476, 27, 1], [1490, 24.6, 1], [1504, 22.3, 1], [1519, 21.5, 1], [1523, 23.5, 1],
[1527, 21.5, 1], [1532, 19.3, 1], [1546, 23.2, 1], [1560, 27.2, 1], [1574, 29.4, 1], [1602, 29.4, 1], [1616, 29.4, 1],
[1627, 30.6, 1], [1632, 33.2, 1], [1637, 30.6, 1], [1644, 28.4, 1], [1658, 26, 1], [1672, 23.6, 1], [1686, 21.2, 1],
[1697, 21, 1], [1701, 23, 1], [1705, 21, 1], [1714, 20, 1], [1728, 24, 1], [1742, 27.9, 1], [1770, 29, 1],
[1784, 29, 1], [1798, 29, 1], [1801, 30.2, 1], [1806, 32.8, 1], [1811, 30.2, 1], [1826, 27.3, 1], [1829, 27.1, 1],
[1834, 29.7, 1], [1839, 27.1, 1], [1854, 22.5, 1], [1875, 20.7, 1], [1879, 22.7, 1], [1883, 20.7, 1], [1896, 20.8, 1],
[1910, 24.7, 1], [1924, 28.6, 1], [1938, 28.6, 1], [1952, 28.6, 1], [1980, 28.6, 1], [1994, 28.6, 1], [2008, 26.2, 1],
[2022, 23.9, 1], [2036, 21.5, 1], [2053, 20.4, 1], [2057, 22.4, 1], [2061, 20.4, 1], [2064, 17.7, 1], [2078, 21.6, 1],
[2092, 25.5, 1], [2106, 28.3, 1], [2109, 29.5, 1], [2114, 32.1, 1], [2119, 29.5, 1], [2134, 28.3, 1], [2148, 28.3, 1],
[2162, 28.3, 1], [2204, 22.8, 1], [2218, 20.4, 1], [2231, 20, 1], [2235, 22, 1], [2239, 20, 1], [2246, 18.4, 1],
[2260, 22.3, 1], [2274, 26.2, 1], [2288, 27.9, 1], [2293, 29.1, 1], [2298, 31.7, 1], [2303, 29.1, 1], [2316, 27.9, 1],
[2330, 27.9, 1], [2358, 26.5, 1], [2372, 24.2, 1], [2386, 21.8, 1], [2400, 19.5, 1], [2409, 19.7, 1], [2413, 21.7, 1],
[2417, 19.7, 1], [2428, 19.2, 1], [2442, 23.1, 1], [2456, 27, 1], [2470, 27.6, 1], [2483, 28.8, 1], [2488, 31.4, 1],
[2493, 28.8, 1], [2498, 27.6, 1], [2512, 27.6, 1], [2526, 27.6, 1], [2540, 25.6, 1], [2554, 23.2, 1], [2568, 20.8, 1],
[2587, 19.3, 1], [2591, 21.3, 1], [2595, 19.3, 1], [2596, 16, 1], [2610, 19.9, 1], [2624, 23.8, 1], [2638, 27.2, 1],
[2666, 27.2, 1], [2680, 27.2, 1], [2694, 27.2, 1], [2736, 22.1, 1], [2750, 19.7, 1], [2765, 18.9, 1], [2769, 20.9, 1],
[2773, 18.9, 1], [2778, 16.7, 1], [2792, 20.6, 1], [2806, 24.6, 1], [2820, 26.8, 1], [2825, 28, 1], [2830, 30.6, 1],
[2835, 28, 1], [2848, 26.8, 1], [2862, 26.8, 1], [2890, 25.8, 1], [2904, 23.4, 1], [2918, 21.1, 1], [2932, 18.7, 1],
[2943, 18.6, 1], [2947, 20.6, 1], [2951, 18.6, 1], [2960, 17.5, 1], [2974, 21.5, 1], [2988, 25.4, 1], [3003, 27.7, 1],
[3008, 30.3, 1], [3013, 27.7, 1], [3016, 26.5, 1], [3030, 26.5, 1], [3044, 26.5, 1], [3058, 28.2, 1],
],
items: [],
spawns: [],
horde: [],
ride: {
runner: "tray",
time: 110000,
finish: 3086,
how: "UP to jump, DOWN to duck, hold space to shoot",
track: [
[[0, 30], [36, 30], [94, 20.1]],
[[104, 18.4], [144, 29.6], [214, 29.6], [272, 19.8]],
[[282, 18.1], [322, 29.3], [392, 29.3], [450, 19.4]],
[[460, 17.7], [500, 28.9], [570, 28.9], [628, 19.1]],
[[638, 17.4], [678, 28.6], [748, 28.6], [806, 18.7]],
[[816, 17], [856, 28.2], [926, 28.2], [984, 18.3]],
[[994, 16.6], [1034, 27.8], [1104, 27.8], [1162, 18]],
[[1172, 16.3], [1212, 27.5], [1282, 27.5], [1340, 17.6]],
[[1350, 15.9], [1390, 27.1], [1460, 27.1], [1518, 17.3]],
[[1528, 15.6], [1568, 26.8], [1638, 26.8], [1696, 16.9]],
[[1706, 15.2], [1746, 26.4], [1816, 26.4], [1874, 16.5]],
[[1884, 14.8], [1924, 26], [1994, 26], [2052, 16.2]],
[[2062, 14.5], [2102, 25.7], [2172, 25.7], [2230, 15.8]],
[[2240, 14.1], [2280, 25.3], [2350, 25.3], [2408, 15.5]],
[[2418, 13.8], [2458, 25], [2528, 25], [2586, 15.1]],
[[2596, 13.4], [2636, 24.6], [2706, 24.6], [2764, 14.7]],
[[2774, 13], [2814, 24.2], [2884, 24.2], [2942, 14.4]],
[[2952, 12.7], [2992, 23.9], [3052, 23.9], [3076, 30.6]],
],
pots: [[46, 0, 0], [162, 1, 0], [352, 2, 0], [560, 3, 0], [588, 3, 0], [690, 4, 0], [1050, 6, 1], [1420, 8, 0], [1632, 9, 0], [1806, 10, 0], [1834, 10, 0], [2114, 12, 0], [2298, 13, 1], [2488, 14, 0], [2830, 16, 1], [3008, 17, 0]],
lows: [[206, 214, 32.6, 1], [512, 519, 31.9, 0], [890, 898, 31.2, 1], [1092, 1099, 30.8, 0], [1224, 1231, 30.5, 0], [1582, 1589, 29.8, 0], [1758, 1765, 29.4, 0], [1958, 1966, 29, 1], [2346, 2353, 28.3, 0], [2648, 2655, 27.6, 0], [2872, 2879, 27.2, 0]],
cooks: [[766, 4], [1296, 7], [2190, 12], [2720, 15]],
domes: [[52, 0, 7], [168, 1, 7], [358, 2, 7], [566, 3, 7], [696, 4, 7], [716, 4, 0], [912, 5, 6.5], [1056, 6, 6.5], [1252, 7, 6.5], [1426, 8, 7], [1638, 9, 7], [1812, 10, 7], [1980, 11, 6.5], [2120, 12, 7], [2140, 12, 0], [2304, 13, 7], [2340, 13, 0], [2494, 14, 7], [2676, 15, 6.5], [2836, 16, 6.5], [3014, 17, 7]],
plates: [[74, 0, 2.4], [230, 1, 2.4], [392, 2, 3], [540, 3, 2.4], [730, 4, 3], [928, 5, 2.4], [1119, 6, 5], [1268, 7, 4], [1460, 8, 3], [1656, 9, 4], [1786, 10, 2.4], [1996, 11, 2.4], [2154, 12, 3], [2368, 13, 3], [2528, 14, 3], [2692, 15, 4], [2899, 16, 5], [3032, 17, 2.4]],
grease: [[324, 390], [858, 924], [1392, 1458], [1926, 1992], [2460, 2526]],
checks: [298, 654, 1010, 1366, 1722, 2078, 2434, 2790],
},
}),
// The second boss, down among the tombs.
room("crypt", "Crypt", "Something old is awake down here", {
length: 200,
@@ -322,6 +552,67 @@ export const ROOMS = freeze([
horde: ["rotter", "crow"],
hordeMs: 2200,
}),
// The Midnight Hearse, the Graveyard's BONUS ROUND (see ghoul-hearse.js and ghoul-bonus.js): a ride, not a
// walk. Planny hijacks a runaway black hearse and tears along the cemetery road at 42 a second, about 64
// seconds of it, on a flat road with two lanes (the road, and the grass verge, a raised bank beside it)
// that he switches at thirteen lane gates: open graves, headstones and fallen crosses to jump, low branches
// and the lychgate arch to duck, grasping hands and carrion crows to shoot, five closed stretches (a fallen
// oak on the road, a hedge wall on the verge) to go round, lanterns that keep the lamp lit, fog banks that
// burn it down, and six checkpoints. Five hearts of its own; a heart lost throws a coffin out ahead and a
// ghoul sits up in it to shoot. The numbers are generated: thirteen sections of four slots between the gates.
room("hearse", "The Midnight Hearse", "Everyone else is already dead on time", {
length: 2760,
ground: [[0, 2760, 9]],
start: 8,
key: null,
door: 2750,
bonus: true,
dark: false,
candy: [
[124, 11, 3], [124, 17, 3], [141, 17.5, 3], [181, 23.5, 3], [184, 11, 3], [221, 17.5, 3],
[244, 11, 3], [244, 17, 3], [261, 23.5, 3], [341, 23.5, 3], [364, 11, 3], [364, 17, 3],
[381, 17.5, 3], [421, 23.5, 3], [424, 11, 3], [461, 17.5, 3], [461, 23.5, 3], [484, 11, 3],
[484, 17, 3], [541, 23.5, 3], [604, 17, 3], [621, 23.5, 3], [661, 17.5, 3], [664, 17, 3],
[724, 11, 3], [724, 17, 3], [741, 17.5, 3], [781, 23.5, 3], [784, 11, 3], [821, 17.5, 3],
[821, 23.5, 3], [844, 11, 3], [844, 17, 3], [861, 23.5, 3], [941, 17.5, 3], [964, 11, 3],
[1021, 17.5, 3], [1024, 17, 3], [1061, 23.5, 3], [1084, 11, 3], [1084, 17, 3], [1141, 23.5, 3],
[1144, 11, 3], [1181, 17.5, 3], [1204, 11, 3], [1204, 17, 3], [1221, 23.5, 3], [1261, 17.5, 3],
[1264, 17, 3], [1324, 11, 3], [1324, 17, 3], [1341, 23.5, 3], [1384, 17, 3], [1421, 23.5, 3],
[1444, 11, 3], [1444, 17, 3], [1461, 17.5, 3], [1541, 17.5, 3], [1564, 11, 3], [1564, 17, 3],
[1581, 23.5, 3], [1621, 17.5, 3], [1624, 17, 3], [1661, 17.5, 3], [1661, 23.5, 3], [1684, 11, 3],
[1684, 17, 3], [1744, 11, 3], [1781, 17.5, 3], [1804, 11, 3], [1821, 23.5, 3], [1861, 17.5, 3],
[1864, 17, 3], [1924, 11, 3], [1924, 17, 3], [1941, 23.5, 3], [1981, 17.5, 3], [1984, 17, 3],
[2021, 23.5, 3], [2044, 11, 3], [2044, 17, 3], [2061, 17.5, 3], [2164, 17, 3], [2181, 23.5, 3],
[2221, 17.5, 3], [2224, 17, 3], [2261, 23.5, 3], [2284, 11, 3], [2284, 17, 3], [2341, 17.5, 3],
[2344, 17, 3], [2381, 23.5, 3], [2404, 11, 3], [2404, 17, 3], [2421, 17.5, 3], [2461, 17.5, 3],
[2461, 23.5, 3], [2524, 11, 3], [2524, 17, 3], [2541, 23.5, 3], [2581, 17.5, 3], [2584, 17, 3],
[2621, 17.5, 3], [2621, 23.5, 3], [2644, 11, 3], [2644, 17, 3],
],
items: [],
spawns: [],
horde: [],
ride: {
runner: "hearse",
time: 110000,
finish: 2690,
how: "LEFT or RIGHT at a gate: switch lane. UP jump, DOWN duck, SPACE shoot",
gates: [[100, 116], [300, 316], [500, 516], [700, 716], [900, 916], [1100, 1116], [1300, 1316], [1500, 1516], [1700, 1716], [1900, 1916], [2100, 2116], [2300, 2316], [2500, 2516]],
graves: [[144, 0], [464, 0], [744, 0], [1184, 0], [1464, 0], [1784, 0], [2464, 0], [2464, 1], [2624, 0], [2624, 1]],
stones: [[184, 1, 0], [464, 1, 0], [624, 1, 0], [864, 1, 0], [1024, 0, 1], [1144, 1, 0], [1344, 1, 0], [1544, 0, 1], [1664, 1, 0], [1864, 0, 1], [2224, 0, 1], [2384, 1, 0], [2584, 0, 1]],
lows: [[221, 227, 0, 1], [261, 267, 1, 0], [421, 427, 1, 0], [541, 547, 1, 0], [821, 827, 1, 0], [1421, 1427, 1, 0], [1821, 1827, 1, 0], [2021, 2027, 1, 0], [2261, 2267, 1, 0]],
hands: [[350, 1], [670, 0], [950, 0], [1070, 1], [1270, 0], [1630, 0], [1990, 0], [2190, 1], [2350, 0]],
crows: [[401, 0, 2.6], [801, 1, 2.6], [841, 0, 2.6], [1241, 1, 2.6], [1601, 1, 2.6], [1681, 0, 2.6], [1961, 1, 2.6], [2081, 0, 2.6], [2441, 0, 2.6], [2561, 1, 2.6]],
blocks: [[560, 592, 0], [960, 992, 1], [1360, 1392, 0], [1760, 1792, 1], [2160, 2192, 0]],
lanterns: [
[164, 0], [244, 0], [204, 1], [284, 1], [364, 0], [444, 0], [644, 0], [764, 0],
[844, 0], [804, 1], [884, 1], [964, 0], [1044, 0], [1164, 0], [1244, 0], [1444, 0],
[1404, 1], [1484, 1], [1564, 0], [1644, 0], [1764, 0], [1844, 0], [1964, 0], [2044, 0],
[2004, 1], [2084, 1], [2244, 0], [2364, 0], [2444, 0], [2564, 0], [2604, 1],
],
fog: [[560, 700], [1160, 1300], [1760, 1900], [2290, 2430]],
checks: [480, 880, 1280, 1680, 2080, 2480],
},
}),
// The Graveyard's boss: Mother Mourning, in the plot at the end.
room("angel", "Angel's Rest", "She has wept here for two hundred years", {
length: 200,
@@ -378,6 +669,67 @@ export const ROOMS = freeze([
horde: ["moth", "zombie", "topiary", "moth"],
hordeMs: 2000,
}),
// The Gardener's Revenge, the Grounds' BONUS ROUND (see ghoul-mower.js and ghoul-bonus.js): a ride, not a
// walk. YOU ride the gardener's rusty ride-on mower down one long straight run through the overgrown
// lawn, about 65 seconds of it at 32 a second: 8 gnomes, wheelbarrows and flowerpots and 8 thorn hedges
// to jump, 8 hedge arches and clothes lines of ghostly gloves to duck, 4 ponds and 3 ha-ha ditches to
// jump, 5 snapping topiary beasts to shoot, and the twist: hold fire and the blades cut the tall grass,
// the weed patches and the thorn hedges ahead (the blades overheat and jam, so you pulse them). Five
// checkpoints, then the lawn's end where the door is. Five hearts of its own. The numbers are generated:
// a slot every 52 units from 80 to 1900 holds one obstacle, the grass and weeds lie between.
room("mower", "The Gardener's Revenge", "The lawn has not been mowed since 1893", {
length: 2120,
ground: [[0, 30, 12], [2000, 2120, 12]],
start: 8,
key: null,
door: 2110,
bonus: true,
dark: false,
candy: [
[76, 20, 1], [80, 21.5, 1], [84, 20, 1], [100, 13.8, 1], [152, 13.8, 1], [204, 13.8, 1], [232, 20, 1], [236, 21.5, 1],
[240, 20, 1], [256, 13.8, 1], [288, 20, 1], [308, 13.8, 1], [336, 20, 1], [340, 21.5, 1], [344, 20, 1], [360, 13.8, 1],
[412, 13.8, 1], [464, 13.8, 1], [492, 20, 1], [496, 21.5, 1], [500, 20, 1], [516, 13.8, 1], [548, 20, 1], [568, 13.8, 1],
[620, 13.8, 1], [672, 13.8, 1], [700, 20, 1], [704, 21.5, 1], [708, 20, 1], [724, 13.8, 1], [752, 20, 1], [756, 21.5, 1],
[760, 20, 1], [776, 13.8, 1], [808, 20, 1], [828, 13.8, 1], [880, 13.8, 1], [932, 13.8, 1], [960, 20, 1], [964, 21.5, 1],
[968, 20, 1], [984, 13.8, 1], [1012, 20, 1], [1016, 21.5, 1], [1020, 20, 1], [1036, 13.8, 1], [1068, 20, 1], [1088, 13.8, 1],
[1140, 13.8, 1], [1192, 13.8, 1], [1220, 20, 1], [1224, 21.5, 1], [1228, 20, 1], [1244, 13.8, 1], [1276, 20, 1], [1296, 13.8, 1],
[1324, 20, 1], [1328, 21.5, 1], [1332, 20, 1], [1348, 13.8, 1], [1400, 13.8, 1], [1452, 13.8, 1], [1480, 20, 1], [1484, 21.5, 1],
[1488, 20, 1], [1504, 13.8, 1], [1536, 20, 1], [1556, 13.8, 1], [1584, 20, 1], [1588, 21.5, 1], [1592, 20, 1], [1608, 13.8, 1],
[1660, 13.8, 1], [1712, 13.8, 1], [1740, 20, 1], [1744, 21.5, 1], [1748, 20, 1], [1764, 13.8, 1], [1816, 13.8, 1], [1868, 13.8, 1],
[1900, 20, 1], [1920, 13.8, 1], [1946, 13.8, 1], [1972, 13.8, 1],
],
items: [["rapid", 366, 15.5], ["garlic", 730, 15.5], ["cocoa", 1094, 15.5], ["spread", 1510, 15.5]],
spawns: [],
horde: [],
ride: {
runner: "mower",
time: 105000,
finish: 2000,
how: "UP to jump, DOWN to duck, hold space to shoot and mow",
track: [
[[0, 12], [282.5, 12]], [[293.5, 12], [544, 12]],
[[552, 12], [802.5, 12]], [[813.5, 12], [1064, 12]],
[[1072, 12], [1270.5, 12]], [[1281.5, 12], [1532, 12]],
[[1540, 12], [1894.5, 12]], [[1905.5, 12], [2000, 12]],
],
gaps: [0, 1, 0, 1, 0, 1, 0],
junk: [[80, 0], [236, 1], [496, 2], [756, 0], [964, 2], [1224, 1], [1484, 0], [1744, 2]],
lows: [[181, 187, 15, 0], [439, 449, 15, 1], [649, 655, 15, 0], [907, 917, 15, 1], [1169, 1175, 15, 0], [1427, 1437, 15, 1], [1689, 1695, 15, 0], [1791, 1801, 15, 1]],
hedges: [132, 392, 600, 860, 1120, 1380, 1640, 1848],
beasts: [340, 704, 1016, 1328, 1588],
grass: [
[36, 58], [100, 112], [152, 171], [204, 219], [256, 278], [308, 326],
[360, 374], [412, 433], [464, 481], [516, 529], [568, 588], [620, 636],
[672, 684], [724, 743], [776, 791], [828, 850], [880, 898], [932, 946],
[984, 1005], [1036, 1053], [1088, 1101], [1140, 1160], [1192, 1208], [1244, 1256],
[1296, 1315], [1348, 1363], [1400, 1422], [1452, 1470], [1504, 1518], [1556, 1577],
[1608, 1625], [1660, 1673], [1712, 1732], [1764, 1780], [1816, 1828], [1868, 1887],
[1920, 1935], [1915, 1985],
],
weeds: [144, 248, 352, 456, 560, 664, 768, 872, 976, 1080, 1184, 1288, 1392, 1496, 1600, 1704, 1808, 1912],
checks: [418, 782, 1146, 1510, 1822],
},
}),
// The Grounds' boss: the Groundskeeper, in his yard behind the gazebo.
room("yard", "The Groundskeeper's Yard", "He has been tending this garden a long time", {
length: 200,
@@ -440,6 +792,34 @@ export const ROOMS = freeze([
horde: ["monk", "chorister", "bellbat", "zombie"],
hordeMs: 2000,
}),
// Holy Roller, the Chapel's BONUS ROUND (see ghoul-pew.js and ghoul-bonus.js): an endless-runner, seen from
// behind. YOU surf a runaway church pew down the nave's aisle in three lanes, faster and faster for about 66
// seconds: change lane, jump the low things, slide under the high ones, shoot the gargoyles (or ring a bell rope
// to stun them) and gather the wax souls for a combo. The course is written in ghoul-pew-course.js (seconds,
// laid by the speed ramp) and the whole field is drawn by the Chapel's own pseudo-3D art, so this room's
// ground is only the floor under the distance run and the door Planny steps to at the finish. Five hearts of its own.
room("pew", "Holy Roller", "The organist has been waiting for YOU", {
length: COURSE.finish + 60,
ground: [[0, COURSE.finish + 60, 12]],
start: 8,
key: null,
door: COURSE.finish + 30,
bonus: true,
dark: false,
candy: [],
items: [],
spawns: [],
horde: [],
ride: {
runner: "pew",
time: 110000,
finish: COURSE.finish,
how: "LEFT/RIGHT change lane, UP jump, DOWN slide, hold space to shoot",
items: COURSE.items,
souls: COURSE.souls,
checks: COURSE.checks,
},
}),
// The Chapel's boss: the Choirmaster at his organ. Boards at three heights
// for the staff's gaps (a note is passed on the floor or on a board).
room("choir", "The Choir", "He has been rehearsing for centuries", {
@@ -504,6 +884,51 @@ export const ROOMS = freeze([
hordeMs: 2000,
flicker: 6500,
}),
// Code Blue, Blackmoor Sanatorium's BONUS ROUND (see ghoul-gurney.js and ghoul-bonus.js): a ride, not a
// walk. YOU lie strapped to a runaway hospital gurney that flies down the sanatorium's endless corridors
// and ramps, about 67 seconds of it at 48 a second: eight corridors joined by seven elevator shafts to jump,
// 8 wheelchairs (they roll at you) and 7 IV stands to jump, 11 hanging surgical lamps and swinging doors to duck,
// 11 orderlies who lunge from doorways (jump or shoot), seven checkpoints, and a loading ramp at the end that
// launches the gurney out of the ambulance doors onto the bay where the door is. Five hearts of its own.
// The twist is the lights: 6 blackouts, each announced by a flicker and a 3, 2, 1, then pitch black (only the
// flashlight cone, the dying emergency strips and a faint glow on what is near), unless the buzzing surge lamp
// hung high before it is shot out from the air (no low hangs in the 80 before a lamp: room to hop). The numbers are generated.
room("codeblue", "Code Blue", "Please remain calm. The gurney will not", {
length: 3294,
ground: [[0, 30, 20.6], [3216, 3294, 10]],
start: 8,
key: null,
door: 3284,
bonus: true,
dark: false,
candy: [],
items: [],
spawns: [],
horde: [],
ride: {
runner: "codeblue",
time: 100000,
finish: 3216,
how: "UP to jump, DOWN to duck, hold space to shoot",
track: [
[[0, 22], [75, 22], [108, 17], [194, 17], [226, 22], [312, 22], [339, 18], [370, 18]],
[[382, 16], [476, 16], [508, 12], [639, 12], [673, 18], [745, 18], [762, 18]],
[[776, 15], [849, 15], [910, 24], [1024, 24], [1078, 17], [1160, 17]],
[[1173, 13], [1298, 13], [1330, 17], [1407, 17], [1459, 25], [1531, 25], [1561, 25]],
[[1576, 23], [1696, 23], [1762, 15], [1871, 15], [1898, 19], [1968, 19]],
[[1980, 16], [2067, 16], [2121, 24], [2250, 24], [2279, 29], [2376, 29]],
[[2390, 28], [2483, 28], [2539, 20], [2633, 20], [2681, 27], [2770, 27], [2788, 27]],
[[2804, 22], [2904, 22], [2958, 14], [3048, 14], [3074, 19], [3110, 19], [3180, 11.6], [3206, 18.8]],
],
chairs: [[288, 0], [445, 1], [996, 2], [1227, 3], [1275, 3], [1828, 4], [2454, 6], [3021, 7]],
stands: [[236, 0], [511, 1], [683, 1], [1103, 2], [1901, 4], [2704, 6], [2856, 7]],
lows: [[48.8, 55.2, 25, 1], [122, 128.4, 20, 0], [556.6, 563, 15, 0], [620.8, 627.2, 15, 1], [1336.8, 1343.2, 20, 0], [1466.6, 1473, 28, 1], [1502.8, 1509.2, 28, 1], [1673.6, 1680, 26, 1], [2034.8, 2041.2, 19, 1], [2601.4, 2607.8, 23, 0], [3082, 3088.4, 22, 1]],
orderlies: [[840, 2], [913, 2], [948, 2], [1404, 3], [1628, 4], [1780, 4], [2133, 5], [2212, 5], [2283, 5], [2550, 6], [2966, 7]],
lamps: [[350, 0], [830, 2], [1310, 3], [1770, 4], [2250, 5], [2730, 6]],
waves: [[420, 590], [900, 1080], [1380, 1570], [1840, 2040], [2320, 2530], [2800, 3000]],
checks: [390, 784, 1181, 1584, 1988, 2398, 2812],
},
}),
// The Sanatorium's boss: the Night Matron, on her rounds in the ward. Two
// medicine cabinets (raised floor blocks 4.5 high at 136 and 164: cover from
// her lantern, which hangs 8 over her feet; bolts stop at them too) and, up
@@ -570,6 +995,47 @@ export const ROOMS = freeze([
hordeMs: 2285,
moon: 35000,
}),
// The Torch Mob, Hollow End Village's BONUS ROUND (see ghoul-wagon.js and ghoul-bonus.js): a ride, not a
// walk. Planny steals a hay wagon and races out of the village down the cobbled road and over the old stone
// bridge, about 68 seconds of it at 42 a second, a torch-and-pitchfork mob on his heels: 7 barrels and crates
// to jump, 6 washing lines and inn signs to duck, 4 ditches and the collapsed bridge (off its ramp) to jump,
// 9 villagers who hurl pitchforks (duck) and torches (jump) from windows and roofs, any of them to shoot, 2
// spooked horses, seven checkpoints and a lip off the end onto the green. The mob's gap is the twist (the
// brake and the hits close it, clean riding and shot torches open it). Five hearts of its own. No candy and no pickups.
room("wagon", "Torch Mob", "Hollow End sends its regards. Loudly", {
length: 2990,
ground: [[0, 40, 14], [2880, 2990, 7]],
start: 34,
key: null,
door: 2980,
bonus: true,
dark: false,
candy: [],
items: [],
spawns: [],
horde: [],
ride: {
runner: "wagon",
time: 105000,
finish: 2880,
how: "UP to jump, DOWN to duck (it slows you), hold space to shoot",
bridge: [2236, 2730],
track: [
[[0, 16], [376, 16]],
[[384, 16], [880, 16]],
[[888, 16], [1370, 16]],
[[1378, 16], [1940, 16]],
[[1948, 16], [2236, 16], [2330, 22], [2552, 22], [2576, 29.2]],
[[2602, 23], [2690, 23], [2760, 16], [2866, 16], [2880, 19.92]],
],
blocks: [[133,0,0], [303,0,1], [673,1,0], [1173,2,1], [1673,3,0], [2153,4,1], [2803,5,0]],
lows: [[210,216,19,0], [584,590,19,1], [978,984,19,0], [1470,1476,19,1], [1860,1866,19,0], [2652,2658,26,1]],
throwers: [[520,1,0], [790,1,1], [1290,2,0], [1590,3,1], [2080,4,0], [2330,4,1], [2400,4,0], [2490,4,1], [2730,5,0]],
horses: [[1100,2], [1790,3]],
surge: [[2330, 2540, 6]],
checks: [460, 830, 1230, 1640, 2000, 2270, 2690],
},
}),
// The Village's boss: the Beast, on the green. The arena's two ends are the
// walls it clings to (not terrain: nothing to jump); boards at 12 and 17.5
// either side, the high ones above the floor-bound Beast's reach (10.5 tall).
@@ -966,6 +1432,120 @@ export const ROOMS = freeze([
spawns: [["zombie", 40], ["frozen", 66]],
boss: "frostwidow",
}),
// Gallows Bog: a sunken boardwalk over the mire. Rotting planks with gaps,
// boards that give way, and mud that grabs you in the dips. The stage's own
// kinds: lurkers' eyes in the mud, leech swarms in the wet, wisps to lure
// the dead onto you and bog bodies risen from the muck; Stilt Boots and the
// Harpoon are placed before what they answer.
room("boardwalk", "Sunken Boardwalk", "Mind the gaps. Something lives in them", {
length: 480,
ground: [[0, 90, 6], [100, 180, 6], [190, 262, 6], [262, 268, 8.5], [268, 320, 11], [330, 402, 6], [410, 480, 6]],
mud: [[24, 84], [118, 172], [342, 396]],
shelves: [[40, 56, 11], [140, 156, 15], [200, 216, 15], [236, 252, 24], [240, 248, 15], [344, 360, 15], [372, 388, 15, "crumble"], [420, 436, 15]],
key: [244, 24],
door: 470,
candy: [[18, 8.5, 4], [41, 14, 3], [102, 8.5, 4], [141, 18, 3], [201, 18, 3], [237, 27, 3], [282, 13.5, 4], [345, 18, 3], [412, 8.5, 4], [421, 18, 3]],
items: [["boots", 20, 6], ["wings", 60, 6], ["harpoon", 128, 6], ["spread", 148, 15], ["garlic", 208, 15], ["rocket", 350, 6]],
sky: [["crystal", 238, 44], ["crystal", 244, 46], ["crystal", 250, 44]],
spawns: [["lurker", 40], ["leech", 60], ["lurker", 140], ["leech", 155], ["bogbody", 174], ["wisp", 210, 14], ["door", 214, 2, 1800, "bogbody"], ["bogbody", 290], ["lurker", 356], ["leech", 375], ["wisp", 400, 14]],
horde: ["leech", "wisp", "bogbody"],
hordeMs: 2600,
}),
// Cypress Hollow: shallow pools of black water beside the mud, moss-veiled
// boards, a little harder.
room("hollow", "Cypress Hollow", "The moss is breathing", {
length: 520,
ground: [[0, 120, 6], [120, 126, 8.5], [126, 200, 11], [200, 206, 8.5], [206, 300, 6], [310, 404, 6], [404, 410, 8.5], [410, 446, 11], [454, 520, 6]],
water: [[22, 78], [216, 286]],
mud: [[90, 114], [322, 396], [460, 510]],
shelves: [[30, 46, 11], [96, 112, 15], [140, 156, 17], [162, 178, 17, "crumble"], [226, 242, 15], [250, 266, 24], [262, 278, 15], [330, 346, 15], [356, 372, 15], [386, 402, 15, "crumble"], [420, 436, 17], [466, 482, 15]],
key: [258, 24],
door: 510,
candy: [[18, 8.5, 4], [31, 14, 3], [97, 18, 3], [141, 20, 3], [208, 8.5, 4], [227, 18, 3], [251, 27, 3], [331, 18, 3], [357, 18, 3], [412, 13.5, 4], [421, 20, 3], [467, 18, 3]],
items: [["wings", 40, 6], ["boots", 86, 6], ["lantern", 104, 15], ["spread", 232, 15], ["harpoon", 312, 6], ["hourglass", 428, 17]],
sky: [["crystal", 252, 44], ["silver", 258, 46], ["crystal", 264, 44]],
spawns: [["leech", 40], ["lurker", 100], ["wisp", 150, 16], ["bogbody", 200], ["leech", 250], ["door", 336, 3, 1500, "bogbody"], ["lurker", 340], ["wisp", 430, 16], ["bogbody", 470], ["leech", 485]],
horde: ["leech", "bogbody", "wisp"],
hordeMs: 2300,
}),
// Stilt House: the hag's house on stilts, its floors stacked shelves over
// the swamp. The hardest of the three.
room("stilts", "Stilt House", "She has been expecting you", {
length: 560,
ground: [[0, 140, 6], [150, 236, 6], [236, 242, 8.5], [242, 248, 11], [248, 254, 13.5], [254, 330, 16], [330, 336, 13.5], [336, 342, 11], [342, 348, 8.5], [348, 430, 6], [438, 560, 6]],
water: [[160, 230]],
mud: [[30, 132], [356, 424], [446, 540]],
shelves: [[20, 36, 11], [56, 72, 15], [100, 116, 15, "crumble"], [160, 176, 15], [196, 212, 15], [266, 282, 22], [292, 308, 24], [358, 374, 15], [400, 416, 15], [462, 478, 15], [500, 516, 17], [520, 536, 17, "crumble"]],
key: [300, 24],
door: 550,
candy: [[18, 8.5, 4], [57, 18, 3], [101, 18, 3], [161, 18, 3], [197, 18, 3], [266, 25, 3], [293, 27, 3], [359, 18, 3], [401, 18, 3], [440, 8.5, 4], [463, 18, 3], [501, 20, 3]],
items: [["wings", 60, 6], ["rapid", 168, 15], ["dyn", 204, 15], ["boots", 350, 6], ["harpoon", 380, 6], ["garlic", 404, 15], ["rocket", 508, 17]],
sky: [["crystal", 296, 44], ["crystal", 302, 46], ["crystal", 308, 44]],
spawns: [["lurker", 70], ["wisp", 140, 16], ["leech", 190], ["bogbody", 240], ["lurker", 390], ["door", 412, 3, 1400, "bogbody"], ["wisp", 460, 16], ["bogbody", 480], ["leech", 500]],
horde: ["bogbody", "leech"],
hordeMs: 2000,
}),
// The Bog Runner, Gallows Bog's BONUS ROUND: a fan-boat skim over black
// water with a leech swarm in its wake. A ride, not a walk; the course is
// from a one-off hash generator (no random draws), the rules are in
// ghoul-bogboat.js.
room("bogboat", "The Bog Runner", "Something swims in your wake", {
length: 2400,
ground: [[0, 2400, 9]],
start: 8,
key: null,
door: 2390,
bonus: true,
dark: false,
candy: [
[14, 11.5, 4], [140, 11.6, 3], [144, 11.6, 3], [180, 17.5, 3], [210, 11.6, 3], [216, 10.4, 3], [216, 17.6, 3], [240, 17.6, 3],
[252, 17.5, 3], [280, 11.6, 3], [344, 10.4, 3], [344, 23.5, 3], [350, 11.6, 3], [380, 10.4, 3], [380, 17.6, 3], [416, 10.4, 3],
[416, 17.6, 3], [420, 11.6, 3], [450, 17.6, 3], [452, 17.5, 3], [452, 17.6, 3], [490, 11.6, 3], [544, 17.5, 3], [544, 17.6, 3],
[560, 11.6, 3], [580, 17.5, 3], [580, 17.6, 3], [616, 11.6, 3], [616, 17.6, 3], [630, 11.6, 3], [652, 17.5, 3], [652, 17.6, 3],
[660, 17.6, 3], [700, 11.6, 3], [744, 17.5, 3], [744, 17.6, 3], [770, 11.6, 3], [780, 11.6, 3], [780, 16.4, 3], [816, 10.4, 3],
[816, 17.6, 3], [840, 11.6, 3], [852, 10.4, 3], [852, 17.6, 3], [870, 17.6, 3], [910, 11.6, 3], [944, 10.4, 3], [944, 16.4, 3],
[980, 11.6, 3], [980, 23.5, 3], [980, 11.6, 3], [1016, 10.4, 3], [1016, 16.4, 3], [1050, 11.6, 3], [1052, 17.5, 3], [1052, 17.6, 3],
[1080, 17.6, 3], [1120, 11.6, 3], [1144, 11.6, 3], [1144, 17.6, 3], [1180, 11.6, 3], [1180, 17.6, 3], [1190, 11.6, 3], [1216, 17.6, 3],
[1252, 17.5, 3], [1252, 17.6, 3], [1260, 11.6, 3], [1290, 17.6, 3], [1330, 11.6, 3], [1344, 11.6, 3], [1344, 23.5, 3], [1380, 23.5, 3],
[1400, 11.6, 3], [1416, 17.5, 3], [1416, 23.5, 3], [1452, 10.4, 3], [1452, 16.4, 3], [1470, 11.6, 3], [1500, 17.6, 3], [1540, 11.6, 3],
[1544, 17.5, 3], [1544, 17.6, 3], [1580, 17.5, 3], [1610, 11.6, 3], [1616, 10.4, 3], [1616, 17.6, 3], [1652, 17.5, 3], [1680, 11.6, 3],
[1710, 17.6, 3], [1744, 11.6, 3], [1744, 17.6, 3], [1750, 11.6, 3], [1780, 11.6, 3], [1816, 17.5, 3], [1816, 17.6, 3], [1820, 11.6, 3],
[1852, 10.4, 3], [1852, 17.6, 3], [1890, 11.6, 3], [1920, 17.6, 3], [1944, 17.5, 3], [1944, 17.6, 3], [1960, 11.6, 3], [1980, 17.5, 3],
[1980, 23.5, 3], [2016, 17.5, 3], [2030, 11.6, 3], [2052, 10.4, 3], [2052, 23.5, 3], [2100, 11.6, 3], [2130, 17.6, 3], [2144, 10.4, 3],
[2144, 23.5, 3], [2170, 11.6, 3], [2180, 11.6, 3], [2180, 16.4, 3], [2216, 11.6, 3], [2216, 17.6, 3], [2240, 11.6, 3], [2252, 10.4, 3],
[2252, 23.5, 3], [2330, 11.5, 4],
],
spawns: [],
horde: [],
ride: {
runner: "bogboat",
how: "LEFT or RIGHT at a bank: switch lane. UP jump, DOWN duck, SPACE shoot",
time: 100000,
finish: 2320,
checks: [480, 960, 1440, 1920],
banks: [[90, 106], [290, 306], [490, 506], [690, 706], [890, 906], [1090, 1106], [1290, 1306], [1490, 1506], [1690, 1706], [1890, 1906], [2090, 2106]],
snags: [[180, 0], [452, 0], [580, 0], [744, 0], [980, 1], [1052, 0], [1252, 0], [1344, 1], [1416, 0], [1416, 1], [1580, 0], [1652, 0], [1980, 0], [2052, 1], [2144, 1], [2252, 1]],
knees: [[252, 0], [344, 1], [544, 0], [652, 0], [1380, 1], [1544, 0], [1816, 0], [1944, 0], [1980, 1], [2016, 0]],
veils: [[340, 348, 0], [776, 784, 1], [848, 856, 0], [940, 948, 0], [940, 948, 1], [1448, 1456, 0], [1448, 1456, 1], [1848, 1856, 0], [2048, 2056, 0], [2140, 2148, 0], [2176, 2184, 1], [2248, 2256, 0]],
limbs: [[213, 219, 0], [377, 383, 0], [413, 419, 0], [813, 819, 0], [1013, 1019, 0], [1013, 1019, 1], [1613, 1619, 0]],
props: [[144, 0, 0], [544, 1, 0], [580, 1, 1], [616, 0, 1], [616, 1, 0], [780, 0, 1], [816, 1, 0], [1052, 1, 0], [1144, 0, 1], [1144, 1, 0], [1180, 0, 1], [1180, 1, 1], [1344, 0, 0], [1744, 0, 1], [1780, 0, 0], [1944, 1, 1]],
gas: [[216, 1], [380, 1], [416, 1], [452, 1], [652, 1], [744, 1], [852, 1], [980, 0], [1216, 1], [1252, 1], [1544, 1], [1616, 1], [1744, 1], [1816, 1], [1852, 1], [2180, 0], [2216, 0], [2216, 1]],
},
}),
// The Drowning Pool, Gallows Bog's boss room: planks over open black
// water, the hag's arena. Old Mother Bog's fight lands with the pack's
// boss rules in Phase 2; `dark` is left to the roll.
room("drowning", "The Drowning Pool", "Keep to the planks, she owns the water", {
length: 200,
ground: [[0, 60, 6], [68, 132, 6], [140, 200, 6]],
shelves: [[112, 124, 12], [132, 146, 18], [160, 172, 12], [150, 162, 18]],
key: null,
door: 194,
candy: [[18, 8.5, 5], [70, 8.5, 5]],
items: [["garlic", 24, 6]],
spawns: [["zombie", 44], ["crawl", 96]],
boss: "motherbog",
}),
]);
const ROOM_IDS = new Set(ROOMS.map((r) => r.id));
@@ -981,15 +1561,16 @@ function stage(id, title, sub, rooms) {
}
export const STAGES = freeze([
stage("manor", "The Manor", "Where the screaming started", ["foyer", "gallery", "library", "ballroom"]),
stage("wing", "The East Wing", "The servants never left", ["kitchen", "conservatory", "attic", "crypt"]),
stage("graveyard", "The Graveyard", "Everyone here was buried in a hurry", ["lychgate", "graves", "mausoleums", "angel"]),
stage("grounds", "The Grounds", "The gardener never stopped working", ["maze", "topiary", "gazebo", "yard"]),
stage("chapel", "The Chapel", "Service is still in session", ["nave", "tower", "loft", "choir"]),
stage("sanatorium", "Blackmoor Sanatorium", "Visiting hours ended in 1912", ["admissions", "baths", "theater", "ward"]),
stage("village", "Hollow End Village", "Every curtain twitches as you pass", ["street", "inn", "square", "green"]),
stage("manor", "The Manor", "Where the screaming started", ["foyer", "gallery", "library", "banister", "ballroom"]),
stage("wing", "The East Wing", "The servants never left", ["kitchen", "conservatory", "attic", "tray", "crypt"]),
stage("graveyard", "The Graveyard", "Everyone here was buried in a hurry", ["lychgate", "graves", "mausoleums", "hearse", "angel"]),
stage("grounds", "The Grounds", "The gardener never stopped working", ["maze", "topiary", "gazebo", "mower", "yard"]),
stage("chapel", "The Chapel", "Service is still in session", ["nave", "tower", "loft", "pew", "choir"]),
stage("sanatorium", "Blackmoor Sanatorium", "Visiting hours ended in 1912", ["admissions", "baths", "theater", "codeblue", "ward"]),
stage("village", "Hollow End Village", "Every curtain twitches as you pass", ["street", "inn", "square", "wagon", "green"]),
stage("mine", "The Deep Seam Mine", "They are still knocking", ["shaft", "tunnels", "collapse", "cart", "seam"]),
stage("carnival", "The Midnight Carnival", "Every game is rigged in its favor", ["midway", "mirrors", "funhouse", "darkride", "bigtop"]),
stage("frozen", "The Frozen Lake", "The ice remembers who fell through", ["huts", "lodge", "blackice", "sled", "widow"]),
stage("bog", "Gallows Bog", "The mud does not like to let go", ["boardwalk", "hollow", "stilts", "bogboat", "drowning"]),
]);
export const stageById = (id) => STAGES.find((s) => s.id === id) || null;
@@ -175,6 +175,64 @@ export function nextRoom(round, random, kit) {
round.events.push({ type: "offer", offer: offer.slice() });
}
// A stage's intro card (ghoul-intros.js, drawn by ghoul-intro-draw.js) holds
// the first room's "Ready?" back until YOU press a key: any move (left, right,
// up, down), fire, or a click moves it on, and not before INTRO_MIN_MS (so a
// key still held never skips it; a key repeat never counts). It never moves on
// by itself: it waits as long as YOU like (a pause holds it). Only entering a
// stage's first room.
export const INTRO_MIN_MS = 1200;
function startIntro(round, kit) {
if (!kit.introFor(round.stage)) return;
// The room's own announcement waits for the end of the card.
const at = round.events.findIndex((e) => e.type === "room");
if (at >= 0) round.events.splice(at, 1);
round.phase = "intro";
round.phaseMs = 0;
round.introMs = 0;
round.input.jump = 0;
round.events.push({ type: "intro", stage: round.stage });
}
// Whether a full-field card (a stage's intro or a boss's) is up.
export const onCard = (round) => round.phase === "intro" || round.phase === "bossintro";
// A boss room's intro card (ghoul-boss-intros.js, drawn by ghoul-bossintro-draw.js):
// the same rules as the stage's card, shown once when the boss room is entered
// (after the last room or the bonus ride, or from the stage select), never on
// a respawn. The boss room is already set up behind it.
function startBossIntro(round, kit) {
const id = round.spec && round.spec.boss;
if (!id || !kit.bossIntroFor(id)) return;
const at = round.events.findIndex((e) => e.type === "room");
if (at >= 0) round.events.splice(at, 1);
round.phase = "bossintro";
round.phaseMs = 0;
round.introMs = 0;
round.input.jump = 0;
round.events.push({ type: "bossIntro", boss: id, stage: round.stage });
}
function endIntro(round, kit) {
round.phase = "ready";
round.phaseMs = round.bonusRound ? (round.spec.ride && round.spec.ride.ready) || kit.BONUS_READY_MS : kit.READY_MS;
round.input.jump = 0;
round.events.push({ type: "room", room: round.room });
}
// One slice of the card: it only counts the time (the lockout and the animation).
export function stepIntro(round, ms) {
round.introMs = (round.introMs || 0) + ms;
}
// A move key, fire or a click: on into the room, once the card has been up a moment.
export function takeIntro(round, kit) {
if (!onCard(round) || (round.introMs || 0) < INTRO_MIN_MS) return false;
endIntro(round, kit);
return true;
}
function enter(round, id, kit) {
round.room++;
setupRoom(round, id, kit);
@@ -183,6 +241,7 @@ function enter(round, id, kit) {
// A bonus room announces itself before its name.
if (round.bonusRound) round.events.push({ type: "bonusStart", hearts: round.bonusRound.hearts, max: round.bonusRound.max, how: round.spec.ride ? round.spec.ride.how : undefined });
round.events.push({ type: "room", room: round.room });
startBossIntro(round, kit);
}
// While choosing: `dir` -1 or 1 moves the pick between what is offered.
@@ -209,6 +268,7 @@ export function pickStage(round, i = round.pick, kit) {
round.stageAt = 0;
round.events.push({ type: "stage", stage: st.id, n: round.cleared.length + 1, of: STAGES.length });
enter(round, st.rooms[0], kit);
startIntro(round, kit);
return true;
}
@@ -248,6 +308,7 @@ export function takeSelect(round, kit) {
round.stageAt = sel.room;
round.events.push({ type: "stage", stage: st.id, n: 1, of: kit.STAGES.length });
enter(round, st.rooms[sel.room], kit);
if (!sel.room) startIntro(round, kit);
return true;
}
@@ -0,0 +1,241 @@
// Plan2Code Web Console - ghoul: The Grand Banister's own sound effects and music track, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulBan<Act>` sound for the ride's
// things) and `music` (a track for the room, named in ROOM_MUSIC in ghoul.js). Built from the house
// tone layers only (no external audio), each tone under 1.2 s; the music is a loop built from
// parts. These are first drafts, to be picked by ear. A name may be defined only once across
// tones.js and every game's file. No imports.
export const BANISTER_SFX = {
tones: {
// The Grand Banister: the bonus ride: you slide down the grand staircase's polished rail, jumping, ducking and shooting.
// Jumps: A push off the wood and a rush of air.
ghoulBanJump: {
layers: [
{ type: "noise", seconds: 0.2, attack: 0.06, gain: 0.34, filter: { type: "bandpass", from: 2600, to: 1400, q: 4 } },
{ type: "triangle", from: 170, to: 130, seconds: 0.08, attack: 0.002, gain: 0.5, filter: { type: "lowpass", from: 700, to: 500, q: 1 } },
],
},
// Lands: A slap of wood and a squeak of polish.
ghoulBanLand: {
layers: [
{ type: "triangle", from: 150, to: 95, seconds: 0.12, attack: 0.002, gain: 0.7, filter: { type: "lowpass", from: 800, to: 500, q: 1 } },
{ type: "brown", seconds: 0.1, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 400, to: 300, q: 1 } },
{ type: "sine", from: 1400, to: 1900, seconds: 0.09, attack: 0.01, gain: 0.12, delay: 0.05, vibrato: { rate: 30, depth: 0.04 } },
],
},
// Launches off the end of the rail: A long whoosh and a whoop.
ghoulBanLaunch: {
layers: [
{ type: "noise", seconds: 0.8, attack: 0.3, gain: 0.5, filter: { type: "bandpass", from: 400, to: 2400, q: 2 } },
{ type: "pink", seconds: 0.8, attack: 0.4, gain: 0.3, filter: { type: "bandpass", from: 240, to: 1700, q: 1 } },
{ type: "sine", from: 320, to: 880, seconds: 0.5, attack: 0.1, gain: 0.36, vibrato: { rate: 6, depth: 0.05 } },
],
},
// Ducks: A quick swish under the lamp.
ghoulBanDuck: {
layers: [
{ type: "noise", seconds: 0.18, attack: 0.07, gain: 0.5, filter: { type: "bandpass", from: 500, to: 2400, q: 1.5 } },
],
},
// Switches rails: A brass ring.
ghoulBanSwitch: {
layers: [
{ type: "sine", from: 1568, to: 1555, seconds: 0.3, attack: 0.003, gain: 0.3 },
{ type: "sine", from: 3136, to: 3110, seconds: 0.2, attack: 0.003, gain: 0.14 },
{ type: "sine", from: 2349, to: 2330, seconds: 0.24, attack: 0.003, gain: 0.18, delay: 0.05 },
],
},
// Crash: Wood cracks and china and crystal shatter.
ghoulBanCrash: {
layers: [
{ type: "sine", from: 90, to: 34, seconds: 0.22, attack: 0, gain: 0.9 },
{ type: "brown", seconds: 0.18, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 260, to: 260, q: 1 } },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 3600, to: 2400, q: 5 }, delay: 0.02 },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 4400, to: 3000, q: 6 }, delay: 0.09 },
{ type: "sine", from: 3900, to: 3700, seconds: 0.3, attack: 0.002, gain: 0.12, delay: 0.1 },
],
},
// Checkpoint: A chime of the hall clock.
ghoulBanCheck: {
layers: [
{ type: "sine", from: 784, to: 780, seconds: 0.5, attack: 0.004, gain: 0.34 },
{ type: "sine", from: 1568, to: 1560, seconds: 0.4, attack: 0.004, gain: 0.14 },
{ type: "sine", from: 988, to: 984, seconds: 0.6, attack: 0.004, gain: 0.34, delay: 0.16 },
{ type: "sine", from: 1976, to: 1968, seconds: 0.45, attack: 0.004, gain: 0.14, delay: 0.16 },
],
},
// Finish: A fanfare of the house organ.
ghoulBanFinish: {
layers: [
{ type: "triangle", seconds: 0.95, attack: 0.01, gain: 0.7, notes: [440, 523, 659, 880] },
{ type: "square", seconds: 0.95, attack: 0.01, gain: 0.12, notes: [220, 262, 330, 440], filter: { type: "lowpass", from: 1600, to: 1200, q: 1 } },
{ type: "sine", seconds: 0.95, attack: 0.01, gain: 0.22, notes: [880, 1047, 1319, 1760] },
],
},
// Butler: A ghostly butler on the stairs: it bows, then lunges with its silver tray. Shoot it twice, or jump it.
// Bows: A polite ring of a service bell.
ghoulBanButlerWarn: {
layers: [
{ type: "sine", from: 2637, to: 2620, seconds: 0.3, attack: 0.002, gain: 0.3 },
{ type: "sine", from: 5274, to: 5240, seconds: 0.16, attack: 0.002, gain: 0.1 },
{ type: "sine", from: 2637, to: 2620, seconds: 0.34, attack: 0.002, gain: 0.3, delay: 0.2 },
{ type: "sine", from: 5274, to: 5240, seconds: 0.18, attack: 0.002, gain: 0.1, delay: 0.2 },
],
},
// Lunges: A hiss of cold air and a hollow moan.
ghoulBanButlerLunge: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0.1, gain: 0.4, filter: { type: "bandpass", from: 1800, to: 900, q: 2 } },
{ type: "sawtooth", from: 200, to: 140, seconds: 0.4, attack: 0.05, gain: 0.4, vibrato: { rate: 9, depth: 0.12 }, filter: { type: "bandpass", from: 800, to: 420, q: 3 } },
{ type: "square", from: 100, to: 80, seconds: 0.4, attack: 0.05, gain: 0.16, filter: { type: "lowpass", from: 420, to: 420, q: 1 } },
],
},
// Takes a bolt: A clang on the tray.
ghoulBanButlerHit: {
layers: [
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 2800, to: 1800, q: 3 } },
{ type: "square", from: 1250, to: 1100, seconds: 0.12, attack: 0.002, gain: 0.26, filter: { type: "bandpass", from: 1800, to: 1400, q: 4 } },
{ type: "sine", from: 2100, to: 2040, seconds: 0.3, attack: 0.002, gain: 0.14 },
],
},
// Breaks: The tray clatters down and the ghost sighs away.
ghoulBanButlerBreak: {
layers: [
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 2800, to: 1800, q: 3 } },
{ type: "square", from: 1100, to: 800, seconds: 0.1, attack: 0.002, gain: 0.26, filter: { type: "bandpass", from: 1600, to: 1200, q: 4 } },
{ type: "noise", seconds: 0.04, delay: 0.1, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 2200, to: 1500, q: 4 } },
{ type: "noise", seconds: 0.04, delay: 0.17, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 3000, to: 2000, q: 4 } },
{ type: "triangle", from: 330, to: 220, seconds: 0.6, attack: 0.25, gain: 0.34, vibrato: { rate: 5, depth: 0.03 }, filter: { type: "lowpass", from: 1400, to: 800, q: 1 }, delay: 0.1 },
{ type: "pink", seconds: 0.6, attack: 0.3, gain: 0.12, filter: { type: "bandpass", from: 500, to: 300, q: 5 }, delay: 0.1 },
],
},
// Cobweb: A web strung across the rail: shoot it for points; riding through only tears it.
// Tears: A soft dry rip.
ghoulBanWebTear: {
layers: [
{ type: "noise", seconds: 0.16, attack: 0.02, gain: 0.3, filter: { type: "highpass", from: 2400, to: 3600, q: 1 } },
{ type: "noise", seconds: 0.1, attack: 0.01, gain: 0.2, delay: 0.05, filter: { type: "bandpass", from: 4200, to: 3200, q: 3 } },
],
},
// Shot: A quick zip and a pop.
ghoulBanWebShot: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 3400, to: 2200, q: 3 } },
{ type: "sine", from: 1800, to: 700, seconds: 0.08, attack: 0.002, gain: 0.2 },
{ type: "noise", seconds: 0.12, attack: 0.01, gain: 0.2, delay: 0.04, filter: { type: "highpass", from: 3000, to: 4200, q: 1 } },
],
},
},
music: {
// The Grand Banister: a harpsichord waltz at a gallop. The hall's harpsichord runs
// broken chords over a slow organ and a walking bass in A minor (Am, F, C, E),
// with a thin violin line over the second round and a ticking clock of hats. At
// high dread a chandelier-bright octave and a riser join.
ghoulBanister: {
bpm: 150,
rush: 12,
voices: {
harp: { wave: "pulse", duty: 0.25, gain: 0.13, decay: 0.16, sustain: 0.15 },
harp2: { wave: "pulse", duty: 0.125, gain: 0.06, decay: 0.12, sustain: 0.1, from: 0.85 },
organ: { wave: "triangle", gain: 0.1, decay: 0.8, sustain: 0.85, from: 0.1 },
violin: { wave: "sawtooth", gain: 0.045, decay: 0.3, sustain: 0.7, from: 0.35, vibrato: { rate: 5.2, depth: 0.035, delay: 0.1 } },
bass: { wave: "triangle", gain: 0.4, decay: 0.1, sustain: 0.5 },
kick: { kit: true, gain: 0.24, from: 0.2 },
hat: { kit: true, gain: 0.08, from: 0.45 },
snap: { kit: true, gain: 0.14, from: 0.6 },
riser: { wave: "sawtooth", gain: 0.03, decay: 0.3, sustain: 1, from: 0.8, vibrato: { rate: 0.6, depth: 0.04, delay: 0 } },
},
patterns: {
A: {
harp:
"A4 . C5 . E5 . A5 . E5 . C5 . E5 . C5 . | F4 . A4 . C5 . F5 . C5 . A4 . C5 . A4 . | " +
"E4 . G4 . C5 . E5 . C5 . G4 . C5 . G4 . | E4 . G#4 . B4 . E5 . D5 . B4 . G#4 . B4 .",
harp2:
"A5 . . . E6 . . . A5 . . . E6 . . . | F5 . . . C6 . . . F5 . . . C6 . . . | " +
"E5 . . . C6 . . . E5 . . . C6 . . . | E5 . . . B5 . . . E5 . . . B5 . . .",
organ:
"A3^037 - - - - - - - - - - - - - - - | F3^047 - - - - - - - - - - - - - - - | " +
"C3^047 - - - - - - - - - - - - - - - | E3^047 - - - - - - - - - - - - - - -",
violin:
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
bass:
"A2 . . . . . A2 . . . . . A2 . . . | F2 . . . . . F2 . . . . . F2 . . . | " +
"C3 . . . . . C3 . . . . . C3 . . . | E2 . . . . . E2 . . . . . E2 . . .",
kick:
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . . | " +
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . .",
hat:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .",
riser:
"A3^037 - - - - - - - - - - - - - - - | F3^047 - - - - - - - - - - - - - - - | " +
"C4^047 - - - - - - - - - - - - - - - | E3^047 - - - - - - - - - - - - - - -",
},
B: {
harp:
"A4 . C5 . E5 . A5 . E5 . C5 . E5 . C5 . | D5 . F5 . A5 . D6 . A5 . F5 . A5 . F5 . | " +
"C5 . E5 . G5 . C6 . G5 . E5 . G5 . E5 . | B4 . D#5 . F#5 . B5 . F#5 . D#5 . G#4 . B4 .",
harp2:
"A5 . . . E6 . . . A5 . . . E6 . . . | D6 . . . A5 . . . D6 . . . A5 . . . | " +
"C6 . . . G5 . . . C6 . . . G5 . . . | B5 . . . F#5 . . . B5 . . . F#5 . . .",
organ:
"A3^037 - - - - - - - - - - - - - - - | D3^037 - - - - - - - - - - - - - - - | " +
"C3^047 - - - - - - - - - - - - - - - | B2^047 - - - - - - - - - - - - - - -",
violin:
"E5 - - - - - D5 - C5 - - - B4 - - - | A4 - - - - - - - D5 - - - F5 - - - | " +
"G5 - - - - - E5 - C5 - - - E5 - - - | D#5 - - - - - F#5 - B4 - - - - - - -",
bass:
"A2 . . . . . A2 . . . . . A2 . . . | D3 . . . . . D3 . . . . . D3 . . . | " +
"C3 . . . . . C3 . . . . . C3 . . . | B2 . . . . . B2 . . . . . B2 . . .",
kick:
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . . | " +
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . .",
hat:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .",
riser:
"A3^037 - - - - - - - - - - - - - - - | D3^037 - - - - - - - - - - - - - - - | " +
"C4^047 - - - - - - - - - - - - - - - | B3^047 - - - - - - - - - - - - - - -",
},
C: {
harp:
"E5 . A4 . C5 . E5 . A5 . E5 . C5 . A4 . | F5 . A4 . C5 . F5 . A5 . F5 . C5 . A4 . | " +
"G5 . C5 . E5 . G5 . C6 . G5 . E5 . C5 . | G#4 . B4 . E5 . G#5 . B5 . G#5 . E5 . B4 .",
harp2:
"A5 A5 . . E6 E6 . . A5 A5 . . E6 E6 . . | F5 F5 . . C6 C6 . . F5 F5 . . C6 C6 . . | " +
"E5 E5 . . C6 C6 . . E5 E5 . . C6 C6 . . | E5 E5 . . B5 B5 . . E5 E5 . . B5 B5 . .",
organ:
"A3^037 - - - - - - - - - - - - - - - | F3^047 - - - - - - - - - - - - - - - | " +
"C3^047 - - - - - - - - - - - - - - - | E3^047 - - - - - - - - - - - - - - -",
violin:
"A5 - - - - - - - E5 - - - A5 - - - | A5 - - - - - - - C6 - - - A5 - - - | " +
"G5 - - - - - - - E5 - - - G5 - - - | G#5 - - - - - B5 - E6 - - - - - - -",
bass:
"A2 . A2 . . . A2 . A2 . A2 . . . A2 . | F2 . F2 . . . F2 . F2 . F2 . . . F2 . | " +
"C3 . C3 . . . C3 . C3 . C3 . . . C3 . | E2 . E2 . . . E2 . E2 . E2 . . . E2 .",
kick:
"k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . . | " +
"k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . .",
hat:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .",
riser:
"A3^037 - - - - - - - - - - - - - - - | F3^047 - - - - - - - - - - - - - - - | " +
"C4^047 - - - - - - - - - - - - - - - | E3^047 - - - - - - - - - - - - - - -",
},
},
order: ["A", "A", "B", "A", "C", "B", "A", "C"],
},
},
};
@@ -0,0 +1,339 @@
// Plan2Code Web Console - ghoul: Gallows Bog's own sound effects and music tracks, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-mine.js: `tones` (the stage's monsters' and boss's
// `ghoul<Kind><Act>` sounds, none over 1.2 s with its delay) and `music` (a track per room,
// named in ROOM_MUSIC in ghoul.js). The tones are first drafts (option 1 of each act on
// prototypes/sounds/ghoul-rush/bog.html) until the user's vote replaces them with
// prototypes/ghoul-rush-tools/wire-bog-sounds.cjs; the rooms play borrowed tracks until
// wire-music-bog.cjs lands the picked ones. A name may be defined only once across
// tones.js and every game's file. No imports.
export const BOG_SFX = {
tones: {
// Bog Lurker: A pair of eyes in the black water: it watches from under the boards, sinks when you turn, then snaps at your feet.
// Surfaces: Bubbles and ripple.
ghoulLurkerAppear: {
layers: [
{ type: "sine", from: 861, to: 1464, seconds: 0.05, delay: 0.02, attack: 0, gain: 0.35 },
{ type: "sine", from: 856, to: 1456, seconds: 0.05, delay: 0.12, attack: 0, gain: 0.35 },
{ type: "sine", from: 691, to: 1174, seconds: 0.05, delay: 0.16, attack: 0, gain: 0.35 },
{ type: "sine", from: 648, to: 1101, seconds: 0.05, delay: 0.12, attack: 0, gain: 0.35 },
{ type: "noise", seconds: 0.2, attack: 0.01, gain: 0.4, filter: { type: "bandpass", from: 700, to: 2600, q: 1.2 } },
{ type: "pink", seconds: 0.26, attack: 0.03, gain: 0.25, delay: 0.04, filter: { type: "highpass", from: 1800, to: 3000, q: 1 } },
{ type: "sine", from: 300, to: 120, seconds: 0.12, attack: 0.003, gain: 0.2 },
],
},
// Snaps: Jaws clap.
ghoulLurkerSnap: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 1080, to: 720, q: 2 } },
{ type: "square", from: 540, to: 180, seconds: 0.05, attack: 0, gain: 0.36 },
{ type: "noise", seconds: 0.04, delay: 0.06, attack: 0, gain: 0.63, filter: { type: "bandpass", from: 1560, to: 1080, q: 3 } },
{ type: "sine", from: 99, to: 36, seconds: 0.25, attack: 0, gain: 0.7, delay: 0.03 },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.56, filter: { type: "lowpass", from: 288, to: 288, q: 1 }, delay: 0.03 },
{ type: "noise", seconds: 0.25, attack: 0.01, gain: 0.4, delay: 0.02, filter: { type: "bandpass", from: 700, to: 2600, q: 1.2 } },
{ type: "pink", seconds: 0.33, attack: 0.03, gain: 0.25, delay: 0.06, filter: { type: "highpass", from: 1800, to: 3000, q: 1 } },
{ type: "sine", from: 300, to: 120, seconds: 0.12, attack: 0.003, gain: 0.2, delay: 0.02 },
],
},
// Sinks: Slow gurgle under.
ghoulLurkerSink: {
layers: [
{ type: "sine", from: 98, to: 74, seconds: 0.7, attack: 0.05, gain: 0.9, vibrato: { rate: 15, depth: 0.4 } },
{ type: "brown", seconds: 0.7, attack: 0.05, gain: 0.7, filter: { type: "lowpass", from: 700, to: 300, q: 1 } },
{ type: "sine", from: 147, to: 118, seconds: 0.49, delay: 0.11, attack: 0.03, gain: 0.4, vibrato: { rate: 9, depth: 0.5 } },
{ type: "sine", from: 240, to: 55, seconds: 0.5, attack: 0.02, gain: 0.4, delay: 0.1 },
{ type: "brown", seconds: 0.5, attack: 0.04, gain: 0.4, delay: 0.1, filter: { type: "lowpass", from: 700, to: 110, q: 1 } },
{ type: "noise", seconds: 0.25, attack: 0.05, gain: 0.15, delay: 0.15, filter: { type: "bandpass", from: 900, to: 300, q: 2 } },
],
},
// Hit: Grunt.
ghoulLurkerHurt: {
layers: [
{ type: "sawtooth", from: 82, to: 57, seconds: 0.16, attack: 0.01, gain: 0.9, vibrato: { rate: 8, depth: 0.1 }, filter: { type: "lowpass", from: 891, to: 891, q: 1 } },
{ type: "brown", seconds: 0.13, attack: 0.01, gain: 0.6, filter: { type: "lowpass", from: 450, to: 450, q: 1 } },
],
},
// Dies: Sinking groan.
ghoulLurkerDie: {
layers: [
{ type: "sawtooth", from: 69, to: 49, seconds: 0.9, attack: 0.12, gain: 0.9, vibrato: { rate: 8, depth: 0.07 }, filter: { type: "lowpass", from: 900, to: 450, q: 5 } },
{ type: "sawtooth", from: 70, to: 49, seconds: 0.9, attack: 0.14, gain: 0.5, filter: { type: "lowpass", from: 720, to: 360, q: 3 } },
{ type: "brown", seconds: 0.9, attack: 0.1, gain: 0.6, filter: { type: "bandpass", from: 252, to: 189, q: 2 } },
{ type: "sine", from: 98, to: 74, seconds: 0.6, attack: 0.05, gain: 0.45, vibrato: { rate: 15, depth: 0.4 }, delay: 0.3 },
{ type: "brown", seconds: 0.6, attack: 0.05, gain: 0.35, filter: { type: "lowpass", from: 700, to: 300, q: 1 }, delay: 0.3 },
{ type: "sine", from: 147, to: 118, seconds: 0.42, delay: 0.39, attack: 0.03, gain: 0.2, vibrato: { rate: 9, depth: 0.5 } },
],
},
// Leech Swarm: A drifting cloud of black leeches over the water: they flow toward you, latch on and drain a life.
// Drifts in: Chittering.
ghoulLeechAppear: {
layers: [
{ type: "square", from: 566, to: 396, seconds: 0.03, gain: 0.5, filter: { type: "bandpass", from: 849, to: 566, q: 4 } },
{ type: "square", from: 668, to: 468, seconds: 0.03, delay: 0.04, gain: 0.5, filter: { type: "bandpass", from: 1002, to: 668, q: 4 } },
{ type: "square", from: 649, to: 454, seconds: 0.03, delay: 0.08, gain: 0.5, filter: { type: "bandpass", from: 974, to: 649, q: 4 } },
{ type: "square", from: 596, to: 417, seconds: 0.03, delay: 0.12, gain: 0.5, filter: { type: "bandpass", from: 893, to: 596, q: 4 } },
{ type: "square", from: 605, to: 423, seconds: 0.03, delay: 0.16, gain: 0.5, filter: { type: "bandpass", from: 907, to: 605, q: 4 } },
{ type: "square", from: 559, to: 392, seconds: 0.03, delay: 0.2, gain: 0.5, filter: { type: "bandpass", from: 839, to: 559, q: 4 } },
{ type: "square", from: 626, to: 439, seconds: 0.03, delay: 0.24, gain: 0.5, filter: { type: "bandpass", from: 940, to: 626, q: 4 } },
{ type: "square", from: 433, to: 303, seconds: 0.03, delay: 0.28, gain: 0.5, filter: { type: "bandpass", from: 649, to: 433, q: 4 } },
],
},
// Latches on: Squelch and chitter.
ghoulLeechLatch: {
layers: [
{ type: "brown", seconds: 0.3, attack: 0.01, gain: 0.8, filter: { type: "lowpass", from: 1560, to: 180, q: 1 } },
{ type: "sine", from: 312, to: 72, seconds: 0.22, attack: 0.01, gain: 0.56 },
{ type: "noise", seconds: 0.12, attack: 0.01, gain: 0.32, filter: { type: "bandpass", from: 1080, to: 360, q: 3 } },
{ type: "square", from: 661, to: 463, seconds: 0.03, delay: 0.1, gain: 0.5, filter: { type: "bandpass", from: 992, to: 661, q: 4 } },
{ type: "square", from: 532, to: 372, seconds: 0.03, delay: 0.13, gain: 0.5, filter: { type: "bandpass", from: 797, to: 532, q: 4 } },
{ type: "square", from: 466, to: 326, seconds: 0.03, delay: 0.16, gain: 0.5, filter: { type: "bandpass", from: 698, to: 466, q: 4 } },
{ type: "square", from: 462, to: 323, seconds: 0.03, delay: 0.19, gain: 0.5, filter: { type: "bandpass", from: 693, to: 462, q: 4 } },
{ type: "square", from: 569, to: 398, seconds: 0.03, delay: 0.22, gain: 0.5, filter: { type: "bandpass", from: 853, to: 569, q: 4 } },
{ type: "square", from: 556, to: 389, seconds: 0.03, delay: 0.25, gain: 0.5, filter: { type: "bandpass", from: 834, to: 556, q: 4 } },
],
},
// Hit: Squeak.
ghoulLeechHurt: {
layers: [
{ type: "sine", from: 462, to: 601, seconds: 0.08, attack: 0.01, gain: 0.8, vibrato: { rate: 40, depth: 0.08 } },
{ type: "sine", from: 554, to: 716, seconds: 0.07, delay: 0.1, attack: 0.01, gain: 0.6, vibrato: { rate: 40, depth: 0.08 } },
],
},
// Dies: Splat.
ghoulLeechDie: {
layers: [
{ type: "noise", seconds: 0.28, attack: 0, gain: 0.9, filter: { type: "lowpass", from: 3900, to: 300, q: 1 } },
{ type: "square", from: 210, to: 60, seconds: 0.16, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 900, to: 900, q: 1 } },
{ type: "sine", from: 1350, to: 1950, seconds: 0.05, delay: 0.2, gain: 0.25 },
{ type: "sine", from: 1140, to: 1650, seconds: 0.05, delay: 0.34, gain: 0.18 },
],
},
// Will-o'-Wisp: A cold green light that drifts over the water: the dead are pulled toward you inside its glow; a shot puts it out, and it relights.
// Glows: Rising chime.
ghoulWispAppear: {
layers: [
{ type: "sine", from: 880, to: 1320, seconds: 0.5, attack: 0.02, gain: 0.5 },
{ type: "sine", from: 1175, to: 1760, seconds: 0.5, attack: 0.02, gain: 0.3, delay: 0.1 },
],
},
// Goes out: Falling ring.
ghoulWispOut: {
layers: [
{ type: "sine", notes: [1000, 840, 670, 500], seconds: 0.7, attack: 0.02, gain: 0.6, vibrato: { rate: 7, depth: 0.02 } },
{ type: "triangle", notes: [1500, 1260, 1000, 750], seconds: 0.7, attack: 0.02, gain: 0.25 },
],
},
// Relights: Spark and chime.
ghoulWispRelight: {
layers: [
{ type: "noise", seconds: 0.06, attack: 0.003, gain: 0.5, filter: { type: "bandpass", from: 3500, to: 5000, q: 3 } },
{ type: "sine", from: 700, to: 1400, seconds: 0.4, attack: 0.02, gain: 0.5, delay: 0.05 },
],
},
// Burns bright: Held wail.
ghoulWispOn: {
layers: [
{ type: "sine", from: 1100, to: 1650, seconds: 0.38, attack: 0.15, gain: 0.48, vibrato: { rate: 6, depth: 0.04 } },
{ type: "sine", from: 1650, to: 770, seconds: 0.56, delay: 0.34, attack: 0.04, gain: 0.48, vibrato: { rate: 6, depth: 0.05 } },
{ type: "triangle", from: 2211, to: 1540, seconds: 0.9, attack: 0.3, gain: 0.12 },
{ type: "pink", seconds: 0.9, attack: 0.3, gain: 0.12, filter: { type: "bandpass", from: 2200, to: 2200, q: 8 } },
],
},
// Hit: Squeak.
ghoulWispHurt: {
layers: [
{ type: "sine", from: 1300, to: 1690, seconds: 0.08, attack: 0.01, gain: 0.8, vibrato: { rate: 40, depth: 0.08 } },
{ type: "sine", from: 1560, to: 2015, seconds: 0.07, delay: 0.1, attack: 0.01, gain: 0.6, vibrato: { rate: 40, depth: 0.08 } },
],
},
// Dies: Long falling ring.
ghoulWispDie: {
layers: [
{ type: "sine", notes: [1200, 1008, 804, 600], seconds: 1, attack: 0.02, gain: 0.6, vibrato: { rate: 7, depth: 0.02 } },
{ type: "triangle", notes: [1800, 1512, 1200, 900], seconds: 1, attack: 0.02, gain: 0.25 },
],
},
// Bog Body: An old drowned thing that climbs out of the muck and walks: it is harmless while it climbs, then it drags at you.
// Shows itself: Low groan.
ghoulBogbodyAppear: {
layers: [
{ type: "sawtooth", from: 83, to: 59, seconds: 0.8, attack: 0.12, gain: 0.9, vibrato: { rate: 20, depth: 0.07 }, filter: { type: "lowpass", from: 800, to: 400, q: 5 } },
{ type: "sawtooth", from: 83, to: 58, seconds: 0.8, attack: 0.14, gain: 0.5, filter: { type: "lowpass", from: 640, to: 320, q: 3 } },
{ type: "brown", seconds: 0.8, attack: 0.1, gain: 0.6, filter: { type: "bandpass", from: 300, to: 225, q: 2 } },
],
},
// Climbs out: Squelch and groan.
ghoulBogbodyRise: {
layers: [
{ type: "brown", seconds: 0.3, attack: 0.01, gain: 0.8, filter: { type: "lowpass", from: 780, to: 90, q: 1 } },
{ type: "sine", from: 156, to: 36, seconds: 0.22, attack: 0.01, gain: 0.56 },
{ type: "noise", seconds: 0.12, attack: 0.01, gain: 0.32, filter: { type: "bandpass", from: 540, to: 180, q: 3 } },
{ type: "sawtooth", from: 60, to: 94, seconds: 0.8, attack: 0.12, gain: 0.54, vibrato: { rate: 20, depth: 0.07 }, filter: { type: "lowpass", from: 800, to: 400, q: 5 }, delay: 0.1 },
{ type: "sawtooth", from: 60, to: 93, seconds: 0.8, attack: 0.14, gain: 0.3, filter: { type: "lowpass", from: 640, to: 320, q: 3 }, delay: 0.1 },
{ type: "brown", seconds: 0.8, attack: 0.1, gain: 0.36, filter: { type: "bandpass", from: 300, to: 225, q: 2 }, delay: 0.1 },
],
},
// Hit: Grunt.
ghoulBogbodyHurt: {
layers: [
{ type: "sawtooth", from: 98, to: 68, seconds: 0.16, attack: 0.01, gain: 0.9, vibrato: { rate: 20, depth: 0.1 }, filter: { type: "lowpass", from: 880, to: 880, q: 1 } },
{ type: "brown", seconds: 0.13, attack: 0.01, gain: 0.6, filter: { type: "lowpass", from: 500, to: 500, q: 1 } },
],
},
// Dies: Long groan, squelch.
ghoulBogbodyDie: {
layers: [
{ type: "sawtooth", from: 83, to: 59, seconds: 1, attack: 0.12, gain: 0.9, vibrato: { rate: 20, depth: 0.07 }, filter: { type: "lowpass", from: 800, to: 400, q: 5 } },
{ type: "sawtooth", from: 83, to: 58, seconds: 1, attack: 0.14, gain: 0.5, filter: { type: "lowpass", from: 640, to: 320, q: 3 } },
{ type: "brown", seconds: 1, attack: 0.1, gain: 0.6, filter: { type: "bandpass", from: 300, to: 225, q: 2 } },
{ type: "brown", seconds: 0.3, attack: 0.01, gain: 0.7, filter: { type: "lowpass", from: 910, to: 105, q: 1 }, delay: 0.5 },
{ type: "sine", from: 182, to: 42, seconds: 0.22, attack: 0.01, gain: 0.49, delay: 0.5 },
{ type: "noise", seconds: 0.12, attack: 0.01, gain: 0.28, filter: { type: "bandpass", from: 630, to: 210, q: 3 }, delay: 0.5 },
],
},
// Old Mother Bog: A hag of mud and reeds stewing in her cauldron in the Drowning Pool: she sends a wave of mud down the boards, spits from the pot, then sinks and comes up somewhere else.
// Wakes: Big roar.
ghoulMotherWake: {
layers: [
{ type: "sawtooth", from: 54, to: 69, seconds: 0.39, attack: 0.05, gain: 0.9, vibrato: { rate: 5, depth: 0.1 }, filter: { type: "lowpass", from: 300, to: 2200, q: 4 } },
{ type: "sawtooth", from: 69, to: 42, seconds: 0.77, delay: 0.33, attack: 0.02, gain: 0.9, vibrato: { rate: 5, depth: 0.12 }, filter: { type: "lowpass", from: 2200, to: 260, q: 4 } },
{ type: "sawtooth", from: 30, to: 22, seconds: 1.1, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 500, to: 500, q: 1 } },
{ type: "brown", seconds: 1.1, attack: 0.06, gain: 0.8, filter: { type: "lowpass", from: 900, to: 180, q: 1 } },
{ type: "sine", from: 30, to: 21, seconds: 1.1, attack: 0.05, gain: 0.7 },
],
},
// Winds up the wave: Rising groan.
ghoulMotherWind: {
layers: [
{ type: "sawtooth", from: 48, to: 75, seconds: 0.9, attack: 0.12, gain: 0.9, vibrato: { rate: 5, depth: 0.07 }, filter: { type: "lowpass", from: 1000, to: 500, q: 5 } },
{ type: "sawtooth", from: 48, to: 75, seconds: 0.9, attack: 0.14, gain: 0.5, filter: { type: "lowpass", from: 800, to: 400, q: 3 } },
{ type: "brown", seconds: 0.9, attack: 0.1, gain: 0.6, filter: { type: "bandpass", from: 240, to: 180, q: 2 } },
{ type: "noise", seconds: 0.6, attack: 0.21, gain: 0.4, filter: { type: "bandpass", from: 180, to: 1080, q: 1.5 }, delay: 0.2 },
],
},
// Mud wave: Rumble and splash.
ghoulMotherWave: {
layers: [
{ type: "brown", seconds: 1, attack: 0.08, gain: 0.8, filter: { type: "lowpass", from: 180, to: 70, q: 1 } },
{ type: "sine", from: 48, to: 30, seconds: 1, attack: 0.05, gain: 0.64 },
{ type: "noise", seconds: 0.4, attack: 0.01, gain: 0.64, delay: 0.1, filter: { type: "bandpass", from: 490, to: 1820, q: 1.2 } },
{ type: "pink", seconds: 0.52, attack: 0.03, gain: 0.4, delay: 0.14, filter: { type: "highpass", from: 1260, to: 2100, q: 1 } },
{ type: "sine", from: 210, to: 84, seconds: 0.12, attack: 0.003, gain: 0.32, delay: 0.1 },
],
},
// Gulps for a spit: Gurgle and gasp.
ghoulMotherSpitWind: {
layers: [
{ type: "sine", from: 96, to: 72, seconds: 0.6, attack: 0.05, gain: 0.9, vibrato: { rate: 15, depth: 0.4 } },
{ type: "brown", seconds: 0.6, attack: 0.05, gain: 0.7, filter: { type: "lowpass", from: 700, to: 300, q: 1 } },
{ type: "sine", from: 144, to: 115, seconds: 0.42, delay: 0.09, attack: 0.03, gain: 0.4, vibrato: { rate: 9, depth: 0.5 } },
{ type: "noise", seconds: 0.22, attack: 0.15, gain: 0.7, filter: { type: "bandpass", from: 770, to: 1680, q: 4 }, delay: 0.3 },
{ type: "sawtooth", from: 84, to: 109, seconds: 0.2, attack: 0.14, gain: 0.25, filter: { type: "lowpass", from: 980, to: 980, q: 1 }, delay: 0.3 },
],
},
// Spits: Spit and splat.
ghoulMotherSpit: {
layers: [
{ type: "noise", seconds: 0.1, attack: 0, gain: 0.8, filter: { type: "highpass", from: 1260, to: 1260, q: 1 } },
{ type: "sine", from: 490, to: 105, seconds: 0.16, delay: 0.02, gain: 0.6 },
{ type: "brown", seconds: 0.12, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 294, to: 294, q: 1 } },
{ type: "noise", seconds: 0.28, attack: 0, gain: 0.54, filter: { type: "lowpass", from: 1820, to: 140, q: 1 }, delay: 0.15 },
{ type: "square", from: 98, to: 28, seconds: 0.16, attack: 0, gain: 0.3, filter: { type: "lowpass", from: 420, to: 420, q: 1 }, delay: 0.15 },
{ type: "sine", from: 630, to: 910, seconds: 0.05, delay: 0.35, gain: 0.15 },
{ type: "sine", from: 532, to: 770, seconds: 0.05, delay: 0.49, gain: 0.11 },
],
},
// Cauldron opens: Lid clank, bubbles.
ghoulMotherOpen: {
layers: [
{ type: "sine", from: 260, to: 250, seconds: 0.35, attack: 0.003, gain: 0.6 },
{ type: "sine", from: 718, to: 702, seconds: 0.2, attack: 0.003, gain: 0.3 },
{ type: "noise", seconds: 0.04, attack: 0.003, gain: 0.5, filter: { type: "bandpass", from: 1300, to: 1300, q: 2 } },
{ type: "sine", from: 330, to: 560, seconds: 0.05, delay: 0.24, attack: 0, gain: 0.35 },
{ type: "sine", from: 462, to: 785, seconds: 0.05, delay: 0.41, attack: 0, gain: 0.35 },
{ type: "sine", from: 384, to: 653, seconds: 0.05, delay: 0.38, attack: 0, gain: 0.35 },
{ type: "sine", from: 702, to: 1193, seconds: 0.05, delay: 0.43, attack: 0, gain: 0.35 },
{ type: "sine", from: 860, to: 1462, seconds: 0.05, delay: 0.23, attack: 0, gain: 0.35 },
],
},
// Sinks: Long gurgle, rumble.
ghoulMotherSink: {
layers: [
{ type: "sine", from: 84, to: 63, seconds: 0.9, attack: 0.05, gain: 0.9, vibrato: { rate: 15, depth: 0.4 } },
{ type: "brown", seconds: 0.9, attack: 0.05, gain: 0.7, filter: { type: "lowpass", from: 700, to: 300, q: 1 } },
{ type: "sine", from: 126, to: 101, seconds: 0.63, delay: 0.14, attack: 0.03, gain: 0.4, vibrato: { rate: 9, depth: 0.5 } },
{ type: "brown", seconds: 1, attack: 0.08, gain: 0.5, filter: { type: "lowpass", from: 180, to: 70, q: 1 } },
{ type: "sine", from: 48, to: 30, seconds: 1, attack: 0.05, gain: 0.4 },
],
},
// Bubbles warn: Few bubbles.
ghoulMotherBubble: {
layers: [
{ type: "sine", from: 435, to: 740, seconds: 0.05, delay: 0.46, attack: 0, gain: 0.35 },
{ type: "sine", from: 538, to: 915, seconds: 0.05, delay: 0.15, attack: 0, gain: 0.35 },
{ type: "sine", from: 783, to: 1331, seconds: 0.05, delay: 0.09, attack: 0, gain: 0.35 },
{ type: "sine", from: 440, to: 748, seconds: 0.05, delay: 0.04, attack: 0, gain: 0.35 },
],
},
// Resurfaces: Rising roar.
ghoulMotherRise: {
layers: [
{ type: "sawtooth", from: 54, to: 69, seconds: 0.35, attack: 0.05, gain: 0.9, vibrato: { rate: 5, depth: 0.1 }, filter: { type: "lowpass", from: 300, to: 2200, q: 4 } },
{ type: "sawtooth", from: 69, to: 42, seconds: 0.7, delay: 0.3, attack: 0.02, gain: 0.9, vibrato: { rate: 5, depth: 0.12 }, filter: { type: "lowpass", from: 2200, to: 260, q: 4 } },
{ type: "sawtooth", from: 30, to: 22, seconds: 1, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 500, to: 500, q: 1 } },
{ type: "brown", seconds: 1, attack: 0.06, gain: 0.8, filter: { type: "lowpass", from: 900, to: 180, q: 1 } },
{ type: "sine", from: 30, to: 21, seconds: 1, attack: 0.05, gain: 0.7 },
{ type: "noise", seconds: 0.4, attack: 0.01, gain: 0.48, filter: { type: "bandpass", from: 490, to: 1820, q: 1.2 } },
{ type: "pink", seconds: 0.52, attack: 0.03, gain: 0.3, delay: 0.04, filter: { type: "highpass", from: 1260, to: 2100, q: 1 } },
{ type: "sine", from: 210, to: 84, seconds: 0.12, attack: 0.003, gain: 0.24 },
],
},
// Muck lands: Splat.
ghoulMotherMuck: {
layers: [
{ type: "noise", seconds: 0.28, attack: 0, gain: 0.9, filter: { type: "lowpass", from: 2080, to: 160, q: 1 } },
{ type: "square", from: 112, to: 32, seconds: 0.16, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 480, to: 480, q: 1 } },
{ type: "sine", from: 720, to: 1040, seconds: 0.05, delay: 0.2, gain: 0.25 },
{ type: "sine", from: 608, to: 880, seconds: 0.05, delay: 0.34, gain: 0.18 },
],
},
// Hit: Short roar.
ghoulMotherHurt: {
layers: [
{ type: "sawtooth", from: 59, to: 76, seconds: 0.16, attack: 0.05, gain: 0.9, vibrato: { rate: 5, depth: 0.1 }, filter: { type: "lowpass", from: 300, to: 2200, q: 4 } },
{ type: "sawtooth", from: 76, to: 46, seconds: 0.32, delay: 0.14, attack: 0.02, gain: 0.9, vibrato: { rate: 5, depth: 0.12 }, filter: { type: "lowpass", from: 2200, to: 260, q: 4 } },
{ type: "sawtooth", from: 33, to: 24, seconds: 0.45, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 500, to: 500, q: 1 } },
{ type: "brown", seconds: 0.45, attack: 0.06, gain: 0.8, filter: { type: "lowpass", from: 900, to: 180, q: 1 } },
{ type: "sine", from: 33, to: 23, seconds: 0.45, attack: 0.05, gain: 0.7 },
],
},
// Weak spot: Crack and roar.
ghoulMotherWeak: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.9, filter: { type: "bandpass", from: 1260, to: 840, q: 2 } },
{ type: "square", from: 630, to: 210, seconds: 0.05, attack: 0, gain: 0.36 },
{ type: "noise", seconds: 0.04, delay: 0.06, attack: 0, gain: 0.63, filter: { type: "bandpass", from: 1820, to: 1260, q: 3 } },
{ type: "sawtooth", from: 54, to: 69, seconds: 0.21, attack: 0.05, gain: 0.63, vibrato: { rate: 5, depth: 0.1 }, filter: { type: "lowpass", from: 300, to: 2200, q: 4 }, delay: 0.05 },
{ type: "sawtooth", from: 69, to: 42, seconds: 0.42, delay: 0.23, attack: 0.02, gain: 0.63, vibrato: { rate: 5, depth: 0.12 }, filter: { type: "lowpass", from: 2200, to: 260, q: 4 } },
{ type: "sawtooth", from: 30, to: 22, seconds: 0.6, attack: 0.08, gain: 0.42, filter: { type: "lowpass", from: 500, to: 500, q: 1 }, delay: 0.05 },
{ type: "brown", seconds: 0.6, attack: 0.06, gain: 0.56, filter: { type: "lowpass", from: 900, to: 180, q: 1 }, delay: 0.05 },
{ type: "sine", from: 30, to: 21, seconds: 0.6, attack: 0.05, gain: 0.49, delay: 0.05 },
],
},
// Dies: Falling roar, rumble.
ghoulMotherDie: {
layers: [
{ type: "sawtooth", from: 49, to: 62, seconds: 0.42, attack: 0.05, gain: 0.9, vibrato: { rate: 5, depth: 0.1 }, filter: { type: "lowpass", from: 300, to: 2200, q: 4 } },
{ type: "sawtooth", from: 62, to: 38, seconds: 0.84, delay: 0.36, attack: 0.02, gain: 0.9, vibrato: { rate: 5, depth: 0.12 }, filter: { type: "lowpass", from: 2200, to: 260, q: 4 } },
{ type: "sawtooth", from: 27, to: 20, seconds: 1.2, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 500, to: 500, q: 1 } },
{ type: "brown", seconds: 1.2, attack: 0.06, gain: 0.8, filter: { type: "lowpass", from: 900, to: 180, q: 1 } },
{ type: "sine", from: 27, to: 20, seconds: 1.2, attack: 0.05, gain: 0.7 },
{ type: "brown", seconds: 1.2, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 180, to: 70, q: 1 } },
{ type: "sine", from: 48, to: 30, seconds: 1.2, attack: 0.05, gain: 0.48 },
],
},
},
music: {
},
};
@@ -0,0 +1,203 @@
// Plan2Code Web Console - ghoul: The Bog Runner's own sound effects and music track, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-hearse.js: `tones` (a `ghoulBogboat<Act>` sound for the
// fan boat's things, built from the house tone layers, none over 1.2 s with its delay) and
// `music` (the room's track, `ghoulBoatRide`, named in ROOM_MUSIC in ghoul.js: a drone and a
// fan's chug under a reedy line, built from four-bar parts the way the hearse's is). Both are
// first drafts, to be picked by ear later (Phase 5's pick pages). A name may be defined only
// once across tones.js and every game's file. No imports (the little helpers below are local).
const bars = (...b) => b.join(" | ");
// The fan's chug under the line: a root on the off steps, the propeller nobody is turning.
const chug = (n) => `${n} . ${n} . ${n} ${n} . ${n} ${n} . ${n} . ${n} ${n} . .`;
const FLOOR = "k . . . k . . . k . . . k . . .";
const OFFBEAT = ". . h . . . h . . . h . . . h .";
const SNAP = ". . . . s . . . . . . . s . . .";
// One slow drone note on the first step of a bar.
const drone = (n) => `${n} - - - - - - - - - - - - - - -`;
export const BOGBOAT_SFX = {
tones: {
// The Bog Runner: the bonus ride down the black channel, jumping, ducking, switching lanes and shooting.
// Jumps: the fan screams up and the hull lifts clear of the water.
ghoulBogboatJump: {
layers: [
{ type: "sawtooth", from: 120, to: 300, seconds: 0.26, attack: 0.04, gain: 0.28, filter: { type: "lowpass", from: 600, to: 2200, q: 2 } },
{ type: "noise", seconds: 0.22, attack: 0.08, gain: 0.3, filter: { type: "bandpass", from: 600, to: 2600, q: 1.5 } },
],
},
// Lands: a flat smack on the water and a spray.
ghoulBogboatLand: {
layers: [
{ type: "sine", from: 130, to: 52, seconds: 0.16, attack: 0, gain: 0.7 },
{ type: "noise", seconds: 0.2, attack: 0.02, gain: 0.4, filter: { type: "bandpass", from: 1400, to: 500, q: 1.5 } },
{ type: "brown", seconds: 0.12, attack: 0, gain: 0.4, filter: { type: "lowpass", from: 300, to: 180, q: 1 } },
],
},
// Ducks: a quick swish under the limb.
ghoulBogboatDuck: {
layers: [
{ type: "noise", seconds: 0.18, attack: 0.06, gain: 0.45, filter: { type: "bandpass", from: 700, to: 2800, q: 1.5 } },
],
},
// Switches lane: a shudder up the mud ramp and a wet slap.
ghoulBogboatSwitch: {
layers: [
{ type: "sine", from: 150, to: 70, seconds: 0.12, attack: 0, gain: 0.6 },
{ type: "brown", seconds: 0.3, attack: 0.04, gain: 0.5, filter: { type: "lowpass", from: 500, to: 160, q: 1 } },
{ type: "noise", seconds: 0.16, attack: 0.03, gain: 0.25, delay: 0.14, filter: { type: "bandpass", from: 500, to: 1500, q: 2 } },
],
},
// Crash: wood, a splash and the prop catching.
ghoulBogboatCrash: {
layers: [
{ type: "sine", from: 98, to: 32, seconds: 0.3, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.25, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 260, to: 200, q: 1 } },
{ type: "noise", seconds: 0.4, attack: 0.1, gain: 0.45, delay: 0.03, filter: { type: "bandpass", from: 800, to: 3000, q: 2 } },
{ type: "square", from: 320, to: 150, seconds: 0.1, gain: 0.2, delay: 0.08 },
],
},
// Checkpoint: a single bell over the water.
ghoulBogboatCheck: {
layers: [
{ type: "sine", from: 587, to: 584, seconds: 0.6, attack: 0.003, gain: 0.34 },
{ type: "sine", from: 1175, to: 1168, seconds: 0.4, attack: 0.003, gain: 0.14 },
{ type: "sine", from: 880, to: 876, seconds: 0.5, attack: 0.003, gain: 0.22, delay: 0.1 },
],
},
// The finish: the fan winding down, then the pier's bell.
ghoulBogboatFinish: {
layers: [
{ type: "sawtooth", from: 420, to: 90, seconds: 0.7, attack: 0.03, gain: 0.2, vibrato: { rate: 14, depth: 0.05 }, filter: { type: "lowpass", from: 1400, to: 300, q: 2 } },
{ type: "noise", seconds: 0.5, attack: 0.1, gain: 0.28, filter: { type: "bandpass", from: 1400, to: 500, q: 2 } },
{ type: "sine", from: 220, to: 216, seconds: 0.6, attack: 0.003, gain: 0.5, delay: 0.5 },
],
},
// The swarm boils close behind: a rising wet churn.
ghoulBogboatPanic: {
layers: [
{ type: "noise", seconds: 0.6, attack: 0.25, gain: 0.4, filter: { type: "bandpass", from: 300, to: 1800, q: 3 } },
{ type: "sine", from: 70, to: 120, seconds: 0.6, attack: 0.2, gain: 0.35, vibrato: { rate: 9, depth: 0.08 } },
],
},
// The swarm has you: a snap of tiny teeth under a squelch.
ghoulBogboatCatch: {
layers: [
{ type: "noise", seconds: 0.35, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 2800, to: 900, q: 3 } },
{ type: "sine", from: 140, to: 50, seconds: 0.3, attack: 0, gain: 0.7 },
{ type: "square", from: 900, to: 400, seconds: 0.04, gain: 0.14, delay: 0.05 },
{ type: "square", from: 800, to: 380, seconds: 0.04, gain: 0.14, delay: 0.11 },
],
},
// The fan is clogging: a labouring grind.
ghoulBogboatClog: {
layers: [
{ type: "sawtooth", from: 150, to: 90, seconds: 0.45, attack: 0.05, gain: 0.26, vibrato: { rate: 24, depth: 0.1 }, filter: { type: "lowpass", from: 700, to: 300, q: 2 } },
{ type: "brown", seconds: 0.4, attack: 0.1, gain: 0.4, filter: { type: "lowpass", from: 400, to: 160, q: 1 } },
],
},
// The fan stalls: a cough, a clunk and silence.
ghoulBogboatStall: {
layers: [
{ type: "sawtooth", from: 240, to: 40, seconds: 0.5, attack: 0.01, gain: 0.3, filter: { type: "lowpass", from: 900, to: 150, q: 2 } },
{ type: "square", from: 90, to: 60, seconds: 0.08, gain: 0.3, delay: 0.5 },
{ type: "brown", seconds: 0.3, attack: 0, gain: 0.5, delay: 0.5, filter: { type: "lowpass", from: 260, to: 120, q: 1 } },
],
},
// A gas pocket shot: a fat bubbling pop and a hiss.
ghoulBogboatGas: {
layers: [
{ type: "sine", from: 180, to: 520, seconds: 0.12, attack: 0, gain: 0.5 },
{ type: "noise", seconds: 0.5, attack: 0.02, gain: 0.4, filter: { type: "bandpass", from: 3200, to: 1200, q: 2 } },
{ type: "sine", from: 240, to: 600, seconds: 0.1, attack: 0, gain: 0.3, delay: 0.14 },
],
},
// A charm shot: a rattle of bone or a clink of glass.
ghoulBogboatProp: {
layers: [
{ type: "noise", seconds: 0.14, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 3600, to: 1800, q: 3 } },
{ type: "sine", from: 1320, to: 880, seconds: 0.2, attack: 0.002, gain: 0.26 },
{ type: "sine", from: 420, to: 160, seconds: 0.14, attack: 0, gain: 0.4 },
],
},
},
music: {
// The Bog Runner: a fan boat at a chug through the dark. E minor: a drone under the
// chug, a reedy pulse line that wanders around the root and flat second, four on the
// floor and a snap on two and four; at high dread a shrill octave joins. The swarm is
// in the water behind it.
ghoulBoatRide: {
bpm: 150,
rush: 8,
voices: {
reed: { wave: "pulse", duty: 0.2, gain: 0.13, decay: 0.2, sustain: 0.65, vibrato: { rate: 5, depth: 0.014, delay: 0.2 } },
drone: { wave: "sine", gain: 0.3, decay: 0.9, sustain: 0.6 },
bass: { wave: "triangle", gain: 0.45, decay: 0.08, sustain: 0.5 },
kick: { kit: true, gain: 0.28, from: 0.2 },
hat: { kit: true, gain: 0.1, from: 0.4 },
snap: { kit: true, gain: 0.16, from: 0.55 },
shrill: { wave: "pulse", duty: 0.125, gain: 0.05, decay: 0.1, sustain: 0.4, from: 0.85 },
},
patterns: {
A: {
reed: bars(
"E5 - - - G5 - - - B5 - - - G5 - E5 -",
"F5 - - - A5 - - - C6 - - - A5 - F5 -",
"E5 - - - G5 - - - B5 - D6 - B5 - G5 -",
"F5 - E5 - D5 - E5 - . . E5 - - - - -",
),
drone: bars(drone("E3"), drone("F3"), drone("E3"), drone("B2")),
bass: bars(chug("E2"), chug("F2"), chug("E2"), chug("B1")),
kick: bars(FLOOR, FLOOR, FLOOR, FLOOR),
hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT),
snap: bars(SNAP, SNAP, SNAP, SNAP),
shrill: bars(
"E6 . E6 . G6 . G6 . B6 . B6 . G6 . E6 .",
"F6 . F6 . A6 . A6 . C7 . C7 . A6 . F6 .",
"E6 . E6 . G6 . G6 . B6 . D7 . B6 . G6 .",
"F6 . E6 . D6 . E6 . . . E6 . . . . .",
),
},
B: {
reed: bars(
"B5 - B5 - A5 - G5 - F5 - E5 - F5 - G5 -",
"C6 - C6 - B5 - A5 - G5 - F5 - G5 - A5 -",
"B5 - B5 - A5 - G5 - F5 - E5 - F5 - G5 -",
"B4 - D5 - F5 - B5 - . . B5 - A5 - F5 -",
),
drone: bars(drone("E3"), drone("F3"), drone("E3"), drone("B2")),
bass: bars(chug("E2"), chug("F2"), chug("E2"), chug("B1")),
kick: bars(FLOOR, FLOOR, FLOOR, FLOOR),
hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT),
snap: bars(SNAP, SNAP, SNAP, SNAP),
shrill: bars(
"B6 . B6 . A6 . G6 . F6 . E6 . F6 . G6 .",
"C7 . C7 . B6 . A6 . G6 . F6 . G6 . A6 .",
"B6 . B6 . A6 . G6 . F6 . E6 . F6 . G6 .",
"B5 . D6 . F6 . B6 . . . B6 . A6 . F6 .",
),
},
C: {
reed: bars(
"G5 - - - - - E5 - G5 - - - B5 - - -",
"A5 - - - - - F5 - A5 - - - C6 - - -",
"G5 - - - - - E5 - G5 - - - B5 - - -",
"F5 - - - D5 - - - B4 - - - E4 - - -",
),
drone: bars(drone("E3"), drone("F3"), drone("E3"), drone("B2")),
bass: bars(chug("E2"), chug("F2"), chug("E2"), chug("B1")),
kick: bars(FLOOR, FLOOR, FLOOR, FLOOR),
hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT),
snap: bars(SNAP, SNAP, SNAP, SNAP),
shrill: bars(
"G6 . . . . . E6 . G6 . . . B6 . . .",
"A6 . . . . . F6 . A6 . . . C7 . . .",
"G6 . . . . . E6 . G6 . . . B6 . . .",
"F6 . . . D6 . . . B5 . . . E5 . . .",
),
},
},
order: ["A", "A", "B", "A", "C", "B", "A", "C", "B", "A"],
},
},
};
@@ -0,0 +1,223 @@
// Plan2Code Web Console - ghoul: Code Blue's own sound effects and music track, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulBlue<Act>` sound for the
// gurney's things) and `music` (a track for the room, named in ROOM_MUSIC in ghoul.js).
// Every tone is built from the house's layers and is at most 1.2 s long. These are first
// picks and still pending a listen: the sounds and the track are to be chosen by ear. A
// name may be defined only once across tones.js and every game's file. No imports.
export const GURNEY_SFX = {
tones: {
// Code Blue: The bonus ride: YOU lie strapped to a runaway hospital gurney, jumping, ducking and shooting as the lights go out in waves.
// Jumps: Wheels squeal as the gurney lifts.
ghoulBlueJump: {
layers: [
{ type: "noise", seconds: 0.2, attack: 0.05, gain: 0.3, filter: { type: "bandpass", from: 1200, to: 2800, q: 6 } },
{ type: "square", from: 300, to: 560, seconds: 0.1, gain: 0.1 },
],
},
// Lands: Clatter of casters and a thud.
ghoulBlueLand: {
layers: [
{ type: "sine", from: 130, to: 55, seconds: 0.14, attack: 0, gain: 0.6 },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1900, to: 1500, q: 6 } },
{ type: "noise", seconds: 0.04, delay: 0.06, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 2300, to: 1700, q: 6 } },
{ type: "noise", seconds: 0.3, attack: 0.09, gain: 0.2, delay: 0.08, filter: { type: "bandpass", from: 3000, to: 1500, q: 5 } },
],
},
// Launches off the loading ramp: Big whoosh and a whoop.
ghoulBlueLaunch: {
layers: [
{ type: "noise", seconds: 0.8, attack: 0.3, gain: 0.5, filter: { type: "bandpass", from: 400, to: 2500, q: 2 } },
{ type: "sine", from: 300, to: 900, seconds: 0.5, attack: 0.1, gain: 0.35, vibrato: { rate: 6, depth: 0.05 } },
],
},
// Ducks: Quick swish.
ghoulBlueDuck: {
layers: [
{ type: "noise", seconds: 0.2, attack: 0.07, gain: 0.5, filter: { type: "bandpass", from: 420, to: 2520, q: 1.5 } },
],
},
// Crash: Metal clang and a groan.
ghoulBlueCrash: {
layers: [
{ type: "sine", from: 140, to: 50, seconds: 0.25, attack: 0, gain: 1 },
{ type: "square", from: 220, to: 90, seconds: 0.2, attack: 0, gain: 0.3 },
{ type: "noise", seconds: 0.35, attack: 0.02, gain: 0.35, delay: 0.02, filter: { type: "bandpass", from: 1500, to: 3500, q: 2 } },
{ type: "brown", seconds: 0.25, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 300, to: 200, q: 1 } },
],
},
// Checkpoint: Two monitor pings.
ghoulBlueCheck: {
layers: [
{ type: "sine", from: 1318, to: 1318, seconds: 0.12, attack: 0.004, gain: 0.35 },
{ type: "sine", from: 1760, to: 1760, seconds: 0.18, attack: 0.004, gain: 0.35, delay: 0.1 },
],
},
// Finish: Fanfare notes.
ghoulBlueFinish: {
layers: [
{ type: "triangle", seconds: 0.9, attack: 0.01, gain: 0.7, notes: [392, 523, 659, 784] },
{ type: "sine", seconds: 0.9, attack: 0.01, gain: 0.25, notes: [784, 1047, 1319, 1568] },
],
},
// Countdown tick (3, 2, 1): An electric buzz and a beep.
ghoulBlueWarn: {
layers: [
{ type: "sawtooth", from: 118, to: 112, seconds: 0.2, attack: 0.01, gain: 0.3, vibrato: { rate: 50, depth: 0.04 } },
{ type: "noise", seconds: 0.14, attack: 0.01, gain: 0.3, filter: { type: "highpass", from: 3000, to: 3000 } },
{ type: "sine", from: 880, to: 880, seconds: 0.1, attack: 0.004, gain: 0.3, delay: 0.1 },
],
},
// Lights out: A power-down groan and a thunk.
ghoulBlueDark: {
layers: [
{ type: "sine", from: 900, to: 60, seconds: 0.9, attack: 0.01, gain: 0.4 },
{ type: "noise", seconds: 0.6, attack: 0.02, gain: 0.4, filter: { type: "lowpass", from: 800, to: 100, q: 1 } },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.8, delay: 0.05, filter: { type: "lowpass", from: 200, to: 120, q: 1 } },
],
},
// Lights back on: A power-up rise and a pop.
ghoulBlueLit: {
layers: [
{ type: "sine", from: 120, to: 700, seconds: 0.5, attack: 0.02, gain: 0.35 },
{ type: "noise", seconds: 0.06, attack: 0, gain: 0.4, delay: 0.45, filter: { type: "highpass", from: 2500, to: 2500 } },
{ type: "triangle", seconds: 0.25, attack: 0.01, gain: 0.3, delay: 0.5, notes: [659, 988] },
],
},
// Heartbeat monitor: A clean beep.
ghoulBlueBeat: {
layers: [
{ type: "sine", from: 1000, to: 1000, seconds: 0.1, attack: 0.003, gain: 0.4 },
],
},
// Flatline: One long tone.
ghoulBlueFlat: {
layers: [
{ type: "sine", from: 1000, to: 1000, seconds: 1.1, attack: 0.003, gain: 0.35 },
{ type: "sine", from: 2000, to: 2000, seconds: 1.1, attack: 0.003, gain: 0.05 },
],
},
// Wheelchair: A squeaky wheel starts to roll.
ghoulBlueChair: {
layers: [
{ type: "noise", seconds: 0.25, attack: 0.04, gain: 0.3, filter: { type: "bandpass", from: 800, to: 1700, q: 8 } },
{ type: "square", from: 600, to: 760, seconds: 0.05, gain: 0.08, delay: 0.05 },
{ type: "square", from: 640, to: 800, seconds: 0.05, gain: 0.08, delay: 0.13 },
],
},
// Orderly: The door shivers in its frame.
ghoulBlueOrderlyWarn: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0.02, gain: 0.35, filter: { type: "bandpass", from: 200, to: 420, q: 3 } },
{ type: "square", from: 90, to: 80, seconds: 0.05, gain: 0.25 },
{ type: "square", from: 90, to: 80, seconds: 0.05, gain: 0.25, delay: 0.1 },
{ type: "square", from: 90, to: 80, seconds: 0.05, gain: 0.25, delay: 0.2 },
],
},
// Orderly: The door flies open and he roars.
ghoulBlueOrderlyUp: {
layers: [
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 400, to: 200, q: 1 } },
{ type: "sawtooth", from: 110, to: 80, seconds: 0.45, attack: 0.03, gain: 0.3, delay: 0.05, vibrato: { rate: 18, depth: 0.05 } },
],
},
// Orderly: A bolt thumps into him.
ghoulBlueOrderlyHit: {
layers: [
{ type: "sine", from: 110, to: 60, seconds: 0.12, attack: 0, gain: 0.7 },
{ type: "noise", seconds: 0.12, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 600, to: 300, q: 2 } },
],
},
// Orderly: Down he goes.
ghoulBlueOrderlyBreak: {
layers: [
{ type: "sawtooth", from: 200, to: 50, seconds: 0.5, attack: 0.01, gain: 0.35 },
{ type: "noise", seconds: 0.35, attack: 0.01, gain: 0.4, filter: { type: "lowpass", from: 1500, to: 200, q: 1 } },
{ type: "sine", from: 90, to: 40, seconds: 0.3, attack: 0, gain: 0.7, delay: 0.1 },
],
},
// Surge lamp: Glass shatters and a zap.
ghoulBlueLampBreak: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0, gain: 0.5, filter: { type: "highpass", from: 2200, to: 2200 } },
{ type: "sine", from: 3000, to: 200, seconds: 0.22, attack: 0, gain: 0.25 },
{ type: "square", from: 140, to: 60, seconds: 0.18, attack: 0, gain: 0.2, delay: 0.04 },
],
},
},
music: {
// Code Blue: monitor rush. A pulsing minor-key chase: an urgent staccato lead over a driving
// bass, a kick on every beat, hats and a snap, and a monitor beep once a bar that keeps
// the heartbeat; at high dread a stab and an octave-up lead join.
ghoulBlueRide: {
bpm: 144,
rush: 10,
voices: {
lead: { wave: "pulse", duty: 0.25, gain: 0.1, decay: 0.07, sustain: 0.3 },
bass: { wave: "triangle", gain: 0.4, decay: 0.08, sustain: 0.6 },
kick: { kit: true, gain: 0.26, from: 0.15 },
hat: { kit: true, gain: 0.1, from: 0.35 },
snap: { kit: true, gain: 0.16, from: 0.5 },
beep: { wave: "sine", gain: 0.1, decay: 0.12, sustain: 0.2 },
stab: { wave: "sawtooth", gain: 0.05, decay: 0.1, sustain: 0.3, from: 0.75 },
lead2: { wave: "pulse", duty: 0.125, gain: 0.06, decay: 0.08, sustain: 0.3, from: 0.9 },
},
patterns: {
A: {
lead:
"D5 . . F5 . . A5 . . F5 . . E5 . D5 . | Bb4 . . D5 . . F5 . . D5 . . C5 . Bb4 . | " +
"G4 . . Bb4 . . D5 . . Bb4 . . A4 . G4 . | A4 . . C#5 . . E5 . . A5 . G5 . F5 . E5",
bass:
"D2 . D2 . D2 . D2 . D2 . D2 . D2 . D2 . | Bb1 . Bb1 . Bb1 . Bb1 . Bb1 . Bb1 . Bb1 . Bb1 . | " +
"G1 . G1 . G1 . G1 . G1 . G1 . G1 . G1 . | A1 . A1 . A1 . A1 . A1 . A1 . A1 . A1 .",
kick:
"k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . . | " +
"k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . .",
hat:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .",
beep:
"E6 . . . . . . . . . . . . . . . | E6 . . . . . . . . . . . . . . . | " +
"E6 . . . . . . . . . . . . . . . | E6 . . . . . . . . . . . . . . .",
stab:
"D4^037 . . . . . . . . . . . . . . . | Bb3^047 . . . . . . . . . . . . . . . | " +
"G3^037 . . . . . . . . . . . . . . . | A3^047 . . . . . . . . . . . . . . .",
lead2:
"D6 . . F6 . . A6 . . F6 . . E6 . D6 . | Bb5 . . D6 . . F6 . . D6 . . C6 . Bb5 . | " +
"G5 . . Bb5 . . D6 . . Bb5 . . A5 . G5 . | A5 . . C#6 . . E6 . . A6 . G6 . F6 . E6",
},
B: {
lead:
"A5 . F5 . D5 . F5 . A5 . . D6 . C6 . A5 | F5 . D5 . Bb4 . D5 . F5 . . Bb5 . A5 . F5 | " +
"D5 . Bb4 . G4 . Bb4 . D5 . . G5 . F5 . D5 | E5 . C#5 . A4 . C#5 . E5 . . A5 . G5 . E5",
bass:
"D2 . . D2 . . D2 . D2 . . D2 . . D2 . | Bb1 . . Bb1 . . Bb1 . Bb1 . . Bb1 . . Bb1 . | " +
"G1 . . G1 . . G1 . G1 . . G1 . . G1 . | A1 . . A1 . . A1 . A1 . . A1 . . A1 .",
kick:
"k . . . k . . . k . . . k . . k | k . . . k . . . k . . . k . . k | " +
"k . . . k . . . k . . . k . . k | k . . . k . . . k . . . k . k k",
hat:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . s",
beep:
"E6 . . . . . . . E6 . . . . . . . | E6 . . . . . . . E6 . . . . . . . | " +
"E6 . . . . . . . E6 . . . . . . . | E6 . . . . . . . E6 . . . . . . .",
stab:
"D4^037 . . . . . . . D4^037 . . . . . . . | Bb3^047 . . . . . . . Bb3^047 . . . . . . . | " +
"G3^037 . . . . . . . G3^037 . . . . . . . | A3^047 . . . . . . . A3^047 . . . . . . .",
lead2:
"A6 . F6 . D6 . F6 . A6 . . D7 . C7 . A6 | F6 . D6 . Bb5 . D6 . F6 . . Bb6 . A6 . F6 | " +
"D6 . Bb5 . G5 . Bb5 . D6 . . G6 . F6 . D6 | E6 . C#6 . A5 . C#6 . E6 . . A6 . G6 . E6",
},
},
order: ["A", "A", "B", "A", "B", "B", "A", "B", "A", "A", "B", "B", "A"],
},
},
};
@@ -0,0 +1,247 @@
// Plan2Code Web Console - ghoul: The Midnight Hearse's own sound effects and music track, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulHearse<Act>` sound for the
// hearse's things, built from the house tone layers, none over 1.2 s with its delay) and
// `music` (the room's track, `ghoulHearseRide`, named in ROOM_MUSIC in ghoul.js: a
// funeral march at a gallop, built from four-bar parts the way the sled's is). Both are
// first drafts, to be picked by ear later. A name may be defined only once across
// tones.js and every game's file. No imports (the little helpers below are local).
const bars = (...b) => b.join(" | ");
// The gallop under the march: a root on the beat's off steps, the horses' hoofbeat that no horse is making.
const gallop = (n) => `${n} . ${n} ${n} . ${n} ${n} . ${n} . ${n} ${n} . ${n} ${n} .`;
const FLOOR = "k . . . k . . . k . . . k . . .";
const OFFBEAT = ". . h . . . h . . . h . . . h .";
const SNAP = ". . . . s . . . . . . . s . . .";
// One toll of a bell on the first step of a bar.
const toll = (n) => `${n} . . . . . . . . . . . . . . .`;
export const HEARSE_SFX = {
tones: {
// The midnight hearse: the bonus ride along the cemetery road, jumping, ducking, switching lanes and shooting.
// Jumps: the engine roars and the coffins lift.
ghoulHearseJump: {
layers: [
{ type: "sawtooth", from: 90, to: 240, seconds: 0.26, attack: 0.04, gain: 0.3, filter: { type: "lowpass", from: 500, to: 1800, q: 2 } },
{ type: "noise", seconds: 0.2, attack: 0.07, gain: 0.3, filter: { type: "bandpass", from: 400, to: 1800, q: 1.5 } },
],
},
// Lands: a thud and the coffins rattling.
ghoulHearseLand: {
layers: [
{ type: "sine", from: 110, to: 46, seconds: 0.16, attack: 0, gain: 0.8 },
{ type: "brown", seconds: 0.12, attack: 0, gain: 0.5, filter: { type: "lowpass", from: 300, to: 200, q: 1 } },
{ type: "square", from: 420, to: 380, seconds: 0.02, gain: 0.14, delay: 0.06 },
{ type: "square", from: 520, to: 470, seconds: 0.02, gain: 0.14, delay: 0.1 },
{ type: "square", from: 360, to: 330, seconds: 0.02, gain: 0.14, delay: 0.15 },
],
},
// Ducks: a quick swish under the branch.
ghoulHearseDuck: {
layers: [
{ type: "noise", seconds: 0.18, attack: 0.06, gain: 0.5, filter: { type: "bandpass", from: 500, to: 2400, q: 1.5 } },
],
},
// Switches lane: two bumps over the curb.
ghoulHearseSwitch: {
layers: [
{ type: "sine", from: 170, to: 80, seconds: 0.1, attack: 0, gain: 0.7 },
{ type: "noise", seconds: 0.14, attack: 0.03, gain: 0.3, filter: { type: "bandpass", from: 800, to: 2000, q: 2 } },
{ type: "sine", from: 150, to: 70, seconds: 0.12, attack: 0, gain: 0.6, delay: 0.17 },
],
},
// Crash: wood, iron and a coffin lid.
ghoulHearseCrash: {
layers: [
{ type: "sine", from: 92, to: 30, seconds: 0.3, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.25, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 260, to: 220, q: 1 } },
{ type: "noise", seconds: 0.4, attack: 0.12, gain: 0.4, delay: 0.03, filter: { type: "bandpass", from: 900, to: 3200, q: 2 } },
{ type: "square", from: 300, to: 160, seconds: 0.1, gain: 0.2, delay: 0.08 },
{ type: "square", from: 240, to: 120, seconds: 0.1, gain: 0.2, delay: 0.18 },
],
},
// Checkpoint: a single bell.
ghoulHearseCheck: {
layers: [
{ type: "sine", from: 523, to: 520, seconds: 0.6, attack: 0.003, gain: 0.34 },
{ type: "sine", from: 1047, to: 1040, seconds: 0.4, attack: 0.003, gain: 0.14 },
{ type: "sine", from: 784, to: 780, seconds: 0.5, attack: 0.003, gain: 0.22, delay: 0.1 },
],
},
// The finish: brakes squealing, then a toll.
ghoulHearseFinish: {
layers: [
{ type: "sawtooth", from: 1100, to: 380, seconds: 0.6, attack: 0.03, gain: 0.16, vibrato: { rate: 18, depth: 0.04 }, filter: { type: "bandpass", from: 1800, to: 900, q: 3 } },
{ type: "noise", seconds: 0.55, attack: 0.1, gain: 0.3, filter: { type: "bandpass", from: 1500, to: 600, q: 2 } },
{ type: "sine", from: 196, to: 192, seconds: 0.6, attack: 0.003, gain: 0.5, delay: 0.5 },
],
},
// A hand stirs in the grave mound: earth shifting.
ghoulHearseHandWarn: {
layers: [
{ type: "brown", seconds: 0.4, attack: 0.15, gain: 0.5, filter: { type: "lowpass", from: 200, to: 420, q: 1 } },
{ type: "sine", from: 70, to: 90, seconds: 0.4, attack: 0.1, gain: 0.3 },
],
},
// The hand reaches up: clawing dirt.
ghoulHearseHandUp: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0.1, gain: 0.45, filter: { type: "bandpass", from: 500, to: 2600, q: 2 } },
{ type: "square", from: 110, to: 200, seconds: 0.2, gain: 0.16 },
],
},
// A hit on the hand: a dull smack.
ghoulHearseHandHit: {
layers: [
{ type: "sine", from: 300, to: 190, seconds: 0.09, attack: 0, gain: 0.5 },
{ type: "noise", seconds: 0.08, attack: 0, gain: 0.35, filter: { type: "bandpass", from: 1200, to: 900, q: 3 } },
],
},
// The hand breaks: bone and dirt.
ghoulHearseHandBreak: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0, gain: 0.55, filter: { type: "bandpass", from: 2400, to: 700, q: 2 } },
{ type: "sine", from: 210, to: 70, seconds: 0.25, attack: 0, gain: 0.6 },
{ type: "square", from: 700, to: 300, seconds: 0.05, gain: 0.14, delay: 0.04 },
],
},
// A crow takes wing: two caws and the flap.
ghoulHearseCrowWake: {
layers: [
{ type: "sawtooth", from: 900, to: 520, seconds: 0.16, attack: 0.01, gain: 0.26, filter: { type: "bandpass", from: 1100, to: 800, q: 3 } },
{ type: "sawtooth", from: 800, to: 460, seconds: 0.18, attack: 0.01, gain: 0.26, delay: 0.2, filter: { type: "bandpass", from: 1000, to: 700, q: 3 } },
{ type: "noise", seconds: 0.35, attack: 0.1, gain: 0.2, delay: 0.1, filter: { type: "bandpass", from: 3000, to: 1500, q: 4 } },
],
},
// A crow shot: a puff of feathers.
ghoulHearseCrowHit: {
layers: [
{ type: "noise", seconds: 0.2, attack: 0.02, gain: 0.4, filter: { type: "bandpass", from: 3400, to: 1800, q: 2 } },
{ type: "sine", from: 520, to: 240, seconds: 0.12, attack: 0, gain: 0.4 },
],
},
// A lantern taken: glass chimes.
ghoulHearseLantern: {
layers: [
{ type: "sine", from: 1568, to: 1560, seconds: 0.3, attack: 0.002, gain: 0.3 },
{ type: "sine", from: 2093, to: 2085, seconds: 0.3, attack: 0.002, gain: 0.22, delay: 0.06 },
{ type: "sine", from: 2637, to: 2625, seconds: 0.24, attack: 0.002, gain: 0.14, delay: 0.12 },
],
},
// The lamp goes out: a sigh down into the dark.
ghoulHearseLampOut: {
layers: [
{ type: "sine", from: 440, to: 96, seconds: 0.7, attack: 0.01, gain: 0.45 },
{ type: "brown", seconds: 0.5, attack: 0.1, gain: 0.5, filter: { type: "lowpass", from: 500, to: 120, q: 1 } },
],
},
// The lamp lit again: a whump of flame.
ghoulHearseLampLit: {
layers: [
{ type: "sine", from: 220, to: 660, seconds: 0.3, attack: 0.02, gain: 0.4 },
{ type: "noise", seconds: 0.25, attack: 0.08, gain: 0.3, filter: { type: "bandpass", from: 1800, to: 4200, q: 2 } },
],
},
// A coffin flies out of the back: a whoosh, then the knocks.
ghoulHearseCoffin: {
layers: [
{ type: "noise", seconds: 0.5, attack: 0.2, gain: 0.35, filter: { type: "bandpass", from: 300, to: 1500, q: 1.5 } },
{ type: "square", from: 180, to: 110, seconds: 0.08, gain: 0.2, delay: 0.4 },
{ type: "square", from: 150, to: 95, seconds: 0.08, gain: 0.2, delay: 0.52 },
],
},
// The lid pops and a ghoul sits up: a crack and a moan.
ghoulHearseSitUp: {
layers: [
{ type: "square", from: 160, to: 320, seconds: 0.08, gain: 0.26 },
{ type: "sine", from: 130, to: 210, seconds: 0.55, attack: 0.12, gain: 0.3, vibrato: { rate: 5, depth: 0.05 }, delay: 0.06 },
],
},
// The sat-up ghoul shot: a bony pop.
ghoulHearseSitHit: {
layers: [
{ type: "noise", seconds: 0.12, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 2200, to: 900, q: 3 } },
{ type: "sine", from: 420, to: 150, seconds: 0.16, attack: 0, gain: 0.5 },
],
},
},
music: {
// The Midnight Hearse: a funeral march at a gallop. D minor: the organ says the dirge
// (D, Bb, C, then an A major that never resolves) over a hoofbeat bass nobody is
// making, a bell tolling each bar, four on the floor and a snap on two and four; at
// high dread a riser and a shrill octave join. The march that cannot slow down.
ghoulHearseRide: {
bpm: 142,
rush: 8,
voices: {
organ: { wave: "pulse", duty: 0.25, gain: 0.13, decay: 0.2, sustain: 0.7, vibrato: { rate: 5, depth: 0.012, delay: 0.2 } },
toll: { wave: "sine", gain: 0.32, decay: 0.9, sustain: 0.15 },
bass: { wave: "triangle", gain: 0.45, decay: 0.08, sustain: 0.5 },
kick: { kit: true, gain: 0.28, from: 0.2 },
hat: { kit: true, gain: 0.1, from: 0.4 },
snap: { kit: true, gain: 0.16, from: 0.55 },
shrill: { wave: "pulse", duty: 0.125, gain: 0.05, decay: 0.1, sustain: 0.4, from: 0.85 },
},
patterns: {
A: {
organ: bars(
"D5 - - - F5 - - - A5 - - - F5 - D5 -",
"Bb4 - - - D5 - - - F5 - - - D5 - Bb4 -",
"C5 - - - E5 - - - G5 - - - E5 - C5 -",
"A4 - - - C#5 - - - E5 - A5 - G5 - E5 -",
),
toll: bars(toll("D4"), toll("Bb3"), toll("C4"), toll("A3")),
bass: bars(gallop("D3"), gallop("Bb2"), gallop("C3"), gallop("A2")),
kick: bars(FLOOR, FLOOR, FLOOR, FLOOR),
hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT),
snap: bars(SNAP, SNAP, SNAP, SNAP),
shrill: bars(
"D6 . D6 . F6 . F6 . A6 . A6 . F6 . D6 .",
"Bb5 . Bb5 . D6 . D6 . F6 . F6 . D6 . Bb5 .",
"C6 . C6 . E6 . E6 . G6 . G6 . E6 . C6 .",
"A5 . A5 . C#6 . C#6 . E6 . A6 . G6 . E6 .",
),
},
B: {
organ: bars(
"A5 - A5 - G5 - F5 - E5 - D5 - E5 - F5 -",
"F5 - F5 - E5 - D5 - C5 - Bb4 - C5 - D5 -",
"E5 - E5 - D5 - C5 - Bb4 - A4 - Bb4 - C5 -",
"A4 - C#5 - E5 - A5 - . . A5 - G5 - E5 -",
),
toll: bars(toll("D4"), toll("Bb3"), toll("C4"), toll("A3")),
bass: bars(gallop("D3"), gallop("Bb2"), gallop("C3"), gallop("A2")),
kick: bars(FLOOR, FLOOR, FLOOR, FLOOR),
hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT),
snap: bars(SNAP, SNAP, SNAP, SNAP),
shrill: bars(
"A6 . A6 . G6 . F6 . E6 . D6 . E6 . F6 .",
"F6 . F6 . E6 . D6 . C6 . Bb5 . C6 . D6 .",
"E6 . E6 . D6 . C6 . Bb5 . A5 . Bb5 . C6 .",
"A5 . C#6 . E6 . A6 . . . A6 . G6 . E6 .",
),
},
C: {
organ: bars(
"F5 - - - - - D5 - F5 - - - A5 - - -",
"D5 - - - - - Bb4 - D5 - - - F5 - - -",
"E5 - - - - - C5 - E5 - - - G5 - - -",
"E5 - - - C#5 - - - A4 - - - E4 - - -",
),
toll: bars(toll("D4"), toll("Bb3"), toll("C4"), toll("A3")),
bass: bars(gallop("D3"), gallop("Bb2"), gallop("C3"), gallop("A2")),
kick: bars(FLOOR, FLOOR, FLOOR, FLOOR),
hat: bars(OFFBEAT, OFFBEAT, OFFBEAT, OFFBEAT),
snap: bars(SNAP, SNAP, SNAP, SNAP),
shrill: bars(
"F6 . . . . . D6 . F6 . . . A6 . . .",
"D6 . . . . . Bb5 . D6 . . . F6 . . .",
"E6 . . . . . C6 . E6 . . . G6 . . .",
"E6 . . . C#6 . . . A5 . . . E5 . . .",
),
},
},
order: ["A", "A", "B", "A", "C", "B", "A", "C", "B", "A"],
},
},
};
@@ -0,0 +1,221 @@
// Plan2Code Web Console - ghoul: The Gardener's Revenge's own sound effects and music track, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulMower<Act>` sound for the
// mower's things, each under 1.2 s, built only from the house's tone layers) and `music` (a
// track for the room, `ghoulMowerRide`, named in ROOM_MUSIC in ghoul.js). The sounds and the
// track are first drafts, to be picked by ear. A name may be defined only once across tones.js
// and every game's file. No imports.
export const MOWER_SFX = {
tones: {
// The Gardener's Revenge: the bonus ride: you mow a long lawn on a haunted ride-on mower, jumping, ducking, shooting and cutting.
// Jump: the engine revs as the deck bounces up.
ghoulMowerJump: {
layers: [
{ type: "sawtooth", from: 70, to: 150, seconds: 0.3, attack: 0.02, gain: 0.5, vibrato: { rate: 22, depth: 0.1 }, filter: { type: "lowpass", from: 900, to: 1500, q: 2 } },
{ type: "noise", seconds: 0.2, attack: 0.06, gain: 0.3, filter: { type: "bandpass", from: 500, to: 1800, q: 1.5 } },
{ type: "triangle", from: 180, to: 320, seconds: 0.18, attack: 0.01, gain: 0.3 },
],
},
// Land: a clunk of the deck and a rattle of the chassis.
ghoulMowerLand: {
layers: [
{ type: "sine", from: 110, to: 50, seconds: 0.14, attack: 0, gain: 0.8 },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1600, to: 900, q: 5 } },
{ type: "square", from: 330, to: 270, seconds: 0.03, delay: 0.04, gain: 0.14 },
{ type: "noise", seconds: 0.05, delay: 0.08, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 1300, to: 800, q: 6 } },
],
},
// Duck: a quick swish under a branch.
ghoulMowerDuck: {
layers: [
{ type: "noise", seconds: 0.18, attack: 0.06, gain: 0.5, filter: { type: "bandpass", from: 350, to: 1900, q: 1.5 } },
],
},
// Crash: a clang of metal, a thud and a rattle of loose parts.
ghoulMowerCrash: {
layers: [
{ type: "sine", from: 90, to: 34, seconds: 0.25, attack: 0, gain: 1 },
{ type: "square", from: 520, to: 300, seconds: 0.12, attack: 0, gain: 0.22, filter: { type: "bandpass", from: 800, to: 500, q: 3 } },
{ type: "noise", seconds: 0.3, attack: 0.01, gain: 0.45, delay: 0.02, filter: { type: "bandpass", from: 2200, to: 700, q: 2 } },
{ type: "noise", seconds: 0.04, delay: 0.16, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1500, to: 1000, q: 6 } },
{ type: "noise", seconds: 0.04, delay: 0.23, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 1900, to: 1200, q: 6 } },
],
},
// Checkpoint: a rusty bicycle bell, twice.
ghoulMowerCheck: {
layers: [
{ type: "sine", from: 1976, to: 1960, seconds: 0.25, attack: 0.003, gain: 0.3 },
{ type: "sine", from: 4150, to: 4100, seconds: 0.12, attack: 0.003, gain: 0.12 },
{ type: "sine", from: 1976, to: 1960, seconds: 0.3, attack: 0.003, gain: 0.3, delay: 0.14 },
{ type: "sine", from: 4150, to: 4100, seconds: 0.14, attack: 0.003, gain: 0.12, delay: 0.14 },
],
},
// Finish: the engine coughs, rattles and dies, then a triumphant ding.
ghoulMowerFinish: {
layers: [
{ type: "sawtooth", from: 120, to: 40, seconds: 0.7, attack: 0.01, gain: 0.5, vibrato: { rate: 14, depth: 0.2 }, filter: { type: "lowpass", from: 700, to: 200, q: 2 } },
{ type: "noise", seconds: 0.5, attack: 0.05, gain: 0.25, filter: { type: "bandpass", from: 900, to: 300, q: 1.5 } },
{ type: "triangle", seconds: 0.5, attack: 0.01, delay: 0.6, gain: 0.5, notes: [659, 880, 1175] },
],
},
// Grass: the blades biting a swathe, a quick chatter.
ghoulMowerGrass: {
layers: [
{ type: "noise", seconds: 0.1, attack: 0.02, gain: 0.4, filter: { type: "bandpass", from: 3200, to: 1800, q: 2.5 } },
{ type: "sawtooth", from: 200, to: 170, seconds: 0.08, attack: 0.005, gain: 0.2, vibrato: { rate: 40, depth: 0.15 }, filter: { type: "lowpass", from: 1200, to: 900, q: 1 } },
],
},
// Hedge: the blades chop a thorn hedge, a crunch with a thunk.
ghoulMowerHedge: {
layers: [
{ type: "noise", seconds: 0.18, attack: 0.005, gain: 0.7, filter: { type: "bandpass", from: 2400, to: 800, q: 1.5 } },
{ type: "square", from: 260, to: 110, seconds: 0.1, attack: 0, gain: 0.3, filter: { type: "lowpass", from: 1200, to: 500, q: 1 } },
{ type: "brown", seconds: 0.2, attack: 0.01, gain: 0.6, filter: { type: "lowpass", from: 500, to: 300, q: 1 } },
{ type: "triangle", seconds: 0.2, delay: 0.1, attack: 0.005, gain: 0.35, notes: [784, 1047] },
],
},
// Weed: a small pop of a weed patch.
ghoulMowerWeed: {
layers: [
{ type: "sine", from: 500, to: 950, seconds: 0.08, attack: 0.002, gain: 0.5 },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.3, filter: { type: "bandpass", from: 2600, to: 2000, q: 3 } },
],
},
// Jam: the blades overheat: a clank, a grind winding down and a long hiss of steam.
ghoulMowerJam: {
layers: [
{ type: "square", from: 140, to: 60, seconds: 0.2, attack: 0, gain: 0.4, filter: { type: "lowpass", from: 900, to: 400, q: 3 } },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 1400, to: 900, q: 5 } },
{ type: "sawtooth", from: 190, to: 50, seconds: 0.6, attack: 0.02, delay: 0.05, gain: 0.35, vibrato: { rate: 18, depth: 0.3 }, filter: { type: "lowpass", from: 800, to: 150, q: 2 } },
{ type: "noise", seconds: 0.8, attack: 0.1, delay: 0.1, gain: 0.3, filter: { type: "highpass", from: 3500, to: 5000 } },
],
},
// Topiary Beast: a bush that comes alive and lunges across the lane, snapping its hedge-trimmed jaws.
// Warn: leaves rustle and shake.
ghoulMowerBeastWarn: {
layers: [
{ type: "noise", seconds: 0.4, attack: 0.15, gain: 0.4, filter: { type: "bandpass", from: 1800, to: 3200, q: 1.5 }, vibrato: { rate: 24, depth: 0.2 } },
{ type: "pink", seconds: 0.4, attack: 0.2, gain: 0.25, filter: { type: "bandpass", from: 900, to: 1500, q: 1 } },
],
},
// Snap: the lunge and two clacks of the shears.
ghoulMowerBeastSnap: {
layers: [
{ type: "noise", seconds: 0.2, attack: 0.06, gain: 0.45, filter: { type: "bandpass", from: 600, to: 2400, q: 1.5 } },
{ type: "square", from: 880, to: 300, seconds: 0.04, delay: 0.1, attack: 0, gain: 0.35 },
{ type: "noise", seconds: 0.04, delay: 0.1, attack: 0, gain: 0.55, filter: { type: "bandpass", from: 3000, to: 2000, q: 4 } },
{ type: "square", from: 780, to: 260, seconds: 0.04, delay: 0.22, attack: 0, gain: 0.35 },
{ type: "noise", seconds: 0.04, delay: 0.22, attack: 0, gain: 0.55, filter: { type: "bandpass", from: 2800, to: 1900, q: 4 } },
],
},
// Hit: a bolt strikes it: a leafy thwack.
ghoulMowerBeastHit: {
layers: [
{ type: "noise", seconds: 0.06, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 1800, to: 1000, q: 2 } },
{ type: "square", from: 640, to: 220, seconds: 0.05, attack: 0, gain: 0.3 },
{ type: "pink", seconds: 0.15, delay: 0.03, attack: 0.02, gain: 0.3, filter: { type: "bandpass", from: 1400, to: 800, q: 1 } },
],
},
// Break: it is trimmed to a stump: a crunch of cut branches.
ghoulMowerBeastBreak: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0.01, gain: 0.7, filter: { type: "bandpass", from: 2600, to: 700, q: 1.5 } },
{ type: "brown", seconds: 0.25, attack: 0.01, gain: 0.6, filter: { type: "lowpass", from: 500, to: 250, q: 1 } },
{ type: "square", from: 500, to: 160, seconds: 0.08, attack: 0, gain: 0.3 },
{ type: "triangle", seconds: 0.3, delay: 0.1, attack: 0.005, gain: 0.35, notes: [988, 1319, 1760] },
],
},
},
music: {
// The Gardener's Revenge: a sputtering waltz-march. A reedy pulse lead walks an E minor
// figure over a chugging two-stroke bass (a bass note on every beat's offbeat, like an
// engine), a kick and a snare crack on the backbeat; a thin siren-like wheeze joins as the
// dread grows. The bridge drops the drums for a creeping line.
ghoulMowerRide: {
bpm: 138,
rush: 8,
voices: {
lead: { wave: "pulse", duty: 0.25, gain: 0.1, decay: 0.12, sustain: 0.45 },
bass: { wave: "triangle", gain: 0.42, decay: 0.08, sustain: 0.5 },
chug: { wave: "sawtooth", gain: 0.07, decay: 0.06, sustain: 0.2, from: 0.15 },
kick: { kit: true, gain: 0.26, from: 0.2 },
hat: { kit: true, gain: 0.1, from: 0.35 },
snap: { kit: true, gain: 0.16, from: 0.5 },
wheeze: { wave: "sawtooth", gain: 0.03, decay: 0.3, sustain: 1, from: 0.75, vibrato: { rate: 0.7, depth: 0.05, delay: 0 } },
},
patterns: {
A: {
lead:
"E4 . G4 . B4 . G4 . E4 . G4 . B4 . G4 . | E4 . G4 . A4 . F#4 . E4 . G4 . A4 . F#4 . | " +
"E4 . G4 . B4 . D5 . B4 . G4 . B4 . D5 . | C5 . B4 . A4 . G4 . F#4 . . . B4 . . .",
bass:
"E2 . . E2 . . E2 . E2 . . E2 . . E2 . | E2 . . E2 . . E2 . E2 . . E2 . . E2 . | " +
"C2 . . C2 . . C2 . C2 . . C2 . . C2 . | B1 . . B1 . . B1 . B1 . . B1 . . B1 .",
chug:
". . E3 . . . E3 . . . E3 . . . E3 . | . . E3 . . . E3 . . . E3 . . . E3 . | " +
". . C3 . . . C3 . . . C3 . . . C3 . | . . B2 . . . B2 . . . B2 . . . B2 .",
kick:
"k . . . . . k . k . . . . . k . | k . . . . . k . k . . . . . k . | " +
"k . . . . . k . k . . . . . k . | k . . . . . k . k . . . . . k .",
hat:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .",
wheeze:
"B3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - - | " +
"G3 - - - - - - - - - - - - - - - | F#3 - - - - - - - - - - - - - - -",
},
B: {
lead:
"B4 . D5 . E5 . D5 . B4 . D5 . E5 . G5 . | F#5 . E5 . D5 . B4 . A4 . B4 . D5 . . . | " +
"E5 . D5 . B4 . D5 . E5 . G5 . E5 . D5 . | C5 . D5 . B4 . A4 . B4 . . . . . . .",
bass:
"E2 . . E2 . . E2 . E2 . . E2 . . E2 . | A1 . . A1 . . A1 . A1 . . A1 . . A1 . | " +
"C2 . . C2 . . C2 . C2 . . C2 . . C2 . | B1 . . B1 . . B1 . B1 . . B1 . . B1 .",
chug:
". . E3 . . . E3 . . . E3 . . . E3 . | . . A2 . . . A2 . . . A2 . . . A2 . | " +
". . C3 . . . C3 . . . C3 . . . C3 . | . . B2 . . . B2 . . . B2 . . . B2 .",
kick:
"k . . . . . k . k . . . . . k . | k . . . . . k . k . . . . . k . | " +
"k . . . . . k . k . . . . . k . | k . . . . . k . k . . . k . k .",
hat:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . h . h .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . s s",
wheeze:
"E4 - - - - - - - - - - - - - - - | C#4 - - - - - - - - - - - - - - - | " +
"C4 - - - - - - - - - - - - - - - | B3 - - - - - - - - - - - - - - -",
},
C: {
lead:
"E4 . . . G4 . . . B4 . . . G4 . . . | A4 . . . F#4 . . . E4 . . . . . . . | " +
"E4 . . . G4 . . . B4 . . . D5 . . . | C5 . . . B4 . . . A4 . . . . . . .",
bass:
"E2 . . . . . . . E2 . . . . . . . | A1 . . . . . . . A1 . . . . . . . | " +
"C2 . . . . . . . C2 . . . . . . . | B1 . . . . . . . B1 . . . . . . .",
chug:
". . . . . . E3 . . . . . . . E3 . | . . . . . . A2 . . . . . . . A2 . | " +
". . . . . . C3 . . . . . . . C3 . | . . . . . . B2 . . . . . . . B2 .",
kick:
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
hat:
". . . . h . . . . . . . h . . . | . . . . h . . . . . . . h . . . | " +
". . . . h . . . . . . . h . . . | . . . . h . . . . . . . h . . .",
snap:
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
". . . . . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
wheeze:
"B3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - - | " +
"G3 - - - - - - - - - - - - - - - | F#3 - - - - - - - - - - - - - - -",
},
},
order: ["A", "A", "B", "A", "C", "B", "A", "B", "C"],
},
},
};
@@ -0,0 +1,220 @@
// Plan2Code Web Console - ghoul: Holy Roller's own sound effects and music track, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoul<Kind><Act>` sound for the runner's
// moves and things, each under 1.2 s) and `music` (a track for the room, named in ROOM_MUSIC in ghoul.js).
// The sounds and the track are first drafts in the house's tone layers; they are still to be
// picked by ear. A name may be defined only once across tones.js and every game's file. No imports.
export const PEW_SFX = {
tones: {
// Lane change: a quick whoosh as the pew slides across.
ghoulPewLane: {
layers: [
{ type: "noise", seconds: 0.16, attack: 0.04, gain: 0.4, filter: { type: "bandpass", from: 600, to: 2400, q: 1.4 } },
{ type: "triangle", from: 180, to: 260, seconds: 0.12, attack: 0.01, gain: 0.18 },
],
},
// A lane press at the edge: a tiny bump on the chapel wall.
ghoulPewBump: {
layers: [
{ type: "sine", from: 120, to: 70, seconds: 0.1, attack: 0, gain: 0.6 },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.25, filter: { type: "lowpass", from: 900, to: 400, q: 1 } },
],
},
// Jump: wood creak and a lift.
ghoulPewJump: {
layers: [
{ type: "noise", seconds: 0.18, attack: 0.05, gain: 0.3, filter: { type: "bandpass", from: 700, to: 1800, q: 4 } },
{ type: "triangle", from: 240, to: 420, seconds: 0.2, attack: 0.02, gain: 0.3 },
],
},
// Landing: a wooden thump.
ghoulPewLand: {
layers: [
{ type: "sine", from: 130, to: 55, seconds: 0.14, attack: 0, gain: 0.8 },
{ type: "noise", seconds: 0.06, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 900, to: 500, q: 3 } },
],
},
// Slide: a scrape of wood on stone.
ghoulPewSlide: {
layers: [
{ type: "noise", seconds: 0.4, attack: 0.03, gain: 0.42, filter: { type: "bandpass", from: 2200, to: 900, q: 2 } },
{ type: "sawtooth", from: 110, to: 80, seconds: 0.35, attack: 0.02, gain: 0.1, filter: { type: "lowpass", from: 700, to: 300, q: 1 } },
],
},
// Down in the air, a fast fall: a falling whistle.
ghoulPewDive: {
layers: [
{ type: "sine", from: 900, to: 260, seconds: 0.2, attack: 0.01, gain: 0.2 },
{ type: "noise", seconds: 0.18, attack: 0.02, gain: 0.2, filter: { type: "highpass", from: 1200, to: 1200, q: 1 } },
],
},
// A wax soul taken: a bright tick (the art raises its pitch with the combo).
ghoulPewSoul: {
layers: [
{ type: "sine", from: 880, to: 880, seconds: 0.1, attack: 0.003, gain: 0.3 },
{ type: "triangle", from: 1760, to: 1760, seconds: 0.08, attack: 0.003, gain: 0.12 },
{ type: "noise", seconds: 0.02, attack: 0, gain: 0.1, filter: { type: "highpass", from: 5000, to: 5000, q: 1 } },
],
},
// A halo caught: a rising shimmer.
ghoulPewHalo: {
layers: [
{ type: "sine", from: 660, to: 1320, seconds: 0.5, attack: 0.01, gain: 0.28 },
{ type: "sine", from: 990, to: 1980, seconds: 0.5, attack: 0.01, gain: 0.16, delay: 0.04 },
{ type: "sine", from: 1320, to: 2640, seconds: 0.4, attack: 0.01, gain: 0.1, delay: 0.08 },
],
},
// A hit: splintering wood and a sour organ chord.
ghoulPewCrash: {
layers: [
{ type: "sine", from: 96, to: 34, seconds: 0.25, attack: 0, gain: 0.95 },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 300, to: 260, q: 1 } },
{ type: "noise", seconds: 0.3, attack: 0.04, gain: 0.4, delay: 0.02, filter: { type: "bandpass", from: 1200, to: 3200, q: 2 } },
{ type: "sawtooth", from: 196, to: 190, seconds: 0.5, attack: 0.02, gain: 0.2, delay: 0.05, filter: { type: "lowpass", from: 900, to: 500, q: 1 } },
{ type: "sawtooth", from: 208, to: 200, seconds: 0.5, attack: 0.02, gain: 0.2, delay: 0.05, filter: { type: "lowpass", from: 900, to: 500, q: 1 } },
{ type: "sawtooth", from: 233, to: 225, seconds: 0.5, attack: 0.02, gain: 0.2, delay: 0.05, filter: { type: "lowpass", from: 900, to: 500, q: 1 } },
],
},
// Checkpoint: two chapel bell strokes.
ghoulPewCheck: {
layers: [
{ type: "sine", from: 784, to: 776, seconds: 0.4, attack: 0.003, gain: 0.3 },
{ type: "sine", from: 2093, to: 2070, seconds: 0.2, attack: 0.003, gain: 0.12 },
{ type: "sine", from: 988, to: 980, seconds: 0.5, attack: 0.003, gain: 0.3, delay: 0.16 },
{ type: "sine", from: 2637, to: 2610, seconds: 0.25, attack: 0.003, gain: 0.12, delay: 0.16 },
],
},
// Finish: an organ fanfare, a major chord.
ghoulPewFinish: {
layers: [
{ type: "square", seconds: 1, attack: 0.02, gain: 0.2, notes: [262, 330, 392, 523], filter: { type: "lowpass", from: 1600, to: 1600, q: 1 } },
{ type: "triangle", seconds: 1, attack: 0.02, gain: 0.4, notes: [131, 165, 196, 262] },
{ type: "sine", seconds: 1, attack: 0.02, gain: 0.2, notes: [523, 659, 784, 1047] },
],
},
// The ride picks up speed: an organ swell, rising.
ghoulPewSpeed: {
layers: [
{ type: "sawtooth", from: 147, to: 294, seconds: 0.7, attack: 0.3, gain: 0.2, filter: { type: "lowpass", from: 600, to: 1600, q: 1 } },
{ type: "sawtooth", from: 220, to: 440, seconds: 0.7, attack: 0.3, gain: 0.14, filter: { type: "lowpass", from: 600, to: 1600, q: 1 } },
{ type: "noise", seconds: 0.6, attack: 0.3, gain: 0.18, filter: { type: "bandpass", from: 500, to: 3000, q: 1.5 } },
],
},
// Gargoyle: a stone gargoyle in the arches. It shudders (grinding stone) ...
ghoulPewGargWarn: {
layers: [
{ type: "brown", seconds: 0.45, attack: 0.05, gain: 0.5, filter: { type: "bandpass", from: 300, to: 700, q: 3 } },
{ type: "sawtooth", from: 92, to: 70, seconds: 0.45, attack: 0.05, gain: 0.3, vibrato: { rate: 18, depth: 0.12 }, filter: { type: "lowpass", from: 500, to: 300, q: 2 } },
],
},
// ... drops into the lane (a heavy stone thud) ...
ghoulPewGargDrop: {
layers: [
{ type: "sine", from: 74, to: 28, seconds: 0.3, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.25, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 240, to: 200, q: 1 } },
{ type: "noise", seconds: 0.1, attack: 0, gain: 0.35, delay: 0.02, filter: { type: "bandpass", from: 1400, to: 800, q: 2 } },
],
},
// ... a first bolt chips it (a stone crack) ...
ghoulPewGargChip: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 2200, to: 1400, q: 3 } },
{ type: "square", from: 520, to: 300, seconds: 0.04, attack: 0, gain: 0.2 },
],
},
// ... and the second bolt breaks it: stone cracking apart.
ghoulPewGargHit: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.8, filter: { type: "bandpass", from: 1800, to: 1000, q: 2 } },
{ type: "square", from: 600, to: 200, seconds: 0.05, attack: 0, gain: 0.3 },
{ type: "noise", seconds: 0.04, delay: 0.07, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 2600, to: 1600, q: 3 } },
{ type: "brown", seconds: 0.3, attack: 0.02, gain: 0.5, delay: 0.04, filter: { type: "lowpass", from: 500, to: 200, q: 1 } },
],
},
// Bell rope: shoot it and the bell rings, a deep stroke, and the gargoyles ahead are stunned.
ghoulPewBell: {
layers: [
{ type: "sine", from: 392, to: 386, seconds: 1.1, attack: 0.004, gain: 0.5 },
{ type: "sine", from: 784, to: 772, seconds: 0.9, attack: 0.004, gain: 0.22 },
{ type: "sine", from: 1180, to: 1160, seconds: 0.6, attack: 0.004, gain: 0.14 },
{ type: "sine", from: 1990, to: 1960, seconds: 0.35, attack: 0.004, gain: 0.08 },
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 3000, to: 2000, q: 3 } },
],
},
},
music: {
// Holy Roller: the organist's chase. A driving D minor organ ride at 132 beats a minute (the pulse the
// art throbs in the pillars and windows): four on the floor, a pedal bass in eighths, organ chords on the
// off-beats, a reed line that climbs through the bars, and a bell stroke on the backbeat. Built to loop:
// two four-bar phrases that answer each other, round and round.
ghoulPewDirge: {
bpm: 132,
rush: 0,
voices: {
organ: { wave: "square", gain: 0.045, decay: 0.12, sustain: 0.6, vibrato: { rate: 5, depth: 0.01, delay: 0.2 } },
reed: { wave: "sawtooth", gain: 0.04, decay: 0.12, sustain: 0.6, vibrato: { rate: 5.5, depth: 0.018, delay: 0.2 } },
pedal: { wave: "triangle", gain: 0.42, decay: 0.2, sustain: 0.7 },
kick: { kit: true, gain: 0.22, from: 0 },
toll: { kit: true, gain: 0.12, from: 0.35 },
},
patterns: {
A: {
organ:
". . D4^037 - . . D4^037 - . . D4^037 - . . D4^037 - | " +
". . Bb3^047 - . . Bb3^047 - . . Bb3^047 - . . Bb3^047 - | " +
". . G3^037 - . . G3^037 - . . G3^037 - . . G3^037 - | " +
". . A3^047 - . . A3^047 - . . A3^047 - . . A3^047 -",
reed:
"D5 - F5 - A5 - F5 - D5 - F5 - A5 - F5 - | " +
"D5 - F5 - Bb5 - F5 - D5 - F5 - Bb5 - F5 - | " +
"D5 - G5 - Bb5 - G5 - D5 - G5 - Bb5 - G5 - | " +
"E5 - A5 - C#6 - A5 - E5 - A5 - C#6 - A5 -",
pedal:
"D2 - D2 - D2 - D2 - D2 - D2 - D2 - D2 - | " +
"Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - | " +
"G1 - G1 - G1 - G1 - G1 - G1 - G1 - G1 - | " +
"A1 - A1 - A1 - A1 - A1 - A1 - A1 - A1 -",
kick:
"k . . . k . . . k . . . k . . . | " +
"k . . . k . . . k . . . k . . . | " +
"k . . . k . . . k . . . k . . . | " +
"k . . . k . . . k . . . k . . .",
toll:
". . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . s .",
},
B: {
organ:
". . F4^037 - . . F4^037 - . . F4^037 - . . F4^037 - | " +
". . G3^037 - . . G3^037 - . . G3^037 - . . G3^037 - | " +
". . Bb3^047 - . . Bb3^047 - . . Bb3^047 - . . Bb3^047 - | " +
". . A3^047 - . . A3^047 - . . A3^047 - . . A3^047 -",
reed:
"A5 - F5 - A5 - D6 - A5 - F5 - A5 - D6 - | " +
"G5 - D5 - G5 - Bb5 - G5 - D5 - G5 - Bb5 - | " +
"F5 - D5 - F5 - Bb5 - F5 - D5 - F5 - Bb5 - | " +
"E5 - A5 - C#6 - E6 - D6 - A5 - F5 - A4 -",
pedal:
"F1 - F1 - F1 - F1 - F1 - F1 - F1 - F1 - | " +
"G1 - G1 - G1 - G1 - G1 - G1 - G1 - G1 - | " +
"Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - Bb1 - | " +
"A1 - A1 - A1 - A1 - A1 - A1 - A1 - A1 -",
kick:
"k . . . k . . . k . . . k . . . | " +
"k . . . k . . . k . . . k . . . | " +
"k . . . k . . . k . . . k . . . | " +
"k . . . k . . . k . . . k . k .",
toll:
". . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . .",
},
},
order: ["A", "B", "A", "B", "A", "B"],
},
},
};
@@ -0,0 +1,116 @@
// Plan2Code Web Console - ghoul: the game's intro story's own sounds, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-tray.js: `tones` (one-shots named in the pages' `cues` in
// ghoul-story.js: wind, a distant bell, a heartbeat, a door creak, knocks, a whisper, a flashlight
// click, a page turn, the last page's "begin") and `hums` (the low drone that runs under the whole
// story, asked for every tick by ghoul.js while the story is up). Made from the house tone
// layers only; no tone is longer than 1.2 s. A name may be defined only once across tones.js and
// every game's file. No imports.
export const STORY_SFX = {
tones: {
// A long cold gust over open ground.
ghoulStoryWind: {
layers: [
{ type: "noise", seconds: 1.15, attack: 0.5, gain: 0.34, filter: { type: "bandpass", from: 420, to: 1100, q: 1.6 } },
{ type: "brown", seconds: 1.1, attack: 0.4, gain: 0.5, filter: { type: "lowpass", from: 260, to: 520 } },
{ type: "sine", from: 310, to: 380, seconds: 1.0, attack: 0.5, delay: 0.1, gain: 0.05, vibrato: { rate: 5, depth: 0.04 } },
],
},
// A far-off bell: a dull strike and a long, falling ring.
ghoulStoryBell: {
layers: [
{ type: "sine", from: 233, to: 231, seconds: 1.15, attack: 0.004, gain: 0.34 },
{ type: "sine", from: 466, to: 462, seconds: 1.0, attack: 0.004, gain: 0.16 },
{ type: "sine", from: 700, to: 694, seconds: 0.8, attack: 0.004, gain: 0.08 },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.2, filter: { type: "lowpass", from: 1400, to: 700 } },
],
},
// Two heavy beats of a heart under the floor.
ghoulStoryBeat: {
layers: [
{ type: "sine", from: 62, to: 38, seconds: 0.22, attack: 0.008, gain: 0.7 },
{ type: "brown", seconds: 0.16, attack: 0.004, gain: 0.5, filter: { type: "lowpass", from: 200, to: 90 } },
{ type: "sine", from: 56, to: 34, seconds: 0.26, attack: 0.008, delay: 0.3, gain: 0.55 },
{ type: "brown", seconds: 0.18, attack: 0.004, delay: 0.3, gain: 0.4, filter: { type: "lowpass", from: 180, to: 80 } },
],
},
// A door opening on dry hinges.
ghoulStoryCreak: {
layers: [
{ type: "sawtooth", from: 150, to: 310, seconds: 1.0, attack: 0.1, gain: 0.12, vibrato: { rate: 13, depth: 0.08 }, filter: { type: "bandpass", from: 700, to: 1500, q: 7 } },
{ type: "sawtooth", from: 180, to: 250, seconds: 0.8, attack: 0.2, delay: 0.2, gain: 0.08, vibrato: { rate: 9, depth: 0.06 }, filter: { type: "bandpass", from: 1100, to: 800, q: 6 } },
{ type: "noise", seconds: 0.9, attack: 0.3, gain: 0.05, filter: { type: "bandpass", from: 2400, to: 1800, q: 3 } },
],
},
// Three slow knocks from the wrong side of a wall.
ghoulStoryKnock: {
layers: [0, 0.3, 0.6].flatMap((delay, i) => [
{ type: "sine", from: 140 - i * 6, to: 90, seconds: 0.09, attack: 0.002, delay, gain: 0.6 },
{ type: "noise", seconds: 0.04, attack: 0, delay, gain: 0.3, filter: { type: "bandpass", from: 900, to: 500, q: 3 } },
]),
},
// A whisper in the next room: breath shaped into almost-words.
ghoulStoryWhisper: {
layers: [
{ type: "pink", seconds: 1.1, attack: 0.3, gain: 0.3, filter: { type: "bandpass", from: 1700, to: 2600, q: 5 } },
{ type: "pink", seconds: 0.9, attack: 0.25, delay: 0.15, gain: 0.2, filter: { type: "bandpass", from: 3000, to: 2100, q: 6 } },
{ type: "sine", from: 190, to: 170, seconds: 1.0, attack: 0.4, gain: 0.04, vibrato: { rate: 7, depth: 0.05 } },
],
},
// A flashlight clicking on: a switch, a hum of current, a bright bloom.
ghoulStoryClick: {
layers: [
{ type: "square", from: 1600, to: 900, seconds: 0.018, attack: 0, gain: 0.3 },
{ type: "noise", seconds: 0.03, attack: 0, delay: 0.02, gain: 0.3, filter: { type: "highpass", from: 3000, to: 4000 } },
{ type: "triangle", from: 400, to: 1250, seconds: 0.45, attack: 0.05, delay: 0.06, gain: 0.16 },
{ type: "sine", from: 1250, to: 1260, seconds: 0.5, attack: 0.02, delay: 0.3, gain: 0.08 },
],
},
// A page turning: a soft paper whoosh.
ghoulStoryPage: {
layers: [
{ type: "noise", seconds: 0.22, attack: 0.05, gain: 0.2, filter: { type: "bandpass", from: 1600, to: 4200, q: 1.2 } },
{ type: "sine", from: 330, to: 262, seconds: 0.2, attack: 0.01, gain: 0.05 },
],
},
// A crow, once, from somewhere in the dark.
ghoulStoryCrow: {
layers: [
{ type: "sawtooth", from: 520, to: 360, seconds: 0.2, attack: 0.01, gain: 0.16, filter: { type: "bandpass", from: 1200, to: 900, q: 3 } },
{ type: "sawtooth", from: 500, to: 330, seconds: 0.22, attack: 0.01, delay: 0.26, gain: 0.14, filter: { type: "bandpass", from: 1100, to: 800, q: 3 } },
],
},
// A swallow: something very large clearing its throat.
ghoulStoryGulp: {
layers: [
{ type: "sine", from: 95, to: 48, seconds: 0.6, attack: 0.15, gain: 0.5, vibrato: { rate: 8, depth: 0.1 } },
{ type: "brown", seconds: 0.5, attack: 0.2, gain: 0.5, filter: { type: "lowpass", from: 500, to: 120 } },
{ type: "noise", seconds: 0.2, attack: 0.02, delay: 0.5, gain: 0.1, filter: { type: "bandpass", from: 800, to: 400, q: 2 } },
],
},
// A lock turning and a bolt thrown home.
ghoulStoryLock: {
layers: [
{ type: "noise", seconds: 0.03, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 2600, to: 2000, q: 8 } },
{ type: "noise", seconds: 0.05, attack: 0, delay: 0.14, gain: 0.6, filter: { type: "bandpass", from: 1200, to: 700, q: 6 } },
{ type: "sine", from: 120, to: 70, seconds: 0.25, attack: 0.004, delay: 0.14, gain: 0.5 },
],
},
// The last page: a slammed chord, a rising sweep and a flash of bright metal. The run begins.
ghoulStoryBegin: {
layers: [
{ type: "sawtooth", from: 110, to: 108, seconds: 1.0, attack: 0.005, gain: 0.4, filter: { type: "lowpass", from: 2600, to: 400 } },
{ type: "sawtooth", from: 165, to: 163, seconds: 1.0, attack: 0.005, gain: 0.34, filter: { type: "lowpass", from: 2600, to: 400 } },
{ type: "sawtooth", from: 220, to: 218, seconds: 0.9, attack: 0.005, gain: 0.3, filter: { type: "lowpass", from: 2600, to: 400 } },
{ type: "brown", seconds: 0.5, attack: 0.003, gain: 0.7, filter: { type: "lowpass", from: 500, to: 100 } },
{ type: "noise", seconds: 0.6, attack: 0.3, gain: 0.14, delay: 0.5, filter: { type: "highpass", from: 1500, to: 6000 } },
{ type: "triangle", from: 880, to: 1760, seconds: 0.45, attack: 0.02, delay: 0.6, gain: 0.14 },
],
},
},
hums: {
// Under every page: a low, slow breath, a house asleep with one eye open.
ghoulStoryDrone: { parts: [{ type: "sawtooth", freq: 55 }, { type: "sawtooth", freq: 55.7, gain: 0.8 }, { type: "sine", freq: 82.4, gain: 0.35 }], noise: { color: "brown", gain: 0.4 }, filter: { type: "lowpass", freq: 220, q: 3, follow: 0.6 }, pulse: { rate: 0.35, depth: 0.5 }, peak: 0.035 },
},
};
@@ -0,0 +1,225 @@
// Plan2Code Web Console - ghoul: The Servants' Back Stairs' own sound effects and music track, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulTray<Act>` sound for the tray's
// things, named in ghoul-tray-draw.js's VOICES) and `music` (the room's track, named in
// ROOM_MUSIC in ghoul.js). Made from the house tone layers only; no tone is longer than 1.2 s.
// Sound and music picks are still pending (these are first drafts to be picked by ear). A name
// may be defined only once across tones.js and every game's file. No imports.
export const TRAY_SFX = {
tones: {
// The Servants' Back Stairs: the bonus ride: you rush down the back stairs and through the kitchens on a silver tray.
// Jumps: A tin clank and a whoosh.
ghoulTrayJump: {
layers: [
{ type: "square", from: 560, to: 320, seconds: 0.06, attack: 0, gain: 0.16 },
{ type: "noise", seconds: 0.2, attack: 0.06, gain: 0.34, filter: { type: "bandpass", from: 2800, to: 1300, q: 5 } },
{ type: "noise", seconds: 0.28, attack: 0.1, gain: 0.3, delay: 0.04, filter: { type: "bandpass", from: 300, to: 1700, q: 1.5 } },
],
},
// Lands: Cutlery clatter.
ghoulTrayLand: {
layers: [
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.54, filter: { type: "bandpass", from: 2400, to: 1900, q: 7 } },
{ type: "triangle", from: 880, to: 700, seconds: 0.05, gain: 0.2 },
{ type: "noise", seconds: 0.04, delay: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 3100, to: 2500, q: 7 } },
{ type: "noise", seconds: 0.04, delay: 0.09, attack: 0, gain: 0.46, filter: { type: "bandpass", from: 1900, to: 1500, q: 7 } },
{ type: "noise", seconds: 0.3, attack: 0.09, gain: 0.26, delay: 0.1, filter: { type: "bandpass", from: 3500, to: 1800, q: 4 } },
],
},
// Launches off the last shelf: A big whoosh and a rising ting.
ghoulTrayLaunch: {
layers: [
{ type: "noise", seconds: 0.8, attack: 0.3, gain: 0.5, filter: { type: "bandpass", from: 400, to: 2600, q: 2 } },
{ type: "sine", from: 400, to: 1200, seconds: 0.5, attack: 0.1, gain: 0.36, vibrato: { rate: 6, depth: 0.05 } },
{ type: "sine", from: 2093, to: 2093, seconds: 0.4, attack: 0.003, gain: 0.2, delay: 0.5 },
],
},
// Ducks: A quick swish.
ghoulTrayDuck: {
layers: [
{ type: "noise", seconds: 0.18, attack: 0.06, gain: 0.5, filter: { type: "bandpass", from: 500, to: 2400, q: 1.5 } },
],
},
// Crash: A pot dropped down the stairs.
ghoulTrayCrash: {
layers: [
{ type: "sine", from: 110, to: 38, seconds: 0.25, attack: 0, gain: 1 },
{ type: "square", from: 720, to: 380, seconds: 0.08, attack: 0, gain: 0.22 },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.7, delay: 0.02, filter: { type: "bandpass", from: 1800, to: 1400, q: 6 } },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.6, delay: 0.09, filter: { type: "bandpass", from: 2300, to: 1700, q: 6 } },
{ type: "noise", seconds: 0.4, attack: 0.12, gain: 0.3, delay: 0.05, filter: { type: "bandpass", from: 1400, to: 3200, q: 2 } },
],
},
// Checkpoint: A service bell, ding ding.
ghoulTrayCheck: {
layers: [
{ type: "sine", from: 1760, to: 1750, seconds: 0.5, attack: 0.003, gain: 0.34 },
{ type: "sine", from: 3520, to: 3500, seconds: 0.35, attack: 0.003, gain: 0.16 },
{ type: "sine", from: 5280, to: 5250, seconds: 0.2, attack: 0.003, gain: 0.08 },
{ type: "sine", from: 1760, to: 1750, seconds: 0.5, attack: 0.003, gain: 0.34, delay: 0.14 },
{ type: "sine", from: 3520, to: 3500, seconds: 0.35, attack: 0.003, gain: 0.16, delay: 0.14 },
],
},
// Finish: A fanfare, and plates ringing.
ghoulTrayFinish: {
layers: [
{ type: "triangle", seconds: 0.9, attack: 0.01, gain: 0.7, notes: [392, 494, 587, 784] },
{ type: "sine", seconds: 0.9, attack: 0.01, gain: 0.25, notes: [784, 988, 1175, 1568] },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.4, delay: 0.7, filter: { type: "highpass", from: 3500, to: 3500, q: 1 } },
],
},
// A silver dome: Run through it and it chimes up the scale.
ghoulTrayDome: {
layers: [
{ type: "sine", from: 2637, to: 2620, seconds: 0.28, attack: 0.003, gain: 0.3 },
{ type: "sine", from: 3951, to: 3930, seconds: 0.22, attack: 0.003, gain: 0.2, delay: 0.06 },
{ type: "sine", from: 5274, to: 5250, seconds: 0.18, attack: 0.003, gain: 0.14, delay: 0.12 },
{ type: "noise", seconds: 0.03, attack: 0, gain: 0.3, filter: { type: "highpass", from: 5000, to: 5000, q: 1 } },
],
},
// A flying plate: Caught with a china clink and a sweet chime.
ghoulTrayPlate: {
layers: [
{ type: "sine", from: 3322, to: 3300, seconds: 0.12, attack: 0.002, gain: 0.3 },
{ type: "sine", from: 4435, to: 4400, seconds: 0.08, attack: 0.002, gain: 0.2, delay: 0.03 },
{ type: "noise", seconds: 0.03, attack: 0, gain: 0.35, filter: { type: "highpass", from: 4000, to: 4000, q: 1 } },
{ type: "sine", from: 1568, to: 1560, seconds: 0.3, attack: 0.003, gain: 0.3, delay: 0.1 },
{ type: "sine", from: 2093, to: 2085, seconds: 0.4, attack: 0.003, gain: 0.3, delay: 0.17 },
],
},
// Spectral cook: A cook who winds up to fling a dish at you (shoot him, or jump the dish).
// Appears: A hollow, hungry groan.
ghoulTrayCookUp: {
layers: [
{ type: "sawtooth", from: 170, to: 105, seconds: 0.5, attack: 0.06, gain: 0.3, vibrato: { rate: 6, depth: 0.08 }, filter: { type: "lowpass", from: 800, to: 400, q: 2 } },
{ type: "pink", seconds: 0.5, attack: 0.1, gain: 0.14, filter: { type: "bandpass", from: 520, to: 300, q: 1 } },
],
},
// Flings the dish: A whoosh.
ghoulTrayToss: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0.1, gain: 0.4, filter: { type: "bandpass", from: 700, to: 2200, q: 2 } },
{ type: "triangle", from: 300, to: 520, seconds: 0.15, attack: 0.01, gain: 0.2 },
],
},
// Shot: A pop and a sigh.
ghoulTrayCookHit: {
layers: [
{ type: "sine", from: 620, to: 190, seconds: 0.1, attack: 0, gain: 0.6 },
{ type: "noise", seconds: 0.14, attack: 0, gain: 0.3, filter: { type: "bandpass", from: 1600, to: 600, q: 2 } },
{ type: "sine", from: 230, to: 110, seconds: 0.4, attack: 0.02, gain: 0.3, delay: 0.05, vibrato: { rate: 5, depth: 0.1 } },
],
},
// A dish shot out of the air: China smashing.
ghoulTrayDishBreak: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "highpass", from: 3000, to: 3000, q: 1 } },
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.45, delay: 0.04, filter: { type: "bandpass", from: 4200, to: 3000, q: 5 } },
{ type: "noise", seconds: 0.04, attack: 0, gain: 0.4, delay: 0.09, filter: { type: "bandpass", from: 3400, to: 2400, q: 5 } },
{ type: "square", from: 1400, to: 600, seconds: 0.05, attack: 0, gain: 0.16 },
],
},
},
music: {
// The Servants' Back Stairs: kitchen galop. A clattering, hurried polka for the tray's rush
// down the back stairs: a pulse lead skipping over a stair-step oompah bass, a tin tick of
// cutlery on the offbeats, a kick, a hat and the snap of a pan. At high dread a riser and
// a second lead an octave up join in.
ghoulTrayRide: {
bpm: 172,
rush: 10,
voices: {
lead: { wave: "pulse", duty: 0.25, gain: 0.12, decay: 0.08, sustain: 0.35 },
tin: { wave: "pulse", duty: 0.125, gain: 0.05, decay: 0.03, sustain: 0.2, from: 0.15 },
bass: { wave: "triangle", gain: 0.4, decay: 0.08, sustain: 0.5 },
kick: { kit: true, gain: 0.26, from: 0.2 },
hat: { kit: true, gain: 0.1, from: 0.4 },
snap: { kit: true, gain: 0.16, from: 0.55 },
riser: { wave: "sawtooth", gain: 0.035, decay: 0.3, sustain: 1, from: 0.8, vibrato: { rate: 0.6, depth: 0.04, delay: 0 } },
lead2: { wave: "pulse", duty: 0.25, gain: 0.07, decay: 0.1, sustain: 0.3, from: 0.9 },
},
patterns: {
A: {
lead:
"D5 . F5 . A5 . F5 . D5 . F5 . A5 . D6 . | C5 . E5 . G5 . E5 . C5 . E5 . G5 . C6 . | " +
"Bb4 . D5 . F5 . D5 . Bb4 . D5 . F5 . Bb5 . | A4 . C#5 . E5 . A5 . E5 . C#5 . A4 . . .",
tin:
". D6 . D6 . D6 . D6 . D6 . D6 . D6 . D6 | . C6 . C6 . C6 . C6 . C6 . C6 . C6 . C6 | " +
". Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 | . A5 . A5 . A5 . A5 . A5 . A5 . A5 . A5",
bass:
"D3 . A3 . D3 . A3 . D3 . A3 . D3 . A3 . | C3 . G3 . C3 . G3 . C3 . G3 . C3 . G3 . | " +
"Bb2 . F3 . Bb2 . F3 . Bb2 . F3 . Bb2 . F3 . | A2 . E3 . A2 . E3 . A2 . E3 . A2 . E3 .",
kick:
"k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . . | " +
"k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . .",
hat:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .",
riser:
"D4 - - - - - - - - - - - - - - - | C4 - - - - - - - - - - - - - - - | " +
"Bb3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -",
lead2:
"D5 D5 D5 D5 F5 F5 F5 F5 A5 A5 A5 A5 . . . . | C5 C5 C5 C5 E5 E5 E5 E5 G5 G5 G5 G5 . . . . | " +
"Bb4 Bb4 Bb4 Bb4 D5 D5 D5 D5 F5 F5 F5 F5 . . . . | A4 A4 A4 A4 C#5 C#5 C#5 C#5 E5 E5 E5 E5 . . . .",
},
B: {
lead:
"A5 . F5 . D5 . F5 . A5 . F5 . D5 . A4 . | G5 . E5 . C5 . E5 . G5 . E5 . C5 . G4 . | " +
"F5 . D5 . Bb4 . D5 . F5 . D5 . Bb4 . F4 . | E5 . C#5 . A4 . C#5 . E5 . C#5 . A4 . . .",
tin:
". D6 . D6 . D6 . D6 . D6 . D6 . D6 . D6 | . C6 . C6 . C6 . C6 . C6 . C6 . C6 . C6 | " +
". Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 . Bb5 | . A5 . A5 . A5 . A5 . A5 . A5 . A5 . A5",
bass:
"D3 . A3 . D3 . A3 . D3 . A3 . D3 . A3 . | C3 . G3 . C3 . G3 . C3 . G3 . C3 . G3 . | " +
"Bb2 . F3 . Bb2 . F3 . Bb2 . F3 . Bb2 . F3 . | A2 . E3 . A2 . E3 . A2 . E3 . A2 . E3 .",
kick:
"k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . . | " +
"k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . .",
hat:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .",
riser:
"D4 - - - - - - - - - - - - - - - | C4 - - - - - - - - - - - - - - - | " +
"Bb3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -",
lead2:
"A5 A5 A5 A5 F5 F5 F5 F5 D5 D5 D5 D5 . . . . | G5 G5 G5 G5 E5 E5 E5 E5 C5 C5 C5 C5 . . . . | " +
"F5 F5 F5 F5 D5 D5 D5 D5 Bb4 Bb4 Bb4 Bb4 . . . . | E5 E5 E5 E5 C#5 C#5 C#5 C#5 A4 A4 A4 A4 . . . .",
},
C: {
lead:
"G5 . Bb5 . D6 . Bb5 . G5 . Bb5 . D6 . G6 . | F5 . A5 . C6 . A5 . F5 . A5 . C6 . F6 . | " +
"Eb5 . G5 . Bb5 . G5 . Eb5 . G5 . Bb5 . Eb6 . | A5 . C#6 . E6 . C#6 . A5 . E5 . A4 . . .",
tin:
". G6 . G6 . G6 . G6 . G6 . G6 . G6 . G6 | . F6 . F6 . F6 . F6 . F6 . F6 . F6 . F6 | " +
". Eb6 . Eb6 . Eb6 . Eb6 . Eb6 . Eb6 . Eb6 . Eb6 | . A5 . A5 . A5 . A5 . A5 . A5 . A5 . A5",
bass:
"G2 . D3 . G2 . D3 . G2 . D3 . G2 . D3 . | F2 . C3 . F2 . C3 . F2 . C3 . F2 . C3 . | " +
"Eb2 . Bb2 . Eb2 . Bb2 . Eb2 . Bb2 . Eb2 . Bb2 . | A2 . E3 . A2 . E3 . A2 . E3 . A2 . E3 .",
kick:
"k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . . | " +
"k . . . k . . . k . . . k . . . | k . . . k . . . k . . . k . . .",
hat:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .",
riser:
"G3 - - - - - - - - - - - - - - - | F3 - - - - - - - - - - - - - - - | " +
"Eb3 - - - - - - - - - - - - - - - | A3 - - - - - - - - - - - - - - -",
lead2:
"G5 G5 G5 G5 Bb5 Bb5 Bb5 Bb5 D6 D6 D6 D6 . . . . | F5 F5 F5 F5 A5 A5 A5 A5 C6 C6 C6 C6 . . . . | " +
"Eb5 Eb5 Eb5 Eb5 G5 G5 G5 G5 Bb5 Bb5 Bb5 Bb5 . . . . | A5 A5 A5 A5 C#6 C#6 C#6 C#6 E6 E6 E6 E6 . . . .",
},
},
order: ["A", "B", "A", "C", "B", "A", "B", "A", "C", "B", "A"],
},
},
};
@@ -0,0 +1,230 @@
// Plan2Code Web Console - ghoul: The Torch Mob's own sound effects and music track, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-sled.js: `tones` (a `ghoulWagon<Act>` sound for the
// wagon's things) and `music` (a track for the room, named in ROOM_MUSIC in ghoul.js). Both are
// built here from the house's tone layers (no audio files); the picks are still to be made by ear,
// so each is a first sketch. No tone runs over 1.2 s; the track is built from short patterns. A
// name may be defined only once across tones.js and every game's file. No imports.
export const WAGON_SFX = {
tones: {
// Torch Mob: The bonus ride: you race a stolen hay wagon out of Hollow End with the whole village behind you.
// Jumps: Wheels leave the cobbles with a creak.
ghoulWagonJump: {
layers: [
{ type: "noise", seconds: 0.2, attack: 0.06, gain: 0.34, filter: { type: "bandpass", from: 1200, to: 2600, q: 3 } },
{ type: "sawtooth", from: 150, to: 230, seconds: 0.18, attack: 0.04, gain: 0.2, vibrato: { rate: 22, depth: 0.1 }, filter: { type: "bandpass", from: 500, to: 900, q: 4 } },
],
},
// Lands: Wheels and planks clatter back down.
ghoulWagonLand: {
layers: [
{ type: "sine", from: 120, to: 50, seconds: 0.16, attack: 0, gain: 0.8 },
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1500, to: 900, q: 4 } },
{ type: "noise", seconds: 0.05, delay: 0.06, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 1900, to: 1200, q: 4 } },
{ type: "noise", seconds: 0.05, delay: 0.11, attack: 0, gain: 0.3, filter: { type: "bandpass", from: 1300, to: 800, q: 4 } },
],
},
// Launches off the bridge ramp: A whoosh and a whooping horse.
ghoulWagonLaunch: {
layers: [
{ type: "noise", seconds: 0.8, attack: 0.3, gain: 0.5, filter: { type: "bandpass", from: 300, to: 2200, q: 2 } },
{ type: "sawtooth", from: 420, to: 1150, seconds: 0.55, attack: 0.08, gain: 0.3, vibrato: { rate: 9, depth: 0.08 }, filter: { type: "bandpass", from: 1100, to: 1700, q: 3 } },
{ type: "triangle", from: 280, to: 640, seconds: 0.5, attack: 0.1, gain: 0.3 },
],
},
// Brakes: Wood scrapes on stone, an axle squeal.
ghoulWagonBrake: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0.05, gain: 0.45, filter: { type: "bandpass", from: 1800, to: 700, q: 2 } },
{ type: "sawtooth", from: 900, to: 620, seconds: 0.28, attack: 0.03, gain: 0.16, vibrato: { rate: 30, depth: 0.05 }, filter: { type: "bandpass", from: 1500, to: 800, q: 6 } },
],
},
// Crash: Splintering wood.
ghoulWagonCrash: {
layers: [
{ type: "sine", from: 96, to: 36, seconds: 0.25, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.2, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 300, to: 300, q: 1 } },
{ type: "noise", seconds: 0.05, delay: 0.02, attack: 0, gain: 0.7, filter: { type: "bandpass", from: 2400, to: 1500, q: 3 } },
{ type: "noise", seconds: 0.05, delay: 0.08, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 3000, to: 2000, q: 3 } },
{ type: "noise", seconds: 0.3, delay: 0.1, attack: 0.1, gain: 0.25, filter: { type: "bandpass", from: 1200, to: 3000, q: 2 } },
],
},
// Checkpoint: The village's church bell.
ghoulWagonCheck: {
layers: [
{ type: "sine", from: 392, to: 388, seconds: 0.9, attack: 0.004, gain: 0.45 },
{ type: "sine", from: 784, to: 776, seconds: 0.7, attack: 0.004, gain: 0.22 },
{ type: "sine", from: 1180, to: 1170, seconds: 0.5, attack: 0.004, gain: 0.12 },
{ type: "sine", from: 523, to: 520, seconds: 0.8, attack: 0.004, gain: 0.3, delay: 0.16 },
{ type: "sine", from: 1046, to: 1040, seconds: 0.5, attack: 0.004, gain: 0.14, delay: 0.16 },
],
},
// Finish: A fanfare through the gate.
ghoulWagonFinish: {
layers: [
{ type: "triangle", seconds: 0.9, attack: 0.01, gain: 0.7, notes: [392, 494, 587, 784] },
{ type: "sine", seconds: 0.9, attack: 0.01, gain: 0.25, notes: [784, 988, 1175, 1568] },
],
},
// Horses bolt: The mob is close, a panicked whinny.
ghoulWagonPanic: {
layers: [
{ type: "sawtooth", from: 520, to: 1250, seconds: 0.35, attack: 0.04, gain: 0.34, vibrato: { rate: 24, depth: 0.1 }, filter: { type: "bandpass", from: 1400, to: 2200, q: 3 } },
{ type: "sawtooth", from: 1250, to: 640, seconds: 0.5, attack: 0.02, gain: 0.3, delay: 0.35, vibrato: { rate: 20, depth: 0.12 }, filter: { type: "bandpass", from: 1600, to: 900, q: 3 } },
],
},
// Caught: The mob's roar and a hard knock.
ghoulWagonCatch: {
layers: [
{ type: "sawtooth", from: 110, to: 70, seconds: 0.7, attack: 0.04, gain: 0.5, vibrato: { rate: 13, depth: 0.15 }, filter: { type: "lowpass", from: 900, to: 400, q: 2 } },
{ type: "noise", seconds: 0.7, attack: 0.1, gain: 0.35, filter: { type: "bandpass", from: 500, to: 1500, q: 1 } },
{ type: "sine", from: 80, to: 36, seconds: 0.25, attack: 0, gain: 0.9, delay: 0.05 },
],
},
// Hay catches: A flare and crackle.
ghoulWagonFire: {
layers: [
{ type: "noise", seconds: 0.5, attack: 0.1, gain: 0.5, filter: { type: "bandpass", from: 500, to: 2800, q: 1.5 } },
{ type: "pink", seconds: 0.6, attack: 0.2, gain: 0.3, filter: { type: "bandpass", from: 800, to: 3200, q: 1 } },
{ type: "noise", seconds: 0.03, delay: 0.25, attack: 0, gain: 0.5, filter: { type: "highpass", from: 3500, to: 3500 } },
{ type: "noise", seconds: 0.03, delay: 0.38, attack: 0, gain: 0.5, filter: { type: "highpass", from: 3800, to: 3800 } },
],
},
// Fire out: A hiss that dies away.
ghoulWagonOut: {
layers: [
{ type: "noise", seconds: 0.5, attack: 0.02, gain: 0.35, filter: { type: "bandpass", from: 4200, to: 1800, q: 1.5 } },
],
},
// Thrower: A villager in a window or on a roof, with a pitchfork or a torch for the wagon (shoot it or dodge it).
// Winds up: A torch flares and a grunt.
ghoulWagonWind: {
layers: [
{ type: "noise", seconds: 0.4, attack: 0.15, gain: 0.34, filter: { type: "bandpass", from: 600, to: 2400, q: 2 } },
{ type: "sawtooth", from: 150, to: 110, seconds: 0.3, attack: 0.04, gain: 0.3, vibrato: { rate: 9, depth: 0.1 }, filter: { type: "lowpass", from: 700, to: 450, q: 2 }, delay: 0.1 },
],
},
// Throws: A swish through the air.
ghoulWagonThrow: {
layers: [
{ type: "noise", seconds: 0.25, attack: 0.08, gain: 0.5, filter: { type: "bandpass", from: 3000, to: 900, q: 3 } },
{ type: "sine", from: 900, to: 400, seconds: 0.2, attack: 0.02, gain: 0.12 },
],
},
// Shot down: A crack and a shower of sparks.
ghoulWagonShot: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.8, filter: { type: "bandpass", from: 2000, to: 1300, q: 2 } },
{ type: "square", from: 900, to: 300, seconds: 0.05, attack: 0, gain: 0.3 },
{ type: "noise", seconds: 0.04, delay: 0.06, attack: 0, gain: 0.5, filter: { type: "highpass", from: 3500, to: 3500 } },
{ type: "sine", from: 2600, to: 3800, seconds: 0.16, attack: 0.002, gain: 0.15, delay: 0.05 },
],
},
// A torch lands short: A soft thud and sputter.
ghoulWagonEmber: {
layers: [
{ type: "brown", seconds: 0.1, attack: 0, gain: 0.4, filter: { type: "lowpass", from: 300, to: 300, q: 1 } },
{ type: "noise", seconds: 0.2, delay: 0.04, attack: 0.04, gain: 0.2, filter: { type: "bandpass", from: 3000, to: 1500, q: 2 } },
],
},
// Spooked Horse: A loose horse that rears, then charges down the road (jump it, or shoot it three times to turn it).
// Rears: A whinny.
ghoulWagonRear: {
layers: [
{ type: "sawtooth", from: 700, to: 1500, seconds: 0.3, attack: 0.03, gain: 0.34, vibrato: { rate: 26, depth: 0.1 }, filter: { type: "bandpass", from: 1500, to: 2400, q: 3 } },
{ type: "sawtooth", from: 1500, to: 800, seconds: 0.4, attack: 0.02, gain: 0.3, delay: 0.3, vibrato: { rate: 22, depth: 0.12 }, filter: { type: "bandpass", from: 1700, to: 1000, q: 3 } },
{ type: "noise", seconds: 0.2, attack: 0.05, gain: 0.15, filter: { type: "bandpass", from: 2400, to: 3600, q: 1.5 } },
],
},
// Takes a bolt: A startled snort.
ghoulWagonHorseHit: {
layers: [
{ type: "noise", seconds: 0.05, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 1600, to: 1100, q: 2 } },
{ type: "sawtooth", from: 420, to: 300, seconds: 0.18, attack: 0.01, gain: 0.35, vibrato: { rate: 14, depth: 0.1 }, filter: { type: "lowpass", from: 1200, to: 700, q: 2 }, delay: 0.03 },
{ type: "noise", seconds: 0.15, delay: 0.08, attack: 0.03, gain: 0.25, filter: { type: "bandpass", from: 800, to: 400, q: 1 } },
],
},
// Turns back: A whinny and hooves galloping away.
ghoulWagonHorseTurn: {
layers: [
{ type: "sawtooth", from: 800, to: 1400, seconds: 0.25, attack: 0.02, gain: 0.3, vibrato: { rate: 24, depth: 0.1 }, filter: { type: "bandpass", from: 1500, to: 2200, q: 3 } },
{ type: "noise", seconds: 0.04, delay: 0.25, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 500, to: 300, q: 4 } },
{ type: "noise", seconds: 0.04, delay: 0.33, attack: 0, gain: 0.45, filter: { type: "bandpass", from: 520, to: 320, q: 4 } },
{ type: "noise", seconds: 0.04, delay: 0.4, attack: 0, gain: 0.4, filter: { type: "bandpass", from: 500, to: 300, q: 4 } },
{ type: "noise", seconds: 0.04, delay: 0.5, attack: 0, gain: 0.3, filter: { type: "bandpass", from: 520, to: 320, q: 4 } },
{ type: "noise", seconds: 0.04, delay: 0.57, attack: 0, gain: 0.2, filter: { type: "bandpass", from: 500, to: 300, q: 4 } },
],
},
},
music: {
// Torch Mob: a runaway hoedown. A sawing fiddle line over a galloping bass (long, short, short
// on every beat) and a stomping kick and snare, in D minor, quick enough to feel chased. As the
// dread rises a drone of low chords and a high second fiddle join, and the tempo climbs.
ghoulWagonRide: {
bpm: 168,
rush: 14,
voices: {
fiddle: { wave: "pulse", duty: 0.25, gain: 0.11, decay: 0.12, sustain: 0.55, vibrato: { rate: 5.5, depth: 0.02, delay: 0.1 } },
chord: { wave: "pulse", duty: 0.125, gain: 0.045, decay: 0.05, sustain: 0.4, from: 0.25 },
bass: { wave: "triangle", gain: 0.42, decay: 0.07, sustain: 0.45 },
drums: { kit: true, gain: 0.24 },
fiddle2: { wave: "pulse", duty: 0.5, gain: 0.05, decay: 0.1, sustain: 0.5, from: 0.6 },
},
patterns: {
A: {
fiddle:
"D5 - F5 - A5 - F5 - D5 - F5 - A5 - D6 - | C6 - A5 - F5 - A5 - C6 - A5 - F5 - A5 - | " +
"Bb5 - G5 - D5 - G5 - Bb5 - G5 - D5 - G5 - | A5 - - - E5 - - - A5 - C#6 - E6 - - -",
chord:
"D4^037 - - - D4^037 - - - D4^037 - - - D4^037 - - - | F4^047 - - - F4^047 - - - F4^047 - - - F4^047 - - - | " +
"Bb3^047 - - - Bb3^047 - - - Bb3^047 - - - Bb3^047 - - - | A3^047 - - - A3^047 - - - A3^047 - - - A3^047 - - -",
bass:
"D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 | F2 . F3 F2 F2 . F3 F2 F2 . F3 F2 F2 . F3 F2 | " +
"Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 | A1 . A2 A1 A1 . A2 A1 A1 . A2 A1 A1 . A2 A1",
drums:
"k . h . s . h . k . h k s . h . | k . h . s . h . k . h k s . h . | " +
"k . h . s . h . k . h k s . h . | k . h . s . h . k . h k s . s s",
fiddle2:
"A5 - - - - - - - F5 - - - - - - - | A5 - - - - - - - C6 - - - - - - - | " +
"D6 - - - - - - - Bb5 - - - - - - - | E6 - - - - - - - A5 - - - - - - -",
},
B: {
fiddle:
"A5 - A5 D6 - D6 A5 - F5 - A5 - D6 - - - | G5 - G5 C6 - C6 G5 - E5 - G5 - C6 - - - | " +
"F5 - F5 Bb5 - Bb5 F5 - D5 - F5 - Bb5 - - - | E5 - G5 - Bb5 - A5 - G5 - E5 - C#5 - A4 -",
chord:
"D4^037 - - - D4^037 - - - D4^037 - - - D4^037 - - - | C4^047 - - - C4^047 - - - C4^047 - - - C4^047 - - - | " +
"Bb3^047 - - - Bb3^047 - - - Bb3^047 - - - Bb3^047 - - - | A3^047 - - - A3^047 - - - A3^047 - - - A3^047 - - -",
bass:
"D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 | C2 . C3 C2 C2 . C3 C2 C2 . C3 C2 C2 . C3 C2 | " +
"Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 Bb1 . Bb2 Bb1 | A1 . A2 A1 A1 . A2 A1 A1 . A2 A1 A1 . A2 A1",
drums:
"k . h . s . h . k . h k s . h . | k . h . s . h . k . h k s . h . | " +
"k . h . s . h . k . h k s . h . | k . h . s . h . k . h k s . s s",
fiddle2:
"D6 - - - - - - - D6 - - - - - - - | E6 - - - - - - - E6 - - - - - - - | " +
"F6 - - - - - - - D6 - - - - - - - | E6 - - - - - - - A5 - - - - - - -",
},
C: {
fiddle:
"F5 - A5 - D6 - A5 - F5 - A5 - D6 - F6 - | E6 - D6 - C6 - A5 - E5 - A5 - C6 - E6 - | " +
"D6 - Bb5 - G5 - Bb5 - D6 - Bb5 - G5 - D5 - | C#6 - E6 - A5 - C#6 - E5 - A5 - C#6 - E6 -",
chord:
"D4^037 - - - D4^037 - - - D4^037 - - - D4^037 - - - | A3^037 - - - A3^037 - - - A3^037 - - - A3^037 - - - | " +
"G3^037 - - - G3^037 - - - G3^037 - - - G3^037 - - - | A3^047 - - - A3^047 - - - A3^047 - - - A3^047 - - -",
bass:
"D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 D2 . D3 D2 | A1 . A2 A1 A1 . A2 A1 A1 . A2 A1 A1 . A2 A1 | " +
"G1 . G2 G1 G1 . G2 G1 G1 . G2 G1 G1 . G2 G1 | A1 . A2 A1 A1 . A2 A1 A1 . A2 A1 A1 . A2 A1",
drums:
"k . h k s . h . k . h k s . h k | k . h k s . h . k . h k s . h k | " +
"k . h k s . h . k . h k s . h k | k . h k s . h . k s k s k s s s",
fiddle2:
"F6 - - - - - - - A6 - - - - - - - | E6 - - - - - - - C6 - - - - - - - | " +
"D6 - - - - - - - Bb5 - - - - - - - | E6 - - - - - - - A6 - - - - - - -",
},
},
order: ["A", "A", "B", "A", "C", "B", "A", "B", "C", "A"],
},
},
};
+40 -1
View File
@@ -20,12 +20,22 @@ import { MINE_SFX } from "./ghoul-sfx-mine.js";
import { CARNIVAL_SFX } from "./ghoul-sfx-carnival.js";
import { FROZEN_SFX } from "./ghoul-sfx-frozen.js";
import { SLED_SFX } from "./ghoul-sfx-sled.js";
import { BANISTER_SFX } from "./ghoul-sfx-banister.js";
import { HEARSE_SFX } from "./ghoul-sfx-hearse.js";
import { BOG_SFX } from "./ghoul-sfx-bog.js";
import { BOGBOAT_SFX } from "./ghoul-sfx-bogboat.js";
import { GURNEY_SFX } from "./ghoul-sfx-gurney.js";
import { PEW_SFX } from "./ghoul-sfx-pew.js";
import { MOWER_SFX } from "./ghoul-sfx-mower.js";
import { WAGON_SFX } from "./ghoul-sfx-wagon.js";
import { TRAY_SFX } from "./ghoul-sfx-tray.js";
import { ARMS_SFX } from "./ghoul-sfx-arms.js";
import { RIDE_SFX } from "./ghoul-sfx-ride.js";
import { STORY_SFX } from "./ghoul-sfx-story.js";
// Each stage's sounds and tracks, by stage: `tones`, `hums` and `music` as
// below, any of them left out.
const STAGE_SFX = Object.freeze([GRAVEYARD_SFX, GROUNDS_SFX, CHAPEL_SFX, SANATORIUM_SFX, VILLAGE_SFX, MINE_SFX, CARNIVAL_SFX, FROZEN_SFX,SLED_SFX, ARMS_SFX, RIDE_SFX]);
const STAGE_SFX = Object.freeze([GRAVEYARD_SFX, GROUNDS_SFX, CHAPEL_SFX, SANATORIUM_SFX, VILLAGE_SFX, MINE_SFX, CARNIVAL_SFX, FROZEN_SFX,SLED_SFX, HEARSE_SFX, BOG_SFX, BOGBOAT_SFX, GURNEY_SFX, PEW_SFX, MOWER_SFX, WAGON_SFX, TRAY_SFX, ARMS_SFX, RIDE_SFX, BANISTER_SFX, STORY_SFX]);
const fromStages = (key) => Object.assign({}, ...STAGE_SFX.map((st) => st[key] || {}));
// One second of the laugh track (part 0, 1 or 2): every event is placed on the
@@ -121,6 +131,14 @@ const HOUSE = {
{ type: "noise", seconds: 0.25, delay: 0.5, gain: 0.15, filter: { type: "highpass", from: 5000, to: 8000 } },
],
},
// The Lucky die leaving the HUD: the screen holds under a low drone that swells and closes in.
ghoulDiceDrone: {
layers: [
{ type: "sawtooth", from: 52, to: 78, seconds: 0.85, attack: 0.3, gain: 0.35, filter: { type: "lowpass", from: 200, to: 700 } },
{ type: "sine", from: 104, to: 156, seconds: 0.85, attack: 0.3, gain: 0.3, vibrato: { rate: 6, depth: 0.03 } },
{ type: "noise", seconds: 0.8, gain: 0.12, filter: { type: "bandpass", from: 300, to: 2400, q: 1 } },
],
},
// A Lucky die's 1: a wind-up toy laughing at you, a ratchet clicking before
// each buzzy "ha", running down as its spring does.
ghoulDiceLaugh: {
@@ -138,6 +156,27 @@ const HOUSE = {
// pseudo-voices at staggered pitches, a hiss of applause beneath, the lot
// slowing and sagging as its spring runs down (about 3.2 s in all).
...Object.fromEntries([0, 1, 2].map((part) => [part ? `ghoulLaughTrack${part + 1}` : "ghoulLaughTrack", { layers: laughPart(part) }])),
// A stage's intro card opening: a low swell and a minor arpeggio climbing to a held, shimmering top note (about 1 s).
ghoulStageIntro: {
layers: [
{ type: "sawtooth", from: 55, to: 82, seconds: 1.0, attack: 0.2, gain: 0.3, filter: { type: "lowpass", from: 300, to: 1200 } },
...[[0, 220], [0.14, 262], [0.28, 330], [0.42, 440]].map(([delay, hz]) => ({ type: "triangle", from: hz, to: hz * 1.01, seconds: 0.55, delay, attack: 0.01, gain: 0.32 })),
{ type: "sine", from: 880, to: 884, seconds: 0.5, delay: 0.56, attack: 0.02, gain: 0.22, vibrato: { rate: 6, depth: 0.01 } },
{ type: "noise", seconds: 0.5, delay: 0.5, gain: 0.08, filter: { type: "highpass", from: 3000, to: 6000 } },
],
},
// A boss fight's card: four slamming drum hits (the letters of BOSS), a heartbeat, then low brass-like saws swelling in a dark minor chord (about 1.2 s).
ghoulBossIntro: {
layers: [
...[0.2, 0.3, 0.4, 0.5].map((delay) => ({ type: "sine", from: 120, to: 38, seconds: 0.22, delay, attack: 0.002, gain: 0.8 })),
...[0.2, 0.3, 0.4, 0.5].map((delay) => ({ type: "brown", seconds: 0.12, delay, attack: 0, gain: 0.55, filter: { type: "lowpass", from: 900, to: 150 } })),
...[0.7, 0.86].map((delay) => ({ type: "sine", from: 70, to: 40, seconds: 0.22, delay, attack: 0.004, gain: 0.7 })),
{ type: "sawtooth", from: 55, to: 58, seconds: 1.15, delay: 0.05, attack: 0.5, gain: 0.34, filter: { type: "lowpass", from: 320, to: 900 } },
{ type: "sawtooth", from: 65.4, to: 69, seconds: 1.1, delay: 0.1, attack: 0.5, gain: 0.3, filter: { type: "lowpass", from: 320, to: 900 } },
{ type: "sawtooth", from: 82.4, to: 87, seconds: 1.05, delay: 0.15, attack: 0.5, gain: 0.26, filter: { type: "lowpass", from: 320, to: 1000 } },
{ type: "noise", seconds: 0.3, delay: 0.85, attack: 0.2, gain: 0.08, filter: { type: "highpass", from: 2500, to: 5500 } },
],
},
// A horror stinger: a minor chord stabbed on low saws, the fight on.
ghoulStinger: {
layers: [
@@ -0,0 +1,811 @@
// Plan2Code Web Console - Ghoul Rush's intro story, drawn: eight animated scenes (a lonely road, the house on its hill, the hunger, the long arms, the world inside the windows, why YOU, no way back, The Long Hall as the game draws it) in canvas shapes, with the page's heading, its lines typing out, the hints and the skip bar over them.
//
// ghoul-draw.js plugs it in, the way it plugs in ghoul-intro-draw.js:
// storyArt(d) takes its drawing helpers (`d`: label, GOLD, BONE, LOOKS) and hands back
// `(ctx, v)`, drawn over the whole field while `round.phase === "story"` (also
// while paused). `round.story.ms` is the page's clock (it stops with the game,
// so a pause holds every animation). The words, colors and sounds live in
// ghoul-story.js. Field units (96 by 54), y counted down from the field's top;
// a scene gets the top SCENE_H units, the words the band below. No gradients
// (the tests' fake canvas has none): bands of flat color and alpha instead.
import { INTROS } from "./ghoul-intros.js";
import { dot, faint, flame, poly, rnd, stroke, titleLayout, dropAt } from "./ghoul-intro-draw.js";
import { CHAR_MS, FINALE_TITLE, LAST_HINT, PAGES, SKIP_HINT, REVEAL_AT_MS, SKIP_HOLD_MS, STORY_HINT, lineAt, ready, revealEnd, shown, typed } from "./ghoul-story.js";
export const SCENE_H = 33;
export const TEXT_SIZE = 2.3;
const TAU = Math.PI * 2;
const W = 96;
const H = 54;
const clamp = (x, lo = 0, hi = 1) => Math.max(lo, Math.min(hi, x));
// Eases 0..1 in and out.
const smooth = (x) => {
const k = clamp(x);
return k * k * (3 - 2 * k);
};
const rect = (ctx, x, y, w, h, fill) => {
ctx.fillStyle = fill;
ctx.fillRect(x, y, w, h);
};
const circle = (ctx, x, y, r, fill) => dot(ctx, x, y, r, fill);
const star = (ctx, cx, cy, R, r, fill, rot = 0) => {
const pts = [];
for (let i = 0; i < 10; i++) {
const a = rot - Math.PI / 2 + (i * Math.PI) / 5;
const rad = i % 2 ? r : R;
pts.push([cx + Math.cos(a) * rad, cy + Math.sin(a) * rad]);
}
poly(ctx, pts, fill);
};
// A flicker for light number `i`: mostly on, now and then guttering.
const flick = (i, t) => clamp(0.65 + 0.35 * Math.sin(t / (150 + (i % 5) * 41) + i * 1.9) + 0.2 * Math.sin(t / 53 + i), 0.15, 1);
/* ------------------------------------------------------- shared pieces */
// A sky of flat bands: the page's sky color, lighter toward the horizon.
function sky(ctx, pal, to = SCENE_H) {
rect(ctx, 0, 0, W, to, pal.sky);
for (let i = 0; i < 6; i++) faint(ctx, 0.05, () => rect(ctx, 0, to - (i + 1) * (to / 7), W, to / 7, pal.glow));
}
function stars(ctx, t, n, maxY, color = "#ffffff") {
for (let i = 0; i < n; i++) faint(ctx, 0.3 + 0.7 * (0.5 + 0.5 * Math.sin(t / (300 + rnd(i, 4) * 500) + i)), () => dot(ctx, rnd(i) * W, rnd(i, 1) * maxY, 0.14 + rnd(i, 2) * 0.16, color));
}
function moon(ctx, x, y, r, color, t) {
for (let i = 3; i >= 1; i--) faint(ctx, 0.05 + 0.01 * Math.sin(t / 700), () => circle(ctx, x, y, r * (1 + i * 0.5), color));
circle(ctx, x, y, r, color);
faint(ctx, 0.18, () => {
circle(ctx, x - r * 0.3, y - r * 0.2, r * 0.22, "#8a93b8");
circle(ctx, x + r * 0.35, y + r * 0.3, r * 0.15, "#8a93b8");
circle(ctx, x + r * 0.1, y - r * 0.5, r * 0.12, "#8a93b8");
});
}
// A rolling hill line filled down to `to`, scrolled by `off` units.
function hills(ctx, base, amp, color, off, seed, to = SCENE_H) {
const pts = [[0, to]];
for (let x = 0; x <= W + 2; x += 2) pts.push([x, base - amp * (0.6 * Math.sin((x + off) * 0.07 + seed) + 0.4 * Math.sin((x + off) * 0.17 + seed * 2))]);
pts.push([W + 2, to]);
poly(ctx, pts, color);
}
// A dead tree, trunk at (x, y), `h` tall, three bare limbs.
function tree(ctx, x, y, h, color, sway = 0) {
const limb = (x1, y1, x2, y2, w) => stroke(ctx, x1, y1, x2, y2, color, w);
limb(x, y, x + sway * 0.2, y - h, h * 0.07);
limb(x + sway * 0.2, y - h * 0.55, x - h * 0.3 + sway * 0.4, y - h * 0.85, h * 0.04);
limb(x + sway * 0.2, y - h * 0.7, x + h * 0.32 + sway * 0.5, y - h * 0.98, h * 0.04);
limb(x + sway * 0.2, y - h * 0.9, x + h * 0.08 + sway, y - h * 1.15, h * 0.03);
}
// Drifting banks of fog.
function fog(ctx, t, y, color, alpha, speed = 0.01, n = 5) {
for (let i = 0; i < n; i++) {
faint(ctx, alpha, () => {
ctx.beginPath();
ctx.ellipse((((t * speed * 1000) / 1000 + i * (W / n + 7)) % (W + 40)) - 20, y + (i % 2) * 1.2, 15, 1.8, 0, 0, TAU);
ctx.fillStyle = color;
ctx.fill();
});
}
}
function lightning(ctx, t, times, S = SCENE_H) {
let a = 0;
for (const at of times) {
const d = t - at;
if (d >= 0 && d < 420) a = Math.max(a, d < 60 ? 1 : d < 160 ? 0.3 : d < 220 ? 0.8 : 0.9 * (1 - (d - 220) / 200));
}
if (a > 0) faint(ctx, a * 0.55, () => rect(ctx, 0, 0, W, S, "#e6ecff"));
return a;
}
// A house in silhouette, its feet at (x, y), `s` times its size (about 34 units wide, 25 tall at s 1: a turret on the left, the main roof, a wing on the right, a chimney). It stands on a stone foundation course along its whole width; draw a hill (knoll) over its feet afterward so no part of the base hangs in the air. `o`: t, body color, win(i) -> { c, a } for each of ten windows, mouth (the door a gaping mouth, 0..1 open).
const WINS = [[-14, -14], [-14, -9], [-8.5, -9], [-5, -9], [3.5, -9], [7, -9], [-8.5, -4.6], [7, -4.6], [11.5, -5.4], [-1, -15.2]];
// The main roof's height over x (house units, x from -11 to 11): the chimney stands on this.
const roofAt = (dx) => -19.5 + (Math.abs(dx) / 11) * 8.5;
function house(ctx, x, y, s, o = {}) {
const t = o.t || 0;
const body = o.body || "#0c0815";
const rr = (dx, dy, w, h, c) => rect(ctx, x + dx * s, y + dy * s, w * s, h * s, c);
const tri = (pts, c) => poly(ctx, pts.map(([px, py]) => [x + px * s, y + py * s]), c);
rr(-15, -17, 5, 17, body);
tri([[-16, -17], [-12.5, -25], [-9, -17]], body);
rr(10, -8, 7, 8, body);
tri([[9, -8], [13.5, -13.5], [18, -8]], body);
rr(-10, -11, 20, 11, body);
tri([[-11, -11], [0, -19.5], [11, -11]], body);
// The chimney runs down INTO the roof: past the slope at both its sides, to the eaves.
const cx0 = 4.8;
const cx1 = 7.2;
rr(cx0, -22, cx1 - cx0, Math.max(roofAt(cx0), roofAt(cx1)) + 22 + 1.5, body);
rr(cx0 - 0.4, -22.5, cx1 - cx0 + 0.8, 0.8, body);
rr(-11.5, -17.2, 9, 0.4, "#1a1228");
// The stone foundation course, wall to wall, with its blocks.
const stone = o.stone || "#1b1530";
rr(-16.5, -1.5, 35, 1.5, stone);
rr(-16.5, -1.5, 35, 0.2, "#2a2146");
for (let k = -16.5; k < 18.5; k += 2.4) rr(k + ((Math.round(k) % 2) ? 0.6 : 0), -1.5, 0.14, 1.5, body);
rr(-16.5, -0.75, 35, 0.12, body);
WINS.forEach(([dx, dy], i) => {
const w = o.win ? o.win(i) : { c: "#ffd27a", a: flick(i, t) };
if (!w || !(w.a > 0)) {
rr(dx, dy, 2, 2.6, "#05030a");
return;
}
faint(ctx, w.a * 0.12, () => rr(dx - 0.6, dy - 0.6, 3.2, 3.8, w.c));
faint(ctx, w.a, () => rr(dx, dy, 2, 2.6, w.c));
rr(dx + 0.9, dy, 0.2, 2.6, body);
rr(dx, dy + 1.2, 2, 0.2, body);
});
// The door: an arch, or a mouth.
const open = o.mouth || 0;
rr(-1.7, -4.8 - open * 0.8, 3.4, 4.8 + open * 0.8, o.mouth !== undefined ? "#2a0508" : "#050308");
circle(ctx, x, y - 4.8 * s - open * 0.8 * s, 1.7 * s, o.mouth !== undefined ? "#2a0508" : "#050308");
if (o.mouth !== undefined) {
faint(ctx, 0.5 + 0.3 * Math.sin(t / 200), () => rr(-1.2, -3.2, 2.4, 2.8, "#ff3b30"));
for (let i = 0; i < 4; i++) {
tri([[-1.6 + i * 0.85, -4.9 - open * 0.8], [-1.2 + i * 0.85, -3.7 - open * 0.8 * 0.4], [-0.8 + i * 0.85, -4.9 - open * 0.8]], "#efe6cf");
tri([[-1.6 + i * 0.85, 0], [-1.2 + i * 0.85, -1.2 - open * 0.3], [-0.8 + i * 0.85, 0]], "#efe6cf");
}
}
}
// The little hero, facing right, feet at (x, y), `s` times its size (4.4 units tall at s 1): a box, a star for an eye, stick arms and two small feet, a flashlight in one hand. `o`: t, walk, lit (the beam's alpha, for a glow at the lens), cheer.
function hero(ctx, x, y, s, face, o = {}) {
const t = o.t || 0;
const stepA = o.walk ? Math.sin(t / 110) : 0;
const bob = o.walk ? Math.abs(stepA) * 0.28 : 0;
ctx.save();
ctx.translate(x, y - bob * s);
ctx.scale(s * face, s);
ctx.lineCap = "round";
ctx.strokeStyle = "#cfc4a6";
ctx.lineWidth = 0.32;
for (const k of [-1, 1]) {
const fx = k * 0.75 + (o.walk ? stepA * 0.7 * k : 0);
stroke(ctx, k * 0.6, -1.2, fx, -0.2, "#cfc4a6", 0.32);
ctx.beginPath();
ctx.ellipse(fx + 0.15, -0.18, 0.6, 0.32, 0, 0, TAU);
ctx.fillStyle = "#cfc4a6";
ctx.fill();
}
// The free arm behind, then the box.
stroke(ctx, -1.6, -2.7, -2.2 - (o.cheer ? 0.4 : 0), o.cheer ? -5.2 : -1.6 + (o.walk ? stepA * 0.5 : 0), "#cfc4a6", 0.32);
rect(ctx, -1.6, -4.4, 3.2, 3.2, "#1e2838");
ctx.strokeStyle = "#cfc4a6";
ctx.lineWidth = 0.22;
ctx.strokeRect(-1.6, -4.4, 3.2, 3.2);
star(ctx, 0.15, -3.6, 0.95, 0.4, "#ffd24a", o.t ? Math.sin(t / 900) * 0.15 : 0);
ctx.beginPath();
ctx.arc(0.15, -2.55, 0.45, 0.15 * Math.PI, 0.85 * Math.PI);
ctx.lineWidth = 0.18;
ctx.strokeStyle = "#cfc4a6";
ctx.stroke();
// The flashlight, held out level.
stroke(ctx, 1.6, -2.6, 2.5, -2.25, "#cfc4a6", 0.32);
rect(ctx, 2.3, -2.6, 1.6, 0.7, "#4a4f5a");
rect(ctx, 3.7, -2.75, 0.4, 1, "#c9ced6");
ctx.lineCap = "butt";
ctx.restore();
if (o.lit > 0) faint(ctx, o.lit * 0.9, () => circle(ctx, x + face * 4.1 * s, y - 2.25 * s - bob * s, 0.7 * s, "#fffbe0"));
return { x: x + face * 4.2 * s, y: y - 2.25 * s - bob * s };
}
// A cone of light from `from` out `len` units, `spread` wide at the far end.
function beam(ctx, from, len, spread, alpha, color = "#fff3b0", tilt = 0) {
if (!(alpha > 0)) return;
for (let i = 0; i < 3; i++) {
const sp = spread * (1 - i * 0.3);
faint(ctx, alpha * (0.12 + i * 0.06), () => poly(ctx, [[from.x, from.y - 0.3], [from.x + len, from.y + tilt - sp], [from.x + len, from.y + tilt + sp], [from.x, from.y + 0.3]], color));
}
}
// A mix of two #rrggbb colors, `k` of the way from a to b.
const mix = (a, b, k) => {
const pa = [1, 3, 5].map((i) => parseInt(a.slice(i, i + 2), 16));
const pb = [1, 3, 5].map((i) => parseInt(b.slice(i, i + 2), 16));
return `rgb(${pa.map((v, i) => Math.round(v + (pb[i] - v) * k)).join(",")})`;
};
const ell = (ctx, x, y, rx, ry, fill) => {
ctx.beginPath();
ctx.ellipse(x, y, rx, ry, 0, 0, TAU);
ctx.fillStyle = fill;
ctx.fill();
};
// An arch: a door or window, its feet at y + h, a half circle on top.
function archPath(ctx, x, y, w, h) {
ctx.beginPath();
ctx.moveTo(x, y + h);
ctx.lineTo(x, y + w / 2);
ctx.arc(x + w / 2, y + w / 2, w / 2, Math.PI, 0);
ctx.lineTo(x + w, y + h);
ctx.closePath();
}
function arch(ctx, x, y, w, h, fill) {
archPath(ctx, x, y, w, h);
ctx.fillStyle = fill;
ctx.fill();
}
// A shambling dark shape, feet at (x, y): head, hunched body, arms out in front (toward the left), `a` its alpha.
function ghoulShape(ctx, x, y, s, t, i, a = 1) {
const c = "#060409";
const lurch = Math.sin(t / 380 + i * 1.7);
faint(ctx, a, () => {
stroke(ctx, x - 0.5 * s, y - 2.2 * s, x - 0.9 * s + lurch * 0.3, y, c, 0.6 * s);
stroke(ctx, x + 0.5 * s, y - 2.2 * s, x + 0.9 * s - lurch * 0.3, y, c, 0.6 * s);
poly(ctx, [[x - 1.3 * s, y - 2.4 * s], [x + 1.4 * s, y - 2.4 * s], [x + 1 * s, y - 4.3 * s], [x - 1 * s, y - 4.3 * s]], c);
stroke(ctx, x - 0.8 * s, y - 3.8 * s, x - 3.2 * s, y - 3.5 * s + lurch * 0.3, c, 0.45 * s);
stroke(ctx, x - 0.6 * s, y - 3.4 * s, x - 3 * s, y - 2.9 * s - lurch * 0.3, c, 0.45 * s);
circle(ctx, x - 0.2 * s, y - 4.7 * s, 0.95 * s, c);
});
}
// A hill's top: flat under the whole of what stands on it (`flat` each side of cx, at height y), then rounded shoulders easing down `depth` over `slope` units to the ground behind. Draw it AFTER the house so the base is set into it.
function knoll(ctx, cx, y, flat, slope, depth, color, to = SCENE_H) {
const x0 = cx - flat - slope;
const x1 = cx + flat + slope;
const pts = [[x0, to]];
for (let x = x0; x < x1 + 0.5; x += 1) pts.push([Math.min(x, x1), y + depth * smooth((Math.abs(Math.min(x, x1) - cx) - flat) / slope)]);
pts.push([x1, to]);
poly(ctx, pts, color);
}
// Grass tufts along a crest.
function tufts(ctx, x0, x1, y, color, t = 0) {
for (let x = x0; x < x1; x += 1.7) stroke(ctx, x, y + 0.2, x + 0.3 + Math.sin(t / 400 + x) * 0.3, y - 0.8 - rnd(x) * 0.5, color, 0.18);
}
// The three little places seen through the house's windows (each drawn inside its window's clip: `x`, `y` the window's top left, `w` by `h`).
function lakeInside(ctx, x, y, w, h, t) {
rect(ctx, x, y, w, h, "#0e1a30");
for (let i = 0; i < 9; i++) faint(ctx, 0.4 + 0.5 * Math.sin(t / 500 + i), () => dot(ctx, x + rnd(i, 3) * w, y + 1 + rnd(i, 4) * 6, 0.17, "#ffffff"));
poly(ctx, [[x, y + 11], [x + 5, y + 8.6], [x + 11, y + 10.8], [x + 17, y + 8.8], [x + w, y + 10.5], [x + w, y + h], [x, y + h]], "#0a1020");
for (const [px, ph] of [[3, 5], [6.5, 4], [18, 5.2], [20.5, 3.6]]) poly(ctx, [[x + px - 1.1, y + 11.6], [x + px, y + 11.6 - ph], [x + px + 1.1, y + 11.6]], "#050a14");
ell(ctx, x + w / 2, y + h - 3.6, w * 0.55, 2.9, "#bae6fd");
stroke(ctx, x + 4, y + h - 3.6, x + 10, y + h - 4.4, "#e0f2fe", 0.15);
stroke(ctx, x + 10, y + h - 4.4, x + 16, y + h - 3, "#e0f2fe", 0.15);
const rise = 0.65 + 0.35 * Math.sin(t / 900);
stroke(ctx, x + 14.5, y + h - 3.8, x + 14.5, y + h - 3.8 - 3 * rise, "#8fb7d1", 0.4);
for (let i = -1; i <= 1; i++) stroke(ctx, x + 14.5 + i * 0.4, y + h - 6.8 * rise - 0.8 + 3 * (1 - rise) * 0.2, x + 14.5 + i * 0.6, y + h - 7.8 * rise, "#8fb7d1", 0.2);
}
function wheelInside(ctx, x, y, w, h, t) {
rect(ctx, x, y, w, h, "#241628");
for (let i = 0; i < 6; i++) rect(ctx, x + i * 4 + 1, y, 1.4, h, "#2f1d34");
const cx = x + w / 2;
const cy = y + h - 7.2;
const r = 6.3;
ctx.beginPath();
ctx.arc(cx, cy, r, 0, TAU);
ctx.strokeStyle = "#f472b6";
ctx.lineWidth = 0.3;
ctx.stroke();
for (let i = 0; i < 8; i++) {
const a = t / 2200 + (i * TAU) / 8;
const gx = cx + Math.cos(a) * r;
const gy = cy + Math.sin(a) * r;
stroke(ctx, cx, cy, gx, gy, "#c04a8a", 0.18);
circle(ctx, gx, gy + 0.5, 0.65, i % 2 ? "#fde047" : "#fb7185");
}
for (let i = 0; i < 16; i++) faint(ctx, 0.5 + 0.5 * Math.sin(t / 220 + i), () => dot(ctx, cx + Math.cos((i * TAU) / 16) * r, cy + Math.sin((i * TAU) / 16) * r, 0.2, "#fff1c4"));
stroke(ctx, cx - 2.6, y + h - 2.2, cx, cy, "#6a3a60", 0.35);
stroke(ctx, cx + 2.6, y + h - 2.2, cx, cy, "#6a3a60", 0.35);
circle(ctx, cx, cy, 0.7, "#fbcfe8");
}
function villageInside(ctx, x, y, w, h, t) {
rect(ctx, x, y, w, h, "#10142e");
circle(ctx, x + 16, y + 4.5, 1.7, "#f3e9c0");
for (let i = 0; i < 6; i++) faint(ctx, 0.5 + 0.4 * Math.sin(t / 450 + i), () => dot(ctx, x + rnd(i, 7) * 12 + 1, y + 1 + rnd(i, 8) * 5, 0.16, "#ffffff"));
poly(ctx, [[x, y + 12], [x + 8, y + 9.6], [x + 15, y + 11.4], [x + w, y + 10], [x + w, y + h], [x, y + h]], "#0a0d22");
for (let i = 0; i < 4; i++) {
const hx = x + 2 + i * 5;
const hh = 3.2 + (i % 2) * 1.2;
rect(ctx, hx, y + h - 2.2 - hh, 3.4, hh, "#2e2a66");
poly(ctx, [[hx - 0.4, y + h - 2.2 - hh], [hx + 1.7, y + h - 2.2 - hh - 1.7], [hx + 3.8, y + h - 2.2 - hh]], "#1d1a4a");
rect(ctx, hx + 1.1, y + h - 2.2 - hh + 0.9, 1.2, 1.2, Math.sin(t / 700 + i * 2) > -0.4 ? "#ffd27a" : "#0b0a22");
}
}
/* ------------------------------------------------------------- scenes */
const SCENES = {
// I. A lonely road at night: parallax hills and trees, a moon, a house far off with one winking window, eyes in the bushes, YOU walking with the flashlight.
road(ctx, p) {
const { t, pal } = p;
sky(ctx, pal);
stars(ctx, t, 46, 19);
moon(ctx, 76, 9, 4.6, "#dfe9ff", t);
hills(ctx, 21, 2.4, "#0e1838", 0, 1);
// The house on the far hill, one window winking.
house(ctx, 70, 19.6, 0.28, { t, body: "#080b1c", stone: "#12183a", win: (i) => (i === 3 ? { c: "#ffd27a", a: Math.sin(t / 800) > -0.3 ? 0.9 : 0 } : null) });
// Its ridge: a hilltop flat under the whole house, so its base is set into the land.
knoll(ctx, 70.2, 19.6, 6, 34, 12, "#060a16");
tufts(ctx, 64, 77, 19.6, "#080b1c", t);
hills(ctx, 25, 3, "#0a1028", t * 0.006, 3);
for (let i = 0; i < 4; i++) tree(ctx, ((i * 31 - t * 0.012) % (W + 24) + (W + 24)) % (W + 24) - 8, 28, 9 + (i % 2) * 3, "#05060f", Math.sin(t / 500 + i) * 1.4);
fog(ctx, t, 27.3, "#8da4e0", 0.1, 0.012);
rect(ctx, 0, 28, W, SCENE_H - 28, pal.ground);
rect(ctx, 0, 28.4, W, 2.6, "#171c36");
// The road runs on from here up the land to the house on its ridge.
poly(ctx, [[45, 28.6], [56, 28.6], [70.9, 19.8], [69.5, 19.8]], "#1d2342");
for (let i = 0; i < 9; i++) rect(ctx, (((i * 13 - t * 0.02) % (W + 14)) + W + 14) % (W + 14) - 6, 29.5, 5, 0.4, "#2b3358");
// Fence posts racing past, and grass bending in the wind.
for (let i = 0; i < 6; i++) {
const x = (((i * 19 - t * 0.03) % (W + 19)) + W + 19) % (W + 19) - 4;
rect(ctx, x, 30.2, 0.7, 3, "#03040a");
}
for (let i = 0; i < 40; i++) stroke(ctx, i * 2.4 + 0.5, 33, i * 2.4 + 0.5 + Math.sin(t / 300 + i * 0.8) * 0.9 + 0.6, 31.2, "#03040a", 0.2);
// Two eyes in the dark that open, then close.
const blink = (t % 5200) / 5200;
if (blink > 0.35 && blink < 0.8 && blink % 0.18 > 0.02) {
circle(ctx, 62, 26.2, 0.32, "#ffe14a");
circle(ctx, 63.6, 26.2, 0.32, "#ffe14a");
}
const lens = hero(ctx, 24, 30.2, 1.15, 1, { t, walk: true });
beam(ctx, lens, 24, 3.4, 0.7 + 0.1 * Math.sin(t / 90));
},
// II. The house on the hill: lightning, flickering windows, bats, clouds over the moon, a pale shape in the tower, a slow push-in.
house(ctx, p) {
const { t, pal } = p;
sky(ctx, pal);
stars(ctx, t, 30, 14);
moon(ctx, 18, 8, 4.2, "#e8dcff", t);
for (let i = 0; i < 4; i++) {
faint(ctx, 0.85, () => {
ctx.beginPath();
ctx.ellipse((((t / 120 + i * 29) % (W + 40)) - 20), 7 + (i % 2) * 5, 14, 2.4, 0, 0, TAU);
ctx.fillStyle = "#120a26";
ctx.fill();
});
}
const k = 1 + t / 60000;
ctx.save();
ctx.translate(60, 22);
ctx.scale(k, k);
ctx.translate(-60, -22);
hills(ctx, 31, 0, "#0a0614", 0, 0);
const lit = (i) => {
if (i === 0 && t > 3800 && t < 5600) return { c: "#e8f2ff", a: 0.95 };
return { c: "#ffc15a", a: flick(i, t) };
};
house(ctx, 60, 22, 1.05, { t, win: lit });
// The hill: a wide dome flat under the whole house (turret to wing), set over its foundation.
knoll(ctx, 61, 22, 19.5, 22, 9, "#07040d");
tufts(ctx, 41, 81, 22, "#030207", t);
// A pale shape in the tower window, a while in.
if (t > 3800 && t < 5600) {
rect(ctx, 60 - 14 * 1.05 + 0.5, 22 - 14 * 1.05 + 1, 0.9, 1.5, "#04030a");
circle(ctx, 60 - 14 * 1.05 + 0.95, 22 - 14 * 1.05 + 0.9, 0.4, "#04030a");
}
// The fence in front.
for (let x = 30; x < 92; x += 2.2) {
rect(ctx, x, 27.5, 0.35, 5, "#030207");
poly(ctx, [[x - 0.3, 27.5], [x + 0.18, 26.2], [x + 0.65, 27.5]], "#030207");
}
rect(ctx, 30, 29, 62, 0.3, "#030207");
ctx.restore();
// Bats, and clouds sliding over the moon.
for (let i = 0; i < 4; i++) {
const x = ((t / 22 + i * 29) % (W + 20)) - 10;
const y = 6 + i * 4 + Math.sin(t / 380 + i) * 2;
const f = Math.sin(t / 70 + i) * 1.4;
poly(ctx, [[x, y], [x - 2.6, y - 1.3 + f], [x - 1.2, y + 0.4], [x, y + 0.7], [x + 1.2, y + 0.4], [x + 2.6, y - 1.3 + f]], "#04030a");
}
lightning(ctx, t, [150, 3100]);
},
// III. The hunger: the house's door is a mouth; small frightened figures walk toward it and their fright streams in as light.
hunger(ctx, p) {
const { t, pal } = p;
sky(ctx, pal);
const beat = Math.max(0, Math.sin(t / 380)) ** 6;
faint(ctx, 0.12 + 0.18 * beat, () => rect(ctx, 0, 0, W, SCENE_H, "#7f1d1d"));
rect(ctx, 0, 29, W, SCENE_H - 29, pal.ground);
house(ctx, 66, 29.5, 1.05, { t, mouth: 0.5 + 0.5 * Math.sin(t / 650), win: (i) => ({ c: "#ff2d2d", a: 0.5 + 0.5 * flick(i, t) }) });
// The chimney glows with each swallow.
faint(ctx, 0.3 + 0.7 * beat, () => circle(ctx, 66 + 6 * 1.05, 29.5 - 21 * 1.05, 2, "#ff5a36"));
// Little figures with their arms up, each shedding fright that flies to the mouth.
for (let i = 0; i < 4; i++) {
const fx = 8 + i * 9;
const fy = 29.5;
const sway = Math.sin(t / 240 + i * 2) * 0.4;
stroke(ctx, fx, fy - 1.2, fx + sway, fy - 3, "#d8cfe8", 0.35);
stroke(ctx, fx + sway, fy - 2.6, fx + sway - 1, fy - 3.8, "#d8cfe8", 0.25);
stroke(ctx, fx + sway, fy - 2.6, fx + sway + 1, fy - 3.8, "#d8cfe8", 0.25);
stroke(ctx, fx, fy - 1.2, fx - 0.5, fy, "#d8cfe8", 0.25);
stroke(ctx, fx, fy - 1.2, fx + 0.5, fy, "#d8cfe8", 0.25);
circle(ctx, fx + sway, fy - 3.7, 0.8, "#d8cfe8");
circle(ctx, fx + sway, fy - 3.6, 0.28, "#2a0508");
for (let j = 0; j < 6; j++) {
const q = ((t / 1800 + j / 6 + i * 0.13) % 1);
const x0 = fx + sway;
const y0 = fy - 3.7;
const x1 = 66;
const y1 = 29.5 - 2.4;
const cx = (x0 + x1) / 2;
const cy = Math.min(y0, y1) - 9 - i;
const mx = (1 - q) * (1 - q) * x0 + 2 * (1 - q) * q * cx + q * q * x1;
const my = (1 - q) * (1 - q) * y0 + 2 * (1 - q) * q * cy + q * q * y1;
faint(ctx, Math.sin(q * Math.PI), () => circle(ctx, mx, my, 0.45 - q * 0.2, "#fecaca"));
}
}
fog(ctx, t, 29, "#7f1d1d", 0.18, 0.008, 4);
ctx.globalAlpha = 1;
},
// IV. A house with long arms: the house on its hill, its windows waking, its shadow stretching across the ground and long dark arms reaching out of it to both edges; things it swallowed ride the arms back in.
arms(ctx, p) {
const { t, pal, line, full, grow } = p;
sky(ctx, pal);
stars(ctx, t, 24, 12);
moon(ctx, 86, 7, 2.8, "#cfe9dc", t);
hills(ctx, 27.5, 1.2, "#07140f", 0, 6);
rect(ctx, 0, 29, W, SCENE_H - 29, "#0d251c");
const on = (n) => full || line >= n;
const wake = grow(0, 900);
const reach = 0.1 + 0.9 * grow(1, 1700);
// The shadow: the house's, thrown a long way across the ground.
const len = 6 + 40 * grow(1, 1700);
faint(ctx, 0.8, () => poly(ctx, [[38, 29.2], [38 - len, 31.4], [38 - len * 0.92, 32.2], [46, 33]], "#020604"));
// The house on its hill, its windows eyes, its door a mouth.
house(ctx, 48, 28, 0.85, { t, mouth: 0.15 + 0.5 * wake * (0.5 + 0.5 * Math.sin(t / 600)), win: (i) => ({ c: pal.glow, a: 0.12 + wake * (0.3 + 0.5 * flick(i, t)) }) });
knoll(ctx, 48.5, 28, 16, 14, 1, "#0d251c");
tufts(ctx, 33, 65, 28, "#030a07", t);
// One arm: a quadratic curve out of the house, tapering to a hooked hand; returns where a point `q` along it is.
const arm = (x0, y0, cx, cy, x1, y1, seed) => {
const at = (q) => {
const k = q * reach;
const wob = Math.sin(t / 520 + seed * 2 + q * 5) * 0.6 * q;
return [(1 - k) * (1 - k) * x0 + 2 * (1 - k) * k * cx + k * k * x1 + wob * 0.4, (1 - k) * (1 - k) * y0 + 2 * (1 - k) * k * cy + k * k * y1 + wob];
};
ctx.lineCap = "round";
let prev = at(0);
for (let i = 1; i <= 16; i++) {
const cur = at(i / 16);
const w = 1.1 * (1 - (i / 16) * 0.75) + 0.2;
faint(ctx, 0.35, () => stroke(ctx, prev[0], prev[1], cur[0], cur[1], pal.glow, w + 0.25));
prev = cur;
}
faint(ctx, 1, () => {
let a = at(0);
for (let i = 1; i <= 16; i++) {
const b = at(i / 16);
stroke(ctx, a[0], a[1], b[0], b[1], "#030a06", 1.2 * (1 - (i / 16) * 0.75) + 0.25);
a = b;
}
});
const end = at(1);
const dir = x1 < x0 ? -1 : 1;
for (let f = -1; f <= 1; f++) stroke(ctx, end[0], end[1], end[0] + dir * 1.3, end[1] + f * 0.9 + Math.sin(t / 300 + f) * 0.2, "#041009", 0.25);
ctx.lineCap = "butt";
return at;
};
const arms = [
arm(41, 27, 22, 33, 3, 30, 1),
arm(40.5, 19, 21, 6, 4, 14, 2),
arm(56, 27, 76, 33, 93, 29, 3),
arm(57, 20, 78, 7, 93, 13, 4),
];
// What it has swallowed rides the arms home: small lights in the colors of other places.
if (on(2)) {
const cols = ["#bae6fd", "#f472b6", "#fde68a", "#fca5a5"];
arms.forEach((at, i) => {
for (let j = 0; j < 3; j++) {
const q = 1 - ((t / 2600 + j / 3 + i * 0.21) % 1);
const [mx, my] = at(q);
faint(ctx, Math.sin(q * Math.PI) * 0.9, () => circle(ctx, mx, my, 0.5, cols[(i + j) % 4]));
}
});
}
fog(ctx, t, 30.5, "#6ee7b7", 0.07, 0.008, 4);
},
// V. A world inside: the house's front is a wall of windows, and through each one a whole tiny place sits inside a room (a frozen lake, a ferris wheel, a village), lighting one by one.
far(ctx, p) {
const { t, pal, full, grow } = p;
sky(ctx, pal);
stars(ctx, t, 26, 6);
// The front of the house: a wall, a gable and a chimney.
const wall = "#0b0a1e";
rect(ctx, 5, 9, 86, SCENE_H - 9, wall);
poly(ctx, [[2, 9.5], [48, 0.8], [94, 9.5]], wall);
rect(ctx, 74, 1.5, 3, 6, wall);
rect(ctx, 5, 28.4, 86, 0.4, "#1a1838");
const windows = [[9, 0], [37, 1], [65, 2]];
windows.forEach(([x0, n]) => {
const lit = full ? 1 : n === 0 ? grow(1, 900) : grow(n + 1, 900);
const y0 = 11.5;
const w = 22;
const h = 16.5;
arch(ctx, x0 - 1, y0 - 1, w + 2, h + 1, "#1d1a40");
// Seen through: the room inside.
ctx.save();
archPath(ctx, x0, y0, w, h);
ctx.clip();
rect(ctx, x0, y0, w, h, "#0a0818");
if (n === 0) lakeInside(ctx, x0, y0, w, h, t);
else if (n === 1) wheelInside(ctx, x0, y0, w, h, t);
else villageInside(ctx, x0, y0, w, h, t);
// The room: a hanging bulb on its cord, boards in front and a baseboard.
stroke(ctx, x0 + w / 2, y0, x0 + w / 2, y0 + 2.6, "#0a0818", 0.15);
faint(ctx, 0.14 * flick(n * 3 + 1, t), () => circle(ctx, x0 + w / 2, y0 + 3.2, 2.4, "#ffd27a"));
circle(ctx, x0 + w / 2, y0 + 3.2, 0.5, "#fff1c4");
rect(ctx, x0, y0 + h - 2.2, w, 2.2, "#2a1c14");
rect(ctx, x0, y0 + h - 2.2, w, 0.3, "#4a3424");
for (let k = 0; k < 4; k++) rect(ctx, x0 + 2 + k * 6 + n, y0 + h - 1.9, 0.15, 1.9, "#120c08");
// Dark until its line is typed.
faint(ctx, 0.85 * (1 - lit), () => rect(ctx, x0, y0, w, h, "#06050f"));
ctx.restore();
// The frame, the sill and the cross bar.
rect(ctx, x0 - 1.5, y0 + h, w + 3, 0.9, "#1d1a40");
});
// The ground at its feet.
rect(ctx, 0, 30.4, W, SCENE_H - 30.4, pal.ground);
tufts(ctx, 3, 93, 30.4, "#030210", t);
fog(ctx, t, 31.5, "#a78bfa", 0.06, 0.008, 4);
},
// VI. Why YOU: in the dark, the house watches with dim red windows; the flashlight clicks on, the house flinches and goes dark, then winks at YOU.
why(ctx, p) {
const { t, pal } = p;
sky(ctx, pal);
stars(ctx, t, 26, 15);
const click = 1500;
const wink = 3400;
const lit = t >= click;
const since = t - click;
const shake = lit && since < 800 ? (rnd(Math.floor(t / 40)) - 0.5) * 1.4 * (1 - since / 800) : 0;
rect(ctx, 0, 29, W, SCENE_H - 29, pal.ground);
house(ctx, 73 + shake, 29.5, 1.05, {
t,
win: (i) => {
if (t < click) return { c: "#7f1d1d", a: 0.3 + 0.4 * flick(i, t) };
if (t < wink) return null;
const open = Math.floor((t - wink) / 260);
return i <= open ? { c: "#fde047", a: i === open ? 0.4 : 0.9 } : null;
},
});
const lens = hero(ctx, 18, 30.2, 1.3, 1, { t, lit: lit ? clamp(1 - since / 500, 0, 1) : 0 });
if (lit) {
const a = clamp(since / 250) * (0.8 + 0.1 * Math.sin(t / 70));
beam(ctx, lens, 38, 5.5, a);
faint(ctx, a * 0.4, () => {
ctx.beginPath();
ctx.ellipse(61 + shake, 23, 3, 8, 0, 0, TAU);
ctx.fillStyle = "#fff3b0";
ctx.fill();
});
// Flinch marks off the house's corners.
if (since < 700) for (let i = 0; i < 5; i++) stroke(ctx, 57 + i * 1.2, 14 + i * 2.2, 54 + i * 0.4 - since / 90, 12 + i * 2.2, "#fff3b0", 0.25);
}
fog(ctx, t, 30, "#8da4e0", 0.07, 0.01, 4);
if (!lit) faint(ctx, 0.25 * (1 - Math.min(1, t / 1500)), () => rect(ctx, 0, 0, W, SCENE_H, "#000"));
// The click's bloom.
if (since >= 0 && since < 200) faint(ctx, 0.35 * (1 - since / 200), () => rect(ctx, 0, 0, W, SCENE_H, "#fffbe0"));
},
// VII. No way back: the road behind YOU folds up like a napkin; a row of doors runs on ahead past the edge, each with its keeper's light under it, and they lock one by one.
trap(ctx, p) {
const { t, pal } = p;
sky(ctx, pal);
rect(ctx, 0, 7, W, 22, "#12070f");
const glows = Object.values(INTROS).map((i) => i.palette.glow);
for (let i = 0; i < 11; i++) {
const glow = glows[i % glows.length];
const x = 5 + i * 9;
const lockAt = 1400 + i * 420;
const locked = t >= lockAt;
rect(ctx, x, 13, 7, 15, "#1f0e1c");
// The keeper's light under the door, until it is locked.
if (!locked) faint(ctx, 0.55 + 0.35 * Math.sin(t / 150 + i), () => rect(ctx, x + 0.4, 26.5, 6.2, 1.5, glow));
else if (t < lockAt + 200) faint(ctx, 1 - (t - lockAt) / 200, () => rect(ctx, x + 0.4, 13.4, 6.2, 14.4, glow));
rect(ctx, x, 13, 7, 0.5, "#3a1a34");
circle(ctx, x + 3.5, 15.2, 0.6, glow);
circle(ctx, x + 5.4, 21, 0.35, "#c9ced6");
if (locked) {
const pop = clamp((t - lockAt) / 160);
rect(ctx, x + 3.4 - 1.1 * pop, 19.5, 2.2 * pop, 1.8 * pop, "#ef4444");
ctx.beginPath();
ctx.arc(x + 3.5, 19.5, 0.9 * pop, Math.PI, 0);
ctx.strokeStyle = "#c9ced6";
ctx.lineWidth = 0.3;
ctx.stroke();
}
}
rect(ctx, 0, 28, W, SCENE_H - 28, pal.ground);
// The road behind YOU, pleating up from the far end toward YOU.
const front = clamp(t / 3200) * 8;
for (let i = 0; i < 8; i++) {
const x0 = i * 5;
const fold = smooth(front - (7 - i) + 1);
const h = fold * 6;
const up = i % 2;
poly(ctx, [[x0, 31], [x0 + 5, 31], [x0 + 5, 31 - (up ? h * 0.3 : h)], [x0, 31 - (up ? h : h * 0.3)]], i % 2 ? "#2a2440" : "#1b1830");
if (fold > 0.02) faint(ctx, 0.5, () => rect(ctx, x0, 31 - (up ? h * 0.3 : h) - 0.2, 5, 0.3, "#8a7fb0"));
}
rect(ctx, 40, 29.5, W - 40, 1.6, "#1b1830");
const lens = hero(ctx, 50, 31, 1.25, 1, { t });
beam(ctx, lens, 22, 3, 0.55);
fog(ctx, t, 31, "#c084fc", 0.07, 0.01, 4);
},
// VIII. The Long Hall as the game draws it, side on: the hall's own wall colors, striped paper, arched windows, a portrait, candle sconces, the wainscot and the floor boards, the exit door at the far end; YOU at the left switch the flashlight on and its cone lights the hall, where dark shapes with glowing eyes wait; THE RUN BEGINS drops in letter by letter and the light flares.
begin(ctx, p) {
const { t, pal, look } = p;
const FY = 28;
// The wall: the hall's top and bottom colors in flat bands, and the old striped paper.
for (let i = 0; i < 10; i++) rect(ctx, 0, (i * FY) / 10, W, FY / 10 + 0.1, mix(look.wallTop, look.wallLow, i / 9));
for (let x = 0; x < W + 4; x += 4) {
const n = Math.round(x / 4);
faint(ctx, 0.3 + (n % 3) * 0.08, () => rect(ctx, x, 0, 1.6, FY - 2, look.paper));
}
// A crack, and the arched windows with the sickly moon (the game's own window).
stroke(ctx, 41, 2, 40.4, 6, "rgba(0, 0, 0, 0.5)", 0.18);
stroke(ctx, 40.4, 6, 41.2, 9, "rgba(0, 0, 0, 0.5)", 0.18);
for (const [wx, n] of [[28.5, 0], [64.5, 1]]) {
const x = wx - 3.5;
const top = 5;
const w = 7;
const h = 14;
arch(ctx, x - 0.5, top - 0.5, w + 1, h + 0.5, look.wainscot);
arch(ctx, x, top, w, h, "#05070d");
faint(ctx, 0.55, () => circle(ctx, x + w * (0.3 + n * 0.2), top + h * 0.28, w * 0.16, look.window));
faint(ctx, 0.7, () => ell(ctx, x + w * (0.25 + n * 0.2), top + h * 0.31, w * 0.22, w * 0.07, "#05070d"));
faint(ctx, 0.12, () => rect(ctx, x, top + h * 0.55, w, h * 0.45, look.window));
rect(ctx, x + w / 2 - 0.2, top + 0.5, 0.4, h - 0.5, look.wainscot);
rect(ctx, x, top + h * 0.55, w, 0.4, look.wainscot);
}
// A portrait in a tarnished frame: a long pale face with empty eyes.
rect(ctx, 44.2, 7.6, 5.6, 7.4, "#4a3a1a");
rect(ctx, 44.7, 8.1, 4.6, 6.4, "#141a14");
ell(ctx, 47, 10.8, 1.1, 1.8, "#7a7468");
ell(ctx, 46.55, 10.4, 0.25, 0.4, "#000000");
ell(ctx, 47.45, 10.4, 0.25, 0.4, "#000000");
ell(ctx, 47, 11.8, 0.25, 0.4, "#000000");
rect(ctx, 45, 12.9, 4, 1.4, "#1a1210");
// The wainscot, then the floor: its lit edge, its boards and their seams.
rect(ctx, 0, FY - 4, W, 4, look.wainscot);
rect(ctx, 0, FY - 4.25, W, 0.25, look.floorEdge);
rect(ctx, 0, FY, W, SCENE_H - FY, look.floor);
rect(ctx, 0, FY, W, 1.2, look.floorTop);
rect(ctx, 0, FY, W, 0.25, look.floorEdge);
for (let i = 0; i < 12; i++) rect(ctx, 2 + i * 8.5, FY + 0.25, 0.16, 0.95, look.floorEdge);
for (let i = 0; i < 12; i++) rect(ctx, 6 + i * 8.5, FY + 1.2, 0.16, SCENE_H - FY - 1.2, look.floorEdge);
rect(ctx, 0, FY + 2.6, W, 0.16, look.floorEdge);
// The exit at the right end: an arched door in its frame, a thin gold line round it.
arch(ctx, 82.4, FY - 15.2, 9.6, 15.2, look.shelf);
arch(ctx, 83.2, FY - 14.4, 8, 14.4, "#0e0806");
faint(ctx, 0.25 + 0.15 * Math.sin(t / 500), () => {
rect(ctx, 83.2, FY - 0.5, 8, 0.5, "#fbbf24");
rect(ctx, 86.9, FY - 14.4, 0.4, 14.4, "#fbbf24");
});
rect(ctx, 89.2, FY - 7.4, 0.5, 1.4, "#c9a24a");
// Candle sconces, the candle burned low, a warm pool on the wall.
[18, 38, 55, 76].forEach((sx, i) => {
const f = flick(i + 2, t);
faint(ctx, 0.035 * f, () => circle(ctx, sx, 11.5, 7, "#ffb84a"));
faint(ctx, 0.05 * f, () => circle(ctx, sx, 11.5, 3.4, "#ffb84a"));
rect(ctx, sx - 0.3, 12, 0.6, 2.4, "#3a2e16");
rect(ctx, sx - 0.45, 10.6, 0.9, 1.5, "#b8ae94");
flame(ctx, sx, 10.6, 1.7, t, sx, "#ffb84a");
});
// The far end of the hall sinks into the dark.
for (let i = 0; i < 8; i++) faint(ctx, 0.07, () => rect(ctx, 50 + i * 6, 0, W - 50 - i * 6, SCENE_H, "#050308"));
// YOU click the flashlight on at the left and its cone lights the hall.
const clickAt = 450;
const lit = smooth((t - clickAt) / 260);
const lens = hero(ctx, 10, FY + 1.3, 1.3, 1, { t, lit: t >= clickAt ? clamp(1 - (t - clickAt) / 500) : 0 });
beam(ctx, lens, 78, 6.4, lit * (0.8 + 0.08 * Math.sin(t / 80)), "#fff3b0", 0.4);
if (t >= clickAt && t < clickAt + 200) faint(ctx, 0.25 * (1 - (t - clickAt) / 200), () => rect(ctx, 0, 0, W, SCENE_H, "#fffbe0"));
// Dark shapes far down the hall, their eyes opening one by one.
[[55, 1.15, "#ff3b30"], [66, 1.05, "#ffe14a"], [75, 1.2, "#ff3b30"]].forEach(([mx, ms, eye], i) => {
const sway = Math.sin(t / 700 + i * 2) * 0.9;
const open = smooth((t - 1200 - i * 600) / 400);
ghoulShape(ctx, mx + sway, FY + 1.1, ms, t, i, i === 2 ? 0.55 : 1);
if (open > 0) {
const bx = mx + sway - 0.2 * ms;
const by = FY + 1.1 - 4.6 * ms;
faint(ctx, open * 0.35, () => {
circle(ctx, bx - 0.5 * ms, by, 0.55 * ms, eye);
circle(ctx, bx + 0.5 * ms, by, 0.55 * ms, eye);
});
faint(ctx, open, () => {
circle(ctx, bx - 0.5 * ms, by, 0.28 * ms, eye);
circle(ctx, bx + 0.5 * ms, by, 0.28 * ms, eye);
});
}
});
// The title, on a dark band so it reads over the windows.
faint(ctx, 0.6 * smooth((t - 2800) / 400), () => rect(ctx, 0, 3.4, W, 13, "#050308"));
const { size, xs } = titleLayout(FINALE_TITLE, 88);
const chars = [...FINALE_TITLE];
const base = 3000;
for (let i = 0; i < chars.length; i++) {
if (chars[i] === " ") continue;
const at = t - base - i * 70;
const fall = dropAt(at);
p.label(ctx, chars[i], 48 + xs[i] + 0.3, 9.8 - fall * 15 + 0.5, size * 0.95, "rgba(0, 0, 0, 0.7)", "center");
const landed = at >= 520;
if (at > -40) {
if (landed) faint(ctx, 0.25 + 0.2 * Math.sin(t / 280 - i * 0.5), () => p.label(ctx, chars[i], 48 + xs[i], 9.8, size * 1.1, pal.glow, "center"));
p.label(ctx, chars[i], 48 + xs[i], 9.8 - fall * 15 + (landed ? Math.sin(t / 260 - i * 0.6) * size * 0.04 : 0), size * 0.95, i % 2 ? "#fbbf24" : "#fff3c4", "center");
}
}
// The flare as the last stinger lands.
const flare = t - 3900;
if (flare >= 0 && flare < 700) faint(ctx, 0.55 * (1 - flare / 700), () => rect(ctx, 0, 0, W, SCENE_H, "#fff3c4"));
},
};
/* --------------------------------------------------------------- the page */
// The width of `text` as the label helper sets it (it must have just set the font), or a guess where a canvas cannot measure.
const widthOf = (ctx, text, size) => {
const m = typeof ctx.measureText === "function" ? ctx.measureText(text) : null;
return m && typeof m.width === "number" ? m.width : text.length * size * 0.58;
};
export function storyArt(d) {
const { label, GOLD, BONE, LOOKS } = d;
return function storyPage(ctx, v) {
const { round } = v;
const s = round.story;
if (!s) return;
const pg = PAGES[s.page];
const t = s.ms;
const n = shown(pg, t, s.full);
const line = lineAt(pg, n);
const done = n >= pg.lines.reduce((c, l) => c + l.length, 0);
ctx.save();
ctx.globalAlpha = 1;
rect(ctx, 0, 0, W, H, "#050308");
// The scene, clipped to its top.
ctx.save();
ctx.beginPath();
ctx.rect(0, 0, W, SCENE_H);
ctx.clip();
// grow(n, ms): 0 to 1 over ms from when line n starts typing (1 once the page is typed out).
const startOf = (i) => REVEAL_AT_MS + pg.lines.slice(0, i).reduce((c, l) => c + l.length, 0) * CHAR_MS;
const grow = (i, ms = 1200) => (s.full || done ? 1 : smooth((t - startOf(i)) / ms));
SCENES[pg.scene](ctx, { t, pal: pg.pal, line, full: s.full || done, label, grow, look: LOOKS.hall });
ctx.restore();
ctx.globalAlpha = 1;
// A soft dark foot to the scene, and the band for the words.
for (let i = 0; i < 4; i++) faint(ctx, 0.12, () => rect(ctx, 0, SCENE_H - (i + 1) * 0.6, W, 0.6, "#050308"));
rect(ctx, 0, SCENE_H, W, H - SCENE_H, "#07050c");
rect(ctx, 0, SCENE_H, W, 0.25, pg.pal.glow);
// The heading, fading in, with the page's dots and the skip hint along the top.
faint(ctx, clamp((t - 150) / 350), () => {
label(ctx, pg.chapter, W / 2, SCENE_H + 2.3, 2.1, pg.pal.a, "center", W - 8);
stroke(ctx, W / 2 - 14, SCENE_H + 4.1, W / 2 + 14, SCENE_H + 4.1, pg.pal.glow, 0.2);
});
// The lines typing out.
const shownLines = typed(pg, n);
shownLines.forEach((text, i) => {
if (!text) return;
const size = TEXT_SIZE;
const full = pg.lines[i];
label(ctx, "", 0, 0, size, BONE, "left");
const x0 = W / 2 - widthOf(ctx, full, size) / 2;
const y = SCENE_H + 6.7 + i * 3.35;
label(ctx, text, x0, y, size, BONE, "left", W - 4);
if (i === line && !done) {
const w = widthOf(ctx, text, size);
faint(ctx, 0.5 + 0.5 * Math.sin(t / 110), () => rect(ctx, x0 + w + 0.3, y - 1, 0.7, 2, pg.pal.glow));
}
});
// The page dots, the skip hint and its bar.
PAGES.forEach((_, i) => circle(ctx, 3 + i * 2.2, 3, i === s.page ? 0.7 : 0.35, i === s.page ? pg.pal.glow : "rgba(255, 255, 255, 0.35)"));
faint(ctx, 0.85, () => label(ctx, SKIP_HINT.toUpperCase(), W - 3, 3, 1.5, BONE, "right", 40));
if (s.hold >= 0) {
const k = clamp(s.hold / SKIP_HOLD_MS);
rect(ctx, W - 3 - 30, 4.9, 30, 0.7, "rgba(255, 255, 255, 0.2)");
rect(ctx, W - 3 - 30, 4.9, 30 * k, 0.7, GOLD);
}
// The hint, pulsing once a press counts.
if (ready(s)) {
const last = s.page === PAGES.length - 1;
faint(ctx, 0.55 + 0.45 * Math.sin(t / 260), () => label(ctx, last ? LAST_HINT : STORY_HINT, W / 2, H - 1.5, 1.6, pg.pal.glow, "center", W - 6));
}
// A fade up from black as each page opens.
if (t < 500) faint(ctx, 1 - t / 500, () => rect(ctx, 0, 0, W, H, "#000"));
ctx.restore();
ctx.globalAlpha = 1;
};
}
// The ms a page's typing ends, for the tests.
export { revealEnd };
@@ -0,0 +1,216 @@
// Plan2Code Web Console - Ghoul Rush's intro story: eight short pages shown after YOU start a run and before The Long Hall, the words as data and the rules (lockout, reveal, skip) as plain functions over a round. ghoul-story-draw.js draws the scenes; ghoul-sfx-story.js has the sounds; scripts/test-web-console-activities-ghoul-story.mjs checks it all.
//
// The lore bible lives in prototypes/Ghoul-Rush-TODO.md ("The game's intro
// story"): read it before you change a page or add a stage, so the story
// never contradicts a stage's intro card (ghoul-intros.js). In short: the house
// is MARROW MANOR, a hungry thing older than the valley that eats fright; it
// copies what it eats and builds it again INSIDE itself, so every place of horror
// (a village, a lake, a carnival) is a room, a whole world, within the house; YOU
// once switched a flashlight on in its hall and it flinched, so it called YOU back; the road
// behind YOU is gone, every door YOU pick is locked after YOU, and if YOU get
// out, it starves.
//
// Rules for the text: 2 to 4 lines a page, each at most MAX_LINE characters
// (the field is 96 units wide), always YOU (never the hero's name, "the player"
// or "the hero"), no em dash, US English, spooky-fun, one joke a page at most.
//
// A page: `id`, `scene` (the drawing's id in ghoul-story-draw.js), `chapter`
// (its heading), `pal` ({ sky, ground, a, glow }: the scene's colors and the
// heading's and halo's), `lines` and `cues` ([ms, tone, level, pitch] sounds
// timed from the page's start).
//
// KEEP THE STORY GENERIC: never name a stage, never give a count of stages, rooms,
// doors or keepers. More stages will come, and the story must stay true.
//
// The phase `story` (round.phase): round.story = { page, ms, full, arm, hold,
// cue }. `ms` is the page's clock (a pause holds it), `full` is whether a press
// has finished the typing, `arm` the earliest ms the next press counts, `hold`
// how long fire has been held (-1 when it is not), `cue` the next sound due.
export const MAX_LINE = 60;
// A press counts only after a page has been up this long (a held key or a key's repeats never skip a page), and again a moment after a press finished the typing.
export const STORY_LOCK_MS = 600;
export const RELOCK_MS = 200;
// Fire held this long skips the whole story.
export const SKIP_HOLD_MS = 1000;
// The typing: it starts a little after the page fades in, then one character each CHAR_MS.
export const REVEAL_AT_MS = 450;
export const CHAR_MS = 26;
export const STORY_HINT = "Press any move key or fire to go on";
export const LAST_HINT = "Press any move key or fire to enter the hall";
export const SKIP_HINT = "Hold fire to skip the story";
export const FINALE_TITLE = "THE RUN BEGINS";
const freeze = Object.freeze;
const page = (id, scene, chapter, pal, lines, cues) => freeze({ id, scene, chapter, pal: freeze(pal), lines: freeze(lines), cues: freeze(cues.map((c) => freeze(c))) });
export const PAGES = freeze([
page("road", "road", "I. THE ROAD", { sky: "#0b1230", ground: "#06070f", a: "#bcd4ff", glow: "#7aa2ff" }, [
"Midnight. YOU walk a road no map has ever admitted to.",
"Your flashlight is the friendliest thing for miles.",
"The road is not leading YOU. It is herding YOU.",
], [[0, "ghoulStoryWind", 0.5, 1], [2800, "ghoulStoryBell", 0.3, 0.8], [4600, "ghoulStoryWind", 0.3, 0.85]]),
page("house", "house", "II. THE HOUSE ON THE HILL", { sky: "#160d2b", ground: "#08050f", a: "#e9d5ff", glow: "#c084fc" }, [
"That is Marrow Manor, older than the valley under it.",
"Every window is lit. Nobody has paid the bill in a century.",
"It is not waiting for guests. It is waiting for YOU.",
], [[0, "ghoulThunder", 0.4, 0.9], [1900, "ghoulStoryCrow", 0.3, 1], [3600, "ghoulStoryCreak", 0.3, 1]]),
page("hunger", "hunger", "III. WHAT MARROW EATS", { sky: "#1a0a0c", ground: "#0a0405", a: "#fecaca", glow: "#f87171" }, [
"Marrow does not eat food. Marrow eats fright.",
"Every scream is a meal. Every shiver, a snack.",
"It was a cottage once, then it got a taste for it.",
"A scared guest is a fresh guest. YOU look very fresh.",
], [[0, "ghoulStoryBeat", 0.5, 1], [2500, "ghoulStoryWhisper", 0.35, 1], [4300, "ghoulStoryBeat", 0.5, 0.95], [6000, "ghoulStoryGulp", 0.35, 1]]),
page("arms", "arms", "IV. A HOUSE WITH LONG ARMS", { sky: "#0e1a16", ground: "#05100c", a: "#d1fae5", glow: "#6ee7b7" }, [
"Marrow is not only a house. It is a hunger with a roof.",
"Its shadow reaches farther than the road YOU walked.",
"Whatever it swallows, it keeps, and it builds inside.",
], [[0, "ghoulStoryGulp", 0.4, 1], [1900, "ghoulStoryBeat", 0.4, 0.9], [3600, "ghoulStoryBell", 0.25, 1]]),
page("far", "far", "V. A WORLD INSIDE", { sky: "#14122e", ground: "#07061a", a: "#fde68a", glow: "#fbbf24" }, [
"Peek through a window. The room is bigger than the house.",
"Marrow copies what it eats, then builds it again inside.",
"Whole villages in there. Even a carnival it never forgot.",
"None of it is real. All of it can still swallow YOU.",
], [[0, "ghoulStoryKnock", 0.4, 1], [2300, "ghoulStoryBell", 0.3, 1.2], [4300, "ghoulStoryKnock", 0.35, 1.1], [6100, "ghoulStoryWind", 0.3, 1.3]]),
page("why", "why", "VI. WHY YOU", { sky: "#0a1620", ground: "#04080d", a: "#fff3b0", glow: "#fde047" }, [
"On a dare, YOU once clicked a flashlight on in its hall.",
"Marrow flinched. Nothing had ever made it flinch.",
"Light shows a house for what it is: a draft with a mortgage.",
"It never forgot YOU. Every window has winked at YOU since.",
], [[0, "ghoulStoryWhisper", 0.35, 0.8], [1500, "ghoulStoryClick", 0.5, 1], [3400, "ghoulStoryBeat", 0.35, 1.2], [5200, "ghoulStoryWhisper", 0.3, 1.2]]),
page("trap", "trap", "VII. NO WAY BACK", { sky: "#190a14", ground: "#0b0408", a: "#fbcfe8", glow: "#f472b6" }, [
"Behind YOU, the road folds up like a napkin.",
"Door after door YOU pick, Marrow locks behind YOU.",
"A keeper in each room. The deeper YOU go, the worse.",
"Win, and every window goes dark. Marrow starves for good.",
], [[0, "ghoulStoryLock", 0.5, 1], [1200, "ghoulStoryCreak", 0.3, 0.8], [3200, "ghoulStoryLock", 0.5, 0.85], [5200, "ghoulStoryLock", 0.5, 0.75]]),
page("begin", "begin", "VIII. THE LONG HALL", { sky: "#100c12", ground: "#281a14", a: "#e9ddf3", glow: "#c4a8dc" }, [
"Ahead lies The Long Hall, candles lit, nobody home.",
"Far below it all, something enormous is still beating.",
"Switch on YOUR light. Let it flinch again.",
], [[0, "ghoulStoryCreak", 0.4, 1], [2300, "ghoulStoryBeat", 0.5, 1], [3900, "ghoulStoryBegin", 0.8, 1]]),
]);
// The characters on a page, and the ms its typing is done.
export const pageChars = (pg) => pg.lines.reduce((n, l) => n + l.length, 0);
export const revealEnd = (pg) => REVEAL_AT_MS + pageChars(pg) * CHAR_MS;
// How many characters of the page (all its lines in a row) are showing `ms` in; `full` shows all.
export function shown(pg, ms, full = false) {
const total = pageChars(pg);
if (full) return total;
return Math.max(0, Math.min(total, Math.floor((ms - REVEAL_AT_MS) / CHAR_MS)));
}
// The text showing on each line, given the characters showing in all.
export function typed(pg, count) {
let left = count;
return pg.lines.map((line) => {
const n = Math.max(0, Math.min(line.length, left));
left -= line.length;
return line.slice(0, n);
});
}
// Which line the typing is on (the last one once it is done).
export function lineAt(pg, count) {
let left = count;
for (let i = 0; i < pg.lines.length; i++) {
if (left < pg.lines[i].length) return i;
left -= pg.lines[i].length;
}
return pg.lines.length - 1;
}
// Whether a press would count right now (not before the lockout).
export const ready = (s) => s.ms >= Math.max(STORY_LOCK_MS, s.arm);
/* ------------------------------------------------------------ the phase */
function showPage(round, at) {
const s = round.story;
s.page = at;
s.ms = 0;
s.full = false;
s.arm = 0;
s.cue = 0;
round.events.push({ type: "storyPage", page: at });
}
// Opens the story on its first page: the round waits behind it, the hall already set up.
export function beginStory(round) {
round.phase = "story";
round.phaseMs = 0;
round.input.jump = 0;
round.story = { page: 0, ms: 0, full: false, arm: 0, hold: -1, cue: 0, shown: 0 };
round.events.push({ type: "storyPage", page: 0 });
}
// Out of the story into The Long Hall: the room is announced now, as a round's first room always was.
export function endStory(round) {
round.story = null;
round.phase = "play";
round.phaseMs = 0;
round.input.jump = 0;
round.events.push({ type: "storyEnd" });
round.events.push({ type: "room", room: round.room || 1 });
}
// One slice of the story: the page's clock, its sounds and typing blips, and a fire key held long enough to skip it all.
export function stepStory(round, ms) {
const s = round.story;
if (!s) return;
const pg = PAGES[s.page];
if (s.hold >= 0) {
s.hold += ms;
if (s.hold >= SKIP_HOLD_MS) {
endStory(round);
return;
}
}
s.ms += ms;
while (s.cue < pg.cues.length && pg.cues[s.cue][0] <= s.ms) {
const [, name, vol, rate] = pg.cues[s.cue++];
round.events.push({ type: "storyTone", name, vol, rate });
}
// A soft blip every third character typed.
const now = shown(pg, s.ms, s.full);
if (!s.full && Math.floor(now / 3) > Math.floor(s.shown / 3)) round.events.push({ type: "storyTone", name: "tickSoft", vol: 0.1, rate: 1.5 });
s.shown = now;
}
// A press (a move key, fire or a click): finishes the typing first, then turns the page, and the last page opens the hall. False when it does not count (too soon, or not in the story).
export function takeStory(round) {
const s = round.story;
if (round.phase !== "story" || !s || !ready(s)) return false;
const pg = PAGES[s.page];
if (!s.full && s.ms < revealEnd(pg)) {
s.full = true;
s.arm = s.ms + RELOCK_MS;
return true;
}
if (s.page + 1 >= PAGES.length) endStory(round);
else showPage(round, s.page + 1);
return true;
}
// Fire pressed (a fresh press starts the skip's clock and also counts as a press) or repeating (nothing).
export function pressStory(round, repeat) {
const s = round.story;
if (round.phase !== "story" || !s || repeat) return false;
s.hold = 0;
takeStory(round);
return true;
}
// Fire let go: the skip's clock stops.
export function releaseStory(round) {
if (round.story) round.story.hold = -1;
}
// The whole story at once.
export function skipStory(round) {
if (round.phase !== "story" || !round.story) return false;
endStory(round);
return true;
}
@@ -0,0 +1,930 @@
// Plan2Code Web Console - Ghoul Rush's Servants' Back Stairs, its drawing: a rush down the back stairs and through the basement kitchens on a silver serving tray. A tiled wall of arches behind, a rail of hanging copper pots and ovens in the middle distance, steam and drifting flour, the shelves and stair flights the tray rides (a sheen of grease on the quick stretches), rolling pots and cutlery, hams and copper pans hanging from the ceiling, spectral cooks flinging dishes, silver domes and flying plates with a dessert, service bells for checkpoints, the dining table at the end, and the tray with Planny on it.
//
// ghoul-draw.js plugs it in. LOOKS, VOICES, EVENT_VOICE, LOSE_WORDS and LOSE_SOUNDS are plain
// data; trayArt(d) takes ghoul-draw.js's drawing helpers (`d`) and hands back the drawing by
// kind, so this file never reaches back into it. Drawn in room units, the way ghoul-draw.js
// draws: y counted down from the field's top, so a world height `y` is drawn at `FIELD_H - y`.
// The still layers' pit is dark under the whole ride, so the world is drawn by `moving` (every
// frame, over them); the ham and pans (lows), the tray itself, the flour in front and the
// glyphs that say what to do are drawn by `front`. No random numbers: everything comes from a
// hash. What the art reads off the rules (ghoul-tray.js):
//
// - the room: `spec.ride` ({ track, pots, lows [x0, x1, y, kind], cooks, domes, plates, grease,
// checks, finish }), `spec.ground` (the landing at the start and the dining table at the end).
// - `round.runner` (id "tray"; any other state is none of ours): `v`, `line` (-1 in the air),
// `check`, `done`, `served`, `domes` [taken], `plates` [caught], `cooks` [{ state "down" | "up"
// | "toss" | "spent" | "broken", t, dish: null | { x, y } }].
// - Planny: `you.state`, `you.vy` (tilts the tray in the air), `you.ducking`, `you.x`, `you.y`.
// - events leave short-lived bits in the view's `fx` (`trayBits`, `trayLand`).
const freeze = (o) => Object.freeze(o);
const TAU = Math.PI * 2;
const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x));
const pit = (o) => freeze({ pack: "tray", custom: true, noMoon: true, pit: "#0c0706", ...o });
export const LOOKS = freeze({
tray: pit({ wallTop: "#1a120e", wallLow: "#3a2a22", paper: "#4a3a30", wainscot: "#2c201a", floorTop: "#c9bfa6", floor: "#6a5a48", floorEdge: "#2a1e16", shelf: "#6a4a30", shelfTop: "#a8825a", window: "#ffd9a0", decor: "kitchen", color: "#e8c890", dark: 0.45 }),
});
// How each new kind sounds, by act (first drafts, in ghoul-sfx-tray.js).
export const VOICES = freeze({
tray: freeze({ jump: "ghoulTrayJump", land: "ghoulTrayLand", launch: "ghoulTrayLaunch", duck: "ghoulTrayDuck", crash: "ghoulTrayCrash", check: "ghoulTrayCheck", finish: "ghoulTrayFinish" }),
traydome: freeze({ get: "ghoulTrayDome" }),
trayplate: freeze({ catch: "ghoulTrayPlate" }),
traycook: freeze({ up: "ghoulTrayCookUp", toss: "ghoulTrayToss", hit: "ghoulTrayCookHit" }),
traydish: freeze({ break: "ghoulTrayDishBreak" }),
});
// What each of the pack's events plays: [kind, act], once.
export const EVENT_VOICE = freeze({
trayJump: ["tray", "jump"],
trayLand: ["tray", "land"],
trayLaunch: ["tray", "launch"],
trayDuck: ["tray", "duck"],
trayCrash: ["tray", "crash"],
trayCheck: ["tray", "check"],
trayFinish: ["tray", "finish"],
trayDome: ["traydome", "get"],
trayPlate: ["trayplate", "catch"],
trayCookUp: ["traycook", "up"],
trayToss: ["traycook", "toss"],
trayCookHit: ["traycook", "hit"],
trayDishBreak: ["traydish", "break"],
});
export const LOSE_WORDS = freeze({ pot: "Tripped on a pot", cutlery: "Skewered by cutlery", ham: "Hit by a ham", pans: "Clonked by the pans", dish: "Hit by a dish", tumble: "Down the stairs" });
export const LOSE_SOUNDS = freeze({
pot: ["clank", 0.6, 0.8],
cutlery: ["clank", 0.5, 1.3],
ham: ["smash", 0.5, 0.8],
pans: ["clank", 0.6, 0.6],
dish: ["smash", 0.6, 1],
tumble: ["ghoulPitFall", 0.55, 0.9],
});
const FW = 96;
let FH = 54;
const COPPER = "#c8793a";
const COPPER_D = "#8a4a22";
const SILVER = "#dde3ee";
const SILVER_D = "#9aa4b8";
const CHINA = "#f4f1e8";
// A number in 0..1 from two integers, the same every time (no random draws).
const rnd = (a, b = 0) => {
let h = Math.imul((a | 0) + 0x9e37, 0x85ebca6b) ^ Math.imul((b | 0) + 0x7f4a, 0xc2b2ae35);
h ^= h >>> 13;
h = Math.imul(h, 0x5bd1e995);
h ^= h >>> 15;
return (h >>> 0) / 4294967296;
};
const poly = (c, pts) => {
c.beginPath();
pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y)));
c.closePath();
};
const seg = (c, x0, y0, x1, y1) => {
c.beginPath();
c.moveTo(x0, y0);
c.lineTo(x1, y1);
c.stroke();
};
const disc = (c, x, y, r) => {
c.beginPath();
c.arc(x, y, r, 0, TAU);
c.fill();
};
// A vertical gradient, or its middle color on a context with none.
const vgrad = (c, y0, y1, stops) => {
const g = typeof c.createLinearGradient === "function" ? c.createLinearGradient(0, y0, 0, y1) : null;
if (!g || typeof g.addColorStop !== "function") return stops[stops.length >> 1][1];
for (const [o, col] of stops) g.addColorStop(o, col);
return g;
};
// A soft glow: a few stacked translucent discs (cheap, and the same on any context).
function glow(c, x, y, r, rgb, alpha) {
for (let k = 3; k >= 1; k--) {
c.fillStyle = `rgba(${rgb},${alpha * (0.14 + (3 - k) * 0.1)})`;
disc(c, x, y, (r * k) / 3);
}
}
/* ------------------------------------------------------------ the track */
const yOn = (pts, x) => {
if (x <= pts[0][0]) return pts[0][1];
let i = 0;
while (i < pts.length - 2 && x > pts[i + 1][0]) i++;
const [xa, ya] = pts[i];
const [xb, yb] = pts[i + 1];
if (x >= xb) return yb;
return ya + ((yb - ya) * (x - xa)) / (xb - xa);
};
const heightAt = (R, x) => {
let best = null;
for (const pts of R.track) {
if (x < pts[0][0] || x > pts[pts.length - 1][0]) continue;
const y = yOn(pts, x);
if (best === null || y > best) best = y;
}
return best;
};
/* ------------------------------------------------------------ telegraphs */
// What to do about each obstacle, as a glyph that fades in ahead of it: DUCK for a ham or pans (an
// arrow down, amber), JUMP for a gap, a pot or cutlery (an arrow up, cyan), SHOOT for a cook (a
// ring, red; a jump over his dish works too). Domes and plates are rewards and get none. It all
// comes from the room's `ride` fields and where the tray is (no random numbers, no rules).
export const TELEGRAPH_SEE = 40;
export const TELEGRAPH_FULL = 30;
export const TELEGRAPH_WORDS = 3;
export const TELEGRAPH_ALPHA = 0.72;
export const ANSWERS = freeze({ gap: "JUMP", pot: "JUMP", cutlery: "JUMP", ham: "DUCK", pans: "DUCK", cook: "SHOOT" });
export const ANSWER_COLORS = freeze({ JUMP: "#5fe3ff", DUCK: "#ffb02e", SHOOT: "#ff7a6a" });
const marks = new WeakMap();
// Every obstacle that wants a glyph: { kind, lead (where it begins), x (its middle), up (height of
// the glyph's anchor), n (which of its kind), answer }, in the room's order.
export function telegraphMarks(R) {
if (marks.has(R)) return marks.get(R);
const out = [];
const count = {};
const add = (kind, lead, x, up) => {
const n = count[kind] || 0;
count[kind] = n + 1;
out.push({ kind, lead, x, up, n, answer: ANSWERS[kind] });
};
for (let i = 0; i + 1 < R.track.length; i++) {
const a = R.track[i].at(-1)[0];
const b = R.track[i + 1][0][0];
add("gap", a, (a + b) / 2, Math.max(heightAt(R, a - 0.1) ?? 0, heightAt(R, b + 0.1) ?? 0) + 6.5);
}
for (const [x, , kind] of R.pots) add(kind ? "cutlery" : "pot", x, x, (heightAt(R, x) ?? 10) + 7);
for (const [x0, x1, y, kind] of R.lows) add(kind ? "pans" : "ham", x0 - 3.2, (x0 + x1) / 2, y + (kind ? 7 : 7.4));
for (const [x] of R.cooks) add("cook", x - 40, x, (heightAt(R, x) ?? 10) + 9);
out.sort((p, q) => p.lead - q.lead);
marks.set(R, out);
return out;
}
// The glyphs showing with the tray at `x`: { ...mark, alpha (0..1, before the pulse), words }.
export function telegraphs(R, x) {
const out = [];
for (const m of telegraphMarks(R)) {
const d = m.lead - x;
if (d > TELEGRAPH_SEE || d < -6) continue;
const alpha = Math.min(clamp((TELEGRAPH_SEE - d) / (TELEGRAPH_SEE - TELEGRAPH_FULL), 0, 1), clamp((d + 4) / 6, 0, 1));
if (alpha > 0.01) out.push({ ...m, alpha, words: m.n < TELEGRAPH_WORDS });
}
return out;
}
/* --------------------------------------------------------------------- art */
export function trayArt(d) {
const { ellipse, say, label, GOLD } = d;
const ride = (v) => (v.spec && v.spec.ride && v.spec.ride.runner === "tray" ? v.spec.ride : null);
const state = (v) => (v.round && v.round.runner && v.round.runner.id === "tray" ? v.round.runner : null);
const worldY = (y) => FH - y;
const baseOf = (R, x, line) => worldY(heightAt(R, x) ?? 10);
/* ------------------------------------------------------------- the room */
// The still layers only get the wall's color: the world is drawn by `moving`.
function backdrop(ctx, v, look, x0, x1) {
ctx.fillStyle = look.wallLow;
ctx.fillRect(x0, 0, x1 - x0, v.g.FIELD_H);
}
// The landing at the top of the stairs (flagstones), and the dining table at the end (a long
// table under a white cloth, a runner of red along it).
function ground(ctx, v, look, a, b, top) {
const R = ride(v);
const y = v.g.FIELD_H - top;
if (R && a >= R.finish - 1) {
ctx.fillStyle = "#5a3a22";
ctx.fillRect(a, y, b - a, top + 2);
ctx.fillStyle = "#f2efe6";
ctx.fillRect(a, y, b - a, 1.1);
ctx.fillStyle = "#b2182b";
ctx.fillRect(a, y + 0.1, b - a, 0.35);
ctx.fillStyle = "#d9d3c4";
for (let x = a; x < b; x += 3.2) ctx.fillRect(x, y + 1.1, 1.4, Math.min(top, 5));
return;
}
ctx.fillStyle = vgrad(ctx, y, y + top, [[0, "#c9bfa6"], [0.3, "#8f846c"], [1, "#2a2018"]]);
ctx.fillRect(a, y, b - a, top + 2);
ctx.strokeStyle = "rgba(20,14,8,0.4)";
ctx.lineWidth = 0.1;
for (let x = a; x <= b; x += 4) seg(ctx, x, y, x, y + 3);
seg(ctx, a, y + 1.5, b, y + 1.5);
ctx.fillStyle = "#f2ead2";
ctx.fillRect(a, y, b - a, 0.3);
}
function shelf() {}
/* --------------------------------------------------------- the distance */
// The kitchen behind: warm dark, a wall of white tile with arches, a rail of hanging pots and
// ladles, brick ovens, drifting steam. Parallax tiles drawn straight, no layers cached.
function distance(ctx, cam, clock) {
ctx.fillStyle = vgrad(ctx, 0, FH, [[0, "#0e0908"], [0.5, "#241813"], [1, "#4a3426"]]);
ctx.fillRect(cam - 1, 0, FW + 2, FH);
// The tiled wall, a band of white tile lines, behind.
const wall = cam * 0.88;
ctx.fillStyle = "rgba(214,206,186,0.14)";
ctx.fillRect(cam - 1, 12, FW + 2, 34);
ctx.strokeStyle = "rgba(230,222,200,0.12)";
ctx.lineWidth = 0.1;
for (let r = 0; r < 9; r++) seg(ctx, cam - 1, 13 + r * 3.8, cam + FW + 1, 13 + r * 3.8);
for (let x = Math.floor(wall / 3.8) * 3.8; x < wall + FW + 4; x += 3.8) seg(ctx, x + cam - wall, 12, x + cam - wall, 46);
// Arches every 36 with a hanging lamp, slow.
const par = 0.82;
for (let k = Math.floor((cam * par - 10) / 36); k <= Math.floor((cam * par + FW + 10) / 36); k++) {
const ax = cam + (k * 36 - cam * par);
ctx.fillStyle = "rgba(10,6,4,0.55)";
ctx.beginPath();
ctx.moveTo(ax, 46);
ctx.lineTo(ax, 24);
ctx.arc(ax + 7, 24, 7, Math.PI, 0);
ctx.lineTo(ax + 14, 46);
ctx.closePath();
ctx.fill();
ctx.strokeStyle = "#5a4a3a";
ctx.lineWidth = 0.5;
ctx.stroke();
glow(ctx, ax + 7, 10 + rnd(k, 1) * 3, 6, "255,190,110", 0.5 + 0.1 * Math.sin(clock / 300 + k));
}
// The rail of hanging pots and ladles in the middle distance.
const mid = 0.62;
ctx.strokeStyle = "#2a1e16";
ctx.lineWidth = 0.5;
seg(ctx, cam - 1, 9, cam + FW + 1, 9);
for (let k = Math.floor((cam * mid - 4) / 11); k <= Math.floor((cam * mid + FW + 4) / 11); k++) {
const px = cam + (k * 11 - cam * mid);
const drop = 3 + rnd(k, 2) * 5;
const kind = Math.floor(rnd(k, 3) * 3);
ctx.strokeStyle = "#2a1e16";
ctx.lineWidth = 0.18;
seg(ctx, px, 9, px, 9 + drop);
ctx.fillStyle = kind === 2 ? SILVER_D : COPPER_D;
if (kind === 0) {
ctx.fillRect(px - 1.5, 9 + drop, 3, 2.4);
ctx.fillStyle = "rgba(255,200,140,0.3)";
ctx.fillRect(px - 1.2, 9 + drop + 0.2, 0.5, 2);
} else if (kind === 1) {
disc(ctx, px, 9 + drop + 1.6, 1.7);
ctx.fillStyle = "#1a120c";
disc(ctx, px, 9 + drop + 1.6, 0.9);
} else {
ctx.fillRect(px - 0.2, 9 + drop, 0.4, 3.4);
disc(ctx, px, 9 + drop + 3.6, 0.9);
}
}
// Steam, rising and fading.
for (let k = 0; k < 14; k++) {
const p = (clock / (3200 + (k % 5) * 400) + rnd(k, 7)) % 1;
const sx = cam + ((((rnd(k, 8) * 120 - cam * 0.5) % 120) + 120) % 120) - 12 - p * 4;
ctx.fillStyle = `rgba(235,235,230,${0.16 * (1 - p)})`;
disc(ctx, sx, FH - 8 - p * 34, 2 + p * 4);
}
}
/* ------------------------------------------------------------ the track */
// The shelves and stair flights of every line in view: a wooden fill down to the bottom, a
// pale rim, plank lines and brackets on the shelves, step noses and risers on the flights, and
// a ragged lip at each line's end over the dark gap.
function paintTrack(ctx, R, lo, hi, clock) {
for (const pts of R.track) {
if (pts[pts.length - 1][0] < lo || pts[0][0] > hi) continue;
const top = pts.map(([x, y]) => [x, FH - y]);
ctx.fillStyle = vgrad(ctx, FH - 40, FH, [[0, "#6a4a30"], [0.6, "#3a281c"], [1, "#150e0a"]]);
poly(ctx, [...top, [pts.at(-1)[0], FH + 1], [pts[0][0], FH + 1]]);
ctx.fill();
for (let i = 0; i + 1 < pts.length; i++) {
const [xa, ya] = pts[i];
const [xb, yb] = pts[i + 1];
if (xb < lo || xa > hi) continue;
const slope = (yb - ya) / (xb - xa);
if (slope < -0.08) {
// Stairs: a nose every 2.2 across with a dark riser under it.
for (let x = xa; x < xb; x += 2.2) {
const y = FH - yOn(pts, x);
ctx.fillStyle = "#c9a878";
ctx.fillRect(x, y, 2.2, 0.35);
ctx.fillStyle = "rgba(10,6,4,0.55)";
poly(ctx, [[x, y + 0.35], [x + 2.2, y + 0.35 + 0.37 * 2.2 * 0.5], [x, y + 0.35 + 0.9]]);
ctx.fill();
}
} else {
// A shelf: a pale board, plank joins, brackets underneath, and a jar here and there.
ctx.fillStyle = "#a8825a";
poly(ctx, [[xa, FH - ya], [xb, FH - yb], [xb, FH - yb + 0.9], [xa, FH - ya + 0.9]]);
ctx.fill();
ctx.fillStyle = "#e0c08c";
poly(ctx, [[xa, FH - ya], [xb, FH - yb], [xb, FH - yb + 0.25], [xa, FH - ya + 0.25]]);
ctx.fill();
ctx.strokeStyle = "rgba(30,18,10,0.5)";
ctx.lineWidth = 0.1;
for (let x = Math.ceil(xa / 9) * 9; x < xb; x += 9) seg(ctx, x, FH - yOn(pts, x), x, FH - yOn(pts, x) + 0.9);
for (let x = Math.ceil(xa / 14) * 14; x < xb; x += 14) {
const y = FH - yOn(pts, x);
ctx.strokeStyle = "#2a1e16";
ctx.lineWidth = 0.3;
seg(ctx, x, y + 0.9, x - 1.6, y + 3.4);
}
}
}
// The ragged lip at the end of the line, over the gap.
const [ex, ey] = pts[pts.length - 1];
ctx.fillStyle = "#2a1e16";
poly(ctx, [[ex, FH - ey], [ex + 0.5, FH - ey + 1.6], [ex - 0.4, FH - ey + 2.6], [ex, FH - ey + 4]]);
ctx.fill();
}
// The grease: a sheen on the quick stretches, with a glint that slides along.
for (const [a, b] of R.grease) {
if (b < lo || a > hi) continue;
for (let x = Math.max(a, lo); x < Math.min(b, hi); x += 1) {
const y = FH - (heightAt(R, x) ?? 10);
ctx.fillStyle = "rgba(255,226,120,0.5)";
ctx.fillRect(x, y - 0.05, 1.05, 0.38);
}
const gx = a + (((clock / 14) % (b - a + 12)) - 6);
if (gx > a && gx < b) {
ctx.fillStyle = "rgba(255,255,230,0.8)";
ctx.fillRect(gx, FH - (heightAt(R, gx) ?? 10) - 0.05, 3, 0.4);
}
}
}
/* ------------------------------------------------------------ the things */
// A service bell on a post: red until passed, then green.
function checkpoint(ctx, v, x, base, on, i) {
ctx.strokeStyle = "#2a1e16";
ctx.lineWidth = 0.35;
seg(ctx, x, base + 0.2, x, base - 4.4);
ctx.fillStyle = on ? "#bff0c8" : SILVER;
ctx.beginPath();
ctx.arc(x, base - 4.4, 1.5, Math.PI, 0);
ctx.closePath();
ctx.fill();
ctx.fillStyle = SILVER_D;
ctx.fillRect(x - 1.8, base - 4.5, 3.6, 0.3);
disc(ctx, x, base - 6, 0.3);
const pulse = on ? 1 : 0.7 + 0.3 * Math.sin(v.clock / 160 + i);
glow(ctx, x, base - 5, 3.6, on ? "90,240,130" : "255,70,50", 0.7 * pulse);
}
// A rolling pot: a copper stockpot on its side with a handle, wobbling; or a heap of dropped cutlery.
function pot(ctx, v, x, base, kind, i) {
ctx.fillStyle = "rgba(0,0,0,0.3)";
ellipse(ctx, x, base + 0.1, kind ? 2.8 : 1.9, 0.3);
ctx.fill();
if (kind) {
ctx.lineCap = "round";
for (let k = 0; k < 7; k++) {
const a = -0.5 + k * 0.17 + (rnd(i, k) - 0.5) * 0.3;
ctx.strokeStyle = k % 2 ? SILVER : SILVER_D;
ctx.lineWidth = 0.22;
const bx = x - 2 + k * 0.65;
seg(ctx, bx, base, bx + Math.sin(a) * 2.2, base - 1.2 - Math.abs(Math.cos(a)) * 0.5);
ctx.fillStyle = SILVER;
disc(ctx, bx + Math.sin(a) * 2.2, base - 1.4, 0.3);
}
ctx.lineCap = "butt";
return;
}
ctx.save();
ctx.translate(x, base - 1.4);
ctx.rotate(Math.sin(v.clock / 140 + i) * 0.12);
ctx.fillStyle = COPPER;
ctx.fillRect(-1.4, -1.4, 2.8, 2.8);
ctx.fillStyle = COPPER_D;
ctx.fillRect(-1.4, 0.7, 2.8, 0.7);
ctx.fillStyle = "rgba(255,220,170,0.55)";
ctx.fillRect(-1.1, -1.2, 0.5, 2.2);
ctx.fillStyle = "#1a120c";
ellipse(ctx, 1.4, 0, 0.3, 1.2);
ctx.fill();
ctx.strokeStyle = "#2a1e16";
ctx.lineWidth = 0.28;
seg(ctx, -1.4, -0.4, -2.6, -0.8);
ctx.restore();
}
// A silver dome (a cloche) on its plate, a handle ball on top, a shine; gone once run through.
function dome(ctx, v, x, y, i) {
const bob = Math.sin(v.clock / 300 + i * 1.7) * 0.25;
ctx.save();
ctx.translate(x, y + bob);
glow(ctx, 0, -1.4, 3.2, "230,240,255", 0.45);
ctx.fillStyle = SILVER_D;
ellipse(ctx, 0, -0.15, 1.9, 0.3);
ctx.fill();
ctx.fillStyle = vgrad(ctx, -2.4, 0, [[0, "#ffffff"], [0.5, SILVER], [1, SILVER_D]]);
ctx.beginPath();
ctx.moveTo(-1.6, -0.2);
ctx.arc(0, -0.2, 1.6, Math.PI, 0);
ctx.closePath();
ctx.fill();
ctx.fillStyle = SILVER;
disc(ctx, 0, -2.0, 0.28);
ctx.fillStyle = "rgba(255,255,255,0.8)";
ellipse(ctx, -0.6, -1.1, 0.3, 0.55, -0.5);
ctx.fill();
ctx.restore();
}
// A flying plate with a dessert (a little cake and a cherry), turning end over end a little.
function plate(ctx, v, x, y, i) {
const t = v.clock / 160 + i * 2.1;
const bob = Math.sin(v.clock / 260 + i) * 0.35;
ctx.save();
ctx.translate(x, y + bob);
glow(ctx, 0, 0, 3.6, "255,200,220", 0.4);
ctx.rotate(Math.sin(t) * 0.35);
ctx.fillStyle = CHINA;
ellipse(ctx, 0, 0.5, 1.7, 0.4);
ctx.fill();
ctx.strokeStyle = "#5a7ac8";
ctx.lineWidth = 0.1;
ellipse(ctx, 0, 0.5, 1.3, 0.28);
ctx.stroke();
ctx.fillStyle = "#8a5a3a";
ctx.fillRect(-0.7, -0.5, 1.4, 0.9);
ctx.fillStyle = "#ffd0e0";
ctx.fillRect(-0.7, -0.75, 1.4, 0.35);
ctx.fillStyle = "#d4162e";
disc(ctx, 0, -1.05, 0.34);
ctx.restore();
}
// A spectral cook: a pale, see-through chef with a tall hat and a dark glowing eye, a plate in his raised hand while he winds up, flung forward after.
function cook(ctx, v, x, base, o, i) {
if (o.state === "down" || o.state === "spent") return;
const clock = v.clock;
if (o.state === "broken") return;
const wind = o.state === "up" ? clamp(1 - o.t / 700, 0, 1) : 1;
const rise = o.state === "up" ? Math.min(1, (700 - o.t) / 160) : 1;
ctx.save();
ctx.translate(x, base + (1 - rise) * 4);
ctx.globalAlpha = 0.7 + 0.15 * Math.sin(clock / 180 + i);
glow(ctx, 0, -3, 5, "170,220,255", 0.4);
ctx.fillStyle = "#cfe3f0";
// The body: an apron over a rounded coat.
poly(ctx, [[-1.6, 0], [-1.3, -3.4], [1.3, -3.4], [1.6, 0]]);
ctx.fill();
ctx.fillStyle = "#f4f8fc";
ctx.fillRect(-1, -2.6, 2, 2.6);
ctx.fillStyle = "#cfe3f0";
disc(ctx, 0, -4.1, 1.05);
// The hat.
ctx.fillStyle = "#f4f8fc";
ctx.fillRect(-0.9, -5.3, 1.8, 0.7);
disc(ctx, -0.6, -5.7, 0.8);
disc(ctx, 0.6, -5.7, 0.8);
disc(ctx, 0, -6.1, 0.9);
// The eyes and a hungry mouth.
ctx.fillStyle = "#101820";
disc(ctx, -0.35, -4.2, 0.2);
disc(ctx, 0.35, -4.2, 0.2);
ctx.fillRect(-0.45, -3.7, 0.9, 0.18);
// The arm: up with a plate while winding, then out toward the tray.
ctx.strokeStyle = "#cfe3f0";
ctx.lineWidth = 0.5;
ctx.lineCap = "round";
const ax = o.state === "toss" ? -2.8 : -1.6 - wind * 0.4;
const ay = o.state === "toss" ? -3.1 : -3 - wind * 2.2;
seg(ctx, -1.2, -3, ax, ay);
ctx.lineCap = "butt";
if (o.state === "up") {
ctx.fillStyle = CHINA;
ellipse(ctx, ax, ay - 0.3, 1.3, 0.3);
ctx.fill();
}
ctx.restore();
}
// A dish in flight, spinning, toward the tray.
function dish(ctx, v, dd, i) {
ctx.save();
ctx.translate(dd.x, worldY(dd.y) - 0.7);
glow(ctx, 0, 0, 2.6, "255,235,200", 0.35);
ctx.fillStyle = CHINA;
ellipse(ctx, 0, 0, 1.1, 0.25 + 0.5 * Math.abs(Math.sin(v.clock / 70 + i)));
ctx.fill();
ctx.strokeStyle = "#5a7ac8";
ctx.lineWidth = 0.08;
ellipse(ctx, 0, 0, 0.8, 0.15 + 0.35 * Math.abs(Math.sin(v.clock / 70 + i)));
ctx.stroke();
ctx.restore();
}
// The dining table's banner over the door: LAST ORDERS, lit.
function banner(ctx, v, x) {
ctx.strokeStyle = "#2a1e16";
ctx.lineWidth = 0.4;
seg(ctx, x - 14, FH - 30, x + 20, FH - 30);
ctx.fillStyle = "#7a1426";
poly(ctx, [[x - 12, FH - 30], [x + 18, FH - 30], [x + 18, FH - 23], [x + 3, FH - 21], [x - 12, FH - 23]]);
ctx.fill();
label(ctx, "LAST ORDERS", x + 3, FH - 25.6, 3, "#ffd98a", "center");
}
/* ---------------------------------------------------------- the world */
function moving(ctx, v, cam) {
const R = ride(v);
const c = state(v);
if (!R || !c) return;
FH = v.g.FIELD_H;
const clock = v.clock;
cam = Math.round(cam * 8) / 8;
distance(ctx, cam, clock);
const lo = cam - 8;
const hi = cam + FW + 8;
paintTrack(ctx, R, lo - 6, hi + 6, clock);
R.checks.forEach((x, i) => {
if (x > lo && x < hi) checkpoint(ctx, v, x, baseOf(R, x), i <= c.check, i);
});
if (R.finish > lo - 24 && R.finish < hi) banner(ctx, v, R.finish + 28);
// The shadow of a ham or pans on the shelf beneath it.
for (const [x0, x1, , kind] of R.lows) {
if (x1 < lo || x0 > hi) continue;
ctx.fillStyle = `rgba(4,2,2,${kind ? 0.3 : 0.4})`;
ctx.fillRect(x0 - 0.5, baseOf(R, x0) - 0.1, x1 - x0 + 1, 0.5);
}
R.pots.forEach(([x, line, kind], i) => {
if (x > lo && x < hi) pot(ctx, v, x, baseOf(R, x, line), kind, i);
});
R.cooks.forEach(([x, line], i) => {
const o = c.cooks[i];
if (x > lo && x < hi) cook(ctx, v, x, baseOf(R, x, line), o, i);
if (o.dish) dish(ctx, v, o.dish, i);
});
R.domes.forEach(([x, line, lift], i) => {
if (x > lo && x < hi && !c.domes[i]) dome(ctx, v, x, baseOf(R, x, line) - lift, i);
});
R.plates.forEach(([x, line, lift], i) => {
if (x > lo && x < hi && !c.plates[i]) plate(ctx, v, x, baseOf(R, x, line) - lift - 1.4, i);
});
// The dining table, over the sky (the still layers' was painted under it).
for (const [a, b, top] of v.spec.ground) if (a >= R.finish - 1 && b > lo && a < hi) ground(ctx, v, LOOKS.tray, a, b, top);
}
/* ----------------------------------------------------- the tray, in front */
// The big silver tray, side on: a shallow oval with a raised rim, two handles, a shine and a dent;
// clattering on the stairs, scattering crumbs. Planny is drawn by the game over it.
function tray(ctx, v, R, c) {
const { round } = v;
const you = round.you;
const clock = v.clock;
const done = c.done;
const x = done && c.restX !== undefined ? c.restX : you.x;
const y = done ? (v.spec.ground.find(([a, b]) => x >= a && x <= b) || [0, 0, 10])[2] : you.y;
let pitch = 0;
if (!done) pitch = c.line >= 0 ? Math.atan2((heightAt(R, x + 3) ?? y) - (heightAt(R, x - 3) ?? y), 6) * 0.95 : clamp(you.vy / Math.max(14, c.v), -1, 1) * 0.5;
const shake = !done && c.line >= 0 ? Math.sin(clock / 29) * 0.04 * (c.v / 44) : 0;
ctx.save();
ctx.translate(x, FH - y + shake);
ctx.rotate(-pitch);
// Sparks and crumbs off the rim, longer the faster it goes.
if (!done && c.line >= 0) {
for (let k = 0; k < 9; k++) {
const p = (clock / (300 + (k % 4) * 60) + k * 0.13) % 1;
ctx.fillStyle = `rgba(255,230,160,${(1 - p) * 0.8})`;
disc(ctx, -3.4 - p * (2.5 + (c.v / 44) * 3) * (0.6 + rnd(k, 1)), -0.1 - p * (0.8 + rnd(k, 2) * 1.6), 0.12 + (1 - p) * 0.16);
}
}
ctx.scale(1.12, 1.3);
ctx.fillStyle = "rgba(10,6,4,0.35)";
ellipse(ctx, 0, 0.6, 3.9, 0.25);
ctx.fill();
// The dish of the tray: a shallow silver bowl, a rim, a bright top.
ctx.fillStyle = vgrad(ctx, -0.6, 0.6, [[0, "#ffffff"], [0.4, SILVER], [1, SILVER_D]]);
ctx.beginPath();
ctx.moveTo(-3.9, -0.3);
ctx.quadraticCurveTo(-3.6, 0.5, -2.4, 0.5);
ctx.lineTo(2.4, 0.5);
ctx.quadraticCurveTo(3.6, 0.5, 3.9, -0.3);
ctx.lineTo(3.3, -0.3);
ctx.lineTo(-3.3, -0.3);
ctx.closePath();
ctx.fill();
ctx.strokeStyle = "#7a8498";
ctx.lineWidth = 0.1;
ctx.stroke();
ctx.fillStyle = "#ffffff";
ctx.fillRect(-3.6, -0.34, 7.2, 0.14);
// The handles at each end, and a few dents.
ctx.strokeStyle = SILVER_D;
ctx.lineWidth = 0.18;
ctx.beginPath();
ctx.arc(-3.95, -0.1, 0.35, Math.PI * 1.5, Math.PI * 0.5, true);
ctx.stroke();
ctx.beginPath();
ctx.arc(3.95, -0.1, 0.35, Math.PI * 1.5, Math.PI * 0.5, false);
ctx.stroke();
ctx.fillStyle = "rgba(110,120,140,0.5)";
ellipse(ctx, 1.6, 0.1, 0.35, 0.12);
ctx.fill();
// A landing's puff of flour.
const fx = v.fx;
const land = fx && fx.trayLand !== undefined ? fx.clock - fx.trayLand.t0 : 1e9;
if (land < 380) {
for (let k = 0; k < 8; k++) {
const p = land / 380;
ctx.fillStyle = `rgba(250,246,236,${(1 - p) * 0.8})`;
disc(ctx, (k - 3.5) * 0.9 * (0.5 + p * 1.4), -0.3 - p * (1 + rnd(k, 4) * 1.6) * (fx.trayLand.big ? 1.6 : 1), 0.3 + p * 0.3);
}
}
ctx.restore();
}
// Hams on hooks, or a rack of copper pans, hanging from the ceiling over the track.
function low(ctx, v, x0, x1, y, kind, i) {
const clock = v.clock;
const under = worldY(y);
const xm = (x0 + x1) / 2;
if (kind === 0) {
// A rail with two hams swinging a little on ropes.
ctx.strokeStyle = "#2a1e16";
ctx.lineWidth = 0.4;
seg(ctx, x0 - 1, 1.5, x1 + 1, 1.5);
for (const [h, px] of [[0, x0 + 1.8], [1, x1 - 1.8]]) {
const sw = Math.sin(clock / 380 + i * 1.3 + h * 1.9) * 0.5;
const len = under - 3.4 - 1.5;
ctx.strokeStyle = "#6a5030";
ctx.lineWidth = 0.16;
seg(ctx, px, 1.5, px + sw, 1.5 + len);
ctx.save();
ctx.translate(px + sw, 1.5 + len);
ctx.fillStyle = "#b8545a";
ellipse(ctx, 0, 1.7, 1.5, 1.9);
ctx.fill();
ctx.fillStyle = "#d98a8a";
ellipse(ctx, -0.4, 1.2, 0.5, 0.9);
ctx.fill();
ctx.fillStyle = "#e8dcc0";
ctx.fillRect(-0.2, -0.4, 0.4, 0.9);
ctx.restore();
}
} else {
// A rack with copper pans on ropes, their bases about the underside.
ctx.strokeStyle = "#2a1e16";
ctx.lineWidth = 0.3;
seg(ctx, x0 - 1, 1.5, x0 - 1, under - 3.6);
seg(ctx, x1 + 1, 1.5, x1 + 1, under - 3.6);
ctx.lineWidth = 0.45;
seg(ctx, x0 - 1.4, under - 3.6, x1 + 1.4, under - 3.6);
const n = 4;
for (let k = 0; k < n; k++) {
const px = x0 + 0.6 + (k * (x1 - x0 - 1.2)) / (n - 1);
const sw = Math.sin(clock / 420 + i + k * 1.4) * 0.15;
ctx.strokeStyle = "#6a5030";
ctx.lineWidth = 0.14;
seg(ctx, px, under - 3.6, px + sw, under - 2.8);
ctx.fillStyle = COPPER;
ctx.beginPath();
ctx.arc(px + sw, under - 1.6, 1.2, 0, TAU);
ctx.fill();
ctx.fillStyle = "#1a120c";
disc(ctx, px + sw, under - 1.6, 0.8);
ctx.fillStyle = COPPER_D;
ctx.fillRect(px + sw - 0.2, under - 0.4, 0.4, 0.4);
}
}
ctx.globalAlpha = 0.4 + 0.15 * Math.sin(clock / 400 + i);
glow(ctx, xm, under + 0.2, 4, "255,200,130", 0.4);
ctx.globalAlpha = 1;
}
// A see-through glyph over an obstacle: a pair of chevrons (a ring for a cook) and, for the first few, the word.
function glyph(ctx, v, t) {
const up = t.answer === "JUMP";
const col = ANSWER_COLORS[t.answer];
const pulse = 0.85 + 0.15 * Math.sin(v.clock / 260 + t.lead);
const cy = Math.min(FH - 7, FH - t.up) + Math.sin(v.clock / 260 + t.lead) * 0.35;
ctx.save();
ctx.globalAlpha = t.alpha * pulse * TELEGRAPH_ALPHA;
ctx.lineCap = "round";
ctx.lineJoin = "round";
if (t.answer === "SHOOT") {
for (const [w, c] of [[1.2, "rgba(8,4,4,0.8)"], [0.5, col]]) {
ctx.strokeStyle = c;
ctx.lineWidth = w;
ctx.beginPath();
ctx.arc(t.x, cy - 2.2, 1.4, 0, TAU);
ctx.stroke();
seg(ctx, t.x - 2.2, cy - 2.2, t.x + 2.2, cy - 2.2);
seg(ctx, t.x, cy - 4.4, t.x, cy);
}
} else {
const dir = up ? -1 : 1;
const ay = cy + (up ? -2.6 : 2.6);
for (const [w, c] of [[1.3, "rgba(8,4,4,0.8)"], [0.6, col]]) {
ctx.strokeStyle = c;
ctx.lineWidth = w;
for (let k = 0; k < 2; k++) {
const oy = ay + (k - 0.5) * 1.5 * dir - dir * 0.2;
ctx.beginPath();
ctx.moveTo(t.x - 1.7, oy - dir * 0.9);
ctx.lineTo(t.x, oy + dir * 0.9);
ctx.lineTo(t.x + 1.7, oy - dir * 0.9);
ctx.stroke();
}
}
}
if (t.words) label(ctx, t.answer, t.x, cy + (up || t.answer === "SHOOT" ? 1.2 : -1.2), 2.3, col, "center");
ctx.restore();
}
function front(ctx, v) {
const R = ride(v);
const round = v.round;
const c = state(v);
if (!R || !c) return;
FH = v.g.FIELD_H;
const cam = Math.round(round.camX * 8) / 8;
const lo = cam - 8;
const hi = cam + FW + 8;
tray(ctx, v, R, c);
R.lows.forEach(([x0, x1, y, kind], i) => {
if (x1 >= lo && x0 <= hi) low(ctx, v, x0, x1, y, kind, i);
});
// Clouds of flour drifting over the route, here and there: they dim the view, never hide a glyph.
for (let n = Math.max(0, Math.floor((cam - 40) / 230)); n <= Math.floor((cam + FW + 40) / 230); n++) {
const bx = 140 + n * 230;
for (let k = 0; k < 5; k++) {
const px = bx + (rnd(n, k) - 0.3) * 26 + Math.sin(v.clock / 900 + k + n) * 1.5;
if (px < lo - 10 || px > hi + 10) continue;
const py = FH - (heightAt(R, px) ?? 20) - 2 - rnd(n, k + 9) * 5;
ctx.fillStyle = `rgba(246,240,226,${0.1 + 0.05 * rnd(n, k + 3)})`;
disc(ctx, px, py, 3 + rnd(n, k + 5) * 4);
}
}
if (!c.done) for (const t of telegraphs(R, round.you.x)) glyph(ctx, v, t);
// Splinters of china and tin from a broken dish or a cook, tumbling.
const bits = v.fx && v.fx.trayBits;
if (bits) {
for (const b of bits) {
const t = (v.fx.clock - b.t0) / 1000;
if (t < 0 || t > 0.9) continue;
ctx.save();
ctx.translate(b.x + b.vx * t, FH - (b.y + b.vy * t - 30 * t * t));
ctx.rotate(b.rot + b.vr * t);
ctx.globalAlpha = clamp(1.6 - t * 1.6, 0, 1);
ctx.fillStyle = b.c;
ctx.fillRect(-b.w / 2, -0.12, b.w, 0.24);
ctx.restore();
}
ctx.globalAlpha = 1;
}
// The course count, a small plate of dots under the hearts' pill: one per course, a gold one for each eaten.
if (!c.done && round.phase === "play") {
const goal = 7;
for (let k = 0; k < goal; k++) {
const x = cam + FW / 2 - (goal * 2.2) / 2 + k * 2.2 + 1.1;
ctx.fillStyle = k < c.served ? "#ffd24a" : "rgba(220,220,230,0.28)";
disc(ctx, x, 8.6, 0.8);
ctx.strokeStyle = "rgba(20,12,8,0.6)";
ctx.lineWidth = 0.12;
ctx.beginPath();
ctx.arc(x, 8.6, 0.8, 0, TAU);
ctx.stroke();
}
}
}
const dim = () => 0;
/* -------------------------------------------------------------- lights */
function lights(v, add) {
const R = ride(v);
const round = v.round;
const c = state(v);
if (!R || !c) return;
const you = round.you;
const clock = v.clock;
const lo = round.camX - 10;
const hi = round.camX + FW + 10;
add(you.x + 2, you.y + 2.4, 10, 0.6);
R.checks.forEach((x, i) => {
if (x > lo && x < hi) add(x, (heightAt(R, x) ?? 10) + 5, i <= c.check ? 8 : 7, i <= c.check ? 0.6 : 0.5);
});
R.domes.forEach(([x, line, lift], i) => {
if (x > lo && x < hi && !c.domes[i]) add(x, (heightAt(R, x) ?? 10) + lift + 1.5, 4, 0.3);
});
R.plates.forEach(([x, line, lift], i) => {
if (x > lo && x < hi && !c.plates[i]) add(x, (heightAt(R, x) ?? 10) + lift + 1.4, 4, 0.3);
});
R.cooks.forEach(([x], i) => {
if (x > lo && x < hi && (c.cooks[i].state === "up" || c.cooks[i].state === "toss")) add(x, (heightAt(R, x) ?? 10) + 3, 5, 0.3);
});
R.lows.forEach(([x0, x1, y], i) => {
if (x1 > lo && x0 < hi) add((x0 + x1) / 2, y + 1, 6, 0.3 * (0.85 + 0.15 * Math.sin(clock / 200 + i)));
});
if (R.finish > lo - 24 && R.finish < hi) add(R.finish + 28, 22, 16, 0.6);
if (v.fx && v.fx.trayLand && v.fx.clock - v.fx.trayLand.t0 < 260) add(you.x, you.y + 1, 6, 0.4);
}
/* -------------------------------------------------------------- events */
// A throttle on a repeating cue.
function gateOnce(fx, key, ms) {
if ((fx[key] || 0) > fx.clock) return false;
fx[key] = fx.clock + ms;
return true;
}
// China and tin flying out of a spot.
function splinter(fx, x, y, colors) {
fx.trayBits = (fx.trayBits || []).filter((b) => fx.clock - b.t0 < 1000);
for (let k = 0; k < 9; k++) fx.trayBits.push({ x, y, t0: fx.clock, vx: (rnd(k, 1) - 0.5) * 22, vy: 8 + rnd(k, 2) * 14, rot: rnd(k, 3) * TAU, vr: (rnd(k, 4) - 0.5) * 22, w: 0.5 + rnd(k, 5) * 0.9, c: colors[k % colors.length] });
}
// What the pack's events look and sound like; true when the event is its own. Each of its
// sounds plays once, from EVENT_VOICE.
function react(e, k) {
const { shake, flash, burst, float, ring, fx, tone } = k;
const voice = EVENT_VOICE[e.type];
if (!voice) return false;
if (e.type === "trayDuck" && !gateOnce(fx, "trayDuckMs", 160)) return true;
say(tone, voice[0], voice[1], 0.5);
switch (e.type) {
case "trayJump":
burst(e.x, e.y, CHINA, 5, 7, 300);
break;
case "trayLand":
fx.trayLand = { t0: fx.clock, big: Boolean(e.big) };
burst(e.x, e.y, SILVER, e.big ? 14 : 6, e.big ? 12 : 8, 360);
if (e.big) shake(200, 0.5);
break;
case "trayLaunch":
burst(e.x, e.y, SILVER, 12, 14, 380);
float(e.x, e.y + 5, e.last ? "Jump!" : "Whee!", GOLD, 2.2);
break;
case "trayCrash":
shake(320, 1);
flash("#ffe2b0", 200);
burst(e.x, e.y + 1, e.what === "pot" || e.what === "pans" ? COPPER : SILVER, 18, 17, 520);
burst(e.x, e.y + 1, "#f4f1e8", 8, 14, 360);
break;
case "trayCheck":
float(e.x, e.y + 5, "Checkpoint", GOLD, 2.2);
ring(e.x, e.y + 3, "#7dffa0", 1, 8, 500);
break;
case "trayFinish":
shake(260, 0.7);
burst(e.x, e.y, CHINA, e.big ? 22 : 14, 13, 560);
float(e.x, e.y + 5, e.served >= 7 ? "Seven courses!" : "Made it!", GOLD, 2.6);
break;
case "trayDome":
burst(e.x, e.y, SILVER, 10, 10, 420);
ring(e.x, e.y, "#cfe6ff", 1, 6, 400);
float(e.x, e.y + 3, `Course ${e.n}`, GOLD, 2);
break;
case "trayPlate":
burst(e.x, e.y, "#ffd0e0", 12, 12, 460);
splinter(fx, e.x, e.y, [CHINA, "#5a7ac8", "#ffd0e0"]);
float(e.x, e.y + 3, `Course ${e.n}`, GOLD, 2);
break;
case "trayCookUp":
burst(e.x, e.y + 1, "#cfe3f0", 6, 6, 400);
break;
case "trayToss":
burst(e.x, e.y, CHINA, 4, 6, 260);
break;
case "trayCookHit":
burst(e.x, e.y, "#cfe3f0", 14, 14, 480);
float(e.x, e.y + 3, `+${e.points}`, GOLD, 2);
break;
case "trayDishBreak":
burst(e.x, e.y, CHINA, 10, 12, 380);
splinter(fx, e.x, e.y, [CHINA, "#5a7ac8"]);
break;
default:
break;
}
return true;
}
return freeze({
looks: LOOKS,
backdrop,
ground,
shelf,
front,
moving,
dim,
monsters: freeze({}),
bosses: freeze({}),
missiles: freeze({}),
hazards: freeze({}),
powers: freeze({}),
lights,
react,
});
}
@@ -0,0 +1,496 @@
// Plan2Code Web Console - Ghoul Rush's Servants' Back Stairs, its rules: the East Wing's bonus round. YOU ride a huge silver serving tray down the cramped back stairs and through the steamy basement kitchens in one long clattering rush: jump the rolling pots, dropped cutlery and the gaps between flights, duck the swinging hams and hanging copper pans, shoot (or jump) the dishes the spectral cooks fling, and eat your way through the courses on the route, as a stage pack that ghoul.js plugs in.
//
// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it, handed a
// kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js (it borrows the
// Cart's track helpers). Pack fields used: `ride` (a hook that moves Planny himself, so no
// key walks him), `place` (Planny put down in a room) and `target` (a bolt strikes something
// that is no monster: the plates, the cooks and their dishes). It adds no monster, boss or
// hazard kind and draws NO random number. Its state is `round.runner` (the shared slot for a
// rolling bonus ride, with `id: "tray"`), and the room's `ride.runner` is "tray".
//
// THE ROOM (spec.ride, see ghoul-rooms.js):
//
// - `track`: polylines [x, y] the tray slides along (the sled's: a gap between two lines is a
// crack to jump, cause "tumble"). The route is 17 laps of a climb onto a pantry shelf (+0.28),
// a flat run along it and a flight of back stairs down (-0.17), each lap a little lower than
// the last; a gap between two lines is the gap between two flights. The last line ends on a
// rising lip (over RAMP_SLOPE) that launches the tray onto the dining table at `finish`.
// - `pots` [x, line, kind] (a rolling pot, kind 0, or a drop of cutlery, kind 1: POT_W by POT_H
// or CUTLERY_W by CUTLERY_H, JUMP), `lows` [x0, x1, y, kind] (a swinging ham, kind 0, or
// hanging copper pans, kind 1: the underside is y, to the roof, so DUCK it: 3.0 over the
// highest track under it), `cooks` [x, line] (a spectral cook who, when the tray is COOK_NEAR
// short of him, winds up COOK_WIND_MS and flings a dish that flies left at DISH_V at
// DISH_LO up: JUMP it, or shoot the cook, one bolt, or the dish itself),
// `domes` [x, line, lift] (a silver dome, DOME_W by DOME_H, lift over the track: run through
// it, a high one takes a jump), `plates` [x, line, lift] (a flying plate with a dessert,
// PLATE_W by PLATE_H: SHOOT it to catch the dessert), `grease` [x0, x1] (flat stretches
// where the tray picks up to GREASE_V), `checks`, `finish` and `time`. The room's `candy` are
// the cherries along the route.
//
// THE TWIST (the courses): every dome run through and every plate shot is a course
// (`round.runner.served`); SEVEN (COURSES_GOAL) is a full seven course meal and the grade's
// "acts" die. The cherries taken are the other die (CHERRY_SHARE of them: `perf.steady`). So
// the best ride is a hungry, aggressive one: jumping for the high domes, shooting plates on
// the way, over greased stretches that come quicker than the rest.
//
// THE TRAY (`round.runner`): { id, room, v, line, coyote, from, left, check, done, served,
// domes, plates, cooks, cherries, ... }. Planny rides at (you.x, you.y), always facing right.
// Speed `v` relaxes to TRAY_V (GREASE_V on a grease stretch) and is pushed by the slope
// (SLOPE_G), between TRAY_MIN and TRAY_MAX. Up jumps (TRAY_JUMP_V against TRAY_G: about 13
// high, 0.75 s, 33 across at TRAY_V), COYOTE_MS of grace; down ducks. A bolt flies parallel
// to the track (`s.off` keeps what he aimed).
//
// A hit costs one of the round's five hearts (ghoul-bonus.js), not a life; the tray rolls on,
// Planny blinking safe BONUS_SAFE_MS; the last heart gone ends the round with nothing. Causes:
// "pot", "cutlery", "ham", "pans", "dish", "tumble" (a fall). Every obstacle is a number for
// the grade (`perf.total`: pots, lows, cooks and cracks, each id once in `perf.hits`).
//
// WHAT THE ART READS: `spec.ride`, `round.runner` { v, line, check, done, served, domes
// [taken], plates [caught], cooks: [{ state "down" | "up" | "toss" | "spent" | "broken", t,
// dish: null | { x, y } }] }, `round.you`, the events in EVENTS.
import { linesAt, linesOf, slopeOf, trackY } from "./ghoul-cart.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
export const MONSTERS = freeze({});
// Every event this pack puts on the field, for the art and the sounds to answer.
export const EVENTS = freeze([
"trayJump", "trayLand", "trayLaunch", "trayDuck", "trayCrash", "trayCheck", "trayFinish",
"trayDome", "trayPlate", "trayCookUp", "trayToss", "trayCookHit", "trayDishBreak",
]);
// The tray. Speeds are units across a second, TRAY_G units a second squared.
export const TRAY_V = 44;
export const GREASE_V = 60;
export const TRAY_MIN = 28;
export const TRAY_MAX = 66;
export const SLOPE_G = 60;
export const RELAX = 1.5;
export const TRAY_JUMP_V = 74;
export const TRAY_G = 200;
export const COYOTE_MS = 100;
export const RAMP_SLOPE = 0.25;
export const RAMP_POP = 30;
export const LAND_TOL = 0.9;
export const BIG_LAND = 8;
export const DERAIL_Y = 3;
export const CAM_AHEAD = 10;
export const CAM_PER_V = 0.25;
// Obstacles.
export const POT_W = 2.8;
export const POT_H = 2.8;
export const CUTLERY_W = 4.6;
export const CUTLERY_H = 1.8;
export const COOK_W = 2.8;
export const COOK_H = 4.8;
export const COOK_NEAR = 58;
export const COOK_WIND_MS = 700;
export const COOK_STAY_MS = 1500;
export const DISH_V = 24;
export const DISH_W = 2.2;
export const DISH_H = 1.4;
export const DISH_LO = 1.6;
// The courses: a dome run through, a plate shot, a cook shot, and the points for each.
export const DOME_W = 2.8;
export const DOME_H = 2.4;
export const PLATE_W = 3.2;
export const PLATE_H = 2.8;
export const DOME_POINTS = 80;
export const PLATE_POINTS = 120;
export const COOK_POINTS = 150;
const SHOT_R = 0.5;
// The grade: a seven course meal is the acts die; the cherries are the steady die.
export const COURSES_GOAL = 7;
export const CHERRY_SHARE = 0.45;
// Notes for a bonus round that obstacle `id` cost a heart (once each).
function noteHit(round, id) {
const b = round.bonusRound;
if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id);
}
const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H);
const boxHit = (k, you, x, y0, w, h) => Math.abs(you.x - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0;
// The highest line under x, as [line, y], or null over a crack.
const topAt = (R, x) => linesAt(R, x)[0] || null;
// The tray's state in this round, or null (the shared slot may hold another ride's).
const mine = (round) => (round.runner && round.runner.id === "tray" ? round.runner : null);
// Whether x is on a greased stretch.
export const greasy = (R, x) => R.grease.some(([a, b]) => x >= a && x <= b);
// The highest line the tray, falling from `py` to `y` at `x`, crossed going down.
function landOn(R, x, py, y) {
for (const [line, ly] of linesAt(R, x)) if (py >= ly - LAND_TOL && y <= ly) return { line, y: ly };
return null;
}
// Where a tray in the air at (x, y) going up at vy and across at v lands, if it does not
// steer: { x, y, line } or null when it derails. The unit suite's measure of which gaps a jump clears.
export function flight(R, x, y, vy, v) {
const dt = 0.004;
for (let t = 0; t < 5; t += dt) {
const py = y;
vy = Math.max(-120, vy - TRAY_G * dt);
x += v * dt;
y += vy * dt;
if (vy <= 0) {
const f = landOn(R, x, py, y);
if (f) return { x, y: f.y, line: f.line };
}
if (y < DERAIL_Y) return null;
}
return null;
}
/* -------------------------------------------------------------- placing */
// A fresh set of the room's things. What was eaten or shot stays so (`old`, the tray of an earlier try).
function things(R, old) {
const was = (list, i, state) => (old && old.cooks[i] && old.cooks[i].state === state ? state : null);
return {
domes: R.domes.map((d, i) => Boolean(old && old.domes[i])),
plates: R.plates.map((p, i) => Boolean(old && old.plates[i])),
cooks: R.cooks.map((c, i) => ({ state: was("cooks", i, "broken") || "down", t: 0, dish: null })),
};
}
// Planny put down in the room: on the tray at the start of a ride, or at the last checkpoint
// passed after the last heart (the same room). Any other room: this ride's state goes.
function place(round, k) {
const R = round.spec.ride;
if (!R || R.runner !== "tray") {
if (mine(round)) round.runner = null;
return;
}
const old = mine(round);
const again = old && old.room === round.room;
const check = again ? old.check : -1;
const you = round.you;
const x = check >= 0 ? R.checks[check] : round.spec.start;
const top = topAt(R, x);
Object.assign(you, { x, y: top ? top[1] : you.y, vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 });
round.runner = { id: "tray", room: round.room, check, v: TRAY_V, line: top ? top[0] : -1, coyote: 0, from: you.y, left: top ? top[0] : 0, done: false, served: again ? old.served : 0, cherries: again ? old.cherries : 0, cherryMs: 0, ...things(R, again ? old : null) };
round.camLead = CAM_AHEAD;
const b = round.bonusRound;
if (b && !b.perf.total) {
b.perf.total = R.pots.length + R.lows.length + R.cooks.length + (R.track.length - 1);
b.perf.steady = false;
b.perf.goal = COURSES_GOAL;
}
}
/* ------------------------------------------------------------ the ride */
// After a tumble that cost a heart but not the ride: Planny and the tray go back onto the
// track nearest where they fell (the highest line under him, else the next one ahead) at TRAY_V.
function reseat(round, c, R) {
const you = round.you;
const under = topAt(R, you.x);
let line;
let x;
let y;
if (under) {
[line, y] = under;
x = you.x;
} else {
const ahead = linesOf(R)
.map((L, i) => ({ i, x0: L.x0 }))
.filter((L) => L.x0 > you.x)
.sort((a, b) => a.x0 - b.x0)[0];
line = ahead ? ahead.i : linesOf(R).length - 1;
x = ahead ? ahead.x0 + 2 : R.finish - 2;
y = trackY(R, line, x) ?? you.y;
}
Object.assign(you, { x, y, vy: 0, state: "run", shelf: -1, ducking: false, coyote: 0, drop: -1 });
Object.assign(c, { line, v: TRAY_V, coyote: 0, from: y });
}
// The grade's cherries: the souls taken against what is laid out; and the courses served so far.
function appetite(round, c) {
c.cherries = round.candy.reduce((n, got) => n + (got ? 1 : 0), 0);
const b = round.bonusRound;
if (b) {
b.perf.steady = c.cherries >= Math.ceil(CHERRY_SHARE * round.candy.length);
b.perf.acts = c.served;
}
}
// The tray's motion for one slice. Returns true once it has moved Planny (every slice of a
// ride); false outside a ride and once he has stepped out onto the dining table.
function ride(round, ms, k) {
const R = round.spec.ride;
const c = mine(round);
if (!R || R.runner !== "tray" || !c || c.done) return false;
const you = round.you;
const inp = round.input;
const dt = ms / 1000;
const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra });
// Already down on the table (set there, or past the lip some other way): the ride is over.
if (you.x >= R.finish && you.vy <= 0 && you.y <= k.groundAt(round.spec, you.x) + 0.01) return finish(round, c, R, k.groundAt(round.spec, you.x), k);
// A stomp's bounce (or anything else) lifts the tray off its line.
if (you.state === "air" && c.line >= 0) {
c.left = c.line;
c.line = -1;
c.coyote = 0;
c.from = you.y;
}
steerShots(round, R);
const want = inp.jump > 0;
if (c.line >= 0) {
// On the stairs or the shelf.
const slope = slopeOf(R, c.line, you.x);
const goal = greasy(R, you.x) ? GREASE_V : TRAY_V;
c.v = clamp(c.v + ((goal - c.v) * RELAX - SLOPE_G * slope) * dt, TRAY_MIN, TRAY_MAX);
const duck = Boolean(inp.down) && !want;
if (duck && !you.ducking) ev("trayDuck");
you.ducking = duck;
if (want) {
inp.jump = 0;
you.vy = TRAY_JUMP_V + slope * c.v;
Object.assign(c, { left: c.line, line: -1, coyote: 0, from: you.y });
you.state = "air";
you.ducking = false;
ev("trayJump", { v: c.v });
} else {
const L = linesOf(R)[c.line];
const nx = you.x + c.v * dt;
you.state = "run";
you.vy = 0;
if (nx >= L.x1) {
// Off the end of the line, on along its last slope.
const end = L.pts[L.pts.length - 1];
const rise = slopeOf(R, c.line, L.x1);
you.x = L.x1;
you.y = end[1];
const ramp = rise >= RAMP_SLOPE;
you.vy = rise * c.v + (ramp ? RAMP_POP : 0);
Object.assign(c, { left: c.line, line: -1, coyote: COYOTE_MS, from: you.y });
you.state = "air";
you.ducking = false;
if (ramp) ev("trayLaunch", { v: c.v, last: c.left === linesOf(R).length - 1 });
} else {
you.x = nx;
you.y = trackY(R, c.line, nx);
}
}
} else {
// In the air.
c.coyote = Math.max(0, c.coyote - ms);
if (want && c.coyote > 0) {
inp.jump = 0;
c.coyote = 0;
you.vy = TRAY_JUMP_V;
c.from = you.y;
ev("trayJump", { v: c.v });
}
const py = you.y;
you.vy = Math.max(-k.FALL_MAX, you.vy - TRAY_G * dt);
you.x += c.v * dt;
you.y += you.vy * dt;
you.ducking = false;
you.state = "air";
if (you.vy <= 0) {
const f = landOn(R, you.x, py, you.y);
if (f) {
you.y = f.y;
you.vy = 0;
you.state = "run";
c.line = f.line;
ev("trayLand", { big: c.from - f.y >= BIG_LAND });
c.from = f.y;
} else if (you.x >= R.finish) {
// Over the dining table at the end: down onto it, and the ride is over.
const g = k.groundAt(round.spec, you.x);
if (g > -Infinity && you.y <= g + 0.01) return finish(round, c, R, g, k);
}
}
}
// A press nothing took waits a moment for a landing, then goes.
if (want && inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms);
// Past the end of the world: a gap, or the edge of the table.
if (you.y < DERAIL_Y || k.groundAt(round.spec, you.x) > you.y + 0.5) {
noteHit(round, `k${c.left}`);
if (k.lose(round, "tumble") && round.phase === "play") reseat(round, c, R);
return true;
}
while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) {
c.check++;
ev("trayCheck", { n: c.check + 1 });
}
round.camLead = CAM_AHEAD + (c.v - TRAY_V) * CAM_PER_V;
c.cherryMs -= ms;
if (c.cherryMs <= 0) {
c.cherryMs = 400;
appetite(round, c);
}
eat(round, c, R, k);
if (obstacles(round, c, R, k)) return true;
creatures(round, c, R, ms);
return true;
}
// The ride is over: the tray halts on the table, the door opens, Planny walks out.
function finish(round, c, R, g, k) {
const you = round.you;
c.done = true;
c.restX = you.x;
Object.assign(you, { y: g, vy: 0, state: "run", shelf: -1, ducking: false });
round.hasKey = true;
round.camLead = 0;
appetite(round, c);
round.events.push({ type: "trayFinish", x: you.x, y: you.y, big: c.from - g >= BIG_LAND, served: c.served });
return false;
}
// A bolt flies parallel to the track under it, whatever way he aimed (`s.off`): the stairs are
// steep, and a level bolt would sail over everything on a descent.
function steerShots(round, R) {
for (const s of round.shots) {
if (s.arm || s.free) continue;
if (s.off === undefined) s.off = s.vy;
const top = topAt(R, s.x);
if (top) s.sl = slopeOf(R, top[0], s.x);
s.vy = s.vx * (s.sl ?? 0) + s.off;
}
}
// A course served: the points and the count.
function serve(round, c, type, x, y, points) {
c.served++;
round.score += points;
const b = round.bonusRound;
if (b) b.perf.acts = c.served;
round.events.push({ type, x, y, points, n: c.served, goal: COURSES_GOAL });
}
// The silver domes: run through one (a high one takes a jump) and it is a course.
function eat(round, c, R, k) {
const you = round.you;
R.domes.forEach(([x, line, lift], i) => {
if (c.domes[i] || Math.abs(you.x - x) > 4) return;
const y0 = trackY(R, line, x) + lift;
if (!boxHit(k, you, x, y0, DOME_W, DOME_H)) return;
c.domes[i] = true;
serve(round, c, "trayDome", x, y0 + DOME_H / 2, DOME_POINTS);
});
}
// What the tray runs into: a pot, a drop of cutlery, a ham or pans, a dish. Returns whether it cost a heart.
function obstacles(round, c, R, k) {
const you = round.you;
const hh = duckH(k, you);
for (const [i, [x0, x1, y, kind]] of R.lows.entries()) {
if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > y && k.struck(round, kind ? "pans" : "ham")) {
noteHit(round, `l${i}`);
round.events.push({ type: "trayCrash", what: kind ? "pans" : "ham", x: you.x, y: you.y + hh });
return true;
}
}
for (const [i, [x, line, kind]] of R.pots.entries()) {
if (Math.abs(you.x - x) > 6) continue;
if (boxHit(k, you, x, trackY(R, line, x), kind ? CUTLERY_W : POT_W, kind ? CUTLERY_H : POT_H) && k.struck(round, kind ? "cutlery" : "pot")) {
noteHit(round, `p${i}`);
round.events.push({ type: "trayCrash", what: kind ? "cutlery" : "pot", x, y: you.y });
return true;
}
}
for (const [i, cook] of c.cooks.entries()) {
const d = cook.dish;
if (!d || Math.abs(you.x - d.x) > 5) continue;
if (boxHit(k, you, d.x, d.y, DISH_W, DISH_H) && k.struck(round, "dish")) {
noteHit(round, `c${i}`);
round.events.push({ type: "trayCrash", what: "dish", x: d.x, y: d.y });
cook.dish = null;
return true;
}
}
return false;
}
// The cooks wake when the tray comes near, wind up and fling a dish back along the track.
function creatures(round, c, R, ms) {
const you = round.you;
const dt = ms / 1000;
R.cooks.forEach(([x, line], i) => {
const o = c.cooks[i];
const y = trackY(R, line, x);
if (o.state === "down") {
const ahead = x - you.x;
if (ahead < COOK_NEAR && ahead > -COOK_W) {
Object.assign(o, { state: "up", t: COOK_WIND_MS });
round.events.push({ type: "trayCookUp", x, y });
}
} else if (o.state === "up" || o.state === "toss") {
o.t -= ms;
if (o.t <= 0 && o.state === "up") {
Object.assign(o, { state: "toss", t: COOK_STAY_MS, dish: { x: x - 1.2, y: y + DISH_LO } });
round.events.push({ type: "trayToss", x, y: y + DISH_LO + 1 });
} else if (o.t <= 0) Object.assign(o, { state: "spent", t: 0 });
}
// A dish in flight, along the track it left, until it is behind the tray or far from its cook.
const d = o.dish;
if (d) {
d.x -= DISH_V * dt;
const ty = trackY(R, line, d.x);
if (ty !== null) d.y = ty + DISH_LO;
if (d.x < you.x - 10 || d.x < x - 110) o.dish = null;
}
});
}
/* ------------------------------------------------------------- targets */
// A bolt into something to shoot: a flying plate (a course), a cook winding up or flinging, a
// dish in the air. True when one took it (the bolt is spent).
function trayShot(round, s) {
const R = round.spec.ride;
const c = mine(round);
if (!R || R.runner !== "tray" || !c) return false;
const hit = (x, y0, w, h) => Math.abs(s.x - x) <= w / 2 + SHOT_R && s.y >= y0 - SHOT_R && s.y <= y0 + h + SHOT_R;
for (let i = 0; i < R.plates.length; i++) {
if (c.plates[i]) continue;
const [x, line, lift] = R.plates[i];
const y0 = trackY(R, line, x) + lift;
if (!hit(x, y0, PLATE_W, PLATE_H)) continue;
c.plates[i] = true;
serve(round, c, "trayPlate", x, y0 + PLATE_H / 2, PLATE_POINTS);
return true;
}
for (let i = 0; i < R.cooks.length; i++) {
const o = c.cooks[i];
const [x, line] = R.cooks[i];
const y = trackY(R, line, x);
if (o.dish && hit(o.dish.x, o.dish.y, DISH_W, DISH_H)) {
round.events.push({ type: "trayDishBreak", x: o.dish.x, y: o.dish.y });
o.dish = null;
return true;
}
if ((o.state === "up" || o.state === "toss") && hit(x, y, COOK_W, COOK_H)) {
Object.assign(o, { state: "broken", t: 0 });
round.score += COOK_POINTS;
round.events.push({ type: "trayCookHit", x, y: y + COOK_H / 2, points: COOK_POINTS });
return true;
}
}
return false;
}
export const TRAY = freeze({
id: "tray",
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
horde: freeze({}),
ride: freeze([ride]),
place: freeze([place]),
target: trayShot,
});
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,601 @@
// Plan2Code Web Console - Ghoul Rush's Torch Mob, its rules: Hollow End Village's bonus round. YOU steal a hay wagon and race out of the village down the cobbled road and over the old stone bridge with a torch-and-pitchfork mob on your heels: jump the barrels, crates, ditches and spooked horses, duck the washing lines and inn signs, shoot (or dodge) the pitchforks and torches the villagers hurl from the windows and roofs, and jump the collapsed bridge off its ramp, as a stage pack that ghoul.js plugs in.
//
// Modeled on the Coffin Sled (ghoul-sled.js: read its header first) and, like it, handed a
// kit `k` of ghoul.js's own helpers, so this file never imports ghoul.js (it borrows the
// cart's track helpers). Pack fields used: `ride` (a hook that moves Planny himself, so no
// key walks him), `place` (Planny put down in a room: a room set up or a respawn) and
// `target` (a bolt strikes something that is no monster: a hurled torch or pitchfork, a
// spooked horse). It adds no monster, boss or hazard kind, so there is nothing to merge by
// name, and it draws NO random number. Its state lives in `round.runner` (the slot the
// bonus rides share, null in any other room; `id` "wagon").
//
// THE TWIST: THE MOB. A pack of villagers and moonhounds runs behind the wagon, `gap`
// units back (GAP_START at the start, never over GAP_MAX). The mob runs at MOB_V, the wagon
// at its own speed, so a clean stretch (WAGON_V) wins ground and everything else loses it:
// DOWN held on the road (a duck, and the brake: BRAKE_V) slows the wagon, a hit shoves the
// mob HIT_CLOSE closer, a burning hay load draws it on (FIRE_BOOST) and its surge spans
// (`surge`, the bridge's run-up) quicken it. A torch or pitchfork shot out of the air pushes
// it back (TORCH_BACK, FORK_BACK, HORSE_BACK). Inside PANIC_ON the horses bolt (PANIC_V
// faster, until PANIC_OFF), which also carries the wagon further off a ramp. At CATCH_GAP
// the mob has you: a heart (cause "mob"), and it falls back to GAP_RESET. A torch that
// lands on the wagon is a heart (cause "torch") and sets the hay alight for FIRE_MS (the
// mob closes faster for as long, ducking on the hay smothers it SMOTHER times quicker).
//
// THE ROOM (spec.ride, see ghoul-rooms.js; `runner: "wagon"` marks it a ride room that the
// Cart's `place` leaves alone):
//
// - `track`: polylines [x, y] the wagon's deck rides, one per stretch of road; a gap between
// two lines is a DITCH or the collapsed bridge (jump it: the wagon flies on along its last
// slope, drops, and a fall below DERAIL_Y is a heart, cause "ditch", or "river" in
// `bridge`). A line ending rising at over RAMP_SLOPE launches (RAMP_POP): the bridge's ramp
// and the lip at the end (`finish`, where the gate and the green begin, lower).
// - `blocks` [x, line, kind] (kind 0 a barrel, 1 a crate: BARREL_W/CRATE_W by BLOCK_H, jump;
// smashed on a hit), `lows` [x0, x1, y, kind] (a washing line, kind 0, or an inn sign,
// kind 1: its underside is y, from there up, so DUCK it; y is 3.0 over the road under it),
// `throwers` [x, line, kind] (a villager in a window or on a roof at x: kind 0 hurls a
// pitchfork at chest height, DUCK it, kind 1 lobs a torch at the hay, JUMP it; either can
// be shot; he winds up WIND_MS once the wagon is WIND_NEAR short, then throws at where the
// wagon will be, PROJ_V fast: it meets a wagon at WAGON_V THROW_MEET short of him),
// `horses` [x, line] (a spooked horse: it rears HORSE_REAR_MS once the wagon is HORSE_NEAR
// short, then charges at HORSE_V, HORSE_W by HORSE_H over the road: jump it, or shoot it
// HORSE_HP times to turn it back), `checks`, `surge` ([x0, x1, extra] spans where the mob
// runs extra units a second faster), `bridge` ([x0, x1], the stone bridge, for the art),
// `finish` and `time` (the room's clock, ms).
// - The ground is the start's cobbles and the green's grass at the end only.
//
// THE WAGON (`round.runner`): { id, room, v, line, coyote, from, left, check, done, gap,
// panic, fireMs, catches, ... }. Planny rides at (you.x, you.y), facing right (`you.state`
// "run" on the road, "air" off it, `you.ducking` ducked on the hay). Up jumps (WAGON_JUMP_V
// against WAGON_G: about 7 high, 0.6 s, 26 across at WAGON_V), COYOTE_MS of grace off a
// line's end; down ducks and brakes; no key steers. A hit costs one of the round's five
// hearts (ghoul-bonus.js), not a life, and the wagon rolls on, Planny blinking safe
// BONUS_SAFE_MS; the last heart gone ends the round with nothing, at once. A derail puts it
// back on the road ahead. Causes: "barrel", "crate", "wash", "sign", "fork", "torch",
// "horse", "ditch", "river", "mob". Every obstacle is a number for the grade (`perf.total`,
// each id once in `perf.hits` if it ever cost a heart; a catch adds one of its own). Shooting
// a torch, a pitchfork or a horse is an act (ACTS_GOAL of them for the die). The steady die
// is the mob kept far: the gap's average over the ride at least STEADY_GAP.
//
// Checkpoints are passed at their x (`wagonCheck`); a restart after the last heart goes
// back to the last one passed (that ends the round, as the cart's does).
//
// WHAT THE ART READS: `spec.ride` (above), `round.runner` { v, line, gap, panic, fireMs,
// check, done, throwers: [{ state "idle"|"wind"|"spent", t }], props: [{ kind, x, y, s,
// dead }], horses: [{ state "wait"|"rear"|"run"|"hit"|"fled", t, x, hp }], smashed: [bool] },
// `round.you` (`state`, `vy`, `ducking`), the events in EVENTS.
import { linesAt, linesOf, slopeOf, trackY } from "./ghoul-cart.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
export const MONSTERS = freeze({});
// Every event this pack puts on the field, for the art and the sounds to answer.
export const EVENTS = freeze([
"wagonJump", "wagonLand", "wagonLaunch", "wagonBrake", "wagonCrash", "wagonCheck", "wagonFinish",
"wagonWind", "wagonThrow", "wagonShot", "wagonEmber", "wagonCatch", "wagonPanic", "wagonFire", "wagonOut",
"wagonRear", "wagonHorseHit", "wagonHorseTurn",
]);
// The wagon. Speeds are units across a second, WAGON_G units a second squared.
export const WAGON_V = 42;
export const BRAKE_V = 20;
export const PANIC_V = 9;
export const RELAX = 5;
export const WAGON_JUMP_V = 46;
export const WAGON_G = 150;
export const COYOTE_MS = 100;
export const RAMP_SLOPE = 0.25;
export const RAMP_POP = 22;
export const LAND_TOL = 0.9;
export const BIG_LAND = 8;
export const DERAIL_Y = 3;
// The camera sits this far behind its usual spot, so the mob shows at the left edge.
export const CAM_LEAD = -15;
// How far in front of Planny the wagon's nose (and the horse's chest) meets a barrel or a horse.
export const REACH = 3;
// The mob.
export const MOB_V = 40;
export const GAP_START = 24;
export const GAP_MAX = 32;
export const GAP_RESET = 20;
export const CATCH_GAP = 6.5;
export const PANIC_ON = 14;
export const PANIC_OFF = 19;
export const HIT_CLOSE = 10;
export const TORCH_BACK = 6;
export const FORK_BACK = 3;
export const HORSE_BACK = 4;
export const FIRE_MS = 3200;
export const FIRE_BOOST = 8;
export const SMOTHER = 3;
export const STEADY_GAP = 20;
// Obstacles.
export const BARREL_W = 2.6;
export const CRATE_W = 3.4;
export const BLOCK_H = 3.4;
export const HORSE_W = 4.6;
export const HORSE_H = 4.2;
export const HORSE_HP = 3;
export const HORSE_NEAR = 62;
export const HORSE_REAR_MS = 500;
export const HORSE_V = 26;
export const HORSE_FLEE_V = 48;
// The throwers: wound up WIND_MS once the wagon is WIND_NEAR short, the throw aimed at where
// the wagon will be, PROJ_V fast. A pitchfork flies down to chest height (FORK_Y over the deck)
// from the sill (SILL_Y), a torch lobs from the roof (ROOF_Y) to the hay (TORCH_Y).
export const WIND_NEAR = 62;
export const WIND_MS = 550;
export const PROJ_V = 40;
export const THROW_MEET = 19;
export const FORK_Y = 3.2;
export const FORK_HALF_W = 1.6;
export const FORK_TOL = 0.4;
export const TORCH_Y = 1.6;
export const SILL_Y = 8.5;
export const ROOF_Y = 11;
export const LOB = 3.5;
export const HAY_BACK = 4.5;
export const HAY_FRONT = 1.2;
export const HAY_H = 3;
export const BOLT_R = 0.5;
export const PROP_HIT = 1.3;
export const TORCH_POINTS = 60;
export const FORK_POINTS = 40;
export const HORSE_POINTS = 120;
// The things shot out of the air (or turned back) that are worth a die.
export const ACTS_GOAL = 8;
// Notes for a bonus round that obstacle `id` cost a heart (once each).
function noteHit(round, id) {
const b = round.bonusRound;
if (b && !b.perf.hits.includes(id)) b.perf.hits.push(id);
}
const duckH = (k, you) => (you.ducking ? k.DUCK_H : k.HIT_H);
const boxHit = (k, cx, you, x, y0, w, h) => Math.abs(cx - x) < (k.HIT_W + w) / 2 && you.y < y0 + h && you.y + duckH(k, you) > y0;
// The highest line under x, as [line, y], or null over a gap.
const topAt = (R, x) => linesAt(R, x)[0] || null;
// The mob's extra speed at x (the surge spans).
export function surgeAt(R, x) {
for (const [x0, x1, extra] of R.surge || []) if (x >= x0 && x <= x1) return extra;
return 0;
}
// The highest line the wagon, falling from `py` to `y` at `x`, crossed going down.
function landOn(R, x, py, y) {
for (const [line, ly] of linesAt(R, x)) if (py >= ly - LAND_TOL && y <= ly) return { line, y: ly };
return null;
}
// Where a wagon in the air at (x, y) going up at vy and across at v lands, if nothing changes:
// { x, y, line } or null when it derails. The unit suite's measure of which gaps a jump clears.
export function flight(R, x, y, vy, v) {
const dt = 0.004;
for (let t = 0; t < 5; t += dt) {
const py = y;
vy = Math.max(-120, vy - WAGON_G * dt);
x += v * dt;
y += vy * dt;
if (vy <= 0) {
const f = landOn(R, x, py, y);
if (f) return { x, y: f.y, line: f.line };
}
if (y < DERAIL_Y) return null;
}
return null;
}
// Where a throw flies, at time fraction s (0 at the window, 1 where it meets the wagon):
// a pitchfork on a straight line down to chest height that goes on past it level (so a wagon slowed
// by the brake still meets it at chest height), a torch on a lob that ends there.
export function propAt(p, s) {
const x = p.x0 + (p.x1 - p.x0) * s;
const y = p.y0 + (p.y1 - p.y0) * (p.kind ? s : Math.min(1, s)) + (p.kind === 1 ? LOB * 4 * s * (1 - s) : 0);
return { x, y };
}
/* -------------------------------------------------------------- placing */
// A fresh set of the room's things: every thrower still, every horse waiting.
function things(R) {
return {
throwers: R.throwers.map(() => ({ state: "idle", t: 0 })),
horses: R.horses.map((h) => ({ state: "wait", t: 0, x: h[0], hp: HORSE_HP })),
smashed: R.blocks.map(() => false),
props: [],
};
}
// Planny put down in the room: on the wagon at the start of a ride, or at the last
// checkpoint passed after the last heart (the same room).
function place(round, k) {
const R = round.spec.ride;
if (!R || R.runner !== "wagon") {
if (round.runner && round.runner.id === "wagon") round.runner = null;
return;
}
const again = round.runner && round.runner.id === "wagon" && round.runner.room === round.room;
const check = again ? round.runner.check : -1;
const you = round.you;
const x = check >= 0 ? R.checks[check] : round.spec.start;
const top = topAt(R, x);
Object.assign(you, { x, y: top ? top[1] : you.y, vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 });
round.runner = { id: "wagon", room: round.room, check, v: WAGON_V, line: top ? top[0] : -1, coyote: 0, from: you.y, left: top ? top[0] : 0, done: false, gap: GAP_START, panic: false, fireMs: 0, braking: false, catches: again ? round.runner.catches : 0, gapMs: 0, gapSum: 0, ...things(R) };
round.camLead = CAM_LEAD;
const b = round.bonusRound;
if (b && !b.perf.total) {
b.perf.total = R.blocks.length + R.lows.length + R.throwers.length + R.horses.length + (R.track.length - 1);
b.perf.steady = true;
b.perf.goal = ACTS_GOAL;
}
}
/* ------------------------------------------------------------ the ride */
// After a derail that cost a heart but not the ride: Planny and the wagon go back onto the
// road nearest where they fell (the highest line under him, else the next one ahead) at
// WAGON_V. He blinks safe (ghoul.js's takeLife).
function reseat(round, c, R) {
const you = round.you;
const under = topAt(R, you.x);
let line;
let x;
let y;
if (under) {
[line, y] = under;
x = you.x;
} else {
const ahead = linesOf(R)
.map((L, i) => ({ i, x0: L.x0 }))
.filter((L) => L.x0 > you.x)
.sort((a, b) => a.x0 - b.x0)[0];
line = ahead ? ahead.i : linesOf(R).length - 1;
x = ahead ? ahead.x0 + 2 : R.finish - 2;
y = trackY(R, line, x) ?? you.y;
}
Object.assign(you, { x, y, vy: 0, state: "run", shelf: -1, ducking: false, coyote: 0, drop: -1 });
Object.assign(c, { line, v: WAGON_V, coyote: 0, from: y });
}
// The grade's steady die: the mob kept far, the gap's average over the ride so far.
function steadiness(round, c) {
const b = round.bonusRound;
if (b && c.gapMs > 0) b.perf.steady = c.gapSum / c.gapMs >= STEADY_GAP;
}
// The wagon's motion for one slice. Returns true once it has moved Planny (every slice
// of a ride); false outside a ride and once he has stepped out onto the green.
function ride(round, ms, k) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "wagon" || !c || c.id !== "wagon" || c.done) return false;
const you = round.you;
const inp = round.input;
const dt = ms / 1000;
const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra });
// Already down on the green (set there, or past the lip some other way): the ride is over.
if (you.x >= R.finish && you.vy <= 0 && you.y <= k.groundAt(round.spec, you.x) + 0.01) return finish(round, c, R, k.groundAt(round.spec, you.x), k);
// A stomp's bounce (or anything else) lifts the wagon off its line.
if (you.state === "air" && c.line >= 0) {
c.left = c.line;
c.line = -1;
c.coyote = 0;
c.from = you.y;
}
const want = inp.jump > 0;
if (c.line >= 0) {
// On the road: the mob's pull and the brake set the speed.
const brake = Boolean(inp.down) && !want;
if (brake && !c.braking) ev("wagonBrake");
c.braking = brake;
const target = brake ? BRAKE_V : WAGON_V + (c.panic ? PANIC_V : 0);
c.v += (target - c.v) * Math.min(1, RELAX * dt);
you.ducking = brake;
if (want) {
inp.jump = 0;
you.vy = WAGON_JUMP_V;
Object.assign(c, { left: c.line, line: -1, coyote: 0, from: you.y, braking: false });
you.state = "air";
you.ducking = false;
ev("wagonJump", { v: c.v });
} else {
const L = linesOf(R)[c.line];
const nx = you.x + c.v * dt;
you.state = "run";
you.vy = 0;
if (nx >= L.x1) {
// Off the end of the line, on along its last slope.
const end = L.pts[L.pts.length - 1];
const rise = slopeOf(R, c.line, L.x1);
you.x = L.x1;
you.y = end[1];
const ramp = rise >= RAMP_SLOPE;
you.vy = rise * c.v + (ramp ? RAMP_POP : 0);
Object.assign(c, { left: c.line, line: -1, coyote: COYOTE_MS, from: you.y, braking: false });
you.state = "air";
you.ducking = false;
if (ramp) ev("wagonLaunch", { v: c.v, last: c.left === linesOf(R).length - 1 });
} else {
you.x = nx;
you.y = trackY(R, c.line, nx);
}
}
} else {
// In the air: the speed it left with.
c.coyote = Math.max(0, c.coyote - ms);
if (want && c.coyote > 0) {
inp.jump = 0;
c.coyote = 0;
you.vy = WAGON_JUMP_V;
c.from = you.y;
ev("wagonJump", { v: c.v });
}
const py = you.y;
you.vy = Math.max(-k.FALL_MAX, you.vy - WAGON_G * dt);
you.x += c.v * dt;
you.y += you.vy * dt;
you.ducking = false;
c.braking = false;
you.state = "air";
if (you.vy <= 0) {
const f = landOn(R, you.x, py, you.y);
if (f) {
you.y = f.y;
you.vy = 0;
you.state = "run";
c.line = f.line;
ev("wagonLand", { big: c.from - f.y >= BIG_LAND });
c.from = f.y;
} else if (you.x >= R.finish) {
// Over the green at the end: down onto it, and the ride is over.
const g = k.groundAt(round.spec, you.x);
if (g > -Infinity && you.y <= g + 0.01) return finish(round, c, R, g, k);
}
}
}
// A press nothing took waits a moment for a landing, then goes.
if (want && inp.jump > 0) inp.jump = Math.max(0, inp.jump - ms);
// Past the end of the world: a ditch, or the river under the bridge.
if (you.y < DERAIL_Y || k.groundAt(round.spec, you.x) > you.y + 0.5) {
const river = R.bridge && you.x >= R.bridge[0] && you.x <= R.bridge[1];
noteHit(round, `k${c.left}`);
if (k.lose(round, river ? "river" : "ditch") && round.phase === "play") reseat(round, c, R);
return true;
}
while (c.check + 1 < R.checks.length && you.x >= R.checks[c.check + 1]) {
c.check++;
ev("wagonCheck", { n: c.check + 1 });
}
round.camLead = CAM_LEAD;
if (obstacles(round, c, R, k)) return true;
creatures(round, c, R, ms, k);
if (flying(round, c, R, ms, k)) return true;
mob(round, c, R, ms, k);
return true;
}
// The ride is over: the wagon halts on the green, the door opens, Planny walks out.
function finish(round, c, R, g, k) {
const you = round.you;
c.done = true;
c.restX = you.x;
Object.assign(you, { y: g, vy: 0, state: "run", shelf: -1, ducking: false });
round.hasKey = true;
round.camLead = 0;
steadiness(round, c);
round.events.push({ type: "wagonFinish", x: you.x, y: you.y, big: c.from - g >= BIG_LAND });
return false;
}
// A hit that took a heart: the mob closes, the cause is noted for the grade.
function hurt(round, c, k, cause, id, extra) {
if (!k.struck(round, cause)) return false;
noteHit(round, id);
c.gap = Math.max(CATCH_GAP + 1, c.gap - HIT_CLOSE);
round.events.push({ type: "wagonCrash", cause, x: round.you.x, y: round.you.y, ...extra });
return true;
}
// What the wagon runs into: a barrel or crate, a washing line or an inn sign, a charging horse.
// Returns whether it cost a heart.
function obstacles(round, c, R, k) {
const you = round.you;
const hh = duckH(k, you);
const cx = you.x + REACH;
for (const [i, [x0, x1, y, kind]] of R.lows.entries()) {
if (you.x > x0 - k.HIT_W / 2 && you.x < x1 + k.HIT_W / 2 && you.y + hh > y && hurt(round, c, k, kind ? "sign" : "wash", `l${i}`, { what: "low", y: you.y + hh })) return true;
}
for (const [i, [x, line, kind]] of R.blocks.entries()) {
if (c.smashed[i] || Math.abs(cx - x) > 6) continue;
if (boxHit(k, cx, you, x, trackY(R, line, x), kind ? CRATE_W : BARREL_W, BLOCK_H) && hurt(round, c, k, kind ? "crate" : "barrel", `b${i}`, { what: "block", x, kind })) {
c.smashed[i] = true;
return true;
}
}
for (const [i, h] of c.horses.entries()) {
if (h.state !== "run") continue;
const y = trackY(R, R.horses[i][1], h.x);
if (y !== null && boxHit(k, cx, you, h.x, y, HORSE_W, HORSE_H) && hurt(round, c, k, "horse", `h${i}`, { what: "horse", x: h.x })) {
h.state = "hit";
h.t = 600;
return true;
}
}
return false;
}
// The throwers wind up and throw; the horses rear and charge.
function creatures(round, c, R, ms, k) {
const you = round.you;
R.throwers.forEach(([x, line, kind], i) => {
const t = c.throwers[i];
const y = trackY(R, line, x) ?? you.y;
if (t.state === "idle") {
const ahead = x - you.x;
if (ahead < WIND_NEAR && ahead > 4) {
Object.assign(t, { state: "wind", t: WIND_MS });
round.events.push({ type: "wagonWind", x, y: y + (kind ? ROOF_Y : SILL_Y), kind });
}
} else if (t.state === "wind") {
t.t -= ms;
if (t.t > 0) return;
t.state = "spent";
// Aimed at where the wagon will be when the throw gets there.
const d = Math.max(1, x - you.x);
const tm = d / (c.v + PROJ_V);
const mx = you.x + c.v * tm;
const my = (topAt(R, mx) || [0, you.y])[1];
const p = { kind, x0: x, y0: y + (kind ? ROOF_Y : SILL_Y), x1: mx, y1: my + (kind ? TORCH_Y : FORK_Y), T: tm, t: 0, s: 0, dead: false, age: 0, id: i };
c.props.push(p);
round.events.push({ type: "wagonThrow", x, y: p.y0, kind });
}
});
c.horses.forEach((h, i) => {
const [hx, line] = R.horses[i];
if (h.state === "wait") {
const ahead = hx - you.x;
if (ahead < HORSE_NEAR && ahead > 0) {
Object.assign(h, { state: "rear", t: HORSE_REAR_MS });
round.events.push({ type: "wagonRear", x: hx, y: trackY(R, line, hx) });
}
} else if (h.state === "rear") {
h.t -= ms;
if (h.t <= 0) Object.assign(h, { state: "run", t: 0 });
} else if (h.state === "run" || h.state === "fled") {
h.x -= (h.state === "run" ? HORSE_V : HORSE_FLEE_V) * (ms / 1000);
if (h.x < you.x - 14 || trackY(R, line, h.x) === null) h.state = "gone";
} else if (h.state === "hit") {
h.t -= ms;
h.x -= HORSE_V * (ms / 1000);
if (h.t <= 0) h.state = "gone";
}
});
}
// The hurled torches and pitchforks in flight: one that reaches the wagon is a heart (a torch
// also sets the hay alight); a torch lands where it is aimed and burns out; a fork goes on.
// Returns whether the wagon was hit.
function flying(round, c, R, ms, k) {
const you = round.you;
const hh = duckH(k, you);
let hit = false;
for (const p of c.props) {
if (p.dead) {
p.age += ms;
continue;
}
p.t += ms / 1000;
p.s = p.t / p.T;
const { x, y } = propAt(p, p.kind ? Math.min(1, p.s) : p.s);
p.x = x;
p.y = y;
if (!hit) {
const on = p.kind
? x > you.x - HAY_BACK && x < you.x + HAY_FRONT && y > you.y - 0.2 && y < you.y + HAY_H
: Math.abs(x - you.x) < k.HIT_W / 2 + FORK_HALF_W && y > you.y - FORK_TOL && y < you.y + hh;
if (on && hurt(round, c, k, p.kind ? "torch" : "fork", `t${p.id}`, { what: p.kind ? "torch" : "fork" })) {
p.dead = true;
hit = true;
if (p.kind) {
c.fireMs = FIRE_MS;
round.events.push({ type: "wagonFire", x: you.x, y: you.y });
}
continue;
}
}
if (p.kind && p.s >= 1) {
p.dead = true;
round.events.push({ type: "wagonEmber", x, y });
} else if (!p.kind && (p.s > 1.8 || y < -2)) p.dead = true;
}
c.props = c.props.filter((p) => !p.dead || p.age < 500);
return hit;
}
// The mob: its gap, the panic, the hay fire and the grade's steady die, and a catch at CATCH_GAP.
function mob(round, c, R, ms, k) {
const you = round.you;
const dt = ms / 1000;
const ev = (type, extra = {}) => round.events.push({ type, x: you.x, y: you.y, ...extra });
if (c.fireMs > 0) {
c.fireMs -= ms * (you.ducking && c.line >= 0 ? SMOTHER : 1);
if (c.fireMs <= 0) {
c.fireMs = 0;
ev("wagonOut");
}
}
const mobV = MOB_V + surgeAt(R, you.x) + (c.fireMs > 0 ? FIRE_BOOST : 0);
c.gap = clamp(c.gap + (c.v - mobV) * dt, 0, GAP_MAX);
if (!c.panic && c.gap < PANIC_ON) {
c.panic = true;
ev("wagonPanic");
} else if (c.panic && c.gap >= PANIC_OFF) c.panic = false;
c.gapMs += ms;
c.gapSum += c.gap * ms;
steadiness(round, c);
if (c.gap > CATCH_GAP) return;
c.gap = GAP_RESET;
c.panic = false;
c.catches++;
noteHit(round, `m${c.catches}`);
ev("wagonCatch");
k.struck(round, "mob");
}
/* ------------------------------------------------------------- targets */
// A bolt into something to shoot: a torch or pitchfork in the air, a horse. True when one
// took it (the bolt is spent).
function wagonShot(round, s) {
const R = round.spec.ride;
const c = round.runner;
if (!R || R.runner !== "wagon" || !c || c.id !== "wagon") return false;
const score = (n) => {
round.score += n;
if (round.bonusRound) round.bonusRound.perf.acts++;
};
for (const p of c.props) {
if (p.dead || p.x === undefined) continue;
if (Math.abs(s.x - p.x) > PROP_HIT + BOLT_R || Math.abs(s.y - p.y) > PROP_HIT + BOLT_R) continue;
p.dead = true;
const pts = p.kind ? TORCH_POINTS : FORK_POINTS;
score(pts);
c.gap = Math.min(GAP_MAX, c.gap + (p.kind ? TORCH_BACK : FORK_BACK));
round.events.push({ type: "wagonShot", x: p.x, y: p.y, kind: p.kind, points: pts });
return true;
}
for (let i = 0; i < c.horses.length; i++) {
const h = c.horses[i];
if (h.state !== "run" && h.state !== "rear") continue;
const y = trackY(R, R.horses[i][1], h.x);
if (y === null || Math.abs(s.x - h.x) > HORSE_W / 2 + BOLT_R || s.y < y - BOLT_R || s.y > y + HORSE_H + BOLT_R) continue;
h.hp--;
if (h.hp > 0) round.events.push({ type: "wagonHorseHit", x: h.x, y: y + HORSE_H / 2 });
else {
h.state = "fled";
score(HORSE_POINTS);
c.gap = Math.min(GAP_MAX, c.gap + HORSE_BACK);
round.events.push({ type: "wagonHorseTurn", x: h.x, y: y + HORSE_H / 2, points: HORSE_POINTS });
}
return true;
}
return false;
}
export const WAGON = freeze({
id: "wagon",
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
horde: freeze({}),
ride: freeze([ride]),
place: freeze([place]),
target: wagonShot,
});