Move Ghoul Rush into activities/ghoul-rush/ and split ghoul.js

Every Ghoul Rush file moves under activities/ghoul-rush/, sorted into core,
arms, draw, story, sfx, stages/<stage> and rides/<ride>, with names unchanged.
ghoul.js is now a facade over seven parts in core/, taking it from over the
3,000 line cap to 50 lines.

Also in this tree: the Drowned Lantern replaces the Bog Runner, the "Use a
Lucky Die?" question, the Old Mother Bog rework, Rapid fire at 60 ms, the
rules for the finale's first kill (not plugged in yet), and small fixes the
suites asked for (the Stilt House's and Drowning Pool's weapons).

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-03 15:18:09 -08:00
1 parent 0454bdd19a
commit 903fbf5680
160 files changed
+11022 -7061

No files matched your search

+1 -1
View File
@@ -43,7 +43,7 @@ export const ACTIVITIES = Object.freeze([
entry("fuse", "Hot Potato", "Pass the bomb before it blows. Last one standing wins."),
entry("hop", "Crossing Rush", "Hop through traffic and rivers. Race your rivals to the top."),
entry("bounce", "Bounce Road", "Ten wild stages of toy-car mayhem. Jump, stomp and outrun the Monster truck."),
entry("ghoul", "Ghoul Rush", "Run and gun through a pitch-dark haunted house. Keep moving.", { music: 65 }),
entry("ghoul", "Ghoul Rush", "Run and gun through a pitch-dark haunted house. Keep moving.", { music: 65, module: "/activities/ghoul-rush/ghoul.js" }),
]);
const cap = (word) => word[0].toUpperCase() + word.slice(1);
@@ -1,496 +0,0 @@
// 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 }),
});
@@ -1,949 +0,0 @@
// 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,
});
}
@@ -1,420 +0,0 @@
// 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,
});
@@ -6,7 +6,7 @@
// `shot`, drawing a thrown weapon in `round.shots` (drawShots hands it any shot
// with `arm`), and `pill`, the HUD's icon, count and the "TAP TAP" prompt.
import { pillInk, PILL } from "./pills.js";
import { pillInk, PILL } from "../../pills.js";
import { panAngle, panRadius } from "./ghoul-pans.js";
import { rocketArt } from "./ghoul-rockets-draw.js";
@@ -48,7 +48,7 @@
// but never wins the fight. No fight needs one. If a boss is at half hp and your
// bag is empty, one of its stage's weapons falls near you, once a fight.
import { ARM_POP_MS, POWERS, STAGE_ARMS, addArm } from "./ghoul-powers.js";
import { ARM_POP_MS, POWERS, STAGE_ARMS, addArm } from "../core/ghoul-powers.js";
import { stepPans, usePans } from "./ghoul-pans.js";
import { FLARE_VX, FLARE_VY, stepFlareFly, stepRoadFire, useFlare } from "./ghoul-flare.js";
import { stepBoom, stepMuzzle, stepRocket, useRockets } from "./ghoul-rockets.js";
@@ -238,7 +238,7 @@ export const armOnTop = (round) => (round.spec.ride ? round.arms.find((a) => !NE
// Whether a weapon can come out just now: not while frozen, held, thrown or down.
export function canUseArm(round) {
const you = round.you;
return round.phase === "play" && you.out <= 0 && !(round.stunMs > 0) && !(you.heldMs > 0) && !(you.flingMs > 0) && !you.lift && !(round.armCool > 0) && Boolean(armOnTop(round));
return round.phase === "play" && you.out <= 0 && !(round.runner && round.runner.id === "lantern") && !(round.stunMs > 0) && !(you.heldMs > 0) && !(you.flingMs > 0) && !you.lift && !(round.armCool > 0) && Boolean(armOnTop(round));
}
// The top of the bag, used. Bolts held through it pick up ARM_GAP_MS later.
@@ -286,9 +286,12 @@ function armShot(round, k, arm, speed, over) {
export const LOB_GROUP = 9;
const LOB_MIN_VX = 6;
const LOB_MAX_VX = 70;
// Grave Salt aims this far ahead of a monster along the way it walks, so the line
// lands where it will be, not where it was.
export const SALT_LEAD = 3;
// `also` names kinds that count though they cannot be shot (the buried hands the salt is for).
export function lobTarget(round, k, also = []) {
export function lobTarget(round, k, also = [], lead = 0) {
const you = round.you;
const lo = round.camX;
const hi = round.camX + k.FIELD_W;
@@ -298,11 +301,11 @@ export function lobTarget(round, k, also = []) {
if (!ahead.length) return null;
const first = ahead[0];
const group = ahead.filter((m) => Math.abs(m.x - first.x) <= LOB_GROUP);
return group.reduce((sum, m) => sum + m.x, 0) / group.length;
return group.reduce((sum, m) => sum + m.x + (m.dir || -you.face) * lead, 0) / group.length;
}
export function lobVx(round, k, vy, fixed, also) {
const tx = lobTarget(round, k, also);
export function lobVx(round, k, vy, fixed, also, lead = 0) {
const tx = lobTarget(round, k, also, lead);
if (tx === null) return round.you.face * fixed;
const at = hand(round, k);
const dy = k.groundAt(round.spec, tx) - at.y;
@@ -323,7 +326,7 @@ function lobStick(round, k) {
function lobPod(round, k, pay, aimed = false) {
const you = round.you;
const at = hand(round, k);
round.hazards.push({ kind: "armPod", pay, x: at.x, y: at.y, vx: aimed ? lobVx(round, k, POD_VY, POD_VX, ["hands"]) : you.face * POD_VX, vy: POD_VY, spin: 0, w: 0.8, h: 0.8, live: 0, cause: "" });
round.hazards.push({ kind: "armPod", pay, x: at.x, y: at.y, vx: aimed ? lobVx(round, k, POD_VY, POD_VX, ["hands"], pay === "salt" ? SALT_LEAD : 0) : you.face * POD_VX, vy: POD_VY, spin: 0, w: 0.8, h: 0.8, live: 0, cause: "" });
}
function lobPie(round, k) {
@@ -65,7 +65,7 @@ export function bonusArt(d, die) {
const face = landed ? 6 : 1 + (Math.floor(since / 60) + i) % 5;
die(ctx, x0 + i * step, y0 + drop + bounce, size, face, landed ? 0 : (1 - p) * 9 * (i % 2 ? -1 : 1), landed ? "#b8860b" : "#1d1a17");
}
const tail = b.gained < b.dice ? `${round.dice} of 9 in hand (full)` : `${round.dice} in hand`;
const tail = `${round.dice} in hand`;
label(ctx, tail, cx, cy + 12, 2.4, t > LAND_FIRST_MS + (b.dice - 1) * LAND_STEP_MS ? GOLD : "rgba(255,255,255,0.5)", "center", w - 4);
ctx.globalAlpha = 1;
}
@@ -18,7 +18,7 @@
// game over), and the run carries on to the next room. A room that is finished
// alive ends it with Lucky dice (`endBonus(round, true)`): `dice` is how many
// the round earned (BONUS_FLOOR at least, MAX_DICE at most, see `diceFor`) and
// they are added to `round.dice`, capped at MAX_DICE.
// they are added to `round.dice`, which has no limit.
//
// A room with its own grade (the dark ride) sets `perf.dice` (dice earned) and
// `perf.cardMs` (its card's length) before it finishes; `diceFor` is then not used.
@@ -86,7 +86,7 @@ export function endBonus(round, won, kit) {
// A room that grades itself (the dark ride) sets `perf.dice` and `perf.cardMs`.
b.dice = b.perf.dice !== undefined ? b.perf.dice : diceFor(b, round.stats.kills);
const had = round.dice;
round.dice = Math.min(MAX_DICE, round.dice + b.dice);
round.dice += b.dice;
points = kit.ROOM_POINTS * round.room;
kit.award(round, points);
round.stats.rooms++;
@@ -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, LEAD_MS, TUMBLE_MS } from "./ghoul-dice.js";
import { ASK_GUARD_MS, DICE_FACES, LEAD_MS, TUMBLE_MS } from "./ghoul-dice.js";
const BODY = "#f4f1e8";
const EDGE = "#8f8a7d";
@@ -212,11 +212,56 @@ export function diceArt(d) {
}
}
// The question before a roll: "Use a Lucky Die?" with Yes and No, the lit one
// gold, on the same panel the roll uses, and how many dice are in hand.
function ask(ctx, v) {
const a = v.round.ask;
if (!a) return;
const { x, y } = panelAt(v, a);
const fit = panelFit(v.g);
ctx.save();
ctx.translate(x, y);
ctx.scale(fit, fit);
ctx.translate(-x, -y);
ctx.fillStyle = "rgba(0, 0, 0, 0.7)";
roundRect(ctx, x - PANEL_W / 2, y - PANEL_H / 2, PANEL_W, PANEL_H, 2.5);
ctx.fill();
ctx.strokeStyle = GOLD;
ctx.lineWidth = 0.5;
ctx.stroke();
die(ctx, x, y - 10.5, 8.5, 1 + (Math.floor(a.t / 900) * 2) % 6, 0.12 * Math.sin(v.clock / 300));
label(ctx, "Use a Lucky Die?", x, y - 1.6, 3.4, "#ffffff", "center", PANEL_W - 3);
const n = v.round.dice;
label(ctx, `You have ${n} Lucky ${n === 1 ? "Die" : "Dice"}`, x, y + 3.4, 2.2, "#8fd8ff", "center", PANEL_W - 3);
const ready = a.t >= ASK_GUARD_MS;
for (const [word, yes, bx] of [["YES", true, x - 10.5], ["NO", false, x + 10.5]]) {
const lit = a.yes === yes;
ctx.globalAlpha = ready ? 1 : 0.45;
ctx.fillStyle = lit ? GOLD : "rgba(255, 255, 255, 0.12)";
roundRect(ctx, bx - 8.5, y + 7, 17, 7, 1.6);
ctx.fill();
ctx.strokeStyle = lit ? "#fffbe8" : "rgba(255, 255, 255, 0.4)";
ctx.lineWidth = lit ? 0.5 : 0.25;
ctx.stroke();
label(ctx, word, bx, y + 12.4, 3.4, lit ? INK : "#ffffff", "center");
ctx.globalAlpha = 1;
}
label(ctx, "Keep it to save it for later", x, y + 17.5, 1.9, "#b9b4a6", "center", PANEL_W - 3);
ctx.restore();
}
// What each step of the roll looks and sounds like (house tones for now);
// whether `e` was one of them.
function react(e, k) {
const { tone, burst, float, ring, flash, glow, shake, banner, fx, powers: POWERS } = k;
if (e.type === "diceStart") {
if (e.type === "diceAsk") {
tone("heartbeat", 0.4);
tone("click", 0.3, 0.8);
ring(e.x, e.y + 2.5, BODY, 2, 8, 500);
} else if (e.type === "diceKeep") {
tone("click", 0.3, 0.7);
float(e.x, e.y + 8, "Die kept", "#8fd8ff", 2.4);
} else if (e.type === "diceStart") {
tone("ghoulDiceDrone", 0.6);
tone("heartbeat", 0.45);
ring(e.x, e.y + 2.5, BODY, 2, 8, 500);
@@ -289,5 +334,5 @@ export function diceArt(d) {
ctx.globalAlpha = 1;
}
return { drop, roll, lucky, react, die };
return { drop, roll, ask, lucky, react, die };
}
@@ -5,9 +5,11 @@
// ghoul-powers.js its POWER_KIT, so this file never reaches back into it.
//
// A Lucky die turns up only as a drop from a kill (see ghoul-powers.js) and
// is kept, up to MAX_DICE, through every room and stage until used. When
// is kept, with no limit, through every room and stage until used. When
// Planny would lose a life, whatever the cause (a pit, the clock and the
// last life included), a round with dice holds in the phase "roll" and rolls
// last life included), a round with dice holds in the phase "ask" and asks
// "Use a Lucky Die?" (Yes spends one, No keeps them all and lets the loss go
// ahead); on Yes it holds in the phase "roll" and rolls
// one on screen, for ROLL_MS: tumbling for TUMBLE_MS, then landing on its face
// for a beat to read. One die a death; the others are kept. DICE_FACES says
// what each face does. A 4, 5 or 6 saves him: he comes back where he died
@@ -21,6 +23,7 @@
// The faces come from the `random` handed to advance(), so a seed plays the
// same. Endless lives never roll.
// The most one bonus round or ride can pay (a cap on what is earned, not on what is held).
export const MAX_DICE = 9;
// Every run starts with these dice in hand.
export const START_DICE = 3;
@@ -85,16 +88,50 @@ export function reviveSpot(round, kit) {
}
// A life about to be lost: with dice in hand (and no endless lives) the round
// holds to roll them instead. Whether it did.
// holds and ASKS whether to use one ("Use a Lucky Die?", the phase "ask"), since
// the player may want to keep it for later. Whether it did hold.
export function beginRoll(round, cause, kit) {
if (round.infinite || !(round.dice > 0)) return false;
const at = reviveSpot(round, kit);
round.dice--;
round.roll = { cause, t: 0, face: 0, landed: false, x: at.x, y: at.y, shelf: at.shelf, pit: at.pit };
round.phase = "roll";
round.ask = { cause, yes: true, t: 0, x: at.x, y: at.y, shelf: at.shelf, pit: at.pit };
round.phase = "ask";
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: "diceAsk", cause, n: round.dice, x: at.x, y: at.y });
return true;
}
// A press in the first ASK_GUARD_MS does nothing: the key that was held or
// mashed as Planny died must not answer for the player.
export const ASK_GUARD_MS = 600;
// One slice of the question: only its clock moves.
export function askStep(round, ms) {
if (round.ask) round.ask.t += ms;
}
// Which answer is lit: true for "Yes", false for "No".
export function steerAsk(round, yes) {
if (round.ask) round.ask.yes = yes;
}
// The answer. Yes spends a die and starts the roll; No keeps every die and
// lets the loss go ahead. Whether the answer was taken (not inside the guard).
export function answerAsk(round, yes, kit) {
const a = round.ask;
if (!a || a.t < ASK_GUARD_MS) return false;
round.ask = null;
round.phaseMs = 0;
if (!yes) {
round.phase = "play";
round.events.push({ type: "diceKeep", cause: a.cause, n: round.dice, x: a.x, y: a.y });
kit.takeLife(round, a.cause);
return true;
}
round.dice--;
round.roll = { cause: a.cause, t: 0, face: 0, landed: false, x: a.x, y: a.y, shelf: a.shelf, pit: a.pit };
round.phase = "roll";
round.events.push({ type: "diceStart", cause: a.cause, n: round.dice, x: a.x, y: a.y });
return true;
}
@@ -0,0 +1,282 @@
// Plan2Code Web Console - Ghoul Rush's bosses and damage: a boss's fight and fall, hurting and killing a monster, and losing a life.
//
// One of the parts of ghoul.js (see its header and the list of parts there).
import { BONUS_SAFE_MS } from "./ghoul-bonus.js";
import { answerAsk, beginRoll } from "./ghoul-dice.js";
import { ARM_DROP, POWERS, applyPower as applyPowerWith, armDrop, pickPower } from "./ghoul-powers.js";
import { FIELD_W } from "./ghoul-rooms.js";
import { BOSS_MOVERS, HAZARDS, ON_KILL, nextSerial, spawnMonster, throwBone } from "./ghoul-monsters.js";
import { footing, groundAt, landing, leftEdge, rightEdge } from "./ghoul-planny.js";
import { KIT } from "./ghoul-kit.js";
import { BOSSES, BOSS_INTRO_MS, CHAIN_MS, CRASH_MS, DROP_CANDY, DROP_MS, DROP_POWER, FALL_MAX, GARLIC_SAFE_MS, GOURD_ACTS, GOURD_BIG_V, GOURD_HOP_V, GOURD_QUAKE_V, GOURD_SPIT, GOURD_SPIT_MS, GOURD_WAIT_MS, GRAVITY, HIT_H, HIT_W, MAX_SEEDS, MONSTERS, PIT_Y, QUICK_LOSS_MS, SAFE_MS, STRAY_FADE, STRAY_MIN, chainMult, clamp, seeded } from "./ghoul-tables.js";
/* --------------------------------------------------------------- bosses */
// One slice of each hazard by its kind's rule; gone once its rule says so.
export function moveHazards(round, ms) {
if (!round.hazards.length) return;
let n = 0;
for (const h of round.hazards) if (HAZARDS[h.kind] && HAZARDS[h.kind](round, h, ms, KIT)) round.hazards[n++] = h;
// A hazard that felled the boss has just emptied the list.
round.hazards.length = Math.min(n, round.hazards.length);
}
export function makeBoss(round) {
const spec = round.spec;
const def = BOSSES[spec.boss];
const x = spec.length - 24;
return { kind: spec.boss, x, y: groundAt(spec, x), vx: 0, vy: 0, w: def.w, h: def.h, hp: spec.bossHp, max: spec.bossHp, state: "sleep", t: 0, wait: GOURD_WAIT_MS, hops: 0, attacks: 0, windup: 0, act: "", run: 0, landX: x, hurt: 0, dir: -1 };
}
// The arena's ends for the boss: it keeps ARENA_POCKET clear of each, so
// a corner is always somewhere a hop cannot land on you.
export const ARENA_POCKET = 6;
export const arenaMin = (round, b) => round.spec.arena + ARENA_POCKET + b.w / 2;
export const arenaMax = (round, b) => round.spec.length - ARENA_POCKET - b.w / 2;
// The Gourd's next move: any of GOURD_ACTS at random, but never one three
// times running (and only a spit at you up on a balcony over its head).
export function gourdAct(b, random) {
let act = GOURD_ACTS[Math.floor(random() * GOURD_ACTS.length) % GOURD_ACTS.length];
if (act === b.act && b.run >= 2) act = GOURD_ACTS[(GOURD_ACTS.indexOf(act) + 1 + Math.floor(random() * 2)) % GOURD_ACTS.length];
b.run = act === b.act ? b.run + 1 : 1;
return act;
}
export function moveBoss(round, ms, random) {
const b = round.boss;
if (!b || b.state === "sleep") return;
if (b.state === "down") {
b.t += ms;
return;
}
const dt = ms / 1000;
const you = round.you;
const spec = round.spec;
const pace = spec.pace;
b.t += ms;
b.hurt = Math.max(0, b.hurt - ms);
if (b.state === "intro") {
if (b.t >= BOSS_INTRO_MS) {
b.state = "fight";
round.events.push({ type: "bossGo", kind: b.kind });
}
return;
}
// Dazed by Flash Powder or pinned by a Bear Trap (ghoul-arms.js).
if (b.stunMs > 0) {
b.stunMs -= ms;
return;
}
if (BOSS_MOVERS[b.kind]) return BOSS_MOVERS[b.kind](round, b, ms, random, KIT);
const floor = groundAt(spec, b.x);
if (b.kind === "gourd") {
if (b.vy !== 0 || b.y > floor) {
b.vy -= GRAVITY * dt;
const py = b.y;
b.x = clamp(b.x + b.vx * dt, arenaMin(round, b), arenaMax(round, b));
b.y += b.vy * dt;
if (b.vy < 0 && py >= floor && b.y <= floor) {
b.y = floor;
b.vy = 0;
b.vx = 0;
b.wait = GOURD_WAIT_MS / pace;
if (b.act === "quake") {
for (const d of [-1, 1]) round.waves.push({ x: b.x + d * (b.w / 2), y: floor, dir: d, life: 6000, kind: "gourd" });
round.events.push({ type: "slam", kind: "gourd", x: b.x, y: b.y, big: true });
return;
}
const big = b.hops % 3 === 0;
round.events.push({ type: "slam", kind: "gourd", x: b.x, y: b.y, big });
const seeds = round.monsters.filter((m) => m.kind === "seed").length;
for (let k = 0; k < (big ? 2 : 1) && seeds + k < MAX_SEEDS; k++) {
const side = k % 2 ? 1 : -1;
spawnMonster(round, "seed", b.x + side * (b.w / 2), b.y + 4, { vx: side * (8 + random() * 10), vy: 26 + random() * 14, dir: side, force: true });
}
}
return;
}
b.dir = Math.sign(you.x - b.x) || b.dir;
if (b.windup > 0) {
b.windup = Math.max(0, b.windup - ms);
if (b.windup > 0) return;
for (const s of GOURD_SPIT) throwBone(round, b.x + b.dir * b.w * 0.3, b.y + b.h * 0.6, s, "acid", b.kind);
round.events.push({ type: "spit", kind: b.kind, x: b.x, y: b.y + b.h * 0.6 });
b.wait = GOURD_WAIT_MS / pace;
return;
}
b.wait -= ms;
if (b.wait > 0) return;
// Up on a balcony over its head, you are out of a hop's reach: it spits.
const high = you.state === "run" && you.shelf >= 0 && you.y >= floor + b.h + 2;
b.act = high ? "spit" : gourdAct(b, random);
if (high) b.run = 0;
if (b.act === "spit") {
b.windup = GOURD_SPIT_MS / pace;
round.events.push({ type: "windup", x: b.x, y: b.y, boss: true, act: b.act });
return;
}
if (b.act === "quake") {
b.vx = 0;
b.vy = GOURD_QUAKE_V;
b.y += 0.01;
round.events.push({ type: "hop", kind: "gourd", x: b.x, y: b.y, landX: b.x });
return;
}
b.hops++;
const v = b.hops % 3 === 0 ? GOURD_BIG_V : GOURD_HOP_V;
const air = (2 * v) / GRAVITY;
b.landX = clamp(you.x, arenaMin(round, b), arenaMax(round, b));
b.vx = (b.landX - b.x) / air;
b.vy = v;
b.y += 0.01;
round.events.push({ type: "hop", kind: "gourd", x: b.x, y: b.y, landX: b.landX });
return;
}
}
// Damage to the boss; at none it falls and the door opens.
export function hurtBoss(round, dmg, how) {
const b = round.boss;
if (!b || b.state !== "fight") return false;
b.hp = Math.max(0, b.hp - dmg);
b.hurt = 120;
round.events.push({ type: "bossHit", kind: b.kind, x: b.x, y: b.y + b.h / 2, how, weak: how === "weak" });
if (b.hp > 0) return true;
b.state = "down";
b.t = 0;
const points = round.spec.bossPoints;
award(round, points);
round.stats.bosses++;
round.hasKey = true;
const life = true;
round.lives++;
for (const m of round.monsters) round.events.push({ type: "poof", kind: m.kind, x: m.x, y: m.y + m.h / 2 });
round.monsters.length = 0;
round.bones.length = 0;
round.waves.length = 0;
round.puddles.length = 0;
round.hazards.length = 0;
round.events.push({ type: "bossDown", kind: b.kind, x: b.x, y: b.y + b.h / 2, points, life });
return true;
}
/* ---------------------------------------------------------- hits, kills */
export const award = (round, points) => {
round.score += points;
};
// A shot, a stomp or a chandelier on monster `m`: hp off, and at none a kill.
export function hurt(round, m, dmg, how, random = Math.random) {
if (m.dead) return false;
m.hp -= dmg;
m.hurt = 110;
if (m.hp > 0) {
round.events.push({ type: "hit", kind: m.kind, x: m.x, y: m.y + m.h / 2, how });
return false;
}
kill(round, m, how, random);
return true;
}
// A monster gone: its points times the chain, doubled for a headshot, a
// stomp or a chandelier, and now and then candy or a power-up left behind.
export function kill(round, m, how = "shot", random = Math.random) {
m.dead = true;
round.chain = round.chainMs > 0 ? round.chain + 1 : 1;
round.chainMs = CHAIN_MS;
const mult = chainMult(round.chain);
const bonus = how === "head" || how === "stomp" || how === "crush" ? 2 : 1;
const fade = m.horde ? Math.max(STRAY_MIN, STRAY_FADE ** round.strays++) : 1;
const points = Math.round(MONSTERS[m.kind].points * mult * bonus * fade);
award(round, points);
round.stats.kills++;
if (how === "head") round.stats.headshots++;
if (how === "stomp") round.stats.stomps++;
round.stats.bestChain = Math.max(round.stats.bestChain, round.chain);
round.events.push({ type: "kill", kind: m.kind, x: m.x, y: m.y + m.h / 2, points, mult, how });
// A bloater bursts in a harmless splash: only the acid it spits burns.
if (m.kind === "spitter") round.events.push({ type: "burst", x: m.x, y: m.y + m.h / 2 });
if (ON_KILL[m.kind]) ON_KILL[m.kind](round, m, how, KIT);
if (m.horde) return points;
const r = random();
if (r < DROP_POWER) dropItem(round, pickPower(random, round, "", true), m.x, m.y + m.h / 2);
else if (r < DROP_POWER + DROP_CANDY) dropItem(round, "candy", m.x, m.y + m.h / 2);
// A weapon: its own band of the same roll, so no later roll shifts (ghoul-powers.js).
else if (r < DROP_POWER + DROP_CANDY + ARM_DROP) dropItem(round, armDrop(round, (r - DROP_POWER - DROP_CANDY) / ARM_DROP), m.x, m.y + m.h / 2);
return points;
}
// A weapon's drop takes no monster serial, so it shifts nothing later (a monster's id sets how long it ponders).
export function dropItem(round, kind, x, y) {
round.drops.push({ id: POWERS[kind]?.arm ? 0 : nextSerial(), kind, x, y, vx: 0, vy: 22, life: DROP_MS, rest: false });
}
// A life lost: with Lucky dice in hand the round first holds to roll one
// (ghoul-dice.js); else, or when it lands on 3 or lower, it holds while Planny
// tumbles, then puts him back.
export function lose(round, cause) {
if (round.phase !== "play" || round.you.out > 0) return false;
round.you.lift = null;
// A bonus room's hearts are its own: no Lucky die is rolled for one.
if (!round.bonusRound && beginRoll(round, cause, DICE_KIT)) return true;
return takeLife(round, cause);
}
function takeLife(round, cause) {
const you = round.you;
if (!round.infinite) round.bonusRound ? round.bonusRound.hearts-- : round.lives--;
round.chain = 0;
round.chainMs = 0;
round.roomLost = true;
// The dark ride and the Runaway Cart play on after a hit that is not the last heart
// (ghoul-ride.js; the cart blinks safe a moment, and a derail is re-seated by ghoul-cart.js).
const b = round.bonusRound;
const rolling = round.gallery || (round.cart && !round.cart.done) || (round.sled && !round.sled.done) || (round.runner && !round.runner.done);
if (rolling && b && (round.infinite || b.hearts > 0)) {
if (!round.gallery) you.safeMs = Math.max(you.safeMs, BONUS_SAFE_MS);
round.events.push({ type: "lose", cause, x: you.x, y: you.y, lives: round.lives, hearts: b.hearts });
return true;
}
you.out = CRASH_MS;
you.outKind = cause;
round.quickLoss = (you.aliveMs || 0) < QUICK_LOSS_MS;
round.phase = "crash";
round.phaseMs = CRASH_MS;
round.input.jump = 0;
round.events.push({ type: "lose", cause, x: you.x, y: you.y, lives: round.lives, hearts: round.bonusRound ? round.bonusRound.hearts : undefined });
return true;
}
// Something touched you: the Garlic shield takes it (seeing off the monster
// that touched you), else a life.
export function struck(round, cause, m = null) {
const you = round.you;
if (you.safeMs > 0) return false;
if (you.garlic) {
you.garlic = false;
you.safeMs = GARLIC_SAFE_MS;
if (m && !m.dead && MONSTERS[m.kind]) {
kill(round, m, "garlic", () => 1);
round.monsters = round.monsters.filter((q) => !q.dead);
}
round.events.push({ type: "garlic", x: you.x, y: you.y });
return false;
}
return lose(round, cause);
}
/* ------------------------------------------------------------- powers */
// What ghoul-powers.js needs from here, handed to its rules the way KIT is
// handed to a stage pack.
export const POWER_KIT = Object.freeze({ footing, leftEdge, rightEdge, seeded, landing, GRAVITY, FALL_MAX, PIT_Y, HIT_W, HIT_H });
// And what ghoul-dice.js needs.
export const DICE_KIT = Object.freeze({ SAFE_MS, PIT_Y, FIELD_W, footing, groundAt, leftEdge, rightEdge, takeLife, kill, give: (round, kind) => applyPowerWith(round, kind, POWER_KIT) });
export const applyPower = (round, kind) => applyPowerWith(round, kind, POWER_KIT);
// Answer "Use a Lucky Die?": true spends one and rolls, false keeps every die and lets the loss go ahead.
export const answerDie = (round, yes) => answerAsk(round, yes, DICE_KIT);
@@ -0,0 +1,3 @@
// Plan2Code Web Console - Ghoul Rush's KIT: what the stage packs are handed, the game's own helpers and numbers. One empty object here that ghoul-play.js fills as it loads, so the parts of the game that only pass the kit on need not load after the part that fills it. No imports.
export const KIT = {};
@@ -0,0 +1,721 @@
// Plan2Code Web Console - Ghoul Rush's monsters: spawning them, how each kind walks, hops, climbs and swoops, and what they throw.
//
// One of the parts of ghoul.js (see its header and the list of parts there).
import { CHANDELIER_Y, FIELD_W } from "./ghoul-rooms.js";
import { hurt } from "./ghoul-fight.js";
import { footing, groundAt, landing, leftEdge, shelfThere, wallAt } from "./ghoul-planny.js";
import { KIT } from "./ghoul-kit.js";
import { BAT_NEAR, BAT_STEER, BAT_TURN, BONE_G, BONE_V, BONE_VX, BOUND_UP, BOUND_V, CLIMBERS, CLIMB_V, FALL_MAX, GHOST_APPEAR_MS, GHOST_CLEAR, GHOST_HIDE_MS, GHOST_SHOW_MS, GRAVITY, HEAVY, HIT_W, HOP_IN, HOP_V, HOUND_CROUCH_MS, HOUND_LUNGE_V, HOUND_LUNGE_VX, HOUND_RANGE, HOUND_REST_MS, HUNT_CROUCH_MS, HUNT_HIGH, HUNT_RANGE, HUNT_REST_MS, HUNT_UP, HUNT_VX, LURCH_RANGE, MAX_MONSTERS, MONSTERS, PIT_Y, PONDER_MS, PONDER_STEP_MS, PUDDLE_MS, RISE_MS, RUNNER_WARN, SEED_LAND_MS, SHOT_Y, SKEL_MS, SKEL_NEAR, SKEL_RANGE, SKEL_WINDUP_MS, SPIDER_DROP_V, SPIDER_NEAR, SPIT_KEEP, SPIT_MS, SPIT_RANGE, SPIT_WINDUP_MS, STACKERS, STACK_MIN, STACK_NEAR, STACK_REACH, STACK_STEP, STEP_UP, SWOOP_CLEAR, SWOOP_NEAR, UNSTACK_V, WALKERS, WALL_MAX, WALL_V, WAVE_SPEED, WRAITH_ABOVE, WRAITH_DIVE_V, WRAITH_HOVER_MS, WRAITH_KEEP, WRAITH_NEAR, WRAITH_PAST, WRAITH_WIND_MS, YOU_H, ZOMBIES, bounds, clamp, fromPacks, hopReach, listPacks } from "./ghoul-tables.js";
/* ------------------------------------------------------------ monsters */
let serial = 0;
// The next id, for what the other parts make (a module's binding can only be changed from inside it).
export const nextSerial = () => ++serial;
// A monster of `kind` at (x, y), facing you; `over` adds or replaces fields.
export function spawnMonster(round, kind, x, y, over = {}) {
if (round.monsters.length >= MAX_MONSTERS && !over.force) return null;
const def = MONSTERS[kind];
const spec = round.spec;
const extra = ZOMBIES.has(kind) || kind === "skeleton" || kind === "hound" || kind === "spitter" || kind === "huntsman" ? spec.tough : 0;
const m = {
id: ++serial,
kind,
x,
y,
w: def.w,
h: def.h,
hp: def.hp + extra,
max: def.hp + extra,
vx: 0,
vy: 0,
dir: round.you.x < x ? -1 : 1,
t: 0,
rise: kind === "crawler" ? RISE_MS : 0,
awake: kind !== "bat",
act: ACT_START[kind] || "",
wait: 0,
phase: 0,
throwIn: (kind === "spitter" ? SPIT_MS : SKEL_MS) * 0.45,
windup: 0,
hurt: 0,
home: y,
lift: 0,
...over,
};
delete m.force;
round.monsters.push(m);
round.events.push({ type: "spawn", kind, x, y });
return m;
}
// What a hellhound, a widow and a wraith start out doing.
const ACT_START = Object.freeze({ hound: "prowl", spider: "hang", wraith: "idle", huntsman: "prowl", ...fromPacks("act") });
// The packs' rules by kind: whether one is solid, its moving, what its death
// leaves, what a horde one comes in with; a boss's fight, whether it shrugs
// off a hit, and each kind of hazard a boss leaves on the field.
const SOLIDS = fromPacks("solid");
const MOVERS = fromPacks("move");
export const ON_KILL = fromPacks("kill");
export const HORDE_WITH = fromPacks("horde");
export const BOSS_MOVERS = fromPacks("boss");
const GUARDS = fromPacks("guard");
export const HAZARDS = fromPacks("hazards");
// Kinds the Hedge Shears kill outright, a boss's weak spot (the damage
// multiplier of a shot) and what a boss's touch is called when it costs a life.
export const CUT = new Set(listPacks("cut"));
export const WEAK = fromPacks("weak");
export const CAUSES = fromPacks("cause");
// Kinds that are stone just now (a shot glances off), a stage-wide twist run
// each slice (the Chapel's bell, which may set `round.stunMs`), what a bolt
// that hit a monster does besides its damage, and what else a bolt can strike.
export const STONE = fromPacks("stone");
export const TICKS = listPacks("tick");
export const SHOTS = listPacks("shot");
export const TARGETS = listPacks("target");
// What a pack does to carry Planny itself (the Runaway Cart's ride: a hook that
// returns true has moved him), and when he is put down in a room (a room set up,
// a respawn).
export const RIDES = listPacks("ride");
export const PLACES = listPacks("place");
export const POINTERS = listPacks("pointer");
// Kinds that are out of sight just now (a shot goes through, a touch does
// nothing), that hurt nothing by touch, that Planny can stand on, and what a
// missile of a kind does where it lands (see ghoul-sanatorium.js).
const UNSEEN = fromPacks("unseen");
export const HARMLESS = fromPacks("harmless");
const LANDS = fromPacks("land");
// Whether the boss shrugs off shots and stomps just now.
export const guarded = (b) => Boolean(GUARDS[b.kind] && GUARDS[b.kind](b));
// Whether a monster can be hit and can hurt: a crawler or a door's zombie
// still coming up, a gourdling still in the air, a faded ghost and a wraith
// not yet come cannot.
export function solid(m) {
if (m.unseen) return false;
if (SOLIDS[m.kind]) return SOLIDS[m.kind](m);
if (m.kind === "crawler" || ZOMBIES.has(m.kind)) return m.rise <= 0;
// A gourdling flung out of the Gourd is harmless till it lands and finds its feet.
if (m.kind === "seed") return m.vy === 0 && m.rise <= 0;
if (m.kind === "ghost") {
const t = (m.t + m.phase) % (GHOST_SHOW_MS + GHOST_HIDE_MS);
return t >= GHOST_APPEAR_MS && t < GHOST_SHOW_MS;
}
if (m.kind === "wraith") return m.act !== "idle";
return true;
}
// Whether a monster is up and after you: solid, and not a roosting bat or a
// widow still on the ceiling.
export const roused = (m) => (m.kind !== "bat" || m.awake) && !(m.kind === "spider" && m.act === "hang") && solid(m);
// The ghost's share of full sight, 0 to 1, for the drawing.
export function ghostSight(m) {
const t = (m.t + m.phase) % (GHOST_SHOW_MS + GHOST_HIDE_MS);
if (t < GHOST_APPEAR_MS) return t / GHOST_APPEAR_MS;
if (t < GHOST_SHOW_MS) return 1;
const fade = Math.min(1, (t - GHOST_SHOW_MS) / 250);
return 1 - fade * 0.88;
}
// Within UNDER_DX of straight under (or over) you a monster stops where it
// is, still facing the way it went, rather than turning back and forth
// every frame; once you move off it turns and comes on.
export const UNDER_DX = 1;
export const towardYou = (round, m) => (Math.abs(round.you.x - m.x) < UNDER_DX ? m.dir : Math.sign(round.you.x - m.x) || m.dir);
// A walker's step toward `dx` (the sign of the way it goes) at `speed`:
// never off an edge or up a wall; it stands and sways instead, or at a pit
// narrow enough, thinks about it and then leaps (ponder). Under you, it
// stands (UNDER_DX).
export function walk(round, m, dir, speed, dt) {
// One up a pile is moved by the pile.
if (!dir || m.lift > 0 || Math.abs(round.you.x - m.x) < UNDER_DX) return;
if (m.dir !== dir) m.ponder = 0;
m.dir = dir;
const nx = m.x + dir * speed * dt;
if (wallAt(round.spec, nx + dir * m.w * 0.4, m.y + STEP_UP)) return wall(round, m, nx + dir * m.w * 0.4, dir, dt);
// Walkers keep to the ground, but cross a board laid level with it over a
// pit (a bridge) while it is there; never up onto a shelf.
const f = footing(round, nx, m.y);
// A gourdling runs straight off a shelf's end after you.
if (!f && m.kind === "seed" && Number.isFinite(groundAt(round.spec, nx)) && groundAt(round.spec, nx) < m.y) {
m.hop = { vx: dir * speed, vy: 6 };
return;
}
if (!f) return ponder(round, m, nx, dir, dt);
if (f.shelf >= 0 && Math.abs(f.y - m.y) > 0.01) return;
m.ponder = 0;
m.x = nx;
m.y = f.y;
}
// A leap's time in the air, rising at `v`, to come down `drop` below where it
// left (a negative drop is floor above it).
const hopTime = (drop, v) => (v + Math.sqrt(v * v + 2 * GRAVITY * drop)) / GRAVITY;
// Where a leap from the edge at `nx` going `dir` lands, as { x, y, t, v }:
// HOP_IN past the first floor no higher than a step up (BOUND_UP on four legs) that a leap reaches
// (hopReach across on the level, more the further down); null for floor out
// of reach, too high, or past the arena's wall.
export function farSide(round, m, nx, dir) {
const spec = round.spec;
if (groundAt(spec, nx) >= m.y - STEP_UP) return null;
const bound = bounds(m);
const v = bound ? BOUND_V : HOP_V;
const up = bound ? BOUND_UP : STEP_UP;
const flat = hopTime(0, v);
const reach = hopReach(m);
for (let d = 0; d <= reach * 2; d += 0.5) {
const x = nx + dir * d;
const g = groundAt(spec, x);
if (!Number.isFinite(g)) continue;
if (g > m.y + up) return null;
const t = hopTime(bound ? m.y - g : Math.max(0, m.y - g), v);
if (d > (reach * t) / flat) return null;
const to = x + dir * HOP_IN;
const left = round.lockX >= 0 ? round.lockX + 2 : 2;
return to >= left && to <= spec.length - 2 && groundAt(spec, to) === g ? { x: to, y: g, t, v } : null;
}
return null;
}
// Whether a walker has stood thinking long enough (a "ponder" event as it
// starts).
function thought(round, m, dt) {
if (!m.ponder) round.events.push({ type: "ponder", x: m.x, y: m.y + m.h });
m.ponder = (m.ponder || 0) + dt * 1000;
if (m.ponder < PONDER_MS + (m.id % 4) * PONDER_STEP_MS) return false;
m.ponder = 0;
return true;
}
// A walker at a pit's edge: it stands thinking, then leaps across. One too
// heavy to leap still steps off a ledge onto the floor below.
function ponder(round, m, nx, dir, dt) {
const below = groundAt(round.spec, nx);
if (HEAVY.has(m.kind) && Number.isFinite(below) && below < m.y) {
m.ponder = 0;
m.hop = { vx: dir * MONSTERS[m.kind].speed * round.spec.pace, vy: 0 };
return;
}
const to = HEAVY.has(m.kind) ? null : farSide(round, m, nx, dir);
if (!to) {
m.ponder = 0;
return;
}
if (!thought(round, m, dt)) return;
m.hop = { vx: (to.x - m.x) / to.t, vy: to.v };
round.events.push({ type: "leap", kind: m.kind, x: m.x, y: m.y });
}
// A climber at a wall (its face at `wx`): it stands thinking, then climbs.
function wall(round, m, wx, dir, dt) {
const spec = round.spec;
const top = groundAt(spec, wx);
if (!CLIMBERS.has(m.kind) || !Number.isFinite(top) || top - m.y > WALL_MAX) {
m.ponder = 0;
return;
}
if (!thought(round, m, dt)) return;
const on = wx + dir * (m.w / 2 + 0.3);
m.scale = { top, x: groundAt(spec, on) === top ? on : wx + dir * 0.5 };
round.events.push({ type: "scale", kind: m.kind, x: m.x, y: m.y });
}
// A walker up a wall: on up its face, then onto the floor at its top.
function scaleOn(m, dt) {
m.y += WALL_V * dt;
if (m.y < m.scale.top) return;
m.y = m.scale.top;
m.x = m.scale.x;
m.scale = null;
}
// A walker in the air: down onto the floor or shelf it crosses, or into
// the dark below.
function hopOn(round, m, dt) {
const py = m.y;
m.hop.vy = Math.max(-FALL_MAX, m.hop.vy - GRAVITY * dt);
m.x += m.hop.vx * dt;
m.y += m.hop.vy * dt;
const f = m.hop.vy < 0 ? landing(round, m.x, py, m.y, -1) : null;
if (f) {
m.y = f.y;
m.hop = null;
} else if (m.y < PIT_Y) m.dead = true;
}
// Gourdlings chase you up and down the shelves: with you above, one under a
// shelf no more than SEED_REACH over it crouches SEED_CROUCH_MS and jumps up
// onto it (toward where you are along it), SEED_JUMP_MS between jumps; with
// you below, it runs off its shelf's end and drops (see walk).
export const SEED_REACH = 13;
export const SEED_CROUCH_MS = 250;
export const SEED_JUMP_MS = 700;
function seedJump(round, m, ms) {
const you = round.you;
m.jumpIn = Math.max(0, (m.jumpIn || 0) - ms);
if (m.crouch > 0) {
m.crouch = Math.max(0, m.crouch - ms);
if (m.crouch > 0) return true;
const vy = Math.sqrt(2 * GRAVITY * (m.to.top - m.y + 2));
const t = (vy + Math.sqrt(2 * GRAVITY * 2)) / GRAVITY;
m.hop = { vx: (m.to.x - m.x) / t, vy };
m.dir = Math.sign(m.to.x - m.x) || m.dir;
m.jumpIn = SEED_JUMP_MS;
round.events.push({ type: "leap", kind: m.kind, x: m.x, y: m.y });
return true;
}
if (m.jumpIn > 0 || you.y < m.y + 2.5 || Math.abs(you.x - m.x) > 40) return false;
let to = null;
round.spec.shelves.forEach(([x0, x1, top], i) => {
if (!shelfThere(round, i) || top <= m.y + 2 || top > m.y + SEED_REACH || top > you.y + 1) return;
const x = clamp(you.x, x0 + 1.2, x1 - 1.2);
if (Math.abs(x - m.x) > 12) return;
if (!to || Math.abs(top - you.y) < Math.abs(to.top - you.y)) to = { top, x };
});
if (!to) return false;
m.to = to;
m.crouch = SEED_CROUCH_MS;
return true;
}
// A thrown bone (or glob of acid, `kind`) from (x, y) at your chest: its
// flight timed to come down there, across no faster than BONE_VX. `by`, the
// thrower's kind, rides on the "throw" event so each thrower sounds its own.
export function throwBone(round, x, y, scale = 1, kind = "bone", by = null) {
const you = round.you;
const dy = you.y + 2 - y;
const disc = BONE_V * BONE_V - 2 * BONE_G * dy;
const t = disc > 0 ? (BONE_V + Math.sqrt(disc)) / BONE_G : (2 * BONE_V) / BONE_G;
const vx = clamp(((you.x - x) / t) * scale, -BONE_VX * scale, BONE_VX * scale);
const b = { id: ++serial, kind, x, y, vx, vy: BONE_V, spin: 0, life: 4000 };
round.bones.push(b);
round.events.push({ type: "throw", kind, by, x, y });
return b;
}
// One slice of each monster's moving, by kind.
export function moveMonsters(round, slice, random) {
const you = round.you;
const spec = round.spec;
const pace = spec.pace;
for (const m of round.monsters) {
// A choir ghost's song (`hasteMs`) runs a monster's time `haste` times as fast.
const ms = m.hasteMs > 0 ? slice * m.haste : slice;
const dt = ms / 1000;
if (UNSEEN[m.kind]) m.unseen = Boolean(UNSEEN[m.kind](round, m));
if (m.hasteMs > 0) m.hasteMs -= slice;
// A faded ghost never turns solid on top of you: it waits till you are clear.
if (!(m.kind === "ghost" && !solid(m) && Math.abs(you.x - m.x) < GHOST_CLEAR && Math.abs(you.y + YOU_H / 2 - (m.y + m.h / 2)) < GHOST_CLEAR)) m.t += ms;
m.hurt = Math.max(0, m.hurt - ms);
// Dazed by Flash Powder or held by a Bear Trap (ghoul-arms.js): shown a while, and still deadly to touch.
if (m.litMs > 0) m.litMs -= slice;
if (m.stunMs > 0) {
m.stunMs -= slice;
continue;
}
if (m.hop) {
hopOn(round, m, dt);
continue;
}
if (m.scale) {
scaleOn(m, dt);
continue;
}
// A bridge gone from under a walker: it drops into the pit.
if (WALKERS.has(m.kind) && m.rise <= 0 && !m.vy && !(m.lift > 0) && !footing(round, m.x, m.y)) {
m.hop = { vx: 0, vy: 0 };
hopOn(round, m, dt);
continue;
}
if (MOVERS[m.kind]) {
MOVERS[m.kind](round, m, ms, KIT);
continue;
}
const dx = you.x - m.x;
const toward = towardYou(round, m);
if (ZOMBIES.has(m.kind)) {
if (m.kind === "runner" && !m.warned && m.x > round.camX - RUNNER_WARN && m.x < round.camX + FIELD_W + RUNNER_WARN) {
m.warned = true;
round.events.push({ type: "runner", x: clamp(m.x, round.camX + 3, round.camX + FIELD_W - 3), y: m.y + m.h, side: Math.sign(m.x - you.x) || 1 });
}
if (m.rise > 0) {
m.rise = Math.max(0, m.rise - ms);
continue;
}
const near = Math.abs(dx) < LURCH_RANGE && Math.abs(you.y - m.y) < 6;
walk(round, m, toward, (near ? MONSTERS[m.kind].lurch : MONSTERS[m.kind].speed) * pace, dt);
m.lurching = near;
} else if (m.kind === "crawler" || m.kind === "seed") {
if (m.rise > 0) {
m.rise = Math.max(0, m.rise - ms);
continue;
}
if (m.kind === "seed" && m.vy !== 0) {
// Flung out of the Gourd: in the air till it lands.
m.vy -= GRAVITY * dt;
const py = m.y;
const nx = clamp(m.x + m.vx * dt, round.lockX >= 0 ? round.lockX + 2 : 2, spec.length - 2);
m.x = nx;
m.y += m.vy * dt;
const f = m.vy < 0 ? landing(round, m.x, py, m.y, -1) : null;
if (f) {
m.y = f.y;
m.vy = 0;
m.vx = 0;
// A moment to find its feet before it runs at you.
m.rise = SEED_LAND_MS;
}
if (m.y < PIT_Y) m.dead = true;
continue;
}
if (m.kind === "seed" && seedJump(round, m, ms)) continue;
walk(round, m, toward, MONSTERS[m.kind].speed * pace, dt);
} else if (m.kind === "bat") {
if (!m.awake) {
if (Math.abs(dx) < BAT_NEAR) {
m.awake = true;
round.events.push({ type: "bat", x: m.x, y: m.y });
}
continue;
}
// Swoops: level passes at your chest, turning BAT_TURN past you and
// climbing a little before it comes back down for the next.
const speed = MONSTERS.bat.speed * pace;
if (!m.pass) m.pass = toward;
const ahead = (m.x - you.x) * m.pass;
if (ahead > BAT_TURN) {
m.pass = -m.pass;
m.climb = 300;
}
m.climb = Math.max(0, (m.climb || 0) - ms);
const ty = m.climb > 0 ? you.y + 12 : you.y + SHOT_Y - MONSTERS.bat.h / 2;
// Once close it holds its height: it never drops onto your head.
const close = Math.abs(dx) <= 9 && m.climb <= 0;
const steer = close ? 0 : clamp((ty - m.y) * 5, -BAT_STEER, BAT_STEER);
m.vx = clamp(m.vx + m.pass * BAT_STEER * 2 * dt, -speed, speed);
m.vy = clamp(m.vy + (steer - m.vy) * Math.min(1, (close ? 20 : 6) * dt), -speed * 0.8, speed * 0.8);
m.x += m.vx * dt;
m.y = Math.max(groundAt(spec, m.x) + 0.6, Math.min(CHANDELIER_Y, m.y + (m.vy + Math.sin(m.t / 140) * 1.5) * dt));
m.dir = Math.sign(m.vx) || m.dir;
} else if (m.kind === "ghost") {
const speed = MONSTERS.ghost.speed * pace;
const ty = you.y + 1;
const d = Math.hypot(dx, ty - m.y) || 1;
m.x += (dx / d) * speed * dt;
m.y += ((ty - m.y) / d) * speed * dt;
m.dir = toward;
} else if (m.kind === "hound") moveHound(round, m, ms, toward);
else if (m.kind === "spider") moveSpider(round, m, ms, toward);
else if (m.kind === "huntsman") moveHuntsman(round, m, ms, toward);
else if (m.kind === "wraith") moveWraith(round, m, ms);
else if (m.kind === "spitter") {
m.dir = toward;
if (m.windup > 0) {
m.windup = Math.max(0, m.windup - ms);
if (!m.windup) throwBone(round, m.x + m.dir * 1.8, m.y + m.h * 0.7, 0.9 + random() * 0.2, "acid", m.kind);
continue;
}
if (Math.abs(dx) > SPIT_KEEP) walk(round, m, toward, MONSTERS.spitter.speed * pace, dt);
const inView = m.x > round.camX - 2 && m.x < round.camX + FIELD_W + 2;
if (!inView || Math.abs(dx) > SPIT_RANGE || Math.abs(dx) < SKEL_NEAR) continue;
m.throwIn -= ms * pace;
if (m.throwIn <= 0) {
m.throwIn = SPIT_MS * (0.85 + random() * 0.3);
m.windup = SPIT_WINDUP_MS;
round.events.push({ type: "spit", kind: m.kind, x: m.x, y: m.y });
}
} else if (m.kind === "skeleton") {
m.dir = toward;
const inView = m.x > round.camX - 2 && m.x < round.camX + FIELD_W + 2;
if (m.windup > 0) {
m.windup = Math.max(0, m.windup - ms);
if (!m.windup) throwBone(round, m.x + m.dir * 1.2, m.y + m.h * 0.85, 0.9 + random() * 0.2, "bone", m.kind);
continue;
}
if (!inView || Math.abs(dx) > SKEL_RANGE || Math.abs(dx) < SKEL_NEAR) continue;
m.throwIn -= ms * pace;
if (m.throwIn <= 0) {
m.throwIn = SKEL_MS * (0.85 + random() * 0.3);
m.windup = SKEL_WINDUP_MS;
round.events.push({ type: "windup", x: m.x, y: m.y });
}
}
}
skimOver(round);
}
// What swoops, and when: a ducked Planny is passed overhead (see SWOOP_CLEAR).
const SWOOPS = Object.freeze({ bat: () => true, wraith: (m) => m.act === "dive", ...fromPacks("swoops") });
// Holds each swooper near a ducked Planny on a ramp up over his head. A ramp by
// distance, not a rate, so no dive is too fast for it.
function skimOver(round) {
const you = round.you;
if (!you.ducking) return;
for (const m of round.monsters) {
if (m.dead || !SWOOPS[m.kind]?.(m)) continue;
const short = Math.abs(m.x - you.x) - (HIT_W + m.w * 0.8) / 2;
if (short > SWOOP_NEAR || m.y < you.y - 1) continue;
m.y = Math.max(m.y, you.y + SWOOP_CLEAR - Math.max(0, short));
}
}
// The piles: walkers on the same floor in a run each within STACK_NEAR of
// the next, STACK_MIN or more of them, climb over each other toward you
// while you are above and near; every walker not in a climbing pile comes
// back down. Returns the piles found, oldest walker first in each, for the
// unit suite.
export function piles(round, ms) {
const dt = ms / 1000;
const you = round.you;
const floorOf = (m) => m.y - (m.lift || 0);
const walkers = round.monsters.filter((m) => STACKERS.has(m.kind) && !m.dead && solid(m) && !m.vy && !m.hop && !m.scale);
walkers.sort((a, b) => a.x - b.x);
const found = [];
let run = [];
const close = () => {
if (run.length >= STACK_MIN) found.push(run.slice().sort((a, b) => a.id - b.id));
run = [];
};
for (const m of walkers) {
const last = run[run.length - 1];
if (last && (m.x - last.x > STACK_NEAR || Math.abs(floorOf(m) - floorOf(last)) > 0.5)) close();
run.push(m);
}
close();
const target = new Map();
const pileOf = new Map();
for (const pile of found) {
const base = pile[0];
const floor = floorOf(base);
const need = you.y - floor;
if (need < base.h * 0.5 || Math.abs(you.x - base.x) > STACK_REACH || you.out > 0) continue;
let lift = 0;
pile.forEach((m, i) => {
if (i > 0 && lift + STACK_STEP * pile[i - 1].h <= need) lift += STACK_STEP * pile[i - 1].h;
target.set(m, lift);
pileOf.set(m, pile);
});
if (!round.climbSeen && pile.some((m) => m.lift > 1)) {
round.climbSeen = true;
round.events.push({ type: "climb", x: base.x, y: floor + lift });
}
}
for (const m of round.monsters) {
if (!STACKERS.has(m.kind) || m.dead) continue;
const want = target.get(m) ?? 0;
if (!m.lift && !want) continue;
const floor = floorOf(m);
m.lift = want > m.lift ? Math.min(want, m.lift + CLIMB_V * dt) : Math.max(want, m.lift - UNSTACK_V * dt);
m.y = floor + m.lift;
if (want > 0 && m.lift > 0) {
// Up the pile: drawn in over the one at the bottom, a little to one side.
const pile = pileOf.get(m);
const sway = pile.indexOf(m) % 2 ? 0.35 : -0.35;
m.x += (pile[0].x + sway - m.x) * Math.min(1, 6 * dt);
m.dir = towardYou(round, m);
}
}
return found;
}
// A hellhound: prowls toward you, crouches growling once close on your
// level, lunges in a low arc, and rests a moment after it lands. One that
// lunges into a pit is gone.
function moveHound(round, m, ms, toward) {
const dt = ms / 1000;
const you = round.you;
const spec = round.spec;
const pace = spec.pace;
if (m.act === "leap") {
const py = m.y;
const nx = m.x + m.vx * dt;
if (!wallAt(spec, nx + Math.sign(m.vx) * m.w * 0.4, m.y + 0.05)) m.x = nx;
m.vy = Math.max(-FALL_MAX, m.vy - GRAVITY * dt);
m.y += m.vy * dt;
const g = groundAt(spec, m.x);
if (m.vy < 0 && py >= g && m.y <= g) Object.assign(m, { y: g, vx: 0, vy: 0, act: "rest", wait: HOUND_REST_MS });
if (m.y < PIT_Y) m.dead = true;
return;
}
if (m.wait > 0) {
m.wait = Math.max(0, m.wait - ms * (m.act === "crouch" ? 1 : pace));
if (m.wait > 0) return;
if (m.act === "crouch") {
Object.assign(m, { act: "leap", vx: m.dir * HOUND_LUNGE_VX * pace, vy: HOUND_LUNGE_V });
round.events.push({ type: "lunge", x: m.x, y: m.y });
return;
}
}
if (Math.abs(you.x - m.x) < HOUND_RANGE && Math.abs(you.y - m.y) < 5) {
Object.assign(m, { dir: toward, act: "crouch", wait: HOUND_CROUCH_MS });
round.events.push({ type: "growl", x: m.x, y: m.y });
return;
}
m.act = "prowl";
walk(round, m, toward, MONSTERS.hound.speed * pace, dt);
}
// A Huntsman: runs at you along the floor, crouches once close, and springs
// at you, high and fast; one that springs into a pit is gone.
function moveHuntsman(round, m, ms, toward) {
const dt = ms / 1000;
const you = round.you;
const spec = round.spec;
const pace = spec.pace;
if (m.act === "leap") {
const py = m.y;
const nx = m.x + m.vx * dt;
if (!wallAt(spec, nx + Math.sign(m.vx) * m.w * 0.4, m.y + 0.05)) m.x = nx;
m.vy = Math.max(-FALL_MAX, m.vy - GRAVITY * dt);
m.y += m.vy * dt;
const g = groundAt(spec, m.x);
if (m.vy < 0 && py >= g && m.y <= g) Object.assign(m, { y: g, vx: 0, vy: 0, act: "rest", wait: HUNT_REST_MS });
if (m.y < PIT_Y) m.dead = true;
return;
}
if (m.wait > 0) {
m.wait = Math.max(0, m.wait - ms * (m.act === "crouch" ? 1 : pace));
if (m.wait > 0) return;
if (m.act === "crouch") return springAt(round, m);
}
const up = you.y - m.y;
if (Math.abs(you.x - m.x) < HUNT_RANGE && up > -3 && up < HUNT_HIGH && you.out <= 0) {
Object.assign(m, { dir: toward, act: "crouch", wait: HUNT_CROUCH_MS });
round.events.push({ type: "growl", kind: m.kind, x: m.x, y: m.y });
return;
}
m.act = "prowl";
walk(round, m, toward, MONSTERS.huntsman.speed * pace, dt);
}
// A Huntsman's spring: up to HUNT_UP over your height, coming down on where
// you are now.
export function springAt(round, m) {
const you = round.you;
const rise = Math.max(0, you.y + 1 - m.y);
const vy = Math.sqrt(2 * GRAVITY * (rise + HUNT_UP));
const t = (vy + Math.sqrt(2 * GRAVITY * HUNT_UP)) / GRAVITY;
const vx = clamp((you.x - m.x) / t, -HUNT_VX, HUNT_VX);
Object.assign(m, { act: "leap", vx, vy, dir: Math.sign(vx) || m.dir, y: m.y + 0.01 });
round.events.push({ type: "lunge", kind: m.kind, x: m.x, y: m.y });
}
// A widow: hangs from the ceiling till you come near, drops on its thread
// onto whatever is under it, then skitters after you.
function moveSpider(round, m, ms, toward) {
const you = round.you;
if (m.act === "hang") {
if (Math.abs(you.x - m.x) < SPIDER_NEAR && you.y < m.y - 4) {
m.act = "drop";
round.events.push({ type: "skitter", x: m.x, y: m.y });
}
return;
}
if (m.act === "drop") {
const py = m.y;
m.y -= SPIDER_DROP_V * round.spec.pace * (ms / 1000);
const f = landing(round, m.x, py, m.y, -1);
if (f) {
m.y = f.y;
m.act = "walk";
} else if (m.y < PIT_Y) m.dead = true;
return;
}
walk(round, m, toward, MONSTERS.spider.speed * round.spec.pace, ms / 1000);
}
// A wraith: unseen till you come near, then hovers ahead of you, shrieks,
// dives straight at where your chest was and on past, and climbs back to
// hover again. Walls never stop it; the floor turns it.
function moveWraith(round, m, ms) {
const dt = ms / 1000;
const you = round.you;
const spec = round.spec;
const pace = spec.pace;
if (m.act === "idle") {
if (Math.abs(you.x - m.x) < WRAITH_NEAR) {
Object.assign(m, { act: "hover", wait: WRAITH_HOVER_MS * 0.6 });
round.events.push({ type: "wraith", x: m.x, y: m.y });
}
return;
}
if (m.act === "hover" || m.act === "rise") {
const side = Math.sign(m.x - you.x) || 1;
const tx = you.x + side * WRAITH_KEEP;
const ty = Math.min(m.home, you.y + WRAITH_ABOVE) + Math.sin(m.t / 400) * 1.5;
const step = MONSTERS.wraith.speed * pace * (m.act === "rise" ? 1.8 : 1) * dt;
m.x += clamp(tx - m.x, -step * 3, step * 3);
m.y += clamp(ty - m.y, -step, step);
m.dir = -side;
if (m.act === "rise") {
if (Math.abs(ty - m.y) < 1.5) Object.assign(m, { act: "hover", wait: WRAITH_HOVER_MS });
return;
}
m.wait -= ms * pace;
const inView = m.x > round.camX + 2 && m.x < round.camX + FIELD_W - 2;
if (m.wait <= 0 && inView) {
Object.assign(m, { act: "wind", wait: WRAITH_WIND_MS });
round.events.push({ type: "shriek", x: m.x, y: m.y });
}
return;
}
if (m.act === "wind") {
m.wait -= ms;
if (m.wait > 0) return;
const tx = you.x - m.x;
const ty = you.y + (YOU_H - m.h) / 2 - m.y;
const d = Math.hypot(tx, ty) || 1;
Object.assign(m, { act: "dive", vx: (tx / d) * WRAITH_DIVE_V * pace, vy: (ty / d) * WRAITH_DIVE_V * pace, left: d + WRAITH_PAST, dir: Math.sign(tx) || m.dir });
round.events.push({ type: "dive", x: m.x, y: m.y });
return;
}
m.x += m.vx * dt;
m.y += m.vy * dt;
m.left -= Math.hypot(m.vx, m.vy) * dt;
const floor = groundAt(spec, m.x);
if (floor > -Infinity && m.y < floor + 0.3) {
m.y = floor + 0.3;
m.vy = Math.max(0, m.vy);
}
if (m.left <= 0) m.act = "rise";
}
// One slice of the thrown bones and acid, the puddles and the shockwaves.
export function moveMissiles(round, ms) {
const dt = ms / 1000;
const spec = round.spec;
let n = 0;
for (const b of round.bones) {
b.vy -= BONE_G * dt;
b.x += b.vx * dt;
b.y += b.vy * dt;
b.spin += dt * 12 * (Math.sign(b.vx) || 1);
b.life -= ms;
const g = groundAt(spec, b.x);
if (b.vy < 0 && b.y <= g) {
if (b.kind === "acid") {
round.puddles.push({ id: ++serial, x: b.x, y: g, life: PUDDLE_MS });
round.events.push({ type: "splash", x: b.x, y: g });
} else if (!(LANDS[b.kind] && LANDS[b.kind](round, b, g, KIT))) round.events.push({ type: "clatter", x: b.x, y: g });
continue;
}
if (b.life > 0 && b.y > PIT_Y && b.x > round.camX - 20 && b.x < round.camX + FIELD_W + 20) round.bones[n++] = b;
}
round.bones.length = n;
n = 0;
for (const p of round.puddles) if ((p.life -= ms) > 0) round.puddles[n++] = p;
round.puddles.length = n;
n = 0;
for (const w of round.waves) {
w.x += w.dir * WAVE_SPEED * spec.pace * dt;
w.life -= ms;
if (w.life > 0 && groundAt(spec, w.x) === w.y && w.x > leftEdge(round) - 2 && w.x < spec.length) round.waves[n++] = w;
}
round.waves.length = n;
}
@@ -0,0 +1,206 @@
// Plan2Code Web Console - Ghoul Rush's ground and Planny: what stands where (surfaces, shelves and landing on them), and how Planny runs, jumps and falls.
//
// One of the parts of ghoul.js (see its header and the list of parts there).
import { iceRun } from "../stages/frozen/ghoul-frozen.js";
import { SLOW_SHARE } from "../stages/graveyard/ghoul-graveyard.js";
import { COYOTE_MS, FROZEN, PLATFORMS, EDGE, FALL_MAX, GRAVITY, JUMP_V, RUN_SPEED, STEP_UP, WATER_JUMP, WATER_SPEED, clamp, mudJump, mudSpeed } from "./ghoul-tables.js";
/* ----------------------------------------------------------- surfaces */
// The top of the ground at `x`, or -Infinity over a pit. Pieces are
// [x0, x1); the last one takes its end too.
export function groundAt(spec, x) {
const g = spec.ground;
for (let i = 0; i < g.length; i++) {
const [x0, x1, y] = g[i];
if (x >= x0 && (x < x1 || (i === g.length - 1 && x <= x1))) return y;
}
return -Infinity;
}
// Whether shelf `i` is there (a crumbled board is not, for a while).
export const shelfThere = (round, i) => !(round.down[i] > 0);
// What something walking at height `y` stands on at `x`: the highest
// surface (the ground or a shelf there) within STEP_UP of `y` either way,
// as { y, shelf } (shelf -1 for the ground), or null. `skip` is a shelf to
// ignore (one being dropped through).
export function footing(round, x, y, skip = -1) {
const spec = round.spec;
let best = null;
const g = groundAt(spec, x);
if (g >= y - STEP_UP && g <= y + STEP_UP) best = { y: g, shelf: -1 };
spec.shelves.forEach(([x0, x1, top], i) => {
if (i === skip || !shelfThere(round, i) || x < x0 || x > x1) return;
if (top >= y - STEP_UP && top <= y + STEP_UP && (!best || top > best.y)) best = { y: top, shelf: i };
});
return best;
}
// The surface a fall from (x, py) to (x, y) lands on: the highest one whose
// top it crossed going down, as { y, shelf }, or null.
export function landing(round, x, py, y, skip) {
const spec = round.spec;
let best = null;
const g = groundAt(spec, x);
if (py >= g - 0.05 && y <= g) best = { y: g, shelf: -1 };
spec.shelves.forEach(([x0, x1, top], i) => {
if (i === skip || !shelfThere(round, i) || x < x0 || x > x1) return;
if (py >= top - 0.05 && y <= top && (!best || top > best.y)) best = { y: top, shelf: i };
});
return best;
}
// Like footing() and landing() for Planny alone: a monster the pack says is a
// floor just now (a parked gurney) counts as one more surface, its top.
function standing(round, x, y) {
let best = footing(round, x, y);
for (const m of round.monsters) {
if (m.dead || !PLATFORMS[m.kind] || !PLATFORMS[m.kind](m) || Math.abs(x - m.x) > m.w / 2) continue;
const top = m.y + m.h;
if (top >= y - STEP_UP && top <= y + STEP_UP && (!best || top > best.y)) best = { y: top, shelf: -1 };
}
return best;
}
function landOn(round, x, py, y, skip) {
let best = landing(round, x, py, y, skip);
for (const m of round.monsters) {
if (m.dead || !PLATFORMS[m.kind] || !PLATFORMS[m.kind](m) || Math.abs(x - m.x) > m.w / 2) continue;
const top = m.y + m.h;
if (py >= top - 0.05 && y <= top && (!best || top > best.y)) best = { y: top, shelf: -1 };
}
return best;
}
// Whether the ground at `x` stands above `y`: a wall to anything there.
export const wallAt = (spec, x, y) => groundAt(spec, x) > y;
// How far left and right Planny may go: the room, or the arena once locked.
export const leftEdge = (round) => Math.max(1.5, round.lockX >= 0 ? round.lockX + 1.5 : 1.5);
export const rightEdge = (round) => round.spec.length - 1.5;
/* -------------------------------------------------------------- Planny */
export function makeYou(x, y) {
return { x, y, vx: 0, vy: 0, state: "run", shelf: -1, face: 1, coyote: 0, drop: -1, cuttable: false, airMs: 0, out: 0, outKind: "", safeMs: 0, garlic: false, hat: false, aliveMs: 0, runMs: 0, fireFx: 0, flapped: false, flingMs: 0, flingVx: 0, heldMs: 0, wet: false, mud: false, mudMs: 0, belt: 0, dimMs: 0, dimBy: 0, slide: 0, glide: false, onIce: false };
}
// The conveyor belts (a room's `belts`, the Funhouse's) push him along the floor: the speed of the one he stands on, or 0.
const beltAt = (spec, you) => {
if (!spec.belts || !spec.belts.length || you.state !== "run" || you.shelf >= 0 || you.y > groundAt(spec, you.x) + 0.01) return 0;
const b = spec.belts.find(([x0, x1]) => you.x >= x0 && you.x <= x1);
return b ? b[2] : 0;
};
// Whether Planny stands on the floor in one of the room's water spans.
const wetAt = (spec, you) => Boolean(spec.water && spec.water.length) && you.state === "run" && you.shelf < 0 && you.y <= groundAt(spec, you.x) + 0.01 && spec.water.some(([x0, x1]) => you.x >= x0 && you.x <= x1);
// Whether Planny stands on the floor in one of the room's mud spans.
const mudAt = (spec, you) => Boolean(spec.mud && spec.mud.length) && you.state === "run" && you.shelf < 0 && you.y <= groundAt(spec, you.x) + 0.01 && spec.mud.some(([x0, x1]) => you.x >= x0 && you.x <= x1);
// Leaves the ground at JUMP_V, or bounces off a stomp at STOMP_V.
export function jump(round, v = JUMP_V) {
const you = round.you;
if (you.out > 0) return false;
you.vy = v === JUMP_V ? JUMP_V * (you.wet ? WATER_JUMP : 1) * (you.mud ? mudJump(you.mudMs) : 1) : v;
you.state = "air";
you.ducking = false;
you.shelf = -1;
you.coyote = 0;
you.drop = -1;
// Only a jump from a press is cut short by letting up go, and only once it
// has risen CUT_AFTER_MS.
you.cuttable = v === JUMP_V;
you.airMs = 0;
if (v === JUMP_V) round.events.push({ type: "jump", x: you.x, y: you.y });
return true;
}
// One slice of your moving: running along the ground or a shelf (walking a
// step, or off an edge into a fall), dropping through a shelf with down,
// ducking with down on the ground (a direction held runs instead), or
// flying, blocked by any wall in the way.
export function moveYou(round, ms) {
const dt = ms / 1000;
const you = round.you;
// Frozen by the bell, held by an orderly or thrown: no key does anything.
const flung = you.flingMs > 0;
const inp = round.stunMs > 0 || you.heldMs > 0 || flung ? FROZEN : round.input;
const spec = round.spec;
const dir = (inp.right ? 1 : 0) - (inp.left ? 1 : 0);
if (dir) you.face = dir;
you.runMs = dir && you.state === "run" ? you.runMs + ms : 0;
// A mourner's wail leaves you running at SLOW_SHARE of your speed a while.
// Knee-deep water (a room's `water` spans): slower on the floor in it.
you.wet = wetAt(spec, you);
// Sinking mud: it grabs harder the longer he stands in it, and lets go on
// dry floor or in the air. Stilt Boots wade free of it (ghoul-powers.js).
you.mud = mudAt(spec, you) && !(round.effects.boots > 0);
you.mudMs = you.mud ? you.mudMs + ms : Math.max(0, you.mudMs - ms);
const speed = RUN_SPEED * (you.slowMs > 0 ? SLOW_SHARE : 1) * (you.wet ? WATER_SPEED : 1) * (you.mud ? mudSpeed(you.mudMs) : 1);
you.belt = beltAt(spec, you);
// Slippery ice (a room's `ice`, the Frozen Lake's): his run eases and slides (ghoul-frozen.js).
const run = spec.ice && spec.ice.length ? iceRun(round, dir, speed, dt, you.state === "run" && you.shelf < 0 && you.y <= groundAt(spec, you.x) + 0.01) : dir * speed;
const want = you.x + (run + you.belt) * dt;
let nx = clamp(want, leftEdge(round), rightEdge(round));
if (nx !== want) you.slide = 0;
if (you.state === "run") {
if (you.shelf >= 0 && !shelfThere(round, you.shelf)) return fall(you, 0);
if (inp.down && you.shelf >= 0 && !dir) {
you.drop = you.shelf;
you.ducking = false;
return fall(you, 0);
}
const duck = Boolean(inp.down) && !dir && you.shelf < 0;
if (duck && !you.ducking) round.events.push({ type: "duck", x: you.x, y: you.y });
you.ducking = duck;
const way = Math.sign(nx - you.x);
if (way && wallAt(spec, nx + way * EDGE, you.y + STEP_UP)) {
nx = you.x;
you.slide = 0;
}
const f = standing(round, nx, you.y);
you.x = nx;
if (f) {
you.y = f.y;
you.shelf = f.shelf;
return;
}
return fall(you, COYOTE_MS);
}
// In the air: no wall passed, gravity, then a landing.
if (flung) nx = clamp(you.x + you.flingVx * dt, leftEdge(round), rightEdge(round));
const push = flung ? Math.sign(you.flingVx) : dir || Math.sign(nx - you.x);
if (push && wallAt(spec, nx + push * EDGE, you.y + 0.05)) {
nx = you.x;
you.slide = 0;
}
you.coyote = Math.max(0, you.coyote - ms);
you.vy = Math.max(-FALL_MAX, you.vy - GRAVITY * dt);
const py = you.y;
you.x = nx;
you.y += you.vy * dt;
if (you.drop >= 0 && you.y < spec.shelves[you.drop][2] - 1) you.drop = -1;
if (you.vy > 0) return;
const f = landOn(round, you.x, py, you.y, you.drop);
if (!f) return;
you.y = f.y;
you.vy = 0;
you.flingMs = 0;
you.state = "run";
you.shelf = f.shelf;
you.drop = -1;
you.cuttable = false;
you.flapped = false;
round.events.push({ type: "land", x: you.x, y: you.y });
}
function fall(you, coyote) {
you.state = "air";
you.ducking = false;
you.vy = 0;
you.shelf = -1;
you.coyote = coyote;
}
@@ -0,0 +1,616 @@
// Plan2Code Web Console - Ghoul Rush's play loop: the kits it hands its packs and ghoul-run.js (KIT, RUN_KIT), the blaster and bolts, hits, stomps and timers, one slice of play, and advance().
//
// One of the parts of ghoul.js (see its header and the list of parts there).
import { armBossDamage, fillBag } from "../arms/ghoul-arms.js";
import { bossIntroFor } from "../story/ghoul-boss-intros.js";
import { introFor } from "../story/ghoul-intros.js";
import { stepStory } from "../story/ghoul-story.js";
import { BONUS_READY_MS, endBonus as endBonusWith, makeBonus } from "./ghoul-bonus.js";
import { START_DICE, askStep, giveDiceGift, markRest, reviveSpot, rollDice } from "./ghoul-dice.js";
import { FLAP_CLEAR, TIMED, pickPower, pickups, powerHere, retryMercy } from "./ghoul-powers.js";
import { CHANDELIER_Y, FIELD_H, FIELD_W, ROOMS, STAGES, stageById } from "./ghoul-rooms.js";
import { camera as cameraWith, clearRoom as clearRoomWith, horde as hordeWith, hurry as hurryWith, lockArena, newRound as newRoundWith, nextRoom as nextRoomWith, onCard, pickStage as pickStageWith, respawn as respawnWith, setupRoom as setupRoomWith, spawners as spawnersWith, stagesLeft as stagesLeftWith, steerSelect as steerSelectWith, stepIntro as stepIntroWith, takeIntro as takeIntroWith, takeSelect as takeSelectWith } from "./ghoul-run.js";
import { pressFire as pressFireWith } from "../arms/ghoul-arms.js";
import { KIT } from "./ghoul-kit.js";
import { DICE_KIT, POWER_KIT, arenaMax, arenaMin, award, dropItem, hurt, hurtBoss, lose, makeBoss, moveBoss, moveHazards, struck } from "./ghoul-fight.js";
import { CAUSES, CUT, HARMLESS, HORDE_WITH, PLACES, RIDES, SHOTS, STONE, TARGETS, TICKS, WEAK, guarded, moveMissiles, moveMonsters, piles, roused, solid, spawnMonster, throwBone, towardYou, walk } from "./ghoul-monsters.js";
import { footing, groundAt, jump, makeYou, moveYou, shelfThere, wallAt } from "./ghoul-planny.js";
import { AIM_DY, AIM_MAX, AIM_RANGE, ARMS_UP, BANNER_REACH, BONE_G, BONE_POINTS, BONE_R, BONUS_START, BONUS_STEP, BOSSES, BOSS_LOCK, CAM_AT, CAM_EASE, CAM_LEAD, CHANDELIER_NEAR, CHANDELIER_SHAKE_MS, CHANDELIER_W, CLEAR_MS, COOL_DELAY_MS, COOL_RATE, CRAWL_NEAR, CRUMBLE_BACK_MS, CRUMBLE_MS, CUT_AFTER_MS, CUT_V, DARK_BEHIND, DARK_CHANCE, DOOR_CLEAR, DOOR_REACH, DUCK_H, DUCK_SHOT_Y, EMERGE_MS, FALL_MAX, FLAWLESS_POINTS, GHOST_HIDE_MS, GHOST_SHOW_MS, GRAVITY, HEAD_BONK, HEAD_SHARE, HEAT_MAX, HIT_H, HIT_W, HORDE_ROOM, HURRY_MS, JUMP_V, MAX_MONSTERS, MONSTERS, OFFER_N, PICK_HOLD_MS, PIT_Y, PUDDLE_W, RAPID_MS, READY_MS, ROOM_POINTS, SAFE_MS, SHOT_R, SHOT_RANGE, SHOT_SPEED, SHOT_Y, SKULL_FROM, SLICE_MS, SPAWN_AHEAD, SPIDER_Y, SPREAD_ANGLE, START_LIVES, STOMP_DAMAGE, STOMP_V, TIME_WARN_MS, WAVE_H, WING_SAVE_ARC, WING_SAVE_MS, YOU_H, clamp, fireGap, reaching, roomFor, seeded, timeFor, variant } from "./ghoul-tables.js";
/* ---------------------------------------------------------------- run */
// The double tap, for the tests (the game calls it from key()).
export const pressFire = (round) => pressFireWith(round, KIT);
// What ghoul-run.js needs from here: the room and stage tables, the timings
// and the helpers that set a room up, handed to its rules the way KIT is
// handed to a stage pack.
const RUN_KIT = Object.freeze({
ROOMS, STAGES, stageById, FIELD_W, CHANDELIER_Y, START_LIVES, START_DICE, TIMED, DARK_CHANCE, BONUS_START, HURRY_MS, OFFER_N, PICK_HOLD_MS,
READY_MS, BONUS_READY_MS, makeBonus, endBonus: (round, won) => endBonusWith(round, won, { award, ROOM_POINTS }), SAFE_MS, CLEAR_MS, BOSS_LOCK, ROOM_POINTS, FLAWLESS_POINTS, CAM_AT, CAM_LEAD, CAM_EASE,
SPAWN_AHEAD, DOOR_CLEAR, EMERGE_MS, CRAWL_NEAR, SPIDER_Y, GHOST_SHOW_MS, GHOST_HIDE_MS, DARK_BEHIND, MAX_MONSTERS, HORDE_ROOM, HORDE_WITH, MONSTERS,
roomFor, seeded, powerHere, pickPower, makeYou, makeBoss, groundAt, timeFor, award, clamp, variant, spawnMonster, introFor, bossIntroFor,
mercy: (round) => retryMercy(round, POWER_KIT),
diceGift: (round) => giveDiceGift(round, DICE_KIT.give),
place: (round) => PLACES.forEach((f) => f(round, KIT)),
});
export const newRound = (seed = (Math.random() * 2 ** 31) >>> 0) => newRoundWith(seed, RUN_KIT);
// Puts the round in a room by id, outside any stage's order (the suites reach a room no stage lists this way).
export const setupRoom = (round, id) => setupRoomWith(round, id, RUN_KIT);
export const stagesLeft = (round) => stagesLeftWith(round, RUN_KIT);
export const pickStage = (round, i = round.pick) => pickStageWith(round, i, RUN_KIT);
export const steerSelect = (round, dStage, dRoom) => steerSelectWith(round, dStage, dRoom, RUN_KIT);
export const takeSelect = (round) => {
if (!takeSelectWith(round, RUN_KIT)) return false;
fillBag(round, round.stage);
return true;
};
const nextRoom = (round, random) => nextRoomWith(round, random, RUN_KIT);
// A stage's intro card moves on (ghoul-run.js): a move key, fire or a click.
export const takeIntro = (round) => takeIntroWith(round, RUN_KIT);
const camera = (round, ms) => cameraWith(round, ms, RUN_KIT);
const respawn = (round) => respawnWith(round, RUN_KIT);
const clearRoom = (round) => clearRoomWith(round, RUN_KIT);
const spawners = (round, ms, random) => spawnersWith(round, ms, random, RUN_KIT);
const horde = (round, ms, random) => hordeWith(round, ms, random, RUN_KIT);
const hurry = (round, ms, random) => hurryWith(round, ms, random, RUN_KIT);
// The tilt for your next bolt: toward the nearest monster (or bone) ahead
// whose middle is near your chest's height (a wraith anywhere the tilt
// reaches), never more than AIM_MAX; 0 for none.
export function aimAt(round) {
const you = round.you;
let best = AIM_RANGE;
let aim = 0;
for (const m of round.monsters) {
if (m.dead || !roused(m)) continue;
const dx = (m.x - you.x) * you.face;
const dy = m.y + m.h / 2 - (you.y + shotY(you));
const reach = m.kind === "wraith" ? Math.max(AIM_DY, dx * Math.tan(AIM_MAX)) : AIM_DY;
if (dx <= 0 || dx >= best || Math.abs(dy) > reach) continue;
best = dx;
aim = clamp(Math.atan2(dy, dx), -AIM_MAX, AIM_MAX);
}
for (const b of round.bones) {
const dx = (b.x - you.x) * you.face;
const dy = b.y - (you.y + shotY(you));
if (b.dead || dx <= 0 || dx >= best || Math.abs(dy) > AIM_DY) continue;
best = dx;
aim = clamp(Math.atan2(dy, dx), -AIM_MAX, AIM_MAX);
}
return aim;
}
// The blaster: while fire is held, a bolt (or three) every fireGap() of its
// heat (RAPID_MS with Rapid fire), and while it is not, it cools.
export function fire(round, ms) {
round.fireMs = Math.max(0, round.fireMs - ms);
const you = round.you;
if (!round.input.fire || you.out > 0 || round.gallery || (round.runner && round.runner.id === "lantern")) {
round.coolMs += ms;
const cooling = Math.min(ms, round.coolMs - COOL_DELAY_MS);
if (cooling > 0) round.heat = Math.max(0, round.heat - (COOL_RATE * cooling) / 1000);
return;
}
round.coolMs = 0;
if (round.fireMs > 0) return;
if (round.effects.rapid > 0) round.fireMs = RAPID_MS;
else {
round.heat = Math.min(HEAT_MAX, round.heat + 1);
round.fireMs = fireGap(round.heat);
}
const aim = aimAt(round);
const angles = round.effects.spread > 0 ? [0, SPREAD_ANGLE, -SPREAD_ANGLE] : [0];
for (const a of angles) round.shots.push({ x: you.x + you.face * 1.8, y: you.y + shotY(you), vx: Math.cos(a + aim) * SHOT_SPEED * you.face, vy: Math.sin(a + aim) * SHOT_SPEED, gone: 0 });
you.fireFx = 90;
round.stats.shots++;
round.events.push({ type: "fire", x: you.x, y: you.y + shotY(you), face: you.face, spread: angles.length > 1 });
}
// Whether a circle at (x, y) of radius r touches a box w by h standing at (bx, by).
const touchBox = (x, y, r, bx, by, w, h) => {
const cx = clamp(x, bx - w / 2, bx + w / 2);
const cy = clamp(y, by, by + h);
return Math.hypot(x - cx, y - cy) < r;
};
// One slice of the bolts: each flies until it hits a monster, a bone, the
// boss or a wall, or has gone SHOT_RANGE.
function moveShots(round, ms, random) {
const dt = ms / 1000;
const spec = round.spec;
let n = 0;
for (const s of round.shots) {
const step = Math.hypot(s.vx, s.vy) * dt;
s.x += s.vx * dt;
s.y += s.vy * dt;
s.gone += step;
let used = false;
if (wallAt(spec, s.x, s.y)) {
round.events.push({ type: "puff", x: s.x, y: s.y });
continue;
}
// A silver bolt (or the Bone Saw's) goes on through every monster it hits, once each.
const silver = round.effects.silver > 0 || round.effects.saw > 0;
for (const m of round.monsters) {
const stone = !m.dead && STONE[m.kind]?.(m);
if (m.dead || !(stone || solid(m)) || (s.hit && s.hit.includes(m.id)) || !touchBox(s.x, s.y, SHOT_R, m.x, m.y, m.w, m.h)) continue;
// Stone: a shot glances off, Holy Water breaks it.
if (stone) {
if (round.effects.holy > 0) hurt(round, m, 99, "holy", random);
else round.events.push({ type: "glance", kind: m.kind, x: s.x, y: s.y });
used = true;
break;
}
const head = MONSTERS[m.kind].head && s.y > m.y + m.h * (1 - HEAD_SHARE);
const cut = round.effects.shears > 0 && CUT.has(m.kind);
const mult = SHOTS.reduce((d, f) => d * f(round, m, s, KIT, random), 1) * (s.dmg || 1);
hurt(round, m, cut ? 99 : mult, cut ? "shears" : head ? "head" : "shot", random);
if (silver || s.pierce) {
s.hit = [...(s.hit || []), m.id];
continue;
}
used = true;
break;
}
if (!used) {
for (const b of round.bones) {
if (b.dead || Math.hypot(b.x - s.x, b.y - s.y) > BONE_R + SHOT_R) continue;
b.dead = true;
award(round, BONE_POINTS);
round.events.push({ type: "bone", kind: b.kind, x: b.x, y: b.y, points: BONE_POINTS });
// A thrown weapon breaks what it meets and flies on.
used = !s.arm;
break;
}
}
if (!used) used = TARGETS.some((f) => f(round, s, KIT));
const boss = round.boss;
if (!used && boss && boss.state === "fight" && touchBox(s.x, s.y, SHOT_R, boss.x, boss.y, boss.w, boss.h) && guarded(boss)) {
round.events.push({ type: "bossBlock", kind: boss.kind, x: s.x, y: s.y });
used = true;
}
if (!used && boss && boss.state === "fight" && touchBox(s.x, s.y, SHOT_R, boss.x, boss.y, boss.w, boss.h)) {
const skull = boss.kind === "bones" && !boss.headless && s.y > boss.y + boss.h * SKULL_FROM;
const weak = WEAK[boss.kind] ? WEAK[boss.kind](boss, s, round, KIT) : 1;
const dmg = (skull ? 2 : 1) * weak;
hurtBoss(round, s.arm ? armBossDamage(round, dmg * s.bossDmg, KIT) : dmg, weak > 1 ? "weak" : skull ? "head" : "shot");
used = true;
}
if (!used && s.gone < (s.range || SHOT_RANGE) && (s.free || (s.x > round.camX - 4 && s.x < round.camX + FIELD_W + 4))) round.shots[n++] = s;
}
round.shots.length = n;
if (round.bones.some((b) => b.dead)) round.bones = round.bones.filter((b) => !b.dead);
if (round.monsters.some((m) => m.dead)) round.monsters = round.monsters.filter((m) => !m.dead);
}
// Your feet came down on a monster's head (or the boss's): it is stomped
// and you bounce. A ghost cannot be stomped. Returns true for a stomp.
export function stomps(round, py, random) {
const you = round.you;
if (you.vy >= 0 && !(you.state === "run" && py > you.y)) return false;
if (you.out > 0) return false;
for (const m of round.monsters) {
if (m.dead || !MONSTERS[m.kind].stomp || !solid(m)) continue;
const top = m.y + m.h;
if (py < top - 0.9 || you.y > top + 0.01 || Math.abs(you.x - m.x) > (reaching(m) ? HEAD_BONK : (HIT_W + m.w) / 2)) continue;
hurt(round, m, MONSTERS[m.kind].stompDamage ?? 99, "stomp", random);
round.events.push({ type: "stomp", x: m.x, y: top });
jump(round, round.input.up ? JUMP_V : STOMP_V);
round.monsters = round.monsters.filter((q) => !q.dead);
return true;
}
const b = round.boss;
if (b && b.state === "fight") {
const top = b.y + b.h;
if (py >= top - 1.2 && you.y <= top + 0.01 && Math.abs(you.x - b.x) <= (HIT_W + b.w) / 2) {
if (guarded(b)) round.events.push({ type: "bossBlock", kind: b.kind, x: you.x, y: top });
else hurtBoss(round, STOMP_DAMAGE, "stomp");
round.events.push({ type: "stomp", x: b.x, y: top });
jump(round, STOMP_V + 8);
return true;
}
}
return false;
}
// How tall you are to what hits you, and where your bolts fly from.
const hitH = (you) => (you.ducking ? DUCK_H : HIT_H);
const shotY = (you) => (you.ducking ? DUCK_SHOT_Y : SHOT_Y);
// Whether a box (the monster's, shrunk a little) overlaps your hit box.
const boxHits = (you, x, y, w, h) => Math.abs(you.x - x) < (HIT_W + w * 0.8) / 2 && you.y < y + h * 0.9 && you.y + hitH(you) > y + h * 0.1;
// Whether a climbing walker's raised arms, ARMS_UP over its head either side
// of it, reach you.
const armsHit = (you, m) => {
const dx = Math.abs(you.x - m.x);
return reaching(m) && dx > HEAD_BONK && dx < (HIT_W + m.w * 0.8) / 2 && you.y < m.y + m.h + ARMS_UP && you.y + hitH(you) > m.y + m.h * 0.9;
};
// The first thing touching you, unless you are safe for a moment.
function hits(round) {
const you = round.you;
if (you.safeMs > 0 || you.out > 0) return;
for (const m of round.monsters) {
if (m.dead || !solid(m) || HARMLESS[m.kind]?.(m) || !(boxHits(you, m.x, m.y, m.w, m.h) || armsHit(you, m))) continue;
struck(round, m.kind, m);
return;
}
for (const b of round.bones) {
if (!touchBox(b.x, b.y, BONE_R, you.x, you.y, HIT_W, hitH(you))) continue;
b.dead = true;
round.bones = round.bones.filter((q) => !q.dead);
struck(round, b.cause || (b.kind === "acid" ? "acid" : b.kind === "stone" ? "stone" : "bone"));
return;
}
for (const h of round.hazards) {
if (!(h.live > 0) || Math.abs(you.x - h.x) >= (h.w + HIT_W) / 2 || you.y >= h.y + h.h || you.y + hitH(you) <= h.y) continue;
struck(round, h.cause);
return;
}
for (const p of round.puddles) {
if (you.state !== "run" || you.y !== p.y || Math.abs(you.x - p.x) >= (PUDDLE_W + HIT_W) / 2 - 0.6) continue;
struck(round, "acid");
return;
}
for (const w of round.waves) {
if (Math.abs(w.x - you.x) < 1.4 && you.y < w.y + WAVE_H) {
struck(round, w.cause || "wave");
return;
}
}
const b = round.boss;
if (b && (b.state === "fight" || b.state === "intro") && boxHits(you, b.x, b.y, b.w, b.h)) struck(round, CAUSES[b.kind] ? CAUSES[b.kind](b) : b.kind);
}
// The chandeliers: one shakes as you run under it, then drops and crushes
// whatever is under it where it lands.
function chandeliers(round, ms, random) {
const dt = ms / 1000;
const you = round.you;
const spec = round.spec;
for (const c of round.falls) {
if (c.state === "hang") {
if (Math.abs(you.x - c.x) < CHANDELIER_NEAR && you.y < c.y - 6) {
c.state = "shake";
c.shake = CHANDELIER_SHAKE_MS;
round.events.push({ type: "creak", x: c.x, y: c.y });
}
continue;
}
if (c.state === "shake") {
c.shake -= ms;
if (c.shake <= 0) c.state = "fall";
continue;
}
if (c.state !== "fall") continue;
c.vy -= GRAVITY * dt;
c.y += c.vy * dt;
const bottom = c.y - 2;
for (const m of round.monsters) {
if (m.dead || Math.abs(m.x - c.x) > (CHANDELIER_W + m.w) / 2 || bottom > m.y + m.h || bottom < m.y) continue;
hurt(round, m, 99, "crush", random);
}
round.monsters = round.monsters.filter((m) => !m.dead);
if (Math.abs(you.x - c.x) < (CHANDELIER_W + HIT_W) / 2 - 0.4 && bottom < you.y + HIT_H && bottom > you.y) struck(round, "chandelier");
const g = groundAt(spec, c.x);
if (bottom <= g) {
c.y = g + 2;
c.state = "down";
round.events.push({ type: "crash", x: c.x, y: g });
}
}
}
// The crumbling boards: one you stand on shakes, then falls away, then
// comes back.
function crumble(round, ms) {
const { shelves } = round.spec;
const you = round.you;
for (let i = 0; i < shelves.length; i++) {
if (shelves[i][3] !== "crumble") continue;
if (round.down[i] > 0) {
round.down[i] = Math.max(0, round.down[i] - ms);
if (!round.down[i]) round.events.push({ type: "back", shelf: i });
} else if (round.shake[i] > 0) {
round.shake[i] = Math.max(0, round.shake[i] - ms);
if (!round.shake[i]) {
round.down[i] = CRUMBLE_BACK_MS;
round.events.push({ type: "drop", shelf: i });
}
} else if (you.state === "run" && you.shelf === i) {
round.shake[i] = CRUMBLE_MS;
round.events.push({ type: "crumble", shelf: i, x: you.x, y: you.y });
}
}
}
// The clocks that run while you play: the bonus, the power-ups, being safe,
// the chain's window.
function timers(round, ms) {
const you = round.you;
round.bonusMs += ms;
while (round.bonusMs >= 1000) {
round.bonusMs -= 1000;
if (round.bonus > 0) {
round.bonus = Math.max(0, round.bonus - BONUS_STEP);
if (!round.bonus && !round.hurry && !round.bonusRound) {
round.hurry = true;
round.events.push({ type: "hurry" });
}
}
}
if (round.timeMs > 0) {
const was = Math.ceil(round.timeMs / 1000);
round.timeMs = Math.max(0, round.timeMs - ms);
const now = Math.ceil(round.timeMs / 1000);
if (now < was && round.timeMs > 0 && round.timeMs <= TIME_WARN_MS) round.events.push({ type: "tick", left: now });
if (!round.timeMs) {
round.events.push({ type: "timeUp", x: you.x, y: you.y });
lose(round, "time");
return;
}
}
for (const k of TIMED) {
if (round.effects[k] > 0) {
round.effects[k] = Math.max(0, round.effects[k] - ms);
if (!round.effects[k]) round.events.push({ type: "expire", kind: k });
}
}
round.stunMs = Math.max(0, (round.stunMs || 0) - ms);
you.heldMs = Math.max(0, (you.heldMs || 0) - ms);
you.flingMs = Math.max(0, (you.flingMs || 0) - ms);
you.safeMs = Math.max(0, you.safeMs - ms);
you.aliveMs = (you.aliveMs || 0) + ms;
you.slowMs = Math.max(0, (you.slowMs || 0) - ms);
you.dimMs = Math.max(0, (you.dimMs || 0) - ms);
you.fireFx = Math.max(0, you.fireFx - ms);
if (round.chainMs > 0) {
round.chainMs = Math.max(0, round.chainMs - ms);
if (!round.chainMs) round.chain = 0;
}
}
// The top of the highest surface under you (the ground, or a shelf there),
// or -Infinity over a pit.
function surfaceBelow(round) {
const you = round.you;
let top = groundAt(round.spec, you.x);
if (top > you.y) top = -Infinity;
round.spec.shelves.forEach(([x0, x1, y], i) => {
if (shelfThere(round, i) && i !== you.drop && you.x >= x0 && you.x <= x1 && y <= you.y && y > top) top = y;
});
return top;
}
// A jump press, first in its slice: from the ground or a shelf, from the
// air a moment after running off an edge, or saved a moment for the landing.
function takeOff(round, ms) {
const you = round.you;
const inp = round.input;
if (inp.jump <= 0) return false;
if (you.state === "run" || you.coyote > 0) {
inp.jump = 0;
return jump(round);
}
// With Bat wings, a press in the air flaps once for another jump, unless
// you are coming down within FLAP_CLEAR of a surface: then it is a press
// saved for the landing, as without them.
if (round.effects.wings > 0 && !you.flapped && you.out <= 0 && !(you.vy < 0 && you.y - surfaceBelow(round) < FLAP_CLEAR)) {
inp.jump = 0;
you.flapped = true;
jump(round);
round.events.push({ type: "flap", x: you.x, y: you.y });
return true;
}
inp.jump = Math.max(0, inp.jump - ms);
return false;
}
// Whether you are at the open door, standing.
function atDoor(round) {
const you = round.you;
return round.hasKey && you.state === "run" && Math.abs(you.x - round.spec.door) < DOOR_REACH && you.y === groundAt(round.spec, round.spec.door);
}
// Your keys for one slice of walking: a jump press, a short hop (up let go
// while a jump still rises), then moveYou.
function walkYou(round, ms, frozen) {
const you = round.you;
if (frozen || you.heldMs > 0 || you.flingMs > 0) round.input.jump = 0;
else takeOff(round, ms);
if (you.state === "air") you.airMs = (you.airMs || 0) + ms;
if (you.cuttable && !round.input.up && you.vy > CUT_V && you.airMs >= CUT_AFTER_MS) {
you.vy = CUT_V;
you.cuttable = false;
}
moveYou(round, ms);
}
function play(round, ms, random) {
for (const f of TICKS) f(round, ms, KIT);
timers(round, ms);
if (round.phase !== "play") return;
// The bell has frozen you (see moveYou) and everything else on the field,
// but for the bolts in flight: no key does anything till it passes.
const frozen = round.stunMs > 0;
const you = round.you;
const py = you.y;
if (you.lift) stepLift(round, ms);
else if (frozen || !RIDES.some((f) => f(round, ms, KIT))) walkYou(round, ms, frozen);
markRest(you);
if (atDoor(round)) return clearRoom(round);
const spec = round.spec;
if (round.boss && round.lockX < 0 && you.x > spec.arena + BOSS_LOCK) lockArena(round);
if (!frozen) fire(round, ms);
// While the Church bell rings, the dead stand still and no more come.
if (!(round.effects.bell > 0 || frozen)) {
spawners(round, ms, random);
horde(round, ms, random);
hurry(round, ms, random);
moveMonsters(round, ms, random);
piles(round, ms);
}
if (!frozen) {
moveBoss(round, ms, random);
moveHazards(round, ms);
moveMissiles(round, ms);
}
moveShots(round, ms, random);
stomps(round, py, random);
chandeliers(round, ms, random);
if (round.phase !== "play") return;
hits(round);
if (round.phase !== "play") return;
pickups(round, ms, POWER_KIT);
crumble(round, ms);
if (you.y < PIT_Y && !you.lift && !wingSave(round)) {
struckFall(round);
return;
}
// Monsters far behind the camera are let go.
if (round.monsters.some((m) => m.x < round.camX - 30 || m.y < PIT_Y)) round.monsters = round.monsters.filter((m) => m.x >= round.camX - 30 && m.y >= PIT_Y);
camera(round, ms);
}
// What a stage pack's rules may use of this file's.
Object.assign(KIT, { BOSSES, shotY, aimAt, dropItem, guarded, weakOf: (b, s, round) => (WEAK[b.kind] ? WEAK[b.kind](b, s, round, KIT) : 1), stone: (m) => Boolean(STONE[m.kind]?.(m)), strike: (round, s) => TARGETS.some((f) => f(round, s, KIT)), harmlessNow: (m) => Boolean(HARMLESS[m.kind]?.(m)), walk, towardYou, throwBone, spawnMonster, groundAt, footing, struck, hurt, hurtBoss, fling, arenaMin, arenaMax, solid, FIELD_W, CHANDELIER_Y, SHOT_Y, YOU_H, HIT_W, HIT_H, GRAVITY, FALL_MAX, PIT_Y, BONE_G, DUCK_H, lose });
Object.freeze(KIT);
// Throws Planny: up at `v` and `dx` units across (signed) by the time he is
// back at the height he left, no key doing anything till he lands. What he
// lands on (a pit, a monster) is what it costs, never the throw.
function fling(round, dx, v) {
const you = round.you;
const t = (2 * v) / GRAVITY;
Object.assign(you, { vy: v, state: "air", shelf: -1, coyote: 0, drop: -1, cuttable: false, airMs: 0, flapped: false, flingVx: dx / t, flingMs: Math.round(t * 1000) + 200 });
return true;
}
// Bat wings catch a fall down a pit, before a life or a Lucky die is at stake:
// no key works while they carry him back. A ride has no ground to go back to.
function wingSave(round) {
if (!(round.effects.wings > 0) || round.spec.ride) return false;
const you = round.you;
const at = reviveSpot(round, DICE_KIT);
round.effects.wings = 0;
round.input.jump = 0;
Object.assign(you, { lift: { x0: you.x, y0: you.y, x: at.x, y: at.y, shelf: at.shelf, t: 0 }, vy: 0, state: "air", shelf: -1, coyote: 0, drop: -1, cuttable: false, flapped: false, flingMs: 0, ducking: false, safeMs: Math.max(you.safeMs, WING_SAVE_MS + SAFE_MS) });
if (at.x !== you.x) you.face = Math.sign(at.x - you.x);
round.events.push({ type: "wingSave", x: you.x, y: 1 });
return true;
}
// One slice of the flight back, and setting him down at the end of it.
function stepLift(round, ms) {
const you = round.you;
const l = you.lift;
l.t += ms;
const k = Math.min(1, l.t / WING_SAVE_MS);
const ease = k * (2 - k);
you.x = l.x0 + (l.x - l.x0) * ease;
you.y = l.y0 + (l.y - l.y0) * ease + Math.sin(Math.PI * k) * WING_SAVE_ARC;
if (k < 1) return;
Object.assign(you, { lift: null, x: l.x, y: l.y, shelf: l.shelf, state: "run", vy: 0 });
round.events.push({ type: "land", x: you.x, y: you.y });
}
// A fall down a pit: always a life, garlic or not.
function struckFall(round) {
round.you.garlic = false;
lose(round, "pit");
}
export function advance(round, ms, random = Math.random) {
let left = ms;
while (left > 0 && !round.over) {
const slice = Math.min(left, SLICE_MS);
left -= slice;
if (round.phase === "ready") {
// The dark ride's title screen holds for a key or a press, its clock running on for the art.
if (round.gallery?.waiting) {
round.phaseMs += slice;
continue;
}
round.phaseMs -= slice;
if (round.phaseMs <= 0) {
round.phase = "play";
round.input.jump = 0;
round.events.push({ type: "go" });
}
continue;
}
if (round.phase === "clear") {
round.phaseMs -= slice;
if (round.phaseMs <= 0) nextRoom(round, random);
continue;
}
// Waiting on a choice of stage: nothing moves.
if (round.phase === "pick") {
round.phaseMs = Math.max(0, round.phaseMs - slice - left);
return "pick";
}
if (round.phase === "select") return "select";
if (onCard(round)) {
stepIntroWith(round, slice);
continue;
}
// The intro story, before the first room: only its pages move.
if (round.phase === "story") {
stepStory(round, slice);
continue;
}
round.clock += slice;
// Asking whether to use a Lucky die for a life: nothing else moves.
if (round.phase === "ask") {
askStep(round, slice);
continue;
}
// Rolling the Lucky dice for a life: nothing else moves.
if (round.phase === "roll") {
rollDice(round, slice, random, DICE_KIT);
continue;
}
if (round.phase === "crash") {
round.phaseMs -= slice;
round.you.out = Math.max(1, round.phaseMs);
moveMonsters(round, slice, random);
moveMissiles(round, slice);
if (round.phaseMs <= 0) respawn(round);
continue;
}
play(round, slice, random);
}
return round.over ? "over" : round.phase;
}
/* ------------------------------------------------------------- banners */
// Whether anything that matters to you is in a banner's strip, its middle
// `y` units down from the field's top: you, a monster on screen that can
// hurt you (not a roosting bat, a widow still on the ceiling, a faded ghost
// or one still coming up), the boss, a bone, a glob of acid, a puddle or a
// shockwave.
export function underBanner(round, y) {
const lo = round.camX - 2;
const hi = round.camX + FIELD_W + 2;
const inStrip = (x, bottom, h) => x > lo && x < hi && FIELD_H - (bottom + h) < y + BANNER_REACH && FIELD_H - bottom > y - BANNER_REACH;
const you = round.you;
if (inStrip(you.x, you.y, YOU_H)) return true;
// A roosting bat, or anything not yet able to hurt you, does not count.
if (round.monsters.some((m) => roused(m) && inStrip(m.x, m.y, m.h))) return true;
if (round.bones.some((b) => inStrip(b.x, b.y - BONE_R, BONE_R * 2))) return true;
if (round.puddles.some((p) => inStrip(p.x, p.y, 1))) return true;
if (round.waves.some((w) => inStrip(w.x, w.y, WAVE_H))) return true;
// A room drawn whole by its own art (the Drowned Lantern) lists what matters there as [x, y up].
if (round.runner && round.runner.marks && round.runner.marks.some(([x, y]) => inStrip(x, y - YOU_H / 2, YOU_H))) return true;
const b = round.boss;
return Boolean(b && b.state !== "sleep" && b.state !== "down" && inStrip(b.x, b.y, b.h));
}
// Where a banner goes: high on the field while you are low on it, low
// while you are high.
export const bannerY = (round) => (round.you.y > FIELD_H * 0.42 ? FIELD_H * 0.72 : FIELD_H * 0.3);
@@ -1,7 +1,7 @@
// Plan2Code Web Console - Ghoul Rush's power-ups and pickups: what each power-up does (POWERS), which can turn up where, picking one, and taking candy, power-ups, crystals and the key.
//
// No imports: ghoul.js hands the rules here a kit of its own helpers and
// numbers (landing, MAX_LIVES, GRAVITY and the rest), the way it hands a
// numbers (landing, GRAVITY and the rest), the way it hands a
// stage pack its KIT, so this file never reaches back into it. ghoul.js
// re-exports what it always exported from here (POWERS, TIMED, powerHere,
// applyPower and the numbers), so its importers need not know.
@@ -22,16 +22,16 @@
// found only in The Deep Seam Mine) is worn till a rock bounces off it or an imp
// knocks it off;
// the secondary weapons (`arm: true`, see below) are not timed either; the Garlic shield shrugs off one hit (and sees off whatever
// touched you), a 1UP is a life (POWER_POINTS more past MAX_LIVES), and the
// touched you), a 1UP is a life (no limit), and the
// Hourglass puts HOURGLASS_MS on the room's clock (POWER_POINTS more where
// there is none). A Lucky die is kept for the run (ghoul-dice.js rolls it
// when a life would be lost), up to MAX_DICE (POWER_POINTS more past it), and
// when a life would be lost), with no limit on how many, and
// turns up only as a drop (`drop: true`), as often as a 1UP. A kill (in
// ghoul.js) drops candy DROP_CANDY of the time and a power-up DROP_POWER, by
// `weight`.
export const POWERS = Object.freeze({
spread: Object.freeze({ name: "Spread shot", blurb: "Three bolts at once", color: "#ff8a1f", ms: 8000, weight: 3 }),
rapid: Object.freeze({ name: "Rapid fire", blurb: "Twice the bolts", color: "#e04dd0", ms: 8000, weight: 3 }),
rapid: Object.freeze({ name: "Rapid fire", blurb: "65% more bolts", color: "#e04dd0", ms: 8000, weight: 3 }),
garlic: Object.freeze({ name: "Garlic shield", blurb: "Shrugs off one hit", color: "#e6e0b8", weight: 2 }),
life: Object.freeze({ name: "1UP", blurb: "An extra life", color: "#ff4fa3", weight: 1.5 }),
lantern: Object.freeze({ name: "Lantern", blurb: "The dark pulls back", color: "#ffc857", ms: 15000, weight: 3, dark: true }),
@@ -144,7 +144,7 @@ export function pickPower(random, round, skip = "", dropping = false) {
}
// A power-up taken: a timed one starts, or adds its time to what is left of
// the same one already running; the rest act at once. `kit` is ghoul.js's kit (for MAX_LIVES).
// the same one already running; the rest act at once. `kit` is ghoul.js's kit.
export function applyPower(round, kind, kit) {
const you = round.you;
if (TIMED.includes(kind)) round.effects[kind] = (round.effects[kind] || 0) + POWERS[kind].ms;
@@ -155,11 +155,9 @@ export function applyPower(round, kind, kit) {
else award(round, POWER_POINTS);
}
else if (kind === "life") {
if (round.lives < kit.MAX_LIVES) round.lives++;
else award(round, POWER_POINTS * 10);
round.lives++;
} else if (kind === "die") {
if (round.dice < kit.MAX_DICE) round.dice++;
else award(round, POWER_POINTS * 10);
round.dice++;
} else if (POWERS[kind].arm && !addArm(round, kind)) award(round, POWER_POINTS);
}
@@ -143,7 +143,7 @@
// 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";
import { COURSE } from "../rides/pew/ghoul-pew-course.js";
export const FIELD_W = 96;
@@ -1479,57 +1479,58 @@ export const ROOMS = freeze([
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]],
items: [["wings", 60, 6], ["rapid", 168, 15], ["spread", 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]],
// The Drowned Lantern, Gallows Bog's BONUS ROUND (see ghoul-lantern.js and ghoul-bonus.js): not a ride.
// A top-down game on one fixed screen: carry a lantern over a black island of mossy hummocks and plank
// walks, light the five wisp shrines (each guarded by a circling wisp), then run back to the boat while
// Old Mother Bog rises out of her pool in the middle. The Bog Lurker hears steps on the planks, the
// leeches keep out of the light, the bog bodies lie beside the planks. The whole field is the art's
// (ghoul-lantern-draw.js), so this room's ground is only the floor the door stands on; the island is
// `ride`. Positions are field units, y counted down from the field's top; `planks` join two hummocks.
room("lantern", "The Drowned Lantern", "Keep the flame lit, and keep quiet", {
length: 96,
ground: [[0, 96, 12]],
start: 8,
key: null,
door: 2390,
door: 95,
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],
],
candy: [],
items: [],
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]],
runner: "lantern",
time: 90000,
how: "ARROWS walk, SPACE flares. Light 5 shrines, then run to the boat",
start: [10, 45],
boat: [3.5, 45],
pool: [48.5, 30],
hummocks: [[10, 45, 5.5], [28, 44, 4.5], [13, 23, 5], [32, 30, 4.5], [40, 15, 5], [62, 15, 4.5], [83, 16, 5.5], [84, 36, 5], [64, 46, 5], [47, 44, 4], [65, 30, 4]],
planks: [[0, 1], [0, 2], [1, 3], [1, 9], [2, 3], [2, 4], [3, 4], [4, 5], [5, 6], [5, 10], [6, 7], [7, 8], [8, 9], [10, 7], [10, 8], [3, 10]],
shrines: [2, 4, 6, 7, 8],
bodies: [[14.4, 34.4], [51, 17.9], [48.5, 32.9], [37.5, 41.1], [75.3, 43.6]],
lurker: { home: [74, 24], route: [[74, 24], [56, 38], [38, 37], [22, 33], [22, 14], [52, 22]] },
leeches: [
{ home: [22, 14], route: [[22, 14], [30, 22], [18, 30]] },
{ home: [56, 22], route: [[56, 22], [56, 38], [42, 24]] },
{ home: [78, 50], route: [[78, 50], [90, 46], [72, 52]] },
],
wisps: [
{ shrine: 0, phase: 0, home: [18.5, 23] },
{ shrine: 1, phase: 1.3, home: [41.5, 20.3] },
{ shrine: 2, phase: 2.6, home: [78.3, 18.8] },
{ shrine: 3, phase: 3.9, home: [80, 32.3] },
{ shrine: 4, phase: 5.2, home: [66.6, 41.1] },
{ shrine: -1, wake: 3, home: [48.5, 30], route: [[48.5, 30], [30, 38], [20, 30], [40, 22]] },
{ shrine: -1, wake: 4, home: [48.5, 30], route: [[48.5, 30], [70, 40], [86, 26], [60, 22]] },
{ shrine: -1, wake: 5, home: [48.5, 30], route: [[48.5, 30], [30, 40], [12, 40], [28, 46]] },
],
},
}),
// The Drowning Pool, Gallows Bog's boss room: planks over open black
@@ -1542,7 +1543,7 @@ export const ROOMS = freeze([
key: null,
door: 194,
candy: [[18, 8.5, 5], [70, 8.5, 5]],
items: [["garlic", 24, 6]],
items: [["garlic", 24, 6], ["harpoon", 48, 6]],
spawns: [["zombie", 44], ["crawl", 96]],
boss: "motherbog",
}),
@@ -1571,6 +1572,6 @@ export const STAGES = freeze([
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"]),
stage("bog", "Gallows Bog", "The mud does not like to let go", ["boardwalk", "hollow", "stilts", "lantern", "drowning"]),
]);
export const stageById = (id) => STAGES.find((s) => s.id === id) || null;
@@ -114,6 +114,7 @@ export function newRound(seed, kit) {
// Lucky dice kept for the run, and the roll in hand while a life is at stake.
dice: START_DICE,
roll: null,
ask: null,
// The bonus room's own hearts and result, null elsewhere (ghoul-bonus.js).
bonusRound: null,
// The secondary weapons in the bag, the latest picked up first, and whether one has been used yet (ghoul-arms.js).
@@ -0,0 +1,557 @@
// Plan2Code Web Console - Ghoul Rush's numbers and tables: every timing and size the rules share, the monsters and bosses with each stage pack's joined in (PACKS), the seeded dice, and a room's numbers at a depth (roomFor).
//
// One of the parts of ghoul.js (see its header and the list of parts there).
import { ARMS, releaseFire } from "../arms/ghoul-arms.js";
import { BANISTER } from "../rides/banister/ghoul-banister.js";
import { CART } from "../rides/cart/ghoul-cart.js";
import { RIDE } from "../rides/dark-ride/ghoul-ride.js";
import { GURNEY } from "../rides/gurney/ghoul-gurney.js";
import { HEARSE } from "../rides/hearse/ghoul-hearse.js";
import { LANTERN } from "../rides/lantern/ghoul-lantern.js";
import { MOWER } from "../rides/mower/ghoul-mower.js";
import { PEW } from "../rides/pew/ghoul-pew.js";
import { SLED } from "../rides/sled/ghoul-sled.js";
import { TRAY } from "../rides/tray/ghoul-tray.js";
import { WAGON } from "../rides/wagon/ghoul-wagon.js";
import { BOG } from "../stages/bog/ghoul-bog.js";
import { CARNIVAL } from "../stages/carnival/ghoul-carnival.js";
import { CHAPEL } from "../stages/chapel/ghoul-chapel.js";
import { FROZEN as FROZEN_LAKE } from "../stages/frozen/ghoul-frozen.js";
import { GRAVEYARD } from "../stages/graveyard/ghoul-graveyard.js";
import { GROUNDS } from "../stages/grounds/ghoul-grounds.js";
import { MINE } from "../stages/mine/ghoul-mine.js";
import { SANATORIUM } from "../stages/sanatorium/ghoul-sanatorium.js";
import { VILLAGE } from "../stages/village/ghoul-village.js";
import { BONES } from "../stages/wing/ghoul-bones.js";
import { FLAP_CLEAR, POWERS, TIMED, powerHere } from "./ghoul-powers.js";
import { CEILING_Y, FIELD_H, FIELD_W, FLOOR_Y, ROOMS, STAGES, roomById, stageById } from "./ghoul-rooms.js";
import { steerPick } from "./ghoul-run.js";
export { FIELD_H, FIELD_W, FLOOR_Y, ROOMS, STAGES, roomById, stageById };
export { FLAP_CLEAR, POWERS, TIMED, powerHere };
export { INTRO_MIN_MS } from "./ghoul-run.js";
export { releaseFire };
// The stage pick, which moved to ghoul-run.js.
export { steerPick };
export { CANDY_POINTS, CRYSTAL_POINTS, HOURGLASS_MS, POWER_POINTS } from "./ghoul-powers.js";
// The Lucky die's numbers, which the tests read from here.
export { ASK_GUARD_MS, DICE_FACES, LEAD_MS, MAX_DICE, START_DICE, ROLL_MS, SAVED_TIME_MS, TUMBLE_MS } from "./ghoul-dice.js";
// The bonus rounds' numbers (the Runaway Cart is the first), which the tests read from here.
export { BONUS_FLOOR, BONUS_HEARTS, BONUS_SAFE_MS, CARD_LOST_MS, CARD_MS, diceFor } from "./ghoul-bonus.js";
// Old Rattlebones' numbers, which the tests read from here.
export { BONES_KEEP, BONES_MS, BONES_RAGE_MS, BONES_WINDUP_MS, VOLLEY } from "../stages/wing/ghoul-bones.js";
// The board: the strip of pills along the top, then the field. The strip is
// one row of pills tall (ghoul-draw.js's hudLayout shrinks the pills to keep
// them in one row), so the field gets the room. The field runs to the
// canvas's edges with no frame (PAD 0), so full screen shows all play. The
// canvas scales a unit in quarter-pixel steps.
export const HUD_H = 4.5;
export const PAD = 0;
export const W = PAD * 2 + FIELD_W;
export const H = HUD_H + FIELD_H + PAD;
// Below this many pixels a unit, Planny and the monsters are too small to
// read; the window shows its bigger-window note.
export const MIN_CELL = 3;
// Planny, in units: YOU_W across and YOU_H tall as drawn, his feet at his y.
// Monsters hit a smaller box, HIT_W by HIT_H, so a graze never counts.
export const YOU_W = 3.6;
export const YOU_H = 5;
export const HIT_W = 2.4;
export const HIT_H = 4.4;
// Ducking (down, on the ground, not running): HIT_H falls to DUCK_H, and his
// bolts fly from DUCK_SHOT_Y. A swooper (a pack's `swoops`) ramps up over a
// ducked Planny, its underside SWOOP_CLEAR above his feet by the time it can
// touch him, starting SWOOP_NEAR short of that: so duck before it arrives and it
// passes overhead, whatever the angle of its dive. Standing, it still hits him.
export const DUCK_H = 2.4;
export const DUCK_SHOT_Y = 1.4;
export const SWOOP_CLEAR = 2.6;
export const SWOOP_NEAR = 3;
// Half his width, where his front edge meets a wall.
export const EDGE = 1.2;
// Moving, in units and seconds. Running is RUN_SPEED at once, on the ground
// and in the air alike (no slide, no drift: an arcade's grip). A jump leaves
// at JUMP_V against GRAVITY (12 units high and about 0.61 s in the air, a
// snappy arc); letting up go while still rising cuts the jump to CUT_V.
// Landing on a monster bounces you up at STOMP_V. Nothing falls faster than
// FALL_MAX.
export const RUN_SPEED = 36;
export const GRAVITY = 260;
export const JUMP_V = 79;
export const CUT_V = 28;
// A jump always rises CUT_AFTER_MS before letting go of up can cut it, so a
// press saved for a landing and let go before it never comes out as a twitch.
export const CUT_AFTER_MS = 50;
export const STOMP_V = 58;
export const FALL_MAX = 120;
// Knee-deep water (a room's `water` spans of floor, the Mine's tunnels): on the
// floor in one Planny runs at WATER_SPEED of his speed and a jump leaves at
// WATER_JUMP of its speed; `you.wet` says so (ghoul-mine.js reads it).
export const WATER_SPEED = 0.65;
export const WATER_JUMP = 0.93;
// Sinking mud (a room's `mud` spans, Gallows Bog): on the floor in one,
// `you.mudMs` climbs toward MUD_MS and the run sags from WATER_SPEED down to
// MUD_SPEED_MIN, a jump from WATER_JUMP down to MUD_JUMP_MIN; dry floor or
// the air lets it go again (`you.mud`, `you.mudMs`).
export const MUD_MS = 2400;
export const MUD_SPEED_MIN = 0.25;
export const MUD_JUMP_MIN = 0.7;
export const mudSpeed = (ms) => WATER_SPEED + (MUD_SPEED_MIN - WATER_SPEED) * Math.min(1, ms / MUD_MS);
export const mudJump = (ms) => WATER_JUMP + (MUD_JUMP_MIN - WATER_JUMP) * Math.min(1, ms / MUD_MS);
// A step of STEP_UP or less between two surfaces is walked, not jumped.
export const STEP_UP = 3;
// Forgiving edges: a jump pressed up to COYOTE_MS after running off an edge
// still leaves it, and a press up to JUMP_BUFFER_MS before landing jumps as
// you land.
export const COYOTE_MS = 100;
export const JUMP_BUFFER_MS = 120;
// Under this height a fall has gone down a pit.
export const PIT_Y = -8;
// Bat wings save a fall down a pit: Planny flies back over WING_SAVE_MS to the
// last solid ground he stood on, swooping WING_SAVE_ARC over the straight line,
// safe till a moment after he lands, and the wings are spent (see wingSave).
export const WING_SAVE_MS = 700;
export const WING_SAVE_ARC = 7;
// Nothing moves more than FALL_MAX * SLICE_MS / 1000 units (0.48) in a
// slice, and a landing is found by crossing a surface's line, so no fall
// goes through one.
export const SLICE_MS = 4;
// The flashlight blaster: a bolt every FIRE_MS while fire is held (RAPID_MS
// with Rapid fire), flying SHOT_SPEED level with Planny's chest (SHOT_Y over
// his feet) until it hits something, a wall, or has gone SHOT_RANGE. Spread
// shot adds two more, SPREAD_ANGLE up and down.
export const FIRE_MS = 100;
export const RAPID_MS = 60;
export const SHOT_SPEED = 130;
export const SHOT_RANGE = 80;
export const SHOT_Y = 2.4;
export const SHOT_R = 0.5;
// The blaster heats up, so holding or hammering fire is not the whole game.
// Each bolt adds a shot of heat: the first HEAT_FREE go at the full rate,
// then each waits longer, until from HEAT_MAX on it fires one bolt every
// SLOW_FIRE_MS. Let go of fire and, once COOL_DELAY_MS has passed without
// firing (so tapping it does not cool it), it sheds COOL_RATE shots of heat a
// second. So about three seconds of fire go at the full rate, a held blaster
// is down to one bolt a second some fifteen seconds in, and the hottest one
// is cool again a couple of seconds after it is let go. Rapid fire's bolts
// add no heat and ignore it.
export const HEAT_FREE = 30;
export const HEAT_MAX = 50;
export const SLOW_FIRE_MS = 1000;
export const COOL_DELAY_MS = 200;
export const COOL_RATE = 25;
// The blaster fizzes from half of HEAT_FREE on.
export const HEAT_SHOWN = HEAT_FREE / 2;
// The wait after a bolt fired at `heat`: FIRE_MS while cool, rising in a
// line to SLOW_FIRE_MS at HEAT_MAX.
export function fireGap(heat) {
const t = clamp((heat - HEAT_FREE) / (HEAT_MAX - HEAT_FREE), 0, 1);
return Math.round(FIRE_MS + (SLOW_FIRE_MS - FIRE_MS) * t);
}
export const SPREAD_ANGLE = 0.13;
// A little help aiming: a bolt tilts toward the nearest monster ahead within
// AIM_RANGE whose middle is within AIM_DY of your chest, by up to AIM_MAX.
export const AIM_RANGE = 50;
export const AIM_DY = 9;
export const AIM_MAX = 0.5;
// The monsters: a box `w` across and `h` tall standing on (or flying with
// its bottom at) its y, the shots it takes, its speed, the points a kill is
// worth, whether a stomp from above kills it and whether its head (the top
// HEAD_SHARE of it) doubles a kill. A zombie (a runner, a glutton) sprints at
// `lurch` once you are within LURCH_RANGE on its level. `stompDamage`, where
// set, is all a stomp takes off (a glutton is too soft to burst at once).
// `color` is what spills when it dies.
// The stage packs: each stage past the house's own two brings its monsters,
// its boss and their rules (see ghoul-graveyard.js for what a pack holds).
// Their tables join this file's own, and their rules run where its own do.
const PACKS = Object.freeze([BONES, GRAVEYARD, GROUNDS, CHAPEL, SANATORIUM, VILLAGE, MINE, ARMS, CART, SLED, GURNEY, PEW, MOWER, WAGON, HEARSE, TRAY, CARNIVAL, FROZEN_LAKE, BOG, LANTERN, RIDE, BANISTER]);
export const fromPacks = (key) => Object.assign({}, ...PACKS.map((pk) => pk[key] || {}));
export const listPacks = (key) => PACKS.flatMap((pk) => pk[key] || []);
export const MONSTERS = Object.freeze({
...fromPacks("monsters"),
zombie: Object.freeze({ name: "Zombie", w: 3, h: 5, hp: 3, speed: 9, lurch: 20, points: 100, stomp: true, head: true, color: "#7a1010" }),
runner: Object.freeze({ name: "Runner", w: 2.4, h: 5.2, hp: 1, speed: 24, lurch: 34, points: 120, stomp: true, head: true, color: "#7a1010" }),
glutton: Object.freeze({ name: "Glutton", w: 4.8, h: 5.4, hp: 15, speed: 5, lurch: 7, points: 250, stomp: true, stompDamage: 3, head: true, color: "#6a1a10" }),
crawler: Object.freeze({ name: "Crawler", w: 3, h: 2.4, hp: 2, speed: 16, points: 75, stomp: true, head: false, color: "#7a1010" }),
bat: Object.freeze({ name: "Bat", w: 2.6, h: 1.6, hp: 1, speed: 26, points: 50, stomp: true, head: false, color: "#5a0c14" }),
ghost: Object.freeze({ name: "Ghost", w: 3.2, h: 4, hp: 3, speed: 10, points: 150, stomp: false, head: false, color: "#b8e6d0" }),
skeleton: Object.freeze({ name: "Skeleton", w: 3, h: 5.2, hp: 4, speed: 0, points: 200, stomp: true, head: true, color: "#cfc4a6" }),
seed: Object.freeze({ name: "Gourdling", w: 2.2, h: 2, hp: 1, speed: 14, points: 40, stomp: true, head: false, color: "#8a4a12" }),
hound: Object.freeze({ name: "Hellhound", w: 3.8, h: 2.6, hp: 2, speed: 13, points: 150, stomp: true, head: false, color: "#8a0e0e" }),
spider: Object.freeze({ name: "Widow", w: 3.2, h: 2, hp: 2, speed: 18, points: 120, stomp: true, head: false, color: "#3d5a1a" }),
huntsman: Object.freeze({ name: "Huntsman", w: 4.8, h: 2.8, hp: 4, speed: 20, points: 300, stomp: true, head: false, color: "#3a2a12" }),
wraith: Object.freeze({ name: "Wraith", w: 3, h: 4.2, hp: 2, speed: 12, points: 200, stomp: false, head: false, color: "#9fb2c4" }),
spitter: Object.freeze({ name: "Bloater", w: 4.2, h: 4.8, hp: 5, speed: 3, points: 250, stomp: false, head: true, color: "#8fa82a" }),
});
export const HEAD_SHARE = 0.3;
// The zombies and their kin, which shamble, lurch and come out of doors alike.
export const ZOMBIES = new Set(["zombie", "runner", "glutton", ...listPacks("zombies")]);
// Now and then a zombie that comes is a Runner (RUNNER_CHANCE: fast, and
// down in one bolt) or a Glutton (GLUTTON_CHANCE: slow, 15 bolts to kill, and
// it never leaps or climbs), and a widow or a hellhound is a Huntsman
// (HUNTSMAN_CHANCE): a big spider on the floor that springs at you.
export const RUNNER_CHANCE = 0.14;
// A runner shrieks once as it comes within RUNNER_WARN of the view, a
// "runner" event with the x on screen nearest it, so one coming up from
// behind is heard before it is on you.
export const RUNNER_WARN = 14;
export const GLUTTON_CHANCE = 0.07;
export const HUNTSMAN_CHANCE = 0.12;
export function variant(kind, random) {
if (kind === "zombie") {
const r = random();
return r < GLUTTON_CHANCE ? "glutton" : r < GLUTTON_CHANCE + RUNNER_CHANCE ? "runner" : "zombie";
}
if (kind === "spider" || kind === "hound") return random() < HUNTSMAN_CHANCE ? "huntsman" : kind;
return kind;
}
// A Huntsman runs at you, and within HUNT_RANGE across (and no higher than
// HUNT_HIGH over it) crouches HUNT_CROUCH_MS, then springs to come down on
// where you are from HUNT_UP above, as high as you are, no faster across
// than HUNT_VX, and rests HUNT_REST_MS where it lands.
export const HUNT_RANGE = 26;
export const HUNT_HIGH = 26;
export const HUNT_CROUCH_MS = 380;
export const HUNT_UP = 3;
export const HUNT_VX = 60;
export const HUNT_REST_MS = 700;
export const LURCH_RANGE = 20;
// A crawler takes RISE_MS to come up through the boards (harmless till up),
// woken once you are within CRAWL_NEAR. A bat wakes within BAT_NEAR and
// steers toward your chest at BAT_STEER a second. A ghost is solid (it can
// hurt and be hit) from GHOST_APPEAR_MS to GHOST_SHOW_MS of its cycle and
// faded the rest, GHOST_HIDE_MS; a faded one within GHOST_CLEAR of you stays
// faded till you are clear. A skeleton throws a bone every SKEL_MS,
// raising its arm for SKEL_WINDUP_MS first, when you are within SKEL_RANGE.
export const RISE_MS = 450;
export const CRAWL_NEAR = 26;
export const BAT_NEAR = 44;
export const BAT_STEER = 60;
export const BAT_TURN = 18;
export const GHOST_APPEAR_MS = 300;
export const GHOST_SHOW_MS = 2200;
export const GHOST_HIDE_MS = 900;
export const GHOST_CLEAR = 4;
export const SKEL_MS = 1500;
export const SKEL_WINDUP_MS = 350;
export const SKEL_RANGE = 60;
// Closer than SKEL_NEAR a skeleton holds its bone (it would only go straight up).
export const SKEL_NEAR = 6;
// A thrown bone (or a glob of acid): up at BONE_V against BONE_G, never
// across faster than BONE_VX; shot down for BONE_POINTS.
export const BONE_V = 40;
export const BONE_G = 110;
export const BONE_VX = 42;
export const BONE_R = 0.8;
export const BONE_POINTS = 25;
// A hellhound prowls at its speed; within HOUND_RANGE on your level it
// crouches for HOUND_CROUCH_MS (growling), then lunges at HOUND_LUNGE_VX,
// up at HOUND_LUNGE_V, and needs HOUND_REST_MS after it lands.
export const HOUND_RANGE = 16;
export const HOUND_CROUCH_MS = 320;
export const HOUND_LUNGE_VX = 40;
export const HOUND_LUNGE_V = 40;
export const HOUND_REST_MS = 600;
// A widow hangs from the ceiling at SPIDER_Y until you come within
// SPIDER_NEAR across, then drops on its thread at SPIDER_DROP_V and skitters
// after you.
export const SPIDER_Y = CEILING_Y - 4;
export const SPIDER_NEAR = 22;
export const SPIDER_DROP_V = 70;
// A wraith waits unseen until you are within WRAITH_NEAR, then hovers
// WRAITH_KEEP ahead of you at its height (never more than WRAITH_ABOVE over
// you, where a tilted bolt still finds it) for WRAITH_HOVER_MS, shrieks for
// WRAITH_WIND_MS, and dives at where your chest was at WRAITH_DIVE_V, on
// WRAITH_PAST beyond it before it climbs back.
export const WRAITH_NEAR = 60;
export const WRAITH_KEEP = 26;
export const WRAITH_ABOVE = 12;
export const WRAITH_HOVER_MS = 1400;
export const WRAITH_WIND_MS = 450;
export const WRAITH_DIVE_V = 48;
export const WRAITH_PAST = 18;
// A bloater wades toward you till SPIT_KEEP away and lobs a glob of acid
// every SPIT_MS within SPIT_RANGE, swelling for SPIT_WINDUP_MS first. Acid
// that lands leaves a puddle PUDDLE_W wide for PUDDLE_MS that burns whoever
// stands in it, and a bloater bursts into globs when it dies.
export const SPIT_KEEP = 22;
export const SPIT_MS = 2000;
export const SPIT_WINDUP_MS = 450;
export const SPIT_RANGE = 54;
export const PUDDLE_W = 4;
export const PUDDLE_MS = 1800;
// A wall door holds its zombies while you are within DOOR_CLEAR of it, and
// each one steps out over EMERGE_MS, harmless till it is through.
export const DOOR_CLEAR = 14;
export const EMERGE_MS = 350;
// Monsters wake a little off screen; no more than MAX_MONSTERS at once (the
// horde stops HORDE_ROOM short of that, leaving room for the rest).
export const SPAWN_AHEAD = 4;
export const MAX_MONSTERS = 18;
export const HORDE_ROOM = 4;
// The bosses, in a room's last FIELD_W. The arena locks once you are
// BOSS_LOCK into it, and the boss wakes after BOSS_INTRO_MS. Its hp grows
// BOSS_DEPTH_HP for each stage already cleared that run (up to
// BOSS_DEPTH_MAX of them); a stomp deals STOMP_DAMAGE, a shot one (two to
// Rattlebones' skull).
export const BOSSES = Object.freeze({
gourd: Object.freeze({ name: "The Rotting Gourd", sub: "Watch its shadow, then run", w: 14, h: 12, hp: 65, points: 2000, color: "#d0631c" }),
...fromPacks("bosses"),
});
export const BOSS_LOCK = 10;
export const BOSS_INTRO_MS = 1000;
export const BOSS_DEPTH_HP = 0.12;
export const BOSS_DEPTH_MAX = 12;
// Each stage cleared makes the monsters a little quicker and lets them out a
// little sooner (see roomFor).
export const DEPTH_PACE = 0.03;
export const DEPTH_EVERY = 0.95;
export const STOMP_DAMAGE = 3;
// Old Rattlebones' skull starts SKULL_FROM of the way up it: a level bolt
// from the Crypt's shelf reaches it.
export const SKULL_FROM = 0.72;
// The Rotting Gourd waits GOURD_WAIT_MS (shaking the last part of it), then
// picks its next move at random, never one three times running: a hop at
// GOURD_HOP_V (every third hop GOURD_BIG_V) to land where you stood,
// shaking the floor and letting gourdlings loose; a spit, winding up
// GOURD_SPIT_MS, then lobbing a glob of acid at each GOURD_SPIT scale of the
// throw that lands on you; or a quake, a leap straight up at GOURD_QUAKE_V
// that sends a shockwave along the floor both ways as it lands.
export const GOURD_WAIT_MS = 850;
export const GOURD_HOP_V = 95;
export const GOURD_BIG_V = 110;
export const GOURD_ACTS = Object.freeze(["hop", "spit", "quake"]);
export const GOURD_SPIT_MS = 500;
export const GOURD_SPIT = Object.freeze([1, 1.35]);
export const GOURD_QUAKE_V = 100;
// A gourdling lands and finds its feet for SEED_LAND_MS before it can hurt.
export const SEED_LAND_MS = 300;
// No more than MAX_SEEDS gourdlings run about at once: one a hop, two a big one.
export const MAX_SEEDS = 4;
// Old Rattlebones' fight (his volleys, slams, skull, bone rain and skeletons)
// lives in ghoul-bones.js; a shockwave runs along the floor at WAVE_SPEED,
// WAVE_H high.
export const WAVE_SPEED = 40;
export const WAVE_H = 2.2;
// A chandelier shakes CHANDELIER_SHAKE_MS once you run within CHANDELIER_NEAR
// under it, then drops; whatever it lands on is crushed.
export const CHANDELIER_NEAR = 6;
export const CHANDELIER_SHAKE_MS = 350;
export const CHANDELIER_W = 7;
// A crumbling board shakes CRUMBLE_MS once stood on, then is gone for
// CRUMBLE_BACK_MS.
export const CRUMBLE_MS = 500;
export const CRUMBLE_BACK_MS = 3500;
// The power-ups (POWERS, TIMED, FLAP_CLEAR, HOURGLASS_MS), which can turn up
// where, and picking up candy, power-ups, crystals and the key live in
// ghoul-powers.js.
// A room is dark DARK_CHANCE of the times it is entered (unless its spec
// says which); a lit one never has a Lantern, its placed ones swapped for
// another power-up (never a 1UP).
export const DARK_CHANCE = 0.6;
// In a dark room only DARK_BEHIND of what comes in from the edge behind
// you (the horde, the stragglers once the bonus is gone) gets in.
export const DARK_BEHIND = 0.5;
export const DROP_CANDY = 0.3;
export const DROP_POWER = 0.07;
// Stragglers: the horde (and the dead that come once the bonus is gone)
// never ends, so each of its kills in a room is worth STRAY_FADE of the last
// (never under STRAY_MIN of its points) and leaves nothing behind. Holding a
// doorway to farm them pays next to nothing.
export const STRAY_FADE = 0.8;
export const STRAY_MIN = 0.1;
export const DROP_MS = 9000;
export const GARLIC_SAFE_MS = 1200;
// Points: a kill is its points times the chain (kills each within CHAIN_MS
// of the last, the multiplier capped at MAX_MULT), doubled for a headshot or
// a stomp. Candy is CANDY_POINTS, a power-up POWER_POINTS. Through a door,
// ROOM_POINTS times the room plus the time bonus left (BONUS_START, dropping
// BONUS_STEP a second) and FLAWLESS_POINTS with no life lost; a boss is its
// points, more the deeper into the run (see roomFor), and a life.
export const CHAIN_MS = 1200;
export const MAX_MULT = 10;
// CANDY_POINTS, POWER_POINTS and CRYSTAL_POINTS are in ghoul-powers.js.
export const ROOM_POINTS = 300;
export const BONUS_START = 1500;
export const BONUS_STEP = 50;
export const FLAWLESS_POINTS = 500;
// With the bonus run out, a zombie shambles in from the edge every HURRY_MS.
export const HURRY_MS = 1500;
// The clock: every room but a boss's gives TIME_BASE_S plus TIME_PER_UNIT_S
// a unit of its length, to the nearest 5 seconds (70 to 80), to get out. At
// none a life goes, and the room starts over with a full clock. The last
// TIME_WARN_MS tick away out loud.
export const TIME_BASE_S = 30;
export const TIME_PER_UNIT_S = 0.09;
export const TIME_WARN_MS = 10000;
export const timeFor = (spec) => (spec.boss ? 0 : spec.ride ? spec.ride.time : Math.round((TIME_BASE_S + spec.length * TIME_PER_UNIT_S) / 5) * 5000);
// Piling up: STACK_MIN or more walkers (zombies, crawlers, gourdlings) each
// within STACK_NEAR of the next on the same floor are a pile, and once you
// are above them and within STACK_REACH across they climb over each other to
// reach you: the oldest stays at the bottom and each one more stands
// STACK_STEP of its height over the one below, rising at CLIMB_V, only as
// high as it takes to reach your feet. A pile that breaks up, or that you
// leave, drops back at UNSTACK_V. So waiting on a shelf over a crowd for a
// run of stomps is never safe.
export const STACK_MIN = 2;
export const STACK_NEAR = 2.2;
export const STACK_REACH = 12;
export const STACK_STEP = 0.8;
export const CLIMB_V = 14;
export const UNSTACK_V = 30;
export const STACKERS = new Set(["zombie", "runner", "crawler", "seed", ...listPacks("stackers")]);
// A walker climbing (a pile or a wall) reaches up with both arms, ARMS_UP
// over its head: landing on them hurts you. Only a landing within HEAD_BONK
// of its middle comes down on its head between them, for a stomp.
export const ARMS_UP = 1.4;
export const HEAD_BONK = 0.9;
export const reaching = (m) => m.lift > 0.5 || Boolean(m.scale);
// Hopping a pit: a walker that comes to the edge of a pit, or of a drop to
// a lower floor, stops and thinks about it for PONDER_MS (PONDER_STEP_MS
// more for some, so a crowd does not leap as one), then leaps, rising at
// HOP_V and landing HOP_IN past the far edge. Across to floor about its own
// height it clears HOP_GAP; down to a lower one it is longer in the air and
// so clears more, as far as the same leap carries. Floor higher than a step
// up, or a pit too wide, stops it for good. Anything on four legs (a hound, a
// topiary beast, a wolf-man) leaps BOUND_REACH times as far and twice as high
// (rising at BOUND_V), so it also lands on floor up to BOUND_UP above it across
// a gap. A wall with no gap before it still stops one: it never climbs.
export const HOP_GAP = 10.5;
export const BOUND_REACH = 2;
export const HOP_V = 50;
export const BOUND_V = HOP_V * Math.SQRT2;
export const BOUND_UP = 9;
export const HOP_IN = 1.5;
export const PONDER_MS = 900;
export const PONDER_STEP_MS = 150;
// Climbing a wall: a zombie, a runner or a crawler stopped by floor more than
// a step up (no more than WALL_MAX) thinks about it the same way, then
// climbs its face at WALL_V and steps on at the top. A glutton is too heavy
// to leap a pit or climb, but steps off a ledge onto the floor below.
export const WALL_MAX = 8;
export const WALL_V = 7;
export const CLIMBERS = new Set(["zombie", "runner", "crawler", ...listPacks("climbers")]);
export const HEAVY = new Set(["glutton"]);
const FOUR_LEGGED = new Set(["hound", ...listPacks("fourLegged")]);
// A turned villager is a villager until the moon says otherwise, so it goes by
// `m.turned`, not kind.
export const bounds = (m) => FOUR_LEGGED.has(m.kind) || Boolean(m.turned);
// How far across a monster's leap clears, on the level.
export const hopReach = (m) => HOP_GAP * (bounds(m) ? BOUND_REACH : 1);
// Everything that walks the floor with walk(), and so can stand on a bridge.
export const WALKERS = new Set(["zombie", "runner", "glutton", "crawler", "seed", "spitter", "hound", "huntsman", ...listPacks("walkers"), ...listPacks("zombies")]);
// A life lost holds CRASH_MS, then puts you back at the room's start (in a
// boss room, the arena's) for READY_MS, safe for SAFE_MS. A door gone through
// holds CLEAR_MS.
export const START_LIVES = 7;
export const CRASH_MS = 900;
export const READY_MS = 500;
export const SAFE_MS = 1200;
// A life lost within QUICK_LOSS_MS (12 s) of coming in (into a room, or back after
// the last life lost) brings Planny back holding the Garlic shield.
export const QUICK_LOSS_MS = 12000;
export const CLEAR_MS = 1200;
// Stages offered at each choice, and how long the offer settles before a
// press takes one.
export const OFFER_N = 2;
export const PICK_HOLD_MS = 700;
export const BANNER_STRETCH = 2;
export const DOOR_REACH = 2.5;
// A banner fades to BANNER_SEE_THROUGH over BANNER_FADE_MS while something
// that matters to you is in its strip, BANNER_REACH either side of its middle.
export const BANNER_SEE_THROUGH = 0.12;
export const BANNER_FADE_MS = 140;
export const BANNER_REACH = 8;
// The camera eases toward a spot CAM_LEAD ahead of the way you face.
export const CAM_EASE = 9;
export const CAM_AT = 0.32;
export const CAM_LEAD = 12;
export const chainMult = (chain) => Math.max(1, Math.min(MAX_MULT, chain));
export const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
// A small seeded random (mulberry32), handed to advance() so a seed always
// plays the same drops, throws and hops (the rooms themselves are fixed).
export function seeded(seed) {
let a = seed >>> 0;
return () => {
a = (a + 0x6d2b79f5) >>> 0;
let t = a;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
// How high a jump is, `dx` across from where it left, at RUN_SPEED: the
// unit suite's measure of which gaps and ledges a jump can clear.
export function jumpHeightAt(dx) {
const t = Math.abs(dx) / RUN_SPEED;
return JUMP_V * t - (GRAVITY * t * t) / 2;
}
export const JUMP_TOP = (JUMP_V * JUMP_V) / (2 * GRAVITY);
/* -------------------------------------------------------------- rooms */
// A room's numbers, built once each for the room `id` (as ghoul-rooms.js
// lays it out) played `depth` stages into a run: the deeper, the quicker and
// tougher its monsters, the sooner they are let out, and the more hp (and
// points) its boss has, each capped.
const BUILT = new Map();
export function roomFor(id, depth = 0) {
const base = roomById(id) || ROOMS[0];
const d = Math.max(0, Math.floor(depth) || 0);
const k = `${base.id}:${d}`;
if (BUILT.has(k)) return BUILT.get(k);
const candy = [];
for (const [x0, y, count] of base.candy) for (let i = 0; i < count; i++) candy.push(Object.freeze({ x: x0 + i * 3, y }));
const spec = Object.freeze({
...base,
depth: d,
base,
name: base.title,
pace: Math.min(1.4, 1 + DEPTH_PACE * d),
every: Math.max(0.55, DEPTH_EVERY ** d),
tough: Math.min(2, Math.floor(d / 3)),
// Doors in the wall let this many more out.
extra: Math.min(2, Math.floor(d / 2)),
bossHp: base.boss ? Math.round(BOSSES[base.boss].hp * (1 + BOSS_DEPTH_HP * Math.min(d, BOSS_DEPTH_MAX))) : 0,
bossPoints: base.boss ? Math.round(BOSSES[base.boss].points * (1 + d / 4)) : 0,
candyAt: Object.freeze(candy),
arena: base.boss ? base.length - FIELD_W : -1,
});
BUILT.set(k, spec);
return spec;
}
// "Library (room 3)": room `n` of a run.
export const roomName = (spec, n) => `${spec.name} (room ${n})`;
export const PLATFORMS = fromPacks("platform");
// Your keys while the bell has frozen you: none.
export const FROZEN = Object.freeze({});
@@ -0,0 +1,653 @@
// Plan2Code Web Console - Ghoul Rush's window: the game's contract with the Activities page (create), its keys and pointer, what fx and sounds its events set off, each room's music (ROOM_MUSIC), and the view handed to the drawing.
//
// One of the parts of ghoul.js (see its header and the list of parts there).
import { armOnTop, pressFire as pressFireWith, releaseFire, resetTap } from "../arms/ghoul-arms.js";
import { GOLD, bonusTick, drawScene, lookOf, react, readColors } from "../draw/ghoul-draw.js";
import { isWaiting, startRide } from "../rides/dark-ride/ghoul-ride.js";
import { lanternHums } from "../rides/lantern/ghoul-lantern.js";
import { BONES_WINDUP_MS } from "../stages/wing/ghoul-bones.js";
import { beginStory, pressStory, releaseStory, takeStory } from "../story/ghoul-story.js";
import { heartsText } from "./ghoul-bonus.js";
import { answerAsk, steerAsk } from "./ghoul-dice.js";
import { ARM_POP_MS, PILL_WORDS, POWERS, TIMED } from "./ghoul-powers.js";
import { CEILING_Y, FIELD_H, FIELD_W, STAGES, roomById, stageById } from "./ghoul-rooms.js";
import { onCard, openSelect, steerPick } from "./ghoul-run.js";
import { DICE_KIT } from "./ghoul-fight.js";
import { POINTERS, ghostSight, solid } from "./ghoul-monsters.js";
import { groundAt, shelfThere } from "./ghoul-planny.js";
import { KIT } from "./ghoul-kit.js";
import { advance, bannerY, fire, newRound, pickStage, steerSelect, stomps, takeIntro, takeSelect, underBanner } from "./ghoul-play.js";
import { BANNER_FADE_MS, BANNER_SEE_THROUGH, BANNER_STRETCH, BOSSES, BOSS_INTRO_MS, CHAIN_MS, CHANDELIER_SHAKE_MS, CHANDELIER_W, CLEAR_MS, CRASH_MS, CRUMBLE_BACK_MS, DUCK_SHOT_Y, EMERGE_MS, GOURD_WAIT_MS, H, HEAT_FREE, HEAT_MAX, HEAT_SHOWN, HOUND_CROUCH_MS, HUD_H, JUMP_BUFFER_MS, MIN_CELL, MONSTERS, OFFER_N, PAD, PUDDLE_MS, PUDDLE_W, READY_MS, RISE_MS, SHOT_Y, SKEL_WINDUP_MS, SPIT_WINDUP_MS, TIME_WARN_MS, W, WAVE_H, WRAITH_WIND_MS, YOU_H, YOU_W, ZOMBIES, chainMult, roomFor, roomName } from "./ghoul-tables.js";
/* ------------------------------------------------------------- contract */
const MAX_PARTS = 320;
// Flares of light and floor stains kept at once, and how long a stain lasts.
const MAX_GLOWS = 24;
const MAX_SPLATS = 40;
const SPLAT_MS = 14000;
// Lightning: the first a few seconds in, then every BOLT_EVERY_MS or so,
// each BOLT_MS long.
const BOLT_FIRST_MS = 4000;
const BOLT_EVERY_MS = 11000;
const BOLT_MS = 650;
// How far a flash of lightning `left` ms from its end lifts the dark, 0 to
// 1: a bright flash, a flicker off, a second flash, then a fade.
export function lightning(left) {
if (!(left > 0)) return 0;
const p = 1 - left / BOLT_MS;
if (p < 0.1) return 1;
if (p < 0.2) return 0.15;
if (p < 0.3) return 0.85;
return Math.max(0, (1 - p) / 0.7) * 0.4;
}
// The end screen's nudge to play again, by the most stages ever cleared.
function teaser(most) {
if (most < STAGES.length) return `Best: ${most} of ${STAGES.length} stages. Clear them all to escape.`;
return "You have escaped the house before. Can you do it again?";
}
// The held sounds under play (no drone under the house: every room has its
// own music). The nearest monster within NEAR_SOUND (its hum by kind,
// louder the closer); a footstep every STEP_MS while you run; the heart
// pounding on the last life, quicker with a monster within HEART_NEAR.
const NEAR_HUMS = Object.freeze({ zombie: "ghoulMoan", runner: "ghoulMoan", glutton: "ghoulMoan", huntsman: "ghoulSnarl", crawler: "ghoulMoan", spitter: "ghoulMoan", bat: "ghoulFlutter", ghost: "ghoulSpecter", wraith: "ghoulSpecter", hound: "ghoulSnarl", spider: "ghoulSnarl" });
const NEAR_PITCH = Object.freeze({ runner: 1.35, glutton: 0.6, huntsman: 0.75, crawler: 1.25, spitter: 0.7, wraith: 0.8, spider: 1.4 });
const NEAR_SOUND = 36;
const STEP_MS = 270;
const HEART_MS = 1000;
const HEART_FAST_MS = 600;
const HEART_NEAR = 16;
// Each room's music, from ghoul-sfx.js, at one steady level whatever the
// monsters are doing: DREAD_ROOM brings in everything but a track's top
// layers (its melody and drums included), the clock's last seconds add
// DREAD_CLOCK, and a boss fight plays all of it. The level eases toward its
// target over about DREAD_EASE_MS, so a change never lands as a jolt.
export const ROOM_MUSIC = Object.freeze({ banister: "ghoulBanister", hall: "ghoulHall", darkride: "ghoulRideTheme", lychgate: "ghoulLychgate", graves: "ghoulGraves", mausoleums: "ghoulMausoleums", angel: "ghoulAngel", maze: "ghoulMaze", topiary: "ghoulTopiary", gazebo: "ghoulGazebo", yard: "ghoulYard", nave: "ghoulNave", tower: "ghoulTower", loft: "ghoulLoft", choir: "ghoulChoir", shaft: "ghoulShaft", tunnels: "ghoulTunnels", collapse: "ghoulCollapse", seam: "ghoulSeam", cart: "ghoulCart", midway: "ghoulMidway", mirrors: "ghoulMirrors", funhouse: "ghoulFunhouse", bigtop: "ghoulBigTop", admissions: "ghoulAdmissions", baths: "ghoulBaths", theater: "ghoulTheater", ward: "ghoulWard", street: "ghoulStreet", inn: "ghoulInn", square: "ghoulSquare", green: "ghoulGreen", foyer: "ghoulFoyer", gallery: "ghoulGallery", library: "ghoulLibrary", ballroom: "ghoulBallroom", kitchen: "ghoulKitchen", conservatory: "ghoulConservatory", attic: "ghoulAttic", crypt: "ghoulCrypt", huts: "ghoulHuts", lodge: "ghoulLodge", blackice: "ghoulBlackIce", sled: "ghoulSledRide", codeblue: "ghoulBlueRide", pew: "ghoulPewDirge", mower: "ghoulMowerRide", wagon: "ghoulWagonRide", hearse: "ghoulHearseRide", tray: "ghoulTrayRide", widow: "ghoulWidow", boardwalk: "ghoulBoardwalk", hollow: "ghoulHollow", stilts: "ghoulStilts", lantern: "ghoulLanternTheme", drowning: "ghoulDrowning" });
const DREAD_ROOM = 0.7;
const DREAD_CLOCK = 0.2;
const DREAD_EASE_MS = 900;
// How full the music is right now, 0 to 1: the target the music eases toward.
export function dread(round) {
const b = round.boss;
if (b && round.lockX >= 0 && (b.state === "fight" || b.state === "intro")) return 0.9 + 0.1 * (1 - b.hp / Math.max(1, b.max));
if (round.gallery && round.gallery.track) return 0.9;
let level = DREAD_ROOM;
if (round.timeMs > 0 && round.timeMs <= TIME_WARN_MS) level += DREAD_CLOCK;
return Math.min(1, level);
}
// A sound's pitch a little either side of 1, so it never repeats exactly.
const vary = (n = 0.1) => 1 - n / 2 + Math.random() * n;
function create({ canvas, tone = () => {}, hum = () => {}, music = () => {}, onScore = () => {}, best = () => 0, memo = null }) {
const ctx = canvas.getContext("2d");
let colors = null;
let round = newRound();
let state = "ready";
let u = MIN_CELL;
let bestAtStart = 0;
let beaten = false;
// A jump press waits for the first tick after a start or a play-on, so the
// key that plays on never also jumps; and up must be let go between jumps.
let armed = false;
let upHeld = false;
// The most stages ever cleared in one run, and whether this run beat it.
// Without a memo (the unit suite) it lasts as long as the game.
let most = 0;
let further = false;
try {
most = Math.max(0, memo ? Number(memo.get()) | 0 : 0);
} catch {}
// Particles, floating words, rings, banners, the chain's big number, the
// shake and the flash, the flares of light and the stains on the floor,
// and the lightning, in room units (y up) and ms.
let fx = null;
const resetFx = () => (fx = { parts: [], floats: [], banners: [], rings: [], glows: [], splats: [], shake: 0, shakeMag: 0, flash: null, clock: 0, cheer: 0, combo: null, candyRun: 0, candyMs: 0, step: 0, bolt: 0, nextBolt: BOLT_FIRST_MS, stepMs: 0, foot: 0, beatMs: 0, hot: false, dread: 0 });
resetFx();
const burst = (x, y, color, n, speed = 14, life = 500) => {
for (let i = 0; i < n && fx.parts.length < MAX_PARTS; i++) {
const a = Math.random() * Math.PI * 2;
const v = speed * (0.35 + Math.random() * 0.65);
fx.parts.push({ x, y, vx: Math.cos(a) * v, vy: Math.sin(a) * v, life: life * (0.6 + Math.random() * 0.4), max: life, color, size: 0.45 + Math.random() * 0.55 });
}
};
const float = (x, y, text, color, size = 2.4) => fx.floats.push({ x, y, rise: 0, text, color, size, life: 900, max: 900 });
const ring = (x, y, color, r0, grow, ms = 420) => fx.rings.push({ x, y, color, r0, grow, life: ms, max: ms });
// A flare of light that lifts the dark around (x, y) and fades over `ms`.
const glow = (x, y, r, s, ms) => fx.glows.length < MAX_GLOWS && fx.glows.push({ x, y, r, s, life: ms, max: ms });
// A stain on the floor at (x, y), the oldest gone once there are too many.
const splat = (x, y, r, color) => {
if (fx.splats.length >= MAX_SPLATS) fx.splats.shift();
fx.splats.push({ x, y, r, color, life: SPLAT_MS });
};
const floorAt = (x) => groundAt(round.spec, x);
// A banner waits its turn behind the one showing, three at most. One
// tied to a phase (`phase`: "Ready?" to the hold before play) is dropped
// once that phase has passed; a full queue makes room for a more
// important one (`rank`: "New best!") by dropping the least important one
// waiting, and otherwise drops the newcomer.
// Every banner is up BANNER_STRETCH times as long as its caller asks, so the words can be read.
const banner = (title, sub, color, ms = 1800, { phase = "", rank = 0 } = {}) => {
ms *= BANNER_STRETCH;
if (fx.banners.some((b) => b.title === title)) return null;
if (fx.banners.length >= 3) {
let low = -1;
for (let i = 1; i < fx.banners.length; i++) if (fx.banners[i].rank < rank && (low < 0 || fx.banners[i].rank < fx.banners[low].rank)) low = i;
if (low < 0) return null;
fx.banners.splice(low, 1);
}
const b = { title, sub, color, life: ms, max: ms, tag: "", y: null, see: 1, phase, rank };
fx.banners.push(b);
return b;
};
// A shake still running keeps the stronger of the two; a new one starts
// from its own strength, so one big hit never loudens every later shake.
const shake = (ms, mag) => {
fx.shakeMag = Math.max(fx.shake > 0 ? fx.shakeMag : 0, mag);
fx.shake = Math.max(fx.shake, ms);
};
const flash = (color, ms = 220) => (fx.flash = { color, life: ms, max: ms });
// A stage cleared: a new record (most stages in a run) is saved, and
// named on the banner `b`.
const markFurthest = (n, b) => {
if (n <= most || round.practice) return;
most = n;
further = true;
try {
if (memo) memo.set(most);
} catch {}
if (b) b.tag = `NEW RECORD: ${n} OF ${STAGES.length} STAGES`;
};
// A room's banner, named for its stage and how far into it.
const roomBanner = (n) => {
const spec = round.spec;
const b = banner(`Room ${n}: ${spec.name}`, spec.sub, lookOf(spec.id).color, 2000);
const st = round.stage && stageById(round.stage);
if (b && st) b.tag = `${st.title.toUpperCase()}, ${round.stageAt + 1} OF ${st.rooms.length}`;
return b;
};
const kit = { tone, burst, float, ring, banner, shake, flash, glow, splat, floorAt, get fx() { return fx; }, roomBanner, markFurthest, monsters: MONSTERS, powers: POWERS, bosses: BOSSES, g: Object.freeze({ READY_MS, BOSS_INTRO_MS, CLEAR_MS }) };
const handle = (e) => react(e, kit);
// A score past the best this round began with: once a round, a fanfare.
const checkBest = () => {
if (beaten || round.practice || !(bestAtStart > 0) || round.score <= bestAtStart) return;
beaten = true;
tone("best");
tone("fanfare", 0.45);
banner("New best!", "Every point from here is a record", GOLD, 1700, { rank: 2 });
};
const drain = () => {
colors ||= readColors(canvas);
for (const e of round.events.splice(0)) handle(e);
checkBest();
};
// Banners tied to a phase that has passed ("Ready?" once play is on) go,
// wherever they wait in the queue.
const dropPassed = () => {
if (fx.banners.some((b) => b.phase && b.phase !== round.phase)) fx.banners = fx.banners.filter((b) => !b.phase || b.phase === round.phase);
};
const runFx = (ms) => {
fx.clock += ms;
const s = ms / 1000;
fx.parts = fx.parts.filter((p) => {
p.life -= ms;
p.x += p.vx * s;
p.y += p.vy * s;
const drag = 0.9 ** (ms / 16);
p.vx *= drag;
p.vy = p.vy * drag - 12 * s;
return p.life > 0;
});
fx.floats = fx.floats.filter((f) => {
f.life -= ms;
f.rise += 5 * s;
return f.life > 0;
});
fx.rings = fx.rings.filter((r) => (r.life -= ms) > 0);
fx.glows = fx.glows.filter((gl) => (gl.life -= ms) > 0);
fx.splats = fx.splats.filter((sp) => (sp.life -= ms) > 0);
// Lightning now and then, the thunder with it.
fx.bolt = Math.max(0, fx.bolt - ms);
fx.nextBolt -= ms;
if (fx.nextBolt <= 0) {
fx.bolt = BOLT_MS;
fx.nextBolt = BOLT_EVERY_MS * (0.6 + Math.random() * 0.8);
const deep = 0.8 + Math.random() * 0.4;
tone("ghoulThunder", 0.5, deep);
tone("ghoulCrack", 0.3, deep);
tone("rumbleLong", 0.5, deep);
}
if (fx.combo && (fx.combo.life -= ms) <= 0) fx.combo = null;
if (fx.lucky && (fx.lucky.life -= ms) <= 0) fx.lucky = null;
fx.cheer = Math.max(0, fx.cheer - ms);
fx.candyMs = Math.max(0, fx.candyMs - ms);
dropPassed();
if (fx.banners.length) {
const b = fx.banners[0];
if (b.y == null) b.y = bannerY(round);
const target = underBanner(round, b.y) ? BANNER_SEE_THROUGH : 1;
b.see += (target - b.see) * Math.min(1, ms / BANNER_FADE_MS);
b.life -= ms;
if (b.life <= 0) fx.banners.shift();
dropPassed();
}
fx.shake = Math.max(0, fx.shake - ms);
if (fx.flash && (fx.flash.life -= ms) <= 0) fx.flash = null;
};
// The pills' numbers: the stage and how many are cleared, lives, the bonus, the chain while it runs,
// the key once held, and the power-ups held (a timed one emptying as it runs).
const effects = [];
const gauge = { fill: 0, free: HEAT_FREE / HEAT_MAX, rapid: null };
const hud = { room: "", stage: "", time: 0, timeLow: false, bonus: 0, chain: 0, chainFill: 1, key: "", effects, gauge, arm: null };
const hudOf = () => {
const you = round.you;
effects.length = 0;
for (const k of TIMED) if (round.effects[k] > 0) effects.push({ text: PILL_WORDS[k], color: POWERS[k].color, fill: Math.min(1, round.effects[k] / POWERS[k].ms) });
if (you.garlic) effects.push({ text: "GARLIC", color: POWERS.garlic.color, fill: 1 });
if (you.hat) effects.push({ text: PILL_WORDS.hat, color: POWERS.hat.color, fill: 1 });
if (round.dice > 0) effects.push({ text: `DICE x${round.dice}`, color: POWERS.die.color, fill: 1 });
// The blaster's heat for the gauge, the notch where its bolts slow.
gauge.fill = round.heat / HEAT_MAX;
gauge.rapid = round.effects.rapid > 0 ? POWERS.rapid.color : null;
// The stage (or the hall) by name, and how many stages are cleared of
// all there are.
const st = round.stage && stageById(round.stage);
hud.room = (st ? st.title : round.spec.name).toUpperCase();
hud.stage = `STAGE ${round.cleared.length} OF ${STAGES.length}`;
hud.bonus = round.bonus;
hud.hearts = round.bonusRound ? heartsText(round.bonusRound) : "";
hud.time = round.timeMs > 0 ? Math.ceil(round.timeMs / 1000) : 0;
hud.timeLow = round.timeMs > 0 && round.timeMs <= TIME_WARN_MS;
hud.chain = round.chain > 1 ? chainMult(round.chain) : 0;
hud.chainFill = round.chainMs / CHAIN_MS;
// "have" once found, "need" until then; a room with no key (a boss, a bonus ride) shows nothing.
hud.key = round.spec.key && !round.spec.boss && !round.spec.bonus ? (round.hasKey ? "have" : "need") : "";
// The Drowned Lantern has no blaster (SPACE flares the lantern, its oil drawn by the room's own art): no gauge.
hud.gauge = round.runner && round.runner.id === "lantern" ? null : gauge;
// The weapon that comes out next, its count, and how many other kinds wait under it.
const top = armOnTop(round);
hud.arm = top ? { kind: top.kind, n: top.n, more: round.arms.length - 1, text: `x${top.n}${round.arms.length > 1 ? ` +${round.arms.length - 1}` : ""}${round.armUsed ? "" : " TAP TAP"}`, color: POWERS[top.kind].color, fresh: !round.armUsed, pop: (round.armPopMs || 0) / ARM_POP_MS } : null;
return hud;
};
// The view ghoul-draw.js draws from: one object, refilled each frame.
const view = { g: Object.freeze({ W, H, HUD_H, PAD, FIELD_W, FIELD_H, YOU_W, YOU_H, CRASH_MS, CRUMBLE_BACK_MS, RISE_MS, SKEL_WINDUP_MS, BONES_WINDUP_MS, WAVE_H, CHANDELIER_W, CHANDELIER_SHAKE_MS, SHOT_Y, DUCK_SHOT_Y, GOURD_WAIT_MS, EMERGE_MS, PUDDLE_W, PUDDLE_MS, HOUND_CROUCH_MS, WRAITH_WIND_MS, SPIT_WINDUP_MS, CEILING_Y, ZOMBIES }), powers: POWERS, monsters: MONSTERS, bosses: BOSSES, groundAt, shelfThere, solid, ghostSight, roomFor, roomById, stages: STAGES, stageById, OFFER_N };
const shakeAt = { x: 0, y: 0 };
const paint = () => {
if (!ctx) return;
colors ||= readColors(canvas);
// A banner takes its place on its first frame: a frame painted before the
// next tick (the start's, held through the 3, 2, 1) would draw it at the top.
dropPassed();
const head = fx.banners[0] || null;
if (head && head.y == null) head.y = bannerY(round);
view.u = u;
view.clock = fx.clock;
view.state = state;
view.colors = colors;
view.round = round;
view.spec = round.spec;
view.fx = fx;
view.pillH = Math.max(12 / u, 2.4);
view.hud = hudOf();
view.cheer = fx.cheer > 0 || round.phase === "clear";
view.combo = fx.combo;
view.flash = fx.flash;
view.banner = head;
view.lightning = lightning(fx.bolt);
view.furthest = most;
view.won = round.won;
// A dot per stage along the start and end screens: those cleared this
// run in their colors (or, before one, as many as the record, in gold).
view.dots = STAGES.map((_, i) => (state === "ready" ? (i < most ? GOLD : null) : round.cleared[i] || null));
view.lost = state === "over";
view.overMs = fx.clock - (fx.overAt || 0);
view.shake = null;
if (fx.shake > 0 && state === "running") {
shakeAt.x = (Math.random() - 0.5) * 2 * fx.shakeMag;
shakeAt.y = (Math.random() - 0.5) * 2 * fx.shakeMag;
view.shake = shakeAt;
}
view.tally = null;
view.big = null;
const record = most >= STAGES.length ? "You have escaped before" : `Best: ${most} of ${STAGES.length} stages`;
if (state === "ready") view.tally = ["Run. Shoot. Clear every stage and escape before the house gets you", `Arrows run, up jumps, hold space to fire, tap it twice to throw what you find. ${record}`];
else if (state === "over") {
const st = round.stats;
view.big = String(round.score);
const how = `${st.kills} ghouls (${st.headshots} headshots, ${st.stomps} stomps), best chain x${chainMult(st.bestChain)}, ${st.candy} souls.`;
if (round.won) view.tally = [`You escaped! Every stage cleared${beaten ? ". A new best!" : ""}`, how];
else view.tally = [`Cleared ${round.cleared.length} of ${STAGES.length} stages, out in ${roomName(round.spec, round.room)}${further ? ". A new record!" : ""}${beaten ? " A new best!" : ""}`, `${how} ${round.practice ? "A practice run: nothing kept." : teaser(most)}`];
}
drawScene(ctx, view);
};
// Nothing held carries over a pause or a new round: a release may never
// arrive, and a jump pressed early is dropped.
const letGo = () => {
const inp = round.input;
inp.up = inp.down = inp.left = inp.right = inp.fire = false;
resetTap(round);
inp.jump = 0;
upHeld = false;
releaseStory(round);
};
// A new round. A real run opens on the intro story (ghoul-story.js) and the hall is announced when it ends; the stage select skips it.
const begin = (story) => {
colors = readColors(canvas);
round = newRound();
if (story) beginStory(round);
state = "running";
further = false;
armed = false;
upHeld = false;
resetFx();
try {
bestAtStart = Number(best()) || 0;
} catch {
bestAtStart = 0;
}
beaten = false;
if (!story) roomBanner(1);
paint();
};
const start = () => begin(true);
// The held sounds and the ones kept to a beat, each tick of a round still
// running: a hum not asked for again fades by itself, so a pause or the
// end goes quiet. Sounds only: nothing here touches the round.
const sounds = (ms) => {
const you = round.you;
const spec = round.spec;
const playing = round.phase === "play";
// The story has its own drone under its own sounds, and the hall's music waits for the hall.
if (round.phase === "story") {
hum("ghoul:story", "ghoulStoryDrone", 0.6, 1);
return;
}
const b = round.boss;
const fight = Boolean(b && round.lockX >= 0 && (b.state === "fight" || b.state === "intro"));
// The room's music, its dread eased toward where play is now.
fx.dread += (dread(round) - fx.dread) * Math.min(1, ms / DREAD_EASE_MS);
// A pack may switch the room's track mid-room with round.gallery.track (the dark ride's finale).
const track = (round.gallery && round.gallery.track) || ROOM_MUSIC[spec.id];
if (track) music(track, fx.dread);
// The nearest monster that can be heard.
let near = null;
let nearD = Infinity;
for (const m of round.monsters) {
if (m.dead || !NEAR_HUMS[m.kind] || (m.kind === "bat" && !m.awake)) continue;
const d = Math.hypot(m.x - you.x, m.y - you.y);
if (d < nearD) {
near = m;
nearD = d;
}
}
if (near && nearD < NEAR_SOUND) {
const close = (1 - nearD / NEAR_SOUND) ** 1.5;
hum("ghoul:near", NEAR_HUMS[near.kind], close * (solid(near) ? 1 : 0.5), (NEAR_PITCH[near.kind] ?? 1) * (1 + (near.id % 5) * 0.04));
}
// The boss heaving, its breath quickening as its hp runs down.
if (fight) hum("ghoul:boss", "ghoulBoss", b.state === "intro" ? 0.6 : 0.9, 1 + 0.5 * (1 - b.hp / Math.max(1, b.max)));
// A chandelier shaking loose rattles its chains.
if (round.falls.some((c) => c.state === "shake")) hum("ghoul:chains", "ghoulChains", 0.8, 1);
// The blaster's heat fizzing, a hiss once it starts to slow.
if (round.heat >= HEAT_SHOWN && round.effects.rapid <= 0) {
hum("ghoul:heat", "ghoulHeat", round.heat / HEAT_MAX, 0.7 + round.heat / HEAT_MAX);
if (!fx.hot && round.heat > HEAT_FREE) {
fx.hot = true;
tone("hiss", 0.25, 1.2);
}
}
if (round.heat < HEAT_FREE * 0.8) fx.hot = false;
if (you.garlic) hum("ghoul:garlic", "ghoulGarlic", 0.8, 1);
// The Drowned Lantern's own: the Lurker near, Mother awake.
for (const [id, name, level, pitch] of lanternHums(round)) hum(id, name, level, pitch);
// Footsteps on the boards, left and right, higher on a shelf, now and
// then a board creaking under you.
if (playing && you.state === "run" && you.runMs > 0) {
fx.stepMs -= ms;
if (fx.stepMs <= 0) {
fx.stepMs = STEP_MS;
fx.foot ^= 1;
tone("ghoulStep", 0.3, (you.shelf >= 0 ? 1.25 : 1) * (fx.foot ? 1.05 : 0.95) * vary(0.06));
if (Math.random() < 0.08) tone("creakBoard", 0.12, vary(0.5));
}
} else fx.stepMs = 0;
// The last life: a heartbeat, quicker with something close.
if (playing && round.lives === 1) {
fx.beatMs -= ms;
if (fx.beatMs <= 0) {
const close = nearD < HEART_NEAR || fight;
fx.beatMs = close ? HEART_FAST_MS : HEART_MS;
tone("heartbeat", close ? 0.55 : 0.4);
}
} else fx.beatMs = 0;
};
const end = () => {
if (round.won) {
tone("victory", 0.8);
tone("fanfare", 0.6);
flash(GOLD, 500);
} else {
tone("gameOver", 0.7);
tone("ghoulToll", 0.45, 0.7);
tone("ghoulLaughTrack", 0.55);
fx.overAt = fx.clock;
fx.laugh = 1;
}
state = "over";
letGo();
if (!round.practice) onScore(round.score);
};
const MOVES = Object.freeze({ left: true, right: true, up: true, down: true });
return {
get score() {
return round.score;
},
get state() {
return state;
},
// The lost end screen animates, so the window keeps ticking it.
get animating() {
return state === "over" && !round.won;
},
// For the tests only: the window never reads it.
get round() {
return round;
},
// Endless lives for this round (the Activities window's code), or not.
cheat(on) {
round.infinite = Boolean(on);
},
// The stage select (the window's stage code, for testing): a new round
// that opens on every stage and room to choose from, kept as practice
// (no best score, no record). Endless lives already on carry over.
stageSelect() {
const endless = Boolean(round.infinite);
begin(false);
round.infinite = endless;
fx.banners.length = 0;
openSelect(round);
paint();
},
// And the pills' numbers, the blaster's gauge among them.
get hud() {
return hudOf();
},
start,
pause() {
if (state === "running") state = "paused";
letGo();
paint();
},
resume() {
if (state !== "paused") return;
state = "running";
armed = false;
},
// The mouse (the window hands a press, a move and a let-go in CSS pixels): it
// starts a round, and in the dark ride it aims and fires (ghoul-ride.js).
// Any other key the window does not use: whether it started a ride waiting on one.
anyKey() {
return state === "running" && startRide(round);
},
pointer(type, x, y) {
if (state === "ready" || state === "over") {
if (type !== "down") return false;
start();
return true;
}
if (state !== "running") return false;
const fx = x / u - PAD;
const fy = y / u - HUD_H - PAD;
if (onCard(round)) return type === "down" ? takeIntro(round) || true : true;
if (round.phase === "story") return type === "down" ? takeStory(round) || true : true;
// Use a Lucky die? A click lights its half (Yes on the left, No on the right); a click on the lit half answers.
if (round.phase === "ask") {
if (type === "down") {
const yes = fx < FIELD_W / 2;
if (round.ask.yes === yes) answerAsk(round, yes, DICE_KIT);
else steerAsk(round, yes);
}
return true;
}
return POINTERS.some((f) => f(round, type, fx, fy));
},
// Held arrows run until let go (their key repeats, held through the
// countdown, keep them held). Up jumps once a press: never on a repeat,
// never again until it is let go, never with the press that plays on.
// Space starts a round (with fire off) or fires while held; while
// paused it does nothing, since only the window plays on, through
// resume().
key(name, repeat = false) {
if (state === "running" && isWaiting(round)) {
if (!repeat) startRide(round);
return true;
}
if (name === "action") {
if (state === "ready" || state === "over") start();
else if (state === "running" && round.phase === "select") {
if (!repeat) takeSelect(round);
} else if (state === "running" && round.phase === "ask") {
if (!repeat) answerAsk(round, round.ask.yes, DICE_KIT);
} else if (state === "running" && round.phase === "pick") {
if (!repeat) pickStage(round);
} else if (state === "running" && onCard(round)) {
if (!repeat) takeIntro(round);
} else if (state === "running" && round.phase === "story") {
pressStory(round, repeat);
} else if (state === "running") {
round.input.fire = true;
// The dark ride's trigger: a tap shorter than a step still fires; no weapon.
if (round.gallery) round.gallery.trigger = true;
else if (!repeat) pressFireWith(round, KIT);
}
return true;
}
if (!MOVES[name]) return false;
if (state !== "running") return true;
// On the stage select: up and down pick a stage out, left and right
// one of its rooms.
if (round.phase === "select") {
if (name === "up" || name === "down") steerSelect(round, name === "up" ? -1 : 1, 0);
else steerSelect(round, 0, name === "left" ? -1 : 1);
return true;
}
// Use a Lucky die? Left and up light Yes, right and down No; the action key answers.
if (round.phase === "ask") {
steerAsk(round, name === "left" || name === "up");
return true;
}
// Choosing a stage: left and right pick one out, up takes it.
if (round.phase === "pick") {
if (name === "left" || name === "right") steerPick(round, name === "left" ? -1 : 1);
else if (name === "up" && !repeat) pickStage(round);
return true;
}
// The intro story: any fresh move key turns the page.
if (round.phase === "story") {
if (!repeat) takeStory(round);
return true;
}
// A stage's intro card: any fresh move key walks in (a repeat never does).
if (onCard(round)) {
if (!repeat) takeIntro(round);
return true;
}
round.input[name] = true;
if (name === "up") {
if (!repeat && armed && !upHeld && round.phase === "play") round.input.jump = JUMP_BUFFER_MS;
upHeld = true;
}
return true;
},
// A key let go: stop running that way, cut a rising jump short, or stop
// firing.
release(name) {
if (name === "action") {
round.input.fire = false;
releaseFire(round);
releaseStory(round);
}
else if (MOVES[name]) round.input[name] = false;
if (name === "up") upHeld = false;
},
tick(ms) {
// The lost end screen animates its "G A M E - O V E R"; the rest hold still.
if (state === "over" && !round.won) {
fx.clock += ms;
// The rest of the laugh track, a second a part.
if (fx.laugh && fx.laugh < 3 && fx.clock - fx.overAt >= fx.laugh * 1000) tone(`ghoulLaughTrack${++fx.laugh}`, 0.55);
paint();
return;
}
if (state !== "running") return;
runFx(ms);
advance(round, ms);
drain();
bonusTick(round, kit);
if (round.over) end();
else sounds(ms);
paint();
armed = true;
},
resize(w, h) {
const next = Math.floor(Math.min(w / W, h / H) * 4) / 4;
if (!(next >= MIN_CELL)) return false;
u = next;
colors = null;
const ratio = typeof devicePixelRatio === "number" && devicePixelRatio > 0 ? devicePixelRatio : 1;
canvas.width = Math.round(W * u * ratio);
canvas.height = Math.round(H * u * ratio);
if (canvas.style) {
canvas.style.width = `${Math.round(W * u)}px`;
canvas.style.height = `${Math.round(H * u)}px`;
}
if (ctx && typeof ctx.setTransform === "function") ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
paint();
return true;
},
};
}
export default Object.freeze({ id: "ghoul", title: "Ghoul Rush", create });
@@ -29,37 +29,37 @@
// The strip the pills sit on, Planny's box and his star (in your highlight)
// follow the page.
import { drawPill, LIVES, livesText, PILL, pillInk } from "./pills.js";
import { LOSE_SOUNDS as BONES_LOSE_SOUNDS, LOSE_WORDS as BONES_LOSE_WORDS, boneArt } from "./ghoul-bones-draw.js";
import { LOOKS as GRAVEYARD_LOOKS, graveyardArt } from "./ghoul-graveyard-draw.js";
import { LOOKS as GROUNDS_LOOKS, LOSE_SOUNDS as GROUNDS_LOSE_SOUNDS, LOSE_WORDS as GROUNDS_LOSE_WORDS, VOICES as GROUNDS_VOICES, groundsArt } from "./ghoul-grounds-draw.js";
import { LOOKS as CHAPEL_LOOKS, LOSE_SOUNDS as CHAPEL_LOSE_SOUNDS, LOSE_WORDS as CHAPEL_LOSE_WORDS, VOICES as CHAPEL_VOICES, chapelArt } from "./ghoul-chapel-draw.js";
import { LOOKS as SANATORIUM_LOOKS, LOSE_SOUNDS as SANATORIUM_LOSE_SOUNDS, LOSE_WORDS as SANATORIUM_LOSE_WORDS, VOICES as SANATORIUM_VOICES, sanatoriumArt } from "./ghoul-sanatorium-draw.js";
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 { drawPill, LIVES, livesText, PILL, pillInk } from "../../pills.js";
import { LOSE_SOUNDS as BONES_LOSE_SOUNDS, LOSE_WORDS as BONES_LOSE_WORDS, boneArt } from "../stages/wing/ghoul-bones-draw.js";
import { LOOKS as GRAVEYARD_LOOKS, graveyardArt } from "../stages/graveyard/ghoul-graveyard-draw.js";
import { LOOKS as GROUNDS_LOOKS, LOSE_SOUNDS as GROUNDS_LOSE_SOUNDS, LOSE_WORDS as GROUNDS_LOSE_WORDS, VOICES as GROUNDS_VOICES, groundsArt } from "../stages/grounds/ghoul-grounds-draw.js";
import { LOOKS as CHAPEL_LOOKS, LOSE_SOUNDS as CHAPEL_LOSE_SOUNDS, LOSE_WORDS as CHAPEL_LOSE_WORDS, VOICES as CHAPEL_VOICES, chapelArt } from "../stages/chapel/ghoul-chapel-draw.js";
import { LOOKS as SANATORIUM_LOOKS, LOSE_SOUNDS as SANATORIUM_LOSE_SOUNDS, LOSE_WORDS as SANATORIUM_LOSE_WORDS, VOICES as SANATORIUM_VOICES, sanatoriumArt } from "../stages/sanatorium/ghoul-sanatorium-draw.js";
import { LOOKS as VILLAGE_LOOKS, LOSE_SOUNDS as VILLAGE_LOSE_SOUNDS, LOSE_WORDS as VILLAGE_LOSE_WORDS, VOICES as VILLAGE_VOICES, villageArt } from "../stages/village/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 "../stages/mine/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 "../rides/cart/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 "../rides/wagon/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 "../rides/sled/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 "../rides/banister/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 "../rides/hearse/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 "../rides/gurney/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 "../rides/pew/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 "../rides/mower/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 "../rides/tray/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 "../stages/carnival/ghoul-carnival-draw.js";
import { LOOKS as FROZEN_LOOKS, LOSE_SOUNDS as FROZEN_LOSE_SOUNDS, LOSE_WORDS as FROZEN_LOSE_WORDS, VOICES as FROZEN_VOICES, frozenArt } from "../stages/frozen/ghoul-frozen-draw.js";
import { LOOKS as BOG_LOOKS, LOSE_SOUNDS as BOG_LOSE_SOUNDS, LOSE_WORDS as BOG_LOSE_WORDS, VOICES as BOG_VOICES, bogArt } from "../stages/bog/ghoul-bog-draw.js";
import { LOOKS as LANTERN_LOOKS, LOSE_SOUNDS as LANTERN_LOSE_SOUNDS, LOSE_WORDS as LANTERN_LOSE_WORDS, VOICES as LANTERN_VOICES, lanternArt } from "../rides/lantern/ghoul-lantern-draw.js";
import { diceArt } from "../core/ghoul-dice-draw.js";
import { gameOverBanner } from "../story/ghoul-gameover-draw.js";
import { introArt } from "../story/ghoul-intro-draw.js";
import { storyArt } from "../story/ghoul-story-draw.js";
import { bonusArt } from "../core/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 "../rides/dark-ride/ghoul-ride-voices.js";
import { rideArt } from "../rides/dark-ride/ghoul-ride-draw.js";
import { armsArt } from "../arms/ghoul-arms-draw.js";
import { pickerArt } from "./ghoul-picker-draw.js";
import { bossIntroArt } from "./ghoul-bossintro-draw.js";
import { bossIntroArt } from "../story/ghoul-bossintro-draw.js";
import { monsterArt } from "./ghoul-monsters-draw.js";
const FALLBACK_COLORS = Object.freeze({ board: "#ffffff", line: "#e4ddd1", you: "#206cc3", ink: "#1d1a17" });
@@ -139,7 +139,7 @@ export const LOOKS = Object.freeze({
...FROZEN_LOOKS,
...RIDE_LOOKS,
...BOG_LOOKS,
...BOGBOAT_LOOKS,
...LANTERN_LOOKS,
crypt: Object.freeze({ wallTop: "#0a0b0e", wallLow: "#1b1e25", paper: "#262a33", wainscot: "#14161b", floorTop: "#43474f", floor: "#22252b", floorEdge: "#0a0b0d", shelf: "#30343c", shelfTop: "#4a4f58", pit: "#010102", window: "#b4bfd1", decor: "tombs", color: "#b4bfd1", dark: 0.9 }),
});
export const lookOf = (id) => LOOKS[id] || LOOKS.foyer;
@@ -263,9 +263,9 @@ 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 = { hudLayout, drawPower, ellipse, circle, roundRect, line, rotate, eye, hash, say, gate, label, drawBoneShape, BONE, DANGER, GOLD, FLASH, EYE_RED, EYE_PALE, EYE_AMBER };
const HELP = { paintDark, hudLayout, drawPower, ellipse, circle, roundRect, line, rotate, eye, hash, say, gate, label, drawBoneShape, BONE, DANGER, GOLD, FLASH, EYE_RED, EYE_PALE, EYE_AMBER };
const ARMS_ART = armsArt(HELP);
const PACK_ART = { arms: ARMS_ART, bones: boneArt(HELP), graveyard: graveyardArt(HELP), grounds: groundsArt(HELP), chapel: chapelArt(HELP), sanatorium: sanatoriumArt(HELP), village: villageArt(HELP), mine: mineArt(HELP), cart: cartArt(HELP), sled: sledArt(HELP), banister: banisterArt(HELP), hearse: hearseArt(HELP), codeblue: gurneyArt(HELP), pew: pewArt(HELP), 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 PACK_ART = { arms: ARMS_ART, bones: boneArt(HELP), graveyard: graveyardArt(HELP), grounds: groundsArt(HELP), chapel: chapelArt(HELP), sanatorium: sanatoriumArt(HELP), village: villageArt(HELP), mine: mineArt(HELP), cart: cartArt(HELP), sled: sledArt(HELP), banister: banisterArt(HELP), hearse: hearseArt(HELP), codeblue: gurneyArt(HELP), pew: pewArt(HELP), lantern: lanternArt(HELP), mower: mowerArt(HELP), tray: trayArt(HELP), wagon: wagonArt(HELP), carnival: carnivalArt(HELP), frozen: frozenArt(HELP), bog: bogArt(HELP), ride: { backdrop() {}, lights() {}, react: rideReact } };
const packs = Object.values(PACK_ART);
const DICE = diceArt(HELP);
const OVER_BANNER = gameOverBanner(HELP);
@@ -1676,6 +1676,27 @@ function hole(c, x, y, r, s) {
c.fill();
}
// A night over the whole field with a hole for each of `lights` ([x, y, r, strength], field units, y down): a room that
// is drawn whole by its own art (the Drowned Lantern) uses it, since it has no scrolling and no still layers to dim.
// False where the page cannot make the layer (the caller dims plainly instead).
function paintDark(ctx, v, alpha, lit) {
const { g } = v;
const d = darkCanvas(ctx, g);
if (!d) return false;
const { c, a } = d;
c.setTransform(1, 0, 0, 1, 0, 0);
c.globalCompositeOperation = "source-over";
c.clearRect(0, 0, d.w, d.h);
c.fillStyle = `rgba(2, 5, 7, ${alpha.toFixed(3)})`;
c.fillRect(0, 0, d.w, d.h);
c.setTransform(a, 0, 0, a, DARK_MARGIN * a, DARK_MARGIN * a);
c.globalCompositeOperation = "destination-out";
for (const [x, y, r, s] of lit) hole(c, x, y, r, s);
c.globalCompositeOperation = "source-over";
ctx.drawImage(d.canvas, -DARK_MARGIN, -DARK_MARGIN, g.FIELD_W + DARK_MARGIN * 2, g.FIELD_H + DARK_MARGIN * 2);
return true;
}
// The flashlight's cone, out from the blaster the way Planny faces.
const CONE_LEN = 46;
const CONE_HALF = 0.36;
@@ -1746,7 +1767,7 @@ function drawGlowing(ctx, v) {
/* ------------------------------------------------------------ feedback */
const KILL_WORDS = Object.freeze({ head: "Headshot!", stomp: "Crunch!", crush: "Flattened!", garlic: "Garlic!" });
const LOSE_WORDS = Object.freeze({ time: "Out of time", pit: "Into the dark", bone: "Skull cracked", chandelier: "Crushed", acid: "Burned alive", wave: "Thrown down", ...BONES_LOSE_WORDS, ...BANISTER_LOSE_WORDS, ...GROUNDS_LOSE_WORDS, ...CHAPEL_LOSE_WORDS, ...SANATORIUM_LOSE_WORDS, ...VILLAGE_LOSE_WORDS, ...MINE_LOSE_WORDS, ...CART_LOSE_WORDS, ...SLED_LOSE_WORDS, ...HEARSE_LOSE_WORDS, ...GURNEY_LOSE_WORDS, ...PEW_LOSE_WORDS, ...MOWER_LOSE_WORDS, ...TRAY_LOSE_WORDS, ...WAGON_LOSE_WORDS, ...CARNIVAL_LOSE_WORDS, ...FROZEN_LOSE_WORDS,...RIDE_LOSE_WORDS, ...BOG_LOSE_WORDS, ...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" });
const LOSE_WORDS = Object.freeze({ time: "Out of time", pit: "Into the dark", bone: "Skull cracked", chandelier: "Crushed", acid: "Burned alive", wave: "Thrown down", ...BONES_LOSE_WORDS, ...BANISTER_LOSE_WORDS, ...GROUNDS_LOSE_WORDS, ...CHAPEL_LOSE_WORDS, ...SANATORIUM_LOSE_WORDS, ...VILLAGE_LOSE_WORDS, ...MINE_LOSE_WORDS, ...CART_LOSE_WORDS, ...SLED_LOSE_WORDS, ...HEARSE_LOSE_WORDS, ...GURNEY_LOSE_WORDS, ...PEW_LOSE_WORDS, ...MOWER_LOSE_WORDS, ...TRAY_LOSE_WORDS, ...WAGON_LOSE_WORDS, ...CARNIVAL_LOSE_WORDS, ...FROZEN_LOSE_WORDS,...RIDE_LOSE_WORDS, ...BOG_LOSE_WORDS, ...LANTERN_LOSE_WORDS, hound: "Mauled", spider: "Bitten", wraith: "Taken", hands: "Dragged under", mourner: "Mourned", robber: "Buried alive", crow: "Pecked", legs: "Kicked down", stone: "Struck by a headstone", fist: "Crushed by stone", angel: "Turned to stone" });
// 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 });
@@ -2108,7 +2129,7 @@ export const VOICES = Object.freeze({
...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,
...LANTERN_VOICES,
});
// Plays a kind's voice for an act, if it has one, its pitch a touch varied.
function say(tone, kind, act, level) {
@@ -2155,7 +2176,7 @@ const LOSE_SOUNDS = Object.freeze({
...WAGON_LOSE_SOUNDS,
...RIDE_LOSE_SOUNDS,
...BOG_LOSE_SOUNDS,
...BOGBOAT_LOSE_SOUNDS,
...LANTERN_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]);
@@ -2475,8 +2496,8 @@ export function drawScene(ctx, v) {
}
// 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);
if (round.runner && (round.runner.id === "pew" || round.runner.id === "lantern")) {
PACK_ART[round.runner.id].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);
@@ -2491,7 +2512,7 @@ export function drawScene(ctx, v) {
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.banner && round.phase !== "pick" && round.phase !== "select" && round.phase !== "roll" && round.phase !== "ask") 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);
@@ -2592,8 +2613,9 @@ export function drawScene(ctx, v) {
ctx.globalAlpha = 1;
}
if (v.state === "running" && round.phase === "roll") DICE.roll(ctx, v);
if (v.state === "running" && round.phase === "ask") DICE.ask(ctx, v);
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.banner && round.phase !== "pick" && round.phase !== "select" && round.phase !== "roll" && round.phase !== "ask") drawBanner(ctx, v, v.banner);
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);
@@ -0,0 +1,50 @@
// Plan2Code Web Console - Ghoul Rush, the twelfth activity: a dark haunted house seen side on, Planny running, jumping and blasting his flashlight through it room by room, the zombies, crawlers, bats, ghosts, skeletons, hellhounds, widows, wraiths, bloaters and bosses, and the game contract.
//
// The Activities window (screens/activities.js) drives everything: it ticks
// the game, hands it keys (and their releases) and pauses it. A game never
// runs a timer or listens for a key of its own, so a paused game cannot move.
// The rules are plain functions over a round object (newRound, roomFor,
// stagesLeft, steerPick, pickStage, steerSelect, takeSelect, groundAt,
// footing, jumpHeightAt, jump, moveYou, spawnMonster, hurt, kill, lose,
// applyPower, advance, underBanner), exported so the unit suite can
// drive them without a canvas; the rooms live in ghoul-rooms.js, the
// power-ups and pickups in ghoul-powers.js, the run flow (rounds, the stage
// pick, the camera, respawns and spawners) in ghoul-run.js and the drawing (and what each
// event looks and sounds like) in ghoul-draw.js, and
// the default export is the contract every listed game answers.
//
// Planny sprints left to right through a haunted mansion, the camera
// scrolling with him: held arrows run, up jumps (let go early for a short
// hop), space fires his flashlight blaster the way he faces (hold it to keep
// firing), and down ducks on the ground or drops through a shelf. Each room's door opens once he grabs its key. A run starts in a
// long hall, then goes stage by stage (three rooms, then a boss whose fall
// opens the door), each next stage picked from two not yet played that run;
// clearing every stage wins. Every other room keeps a horde pouring in from
// the edges of the view, so standing still is never safe. Kills in quick succession build a chain that multiplies their points
// and runs out fast; a shot to the head or a stomp from above doubles a
// kill. Souls (the `candy` in the rules), power-ups (spread shot, rapid
// fire, a garlic shield, an extra life, a lantern, bat wings, a church bell
// and an hourglass) and a time bonus per room add up. Every room but a boss's has
// a clock, and a crowd of the dead piles up to reach him on a shelf above. A
// hit, a fall or the clock running out costs one of seven lives and puts him
// back at the room's start, safe for a moment. Each stage cleared makes the
// next quicker and tougher, and the memo keeps the most stages ever cleared
// in one run.
//
// This file is only the game's public face, so the page and the tests have one
// place to import from. The game itself is in its parts:
//
// core/ghoul-tables.js: numbers and tables: every timing and size the rules share, the monsters and bosses with each stage pack's joined in (PACKS), the seeded dice, and a room's numbers at a depth (roomFor).
// core/ghoul-planny.js: ground and Planny: what stands where (surfaces, shelves and landing on them), and how Planny runs, jumps and falls.
// core/ghoul-monsters.js: monsters: spawning them, how each kind walks, hops, climbs and swoops, and what they throw.
// core/ghoul-fight.js: bosses and damage: a boss's fight and fall, hurting and killing a monster, and losing a life.
// core/ghoul-play.js: play loop: the kits it hands its packs and ghoul-run.js (KIT, RUN_KIT), the blaster and bolts, hits, stomps and timers, one slice of play, and advance().
// core/ghoul-window.js: window: the game's contract with the Activities page (create), its keys and pointer, what fx and sounds its events set off, each room's music (ROOM_MUSIC), and the view handed to the drawing.
export * from "./core/ghoul-tables.js";
export * from "./core/ghoul-planny.js";
export * from "./core/ghoul-monsters.js";
export * from "./core/ghoul-fight.js";
export * from "./core/ghoul-play.js";
export * from "./core/ghoul-window.js";
export { default } from "./core/ghoul-window.js";
@@ -17,9 +17,9 @@
// - YOU: `you.state`, `you.vy`, `you.ducking`, `you.x`, `you.y` (the portraits' eyes follow).
// - events leave short-lived bits in the view's `fx` (`banBits`, `banLand`).
import { linesOf, trackY } from "./ghoul-cart.js";
import { linesOf, trackY } from "../cart/ghoul-cart.js";
import { BUTLER_H, CANDLE_H, SWING_BOB_W, WEB_HI, WEB_LO, lowerLine, swingAt } from "./ghoul-banister.js";
import { ANSWER_COLORS, TELEGRAPH_ALPHA, TELEGRAPH_FULL, TELEGRAPH_SEE, TELEGRAPH_WORDS } from "./ghoul-sled-draw.js";
import { ANSWER_COLORS, TELEGRAPH_ALPHA, TELEGRAPH_FULL, TELEGRAPH_SEE, TELEGRAPH_WORDS } from "../sled/ghoul-sled-draw.js";
const freeze = (o) => Object.freeze(o);
const TAU = Math.PI * 2;
@@ -68,7 +68,7 @@
// 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";
import { linesAt, linesOf, slopeOf, trackY } from "../cart/ghoul-cart.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
@@ -26,7 +26,7 @@
// - Planny: `you.state`, `you.vy` (tilts the gurney in the air), `you.ducking`, `you.x`, `you.y`.
// - events leave short-lived bits in the view's `fx` (`blueBits`, `blueLand`).
import { ANSWER_COLORS } from "./ghoul-sled-draw.js";
import { ANSWER_COLORS } from "../sled/ghoul-sled-draw.js";
const freeze = (o) => Object.freeze(o);
const TAU = Math.PI * 2;
@@ -66,7 +66,7 @@
// "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";
import { linesAt, linesOf, slopeOf, trackY } from "../cart/ghoul-cart.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,809 @@
// Plan2Code Web Console - Ghoul Rush's Drowned Lantern, its rules: Gallows Bog's bonus round, a top-down game on one fixed screen and not a ride. YOU carry a lantern over a black bog island of mossy hummocks joined by plank walks, light the five wisp shrines, then run back to the boat while Old Mother Bog rises out of her pool. Four kinds of hunter each play by one rule you can see and use: the Bog Lurker hears footsteps on wood, the wisps guard the shrines and burst in a flare, the leeches never enter your light, and the bog bodies grab whatever stops beside them. A stage pack that ghoul.js plugs in.
//
// Like Holy Roller (ghoul-pew.js) it is handed a kit `k` of ghoul.js's own helpers and never imports
// ghoul.js. Pack fields used: `ride` (a hook that moves Planny himself, so no key walks him) and `place`
// (Planny put down in the room). It adds no monster, boss or hazard kind, and it draws NO random number:
// every hunter follows a table in the room's `ride` and a fixed rule, stepped on the slice. Its state lives
// in the shared ride slot `round.runner` (`id` "lantern"; null in any other room). Every event it puts on
// the field starts with `lantern`.
//
// THE FIELD IS THE ART'S ALONE (like the pew's): ghoul-draw.js hands the whole field to lanternArt's `field`.
// Positions here are field units with y counted DOWN from the field's top (the way the art draws). `you.x`
// mirrors Planny's x and `you.y` stays on the room's floor, so the engine's own checks never see a fall;
// what the banners must keep clear of is listed in `runner.marks` ([x, y up] pairs, read by ghoul.js's
// underBanner).
//
// THE KEYS (the game has the four arrows and SPACE only): the ARROWS walk (two at once walk a diagonal; a
// walk that runs into the water slides along the shore or the plank, so one arrow follows a crooked plank).
// SPACE flares the lantern: a ring of light FLARE_R wide that bursts every wisp in it and scatters the
// leeches, at the price of FLARE_OIL of the oil and a bang the Lurker hears from anywhere.
//
// THE OBJECTIVE: stand on a shrine's stone for SHRINE_MS (the time is kept if you step off) to light it;
// the fifth lit wakes Old Mother Bog for good, and the boat (`boat`) at the landing you started on is the
// way out. The oil burns down over OIL_MS and the lantern's light shrinks with it (`lightR`); a lit shrine
// fills it again.
//
// THE HUNTERS, one rule each:
// - The BOG LURKER hunts SOUND: a step on the planks (heard within STEP_HEAR; the moss is silent), a flare
// (heard anywhere) and a shrine catching (SHRINE_HEAR). It swims to the last place it heard you; within
// AIM_FROM of it, it stops, lines up a lane through that spot (AIM_MS, the lane drawn red) and dashes down
// it (DASH_V, DASH_PAST beyond the spot). It strikes where it HEARD you, never where you are: off the lane,
// or on the moss, you are safe. After a dash it rests, deaf, for REST_MS. Once Mother rises it cowers (state
// "cower"), deaf, under the far water: the run to the boat is hers.
// - The WISPS guard the shrines: each unlit shrine has one circling it that rushes a lantern within
// GUARD_SENSE (on a leash of LEASH round its shrine) and has you at WISP_CATCH. A flare bursts it; it comes
// back after WISP_REFORM_MS unless its shrine is lit by then. From the third shrine on, Old Mother Bog sends
// roaming wisps out of her pool (`wake`), which drift after a lantern within ROAM_SENSE.
// - The LEECHES never enter your light. They follow you at its edge, and once the oil is out (the flame
// gutters) they swarm in and bite (LEECH_BITE). A flare scatters them for SCATTER_MS.
// - The BOG BODIES lie beside the planks, bubbling: stand still within BODY_NOTICE of one for BODY_STILL_MS and
// the water boils (BODY_RISE_MS), then a hand comes up for BODY_UP_MS and takes anything within BODY_REACH.
// Walking past is always safe; stopping is not (which the Lurker, who hears you walk, makes hard).
// - OLD MOTHER BOG stirs in her pool as the shrines are lit (her eyes open a fifth each). From the third
// shrine (or MOTHER_LATE_S into the round) her hand's shadow finds you every so often: it follows you
// (HAND_TRACK_MS), stops and reddens (HAND_LOCK_MS), then slams (HAND_R). Keep moving and it misses. Once the
// fifth shrine is lit she RISES and the slams come one after another until you reach the boat.
//
// A catch costs one of the round's five hearts (ghoul-bonus.js), never a life, and never moves Planny: he
// blinks safe for BONUS_SAFE_MS and the hunter that took him backs off. The last heart gone ends the round
// with nothing. The room's clock (`round.timeMs`, TIME_S) at nought is the end too, unless the endless-lives
// code is on (the clock then starts again).
//
// THE GRADE (ghoul-bonus.js's `perf`): `total` is the five kinds that can take you (HUNTERS), `hits` the kinds
// that did, `acts` the wisps burst and the close calls (a dash or a slam that missed by less than CLOSE_R;
// the goal is ACTS_GOAL), and `steady` falls if the flame ever gutters.
//
// WHAT THE ART READS: `spec.ride`, `round.runner` (see `place`), `round.you.safeMs`, `round.timeMs`, the
// events in EVENTS, and the exported numbers and helpers.
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
const dist = (ax, ay, bx, by) => Math.hypot(ax - bx, ay - by);
export const MONSTERS = freeze({});
// Every event this pack puts on the field, for the art and the sounds to answer.
export const EVENTS = freeze([
"lanternStep", "lanternFlare", "lanternSputter", "lanternPop", "lanternShrine", "lanternGutter", "lanternCatch", "lanternFinish", "lanternMeet",
"lanternLurkerCue", "lanternAim", "lanternDash", "lanternClose", "lanternWispCue", "lanternLeechCue", "lanternBodyCue",
"lanternWake", "lanternRise", "lanternHand", "lanternSlam",
]);
// What costs a heart, by hunter (and the round's grade counts these five kinds).
export const CAUSES = freeze({ lurker: "lanternLurker", leech: "lanternLeech", wisp: "lanternWisp", body: "lanternBody", mother: "lanternMother" });
export const HUNTERS = freeze(["lurker", "leech", "wisp", "body", "mother"]);
// The field's map, in field units (y down): where Planny and the hunters can be (the band above y0 is the HUD's).
export const MAP = freeze({ x0: 3, x1: 93, y0: 11, y1: 52 });
// Planny. Speeds are units a second.
export const WALK_V = 9.5;
export const PLANK_HALF = 2.4;
// The room's clock.
export const TIME_S = 90;
// The shrines: stand on one SHRINE_MS (kept if you step off) to light it.
export const SHRINES = 5;
export const SHRINE_MS = 1800;
export const SHRINE_R = 2.8;
export const SHRINE_POINTS = 200;
// The light a lit shrine casts, which the art draws.
export const SHRINE_LIGHT = 9;
// The way out: within BOAT_R of the boat, once all five are lit.
export const BOAT_R = 4;
export const ESCAPE_POINTS = 500;
// The oil: full burns down in OIL_MS; the light's radius follows it.
export const OIL_MS = 26000;
export const LIGHT_MIN = 1.6;
export const LIGHT_MAX = 15;
export const OIL_LOW = 0.3;
export const lightR = (oil) => (oil > 0 ? LIGHT_MIN + 2.4 + (LIGHT_MAX - LIGHT_MIN - 2.4) * clamp(oil, 0, 1) : LIGHT_MIN);
// The flare.
export const FLARE_OIL = 0.22;
export const FLARE_CD_MS = 700;
export const FLARE_R = 12;
export const FLARE_MS = 900;
export const POP_POINTS = 80;
// The Bog Lurker.
export const STEP_MS = 330;
export const STEP_HEAR = 28;
export const SHRINE_HEAR = 45;
export const LURKER_V = 9;
export const LURKER_DRIFT_V = 4;
export const AIM_FROM = 14;
export const AIM_MS = 800;
export const DASH_V = 46;
export const DASH_PAST = 8;
export const DASH_HIT = 2.7;
export const REST_MS = 2200;
// A dash or a slam that missed Planny by less than this was a close call (an act).
export const CLOSE_R = 6.5;
export const CLOSE_POINTS = 50;
// The wisps.
export const ORBIT_R = 5.5;
export const ORBIT_W = 1.1;
export const GUARD_SENSE = 12;
export const LEASH = 19;
export const WISP_V = 7;
export const WISP_RETURN_V = 5;
export const ROAM_V = 3.5;
export const ROAM_SENSE = 20;
export const ROAM_CHASE_V = 6;
export const WISP_CATCH = 2;
export const WISP_REFORM_MS = 6000;
// The leeches.
export const LEECH_V = 7;
export const LEECH_DRIFT_V = 3;
export const LEECH_SENSE = 30;
export const LEECH_EDGE = 0.8;
export const LEECH_BITE = 2.4;
export const SCATTER_MS = 3000;
export const SCATTER_V = 10;
// What the leeches' bite leaves in the lantern (Planny shakes them off and fans the flame).
export const OIL_AFTER_BITE = 0.4;
// The bog bodies: they feel Planny stand still within BODY_NOTICE for BODY_STILL_MS.
export const BODY_NOTICE = 6;
export const BODY_STILL_MS = 250;
export const BODY_REACH = 3.4;
export const BODY_RISE_MS = 700;
export const BODY_UP_MS = 900;
export const BODY_REST_MS = 2600;
// Old Mother Bog: her hand's cycle, the gap between hands by shrines lit (risen: MOTHER_RISEN_GAP), and the late wake.
export const HAND_TRACK_MS = 1000;
export const HAND_TRACK_RISEN_MS = 750;
export const HAND_LOCK_MS = 420;
export const HAND_REST_MS = 450;
export const HAND_V = 8;
export const HAND_RISEN_V = 9.5;
export const HAND_R = 4;
export const MOTHER_GAP = freeze([0, 0, 0, 5500, 4000]);
export const MOTHER_LATE_S = 55;
export const MOTHER_RISEN_GAP = 250;
export const RISE_MS = 1300;
// A hunter's tag the first time it comes this near (the art shows its rule once).
export const MEET_R = 22;
// Cues heard before a thing is close: how near, and how often.
export const CUE_R = freeze({ leech: 24, wisp: 22 });
export const CUE_MS = freeze({ leech: 2600, wisp: 1800 });
// The things done on purpose that are worth a die.
export const ACTS_GOAL = 6;
const mine = (round) => (round.runner && round.runner.id === "lantern" ? round.runner : null);
// How far into the round it is (ms), from the room's clock.
export const elapsedOf = (round) => Math.max(0, (round.spec.ride ? round.spec.ride.time : TIME_S * 1000) - round.timeMs);
// The lantern's light radius now.
export const lightOf = (c) => lightR(c.oil);
/* ------------------------------------------------------------- the island */
// The island's walkable shapes, built once per ride: hummock disks and plank capsules.
const GEOM = new WeakMap();
export function geomOf(R) {
let g = GEOM.get(R);
if (!g) {
const disks = R.hummocks.map(([x, y, r]) => freeze({ x, y, r }));
const planks = R.planks.map(([a, b]) => freeze({ x1: R.hummocks[a][0], y1: R.hummocks[a][1], x2: R.hummocks[b][0], y2: R.hummocks[b][1], a, b }));
g = freeze({ disks: freeze(disks), planks: freeze(planks) });
GEOM.set(R, g);
}
return g;
}
// The point of plank `p` nearest (x, y), and how far it is.
function onPlankAxis(p, x, y) {
const dx = p.x2 - p.x1;
const dy = p.y2 - p.y1;
const t = clamp(((x - p.x1) * dx + (y - p.y1) * dy) / (dx * dx + dy * dy), 0, 1);
const sx = p.x1 + dx * t;
const sy = p.y1 + dy * t;
return [sx, sy, dist(x, y, sx, sy)];
}
// The nearest point of the island to (x, y) (the point itself when it is on it).
export function project(R, x, y) {
const g = geomOf(R);
let best = null;
let bd = Infinity;
const take = (px, py) => {
const d = dist(x, y, px, py);
if (d < bd) {
bd = d;
best = [px, py];
}
};
for (const s of g.disks) {
const d = dist(x, y, s.x, s.y);
if (d <= s.r) return [x, y];
take(s.x + ((x - s.x) / d) * s.r, s.y + ((y - s.y) / d) * s.r);
}
for (const p of g.planks) {
const [sx, sy, d] = onPlankAxis(p, x, y);
if (d <= PLANK_HALF) return [x, y];
take(sx + ((x - sx) / d) * PLANK_HALF, sy + ((y - sy) / d) * PLANK_HALF);
}
return best || [x, y];
}
export const onIsland = (R, x, y) => {
const p = project(R, x, y);
return dist(p[0], p[1], x, y) < 1e-6;
};
// Whether (x, y) is on the moss of a hummock (silent) rather than on a plank (heard).
export const onMoss = (R, x, y) => geomOf(R).disks.some((s) => dist(x, y, s.x, s.y) <= s.r);
// The shrine i's stone.
export const shrineAt = (R, i) => R.hummocks[R.shrines[i]];
/* -------------------------------------------------------------- placing */
const wispOf = (w, i) => ({ i, x: w.home[0], y: w.home[1], wp: 0, state: w.wake > 0 ? "asleep" : w.shrine >= 0 ? "guard" : "roam", t: 0, cue: 0 });
// Planny put down in the room: on the landing at the start, or (the same room, after a respawn) with the shrines already lit kept as they were.
function place(round, k) {
const R = round.spec.ride;
if (!R || R.runner !== "lantern") {
// (Another ride's state in the shared slot is not ours to touch.)
if (mine(round)) round.runner = null;
return;
}
const again = mine(round) && round.runner.room === round.room ? round.runner : null;
const [sx, sy] = R.start;
const you = round.you;
Object.assign(you, { x: sx, y: k.groundAt(round.spec, sx), vy: 0, state: "run", shelf: -1, face: 1, ducking: false, coyote: 0, drop: -1 });
const shrines = R.shrines.map((s, i) => (again ? again.shrines[i] : 0));
round.runner = {
id: "lantern", room: round.room, x: sx, y: sy, fx: 1, fy: 0, moving: false, plank: false, stepMs: 0, clock: 0, hf: false,
shrines, lit: shrines.filter((v) => v >= SHRINE_MS).length, oil: 1, gutter: false, flareCd: 0, flare: null, done: false,
lurker: { x: R.lurker.home[0], y: R.lurker.home[1], wp: 0, state: "drift", t: 0, tx: 0, ty: 0, ax: 0, ay: 0, bx: 0, by: 0, near: Infinity },
wisps: R.wisps.map(wispOf),
leeches: R.leeches.map((h, i) => ({ i, x: h.home[0], y: h.home[1], wp: 0, state: "drift", t: 0, cue: 0 })),
bodies: R.bodies.map(([x, y]) => ({ x, y, state: "sunk", t: 0 })),
mother: { stir: 0, risen: false, riseT: 0, gap: 0, hand: null },
met: {}, caught: { lurker: 0, leech: 0, wisp: 0, body: 0, mother: 0 }, marks: [],
};
const b = round.bonusRound;
if (b) {
b.perf.total = HUNTERS.length;
b.perf.goal = ACTS_GOAL;
if (!again) b.perf.steady = true;
}
round.camLead = 0;
}
/* ------------------------------------------------------------ the round */
// Planny and the whole island for one slice. Returns true once it has moved Planny (every slice of the
// round); false once he is in the boat and has been put at the door.
function ride(round, ms, k) {
const R = round.spec.ride;
const c = mine(round);
if (!R || R.runner !== "lantern" || !c || c.done) return false;
const you = round.you;
const inp = round.input;
const ev = (type, extra = {}) => round.events.push({ type, x: c.x, y: c.y, ...extra });
inp.jump = 0;
// The door is past the map's edge, so no walk reaches it; a Planny put at it (the suites, a bot) has the room done, as a ride's finish line does.
if (you.x >= round.spec.door) return finish(round, c, R, k, ev);
c.clock += ms;
const noises = [];
// SPACE: a flare, once a press.
const fire = Boolean(inp.fire);
if (fire && !c.hf) flare(round, c, noises, ev);
c.hf = fire;
walk(round, c, R, ms, noises, ev);
you.x = c.x;
Object.assign(you, { y: k.groundAt(round.spec, c.x), vy: 0, state: "run", ducking: false, face: c.fx < 0 ? -1 : 1 });
oil(round, c, ms, ev);
shrines(round, c, R, ms, noises, ev);
if (c.flare && (c.flare.t -= ms) <= 0) c.flare = null;
c.flareCd = Math.max(0, c.flareCd - ms);
// All five lit and Planny at the boat: away.
if (c.lit >= SHRINES && dist(c.x, c.y, R.boat[0], R.boat[1]) <= BOAT_R) return finish(round, c, R, k, ev);
if (hunters(round, c, R, ms, noises, k, ev) || round.phase !== "play") return true;
marks(c, round);
// The clock ran out: the bog keeps the light.
if (round.timeMs <= 0) return drowned(round, k);
return true;
}
// The walk: the arrows, sliding along the shore when the straight way is water; a step on the planks is heard.
function walk(round, c, R, ms, noises, ev) {
const inp = round.input;
let dx = (inp.right ? 1 : 0) - (inp.left ? 1 : 0);
let dy = (inp.down ? 1 : 0) - (inp.up ? 1 : 0);
c.moving = false;
if (dx || dy) {
const m = Math.hypot(dx, dy);
dx /= m;
dy /= m;
c.fx = dx;
c.fy = dy;
const want = WALK_V * (ms / 1000);
const at = slide(R, c.x, c.y, dx, dy, want);
if (dist(at[0], at[1], c.x, c.y) > want * 0.05) {
c.x = clamp(at[0], MAP.x0, MAP.x1);
c.y = clamp(at[1], MAP.y0, MAP.y1);
c.moving = true;
}
}
c.plank = !onMoss(R, c.x, c.y);
if (c.moving && c.plank) {
c.stepMs -= ms;
if (c.stepMs <= 0) {
c.stepMs += STEP_MS;
noises.push({ x: c.x, y: c.y, r: STEP_HEAR, kind: "step" });
ev("lanternStep");
}
} else c.stepMs = 0;
}
// Where a step of `len` the way (dx, dy) lands: straight on if it can, else turned up to 85 degrees toward
// whichever way the shore or the plank runs, the first that keeps at least half the step going forward.
const TURNS = [0, 0.5, -0.5, 1, -1, 1.48, -1.48];
export function slide(R, x, y, dx, dy, len) {
let best = null;
let bestGo = -Infinity;
for (const a of TURNS) {
const ca = Math.cos(a);
const sa = Math.sin(a);
const ux = dx * ca - dy * sa;
const uy = dx * sa + dy * ca;
const [px, py] = project(R, x + ux * len, y + uy * len);
const go = (px - x) * dx + (py - y) * dy;
if (a === 0 && go >= len * 0.6) return [px, py];
if (go >= len * 0.5 * Math.cos(a) && go > bestGo + 1e-9) {
best = [px, py];
bestGo = go;
if (a !== 0) break;
}
}
return best || project(R, x, y);
}
// The oil burns down; out, the flame gutters (the leeches' moment); a shrine fills it again.
function oil(round, c, ms, ev) {
const was = c.oil;
c.oil = Math.max(0, c.oil - ms / OIL_MS);
if (was > 0 && c.oil <= 0) {
c.gutter = true;
ev("lanternGutter");
if (round.bonusRound) round.bonusRound.perf.steady = false;
}
if (c.oil > 0) c.gutter = false;
}
// SPACE: a ring of light FLARE_R round Planny, if there is oil for it.
function flare(round, c, noises, ev) {
if (c.flareCd > 0) return;
if (c.oil < FLARE_OIL) {
c.flareCd = FLARE_CD_MS;
ev("lanternSputter");
return;
}
c.oil -= FLARE_OIL;
c.flareCd = FLARE_CD_MS;
c.flare = { x: c.x, y: c.y, t: FLARE_MS };
noises.push({ x: c.x, y: c.y, r: Infinity, kind: "flare" });
ev("lanternFlare");
let popped = 0;
for (const w of c.wisps) {
if (!live(w) || dist(w.x, w.y, c.x, c.y) > FLARE_R) continue;
pop(round, c, w, ev, true);
popped++;
}
if (popped >= 2) ev("lanternPop", { combo: popped, x: c.x, y: c.y, points: POP_POINTS * popped });
if (popped >= 2) round.score += POP_POINTS * popped;
for (const S of c.leeches) if (dist(S.x, S.y, c.x, c.y) <= FLARE_R * 2) Object.assign(S, { state: "scatter", t: SCATTER_MS });
}
const live = (w) => w.state !== "popped" && w.state !== "gone" && w.state !== "asleep";
function act(round, points) {
round.score += points;
if (round.bonusRound) round.bonusRound.perf.acts++;
}
// A wisp bursts (an act when it was a flare's doing); it comes back unless its shrine is lit by then.
function pop(round, c, w, ev, byFlare) {
const R = round.spec.ride;
const spec = R.wisps[w.i];
Object.assign(w, { state: spec.shrine >= 0 && c.shrines[spec.shrine] >= SHRINE_MS ? "gone" : "popped", t: WISP_REFORM_MS });
if (byFlare) act(round, POP_POINTS);
ev("lanternPop", { x: w.x, y: w.y, points: byFlare ? POP_POINTS : 0 });
}
/* ----------------------------------------------------------------- shrines */
function shrines(round, c, R, ms, noises, ev) {
R.shrines.forEach((h, i) => {
if (c.shrines[i] >= SHRINE_MS) return;
const [hx, hy] = R.hummocks[h];
if (dist(c.x, c.y, hx, hy) > SHRINE_R) return;
c.shrines[i] += ms;
if (c.shrines[i] < SHRINE_MS) return;
c.shrines[i] = SHRINE_MS;
c.lit++;
c.oil = 1;
c.gutter = false;
round.score += SHRINE_POINTS;
noises.push({ x: hx, y: hy, r: SHRINE_HEAR, kind: "shrine" });
ev("lanternShrine", { n: c.lit, x: hx, y: hy, points: SHRINE_POINTS });
// Its guardian is laid to rest.
c.wisps.forEach((w) => {
if (R.wisps[w.i].shrine !== i) return;
if (live(w)) ev("lanternPop", { x: w.x, y: w.y, points: 0 });
w.state = "gone";
});
// Mother stirs; from the third shrine her hand comes now and then, and the fifth raises her.
const M = c.mother;
M.stir = c.lit;
if (c.lit === 3) ev("lanternWake", { x: R.pool[0], y: R.pool[1] });
if (c.lit >= SHRINES) {
Object.assign(M, { risen: true, riseT: RISE_MS, hand: null, gap: RISE_MS });
Object.assign(c.lurker, { state: "cower", t: 0 });
ev("lanternRise", { x: R.pool[0], y: R.pool[1] });
} else if (c.lit >= 3 && !M.hand) M.gap = Math.min(M.gap || Infinity, 1500);
});
}
// In the boat: Planny is put at the door, which the next slice walks through.
function finish(round, c, R, k, ev) {
const you = round.you;
if (!c.done && c.lit >= SHRINES) {
round.score += ESCAPE_POINTS;
ev("lanternFinish", { lit: c.lit, x: R.boat[0], y: R.boat[1], points: ESCAPE_POINTS });
}
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 });
return false;
}
// The clock is at nought: the last heart goes, and the round with it (the endless-lives code starts the clock again).
function drowned(round, k) {
const b = round.bonusRound;
if (round.infinite || !b) {
round.timeMs = round.spec.ride.time;
return true;
}
b.hearts = Math.min(b.hearts, 1);
k.lose(round, "time");
return true;
}
// What a banner over the field must keep clear of: Planny and anything that can hurt him, as [x, y up].
function marks(c, round) {
const up = (y) => 54 - y;
const out = [[c.x, up(c.y)]];
const L = c.lurker;
if (L.state === "aim" || L.state === "dash" || L.state === "hunt") out.push([L.x, up(L.y)]);
for (const w of c.wisps) if (live(w) && dist(w.x, w.y, c.x, c.y) < 20) out.push([w.x, up(w.y)]);
if (c.mother.hand) out.push([c.mother.hand.x, up(c.mother.hand.y)]);
c.marks = out;
}
/* ----------------------------------------------------------------- hunters */
// A heart lost to `kind`: Planny blinks safe (the engine's) where he stands. False when the blink (or the Garlic) took it.
function grab(round, c, kind, k, ev) {
if (!k.struck(round, CAUSES[kind])) return false;
c.caught[kind]++;
const b = round.bonusRound;
if (b && !b.perf.hits.includes(kind)) b.perf.hits.push(kind);
// The engine's "hearts left" float goes over Planny where he really is (the floor is all `you.y` knows).
const lose = round.events.findLast((e) => e.type === "lose");
if (lose) lose.y = 54 - c.y - 2.5;
ev("lanternCatch", { kind });
return true;
}
// Moves `e` toward (tx, ty) by `v` a second; returns what is left of the way.
function stepTo(e, tx, ty, v, dt) {
const d = dist(e.x, e.y, tx, ty);
if (d < 1e-6) return 0;
const m = Math.min(d, v * dt);
e.x += ((tx - e.x) / d) * m;
e.y += ((ty - e.y) / d) * m;
return d - m;
}
// Along a route: head for the next waypoint, and take the one after on arrival.
function patrol(e, route, v, dt) {
const [tx, ty] = route[e.wp % route.length];
if (stepTo(e, tx, ty, v, dt) < 0.8) e.wp = (e.wp + 1) % route.length;
}
const keep = (e) => {
e.x = clamp(e.x, MAP.x0 - 2, MAP.x1 + 2);
e.y = clamp(e.y, MAP.y0 - 2, MAP.y1 + 2);
};
// The first time a hunter comes near, it is named (the art shows its rule once).
function meet(c, kind, x, y, ev) {
if (c.met[kind]) return;
c.met[kind] = true;
ev("lanternMeet", { kind, x, y });
}
// A cue the ear gets before the eye: at most one a CUE_MS, while `e` is within CUE_R.
function cue(c, e, kind, ms, ev) {
e.cue = Math.max(0, (e.cue || 0) - ms);
if (e.cue > 0 || dist(e.x, e.y, c.x, c.y) > CUE_R[kind]) return;
e.cue = CUE_MS[kind];
ev(kind === "leech" ? "lanternLeechCue" : "lanternWispCue", { x: e.x, y: e.y });
}
// Every hunter for one slice. Returns true when the round is no longer in play (a last heart).
function hunters(round, c, R, ms, noises, k, ev) {
const steps = [lurker, wisps, leeches, bodies, mother];
for (const f of steps) if (f(round, c, R, ms, noises, k, ev)) return true;
return false;
}
// The distance from (px, py) to the segment (ax, ay)-(bx, by).
function toSegment(px, py, ax, ay, bx, by) {
const dx = bx - ax;
const dy = by - ay;
const l2 = dx * dx + dy * dy;
const t = l2 > 0 ? clamp(((px - ax) * dx + (py - ay) * dy) / l2, 0, 1) : 0;
return dist(px, py, ax + dx * t, ay + dy * t);
}
// THE LURKER: drift on its route; hunt the last noise it heard; within AIM_FROM, line up and dash through it; rest.
function lurker(round, c, R, ms, noises, k, ev) {
const L = c.lurker;
const dt = ms / 1000;
const heard = L.state === "drift" || L.state === "hunt" ? noises.filter((n) => dist(L.x, L.y, n.x, n.y) <= n.r).pop() : null;
if (heard) {
if (L.state === "drift") ev("lanternLurkerCue", { x: L.x, y: L.y });
Object.assign(L, { state: "hunt", tx: heard.x, ty: heard.y });
if (dist(L.x, L.y, c.x, c.y) <= MEET_R + 10) meet(c, "lurker", L.x, L.y, ev);
}
if (L.state === "drift") {
patrol(L, R.lurker.route, LURKER_DRIFT_V, dt);
} else if (L.state === "hunt") {
const left = stepTo(L, L.tx, L.ty, LURKER_V, dt);
if (left <= AIM_FROM) {
// The lane: from where it stops, through the spot it heard, DASH_PAST beyond.
const d = Math.max(0.5, dist(L.x, L.y, L.tx, L.ty));
const ux = (L.tx - L.x) / d;
const uy = (L.ty - L.y) / d;
Object.assign(L, { state: "aim", t: AIM_MS, ax: L.x, ay: L.y, bx: clamp(L.tx + ux * DASH_PAST, MAP.x0 - 2, MAP.x1 + 2), by: clamp(L.ty + uy * DASH_PAST, MAP.y0 - 2, MAP.y1 + 2), near: Infinity });
ev("lanternAim", { x: L.x, y: L.y, bx: L.bx, by: L.by });
}
} else if (L.state === "aim") {
L.t -= ms;
if (L.t <= 0) {
L.state = "dash";
ev("lanternDash", { x: L.x, y: L.y });
}
} else if (L.state === "dash") {
const x0 = L.x;
const y0 = L.y;
const left = stepTo(L, L.bx, L.by, DASH_V, dt);
const d = toSegment(c.x, c.y, x0, y0, L.x, L.y);
L.near = Math.min(L.near, d);
if (d <= DASH_HIT && grab(round, c, "lurker", k, ev)) {
Object.assign(L, { state: "rest", t: REST_MS });
return round.phase !== "play";
}
if (left <= 0.01) {
if (L.near > DASH_HIT && L.near <= CLOSE_R && round.you.safeMs <= 0) {
act(round, CLOSE_POINTS);
ev("lanternClose", { x: c.x, y: c.y, points: CLOSE_POINTS, by: "lurker" });
}
Object.assign(L, { state: "rest", t: REST_MS });
}
} else if (L.state === "cower") {
// Away from her pool, as far as its route goes.
let far = R.lurker.route[0];
for (const p of R.lurker.route) if (dist(p[0], p[1], R.pool[0], R.pool[1]) > dist(far[0], far[1], R.pool[0], R.pool[1])) far = p;
stepTo(L, far[0], far[1], LURKER_V, dt);
} else if (L.state === "rest") {
L.t -= ms;
if (L.t <= 0) {
L.state = "drift";
// Back to the nearest point of its route.
let bi = 0;
R.lurker.route.forEach(([x, y], i) => {
if (dist(L.x, L.y, x, y) < dist(L.x, L.y, ...R.lurker.route[bi])) bi = i;
});
L.wp = bi;
}
}
keep(L);
if (dist(L.x, L.y, c.x, c.y) <= MEET_R && L.state !== "rest" && L.state !== "cower") meet(c, "lurker", L.x, L.y, ev);
return false;
}
// THE WISPS: guardians circle their shrine and rush a lantern near it; roamers from Mother's pool drift after one. A flare bursts them.
function wisps(round, c, R, ms, noises, k, ev) {
const dt = ms / 1000;
for (const w of c.wisps) {
const spec = R.wisps[w.i];
if (w.state === "gone") continue;
if (w.state === "asleep") {
if (c.lit >= spec.wake) {
Object.assign(w, { state: "roam", x: R.pool[0], y: R.pool[1] });
ev("lanternWispCue", { x: w.x, y: w.y });
}
continue;
}
if (w.state === "popped") {
w.t -= ms;
if (w.t <= 0) {
if (spec.shrine >= 0 && c.shrines[spec.shrine] >= SHRINE_MS) w.state = "gone";
else Object.assign(w, { state: spec.shrine >= 0 ? "guard" : "roam", x: spec.home[0], y: spec.home[1], wp: 0 });
}
continue;
}
const d = dist(w.x, w.y, c.x, c.y);
if (spec.shrine >= 0) {
const [sx, sy] = shrineAt(R, spec.shrine);
const yours = dist(c.x, c.y, sx, sy) <= LEASH;
if (yours && (w.state === "chase" || d <= GUARD_SENSE)) {
w.state = "chase";
stepTo(w, c.x, c.y, WISP_V, dt);
} else {
// Back to its circle, then round it.
const a = spec.phase + (c.clock / 1000) * ORBIT_W;
const ox = sx + Math.cos(a) * ORBIT_R;
const oy = sy + Math.sin(a) * ORBIT_R;
if (w.state === "chase" || w.state === "back") w.state = stepTo(w, ox, oy, WISP_RETURN_V, dt) < 0.5 ? "guard" : "back";
else {
w.x = ox;
w.y = oy;
}
}
} else if (d <= ROAM_SENSE) {
w.state = "chase";
stepTo(w, c.x, c.y, ROAM_CHASE_V, dt);
} else {
w.state = "roam";
patrol(w, spec.route, ROAM_V, dt);
}
keep(w);
cue(c, w, "wisp", ms, ev);
if (w.state === "chase") meet(c, "wisp", w.x, w.y, ev);
if (dist(w.x, w.y, c.x, c.y) <= WISP_CATCH && grab(round, c, "wisp", k, ev)) {
pop(round, c, w, ev, false);
return round.phase !== "play";
}
}
return false;
}
// THE LEECHES: they follow you at the edge of your light and never come into it; the flame out, they bite. A flare scatters them.
function leeches(round, c, R, ms, noises, k, ev) {
const dt = ms / 1000;
const r = lightOf(c);
for (const S of c.leeches) {
const d = dist(S.x, S.y, c.x, c.y);
if (S.state === "scatter") {
S.t -= ms;
if (d > 0.01) stepTo(S, S.x + (S.x - c.x) * 4, S.y + (S.y - c.y) * 4, SCATTER_V, dt);
if (S.t <= 0) S.state = "drift";
} else if (d <= LEECH_SENSE || c.gutter) {
S.state = c.gutter ? "swarm" : "stalk";
if (c.gutter) stepTo(S, c.x, c.y, LEECH_V * 1.4, dt);
else {
// To the light's edge, a little round from where it is (each swarm its own way), never inside.
const a = Math.atan2(S.y - c.y, S.x - c.x) + (S.i % 2 ? 0.35 : -0.35) * dt;
const edge = r + LEECH_EDGE;
if (d < edge) stepTo(S, c.x + Math.cos(a) * edge, c.y + Math.sin(a) * edge, LEECH_V * 1.3, dt);
else stepTo(S, c.x + Math.cos(a) * edge, c.y + Math.sin(a) * edge, LEECH_V, dt);
}
if (d <= r + 3) meet(c, "leech", S.x, S.y, ev);
} else {
S.state = "drift";
patrol(S, R.leeches[S.i].route, LEECH_DRIFT_V, dt);
}
keep(S);
cue(c, S, "leech", ms, ev);
if (c.gutter && dist(S.x, S.y, c.x, c.y) <= LEECH_BITE && grab(round, c, "leech", k, ev)) {
c.oil = OIL_AFTER_BITE;
c.gutter = false;
for (const T of c.leeches) Object.assign(T, { state: "scatter", t: SCATTER_MS });
return round.phase !== "play";
}
}
return false;
}
// THE BOG BODIES: stand still near one and the water boils, then a hand comes up and takes what is within reach.
function bodies(round, c, R, ms, noises, k, ev) {
for (const B of c.bodies) {
const d = dist(B.x, B.y, c.x, c.y);
if (d <= BODY_NOTICE + 2) meet(c, "body", B.x, B.y, ev);
if (B.state === "sunk") {
B.t = d <= BODY_NOTICE && !c.moving ? B.t + ms : 0;
if (B.t >= BODY_STILL_MS) {
Object.assign(B, { state: "rise", t: BODY_RISE_MS });
ev("lanternBodyCue", { x: B.x, y: B.y });
}
} else if (B.state === "rise") {
B.t -= ms;
if (B.t <= 0) Object.assign(B, { state: "up", t: BODY_UP_MS });
} else if (B.state === "up") {
B.t -= ms;
if (d <= BODY_REACH && grab(round, c, "body", k, ev)) {
Object.assign(B, { state: "rest", t: BODY_REST_MS });
return round.phase !== "play";
}
if (B.t <= 0) Object.assign(B, { state: "rest", t: BODY_REST_MS });
} else if (B.state === "rest") {
B.t -= ms;
if (B.t <= 0) Object.assign(B, { state: "sunk", t: 0 });
}
}
return false;
}
// OLD MOTHER BOG: her hand's shadow finds you, stops, and slams; from the third shrine now and then, once risen one after another.
function mother(round, c, R, ms, noises, k, ev) {
const M = c.mother;
const dt = ms / 1000;
if (M.riseT > 0) M.riseT -= ms;
const late = elapsedOf(round) >= MOTHER_LATE_S * 1000;
const awake = M.risen || c.lit >= 3 || late;
if (!awake) return false;
const H = M.hand;
if (!H) {
M.gap = (M.gap || (M.risen ? MOTHER_RISEN_GAP : MOTHER_GAP[Math.min(4, Math.max(3, c.lit))])) - ms;
if (M.gap > 0) return false;
M.gap = 0;
// The shadow falls a little behind where Planny is heading, so a walk carries him out of it.
M.hand = { x: c.x - c.fx * 2, y: c.y - c.fy * 2, state: "track", t: M.risen ? HAND_TRACK_RISEN_MS : HAND_TRACK_MS };
ev("lanternHand", { x: M.hand.x, y: M.hand.y });
meet(c, "mother", c.x, c.y, ev);
return false;
}
H.t -= ms;
if (H.state === "track") {
stepTo(H, c.x, c.y, M.risen ? HAND_RISEN_V : HAND_V, dt);
if (H.t <= 0) Object.assign(H, { state: "lock", t: HAND_LOCK_MS });
} else if (H.state === "lock") {
if (H.t <= 0) {
const d = dist(H.x, H.y, c.x, c.y);
ev("lanternSlam", { x: H.x, y: H.y });
Object.assign(H, { state: "rest", t: HAND_REST_MS });
if (d <= HAND_R) {
if (grab(round, c, "mother", k, ev)) {
H.t = HAND_REST_MS * 3;
return round.phase !== "play";
}
} else if (d <= CLOSE_R && round.you.safeMs <= 0) {
act(round, CLOSE_POINTS);
ev("lanternClose", { x: c.x, y: c.y, points: CLOSE_POINTS, by: "mother" });
}
}
} else if (H.t <= 0) {
M.hand = null;
M.gap = M.risen ? MOTHER_RISEN_GAP : MOTHER_GAP[Math.min(4, Math.max(3, c.lit))];
}
return false;
}
// The held sounds this room wants now, as [id, hum name, level, pitch] (ghoul.js plays them; sounds never touch the round).
export function lanternHums(round) {
const c = mine(round);
if (!c || c.done || round.phase !== "play") return [];
const out = [];
const L = c.lurker;
const d = dist(L.x, L.y, c.x, c.y);
if (L.state !== "rest" && L.state !== "cower" && d < 34) out.push(["ghoul:lurker", "ghoulLanternLurk", (1 - d / 34) ** 1.4 * (L.state === "drift" ? 0.5 : 1), L.state === "aim" ? 1.4 : L.state === "hunt" ? 1.15 : 1]);
if (c.mother.risen) out.push(["ghoul:mother", "ghoulLanternMother", 0.9, 1]);
else if (c.mother.stir >= 3) out.push(["ghoul:mother", "ghoulLanternMother", 0.35, 0.85]);
return out;
}
export const LANTERN = freeze({
id: "lantern",
monsters: MONSTERS,
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
horde: freeze({}),
ride: freeze([ride]),
place: freeze([place]),
});
@@ -0,0 +1,262 @@
// Plan2Code Web Console - ghoul: The Drowned Lantern's own sound effects, merged into ghoul-sfx.js; defines only.
//
// Same shape and rules as ghoul-sfx-hearse.js: `tones` (a `ghoulLantern<Act>` sound for each thing the
// round does, built from the house tone layers, none over 1.2 s with its delay), `hums` (the held sounds the
// room asks for through lanternHums in ghoul-lantern.js: the Lurker near, Mother awake) and `music` (the
// room's theme, `ghoulLanternTheme`, named in ROOM_MUSIC in ghoul.js, the user's pick, Tiptoe plucks).
// Every hunter is heard before it reaches you: the Lurker's groan when it hears you and the rising
// hiss as it lines up its dash, the leeches' dry skitter, the wisps' thin chime, the bog bodies' wet boil, and
// Mother's low thrum as her hand's shadow falls. 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.
export const LANTERN_SFX = {
tones: {
// Step: a board creaking underfoot, the sound the Lurker listens for.
ghoulLanternStep: {
layers: [
{ type: "triangle", from: 190, to: 150, seconds: 0.09, attack: 0.01, gain: 0.35, vibrato: { rate: 30, depth: 0.08 } },
{ type: "brown", seconds: 0.08, attack: 0, gain: 0.3, filter: { type: "lowpass", from: 900, to: 300, q: 2 } },
],
},
// Flare: the lantern blazes up, a whoomp and a bright hiss.
ghoulLanternFlare: {
layers: [
{ type: "noise", seconds: 0.12, attack: 0, gain: 0.6, filter: { type: "highpass", from: 2200, to: 900 } },
{ type: "sine", from: 160, to: 70, seconds: 0.26, attack: 0, gain: 0.7 },
{ type: "noise", seconds: 0.7, attack: 0.04, gain: 0.3, filter: { type: "bandpass", from: 3400, to: 1800, q: 1 } },
],
},
// Sputter: no oil for a flare, a weak cough of flame.
ghoulLanternSputter: {
layers: [
{ type: "noise", seconds: 0.08, attack: 0, gain: 0.35, filter: { type: "bandpass", from: 1200, to: 600, q: 2 } },
{ type: "noise", seconds: 0.08, delay: 0.12, attack: 0, gain: 0.25, filter: { type: "bandpass", from: 1000, to: 500, q: 2 } },
],
},
// Pop: a wisp bursts, a small bright pop and a falling whistle.
ghoulLanternPop: {
layers: [
{ type: "sine", from: 1500, to: 400, seconds: 0.16, attack: 0, gain: 0.4 },
{ type: "noise", seconds: 0.07, attack: 0, gain: 0.45, filter: { type: "highpass", from: 3000, to: 2000 } },
],
},
// Shrine: a wisp shrine takes the flame, a rising three-note chime.
ghoulLanternShrine: {
layers: [
{ type: "triangle", from: 660, to: 660, seconds: 0.2, attack: 0, gain: 0.4 },
{ type: "triangle", from: 880, to: 880, seconds: 0.2, delay: 0.12, attack: 0, gain: 0.4 },
{ type: "triangle", from: 1320, to: 1320, seconds: 0.5, delay: 0.24, attack: 0, gain: 0.42 },
],
},
// Gutter: the oil is out, the flame shrinks with a choke and a sigh.
ghoulLanternGutter: {
layers: [
{ type: "sawtooth", from: 220, to: 70, seconds: 0.6, attack: 0.02, gain: 0.3, filter: { type: "lowpass", from: 1200, to: 200, q: 2 } },
{ type: "noise", seconds: 0.5, attack: 0.05, gain: 0.3, filter: { type: "lowpass", from: 1400, to: 300, q: 1 } },
],
},
// Catch: a hunter has you, a thump, a splash and a drop in the flame.
ghoulLanternCatch: {
layers: [
{ type: "sine", from: 150, to: 45, seconds: 0.3, attack: 0, gain: 0.8 },
{ type: "noise", seconds: 0.4, attack: 0.02, gain: 0.5, filter: { type: "bandpass", from: 1600, to: 400, q: 1.2 } },
{ type: "brown", seconds: 0.5, attack: 0.04, gain: 0.5, filter: { type: "lowpass", from: 500, to: 120, q: 1 } },
],
},
// Finish: into the boat and away, a bright run of notes.
ghoulLanternFinish: {
layers: [
{ type: "triangle", from: 523, to: 523, seconds: 0.18, attack: 0, gain: 0.4 },
{ type: "triangle", from: 659, to: 659, seconds: 0.18, delay: 0.14, attack: 0, gain: 0.4 },
{ type: "triangle", from: 784, to: 784, seconds: 0.18, delay: 0.28, attack: 0, gain: 0.4 },
{ type: "triangle", from: 1047, to: 1047, seconds: 0.6, delay: 0.42, attack: 0, gain: 0.45 },
],
},
// Meet: a hunter's rule shown for the first time, a soft low sting.
ghoulLanternMeet: {
layers: [
{ type: "sine", from: 311, to: 311, seconds: 0.5, attack: 0.02, gain: 0.3 },
{ type: "sine", from: 440, to: 440, seconds: 0.5, attack: 0.02, gain: 0.22 },
],
},
// Close: a dash or a slam that just missed, a quick rushing whoosh.
ghoulLanternClose: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0.05, gain: 0.45, filter: { type: "bandpass", from: 600, to: 2400, q: 1.5 } },
{ type: "sine", from: 700, to: 1100, seconds: 0.2, delay: 0.1, attack: 0.02, gain: 0.2 },
],
},
// The Bog Lurker hears you: a low bubbling groan under the water.
ghoulLanternLurker: {
layers: [
{ type: "sawtooth", from: 46, to: 62, seconds: 0.9, attack: 0.2, gain: 0.6, vibrato: { rate: 7, depth: 0.14 }, filter: { type: "lowpass", from: 220, to: 480, q: 4 } },
{ type: "brown", seconds: 0.8, attack: 0.1, gain: 0.5, filter: { type: "lowpass", from: 600, to: 160, q: 1 } },
],
},
// It lines up its dash: a rising hiss and a growl, the cue to get off the lane.
ghoulLanternAim: {
layers: [
{ type: "noise", seconds: 0.75, attack: 0.5, gain: 0.45, filter: { type: "bandpass", from: 800, to: 3200, q: 2 } },
{ type: "sawtooth", from: 70, to: 110, seconds: 0.75, attack: 0.2, gain: 0.4, filter: { type: "lowpass", from: 300, to: 700, q: 3 } },
],
},
// The dash: a surge of water and a snap of jaws.
ghoulLanternDash: {
layers: [
{ type: "noise", seconds: 0.35, attack: 0, gain: 0.6, filter: { type: "lowpass", from: 2400, to: 500, q: 1 } },
{ type: "square", from: 140, to: 60, seconds: 0.08, delay: 0.18, attack: 0, gain: 0.45, filter: { type: "lowpass", from: 1600, to: 600, q: 1 } },
],
},
// The leeches: a dry rapid skitter, like many small things on wet wood.
ghoulLanternLeech: {
layers: [
{ type: "noise", seconds: 0.5, attack: 0.02, gain: 0.5, filter: { type: "bandpass", from: 5200, to: 3600, q: 4 } },
{ type: "noise", seconds: 0.4, delay: 0.12, attack: 0.02, gain: 0.35, filter: { type: "bandpass", from: 3000, to: 4400, q: 3 } },
],
},
// The wisps: a thin whistling chime that wavers.
ghoulLanternWisp: {
layers: [
{ type: "sine", from: 1760, to: 1480, seconds: 0.8, attack: 0.1, gain: 0.22, vibrato: { rate: 9, depth: 0.06 } },
{ type: "sine", from: 2640, to: 2220, seconds: 0.7, delay: 0.1, attack: 0.1, gain: 0.12, vibrato: { rate: 11, depth: 0.05 } },
],
},
// A bog body stirs: a wet boil, a slow slurp and a gasp of marsh gas.
ghoulLanternBody: {
layers: [
{ type: "brown", seconds: 0.7, attack: 0.1, gain: 0.7, filter: { type: "lowpass", from: 300, to: 900, q: 2 } },
{ type: "sine", from: 120, to: 240, seconds: 0.5, attack: 0.05, gain: 0.4 },
{ type: "noise", seconds: 0.25, delay: 0.5, attack: 0.04, gain: 0.25, filter: { type: "bandpass", from: 700, to: 1500, q: 1.5 } },
],
},
// Mother stirs (the third shrine): a held low chord that swells.
ghoulLanternWake: {
layers: [
{ type: "sawtooth", from: 55, to: 58, seconds: 1.1, attack: 0.5, gain: 0.5, filter: { type: "lowpass", from: 260, to: 520, q: 3 } },
{ type: "sawtooth", from: 58, to: 62, seconds: 1.1, attack: 0.5, gain: 0.4, filter: { type: "lowpass", from: 260, to: 520, q: 3 } },
{ type: "sine", from: 800, to: 760, seconds: 0.9, delay: 0.2, attack: 0.3, gain: 0.12 },
],
},
// She rises (the fifth): water pouring off her, a long gurgling roar.
ghoulLanternRise: {
layers: [
{ type: "brown", seconds: 1.1, attack: 0.1, gain: 0.8, filter: { type: "lowpass", from: 300, to: 1400, q: 1.5 } },
{ type: "sawtooth", from: 40, to: 72, seconds: 1.1, attack: 0.15, gain: 0.5, vibrato: { rate: 5, depth: 0.12 }, filter: { type: "lowpass", from: 300, to: 700, q: 3 } },
{ type: "noise", seconds: 0.8, delay: 0.3, attack: 0.1, gain: 0.3, filter: { type: "bandpass", from: 500, to: 1800, q: 1 } },
],
},
// Her hand's shadow falls: a low thrum from under the water.
ghoulLanternHand: {
layers: [
{ type: "sine", from: 58, to: 52, seconds: 0.7, attack: 0.15, gain: 0.6 },
{ type: "triangle", from: 116, to: 104, seconds: 0.6, attack: 0.15, gain: 0.25 },
],
},
// The slam: a huge wet slap on the water.
ghoulLanternSlam: {
layers: [
{ type: "sine", from: 110, to: 35, seconds: 0.35, attack: 0, gain: 0.85 },
{ type: "noise", seconds: 0.5, attack: 0, gain: 0.6, filter: { type: "lowpass", from: 2600, to: 400, q: 1 } },
{ type: "brown", seconds: 0.7, delay: 0.08, attack: 0.05, gain: 0.45, filter: { type: "lowpass", from: 700, to: 150, q: 1 } },
],
},
},
hums: {
// The Lurker close: a low bubbling growl under the water, louder and higher as it closes and hunts.
ghoulLanternLurk: { parts: [{ type: "sawtooth", freq: 48 }, { type: "square", freq: 24, gain: 0.4 }], noise: { color: "brown", gain: 0.5 }, filter: { type: "lowpass", freq: 300, q: 4, follow: 0.8 }, pulse: { rate: 3, depth: 0.5 }, peak: 0.035 },
// Mother awake: a deep slow breath from the pool, a held dread under everything once she has risen.
ghoulLanternMother: { parts: [{ type: "sawtooth", freq: 36 }, { type: "sine", freq: 54, gain: 0.5 }], noise: { color: "brown", gain: 0.3 }, filter: { type: "lowpass", freq: 220, q: 2, follow: 0.5 }, pulse: { rate: 0.5, depth: 0.6 }, peak: 0.04 },
},
music: {
// The Drowned Lantern: tiptoe plucks. A sparse stealth tiptoe: dry
// marimba plucks that stop and start, a soft footfall kick, a creeping
// triangle bass and a few pluck plinks in the gaps. The footfalls double
// in the sour third part; a high plink and a snap join only near full
// dread.
ghoulLanternTheme: {
bpm: 88,
rush: 20,
voices: {
marimba: { wave: "triangle", gain: 0.3, decay: 0.03, sustain: 0.05 },
pluck: { wave: "pulse", duty: 0.25, gain: 0.08, decay: 0.03, sustain: 0.15, from: 0.4 },
bass: { wave: "triangle", gain: 0.4, decay: 0.06, sustain: 0.5 },
foot: { kit: true, gain: 0.14, from: 0.3 },
tick: { kit: true, gain: 0.06, from: 0.5 },
plink: { wave: "sine", gain: 0.05, decay: 0.05, sustain: 0.1, from: 0.85 },
snap: { kit: true, gain: 0.12, from: 0.85 },
},
patterns: {
A: {
marimba:
"A3 - . . . . E4 - . . C5 - . . . . | F3 - . . . . C4 - . . A4 - . . . . | " +
"D3 - . . . . A3 - . . F4 - . . . . | E3 - . . . . G#4 - . . B4 - . . E5 .",
pluck:
". . . . C5 . . . . . . . . E5 . . | . . . . . . . C5 . . . . . C5 . . | " +
". . . . D5 . . . . . . . . A4 . . | . . . . . . . G#5 . . . . . B4 . .",
bass:
"A2 - . . . . E3 . A2 - . . . . A2 . | F2 - . . . . C3 . F2 - . . . . F2 . | " +
"D2 - . . . . A2 . D2 - . . . . D2 . | E2 - . . . . B2 . E2 - . . . . G#2 .",
foot:
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . . | " +
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . .",
tick:
". . . . h . . . . . . . h . . . | . . . . h . . . . . . . h . . . | " +
". . . . h . . . . . . . h . . . | . . . . h . . . . . . . h . . .",
plink:
". . . E7 . . . . . . . . . . . . | . . . . . . . . . C7 . . . . . . | " +
". . . A6 . . . . . . . . . . . . | . . . . . . . . . B6 . . . . . .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .",
},
B: {
marimba:
"D3 - . . . . A3 - . . F4 - . A4 . . | A3 - . . . . E4 - . . C5 - . E5 . . | " +
"F3 - . . . . C4 - . . A4 - . C5 . . | E3 - . . . . G#4 - . . B4 - . . E5 .",
pluck:
". . . . F4 . . . . . . . . A4 . . | . . . . . . . E5 . . . . . E5 . . | " +
". . . . F5 . . . . . . . . C5 . . | . . . . . . . G#5 . . . . . B4 . .",
bass:
"D2 - . . . . A2 . D2 - . . . . D2 . | A2 - . . . . E3 . A2 - . . . . A2 . | " +
"F2 - . . . . C3 . F2 - . . . . F2 . | E2 - . . . . B2 . E2 - . . . . G#2 .",
foot:
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . . | " +
"k . . . . . . . k . . . . . . . | k . . . . . . . k . . . . . . .",
tick:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
plink:
". . . A6 . . . . . . . . . . . . | . . . . . . . . . E7 . . . . . . | " +
". . . C7 . . . . . . . . . . . . | . . . . . . . . . B6 . . . . . .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .",
},
C: {
marimba:
"A3 - . . . . E4 - . . C5 - . . . . | A#3 - . . . . F4 - . . D5 - . . . . | " +
"A3 - . . . . E4 - . . C5 - . . . . | E3 - . . . . G#4 - . . B4 - . . E5 .",
pluck:
". . . . C5 . . . . . . . . E5 . . | . . . . . . . F5 . . . . . F5 . . | " +
". . . . A5 . . . . . . . . E5 . . | . . . . . . . G#5 . . . . . B4 . .",
bass:
"A2 - . . . . E3 . A2 - . . . . A2 . | A#2 - . . . . F3 . A#2 - . . . . A#2 . | " +
"A2 - . . . . E3 . A2 - . . . . A2 . | E2 - . . . . B2 . E2 - . . . . G#2 .",
foot:
"k . . k . . . . k . . k . . . . | k . . k . . . . k . . k . . . . | " +
"k . . k . . . . k . . k . . . . | k . . k . . . . k . . k . . . .",
tick:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
plink:
". . . E7 . . . . . . . . . . . . | . . . . . . . . . F7 . . . . . . | " +
". . . E7 . . . . . . . . . . . . | . . . . . . . . . B6 . . . . . .",
snap:
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . . | " +
". . . . s . . . . . . . s . . . | . . . . s . . . . . . . s . . .",
},
},
order: ["A", "B", "A", "C", "B"],
},
},
};
@@ -59,7 +59,7 @@
// "idle"|"warn"|"snap"|"sink"|"spent"|"broken", t }] }, `round.you` (`state`, `vy`, `ducking`),
// the events in EVENTS.
import { linesAt, linesOf, trackY } from "./ghoul-cart.js";
import { linesAt, linesOf, trackY } from "../cart/ghoul-cart.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
@@ -64,7 +64,7 @@
// pops: [{ state "down"|"up"|"hid"|"broken", t }], icicles: [broken], sweet },
// `round.you` (`state`, `vy`, `ducking`), the events in EVENTS.
import { linesAt, linesOf, slopeOf, trackY } from "./ghoul-cart.js";
import { linesAt, linesOf, slopeOf, trackY } from "../cart/ghoul-cart.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
@@ -49,7 +49,7 @@
// [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";
import { linesAt, linesOf, slopeOf, trackY } from "../cart/ghoul-cart.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
@@ -17,7 +17,7 @@
// - Planny: `you.state`, `you.vy`, `you.ducking`, `you.x`, `you.y`.
// - events leave short-lived bits in the view's `fx` (`wagonBits`, `wagonLand`).
import { ANSWER_COLORS, TELEGRAPH_ALPHA } from "./ghoul-sled-draw.js";
import { ANSWER_COLORS, TELEGRAPH_ALPHA } from "../sled/ghoul-sled-draw.js";
import { CATCH_GAP, GAP_MAX, PANIC_ON, REACH, THROW_MEET, WAGON_V, WIND_MS } from "./ghoul-wagon.js";
const freeze = (o) => Object.freeze(o);
@@ -719,7 +719,7 @@ export function wagonArt(d) {
void close;
}
// A moonhound at a gallop, running right: lean grey, long legs, eyes that glow.
// A moonhound at a gallop, running right: lean gray, long legs, eyes that glow.
function hound(ctx, x, base, i, clock) {
const ph = clock / 55 + i * 2.1;
const bob = Math.sin(ph) * 0.35;
@@ -64,7 +64,7 @@
// 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";
import { linesAt, linesOf, slopeOf, trackY } from "../cart/ghoul-cart.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
@@ -11,31 +11,31 @@
// below after the house's, the way ghoul.js merges its stage PACKS. Those are
// the only imports.
import { GRAVEYARD_SFX } from "./ghoul-sfx-graveyard.js";
import { GROUNDS_SFX } from "./ghoul-sfx-grounds.js";
import { CHAPEL_SFX } from "./ghoul-sfx-chapel.js";
import { SANATORIUM_SFX } from "./ghoul-sfx-sanatorium.js";
import { VILLAGE_SFX } from "./ghoul-sfx-village.js";
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";
import { GRAVEYARD_SFX } from "../stages/graveyard/ghoul-sfx-graveyard.js";
import { GROUNDS_SFX } from "../stages/grounds/ghoul-sfx-grounds.js";
import { CHAPEL_SFX } from "../stages/chapel/ghoul-sfx-chapel.js";
import { SANATORIUM_SFX } from "../stages/sanatorium/ghoul-sfx-sanatorium.js";
import { VILLAGE_SFX } from "../stages/village/ghoul-sfx-village.js";
import { MINE_SFX } from "../stages/mine/ghoul-sfx-mine.js";
import { CARNIVAL_SFX } from "../stages/carnival/ghoul-sfx-carnival.js";
import { FROZEN_SFX } from "../stages/frozen/ghoul-sfx-frozen.js";
import { SLED_SFX } from "../rides/sled/ghoul-sfx-sled.js";
import { BANISTER_SFX } from "../rides/banister/ghoul-sfx-banister.js";
import { HEARSE_SFX } from "../rides/hearse/ghoul-sfx-hearse.js";
import { BOG_SFX } from "../stages/bog/ghoul-sfx-bog.js";
import { LANTERN_SFX } from "../rides/lantern/ghoul-sfx-lantern.js";
import { GURNEY_SFX } from "../rides/gurney/ghoul-sfx-gurney.js";
import { PEW_SFX } from "../rides/pew/ghoul-sfx-pew.js";
import { MOWER_SFX } from "../rides/mower/ghoul-sfx-mower.js";
import { WAGON_SFX } from "../rides/wagon/ghoul-sfx-wagon.js";
import { TRAY_SFX } from "../rides/tray/ghoul-sfx-tray.js";
import { ARMS_SFX } from "../arms/ghoul-sfx-arms.js";
import { RIDE_SFX } from "../rides/dark-ride/ghoul-sfx-ride.js";
import { STORY_SFX } from "../story/ghoul-sfx-story.js";
// Each stage's sounds and tracks, by stage: `tones`, `hums` and `music` as
// below, any of them left out.
const STAGE_SFX = Object.freeze([GRAVEYARD_SFX, GROUNDS_SFX, CHAPEL_SFX, SANATORIUM_SFX, VILLAGE_SFX, MINE_SFX, CARNIVAL_SFX, FROZEN_SFX,SLED_SFX, HEARSE_SFX, BOG_SFX, BOGBOAT_SFX, GURNEY_SFX, PEW_SFX, MOWER_SFX, WAGON_SFX, TRAY_SFX, ARMS_SFX, RIDE_SFX, BANISTER_SFX, STORY_SFX]);
const STAGE_SFX = Object.freeze([GRAVEYARD_SFX, GROUNDS_SFX, CHAPEL_SFX, SANATORIUM_SFX, VILLAGE_SFX, MINE_SFX, CARNIVAL_SFX, FROZEN_SFX,SLED_SFX, HEARSE_SFX, BOG_SFX, LANTERN_SFX, GURNEY_SFX, PEW_SFX, MOWER_SFX, WAGON_SFX, TRAY_SFX, ARMS_SFX, RIDE_SFX, BANISTER_SFX, STORY_SFX]);
const fromStages = (key) => Object.assign({}, ...STAGE_SFX.map((st) => st[key] || {}));
// One second of the laugh track (part 0, 1 or 2): every event is placed on the
@@ -1,4 +1,4 @@
// Plan2Code Web Console - Ghoul Rush's Gallows Bog stage, its drawing: the rooms' looks out on the night swamp (sagging boardwalk planks over black water, mud sheen in the dips, moss veils and fireflies in the hollow, the hag's stilt house lit warm, the open water of her arena), its monsters (a lurker's eyes, a leech swarm, a will-o'-wisp, a bog body), Old Mother Bog and her cauldron, the mud wave and the muck patches, the Stilt Boots' and Harpoon's badges, and what its events look and sound like.
// Plan2Code Web Console - Ghoul Rush's Gallows Bog stage, its drawing: the rooms' looks out on the night swamp (sagging boardwalk planks over black water, mud sheen in the dips, moss veils and fireflies in the hollow, the hag's stilt house lit warm, the open water of her arena), its monsters (a lurker's eyes, a leech swarm, a will-o'-wisp, a bog body), Old Mother Bog and her cauldron in a pose for every move, the mud wave, the muck patches, the bog hands and the tide, the Stilt Boots' and Harpoon's badges, and what its events look and sound like.
//
// ghoul-draw.js plugs it in. LOOKS, VOICES, LOSE_WORDS and LOSE_SOUNDS are
// plain data; bogArt(d) takes ghoul-draw.js's own drawing helpers (`d`:
@@ -15,7 +15,7 @@
// (the sound page's vote lands in Phase 5); the acts each event asks for
// are already named so the picks drop in.
import { BOG_RISE_MS, LURKER_SINK_MS, MOTHER_SINK_MS, MOTHER_WIND_MS, MUCK_LAND_MS, RESURFACE_MS, SNAP_MS, SPIT_WIND_MS, WISP_REKINDLE_MS } from "./ghoul-bog.js";
import { BOG_RISE_MS, BROOD_WIND_MS, CALL_WIND_MS, HAND_UP_MS, LANTERN_WIND_MS, LURKER_SINK_MS, MOTHER_SINK_MS, MOTHER_WIND_MS, MUCK_LAND_MS, PULL_WIND_MS, RESURFACE_MS, SHELL_WIND_MS, SNAP_MS, SPIT_WIND_MS, STAGGER_MS, STOMP_WIND_MS, SURGE_SINK, SURGE_WIND_MS, TIDE_MS, TIDE_WARN_MS, WISP_REKINDLE_MS } from "./ghoul-bog.js";
const freeze = (o) => Object.freeze(o);
const TAU = Math.PI * 2;
@@ -42,12 +42,16 @@ export const VOICES = freeze({
leech: freeze({ appear: "ghoulLeechAppear", latch: "ghoulLeechLatch", hurt: "ghoulLeechHurt", die: "ghoulLeechDie" }),
wisp: freeze({ appear: "ghoulWispAppear", out: "ghoulWispOut", relight: "ghoulWispRelight", on: "ghoulWispOn", hurt: "ghoulWispHurt", die: "ghoulWispDie" }),
bogbody: freeze({ appear: "ghoulBogbodyAppear", rise: "ghoulBogbodyRise", hurt: "ghoulBogbodyHurt", die: "ghoulBogbodyDie" }),
motherbog: freeze({ wake: "ghoulMotherWake", wind: "ghoulMotherWind", wave: "ghoulMotherWave", spitWind: "ghoulMotherSpitWind", spit: "ghoulMotherSpit", open: "ghoulMotherOpen", sink: "ghoulMotherSink", bubble: "ghoulMotherBubble", rise: "ghoulMotherRise", muck: "ghoulMotherMuck", hurt: "ghoulMotherHurt", weak: "ghoulMotherWeak", die: "ghoulMotherDie" }),
motherbog: freeze({ wake: "ghoulMotherWake", wind: "ghoulMotherWind", wave: "ghoulMotherWave", spitWind: "ghoulMotherSpitWind", spit: "ghoulMotherSpit", open: "ghoulMotherOpen", sink: "ghoulMotherSink", bubble: "ghoulMotherBubble", rise: "ghoulMotherRise", muck: "ghoulMotherMuck", hurt: "ghoulMotherHurt", weak: "ghoulMotherWeak", die: "ghoulMotherDie",
handsWind: "ghoulMotherHandsWind", handsUp: "ghoulMotherHandsUp", surgeWind: "ghoulMotherSurgeWind", surge: "ghoulMotherSurge", shellWind: "ghoulMotherShellWind", chip: "ghoulMotherChip", shellBreak: "ghoulMotherShellBreak", feed: "ghoulMotherFeed",
broodWind: "ghoulMotherBroodWind", pour: "ghoulMotherPour", stompWind: "ghoulMotherStompWind", leap: "ghoulMotherLeap", slam: "ghoulMotherSlam", tideWarn: "ghoulMotherTideWarn", tide: "ghoulMotherTide", pullWind: "ghoulMotherPullWind", pull: "ghoulMotherPull",
callWind: "ghoulMotherCallWind", call: "ghoulMotherCall", lanternWind: "ghoulMotherLanternWind", lantern: "ghoulMotherLantern", combo: "ghoulMotherCombo" }),
});
// The words on a life lost to each new cause, and the sound beside the
// crash: the lurker's snap, a leech latch, the wisp's cold light, a bog
// body's grip, the mud wave, a muck patch and the hag's own touch.
export const LOSE_WORDS = freeze({ lurker: "Snapped", leeches: "Drained", wisp: "Misled", bogbody: "Dragged down", mudwave: "Swamped", muck: "Scalded", motherbog: "Stewed" });
// body's grip, the mud wave, a muck patch, a bog hand, the tide and the
// hag's own touch.
export const LOSE_WORDS = freeze({ lurker: "Snapped", leeches: "Drained", wisp: "Misled", bogbody: "Dragged down", mudwave: "Swamped", muck: "Scalded", boghand: "Grabbed", tide: "Drowned", motherbog: "Stewed" });
export const LOSE_SOUNDS = freeze({
lurker: ["crunch", 0.55, 0.8],
leeches: ["squish", 0.5, 0.7],
@@ -55,6 +59,8 @@ export const LOSE_SOUNDS = freeze({
bogbody: ["squish", 0.5, 0.8],
mudwave: ["thud", 0.6, 0.7],
muck: ["ghoulSizzle", 0.55, 0.7],
boghand: ["squish", 0.55, 0.55],
tide: ["splash", 0.6, 0.5],
motherbog: ["splat", 0.6, 0.5],
});
@@ -717,7 +723,7 @@ export function bogArt(d) {
}
// The will-o'-wisp: `bright` a flame-licked orb of cold light, pulsing,
// shedding a spark or two; `dim` a grey ember sinking; `rekindle` a glow
// shedding a spark or two; `dim` a gray ember sinking; `rekindle` a glow
// gathering where it will burn again, brighter the nearer it is.
function wisp(ctx, v, m, x, y, t, flash) {
const cy = y - m.h / 2;
@@ -912,17 +918,91 @@ export function bogArt(d) {
}
}
// How far into a timed act she is, 0 to 1 (1 once it is over or untimed).
const into = (b, ms) => (Number.isFinite(b.wait) && b.wait > 0 ? clamp(1 - b.wait / ms, 0, 1) : 1);
// What she shows on the field away from her body: the boiling mud where the
// drowned will climb out, and the shadow where a stomp comes down.
function motherMarks(ctx, v, b) {
const { g } = v;
const t = v.clock;
const fy = g.FIELD_H - (b.floor ?? b.home ?? b.y);
if (b.act === "callWind") {
const p = into(b, CALL_WIND_MS);
for (const [i, x] of (b.callXs || []).entries()) {
ctx.fillStyle = MUD_LIT;
ctx.globalAlpha = 0.35 + p * 0.4;
ellipse(ctx, x, fy - 0.1, 1.6 + p * 0.8, 0.4 + p * 0.2);
ctx.fill();
ctx.fillStyle = CAULDRON_LIT;
for (let k = 0; k < 5; k++) {
const q = (t / 380 + k / 5 + i * 0.3) % 1;
ctx.globalAlpha = (0.9 - q * 0.8) * (0.4 + p * 0.6);
circle(ctx, x - 1.2 + ((k * 37) % 25) / 10, fy - 0.3 - q * (1.4 + p * 1.6), 0.18 + 0.2 * (1 - q));
ctx.fill();
}
// A hand already clawing at the surface near the end.
if (p > 0.6) {
ctx.globalAlpha = (p - 0.6) * 2.5;
ctx.strokeStyle = BOGSKIN_LIT;
ctx.lineWidth = 0.3;
for (const f of [-0.4, 0, 0.4]) line(ctx, x + f, fy - 0.1, x + f * 1.4, fy - 0.6 - (p - 0.6) * 2);
}
ctx.globalAlpha = 1;
}
}
if (b.act === "pull" || b.act === "pullWind") {
// The undertow: streaks along the planks running in to her feet.
const p = b.act === "pull" ? 1 : into(b, PULL_WIND_MS);
ctx.strokeStyle = "#9ac8b8";
ctx.lineWidth = 0.18;
for (const side of [-1, 1]) {
for (let k = 0; k < 7; k++) {
const q = (t / (b.act === "pull" ? 500 : 900) + k / 7) % 1;
const dx = side * (b.w * 0.6 + (1 - q) * 22);
ctx.globalAlpha = p * 0.7 * Math.sin(q * Math.PI);
line(ctx, b.x + dx, fy - 0.25 - (k % 3) * 0.18, b.x + dx - side * 1.6, fy - 0.25 - (k % 3) * 0.18);
}
}
ctx.globalAlpha = 1;
}
if ((b.act === "stompWind" || b.act === "stompAir") && b.landX !== undefined) {
// The shadow darkens and the ring tightens as she comes down.
const p = b.act === "stompAir" ? 0.4 + 0.6 * clamp((b.airMs || 0) / 800, 0, 1) : 0.4 * into(b, STOMP_WIND_MS);
ctx.fillStyle = "#000000";
ctx.globalAlpha = 0.35 + p * 0.45;
ellipse(ctx, b.landX, fy - 0.05, b.w * (0.4 + p * 0.25), 0.45);
ctx.fill();
ctx.strokeStyle = DANGER;
ctx.lineWidth = 0.25;
ctx.globalAlpha = 0.5 + 0.5 * Math.abs(Math.sin(t / 110));
ellipse(ctx, b.landX, fy - 0.05, b.w * (1.1 - p * 0.45), 0.7 - p * 0.2);
ctx.stroke();
ctx.globalAlpha = 1;
}
}
// Old Mother Bog herself, feet at (b.x, y): a stooping hag of mud and
// reed, her cauldron beside her. `idle` she hunches over it, drifting;
// `wind` she throws both arms wide to pull the mud wave up; `rest` she
// sags, the cauldron cracking open late in it; `throwWind` she leans in
// to spit; `sink` she is going down in a swirl, `under` only her bubbles
// remain, `resurface` she is coming up wet.
// reed, her cauldron beside her, in a pose for every move so each one
// reads before it lands. `idle` she hunches over the pot, drifting; `wind`
// she throws both arms wide to pull the mud wave up; `rest` she sags, the
// pot cracking open late in it; `throwWind` she leans in to spit; `hands`
// she is bent double, both arms down through the planks; `surgeWind` she
// crouches behind a growing bow wave, `surge` she charges waist deep;
// `shellWind` mud climbs her, `shell` she is a cracked mud dome with one
// eye in a slit, `stagger` the shell is in pieces and she reels; `broodWind`
// she tips the pot with leeches spilling; `stompWind` she crouches deep,
// `stompAir` she is up with her cloak flared; `tideWind`/`tideHold` both
// arms high, green at her palms; `pullWind`/`pull` she stirs the water with
// her ladle, a whirlpool at her feet; `callWind` her palms up over boiling
// mud; `lanternWind` a lantern held high. `sink`, `under` and `resurface`
// are the dive. Her eye flares red before a combo.
function motherbog(ctx, v, b) {
const { g } = v;
const t = v.clock;
const flash = b.hurt > 0;
const d = b.dir || 1;
motherMarks(ctx, v, b);
// Under the water there is no hag to draw: `sink` shows the swirl where
// she went down, `under` the bubbles over the spot she will rise.
if (b.act === "under") {
@@ -955,7 +1035,7 @@ export function bogArt(d) {
ctx.stroke();
ctx.globalAlpha = 1;
// The last of her hat going under.
const p = b.wait > 0 && Number.isFinite(b.wait) ? clamp(1 - b.wait / MOTHER_SINK_MS, 0, 1) : 1;
const p = into(b, MOTHER_SINK_MS);
ctx.fillStyle = flash ? FLASH : HAG_DARK;
ctx.globalAlpha = 1 - p;
ctx.beginPath();
@@ -969,16 +1049,41 @@ export function bogArt(d) {
}
const x = b.x;
const y = g.FIELD_H - b.y;
const floorY = g.FIELD_H - (b.floor ?? b.home ?? b.y);
const C = (c) => (flash ? FLASH : c);
const resurface = b.act === "resurface" && Number.isFinite(b.wait) ? clamp(b.wait / RESURFACE_MS, 0, 1) : 0;
const wind = b.act === "wind" && Number.isFinite(b.wait) ? clamp(1 - b.wait / MOTHER_WIND_MS, 0, 1) : 0;
const throwP = b.act === "throwWind" && Number.isFinite(b.wait) ? clamp(1 - b.wait / SPIT_WIND_MS, 0, 1) : 0;
const act = b.act;
const resurface = act === "resurface" && Number.isFinite(b.wait) ? clamp(b.wait / RESURFACE_MS, 0, 1) : 0;
const wind = act === "wind" ? into(b, MOTHER_WIND_MS) : 0;
const throwP = act === "throwWind" ? into(b, SPIT_WIND_MS) : 0;
const surgeP = act === "surgeWind" ? into(b, SURGE_WIND_MS) : 0;
const shellP = act === "shellWind" ? into(b, SHELL_WIND_MS) : act === "shell" ? 1 : 0;
const stompP = act === "stompWind" ? into(b, STOMP_WIND_MS) : 0;
const broodP = act === "broodWind" ? into(b, BROOD_WIND_MS) : 0;
const staggerP = act === "stagger" ? into(b, STAGGER_MS) : 0;
const surging = act === "surge";
const breathe = Math.sin(t / 800);
// Waist deep in the charge: only what is above the boards shows, with a
// bow wave of mud and water in front and a wake behind.
if (surging) {
ctx.fillStyle = WATER_SHEEN;
ctx.globalAlpha = 0.7;
ellipse(ctx, x - d * 3.5, floorY + 0.1, 3.6, 0.5);
ctx.fill();
ctx.globalAlpha = 1;
ctx.save();
ctx.beginPath();
ctx.rect(x - b.w * 2, floorY - b.h * 2, b.w * 4, b.h * 2);
ctx.clip();
}
ctx.save();
ctx.translate(x, y);
ctx.scale(d, 1);
ctx.translate(0, resurface * b.h * 0.8);
ctx.scale(1, 1 - resurface * 0.9);
// Crouches: the surge's and the stomp's wind-ups squash her down.
const squash = surgeP * 0.22 + stompP * 0.3;
if (squash > 0) ctx.scale(1 + squash * 0.3, 1 - squash);
if (act === "stompAir") ctx.scale(0.92, 1.08);
// Rising: a ring and water sheeting off her.
if (resurface > 0) {
ctx.strokeStyle = WATER_SHEEN;
@@ -986,19 +1091,41 @@ export function bogArt(d) {
ellipse(ctx, 0, 0.2, b.w * 0.62, 0.8);
ctx.stroke();
}
// The cauldron on her far side, close enough to tend.
cauldron(ctx, v, b.w * 0.5 + 1.6, 0, b.lit, t, flash);
// The cauldron beside her, close enough to tend (tipped toward you for
// the brood, left behind for a charge or a leap).
if (!surging && act !== "stompAir" && act !== "surgeWind") {
ctx.save();
const tip = act === "broodWind" ? broodP * 0.9 : 0;
ctx.translate(b.w * 0.5 + 1.6, 0);
ctx.rotate(tip);
cauldron(ctx, v, 0, 0, b.lit, t, flash);
if (tip > 0.2) {
// Leeches slopping over the rim.
ctx.fillStyle = C(LEECH);
for (let k = 0; k < 4; k++) {
const q = (t / 300 + k / 4) % 1;
ellipse(ctx, 1.2 + q * 1.4, -2.9 + q * 2.4, 0.5, 0.22, 0.6);
ctx.fill();
}
}
ctx.restore();
}
ctx.save();
ctx.rotate((b.act === "rest" ? 0.05 : 0.02) * Math.sin(t / 900));
// The hag's cloak of mud and reed, a humped stoop.
const hunch = b.act === "rest" ? 0.12 : 0;
// Lean: forward for the hands, the spit and the surge; back as she reels.
const lean = act === "hands" ? 0.55 : surging ? 0.35 : act === "surgeWind" ? 0.25 * surgeP : act === "throwWind" ? 0.1 : act === "stagger" ? -0.18 * Math.sin(t / 150) - 0.1 : 0;
ctx.translate(0, -b.h * 0.2);
ctx.rotate(lean + (act === "rest" ? 0.05 : 0.02) * Math.sin(t / 900));
ctx.translate(0, b.h * 0.2);
// The hag's cloak of mud and reed, a humped stoop (flared in the air).
const hunch = act === "rest" || act === "stagger" ? 0.12 : 0;
const flare = act === "stompAir" ? 0.25 : 0;
ctx.fillStyle = C(HAG);
ctx.beginPath();
ctx.moveTo(-b.w * 0.42, 0);
ctx.moveTo(-b.w * (0.42 + flare), 0);
ctx.quadraticCurveTo(-b.w * 0.5, -b.h * 0.4, -b.w * 0.3, -b.h * (0.62 - hunch));
ctx.quadraticCurveTo(-b.w * 0.16, -b.h * (0.8 - hunch), 0, -b.h * (0.82 - hunch));
ctx.quadraticCurveTo(b.w * 0.3, -b.h * (0.8 - hunch), b.w * 0.42, -b.h * 0.42);
ctx.quadraticCurveTo(b.w * 0.5, -b.h * 0.2, b.w * 0.44, 0);
ctx.quadraticCurveTo(b.w * 0.5, -b.h * 0.2, b.w * (0.44 + flare), 0);
ctx.closePath();
ctx.fill();
// Mud plates and reed fringes over the cloak.
@@ -1014,38 +1141,87 @@ export function bogArt(d) {
const l = 1 + (hash(k * 13, 5) % 3) * 0.5;
line(ctx, fx, -0.4 - (k % 2) * 0.5, fx + (hash(k, 3) % 3 - 1) * 0.4, -0.4 - (k % 2) * 0.5 + l);
}
// Her arms: thrown wide for the wind, raised over the cauldron for the
// spit, hanging long otherwise.
// Her arms, by move.
const sh = -b.h * 0.62;
ctx.strokeStyle = C(HAG_DARK);
ctx.lineWidth = 0.7;
if (b.act === "wind") {
if (act === "wind") {
const spread = wind * 1.9;
line(ctx, -0.5, -b.h * 0.62, -1.4 - spread, -b.h * 0.62 - spread * 0.8);
line(ctx, 0.5, -b.h * 0.62, 1.4 + spread, -b.h * 0.62 - spread * 0.8);
line(ctx, -0.5, sh, -1.4 - spread, sh - spread * 0.8);
line(ctx, 0.5, sh, 1.4 + spread, sh - spread * 0.8);
// Mud gathered over her head, growing as she pulls.
ctx.fillStyle = MUD_LIT;
circle(ctx, 0, -b.h * 0.62 - spread * 1.6 - 0.8, 0.6 + wind * 1);
circle(ctx, 0, sh - spread * 1.6 - 0.8, 0.6 + wind * 1);
ctx.fill();
ctx.fillStyle = MUD;
circle(ctx, 0, -b.h * 0.62 - spread * 1.6 - 0.8, 0.42 + wind * 0.75);
circle(ctx, 0, sh - spread * 1.6 - 0.8, 0.42 + wind * 0.75);
ctx.fill();
ctx.fillStyle = "#8a7448";
ctx.globalAlpha = 0.8;
circle(ctx, -0.25, -b.h * 0.62 - spread * 1.6 - 1.15, 0.2 + wind * 0.25);
circle(ctx, -0.25, sh - spread * 1.6 - 1.15, 0.2 + wind * 0.25);
ctx.fill();
ctx.globalAlpha = 1;
} else if (b.act === "throwWind") {
line(ctx, -0.5, -b.h * 0.62, -1.2, -b.h * 0.5);
line(ctx, 0.5, -b.h * 0.62, 1.2 + throwP * 1.2, -b.h * 0.68 - throwP * 1.4);
} else if (act === "throwWind") {
line(ctx, -0.5, sh, -1.2, -b.h * 0.5);
line(ctx, 0.5, sh, 1.2 + throwP * 1.2, -b.h * 0.68 - throwP * 1.4);
// The drip of coming spit at her lip.
ctx.fillStyle = CAULDRON_LIT;
ctx.globalAlpha = 0.7;
circle(ctx, 1.9 + throwP * 0.6, -b.h * 0.72 - throwP * 1.6, 0.22 + throwP * 0.2);
ctx.fill();
ctx.globalAlpha = 1;
} else if (act === "hands") {
// Drawn after the lean (below): both arms reaching down into the boards.
} else if (act === "tideWind" || act === "tideHold" || act === "callWind") {
// Arms up: high over her head for the tide, palms up for the drowned.
const high = act === "callWind" ? 0.6 : 1;
const lift = act === "tideWind" ? into(b, TIDE_WARN_MS) : 1;
const hy = sh - (1.2 + lift * 2.4) * high;
line(ctx, -0.5, sh, -1.8, hy);
line(ctx, 0.5, sh, 1.8, hy);
halo(ctx, -1.8, hy - 0.2, 1.4, CAULDRON_LIT, 0.6);
halo(ctx, 1.8, hy - 0.2, 1.4, CAULDRON_LIT, 0.6);
} else if (act === "pullWind" || act === "pull") {
// Her ladle down in the water, stirring.
const stir = Math.sin(t / (act === "pull" ? 120 : 200));
line(ctx, -0.5, sh, -1.1, -b.h * 0.3);
ctx.lineWidth = 0.7;
line(ctx, 0.5, sh, 1.5 + stir * 0.6, -b.h * 0.25);
ctx.strokeStyle = C("#6a5a3a");
ctx.lineWidth = 0.3;
line(ctx, 1.5 + stir * 0.6, -b.h * 0.25, 2.6 + stir * 1.2, 0.5);
} else if (act === "lanternWind") {
// A lantern held high on a crooked pole.
const p = into(b, LANTERN_WIND_MS);
line(ctx, 0.5, sh, -0.6, sh - 2 - p);
line(ctx, -0.5, sh, -1.1, -b.h * 0.3);
ctx.strokeStyle = C("#5a4a2a");
ctx.lineWidth = 0.25;
line(ctx, -0.6, sh - 2 - p, -0.6, sh - 4.2 - p);
ctx.fillStyle = WISP;
ctx.globalAlpha = 0.6 + 0.4 * p;
roundRect(ctx, -1.1, sh - 4.2 - p, 1, 1.2, 0.25);
ctx.fill();
ctx.globalAlpha = 1;
halo(ctx, -0.6, sh - 3.6 - p, 2.5 + p * 2, WISP, 0.5 + p * 0.4);
} else if (act === "stompAir") {
line(ctx, -0.5, sh, -1.8, sh - 1.8);
line(ctx, 0.5, sh, 1.8, sh - 1.8);
} else if (act === "broodWind") {
// Both hands on the pot, shoving it over.
line(ctx, -0.3, sh, 2.6, -2.6);
line(ctx, 0.6, sh, 2.9, -1.8);
} else if (act === "stagger") {
line(ctx, -0.5, sh, -2, sh + 0.6 + Math.sin(t / 90) * 0.4);
line(ctx, 0.5, sh, 2, sh + 0.6 - Math.sin(t / 90) * 0.4);
} else if (act === "shellWind") {
// Scooping mud up over her shoulders.
const s = Math.sin(shellP * Math.PI * 3);
line(ctx, -0.5, sh, -1.6, sh + 1.5 - s * 1.5);
line(ctx, 0.5, sh, 1.6, sh + 1.5 - s * 1.5);
} else {
line(ctx, -0.5, -b.h * 0.62, -1.1, -b.h * 0.3 - breathe * 0.2);
line(ctx, 0.5, -b.h * 0.62, 1.15, -b.h * 0.3 + breathe * 0.2);
line(ctx, -0.5, sh, -1.1, -b.h * 0.3 - breathe * 0.2);
line(ctx, 0.5, sh, 1.15, -b.h * 0.3 + breathe * 0.2);
}
// Her head: a long chin, one good eye, a wisp of hair, her pointed hat
// gone soft with wet.
@@ -1073,14 +1249,265 @@ export function bogArt(d) {
ctx.fillStyle = C(HAG_LIT);
circle(ctx, 1.28, headY + 0.75, 0.12);
ctx.fill();
// The mud shell: climbing her as she slaps it on, a full cracked dome
// once up, the cracks spreading as your bolts chip it.
if (shellP > 0) {
const top = -b.h * 0.98 * shellP;
ctx.fillStyle = C("#3a2e1a");
ctx.beginPath();
ctx.moveTo(-b.w * 0.55, 0.2);
ctx.quadraticCurveTo(-b.w * 0.62, top * 0.6, -b.w * 0.3, top * 0.92);
ctx.quadraticCurveTo(0, top * 1.06, b.w * 0.3, top * 0.92);
ctx.quadraticCurveTo(b.w * 0.62, top * 0.6, b.w * 0.55, 0.2);
ctx.closePath();
ctx.fill();
ctx.fillStyle = C(MUD_LIT);
for (const [px, py, s] of [[-1.8, 0.25, 0.9], [0.2, 0.42, 1], [1.9, 0.3, 0.8], [-0.9, 0.7, 0.7], [1, 0.75, 0.7]]) {
if (py > shellP) continue;
ellipse(ctx, px, top * py * 1.05, s, s * 0.5, 0.3);
ctx.fill();
}
if (act === "shell") {
// The slit she watches through, and the cracks.
const broken = b.shellMax ? 1 - (b.shell || 0) / b.shellMax : 0;
ctx.fillStyle = "#0a0804";
roundRect(ctx, -0.6, headY - 0.35, 2.2, 0.7, 0.3);
ctx.fill();
ctx.strokeStyle = CAULDRON_LIT;
ctx.lineWidth = 0.18;
ctx.globalAlpha = 0.4 + broken * 0.6;
const cracks = Math.ceil(broken * 7);
for (let k = 0; k < cracks; k++) {
const cx = -b.w * 0.4 + ((k * 29) % 10) / 10 * b.w * 0.8;
const cy = -b.h * (0.15 + ((k * 17) % 7) / 10);
ctx.beginPath();
ctx.moveTo(cx, cy);
ctx.lineTo(cx + 0.6, cy - 0.7);
ctx.lineTo(cx + 0.2, cy - 1.4);
ctx.lineTo(cx + 0.8, cy - 2);
ctx.stroke();
}
ctx.globalAlpha = 1;
}
}
// A broken shell: clods at her feet.
if (act === "stagger") {
ctx.fillStyle = C(MUD_LIT);
for (let k = 0; k < 6; k++) {
ellipse(ctx, -b.w * 0.6 + k * b.w * 0.24, -0.3 - (k % 2) * 0.3, 0.7, 0.35, k);
ctx.fill();
}
// Stars of her daze circling her hat.
ctx.fillStyle = GOLD;
for (let k = 0; k < 3; k++) {
const a = t / 220 + (k * TAU) / 3;
circle(ctx, Math.cos(a) * 1.6, headY - 2 + Math.sin(a) * 0.4, 0.2 * (1 - staggerP * 0.5));
ctx.fill();
}
}
ctx.restore();
// The one good eye, greener while the cauldron is open.
eye(v, x + d * 0.42, y + headY - 0.1, 0.22, b.lit ? CAULDRON_LIT : EYE_AMBER);
// The charge's bow wave, out in front of her.
if (surging || act === "surgeWind") {
const p = surging ? 1 : 0.35 + 0.65 * surgeP;
ctx.fillStyle = MUD_LIT;
ctx.beginPath();
ctx.moveTo(b.w * 0.3, (surging ? -SURGE_SINK : 0) + 0.05);
ctx.quadraticCurveTo(b.w * 0.55 + p * 2, (surging ? -SURGE_SINK : 0) - 3.4 * p, b.w * 0.65 + p * 3.4, (surging ? -SURGE_SINK : 0) + 0.05);
ctx.closePath();
ctx.fill();
ctx.fillStyle = MUD;
ctx.beginPath();
ctx.moveTo(b.w * 0.35, (surging ? -SURGE_SINK : 0) + 0.05);
ctx.quadraticCurveTo(b.w * 0.55 + p * 1.5, (surging ? -SURGE_SINK : 0) - 2.4 * p, b.w * 0.6 + p * 2.6, (surging ? -SURGE_SINK : 0) + 0.05);
ctx.closePath();
ctx.fill();
ctx.fillStyle = WATER_SHEEN;
for (let k = 0; k < 4; k++) {
const q = (t / 160 + k / 4) % 1;
ctx.globalAlpha = p * (1 - q);
circle(ctx, b.w * 0.6 + p * 2.2 + q * 1.5, (surging ? -SURGE_SINK : 0) - 1.6 * p - q * 1.2 + k * 0.3, 0.25);
ctx.fill();
}
ctx.globalAlpha = 1;
}
// The whirlpool at her feet while she pulls.
if (act === "pullWind" || act === "pull") {
const p = act === "pull" ? 1 : into(b, PULL_WIND_MS);
ctx.strokeStyle = WATER_SHEEN;
ctx.lineWidth = 0.2;
for (let k = 0; k < 4; k++) {
const q = (t / 400 + k / 4) % 1;
ctx.globalAlpha = p * (0.3 + 0.6 * q);
ellipse(ctx, 2.6, 0.2, (1 - q) * 7 * p + 0.5, (1 - q) * 1.1 * p + 0.2);
ctx.stroke();
}
ctx.globalAlpha = 1;
}
// Bog hands: bent over the pot, both arms plunged elbow deep into the
// stew, which churns and glows green (her hands are what comes up out
// of the boards).
if (act === "hands") {
const piv = -b.h * 0.2;
const rot = (px, py) => [px * Math.cos(lean) - (py - piv) * Math.sin(lean), px * Math.sin(lean) + (py - piv) * Math.cos(lean) + piv];
const pot = b.w * 0.5 + 1.6;
halo(ctx, pot, -3.3, 2.6, CAULDRON_LIT, 0.55);
ctx.strokeStyle = C(HAG_DARK);
ctx.lineWidth = 0.85;
for (const [s0, hx] of [[-0.3, pot - 0.5], [0.6, pot + 0.5]]) {
const [ax, ay] = rot(s0, sh);
ctx.beginPath();
ctx.moveTo(ax, ay);
ctx.quadraticCurveTo((ax + hx) / 2, ay - 1.2, hx, -2.6);
ctx.stroke();
}
ctx.fillStyle = CAULDRON_LIT;
for (let k = 0; k < 5; k++) {
const q = (t / 260 + k / 5) % 1;
ctx.globalAlpha = 0.9 * (1 - q);
circle(ctx, pot - 1 + k * 0.5, -3.2 - q * 1.6, 0.25 * (1 - q) + 0.08);
ctx.fill();
}
ctx.globalAlpha = 1;
}
ctx.restore();
if (surging) ctx.restore();
// The one good eye, greener while the cauldron is open, red before a
// combo, through the slit while she is shelled: where her head is after
// the lean, the crouch and the rise (her frame's own sums).
const hy = -b.h * (0.86 - hunch) - 0.1 + b.h * 0.2;
const rot = lean + (act === "rest" ? 0.05 : 0.02) * Math.sin(t / 900);
const ex = 0.42 * Math.cos(rot) - hy * Math.sin(rot);
const ey = 0.42 * Math.sin(rot) + hy * Math.cos(rot) - b.h * 0.2;
const sx = (1 + squash * 0.3) * (act === "stompAir" ? 0.92 : 1);
const sy = (1 - squash) * (act === "stompAir" ? 1.08 : 1) * (1 - resurface * 0.9);
const eyeX = x + d * ex * sx;
const eyeY = y + resurface * b.h * 0.8 + ey * sy;
if (!(surging && eyeY > floorY)) eye(v, eyeX, eyeY, 0.22, b.comboMs > 0 ? DANGER : b.lit ? CAULDRON_LIT : EYE_AMBER);
if (b.comboMs > 0) halo(ctx, eyeX, eyeY, 1.6, DANGER, 0.7);
}
/* ------------------------------------------------- hazards and waves */
// A bog hand from the planks: a ring of ripples tightening on its spot for
// `warn` (a dark shape under the boards near the end), then a mud-caked arm
// bursting up HAND_H with clawed fingers, sinking again at the end.
function boghand(ctx, v, h) {
const { g } = v;
const t = v.clock;
const fy = g.FIELD_H - h.y;
if (h.warn > 0) {
const p = h.full ? clamp(1 - h.warn / h.full, 0, 1) : 0.5;
ctx.fillStyle = "#000000";
ctx.globalAlpha = 0.2 + p * 0.5;
ellipse(ctx, h.x, fy - 0.08, h.w * 0.55 + p * 0.3, 0.3);
ctx.fill();
ctx.strokeStyle = p > 0.7 ? DANGER : WATER_SHEEN;
ctx.lineWidth = 0.2;
for (let k = 0; k < 3; k++) {
const q = (t / (420 - p * 220) + k / 3) % 1;
ctx.globalAlpha = (1 - q) * (0.5 + p * 0.5);
ellipse(ctx, h.x, fy - 0.08, 0.4 + (1 - q) * h.w * 0.9, 0.12 + (1 - q) * 0.4);
ctx.stroke();
}
// Fingertips breaking the surface just before.
if (p > 0.75) {
ctx.globalAlpha = (p - 0.75) * 4;
ctx.strokeStyle = BOGSKIN_LIT;
ctx.lineWidth = 0.3;
for (const f of [-0.6, -0.2, 0.2, 0.6]) line(ctx, h.x + f, fy, h.x + f * 1.2, fy - 0.5);
}
ctx.globalAlpha = 1;
return;
}
const age = HAND_UP_MS - h.live;
const up = clamp(Math.min(age / 110, h.live / 160), 0, 1);
const top = fy - h.h * up;
const sway = Math.sin(t / 120 + h.x) * 0.25;
// The forearm, mud dripping off it.
ctx.fillStyle = BOGSKIN_LIT;
ctx.beginPath();
ctx.moveTo(h.x - 0.95, fy);
ctx.quadraticCurveTo(h.x - 0.8 + sway, (fy + top) / 2, h.x - 0.7 + sway, top + 1.3);
ctx.lineTo(h.x + 0.7 + sway, top + 1.3);
ctx.quadraticCurveTo(h.x + 0.8 + sway, (fy + top) / 2, h.x + 0.95, fy);
ctx.closePath();
ctx.fill();
ctx.fillStyle = MUD;
ellipse(ctx, h.x + 0.3 + sway * 0.5, (fy + top) / 2 + 0.6, 0.3, h.h * up * 0.28);
ctx.fill();
// The hand: a palm and four clawed fingers clutching.
ctx.fillStyle = BOGSKIN_LIT;
ellipse(ctx, h.x + sway, top + 1, 1.05, 0.75);
ctx.fill();
ctx.strokeStyle = BOGSKIN_LIT;
ctx.lineWidth = 0.38;
for (const [f, l] of [[-0.75, 0.9], [-0.25, 1.15], [0.25, 1.1], [0.75, 0.85]]) {
const tx = h.x + sway + f * 1.3;
ctx.beginPath();
ctx.moveTo(h.x + sway + f * 0.8, top + 0.8);
ctx.quadraticCurveTo(tx, top + 0.6 - l * 0.6, tx - f * 0.4, top + 0.9 - l);
ctx.stroke();
}
// The splash at the boards.
ctx.fillStyle = MUD_LIT;
for (let k = 0; k < 4; k++) {
const q = (age / 500 + k / 4) % 1;
ctx.globalAlpha = 0.8 * (1 - q);
circle(ctx, h.x + (k - 1.5) * 0.9, fy - q * 1.6, 0.25);
ctx.fill();
}
ctx.globalAlpha = 1;
}
// The tide: for `warn`, black water creeping up over the plank edges and
// lapping higher (a pulse of it at every gap); then for TIDE_MS a sheet of
// water over every plank of the arena, foam along its top, draining away at
// the end. Shelves stay dry.
function tide(ctx, v, h) {
const { g } = v;
const t = v.clock;
const spans = (v.round.spec.ground || []).filter(([a, c]) => c > h.x0 && a < h.x1);
const warn = h.warn > 0;
const p = warn ? clamp(1 - h.warn / TIDE_WARN_MS, 0, 1) : 1;
const out = warn ? 1 : clamp(h.live / 500, 0, 1) * clamp((TIDE_MS - h.live) / 250 + 0.3, 0, 1);
const depth = warn ? 0.35 + p * 0.9 : 1.9 * out;
for (const [a, c, gy] of spans) {
const x0 = Math.max(a, h.x0);
const x1 = Math.min(c, h.x1);
const fy = g.FIELD_H - gy;
ctx.fillStyle = warn ? "#1c3c34" : "#2a5a4c";
ctx.globalAlpha = warn ? 0.5 + 0.3 * p : 0.72 * out;
ctx.beginPath();
ctx.moveTo(x0, fy + 0.5);
for (let xx = x0; xx <= x1 + 0.01; xx += 1) ctx.lineTo(xx, fy - depth + Math.sin(xx * 0.7 + t / 260) * 0.18);
ctx.lineTo(x1, fy + 0.5);
ctx.closePath();
ctx.fill();
// Foam and sheen along the top.
ctx.strokeStyle = warn ? (p > 0.6 ? DANGER : "#7ab8a8") : "#cfeee4";
ctx.lineWidth = warn ? 0.3 : 0.35;
ctx.globalAlpha = warn ? 0.6 + 0.4 * Math.abs(Math.sin(t / 140)) : 0.8 * out;
ctx.beginPath();
for (let xx = x0; xx <= x1 + 0.01; xx += 1) {
const yy = fy - depth + Math.sin(xx * 0.7 + t / 260) * 0.18;
if (xx === x0) ctx.moveTo(xx, yy);
else ctx.lineTo(xx, yy);
}
ctx.stroke();
// The water spilling in at the plank ends.
ctx.fillStyle = WATER_SHEEN;
for (const ex of [x0, x1]) {
for (let k = 0; k < 3; k++) {
const q = (t / 300 + k / 3 + ex) % 1;
ctx.globalAlpha = (1 - q) * (warn ? p : out) * 0.8;
circle(ctx, ex + (ex === x0 ? 1 : -1) * q * 1.6, fy - depth - 0.3 - Math.sin(q * Math.PI) * 0.9, 0.22);
ctx.fill();
}
}
}
ctx.globalAlpha = 1;
}
// A muck patch from her cauldron: in the air it is a glob arcing from
// (sx, sy) to where it lands, a ring closing on the spot; then a steaming
// mound of burning muck for MUCK_MS, glowing at its cracks.
@@ -1224,11 +1651,20 @@ export function bogArt(d) {
else if (m.act === "rekindle") add(m.x, m.y + m.h / 2, 3, 0.4);
else if (m.act === "dim") add(m.x, m.y + m.h / 2, 1.2, 0.15);
}
for (const h of v.round.hazards) if (h.kind === "muck" && h.live > 0) add(h.x, h.y + 1, 4, 0.35 * Math.min(1, h.live / 600));
for (const h of v.round.hazards) {
if (h.kind === "muck" && h.live > 0) add(h.x, h.y + 1, 4, 0.35 * Math.min(1, h.live / 600));
// A ripple and a hand are lit enough to read and dodge in the dark.
else if (h.kind === "boghand") add(h.x, h.y + 1.5, 4, h.warn > 0 ? 0.42 : 0.55);
else if (h.kind === "tide") for (let x = h.x0 + 6; x < h.x1; x += 14) add(x, h.y + 1.5, 6, h.warn > 0 ? 0.15 : 0.25);
}
const b = v.round.boss;
if (b && b.kind === "motherbog" && b.state !== "down" && !b.hidden) {
add(b.x + (b.dir || 1) * (b.w * 0.5 + 1.6), b.y + 3, b.lit ? 8 : 3.5, b.lit ? 0.85 : 0.4);
if (b.act !== "surge" && b.act !== "stompAir") add(b.x + (b.dir || 1) * (b.w * 0.5 + 1.6), b.y + 3, b.lit ? 8 : 3.5, b.lit ? 0.85 : 0.4);
if (!b.hidden && b.act !== "under") add(b.x + (b.dir || 1) * 0.4, b.y + b.h * 0.86, 4, 0.2);
if (b.act === "stompWind" || b.act === "stompAir") add(b.landX ?? b.x, (b.floor ?? 6) + 1, 5, 0.45);
if (b.act === "callWind") for (const x of b.callXs || []) add(x, (b.floor ?? 6) + 1, 4, 0.45);
if (b.act === "tideWind" || b.act === "tideHold" || b.act === "callWind") add(b.x, b.y + b.h + 2, 6, 0.45);
if (b.act === "lanternWind") add(b.x - (b.dir || 1) * 0.6, b.y + b.h + 3.5, 8, 0.7);
}
}
@@ -1299,6 +1735,83 @@ export function bogArt(d) {
say(tone, e.kind, "rise", 0.55);
burst(e.x, e.y + 1, WATER_SHEEN, 14, 12, 500);
shake(200, 0.55);
} else if (e.type === "handsWind") {
say(tone, e.kind, "handsWind", 0.5);
float(e.x, e.y + 6, "Hands!", DANGER, 2.4);
for (const x of e.xs || []) ring(x, 6, WATER_SHEEN, 0.6, 3, 600);
} else if (e.type === "handsUp") {
if (gate(fx, "handMs", 120)) say(tone, "motherbog", "handsUp", 0.5);
burst(e.x, e.y + 0.5, MUD_LIT, 10, 9, 380);
shake(90, 0.25);
} else if (e.type === "surgeWind") {
say(tone, e.kind, "surgeWind", 0.5);
float(e.x, e.y + 6, "Surge! Jump her!", DANGER, 2.4);
} else if (e.type === "motherSurge") {
say(tone, e.kind, "surge", 0.6);
burst(e.x, e.y + 1, WATER_SHEEN, 14, 12, 450);
shake(220, 0.5);
} else if (e.type === "shellWind") {
say(tone, e.kind, "shellWind", 0.5);
float(e.x, e.y + 6, "Mud shell! Break it!", GOLD, 2.4);
} else if (e.type === "shellChip") {
if (gate(fx, "chipMs", 90)) say(tone, e.kind, "chip", 0.35);
burst(e.x, e.y, MUD_LIT, 3, 5, 220);
} else if (e.type === "shellBreak") {
say(tone, e.kind, "shellBreak", 0.6);
burst(e.x, e.y, MUD_LIT, 20, 14, 600);
float(e.x, e.y + 6, "Cracked! Now!", GOLD, 2.6);
shake(200, 0.45);
} else if (e.type === "motherFeed") {
say(tone, e.kind, "feed", 0.5);
glow(e.x, e.y, 6, 0.6, 500);
if (e.heal > 0) float(e.x, e.y + 5, `+${Math.round(e.heal)}`, CAULDRON_LIT, 2.4);
} else if (e.type === "broodWind") {
say(tone, e.kind, "broodWind", 0.45);
float(e.x, e.y + 6, "Leeches!", DANGER, 2.2);
} else if (e.type === "broodPour") {
say(tone, e.kind, "pour", 0.5);
burst(e.x, e.y, LEECH_LIT, 14, 9, 450);
} else if (e.type === "stompWind") {
say(tone, e.kind, "stompWind", 0.5);
if (e.landX !== undefined) ring(e.landX, 6, DANGER, 1, 4.5, 900);
float(e.x, e.y + 6, "Stomp!", DANGER, 2.4);
} else if (e.type === "motherLeap") {
say(tone, e.kind, "leap", 0.5);
burst(e.x, e.y + 0.5, WATER_SHEEN, 10, 10, 400);
} else if (e.type === "motherSlam") {
say(tone, e.kind, "slam", 0.7);
burst(e.x, e.y + 0.5, MUD_LIT, 20, 14, 550);
shake(320, 0.8);
} else if (e.type === "tideWarn") {
say(tone, e.kind, "tideWarn", 0.6);
float(e.x, e.y + 8, "The tide! Get up high!", DANGER, 2.8);
} else if (e.type === "tideRise") {
say(tone, e.kind, "tide", 0.65);
shake(300, 0.5);
} else if (e.type === "pullWind") {
say(tone, e.kind, "pullWind", 0.5);
float(e.x, e.y + 8, "Undertow! Run!", DANGER, 2.4);
ring(e.x, e.y, WATER_SHEEN, 1, 6, 700);
} else if (e.type === "motherPull") {
say(tone, e.kind, "pull", 0.55);
ring(e.x, e.y, WATER_SHEEN, 6, 1, 700);
} else if (e.type === "callWind") {
say(tone, e.kind, "callWind", 0.5);
float(e.x, e.y + 12, "The drowned!", DANGER, 2.4);
for (const x of e.xs || []) ring(x, e.y, MUD_LIT, 0.8, 3.5, 800);
} else if (e.type === "motherCall") {
say(tone, e.kind, "call", 0.55);
for (const x of e.xs || []) burst(x, e.y + 0.5, MUD_LIT, 10, 9, 420);
} else if (e.type === "lanternWind") {
say(tone, e.kind, "lanternWind", 0.45);
glow(e.x, e.y, 6, 0.6, 700);
float(e.x, e.y + 4, "Wisps!", GOLD, 2.2);
} else if (e.type === "motherLantern") {
say(tone, e.kind, "lantern", 0.45);
burst(e.x, e.y, WISP, 12, 8, 450);
} else if (e.type === "motherCombo") {
say(tone, e.kind, "combo", 0.5);
glow(e.x, e.y, 4, 0.7, 300);
} else return false;
return true;
}
@@ -1312,7 +1825,7 @@ export function bogArt(d) {
monsters: freeze({ lurker, leech, wisp, bogbody }),
bosses: freeze({ motherbog }),
missiles: freeze({}),
hazards: freeze({ muck }),
hazards: freeze({ muck, boghand, tide }),
waves: freeze({ mudwave }),
powers: freeze({ boots, harpoon }),
lights,
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,859 @@
// 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 },
],
},
// Her newer moves (first drafts, each a telegraph you can tell apart by ear).
// Bog hands wind-up: arms plunging into the water, a low suck and slosh.
ghoulMotherHandsWind: {
layers: [
{ type: "brown", seconds: 0.5, attack: 0.02, gain: 0.8, filter: { type: "lowpass", from: 900, to: 200, q: 1.5 } },
{ type: "sine", from: 140, to: 60, seconds: 0.45, attack: 0.02, gain: 0.6, vibrato: { rate: 12, depth: 0.3 } },
{ type: "noise", seconds: 0.25, attack: 0.03, gain: 0.4, delay: 0.1, filter: { type: "bandpass", from: 600, to: 250, q: 2 } },
{ type: "sine", from: 420, to: 700, seconds: 0.05, delay: 0.38, gain: 0.25 },
{ type: "sine", from: 380, to: 640, seconds: 0.05, delay: 0.5, gain: 0.2 },
],
},
// A hand bursts up: a wet slap and a grab.
ghoulMotherHandsUp: {
layers: [
{ type: "noise", seconds: 0.18, attack: 0, gain: 0.9, filter: { type: "lowpass", from: 2400, to: 300, q: 1 } },
{ type: "square", from: 180, to: 60, seconds: 0.12, attack: 0, gain: 0.35, filter: { type: "lowpass", from: 600, to: 600, q: 1 } },
{ type: "noise", seconds: 0.05, delay: 0.12, attack: 0, gain: 0.5, filter: { type: "bandpass", from: 1500, to: 900, q: 3 } },
{ type: "sine", from: 90, to: 50, seconds: 0.25, attack: 0, gain: 0.5 },
],
},
// The surge wind-up: a deep breath drawn in and a rising rumble.
ghoulMotherSurgeWind: {
layers: [
{ type: "noise", seconds: 0.7, attack: 0.5, gain: 0.5, filter: { type: "bandpass", from: 400, to: 1400, q: 1.5 } },
{ type: "sawtooth", from: 40, to: 70, seconds: 0.75, attack: 0.3, gain: 0.7, filter: { type: "lowpass", from: 300, to: 900, q: 4 } },
{ type: "brown", seconds: 0.75, attack: 0.4, gain: 0.6, filter: { type: "lowpass", from: 200, to: 400, q: 1 } },
],
},
// The surge: a charging roar and a bow wave hissing through the water.
ghoulMotherSurge: {
layers: [
{ type: "sawtooth", from: 70, to: 52, seconds: 0.6, attack: 0.02, gain: 0.9, vibrato: { rate: 6, depth: 0.12 }, filter: { type: "lowpass", from: 2000, to: 400, q: 4 } },
{ type: "noise", seconds: 0.8, attack: 0.03, gain: 0.6, filter: { type: "bandpass", from: 1800, to: 500, q: 1 } },
{ type: "brown", seconds: 0.8, attack: 0.02, gain: 0.7, filter: { type: "lowpass", from: 300, to: 120, q: 1 } },
],
},
// The shell wind-up: mud slapped on in handfuls.
ghoulMotherShellWind: {
layers: [
{ type: "noise", seconds: 0.12, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 1400, to: 200, q: 1 } },
{ type: "noise", seconds: 0.12, delay: 0.2, attack: 0, gain: 0.7, filter: { type: "lowpass", from: 1300, to: 180, q: 1 } },
{ type: "noise", seconds: 0.14, delay: 0.4, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 1200, to: 160, q: 1 } },
{ type: "sine", from: 70, to: 45, seconds: 0.55, attack: 0.02, gain: 0.5 },
],
},
// A bolt chips the shell: a dull clay knock.
ghoulMotherChip: {
layers: [
{ type: "square", from: 320, to: 160, seconds: 0.05, attack: 0, gain: 0.35, filter: { type: "lowpass", from: 900, to: 900, q: 1 } },
{ type: "noise", seconds: 0.06, attack: 0, gain: 0.6, filter: { type: "bandpass", from: 900, to: 600, q: 2 } },
],
},
// The shell breaks: a crack, falling clods and a stunned groan.
ghoulMotherShellBreak: {
layers: [
{ type: "noise", seconds: 0.08, attack: 0, gain: 1, filter: { type: "highpass", from: 1200, to: 1200, q: 1 } },
{ type: "noise", seconds: 0.5, attack: 0.01, gain: 0.7, delay: 0.05, filter: { type: "lowpass", from: 1600, to: 200, q: 1 } },
{ type: "square", from: 220, to: 50, seconds: 0.2, attack: 0, gain: 0.4, filter: { type: "lowpass", from: 700, to: 700, q: 1 } },
{ type: "sawtooth", from: 66, to: 44, seconds: 0.6, delay: 0.3, attack: 0.05, gain: 0.8, vibrato: { rate: 4, depth: 0.15 }, filter: { type: "lowpass", from: 1200, to: 300, q: 4 } },
],
},
// She feeds: a ladle in the stew, gulps and a satisfied rumble.
ghoulMotherFeed: {
layers: [
{ type: "sine", from: 120, to: 90, seconds: 0.2, attack: 0.02, gain: 0.7, vibrato: { rate: 14, depth: 0.4 } },
{ type: "sine", from: 120, to: 90, seconds: 0.2, delay: 0.28, attack: 0.02, gain: 0.7, vibrato: { rate: 14, depth: 0.4 } },
{ type: "sine", from: 500, to: 820, seconds: 0.05, delay: 0.12, gain: 0.25 },
{ type: "sine", from: 460, to: 760, seconds: 0.05, delay: 0.4, gain: 0.22 },
{ type: "sawtooth", from: 50, to: 62, seconds: 0.5, delay: 0.6, attack: 0.08, gain: 0.6, filter: { type: "lowpass", from: 600, to: 400, q: 3 } },
],
},
// The brood wind-up: the cauldron scraping as it tips.
ghoulMotherBroodWind: {
layers: [
{ type: "sawtooth", from: 180, to: 240, seconds: 0.6, attack: 0.05, gain: 0.35, vibrato: { rate: 18, depth: 0.08 }, filter: { type: "bandpass", from: 900, to: 1400, q: 6 } },
{ type: "sine", from: 260, to: 250, seconds: 0.5, attack: 0.003, gain: 0.3 },
{ type: "brown", seconds: 0.65, attack: 0.05, gain: 0.5, filter: { type: "lowpass", from: 500, to: 300, q: 1 } },
],
},
// The brood pours: a slosh and a writhing squelch.
ghoulMotherPour: {
layers: [
{ type: "noise", seconds: 0.4, attack: 0.02, gain: 0.8, filter: { type: "lowpass", from: 1500, to: 300, q: 1 } },
{ type: "sine", from: 300, to: 180, seconds: 0.08, delay: 0.15, gain: 0.3, vibrato: { rate: 30, depth: 0.3 } },
{ type: "sine", from: 340, to: 200, seconds: 0.08, delay: 0.3, gain: 0.3, vibrato: { rate: 30, depth: 0.3 } },
{ type: "sine", from: 280, to: 160, seconds: 0.08, delay: 0.45, gain: 0.3, vibrato: { rate: 30, depth: 0.3 } },
],
},
// The stomp wind-up: knees creak, a gathering grunt.
ghoulMotherStompWind: {
layers: [
{ type: "sawtooth", from: 52, to: 66, seconds: 0.55, attack: 0.1, gain: 0.8, filter: { type: "lowpass", from: 500, to: 1200, q: 4 } },
{ type: "noise", seconds: 0.08, delay: 0.1, attack: 0, gain: 0.35, filter: { type: "bandpass", from: 2400, to: 2000, q: 6 } },
{ type: "noise", seconds: 0.08, delay: 0.3, attack: 0, gain: 0.35, filter: { type: "bandpass", from: 2200, to: 1800, q: 6 } },
],
},
// The leap: a heave and a rush of air.
ghoulMotherLeap: {
layers: [
{ type: "noise", seconds: 0.5, attack: 0.05, gain: 0.6, filter: { type: "bandpass", from: 500, to: 1800, q: 1.2 } },
{ type: "sawtooth", from: 60, to: 90, seconds: 0.3, attack: 0.02, gain: 0.6, filter: { type: "lowpass", from: 800, to: 1600, q: 3 } },
],
},
// The slam: a huge plank-cracking thud.
ghoulMotherSlam: {
layers: [
{ type: "sine", from: 70, to: 28, seconds: 0.6, attack: 0, gain: 1 },
{ type: "brown", seconds: 0.6, attack: 0, gain: 0.9, filter: { type: "lowpass", from: 400, to: 80, q: 1 } },
{ type: "noise", seconds: 0.1, attack: 0, gain: 0.8, filter: { type: "bandpass", from: 1400, to: 800, q: 2 } },
{ type: "noise", seconds: 0.4, delay: 0.05, attack: 0.01, gain: 0.5, filter: { type: "lowpass", from: 1800, to: 200, q: 1 } },
],
},
// The tide warning: a swelling roar of water and a long low horn.
ghoulMotherTideWarn: {
layers: [
{ type: "sawtooth", from: 44, to: 46, seconds: 1.1, attack: 0.3, gain: 0.7, vibrato: { rate: 3, depth: 0.05 }, filter: { type: "lowpass", from: 400, to: 900, q: 3 } },
{ type: "noise", seconds: 1.1, attack: 0.6, gain: 0.6, filter: { type: "lowpass", from: 600, to: 2400, q: 1 } },
{ type: "sine", from: 88, to: 92, seconds: 1.1, attack: 0.3, gain: 0.4 },
],
},
// The tide comes in: a crashing wash over the boards.
ghoulMotherTide: {
layers: [
{ type: "noise", seconds: 1, attack: 0.02, gain: 0.9, filter: { type: "lowpass", from: 3000, to: 500, q: 1 } },
{ type: "brown", seconds: 1, attack: 0.02, gain: 0.8, filter: { type: "lowpass", from: 300, to: 100, q: 1 } },
{ type: "sine", from: 60, to: 35, seconds: 0.8, attack: 0.02, gain: 0.6 },
],
},
// The pull wind-up: a ladle stirring, a whirlpool starting to spin.
ghoulMotherPullWind: {
layers: [
{ type: "noise", seconds: 0.6, attack: 0.1, gain: 0.6, filter: { type: "bandpass", from: 300, to: 900, q: 4 } },
{ type: "sine", from: 110, to: 180, seconds: 0.6, attack: 0.05, gain: 0.5, vibrato: { rate: 6, depth: 0.3 } },
{ type: "brown", seconds: 0.6, attack: 0.1, gain: 0.5, filter: { type: "lowpass", from: 400, to: 250, q: 1 } },
],
},
// The pull: a sucking, draining gurgle.
ghoulMotherPull: {
layers: [
{ type: "sine", from: 200, to: 70, seconds: 1, attack: 0.05, gain: 0.8, vibrato: { rate: 9, depth: 0.5 } },
{ type: "noise", seconds: 1, attack: 0.05, gain: 0.5, filter: { type: "bandpass", from: 900, to: 200, q: 3 } },
{ type: "brown", seconds: 1, attack: 0.05, gain: 0.6, filter: { type: "lowpass", from: 300, to: 120, q: 1 } },
],
},
// The call wind-up: mud boiling, a chanted moan.
ghoulMotherCallWind: {
layers: [
{ type: "sawtooth", from: 98, to: 92, seconds: 0.75, attack: 0.15, gain: 0.5, vibrato: { rate: 5, depth: 0.2 }, filter: { type: "lowpass", from: 700, to: 500, q: 6 } },
{ type: "sine", from: 400, to: 680, seconds: 0.05, delay: 0.1, gain: 0.25 },
{ type: "sine", from: 360, to: 600, seconds: 0.05, delay: 0.3, gain: 0.25 },
{ type: "sine", from: 440, to: 740, seconds: 0.05, delay: 0.5, gain: 0.25 },
{ type: "brown", seconds: 0.8, attack: 0.1, gain: 0.5, filter: { type: "lowpass", from: 500, to: 300, q: 1 } },
],
},
// The drowned come up: a sucking pop of mud and a long dead groan.
ghoulMotherCall: {
layers: [
{ type: "noise", seconds: 0.2, attack: 0, gain: 0.8, filter: { type: "lowpass", from: 1600, to: 200, q: 1 } },
{ type: "sawtooth", from: 80, to: 60, seconds: 0.8, delay: 0.15, attack: 0.1, gain: 0.7, vibrato: { rate: 4, depth: 0.1 }, filter: { type: "lowpass", from: 900, to: 400, q: 5 } },
],
},
// The lantern wind-up: a glassy rising shimmer.
ghoulMotherLanternWind: {
layers: [
{ type: "sine", from: 600, to: 1200, seconds: 0.65, attack: 0.1, gain: 0.3, vibrato: { rate: 7, depth: 0.03 } },
{ type: "sine", from: 900, to: 1800, seconds: 0.65, attack: 0.15, gain: 0.2, vibrato: { rate: 7, depth: 0.03 } },
{ type: "pink", seconds: 0.6, attack: 0.3, gain: 0.2, filter: { type: "highpass", from: 3000, to: 5000, q: 1 } },
],
},
// The wisps kindle: a soft whoosh and two cold chimes.
ghoulMotherLantern: {
layers: [
{ type: "noise", seconds: 0.3, attack: 0.02, gain: 0.4, filter: { type: "bandpass", from: 800, to: 2400, q: 1 } },
{ type: "sine", from: 1320, to: 1320, seconds: 0.5, attack: 0.003, gain: 0.3 },
{ type: "sine", from: 1760, to: 1760, seconds: 0.5, delay: 0.15, attack: 0.003, gain: 0.25 },
],
},
// The combo: a sharp hiss and a snarl as her eye flares.
ghoulMotherCombo: {
layers: [
{ type: "noise", seconds: 0.2, attack: 0.01, gain: 0.6, filter: { type: "highpass", from: 2400, to: 3200, q: 1 } },
{ type: "sawtooth", from: 90, to: 120, seconds: 0.25, attack: 0.02, gain: 0.6, vibrato: { rate: 20, depth: 0.1 }, filter: { type: "lowpass", from: 1800, to: 1200, q: 4 } },
],
},
},
music: {
// The Sunken Boardwalk: muddy banjo. A two-finger banjo roll over the
// chords with a swing in it: plucked eighths climb and fall through each
// chord, a bass thumps the off beats, and a shuffle of kick, snare and
// hat keeps a slow hitch. The second part runs Dm, Am, F and E, the lead
// an octave higher; the third goes sour on Am, Bb, Am and E, the drums
// thinning out. At high dread a bell rings the toll and a wail drifts
// over the water.
ghoulBoardwalk: {
bpm: 100,
rush: 12,
voices: {
lead: { wave: "pulse", duty: 0.125, gain: 0.14, decay: 0.05, sustain: 0.2 },
bass: { wave: "triangle", gain: 0.42, decay: 0.1, sustain: 0.5 },
drum: { kit: true, gain: 0.24 },
bell: { wave: "sine", gain: 0.26, decay: 0.8, sustain: 0.1, from: 0.7 },
cry: { wave: "sawtooth", gain: 0.04, decay: 0.3, sustain: 0.9, from: 0.9, vibrato: { rate: 6, depth: 0.012, delay: 0 } },
},
patterns: {
A: {
lead:
"A4 . E5 . C5 . E5 . A4 . A5 . E5 . C5 . | F4 . C5 . A4 . C5 . F4 . F5 . C5 . A4 . | " +
"D4 . A4 . F4 . A4 . D4 . D5 . A4 . F4 . | E4 . B4 . G#4 . B4 . E4 . E5 . B4 . G#4 .",
bass:
". . A2 . . . A2 . . . A2 . . . A2 . | . . F2 . . . F2 . . . F2 . . . F2 . | " +
". . D2 . . . D2 . . . D2 . . . D2 . | . . E2 . . . E2 . . . E2 . . . E2 .",
drum:
"k . . h s . . h k . . h s . h . | k . . h s . . h k . . h s . h . | " +
"k . . h s . . h k . . h s . h . | k . . h s . . h k . . h s s s s",
bell:
"A3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
"D3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
cry:
"E6 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . . | " +
"A5 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . .",
},
B: {
lead:
"D5 . A5 . F5 . A5 . D5 . D6 . A5 . F5 . | A5 . E6 . C6 . E6 . A5 . A6 . E6 . C6 . | " +
"F5 . C6 . A5 . C6 . F5 . F6 . C6 . A5 . | E5 . B5 . G#5 . B5 . E5 . E6 . B5 . G#5 .",
bass:
". . D2 . . . D2 . . . D2 . . . D2 . | . . A2 . . . A2 . . . A2 . . . A2 . | " +
". . F2 . . . F2 . . . F2 . . . F2 . | . . E2 . . . E2 . . . E2 . . . E2 .",
drum:
"k . . h s . . h k . . h s . h . | k . . h s . . h k . . h s . h . | " +
"k . . h s . . h k . . h s . h . | k . . h s . . h k . . h s s s s",
bell:
"D3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
"F3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
cry:
"A5 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . . | " +
"C6 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . .",
},
C: {
lead:
"A4 . E5 . C5 . E5 . A4 . A5 . E5 . C5 . | A#4 . F5 . D5 . F5 . A#4 . A#5 . F5 . D5 . | " +
"A4 . E5 . C5 . E5 . A4 . A5 . E5 . C5 . | E4 . B4 . G#4 . B4 . E4 . E5 . B4 . G#4 .",
bass:
". . A2 . . . A2 . . . A2 . . . A2 . | . . A#2 . . . A#2 . . . A#2 . . . A#2 . | " +
". . A2 . . . A2 . . . A2 . . . A2 . | . . E2 . . . E2 . . . E2 . . . E2 .",
drum:
"k . . . . . . . s . . . . . . . | k . . . . . . . s . . . . . . . | " +
"k . . . . . . . s . . . . . . . | k . . . . . . . s . . . s s s s",
bell:
"A3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
"A3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
cry:
"E6 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . . | " +
"E6 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . .",
},
},
order: ["A", "B", "A", "C"],
},
// The Cypress Hollow: whispers in the cypress. Thirds and quiet: a flute
// and a pulse play the toll figure a third apart, sliding in and out of
// tune, over a held bass and the faintest brush of hats. The second part
// runs Dm, Am, F and E; the third goes sour on Am, Bb, Am and E, a melody
// voice slowing. At high dread the bell tolls and a wail rises through
// the knees of the trees.
ghoulHollow: {
bpm: 76,
rush: 10,
voices: {
lead: { wave: "sine", gain: 0.13, decay: 0.3, sustain: 0.8, vibrato: { rate: 5.5, depth: 0.012, delay: 0.2 } },
third: { wave: "sine", gain: 0.09, decay: 0.3, sustain: 0.8, vibrato: { rate: 4, depth: 0.02, delay: 0.2 } },
bass: { wave: "triangle", gain: 0.38, decay: 0.1, sustain: 0.5 },
hats: { kit: true, gain: 0.12, from: 0.4 },
bell: { wave: "sine", gain: 0.27, decay: 0.8, sustain: 0.1, from: 0.8 },
cry: { wave: "sawtooth", gain: 0.04, decay: 0.3, sustain: 0.9, from: 0.9, vibrato: { rate: 6, depth: 0.012, delay: 0 } },
},
patterns: {
A: {
lead:
"E6 - - - - - A5 - C6 - - - A5 - - - | C6 - - - - - A5 - C6 - - - F5 - - - | " +
"F5 - - - - - D5 - A5 - - - F5 - - - | B5 - - - - - E5 - G#5 - - - A#5 - - -",
third:
"C5 - - - - - E5 - A4 - - - E5 - - - | A4 - - - - - F4 - A4 - - - C5 - - - | " +
"D4 - - - - - A4 - F4 - - - D4 - - - | G#4 - - - - - B4 - E4 - - - B4 - - -",
bass:
"A2 - - . E3 - - . A3 - - . E3 - - . | F2 - - . C3 - - . F3 - - . C3 - - . | " +
"D2 - - . A2 - - . D3 - - . A2 - - . | E2 - - . B2 - - . E3 - - . B2 - - .",
hats:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
bell:
"A3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
"D3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
cry:
"E6 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . . | " +
"A5 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . .",
},
B: {
lead:
"F5 - - - - - D5 - A5 - - - F5 - - - | E6 - - - - - A5 - C6 - - - A5 - - - | " +
"C6 - - - - - A5 - C6 - - - F5 - - - | G#5 - - - - - E5 - B5 - - - A#5 - - -",
third:
"D4 - - - - - A4 - F4 - - - D4 - - - | C5 - - - - - E5 - A4 - - - E5 - - - | " +
"A4 - - - - - F4 - A4 - - - C5 - - - | E4 - - - - - B4 - G#4 - - - E4 - - -",
bass:
"D2 - - . A2 - - . D3 - - . A2 - - . | A2 - - . E3 - - . A3 - - . E3 - - . | " +
"F2 - - . C3 - - . F3 - - . C3 - - . | E2 - - . B2 - - . E3 - - . B2 - - .",
hats:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
bell:
"D3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
"F3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
cry:
"A5 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . . | " +
"C6 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . .",
},
C: {
lead:
"A5 - - - - - C6 - A5 - - - E6 - - - | D6 - - - - - F6 - A#5 - - - D6 - - - | " +
"A5 - - - - - E6 - C6 - - - E6 - - - | E5 - - - - - G#5 - E5 - - - B5 - - -",
third:
"E5 - - - - - - - - - - - - - - - | A#4 - - - - - - - - - - - - - - - | " +
"E5 - - - - - - - - - - - - - - - | G#4 - - - - - - - - - - - - - - -",
bass:
"A2 - - . E3 - - . A3 - - . E3 - - . | A#2 - - . F3 - - . A#3 - - . F3 - - . | " +
"A2 - - . E3 - - . A3 - - . E3 - - . | E2 - - . B2 - - . E3 - - . B2 - - .",
hats:
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h . | " +
". . h . . . h . . . h . . . h . | . . h . . . h . . . h . . . h .",
bell:
"A3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
"A3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
cry:
"E6 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . . | " +
"E6 - - - - - - - - - - - - - - - | . . . . . . . . . . . . . . . .",
},
},
order: ["A", "B", "A"],
},
// The Stilt House: hearth and cauldron. Warm and heavy: a square organ
// plays the figure under a thick bass, the kit stamps like a pot on a
// hearth, and a pulse bubbles in eighths on the chord tones. The second
// part runs Dm, Am, F and E, the lead an octave higher; the third goes
// sour on Am, Bb, Am and E, the drums thinning out. At high dread a bell
// tolls and a shrill cry whistles up the flue.
ghoulStilts: {
bpm: 92,
rush: 10,
voices: {
organ: { wave: "square", gain: 0.09, decay: 0.05, sustain: 0.9 },
bubble: { wave: "pulse", duty: 0.25, gain: 0.1, decay: 0.05, sustain: 0.2 },
bass: { wave: "triangle", gain: 0.42, decay: 0.1, sustain: 0.5 },
drum: { kit: true, gain: 0.26 },
bell: { wave: "sine", gain: 0.26, decay: 0.8, sustain: 0.1, from: 0.8 },
wail: { wave: "sawtooth", gain: 0.045, decay: 0.3, sustain: 0.9, from: 0.9, vibrato: { rate: 6, depth: 0.012, delay: 0 } },
},
patterns: {
A: {
organ:
"A4 - - - E5 - - - C5 - - - E5 - - - | F4 - - - A4 - - - C5 - - - F5 - - - | " +
"D4 - - - A4 - - - F4 - - - A4 - - - | E4 - - - G#4 - - - B4 - - - A#4 - - -",
bubble:
"A4 E5 C5 E5 A4 E5 C5 E5 A4 E5 C5 E5 A4 E5 C5 E5 | F4 C5 A4 C5 F4 C5 A4 C5 F4 C5 A4 C5 F4 C5 A4 C5 | " +
"D4 A4 F4 A4 D4 A4 F4 A4 D4 A4 F4 A4 D4 A4 F4 A4 | E4 B4 G#4 B4 E4 B4 G#4 B4 E4 B4 G#4 B4 E4 B4 G#4 B4",
bass:
"A2 - . . E3 - . . A2 - . . E3 - . . | F2 - . . C3 - . . F2 - . . C3 - . . | " +
"D2 - . . A2 - . . D2 - . . A2 - . . | E2 - . . B2 - . . E2 - . . B2 - . .",
drum:
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s . . . | " +
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s s s s",
bell:
"A3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
"D3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
wail:
"C8 - - - - - - - - - - - - - - - | A7 - - - - - - - - - - - - - - - | " +
"F7 - - - - - - - - - - - - - - - | G#7 - - - - - - - - - - - - - - -",
},
B: {
organ:
"F5 - - - A5 - - - D5 - - - F5 - - - | E6 - - - A6 - - - A5 - - - E6 - - - | " +
"A5 - - - C6 - - - F5 - - - A5 - - - | B5 - - - E6 - - - E5 - - - A#5 - - -",
bubble:
"D5 A5 F5 A5 D5 A5 F5 A5 D5 A5 F5 A5 D5 A5 F5 A5 | A5 E6 C6 E6 A5 E6 C6 E6 A5 E6 C6 E6 A5 E6 C6 E6 | " +
"F5 C6 A5 C6 F5 C6 A5 C6 F5 C6 A5 C6 F5 C6 A5 C6 | E5 B5 G#5 B5 E5 B5 G#5 B5 E5 B5 G#5 B5 E5 B5 G#5 B5",
bass:
"D2 - . . A2 - . . D2 - . . A2 - . . | A2 - . . E3 - . . A2 - . . E3 - . . | " +
"F2 - . . C3 - . . F2 - . . C3 - . . | E2 - . . B2 - . . E2 - . . B2 - . .",
drum:
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s . . . | " +
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s s s s",
bell:
"D3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
"F3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
wail:
"F7 - - - - - - - - - - - - - - - | C8 - - - - - - - - - - - - - - - | " +
"A7 - - - - - - - - - - - - - - - | G#7 - - - - - - - - - - - - - - -",
},
C: {
organ:
"E5 - - - C5 - - - E5 - - - A4 - - - | D5 - - - F5 - - - A#5 - - - A#4 - - - | " +
"E5 - - - C5 - - - E5 - - - A4 - - - | G#4 - - - B4 - - - E5 - - - E4 - - -",
bubble:
"A4 E5 C5 E5 A4 E5 C5 E5 A4 E5 C5 E5 A4 E5 C5 E5 | A#4 F5 D5 F5 A#4 F5 D5 F5 A#4 F5 D5 F5 A#4 F5 D5 F5 | " +
"A4 E5 C5 E5 A4 E5 C5 E5 A4 E5 C5 E5 A4 E5 C5 E5 | E4 B4 G#4 B4 E4 B4 G#4 B4 E4 B4 G#4 B4 E4 B4 G#4 B4",
bass:
"A2 - . . E3 - . . A2 - . . E3 - . . | A#2 - . . F3 - . . A#2 - . . F3 - . . | " +
"A2 - . . E3 - . . A2 - . . E3 - . . | E2 - . . B2 - . . E2 - . . B2 - . .",
drum:
"k . . k . . . . . . . . . . . . | k . . k . . . . . . . . . . . . | " +
"k . . k . . . . . . . . . . . . | k . . k . . . . . . . . s s s s",
bell:
"A3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . . | " +
"A3 - - - . . . . . . . . . . . . | . . . . . . . . . . . . . . . .",
wail:
"C8 - - - - - - - - - - - - - - - | D8 - - - - - - - - - - - - - - - | " +
"C8 - - - - - - - - - - - - - - - | G#7 - - - - - - - - - - - - - - -",
},
},
order: ["A", "B", "A", "C"],
},
// The Drowning Pool (Old Mother Bog's fight): tidal march. A tide that
// does not stop: arpeggios surge up and fall back over a bass on the
// root, a snare marches beneath them, and the toll figure surfaces in the
// middle of each part. The second part runs Dm, Am, F and E, the lead an
// octave higher; the third goes sour on Am, Bb, Am and E, the drums
// thinning out. At high dread a bell tolls, a choir of organs swells and
// a wail breaks over the top.
ghoulDrowning: {
bpm: 90,
rush: 10,
voices: {
wash: { wave: "pulse", duty: 0.125, gain: 0.1, decay: 0.08, sustain: 0.6 },
lead: { wave: "pulse", duty: 0.25, gain: 0.14, decay: 0.08, sustain: 0.6, vibrato: { rate: 5, depth: 0.006, delay: 0.1 } },
bass: { wave: "triangle", gain: 0.44, decay: 0.1, sustain: 0.5 },
drum: { kit: true, gain: 0.26 },
bell: { wave: "sine", gain: 0.3, decay: 0.8, sustain: 0.1, from: 0.6 },
choir: { wave: "square", gain: 0.07, decay: 0.05, sustain: 0.9, from: 0.8 },
wail: { wave: "sawtooth", gain: 0.05, decay: 0.3, sustain: 0.9, from: 0.9, vibrato: { rate: 6, depth: 0.012, delay: 0 } },
dk: { kit: true, gain: 0.22, from: 0.95 },
},
patterns: {
A: {
wash:
"A4 - C5 - E5 - A5 - E5 - C5 - A4 - C5 - | F4 - A4 - C5 - F5 - C5 - A4 - F4 - A4 - | " +
"D4 - F4 - A4 - D5 - A4 - F4 - D4 - F4 - | E4 - G#4 - B4 - E5 - B4 - G#4 - E4 - G#4 -",
lead:
". . . . E6 - - - A5 - - - C6 - - - | . . . . F5 - - - C6 - - - F6 - - - | " +
". . . . A5 - - - D5 - - - F5 - - - | . . . . E5 - - - B5 - - - A#5 - - -",
bass:
"A2 - - - E3 - - - A3 - - - E3 - - - | F2 - - - C3 - - - F3 - - - C3 - - - | " +
"D2 - - - A2 - - - D3 - - - A2 - - - | E2 - - - B2 - - - E3 - - - B2 - - -",
drum:
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s . . . | " +
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s s s s",
bell:
"A3 - - - . . . . . . . . . . . . | F3 - - - . . . . . . . . . . . . | " +
"D3 - - - . . . . . . . . . . . . | E3 - - - . . . . . . . . . . . .",
choir:
"C4 - - - - - - - - - - - - - - - | C4 - - - - - - - - - - - - - - - | " +
"D3 - - - - - - - - - - - - - - - | B3 - - - - - - - - - - - - - - -",
wail:
"E6 - - - - - - - - - - - - - - - | C6 - - - - - - - - - - - - - - - | " +
"A5 - - - - - - - - - - - - - - - | B5 - - - - - - - - - - - - - - -",
dk:
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s . . . | " +
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s . . .",
},
B: {
wash:
"D5 - F5 - A5 - D6 - A5 - F5 - D5 - F5 - | A5 - C6 - E6 - A6 - E6 - C6 - A5 - C6 - | " +
"F5 - A5 - C6 - F6 - C6 - A5 - F5 - A5 - | E5 - G#5 - B5 - E6 - B5 - G#5 - E5 - G#5 -",
lead:
". . . . F5 - - - D5 - - - A5 - - - | . . . . A6 - - - E6 - - - A5 - - - | " +
". . . . A5 - - - F5 - - - C6 - - - | . . . . E6 - - - B5 - - - A#5 - - -",
bass:
"D2 - - - A2 - - - D3 - - - A2 - - - | A2 - - - E3 - - - A3 - - - E3 - - - | " +
"F2 - - - C3 - - - F3 - - - C3 - - - | E2 - - - B2 - - - E3 - - - B2 - - -",
drum:
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s . . . | " +
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s s s s",
bell:
"D3 - - - . . . . . . . . . . . . | A3 - - - . . . . . . . . . . . . | " +
"F3 - - - . . . . . . . . . . . . | E3 - - - . . . . . . . . . . . .",
choir:
"D3 - - - - - - - - - - - - - - - | E4 - - - - - - - - - - - - - - - | " +
"A3 - - - - - - - - - - - - - - - | B3 - - - - - - - - - - - - - - -",
wail:
"A5 - - - - - - - - - - - - - - - | E6 - - - - - - - - - - - - - - - | " +
"C6 - - - - - - - - - - - - - - - | B5 - - - - - - - - - - - - - - -",
dk:
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s . . . | " +
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s . . .",
},
C: {
wash:
"A4 - C5 - E5 - A5 - E5 - C5 - A4 - C5 - | A#4 - D5 - F5 - A#5 - F5 - D5 - A#4 - D5 - | " +
"A4 - C5 - E5 - A5 - E5 - C5 - A4 - C5 - | E4 - G#4 - B4 - E5 - B4 - G#4 - E4 - G#4 -",
lead:
". . . . A5 - - - C6 - - - A5 - - - | . . . . F6 - - - A#6 - - - F6 - - - | " +
". . . . A5 - - - C6 - - - A5 - - - | . . . . B5 - - - E6 - - - B5 - - -",
bass:
"A2 - - - E3 - - - A3 - - - E3 - - - | A#2 - - - F3 - - - A#3 - - - F3 - - - | " +
"A2 - - - E3 - - - A3 - - - E3 - - - | E2 - - - B2 - - - E3 - - - B2 - - -",
drum:
"k . . . . . . . s . . . . . . . | k . . . . . . . s . . . . . . . | " +
"k . . . . . . . s . . . . . . . | k . . . . . . . s . . . s s s s",
bell:
"A3 - - - . . . . . . . . . . . . | A#3 - - - . . . . . . . . . . . . | " +
"A3 - - - . . . . . . . . . . . . | E3 - - - . . . . . . . . . . . .",
choir:
"E4 - - - - - - - - - - - - - - - | A#3 - - - - - - - - - - - - - - - | " +
"E4 - - - - - - - - - - - - - - - | G#3 - - - - - - - - - - - - - - -",
wail:
"E6 - - - - - - - - - - - - - - - | F6 - - - - - - - - - - - - - - - | " +
"E6 - - - - - - - - - - - - - - - | B5 - - - - - - - - - - - - - - -",
dk:
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s . . . | " +
"k . . . s . . . k . k . s . . . | k . . . s . . . k . k . s . . .",
},
},
order: ["A", "B", "A", "C"],
},
},
};
@@ -122,7 +122,7 @@
// `round.twist.wind`. The events are in EVENTS; the causes are `ice`, `shard`,
// `spike`, `frostwidow`, `icewraith`, `hand`, `frozen`, `shade`.
import { burrow } from "./ghoul-graveyard.js";
import { burrow } from "../graveyard/ghoul-graveyard.js";
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
@@ -37,7 +37,7 @@
// heading, and each time his lantern opens a few lantern moths flutter in
// toward it (never more than MOTH_CAP alive).
import { burrow } from "./ghoul-graveyard.js";
import { burrow } from "../graveyard/ghoul-graveyard.js";
const freeze = (o) => Object.freeze(o);
@@ -0,0 +1,517 @@
// Plan2Code Web Console - Ghoul Rush's finale, its rules: Marrow, the house itself, as a stage pack that ghoul.js plugs in. This file holds the first of the three kills, The Lawn; the rest land here (or beside it) as they are built.
//
// No imports: ghoul.js hands every rule here a kit `k` of its own helpers. See
// ghoul-bog.js for what a pack holds and "The finale" in
// prototypes/Ghoul-Rush-TODO.md for the whole fight.
//
// THE LAWN. The manor stands up on the right of the arena and fills it; YOU
// cannot walk into it (`WALL_GAP`). Its windows are the only way to hurt it:
// a bolt crosses the front of the house and strikes the first LIT window at its
// height. Each window has a share of the boss's hp (`b.hp` is always their sum),
// and once shot out it stays black: that is the fight's progress and the story's
// promise ("every window goes dark"). A few are lit at a time, in turn, and a
// row only starts to light once enough others are out (`rowsOpen`), so the fight
// climbs from the ground to the eyes in the gable, up the branches of the oak.
//
// Between shots it picks a move by weight (`pickMove`: never one three times
// running, the slow ones on a cooldown). Each has a wind-up and an event first:
//
// - SHINGLES (`shingles`): the roof shakes, shadows show on the lawn, slates fall
// through them from the sky. Step between; a shelf is no shelter.
// - CARPET (`carpet`): the door opens and a red carpet of a tongue rolls out along
// the floor, a wave to jump. Two in a row once it is furious.
// - PICKETS (`pickets`): the lawn ripples where YOU stand and a step either side,
// then fence-post teeth burst up. Step between, jump, or climb.
// - BRICKS (`bricks`, from the second phase): the chimney coughs up bricks aimed
// where YOU stand and ahead of where YOU run.
// - DOORMEN (`doormen`, from the second phase): two of the dead shamble out of the
// door, at most DOORMEN_CAP of its own alive.
// - STOMP (`stomp`, furious only): it rears and comes down: a shockwave to jump
// and slates after it.
//
// Its phase is 0 at first, 1 with PHASE_OUT[0] windows out, 2 with PHASE_OUT[1].
//
// THE RETREAT. The last window out is a real boss kill (a life, the points,
// `hurtBoss`), then `b.t` runs the scene (`retreatStep`): it sags, a false "YOU
// ESCAPED!", one window lights again in red and it laughs, and it drags itself down
// into the ground, leaving its front door standing alone on the lawn. Only then
// can YOU reach that door (`b.gone`), which is the way down after it.
const freeze = (o) => Object.freeze(o);
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
export const BOSSES = freeze({
marrow: freeze({ name: "Marrow", sub: "The house itself", w: 36, h: 44, hp: 90, points: 6000, color: "#c8a04a" }),
});
// The house's place: its left edge HOUSE_BACK short of the room's end, YOU kept
// WALL_GAP clear of it, and its center where the art stands it.
export const HOUSE_W = 36;
export const HOUSE_BACK = 38;
export const WALL_GAP = 1.5;
export const houseLeft = (spec) => spec.length - HOUSE_BACK;
export const houseCenter = (spec) => houseLeft(spec) + HOUSE_W / 2;
// The windows, [row, dx from the house's center, height over the floor]. The
// rows line up with what YOU can shoot from: the floor; the shelf at 18; the
// shelf at 30; the shelf at 38 (the gable's two are its eyes). The door is its mouth.
export const WINDOWS = freeze([
freeze([0, -12.5, 3.6]), freeze([0, 12.5, 3.6]),
freeze([1, -13.5, 14.5]), freeze([1, -4.5, 14.5]), freeze([1, 4.5, 14.5]), freeze([1, 13.5, 14.5]),
freeze([2, -13.5, 26.5]), freeze([2, -4.5, 26.5]), freeze([2, 4.5, 26.5]), freeze([2, 13.5, 26.5]),
freeze([3, -5.5, 36.8]), freeze([3, 5.5, 36.8]),
]);
export const WINDOW_W = 5;
export const WINDOW_H = 6.4;
// How many windows are lit at once, by phase; how long a set stays lit; the beat
// before another lights after one is shot out.
export const LIT_N = freeze([2, 2, 3]);
export const LIT_MS = 5200;
export const RELIGHT_MS = 650;
// Windows out for the second phase and for the third.
export const PHASE_OUT = freeze([4, 8]);
// The highest row that may light, by windows out.
export const rowsOpen = (out) => (out >= PHASE_OUT[1] ? 3 : out >= PHASE_OUT[0] ? 2 : 1);
export const IDLE_MS = 1500;
export const IDLE_JITTER = 0.25;
// How much quicker its waits are, by phase.
export const PHASE_PACE = freeze([1, 0.85, 0.68]);
// Shingles: the wind-up, then each shadow warns SHINGLE_WARN_MS (the later ones
// SHINGLE_STAGGER_MS after) and the slate falls for SHINGLE_FALL_MS.
export const SHINGLE_WIND_MS = 500;
export const SHINGLE_WARN_MS = 750;
export const SHINGLE_STAGGER_MS = 130;
export const SHINGLE_FALL_MS = 340;
export const SHINGLE_W = 3.2;
export const SHINGLE_H = 2.2;
export const SHINGLE_GAP = 8;
export const SHINGLE_TOP = 52;
export const SHINGLE_N = freeze([3, 4, 5]);
// The carpet: the door opens CARPET_WIND_MS, a second one CARPET_GAP_MS behind the first when furious.
export const CARPET_WIND_MS = 750;
export const CARPET_GAP_MS = 620;
export const CARPET_REST_MS = 1000;
// Pickets: the wind-up, then each ripple warns PICKET_WARN_MS and a tooth is up PICKET_UP_MS.
export const PICKET_WIND_MS = 350;
export const PICKET_WARN_MS = 750;
export const PICKET_STAGGER_MS = 120;
export const PICKET_UP_MS = 600;
export const PICKET_W = 2.8;
export const PICKET_H = 5.6;
export const PICKET_GAP = 8;
export const PICKET_N = freeze([3, 3, 4]);
// Bricks: the cough, then a brick is in the air BRICK_FLY_MS and burns BRICK_LIVE_MS where it lands.
export const BRICK_WIND_MS = 600;
export const BRICK_FLY_MS = 800;
export const BRICK_LIVE_MS = 420;
export const BRICK_W = 3.6;
export const BRICK_H = 2.4;
export const BRICK_LEAD = 10;
// Doormen: the door opens, DOORMEN_N walk out, at most DOORMEN_CAP of its own alive.
export const DOORMEN_WIND_MS = 800;
export const DOORMEN_N = 2;
export const DOORMEN_CAP = 2;
// The stomp: rearing STOMP_WIND_MS (it lifts STOMP_LIFT), then the wave and SHINGLE_N slates.
export const STOMP_WIND_MS = 950;
export const STOMP_LIFT = 2.4;
export const STOMP_REST_MS = 1300;
// How many picks a move sits out after it is used.
export const COOLDOWN = freeze({ doormen: 4, stomp: 2, bricks: 1 });
// Each move's weight by phase.
export const WEIGHTS = freeze({
shingles: freeze([3, 2.5, 2.5]),
carpet: freeze([3, 2.5, 2.5]),
pickets: freeze([3, 2.5, 2.5]),
bricks: freeze([0, 3, 3]),
doormen: freeze([0, 1.6, 1.6]),
stomp: freeze([0, 0, 3]),
});
// The retreat's clock, in ms of `b.t` after the kill.
export const FALSE_AT = 1400;
export const LAUGH_AT = 4300;
export const SINK_AT = 5600;
export const GONE_AT = 8200;
/* ------------------------------------------------------------ the windows */
// The run's windows for this room, kept across a life lost (a respawn makes a new
// boss object with the same hp). `share` is one window's hp.
function windowsOf(round, share) {
if (!round.marrow || round.marrow.room !== round.room) {
round.marrow = { room: round.room, windows: WINDOWS.map(([row, dx, up], id) => ({ id, row, dx, up, hp: share, state: "dark" })) };
}
return round.marrow.windows;
}
export const windowsOut = (round) => (round.marrow ? round.marrow.windows.filter((w) => w.state === "out").length : 0);
export const phaseOf = (round) => {
const out = windowsOut(round);
return out >= PHASE_OUT[1] ? 2 : out >= PHASE_OUT[0] ? 1 : 0;
};
// Lights `want` windows more among those dark and open, starting anywhere.
function lightMore(round, want, random) {
const left = round.marrow.windows.filter((w) => w.state !== "out");
// Nothing dark in an open row while some are left: every row opens.
const top = rowsOpen(left.length ? WINDOWS.length - left.length : 0);
let pool = left.filter((w) => w.state === "dark" && w.row <= top);
if (!pool.length && !left.some((w) => w.state === "lit")) pool = left.filter((w) => w.state === "dark");
for (let i = 0; i < want && pool.length; i++) {
const w = pool.splice(Math.floor(random() * pool.length) % pool.length, 1)[0];
w.state = "lit";
round.events.push({ type: "marrowLight", kind: "marrow", x: houseCenter(round.spec) + w.dx, y: round.boss.y + w.up });
}
}
// One set of windows out, another in: the shutters swing, in step with LIT_MS.
function changeLights(round, b, random) {
for (const w of round.marrow.windows) if (w.state === "lit") w.state = "dark";
lightMore(round, LIT_N[phaseOf(round)], random);
b.litMs = LIT_MS;
}
// A bolt across the front of the house: it strikes the first lit window at its
// height (the one nearest where it is), or flies on over the shutters. Returns
// true when it has hit one.
function windowShot(round, s, k) {
const b = round.boss;
if (!b || b.kind !== "marrow" || b.state !== "fight" || !round.marrow) return false;
const cx = houseCenter(round.spec);
for (const w of round.marrow.windows) {
if (w.state !== "lit" || Math.abs(s.x - (cx + w.dx)) > WINDOW_W / 2 + 0.3) continue;
if (Math.abs(s.y - (b.y + w.up + WINDOW_H / 2)) > WINDOW_H / 2 + 0.3) continue;
const dmg = Math.min(w.hp, Math.max(1, s.arm ? k.armBossDamage(round, s.bossDmg || 1) : 1));
w.hp -= dmg;
const out = w.hp <= 0;
if (out) {
w.state = "out";
b.relight = RELIGHT_MS;
round.events.push({ type: "marrowWindowOut", kind: "marrow", x: cx + w.dx, y: b.y + w.up + WINDOW_H / 2, left: round.marrow.windows.filter((q) => q.state !== "out").length });
}
k.hurtBoss(round, dmg, "weak");
return true;
}
return false;
}
/* ------------------------------------------------------------ the moves */
// Its next move: the carpet to open, then a weighted pick by phase that favors
// a change (a third time running is out), the slow moves sitting out COOLDOWN
// picks, the doormen only under their cap. `b.plan` forces one (tests).
export function pickMove(b, phase, random, adds = 0) {
let pick = null;
if (b.plan) {
pick = b.plan;
b.plan = null;
} else if (!b.picks) pick = "carpet";
else {
const w = {};
for (const [n, by] of Object.entries(WEIGHTS)) {
let v = by[phase];
if (b.cool && b.cool[n] > b.picks) v = 0;
if (n === "doormen" && adds >= DOORMEN_CAP) v = 0;
if (n === b.last) v *= b.streak >= 2 ? 0 : 0.35;
if (v > 0) w[n] = v;
}
const names = Object.keys(w);
let r = random() * names.reduce((sum, n) => sum + w[n], 0);
pick = names[0] || "carpet";
for (const n of names) {
pick = n;
if ((r -= w[n]) < 0) break;
}
}
b.picks = (b.picks || 0) + 1;
b.streak = pick === b.last ? (b.streak || 1) + 1 : 1;
b.last = pick;
if (COOLDOWN[pick]) b.cool = { ...(b.cool || {}), [pick]: b.picks + COOLDOWN[pick] + 1 };
return pick;
}
const doormenAlive = (round) => round.monsters.filter((m) => !m.dead && m.doorman).length;
const lawnRange = (spec, x) => clamp(x, spec.arena + 3, houseLeft(spec) - 2);
// Slates falling at `n` spots around x, the first where YOU stand: shadows first.
function dropShingles(round, b, n, wind) {
const spec = round.spec;
const you = round.you;
const ahead = Math.sign(you.vx) || you.face || 1;
const offs = [0, ahead, -ahead, ahead * 2, -ahead * 2];
const xs = [];
offs.slice(0, n).forEach((o, i) => {
const x = lawnRange(spec, you.x + o * SHINGLE_GAP);
if (xs.some((q) => Math.abs(q - x) < SHINGLE_W + 1)) return;
xs.push(x);
const warn = wind + SHINGLE_WARN_MS + i * SHINGLE_STAGGER_MS;
round.hazards.push({ kind: "marrowShingle", x, y: SHINGLE_TOP, w: SHINGLE_W, h: SHINGLE_H, floor: b.y, warn, full: warn, fall: 0, live: 0, cause: "marrowShingle", id: i });
});
return xs;
}
function startMove(round, b, move, k, wait) {
const you = round.you;
const spec = round.spec;
const phase = phaseOf(round);
const doorX = houseCenter(spec);
const ev = (type, extra = {}) => round.events.push({ type, kind: "marrow", x: doorX, y: b.y + 6, ...extra });
b.move = move;
if (move === "shingles") {
const xs = dropShingles(round, b, SHINGLE_N[phase], SHINGLE_WIND_MS);
b.act = "roof";
b.wait = SHINGLE_WIND_MS + SHINGLE_WARN_MS + SHINGLE_STAGGER_MS * Math.max(0, xs.length - 1) + SHINGLE_FALL_MS;
ev("marrowRoof", { y: b.y + 40, xs });
} else if (move === "carpet") {
b.act = "carpetWind";
b.twice = phase === 2;
b.wait = wait(CARPET_WIND_MS);
ev("marrowDoor");
} else if (move === "pickets") {
const ahead = Math.sign(you.vx) || you.face || 1;
const offs = [0, ahead, -ahead, ahead * 2].slice(0, PICKET_N[phase]);
const xs = [];
offs.forEach((o, i) => {
const x = lawnRange(spec, you.x + o * PICKET_GAP);
if (xs.some((q) => Math.abs(q - x) < PICKET_W + 1)) return;
xs.push(x);
const warn = PICKET_WIND_MS + PICKET_WARN_MS + i * PICKET_STAGGER_MS;
round.hazards.push({ kind: "marrowPicket", x, y: b.y, w: PICKET_W, h: PICKET_H, warn, full: warn, live: 0, cause: "marrowPicket", id: i });
});
b.act = "pickets";
b.wait = PICKET_WIND_MS + PICKET_WARN_MS + PICKET_STAGGER_MS * Math.max(0, xs.length - 1) + PICKET_UP_MS;
ev("marrowPicketWind", { xs, y: b.y });
} else if (move === "bricks") {
b.act = "brickWind";
b.wait = wait(BRICK_WIND_MS);
ev("marrowCough", { x: doorX + 9, y: b.y + 42 });
} else if (move === "doormen") {
b.act = "doormenWind";
b.wait = wait(DOORMEN_WIND_MS);
ev("marrowDoor");
} else if (move === "stomp") {
b.act = "stompWind";
b.wait = STOMP_WIND_MS;
b.windFull = STOMP_WIND_MS;
ev("marrowRear", { y: b.y + 20 });
}
}
// Where a brick lands: on the surface under `x` at YOUR height when one is there, else the ground.
function brickSpot(round, x, k) {
const spec = round.spec;
const you = round.you;
const ground = k.groundAt(spec, x);
if (you.state === "run" && you.shelf >= 0 && spec.shelves[you.shelf] && x >= spec.shelves[you.shelf][0] && x <= spec.shelves[you.shelf][1]) return you.y;
return ground;
}
function moveMarrow(round, b, ms, random, k) {
const spec = round.spec;
const phase = phaseOf(round);
const wait = (v) => (v * PHASE_PACE[phase]) / spec.pace;
const idle = () => wait(IDLE_MS * (1 - IDLE_JITTER + 2 * IDLE_JITTER * random()));
const doorX = houseCenter(spec);
if (!b.act) {
b.act = "idle";
b.wait = idle();
changeLights(round, b, random);
}
b.wait -= ms;
b.litMs -= ms;
// A window shot out: another lights a beat later. A set's time up: all change.
if (b.relight > 0 && (b.relight -= ms) <= 0) {
b.relight = 0;
const lit = round.marrow.windows.filter((w) => w.state === "lit").length;
lightMore(round, Math.max(0, LIT_N[phase] - lit), random);
}
if (b.litMs <= 0) changeLights(round, b, random);
// The door stays open through a wind-up and its rest.
b.mouth = b.act === "carpetWind" || b.act === "doormenWind" || b.act === "carpetRest";
b.lift = b.act === "stompWind" ? STOMP_LIFT * (1 - Math.max(0, b.wait) / b.windFull) : 0;
if (b.act === "idle") {
if (b.wait > 0) return;
const move = pickMove(b, phase, random, doormenAlive(round));
b.attacks++;
startMove(round, b, move, k, wait);
return;
}
if (b.wait > 0 && b.act !== "carpetRest") return;
if (b.act === "carpetWind") {
const x = houseLeft(spec) - 0.5;
round.waves.push({ x, y: b.y, dir: -1, life: 6000, kind: "marrowCarpet", cause: "marrowCarpet" });
round.events.push({ type: "marrowCarpet", kind: "marrow", x, y: b.y });
b.echo = b.twice ? wait(CARPET_GAP_MS) : 0;
b.act = "carpetRest";
b.wait = wait(CARPET_REST_MS);
return;
}
if (b.act === "carpetRest") {
if (b.echo > 0 && (b.echo -= ms) <= 0) {
b.echo = 0;
const x = houseLeft(spec) - 0.5;
round.waves.push({ x, y: b.y, dir: -1, life: 6000, kind: "marrowCarpet", cause: "marrowCarpet" });
round.events.push({ type: "marrowCarpet", kind: "marrow", x, y: b.y, echo: true });
}
if (b.wait > 0 || b.echo > 0) return;
b.act = "idle";
b.wait = idle();
return;
}
if (b.act === "brickWind") {
const you = round.you;
const ahead = (Math.sign(you.vx) || you.face || 1) * BRICK_LEAD;
const xs = [lawnRange(spec, you.x), lawnRange(spec, you.x + ahead)];
if (phase === 2) xs.push(lawnRange(spec, you.x - ahead));
const sx = doorX + 9;
const sy = b.y + 42;
xs.forEach((x, i) => {
if (xs.indexOf(x) !== i) return;
const y = brickSpot(round, x, k);
if (!Number.isFinite(y)) return;
round.hazards.push({ kind: "marrowBrick", x, y, w: BRICK_W, h: BRICK_H, warn: BRICK_FLY_MS, full: BRICK_FLY_MS, live: 0, sx, sy, cause: "marrowBrick" });
});
b.act = "idle";
b.wait = idle();
return;
}
if (b.act === "doormenWind") {
const n = Math.min(DOORMEN_N, DOORMEN_CAP - doormenAlive(round));
for (let i = 0; i < n; i++) {
const x = houseLeft(spec) - 1.5 - i * 4;
k.spawnMonster(round, "zombie", x, b.y, { doorman: true, force: true, door: true, rise: 300 });
}
round.events.push({ type: "marrowDoormen", kind: "marrow", x: houseLeft(spec), y: b.y, n });
b.act = "idle";
b.wait = idle();
return;
}
if (b.act === "stompWind") {
const x = houseLeft(spec) - 0.5;
round.waves.push({ x, y: b.y, dir: -1, life: 6000, kind: "marrowQuake", cause: "marrowQuake" });
round.events.push({ type: "marrowStomp", kind: "marrow", x, y: b.y });
dropShingles(round, b, SHINGLE_N[phase], 0);
b.act = "stompRest";
b.wait = wait(STOMP_REST_MS);
return;
}
if (b.act === "roof" || b.act === "pickets" || b.act === "stompRest") {
b.act = "idle";
b.wait = idle();
}
}
/* -------------------------------------------------------------- hazards */
// A slate: a shadow on the lawn for `warn`, then falling through everything to the floor.
function stepShingle(round, h, ms) {
if (h.warn > 0) {
h.warn = Math.max(0, h.warn - ms);
if (h.warn > 0) return true;
h.live = 1;
h.fall = 0;
return true;
}
h.fall += ms;
const p = Math.min(1, h.fall / SHINGLE_FALL_MS);
h.y = SHINGLE_TOP + (h.floor - SHINGLE_TOP) * p;
if (p < 1) return true;
round.events.push({ type: "marrowShingleLand", kind: "marrow", x: h.x, y: h.floor });
return false;
}
// A picket: a ripple for `warn`, then up out of the lawn for PICKET_UP_MS.
function stepPicket(round, h, ms) {
if (h.warn > 0) {
h.warn = Math.max(0, h.warn - ms);
if (h.warn > 0) return true;
h.live = PICKET_UP_MS;
round.events.push({ type: "marrowPicketUp", kind: "marrow", x: h.x, y: h.y });
return true;
}
h.live -= ms;
return h.live > 0;
}
// A brick: in the air for `warn`, then smashed and burning where it landed.
function stepBrick(round, h, ms) {
if (h.warn > 0) {
h.warn = Math.max(0, h.warn - ms);
if (h.warn > 0) return true;
h.live = BRICK_LIVE_MS;
round.events.push({ type: "marrowBrickLand", kind: "marrow", x: h.x, y: h.y });
return true;
}
h.live -= ms;
return h.live > 0;
}
/* --------------------------------------------------------- the stage's tick */
// The house in its place, its box out of the way (only the windows can be hit), YOU
// kept off its front until it has gone, and the retreat's beats by `b.t`.
function retreatStep(round, b) {
const stamp = (key, at, type, extra = {}) => {
if (b[key] || b.t < at) return;
b[key] = true;
round.events.push({ type, kind: "marrow", x: houseCenter(round.spec), y: b.y + 18, ...extra });
};
stamp("sagged", 0, "marrowSag");
stamp("falseWin", FALSE_AT, "marrowFalseWin");
stamp("laughed", LAUGH_AT, "marrowLaugh", { y: b.y + 40 });
stamp("sinking", SINK_AT, "marrowSink");
if (b.t >= GONE_AT && !b.gone) {
b.gone = true;
round.events.push({ type: "marrowGone", kind: "marrow", x: round.spec.door, y: b.y + 14 });
}
}
function marrowTick(round) {
const b = round.boss;
if (!b || b.kind !== "marrow") return;
const spec = round.spec;
if (!b.placed) {
const share = Math.max(1, Math.ceil(spec.bossHp / WINDOWS.length));
const windows = windowsOf(round, share);
b.placed = true;
b.max = share * WINDOWS.length;
// Fresh, it has all its hp; after a life lost, the windows' sum (what it had).
b.hp = windows.reduce((sum, w) => sum + Math.max(0, w.hp), 0);
b.x = spec.length - 0.75;
b.w = 1.5;
b.h = 2;
b.litMs = LIT_MS;
b.relight = 0;
}
if (b.state === "down") retreatStep(round, b);
const wall = houseLeft(spec) - WALL_GAP;
const you = round.you;
if (!b.gone && you.x > wall) {
you.x = wall;
if (you.vx > 0) you.vx = 0;
}
}
export const MARROW = freeze({
id: "marrow",
monsters: freeze({}),
walkers: freeze([]),
zombies: freeze([]),
stackers: freeze([]),
climbers: freeze([]),
act: freeze({}),
swoops: freeze({}),
solid: freeze({}),
move: freeze({}),
kill: freeze({}),
horde: freeze({}),
tick: freeze([marrowTick]),
target: windowShot,
bosses: BOSSES,
boss: freeze({ marrow: moveMarrow }),
// Only its windows can be hurt (windowShot): anything else glances off.
guard: freeze({ marrow: () => true }),
cause: freeze({ marrow: () => "marrow" }),
hazards: freeze({ marrowShingle: stepShingle, marrowPicket: stepPicket, marrowBrick: stepBrick }),
});
Loaded 100 of 160 files, more files were not shown because too many files have changed in this diff. Show more