mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Add Ghoul Rush's finale at Marrow Manor: the House's three kills, two rides and the ending
AI Assisted
This commit is contained in:
1 parent
d716e3c3f5
commit
e681d1f70d
56 files changed
+16585
-141
No files matched your search
@@ -0,0 +1,765 @@
|
||||
// Web console tests, Ghoul Rush's Bone Stair (the finale's second ride, between Kill II and the Pit): its shape (the spiral's flights and seams, every gap of missing treads clears with a jump and swallows YOU without one, every ribcage can be ducked, spacing, checkpoints, the last step over the Pit's floor), the run's speed (DOWN and LEFT slow YOU), every obstacle's cost and cause (missing treads, treads giving way, ribcages, skeletons, hands, masonry, the rubble), the telegraphs (shadows, creaks and cracks, fingers over the edge, skeletons rising), shooting skeletons down, the pursuit meter (the gap that clean running opens and hits, ducks and holds close), the catch, three hearts of its own, the grade and the dice, endless lives, the finish, no random numbers, its sounds and its drawing on a fake canvas, and bots that play it well and badly.
|
||||
// Run with: node --test scripts/test-web-console-activities-ghoul-bonestair.mjs
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
|
||||
import * as bs from "../src/web-console/public/activities/ghoul-rush/rides/bonestair/ghoul-bonestair.js";
|
||||
import { BONESTAIR_ROOM } from "../src/web-console/public/activities/ghoul-rush/rides/bonestair/ghoul-bonestair-room.js";
|
||||
import { ANSWERS, EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as STAIR_LOOKS, VOICES as STAIR_VOICES, telegraphMarks, telegraphs } from "../src/web-console/public/activities/ghoul-rush/rides/bonestair/ghoul-bonestair-draw.js";
|
||||
import * as ghoulSfx from "../src/web-console/public/activities/ghoul-rush/sfx/ghoul-sfx.js";
|
||||
import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
|
||||
import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-rush/core/ghoul-bonus.js";
|
||||
|
||||
const steady = () => 0.5;
|
||||
// The pack draws no random number: a run on this fails on the first draw.
|
||||
const never = () => {
|
||||
throw new Error("the stair drew a random number");
|
||||
};
|
||||
const events = (round, type) => round.events.filter((e) => e.type === type);
|
||||
|
||||
function through(round) {
|
||||
round.phase = "clear";
|
||||
round.phaseMs = 1;
|
||||
ghoul.advance(round, 4, steady);
|
||||
}
|
||||
|
||||
// A round on The Bone Stair reached the way a run reaches it: six stages behind it, on
|
||||
// through the finale's rooms before it; the clocks long, the bonus round on (three hearts).
|
||||
function stairRound(seed = 5) {
|
||||
const round = ghoul.newRound(seed);
|
||||
round.lives = 3;
|
||||
round.dice = 0;
|
||||
through(round);
|
||||
round.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES).map((st) => st.id);
|
||||
round.offer = null;
|
||||
for (let n = 0; n < 14 && round.spec.id !== "bonestair"; n++) through(round);
|
||||
assert.equal(round.spec.id, "bonestair");
|
||||
round.phase = "play";
|
||||
round.timeMs = 1e9;
|
||||
round.bonus = 1e9;
|
||||
round.events.length = 0;
|
||||
return round;
|
||||
}
|
||||
|
||||
const ROOM = ghoul.roomById("bonestair");
|
||||
const R = ROOM.ride;
|
||||
const F = R.flights;
|
||||
const floorOf = (x) => ghoul.groundAt(ROOM, x);
|
||||
const K = { HIT_W: ghoul.HIT_W, HIT_H: ghoul.HIT_H, DUCK_H: ghoul.DUCK_H };
|
||||
|
||||
const NONE = { runner: "bonestair", hearts: 3, time: 1e9, finish: 6020, top: [0, 20, 36], flights: [[20, 6020, 36, -600]], gaps: [], rot: [], ribs: [], skels: [], hands: [], stones: [], surge: [], checks: [] };
|
||||
// The same round over a stair of its own: one long flight to measure the run on (or `ride`'s).
|
||||
function synth(ride) {
|
||||
const round = stairRound();
|
||||
round.spec = { ...round.spec, start: 30, length: 7000, ground: [[0, 20, 36]], ride: { ...NONE, ...ride } };
|
||||
bs.BONESTAIR.place[0](round, {});
|
||||
return round;
|
||||
}
|
||||
// A gentle stair for the obstacle tests: one flight dropping a unit every ten.
|
||||
const GENTLE = [[20, 4020, 36, -364]];
|
||||
|
||||
// YOU on the stair at x, at speed v.
|
||||
function stairAt(round, x, { v = bs.RUN_V, safe = false } = {}) {
|
||||
const y = bs.stairY(round.spec.ride, x);
|
||||
assert.ok(y !== null, `the stair runs under ${x}`);
|
||||
Object.assign(round.you, { x, y, vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false });
|
||||
Object.assign(round.runner, { v, coyote: 0, heldMs: 0 });
|
||||
round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24));
|
||||
}
|
||||
|
||||
function run(round, ms, keys = {}, random = steady) {
|
||||
Object.assign(round.input, keys);
|
||||
for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random);
|
||||
for (const k of Object.keys(keys)) round.input[k] = typeof keys[k] === "number" ? 0 : false;
|
||||
}
|
||||
|
||||
function until(round, done, ms = 6000, random = steady) {
|
||||
let t = 0;
|
||||
for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random);
|
||||
return t;
|
||||
}
|
||||
|
||||
const press = (round) => {
|
||||
round.input.jump = ghoul.JUMP_BUFFER_MS;
|
||||
round.input.up = true;
|
||||
};
|
||||
|
||||
const heard = (e, extra = {}) => {
|
||||
const played = [];
|
||||
const noop = () => {};
|
||||
const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, ...extra };
|
||||
react({ x: 10, y: 6, tx: 20, ty: 6, ...e }, kit);
|
||||
return { played };
|
||||
};
|
||||
|
||||
// Where YOU, in the air at (x, y) going up at vy and across at v, come down: { x, y } on the
|
||||
// stair, or null for a fall through (the room's own geometry, gaps and the seams' lift).
|
||||
function flight(x, y, vy, v) {
|
||||
const dt = 0.004;
|
||||
for (let t = 0; t < 4; t += dt) {
|
||||
const px = x;
|
||||
let py = y;
|
||||
vy = Math.max(-ghoul.FALL_MAX, vy - bs.STAIR_G * dt);
|
||||
x += v * dt;
|
||||
y += vy * dt;
|
||||
for (const s of bs.seams(R)) if (px < s.x && x >= s.x) {
|
||||
y += s.rise;
|
||||
py += s.rise;
|
||||
}
|
||||
const line = bs.stairY(R, x);
|
||||
if (line === null) return null;
|
||||
const inGap = R.gaps.some(([a, b]) => x > a && x < b);
|
||||
if (vy <= 0 && !inGap && py >= line - bs.LAND_TOL && y <= line) return { x, y: line };
|
||||
if (y < line - bs.FALL_DEPTH) return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- the room */
|
||||
|
||||
test("Ghoul Rush's Bone Stair is the finale's second ride, between Kill II and the Pit: ready, lit, no key, no boss, no pickups, a bonus round of three hearts and about 30 seconds", () => {
|
||||
assert.equal(BONESTAIR_ROOM.ready, true);
|
||||
const rooms = ghoul.FINALE.rooms;
|
||||
assert.ok(rooms.includes("bonestair"));
|
||||
assert.ok(rooms.indexOf("bonestair") > rooms.indexOf("lawn"));
|
||||
if (rooms.includes("dollhouse")) assert.equal(rooms.indexOf("bonestair"), rooms.indexOf("dollhouse") + 1, "just after Kill II");
|
||||
if (rooms.includes("pit")) assert.equal(rooms.indexOf("pit"), rooms.indexOf("bonestair") + 1, "just before the Pit");
|
||||
assert.deepEqual([ROOM.title, ROOM.sub], ["The Bone Stair", "Every step down is someone"]);
|
||||
assert.equal(ROOM.dark, false);
|
||||
assert.equal(ROOM.key, null);
|
||||
assert.equal(ROOM.boss, null);
|
||||
assert.equal(ROOM.bonus, true);
|
||||
assert.equal(R.runner, "bonestair");
|
||||
assert.equal(R.hearts, 3, "three hearts, not five");
|
||||
assert.equal(typeof ghoul.ROOM_MUSIC.bonestair, "string", "a track (borrowed until its own is voted)");
|
||||
assert.deepEqual(Object.keys(bs.BONESTAIR.monsters), []);
|
||||
assert.equal(LOOKS.bonestair, STAIR_LOOKS.bonestair);
|
||||
assert.equal(LOOKS.bonestair.pack, "bonestair");
|
||||
assert.ok(Object.isFrozen(R) && Object.isFrozen(R.flights) && Object.isFrozen(R.flights[0]) && Object.isFrozen(R.ribs[0]), "frozen all the way down");
|
||||
assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0, "no monsters: the stair's things are the pack's own");
|
||||
assert.deepEqual([ROOM.candy.length, ROOM.items.length], [0, 0], "no pickups");
|
||||
// The ground: the cellar landing at the start and the Pit's floor at the end only.
|
||||
assert.equal(ROOM.ground.length, 2);
|
||||
assert.deepEqual([...ROOM.ground[0]], [...R.top]);
|
||||
assert.equal(ROOM.ground[1][0], R.finish, "the Pit's floor starts under the last step");
|
||||
assert.ok(ROOM.ground[1][2] < F.at(-1)[3] - 8, "a real drop off the last step");
|
||||
assert.ok(ROOM.door > R.finish + 20 && ROOM.door > ROOM.length - 14, "the door at the room's end, out on the Pit's floor");
|
||||
assert.ok(floorOf(ROOM.door - 2) > -Infinity);
|
||||
// About 30 seconds at a clean run, on a clock that holds it comfortably (the game's ride rule: 70 to 120 s).
|
||||
const secs = (R.finish - ROOM.start) / bs.RUN_V;
|
||||
assert.ok(secs >= 26 && secs <= 34, `${secs.toFixed(1)} s at RUN_V`);
|
||||
assert.equal(ghoul.timeFor(ghoul.roomFor("bonestair")), R.time);
|
||||
assert.ok(R.time >= 70000 && R.time <= 120000);
|
||||
assert.deepEqual([R.gaps.length, R.rot.length, R.ribs.length, R.skels.length, R.hands.length, R.stones.length], [4, 3, 3, 4, 3, 3], "gaps, give-ways, ribcages, skeletons, hands, masonry");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: the spiral is a run of flights, each starting where the last ended, high again; crossing a seam lifts YOU by the flight's height and the field never runs out going down", () => {
|
||||
assert.equal(F[0][0], R.top[1], "the first flight starts at the landing's end");
|
||||
assert.equal(F[0][2], R.top[2], "level with it");
|
||||
for (let i = 0; i < F.length; i++) {
|
||||
const [x0, x1, y0, y1] = F[i];
|
||||
assert.ok(x1 > x0 && y1 < y0, `flight ${i} goes down`);
|
||||
assert.ok(y0 < ghoul.FIELD_H - 12 && y1 > 10, `flight ${i} stays on the field (${y0} to ${y1})`);
|
||||
const slope = (y1 - y0) / (x1 - x0);
|
||||
assert.ok(slope > -0.2 && slope < -0.1, `flight ${i}'s slope ${slope.toFixed(3)}`);
|
||||
if (i) assert.equal(x0, F[i - 1][1], "no hole at a seam");
|
||||
}
|
||||
assert.equal(F.at(-1)[1], R.finish);
|
||||
const seams = bs.seams(R);
|
||||
assert.equal(seams.length, F.length - 1);
|
||||
for (const s of seams) assert.ok(s.rise > 15, "high again");
|
||||
// Running across a seam on the treads.
|
||||
const round = stairRound();
|
||||
const sx = F[0][1];
|
||||
stairAt(round, sx - 6, { safe: true });
|
||||
run(round, 300);
|
||||
assert.ok(round.you.x > sx);
|
||||
assert.ok(Math.abs(round.you.y - bs.stairY(R, round.you.x)) < 1e-6, "on the next flight's treads");
|
||||
assert.ok(round.you.y > F[1][2] - 3, "high again");
|
||||
assert.equal(events(round, "stairTurn").length, 1);
|
||||
assert.equal(round.runner.flight, 1);
|
||||
// And in the air: a jump just before a seam lands on the next flight.
|
||||
const air = stairRound();
|
||||
stairAt(air, sx - 8, { safe: true });
|
||||
press(air);
|
||||
until(air, () => air.you.state === "air", 200);
|
||||
until(air, () => air.you.state === "run", 2000);
|
||||
assert.ok(air.you.x > sx && Math.abs(air.you.y - bs.stairY(R, air.you.x)) < 1e-6, "landed round the column");
|
||||
// A bolt winds round with YOU.
|
||||
const shot = stairRound();
|
||||
stairAt(shot, sx - 14, { safe: true });
|
||||
shot.input.fire = true;
|
||||
run(shot, 30);
|
||||
shot.input.fire = false;
|
||||
const s = shot.shots[0];
|
||||
assert.ok(s, "a bolt");
|
||||
until(shot, () => s.x > sx + 10, 600);
|
||||
assert.ok(Math.abs(s.y - (bs.stairY(R, s.x) + ghoul.SHOT_Y)) < 1.2, `the bolt flies along the next flight (${s.y.toFixed(1)} over ${bs.stairY(R, s.x).toFixed(1)})`);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: every stretch of missing treads clears with a jump at its edge or a few units early (at a run or a duck's speed), and running off it without one is a fall", () => {
|
||||
for (const [x0, x1] of R.gaps) {
|
||||
const w = x1 - x0;
|
||||
assert.ok(w >= 6 && w <= 9, `a gap at ${x0} is ${w} wide`);
|
||||
assert.equal(bs.flightAt(R, x0), bs.flightAt(R, x1), "inside one flight");
|
||||
// Off the edge with no jump.
|
||||
assert.equal(flight(x0, bs.stairY(R, x0), bs.slopeAt(R, x0) * bs.RUN_V, bs.RUN_V), null, `no jump at ${x0}`);
|
||||
for (const v of [bs.DUCK_V, bs.RUN_V]) {
|
||||
for (const early of [0, 3, 6]) {
|
||||
const x = x0 - early;
|
||||
const land = flight(x, bs.stairY(R, x), bs.STAIR_JUMP_V, v);
|
||||
assert.ok(land && land.x > x1, `a jump ${early} early at ${v} clears the gap at ${x0}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// In play: a fall costs a heart (cause "stairGap") and puts YOU back on the treads past it.
|
||||
const round = stairRound();
|
||||
const [x0, x1] = R.gaps[0];
|
||||
stairAt(round, x0 - 6);
|
||||
until(round, () => events(round, "lose").length > 0, 2000);
|
||||
assert.equal(events(round, "lose")[0].cause, "stairGap");
|
||||
assert.equal(round.bonusRound.hearts, 2);
|
||||
assert.equal(round.phase, "play", "the run goes on");
|
||||
assert.ok(round.you.x > x1 && round.you.state === "run", "back on the treads past it");
|
||||
assert.equal(events(round, "stairDrop").length, 1);
|
||||
// A jump clears it in play.
|
||||
const ok = stairRound();
|
||||
stairAt(ok, x0 - 4);
|
||||
press(ok);
|
||||
until(ok, () => ok.you.x > x1 + 4, 2000);
|
||||
assert.equal(events(ok, "lose").length, 0);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: every ribcage's underside sits between a ducked box and a standing one along its width; ducking passes, standing is a heart (cause \"stairRib\"); ducking slows YOU", () => {
|
||||
for (const [x, under] of R.ribs) {
|
||||
const hi = bs.stairY(R, x - bs.RIB_W / 2 - K.HIT_W / 2);
|
||||
const lo = bs.stairY(R, x + bs.RIB_W / 2 + K.HIT_W / 2);
|
||||
assert.ok(hi + K.DUCK_H < under, `a ducked box clears the ribcage at ${x}`);
|
||||
assert.ok(lo + K.HIT_H > under, `a standing box hits the ribcage at ${x}`);
|
||||
}
|
||||
const [x] = R.ribs[0];
|
||||
const stand = stairRound();
|
||||
stairAt(stand, x - 10);
|
||||
until(stand, () => events(stand, "lose").length > 0, 1000);
|
||||
assert.equal(events(stand, "lose")[0].cause, "stairRib");
|
||||
const duck = stairRound();
|
||||
stairAt(duck, x - 8);
|
||||
duck.input.down = true;
|
||||
until(duck, () => duck.you.x > x + 6, 2000);
|
||||
duck.input.down = false;
|
||||
assert.equal(events(duck, "lose").length, 0);
|
||||
assert.ok(duck.runner.v < bs.RUN_V - 4, "a duck slows YOU");
|
||||
// And the speeds.
|
||||
const s = synth({ flights: GENTLE });
|
||||
run(s, 1500, { down: true });
|
||||
assert.ok(Math.abs(s.runner.v - bs.DUCK_V) < 1);
|
||||
run(s, 1500, { left: true });
|
||||
assert.ok(Math.abs(s.runner.v - bs.HOLD_V) < 1, "LEFT holds back");
|
||||
run(s, 2500);
|
||||
assert.ok(Math.abs(s.runner.v - bs.RUN_V) < 1, "back up to a run");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: masonry warns first (a shadow, a creak at once, a crack halfway, more than a second in all), lands ahead of a runner, and lies as a pile to jump; under it, or into the pile, is a heart (cause \"stairStone\")", () => {
|
||||
assert.ok(bs.STONE_MS >= 1200, "a long, clear warning");
|
||||
const round = synth({ flights: GENTLE, stones: [[300]] });
|
||||
stairAt(round, 200, { safe: true });
|
||||
until(round, () => events(round, "stairCreak").length > 0, 2000);
|
||||
const at = round.you.x;
|
||||
assert.ok(300 - at <= bs.STONE_NEAR && 300 - at > bs.STONE_NEAR - 2);
|
||||
assert.equal(round.runner.stones[0].state, "warn");
|
||||
until(round, () => events(round, "stairCrack").length > 0, 2000);
|
||||
assert.ok(Math.abs(round.runner.stones[0].t - bs.STONE_MS / 2) < 20, "the crack halfway");
|
||||
until(round, () => events(round, "stairThud").length > 0, 2000);
|
||||
assert.equal(round.runner.stones[0].state, "pile");
|
||||
assert.ok(300 - round.you.x > 10, `it lands ahead of a runner (${(300 - round.you.x).toFixed(1)} short)`);
|
||||
// Into the pile: a heart.
|
||||
round.you.safeMs = 0;
|
||||
until(round, () => events(round, "lose").length > 0, 1000);
|
||||
assert.equal(events(round, "lose")[0].cause, "stairStone");
|
||||
// Jumped: clean.
|
||||
const ok = synth({ flights: GENTLE, stones: [[300]] });
|
||||
stairAt(ok, 200);
|
||||
until(ok, () => ok.runner.stones[0].state === "pile", 3000);
|
||||
until(ok, () => 300 - ok.you.x < 8, 1000);
|
||||
press(ok);
|
||||
until(ok, () => ok.you.x > 306, 1000);
|
||||
assert.equal(events(ok, "lose").length, 0);
|
||||
// Under it as it lands: a heart.
|
||||
const under = synth({ flights: GENTLE, stones: [[300]] });
|
||||
stairAt(under, 200);
|
||||
until(under, () => under.runner.stones[0].state === "warn" && under.runner.stones[0].t < 200, 3000);
|
||||
stairAt(under, 299.5, { v: 0 });
|
||||
under.runner.heldMs = 1e9;
|
||||
until(under, () => events(under, "lose").length > 0, 2000);
|
||||
assert.equal(events(under, "lose")[0].cause, "stairStone");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: a bone hand's fingers creep over the edge first (HAND_WARN_MS), then it grabs; a jump clears it, a grab is a heart (cause \"stairHand\") and holds YOU still a moment", () => {
|
||||
assert.ok(bs.HAND_WARN_MS >= 700);
|
||||
const round = synth({ flights: GENTLE, hands: [[300]] });
|
||||
stairAt(round, 220);
|
||||
until(round, () => events(round, "stairReach").length > 0, 3000);
|
||||
assert.ok(300 - round.you.x <= bs.HAND_NEAR);
|
||||
until(round, () => events(round, "stairGrab").length > 0, 2000);
|
||||
assert.ok(300 - round.you.x > 10, "it grabs ahead of YOU, in plain sight");
|
||||
until(round, () => events(round, "lose").length > 0, 1000);
|
||||
assert.equal(events(round, "lose")[0].cause, "stairHand");
|
||||
assert.equal(round.runner.heldMs > 0 || round.runner.v < 1, true, "held");
|
||||
const x = round.you.x;
|
||||
run(round, bs.HELD_MS - 40);
|
||||
assert.ok(Math.abs(round.you.x - x) < 0.01, "still while held");
|
||||
run(round, 400);
|
||||
assert.ok(round.you.x > x + 2, "and off again");
|
||||
// Jumped.
|
||||
const ok = synth({ flights: GENTLE, hands: [[300]] });
|
||||
stairAt(ok, 220);
|
||||
until(ok, () => 300 - ok.you.x < 7, 3000);
|
||||
press(ok);
|
||||
until(ok, () => ok.you.x > 306, 1000);
|
||||
assert.equal(events(ok, "lose").length, 0);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: a skeleton rises over the treads first, then climbs up at YOU; SKEL_HP bolts knock it down (an act, points, a little ground back), and running into it is a heart (cause \"stairSkel\")", () => {
|
||||
const round = synth({ flights: GENTLE, skels: [[300]] });
|
||||
stairAt(round, 200);
|
||||
until(round, () => events(round, "stairRise").length > 0, 3000);
|
||||
assert.ok(300 - round.you.x <= bs.SKEL_NEAR);
|
||||
assert.equal(round.runner.skels[0].state, "rise");
|
||||
until(round, () => round.runner.skels[0].state === "climb", 2000);
|
||||
const x0 = round.runner.skels[0].x;
|
||||
run(round, 200);
|
||||
assert.ok(round.runner.skels[0].x < x0, "climbing up the stair at YOU");
|
||||
until(round, () => events(round, "lose").length > 0, 2000);
|
||||
assert.equal(events(round, "lose")[0].cause, "stairSkel");
|
||||
assert.equal(round.runner.skels[0].state, "smashed");
|
||||
// Shot down.
|
||||
const shot = synth({ flights: GENTLE, skels: [[300]] });
|
||||
stairAt(shot, 200);
|
||||
shot.input.fire = true;
|
||||
until(shot, () => shot.runner.skels[0].state === "down" || events(shot, "lose").length > 0, 3000);
|
||||
assert.equal(shot.runner.skels[0].state, "down");
|
||||
assert.equal(events(shot, "stairSkelHit").length, bs.SKEL_HP - 1);
|
||||
assert.equal(events(shot, "stairSkelDown").length, 1);
|
||||
assert.equal(shot.bonusRound.perf.acts, 1);
|
||||
assert.ok(shot.score >= bs.SKEL_POINTS);
|
||||
until(shot, () => shot.you.x > 310, 2000);
|
||||
assert.equal(events(shot, "lose").length, 0);
|
||||
// A waiting skeleton takes no bolt.
|
||||
const early = synth({ flights: GENTLE, skels: [[300]] });
|
||||
assert.equal(bs.BONESTAIR.target(early, { x: 300, y: bs.stairY(early.spec.ride, 300) + 2 }), false);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: treads that give way start crumbling once YOU are in, at a speed between a duck and a run: a runner outruns it, a ducker drops through (cause \"stairGive\") and is put back past the stretch", () => {
|
||||
assert.ok(bs.ROT_V > bs.DUCK_V && bs.ROT_V > bs.HOLD_V && bs.ROT_V < bs.RUN_V);
|
||||
for (const [x0, x1] of R.rot) {
|
||||
assert.ok(x1 - x0 >= 30, "long enough to matter");
|
||||
assert.equal(bs.flightAt(R, x0), bs.flightAt(R, x1), "inside one flight");
|
||||
for (const [a, b] of R.gaps) if (a > x0 && b < x1) assert.ok(a - x0 > 15 && x1 - b > 15, "a gap inside one is well clear of its ends");
|
||||
}
|
||||
const runner = synth({ flights: GENTLE, rot: [[200, 260]] });
|
||||
stairAt(runner, 180);
|
||||
until(runner, () => runner.you.x > 270, 3000);
|
||||
assert.equal(events(runner, "stairRot").length, 1);
|
||||
assert.equal(events(runner, "lose").length, 0, "outrun");
|
||||
const ducker = synth({ flights: GENTLE, rot: [[200, 260]] });
|
||||
stairAt(ducker, 180);
|
||||
ducker.input.down = true;
|
||||
until(ducker, () => events(ducker, "lose").length > 0, 4000);
|
||||
ducker.input.down = false;
|
||||
assert.equal(events(ducker, "lose")[0].cause, "stairGive");
|
||||
assert.ok(ducker.you.x > 260 && ducker.you.state === "run", "back on the treads past it");
|
||||
// Blinking safe after a heart, it waits behind YOU.
|
||||
const safe = synth({ flights: GENTLE, rot: [[200, 260]] });
|
||||
stairAt(safe, 180, { safe: true });
|
||||
safe.input.down = true;
|
||||
until(safe, () => safe.you.x > 262, 6000);
|
||||
safe.input.down = false;
|
||||
assert.equal(events(safe, "lose").length, 0);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: the rubble behind gains on a duck or a hold and loses to a clean run; at CATCH_GAP it has YOU (a heart, cause \"stairRubble\") and falls back; a hit shoves it closer", () => {
|
||||
const s = synth({ flights: GENTLE });
|
||||
assert.equal(s.runner.gap, bs.GAP_START);
|
||||
run(s, 3000);
|
||||
assert.ok(s.runner.gap > bs.GAP_START, "a clean run wins ground");
|
||||
assert.ok(s.runner.gap <= bs.GAP_MAX);
|
||||
const d = synth({ flights: GENTLE });
|
||||
const g0 = d.runner.gap;
|
||||
run(d, 1000, { down: true });
|
||||
assert.ok(d.runner.gap < g0, "a duck loses ground");
|
||||
const caught = synth({ flights: GENTLE });
|
||||
caught.input.left = true;
|
||||
until(caught, () => events(caught, "lose").length > 0, 10000);
|
||||
caught.input.left = false;
|
||||
assert.equal(events(caught, "lose")[0].cause, "stairRubble");
|
||||
assert.equal(events(caught, "stairCatch").length, 1);
|
||||
assert.equal(caught.runner.gap, bs.GAP_RESET);
|
||||
assert.ok(events(caught, "stairClose").length >= 1, "a warning before it");
|
||||
const hit = synth({ flights: GENTLE, ribs: [[200, bs.stairY({ ...NONE, flights: GENTLE }, 197) + 3]] });
|
||||
stairAt(hit, 190);
|
||||
const before = hit.runner.gap;
|
||||
until(hit, () => events(hit, "lose").length > 0, 1000);
|
||||
assert.ok(hit.runner.gap < before - bs.HIT_CLOSE + 1, "the hit lets it closer");
|
||||
assert.ok(hit.runner.v <= bs.STUMBLE_V, "and YOU stumble");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: checkpoints are passed, and running off the last step drops YOU onto the Pit's floor: the run is over, the way out open, and YOU walk to the door", () => {
|
||||
const round = stairRound();
|
||||
stairAt(round, R.checks[0] - 4, { safe: true });
|
||||
run(round, 300);
|
||||
assert.equal(round.runner.check, 0);
|
||||
assert.equal(events(round, "stairCheck").length, 1);
|
||||
const end = stairRound();
|
||||
stairAt(end, R.finish - 6, { safe: true });
|
||||
until(end, () => end.runner.done, 3000);
|
||||
assert.equal(events(end, "stairEdge").length, 1);
|
||||
assert.equal(events(end, "stairFinish").length, 1);
|
||||
assert.equal(end.hasKey, true);
|
||||
assert.equal(end.you.y, floorOf(end.you.x));
|
||||
assert.ok(end.you.x > R.finish && end.you.x < ROOM.door);
|
||||
end.input.right = true;
|
||||
until(end, () => end.phase !== "play", 4000);
|
||||
assert.equal(end.phase, "clear");
|
||||
assert.equal(end.bonusRound.won, true);
|
||||
assert.ok(end.bonusRound.dice >= BONUS_FLOOR);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: no random number is drawn in the room (20 seconds of running, jumping, ducking and shooting, on a draw that throws)", () => {
|
||||
const r = stairRound();
|
||||
for (let t = 0; t < 20000; t += 16) {
|
||||
r.input.fire = t % 4000 < 1500;
|
||||
r.input.down = t % 3000 < 300;
|
||||
if (t % 1700 < 20) press(r);
|
||||
r.you.safeMs = 1e9;
|
||||
ghoul.advance(r, 16, never);
|
||||
r.events.length = 0;
|
||||
}
|
||||
assert.ok(r.you.x > 500);
|
||||
assert.equal(r.runner.id, "bonestair");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair's grade: three hearts pay at most one die for hearts, every skeleton shot is the acts die, the rubble kept far is the steady die", () => {
|
||||
const full = stairRound();
|
||||
const b = full.bonusRound;
|
||||
assert.equal(b.max, 3);
|
||||
assert.equal(b.hearts, 3);
|
||||
assert.equal(b.perf.goal, R.skels.length);
|
||||
assert.equal(b.perf.total, R.gaps.length + R.rot.length + R.ribs.length + R.skels.length + R.hands.length + R.stones.length);
|
||||
const mk = (hearts, hits, acts, steadyDie) => {
|
||||
const bb = makeBonus({ stats: { kills: 0 }, spec: { ride: R } });
|
||||
bb.hearts = hearts;
|
||||
bb.perf = { total: 20, hits: Array.from({ length: hits }, (_, i) => `x${i}`), acts, goal: R.skels.length, steady: steadyDie, kills0: 0 };
|
||||
return diceFor(bb, 0);
|
||||
};
|
||||
assert.equal(mk(3, 0, R.skels.length, true), 8, "a perfect run");
|
||||
assert.equal(mk(3, 0, R.skels.length - 1, true), 7, "a skeleton missed");
|
||||
assert.equal(mk(1, 3, 0, false), 5);
|
||||
const s = synth({ flights: GENTLE });
|
||||
s.runner.gap = 8;
|
||||
s.runner.gapMs = 20000;
|
||||
s.runner.gapSum = 8 * 20000;
|
||||
run(s, 100);
|
||||
assert.equal(s.bonusRound.perf.steady, false, "the rubble stayed close");
|
||||
const t = synth({ flights: GENTLE });
|
||||
run(t, 3000);
|
||||
assert.equal(t.bonusRound.perf.steady, true);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: endless lives (round.infinite) spare the hearts for every cause, the Garlic shield takes a hit instead of a heart", () => {
|
||||
const r = stairRound();
|
||||
r.infinite = true;
|
||||
stairAt(r, R.gaps[0][0] - 6);
|
||||
until(r, () => events(r, "lose").length > 0, 2000);
|
||||
assert.equal(r.bonusRound.hearts, 3);
|
||||
assert.equal(events(r, "lose")[0].cause, "stairGap");
|
||||
assert.equal(r.phase, "play");
|
||||
const m = synth({ flights: GENTLE });
|
||||
m.infinite = true;
|
||||
m.input.left = true;
|
||||
until(m, () => m.runner.catches > 0, 10000);
|
||||
assert.equal(m.bonusRound.hearts, 3);
|
||||
const g = synth({ flights: GENTLE, ribs: [[200, bs.stairY({ ...NONE, flights: GENTLE }, 197) + 3]] });
|
||||
g.you.garlic = true;
|
||||
stairAt(g, 190);
|
||||
until(g, () => !g.you.garlic, 1000);
|
||||
assert.equal(g.bonusRound.hearts, 3);
|
||||
});
|
||||
|
||||
/* ----------------------------------------------------------- sound, names */
|
||||
|
||||
test("Ghoul Rush's Bone Stair: every event has a voice that plays, every cause has words and a sound, every tone exists and is short", () => {
|
||||
assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...bs.EVENTS].sort(), "a voice for every event and no more");
|
||||
const tones = ghoulSfx.default.tones;
|
||||
for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) {
|
||||
const name = STAIR_VOICES[kind] && STAIR_VOICES[kind][act];
|
||||
assert.ok(name, `${event} has a ${kind}.${act} voice`);
|
||||
assert.ok(tones[name], `${name} exists`);
|
||||
assert.equal(VOICES[kind][act], name, "joined to the game's voices");
|
||||
assert.ok(heard({ type: event, n: 0, points: 50, cause: "stairGap" }).played.includes(name), `${event} plays ${name}`);
|
||||
}
|
||||
for (const cause of bs.CAUSES) {
|
||||
assert.ok(LOSE_WORDS[cause], `${cause} has words`);
|
||||
assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3, `${cause} has a sound`);
|
||||
assert.ok(tones[LOSE_SOUNDS[cause][0]] || ["thud", "crunch"].includes(LOSE_SOUNDS[cause][0]), `${cause}'s sound is a tone`);
|
||||
assert.ok(heard({ type: "lose", cause, hearts: 2 }).played.length > 0, `${cause} sounds`);
|
||||
}
|
||||
for (const name of Object.keys(tones).filter((n) => n.startsWith("ghoulStair"))) {
|
||||
const layers = tones[name].layers;
|
||||
assert.ok(Math.max(...layers.map((l) => (l.delay || 0) + l.seconds)) <= 1.2, `${name} is short`);
|
||||
for (const l of layers) assert.ok(l.gain > 0 && l.gain <= 1);
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: its names are its own (every event, cause and tone starts with its prefix), and it keeps to the shared ride slot", () => {
|
||||
for (const e of bs.EVENTS) assert.ok(e.startsWith("stair"), e);
|
||||
for (const c of bs.CAUSES) assert.ok(c.startsWith("stair"), c);
|
||||
for (const kind of Object.keys(STAIR_VOICES)) for (const name of Object.values(STAIR_VOICES[kind])) assert.ok(name.startsWith("ghoulStair"), name);
|
||||
assert.deepEqual(Object.keys(bs.BONESTAIR).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []);
|
||||
const r = stairRound();
|
||||
assert.equal(r.runner.id, "bonestair");
|
||||
assert.ok(!("bonestair" in r));
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ telegraphs */
|
||||
|
||||
test("Ghoul Rush's Bone Stair telegraphs: JUMP over gaps, hands and masonry, DUCK over ribcages, SHOOT over skeletons, RUN where the treads will give way, words on the first three of each kind, seen from afar, the same every time", () => {
|
||||
const marks = telegraphMarks(R);
|
||||
assert.equal(marks.length, R.gaps.length + R.rot.length + R.ribs.length + R.skels.length + R.hands.length + R.stones.length, "one per thing");
|
||||
for (const m of marks) assert.equal(m.answer, ANSWERS[m.kind], m.kind);
|
||||
assert.deepEqual(ANSWERS, { gap: "JUMP", hand: "JUMP", stone: "JUMP", rib: "DUCK", skel: "SHOOT", rot: "RUN" });
|
||||
const m = marks.find((q) => q.kind === "rib");
|
||||
const alphaOf = (x) => (telegraphs(R, x).find((t) => t.kind === "rib" && t.lead === m.lead) || { alpha: 0 }).alpha;
|
||||
assert.equal(alphaOf(m.lead - 45), 0, "not yet");
|
||||
assert.ok(alphaOf(m.lead - 36) > 0 && alphaOf(m.lead - 36) < 1, "fading in");
|
||||
assert.equal(alphaOf(m.lead - 20), 1);
|
||||
assert.equal(alphaOf(m.lead + 7), 0, "gone once passed");
|
||||
const sk = marks.find((q) => q.kind === "skel");
|
||||
assert.ok(telegraphs(R, sk.lead - 55).some((q) => q.lead === sk.lead && q.alpha > 0.5), "a skeleton seen from further");
|
||||
assert.deepEqual(telegraphs(R, m.lead - 33), telegraphs(R, m.lead - 33), "deterministic");
|
||||
for (const kind of Object.keys(ANSWERS)) {
|
||||
const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead);
|
||||
of.forEach((q, i) => {
|
||||
assert.equal(q.n, i);
|
||||
const shown = telegraphs(R, q.lead - 30).find((s) => s.lead === q.lead);
|
||||
assert.equal(shown.words, i < 3, `${kind} ${i}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: every thing sits on the treads, clear of the seams (none within 14 before one or 20 after), and spaced for a player", () => {
|
||||
const seams = bs.seams(R).map((s) => s.x);
|
||||
const things = [...R.gaps.map(([a, b]) => [a, b]), ...R.ribs.map(([x]) => [x - bs.RIB_W / 2, x + bs.RIB_W / 2]), ...R.hands.map(([x]) => [x, x]), ...R.stones.map(([x]) => [x, x]), ...R.rot.map(([a, b]) => [a, b])];
|
||||
for (const [a, b] of things) {
|
||||
assert.ok(bs.stairY(R, a) !== null && bs.stairY(R, b) !== null && a > F[0][0] && b < R.finish - 8);
|
||||
for (const s of seams) assert.ok(b < s - 14 || a > s + 20, `${a} to ${b} is clear of the seam at ${s}`);
|
||||
}
|
||||
for (const [x] of R.skels) for (const s of seams) assert.ok(x < s - 14 || x > s + 30, `a skeleton at ${x} has room to climb from the seam at ${s}`);
|
||||
const xs = [...R.gaps.map(([a]) => a), ...R.ribs.map(([x]) => x), ...R.hands.map(([x]) => x), ...R.stones.map(([x]) => x), ...R.skels.map(([x]) => x)].sort((p, q) => p - q);
|
||||
for (let i = 0; i + 1 < xs.length; i++) assert.ok(xs[i + 1] - xs[i] >= 22, `${xs[i]} and ${xs[i + 1]} are ${xs[i + 1] - xs[i]} apart`);
|
||||
for (const x of R.checks) for (const [a, b] of things) assert.ok(x < a - 10 || x > b + 10, `a checkpoint at ${x} is clear`);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair's intro banner says the controls plainly", () => {
|
||||
assert.match(R.how, /UP jump, DOWN duck/);
|
||||
assert.match(R.how, /SPACE to shoot/);
|
||||
assert.match(R.how, /YOU/);
|
||||
});
|
||||
|
||||
/* --------------------------------------------------------------- drawing */
|
||||
|
||||
test("Ghoul Rush's Bone Stair draws: the stair, each thing in each state, a seam, the rubble far and close, a crash, the last step and the floor, the result card, and the stage select straight into it", () => {
|
||||
const ctx = new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) });
|
||||
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
|
||||
g.resize(900, 900);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
const r = g.round;
|
||||
through(r);
|
||||
r.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES).map((st) => st.id);
|
||||
r.offer = null;
|
||||
for (let n = 0; n < 14 && r.spec.id !== "bonestair"; n++) through(r);
|
||||
r.lives = 99;
|
||||
const spots = [ROOM.start + 4, R.gaps[0][0] - 8, R.ribs[0][0] - 6, R.hands[0][0] - 20, R.stones[0][0] - 30, R.skels[0][0] - 30, R.rot[0][0] + 10, F[0][1] - 1, F[0][1] + 6, R.checks[0], R.finish - 10];
|
||||
for (const dark of [true, false]) {
|
||||
for (const x of spots) {
|
||||
r.dark = dark;
|
||||
r.phase = "play";
|
||||
stairAt(r, x, { safe: true });
|
||||
r.runner.hands = r.runner.hands.map((h, i) => ({ state: ["reach", "grab", "hold", "wait"][i % 4], t: 300 }));
|
||||
r.runner.stones = r.runner.stones.map((s, i) => ({ state: ["warn", "pile", "warn"][i % 3], t: i === 2 ? 100 : 700, cracked: true }));
|
||||
r.runner.skels = r.runner.skels.map((s, i) => ({ state: ["rise", "climb", "down", "wait"][i % 4], t: 300, x: R.skels[i][0] - 3, hp: 2 }));
|
||||
r.runner.rot = r.runner.rot.map((q, i) => (i === 0 ? { state: "go", front: R.rot[0][0] + 6 } : q));
|
||||
for (const gap of [24, 6]) {
|
||||
r.runner.gap = gap;
|
||||
r.runner.close = gap < bs.CLOSE_ON;
|
||||
r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: -10, gone: 0 });
|
||||
for (let k = 0; k < 3; k++) g.tick(16);
|
||||
stairAt(r, x, { safe: true });
|
||||
}
|
||||
r.you.ducking = true;
|
||||
g.tick(16);
|
||||
Object.assign(r.you, { state: "air", vy: 10, y: r.you.y + 3, ducking: false });
|
||||
g.tick(16);
|
||||
}
|
||||
}
|
||||
assert.equal(r.spec.id, "bonestair");
|
||||
// A crash.
|
||||
r.you.safeMs = 0;
|
||||
r.runner.hands = r.runner.hands.map(() => ({ state: "wait", t: 0 }));
|
||||
stairAt(r, R.ribs[0][0] - 8);
|
||||
for (let k = 0; k < 60; k++) g.tick(16);
|
||||
assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too");
|
||||
// Down on the Pit's floor, and the card.
|
||||
const done = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
|
||||
done.resize(900, 900);
|
||||
done.key("action");
|
||||
done.tick(16);
|
||||
const d = done.round;
|
||||
through(d);
|
||||
d.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES).map((st) => st.id);
|
||||
d.offer = null;
|
||||
for (let n = 0; n < 14 && d.spec.id !== "bonestair"; n++) through(d);
|
||||
d.phase = "play";
|
||||
d.runner.done = true;
|
||||
Object.assign(d.you, { x: R.finish + 16, y: floorOf(R.finish + 16), state: "run" });
|
||||
d.camX = R.finish - 40;
|
||||
for (let k = 0; k < 10; k++) done.tick(16);
|
||||
for (const won of [true, false]) {
|
||||
endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) });
|
||||
d.bonusRound.over = true;
|
||||
for (let k = 0; k < 10; k++) {
|
||||
done.tick(16);
|
||||
bonusTick(d, { tone() {}, fx: {} });
|
||||
}
|
||||
d.bonusRound.over = false;
|
||||
}
|
||||
// The stage select goes straight into it.
|
||||
const pick = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
|
||||
pick.resize(900, 900);
|
||||
pick.stageSelect();
|
||||
const p = pick.round;
|
||||
for (let i = 0; i < ghoul.SELECTABLE.length; i++) ghoul.steerSelect(p, 1, 0);
|
||||
const at = ghoul.FINALE.rooms.indexOf("bonestair");
|
||||
for (let i = 0; i < at; i++) ghoul.steerSelect(p, 0, 1);
|
||||
assert.equal(p.select.room, at);
|
||||
pick.tick(16);
|
||||
ghoul.takeSelect(p);
|
||||
assert.equal(p.spec.id, "bonestair");
|
||||
assert.equal(p.runner.id, "bonestair");
|
||||
assert.equal(p.you.y, R.top[2]);
|
||||
assert.equal(p.bonusRound.max, 3);
|
||||
pick.tick(16);
|
||||
});
|
||||
|
||||
/* ----------------------------------------------------------- the bots */
|
||||
|
||||
// A bot that plays well: it jumps at the edge of missing treads, over a grabbing hand and a pile of
|
||||
// masonry, ducks every ribcage, and fires only while a skeleton is up ahead (a held blaster runs
|
||||
// hot). `miss` is the share of things it fails to dodge (by a hash).
|
||||
const mix = (a, b) => {
|
||||
let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35);
|
||||
h ^= h >>> 13;
|
||||
h = Math.imul(h, 0x5bd1e995);
|
||||
h ^= h >>> 15;
|
||||
return (h >>> 0) / 4294967296;
|
||||
};
|
||||
function goodBot(round, seed, miss = 0) {
|
||||
const { you, runner: c, input: inp } = round;
|
||||
inp.left = inp.right = inp.down = false;
|
||||
inp.fire = false;
|
||||
if (round.phase !== "play" || !c || c.done) {
|
||||
inp.up = false;
|
||||
return;
|
||||
}
|
||||
const ok = (x) => mix(seed, Math.round(x)) >= miss;
|
||||
const look = seed % 4;
|
||||
inp.fire = c.skels.some((s) => (s.state === "rise" || s.state === "climb") && s.x > you.x && s.x - you.x < 75);
|
||||
let jump = false;
|
||||
if (you.state === "run") {
|
||||
for (const [x0] of R.gaps) if (x0 - you.x > 0 && x0 - you.x < 1.5 + look * 0.5 && ok(x0)) jump = true;
|
||||
R.hands.forEach(([x], i) => {
|
||||
const h = c.hands[i];
|
||||
if ((h.state === "grab" || h.state === "reach") && x - you.x > 4 && x - you.x < 7 + look && ok(x)) jump = true;
|
||||
});
|
||||
R.stones.forEach(([x], i) => {
|
||||
if (c.stones[i].state === "pile" && x - you.x > 7 && x - you.x < 9 + look && ok(x)) jump = true;
|
||||
});
|
||||
for (const [x] of R.ribs) if (you.x > x - bs.RIB_W / 2 - 3 && you.x < x + bs.RIB_W / 2 + 2 && ok(x)) inp.down = true;
|
||||
}
|
||||
if (jump && !inp.down) press(round);
|
||||
else inp.up = false;
|
||||
}
|
||||
function idleBot(round) {
|
||||
const inp = round.input;
|
||||
inp.left = inp.right = inp.down = inp.up = inp.fire = false;
|
||||
}
|
||||
function rideWith(seed, bot, limit = 80000) {
|
||||
const round = stairRound(seed);
|
||||
const lost = [];
|
||||
let t = 0;
|
||||
for (; t < limit && round.phase !== "clear" && !round.over; t += 16) {
|
||||
bot(round);
|
||||
if (round.runner && round.runner.done && round.phase === "play") round.input.right = true;
|
||||
ghoul.advance(round, 16, steady);
|
||||
for (const e of round.events) if (e.type === "lose") lost.push(e.cause);
|
||||
if (round.runner && !round.runner.done) {
|
||||
const off = round.you.x - round.camX;
|
||||
assert.ok(off > 4 && off < 70, `YOU stay in view (${off.toFixed(1)} from the left edge at ${round.you.x.toFixed(0)})`);
|
||||
}
|
||||
round.events.length = 0;
|
||||
}
|
||||
return { round, lost, ms: t };
|
||||
}
|
||||
|
||||
test("Ghoul Rush's Bone Stair: a bot that dodges well runs the whole stair in about 30 seconds, every skeleton shot, all three hearts kept, 8 dice, past every checkpoint", () => {
|
||||
for (let seed = 1; seed <= 4; seed++) {
|
||||
const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed));
|
||||
const b = round.bonusRound;
|
||||
assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")})`);
|
||||
assert.ok(ms > 26000 && ms < 36000, `${ms} ms`);
|
||||
assert.equal(b.hearts, 3, lost.join(","));
|
||||
assert.equal(b.dice, 8);
|
||||
assert.equal(round.lives, 3, "never a run life");
|
||||
assert.equal(round.runner.done, true);
|
||||
assert.equal(round.runner.check, R.checks.length - 1);
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: a bot that misses some things still mostly finishes, never with a run life lost", () => {
|
||||
let won = 0;
|
||||
for (let seed = 1; seed <= 8; seed++) {
|
||||
const { round } = rideWith(seed, (r) => goodBot(r, seed, 0.12));
|
||||
if (round.bonusRound.won) won++;
|
||||
assert.equal(round.lives, 3);
|
||||
assert.equal(round.over, false);
|
||||
}
|
||||
assert.ok(won >= 4, `${won} of 8 finished`);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: a bot that never dodges loses all three hearts in the first half, ends with 0 dice, BONUS LOST, and the run goes on with no game over", () => {
|
||||
for (let seed = 1; seed <= 3; seed++) {
|
||||
const { round, lost } = rideWith(seed, idleBot);
|
||||
const b = round.bonusRound;
|
||||
assert.equal(b.won, false, "never finishes");
|
||||
assert.equal(b.dice, 0);
|
||||
assert.equal(b.hearts, 0);
|
||||
assert.equal(lost.length, 3);
|
||||
assert.ok(round.you.x < R.finish * 0.5, `out at ${round.you.x}`);
|
||||
assert.equal(round.lives, 3, "never a run life");
|
||||
assert.equal(round.over, false, "no game over");
|
||||
// On into the next room.
|
||||
until(round, () => round.spec.id !== "bonestair", 12000);
|
||||
assert.notEqual(round.spec.id, "bonestair");
|
||||
assert.equal(round.over, false);
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Bone Stair: a bot that ducks or holds back the whole way is caught by the rubble again and again", () => {
|
||||
for (const key of ["down", "left"]) {
|
||||
const { lost } = rideWith(3, (r) => {
|
||||
goodBot(r, 3);
|
||||
if (r.runner && !r.runner.done) r.input[key] = true;
|
||||
}, 30000);
|
||||
assert.ok(lost.filter((c) => c === "stairRubble").length >= 2, `${key}: ${lost.join(",")}`);
|
||||
}
|
||||
});
|
||||
@@ -34,6 +34,11 @@ function selectInto(at, room, texts = [], opts = {}) {
|
||||
g.round.select = { at, room };
|
||||
g.round.practice = true;
|
||||
g.key("action");
|
||||
// A stage that opens on its boss's room (the finale) shows its own card first.
|
||||
if (g.round.phase === "intro") {
|
||||
g.round.introMs = ghoul.INTRO_MIN_MS;
|
||||
g.key("action");
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
@@ -244,7 +249,8 @@ test("Ghoul Rush boss intros: the card draws for every boss at many moments, thr
|
||||
const sizes = { W: 96, H: 54 };
|
||||
for (const room of bossRooms) {
|
||||
const id = room.boss;
|
||||
const st = ghoul.STAGES.find((s) => s.boss === id);
|
||||
// The stage that holds this boss's room (the finale holds three).
|
||||
const st = ghoul.SELECTABLE.find((s) => s.rooms.includes(room.id));
|
||||
const calls = [];
|
||||
const BOSS_ART = new Proxy({}, { get: (t, k) => (k === id ? (ctx, pic, b) => calls.push([pic, b]) : undefined) });
|
||||
const texts = [];
|
||||
@@ -261,7 +267,7 @@ test("Ghoul Rush boss intros: the card draws for every boss at many moments, thr
|
||||
assert.ok(texts.includes(bossIntroFor(id).epithet), `${id}: the epithet`);
|
||||
// The same through the game's own drawing, with the real art.
|
||||
const g2texts = [];
|
||||
const g = selectInto(ghoul.STAGES.findIndex((s) => s.boss === id), ghoul.STAGES.find((s) => s.boss === id).rooms.length - 1, g2texts);
|
||||
const g = selectInto(ghoul.SELECTABLE.indexOf(st), st.rooms.indexOf(room.id), g2texts);
|
||||
assert.equal(g.round.phase, "bossintro", id);
|
||||
for (let ms = 0; ms < 5000; ms += 80) {
|
||||
g.round.introMs = ms;
|
||||
|
||||
@@ -102,7 +102,7 @@ test("Ghoul Rush: a Lucky die is as common as a 1UP, comes only as a drop, and i
|
||||
assert.equal(dark.drops.length, 1, "a kill drops a power-up on a low roll");
|
||||
});
|
||||
|
||||
test("Ghoul Rush: picking up Lucky dice stacks them to nine, then pays points like a 1UP at its cap, and the dice show in a pill", () => {
|
||||
test("Ghoul Rush: picking up Lucky dice stacks them to MAX_HELD_DICE (13), then pays points like a 1UP at its cap, and the dice show in a pill", () => {
|
||||
const round = hall();
|
||||
const drop = { id: 1, kind: "die", x: round.you.x, y: round.you.y + 1, vx: 0, vy: 0, life: 9000, rest: true };
|
||||
round.drops.push(drop);
|
||||
@@ -110,12 +110,13 @@ test("Ghoul Rush: picking up Lucky dice stacks them to nine, then pays points li
|
||||
assert.equal(round.dice, 1);
|
||||
assert.equal(round.drops.length, 0);
|
||||
assert.equal(events(round, "power")[0].kind, "die");
|
||||
for (let k = 0; k < 8; k++) ghoul.applyPower(round, "die");
|
||||
assert.equal(round.dice, 9);
|
||||
assert.equal(ghoul.MAX_HELD_DICE, 13);
|
||||
for (let k = 0; k < 20; k++) ghoul.applyPower(round, "die");
|
||||
assert.equal(round.dice, ghoul.MAX_HELD_DICE, "stacks to the cap");
|
||||
const score = round.score;
|
||||
ghoul.applyPower(round, "die");
|
||||
assert.equal(round.dice, 10, "no cap");
|
||||
assert.equal(round.score, score, "no points instead");
|
||||
assert.equal(round.dice, ghoul.MAX_HELD_DICE, "no more past it");
|
||||
assert.equal(round.score, score + ghoul.POWER_POINTS, "points instead");
|
||||
const canvas = { getContext: () => null };
|
||||
const game = ghoul.default.create({ canvas });
|
||||
game.start();
|
||||
@@ -239,13 +240,18 @@ test("Ghoul Rush: a 5 saves him with a heart and no shield, a 4 just saves him,
|
||||
lose(held, "pit");
|
||||
ghoul.advance(held, ghoul.ROLL_MS + 8, rolls(FOUR));
|
||||
assert.equal(held.you.garlic, true, "a shield he already held stays");
|
||||
const some = hall(1);
|
||||
some.lives = 9;
|
||||
lose(some, "zombie");
|
||||
ghoul.advance(some, ghoul.ROLL_MS + 8, rolls(FIVE));
|
||||
assert.equal(some.lives, 10, "a heart under the cap");
|
||||
const full = hall(1);
|
||||
full.lives = 9;
|
||||
full.lives = ghoul.MAX_LIVES;
|
||||
const score = full.score;
|
||||
lose(full, "zombie");
|
||||
ghoul.advance(full, ghoul.ROLL_MS + 8, rolls(FIVE));
|
||||
assert.equal(full.lives, 10, "no cap");
|
||||
assert.equal(full.score, score, "no points instead");
|
||||
assert.equal(full.lives, ghoul.MAX_LIVES, "never past MAX_LIVES (13)");
|
||||
assert.equal(full.score, score + ghoul.POWER_POINTS, "points instead");
|
||||
});
|
||||
|
||||
test("Ghoul Rush: a 3 costs the life and he comes back with Rapid fire and a Garlic shield, a 2 with Bottle Rockets and a Garlic shield", () => {
|
||||
|
||||
@@ -0,0 +1,380 @@
|
||||
// Web console tests, Ghoul Rush's ending: four pages that obey the story's rules (2 to 4 short lines, no digits, no em dash, YOU on each, the gag's FINAL NOTICE); the House's last room opens it instead of the win; a press turns pages only after the lockout and finishes the typing first; holding fire skips it, a tap never does; the last page wins the run once, with n = round.winN; the window's keys, a click, a pause, its track and its sounds; every scene draws on a fake canvas at many moments; every event it raises has a react; every tone it names exists.
|
||||
// Run with: node --test scripts/test-web-console-activities-ghoul-ending.mjs
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
|
||||
import ghoulSfx from "../src/web-console/public/activities/ghoul-rush/sfx/ghoul-sfx.js";
|
||||
import { react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
|
||||
import { PAGES as STORY_PAGES } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-story.js";
|
||||
import {
|
||||
CLICK_OFF_MS,
|
||||
ENDING_HINT,
|
||||
ENDING_LOCK_MS,
|
||||
ENDING_TRACK,
|
||||
FLAG_MS,
|
||||
LAST_HINT,
|
||||
LIGHTS_OUT,
|
||||
MAX_LINE,
|
||||
PAGES,
|
||||
RELOCK_MS,
|
||||
SKIP_HINT,
|
||||
SKIP_HOLD_MS,
|
||||
SLIDE_MS,
|
||||
STAMP_MS,
|
||||
UNFOLD_MS,
|
||||
beginEnding,
|
||||
pressEnding,
|
||||
releaseEnding,
|
||||
revealEnd,
|
||||
skipEnding,
|
||||
stepEnding,
|
||||
takeEnding,
|
||||
} from "../src/web-console/public/activities/ghoul-rush/story/ghoul-ending.js";
|
||||
import { SCENE_H, TEXT_SIZE, endingArt, roadFlat, windowLit } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-ending-draw.js";
|
||||
import { compileTrack } from "../src/web-console/public/music.js";
|
||||
import { toneNames } from "../src/web-console/public/tones.js";
|
||||
|
||||
const steady = () => 0.5;
|
||||
const DASH = String.fromCharCode(0x2014);
|
||||
const events = (round, type) => round.events.filter((e) => e.type === type);
|
||||
const isTone = (name) => toneNames().includes(name) || Object.hasOwn(ghoulSfx.tones, name);
|
||||
|
||||
function fakeCtx(texts) {
|
||||
return new Proxy({}, {
|
||||
get: (t, name) => (name in t ? t[name] : name === "fillText" ? (s) => texts.push(String(s)) : () => {}),
|
||||
set: (t, name, value) => ((t[name] = value), true),
|
||||
});
|
||||
}
|
||||
|
||||
function through(round) {
|
||||
round.phase = "clear";
|
||||
round.phaseMs = 1;
|
||||
ghoul.advance(round, 4, steady);
|
||||
}
|
||||
|
||||
// A round walked through the hall and every stage to the House, then through each of the finale's rooms until the ending opens.
|
||||
function toEnding(seed = 4) {
|
||||
const round = ghoul.newRound(seed);
|
||||
round.dice = 0;
|
||||
through(round);
|
||||
round.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES).map((st) => st.id);
|
||||
round.offer = null;
|
||||
through(round);
|
||||
assert.equal(round.stage, ghoul.FINALE.id, "the House");
|
||||
for (let k = 0; k < 20 && round.phase !== "ending"; k++) through(round);
|
||||
assert.equal(round.phase, "ending", "the House's last room opens the ending");
|
||||
return round;
|
||||
}
|
||||
|
||||
// A window game in the ending, from the stage select's last entry (the House), and its sounds.
|
||||
function openGame() {
|
||||
const texts = [];
|
||||
const sounds = [];
|
||||
const tracks = [];
|
||||
const ctx = fakeCtx(texts);
|
||||
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, tone: (name) => sounds.push(name), music: (name) => tracks.push(name) });
|
||||
g.resize(900, 900);
|
||||
g.stageSelect();
|
||||
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g.key("down");
|
||||
g.key("action");
|
||||
assert.equal(g.round.stage, ghoul.FINALE.id);
|
||||
for (let k = 0; k < 20 && g.round.phase !== "ending"; k++) through(g.round);
|
||||
assert.equal(g.round.phase, "ending");
|
||||
g.tick(16);
|
||||
return { g, texts, sounds, tracks };
|
||||
}
|
||||
const tick = (g, ms) => {
|
||||
for (let t = 0; t < ms; t += 16) g.tick(16);
|
||||
};
|
||||
const lock = (g) => tick(g, ENDING_LOCK_MS + 20);
|
||||
// To the point the page can turn: its typing done and its scene played out.
|
||||
const playedOut = (pg) => Math.max(revealEnd(pg), pg.wait);
|
||||
const typedOut = (g) => tick(g, playedOut(PAGES[g.round.ending.page]) - g.round.ending.ms + 40);
|
||||
|
||||
test("Ghoul Rush ending: four pages, 2 to 4 short lines each that fit the field, no digits, no em dash, never the hero's name, YOU on every page", () => {
|
||||
assert.equal(PAGES.length, 4);
|
||||
assert.deepEqual(PAGES.map((p) => p.chapter), ["LIGHTS OUT", "THE ROAD", "MORNING", "FINAL NOTICE"]);
|
||||
assert.equal(new Set(PAGES.map((p) => p.id)).size, PAGES.length, "unique ids");
|
||||
for (const p of PAGES) {
|
||||
assert.ok(p.chapter && p.scene && p.pal.sky && p.pal.ground && p.pal.a && p.pal.glow, `${p.id} has a heading, a scene and colors`);
|
||||
assert.ok(p.lines.length >= 2 && p.lines.length <= 4, `${p.id} has 2 to 4 lines`);
|
||||
const text = [p.chapter, ...p.lines].join("\n");
|
||||
assert.ok(!text.includes(DASH), `${p.id} has no em dash`);
|
||||
assert.ok(!/\d/.test(text), `${p.id} has no digit`);
|
||||
assert.ok(!/planny|the player|the hero|\bhero\b/i.test(text), `${p.id} never names the hero`);
|
||||
assert.ok(/\bYOU\b/.test(p.lines.join(" ")), `${p.id} speaks to YOU`);
|
||||
for (const line of p.lines) {
|
||||
assert.ok(line.length <= MAX_LINE, `${p.id}: "${line}" is ${line.length} characters`);
|
||||
assert.ok(line.length * TEXT_SIZE * 0.62 <= ghoul.FIELD_W - 1, `${p.id}: "${line}" fits the field`);
|
||||
}
|
||||
for (const [at, name, vol, rate] of p.cues) {
|
||||
assert.ok(at >= 0 && at < 9000 && vol > 0 && vol <= 1 && rate > 0, `${p.id}: a cue is timed and audible`);
|
||||
assert.ok(isTone(name), `${p.id}: ${name} is a tone`);
|
||||
}
|
||||
assert.ok(p.cues.every((c, i) => i === 0 || c[0] >= p.cues[i - 1][0]), `${p.id}: its cues are in order`);
|
||||
}
|
||||
const lines = PAGES.flatMap((p) => p.lines);
|
||||
assert.equal(new Set(lines).size, lines.length, "no line used twice");
|
||||
const story = new Set(STORY_PAGES.flatMap((p) => p.lines));
|
||||
assert.ok(lines.every((l) => !story.has(l)), "no line copied from the intro story");
|
||||
const all = lines.join("\n");
|
||||
assert.ok(all.includes("FINAL NOTICE") && /unpaid bills/.test(all), "the mailbox gag lands");
|
||||
assert.ok(/unfolds/.test(all) && /cottage/.test(all), "the road and the cottage it was once");
|
||||
assert.equal(ENDING_TRACK, "ghoulMarrowEnding");
|
||||
});
|
||||
|
||||
test("Ghoul Rush ending: the scene timings agree with the cues (a falling tone per window, the click, the flag, the slide, the stamp)", () => {
|
||||
const lights = PAGES[0].cues.filter(([, n]) => n === "ghoulEndingWindow" || n === "ghoulEndingLast");
|
||||
assert.deepEqual(lights.map(([ms]) => ms), LIGHTS_OUT.map(([, ms]) => ms), "a tone as each window goes out");
|
||||
assert.equal(lights.at(-1)[1], "ghoulEndingLast", "the last window has its own tone");
|
||||
const rates = lights.slice(0, -1).map((c) => c[3]);
|
||||
assert.ok(rates.every((r, i) => i === 0 || r < rates[i - 1]), "each window's tone a little lower");
|
||||
assert.equal(new Set(LIGHTS_OUT.map(([i]) => i)).size, 10, "every one of the house's ten windows goes out");
|
||||
assert.ok(LIGHTS_OUT.at(-1)[1] - LIGHTS_OUT.at(-2)[1] >= 1000, "a long breath before the last");
|
||||
for (const [i, ms] of LIGHTS_OUT) {
|
||||
assert.equal(windowLit(i, ms - 1), 1);
|
||||
assert.equal(windowLit(i, ms + 2000), 0);
|
||||
}
|
||||
assert.equal(roadFlat(0, 0), 0, "the road starts folded");
|
||||
assert.equal(roadFlat(0, 20000), 1, "and ends flat");
|
||||
assert.ok(roadFlat(10, UNFOLD_MS + 600) > roadFlat(0, UNFOLD_MS + 600), "it unfolds from the far end toward YOU");
|
||||
const cue = (pg, name) => PAGES[pg].cues.find(([, n]) => n === name)?.[0];
|
||||
assert.equal(cue(1, "ghoulEndingClickOff"), CLICK_OFF_MS);
|
||||
assert.equal(cue(1, "ghoulEndingFold"), UNFOLD_MS);
|
||||
assert.equal(cue(3, "ghoulEndingFlag"), FLAG_MS);
|
||||
assert.equal(cue(3, "ghoulEndingPaper"), SLIDE_MS);
|
||||
assert.equal(cue(3, "ghoulEndingStamp"), STAMP_MS);
|
||||
});
|
||||
|
||||
test("Ghoul Rush ending: the House's end opens it instead of the win, and nothing else moves while it is up", () => {
|
||||
const round = toEnding();
|
||||
assert.equal(round.won, false, "not won yet");
|
||||
assert.equal(round.over, false);
|
||||
assert.equal(round.winN, ghoul.RUN_STAGES + 1);
|
||||
assert.equal(events(round, "won").length, 0);
|
||||
assert.deepEqual(events(round, "endingPage").map((e) => e.page), [0]);
|
||||
assert.equal(round.ending.page, 0);
|
||||
round.input.right = true;
|
||||
const x = round.you.x;
|
||||
const clock = round.clock;
|
||||
ghoul.advance(round, 2000, steady);
|
||||
assert.equal(round.you.x, x, "YOU stay put");
|
||||
assert.equal(round.clock, clock, "the room's clock holds");
|
||||
assert.equal(round.phase, "ending");
|
||||
assert.ok(round.ending.ms >= 2000);
|
||||
assert.equal(beginEnding({ ...round, events: [], input: {} }), true, "beginEnding says there is an ending");
|
||||
});
|
||||
|
||||
test("Ghoul Rush ending: a press turns a page only after the lockout, typing finishes first, and the last page wins the run once with n = winN", () => {
|
||||
const round = toEnding();
|
||||
round.events.length = 0;
|
||||
assert.equal(takeEnding(round), false, "not at once");
|
||||
ghoul.advance(round, ENDING_LOCK_MS - 40, steady);
|
||||
assert.equal(takeEnding(round), false, "not before the lockout");
|
||||
ghoul.advance(round, 60, steady);
|
||||
assert.ok(round.ending.ms < revealEnd(PAGES[0]));
|
||||
assert.equal(takeEnding(round), true);
|
||||
assert.equal(round.ending.page, 0, "the first press finishes the typing");
|
||||
assert.equal(round.ending.full, true);
|
||||
assert.equal(takeEnding(round), false, "a press right on top of it does not count");
|
||||
ghoul.advance(round, RELOCK_MS + 20, steady);
|
||||
assert.equal(takeEnding(round), false, "the page waits for its scene to play out (the last window)");
|
||||
assert.equal(round.ending.page, 0);
|
||||
ghoul.advance(round, PAGES[0].wait - round.ending.ms + 10, steady);
|
||||
assert.ok(round.ending.ms >= LIGHTS_OUT.at(-1)[1], "every window is out by then");
|
||||
assert.equal(takeEnding(round), true);
|
||||
assert.equal(round.ending.page, 1, "now the page turns");
|
||||
assert.equal(round.ending.ms, 0);
|
||||
assert.equal(takeEnding(round), false, "each page has its own lockout");
|
||||
for (let at = 1; at < PAGES.length; at++) {
|
||||
assert.equal(round.ending.page, at);
|
||||
assert.equal(round.won, false, `not won on page ${at + 1}`);
|
||||
ghoul.advance(round, playedOut(PAGES[at]) + 20, steady);
|
||||
assert.equal(takeEnding(round), true);
|
||||
}
|
||||
assert.deepEqual(events(round, "endingPage").map((e) => e.page), [1, 2, 3]);
|
||||
assert.equal(round.won, true, "the last page's press wins");
|
||||
assert.equal(round.over, true);
|
||||
assert.equal(round.ending, null);
|
||||
assert.notEqual(round.phase, "ending");
|
||||
assert.deepEqual(events(round, "won"), [{ type: "won", stages: round.cleared.length, n: ghoul.RUN_STAGES + 1 }]);
|
||||
assert.equal(takeEnding(round), false, "nothing to take after");
|
||||
assert.equal(skipEnding(round), false, "nothing to skip after");
|
||||
ghoul.advance(round, 2000, steady);
|
||||
assert.equal(events(round, "won").length, 1, "the won event fires once");
|
||||
});
|
||||
|
||||
test("Ghoul Rush ending: holding fire for a second skips it all on any page, a tap or a short hold does not, and a skip always works", () => {
|
||||
const r = toEnding();
|
||||
assert.equal(pressEnding(r, true), false, "a repeat is nothing");
|
||||
assert.equal(r.ending.hold, -1);
|
||||
assert.equal(pressEnding(r, false), true);
|
||||
assert.equal(r.ending.hold, 0, "a fresh press starts the clock");
|
||||
stepEnding(r, SKIP_HOLD_MS - 50);
|
||||
assert.equal(r.phase, "ending");
|
||||
releaseEnding(r);
|
||||
assert.equal(r.ending.hold, -1, "let go stops the clock");
|
||||
stepEnding(r, 3000);
|
||||
assert.equal(r.phase, "ending");
|
||||
pressEnding(r, false);
|
||||
stepEnding(r, SKIP_HOLD_MS + 10);
|
||||
assert.equal(r.won, true, "the hold skipped it all");
|
||||
assert.equal(r.over, true);
|
||||
assert.equal(events(r, "won").length, 1);
|
||||
// A skip from any page.
|
||||
for (let at = 0; at < PAGES.length; at++) {
|
||||
const s = toEnding(at + 7);
|
||||
s.ending.page = at;
|
||||
assert.equal(skipEnding(s), true);
|
||||
assert.equal(s.won, true);
|
||||
assert.equal(events(s, "won")[0].n, s.winN);
|
||||
}
|
||||
assert.equal(skipEnding(ghoul.newRound(1)), false, "no ending, nothing to skip");
|
||||
});
|
||||
|
||||
test("Ghoul Rush ending: the window's keys, any move and fire alike, turn pages; repeats and early presses never do; a click does; a pause holds it", () => {
|
||||
for (const name of ["left", "right", "up", "down", "action"]) {
|
||||
const { g } = openGame();
|
||||
g.key(name);
|
||||
assert.equal(g.round.ending.full, false, `${name}: early press ignored`);
|
||||
g.release(name);
|
||||
lock(g);
|
||||
g.key(name, true);
|
||||
assert.equal(g.round.ending.full, false, `${name}: a repeat is ignored`);
|
||||
g.key(name);
|
||||
assert.equal(g.round.ending.full, true, `${name}: a fresh press finishes the typing first`);
|
||||
g.release(name);
|
||||
typedOut(g);
|
||||
g.key(name);
|
||||
assert.equal(g.round.ending.page, 1, `${name}: the next press turns it`);
|
||||
g.release(name);
|
||||
assert.equal(g.round.input.fire || g.round.input.left || g.round.input.right || g.round.input.up || g.round.input.down, false, `${name}: nothing is kept held`);
|
||||
}
|
||||
const { g } = openGame();
|
||||
lock(g);
|
||||
g.pointer("down", 10, 10);
|
||||
assert.equal(g.round.ending.full, true, "a click finishes the typing");
|
||||
typedOut(g);
|
||||
g.pointer("down", 10, 10);
|
||||
assert.equal(g.round.ending.page, 1, "and the next click turns the page");
|
||||
g.pause();
|
||||
const held = g.round.ending.ms;
|
||||
tick(g, 2000);
|
||||
assert.equal(g.round.ending.ms, held, "a pause holds the page's clock");
|
||||
g.key("action");
|
||||
assert.equal(g.round.ending.hold, -1, "no key counts while paused");
|
||||
g.resume();
|
||||
tick(g, 100);
|
||||
assert.ok(g.round.ending.ms > held);
|
||||
});
|
||||
|
||||
test("Ghoul Rush ending: through every page on a real clock to the end screen, with its track, its tones, page turns and the escape", () => {
|
||||
const { g, texts, sounds, tracks } = openGame();
|
||||
tick(g, 1300);
|
||||
assert.ok(tracks.length && tracks.every((t) => t === ENDING_TRACK), "only the ending's track plays under it");
|
||||
assert.ok(sounds.includes("ghoulEndingHush") && sounds.includes("ghoulEndingWindow"), "the first page's tones play");
|
||||
let guard = 0;
|
||||
while (g.state === "running" && guard++ < 20) {
|
||||
typedOut(g);
|
||||
tick(g, RELOCK_MS + 40);
|
||||
g.key("right");
|
||||
g.release("right");
|
||||
tick(g, 16);
|
||||
}
|
||||
assert.equal(g.state, "over");
|
||||
assert.equal(g.round.won, true);
|
||||
assert.ok(sounds.includes("ghoulStoryPage"), "a page turn rustles");
|
||||
for (const n of ["ghoulEndingFold", "ghoulEndingClickOff", "ghoulEndingBird", "ghoulEndingFlag", "ghoulEndingStamp"]) assert.ok(sounds.includes(n), `${n} played`);
|
||||
texts.length = 0;
|
||||
g.resize(900, 900);
|
||||
assert.ok(texts.some((t) => t.startsWith("You escaped! Marrow starves")), "the end screen follows");
|
||||
// Held fire skips it in the window too.
|
||||
const { g: h } = openGame();
|
||||
for (let k = 0; k < 20; k++) h.key("action", true);
|
||||
tick(h, 2000);
|
||||
assert.equal(h.round.phase, "ending", "a held key from before never skips");
|
||||
h.key("action");
|
||||
h.key("action", true);
|
||||
tick(h, SKIP_HOLD_MS + 100);
|
||||
assert.equal(h.state, "over");
|
||||
assert.equal(h.round.won, true);
|
||||
});
|
||||
|
||||
test("Ghoul Rush ending: every scene draws on a fake canvas at many moments, with its heading, hints and lines, without throwing", () => {
|
||||
const { g, texts } = openGame();
|
||||
for (let at = 0; at < PAGES.length; at++) {
|
||||
for (const ms of [0, 1, 120, 600, 900, 1100, 1500, 2300, 2900, 3100, 4000, 4600, 5200, 6200, 6500, 8000, 12000, 40000]) {
|
||||
for (const full of [false, true]) {
|
||||
for (const hold of [-1, 500]) {
|
||||
g.round.ending = { page: at, ms, full, arm: 0, hold, cue: 99, shown: 0, back: "clear" };
|
||||
g.tick(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
g.round.ending = { page: at, ms: 100, full: false, arm: 0, hold: -1, cue: 99, shown: 0, back: "clear" };
|
||||
texts.length = 0;
|
||||
g.tick(1);
|
||||
assert.ok(texts.includes(SKIP_HINT.toUpperCase()), `page ${at + 1} shows how to skip`);
|
||||
assert.equal(texts.includes(ENDING_HINT) || texts.includes(LAST_HINT), false, "no continue hint inside the lockout");
|
||||
if (PAGES[at].wait) {
|
||||
g.round.ending.ms = PAGES[at].wait - 100;
|
||||
g.round.ending.full = true;
|
||||
texts.length = 0;
|
||||
g.tick(1);
|
||||
assert.equal(texts.includes(ENDING_HINT) || texts.includes(LAST_HINT), false, `page ${at + 1}: no continue hint while its scene plays out`);
|
||||
}
|
||||
g.round.ending.ms = 60000;
|
||||
g.round.ending.full = true;
|
||||
texts.length = 0;
|
||||
g.tick(1);
|
||||
assert.ok(texts.includes(PAGES[at].chapter), `page ${at + 1} draws its heading`);
|
||||
assert.ok(texts.includes(at === PAGES.length - 1 ? LAST_HINT : ENDING_HINT), `page ${at + 1} shows the continue hint`);
|
||||
for (const line of PAGES[at].lines) assert.ok(texts.includes(line), `page ${at + 1}: "${line}" is drawn in full`);
|
||||
}
|
||||
assert.ok(texts.includes("FINAL NOTICE"), "the stamp reads FINAL NOTICE");
|
||||
assert.ok(SCENE_H > 20 && SCENE_H < 40, "the scene keeps to the top of the field");
|
||||
// The art alone, with no ending: draws nothing and does not throw.
|
||||
const art = endingArt({ label() {}, GOLD: "#fc0", BONE: "#eee" });
|
||||
art.card(fakeCtx([]), { round: { ending: null } });
|
||||
});
|
||||
|
||||
test("Ghoul Rush ending: every event it raises has a react, its own react answers only its own events, and every tone it owns is a real, prefixed sound", () => {
|
||||
const round = toEnding();
|
||||
const s = round.ending;
|
||||
for (let at = 0; at < PAGES.length; at++) {
|
||||
s.page = at;
|
||||
s.ms = 0;
|
||||
s.cue = 0;
|
||||
s.full = false;
|
||||
stepEnding(round, 10000);
|
||||
s.arm = 0;
|
||||
takeEnding(round);
|
||||
}
|
||||
skipEnding(round);
|
||||
const kinds = new Set(round.events.map((e) => e.type));
|
||||
for (const kind of ["endingPage", "storyTone", "won"]) assert.ok(kinds.has(kind), `${kind} is raised`);
|
||||
const played = [];
|
||||
const marks = [];
|
||||
const fx = { tone: (n) => played.push(n), burst() {}, float() {}, ring() {}, banner: () => ({}), shake() {}, flash() {}, glow() {}, splat() {}, fx: { clock: 0, banners: [] }, markFurthest: (n) => marks.push(n), roomBanner() {}, monsters: {}, powers: {}, bosses: {}, g: ghoul };
|
||||
for (const e of round.events) {
|
||||
if (!["endingPage", "storyTone", "won"].includes(e.type)) continue;
|
||||
react(e, fx);
|
||||
}
|
||||
assert.ok(played.includes("ghoulStoryPage"), "a page turn plays its rustle");
|
||||
assert.ok(played.includes("ghoulEndingWindow") && played.includes("ghoulEndingGag"), "the timed tones play through the story's own event");
|
||||
assert.deepEqual(marks, [ghoul.RUN_STAGES + 1], "the win marks the House beaten");
|
||||
const art = endingArt({ label() {}, GOLD: "#fc0", BONE: "#eee" });
|
||||
const k = { tone() {} };
|
||||
assert.equal(art.react({ type: "endingPage", page: 1 }, k), true);
|
||||
for (const type of ["won", "storyTone", "storyPage", "kill", "hit", "room"]) assert.equal(art.react({ type }, k), false, `${type} is not its own`);
|
||||
const own = Object.keys(ghoulSfx.tones).filter((n) => n.startsWith("ghoulEnding"));
|
||||
assert.ok(own.length >= 10, "a handful of the ending's own tones");
|
||||
for (const p of PAGES) for (const [, name] of p.cues) assert.ok(isTone(name), `${name} exists`);
|
||||
const track = ghoulSfx.music[ENDING_TRACK];
|
||||
assert.ok(track, "the ending's track is in the game's music");
|
||||
const song = compileTrack(track);
|
||||
assert.ok(song.length >= 64, "it runs a few bars");
|
||||
// The user's pick (eighties horror end credits): a steady middle tempo, never a race.
|
||||
assert.ok(track.bpm >= 84 && track.bpm <= 120, "a middle tempo");
|
||||
assert.equal(track.rush || 0, 0, "it never races");
|
||||
});
|
||||
@@ -0,0 +1,703 @@
|
||||
// Web console tests, Ghoul Rush's finale, Kill II, Every Room at Once (the dollhouse): the room
|
||||
// agrees with the rules' house, the boss's box out of reach and always guarded, the Eye (a lamp
|
||||
// flares first, it opens, never twice running in one room, hit only through its open box from its
|
||||
// own floor, a clank while it flares or shuts, two lamps and one true in its last phase), the
|
||||
// shades (the keepers beaten this run, a fixed three in practice, every stage's boss with a move,
|
||||
// a door first, at most SHADE_CAP, each move telegraphed, costing a life with its own cause and
|
||||
// dodged), the lurch (a creak first, YOU slid and stopped at the end walls, a dresser to jump or
|
||||
// shoot apart), the kill and its retreat in order with the door kept until it has gone, a bot's
|
||||
// fight length, the voices, words and drawing.
|
||||
// Run with: node --test scripts/test-web-console-activities-ghoul-eye.mjs
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
|
||||
import * as ey from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-eye.js";
|
||||
import { LOOKS, LOSE_SOUNDS, LOSE_WORDS, VOICES } from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js";
|
||||
import { react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
|
||||
import { bossIntroFor } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-boss-intros.js";
|
||||
import { toneNames } from "../src/web-console/public/tones.js";
|
||||
|
||||
const steady = () => 0.5;
|
||||
const events = (round, type) => round.events.filter((e) => e.type === type);
|
||||
const seededRandom = (seed) => {
|
||||
let s = seed;
|
||||
return () => (s = (s * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff;
|
||||
};
|
||||
|
||||
function stubCanvas() {
|
||||
const calls = { count: 0 };
|
||||
const ctx = new Proxy({}, {
|
||||
get: (target, name) => (name in target ? target[name] : () => { calls.count += 1; }),
|
||||
set: (target, name, value) => { target[name] = value; return true; },
|
||||
});
|
||||
return { canvas: { width: 0, height: 0, getContext: () => ctx }, calls, ctx };
|
||||
}
|
||||
|
||||
function through(round) {
|
||||
round.phase = "clear";
|
||||
round.phaseMs = 1;
|
||||
ghoul.advance(round, 4, steady);
|
||||
}
|
||||
|
||||
function skipCard(round) {
|
||||
round.introMs = ghoul.INTRO_MIN_MS;
|
||||
return ghoul.takeIntro(round);
|
||||
}
|
||||
|
||||
// YOU standing on the floor `row` (0 to 2) at x, or on a shelf by index.
|
||||
function standAt(round, x, row = 0) {
|
||||
const y = ey.EYE_FLOORS[row];
|
||||
const shelf = row ? round.spec.shelves.findIndex(([a, b, top]) => top === y && b - a > 20) : -1;
|
||||
Object.assign(round.you, { x, y, vx: 0, vy: 0, state: "run", shelf, coyote: 0, drop: -1, cuttable: false, out: 0, safeMs: 0, face: 1, ducking: false });
|
||||
}
|
||||
|
||||
function run(round, ms, keys = {}, random = steady) {
|
||||
Object.assign(round.input, keys);
|
||||
for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random);
|
||||
for (const k of Object.keys(keys)) round.input[k] = false;
|
||||
}
|
||||
|
||||
// A run's way to the dollhouse: the finale entered at `depth` stages, on through its rooms to
|
||||
// this one, its boss's card passed, nothing else woken.
|
||||
function eyeRound(depth = ghoul.RUN_STAGES) {
|
||||
const round = ghoul.newRound(5);
|
||||
round.dice = 0;
|
||||
through(round);
|
||||
round.cleared = ghoul.STAGES.slice(0, depth).map((st) => st.id);
|
||||
round.offer = null;
|
||||
through(round);
|
||||
for (let n = 0; round.spec.id !== "dollhouse"; n++) {
|
||||
assert.ok(n < 10, "the dollhouse is in the finale");
|
||||
skipCard(round);
|
||||
skipCard(round);
|
||||
through(round);
|
||||
}
|
||||
skipCard(round);
|
||||
round.phase = "play";
|
||||
round.items.fill(true);
|
||||
round.candy.fill(true);
|
||||
round.events.length = 0;
|
||||
return round;
|
||||
}
|
||||
|
||||
// Nothing coming: the Eye shut a long while, no lurch, no door, no shade.
|
||||
function calm(round) {
|
||||
const b = round.boss;
|
||||
Object.assign(b.eye, { state: "shut", ms: 1e9, room: -1, decoy: -1 });
|
||||
Object.assign(b.lurch, { state: "wait", ms: 1e9 });
|
||||
b.shadeMs = 1e9;
|
||||
round.hazards.length = 0;
|
||||
round.monsters.length = 0;
|
||||
}
|
||||
|
||||
// The fight under way: YOU in the arena, the boss awake, everything calm.
|
||||
function eyeFight(depth = ghoul.RUN_STAGES) {
|
||||
const round = eyeRound(depth);
|
||||
standAt(round, round.spec.arena + 14);
|
||||
run(round, ghoul.BOSS_INTRO_MS + 100);
|
||||
assert.equal(round.boss.state, "fight");
|
||||
calm(round);
|
||||
round.events.length = 0;
|
||||
return round;
|
||||
}
|
||||
|
||||
// The Eye opened now in room `i`.
|
||||
function openIn(round, i) {
|
||||
Object.assign(round.boss.eye, { state: "open", ms: 1e9, full: 4000, room: i, decoy: -1 });
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- the house */
|
||||
|
||||
test("Ghoul Rush's dollhouse: the room agrees with the rules' house, comes after the lawn and the mat in the finale, and its boss is the Eye, named on its card", () => {
|
||||
const base = ghoul.roomById("dollhouse");
|
||||
assert.equal(base.boss, "marroweye");
|
||||
const rooms = ghoul.FINALE.rooms;
|
||||
assert.ok(rooms.indexOf("dollhouse") > rooms.indexOf("lawn"), "after the lawn");
|
||||
if (rooms.includes("mat")) assert.ok(rooms.indexOf("dollhouse") > rooms.indexOf("mat"), "after the mat");
|
||||
const spec = ghoul.roomFor("dollhouse");
|
||||
assert.equal(spec.arena + ey.EYE_COLS * ey.EYE_ROOM_W, spec.length, "the rooms fill the arena");
|
||||
assert.equal(ghoul.groundAt(spec, spec.arena + 1), ey.EYE_FLOORS[0]);
|
||||
for (const f of ey.EYE_FLOORS.slice(1)) assert.ok(spec.shelves.some(([a, b, y]) => y === f && a === spec.arena && b === spec.length), `a floor right across at ${f}`);
|
||||
// A landing between each floor at each end, a jump from each to the next.
|
||||
for (const [lo, hi] of [[ey.EYE_FLOORS[0], ey.EYE_FLOORS[1]], [ey.EYE_FLOORS[1], ey.EYE_FLOORS[2]]]) {
|
||||
const landings = spec.shelves.filter(([a, b, y]) => b - a < 20 && y > lo && y < hi);
|
||||
assert.equal(landings.length, 2, `two landings between ${lo} and ${hi}`);
|
||||
for (const [, , y] of landings) assert.ok(y - lo <= ghoul.JUMP_TOP - 1 && hi - y <= ghoul.JUMP_TOP - 1, "a jump up to it and on");
|
||||
}
|
||||
assert.equal(ghoul.BOSSES.marroweye.name, bossIntroFor("marroweye").name);
|
||||
assert.ok(LOOKS.dollhouse, "a look");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's dollhouse: the Eye's box is out of everything's reach and always guarded, a lost life keeps its hp, and the fight never costs a life by its box's touch", () => {
|
||||
const round = eyeFight();
|
||||
const b = round.boss;
|
||||
assert.equal(ghoul.guarded(b), true);
|
||||
assert.ok(b.y > ghoul.FIELD_H, "its box above the field");
|
||||
assert.equal(b.max, round.spec.bossHp);
|
||||
b.hp -= 10;
|
||||
round.lives = 5;
|
||||
ghoul.lose(round, "eyeRock");
|
||||
run(round, ghoul.CRASH_MS + ghoul.READY_MS + 100);
|
||||
assert.notEqual(round.boss, b, "a new boss object after the life lost");
|
||||
assert.equal(round.boss.hp, b.hp, "the same hp");
|
||||
// A climb to the top floor and back, under the box's x: no touch.
|
||||
const r = eyeFight();
|
||||
for (const row of [0, 1, 2]) {
|
||||
standAt(r, r.spec.length - 2, row);
|
||||
jumpUp(r);
|
||||
run(r, 900);
|
||||
}
|
||||
assert.deepEqual(events(r, "lose"), []);
|
||||
});
|
||||
|
||||
/* ----------------------------------------------------------------- the Eye */
|
||||
|
||||
test("Ghoul Rush's dollhouse: a lamp flares before the Eye opens (a second step heard), it opens in that room, shuts, and never opens in the same room twice running; its open time shrinks with its phase", () => {
|
||||
const round = eyeFight();
|
||||
const b = round.boss;
|
||||
Object.assign(b.eye, { state: "shut", ms: 1 });
|
||||
const order = [];
|
||||
const random = ghoul.seeded(17);
|
||||
for (let t = 0; t < 420000; t += 4) {
|
||||
round.you.safeMs = 1e9;
|
||||
b.shadeMs = 1e9;
|
||||
b.lurch.ms = 1e9;
|
||||
ghoul.advance(round, 4, random);
|
||||
for (const e of round.events) if (e.type.startsWith("eye")) order.push([e.type, e.room, t]);
|
||||
round.events.length = 0;
|
||||
round.hazards.length = 0;
|
||||
round.monsters.length = 0;
|
||||
}
|
||||
const flares = order.filter(([type]) => type === "eyeFlare");
|
||||
const opens = order.filter(([type]) => type === "eyeOpen");
|
||||
assert.ok(opens.length >= 10, `it opened many times (${opens.length})`);
|
||||
for (let i = 0; i < opens.length; i++) {
|
||||
const f = flares[i];
|
||||
assert.equal(f[1], opens[i][1], "it opens where its lamp flared");
|
||||
assert.ok(opens[i][2] - f[2] >= ey.EYE_FLARE_MS - 8, "after the whole flare");
|
||||
if (i) assert.notEqual(opens[i][1], opens[i - 1][1], "never the same room twice running");
|
||||
}
|
||||
const steps = order.filter(([type]) => type === "eyeFlareStep").length;
|
||||
assert.ok(steps >= opens.length && steps <= flares.length, "one step heard each flare");
|
||||
assert.ok(ey.EYE_OPEN_MS[0] > ey.EYE_OPEN_MS[1] && ey.EYE_OPEN_MS[1] > ey.EYE_OPEN_MS[2], "shorter open each phase");
|
||||
assert.equal(new Set(opens.map(([, room]) => room)).size, ey.EYE_ROOMS, "every room gets its turn");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's dollhouse: in its last phase two lamps flare and only one is true; the other pops out as the Eye opens", () => {
|
||||
const round = eyeFight();
|
||||
const b = round.boss;
|
||||
b.hp = Math.floor(b.max * ey.PHASE_HP[1]) - 1;
|
||||
assert.equal(ey.phaseOf(b), 2);
|
||||
Object.assign(b.eye, { state: "shut", ms: 1 });
|
||||
run(round, 8);
|
||||
const flares = events(round, "eyeFlare");
|
||||
assert.equal(flares.length, 2);
|
||||
assert.equal(flares.filter((e) => e.decoy).length, 1);
|
||||
assert.notEqual(flares[0].room, flares[1].room);
|
||||
round.events.length = 0;
|
||||
run(round, ey.EYE_FLARE_MS + 20);
|
||||
assert.equal(events(round, "eyeOpen")[0].room, flares.find((e) => !e.decoy).room, "the true one opens");
|
||||
assert.equal(events(round, "eyeDud")[0].room, flares.find((e) => e.decoy).room, "the false one pops out");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's dollhouse: the open Eye is hurt from its own floor by a bolt standing or ducked, from either side, never from another floor; flaring or shutting it clanks; shut, bolts pass", () => {
|
||||
for (let i = 0; i < ey.EYE_ROOMS; i++) {
|
||||
const r = ey.roomBox(eyeFight().spec, i);
|
||||
for (const [side, duck] of [[-1, false], [1, true]]) {
|
||||
const round = eyeFight();
|
||||
openIn(round, i);
|
||||
const x = Math.min(round.spec.length - 2, Math.max(round.spec.arena + 2, r.cx + side * 12));
|
||||
standAt(round, x, r.row);
|
||||
round.you.face = -side;
|
||||
const hp = round.boss.hp;
|
||||
run(round, 500, { fire: true, down: duck });
|
||||
assert.ok(round.boss.hp < hp, `room ${i} from the ${side < 0 ? "left" : "right"}${duck ? ", ducked" : ""}`);
|
||||
assert.ok(events(round, "bossHit").every((e) => e.how === "eye" && Math.abs(e.x - r.cx) < 0.01), "the hit shows at the Eye");
|
||||
// From the floor over it, nothing.
|
||||
const other = eyeFight();
|
||||
openIn(other, i);
|
||||
standAt(other, x, (r.row + 1) % 3);
|
||||
other.you.face = -side;
|
||||
run(other, 500, { fire: true });
|
||||
assert.equal(other.boss.hp, other.boss.max, `room ${i}: not from another floor`);
|
||||
}
|
||||
}
|
||||
for (const state of ["flare", "closing"]) {
|
||||
const round = eyeFight();
|
||||
Object.assign(round.boss.eye, { state, ms: 1e9, full: 1e9, room: 1 });
|
||||
standAt(round, ey.roomBox(round.spec, 1).cx - 12);
|
||||
run(round, 400, { fire: true });
|
||||
assert.equal(round.boss.hp, round.boss.max, `${state}: no harm`);
|
||||
assert.ok(events(round, "bossBlock").length > 0, `${state}: a clank`);
|
||||
}
|
||||
const shut = eyeFight();
|
||||
standAt(shut, ey.roomBox(shut.spec, 1).cx - 12);
|
||||
run(shut, 400, { fire: true });
|
||||
assert.deepEqual([shut.boss.hp, events(shut, "bossBlock").length], [shut.boss.max, 0], "shut: bolts fly on");
|
||||
});
|
||||
|
||||
/* -------------------------------------------------------------- the shades */
|
||||
|
||||
test("Ghoul Rush's dollhouse: every boss of every stage has a shade's move, a run's shades are the keepers it beat, and practice meets a fixed three", () => {
|
||||
for (const st of ghoul.STAGES) assert.ok(ey.SHADE_MOVES[st.boss], `${st.boss} (${st.id}) has a shade move`);
|
||||
for (const of of Object.keys(ey.SHADE_MOVES)) assert.ok(ghoul.BOSSES[of], `${of} is a boss`);
|
||||
const round = eyeRound();
|
||||
assert.deepEqual(ey.shadesOf(round, { stageById: ghoul.stageById }), round.cleared.map((id) => ghoul.stageById(id).boss));
|
||||
assert.deepEqual(ey.shadesOf({ cleared: [] }, { stageById: ghoul.stageById }), [...ey.PRACTICE_SHADES]);
|
||||
assert.equal(ey.PRACTICE_SHADES.length, 3);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's dollhouse: a door creaks open before its shade steps out, the shade fades in harmless and unhittable, never more than SHADE_CAP, and it fades away at the end of its life", () => {
|
||||
const round = eyeFight();
|
||||
const b = round.boss;
|
||||
round.you.safeMs = 1e9;
|
||||
b.shadeMs = 0;
|
||||
run(round, 8);
|
||||
assert.equal(events(round, "eyeDoor").length, 1, "the door first");
|
||||
assert.equal(round.monsters.length, 0, "no shade yet");
|
||||
const door = round.hazards.find((h) => h.kind === "eyeDoorway");
|
||||
assert.ok(door && round.boss.lastShade === door.of && ey.shadesOf(round, { stageById: ghoul.stageById }).includes(door.of));
|
||||
run(round, ey.EYE_DOOR_MS);
|
||||
const m = round.monsters.find((q) => q.kind === "eyeShade");
|
||||
assert.ok(m, "out steps a shade");
|
||||
assert.equal(ghoul.solid(m), false, "fading in");
|
||||
assert.ok(Math.abs(m.x - round.you.x) >= ey.SHADE_CLEAR / 2 || m.y !== round.you.y, "not on top of YOU");
|
||||
run(round, ey.SHADE_IN_MS + 20);
|
||||
assert.equal(ghoul.solid(m), true, "then solid");
|
||||
for (let t = 0; t < 20000; t += 4) {
|
||||
round.you.safeMs = 1e9;
|
||||
ghoul.advance(round, 4, steady);
|
||||
const alive = round.monsters.filter((q) => q.kind === "eyeShade").length + round.hazards.filter((h) => h.kind === "eyeDoorway").length;
|
||||
assert.ok(alive <= ey.SHADE_CAP[ey.phaseOf(round.boss)], "never past the cap");
|
||||
}
|
||||
assert.ok(!round.monsters.includes(m), "gone at the end of its life");
|
||||
const g = eyeFight();
|
||||
g.you.safeMs = 1e9;
|
||||
g.boss.shadeMs = 0;
|
||||
run(g, 8);
|
||||
g.boss.shadeMs = 1e9;
|
||||
run(g, ey.EYE_DOOR_MS + ey.SHADE_LIFE_MS + 100);
|
||||
assert.equal(g.monsters.length, 0, "a shade left alone fades by itself");
|
||||
assert.equal(events(g, "eyeShadeOut").length, 1);
|
||||
});
|
||||
|
||||
// A shade of `of` put in at x on YOUR floor, out and ready to move at once.
|
||||
function shadeAt(round, of, x, row = 0) {
|
||||
const y = ey.EYE_FLOORS[row];
|
||||
round.hazards.push({ kind: "eyeDoorway", x, y, w: 3, h: 5, warn: 1, full: 1, live: 0, of, cause: "marroweye" });
|
||||
run(round, 4);
|
||||
const m = round.monsters.find((q) => q.kind === "eyeShade" && q.of === of);
|
||||
Object.assign(m, { act: "idle", wait: 0, life: 1e9 });
|
||||
round.events.length = 0;
|
||||
return m;
|
||||
}
|
||||
|
||||
// A full jump: the press, and up held (it stays held: holding it does nothing else) so it is not cut short.
|
||||
const jumpUp = (r) => {
|
||||
r.input.jump = ghoul.JUMP_BUFFER_MS;
|
||||
r.input.up = true;
|
||||
};
|
||||
|
||||
// How YOU dodge each move, called each slice: the shade `m`.
|
||||
const floorThings = new Set(["eyeRipple", "eyeNote", "eyeHoop", "eyeMud"]);
|
||||
const DODGE = {
|
||||
hop: (r) => {
|
||||
if (r.hazards.some((h) => floorThings.has(h.kind) && Math.abs(h.x - r.you.x) < 2 + h.speed * r.spec.pace * 0.1 && Math.sign(r.you.x - h.x) === h.dir)) jumpUp(r);
|
||||
},
|
||||
skull: (r) => {
|
||||
r.input.down = r.hazards.some((h) => h.kind === "eyeSkull" && Math.abs(h.x - r.you.x) < 6);
|
||||
},
|
||||
creep: (r, m) => {
|
||||
r.you.face = Math.sign(m.x - r.you.x) || 1;
|
||||
},
|
||||
scythe: (r) => {
|
||||
if (r.hazards.some((h) => h.kind === "eyeScythe" && h.warn > 0 && h.warn < 100)) jumpUp(r);
|
||||
},
|
||||
dash: (r, m) => {
|
||||
if (m.going && Math.abs(m.x - r.you.x) < 8 && Math.sign(r.you.x - m.x) === m.dir) jumpUp(r);
|
||||
},
|
||||
// Off its mark, away from it, each time it marks YOU.
|
||||
leap: (r, m) => {
|
||||
if (m.act === "wind" && Math.abs(m.tx - r.you.x) < 4) {
|
||||
const away = Math.sign(r.you.x - m.x) || 1;
|
||||
const x = r.you.x + away * 8;
|
||||
standAt(r, x > r.spec.arena + 3 && x < r.spec.length - 3 ? x : r.you.x - away * 8);
|
||||
}
|
||||
},
|
||||
// Away from the knocker, out from under each rock marked at YOU.
|
||||
knock: (r, m) => {
|
||||
if (!r.hazards.some((q) => q.kind === "eyeRock" && q.warn > 0 && Math.abs(q.x - r.you.x) < 3)) return;
|
||||
const away = Math.sign(r.you.x - m.x) || 1;
|
||||
const x = r.you.x + away * 7;
|
||||
standAt(r, x > r.spec.arena + 3 && x < r.spec.length - 3 ? x : r.you.x - away * 14);
|
||||
},
|
||||
// Back the way YOU came: the second icicle falls a step ahead.
|
||||
icicles: (r) => {
|
||||
if (!r.hazards.some((q) => q.kind === "eyeIcicle" && q.warn > 0 && Math.abs(q.x - r.you.x) < 2.5)) return;
|
||||
const x = r.you.x - (r.you.face || 1) * 9;
|
||||
standAt(r, x > r.spec.arena + 3 && x < r.spec.length - 3 ? x : r.you.x + (r.you.face || 1) * 15);
|
||||
},
|
||||
};
|
||||
DODGE.note = DODGE.hop;
|
||||
DODGE.hoop = DODGE.hop;
|
||||
DODGE.mud = DODGE.hop;
|
||||
|
||||
const CAUSE = { hop: "eyeRipple", skull: "eyeSkull", creep: "eyeShade", scythe: "eyeScythe", note: "eyeNote", dash: "eyeShade", leap: ["eyePounce", "eyeShade"], knock: "eyeRock", hoop: "eyeHoop", icicles: "eyeIcicle", mud: "eyeMud" };
|
||||
|
||||
test("Ghoul Rush's dollhouse: each keeper's shade telegraphs its move before it can hurt, hurts standing YOU with its own cause, and is dodged", () => {
|
||||
for (const st of ghoul.STAGES) {
|
||||
const of = st.boss;
|
||||
const move = ey.SHADE_MOVES[of];
|
||||
const near = move === "scythe" ? 7 : move === "dash" || move === "leap" || move === "creep" ? 12 : 16;
|
||||
const hit = eyeFight();
|
||||
standAt(hit, 70);
|
||||
const m = shadeAt(hit, of, 70 + near);
|
||||
// The angel comes on only while YOU look away.
|
||||
if (move === "creep") hit.you.face = -1;
|
||||
const losses = [];
|
||||
let told = Infinity;
|
||||
for (let t = 0; t < 6000 && !losses.length; t += 4) {
|
||||
ghoul.advance(hit, 4, steady);
|
||||
if (events(hit, "eyeShadeWind").length && told === Infinity) told = t;
|
||||
losses.push(...events(hit, "lose").map((e) => [e.cause, t]));
|
||||
hit.events.length = 0;
|
||||
}
|
||||
assert.equal(losses.length, 1, `${of} (${move}): it hurts`);
|
||||
assert.ok([CAUSE[move]].flat().includes(losses[0][0]), `${of} (${move}): as ${CAUSE[move]} (${losses[0][0]})`);
|
||||
if (move !== "creep") assert.ok(losses[0][1] - told >= 600, `${of} (${move}): telegraphed well before (${losses[0][1] - told} ms)`);
|
||||
const safe = eyeFight();
|
||||
standAt(safe, 70);
|
||||
const s = shadeAt(safe, of, 70 + near);
|
||||
const lost = [];
|
||||
for (let t = 0; t < 6000; t += 4) {
|
||||
safe.input.down = false;
|
||||
DODGE[move](safe, s);
|
||||
ghoul.advance(safe, 4, steady);
|
||||
lost.push(...events(safe, "lose").map((e) => e.cause));
|
||||
safe.events.length = 0;
|
||||
}
|
||||
assert.deepEqual(lost, [], `${of} (${move}): dodged`);
|
||||
assert.ok(m.hp > 0, "its hp");
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's dollhouse: a shade takes bolts and dies for points, and endless lives spare every hit", () => {
|
||||
const round = eyeFight();
|
||||
standAt(round, 60);
|
||||
const m = shadeAt(round, "gourd", 75);
|
||||
m.wait = 1e9;
|
||||
const score = round.score;
|
||||
run(round, 2000, { fire: true });
|
||||
assert.ok(!round.monsters.includes(m), "shot down");
|
||||
assert.ok(events(round, "kill").some((e) => e.kind === "eyeShade"));
|
||||
assert.ok(round.score > score);
|
||||
const r = eyeFight();
|
||||
r.infinite = true;
|
||||
standAt(r, 70);
|
||||
shadeAt(r, "keeper", 77);
|
||||
const lives = r.lives;
|
||||
run(r, 3000);
|
||||
assert.ok(events(r, "lose").length >= 1, "hit");
|
||||
assert.equal(r.lives, lives, "no life spent");
|
||||
});
|
||||
|
||||
/* --------------------------------------------------------------- the lurch */
|
||||
|
||||
test("Ghoul Rush's dollhouse: the house creaks before it lurches, slides YOU while YOU stand (never in the air) and stops YOU at its end walls; a dresser comes down YOUR floor: jump it, or shoot it apart", () => {
|
||||
const round = eyeFight();
|
||||
const b = round.boss;
|
||||
standAt(round, 70);
|
||||
round.you.safeMs = 1e9;
|
||||
Object.assign(b.lurch, { ms: 0 });
|
||||
b.planLurch = 1;
|
||||
run(round, 8);
|
||||
assert.equal(events(round, "eyeCreak").length, 1, "a creak first");
|
||||
assert.equal(round.you.x, 70, "nothing slides yet");
|
||||
const dresser = round.hazards.find((h) => h.kind === "eyeDresser");
|
||||
assert.ok(dresser && dresser.y === round.you.y && dresser.x < round.you.x, "a dresser uphill on YOUR floor");
|
||||
run(round, ey.EYE_CREAK_MS);
|
||||
assert.equal(events(round, "eyeLurch").length, 1);
|
||||
const x = round.you.x;
|
||||
run(round, 500);
|
||||
assert.ok(round.you.x > x + 4, `slid (${(round.you.x - x).toFixed(1)})`);
|
||||
standAt(round, round.spec.length - 2);
|
||||
run(round, 800);
|
||||
assert.ok(round.you.x <= round.spec.length - ey.WALL_PAD + 0.01, "held at the end wall");
|
||||
// In the air, nothing pushes.
|
||||
const air = eyeFight();
|
||||
Object.assign(air.boss.lurch, { state: "go", ms: 1e9, dir: 1 });
|
||||
standAt(air, 70);
|
||||
Object.assign(air.you, { state: "air", vy: 0, y: 30, shelf: -1 });
|
||||
const ax = air.you.x;
|
||||
ghoul.advance(air, 4, steady);
|
||||
assert.equal(air.you.x, ax);
|
||||
// The dresser: it costs a life, a jump clears it, three bolts break it.
|
||||
const go = () => {
|
||||
const r = eyeFight();
|
||||
standAt(r, 64);
|
||||
r.boss.lurch.ms = 0;
|
||||
r.boss.planLurch = 1;
|
||||
run(r, 8);
|
||||
return r;
|
||||
};
|
||||
const hit = go();
|
||||
let lost = [];
|
||||
for (let t = 0; t < 5000 && !lost.length; t += 4) {
|
||||
ghoul.advance(hit, 4, steady);
|
||||
lost = events(hit, "lose").map((e) => e.cause);
|
||||
hit.events.length = 0;
|
||||
}
|
||||
assert.deepEqual(lost, ["eyeDresser"]);
|
||||
const jump = go();
|
||||
for (let t = 0; t < 5000; t += 4) {
|
||||
const d = jump.hazards.find((h) => h.kind === "eyeDresser" && h.live > 0);
|
||||
if (d && jump.you.x - d.x < 8 && jump.you.x > d.x) jumpUp(jump);
|
||||
ghoul.advance(jump, 4, steady);
|
||||
assert.deepEqual(events(jump, "lose"), [], "jumped");
|
||||
jump.events.length = 0;
|
||||
}
|
||||
const shoot = go();
|
||||
shoot.you.face = -1;
|
||||
run(shoot, 2500, { fire: true });
|
||||
assert.equal(events(shoot, "eyeDresserSmash").length, 1, "shot apart");
|
||||
assert.deepEqual(events(shoot, "lose"), []);
|
||||
});
|
||||
|
||||
/* ---------------------------------------------------------------- the kill */
|
||||
|
||||
test("Ghoul Rush's dollhouse: the last bolt in the Eye is a boss kill; its retreat plays once and in order; the door is kept from YOU until it has gone, then leads on", () => {
|
||||
const round = eyeFight();
|
||||
const b = round.boss;
|
||||
b.hp = 1;
|
||||
openIn(round, 1);
|
||||
standAt(round, ey.roomBox(round.spec, 1).cx - 12);
|
||||
const lives = round.lives;
|
||||
run(round, 400, { fire: true });
|
||||
assert.equal(b.state, "down");
|
||||
assert.equal(round.lives, lives + 1, "a life, as every boss gives");
|
||||
assert.equal(round.hasKey, true);
|
||||
const order = [];
|
||||
for (let t = 0; t < ey.GONE_AT + 1500 && round.phase !== "clear"; t += 4) {
|
||||
standAt(round, round.spec.door);
|
||||
round.input.right = true;
|
||||
ghoul.advance(round, 4, steady);
|
||||
for (const e of round.events) if (e.type.startsWith("eye")) order.push([e.type, Math.round(b.t)]);
|
||||
round.events.length = 0;
|
||||
if (!b.gone) assert.ok(round.you.x <= round.spec.door - ey.DOOR_KEEP + 0.2, "no door until it has gone");
|
||||
}
|
||||
assert.deepEqual(order.map(([t]) => t), ["eyeBurst", "eyePeel", "eyeCrack", "eyeCrack", "eyeCrack", "eyeGasp", "eyeSink", "eyeGone"]);
|
||||
assert.ok(order[1][1] >= ey.PEEL_AT && order.at(-1)[1] >= ey.GONE_AT, "on the retreat's clock");
|
||||
assert.equal(b.gone, true);
|
||||
assert.equal(round.phase, "clear", "down its stairway of bones");
|
||||
const next = ghoul.FINALE.rooms[ghoul.FINALE.rooms.indexOf("dollhouse") + 1];
|
||||
run(round, ghoul.CLEAR_MS + 50);
|
||||
if (next) assert.equal(round.spec.id, next, "on to the next room");
|
||||
else assert.equal(round.won, true, "or the win while it is the last");
|
||||
});
|
||||
|
||||
/* --------------------------------------------------------------- the fight */
|
||||
|
||||
// A steady player: when a lamp flares it goes to that room's floor (CLIMB_MS a floor, firing nothing
|
||||
// on the way: the bot is put there after), stands a way off the Eye facing it and fires while it is
|
||||
// open; jumps what runs along its floor, the dresser, a dashing shade; ducks a skull; steps out from
|
||||
// under a rock, an icicle or a beast's mark; and shoots what shade is on its floor while the Eye is shut.
|
||||
const CLIMB_MS = 1500;
|
||||
function fight(seed, skilled = true) {
|
||||
const round = eyeFight();
|
||||
const random = seededRandom(seed);
|
||||
Object.assign(round.boss.eye, { state: "shut", ms: 600 });
|
||||
round.boss.lurch.ms = ey.EYE_LURCH_FIRST_MS;
|
||||
round.boss.shadeMs = ey.SHADE_FIRST_DOOR_MS;
|
||||
let at = 0;
|
||||
let travel = 0;
|
||||
let t = 0;
|
||||
const causes = [];
|
||||
const spec = round.spec;
|
||||
for (; t < 300000 && round.boss.state !== "down" && !round.over; t += 4) {
|
||||
const you = round.you;
|
||||
const inp = round.input;
|
||||
const b = round.boss;
|
||||
inp.left = inp.right = inp.fire = inp.down = false;
|
||||
if (round.phase === "ask") ghoul.answerDie(round, false);
|
||||
if (skilled && round.phase === "play" && you.out <= 0 && you.state === "run") {
|
||||
const row = ey.rowOf(you.y);
|
||||
const level = (h) => Math.abs(h.y - ey.EYE_FLOORS[row]) < 0.5;
|
||||
const runner = round.hazards.find((h) => (floorThings.has(h.kind) || h.kind === "eyeDresser") && h.live > 0 && level(h) && Math.abs(h.x - you.x) < 3 + (h.speed || ey.DRESSER_SPEED) * 0.13 && Math.sign(you.x - h.x) === (h.dir || 1));
|
||||
const scythe = round.hazards.find((h) => h.kind === "eyeScythe" && level(h) && h.warn > 0 && h.warn < 100 && Math.abs(h.x - you.x) < h.w / 2 + 2);
|
||||
const dasher = round.monsters.find((m) => m.kind === "eyeShade" && m.going && m.move === "dash" && Math.abs(m.floor - you.y) < 0.5 && Math.abs(m.x - you.x) < 7);
|
||||
const skull = round.hazards.find((h) => h.kind === "eyeSkull" && Math.abs(h.y - ey.SKULL_UP - you.y) < 0.5 && Math.abs(h.x - you.x) < 6);
|
||||
const above = round.hazards.find((h) => (h.kind === "eyeRock" || h.kind === "eyeIcicle") && h.warn > 0 && Math.abs(h.floor - you.y) < 0.5 && Math.abs(h.x - you.x) < 3);
|
||||
const mark = round.monsters.find((m) => m.kind === "eyeShade" && m.move === "leap" && (m.act === "wind" || m.going) && Math.abs(m.floor - you.y) < 0.5 && Math.abs(m.tx - you.x) < 4);
|
||||
const e = b.eye;
|
||||
if (runner || scythe || dasher) jumpUp(round);
|
||||
else if (skull) inp.down = true;
|
||||
else if (above || mark) {
|
||||
const from = above ? above.x : mark.tx;
|
||||
const dir = from >= you.x ? -1 : 1;
|
||||
inp[you.x + dir * 4 < spec.arena + 2 || you.x + dir * 4 > spec.length - 2 ? (dir < 0 ? "right" : "left") : dir < 0 ? "left" : "right"] = true;
|
||||
} else if (travel > 0) travel -= 4;
|
||||
else if (e && e.room >= 0 && e.state !== "shut") {
|
||||
const r = ey.roomBox(spec, e.room);
|
||||
if (r.row !== at) {
|
||||
travel = CLIMB_MS * Math.abs(r.row - at);
|
||||
at = r.row;
|
||||
} else {
|
||||
const side = r.cx - 13 > spec.arena + 2 ? -1 : 1;
|
||||
const x = r.cx + side * 13;
|
||||
if (row !== r.row || Math.abs(you.x - x) > 5) standAt(round, x, r.row);
|
||||
you.face = -side;
|
||||
inp.fire = e.state === "open";
|
||||
}
|
||||
} else {
|
||||
const m = round.monsters.find((q) => q.kind === "eyeShade" && ghoul.solid(q) && Math.abs(q.floor - you.y) < 0.5 && Math.abs(q.x - you.x) < 40);
|
||||
if (m) {
|
||||
you.face = Math.sign(m.x - you.x) || you.face;
|
||||
inp.fire = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ghoul.advance(round, 4, random);
|
||||
causes.push(...events(round, "lose").map((e) => e.cause));
|
||||
round.events.length = 0;
|
||||
}
|
||||
return { won: round.boss.state === "down", secs: t / 1000, causes, round };
|
||||
}
|
||||
|
||||
test("Ghoul Rush's dollhouse takes a steady player a real fight at full depth: 60 to 120 seconds on most seeds, with lives to spare; a player who stands still dies", () => {
|
||||
const times = [];
|
||||
const lives = [];
|
||||
let good = 0;
|
||||
for (const seed of [3, 7, 19, 41]) {
|
||||
const f = fight(seed);
|
||||
assert.ok(f.won, `seed ${seed}: it fell (${f.causes}; ${f.secs.toFixed(1)} s, hp ${f.round.boss.hp})`);
|
||||
assert.ok(f.round.lives > 0, `seed ${seed}: lives to spare (${f.causes})`);
|
||||
for (const c of f.causes) assert.ok(LOSE_WORDS[c] || ghoul.MONSTERS[c], `${c} is the House's or one of the dead`);
|
||||
if (process.env.EYE_DEBUG) console.log(`seed ${seed}: ${f.won ? "won" : "lost"} in ${f.secs.toFixed(1)} s, lives ${f.round.lives}, ${f.causes}`);
|
||||
if (f.secs >= 60 && f.secs <= 120) good++;
|
||||
times.push(f.secs);
|
||||
lives.push(f.round.lives);
|
||||
}
|
||||
assert.ok(good >= 3, `most seeds in 60 to 120 s (${times.map((x) => x.toFixed(1))}; lives ${lives})`);
|
||||
const idle = fight(7, false);
|
||||
assert.equal(idle.won, false);
|
||||
assert.ok(idle.round.over, `game over (${idle.causes})`);
|
||||
assert.equal(idle.round.boss.hp, idle.round.boss.max, "and not a scratch on it");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------- voices, words, drawing */
|
||||
|
||||
const heard = (e) => {
|
||||
const played = [];
|
||||
const noop = () => {};
|
||||
const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6, splats: [] }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, markFurthest: noop };
|
||||
react(e, kit);
|
||||
return played;
|
||||
};
|
||||
|
||||
test("Ghoul Rush's Eye: a voice for every act in tones.js, every event plays its own sound once, and every cause has words and a sound", () => {
|
||||
const known = new Set(toneNames());
|
||||
for (const kind of ["marroweye", "eyeShade"]) for (const [act, name] of Object.entries(VOICES[kind])) assert.ok(known.has(name), `${kind} ${act}: ${name} is a tone`);
|
||||
const eye = { marroweye: { eyeFlare: "flare", eyeFlareStep: "flareStep", eyeOpen: "open", eyeShut: "shut", eyeDud: "dud", eyeDoor: "door", eyeCreak: "creak", eyeCreakStep: "creakStep", eyeLurch: "lurch", eyeDresserCrash: "crash", eyeDresserSmash: "smash", eyeBurst: "burst", eyePeel: "peel", eyeCrack: "crack", eyeGasp: "gasp", eyeSink: "sink", eyeGone: "gone", bossWake: "wake", bossHit: "hurt", bossDown: "die" }, eyeShade: { eyeShadeIn: "come", eyeShadeOut: "fade", eyeShadeWind: "wind", eyeShadeSlam: "slam", eyeSkullThrow: "throw", eyeShadeGrind: "grind", eyeScythe: "scythe", eyeNote: "note", eyeShadeDash: "dash", eyeShadeLeap: "leap", eyePounce: "pounce", eyeKnock: "knock", eyeRockLand: "rock", eyeHoop: "hoop", eyeIcicleLand: "icicle", eyeMud: "mud", hit: "hurt", kill: "die" } };
|
||||
for (const [kind, cases] of Object.entries(eye)) {
|
||||
for (const [type, act] of Object.entries(cases)) {
|
||||
const played = heard({ type, kind, x: 80, y: 20, xs: [70], ty: 20, tx: 70, at: 70, n: 1, dir: 1, move: "hop", how: "eye", points: 1, mult: 1, life: true });
|
||||
assert.equal(played.filter((n) => n === VOICES[kind][act]).length, 1, `${type}: ${VOICES[kind][act]} once`);
|
||||
}
|
||||
}
|
||||
// Every event the rules push is one of those.
|
||||
const pushed = new Set();
|
||||
const round = eyeFight();
|
||||
round.you.safeMs = 1e9;
|
||||
round.boss.hp = Math.floor(round.boss.max * 0.3);
|
||||
Object.assign(round.boss.eye, { state: "shut", ms: 1 });
|
||||
round.boss.lurch.ms = 0;
|
||||
round.boss.shadeMs = 0;
|
||||
const random = seededRandom(9);
|
||||
for (let t = 0; t < 60000; t += 4) {
|
||||
round.you.safeMs = 1e9;
|
||||
ghoul.advance(round, 4, random);
|
||||
for (const e of round.events) if (e.type.startsWith("eye")) pushed.add(e.type);
|
||||
round.events.length = 0;
|
||||
}
|
||||
const all = new Set([...Object.keys(eye.marroweye), ...Object.keys(eye.eyeShade), "eyeSkullTurn"]);
|
||||
for (const type of pushed) assert.ok(all.has(type), `${type} has a reaction`);
|
||||
for (const cause of ["marroweye", "eyeShade", "eyeRipple", "eyeSkull", "eyeScythe", "eyeNote", "eyePounce", "eyeRock", "eyeHoop", "eyeIcicle", "eyeMud", "eyeDresser"]) {
|
||||
assert.ok(LOSE_WORDS[cause], `${cause}: words`);
|
||||
assert.ok(known.has(LOSE_SOUNDS[cause][0]), `${cause}: a sound`);
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's dollhouse draws: the landing, the fight with the Eye in every state, every keeper's shade and move, the lurch, every beat of the retreat, lit and dark, and its card with the card's fake view", () => {
|
||||
const { canvas, calls, ctx } = stubCanvas();
|
||||
const g = ghoul.default.create({ canvas });
|
||||
g.resize(900, 900);
|
||||
g.stageSelect();
|
||||
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g.key("down");
|
||||
for (let i = 0; i < ghoul.FINALE.rooms.indexOf("dollhouse"); i++) g.key("right");
|
||||
g.key("action");
|
||||
for (let n = 0; n < 2 && g.round.phase !== "ready"; n++) {
|
||||
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 50; ms += 16) g.tick(16);
|
||||
g.key("action");
|
||||
}
|
||||
const r = g.round;
|
||||
assert.equal(r.spec.id, "dollhouse");
|
||||
r.infinite = true;
|
||||
const frame = (label) => {
|
||||
const before = calls.count;
|
||||
g.tick(16);
|
||||
assert.ok(calls.count > before, `${label} draws`);
|
||||
};
|
||||
for (const dark of [false, true]) {
|
||||
r.dark = dark;
|
||||
standAt(r, 10);
|
||||
frame("the landing");
|
||||
standAt(r, r.spec.arena + 14);
|
||||
for (let ms = 0; ms < 1600; ms += 16) g.tick(16);
|
||||
for (const [state, decoy] of [["flare", -1], ["flare", 6], ["open", -1], ["closing", -1], ["shut", -1]]) {
|
||||
Object.assign(r.boss.eye, { state, ms: 300, full: 1000, room: 4, decoy });
|
||||
frame(`the Eye ${state}`);
|
||||
}
|
||||
for (const st of ghoul.STAGES) {
|
||||
Object.assign(r, { phase: "play" });
|
||||
Object.assign(r.you, { out: 0, safeMs: 1e9 });
|
||||
shadeAt(r, st.boss, 90, 1);
|
||||
for (let ms = 0; ms < 1500; ms += 16) frame(`${st.boss}'s shade`);
|
||||
r.monsters.length = 0;
|
||||
r.hazards.length = 0;
|
||||
}
|
||||
Object.assign(r.boss.lurch, { state: "creak", ms: 300 });
|
||||
r.boss.planLurch = 1;
|
||||
for (let ms = 0; ms < 2000; ms += 16) frame("the lurch");
|
||||
for (const t of [100, ey.PEEL_AT + 300, ey.CRACK_AT[2] + 100, ey.GASP_AT + 200, ey.SINK_AT + 900, ey.GONE_AT + 100]) {
|
||||
Object.assign(r.boss, { state: "down", t, gone: t >= ey.GONE_AT });
|
||||
frame(`the retreat at ${t}`);
|
||||
}
|
||||
Object.assign(r.boss, { state: "fight", t: 0, gone: false });
|
||||
}
|
||||
// The card draws the boss with its own fake view: no round, no spec, FIELD_H 0.
|
||||
const before = calls.count;
|
||||
g.stageSelect();
|
||||
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g.key("down");
|
||||
for (let i = 0; i < ghoul.FINALE.rooms.indexOf("dollhouse"); i++) g.key("right");
|
||||
g.key("action");
|
||||
assert.equal(g.round.phase, "bossintro");
|
||||
for (let ms = 0; ms < 3000; ms += 100) {
|
||||
g.round.introMs = ms;
|
||||
g.tick(1);
|
||||
}
|
||||
assert.ok(calls.count > before, "the card draws");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Eye draws on its card through its own art with the card's fake view, and every shade through its keeper's", async () => {
|
||||
const { eyeArt } = await import("../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js");
|
||||
const { ctx } = stubCanvas();
|
||||
const noop = () => {};
|
||||
let borrowed = 0;
|
||||
const art = eyeArt({ ellipse: noop, circle: noop, roundRect: noop, line: noop, rotate: noop, eye: noop, hash: (a, b) => Math.abs(a * 31 + b) % 997, say: noop, gate: () => true, label: noop, bossArt: () => () => borrowed++, DANGER: "#f00", GOLD: "#fc0" });
|
||||
const v = { g: { FIELD_H: 0 }, clock: 1000, spec: null, groundAt: () => 0, eyes: [] };
|
||||
const b = { kind: "marroweye", x: 0, y: 0, w: 30, h: 30, hurt: 0, dir: -1, state: "fight", t: 0, hp: 1, max: 1 };
|
||||
assert.doesNotThrow(() => art.bosses.marroweye(ctx, v, b));
|
||||
const game = { g: { FIELD_H: 54 }, clock: 1000, spec: ghoul.roomFor("dollhouse"), round: {}, bosses: ghoul.BOSSES, eyes: [] };
|
||||
for (const st of ghoul.STAGES) art.monsters.eyeShade(ctx, game, { of: st.boss, act: "idle", wait: 0, dir: 1, move: ey.SHADE_MOVES[st.boss], floor: 6, y: 6 }, 60, 48, 0, false);
|
||||
assert.equal(borrowed, ghoul.STAGES.length, "each shade drawn through its keeper's art");
|
||||
});
|
||||
@@ -818,7 +818,7 @@ test("Ghoul Rush's Frost Widow hangs from the roof with her veil up, three fire
|
||||
const barrels = round.hazards.filter((h) => h.kind === "barrel");
|
||||
assert.deepEqual(barrels.map((h) => h.x), fz.BARREL_SPOTS.map((o) => round.spec.arena + o));
|
||||
assert.ok(barrels.every((h) => h.state === "still" && h.y === 6));
|
||||
assert.equal(ghoul.roomFor("widow", 7).bossHp, Math.round(90 * (1 + ghoul.BOSS_DEPTH_HP * 7)));
|
||||
assert.equal(ghoul.roomFor("widow", 7).bossHp, Math.round(90 * (1 + ghoul.BOSS_DEPTH_HP * Math.min(14, ghoul.BOSS_DEPTH_MAX))), "seven stages in counts as fourteen steps, capped");
|
||||
// A shot at her glances off: the veil, and she is off the floor besides.
|
||||
for (const [act, y] of [["hang", 26], ["low", 6]]) {
|
||||
Object.assign(b, { act, y, x: 170, wait: 1e9, lowMs: 1e9 });
|
||||
|
||||
@@ -3,6 +3,7 @@ import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
|
||||
import { skipStory } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-story.js";
|
||||
import { skipEnding } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-ending.js";
|
||||
import { dropAt, gameOverBanner, OVER_WORD } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-gameover-draw.js";
|
||||
import { toneNames } from "../src/web-console/public/tones.js";
|
||||
|
||||
@@ -23,9 +24,14 @@ function winRun(h) {
|
||||
const r = h.round;
|
||||
through(r);
|
||||
while (!r.over) {
|
||||
// The ending's pages once the House is dead.
|
||||
if (r.phase === "ending") {
|
||||
skipEnding(r);
|
||||
continue;
|
||||
}
|
||||
r.phaseMs = 0;
|
||||
ghoul.pickStage(r);
|
||||
for (let k = 0; k < 4; k++) through(r);
|
||||
for (let k = 0; k < 4 && r.phase !== "ending" && !r.over; k++) through(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,576 @@
|
||||
// Web console tests, Ghoul Rush's finale, Kill III, The Pit: the room (dark, a pit each side of the
|
||||
// heart's plinth, the door at its end), the beat (its interval falling with hp, a wave each way on
|
||||
// the dub, the ribs open only between beats: a bolt counts then and clanks otherwise), each move's
|
||||
// warning seen and heard before it can hurt, its cost and its dodge, the beat stopping dead and the
|
||||
// big double wave, the last hp no bolt can take and the HOLD FIRE flood that ends it (the meter,
|
||||
// the weak beats that only knock it back, the white, the last thump, the fall, the daylight and its
|
||||
// door), a life lost keeping it all, a bot's fight length at full depth, the voices, words and drawing.
|
||||
// Run with: node --test scripts/test-web-console-activities-ghoul-heart.mjs
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
|
||||
import * as hr from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-heart.js";
|
||||
import { LOSE_SOUNDS, LOSE_WORDS, VOICES, heartArt } from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-heart-draw.js";
|
||||
import { react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
|
||||
import { bossIntroFor } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-boss-intros.js";
|
||||
import { toneNames } from "../src/web-console/public/tones.js";
|
||||
|
||||
const steady = () => 0.5;
|
||||
const events = (round, type) => round.events.filter((e) => e.type === type);
|
||||
const seededRandom = (seed) => {
|
||||
let s = seed;
|
||||
return () => (s = (s * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff;
|
||||
};
|
||||
|
||||
function stubCanvas() {
|
||||
const calls = { count: 0 };
|
||||
const ctx = new Proxy({}, {
|
||||
get: (target, name) => (name in target ? target[name] : () => { calls.count += 1; }),
|
||||
set: (target, name, value) => { target[name] = value; return true; },
|
||||
});
|
||||
return { canvas: { width: 0, height: 0, getContext: () => ctx }, calls, ctx };
|
||||
}
|
||||
|
||||
function standAt(round, x, shelf = -1) {
|
||||
const y = shelf >= 0 ? round.spec.shelves[shelf][2] : ghoul.groundAt(round.spec, x);
|
||||
Object.assign(round.you, { x, y, vx: 0, vy: 0, state: "run", shelf, coyote: 0, drop: -1, cuttable: false, out: 0, safeMs: 0, face: 1 });
|
||||
}
|
||||
|
||||
function run(round, ms, keys = {}, random = steady) {
|
||||
Object.assign(round.input, keys);
|
||||
for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random);
|
||||
for (const k of Object.keys(keys)) round.input[k] = false;
|
||||
}
|
||||
|
||||
// A run in the Pit, `depth` stages behind it, the finale's last room, nothing else awake.
|
||||
function pitRound(depth = ghoul.RUN_STAGES) {
|
||||
const round = ghoul.newRound(5);
|
||||
round.dice = 0;
|
||||
round.cleared = ghoul.STAGES.slice(0, depth).map((st) => st.id);
|
||||
round.stage = ghoul.FINALE.id;
|
||||
round.stageAt = ghoul.FINALE.rooms.indexOf("pit");
|
||||
ghoul.setupRoom(round, "pit");
|
||||
round.phase = "play";
|
||||
round.items.fill(true);
|
||||
round.candy.fill(true);
|
||||
round.events.length = 0;
|
||||
return round;
|
||||
}
|
||||
|
||||
// The fight under way: in the arena, the heart awake, the next move a long way off.
|
||||
function pitFight(depth = ghoul.RUN_STAGES) {
|
||||
const round = pitRound(depth);
|
||||
standAt(round, 100);
|
||||
run(round, ghoul.BOSS_INTRO_MS + 100);
|
||||
assert.equal(round.boss.state, "fight");
|
||||
calm(round);
|
||||
return round;
|
||||
}
|
||||
|
||||
// Nothing coming: no move for a long while, no beat due, nothing on the field.
|
||||
function calm(round) {
|
||||
Object.assign(round.boss, { act: "idle", wait: 1e9, beatMs: -1e9, dubbed: true, opened: true, stopMs: 0, echo: 0 });
|
||||
round.hazards.length = 0;
|
||||
round.waves.length = 0;
|
||||
round.events.length = 0;
|
||||
}
|
||||
|
||||
// The ribs held open (or shut) a long while.
|
||||
const holdOpen = (b) => Object.assign(b, { beatT: 1e9, beatMs: hr.OPEN_AT + 1, opened: true, dubbed: true });
|
||||
const holdShut = (b) => Object.assign(b, { beatT: 1e9, beatMs: -1e9, opened: true, dubbed: true });
|
||||
|
||||
/* ------------------------------------------------------------ the room */
|
||||
|
||||
test("Ghoul Rush's Pit: the finale's last room, always dark, the heart's boss room with a pit each side of its plinth and the door at the end, and its card", () => {
|
||||
assert.equal(ghoul.FINALE.rooms.at(-1), "pit");
|
||||
const base = ghoul.roomById("pit");
|
||||
assert.equal(base.boss, "marrowheart");
|
||||
assert.equal(base.dark, true);
|
||||
assert.ok(base.door > base.length - 14);
|
||||
const spec = ghoul.roomFor("pit", ghoul.RUN_STAGES);
|
||||
assert.equal(ghoul.groundAt(spec, hr.HEART_X), 6, "the plinth");
|
||||
assert.equal(ghoul.groundAt(spec, hr.LEFT_LIP + 1), -Infinity, "a pit on its left");
|
||||
assert.equal(ghoul.groundAt(spec, hr.RIGHT_LIP - 1), -Infinity, "and on its right");
|
||||
assert.ok(spec.arena < hr.LEFT_LIP - 40, "room to fight on the left");
|
||||
const info = bossIntroFor("marrowheart");
|
||||
assert.deepEqual([info.name, info.epithet], ["The Heart of Marrow", "It has never once skipped a beat"]);
|
||||
assert.equal(ghoul.BOSSES.marrowheart.name, info.name);
|
||||
const r = pitFight();
|
||||
const b = r.boss;
|
||||
assert.deepEqual([b.x, b.y, b.w, b.h], [hr.HEART_X, 6, hr.HEART_BOX_W, hr.HEART_BOX_H], "its box is the plinth");
|
||||
assert.ok(b.x - b.w / 2 <= hr.LEFT_LIP + 6 && b.x + b.w / 2 >= hr.RIGHT_LIP - 6, "nowhere to stand beside it");
|
||||
assert.equal(r.dark, true);
|
||||
// A fall down a pit costs a life.
|
||||
standAt(r, hr.LEFT_LIP + 2);
|
||||
r.you.y = 6;
|
||||
r.you.state = "air";
|
||||
r.you.vy = -10;
|
||||
const lives = r.lives;
|
||||
run(r, 1500);
|
||||
assert.ok(events(r, "lose").some((e) => e.cause === "pit") || r.lives < lives, "into the dark");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ the beat */
|
||||
|
||||
test("Ghoul Rush's Pit: the beat comes every 1.5 s at full hp and quickens toward 0.75 s, a lub then the dub, and the dub sends a wave each way from the lips of the pits", () => {
|
||||
assert.equal(hr.beatFor(1), 1500);
|
||||
assert.equal(hr.beatFor(0), 750);
|
||||
assert.ok(hr.openFor(1) > hr.openFor(0.2), "the ribs' window narrows with hp");
|
||||
const r = pitFight();
|
||||
const b = r.boss;
|
||||
Object.assign(b, { beatT: 1500, beatMs: 1499, dubbed: true, opened: true });
|
||||
run(r, 8);
|
||||
assert.equal(events(r, "heartBeat").length, 1, "the lub");
|
||||
assert.equal(r.waves.length, 0, "no wave yet");
|
||||
run(r, hr.DUB_MS);
|
||||
assert.equal(events(r, "heartWave").length, 1, "the dub");
|
||||
const xs = r.waves.map((w) => [w.kind, w.dir, Math.round(w.x)]);
|
||||
assert.deepEqual(xs.sort(), [["heartBeat", -1, hr.LEFT_LIP - 1], ["heartBeat", 1, hr.RIGHT_LIP + 1]].sort(), "out of each pit's lip");
|
||||
// Low on hp, the beats come faster.
|
||||
calm(r);
|
||||
b.hp = Math.round(b.max * 0.1);
|
||||
Object.assign(b, { beatT: 1500, beatMs: 1499 });
|
||||
let lubs = 0;
|
||||
const times = [];
|
||||
for (let t = 0; t < 6000; t += 4) {
|
||||
ghoul.advance(r, 4, steady);
|
||||
r.you.safeMs = 1e9;
|
||||
if (events(r, "heartBeat").length) times.push(t);
|
||||
lubs += events(r, "heartBeat").length;
|
||||
r.events.length = 0;
|
||||
}
|
||||
const gap = times[2] - times[1];
|
||||
assert.ok(gap >= 780 && gap <= 900, `quick beats at a tenth of its hp (${gap} ms)`);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Pit: a bolt into the open ribs hurts it, one while they are shut clanks off, and its weak spot is open only between beats", () => {
|
||||
const r = pitFight();
|
||||
const b = r.boss;
|
||||
standAt(r, 100);
|
||||
holdShut(b);
|
||||
run(r, 600, { fire: true });
|
||||
assert.equal(b.hp, b.max, "shut: no damage");
|
||||
assert.ok(events(r, "bossBlock").length > 0, "a clank");
|
||||
calm(r);
|
||||
r.heat = 0;
|
||||
r.events.length = 0;
|
||||
holdOpen(b);
|
||||
run(r, 600, { fire: true });
|
||||
assert.ok(b.hp < b.max, "open: it hurts");
|
||||
assert.ok(events(r, "bossHit").length > 0);
|
||||
// Over a normal beat, open only in its window.
|
||||
calm(r);
|
||||
Object.assign(b, { beatT: 1500, beatMs: 1499 });
|
||||
const open = [];
|
||||
for (let t = 0; t < 1500; t += 4) {
|
||||
r.you.safeMs = 1e9;
|
||||
ghoul.advance(r, 4, steady);
|
||||
open.push([t, b.open]);
|
||||
}
|
||||
const first = open.find(([, o]) => o);
|
||||
const last = open.filter(([, o]) => o).at(-1);
|
||||
assert.ok(first[0] >= hr.OPEN_AT - 10 && first[0] <= hr.OPEN_AT + 10, "opens after the dub");
|
||||
assert.ok(last[0] - first[0] <= hr.openFor(1) * 1500 + 10, "for its share of the beat");
|
||||
assert.equal(events(r, "heartOpen").length, 1, "heard once");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Pit: the beat's wave costs a life standing still (shaken off your feet) and is jumped", () => {
|
||||
const r = pitFight();
|
||||
const b = r.boss;
|
||||
standAt(r, 100);
|
||||
Object.assign(b, { beatT: 1e9, beatMs: hr.DUB_MS - 1, dubbed: false });
|
||||
run(r, 900);
|
||||
assert.deepEqual(events(r, "lose").map((e) => e.cause), ["heartBeat"]);
|
||||
const j = pitFight();
|
||||
standAt(j, 100);
|
||||
Object.assign(j.boss, { beatT: 1e9, beatMs: hr.DUB_MS - 1, dubbed: false });
|
||||
for (let t = 0; t < 900; t += 4) {
|
||||
const w = j.waves.find((q) => q.dir < 0);
|
||||
if (w && w.x - j.you.x > 0 && w.x - j.you.x < 4 && j.you.state === "run") j.input.jump = ghoul.JUMP_BUFFER_MS;
|
||||
ghoul.advance(j, 4, steady);
|
||||
}
|
||||
assert.deepEqual(events(j, "lose"), [], "jumped");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ the moves */
|
||||
|
||||
// The fight with `move` next, YOU at x (on a ledge's index when given).
|
||||
function moveRound(move, x = 100, shelf = -1, share = 1) {
|
||||
const r = pitFight();
|
||||
r.boss.hp = Math.max(2, Math.round(r.boss.max * share));
|
||||
standAt(r, x, shelf);
|
||||
holdShut(r.boss);
|
||||
Object.assign(r.boss, { plan: move, wait: 0 });
|
||||
return r;
|
||||
}
|
||||
|
||||
const HAZARD = { roots: "heartRoot", grab: "heartGrab", clots: "heartClot", quake: "heartChunk" };
|
||||
const WIND = { roots: "heartRootWind", grab: "heartGrabWind", clots: "heartClotWind", quake: "heartQuake" };
|
||||
|
||||
test("Ghoul Rush's Pit: every move is seen and heard well before it can hurt, hurts standing YOU with its own cause, and is dodged", () => {
|
||||
const cases = [["roots", 100, -1, 1], ["grab", 99, 1, 1], ["clots", 100, -1, 1], ["quake", 100, -1, 0.2]];
|
||||
for (const [move, x, shelf, share] of cases) {
|
||||
const r = moveRound(move, x, shelf, share);
|
||||
ghoul.advance(r, 4, steady);
|
||||
assert.equal(events(r, WIND[move]).length, 1, `${move}: its warning, heard`);
|
||||
const hz = r.hazards.filter((h) => h.kind === HAZARD[move]);
|
||||
assert.ok(hz.length >= 1, `${move}: something placed`);
|
||||
assert.ok(hz.every((h) => !(h.live > 0) && h.warn >= 900), `${move}: a warning of nearly a second or more before any can hurt`);
|
||||
// Standing still (the ledge's grab: staying on it) costs a life with its cause.
|
||||
const lost = [];
|
||||
for (let t = 0; t < 2500 && !lost.length; t += 4) {
|
||||
ghoul.advance(r, 4, steady);
|
||||
if (r.boss.act === "idle") r.boss.wait = 1e9;
|
||||
lost.push(...events(r, "lose"));
|
||||
r.events.length = 0;
|
||||
}
|
||||
assert.deepEqual(lost.map((e) => e.cause), [HAZARD[move]], `${move}: hurts`);
|
||||
// Dodged: off the ledge, or a few steps aside from where it will come.
|
||||
const d = moveRound(move, x, shelf, share);
|
||||
ghoul.advance(d, 4, steady);
|
||||
const far = [];
|
||||
for (let t = 0; t < 2500; t += 4) {
|
||||
if (d.phase === "play") {
|
||||
const threat = d.hazards.find((h) => Math.abs(h.x - d.you.x) < (h.w + 2.4) / 2 + 1.2);
|
||||
if (shelf >= 0) {
|
||||
if (d.you.shelf >= 0) standAt(d, 75);
|
||||
} else if (threat) standAt(d, Math.max(d.spec.arena + 4, Math.min(hr.LEFT_LIP - 3, threat.x + (threat.x > d.you.x ? -3.6 : 3.6))));
|
||||
}
|
||||
ghoul.advance(d, 4, steady);
|
||||
if (d.boss.act === "idle") d.boss.wait = 1e9;
|
||||
far.push(...events(d, "lose"));
|
||||
d.events.length = 0;
|
||||
}
|
||||
assert.deepEqual(far.map((e) => e.cause), [], `${move}: dodged`);
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Pit: the pick never plays a move three times running, grabs only while YOU are on a ledge, and the quake only below a quarter", () => {
|
||||
const b = {};
|
||||
const random = seededRandom(4);
|
||||
const picks = [];
|
||||
for (let i = 0; i < 300; i++) picks.push(hr.pickMove(b, 0, random, false));
|
||||
for (let i = 2; i < picks.length; i++) assert.ok(!(picks[i] === picks[i - 1] && picks[i] === picks[i - 2]), "never three running");
|
||||
assert.ok(!picks.includes("grab") && !picks.includes("quake"));
|
||||
const high = [];
|
||||
for (let i = 0; i < 200; i++) high.push(hr.pickMove(b, 2, random, true));
|
||||
assert.ok(high.includes("grab") && high.includes("quake"));
|
||||
assert.ok(high.filter((p) => p === "grab").length > high.filter((p) => p === "roots").length, "on a ledge, grabs most of all");
|
||||
assert.equal(hr.phaseFor(0.6), 0);
|
||||
assert.equal(hr.phaseFor(0.5), 1);
|
||||
assert.equal(hr.phaseFor(0.25), 2);
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------- the beat stops dead */
|
||||
|
||||
test("Ghoul Rush's Pit: below half the beat stops dead: silence, its swell heard well before, then a big double wave each way, and a long gasp of open ribs", () => {
|
||||
const r = pitFight();
|
||||
const b = r.boss;
|
||||
b.hp = Math.round(b.max * 0.45);
|
||||
r.you.safeMs = 1e9;
|
||||
Object.assign(b, { beatT: 1500, beatMs: 1499, beats: 99, stopAt: 3 });
|
||||
const seen = [];
|
||||
let opened = 0;
|
||||
let wasOpen = false;
|
||||
let openMs = 0;
|
||||
for (let t = 0; t < hr.STOP_MS + 1500; t += 4) {
|
||||
r.you.safeMs = 1e9;
|
||||
ghoul.advance(r, 4, steady);
|
||||
for (const e of r.events) if (e.type.startsWith("heart")) seen.push([e.type, t, !!e.echo]);
|
||||
if (b.open) openMs += 4;
|
||||
if (b.open && !wasOpen) opened++;
|
||||
wasOpen = b.open;
|
||||
r.events.length = 0;
|
||||
}
|
||||
const types = seen.map(([type]) => type);
|
||||
assert.equal(types[0], "heartStop");
|
||||
const swell = seen.find(([type]) => type === "heartSwell");
|
||||
const slams = seen.filter(([type]) => type === "heartSlam");
|
||||
assert.ok(swell && swell[1] >= hr.STOP_MS - hr.SWELL_MS - 10 && swell[1] <= hr.STOP_MS - hr.SWELL_MS + 10, "the swell, SWELL_MS before");
|
||||
assert.ok(!types.slice(0, types.indexOf("heartSlam")).includes("heartBeat"), "no beat in the silence");
|
||||
assert.equal(slams.length, 2, "a double wave");
|
||||
assert.ok(Math.abs(slams[1][1] - slams[0][1] - hr.BIG_GAP_MS) <= 8, "BIG_GAP_MS apart");
|
||||
assert.ok(openMs >= hr.openFor(0.45) * hr.beatFor(0.45) * hr.GASP * 0.9, `a long gasp open after it (${openMs} ms)`);
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ the hold */
|
||||
|
||||
test("Ghoul Rush's Pit: no bolt takes its last hp: it holds at 1, the ribs lock open and HOLD FIRE begins, once, with the story's click; the blaster fires nothing and cools", () => {
|
||||
const r = pitFight();
|
||||
const b = r.boss;
|
||||
standAt(r, 100);
|
||||
holdOpen(b);
|
||||
b.hp = 3;
|
||||
r.heat = 20;
|
||||
run(r, 1500, { fire: true });
|
||||
assert.equal(b.hp, 1, "held at 1");
|
||||
assert.equal(b.state, "fight");
|
||||
assert.equal(events(r, "heartHold").length, 1, "the hold, once");
|
||||
assert.equal(r.flood, true);
|
||||
assert.equal(r.heart.hold, true);
|
||||
assert.equal(VOICES.marrowheart.hold, "ghoulStoryClick");
|
||||
const shots = r.stats.shots;
|
||||
const heat = r.heat;
|
||||
run(r, 600, { fire: true });
|
||||
assert.equal(r.stats.shots, shots, "fire held fires nothing");
|
||||
assert.ok(r.heat <= heat, "and the heat cools");
|
||||
// A weapon's blow glances off in the hold (the guard).
|
||||
assert.equal(ghoul.guarded(r.boss), true);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Pit: in the hold the meter fills over about 4 s of fire held, drains slowly let go; weak beats every 1.5 s send ripples that only knock it back, never a life", () => {
|
||||
const r = pitFight();
|
||||
const b = r.boss;
|
||||
standAt(r, 100);
|
||||
b.hp = 1;
|
||||
hr.startHold(r, b);
|
||||
r.events.length = 0;
|
||||
// No weak beat for now: the meter alone.
|
||||
r.heart.beatMs = -1e9;
|
||||
run(r, 2000, { fire: true });
|
||||
assert.ok(Math.abs(r.heart.meter - 2000 / hr.HOLD_FILL_MS) < 0.03, `filling (${r.heart.meter})`);
|
||||
const m = r.heart.meter;
|
||||
run(r, 1000);
|
||||
assert.ok(r.heart.meter < m && r.heart.meter > m - 0.2, "drains slowly");
|
||||
r.heart.beatMs = 0;
|
||||
run(r, hr.HOLD_BEAT_MS + 20);
|
||||
assert.equal(events(r, "heartWeakBeat").length, 1, "a weak beat");
|
||||
assert.equal(r.heart.waves.length, 1, "and its ripple");
|
||||
r.heart.waves.length = 0;
|
||||
// A ripple reaching YOU knocks the meter back and costs nothing.
|
||||
const lives = r.lives;
|
||||
r.heart.meter = 0.6;
|
||||
r.heart.waves.push({ x: r.you.x + 0.5, y: 6, dir: -1 });
|
||||
run(r, 40, { fire: true });
|
||||
assert.equal(events(r, "heartKnock").length, 1);
|
||||
assert.ok(r.heart.meter < 0.6 - hr.HOLD_KNOCK + 0.05, "knocked back");
|
||||
assert.equal(r.lives, lives);
|
||||
assert.deepEqual(events(r, "lose"), []);
|
||||
// The flood swells out loud at each quarter climbed.
|
||||
r.heart.meter = 0.2;
|
||||
r.heart.step = 0;
|
||||
r.heart.beatMs = -1e9;
|
||||
r.heart.waves.length = 0;
|
||||
r.events.length = 0;
|
||||
run(r, 2400, { fire: true });
|
||||
assert.deepEqual(events(r, "heartFlood").map((e) => e.n), [1, 2, 3]);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Pit: the meter full turns the screen white, the last thump, the fall (a life, the points), then the daylight and its door, the finale's end", () => {
|
||||
const r = pitFight();
|
||||
const b = r.boss;
|
||||
standAt(r, 100);
|
||||
b.hp = 1;
|
||||
hr.startHold(r, b);
|
||||
r.heart.meter = 0.99;
|
||||
r.heart.step = 3;
|
||||
r.events.length = 0;
|
||||
const lives = r.lives;
|
||||
const order = [];
|
||||
for (let t = 0; t < hr.FALL_AT + hr.DAYLIGHT_AT + 800; t += 4) {
|
||||
r.input.fire = t < 300;
|
||||
ghoul.advance(r, 4, steady);
|
||||
for (const e of r.events) if (e.type.startsWith("heart") || e.type === "bossDown") order.push([e.type, t]);
|
||||
if (t > 400 && t < hr.WHITE_HOLD_MS) assert.ok(hr.whiteOf(r) > 0.9, "white");
|
||||
// (The fall's own slice hands the key over; the next takes it back till the daylight.)
|
||||
if (b.state === "down" && !b.gone && b.t > 8) assert.equal(r.hasKey, false, "no door until the daylight");
|
||||
r.events.length = 0;
|
||||
}
|
||||
assert.deepEqual(order.map(([type]) => type), ["heartWhite", "heartLast", "bossDown", "heartDaylight"]);
|
||||
assert.ok(order[1][1] - order[0][1] >= hr.LAST_AT - 10, "the last thump, after the white");
|
||||
assert.ok(order[2][1] - order[0][1] >= hr.FALL_AT - 10, "then the fall");
|
||||
assert.equal(b.state, "down");
|
||||
assert.equal(r.lives, lives + 1, "a life, as every boss gives");
|
||||
assert.equal(b.gone, true);
|
||||
assert.equal(r.hasKey, true);
|
||||
assert.equal(r.flood, false);
|
||||
assert.equal(hr.whiteOf(r), 0, "the white gone again");
|
||||
// Through the door of light: the finale's end.
|
||||
standAt(r, r.spec.door);
|
||||
run(r, 50);
|
||||
assert.equal(r.phase, "clear");
|
||||
run(r, ghoul.CLEAR_MS + 50);
|
||||
assert.ok(r.phase === "ending" || r.won, `the run's end (${r.phase})`);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Pit: a life lost keeps its hp and the hold, and the endless-lives code spares every hit", () => {
|
||||
const r = pitFight();
|
||||
const b = r.boss;
|
||||
b.hp = Math.round(b.max * 0.7);
|
||||
const hp = b.hp;
|
||||
standAt(r, 100);
|
||||
Object.assign(b, { beatT: 1e9, beatMs: hr.DUB_MS - 1, dubbed: false });
|
||||
run(r, 4000);
|
||||
assert.ok(events(r, "lose").length >= 1);
|
||||
assert.equal(r.boss.hp, hp, "its hp kept");
|
||||
// In the hold, a respawn holds on.
|
||||
const h = pitFight();
|
||||
h.boss.hp = 1;
|
||||
hr.startHold(h, h.boss);
|
||||
h.heart.meter = 0.4;
|
||||
standAt(h, hr.LEFT_LIP - 1);
|
||||
h.you.x = hr.LEFT_LIP + 2;
|
||||
h.you.state = "air";
|
||||
run(h, 3500);
|
||||
assert.ok(events(h, "lose").some((e) => e.cause === "pit"));
|
||||
assert.equal(h.boss.hp, 1);
|
||||
assert.equal(h.heart.hold, true);
|
||||
run(h, ghoul.BOSS_INTRO_MS + 200);
|
||||
assert.equal(h.flood, true, "still holding");
|
||||
// The endless-lives code.
|
||||
const e = moveRound("roots");
|
||||
e.infinite = true;
|
||||
const lives = e.lives;
|
||||
run(e, 2500);
|
||||
assert.ok(events(e, "lose").length >= 1, "hit");
|
||||
assert.equal(e.lives, lives, "no life spent");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ the fight */
|
||||
|
||||
// A steady player on the floor at HOME: fires so its bolts land while the ribs are open, jumps each wave,
|
||||
// steps aside from a root, a clot or a chunk, and in the hold holds fire and jumps the ripples.
|
||||
const HOME = 100;
|
||||
function fight(seed, skilled = true) {
|
||||
const round = pitFight();
|
||||
const random = seededRandom(seed);
|
||||
const b = round.boss;
|
||||
Object.assign(b, { wait: 600, beatT: 0 });
|
||||
let t = 0;
|
||||
const causes = [];
|
||||
for (; t < 240000 && b.state !== "down" && !round.over; t += 4) {
|
||||
const you = round.you;
|
||||
const inp = round.input;
|
||||
inp.left = inp.right = inp.fire = false;
|
||||
if (round.phase === "ask") ghoul.answerDie(round, false);
|
||||
if (skilled && round.phase === "play" && you.out <= 0) {
|
||||
const h = round.heart;
|
||||
const waves = h && h.hold ? h.waves : round.waves;
|
||||
const wave = waves.find((w) => w.dir < 0 && w.x - you.x > 0 && w.x - you.x < (h && h.hold ? 3 : 5));
|
||||
const threat = round.hazards.find((q) => (q.warn > 0 || q.live > 0) && Math.abs(q.x - you.x) < (q.w + 2.4) / 2 + 0.8);
|
||||
if (wave && you.state === "run") inp.jump = ghoul.JUMP_BUFFER_MS;
|
||||
if (threat) {
|
||||
const dir = threat.x >= you.x ? -1 : 1;
|
||||
const lo = round.spec.arena + 4;
|
||||
const hi = hr.LEFT_LIP - 4;
|
||||
inp[(dir < 0 ? you.x - 3 > lo : you.x + 3 > hi) ? "left" : "right"] = true;
|
||||
} else if (Math.abs(you.x - HOME) > 6 && !round.hazards.length) inp[you.x < HOME ? "right" : "left"] = true;
|
||||
else you.face = 1;
|
||||
// Fired so each bolt lands while the ribs are open (the way a player learns the beat).
|
||||
const travel = ((hr.HEART_X - hr.HEART_BOX_W / 2 - you.x - 1.8) / 130) * 1000;
|
||||
const span = hr.openFor(b.hp / b.max) * b.beatT * (b.gasp ? hr.GASP : 1);
|
||||
const at = (b.beatMs || 0) + travel;
|
||||
inp.fire = h && h.hold ? true : !(b.stopMs > 0) && at >= hr.OPEN_AT + 10 && at <= hr.OPEN_AT + span - 10 && you.face === 1;
|
||||
}
|
||||
ghoul.advance(round, 4, random);
|
||||
causes.push(...events(round, "lose").map((e) => e.cause));
|
||||
round.events.length = 0;
|
||||
}
|
||||
return { won: b.state === "down", secs: t / 1000, causes, round };
|
||||
}
|
||||
|
||||
test("Ghoul Rush's Pit takes a steady player a real fight at full depth: 60 to 120 seconds on most seeds, with lives to spare; a player who stands still dies", () => {
|
||||
const times = [];
|
||||
const lives = [];
|
||||
let good = 0;
|
||||
for (const seed of [3, 7, 19, 41]) {
|
||||
const f = fight(seed);
|
||||
assert.ok(f.won, `seed ${seed}: it stopped (${f.causes}; ${f.secs.toFixed(1)} s, hp ${f.round.boss.hp})`);
|
||||
assert.ok(f.round.lives > 0, `seed ${seed}: lives to spare (${f.causes})`);
|
||||
for (const c of f.causes) assert.ok(LOSE_WORDS[c] || c === "pit", `${c} is the heart's`);
|
||||
if (f.secs >= 60 && f.secs <= 120) good++;
|
||||
times.push(f.secs);
|
||||
lives.push(f.round.lives);
|
||||
}
|
||||
assert.ok(good >= 3, `most seeds in 60 to 120 s (${times.map((x) => x.toFixed(1))}; lives ${lives})`);
|
||||
const idle = fight(7, false);
|
||||
assert.equal(idle.won, false);
|
||||
assert.ok(idle.round.over, `game over (${idle.causes})`);
|
||||
assert.equal(idle.round.boss.hp, idle.round.boss.max, "and not a scratch on it");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------- voices, words, drawing */
|
||||
|
||||
const heard = (e) => {
|
||||
const played = [];
|
||||
const noop = () => {};
|
||||
const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, markFurthest: noop };
|
||||
react(e, kit);
|
||||
return played;
|
||||
};
|
||||
|
||||
test("Ghoul Rush's heart: a voice for every act in tones.js, every event plays its own sound once, and every cause has words and a sound", () => {
|
||||
const known = new Set(toneNames());
|
||||
for (const [act, name] of Object.entries(VOICES.marrowheart)) assert.ok(known.has(name), `${act}: ${name} is a tone`);
|
||||
const at = { kind: "marrowheart", x: 120, y: 20, xs: [100], n: 1 };
|
||||
const cases = { heartBeat: "beat", heartOpen: "open", heartRootWind: "rootWind", heartRootCrack: "rootCrack", heartRootUp: "rootUp", heartGrabWind: "grabWind", heartGrabTense: "grabTense", heartGrabLash: "grabLash", heartClotWind: "clotWind", heartClotLand: "clotLand", heartQuake: "quake", heartChunkLand: "chunk", heartStop: "stop", heartSwell: "swell", heartSlam: "slam", heartHold: "hold", heartWeakBeat: "weakBeat", heartKnock: "knock", heartFlood: "flood", heartWhite: "white", heartLast: "last", heartDaylight: "daylight", bossWake: "wake", bossHit: "hurt", bossDown: "die" };
|
||||
for (const [type, act] of Object.entries(cases)) {
|
||||
const played = heard({ type, ...at, how: "shot", points: 1, life: true });
|
||||
assert.equal(played.filter((n) => n === VOICES.marrowheart[act]).length, 1, `${type}: ${VOICES.marrowheart[act]} once`);
|
||||
}
|
||||
assert.deepEqual(heard({ type: "heartWave", ...at }), [], "the dub is the beat's own second thump");
|
||||
for (const cause of ["marrowheart", "heartBeat", "heartBig", "heartRoot", "heartGrab", "heartClot", "heartChunk"]) {
|
||||
assert.ok(LOSE_WORDS[cause], `${cause}: words`);
|
||||
assert.ok(known.has(LOSE_SOUNDS[cause][0]), `${cause}: a sound`);
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Pit draws: the walk in, the heart asleep, every beat's moment, every move's warning and hit, the stopped beat and the slam, the hold, the white, the stopped heart and the daylight, lit and dark, and its card", () => {
|
||||
const { canvas, calls } = stubCanvas();
|
||||
const g = ghoul.default.create({ canvas });
|
||||
g.resize(900, 900);
|
||||
g.stageSelect();
|
||||
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g.key("down");
|
||||
for (let i = 0; i < ghoul.FINALE.rooms.indexOf("pit"); i++) g.key("right");
|
||||
g.key("action");
|
||||
for (let n = 0; n < 3 && g.round.phase !== "ready" && g.round.phase !== "play"; n++) {
|
||||
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 50; ms += 16) g.tick(16);
|
||||
g.key("action");
|
||||
}
|
||||
const r = g.round;
|
||||
assert.equal(r.spec.id, "pit");
|
||||
r.infinite = true;
|
||||
const frame = (label) => {
|
||||
const before = calls.count;
|
||||
g.tick(16);
|
||||
assert.ok(calls.count > before, `${label} draws`);
|
||||
};
|
||||
for (const dark of [false, true]) {
|
||||
r.dark = dark;
|
||||
standAt(r, 20);
|
||||
frame("the walk in");
|
||||
standAt(r, 100);
|
||||
for (let ms = 0; ms < 1600; ms += 16) g.tick(16);
|
||||
for (const beatMs of [10, 200, 320, 500, 1300]) {
|
||||
Object.assign(r.boss, { beatT: 1500, beatMs, wait: 1e9 });
|
||||
frame(`the beat at ${beatMs}`);
|
||||
}
|
||||
for (const [move, share] of [["roots", 1], ["clots", 0.6], ["quake", 0.2]]) {
|
||||
r.boss.hp = Math.round(r.boss.max * share);
|
||||
Object.assign(r.boss, { plan: move, act: "idle", wait: 0 });
|
||||
for (let ms = 0; ms < 1600; ms += 16) frame(move);
|
||||
}
|
||||
standAt(r, 99, 1);
|
||||
Object.assign(r.boss, { plan: "grab", act: "idle", wait: 0 });
|
||||
for (let ms = 0; ms < 1600; ms += 16) frame("grab");
|
||||
standAt(r, 100);
|
||||
Object.assign(r.boss, { stopMs: 1200, swelled: false });
|
||||
for (let ms = 0; ms < 1800; ms += 16) frame("the stop and the slam");
|
||||
}
|
||||
r.boss.hp = 1;
|
||||
hr.startHold(r, r.boss);
|
||||
r.heart.meter = 0.5;
|
||||
r.input.fire = true;
|
||||
for (let ms = 0; ms < 2600; ms += 16) frame("the hold");
|
||||
for (let ms = 0; ms < 6000; ms += 16) frame("the white, the fall and the daylight");
|
||||
assert.equal(r.boss.state, "down");
|
||||
// The boss card's fake view: no round, no room, the floor at 0.
|
||||
const def = ghoul.BOSSES.marrowheart;
|
||||
assert.ok(def.w >= 30 && def.h >= 36, "the card sizes its spotlight to the whole heart");
|
||||
const noop = () => {};
|
||||
const art = heartArt({ ellipse: noop, circle: noop, roundRect: noop, line: noop, rotate: noop, hash: (a, b) => Math.abs(a * 31 + b * 17) % 997, say: noop, gate: () => true, label: noop, DANGER: "#ff3030", GOLD: "#f5b301" });
|
||||
const card = stubCanvas();
|
||||
const fake = { kind: "marrowheart", x: 0, y: 0, w: def.w, h: def.h, hp: 1, max: 1, state: "fight", t: 0 };
|
||||
for (const clock of [0, 400, 900]) art.bosses.marrowheart(card.ctx, { g: { FIELD_H: 0 }, clock, spec: null, groundAt: () => 0, eyes: [] }, fake);
|
||||
assert.ok(card.calls.count > 50, "the card's heart draws");
|
||||
});
|
||||
@@ -51,8 +51,8 @@ test("Ghoul Rush intros: every stage has a card of 3 or 4 short lines, no em das
|
||||
assert.ok(size > 0 && size <= TITLE_SIZE, `${st.id}'s title has a size`);
|
||||
assert.ok(Math.abs(xs[0]) < field / 2 && Math.abs(xs[xs.length - 1]) < field / 2, `${st.id}'s title fits the field`);
|
||||
}
|
||||
assert.deepEqual(Object.keys(INTROS).sort(), ghoul.STAGES.map((st) => st.id).sort(), "no intro for a stage that does not exist");
|
||||
assert.equal(new Set(ghoul.STAGES.flatMap((st) => introFor(st.id).lines)).size, ghoul.STAGES.reduce((n, st) => n + introFor(st.id).lines.length, 0), "no line used twice");
|
||||
assert.deepEqual(Object.keys(INTROS).sort(), ghoul.SELECTABLE.map((st) => st.id).sort(), "no intro for a stage that does not exist");
|
||||
assert.equal(new Set(ghoul.SELECTABLE.flatMap((st) => introFor(st.id).lines)).size, ghoul.SELECTABLE.reduce((n, st) => n + introFor(st.id).lines.length, 0), "no line used twice");
|
||||
assert.ok(toneNames().includes("ghoulStageIntro"));
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,643 @@
|
||||
// Web console tests, Ghoul Rush's finale: the win condition (RUN_STAGES stages, then the House
|
||||
// with no offer, its record one past every stage), the words that count the stages, and Kill I,
|
||||
// The Lawn: the windows (hit from the surface that serves each row, passed while shuttered, out
|
||||
// for good across a life lost), the rows opening, each move's telegraph, hit and dodge, the
|
||||
// weighted pick, the wall in front of the house, the retreat in order and its standing door, a
|
||||
// bot's fight length, the voices, words and drawing.
|
||||
// Run with: node --test scripts/test-web-console-activities-ghoul-marrow.mjs
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
|
||||
import * as mw from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow.js";
|
||||
import { LOSE_SOUNDS, LOSE_WORDS, VOICES } from "../src/web-console/public/activities/ghoul-rush/stages/marrow/ghoul-marrow-draw.js";
|
||||
import { react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
|
||||
import { bossIntroFor } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-boss-intros.js";
|
||||
import { introFor } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-intros.js";
|
||||
import { skipStory } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-story.js";
|
||||
import { skipEnding } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-ending.js";
|
||||
import { toneNames } from "../src/web-console/public/tones.js";
|
||||
|
||||
const steady = () => 0.5;
|
||||
const events = (round, type) => round.events.filter((e) => e.type === type);
|
||||
const seededRandom = (seed) => {
|
||||
let s = seed;
|
||||
return () => (s = (s * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff;
|
||||
};
|
||||
|
||||
function stubCanvas() {
|
||||
const calls = { count: 0 };
|
||||
const ctx = new Proxy({}, {
|
||||
get: (target, name) => (name in target ? target[name] : () => { calls.count += 1; }),
|
||||
set: (target, name, value) => { target[name] = value; return true; },
|
||||
});
|
||||
return { canvas: { width: 0, height: 0, getContext: () => ctx }, calls };
|
||||
}
|
||||
|
||||
function textCanvas() {
|
||||
const texts = [];
|
||||
const ctx = new Proxy({}, {
|
||||
get: (target, name) => (name === "fillText" ? (text) => texts.push([String(text)]) : name in target ? target[name] : () => {}),
|
||||
set: (target, name, value) => { target[name] = value; return true; },
|
||||
});
|
||||
return { canvas: { width: 0, height: 0, getContext: () => ctx }, texts };
|
||||
}
|
||||
|
||||
function through(round) {
|
||||
round.phase = "clear";
|
||||
round.phaseMs = 1;
|
||||
ghoul.advance(round, 4, steady);
|
||||
}
|
||||
|
||||
// Through the rest of the House, room by room (each card passed), then past the ending's pages: the win.
|
||||
function finishHouse(round, g = null) {
|
||||
for (let n = 0; n < 20 && !round.over; n++) {
|
||||
if (round.phase === "ending") skipEnding(round);
|
||||
else {
|
||||
if (round.phase === "intro" || round.phase === "bossintro") skipCard(round);
|
||||
if (round.phase === "intro" || round.phase === "bossintro") skipCard(round);
|
||||
through(round);
|
||||
}
|
||||
if (g) g.tick(16);
|
||||
}
|
||||
}
|
||||
|
||||
function skipCard(round) {
|
||||
round.introMs = ghoul.INTRO_MIN_MS;
|
||||
return ghoul.takeIntro(round);
|
||||
}
|
||||
|
||||
function standAt(round, x, shelf = -1) {
|
||||
const y = shelf >= 0 ? round.spec.shelves[shelf][2] : ghoul.groundAt(round.spec, x);
|
||||
Object.assign(round.you, { x, y, vx: 0, vy: 0, state: "run", shelf, coyote: 0, drop: -1, cuttable: false, out: 0, safeMs: 0, face: 1 });
|
||||
}
|
||||
|
||||
function run(round, ms, keys = {}, random = steady) {
|
||||
Object.assign(round.input, keys);
|
||||
for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random);
|
||||
for (const k of Object.keys(keys)) round.input[k] = false;
|
||||
}
|
||||
|
||||
// A run's way to the House: out of the hall, `depth` stages already behind it, into the
|
||||
// finale (its stage card and the boss's passed), nothing else woken.
|
||||
function lawnRound(depth = ghoul.RUN_STAGES) {
|
||||
const round = ghoul.newRound(5);
|
||||
round.dice = 0;
|
||||
through(round);
|
||||
round.cleared = ghoul.STAGES.slice(0, depth).map((st) => st.id);
|
||||
round.offer = null;
|
||||
through(round);
|
||||
assert.equal(round.spec.id, "lawn");
|
||||
skipCard(round);
|
||||
skipCard(round);
|
||||
round.phase = "play";
|
||||
for (const st of round.spawns) st.over = true;
|
||||
round.monsters.length = 0;
|
||||
round.hordeMs = Infinity;
|
||||
round.items.fill(true);
|
||||
round.candy.fill(true);
|
||||
round.events.length = 0;
|
||||
return round;
|
||||
}
|
||||
|
||||
// Nothing moves: no window lit, the next move a long way off.
|
||||
function calm(round) {
|
||||
const b = round.boss;
|
||||
for (const w of round.marrow.windows) if (w.state === "lit") w.state = "dark";
|
||||
Object.assign(b, { act: "idle", wait: 1e9, litMs: 1e9, relight: 0 });
|
||||
round.hazards.length = 0;
|
||||
round.waves.length = 0;
|
||||
round.monsters.length = 0;
|
||||
}
|
||||
|
||||
// The fight under way: in the arena, the boss awake and idle a long while, no window lit.
|
||||
function lawnFight(depth = ghoul.RUN_STAGES) {
|
||||
const round = lawnRound(depth);
|
||||
standAt(round, 130);
|
||||
run(round, ghoul.BOSS_INTRO_MS + 100);
|
||||
assert.equal(round.boss.state, "fight");
|
||||
calm(round);
|
||||
round.events.length = 0;
|
||||
return round;
|
||||
}
|
||||
|
||||
// Where each row is shot from: [x, shelf index or -1 for the floor].
|
||||
const SERVES = Object.freeze({ 0: [160, -1], 1: [145, 2], 2: [145, 5], 3: [162, 6] });
|
||||
|
||||
function lightOnly(round, id) {
|
||||
for (const w of round.marrow.windows) if (w.state !== "out") w.state = w.id === id ? "lit" : "dark";
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------- the win condition */
|
||||
|
||||
test("Ghoul Rush's finale: a run offers RUN_STAGES picks of stages that never repeat, then goes to the House with no offer, its card and the boss's first; clearing it wins", () => {
|
||||
const round = ghoul.newRound(9);
|
||||
round.dice = 0;
|
||||
through(round);
|
||||
let picks = 0;
|
||||
while (round.phase === "pick") {
|
||||
picks++;
|
||||
round.phaseMs = 0;
|
||||
ghoul.pickStage(round);
|
||||
for (let k = 0, n = ghoul.stageById(round.stage).rooms.length; k < n; k++) through(round);
|
||||
}
|
||||
assert.equal(picks, ghoul.RUN_STAGES, "six picks");
|
||||
assert.equal(new Set(round.cleared).size, ghoul.RUN_STAGES, "no stage twice");
|
||||
assert.equal(events(round, "offer").length, ghoul.RUN_STAGES, "no offer for the House");
|
||||
assert.deepEqual([round.stage, round.spec.id, round.phase], [ghoul.FINALE.id, "lawn", "intro"], "the sixth clear opens the House's card");
|
||||
assert.deepEqual(events(round, "stage").at(-1), { type: "stage", stage: "marrow", n: ghoul.RUN_STAGES, of: ghoul.RUN_STAGES });
|
||||
assert.ok(events(round, "stageClear").every((e) => e.of === ghoul.RUN_STAGES));
|
||||
assert.ok(introFor("marrow") && bossIntroFor("marrow"), "both cards exist");
|
||||
assert.equal(skipCard(round), true);
|
||||
assert.equal(round.phase, "bossintro", "then the boss's card");
|
||||
assert.equal(skipCard(round), true);
|
||||
assert.equal(round.phase, "ready");
|
||||
assert.equal(round.spec.depth, ghoul.RUN_STAGES, "played at full depth");
|
||||
finishHouse(round);
|
||||
assert.equal(round.won, true);
|
||||
assert.deepEqual(events(round, "won").map((e) => e.n), [ghoul.RUN_STAGES + 1]);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's finale is never offered, and the stage select lists it last, played at depth 0", () => {
|
||||
assert.ok(!ghoul.STAGES.includes(ghoul.FINALE));
|
||||
assert.equal(ghoul.SELECTABLE.at(-1), ghoul.FINALE);
|
||||
assert.equal(ghoul.stageById("marrow"), ghoul.FINALE);
|
||||
assert.equal(ghoul.FINALE.rooms[0], "lawn");
|
||||
assert.equal(ghoul.roomById("lawn").boss, "marrow");
|
||||
for (let seed = 1; seed < 30; seed++) {
|
||||
const r = ghoul.newRound(seed);
|
||||
r.dice = 0;
|
||||
through(r);
|
||||
assert.ok(!r.offer.includes("marrow"));
|
||||
}
|
||||
const g = ghoul.default.create({ canvas: stubCanvas().canvas });
|
||||
g.resize(900, 900);
|
||||
g.stageSelect();
|
||||
for (let i = 0; i < ghoul.SELECTABLE.length + 2; i++) g.key("down");
|
||||
assert.equal(g.round.select.at, ghoul.SELECTABLE.length - 1);
|
||||
g.key("action");
|
||||
assert.deepEqual([g.round.stage, g.round.spec.id, g.round.phase], ["marrow", "lawn", "intro"]);
|
||||
assert.equal(g.round.spec.depth, 0, "practice plays it at depth 0");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's record: the memo counts stages up to RUN_STAGES, goes one past only on a win, never from practice, and the words count RUN_STAGES whatever STAGES holds", () => {
|
||||
const { canvas, texts } = textCanvas();
|
||||
let saved = 0;
|
||||
const g = ghoul.default.create({ canvas, memo: { get: () => saved, set: (n) => (saved = n) } });
|
||||
g.resize(900, 900);
|
||||
assert.ok(ghoul.STAGES.length !== ghoul.RUN_STAGES, "the pool is bigger than a run");
|
||||
assert.ok(texts.some(([t]) => t === `Run. Shoot. Clear ${ghoul.RUN_STAGES} stages, then kill the house`));
|
||||
assert.ok(texts.some(([t]) => t.includes(`Best: 0 of ${ghoul.RUN_STAGES} stages`)));
|
||||
g.key("action");
|
||||
if (g.round.phase === "story") {
|
||||
skipStory(g.round);
|
||||
g.tick(0);
|
||||
}
|
||||
const r = g.round;
|
||||
r.dice = 0;
|
||||
const last = ghoul.STAGES[ghoul.RUN_STAGES - 1];
|
||||
r.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES - 1).map((s) => s.id);
|
||||
r.stage = last.id;
|
||||
r.stageAt = last.rooms.length - 1;
|
||||
through(r);
|
||||
g.tick(16);
|
||||
assert.equal(saved, ghoul.RUN_STAGES, "every stage, not yet the House");
|
||||
assert.equal(g.hud.stage, "THE HOUSE: KILL 1 OF 3");
|
||||
finishHouse(r, g);
|
||||
g.tick(16);
|
||||
assert.equal(g.state, "over");
|
||||
assert.equal(saved, ghoul.RUN_STAGES + 1, "the House beaten");
|
||||
texts.length = 0;
|
||||
g.resize(900, 900);
|
||||
assert.ok(texts.some(([t]) => t.startsWith("You escaped! Marrow starves")));
|
||||
// A memo from before reads as beaten, and the start screen says so.
|
||||
const again = textCanvas();
|
||||
const g2 = ghoul.default.create({ canvas: again.canvas, memo: { get: () => 11, set: () => {} } });
|
||||
g2.resize(900, 900);
|
||||
assert.ok(again.texts.some(([t]) => t.includes("You have killed the House")));
|
||||
// Practice never writes it.
|
||||
let p = 0;
|
||||
const g3 = ghoul.default.create({ canvas: stubCanvas().canvas, memo: { get: () => p, set: (n) => (p = n) } });
|
||||
g3.resize(900, 900);
|
||||
g3.stageSelect();
|
||||
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g3.key("down");
|
||||
g3.key("action");
|
||||
finishHouse(g3.round, g3);
|
||||
g3.tick(16);
|
||||
assert.equal(g3.round.won, true);
|
||||
assert.equal(p, 0, "practice keeps nothing");
|
||||
});
|
||||
|
||||
/* --------------------------------------------------------------- the lawn */
|
||||
|
||||
test("Ghoul Rush's lawn: the house fills the arena's right, YOU are kept off it, its box is out of reach and always guarded, and its hp is its windows' sum", () => {
|
||||
const round = lawnFight();
|
||||
const b = round.boss;
|
||||
const spec = round.spec;
|
||||
assert.equal(ghoul.roomById("lawn").boss, "marrow");
|
||||
assert.equal(mw.houseLeft(spec), 172);
|
||||
assert.ok(b.x > mw.houseLeft(spec) + mw.HOUSE_W, "its box past the house's far wall");
|
||||
assert.equal(ghoul.guarded(b), true);
|
||||
const share = Math.ceil(spec.bossHp / mw.WINDOWS.length);
|
||||
assert.equal(b.max, share * mw.WINDOWS.length);
|
||||
assert.equal(b.hp, round.marrow.windows.reduce((s, w) => s + w.hp, 0));
|
||||
standAt(round, 160);
|
||||
run(round, 1500, { right: true });
|
||||
assert.ok(round.you.x <= mw.houseLeft(spec) - mw.WALL_GAP + 0.5, `held off the house (${round.you.x.toFixed(2)})`);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's lawn: every window can be shot from the surface that serves its row; a shuttered one lets the bolts by", () => {
|
||||
mw.WINDOWS.forEach(([row, dx], id) => {
|
||||
const round = lawnFight();
|
||||
const win = round.marrow.windows[id];
|
||||
const [x, shelf] = SERVES[row];
|
||||
standAt(round, x, shelf);
|
||||
const full = win.hp;
|
||||
run(round, 1200, { fire: true });
|
||||
assert.equal(win.hp, full, `window ${id}: shuttered, untouched`);
|
||||
lightOnly(round, id);
|
||||
round.heat = 0;
|
||||
round.events.length = 0;
|
||||
run(round, 800, { fire: true });
|
||||
assert.ok(win.hp < full, `window ${id} (row ${row}): hit from ${shelf < 0 ? "the floor" : `shelf ${shelf}`}`);
|
||||
assert.equal(round.boss.hp, round.marrow.windows.reduce((s, q) => s + q.hp, 0), "hp is the windows' sum");
|
||||
assert.ok(events(round, "bossHit").every((e) => e.how === "window" && Math.abs(e.x - (mw.houseCenter(round.spec) + dx)) < 0.01), "the hit shows at the window");
|
||||
});
|
||||
});
|
||||
|
||||
test("Ghoul Rush's lawn: a window shot out stays out across a life lost, and lit windows come only from the rows open by how many are out", () => {
|
||||
assert.deepEqual([0, 3, 4, 7, 8, 12].map(mw.rowsOpen), [1, 1, 2, 2, 3, 3]);
|
||||
const round = lawnFight();
|
||||
const b = round.boss;
|
||||
const win = round.marrow.windows[0];
|
||||
b.hp -= win.hp - 1;
|
||||
win.hp = 1;
|
||||
lightOnly(round, 0);
|
||||
standAt(round, 160);
|
||||
run(round, 400, { fire: true });
|
||||
assert.equal(win.state, "out");
|
||||
assert.deepEqual(events(round, "marrowWindowOut").map((e) => e.left), [mw.WINDOWS.length - 1]);
|
||||
const hp = round.boss.hp;
|
||||
round.lives = 5;
|
||||
ghoul.lose(round, "marrowShingle");
|
||||
run(round, ghoul.CRASH_MS + ghoul.READY_MS + 100);
|
||||
assert.notEqual(round.boss, b, "a new boss object after the life lost");
|
||||
assert.equal(round.marrow.windows[0].state, "out", "still out");
|
||||
assert.equal(round.boss.hp, hp, "the same hp");
|
||||
const r2 = lawnFight();
|
||||
const random = seededRandom(4);
|
||||
r2.boss.litMs = 0;
|
||||
for (let t = 0; t < 60000; t += 4) {
|
||||
r2.you.safeMs = 1e9;
|
||||
r2.boss.wait = 1e9;
|
||||
ghoul.advance(r2, 4, random);
|
||||
const out = r2.marrow.windows.filter((w) => w.state === "out").length;
|
||||
for (const w of r2.marrow.windows) if (w.state === "lit") assert.ok(w.row <= mw.rowsOpen(out), `row ${w.row} lit with ${out} out`);
|
||||
// Shoot one out now and then, so every row gets its turn.
|
||||
if (t % 2000 === 0 && out < mw.WINDOWS.length - 1) {
|
||||
const lit = r2.marrow.windows.find((w) => w.state === "lit");
|
||||
if (lit) {
|
||||
r2.boss.hp -= lit.hp;
|
||||
Object.assign(lit, { hp: 0, state: "out" });
|
||||
r2.boss.relight = mw.RELIGHT_MS;
|
||||
}
|
||||
}
|
||||
r2.events.length = 0;
|
||||
}
|
||||
assert.ok(r2.marrow.windows.filter((w) => w.state === "out").length >= 9, "the fight reached the eyes");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's lawn: the pick opens on the carpet, never one move three times running, the slow moves sit out their cooldown, the doormen only under their cap, and each phase's moves only", () => {
|
||||
const random = seededRandom(11);
|
||||
for (const phase of [0, 1, 2]) {
|
||||
const b = {};
|
||||
const picks = [];
|
||||
for (let i = 0; i < 400; i++) picks.push(mw.pickMove(b, phase, random, 0));
|
||||
assert.equal(picks[0], "carpet");
|
||||
for (let i = 2; i < picks.length; i++) assert.ok(!(picks[i] === picks[i - 1] && picks[i] === picks[i - 2]), `phase ${phase}: never three running`);
|
||||
for (const [move, n] of Object.entries(mw.COOLDOWN)) {
|
||||
const at = picks.flatMap((p, i) => (p === move ? [i] : []));
|
||||
for (let i = 1; i < at.length; i++) assert.ok(at[i] - at[i - 1] > n, `phase ${phase}: ${move} sits out ${n}`);
|
||||
}
|
||||
for (const [move, w] of Object.entries(mw.WEIGHTS)) if (!w[phase]) assert.ok(!picks.includes(move), `phase ${phase}: no ${move}`);
|
||||
assert.ok(new Set(picks).size >= [3, 5, 6][phase], `phase ${phase}: varied (${[...new Set(picks)]})`);
|
||||
}
|
||||
const b = { picks: 3 };
|
||||
for (let i = 0; i < 100; i++) assert.notEqual(mw.pickMove(b, 1, random, mw.DOORMEN_CAP), "doormen");
|
||||
// Up in the oak the lightning and the crows join, and only there; the crows under their cap.
|
||||
for (const phase of [0, 1, 2]) {
|
||||
const up = {};
|
||||
const picks = [];
|
||||
for (let i = 0; i < 400; i++) picks.push(mw.pickMove(up, phase, random, 0, true, 0));
|
||||
assert.ok(picks.includes("lightning") && picks.includes("crows"), `phase ${phase}: high moves when high`);
|
||||
const capped = { picks: 3 };
|
||||
for (let i = 0; i < 100; i++) assert.notEqual(mw.pickMove(capped, phase, random, 0, true, mw.CROWS_CAP), "crows");
|
||||
}
|
||||
const round = lawnFight();
|
||||
standAt(round, 160);
|
||||
assert.equal(mw.isHigh(round), false, "the lawn is not high");
|
||||
standAt(round, 143, 2);
|
||||
assert.equal(mw.isHigh(round), true, "a branch is");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's lawn: up in the oak, lightning glows on YOUR branch before it strikes (a life, struck down), and a step along it or a drop dodges it; from the second phase a second bolt waits ahead", () => {
|
||||
const go = (outs) => {
|
||||
const round = lawnFight();
|
||||
for (const w of round.marrow.windows.slice(0, outs)) {
|
||||
round.boss.hp -= w.hp;
|
||||
Object.assign(w, { hp: 0, state: "out" });
|
||||
}
|
||||
standAt(round, 141, 2);
|
||||
Object.assign(round.boss, { plan: "lightning", wait: 0, picks: 1 });
|
||||
run(round, 4);
|
||||
return round;
|
||||
};
|
||||
const hit = go(0);
|
||||
assert.equal(events(hit, "marrowStorm").length, 1, "the storm gathers first");
|
||||
const bolts = hit.hazards.filter((h) => h.kind === "marrowBolt");
|
||||
assert.deepEqual(bolts.map((h) => [h.x, h.y]), [[141, 18]], "one glow where YOU stand, at YOUR height");
|
||||
const losses = [];
|
||||
const heard = [];
|
||||
for (let t = 0; t < 3000 && !losses.length; t += 4) {
|
||||
ghoul.advance(hit, 4, steady);
|
||||
losses.push(...events(hit, "lose"));
|
||||
for (const e of hit.events) if (e.type === "marrowCharge" || e.type === "marrowStrike") heard.push([e.type, t]);
|
||||
if (t < mw.LIGHTNING_WARN_MS) assert.equal(losses.length, 0, "never before its glow has run");
|
||||
hit.events.length = 0;
|
||||
}
|
||||
assert.deepEqual(losses.map((e) => e.cause), ["marrowBolt"]);
|
||||
assert.deepEqual(heard.map(([type]) => type), ["marrowCharge", "marrowCharge", "marrowStrike"], "it charges up out loud twice before it strikes");
|
||||
assert.ok(heard[0][1] >= 400 && heard[2][1] - heard[1][1] >= 400, "each step well apart");
|
||||
for (const dodge of [(r) => standAt(r, 145.5, 2), (r) => standAt(r, 141)]) {
|
||||
const safe = go(0);
|
||||
dodge(safe);
|
||||
const lost = [];
|
||||
for (let t = 0; t < 2500; t += 4) {
|
||||
ghoul.advance(safe, 4, steady);
|
||||
if (safe.boss.act === "idle") safe.boss.wait = 1e9;
|
||||
lost.push(...events(safe, "lose"));
|
||||
safe.events.length = 0;
|
||||
}
|
||||
assert.deepEqual(lost, [], "dodged");
|
||||
}
|
||||
const two = go(4);
|
||||
assert.equal(two.hazards.filter((h) => h.kind === "marrowBolt").length, 2, "a second bolt from the second phase");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's lawn: up in the oak, crows burst out of the door's mouth, climb and dive at YOU, never more than CROWS_CAP of its own", () => {
|
||||
const round = lawnFight();
|
||||
standAt(round, 143, 2);
|
||||
round.you.safeMs = 1e9;
|
||||
Object.assign(round.boss, { plan: "crows", wait: 0, picks: 1 });
|
||||
run(round, 4);
|
||||
assert.equal(round.boss.act, "crowsWind");
|
||||
run(round, 4);
|
||||
assert.equal(round.boss.mouth, true, "the door is open");
|
||||
run(round, mw.CROWS_WIND_MS + 40);
|
||||
const crows = round.monsters.filter((m) => m.houseCrow);
|
||||
assert.equal(crows.length, mw.CROWS_N[0]);
|
||||
assert.ok(crows.every((m) => m.kind === "crow" && Math.abs(m.x - mw.houseLeft(round.spec)) < 8), "out of the door");
|
||||
assert.equal(events(round, "marrowCrows").length, 1);
|
||||
run(round, 900);
|
||||
assert.ok(round.monsters.some((m) => m.houseCrow && m.act === "dive"), "a dive at YOU");
|
||||
Object.assign(round.boss, { plan: "crows", wait: 0 });
|
||||
run(round, mw.CROWS_WIND_MS + 60);
|
||||
assert.ok(round.monsters.filter((m) => m.houseCrow && !m.dead).length <= mw.CROWS_CAP);
|
||||
});
|
||||
|
||||
// A move started now, YOU on the floor at `x`, `outs` windows already shot out (for its phase).
|
||||
function moveRound(move, x = 150, outs = 0) {
|
||||
const round = lawnFight();
|
||||
for (const w of round.marrow.windows.slice(0, outs)) {
|
||||
round.boss.hp -= w.hp;
|
||||
Object.assign(w, { hp: 0, state: "out" });
|
||||
}
|
||||
standAt(round, x);
|
||||
Object.assign(round.boss, { plan: move, wait: 0, picks: 1 });
|
||||
run(round, 4);
|
||||
assert.equal(round.boss.move, move);
|
||||
return round;
|
||||
}
|
||||
|
||||
// Steps YOU once out from under the first warning of `kind` that lands where YOU stand.
|
||||
const stepOut = (kind, dx) => (r) => {
|
||||
if (r.stepped) return;
|
||||
const h = r.hazards.find((q) => q.kind === kind && q.warn > 0 && Math.abs(q.x - r.you.x) < 3);
|
||||
if (!h) return;
|
||||
r.stepped = true;
|
||||
standAt(r, r.you.x + dx, r.you.shelf);
|
||||
};
|
||||
|
||||
test("Ghoul Rush's lawn: each move telegraphs before it can hurt, hurts standing YOU with its own cause, and is dodged", () => {
|
||||
const cases = [
|
||||
["shingles", "marrowRoof", "marrowShingle", 0, (r) => r.stepped || ((r.stepped = true), standAt(r, 146))],
|
||||
["pickets", "marrowPicketWind", "marrowPicket", 0, (r) => r.stepped || ((r.stepped = true), standAt(r, 146))],
|
||||
["carpet", "marrowDoor", "marrowCarpet", 0, (r) => r.stepped || ((r.stepped = true), standAt(r, 143, 2))],
|
||||
["bricks", "marrowCough", "marrowBrick", 4, stepOut("marrowBrick", -6)],
|
||||
["stomp", "marrowRear", "marrowQuake", 8, (r) => { if (!r.climbed) { r.climbed = true; standAt(r, 143, 2); } stepOut("marrowShingle", 4)(r); }],
|
||||
];
|
||||
for (const [move, tell, cause, outs, dodge] of cases) {
|
||||
const hit = moveRound(move, 150, outs);
|
||||
assert.equal(events(hit, tell).length, 1, `${move}: ${tell} first`);
|
||||
const losses = [];
|
||||
for (let t = 0; t < 4000 && !losses.length; t += 4) {
|
||||
ghoul.advance(hit, 4, steady);
|
||||
losses.push(...events(hit, "lose"));
|
||||
hit.events.length = 0;
|
||||
if (t < 300) assert.equal(losses.length, 0, `${move}: never before its warning has run`);
|
||||
}
|
||||
assert.deepEqual(losses.map((e) => e.cause), [cause], `${move}: costs a life as ${cause}`);
|
||||
const safe = moveRound(move, 150, outs);
|
||||
const lost = [];
|
||||
for (let t = 0; t < 4000; t += 4) {
|
||||
dodge(safe);
|
||||
ghoul.advance(safe, 4, steady);
|
||||
// The move played out, nothing comes after it.
|
||||
if (safe.boss.act === "idle") safe.boss.wait = 1e9;
|
||||
lost.push(...events(safe, "lose"));
|
||||
safe.events.length = 0;
|
||||
}
|
||||
assert.deepEqual(lost.map((e) => e.cause), [], `${move}: dodged`);
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's lawn: the doormen step out of the door, never more than DOORMEN_CAP of its own, and endless lives spare every hit", () => {
|
||||
const round = moveRound("doormen", 130, 4);
|
||||
round.you.safeMs = 1e9;
|
||||
run(round, mw.DOORMEN_WIND_MS + 50);
|
||||
assert.equal(round.monsters.filter((m) => m.doorman).length, mw.DOORMEN_N);
|
||||
assert.equal(events(round, "marrowDoormen").length, 1);
|
||||
Object.assign(round.boss, { plan: "doormen", wait: 0 });
|
||||
run(round, mw.DOORMEN_WIND_MS + 60);
|
||||
assert.ok(round.monsters.filter((m) => m.doorman && !m.dead).length <= mw.DOORMEN_CAP);
|
||||
const r = moveRound("pickets", 150);
|
||||
r.infinite = true;
|
||||
const lives = r.lives;
|
||||
run(r, 2000);
|
||||
assert.ok(events(r, "lose").length >= 1, "hit");
|
||||
assert.equal(r.lives, lives, "no life spent");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's lawn: the last window out is a boss kill, then the retreat plays its beats once and in order, and only then is the door there to walk through", () => {
|
||||
const round = lawnFight();
|
||||
const b = round.boss;
|
||||
for (const w of round.marrow.windows.slice(1)) Object.assign(w, { hp: 0, state: "out" });
|
||||
round.marrow.windows[0].hp = 1;
|
||||
b.hp = 1;
|
||||
lightOnly(round, 0);
|
||||
const lives = round.lives;
|
||||
standAt(round, 160);
|
||||
run(round, 400, { fire: true });
|
||||
assert.equal(b.state, "down");
|
||||
assert.equal(round.lives, lives + 1, "a life, as every boss gives");
|
||||
assert.equal(round.hasKey, true);
|
||||
const order = [];
|
||||
for (let t = 0; t < mw.GONE_AT + 1500 && round.phase !== "clear"; t += 4) {
|
||||
standAt(round, round.spec.door);
|
||||
round.input.right = true;
|
||||
ghoul.advance(round, 4, steady);
|
||||
for (const e of round.events) if (e.type.startsWith("marrow") && e.type !== "marrowWindowOut") order.push([e.type, Math.round(b.t)]);
|
||||
round.events.length = 0;
|
||||
if (!b.gone) assert.ok(round.you.x <= mw.houseLeft(round.spec), "no door until it has gone");
|
||||
}
|
||||
assert.deepEqual(order.map(([t]) => t), ["marrowSag", "marrowFalseWin", "marrowLaugh", "marrowSink", "marrowGone"]);
|
||||
assert.ok(order[1][1] >= mw.FALSE_AT && order[4][1] >= mw.GONE_AT, "on the retreat's clock");
|
||||
assert.equal(b.gone, true);
|
||||
assert.equal(round.phase, "clear", "through the door it left standing");
|
||||
run(round, ghoul.CLEAR_MS + 50);
|
||||
// On down the House's throat, or (the lawn the finale's only room) the win.
|
||||
if (ghoul.FINALE.rooms.length > 1) assert.equal(round.spec.id, ghoul.FINALE.rooms[1], "on to the next of the House's rooms");
|
||||
else assert.ok(round.won || round.phase === "ending");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ the fight */
|
||||
|
||||
// A steady player: shoots the lowest lit window from the surface serving it (getting there
|
||||
// takes CLIMB_MS a row, about two branches of the oak, firing nothing on the way: the bot is put there after), jumps the
|
||||
// carpet and the quake on the floor, and steps out from under a slate, a ripple or a brick.
|
||||
const CLIMB_MS = 1500;
|
||||
function fight(seed, skilled = true) {
|
||||
const round = lawnFight();
|
||||
const random = seededRandom(seed);
|
||||
Object.assign(round.boss, { wait: 600, litMs: 0 });
|
||||
let at = 0;
|
||||
let travel = 0;
|
||||
let t = 0;
|
||||
const causes = [];
|
||||
for (; t < 240000 && round.boss.state !== "down" && !round.over; t += 4) {
|
||||
const you = round.you;
|
||||
const inp = round.input;
|
||||
inp.left = inp.right = inp.fire = false;
|
||||
if (round.phase === "ask") ghoul.answerDie(round, false);
|
||||
if (skilled && round.phase === "play" && you.out <= 0 && you.state === "run") {
|
||||
const lit = round.marrow.windows.filter((w) => w.state === "lit").sort((a, c) => a.row - c.row);
|
||||
const threat = round.hazards.find((h) => (h.warn > 0 || h.live > 0) && Math.abs(h.x - you.x) < (h.w + 1.6) / 2 + 0.6 && (h.kind === "marrowShingle" || you.y === h.y));
|
||||
const wave = round.waves.find((w) => w.y === you.y && w.x - you.x > 0 && w.x - you.x < 5);
|
||||
if (wave) inp.jump = ghoul.JUMP_BUFFER_MS;
|
||||
else if (threat) {
|
||||
const s = you.shelf >= 0 ? round.spec.shelves[you.shelf] : [mw.houseLeft(round.spec) - 60, mw.houseLeft(round.spec) - 2];
|
||||
const dir = threat.x >= you.x ? -1 : 1;
|
||||
inp[(dir < 0 ? you.x - 3 > s[0] : you.x + 3 > s[1]) ? "left" : "right"] = true;
|
||||
} else if (travel > 0) travel -= 4;
|
||||
else if (lit.length) {
|
||||
const row = lit[0].row;
|
||||
const [x, shelf] = SERVES[row];
|
||||
if (row !== at) {
|
||||
travel = CLIMB_MS * Math.abs(row - at);
|
||||
at = row;
|
||||
} else {
|
||||
if (you.shelf !== shelf || Math.abs(you.x - x) > 4) standAt(round, x, shelf);
|
||||
you.face = 1;
|
||||
inp.fire = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ghoul.advance(round, 4, random);
|
||||
causes.push(...events(round, "lose").map((e) => e.cause));
|
||||
round.events.length = 0;
|
||||
}
|
||||
return { won: round.boss.state === "down", secs: t / 1000, causes, round };
|
||||
}
|
||||
|
||||
test("Ghoul Rush's lawn takes a steady player a real fight at full depth: 60 to 120 seconds on most seeds, with lives to spare; a player who stands still dies", () => {
|
||||
const times = [];
|
||||
const lives = [];
|
||||
let good = 0;
|
||||
for (const seed of [3, 7, 19, 41]) {
|
||||
const f = fight(seed);
|
||||
assert.ok(f.won, `seed ${seed}: it fell (${f.causes}; ${f.secs.toFixed(1)} s, hp ${f.round.boss.hp})`);
|
||||
assert.ok(f.round.lives > 0, `seed ${seed}: lives to spare (${f.causes})`);
|
||||
for (const c of f.causes) assert.ok(LOSE_WORDS[c] || ghoul.MONSTERS[c], `${c} is the House's or one of the dead`);
|
||||
if (f.secs >= 60 && f.secs <= 120) good++;
|
||||
times.push(f.secs);
|
||||
lives.push(f.round.lives);
|
||||
}
|
||||
assert.ok(good >= 3, `most seeds in 60 to 120 s (${times.map((x) => x.toFixed(1))}; lives ${lives})`);
|
||||
const idle = fight(7, false);
|
||||
assert.equal(idle.won, false);
|
||||
assert.ok(idle.round.over, `game over (${idle.causes})`);
|
||||
assert.equal(idle.round.boss.hp, idle.round.boss.max, "and not a window touched");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------- voices, words, drawing */
|
||||
|
||||
const heard = (e) => {
|
||||
const played = [];
|
||||
const noop = () => {};
|
||||
const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, markFurthest: noop };
|
||||
react(e, kit);
|
||||
return played;
|
||||
};
|
||||
|
||||
test("Ghoul Rush's House: a voice for every act in tones.js, every event plays its own sound once, and every cause has words and a sound", () => {
|
||||
const known = new Set(toneNames());
|
||||
for (const [act, name] of Object.entries(VOICES.marrow)) assert.ok(known.has(name), `${act}: ${name} is a tone`);
|
||||
const at = { kind: "marrow", x: 190, y: 20, xs: [150], left: 3 };
|
||||
const cases = { marrowLight: "light", marrowWindowOut: "windowOut", marrowRoof: "roof", marrowDoor: "door", marrowCarpet: "carpet", marrowPicketWind: "picketWind", marrowPicketUp: "picketUp", marrowShingleLand: "shingle", marrowCough: "cough", marrowBrickLand: "brick", marrowDoormen: "doormen", marrowRear: "rear", marrowStomp: "stomp", marrowSag: "sag", marrowFalseWin: "falseWin", marrowLaugh: "laugh", marrowSink: "sink", marrowGone: "gone", marrowStorm: "storm", marrowCharge: "charge", marrowStrike: "strike", marrowCrows: "crows", bossWake: "wake", bossHit: "hurt", bossDown: "die" };
|
||||
for (const [type, act] of Object.entries(cases)) {
|
||||
const played = heard({ type, ...at, how: "window", points: 1, life: true });
|
||||
assert.equal(played.filter((n) => n === VOICES.marrow[act]).length, 1, `${type}: ${VOICES.marrow[act]} once`);
|
||||
}
|
||||
for (const cause of ["marrow", "marrowShingle", "marrowCarpet", "marrowPicket", "marrowBrick", "marrowQuake", "marrowBolt"]) {
|
||||
assert.ok(LOSE_WORDS[cause], `${cause}: words`);
|
||||
assert.ok(known.has(LOSE_SOUNDS[cause][0]), `${cause}: a sound`);
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's lawn draws: the run up, the fight with windows of every state, every move's warning and hit, every beat of the retreat, lit and dark", () => {
|
||||
const { canvas, calls } = stubCanvas();
|
||||
const g = ghoul.default.create({ canvas });
|
||||
g.resize(900, 900);
|
||||
g.stageSelect();
|
||||
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g.key("down");
|
||||
g.key("action");
|
||||
for (let n = 0; n < 2; n++) {
|
||||
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 50; ms += 16) g.tick(16);
|
||||
g.key("action");
|
||||
}
|
||||
const r = g.round;
|
||||
r.infinite = true;
|
||||
const frame = (label) => {
|
||||
const before = calls.count;
|
||||
g.tick(16);
|
||||
assert.ok(calls.count > before, `${label} draws`);
|
||||
};
|
||||
for (const dark of [false, true]) {
|
||||
r.dark = dark;
|
||||
standAt(r, 40);
|
||||
frame("the run up");
|
||||
standAt(r, 130);
|
||||
for (let ms = 0; ms < 1600; ms += 16) g.tick(16);
|
||||
r.marrow.windows.forEach((w, i) => (w.state = ["lit", "dark", "out"][i % 3]));
|
||||
frame("windows lit, shuttered and out");
|
||||
for (const move of ["shingles", "pickets", "carpet", "bricks", "doormen", "stomp", "lightning", "crows"]) {
|
||||
Object.assign(r.boss, { plan: move, wait: 0 });
|
||||
for (let ms = 0; ms < 1400; ms += 16) frame(move);
|
||||
}
|
||||
for (const t of [100, mw.FALSE_AT + 100, mw.LAUGH_AT + 100, mw.SINK_AT + 800, mw.GONE_AT + 100]) {
|
||||
Object.assign(r.boss, { state: "down", t, gone: t >= mw.GONE_AT });
|
||||
frame(`the retreat at ${t}`);
|
||||
}
|
||||
Object.assign(r.boss, { state: "fight", t: 0, gone: false });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,914 @@
|
||||
// Web console tests, Ghoul Rush's Down the Hatch (the finale's first ride, after the Front Lawn): its shape (eleven swallows, every fork's hole swallows a rider who does not jump and its gristle ledge catches one who does, every uvula can be ducked, spacing, checkpoints every 8 to 10 seconds, the lip), the ride's speed on slopes and bile, its jump and duck, a rib, a uvula-lamp, a squeeze's throb, close and ease (peristalsis), the swallowed furniture, a plunge, the checkpoints, the lip and the door, the bonus round's three hearts and dice (3 to 8), endless lives for every cause, a voice for every event, the drawing, the telegraphs, and bots that ride the whole throat (one that rides well finishes, one that never dodges loses all three hearts without a game over).
|
||||
// Run with: node --test scripts/test-web-console-activities-ghoul-mat.mjs
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
|
||||
import * as mt from "../src/web-console/public/activities/ghoul-rush/rides/mat/ghoul-mat.js";
|
||||
import * as ct from "../src/web-console/public/activities/ghoul-rush/rides/cart/ghoul-cart.js";
|
||||
import { MAT_ROOM } from "../src/web-console/public/activities/ghoul-rush/rides/mat/ghoul-mat-room.js";
|
||||
import { EVENT_VOICE, LOSE_SOUNDS, LOSE_WORDS, LOOKS as MAT_LOOKS, VOICES as MAT_VOICES, telegraphMarks, telegraphs, throbAt } from "../src/web-console/public/activities/ghoul-rush/rides/mat/ghoul-mat-draw.js";
|
||||
import { MAT_SFX } from "../src/web-console/public/activities/ghoul-rush/rides/mat/ghoul-sfx-mat.js";
|
||||
import * as ghoulSfx from "../src/web-console/public/activities/ghoul-rush/sfx/ghoul-sfx.js";
|
||||
import { LOOKS, VOICES, bonusTick, react } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
|
||||
import { BONUS_FLOOR, diceFor, endBonus, makeBonus } from "../src/web-console/public/activities/ghoul-rush/core/ghoul-bonus.js";
|
||||
import { toneNames } from "../src/web-console/public/tones.js";
|
||||
|
||||
const steady = () => 0.5;
|
||||
// The pack draws no random number: a run on this fails on the first draw.
|
||||
const never = () => {
|
||||
throw new Error("the mat drew a random number");
|
||||
};
|
||||
const events = (round, type) => round.events.filter((e) => e.type === type);
|
||||
|
||||
function through(round) {
|
||||
round.phase = "clear";
|
||||
round.phaseMs = 1;
|
||||
ghoul.advance(round, 4, steady);
|
||||
}
|
||||
function skipCard(round) {
|
||||
round.introMs = ghoul.INTRO_MIN_MS;
|
||||
return ghoul.takeIntro(round);
|
||||
}
|
||||
|
||||
// A round in Down the Hatch reached the way a run reaches it (six stages behind it, the Front Lawn
|
||||
// passed), nothing woken, the clocks long, the bonus round on (three hearts).
|
||||
function matRound(seed = 5) {
|
||||
const round = ghoul.newRound(seed);
|
||||
round.lives = 3;
|
||||
round.dice = 0;
|
||||
through(round);
|
||||
round.cleared = ghoul.STAGES.slice(0, ghoul.RUN_STAGES).map((st) => st.id);
|
||||
round.offer = null;
|
||||
through(round);
|
||||
assert.equal(round.spec.id, "lawn");
|
||||
skipCard(round);
|
||||
skipCard(round);
|
||||
through(round);
|
||||
assert.equal(round.spec.id, "mat");
|
||||
round.phase = "play";
|
||||
for (const st of round.spawns) st.over = true;
|
||||
round.monsters.length = 0;
|
||||
round.hordeMs = Infinity;
|
||||
round.timeMs = 1e9;
|
||||
round.bonus = 1e9;
|
||||
round.events.length = 0;
|
||||
return round;
|
||||
}
|
||||
|
||||
const NONE = { runner: "mat", hearts: 3, rails: 0, time: 1e9, finish: 1e6, track: [], ribs: [], lows: [], squeezes: [], furniture: [], bile: [], checks: [] };
|
||||
// The same round over a ride of its own (a plain track to measure the rider on).
|
||||
function synth(ride) {
|
||||
const round = matRound();
|
||||
round.spec = { ...round.spec, start: 10, ground: [[0, 5, 0]], ride: { ...NONE, rails: (ride.track || []).length, ...ride } };
|
||||
mt.MAT.place[0](round, {});
|
||||
return round;
|
||||
}
|
||||
const FLAT = [[[0, 20], [4000, 20]]];
|
||||
const DOWN = [[[0, 40], [4000, 40 - 0.1 * 4000]]];
|
||||
|
||||
// The rider on line `line` of the ride at `x`, at speed `v`.
|
||||
function rideAt(round, x, line, { v = mt.MAT_V, safe = false } = {}) {
|
||||
const y = ct.trackY(round.spec.ride, line, x);
|
||||
assert.ok(y !== null, `line ${line} runs under ${x}`);
|
||||
Object.assign(round.you, { x, y, vy: 0, state: "run", shelf: -1, face: 1, out: 0, safeMs: safe ? 1e9 : 0, ducking: false });
|
||||
Object.assign(round.runner, { line, v, coyote: 0 });
|
||||
round.camX = Math.max(0, Math.min(round.spec.length - ghoul.FIELD_W, x - 24));
|
||||
}
|
||||
|
||||
function run(round, ms, keys = {}, random = steady) {
|
||||
Object.assign(round.input, keys);
|
||||
for (let t = 0; t < ms; t += 4) ghoul.advance(round, 4, random);
|
||||
for (const k of Object.keys(keys)) round.input[k] = typeof keys[k] === "number" ? 0 : false;
|
||||
}
|
||||
|
||||
function until(round, done, ms = 6000, random = steady) {
|
||||
let t = 0;
|
||||
for (; t < ms && !done(); t += 4) ghoul.advance(round, 4, random);
|
||||
return t;
|
||||
}
|
||||
|
||||
const press = (round) => {
|
||||
round.input.jump = ghoul.JUMP_BUFFER_MS;
|
||||
round.input.up = true;
|
||||
};
|
||||
|
||||
const heard = (e, extra = {}) => {
|
||||
const played = [];
|
||||
const noop = () => {};
|
||||
const kit = { tone: (name) => played.push(name), burst: noop, float: noop, ring: noop, banner: () => null, shake: noop, flash: noop, glow: noop, splat: noop, fx: { clock: 1e6 }, monsters: ghoul.MONSTERS, powers: ghoul.POWERS, bosses: ghoul.BOSSES, g: {}, floorAt: () => 6, ...extra };
|
||||
react({ x: 10, y: 6, tx: 20, ty: 6, ...e }, kit);
|
||||
return { played };
|
||||
};
|
||||
|
||||
const ROOM = ghoul.roomById("mat");
|
||||
const R = ROOM.ride;
|
||||
const lines = ct.linesOf(R);
|
||||
const floorOf = (x) => ghoul.groundAt(ROOM, x);
|
||||
const slopeAtLine = (L, i) => (L.pts[i + 1][1] - L.pts[i][1]) / (L.pts[i + 1][0] - L.pts[i][0]);
|
||||
const floors = lines.slice(0, R.rails);
|
||||
const ledges = lines.slice(R.rails);
|
||||
const K = { HIT_W: ghoul.HIT_W, HIT_H: ghoul.HIT_H, DUCK_H: ghoul.DUCK_H };
|
||||
|
||||
/* -------------------------------------------------------------- the room */
|
||||
|
||||
test("Ghoul Rush's Down the Hatch is the finale's room after the Front Lawn: a bonus ride of three hearts, lit, no key, no boss, about 30 seconds long", () => {
|
||||
assert.equal(MAT_ROOM.ready, true, "plays in a run");
|
||||
const fin = ghoul.FINALE.rooms;
|
||||
assert.equal(fin[0], "lawn");
|
||||
assert.equal(fin[1], "mat", "straight after the Front Lawn");
|
||||
assert.deepEqual([ROOM.title, ROOM.sub], ["Down the Hatch", "Wipe your feet"]);
|
||||
assert.equal(ROOM.dark, false, "always lit");
|
||||
assert.equal(ROOM.key, null);
|
||||
assert.equal(ROOM.boss, null);
|
||||
assert.equal(ROOM.bonus, true, "a bonus round");
|
||||
assert.equal(R.runner, "mat");
|
||||
assert.equal(R.hearts, 3, "three hearts, not five");
|
||||
assert.equal(typeof ghoul.ROOM_MUSIC.mat, "string", "a track to play");
|
||||
assert.deepEqual(Object.keys(mt.MAT.monsters), [], "no new monster kinds");
|
||||
assert.equal(LOOKS.mat, MAT_LOOKS.mat);
|
||||
assert.equal(LOOKS.mat.pack, "mat");
|
||||
assert.ok(Object.isFrozen(R) && Object.isFrozen(R.track) && Object.isFrozen(R.track[0][0]), "frozen all the way down");
|
||||
assert.ok(ROOM.horde.length === 0 && ROOM.spawns.length === 0 && ROOM.items.length === 0, "no monsters and no pickups");
|
||||
assert.match(R.how, /UP jump, DOWN duck, SPACE shoot/, "the keys in the how line");
|
||||
assert.equal(ROOM.ground.length, 2, "the front step and the cellar floor only");
|
||||
assert.ok(ROOM.ground[0][1] < 60 && ROOM.ground[1][0] > ROOM.length - 100);
|
||||
assert.equal(ROOM.ground[1][0], R.finish);
|
||||
assert.ok(ROOM.door > R.finish && ROOM.door > ROOM.length - 14, "the door at the room's end");
|
||||
assert.ok(floorOf(ROOM.door - 2) > -Infinity);
|
||||
for (const L of lines) for (let i = 0; i + 1 < L.pts.length; i++) assert.ok(L.pts[i + 1][0] > L.pts[i][0], "x rises");
|
||||
assert.ok(ct.trackY(R, 0, ROOM.start) > floorOf(ROOM.start), "the mat starts on the throat over the front step");
|
||||
// About 30 seconds at the mat's speed.
|
||||
const secs = (floors.at(-1).x1 - ROOM.start) / mt.MAT_V;
|
||||
assert.ok(secs >= 27 && secs <= 34, `${secs.toFixed(1)} s at MAT_V`);
|
||||
// The swallows: descents at about 0.10 and short climbs at about 0.3, never steeper.
|
||||
let down = 0;
|
||||
let total = 0;
|
||||
for (const L of floors) {
|
||||
for (let i = 0; i + 1 < L.pts.length; i++) {
|
||||
const s = slopeAtLine(L, i);
|
||||
const len = L.pts[i + 1][0] - L.pts[i][0];
|
||||
assert.ok(s >= -0.15 && s <= 0.32, `a slope of ${s.toFixed(3)}`);
|
||||
total += len;
|
||||
if (s < 0) down += len;
|
||||
}
|
||||
}
|
||||
assert.ok(down / total > 0.6, `${((100 * down) / total).toFixed(0)}% of the throat goes down`);
|
||||
for (const L of lines) for (const [, y] of L.pts) assert.ok(y > mt.DERAIL_Y + 4 && y < 46, `a floor height of ${y}`);
|
||||
assert.equal(ghoul.timeFor(ghoul.roomFor("mat")), R.time);
|
||||
assert.ok(R.time >= 2 * secs * 1000, "the clock never matters on a ride");
|
||||
assert.ok(ct.slopeOf(R, R.rails - 1, floors.at(-1).x1) >= mt.RAMP_SLOPE, "the lip launches");
|
||||
// The bonus round: three hearts of its own.
|
||||
const round = matRound();
|
||||
assert.equal(round.bonusRound.hearts, 3);
|
||||
assert.equal(round.bonusRound.max, 3);
|
||||
assert.equal(round.runner.id, "mat");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: the lip's launch alone carries the rider onto the cellar floor at any speed it can have there", () => {
|
||||
const lip = floors.at(-1);
|
||||
const end = lip.pts.at(-1);
|
||||
const rise = ct.slopeOf(R, R.rails - 1, lip.x1);
|
||||
const floor = floorOf(R.finish + 1);
|
||||
for (const v of [mt.MAT_MIN, 36, mt.MAT_V, 55, mt.MAT_MAX]) {
|
||||
let vy = rise * v + mt.RAMP_POP;
|
||||
let x = end[0];
|
||||
let y = end[1];
|
||||
for (let t = 0; t < 3; t += 0.002) {
|
||||
vy -= mt.MAT_G * 0.002;
|
||||
x += v * 0.002;
|
||||
y += vy * 0.002;
|
||||
if (vy < 0 && y <= floor) break;
|
||||
}
|
||||
assert.ok(x >= R.finish + 2 && x <= R.finish + 40, `at ${v} it lands ${(x - R.finish).toFixed(1)} past the floor's start`);
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: every fork's hole is too wide to jump across and swallows a rider who does not jump, its gristle ledge catches a jump from before the hole at any speed, and off the ledge's end the rider drops back onto the floor", () => {
|
||||
assert.equal(R.rails - 1, 2, "two forks");
|
||||
assert.equal(ledges.length, 2, "a ledge over each");
|
||||
for (let i = 0; i + 1 < R.rails; i++) {
|
||||
const a = lines[i];
|
||||
const b = lines[i + 1];
|
||||
const gap = b.x0 - a.x1;
|
||||
assert.ok(gap >= 46, `hole ${i} is ${gap} wide, past a jump at bile speed`);
|
||||
const end = a.pts.at(-1);
|
||||
const slope = ct.slopeOf(R, i, a.x1);
|
||||
assert.ok(slope < 0, "holes lie on descents (no ramp launch)");
|
||||
// The ledge over it, RAIL_SEP over the throat, from before the hole to past it.
|
||||
const n = ledges.findIndex((L) => L.x0 < a.x1 && L.x1 > b.x0);
|
||||
assert.ok(n >= 0, `a ledge over hole ${i}`);
|
||||
const L = ledges[n];
|
||||
const line = R.rails + n;
|
||||
assert.ok(a.x1 - L.x0 >= 16 && L.x1 - b.x0 >= 10, "the ledge starts well before the hole and ends past it");
|
||||
for (let x = L.x0; x <= Math.min(L.x1, a.x1); x += 2) assert.ok(Math.abs(ct.trackY(R, line, x) - ct.trackY(R, i, x) - mt.RAIL_SEP) < 0.15, `${mt.RAIL_SEP} over at ${x}`);
|
||||
assert.ok(mt.upperLine(R, line) && !mt.upperLine(R, i));
|
||||
for (const v of [mt.MAT_MIN + 6, mt.MAT_V, 55, mt.BILE_V]) {
|
||||
// No jump: into the hole, and a jump with no ledge would not clear it either.
|
||||
assert.equal(mt.flight(R, a.x1, end[1], slope * v, v), null, `hole ${i}, no jump, at ${v}`);
|
||||
const bare = { ...R, track: R.track.slice(0, R.rails) };
|
||||
assert.equal(mt.flight(bare, a.x1 - 2, ct.trackY(R, i, a.x1 - 2), mt.MAT_JUMP_V + slope * v, v), null, `hole ${i} cannot be jumped across at ${v}`);
|
||||
// A jump from a few units before the ledge to the hole's edge lands on the ledge.
|
||||
for (const x of [L.x0 - 6, L.x0, L.x0 + 8, a.x1 - 1]) {
|
||||
const top = ct.linesAt(R, x).find(([ln]) => ln === i);
|
||||
const s = mt.flight(R, x, top[1], mt.MAT_JUMP_V + ct.slopeOf(R, i, x) * v, v);
|
||||
assert.ok(s && s.line === line, `hole ${i}: a jump from ${x} at ${v} lands on the ledge (${JSON.stringify(s)})`);
|
||||
}
|
||||
}
|
||||
// Off the ledge's end: down onto the floor beyond the hole.
|
||||
const tail = L.pts.at(-1);
|
||||
const f = mt.flight(R, L.x1, tail[1], ct.slopeOf(R, line, L.x1) * mt.MAT_V, mt.MAT_V);
|
||||
assert.ok(f && f.line === i + 1, `off ledge ${n}, onto the floor`);
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: every thing is on a line and well inside it, spaced for a player (22 between jumps and 38 between a jump and a duck), a uvula's underside between a ducked box and a standing one, the checkpoints every 8 to 10 seconds", () => {
|
||||
const jumps = [];
|
||||
for (const [x, line] of R.ribs) {
|
||||
assert.ok(ct.trackY(R, line, x) !== null, `a rib at ${x} stands on line ${line}`);
|
||||
assert.ok(!mt.upperLine(R, line), "ribs grow out of the floor");
|
||||
assert.ok(x - lines[line].x0 > 8 && lines[line].x1 - x > 14, `a rib at ${x} well inside its line`);
|
||||
jumps.push([x - 2, x + 2]);
|
||||
}
|
||||
for (const [x, line, kind] of R.furniture) {
|
||||
assert.ok(ct.trackY(R, line, x) !== null);
|
||||
assert.ok([0, 1, 2].includes(kind));
|
||||
assert.ok(x - lines[line].x0 > 20 && lines[line].x1 - x > 14, `furniture at ${x} has room to tumble`);
|
||||
jumps.push([x - 12, x + 2]);
|
||||
}
|
||||
for (const L of ledges) jumps.push([L.x0 - 14, L.x0 + 26]);
|
||||
const ducks = [];
|
||||
for (const [x0, x1] of R.lows) ducks.push([x0, x1]);
|
||||
for (const [x, line] of R.squeezes) {
|
||||
assert.ok(ct.trackY(R, line, x) !== null && !mt.upperLine(R, line), `a squeeze at ${x} over the floor`);
|
||||
assert.ok(!ledges.some((L) => x > L.x0 - 10 && x < L.x1 + 10), "no ledge near a squeeze");
|
||||
ducks.push([x - mt.SQ_W / 2 - 6, x + mt.SQ_W / 2 + 6]);
|
||||
}
|
||||
jumps.sort((p, q) => p[0] - q[0]);
|
||||
for (let i = 0; i + 1 < jumps.length; i++) assert.ok(jumps[i + 1][0] - jumps[i][1] >= 22, `jumps at ${jumps[i][1]} and ${jumps[i + 1][0]}`);
|
||||
for (const [d0, d1] of ducks) for (const [j0, j1] of jumps) assert.ok(j0 - d1 >= 38 || d0 - j1 >= 38, `a jump at ${j0} and a duck at ${d0}`);
|
||||
for (const [x0, x1, y] of R.lows) {
|
||||
let hi = 0;
|
||||
let lo = 99;
|
||||
for (let x = x0 - K.HIT_W / 2; x <= x1 + K.HIT_W / 2; x += 0.25) {
|
||||
const g = ct.linesAt(R, x)[0];
|
||||
assert.ok(g, "a floor or a ledge under a uvula");
|
||||
hi = Math.max(hi, g[1]);
|
||||
lo = Math.min(lo, g[1]);
|
||||
}
|
||||
assert.ok(hi + K.DUCK_H < y, `a ducked box clears the uvula at ${x0}`);
|
||||
assert.ok(lo + K.HIT_H > y, `a standing box hits the uvula at ${x0}`);
|
||||
}
|
||||
for (const [x0, x1] of R.bile) assert.ok(x1 > x0 && ct.linesAt(R, (x0 + x1) / 2).length, "bile lies on the floor");
|
||||
assert.ok(R.ribs.length >= 4 && R.lows.length >= 2 && R.squeezes.length >= 3 && R.furniture.length >= 3 && R.bile.length >= 2);
|
||||
// Checkpoints every 8 to 10 seconds of riding, on the floor, clear of a jump coming up.
|
||||
const cs = R.checks;
|
||||
assert.ok(cs.length >= 3);
|
||||
for (let i = 0; i < cs.length; i++) {
|
||||
assert.ok(ct.linesAt(R, cs[i]).length, `checkpoint ${i} on the floor`);
|
||||
const gap = (cs[i] - (i ? cs[i - 1] : ROOM.start)) / mt.MAT_V;
|
||||
assert.ok(gap >= 7.5 && gap <= 10, `${gap.toFixed(1)} s to checkpoint ${i}`);
|
||||
for (const [j0, j1] of jumps) assert.ok(j0 - cs[i] > 20 || cs[i] - j1 > 4, `a jump at ${j0} near checkpoint ${i}`);
|
||||
}
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ the rider */
|
||||
|
||||
test("Ghoul Rush's Down the Hatch rolls at MAT_V on the flat, faster down a slope, faster again on bile (BILE_V), never past MAT_MIN or MAT_MAX", () => {
|
||||
const flat = synth({ track: FLAT });
|
||||
assert.equal(flat.runner.v, mt.MAT_V);
|
||||
run(flat, 2000);
|
||||
assert.ok(Math.abs(flat.runner.v - mt.MAT_V) < 0.01);
|
||||
assert.equal(flat.you.face, 1);
|
||||
assert.equal(flat.you.state, "run");
|
||||
assert.equal(flat.you.y, 20);
|
||||
const down = synth({ track: DOWN });
|
||||
run(down, 3000);
|
||||
assert.ok(Math.abs(down.runner.v - (mt.MAT_V + (mt.SLOPE_G * 0.1) / mt.RELAX)) < 0.2, `${down.runner.v} down a 0.1 slope`);
|
||||
const slick = synth({ track: FLAT, bile: [[0, 4000]] });
|
||||
run(slick, 3000);
|
||||
assert.ok(Math.abs(slick.runner.v - mt.BILE_V) < 0.2, `${slick.runner.v} on bile`);
|
||||
assert.equal(events(slick, "matBile").length, 1, "one word as it starts");
|
||||
const steep = synth({ track: [[[0, 10000], [4000, 6000]]] });
|
||||
run(steep, 3000);
|
||||
assert.equal(steep.runner.v, mt.MAT_MAX);
|
||||
const wall = synth({ track: [[[0, 0], [4000, 4000]]] });
|
||||
run(wall, 3000);
|
||||
assert.equal(wall.runner.v, mt.MAT_MIN);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch jumps about 13 high for about three quarters of a second, a press saved for a landing jumps on it, and one just after a line's end still jumps", () => {
|
||||
const round = synth({ track: FLAT });
|
||||
let top = 0;
|
||||
press(round);
|
||||
const t = until(round, () => {
|
||||
top = Math.max(top, round.you.y - 20);
|
||||
return round.you.state === "run" && round.you.y === 20 && round.you.vy === 0 && top > 1;
|
||||
}, 3000);
|
||||
assert.ok(Math.abs(top - (mt.MAT_JUMP_V * mt.MAT_JUMP_V) / (2 * mt.MAT_G)) < 0.4, `${top.toFixed(1)} high`);
|
||||
assert.ok(t > 650 && t < 850, `${t} ms in the air`);
|
||||
assert.equal(events(round, "matJump").length, 1);
|
||||
assert.equal(events(round, "matLand").length, 1);
|
||||
const buf = synth({ track: FLAT });
|
||||
press(buf);
|
||||
run(buf, 640);
|
||||
press(buf);
|
||||
until(buf, () => events(buf, "matJump").length >= 2, 1500);
|
||||
assert.equal(events(buf, "matJump").length, 2, "the saved press jumped again at the landing");
|
||||
const edge = synth({ track: [[[0, 20], [60, 20]], [[150, 20], [300, 20]]] });
|
||||
rideAt(edge, 58.5, 0);
|
||||
run(edge, 80);
|
||||
assert.equal(edge.runner.line, -1, "off the end");
|
||||
press(edge);
|
||||
run(edge, 4);
|
||||
assert.equal(events(edge, "matJump").length, 1, "coyote");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: DOWN ducks; a ducked rider passes under a uvula-lamp and a standing one or a jumping one hits it (cause matUvula), a heart and not a life, once", () => {
|
||||
const duck = synth({ track: FLAT, lows: [[60, 67, 23.0]] });
|
||||
run(duck, 20, { down: true });
|
||||
assert.equal(events(duck, "matDuck").length, 1);
|
||||
duck.input.down = true;
|
||||
until(duck, () => duck.you.x > 75, 3000);
|
||||
duck.input.down = false;
|
||||
assert.equal(duck.bonusRound.hearts, 3);
|
||||
const hit = synth({ track: FLAT, lows: [[60, 67, 23.0]] });
|
||||
until(hit, () => hit.bonusRound.hearts < 3, 3000);
|
||||
assert.equal(hit.bonusRound.hearts, 2);
|
||||
assert.equal(hit.lives, 3, "not a life");
|
||||
assert.equal(events(hit, "lose")[0].cause, "matUvula");
|
||||
assert.equal(events(hit, "matCrash")[0].what, "uvula");
|
||||
assert.equal(hit.phase, "play", "the ride rolls on");
|
||||
assert.ok(hit.you.safeMs > 0, "blinking safe");
|
||||
assert.deepEqual(hit.bonusRound.perf.hits, ["u0"]);
|
||||
run(hit, 1000);
|
||||
assert.equal(hit.bonusRound.hearts, 2, "the same uvula costs nothing twice");
|
||||
const jump = synth({ track: FLAT, lows: [[60, 67, 23.0]] });
|
||||
rideAt(jump, 40, 0);
|
||||
press(jump);
|
||||
until(jump, () => jump.bonusRound.hearts < 3 || jump.you.x > 80, 3000);
|
||||
assert.equal(jump.bonusRound.hearts, 2, "a jump does not clear a uvula");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: a rib bone is cleared by a jump from 9 to 26 short of it and costs a heart otherwise (cause matRib), once", () => {
|
||||
const hit = synth({ track: FLAT, ribs: [[60, 0]] });
|
||||
until(hit, () => hit.bonusRound.hearts < 3, 3000);
|
||||
assert.equal(hit.bonusRound.hearts, 2);
|
||||
assert.equal(events(hit, "lose")[0].cause, "matRib");
|
||||
assert.equal(events(hit, "matCrash")[0].what, "rib");
|
||||
assert.deepEqual(hit.bonusRound.perf.hits, ["r0"]);
|
||||
run(hit, 500);
|
||||
assert.equal(hit.bonusRound.hearts, 2);
|
||||
for (const from of [60 - 26, 60 - 14, 60 - 9]) {
|
||||
const clear = synth({ track: FLAT, ribs: [[60, 0]] });
|
||||
rideAt(clear, from, 0);
|
||||
press(clear);
|
||||
until(clear, () => clear.you.x > 80, 3000);
|
||||
assert.equal(clear.bonusRound.hearts, 3, `jumped from ${from}`);
|
||||
}
|
||||
// A ducked rider is no lower than a rib.
|
||||
const low = synth({ track: FLAT, ribs: [[60, 0]] });
|
||||
low.input.down = true;
|
||||
until(low, () => low.you.x > 70, 3000);
|
||||
assert.equal(low.bonusRound.hearts, 2, "ducking does not pass a rib");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------- peristalsis */
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: a squeeze waits, then throbs SQ_WARN_MS (two throbs heard, the walls pulsing) at least 1.5 s before you reach it, closes, holds shut while you pass and eases; a ducked rider passes under it", () => {
|
||||
const round = synth({ track: FLAT, squeezes: [[200, 0]] });
|
||||
rideAt(round, 40, 0);
|
||||
const s = () => round.runner.squeezes[0];
|
||||
assert.equal(s().state, "wait");
|
||||
run(round, 100);
|
||||
assert.equal(s().state, "wait", "far off: waiting");
|
||||
until(round, () => s().state === "throb", 5000);
|
||||
const ahead = 200 - round.you.x;
|
||||
assert.ok(ahead / round.runner.v >= 1.5, `it throbs ${(ahead / round.runner.v).toFixed(2)} s ahead`);
|
||||
assert.deepEqual(events(round, "matSqueezeThrob").map((e) => e.n), [1]);
|
||||
assert.ok(throbAt(round.spec.ride, round.runner, 200) > 0, "the walls throb near it");
|
||||
assert.equal(throbAt(round.spec.ride, round.runner, 280), 0, "and not far from it");
|
||||
assert.equal(mt.squeezeLow(s()), mt.SQ_OPEN, "still open while it throbs");
|
||||
const half = until(round, () => events(round, "matSqueezeThrob").length >= 2, 2000);
|
||||
assert.ok(Math.abs(half - mt.SQ_WARN_MS / 2) < 20, `the second throb ${half} ms in`);
|
||||
assert.equal(events(round, "matSqueezeThrob")[1].n, 2);
|
||||
until(round, () => s().state === "close", 2000);
|
||||
assert.equal(events(round, "matSqueezeClose").length, 1);
|
||||
until(round, () => s().state === "shut", 1000);
|
||||
assert.equal(mt.squeezeLow(s()), mt.SQ_LOW);
|
||||
const early = 200 - mt.SQ_W / 2 - round.you.x;
|
||||
assert.ok(early > 8, `shut ${early.toFixed(1)} before you reach it`);
|
||||
// Ducked through it: nothing.
|
||||
round.input.down = true;
|
||||
until(round, () => round.you.x > 215, 2000);
|
||||
round.input.down = false;
|
||||
assert.equal(round.bonusRound.hearts, 3, "ducked under it");
|
||||
assert.equal(s().state, "shut", "still shut as you leave it");
|
||||
until(round, () => s().state === "done", 3000);
|
||||
assert.equal(mt.squeezeLow({ state: "ease", t: mt.SQ_EASE_MS }), mt.SQ_LOW);
|
||||
assert.equal(mt.squeezeLow({ state: "ease", t: 0 }), mt.SQ_OPEN);
|
||||
// At bile speed it still throbs well ahead and is shut before you arrive.
|
||||
const fast = synth({ track: FLAT, squeezes: [[300, 0]], bile: [[0, 4000]] });
|
||||
rideAt(fast, 40, 0, { v: mt.BILE_V });
|
||||
until(fast, () => fast.runner.squeezes[0].state === "shut", 6000);
|
||||
assert.ok(300 - mt.SQ_W / 2 - fast.you.x > 8, "shut before you get there at bile speed too");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: a squeeze shut over you costs a heart standing or jumping (cause matSqueeze), and nothing while it is still open", () => {
|
||||
const stand = synth({ track: FLAT, squeezes: [[200, 0]] });
|
||||
rideAt(stand, 40, 0);
|
||||
until(stand, () => stand.bonusRound.hearts < 3 || stand.you.x > 220, 6000);
|
||||
assert.equal(stand.bonusRound.hearts, 2);
|
||||
assert.equal(events(stand, "lose")[0].cause, "matSqueeze");
|
||||
assert.equal(events(stand, "matCrash")[0].what, "squeeze");
|
||||
assert.deepEqual(stand.bonusRound.perf.hits, ["s0"]);
|
||||
const hop = synth({ track: FLAT, squeezes: [[200, 0]] });
|
||||
rideAt(hop, 40, 0);
|
||||
until(hop, () => hop.runner.squeezes[0].state === "shut", 6000);
|
||||
until(hop, () => 200 - hop.you.x < 18, 2000);
|
||||
press(hop);
|
||||
until(hop, () => hop.bonusRound.hearts < 3 || hop.you.x > 220, 3000);
|
||||
assert.equal(hop.bonusRound.hearts, 2, "a jump into it hits");
|
||||
// Open (a rider placed past its warning), it is nothing.
|
||||
const open = synth({ track: FLAT, squeezes: [[200, 0]] });
|
||||
rideAt(open, 196, 0);
|
||||
open.runner.squeezes[0] = { state: "throb", t: 900, n: 1 };
|
||||
run(open, 200);
|
||||
assert.equal(open.bonusRound.hearts, 3);
|
||||
});
|
||||
|
||||
/* ----------------------------------------------------------- furniture */
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: a piece of furniture drops from the roof FURN_DROP_MS when you are FURN_LEAD_MS short of it, lands, tumbles up at you and hits (cause matFurniture) if you meet it; a jump clears it", () => {
|
||||
const hit = synth({ track: FLAT, furniture: [[300, 0, 1]] });
|
||||
rideAt(hit, 150, 0);
|
||||
const f = () => hit.runner.furniture[0];
|
||||
assert.equal(f().state, "wait");
|
||||
until(hit, () => f().state === "drop", 5000);
|
||||
const ahead = 300 - hit.you.x;
|
||||
assert.ok(Math.abs(ahead - (mt.MAT_V * mt.FURN_LEAD_MS) / 1000) < 1, `drops ${ahead.toFixed(1)} ahead`);
|
||||
assert.equal(events(hit, "matFurnDrop").length, 1);
|
||||
assert.ok(mt.furnitureLift(f()) > 15, "up near the roof");
|
||||
assert.equal(hit.bonusRound.hearts, 3, "falling, it hurts nobody far off");
|
||||
const ms = until(hit, () => f().state === "roll", 2000);
|
||||
assert.ok(Math.abs(ms - mt.FURN_DROP_MS) < 20);
|
||||
assert.equal(events(hit, "matFurnLand").length, 1);
|
||||
assert.ok(f().x - hit.you.x > 28 && f().x - hit.you.x < 42, `lands ${(f().x - hit.you.x).toFixed(1)} ahead: time to see it`);
|
||||
const x0 = f().x;
|
||||
run(hit, 100);
|
||||
assert.ok(x0 - f().x > mt.FURN_V * 0.09, "it tumbles at you");
|
||||
until(hit, () => hit.bonusRound.hearts < 3, 2000);
|
||||
assert.equal(events(hit, "lose")[0].cause, "matFurniture");
|
||||
assert.equal(events(hit, "matCrash")[0].what, "furniture");
|
||||
assert.equal(f().state, "spent");
|
||||
assert.deepEqual(hit.bonusRound.perf.hits, ["f0"]);
|
||||
const jump = synth({ track: FLAT, furniture: [[300, 0, 0]] });
|
||||
rideAt(jump, 150, 0);
|
||||
until(jump, () => jump.runner.furniture[0].state === "roll" && jump.runner.furniture[0].x - jump.you.x < 16, 5000);
|
||||
press(jump);
|
||||
until(jump, () => jump.you.x > 330, 3000);
|
||||
assert.equal(jump.bonusRound.hearts, 3);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: two bolts break a piece of furniture (FURN_POINTS, an act for the grade), along the slope; what was shot stays shot after a restart", () => {
|
||||
const round = synth({ track: DOWN, furniture: [[260, 0, 2]] });
|
||||
rideAt(round, 120, 0);
|
||||
round.you.safeMs = 1e9;
|
||||
const start = round.score;
|
||||
round.input.fire = true;
|
||||
until(round, () => round.runner.furniture[0].state === "broken", 5000);
|
||||
round.input.fire = false;
|
||||
assert.equal(round.runner.furniture[0].state, "broken");
|
||||
assert.equal(events(round, "matFurnHit").length, mt.FURN_HP - 1);
|
||||
assert.equal(events(round, "matFurnBreak")[0].points, mt.FURN_POINTS);
|
||||
assert.equal(round.bonusRound.perf.acts, 1);
|
||||
assert.ok(round.score - start >= mt.FURN_POINTS);
|
||||
// A bolt flies along the slope, not level.
|
||||
const probe = synth({ track: DOWN });
|
||||
probe.input.fire = true;
|
||||
run(probe, 300);
|
||||
probe.input.fire = false;
|
||||
assert.ok(probe.shots.length > 0);
|
||||
for (const s of probe.shots) assert.ok(Math.abs(s.y - (40 - 0.1 * s.x) - ghoul.SHOT_Y) < 0.5, "a bolt over the floor");
|
||||
// Nothing to shoot while it waits in the roof.
|
||||
const idle = synth({ track: FLAT, furniture: [[300, 0, 0]] });
|
||||
assert.equal(mt.MAT.target(idle, { x: 300, y: 22 }), false);
|
||||
const again = synth({ track: FLAT, furniture: [[300, 0, 0]] });
|
||||
again.runner.furniture[0].state = "broken";
|
||||
mt.MAT.place[0](again, {});
|
||||
assert.equal(again.runner.furniture[0].state, "broken");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------- forks, holes and hearts */
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: a hole with no jump is a heart (cause matPlunge), the rider goes back on the ledge over it (or the floor beyond, with none) at MAT_V and rolls on; a jump onto the ledge passes it, with a switch up and down", () => {
|
||||
const ride = { track: [[[0, 20], [100, 20]], [[160, 20], [400, 20]], [[80, 27], [175, 27]]], rails: 2 };
|
||||
const fall = synth(ride);
|
||||
rideAt(fall, 60, 0);
|
||||
until(fall, () => fall.bonusRound.hearts < 3, 3000);
|
||||
assert.equal(fall.bonusRound.hearts, 2);
|
||||
assert.equal(fall.lives, 3, "not a life");
|
||||
assert.equal(events(fall, "lose")[0].cause, "matPlunge");
|
||||
assert.equal(fall.phase, "play");
|
||||
assert.equal(fall.runner.line, 2, "caught on the ledge over the hole");
|
||||
assert.equal(fall.you.y, 27);
|
||||
assert.equal(fall.runner.v, mt.MAT_V);
|
||||
assert.deepEqual(fall.bonusRound.perf.hits, ["g0"]);
|
||||
until(fall, () => fall.you.x > 200, 3000);
|
||||
assert.equal(fall.runner.line, 1, "and down off its end onto the floor");
|
||||
assert.equal(fall.bonusRound.hearts, 2);
|
||||
const bare = synth({ track: [[[0, 20], [100, 20]], [[160, 20], [400, 20]]] });
|
||||
rideAt(bare, 60, 0);
|
||||
until(bare, () => bare.bonusRound.hearts < 3, 3000);
|
||||
assert.equal(bare.runner.line, 1, "with no ledge: on the floor beyond the hole");
|
||||
assert.ok(bare.you.x >= 160 && bare.you.x < 165);
|
||||
const hop = synth(ride);
|
||||
rideAt(hop, 76, 0);
|
||||
press(hop);
|
||||
until(hop, () => hop.runner.line === 2, 2000);
|
||||
assert.equal(hop.runner.line, 2, "on the ledge");
|
||||
assert.equal(events(hop, "matSwitch")[0].up, true);
|
||||
until(hop, () => hop.you.x > 200, 3000);
|
||||
assert.equal(hop.runner.line, 1, "back down on the floor");
|
||||
assert.equal(events(hop, "matSwitch")[1].up, false);
|
||||
assert.equal(hop.bonusRound.hearts, 3);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: the last heart gone ends the round with nothing at once (BONUS LOST: no life lost, the dice in hand kept, no game over) and the run goes on to the next room", () => {
|
||||
const round = matRound();
|
||||
round.dice = 2;
|
||||
round.bonusRound.hearts = 1;
|
||||
const [x] = R.ribs[0];
|
||||
rideAt(round, x - 10, ct.linesAt(R, x - 10)[0][0]);
|
||||
round.you.safeMs = 0;
|
||||
until(round, () => round.phase === "clear", 6000);
|
||||
assert.equal(round.bonusRound.hearts, 0);
|
||||
assert.equal(round.bonusRound.over, true);
|
||||
assert.equal(round.bonusRound.won, false);
|
||||
const end = events(round, "bonusEnd");
|
||||
assert.equal(end.length, 1);
|
||||
assert.equal(end[0].won, false);
|
||||
assert.equal(end[0].dice, 0);
|
||||
assert.equal(round.over, false, "no game over");
|
||||
assert.equal(round.lives, 3);
|
||||
assert.equal(round.dice, 2);
|
||||
run(round, ghoul.CARD_LOST_MS + 100);
|
||||
const next = ghoul.FINALE.rooms[ghoul.FINALE.rooms.indexOf("mat") + 1];
|
||||
if (next) {
|
||||
assert.equal(round.spec.id, next, "on to the next of the House's rooms");
|
||||
assert.equal(round.bonusRound, null);
|
||||
assert.equal(round.runner ?? null, null);
|
||||
assert.equal(round.lives, 3);
|
||||
assert.equal(round.dice, 2);
|
||||
} else assert.equal(round.won, true, "the last of the House's rooms ready: on to the win");
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: the checkpoints are passed in order (an event each) and the ride goes back to the last one after the last heart; another ride's slot is not its own", () => {
|
||||
const round = matRound();
|
||||
rideAt(round, R.checks[0] - 6, ct.linesAt(R, R.checks[0] - 6)[0][0]);
|
||||
round.you.safeMs = 1e9;
|
||||
until(round, () => round.runner.check >= 0, 4000);
|
||||
assert.deepEqual(events(round, "matCheck").map((e) => e.n), [1]);
|
||||
const c0 = round.runner.check;
|
||||
round.you.x = 1;
|
||||
mt.MAT.place[0](round, {});
|
||||
assert.equal(round.you.x, R.checks[c0]);
|
||||
assert.equal(round.runner.v, mt.MAT_V);
|
||||
assert.equal(round.runner.check, c0);
|
||||
assert.equal(round.camLead, mt.CAM_AHEAD);
|
||||
const fresh = matRound();
|
||||
assert.equal(fresh.you.x, ROOM.start);
|
||||
assert.equal(fresh.runner.check, -1);
|
||||
const other = matRound();
|
||||
other.runner = { id: "banister" };
|
||||
other.spec = { ...other.spec, ride: { ...other.spec.ride, runner: "banister" } };
|
||||
mt.MAT.place[0](other, {});
|
||||
assert.deepEqual(other.runner, { id: "banister" });
|
||||
other.runner = { id: "mat" };
|
||||
mt.MAT.place[0](other, {});
|
||||
assert.equal(other.runner, null);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: off the lip the rider is spat out onto the cellar floor and stops (matFinish), the door opens, and walking out ends the round with 3 to 8 Lucky dice", () => {
|
||||
const round = matRound();
|
||||
round.dice = 1;
|
||||
const last = R.rails - 1;
|
||||
rideAt(round, lines[last].x1 - 12, last, { safe: true });
|
||||
until(round, () => round.runner.done, 4000);
|
||||
assert.equal(round.runner.done, true);
|
||||
assert.equal(events(round, "matLaunch").length, 1);
|
||||
assert.equal(events(round, "matLaunch")[0].last, true);
|
||||
assert.equal(events(round, "matFinish").length, 1);
|
||||
assert.ok(round.you.x > R.finish + 2 && round.you.x < R.finish + 40, `${round.you.x} landed`);
|
||||
assert.equal(round.you.y, floorOf(round.you.x));
|
||||
assert.equal(round.hasKey, true, "the door opens");
|
||||
assert.equal(round.phase, "play");
|
||||
round.input.right = true;
|
||||
until(round, () => round.phase === "clear", 20000);
|
||||
round.input.right = false;
|
||||
const end = events(round, "bonusEnd");
|
||||
assert.equal(end.length, 1);
|
||||
assert.equal(end[0].won, true);
|
||||
assert.ok(end[0].dice >= BONUS_FLOOR && end[0].dice <= 8, `${end[0].dice} dice`);
|
||||
assert.equal(round.dice, 1 + end[0].dice);
|
||||
assert.equal(round.lives, 3);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: no random number is drawn in the room (the whole ride, jumping and shooting, on a draw that throws)", () => {
|
||||
const round = matRound();
|
||||
rideAt(round, 20, 0, { safe: true });
|
||||
round.input.fire = true;
|
||||
for (let t = 0; t < 30000; t += 4) {
|
||||
if (t % 1500 === 0) press(round);
|
||||
ghoul.advance(round, 4, never);
|
||||
round.events.length = 0;
|
||||
round.you.safeMs = 1e9;
|
||||
if (round.phase !== "play" || round.runner.done) break;
|
||||
}
|
||||
assert.ok(round.you.x > 600);
|
||||
});
|
||||
|
||||
/* ----------------------------------------------------------- the grade */
|
||||
|
||||
test("Ghoul Rush's Down the Hatch's grade: three hearts earn at most one die of their share, so a perfect ride is 8 dice; shooting every piece of furniture is the acts die, and taking half the souls ('Wipe your feet') the steady one", () => {
|
||||
const round = matRound();
|
||||
const b = round.bonusRound;
|
||||
assert.equal(b.perf.goal, R.furniture.length);
|
||||
assert.equal(b.perf.total, R.ribs.length + R.lows.length + R.squeezes.length + R.furniture.length + R.rails - 1);
|
||||
assert.equal(b.perf.steady, false, "no souls yet");
|
||||
const mk = (perf, hearts = 3) => {
|
||||
const x = makeBonus({ stats: { kills: 0 }, spec: { ride: { hearts: 3 } } });
|
||||
x.hearts = hearts;
|
||||
Object.assign(x.perf, { total: b.perf.total, goal: R.furniture.length }, perf);
|
||||
return x;
|
||||
};
|
||||
assert.equal(diceFor(mk({ hits: [], acts: R.furniture.length, steady: true })), 8, "a perfect ride");
|
||||
assert.equal(diceFor(mk({ hits: [], acts: 0, steady: false })), 6);
|
||||
assert.equal(diceFor(mk({ hits: [], acts: 0, steady: false }, 2)), 5, "two hearts left: no hearts die");
|
||||
assert.equal(diceFor(mk({ hits: ["r0", "r1", "u0", "s0", "s1", "s2", "f0", "f1", "f2", "g0", "g1", "r2", "r3", "r4", "u1", "u2", "s3"], acts: 0, steady: false }, 1)), BONUS_FLOOR);
|
||||
// Half the souls taken and the die is earned.
|
||||
round.candy.fill(true);
|
||||
rideAt(round, 30, 0, { safe: true });
|
||||
run(round, 500);
|
||||
assert.equal(round.bonusRound.perf.steady, true, "souls taken");
|
||||
assert.ok(round.candy.length >= 30, `${round.candy.length} souls along the throat`);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: endless lives (round.infinite) spare the hearts for every cause, through the same lose path; the Garlic shield takes a hit instead of a heart", () => {
|
||||
const tries = [{ ribs: [[60, 0]] }, { lows: [[56, 62, 23.0]] }, { furniture: [[300, 0, 0]] }, { squeezes: [[200, 0]] }];
|
||||
for (const t of tries) {
|
||||
const r = synth({ track: FLAT, ...t });
|
||||
r.infinite = true;
|
||||
if (t.furniture || t.squeezes) rideAt(r, 120, 0);
|
||||
until(r, () => events(r, "lose").length > 0, 6000);
|
||||
assert.equal(events(r, "lose").length > 0, true, JSON.stringify(Object.keys(t)));
|
||||
assert.equal(r.bonusRound.hearts, 3, JSON.stringify(Object.keys(t)));
|
||||
assert.equal(r.lives, 3);
|
||||
}
|
||||
const hole = synth({ track: [[[0, 20], [60, 20]], [[130, 20], [400, 20]]] });
|
||||
hole.infinite = true;
|
||||
rideAt(hole, 30, 0);
|
||||
until(hole, () => events(hole, "lose").length > 0, 3000);
|
||||
assert.equal(events(hole, "lose")[0].cause, "matPlunge");
|
||||
assert.equal(hole.bonusRound.hearts, 3);
|
||||
const garlic = synth({ track: FLAT, ribs: [[60, 0]] });
|
||||
garlic.you.garlic = true;
|
||||
until(garlic, () => garlic.you.x > 70, 3000);
|
||||
assert.equal(garlic.bonusRound.hearts, 3);
|
||||
assert.equal(garlic.you.garlic, false, "spent");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------ sounds and words */
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: every event has a voice that plays once, every cause has words and a sound, and the voices are tones that exist (none longer than 1.2 s)", () => {
|
||||
assert.deepEqual(Object.keys(EVENT_VOICE).sort(), [...mt.EVENTS].sort(), "a voice for every event and no more");
|
||||
const tones = ghoulSfx.default.tones;
|
||||
for (const [event, [kind, act]] of Object.entries(EVENT_VOICE)) {
|
||||
const name = MAT_VOICES[kind] && MAT_VOICES[kind][act];
|
||||
assert.ok(name, `${event} has a ${kind}.${act} voice`);
|
||||
assert.ok(tones[name], `${name} exists`);
|
||||
assert.equal(VOICES[kind][act], name, "joined to the game's voices");
|
||||
const played = heard({ type: event, what: "rib", points: 150, n: 1, kind: 0 }).played;
|
||||
assert.equal(played.filter((p) => p === name).length, 1, `${event} plays ${name} once`);
|
||||
}
|
||||
for (const [name, tone] of Object.entries(MAT_SFX.tones)) {
|
||||
assert.ok(name.startsWith("ghoulMat"), name);
|
||||
assert.ok(tones[name], `${name} is merged into the game`);
|
||||
const length = Math.max(...tone.layers.map((l) => (l.delay || 0) + l.seconds));
|
||||
assert.ok(length <= 1.2, `${name} is ${length.toFixed(2)} s`);
|
||||
for (const l of tone.layers) assert.ok(l.gain > 0 && l.gain <= 1, `${name}'s gain`);
|
||||
}
|
||||
for (const cause of mt.CAUSES) {
|
||||
assert.ok(LOSE_WORDS[cause], `${cause} has words`);
|
||||
assert.ok(LOSE_SOUNDS[cause] && LOSE_SOUNDS[cause].length === 3 && toneNames().includes(LOSE_SOUNDS[cause][0]), `${cause} has a sound`);
|
||||
assert.ok(heard({ type: "lose", cause, hearts: 2 }).played.length > 0, `${cause} sounds`);
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: the room's own names do not collide with the game's (events, causes, tones, the shared rider slot)", () => {
|
||||
for (const e of mt.EVENTS) assert.ok(e.startsWith("mat"), e);
|
||||
for (const c of mt.CAUSES) assert.ok(c.startsWith("mat"), c);
|
||||
assert.deepEqual(Object.keys(mt.MAT).filter((key) => ["hazards", "bosses", "boss"].includes(key)), []);
|
||||
assert.equal(matRound().runner.id, "mat");
|
||||
assert.equal(matRound().cart, null);
|
||||
});
|
||||
|
||||
/* --------------------------------------------------------------- drawing */
|
||||
|
||||
function stubCtx() {
|
||||
return new Proxy({}, { get: (t, name) => (name in t ? t[name] : () => {}), set: (t, name, value) => ((t[name] = value), true) });
|
||||
}
|
||||
// A live game in Down the Hatch through the stage select's finale row, its second room.
|
||||
function selectInto() {
|
||||
const g = ghoul.default.create({ canvas: { width: 0, height: 0, getContext: () => stubCtx() } });
|
||||
g.resize(900, 900);
|
||||
g.stageSelect();
|
||||
const p = g.round;
|
||||
for (let i = 0; i < ghoul.SELECTABLE.length - 1; i++) ghoul.steerSelect(p, 1, 0);
|
||||
ghoul.steerSelect(p, 0, 1);
|
||||
assert.equal(p.select.room, 1);
|
||||
g.tick(16);
|
||||
ghoul.takeSelect(p);
|
||||
return g;
|
||||
}
|
||||
|
||||
test("Ghoul Rush's Down the Hatch draws: the room lit and dark, the rider on the floor, on a ledge, in the air and ducking, each thing in each state (squeezes waiting, throbbing, closing, shut and easing, furniture falling and tumbling), a crash, the finish and the cards; the stage select goes straight into it", () => {
|
||||
const g = selectInto();
|
||||
const r = g.round;
|
||||
assert.equal(r.spec.id, "mat");
|
||||
assert.equal(r.runner.line, 0);
|
||||
assert.equal(r.you.y, ct.trackY(R, 0, ROOM.start));
|
||||
assert.equal(r.bonusRound.hearts, 3);
|
||||
r.lives = 99;
|
||||
const spots = [ROOM.start + 4, R.ribs[0][0] - 10, R.lows[0][0] - 5, R.squeezes[0][0] - 14, R.furniture[0][0] - 20, R.bile[0][0] + 6, R.checks[0], ledges[0].x0 + 20, lines[0].x1 + 10, R.finish - 30];
|
||||
const SQ = ["wait", "throb", "close", "shut", "ease", "done"];
|
||||
const FU = ["wait", "drop", "roll", "broken", "spent"];
|
||||
for (const dark of [true, false]) {
|
||||
for (const x of spots) {
|
||||
r.dark = dark;
|
||||
r.phase = "play";
|
||||
for (const st of r.spawns) st.over = true;
|
||||
r.monsters.length = 0;
|
||||
const top = ct.linesAt(R, x)[0] || [R.rails - 1, 20];
|
||||
rideAt(r, x, top[0], { safe: true });
|
||||
r.runner.squeezes = r.runner.squeezes.map((s, i) => ({ state: SQ[(i + (x | 0)) % SQ.length], t: 300, n: 1 }));
|
||||
r.runner.furniture = r.runner.furniture.map((f, i) => ({ ...f, state: FU[(i + (x | 0)) % FU.length], t: 400 }));
|
||||
for (const air of [false, true]) {
|
||||
if (air) Object.assign(r.you, { state: "air", vy: 20, y: r.you.y + 4 });
|
||||
if (air) r.runner.line = -1;
|
||||
r.you.ducking = !air && x === R.lows[0][0] - 5;
|
||||
r.shots.push({ x: x + 6, y: r.you.y + 2.4, vx: 130, vy: -10, gone: 0 });
|
||||
for (let k = 0; k < 4; k++) g.tick(16);
|
||||
r.you.safeMs = 1e9;
|
||||
rideAt(r, x, top[0], { safe: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
// A crash.
|
||||
r.you.safeMs = 0;
|
||||
rideAt(r, R.ribs[0][0] - 3, R.ribs[0][1]);
|
||||
for (let k = 0; k < 30; k++) g.tick(16);
|
||||
assert.ok(r.bonusRound.hearts < r.bonusRound.max || r.phase !== "play", "the crash draws too");
|
||||
// The finish, the won and lost cards.
|
||||
const done = selectInto();
|
||||
const d = done.round;
|
||||
d.phase = "play";
|
||||
d.runner.done = true;
|
||||
d.runner.restX = R.finish + 20;
|
||||
Object.assign(d.you, { x: R.finish + 30, y: floorOf(R.finish + 30), state: "run" });
|
||||
d.camX = R.finish - 40;
|
||||
for (let k = 0; k < 10; k++) done.tick(16);
|
||||
for (const won of [true, false]) {
|
||||
endBonus(d, won, { ROOM_POINTS: 300, award: (rd, pts) => (rd.score += pts) });
|
||||
d.bonusRound.over = true;
|
||||
for (let k = 0; k < 10; k++) {
|
||||
done.tick(16);
|
||||
bonusTick(d, { tone() {}, fx: {} });
|
||||
}
|
||||
d.bonusRound.over = false;
|
||||
}
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ telegraphs */
|
||||
|
||||
test("Ghoul Rush's Down the Hatch telegraphs: JUMP over ribs and at each fork's ledge, DUCK under uvulas and squeezes, none for furniture (it warns by itself), words only on the first three of each kind, the same every time", () => {
|
||||
const marks = telegraphMarks(R);
|
||||
const answers = { rib: "JUMP", fork: "JUMP", uvula: "DUCK", squeeze: "DUCK" };
|
||||
assert.equal(marks.length, R.ribs.length + ledges.length + R.lows.length + R.squeezes.length);
|
||||
for (const m of marks) assert.equal(m.answer, answers[m.kind], m.kind);
|
||||
const m = marks.find((q) => q.kind === "squeeze");
|
||||
const alphaOf = (x) => (telegraphs(R, x).find((t) => t.kind === "squeeze" && t.lead === m.lead) || { alpha: 0 }).alpha;
|
||||
assert.equal(alphaOf(m.lead - 45), 0, "not yet in view");
|
||||
assert.ok(alphaOf(m.lead - 36) > 0 && alphaOf(m.lead - 36) < 1, "fading in");
|
||||
assert.equal(alphaOf(m.lead - 10), 1);
|
||||
assert.equal(alphaOf(m.lead + 7), 0, "gone once passed");
|
||||
assert.deepEqual(telegraphs(R, m.lead - 33), telegraphs(R, m.lead - 33), "deterministic");
|
||||
for (const kind of ["rib", "squeeze"]) {
|
||||
const of = marks.filter((q) => q.kind === kind).sort((p, q) => p.lead - q.lead);
|
||||
of.forEach((q, i) => {
|
||||
assert.equal(q.n, i);
|
||||
const shown = telegraphs(R, q.lead - 32).find((t) => t.lead === q.lead && t.kind === kind);
|
||||
assert.equal(shown.words, i < 3, `${kind} ${i}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/* ----------------------------------------------------------- the bots */
|
||||
|
||||
// A bot that rides well: it jumps 9 to 15 short of a rib, onto each fork's ledge a few units before
|
||||
// it starts, over a piece of furniture tumbling at it when it is 6 to 17 short (and holds the
|
||||
// blaster, which usually breaks it first), and ducks under every uvula and every squeeze. `miss`
|
||||
// is the share of things it fails to dodge (by a hash).
|
||||
const mix = (a, b) => {
|
||||
let h = Math.imul(a + 0x9e37, 0x85ebca6b) ^ Math.imul(b + 0x7f4a, 0xc2b2ae35);
|
||||
h ^= h >>> 13;
|
||||
h = Math.imul(h, 0x5bd1e995);
|
||||
h ^= h >>> 15;
|
||||
return (h >>> 0) / 4294967296;
|
||||
};
|
||||
function goodBot(round, seed, miss = 0.04) {
|
||||
const { you, runner: c, input: inp } = round;
|
||||
inp.left = inp.right = inp.down = false;
|
||||
inp.fire = true;
|
||||
if (round.phase !== "play" || !c || c.done) {
|
||||
inp.up = false;
|
||||
return;
|
||||
}
|
||||
const ok = (x) => mix(seed, Math.round(x)) >= miss;
|
||||
const look = 9 + (seed % 7);
|
||||
let jump = false;
|
||||
if (c.line >= 0) {
|
||||
const line = c.line;
|
||||
const onFloor = !mt.upperLine(R, line);
|
||||
for (const [x, ln] of R.ribs) if (ln === line && x - you.x > 6 && x - you.x < look && ok(x)) jump = true;
|
||||
if (onFloor) for (const L of ledges) if (L.x0 - you.x > 1 && L.x0 - you.x < 6 && ok(L.x0)) jump = true;
|
||||
R.furniture.forEach(([, ln], i) => {
|
||||
const f = c.furniture[i];
|
||||
if (ln === line && f.state === "roll" && f.x - you.x > 6 && f.x - you.x < 17 && ok(f.x)) jump = true;
|
||||
});
|
||||
for (const [x0, x1] of R.lows) if (you.x > x0 - 10 && you.x < x1 + 3 && ok(x0)) inp.down = true;
|
||||
for (const [x] of R.squeezes) if (you.x > x - mt.SQ_W / 2 - 10 && you.x < x + mt.SQ_W / 2 + 3 && ok(x)) inp.down = true;
|
||||
}
|
||||
if (jump && !inp.down) press(round);
|
||||
else inp.up = false;
|
||||
}
|
||||
function idleBot(round) {
|
||||
const inp = round.input;
|
||||
inp.left = inp.right = inp.down = false;
|
||||
inp.up = false;
|
||||
inp.fire = true;
|
||||
}
|
||||
function rideWith(seed, bot, limit = 60000) {
|
||||
const round = matRound(seed);
|
||||
const lost = [];
|
||||
let t = 0;
|
||||
for (; t < limit && round.phase !== "clear" && !round.over; t += 16) {
|
||||
bot(round);
|
||||
if (round.runner && round.runner.done && round.phase === "play") round.input.right = true;
|
||||
ghoul.advance(round, 16, steady);
|
||||
for (const e of round.events) if (e.type === "lose") lost.push(e.cause);
|
||||
if (round.runner && !round.runner.done) {
|
||||
const off = round.you.x - round.camX;
|
||||
assert.ok(off > 4 && off < 70, `the rider stays in view (${off.toFixed(1)} from the left edge at ${round.you.x.toFixed(0)})`);
|
||||
}
|
||||
round.events.length = 0;
|
||||
}
|
||||
return { round, lost, ms: t };
|
||||
}
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: a bot that rides well finishes the whole throat in about 30 seconds, 5 to 8 dice, a heart lost at most, past every checkpoint, never a run life", () => {
|
||||
const dice = [];
|
||||
for (let seed = 1; seed <= 12; seed++) {
|
||||
const { round, lost, ms } = rideWith(seed, (r) => goodBot(r, seed));
|
||||
const b = round.bonusRound;
|
||||
assert.equal(b.won, true, `seed ${seed} finished (lost ${lost.join(",")})`);
|
||||
assert.ok(ms > 26000 && ms < 38000, `${ms} ms`);
|
||||
assert.ok(b.dice >= 5 && b.dice <= 8, `${b.dice} dice`);
|
||||
assert.ok(lost.length <= 1, `lost ${lost.join(",")}`);
|
||||
assert.equal(round.lives, 3, "never a run life");
|
||||
assert.equal(round.runner.check, R.checks.length - 1, "past every checkpoint");
|
||||
dice.push(b.dice);
|
||||
}
|
||||
assert.ok(dice.reduce((a, b) => a + b, 0) / dice.length >= 6, `${dice.join(",")}`);
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch: a bot that never dodges (holding fire) loses all three hearts early, ends with 0 dice (BONUS LOST), and the run goes on: no game over, never a run life", () => {
|
||||
for (let seed = 1; seed <= 6; seed++) {
|
||||
const { round, lost } = rideWith(seed, idleBot);
|
||||
const b = round.bonusRound;
|
||||
assert.equal(b.won, false, "never finishes");
|
||||
assert.equal(b.dice, 0);
|
||||
assert.equal(b.hearts, 0);
|
||||
assert.equal(lost.length, 3, `lost ${lost.join(",")}`);
|
||||
assert.ok(round.you.x < ROOM.length * 0.4, `out at ${round.you.x}`);
|
||||
assert.equal(round.lives, 3);
|
||||
assert.equal(round.over, false);
|
||||
assert.equal(round.phase, "clear", "the lost card, then the next room");
|
||||
}
|
||||
});
|
||||
|
||||
test("Ghoul Rush's Down the Hatch's intro banner says the controls plainly", () => {
|
||||
assert.match(R.how, /UP jump/);
|
||||
assert.match(R.how, /DOWN duck/);
|
||||
assert.match(R.how, /SPACE shoot/);
|
||||
assert.match(R.how, /throb/);
|
||||
});
|
||||
@@ -12,6 +12,7 @@ import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import * as ghoul from "../src/web-console/public/activities/ghoul-rush/ghoul.js";
|
||||
import { skipStory as storySkip } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-story.js";
|
||||
import { skipEnding } from "../src/web-console/public/activities/ghoul-rush/story/ghoul-ending.js";
|
||||
import { BANNER_SHADE, CHUNK, GAUGE_COOL, GAUGE_HOT, GAUGE_WARM, LOOKS, SEAM, VOICES, contrast, gaugeColor, hudLayout, labelSpot, limbInk } from "../src/web-console/public/activities/ghoul-rush/draw/ghoul-draw.js";
|
||||
import { ACCENTS } from "../src/web-console/public/palette.js";
|
||||
import { humNames, toneNames } from "../src/web-console/public/tones.js";
|
||||
@@ -379,7 +380,7 @@ test("Ghoul Rush: shelves are one way (jumped up through from below, landed on f
|
||||
const tops = r.spec.shelves.filter(([a, b]) => x >= a && x <= b).map(([, , y]) => y);
|
||||
const want = Math.max(ground, ...tops);
|
||||
if (want === -Infinity) continue;
|
||||
Object.assign(r.you, { x, y: 40, vy: -ghoul.FALL_MAX, state: "air", shelf: -1, drop: -1, out: 0 });
|
||||
Object.assign(r.you, { x, y: 48, vy: -ghoul.FALL_MAX, state: "air", shelf: -1, drop: -1, out: 0 });
|
||||
for (let k = 0; k < 500 && r.you.state === "air"; k++) ghoul.moveYou(r, 4);
|
||||
assert.equal(r.you.y, want, `${r.spec.id} at ${x.toFixed(1)}`);
|
||||
}
|
||||
@@ -1709,7 +1710,7 @@ test("Ghoul Rush: with the time bonus run out, a zombie shambles in from the edg
|
||||
test("Ghoul Rush: each stage is three rooms and a boss's, every room in one stage but the hall, and roomFor builds a room deeper into a run quicker and tougher, its boss with more hp and points, each capped", () => {
|
||||
assert.equal(ghoul.ROOMS[0].id, "hall", "every run starts in the hall");
|
||||
assert.equal(ghoul.ROOMS[0].boss, null);
|
||||
const placed = ghoul.STAGES.flatMap((st) => st.rooms);
|
||||
const placed = ghoul.SELECTABLE.flatMap((st) => st.rooms);
|
||||
assert.equal(new Set(placed).size, placed.length, "no room in two stages");
|
||||
// Every room but the hall is in a stage; one in none is a room forgotten.
|
||||
assert.deepEqual([...placed].sort(), ghoul.ROOMS.slice(1).map((r) => r.id).sort(), "every room but the hall in a stage");
|
||||
@@ -1734,9 +1735,9 @@ test("Ghoul Rush: each stage is three rooms and a boss's, every room in one stag
|
||||
const far = ghoul.roomFor("ballroom", 400);
|
||||
assert.ok(far.pace <= 1.4 && far.every >= 0.55 && far.tough <= 2 && far.extra <= 2);
|
||||
assert.equal(far.bossHp, ghoul.roomFor("ballroom", ghoul.BOSS_DEPTH_MAX).bossHp, "boss hp stops growing");
|
||||
const r = ghoulRound("foyer", 3);
|
||||
const r = ghoulRound("foyer", 2);
|
||||
const z = put(r, "zombie", 80);
|
||||
assert.equal(z.hp, ghoul.MONSTERS.zombie.hp + 1, "three stages in, zombies take a bolt more");
|
||||
assert.equal(z.hp, ghoul.MONSTERS.zombie.hp + 1, "two stages in (four steps), zombies take a bolt more");
|
||||
});
|
||||
|
||||
test("Ghoul Rush: out of the hall, and out of each boss's room, you pick the next stage from two not yet played; left and right move the pick, a press only takes one once the offer settles, and a stage never comes again", () => {
|
||||
@@ -1774,7 +1775,7 @@ test("Ghoul Rush: out of the hall, and out of each boss's room, you pick the nex
|
||||
through(r2);
|
||||
assert.deepEqual(r2.cleared, [want]);
|
||||
assert.equal(r2.stats.stages, 1);
|
||||
assert.deepEqual(events(r2, "stageClear").map((e) => [e.stage, e.n, e.of]), [[want, 1, ghoul.STAGES.length]]);
|
||||
assert.deepEqual(events(r2, "stageClear").map((e) => [e.stage, e.n, e.of]), [[want, 1, ghoul.RUN_STAGES]]);
|
||||
assert.equal(r2.phase, "pick");
|
||||
assert.ok(!r2.offer.includes(want), "a stage cleared is never offered again");
|
||||
assert.deepEqual(ghoul.stagesLeft(r2).map((st) => st.id), ghoul.STAGES.filter((st) => st.id !== want).map((st) => st.id));
|
||||
@@ -1791,19 +1792,28 @@ test("Ghoul Rush: out of the hall, and out of each boss's room, you pick the nex
|
||||
assert.equal(seen.size, ghoul.STAGES.length, "the offer is shuffled: any stage can come first");
|
||||
});
|
||||
|
||||
test("Ghoul Rush: clearing every stage wins the run, and its end says so", () => {
|
||||
test("Ghoul Rush: clearing RUN_STAGES stages and then the finale's rooms wins the run, and its end says so", () => {
|
||||
const round = ghoul.newRound(5);
|
||||
round.dice = 0;
|
||||
through(round);
|
||||
while (!round.over) {
|
||||
while (round.cleared.length < ghoul.RUN_STAGES) {
|
||||
assert.equal(round.phase, "pick");
|
||||
round.phaseMs = 0;
|
||||
ghoul.pickStage(round);
|
||||
for (let k = 0, n = ghoul.stageById(round.stage).rooms.length; k < n; k++) through(round);
|
||||
}
|
||||
assert.equal(round.stage, ghoul.FINALE.id, "on to the House, with no offer");
|
||||
for (const id of ghoul.FINALE.rooms) {
|
||||
assert.equal(round.over, false);
|
||||
assert.equal(round.spec.id, id);
|
||||
through(round);
|
||||
}
|
||||
assert.equal(round.phase, "ending", "the ending's pages first");
|
||||
skipEnding(round);
|
||||
assert.equal(round.won, true);
|
||||
assert.equal(round.cleared.length, ghoul.STAGES.length);
|
||||
assert.deepEqual(new Set(round.cleared), new Set(ghoul.STAGES.map((st) => st.id)), "each stage once");
|
||||
assert.equal(round.cleared.length, ghoul.RUN_STAGES);
|
||||
assert.equal(new Set(round.cleared).size, ghoul.RUN_STAGES, "each stage once");
|
||||
assert.ok(!round.cleared.includes(ghoul.FINALE.id), "the finale is no stage cleared");
|
||||
assert.equal(events(round, "won").length, 1);
|
||||
assert.equal(ghoul.advance(round, 16, steady), "over");
|
||||
});
|
||||
@@ -2104,7 +2114,8 @@ test("Ghoul Rush: every room can be finished: a route from the start to the key
|
||||
const start = surfaceAt(list, base.start, ghoul.groundAt(base, base.start));
|
||||
const door = surfaceAt(list, base.door, ghoul.groundAt(base, base.door));
|
||||
assert.ok(start && door, `${base.id}: start and door on the ground`);
|
||||
assert.ok(base.door > base.length - 14, `${base.id}: the door at the room's end`);
|
||||
// The House stands over its front door until it sinks; that door is the way on.
|
||||
if (base.boss !== "marrow") assert.ok(base.door > base.length - 14, `${base.id}: the door at the room's end`);
|
||||
let from = start;
|
||||
if (base.key) {
|
||||
const key = surfaceAt(list, base.key[0], base.key[1]);
|
||||
@@ -2422,7 +2433,8 @@ test("Ghoul Rush: of ten runs a sharp bot gets nearly all through the hall and t
|
||||
// added: Hollow End's Main Street takes the bot up to a minute). The
|
||||
// Gourd's bound has room for the slow end of the bot's spread, about a
|
||||
// minute, which is one seed or two in thirty.
|
||||
per.forEach((p, i) => assert.ok(p.secs >= 10 && p.secs <= (i === 4 ? 65 : i === 5 ? 70 : 40), `seed ${seed}: room ${i + 1} took ${p.secs.toFixed(1)} s`));
|
||||
// The blaster went to 80% of its old rate (FIRE_MS 124), so the Gourd's fight runs about a quarter longer: 80 s.
|
||||
per.forEach((p, i) => assert.ok(p.secs >= 10 && p.secs <= (i === 4 ? 80 : i === 5 ? 70 : 40), `seed ${seed}: room ${i + 1} took ${p.secs.toFixed(1)} s`));
|
||||
}
|
||||
assert.ok(outOfFoyer >= 9, `${outOfFoyer} of 10 through the hall and out of the Foyer`);
|
||||
assert.ok(pastGourd >= 5, `${pastGourd} of 10 past the Gourd`);
|
||||
@@ -2466,10 +2478,12 @@ function takeManor(g) {
|
||||
}
|
||||
|
||||
// Past a stage's intro card the way a player does: the minimum wait, then fire.
|
||||
// Past every card up (the finale's stage card leads straight into its boss's).
|
||||
function leaveIntro(g) {
|
||||
if (g.round.phase !== "intro" && g.round.phase !== "bossintro") return;
|
||||
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 50; ms += 16) g.tick(16);
|
||||
g.key("action");
|
||||
for (let n = 0; n < 3 && (g.round.phase === "intro" || g.round.phase === "bossintro"); n++) {
|
||||
for (let ms = 0; ms < ghoul.INTRO_MIN_MS + 50; ms += 16) g.tick(16);
|
||||
g.key("action");
|
||||
}
|
||||
}
|
||||
|
||||
// Starts a game with nothing waking.
|
||||
@@ -2570,7 +2584,7 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows
|
||||
const scores = [];
|
||||
const g = ghoul.default.create({ canvas, memo, onScore: (n) => scores.push(n) });
|
||||
g.resize(900, 900);
|
||||
assert.ok(texts.some(([t]) => t.includes(`Best: 0 of ${ghoul.STAGES.length} stages`)), "the start screen names the record");
|
||||
assert.ok(texts.some(([t]) => t.includes(`Best: 0 of ${ghoul.RUN_STAGES} stages`)), "the start screen names the record");
|
||||
g.key("action");
|
||||
skipStory(g);
|
||||
g.round.dice = 0;
|
||||
@@ -2613,7 +2627,7 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows
|
||||
assert.equal(g.round.phase, "pick");
|
||||
texts.length = 0;
|
||||
g.tick(16);
|
||||
assert.ok(texts.some(([t]) => t === `STAGE 1 OF ${ghoul.STAGES.length} CLEARED`));
|
||||
assert.ok(texts.some(([t]) => t === `STAGE 1 OF ${ghoul.RUN_STAGES} CLEARED`));
|
||||
for (let ms = 0; ms < ghoul.PICK_HOLD_MS + 50; ms += 16) g.tick(16);
|
||||
g.key("up");
|
||||
assert.ok(g.round.stage && g.round.stage !== want, "up takes one too, never the stage just cleared");
|
||||
@@ -2628,7 +2642,7 @@ test("Ghoul Rush game: the start screen names the record, the pick screen shows
|
||||
texts.length = 0;
|
||||
g.resize(900, 900);
|
||||
assert.ok(texts.some(([t, font]) => t === String(g.score) && /\b7px/.test(font)), "the score, big");
|
||||
assert.ok(texts.some(([t]) => t.startsWith(`Cleared 1 of ${ghoul.STAGES.length} stages, out in `) && t.includes("A new record!")), "how far, and the record");
|
||||
assert.ok(texts.some(([t]) => t.startsWith(`Cleared 1 of ${ghoul.RUN_STAGES} stages, out in `) && t.includes("A new record!")), "how far, and the record");
|
||||
const again = ghoul.default.create({ canvas, memo: { get: () => 9, set: () => assert.fail("never lowered") } });
|
||||
again.resize(900, 900);
|
||||
again.key("action");
|
||||
@@ -2654,7 +2668,7 @@ test("Ghoul Rush game: stageSelect() (the window's stage code) opens a practice
|
||||
for (let i = 0; i < 30; i++) g.tick(16);
|
||||
assert.equal(r.phase, "select", "it waits on a choice");
|
||||
assert.equal(r.clock, 0, "nothing moves");
|
||||
const last = ghoul.STAGES.length - 1;
|
||||
const last = ghoul.SELECTABLE.length - 1;
|
||||
for (let i = 0; i < last + 3; i++) g.key("down");
|
||||
assert.equal(r.select.at, last, "down stops at the last stage");
|
||||
// Two up clamps inside the list; then steer on to the Manor, whose second
|
||||
@@ -2664,7 +2678,7 @@ test("Ghoul Rush game: stageSelect() (the window's stage code) opens a practice
|
||||
g.key("up");
|
||||
assert.equal(r.select.at, last - 2);
|
||||
const st = ghoul.STAGES[0];
|
||||
for (let i = 0; i < ghoul.STAGES.length; i++) g.key("up");
|
||||
for (let i = 0; i < ghoul.SELECTABLE.length; i++) g.key("up");
|
||||
assert.equal(r.select.at, 0, "the Manor");
|
||||
for (let i = 0; i < st.rooms.length + 3; i++) g.key("right");
|
||||
assert.equal(r.select.room, st.rooms.length - 1, "right stops at the boss room");
|
||||
@@ -2675,7 +2689,7 @@ test("Ghoul Rush game: stageSelect() (the window's stage code) opens a practice
|
||||
assert.equal(r.stage, st.id);
|
||||
assert.equal(r.stageAt, st.rooms.length - 2);
|
||||
assert.equal(r.spec.id, st.rooms[st.rooms.length - 2], "straight into the room picked");
|
||||
r.events.push({ type: "stageClear", stage: st.id, n: 3, of: ghoul.STAGES.length });
|
||||
r.events.push({ type: "stageClear", stage: st.id, n: 3, of: ghoul.RUN_STAGES });
|
||||
g.tick(16);
|
||||
assert.equal(saved, 0, "a practice run never sets the record");
|
||||
r.score = 5000;
|
||||
@@ -2700,9 +2714,14 @@ test("Ghoul Rush game: a run that clears every stage ends in a win, with a fanfa
|
||||
const r = g.round;
|
||||
through(r);
|
||||
while (!r.over) {
|
||||
// The ending's pages once the House is dead.
|
||||
if (r.phase === "ending") {
|
||||
skipEnding(r);
|
||||
continue;
|
||||
}
|
||||
r.phaseMs = 0;
|
||||
ghoul.pickStage(r);
|
||||
for (let k = 0; k < 4; k++) through(r);
|
||||
for (let k = 0; k < 4 && r.phase !== "ending" && !r.over; k++) through(r);
|
||||
}
|
||||
g.tick(16);
|
||||
assert.equal(g.state, "over");
|
||||
@@ -3028,7 +3047,7 @@ test("Ghoul Rush: every pill's text reads at 4.5:1 on its backing and its timer'
|
||||
assert.ok(k >= 4.5, `${theme}/${id}: "${p.text}" in ${p.ink} on ${under} reads ${k.toFixed(2)}:1`);
|
||||
}
|
||||
}
|
||||
for (const want of ["THE LONG HALL", `STAGE 0 OF ${ghoul.STAGES.length}`, "♥", "BONUS 0", "~CHAIN x4", "~SPREAD", "~RAPID", "GARLIC"]) {
|
||||
for (const want of ["THE LONG HALL", `STAGE 0 OF ${ghoul.RUN_STAGES}`, "♥", "BONUS 0", "~CHAIN x4", "~SPREAD", "~RAPID", "GARLIC"]) {
|
||||
const tinted = want.startsWith("~");
|
||||
const text = tinted ? want.slice(1) : want;
|
||||
assert.ok(seen.some((p) => p.text.includes(text) && (!tinted || p.tints.length)), `${theme}/${id}: "${text}" drawn (${seen.map((p) => p.text)})`);
|
||||
@@ -3048,7 +3067,7 @@ test("Ghoul Rush: the top bar names the stage (or the hall) and counts the stage
|
||||
g.tick(16);
|
||||
const seen = pills();
|
||||
const at = seen.findIndex((p) => p.text.startsWith("♥"));
|
||||
assert.deepEqual(seen.slice(0, 2).map((p) => p.text), ["THE LONG HALL", `STAGE 0 OF ${ghoul.STAGES.length}`], "the hall, nothing cleared yet");
|
||||
assert.deepEqual(seen.slice(0, 2).map((p) => p.text), ["THE LONG HALL", `STAGE 0 OF ${ghoul.RUN_STAGES}`], "the hall, nothing cleared yet");
|
||||
assert.equal(at, 2, `right after the stage pills (${seen.map((p) => p.text)})`);
|
||||
assert.equal(seen[at].text, livesText(g.round.lives));
|
||||
assert.equal(seen[at].backing, LIVES_BACK);
|
||||
@@ -3251,9 +3270,9 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug
|
||||
g.resize(900, 900);
|
||||
g.key("action");
|
||||
skipStory(g);
|
||||
// Every room a run can reach: the hall and each stage's, not the retired Bog Runner.
|
||||
const LIVE = 1 + ghoul.STAGES.flatMap((st) => st.rooms).length;
|
||||
for (let n = 1; n <= LIVE; n++) {
|
||||
// Every room the run reaches: the hall, each of its RUN_STAGES stages' and the finale's.
|
||||
for (let n = 1; g.state === "running"; n++) {
|
||||
assert.ok(n < 80, "the run ends");
|
||||
const r = g.round;
|
||||
r.lives = 99;
|
||||
const bot = makeBot(ghoul, 1, ghoul.seeded(n));
|
||||
@@ -3266,7 +3285,8 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug
|
||||
}
|
||||
assert.ok(calls.count > drawn, `room ${n} draws`);
|
||||
leaveIntro(g);
|
||||
if (r.boss) r.boss.state = "down";
|
||||
// A fallen boss, and the House gone from in front of its door.
|
||||
if (r.boss) Object.assign(r.boss, { state: "down", gone: true });
|
||||
r.hasKey = true;
|
||||
// Through the door, once any life lost in the run is over with.
|
||||
for (let ms = 0; ms < 8000 && g.round.room === n && g.state === "running"; ms += 16) {
|
||||
@@ -3278,6 +3298,7 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug
|
||||
r.ask.t = ghoul.ASK_GUARD_MS;
|
||||
ghoul.answerDie(r, true);
|
||||
}
|
||||
if (r.phase === "ending") skipEnding(r);
|
||||
if (r.phase === "pick") {
|
||||
const before = calls.count;
|
||||
g.tick(16);
|
||||
@@ -3287,7 +3308,7 @@ test("Ghoul Rush game: every room and boss draws, and each pick of stage, throug
|
||||
}
|
||||
g.tick(16);
|
||||
}
|
||||
if (n === LIVE) break;
|
||||
if (g.state !== "running") break;
|
||||
leaveIntro(g);
|
||||
for (let ms = 0; ms < ghoul.READY_MS + 100; ms += 16) g.tick(16);
|
||||
assert.equal(g.round.room, n + 1);
|
||||
|
||||
@@ -2512,10 +2512,10 @@ test("Ghoul Rush plays in the real window: its board's shape and Planny big enou
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
test("the server serves the activities' scripts, golf's seventeen, Light Trails, Bug Hunt, Sunset Drive, Stack Deploy, Bumper Ring's two, Rapids Run's two, Hot Potato's two, Crossing Rush's two, Bounce Road's seven, Ghoul Rush's eighty-three, every game's sound effects and the shared pills included", () => {
|
||||
test("the server serves the activities' scripts, golf's seventeen, Light Trails, Bug Hunt, Sunset Drive, Stack Deploy, Bumper Ring's two, Rapids Run's two, Hot Potato's two, Crossing Rush's two, Bounce Road's seven, Ghoul Rush's ninety-five, every game's sound effects and the shared pills included", () => {
|
||||
const server = fs.readFileSync(new URL("../src/web-console/static.mjs", import.meta.url), "utf8");
|
||||
const servable = server.slice(server.indexOf("const SERVABLE = new Set(["), server.indexOf("]);", server.indexOf("const SERVABLE = new Set([")));
|
||||
for (const file of ["activities.js", "tones.js", "music.js", "activities/snake.js", "screens/activities.js", "activities/golf.js", "activities/golf-holes.js", "activities/golf-draw.js", "activities/golf-decor.js", "activities/golf-kit.js", "activities/golf-paint.js", "activities/golf-looks.js", "activities/golf-course-pirate.js", "activities/golf-course-cave.js", "activities/golf-course-dino.js", "activities/golf-course-candy.js", "activities/golf-course-space.js", "activities/golf-course-frost.js", "activities/golf-look-dino.js", "activities/golf-look-candy.js", "activities/golf-look-space.js", "activities/golf-look-frost.js", "activities/trails.js", "activities/bugs.js", "activities/drive.js", "activities/stack.js", "activities/bumper.js", "activities/bumper-draw.js", "activities/rapids.js", "activities/rapids-draw.js", "activities/fuse.js", "activities/fuse-draw.js", "activities/hop.js", "activities/hop-draw.js", "activities/bounce.js", "activities/bounce-draw.js", "activities/bounce-roads.js", "activities/bounce-road.js", "activities/bounce-rivals.js", "activities/bounce-scenery.js", "activities/bounce-cars.js", "activities/ghoul-rush/ghoul.js", "activities/ghoul-rush/draw/ghoul-draw.js", "activities/ghoul-rush/core/ghoul-rooms.js", "activities/ghoul-rush/stages/wing/ghoul-bones.js", "activities/ghoul-rush/stages/wing/ghoul-bones-draw.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard-draw.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds-draw.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel-draw.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium-draw.js", "activities/ghoul-rush/stages/village/ghoul-village.js", "activities/ghoul-rush/stages/village/ghoul-village-draw.js", "activities/ghoul-rush/stages/village/ghoul-village-world.js", "activities/ghoul-rush/stages/village/ghoul-village-wolf.js", "activities/ghoul-rush/stages/mine/ghoul-mine.js", "activities/ghoul-rush/stages/mine/ghoul-mine-draw.js", "activities/ghoul-rush/stages/mine/ghoul-mine-world.js", "activities/ghoul-rush/stages/mine/ghoul-mine-tommy.js", "activities/ghoul-rush/rides/cart/ghoul-cart.js", "activities/ghoul-rush/rides/cart/ghoul-cart-draw.js", "activities/ghoul-rush/rides/sled/ghoul-sled.js", "activities/ghoul-rush/rides/sled/ghoul-sled-draw.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney-draw.js", "activities/ghoul-rush/rides/banister/ghoul-banister.js", "activities/ghoul-rush/rides/banister/ghoul-banister-draw.js", "activities/ghoul-rush/rides/banister/ghoul-sfx-banister.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse-draw.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew.js", "activities/ghoul-rush/rides/pew/ghoul-pew-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew-course.js", "activities/ghoul-rush/rides/pew/ghoul-pew-world.js", "activities/ghoul-rush/rides/mower/ghoul-mower.js", "activities/ghoul-rush/rides/mower/ghoul-mower-draw.js", "activities/ghoul-rush/rides/tray/ghoul-tray.js", "activities/ghoul-rush/rides/tray/ghoul-tray-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-world.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-draw.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-world.js", "activities/ghoul-rush/arms/ghoul-flare.js", "activities/ghoul-rush/stages/bog/ghoul-bog.js", "activities/ghoul-rush/stages/bog/ghoul-bog-draw.js", "activities/ghoul-rush/draw/ghoul-picker-draw.js", "activities/ghoul-rush/core/ghoul-powers.js", "activities/ghoul-rush/arms/ghoul-arms.js", "activities/ghoul-rush/arms/ghoul-arms-draw.js", "activities/ghoul-rush/arms/ghoul-rockets.js", "activities/ghoul-rush/arms/ghoul-rockets-draw.js", "activities/ghoul-rush/arms/ghoul-pans.js", "activities/ghoul-rush/arms/ghoul-sfx-arms.js", "activities/ghoul-rush/core/ghoul-run.js", "activities/ghoul-rush/core/ghoul-dice.js", "activities/ghoul-rush/core/ghoul-dice-draw.js", "activities/ghoul-rush/story/ghoul-gameover-draw.js", "activities/ghoul-rush/story/ghoul-intros.js", "activities/ghoul-rush/story/ghoul-intro-draw.js", "activities/ghoul-rush/story/ghoul-boss-intros.js", "activities/ghoul-rush/story/ghoul-bossintro-draw.js", "activities/ghoul-rush/story/ghoul-story.js", "activities/ghoul-rush/story/ghoul-story-draw.js", "activities/ghoul-rush/story/ghoul-sfx-story.js", "activities/ghoul-rush/core/ghoul-bonus.js", "activities/ghoul-rush/core/ghoul-bonus-drLine truncated
|
||||
for (const file of ["activities.js", "tones.js", "music.js", "activities/snake.js", "screens/activities.js", "activities/golf.js", "activities/golf-holes.js", "activities/golf-draw.js", "activities/golf-decor.js", "activities/golf-kit.js", "activities/golf-paint.js", "activities/golf-looks.js", "activities/golf-course-pirate.js", "activities/golf-course-cave.js", "activities/golf-course-dino.js", "activities/golf-course-candy.js", "activities/golf-course-space.js", "activities/golf-course-frost.js", "activities/golf-look-dino.js", "activities/golf-look-candy.js", "activities/golf-look-space.js", "activities/golf-look-frost.js", "activities/trails.js", "activities/bugs.js", "activities/drive.js", "activities/stack.js", "activities/bumper.js", "activities/bumper-draw.js", "activities/rapids.js", "activities/rapids-draw.js", "activities/fuse.js", "activities/fuse-draw.js", "activities/hop.js", "activities/hop-draw.js", "activities/bounce.js", "activities/bounce-draw.js", "activities/bounce-roads.js", "activities/bounce-road.js", "activities/bounce-rivals.js", "activities/bounce-scenery.js", "activities/bounce-cars.js", "activities/ghoul-rush/ghoul.js", "activities/ghoul-rush/draw/ghoul-draw.js", "activities/ghoul-rush/core/ghoul-rooms.js", "activities/ghoul-rush/stages/wing/ghoul-bones.js", "activities/ghoul-rush/stages/wing/ghoul-bones-draw.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard-draw.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds-draw.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel-draw.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium-draw.js", "activities/ghoul-rush/stages/village/ghoul-village.js", "activities/ghoul-rush/stages/village/ghoul-village-draw.js", "activities/ghoul-rush/stages/village/ghoul-village-world.js", "activities/ghoul-rush/stages/village/ghoul-village-wolf.js", "activities/ghoul-rush/stages/mine/ghoul-mine.js", "activities/ghoul-rush/stages/mine/ghoul-mine-draw.js", "activities/ghoul-rush/stages/mine/ghoul-mine-world.js", "activities/ghoul-rush/stages/mine/ghoul-mine-tommy.js", "activities/ghoul-rush/rides/cart/ghoul-cart.js", "activities/ghoul-rush/rides/cart/ghoul-cart-draw.js", "activities/ghoul-rush/rides/sled/ghoul-sled.js", "activities/ghoul-rush/rides/sled/ghoul-sled-draw.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney-draw.js", "activities/ghoul-rush/rides/banister/ghoul-banister.js", "activities/ghoul-rush/rides/banister/ghoul-banister-draw.js", "activities/ghoul-rush/rides/banister/ghoul-sfx-banister.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse-draw.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew.js", "activities/ghoul-rush/rides/pew/ghoul-pew-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew-course.js", "activities/ghoul-rush/rides/pew/ghoul-pew-world.js", "activities/ghoul-rush/rides/mower/ghoul-mower.js", "activities/ghoul-rush/rides/mower/ghoul-mower-draw.js", "activities/ghoul-rush/rides/tray/ghoul-tray.js", "activities/ghoul-rush/rides/tray/ghoul-tray-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-world.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-draw.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-world.js", "activities/ghoul-rush/arms/ghoul-flare.js", "activities/ghoul-rush/stages/bog/ghoul-bog.js", "activities/ghoul-rush/stages/bog/ghoul-bog-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-draw.js", "activities/ghoul-rush/rides/mat/ghoul-mat-room.js", "activities/ghoul-rush/rides/mat/ghoul-mat.js", "activities/ghoul-rush/rides/mat/ghoul-mat-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-dollhouse-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-room.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-pit-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart-draw.js", "activities/ghoul-rush/story/ghoul-ending.js", "activities/ghoul-rush/story/ghoul-ending-draw.js", "activities/ghoul-rush/draw/ghoul-picker-draw.js", "activities/ghoul-rush/core/ghoLine truncated
|
||||
assert.ok(servable.includes(`"${file}"`), `SERVABLE includes ${file}`);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user