mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Add Bounce Road music, extras and arcade tests
AI Assisted
This commit is contained in:
1 parent
a0300d4ac2
commit
5679101487
23 files changed
+6004
-624
No files matched your search
@@ -0,0 +1,983 @@
|
||||
// Web console tests, Bounce Road's arcade layer: the gadgets a double tap sets off (rockets, oil, the ground pound, the zapper) and the power-ups that work as taken, the Fever, the lives a score earns and a stage's rank, the newer things on the road (conveyors, spring pads, bumpers, lasers, stompers, rollers), the rivals with a trick of their own, the five bosses, and the music's deal.
|
||||
// Run with: node --test scripts/test-web-console-activities-bounce-arcade.mjs
|
||||
//
|
||||
// The driving, the road and the older rivals have their own suite,
|
||||
// scripts/test-web-console-activities-bounce.mjs, whose helpers this file
|
||||
// copies. No browser and no server: a stub canvas stands in for the page.
|
||||
|
||||
import "./seed-random.mjs";
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as bounce from "../src/web-console/public/activities/bounce.js";
|
||||
import { BOUNCE_MUSIC, SCORES } from "../src/web-console/public/activities/bounce-music.js";
|
||||
|
||||
const game = bounce.default;
|
||||
|
||||
/* ------------------------------------------------------------- helpers */
|
||||
|
||||
// A random source that always says the same, so no rival guesses.
|
||||
const steady = () => 0.5;
|
||||
const eventsOf = (round, type) => round.events.filter((e) => e.type === type);
|
||||
|
||||
// A 2D context whose every method is a no-op.
|
||||
function stubCanvas() {
|
||||
const ctx = new Proxy({}, {
|
||||
get: (target, name) => (name in target ? target[name] : () => {}),
|
||||
set: (target, name, value) => { target[name] = value; return true; },
|
||||
});
|
||||
return { width: 0, height: 0, getContext: () => ctx };
|
||||
}
|
||||
|
||||
// A round on the road from `seed`, with only you on it and no rival coming.
|
||||
function bounceRound(seed = 7) {
|
||||
const round = bounce.newRound(seed, steady);
|
||||
round.cars.length = 1;
|
||||
round.spawnMs = 1e12;
|
||||
round.supplyMs = 1e12;
|
||||
round.far = 1e9;
|
||||
return round;
|
||||
}
|
||||
|
||||
// A rival of `kind` put at (x, d), still and on the ground, going nowhere on
|
||||
// its own.
|
||||
function bounceRival(round, kind, x, d, over = {}) {
|
||||
let car = null;
|
||||
for (let at = round.cars[0].d + 300; !car && at < round.cars[0].d + 3000; at += 40) car = bounce.spawnRival(round, kind, steady, at);
|
||||
assert.ok(car, `a ${kind} spawns`);
|
||||
Object.assign(car, { x, d, v: 0, tv: 0, vx: 0, kx: 0, air: 0, tx: x, lane: x, hopIn: 1e9, dropIn: 1e9, phaseIn: 1e9, mode: "calm", ...over });
|
||||
return car;
|
||||
}
|
||||
|
||||
// A spot on plain road: the middle of the first row at or after `d` with
|
||||
// nothing to catch you out for `clear` units either side.
|
||||
function plainSpot(road, d = 40, clear = 20) {
|
||||
bounce.ensureRoad(road, d + 9000);
|
||||
const busy = (lo, hi) => [road.pads, road.blocks, road.hazards, road.items, road.stars].some((list) => list.some((e) => e.d > lo - 12 && (e.d1 ?? e.d) > lo - 12 && e.d < hi + 12));
|
||||
for (let i = Math.floor(d / bounce.ROW); i < road.rows; i++) {
|
||||
let ok = true;
|
||||
for (let j = i - clear / bounce.ROW; ok && j <= i + clear / bounce.ROW; j++) ok = bounce.plainRow(road, j);
|
||||
if (ok && !busy(i * bounce.ROW - clear, i * bounce.ROW + clear)) return { x: (road.L[i] + road.R[i]) / 2, d: i * bounce.ROW + 1, i };
|
||||
}
|
||||
throw new Error("no plain road");
|
||||
}
|
||||
|
||||
// A round with you at speed on a long stretch of plain road.
|
||||
function onPlain(seed = 7, clear = 50) {
|
||||
const round = bounceRound(seed);
|
||||
const at = plainSpot(round.road, 80, clear);
|
||||
const you = round.cars[0];
|
||||
Object.assign(you, { x: at.x, d: at.d, v: 40, pnose: at.d + you.l / 2 });
|
||||
// On the spot's own stage, so no stage line is crossed on the way to it.
|
||||
while (round.road.stageAt[round.stage] <= at.d) round.stage++;
|
||||
return { round, you, at };
|
||||
}
|
||||
|
||||
// The first entry of `list` on the road matching `pick`, with the round set
|
||||
// to its stage and you put `before` it, on the ground.
|
||||
function onto(round, list, pick, before = 30) {
|
||||
const road = round.road;
|
||||
bounce.ensureRoad(road, 60000);
|
||||
const e = road[list].find(pick);
|
||||
assert.ok(e, `a ${list} entry on the road`);
|
||||
const d0 = e.d ?? e.d0;
|
||||
while (road.stageAt[round.stage] <= d0) round.stage++;
|
||||
const you = round.cars[0];
|
||||
const d = d0 - before;
|
||||
Object.assign(you, { d, x: e.x ?? (road.L[bounce.rowOf(d)] + road.R[bounce.rowOf(d)]) / 2, v: 40, air: 0, pnose: d + you.l / 2 });
|
||||
round.far = 1e9;
|
||||
return e;
|
||||
}
|
||||
|
||||
// Lands you on `car` in the next slice.
|
||||
function landOn(round, car) {
|
||||
const you = round.cars[0];
|
||||
Object.assign(car, { x: you.x, d: you.d + 1, air: 0 });
|
||||
Object.assign(you, { air: 4, airMax: 600 });
|
||||
bounce.advance(round, 4, steady);
|
||||
}
|
||||
|
||||
// The round's clock put where `h`'s own cycle is `at` ms in.
|
||||
const cycleTo = (round, h, at) => (round.clock = h.period * 3 - (h.phase % h.period) + at);
|
||||
|
||||
/* ------------------------------------------------------- the gadgets */
|
||||
|
||||
test("Bounce Road arcade: a gadget taken is held until it is set off, one at a time; the rest work as they are taken", () => {
|
||||
const { round, you } = onPlain();
|
||||
assert.deepEqual([...bounce.GADGETS].sort(), ["mega", "nitro", "oil", "pound", "rocket", "zap"]);
|
||||
for (const kind of bounce.GADGETS) {
|
||||
bounce.applyPower(round, kind);
|
||||
assert.deepEqual(you.held, { kind, uses: bounce.POWERS[kind].uses }, `${kind} is held`);
|
||||
}
|
||||
assert.equal(you.held.kind, bounce.GADGETS.at(-1), "a new one takes the old one's place");
|
||||
bounce.applyPower(round, "spring");
|
||||
bounce.applyPower(round, "bubble");
|
||||
bounce.applyPower(round, "magnet");
|
||||
assert.ok(you.spring && you.bubble && you.magnetMs === bounce.MAGNET_MS, "a Spring, a Bubble and a Magnet work at once");
|
||||
assert.equal(you.held.kind, bounce.GADGETS.at(-1), "and leave the gadget held");
|
||||
round.lives = 2;
|
||||
bounce.applyPower(round, "heart");
|
||||
assert.equal(round.lives, 3, "a heart is a life");
|
||||
round.lives = bounce.MAX_LIVES;
|
||||
bounce.applyPower(round, "heart");
|
||||
assert.equal(round.lives, bounce.MAX_LIVES, "never past MAX_LIVES");
|
||||
for (const [kind, , from] of bounce.POWER_ROLL) {
|
||||
assert.ok(bounce.POWERS[kind], `${kind} is a power-up`);
|
||||
assert.ok(from >= 2, "none on the first stage");
|
||||
}
|
||||
assert.equal(new Set(bounce.POWER_ROLL.map((r) => r[0])).size, Object.keys(bounce.POWERS).length, "every power-up turns up");
|
||||
for (let n = 2; n <= 8; n++) for (let r = 0; r < 1; r += 0.05) assert.ok(bounce.POWER_ROLL.find((e) => e[0] === bounce.rollPower(n, r))[2] <= n, `stage ${n} rolls only what has come`);
|
||||
const road = bounce.newRoad(5);
|
||||
bounce.ensureRoad(road, 9000);
|
||||
const arena = road.items.find((it) => it.d > road.stageAt[2]);
|
||||
assert.equal(arena.kind, "rocket", "a boss stage opens with rockets on the road");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a rocket blows up the first rival in its way for its points, takes a hit off a boss, smashes a barrier, and three are a load", () => {
|
||||
const { round, you, at } = onPlain();
|
||||
bounce.applyPower(round, "rocket");
|
||||
const brick = bounceRival(round, "brick", at.x, at.d + 30);
|
||||
assert.equal(bounce.usePower(round), "rocket");
|
||||
assert.equal(you.held.uses, 2);
|
||||
assert.equal(round.shots.length, 1);
|
||||
bounce.advance(round, 500, steady);
|
||||
assert.equal(brick.outKind, "blast", "blown up");
|
||||
const [blast] = eventsOf(round, "blast");
|
||||
assert.equal(blast.points, Math.max(bounce.BLAST_POINTS, bounce.RIVALS.brick.points));
|
||||
assert.equal(round.stats.blasted, 1);
|
||||
assert.equal(round.shots.length, 0, "the rocket is spent");
|
||||
const m = bounceRival(round, "monster", you.x, you.d + 34, { hp: 5, v: you.v, tv: you.v });
|
||||
bounce.usePower(round);
|
||||
bounce.advance(round, 500, steady);
|
||||
assert.equal(m.hp, 4, "a hit off the Monster");
|
||||
assert.ok(eventsOf(round, "stomp").some((e) => e.how === "rocket" && e.points === bounce.ROCKET_BOSS_POINTS));
|
||||
m.out = 1;
|
||||
m.outKind = "gone";
|
||||
bounce.advance(round, 16, steady);
|
||||
const block = { kind: "block", x: you.x, d: you.d + 26, w: 5, l: 3, hit: 0 };
|
||||
round.drops.push(block);
|
||||
bounce.usePower(round);
|
||||
assert.equal(you.held, null, "the third was the last");
|
||||
bounce.advance(round, 400, steady);
|
||||
assert.ok(block.hit > 0, "a barrier smashed");
|
||||
// A rocket that meets nothing runs out of road.
|
||||
bounce.applyPower(round, "rocket");
|
||||
bounce.usePower(round);
|
||||
bounce.advance(round, 1500, steady);
|
||||
assert.equal(round.shots.length, 0);
|
||||
assert.equal(round.stats.fired, 4);
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: oil lies behind you and spins the rival that crosses it, which is yours when the road's edge takes it; a boss's oil only takes your grip", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
bounce.applyPower(round, "oil");
|
||||
bounce.usePower(round);
|
||||
assert.equal(you.held.uses, 1);
|
||||
const [spill] = round.spills;
|
||||
assert.ok(spill.d < you.d && !spill.foe, "behind you");
|
||||
const brick = bounceRival(round, "brick", spill.x + 1, spill.d - 7, { v: 30, tv: 30 });
|
||||
let spun = false;
|
||||
for (let ms = 0; ms < 1200 && !spun; ms += 16) {
|
||||
bounce.advance(round, 16, steady);
|
||||
spun = brick.spinMs > 0;
|
||||
}
|
||||
assert.ok(spun, "it spins");
|
||||
assert.equal(eventsOf(round, "spin").length, 1);
|
||||
assert.ok(brick.credit > 0 && Math.abs(brick.kx) > 10, "thrown sideways, and yours");
|
||||
bounce.think(round, brick, 16, steady);
|
||||
assert.equal(brick.gain, 0, "it cannot steer out of it");
|
||||
assert.equal(round.stats.spun, 1);
|
||||
// A boss's spill: no life, no spin, only a slide.
|
||||
const r2 = onPlain(7, 60);
|
||||
r2.round.spills.push({ x: r2.at.x, d: r2.at.d + 6, w: 9, l: 11, until: r2.round.clock + 5000, foe: true });
|
||||
for (let ms = 0; ms < 400; ms += 16) bounce.advance(r2.round, 16, steady);
|
||||
assert.ok(r2.you.slickMs > 0 || eventsOf(r2.round, "slick").length === 1, "your grip goes");
|
||||
assert.equal(r2.round.lives, bounce.START_LIVES);
|
||||
bounce.advance(r2.round, bounce.OIL_MS + 2000, steady);
|
||||
assert.equal(r2.round.spills.length, 0, "and it dries up");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a ground pound slams you down, flattens what is near, throws what is further and smashes barriers; on the road it goes off at once", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
bounce.applyPower(round, "pound");
|
||||
const near = bounceRival(round, "zigzag", at.x + 2, at.d + 6);
|
||||
const mid = bounceRival(round, "brick", at.x + 8, at.d + 16);
|
||||
const far = bounceRival(round, "frog", at.x, at.d + 60);
|
||||
const block = { kind: "block", x: at.x - 6, d: at.d + 8, w: 5, l: 3, hit: 0 };
|
||||
round.drops.push(block);
|
||||
round.bolts.push({ x: at.x, d: at.d + 10, v: 0 });
|
||||
assert.equal(bounce.usePower(round), "pound");
|
||||
assert.equal(near.outKind, "flat", "flattened");
|
||||
assert.ok(eventsOf(round, "crush").some((e) => e.pound && e.kind === "zigzag"));
|
||||
assert.ok(mid.out === 0 && mid.kx > 5 && mid.credit > 0, "thrown outward, and yours if it goes off");
|
||||
assert.ok(far.out === 0 && far.kx === 0, "out of reach");
|
||||
assert.ok(block.hit > 0, "the barrier is gone");
|
||||
assert.equal(round.bolts.length, 0, "and the bolts");
|
||||
assert.equal(eventsOf(round, "pound").length, 1);
|
||||
assert.equal(you.held.uses, 1);
|
||||
// In the air it brings you down first.
|
||||
Object.assign(you, { air: 500, airMax: 600 });
|
||||
bounce.usePower(round);
|
||||
assert.ok(you.pounding && you.air <= bounce.POUND_DROP_MS, "down in POUND_DROP_MS");
|
||||
assert.equal(eventsOf(round, "pound").length, 1, "nothing until you land");
|
||||
bounce.advance(round, bounce.POUND_DROP_MS + 8, steady);
|
||||
assert.equal(eventsOf(round, "pound").length, 2, "the shockwave on landing");
|
||||
assert.equal(you.pounding, false);
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a zap leaves every rival near coasting blind for ZAP_MS (no steering, no tricks, no hops), stuns a boss and brings the Whirlybird down", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
const frog = bounceRival(round, "frog", at.x + 6, at.d + 20, { hopIn: 0 });
|
||||
const away = bounceRival(round, "zigzag", at.x, at.d + bounce.ZAP_RANGE + 30);
|
||||
const m = bounceRival(round, "monster", at.x - 12, at.d + 40, { hp: 5 });
|
||||
const chopper = bounceRival(round, "chopper", at.x + 12, at.d + 50, { mode: "high", lift: 1, high: true });
|
||||
round.bolts.push({ x: at.x, d: at.d + 30, v: 0 });
|
||||
bounce.applyPower(round, "zap");
|
||||
bounce.usePower(round);
|
||||
assert.equal(you.held, null);
|
||||
assert.equal(frog.zapMs, bounce.ZAP_MS);
|
||||
assert.ok(frog.credit > bounce.ZAP_MS, "the road's edge or a hole makes it yours");
|
||||
assert.equal(away.zapMs, 0, "out of range");
|
||||
assert.ok(m.stunMs > 1000, "a boss is stunned");
|
||||
assert.equal(chopper.mode, "low", "the Whirlybird comes down");
|
||||
assert.equal(round.bolts.length, 0);
|
||||
bounce.think(round, frog, 16, steady);
|
||||
assert.equal(frog.air, 0, "no hop");
|
||||
assert.equal(frog.gain, 0, "no steering");
|
||||
for (let ms = 0; ms < bounce.ZAP_MS + 100; ms += 16) bounce.think(round, frog, 16, steady);
|
||||
assert.equal(frog.zapMs, 0, "it wears off");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a Magnet pulls in the stars and power-ups within MAGNET_R, in the air too, for MAGNET_MS", () => {
|
||||
const { round, you } = onPlain(7, 60);
|
||||
const road = round.road;
|
||||
road.stars.length = 0;
|
||||
road.items.length = 0;
|
||||
const star = { x: you.x + bounce.MAGNET_R - 2, d: you.d + 4, taken: false };
|
||||
const item = { x: you.x - bounce.MAGNET_R + 2, d: you.d + 6, kind: "bubble", taken: false };
|
||||
road.stars.push(star);
|
||||
road.items.push(item);
|
||||
bounce.advance(round, 8, steady);
|
||||
assert.ok(!star.taken && !item.taken, "out of reach without one");
|
||||
bounce.applyPower(round, "magnet");
|
||||
Object.assign(you, { air: 300, airMax: 600 });
|
||||
bounce.advance(round, 8, steady);
|
||||
assert.ok(star.taken && item.taken && you.bubble, "pulled in");
|
||||
for (let ms = 0; ms < bounce.MAGNET_MS + 100; ms += 4) bounce.move(round, you, 4);
|
||||
assert.equal(you.magnetMs, 0, "it runs out");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------- fever, lives, rank */
|
||||
|
||||
test("Bounce Road arcade: stunts fill the Fever; full, it burns for FEVER_MS with every point doubled and a touch flattening a rival; a life lost puts it out", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
const need = Math.ceil(bounce.FEVER_FULL / bounce.FEVER_GAIN);
|
||||
for (let k = 0; k < need - 1; k++) bounce.stunt(round, 10);
|
||||
assert.equal(round.feverMs, 0, "not yet");
|
||||
assert.ok(round.fever > bounce.FEVER_FULL * 0.9);
|
||||
bounce.stunt(round, 10);
|
||||
assert.equal(round.feverMs, bounce.FEVER_MS, "lit");
|
||||
assert.equal(eventsOf(round, "fever").length, 1);
|
||||
assert.equal(bounce.stunt(round, 10), 10 * bounce.MAX_COMBO * 2, "double points");
|
||||
const zig = bounceRival(round, "zigzag", at.x + 4, at.d + 1);
|
||||
assert.equal(bounce.collide(round, you, zig), "mega");
|
||||
assert.equal(zig.outKind, "flat", "a touch flattens");
|
||||
assert.ok(eventsOf(round, "crush").at(-1).fever);
|
||||
const spike = bounceRival(round, "spike", at.x, at.d + 40);
|
||||
landOn(round, spike);
|
||||
assert.equal(spike.outKind, "flat", "even a Spike, from above");
|
||||
you.air = 0;
|
||||
bounce.advance(round, bounce.FEVER_MS + 50, steady);
|
||||
assert.equal(round.feverMs, 0);
|
||||
assert.equal(round.fever, 0, "burnt out");
|
||||
assert.equal(eventsOf(round, "feverEnd").length, 1);
|
||||
for (let k = 0; k < 10; k++) bounce.stunt(round, 10);
|
||||
const held = round.fever;
|
||||
bounce.lose(round, "crash");
|
||||
assert.equal(round.fever, Math.floor(held / 2), "a life lost halves the meter");
|
||||
const r2 = onPlain(7, 60).round;
|
||||
bounce.startFever(r2);
|
||||
bounce.lose(r2, "crash");
|
||||
assert.ok(r2.feverMs === 0 && r2.fever === 0, "and puts a Fever out");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: every LIFE_SCORE points is a life, up to MAX_LIVES", () => {
|
||||
const { round } = onPlain();
|
||||
round.lives = 2;
|
||||
round.score = bounce.LIFE_SCORE - 1;
|
||||
bounce.advance(round, 8, steady);
|
||||
assert.equal(round.lives, 2);
|
||||
round.score = bounce.LIFE_SCORE + 5;
|
||||
bounce.advance(round, 8, steady);
|
||||
assert.equal(round.lives, 3);
|
||||
assert.equal(eventsOf(round, "life").length, 1);
|
||||
bounce.advance(round, 200, steady);
|
||||
assert.equal(round.lives, 3, "once a mark");
|
||||
round.lives = bounce.MAX_LIVES;
|
||||
round.score = bounce.LIFE_SCORE * 2 + 5;
|
||||
bounce.advance(round, 8, steady);
|
||||
assert.equal(round.lives, bounce.MAX_LIVES);
|
||||
assert.equal(round.lifeAt, bounce.LIFE_SCORE * 3, "the mark still moves on");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a stage line ranks the stage: C for a slow run with a life lost, A for a flawless run under par, S with a combo of three on top", () => {
|
||||
const cross = (setup) => {
|
||||
const round = bounceRound(7);
|
||||
const road = round.road;
|
||||
const you = round.cars[0];
|
||||
const d = road.stageAt[1] - 0.5;
|
||||
Object.assign(you, { d, x: (road.L[bounce.rowOf(d)] + road.R[bounce.rowOf(d)]) / 2, v: 40 });
|
||||
setup(round);
|
||||
bounce.advance(round, 60, steady);
|
||||
assert.equal(round.stage, 2);
|
||||
return eventsOf(round, "stage")[0].rank;
|
||||
};
|
||||
assert.equal(cross((r) => { r.stageLost = true; r.clock = 500000; }), "C");
|
||||
assert.equal(cross((r) => { r.clock = 500000; }), "B", "flawless but slow");
|
||||
assert.equal(cross(() => {}), "A");
|
||||
assert.equal(cross((r) => { r.stageCombo = 3; }), "S");
|
||||
const round = bounceRound(7);
|
||||
assert.deepEqual(round.ranks, []);
|
||||
});
|
||||
|
||||
/* --------------------------------------------- new things on the road */
|
||||
|
||||
test("Bounce Road arcade: a conveyor carries you across at BELT_PUSH, a spring pad throws you up POP_AIR the usual jump, and a bumper kicks you away for points, never a life", () => {
|
||||
const round = bounceRound(9);
|
||||
const belt = onto(round, "pads", (p) => p.kind === "belt", 0);
|
||||
const you = round.cars[0];
|
||||
const x0 = you.x;
|
||||
for (let ms = 0; ms < 400; ms += 4) bounce.advance(round, 4, steady);
|
||||
assert.ok((you.x - x0) * belt.dir > bounce.BELT_PUSH * 0.3, `carried ${belt.dir > 0 ? "right" : "left"} (${(you.x - x0).toFixed(1)})`);
|
||||
assert.equal(eventsOf(round, "belt").length, 1);
|
||||
const r2 = bounceRound(9);
|
||||
const pop = onto(r2, "pads", (p) => p.kind === "pop", 5);
|
||||
const y2 = r2.cars[0];
|
||||
y2.v = 50;
|
||||
for (let ms = 0; ms < 300 && y2.air <= 0; ms += 4) bounce.advance(r2, 4, steady);
|
||||
assert.ok(y2.air > 0, "thrown up");
|
||||
assert.ok(Math.abs(y2.airMax - bounce.airMs(y2.v) * bounce.POP_AIR) < 30, "POP_AIR the usual jump");
|
||||
assert.ok(y2.ramped, "big air to land");
|
||||
assert.equal(eventsOf(r2, "pop").length, 1);
|
||||
assert.ok(pop.w > bounce.CAR_W);
|
||||
const r3 = bounceRound(9);
|
||||
const bumper = onto(r3, "blocks", (b) => b.kind === "bumper", 6);
|
||||
const y3 = r3.cars[0];
|
||||
y3.x = bumper.x - 1;
|
||||
const before = r3.score;
|
||||
for (let ms = 0; ms < 400; ms += 4) bounce.advance(r3, 4, steady);
|
||||
const [hit] = eventsOf(r3, "bumper");
|
||||
assert.ok(hit, "it rings");
|
||||
assert.equal(hit.points, bounce.BUMPER_POINTS);
|
||||
assert.ok(r3.score >= before + bounce.BUMPER_POINTS);
|
||||
assert.equal(r3.lives, bounce.START_LIVES, "no life");
|
||||
assert.equal(bumper.hit, 0, "and it stays where it is");
|
||||
assert.ok(y3.x < bumper.x, "kicked to its side");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a laser is a crash while its beam is on and nothing while it is off, and a car in the air goes over it for points", () => {
|
||||
const through = (cycle, air) => {
|
||||
const round = bounceRound(3);
|
||||
const h = onto(round, "hazards", (e) => e.kind === "laser", 2);
|
||||
const you = round.cars[0];
|
||||
cycleTo(round, h, cycle(h));
|
||||
if (air) Object.assign(you, { air: 500, airMax: 600, jumpFrom: you.d });
|
||||
for (let ms = 0; ms < 240; ms += 4) bounce.advance(round, 4, steady);
|
||||
return { round, you, h };
|
||||
};
|
||||
const on = through(() => 10, false);
|
||||
assert.equal(on.round.phase, "crash");
|
||||
assert.equal(eventsOf(on.round, "lose")[0].cause, "laser");
|
||||
const off = through((h) => h.onMs + 200, false);
|
||||
assert.equal(off.round.phase, "drive", "off, it is nothing");
|
||||
assert.ok(off.you.d > off.h.d);
|
||||
const over = through(() => 10, true);
|
||||
assert.equal(over.round.phase, "drive", "over it in the air");
|
||||
assert.ok(over.you.overs.includes(over.h), "to score on landing");
|
||||
const lz = bounce.laserAt(on.h, on.h.period * 5 - (on.h.phase % on.h.period) - 100);
|
||||
assert.ok(lz.warn && !lz.on, "its posts blink before it comes on");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a stomper squashes what is under it as it lands, is a block while it is down, and lets you by while it is up", () => {
|
||||
const under = (at, place) => {
|
||||
const round = bounceRound(3);
|
||||
const h = onto(round, "hazards", (e) => e.kind === "stomper", 0);
|
||||
const you = round.cars[0];
|
||||
place(you, h);
|
||||
cycleTo(round, h, at(h));
|
||||
bounce.advance(round, 60, steady);
|
||||
return { round, h, you };
|
||||
};
|
||||
const hit = under((h) => h.period - 20, (you, h) => Object.assign(you, { x: h.x, d: h.d - 1, v: 16 }));
|
||||
assert.equal(hit.round.phase, "crash");
|
||||
assert.equal(eventsOf(hit.round, "lose")[0].cause, "squash");
|
||||
assert.equal(eventsOf(hit.round, "stompLand").length, 1);
|
||||
const wall = under(() => bounce.STOMP_HIT_MS + 60, (you, h) => Object.assign(you, { x: h.x, d: h.d - h.l / 2 - you.l / 2 - 0.6, v: 40, pnose: h.d - h.l / 2 - 0.6 }));
|
||||
assert.equal(wall.round.phase, "crash", "nose first into it while it is down");
|
||||
assert.equal(eventsOf(wall.round, "lose")[0].cause, "crash");
|
||||
const clear = under((h) => h.downMs + 150, (you, h) => Object.assign(you, { x: h.x, d: h.d - 3, v: 40 }));
|
||||
assert.equal(clear.round.phase, "drive", "up, it lets you by");
|
||||
const st = bounce.stomperAt(hit.h, hit.h.period * 4 - (hit.h.phase % hit.h.period) - bounce.STOMP_WARN_MS / 2);
|
||||
assert.ok(st.fall > 0.3 && st.fall < 0.7 && !st.down, "its shadow grows before it lands");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a roller is a crash to drive into and points to jump", () => {
|
||||
const round = bounceRound(3);
|
||||
const h = onto(round, "hazards", (e) => e.kind === "roller", 1);
|
||||
const you = round.cars[0];
|
||||
you.x = bounce.ballX(h, round.clock);
|
||||
bounce.advance(round, 40, steady);
|
||||
assert.equal(round.phase, "crash");
|
||||
const r2 = bounceRound(3);
|
||||
const h2 = onto(r2, "hazards", (e) => e.kind === "roller", 1);
|
||||
const y2 = r2.cars[0];
|
||||
Object.assign(y2, { x: bounce.ballX(h2, r2.clock), air: 300, airMax: 600, jumpFrom: y2.d });
|
||||
bounce.advance(r2, 40, steady);
|
||||
assert.equal(r2.phase, "drive");
|
||||
assert.ok(y2.overs.includes(h2), "jumped");
|
||||
assert.ok(h2.half > h2.r * 2, "long across the road, thin along it");
|
||||
});
|
||||
|
||||
/* --------------------------------------------- the rivals with a trick */
|
||||
|
||||
test("Bounce Road arcade: a Spike's roof costs a life and its side is a plain bump, a Splitter flattened bursts into two Minis, and the Supply truck's roof hands over a gadget once", () => {
|
||||
const a = onPlain(7, 60);
|
||||
const spike = bounceRival(a.round, "spike", a.at.x, a.at.d + 40);
|
||||
landOn(a.round, spike);
|
||||
assert.equal(a.round.phase, "crash");
|
||||
assert.equal(eventsOf(a.round, "lose")[0].cause, "spike");
|
||||
assert.equal(spike.out, 0, "it drives on");
|
||||
const b = onPlain(7, 60);
|
||||
const spike2 = bounceRival(b.round, "spike", b.at.x + 4.3, b.at.d + 1);
|
||||
assert.equal(bounce.collide(b.round, b.you, spike2), "side");
|
||||
assert.equal(b.round.phase, "drive");
|
||||
const splitter = bounceRival(b.round, "splitter", b.at.x, b.at.d + 60);
|
||||
landOn(b.round, splitter);
|
||||
assert.equal(splitter.outKind, "flat");
|
||||
const minis = b.round.cars.filter((c) => c.kind === "mini");
|
||||
assert.equal(minis.length, 2, "two Minis");
|
||||
assert.ok(minis[0].x < splitter.x && minis[1].x > splitter.x && minis.every((m) => m.v > splitter.v), "one either side, off up the road");
|
||||
assert.equal(eventsOf(b.round, "split").length, 1);
|
||||
const c = onPlain(7, 60);
|
||||
const truck = bounceRival(c.round, "supply", c.at.x, c.at.d + 40);
|
||||
landOn(c.round, truck);
|
||||
assert.ok(c.you.held && bounce.GADGETS.includes(c.you.held.kind), "a gadget");
|
||||
assert.ok(truck.gave && truck.out === 0);
|
||||
assert.equal(eventsOf(c.round, "haul").length, 1, "its roof is a trampoline");
|
||||
c.you.held = null;
|
||||
c.you.air = 0;
|
||||
landOn(c.round, truck);
|
||||
assert.equal(c.you.held, null, "once");
|
||||
assert.ok(bounce.RIVALS.supply.friend && bounce.RIVALS.spike.spiky);
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a Blaster glows, then fires a bolt back down the road that knocks and slows you without a life; in the air it passes under you", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const blaster = bounceRival(round, "blaster", at.x, at.d + 40, { dropIn: 0, v: 40, tv: 40, mode: "" });
|
||||
let aimed = 0;
|
||||
for (let ms = 0; ms < 3000 && !eventsOf(round, "shot").length; ms += 4) {
|
||||
bounce.advance(round, 4, steady);
|
||||
if (blaster.aimMs > 0) aimed += 4;
|
||||
}
|
||||
assert.equal(eventsOf(round, "aim").length >= 1, true, "it takes aim");
|
||||
assert.ok(aimed >= bounce.AIM_MS - 12, `for AIM_MS (${aimed})`);
|
||||
assert.ok(eventsOf(round, "bolt").length >= 1, "and fires");
|
||||
assert.equal(eventsOf(round, "shot").length, 1, "the bolt finds you");
|
||||
assert.equal(round.lives, bounce.START_LIVES, "no life");
|
||||
assert.ok(Math.abs(you.kx) > 5 && you.slickMs > 0, "knocked, and sliding");
|
||||
const r2 = onPlain(11, 90);
|
||||
r2.round.bolts.push({ x: r2.you.x, d: r2.you.d + 4, v: -bounce.BOLT_SPEED });
|
||||
Object.assign(r2.you, { air: 400, airMax: 600 });
|
||||
bounce.advance(r2.round, 300, steady);
|
||||
assert.equal(eventsOf(r2.round, "shot").length, 0, "under a car in the air");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a Slasher alongside glints, then its blades come out and its side is a crash; with them in it is a plain bump", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
const slasher = bounceRival(round, "slasher", at.x + 6, at.d, { mode: "chase", v: 40, tv: 40, offside: 1 });
|
||||
bounce.think(round, slasher, 16, steady);
|
||||
assert.equal(slasher.blade, "warn", "a glint first");
|
||||
assert.equal(eventsOf(round, "blade").length, 1);
|
||||
for (let ms = 0; ms <= bounce.BLADE_WARN_MS; ms += 16) bounce.think(round, slasher, 16, steady);
|
||||
assert.equal(slasher.blade, "out");
|
||||
slasher.x = you.x + 4.1;
|
||||
slasher.d = you.d;
|
||||
assert.equal(bounce.collide(round, you, slasher), "side");
|
||||
assert.equal(round.phase, "crash");
|
||||
assert.equal(eventsOf(round, "lose")[0].cause, "slash");
|
||||
const r2 = onPlain(7, 60);
|
||||
const calm = bounceRival(r2.round, "slasher", r2.at.x + 4.1, r2.at.d, { blade: "" });
|
||||
bounce.collide(r2.round, r2.you, calm);
|
||||
assert.equal(r2.round.phase, "drive", "blades in: a bump");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a Bomber drops a bomb while you follow, which blows BOMB_FUSE_MS on: a life for a car on the ground within BOMB_R, nothing for one clear of it", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const bomber = bounceRival(round, "bomber", at.x, at.d + 50, { dropIn: 0, v: 40, tv: 40, mode: "" });
|
||||
bounce.think(round, bomber, 16, steady);
|
||||
assert.equal(round.bombs.length, 1, "a bomb on the road");
|
||||
assert.equal(eventsOf(round, "bomb").length, 1);
|
||||
assert.equal(round.bombs[0].at, round.clock + bounce.BOMB_FUSE_MS);
|
||||
round.bombs.length = 0;
|
||||
bomber.out = 1;
|
||||
bomber.outKind = "gone";
|
||||
round.bombs.push({ x: you.x + bounce.BOMB_R + you.w, d: you.d + 3, at: round.clock + 40, t0: round.clock, r: bounce.BOMB_R });
|
||||
bounce.advance(round, 80, steady);
|
||||
assert.equal(eventsOf(round, "boom").length, 1);
|
||||
assert.equal(round.phase, "drive", "clear of the blast");
|
||||
round.bombs.push({ x: you.x + 2, d: you.d + 4, at: round.clock + 40, t0: round.clock, r: bounce.BOMB_R });
|
||||
bounce.advance(round, 80, steady);
|
||||
assert.equal(round.phase, "crash");
|
||||
assert.equal(eventsOf(round, "lose")[0].cause, "blast");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a Phantom out of reach cannot be bumped or landed on; a Magnet rival drags you toward it while it is near", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
const phantom = bounceRival(round, "phantom", at.x + 3, at.d, { phased: true });
|
||||
bounce.advance(round, 16, steady);
|
||||
assert.equal(eventsOf(round, "bump").length, 0, "nothing to bump");
|
||||
landOn(round, phantom);
|
||||
assert.equal(phantom.out, 0, "nothing to land on");
|
||||
phantom.phased = false;
|
||||
you.air = 0;
|
||||
Object.assign(phantom, { x: you.x + 3, d: you.d });
|
||||
bounce.advance(round, 16, steady);
|
||||
assert.ok(eventsOf(round, "bump").length > 0, "solid again");
|
||||
const m = onPlain(7, 60);
|
||||
const magnet = bounceRival(m.round, "magnet", m.at.x + 12, m.at.d + 4, { mode: "", v: 40, tv: 40 });
|
||||
for (let ms = 0; ms < 300; ms += 4) bounce.advance(m.round, 4, steady);
|
||||
assert.ok(m.you.kx > 3, `dragged toward it (${m.you.kx.toFixed(1)})`);
|
||||
assert.ok(eventsOf(m.round, "magnet").length >= 1);
|
||||
assert.ok(magnet.pulling);
|
||||
const calm = onPlain(7, 60);
|
||||
bounceRival(calm.round, "magnet", calm.at.x + 12, calm.at.d + bounce.MAG_RANGE + 30, { mode: "" });
|
||||
bounce.advance(calm.round, 100, steady);
|
||||
assert.equal(calm.you.kx, 0, "too far to pull");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ bosses */
|
||||
|
||||
test("Bounce Road arcade: each boss comes in its own arena with its own hp, more of it each lap, and is named as it comes", () => {
|
||||
for (const [k, kind] of bounce.BOSS_ORDER.entries()) {
|
||||
const stage = (k + 1) * bounce.WORLD;
|
||||
assert.equal(bounce.stageFor(stage).boss, kind);
|
||||
const round = bounceRound(4);
|
||||
const road = round.road;
|
||||
bounce.ensureRoad(road, 40000);
|
||||
round.stage = stage;
|
||||
const at = plainSpot(road, road.stageAt[stage - 1] + bounce.stageFor(stage).len * 0.2, 30);
|
||||
Object.assign(round.cars[0], { x: at.x, d: at.d, v: 40 });
|
||||
bounce.advance(round, 16, steady);
|
||||
const boss = round.cars.find((c) => c.kind === kind);
|
||||
assert.ok(boss, `the ${kind} is out`);
|
||||
assert.equal(boss.hp, bounce.RIVALS[kind].hp);
|
||||
assert.ok(bounce.isBoss(boss) && bounce.RIVALS[kind].hint, "with a word on how to beat it");
|
||||
assert.ok(eventsOf(round, "spawn").some((e) => e.kind === kind));
|
||||
bounce.advance(round, 400, steady);
|
||||
assert.equal(round.cars.filter((c) => c.kind === kind).length, 1, "once a stage");
|
||||
}
|
||||
assert.deepEqual([...bounce.BOSS_KINDS].sort(), [...bounce.BOSS_ORDER].sort());
|
||||
const lap2 = bounceRound(4);
|
||||
bounce.ensureRoad(lap2.road, 90000);
|
||||
lap2.stage = 18;
|
||||
const at = plainSpot(lap2.road, lap2.road.stageAt[17] + bounce.stageFor(18).len * 0.2, 30);
|
||||
Object.assign(lap2.cars[0], { x: at.x, d: at.d, v: 40 });
|
||||
bounce.advance(lap2, 16, steady);
|
||||
const again = lap2.cars.find((c) => bounce.isBoss(c));
|
||||
assert.equal(again.hp, bounce.RIVALS[again.kind].hp + 1, "one more hp on the second lap");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: any boss is beaten by landings, rockets or a ground pound: its last hp is BOSS_POINTS, a life, a trophy and a Fever", () => {
|
||||
for (const kind of bounce.BOSS_ORDER) {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
round.lives = 2;
|
||||
const boss = bounceRival(round, kind, at.x, at.d + 30, { hp: 3, lift: 0, high: false, mode: kind === "chopper" ? "low" : "calm", modeMs: 1e9 });
|
||||
landOn(round, boss);
|
||||
assert.equal(boss.hp, 2, `${kind}: a landing`);
|
||||
assert.ok(boss.stunMs > 0, "and it reels");
|
||||
you.air = 0;
|
||||
assert.equal(bounce.hurtBoss(round, boss, "rocket"), "stomp");
|
||||
assert.equal(boss.hp, 1, "a rocket");
|
||||
assert.equal(bounce.hurtBoss(round, boss, "pound"), "boss");
|
||||
assert.equal(boss.outKind, "flat");
|
||||
const [beat] = eventsOf(round, "boss");
|
||||
assert.equal(beat.kind, kind);
|
||||
assert.ok(beat.points >= bounce.BOSS_POINTS && beat.life);
|
||||
assert.equal(round.lives, 3);
|
||||
assert.equal(round.trophies, 1 << bounce.BOSS_ORDER.indexOf(kind), "its trophy");
|
||||
assert.ok(round.feverMs > 0, "and a Fever");
|
||||
assert.equal(bounce.hurtBoss(round, boss, "rocket"), "", "nothing more from a beaten boss");
|
||||
}
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: the Big Rig lobs a barrel at where you are heading, which lands LOB_MS on as a block and squashes what is under it", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const rig = bounceRival(round, "tanker", at.x, at.d + bounce.TANKER_AHEAD, { dropIn: 0, v: 40, tv: 40, mode: "", hp: 4 });
|
||||
bounce.think(round, rig, 16, steady);
|
||||
assert.equal(round.lobs.length, 1);
|
||||
const lob = round.lobs[0];
|
||||
assert.equal(lob.what, "barrel");
|
||||
assert.equal(lob.at, round.clock + bounce.LOB_MS);
|
||||
assert.ok(lob.d > you.d + 20 && lob.d < rig.d, "ahead of you, short of the truck");
|
||||
assert.equal(eventsOf(round, "lob").length, 1);
|
||||
assert.ok(bounce.underBanner(round, bounce.FIELD_H - (lob.d - (you.d - 18)), you.d - 18), "a banner gives way to it");
|
||||
rig.dropIn = 1e9;
|
||||
// Keep still: it lands ahead of you and lies there.
|
||||
you.v = 16;
|
||||
round.input.down = true;
|
||||
bounce.advance(round, bounce.LOB_MS + 20, steady);
|
||||
assert.equal(round.lobs.length, 0);
|
||||
assert.ok(round.drops.some((b) => b.what === "barrel" && b.kind === "block"), "a block on the road");
|
||||
assert.equal(round.phase, "drive");
|
||||
// Under it as it lands.
|
||||
const r2 = onPlain(11, 90);
|
||||
r2.round.lobs.push({ x: r2.you.x, d: r2.you.d + 1, at: r2.round.clock + 8, what: "barrel", boom: 0, w: 4.4, l: 4.4, fx: 0, fd: 0 });
|
||||
bounce.advance(r2.round, 16, steady);
|
||||
assert.equal(eventsOf(r2.round, "lose")[0].cause, "squash");
|
||||
// Now and then it brake-checks: back it comes, its roof in reach.
|
||||
const r4 = onPlain(11, 90);
|
||||
r4.you.v = 60;
|
||||
const rig4 = bounceRival(r4.round, "tanker", r4.at.x, r4.at.d + bounce.TANKER_AHEAD, { brakeIn: 0, v: 60, tv: 60, mode: "", hp: 4 });
|
||||
bounce.think(r4.round, rig4, 16, steady);
|
||||
assert.equal(rig4.mode, "brake");
|
||||
assert.ok(eventsOf(r4.round, "brake").some((e) => e.kind === "tanker"));
|
||||
bounce.think(r4.round, rig4, 16, steady);
|
||||
assert.ok(rig4.tv < r4.you.v - 20, "slower than you, so a jump can reach it");
|
||||
assert.equal(r4.round.lobs.length, 0, "and nothing thrown while it brakes");
|
||||
for (let ms = 0; ms <= bounce.TANKER_BRAKE_MS + 32; ms += 16) bounce.think(r4.round, rig4, 16, steady);
|
||||
assert.equal(rig4.mode, "", "then off it goes again");
|
||||
// Every third thing it drops is oil.
|
||||
const r3 = onPlain(11, 90);
|
||||
const rig3 = bounceRival(r3.round, "tanker", r3.at.x, r3.at.d + bounce.TANKER_AHEAD, { dropIn: 0, drops: 2, v: 40, tv: 40, mode: "", hp: 4 });
|
||||
bounce.think(r3.round, rig3, 16, steady);
|
||||
assert.ok(r3.round.spills.length === 1 && r3.round.spills[0].foe, "an oil spill behind it");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: the Robo-Vac sweeps from edge to edge, warns, then charges back down the road: its nose is a crash, its top a stomp, and it goes back up the road through you", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const vac = bounceRival(round, "vac", at.x, at.d + bounce.VAC_AHEAD, { mode: "sweep", hopIn: 0, v: 40, tv: 40, hp: 4 });
|
||||
bounce.think(round, vac, 16, steady);
|
||||
assert.equal(vac.mode, "warn");
|
||||
assert.ok(eventsOf(round, "bossWarn").some((e) => e.kind === "vac"));
|
||||
for (let ms = 0; ms <= bounce.VAC_WARN_MS + 16; ms += 16) bounce.think(round, vac, 16, steady);
|
||||
assert.equal(vac.mode, "charge");
|
||||
assert.equal(eventsOf(round, "bossCharge").length, 1);
|
||||
assert.ok(vac.tv < you.v - 20, "coming back at you");
|
||||
// Its nose.
|
||||
Object.assign(vac, { x: you.x, d: you.d + (you.l + vac.l) / 2 - 0.2, v: vac.tv });
|
||||
assert.equal(bounce.collide(round, you, vac), "end");
|
||||
assert.equal(round.phase, "crash");
|
||||
// Its top.
|
||||
const r2 = onPlain(11, 90);
|
||||
const vac2 = bounceRival(r2.round, "vac", r2.at.x, r2.at.d + 20, { mode: "charge", hp: 4 });
|
||||
landOn(r2.round, vac2);
|
||||
assert.equal(vac2.hp, 3, "a stomp");
|
||||
bounce.think(r2.round, vac2, 16, steady);
|
||||
assert.equal(vac2.mode, "back");
|
||||
// On its way back up the road it passes through you.
|
||||
r2.you.air = 0;
|
||||
Object.assign(vac2, { x: r2.you.x, d: r2.you.d - 2, stunMs: 0 });
|
||||
bounce.think(r2.round, vac2, 16, steady);
|
||||
assert.ok(vac2.thru, "through anything");
|
||||
r2.round.events.length = 0;
|
||||
bounce.advance(r2.round, 16, steady);
|
||||
assert.equal(eventsOf(r2.round, "bump").length, 0);
|
||||
assert.equal(r2.round.phase, "drive");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: the Whirlybird flies out of reach and bombs where you are heading, then swoops down to the road where a landing is a stomp", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const bird = bounceRival(round, "chopper", at.x, at.d + bounce.CHOPPER_AHEAD, { mode: "high", lift: 1, high: true, dropIn: 0, hopIn: 1e9, v: 40, tv: 40, hp: 4 });
|
||||
bounce.think(round, bird, 16, steady);
|
||||
assert.equal(round.lobs.length, 1);
|
||||
assert.ok(round.lobs[0].boom > 0 && round.lobs[0].what === "bomb", "a bomb on its way");
|
||||
round.lobs.length = 0;
|
||||
bird.dropIn = 1e9;
|
||||
landOn(round, bird);
|
||||
assert.equal(bird.hp, 4, "out of reach up high");
|
||||
assert.equal(round.phase, "drive");
|
||||
you.air = 0;
|
||||
Object.assign(bird, { x: you.x, d: you.d });
|
||||
bounce.advance(round, 16, steady);
|
||||
assert.equal(eventsOf(round, "bump").length, 0, "nothing to bump up there");
|
||||
bird.d = you.d + bounce.CHOPPER_AHEAD;
|
||||
bird.hopIn = 0;
|
||||
bounce.think(round, bird, 16, steady);
|
||||
assert.equal(bird.mode, "low");
|
||||
assert.ok(eventsOf(round, "bossWarn").some((e) => e.kind === "chopper"));
|
||||
for (let ms = 0; ms < 600; ms += 16) bounce.think(round, bird, 16, steady);
|
||||
assert.ok(bird.lift === 0 && !bird.high, "down on the road");
|
||||
assert.ok(bird.tv < you.v, "drifting back to you, so a jump can reach it");
|
||||
landOn(round, bird);
|
||||
assert.equal(bird.hp, 3, "a stomp");
|
||||
bounce.think(round, bird, 16, steady);
|
||||
assert.equal(bird.mode, "high", "and up it goes");
|
||||
// A bomb landing on you.
|
||||
const r2 = onPlain(11, 90);
|
||||
r2.round.lobs.push({ x: r2.you.x + 2, d: r2.you.d + 2, at: r2.round.clock + 8, what: "bomb", boom: bounce.LOB_R, w: 4, l: 4, fx: 0, fd: 0 });
|
||||
bounce.advance(r2.round, 16, steady);
|
||||
assert.equal(eventsOf(r2.round, "lose")[0].cause, "blast");
|
||||
assert.equal(r2.round.drops.length, 0, "nothing left lying");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: the Cat's paw slams down with a quake, then sweeps across the road, there to be jumped on", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const cat = bounceRival(round, "cat", at.x - 8, at.d + 24, { mode: "stalk", hopIn: 0, v: 40, tv: 40, hp: 6 });
|
||||
bounce.think(round, cat, 16, steady);
|
||||
assert.ok(cat.air > 0, "up it goes");
|
||||
assert.equal(eventsOf(round, "bossHop").length, 1);
|
||||
for (let ms = 0; ms < 1400 && cat.mode !== "swipe"; ms += 4) {
|
||||
bounce.think(round, cat, 4, steady);
|
||||
bounce.move(round, cat, 4);
|
||||
}
|
||||
assert.equal(cat.mode, "swipe", "then it sweeps");
|
||||
assert.equal(eventsOf(round, "quake").length, 1);
|
||||
assert.equal(eventsOf(round, "swipe").length, 1);
|
||||
const x0 = cat.x;
|
||||
for (let ms = 0; ms < 600; ms += 4) {
|
||||
bounce.think(round, cat, 4, steady);
|
||||
bounce.move(round, cat, 4);
|
||||
}
|
||||
assert.ok(Math.abs(cat.x - x0) > 8, `across the road (${(cat.x - x0).toFixed(1)})`);
|
||||
for (let ms = 0; ms < bounce.CAT_SWIPE_MS; ms += 16) bounce.think(round, cat, 16, steady);
|
||||
assert.equal(cat.mode, "stalk", "and back to stalking");
|
||||
you.air = 0;
|
||||
cat.air = 0;
|
||||
landOn(round, cat);
|
||||
assert.equal(cat.hp, 5, "a stomp");
|
||||
});
|
||||
|
||||
/* ------------------------------------------- the double tap, the music */
|
||||
|
||||
test("Bounce Road arcade game: the first press of space jumps at once; a second within DOUBLE_TAP_MS sets off the gadget held, a slower one or a key repeat never does", () => {
|
||||
const g = game.create({ canvas: stubCanvas() });
|
||||
g.resize(900, 900);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
const round = g.round;
|
||||
round.cars.length = 1;
|
||||
round.spawnMs = 1e12;
|
||||
round.supplyMs = 1e12;
|
||||
const you = round.cars[0];
|
||||
const at = plainSpot(round.road, 80, 60);
|
||||
Object.assign(you, { x: at.x, d: at.d, v: 40 });
|
||||
const settle = () => {
|
||||
for (let ms = 0; ms < 1200; ms += 16) {
|
||||
Object.assign(you, { x: at.x, d: at.d, v: 40 });
|
||||
g.tick(16);
|
||||
}
|
||||
you.air = 0;
|
||||
};
|
||||
bounce.applyPower(round, "rocket");
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.ok(you.air > 0, "the first press jumps, with no wait");
|
||||
assert.equal(round.stats.fired, 0);
|
||||
g.tick(64);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1, "the second fires");
|
||||
assert.equal(you.held.uses, 2);
|
||||
// A third press right after is a first press again.
|
||||
g.tick(64);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1);
|
||||
settle();
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
g.tick(bounce.DOUBLE_TAP_MS + 40);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1, "too slow to be a double tap");
|
||||
settle();
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
g.key("action", true);
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1, "a held key's repeat never fires");
|
||||
settle();
|
||||
you.held = null;
|
||||
g.key("action");
|
||||
g.tick(32);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1, "nothing held, nothing to fire");
|
||||
assert.equal(round.input.fire, false);
|
||||
bounce.applyPower(round, "oil");
|
||||
settle();
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
g.pause();
|
||||
g.resume();
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1, "a pause forgets the first press");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade game: a run shuffles its stages; the music deals every track, never opening on the last one, and the game asks for one each tick, hotter in a Fever", () => {
|
||||
assert.equal(bounce.MUSIC_TRACKS.length, 20);
|
||||
for (let k = 0; k < 40; k++) {
|
||||
const last = bounce.MUSIC_TRACKS[k % 20];
|
||||
const deck = bounce.dealMusic(Math.random, last);
|
||||
assert.deepEqual([...deck].sort(), [...bounce.MUSIC_TRACKS].sort());
|
||||
assert.notEqual(deck[0], last);
|
||||
}
|
||||
const asked = [];
|
||||
const heats = [];
|
||||
const g = game.create({ canvas: stubCanvas(), music: (name, level, opts) => { asked.push([name, opts]); heats.push(level); return "playing"; } });
|
||||
g.resize(900, 900);
|
||||
g.key("action");
|
||||
assert.equal(g.round.road.shuffle, true, "a real round shuffles");
|
||||
g.tick(16);
|
||||
g.tick(16);
|
||||
assert.equal(asked.length, 2);
|
||||
assert.ok(bounce.MUSIC_TRACKS.includes(asked[0][0]));
|
||||
assert.deepEqual(asked[0][1], { restart: true }, "from the top");
|
||||
assert.equal(asked[1][1], undefined);
|
||||
assert.deepEqual(heats, [bounce.MUSIC_HEAT.road, bounce.MUSIC_HEAT.road], "the open road's heat");
|
||||
g.round.feverMs = 5000;
|
||||
g.tick(16);
|
||||
assert.equal(heats.at(-1), bounce.MUSIC_HEAT.fever, "a Fever plays it at full heat");
|
||||
assert.ok(bounce.MUSIC_HEAT.road < bounce.MUSIC_HEAT.boss && bounce.MUSIC_HEAT.boss < bounce.MUSIC_HEAT.fever);
|
||||
const ended = [];
|
||||
const g2 = game.create({ canvas: stubCanvas(), music: (name) => { ended.push(name); return "ended"; } });
|
||||
g2.resize(900, 900);
|
||||
g2.key("action");
|
||||
for (let k = 0; k < 30; k++) g2.tick(16);
|
||||
assert.deepEqual([...new Set(ended.slice(0, 20))].sort(), [...bounce.MUSIC_TRACKS].sort(), "every track once, in a random order");
|
||||
assert.notEqual(ended[20], ended[19], "a new deal never opens on the track that just ended");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade music: twenty synthesized tracks, each fast, a whole tune in whole bars, with an echo for a boss and a harmony for a Fever", () => {
|
||||
assert.deepEqual(Object.keys(BOUNCE_MUSIC).sort(), [...bounce.MUSIC_TRACKS].sort(), "the game lists the tracks its music file has");
|
||||
assert.equal(SCORES.length, 20);
|
||||
assert.equal(new Set(SCORES.map((s) => s.title)).size, 20, "twenty titles");
|
||||
assert.equal(new Set(SCORES.map((s) => s.A.lead + s.B.lead)).size, 20, "twenty tunes");
|
||||
const stepsOf = (line) => line.split(/\s+/).filter((t) => t !== "|").length;
|
||||
SCORES.forEach((score, k) => {
|
||||
const track = BOUNCE_MUSIC[`bounceSong${k + 1}`];
|
||||
assert.ok(track.bpm >= 140 && track.bpm <= 180, `${score.title} is fast`);
|
||||
assert.ok(track.rush > 0, "and faster as play heats up");
|
||||
for (const part of [score.A, score.B]) {
|
||||
const bars = part.lead.split(/\s+/);
|
||||
assert.equal(bars.length, 8, `${score.title}: eight bars a tune`);
|
||||
for (const bar of bars) assert.match(bar, /^[A-Ga-g1-7.\-]{16}$/, `${score.title}: a bar is sixteen steps`);
|
||||
}
|
||||
for (const [id, pattern] of Object.entries(track.patterns)) {
|
||||
for (const [voice, line] of Object.entries(pattern)) {
|
||||
assert.ok(track.voices[voice], `${score.title} ${id}: ${voice} is a voice`);
|
||||
assert.equal(stepsOf(line) % 16, 0, `${score.title} ${id}.${voice} runs whole bars`);
|
||||
}
|
||||
}
|
||||
const steps = track.order.reduce((n, id) => n + stepsOf(track.patterns[id].drums), 0);
|
||||
const seconds = (steps / 4) * (60 / track.bpm);
|
||||
assert.ok(seconds > 60 && seconds < 100, `${score.title} runs a minute or so (${Math.round(seconds)} s)`);
|
||||
const { road, boss, fever } = bounce.MUSIC_HEAT;
|
||||
for (const v of ["bass", "lead", "arp", "drums"]) assert.ok((track.voices[v].from ?? 0) <= road, `${v} plays on the open road`);
|
||||
assert.ok(track.voices.echo.from > road && track.voices.echo.from <= boss, "the echo joins for a boss");
|
||||
assert.ok(track.voices.harmony.from > boss && track.voices.harmony.from <= fever, "the harmony joins in a Fever");
|
||||
});
|
||||
});
|
||||
|
||||
/* ----------------------------------- the boss hold, the stunt pieces */
|
||||
|
||||
test("Bounce Road arcade: a boss stage lasts until its boss is beaten: more of it is laid ahead while the boss lives, and its line comes once it is flattened", () => {
|
||||
const round = bounceRound(4);
|
||||
round.infinite = true;
|
||||
const road = round.road;
|
||||
const you = round.cars[0];
|
||||
const drive = (ms, until = () => false) => {
|
||||
for (let t = 0; t < ms && !until(); t += 16) {
|
||||
const i = bounce.rowIn(road, you.d + 6);
|
||||
Object.assign(you, { x: (road.L[i] + road.R[i]) / 2, v: 50, ghostMs: 1000 });
|
||||
if (bounce.groundAt(road, you.x, you.d + 4, round.clock) !== bounce.GROUND.road) Object.assign(you, { air: 200, airMax: 400 });
|
||||
bounce.advance(round, 16, steady);
|
||||
}
|
||||
};
|
||||
bounce.buildStage(road, 2);
|
||||
bounce.buildStage(road, 3);
|
||||
you.d = road.stageAt[2] - 1;
|
||||
drive(200);
|
||||
assert.equal(round.stage, 3);
|
||||
drive(20000, () => round.cars.some((c) => bounce.isBoss(c)));
|
||||
const boss = round.cars.find((c) => bounce.isBoss(c));
|
||||
assert.ok(boss, "its boss comes");
|
||||
const line = road.stageAt[3];
|
||||
drive(60000);
|
||||
assert.equal(round.stage, 3, "still on the boss stage a minute on");
|
||||
assert.ok(road.stageAt[3] > line + 1000, "its line moved on with the road");
|
||||
assert.equal(road.built, 3, "and nothing past it is built");
|
||||
assert.ok(road.stageAt[3] - you.d > bounce.FIELD_H, "the line never comes into view");
|
||||
assert.equal(eventsOf(round, "escape").length, 0, "it does not get away");
|
||||
boss.hp = 1;
|
||||
bounce.hurtBoss(round, boss, "rocket");
|
||||
const end = road.stageAt[3];
|
||||
drive(30000, () => round.stage === 4);
|
||||
assert.equal(round.stage, 4, "beaten, the line comes");
|
||||
assert.equal(road.stageAt[3], end, "where the road then ended");
|
||||
assert.equal(eventsOf(round, "stage").at(-1).rank !== "C", true, "and the boss counts toward the rank");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a kicker flies you KICKER_AIR the usual jump over its whole chicane, a wall right across the road can only be jumped, a trampoline is three bounces, and a turbo lane is one boost after another", () => {
|
||||
const round = bounceRound(9);
|
||||
const kicker = onto(round, "pads", (p) => p.kind === "kicker", 8);
|
||||
const you = round.cars[0];
|
||||
you.v = 55;
|
||||
for (let ms = 0; ms < 400 && you.air <= 0; ms += 4) bounce.advance(round, 4, steady);
|
||||
assert.ok(you.air > 0 && Math.abs(you.airMax - bounce.airMs(you.v) * bounce.KICKER_AIR) < 40, "a long flight");
|
||||
assert.ok(bounce.KICKER_AIR > bounce.RAMP_AIR);
|
||||
const walls = round.road.blocks.filter((b) => b.d > kicker.d && b.d < kicker.d + 110);
|
||||
assert.equal(walls.length, 3, "a chicane under it");
|
||||
for (let ms = 0; ms < 3000 && you.air > 0; ms += 4) bounce.advance(round, 4, steady);
|
||||
assert.equal(round.phase, "drive", "down on clear road");
|
||||
assert.ok(you.d > walls.at(-1).d, "past every barrier");
|
||||
assert.ok(eventsOf(round, "land").at(-1).big, "for big air");
|
||||
const r2 = bounceRound(9);
|
||||
const wall = onto(r2, "blocks", (b) => b.wall, 12);
|
||||
const i = bounce.rowOf(wall.d);
|
||||
assert.ok(wall.w > r2.road.R[i] - r2.road.L[i] - 2, "right across the road");
|
||||
for (let ms = 0; ms < 800 && r2.phase === "drive"; ms += 4) bounce.advance(r2, 4, steady);
|
||||
assert.equal(r2.phase, "crash", "no way round");
|
||||
const r3 = bounceRound(9);
|
||||
onto(r3, "blocks", (b) => b.wall, 6);
|
||||
r3.input.jump = bounce.JUMP_BUFFER_MS;
|
||||
for (let ms = 0; ms < 1500; ms += 4) bounce.advance(r3, 4, steady);
|
||||
assert.equal(r3.phase, "drive", "only over");
|
||||
assert.ok(eventsOf(r3, "land").some((e) => e.overs.includes("block")));
|
||||
const road = bounce.newRoad(9);
|
||||
bounce.ensureRoad(road, 60000);
|
||||
const wide = road.pads.filter((p) => p.kind === "pop" && p.w > 20);
|
||||
assert.ok(wide.length >= 3 && wide[1].d - wide[0].d < 70, "trampolines come in a row");
|
||||
const strips = road.pads.filter((p) => p.kind === "boost");
|
||||
const lane = strips.find((p, k) => strips[k + 3] && strips[k + 3].d - p.d < 80 && strips[k + 3].x === p.x);
|
||||
assert.ok(lane, "a turbo lane");
|
||||
const j = bounce.rowOf(lane.d + 20);
|
||||
assert.ok(Math.abs(road.R[j] - road.L[j] - bounce.TURBO_W) < 0.01, "and narrow");
|
||||
for (const s of bounce.STAGES) for (const k of Object.keys(bounce.WILD)) assert.ok(s.weights[k] > 0, `${s.title} lays a ${k}`);
|
||||
});
|
||||
|
||||
test("Bounce Road arcade game: a power-up taken flashes its name near the top of the field for TOAST_MS, at once, whatever banner is showing", () => {
|
||||
const texts = [];
|
||||
const ctx = new Proxy({}, {
|
||||
get: (target, name) => (name === "fillText" ? (text, x, y) => texts.push([String(text), y]) : name in target ? target[name] : () => {}),
|
||||
set: (target, name, value) => { target[name] = value; return true; },
|
||||
});
|
||||
const g = game.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
|
||||
g.resize(900, 900);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
g.round.cars.length = 1;
|
||||
g.round.spawnMs = 1e12;
|
||||
const you = g.round.cars[0];
|
||||
g.round.events.push({ type: "power", kind: "rocket", x: you.x, d: you.d });
|
||||
texts.length = 0;
|
||||
g.tick(16);
|
||||
g.tick(16);
|
||||
const flash = texts.filter(([t]) => t === "ROCKETS");
|
||||
assert.ok(flash.length > 0, "its name, while the stage's banner is still up");
|
||||
assert.ok(flash.every(([, y]) => y < bounce.FIELD_H * 0.2), `near the top of the field (${flash[0][1]})`);
|
||||
for (let ms = 0; ms < bounce.TOAST_MS + 50; ms += 16) g.tick(16);
|
||||
texts.length = 0;
|
||||
g.tick(16);
|
||||
assert.equal(texts.filter(([t]) => t === "ROCKETS").length, 0, "and gone");
|
||||
});
|
||||
@@ -247,6 +247,21 @@ test("Bounce Road: every pill's text reads at 4.5:1 on its backing and its timer
|
||||
});
|
||||
});
|
||||
|
||||
test("Bounce Road: the gadget held, a Magnet and a Fever each show as a pill that reads, every gadget in its own color", () => {
|
||||
for (const kind of bounce.GADGETS) {
|
||||
checkPills({
|
||||
setup: (r) => {
|
||||
const you = r.cars[0];
|
||||
bounce.applyPower(r, kind);
|
||||
you.magnetMs = bounce.MAGNET_MS / 2;
|
||||
r.feverMs = bounce.FEVER_MS / 2;
|
||||
r.fever = bounce.FEVER_FULL;
|
||||
},
|
||||
expect: [`TAP x2: ${bounce.POWERS[kind].tag}`, "~MAGNET", "~FEVER x2"],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("Bounce Road game: held arrows drive and steer until let go; space jumps once a press, never on its key repeat, never with the press that plays on; a pause lets go of every key, drops an early press and holds a jump mid-air; and the board refuses a tiny window", () => {
|
||||
const { canvas } = stubCanvas();
|
||||
const t = game.create({ canvas });
|
||||
@@ -279,7 +294,7 @@ test("Bounce Road game: held arrows drive and steer until let go; space jumps on
|
||||
g.key("left");
|
||||
g.key("action");
|
||||
g.pause();
|
||||
assert.deepEqual(Object.values(g.round.input), [false, false, false, false, 0], "a pause holds nothing, the early press dropped");
|
||||
assert.deepEqual(Object.values(g.round.input), [false, false, false, false, 0, false], "a pause holds nothing, the early press dropped");
|
||||
g.key("action");
|
||||
assert.equal(g.state, "paused", "space never plays on by itself: the window resumes through resume()");
|
||||
g.resume();
|
||||
@@ -316,7 +331,8 @@ test("Bounce Road game: the start screen names the furthest stage, the memo only
|
||||
const scores = [];
|
||||
const g = game.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, memo, onScore: (n) => scores.push(n) });
|
||||
g.resize(900, 900);
|
||||
assert.ok(texts.some(([t]) => t.includes(`Furthest: ${bounce.STAGES[2].title} (stage 3)`)), "the start screen names the furthest stage");
|
||||
assert.ok(texts.some(([t]) => t.includes("Furthest: stage 3")), "the start screen names the furthest stage");
|
||||
assert.ok(texts.some(([t]) => t.includes("double-tap space")), "and how to set off a gadget");
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
g.round.cars.length = 1;
|
||||
@@ -347,7 +363,7 @@ test("Bounce Road game: the start screen names the furthest stage, the memo only
|
||||
texts.length = 0;
|
||||
g.resize(900, 900);
|
||||
assert.ok(texts.some(([t, f]) => t === String(g.score) && /\b7px/.test(f)), "the score, big");
|
||||
assert.ok(texts.some(([t]) => t.includes(`Reached ${bounce.STAGES[3].title} (stage 4). New furthest!`)));
|
||||
assert.ok(texts.some(([t]) => t.includes(`Reached ${bounce.stageName(4, g.round.road)}. New furthest!`)));
|
||||
g.tick(1000);
|
||||
assert.equal(scores.length, 1, "once");
|
||||
});
|
||||
@@ -384,7 +400,7 @@ test("Bounce Road game: a jump springs, a crush squashes higher up the chain, pa
|
||||
g.tick(16);
|
||||
g.tick(16);
|
||||
assert.equal(tones.filter(([n]) => n === "best").length, 1);
|
||||
for (let n = 1; n <= 12; n++) {
|
||||
for (let n = 1; n <= 31; n++) {
|
||||
while (g.round.road.built < n + 1) bounce.buildStage(g.round.road, g.round.road.built + 1);
|
||||
g.round.stage = n;
|
||||
you.d = g.round.road.stageAt[n - 1] + 400;
|
||||
@@ -412,6 +428,16 @@ test("Bounce Road game: every event plays a tone that tones.js has (its blips, i
|
||||
{ type: "spawn", id: 5, kind: "monster", ...at }, { type: "power", kind: "mega", ...at }, { type: "crush", ...at, kind: "cop", id: 3, chain: 2, points: 500 },
|
||||
{ type: "copGone", id: 3, ...at }, { type: "bubble", ...at, cause: "crash" }, { type: "bump", a: 0, b: 3, ...at, speed: 30, kind: "zigzag" },
|
||||
{ type: "bumped", ...at, id: 3, kind: "zigzag", how: "splash", points: 50 }, { type: "haul", ...at, kind: "truck", id: 3, chain: 1, points: 50 },
|
||||
// The arcade layer: the newer things on the road, the gadgets, the Fever, the rivals' tricks and the bosses.
|
||||
{ type: "pop", id: 0, ...at, v: 50 }, { type: "belt", ...at, dir: 1 }, { type: "bumper", ...at, points: 20 }, { type: "laserWarn", ...at }, { type: "stompWarn", ...at, what: "book" },
|
||||
{ type: "stompLand", ...at, what: "book" }, ...bounce.GADGETS.map((kind) => ({ type: "use", kind, ...at, left: 1 })), { type: "pound", ...at, hit: 2 }, { type: "zap", ...at, hit: 2 },
|
||||
{ type: "fever", ...at }, { type: "feverEnd" }, { type: "life", ...at }, { type: "blast", ...at, kind: "brick", id: 3, points: 100 }, { type: "boom", ...at, r: 8, what: "bomb", near: true },
|
||||
{ type: "lob", id: 3, what: "barrel", ...at }, { type: "aim", id: 3, ...at }, { type: "bolt", id: 3, ...at }, { type: "shot", ...at, tough: false }, { type: "shot", ...at, tough: true },
|
||||
{ type: "blade", id: 3, ...at }, { type: "bomb", id: 3, ...at }, { type: "phase", id: 3, ...at, on: true }, { type: "phase", id: 3, ...at, on: false }, { type: "magnet", id: 3, ...at },
|
||||
{ type: "spin", id: 3, kind: "brick", ...at }, { type: "split", ...at }, { type: "spiked", id: 3, ...at }, { type: "meet", kind: "spike", ...at }, { type: "bossWarn", id: 3, kind: "vac", ...at },
|
||||
{ type: "bossWarn", id: 3, kind: "chopper", ...at }, { type: "bossCharge", id: 3, ...at }, { type: "swipe", id: 3, ...at }, { type: "power", kind: "rocket", ...at }, { type: "power", kind: "heart", ...at },
|
||||
...["tanker", "vac", "chopper", "cat", "supply"].map((kind, k) => ({ type: "spawn", id: 6 + k, kind, ...at })), { type: "stomp", ...at, id: 3, kind: "cat", hp: 2, chain: 1, points: 150, how: "rocket" },
|
||||
{ type: "boss", ...at, kind: "vac", points: 2000, life: false }, { type: "escape", ...at, kind: "tanker" }, { type: "lose", cause: "laser", ...at, lives: 2 },
|
||||
];
|
||||
for (const e of events) {
|
||||
tones.length = 0;
|
||||
@@ -456,7 +482,9 @@ test("Bounce Road game: Planny keeps his star eye in your highlight driving, in
|
||||
},
|
||||
"at the end": (g, you) => {
|
||||
g.round.lives = 1;
|
||||
bounce.ensureRoad(g.round.road, 9000);
|
||||
const hole = g.round.road.holes.find((h) => h.kind === "crack");
|
||||
while (g.round.road.stageAt[g.round.stage] <= hole.d0) g.round.stage++;
|
||||
you.d = hole.d0 - 6;
|
||||
g.round.far = you.d;
|
||||
for (let ms = 0; ms < bounce.CRASH_MS + 2000 && g.state === "running"; ms += 16) g.tick(16);
|
||||
@@ -681,7 +709,12 @@ test("Bounce Road game: Night Lights is dark but for your headlights' reach", ()
|
||||
g.tick(16);
|
||||
assert.ok(!fills.includes("evenodd"), "by day, no dark");
|
||||
bounce.ensureRoad(g.round.road, 30000);
|
||||
const night = bounce.STAGES.findIndex((s) => s.id === "night") + 1;
|
||||
// The real game shuffles its stages: the first dark one on this road (Night Lights, or a Lights out twist).
|
||||
let night = 1;
|
||||
while (night < 90 && !bounce.stageFor(night, g.round.road).dark) night++;
|
||||
assert.ok(bounce.stageFor(night, g.round.road).dark, "a dark stage in the run");
|
||||
bounce.ensureRoad(g.round.road, g.round.road.stageAt.at(-1) + 1);
|
||||
while (g.round.road.built < night + 1) bounce.buildStage(g.round.road, g.round.road.built + 1);
|
||||
g.round.stage = night;
|
||||
const you = g.round.cars[0];
|
||||
you.d = g.round.road.stageAt[night - 1] + 30;
|
||||
|
||||
@@ -9,7 +9,7 @@ import "./seed-random.mjs";
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as bounce from "../src/web-console/public/activities/bounce.js";
|
||||
import { hudLayout, labelSpot, LOOKS, limbInk, contrast, inkOn } from "../src/web-console/public/activities/bounce-draw.js";
|
||||
import { CUSTOM_STYLES, hudLayout, labelSpot, LOOKS, limbInk, contrast, inkOn } from "../src/web-console/public/activities/bounce-draw.js";
|
||||
import { CAR_STYLES } from "../src/web-console/public/activities/bounce-cars.js";
|
||||
import { ACCENTS } from "../src/web-console/public/palette.js";
|
||||
|
||||
@@ -31,7 +31,9 @@ function bounceRound(seed = 7, rivals = false) {
|
||||
// A rival of `kind` put at (x, d), still and on the ground, going nowhere on
|
||||
// its own.
|
||||
function bounceRival(round, kind, x, d, over = {}) {
|
||||
const car = bounce.spawnRival(round, kind, steady, round.cars[0].d + 300);
|
||||
// A rival only spawns on plain road: try further along until one takes. It is moved anyway.
|
||||
let car = null;
|
||||
for (let at = round.cars[0].d + 300; !car && at < round.cars[0].d + 3000; at += 40) car = bounce.spawnRival(round, kind, steady, at);
|
||||
assert.ok(car, `a ${kind} spawns`);
|
||||
Object.assign(car, { x, d, v: 0, tv: 0, vx: 0, kx: 0, air: 0, tx: x, lane: x, hopIn: 1e9, dropIn: 1e9, mode: "calm", ...over });
|
||||
return car;
|
||||
@@ -101,7 +103,11 @@ function carefulBot(round) {
|
||||
let tx = (lo + hi) / 2;
|
||||
const things = [];
|
||||
for (const list of [road.blocks, round.drops]) for (const o of list) if (!o.hit && o.d - you.d > -2 && o.d - you.d < 40) things.push(o);
|
||||
for (const h of road.hazards) if (h.kind === "drop" && h.at && !h.landed && h.d - you.d > -4 && h.d - you.d < 70) things.push(h);
|
||||
for (const h of road.hazards) {
|
||||
if (h.kind === "drop" && h.at && !h.landed && h.d - you.d > -4 && h.d - you.d < 70) things.push(h);
|
||||
// A stomper on its way down, or down, is a thing to steer round.
|
||||
if (h.kind === "stomper" && h.d - you.d > -5 && h.d - you.d < 60) things.push(h);
|
||||
}
|
||||
for (const c of round.cars) if (c.id !== 0 && c.out === 0 && c.d - you.d > 0 && c.d - you.d < 24) things.push(c);
|
||||
things.sort((p, q) => p.d - q.d);
|
||||
const o = things[0];
|
||||
@@ -116,7 +122,8 @@ function carefulBot(round) {
|
||||
const soon = (d) => d > you.d && d - you.d < 3 + you.v * 0.02 + you.l / 2;
|
||||
for (let k = bounce.firstAt(road.holes, "d0", you.d); k < road.holes.length && road.holes[k].d0 < you.d + 20; k++) if (soon(road.holes[k].d0)) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
for (const h of road.hazards) {
|
||||
if (h.kind === "ball" && soon(h.d - h.r - 1)) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
if ((h.kind === "ball" || h.kind === "roller") && soon(h.d - h.r - 1)) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
if (h.kind === "laser" && soon(h.d - h.half - 1) && bounce.laserAt(h, round.clock + 150).warn) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
if (h.kind === "train" && soon(h.d - h.half - 1) && bounce.trainAt(h, round.clock + 150).warn) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
}
|
||||
for (const b of things) if (b.l && b.kind && b.id === undefined && soon(b.d - b.l / 2) && Math.abs(b.x - you.x) < (b.w + you.w) / 2) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
@@ -124,7 +131,7 @@ function carefulBot(round) {
|
||||
|
||||
// Plays `round` with `bot` until `stage` or the end, `ms` at most, a rival's
|
||||
// random seeded; returns the seconds each stage took and the lives lost.
|
||||
function play(round, bot, { stage = 11, ms = 900000, rivals = false, seed = 1 } = {}) {
|
||||
function play(round, bot, { stage = 16, ms = 900000, rivals = false, seed = 1 } = {}) {
|
||||
const random = rivals ? bounce.seeded(seed * 13) : steady;
|
||||
const secs = [];
|
||||
const lost = [];
|
||||
@@ -290,7 +297,10 @@ test("Bounce Road: a rival bumped past the road's edge is out, and yours for BUM
|
||||
test("Bounce Road: water or a hole under your wheels costs a life, flying over it does not, and a Bubble throws you clear instead", () => {
|
||||
const round = bounceRound();
|
||||
const you = round.cars[0];
|
||||
bounce.ensureRoad(round.road, 9000);
|
||||
const hole = round.road.holes.find((h) => h.kind === "crack");
|
||||
while (round.road.stageAt[round.stage] <= hole.d0) round.stage++;
|
||||
round.far = 1e9;
|
||||
Object.assign(you, { d: hole.d0 + 2, v: 40, air: 300, airMax: 600 });
|
||||
bounce.advance(round, 100, steady);
|
||||
assert.equal(round.phase, "drive", "in the air over it, nothing");
|
||||
@@ -304,6 +314,9 @@ test("Bounce Road: water or a hole under your wheels costs a life, flying over i
|
||||
assert.ok(you.d < hole.d0 - bounce.RESPAWN_BACK / 2, `back before the hole (${you.d.toFixed(0)} < ${hole.d0})`);
|
||||
assert.equal(bounce.groundAt(round.road, you.x, you.d), bounce.GROUND.road, "on the road");
|
||||
const saved = bounceRound();
|
||||
bounce.ensureRoad(saved.road, 9000);
|
||||
saved.stage = round.stage;
|
||||
saved.far = 1e9;
|
||||
const s = saved.cars[0];
|
||||
s.bubble = true;
|
||||
Object.assign(s, { d: hole.d0 + 2, v: 40 });
|
||||
@@ -342,7 +355,7 @@ test("Bounce Road: a broken span the Bubble's throw carries you over is the Bubb
|
||||
|
||||
/* ---------------------------------------------------- the road is fair */
|
||||
|
||||
test("Bounce Road: every hole of the first twenty stages, on many roads, is jumpable at JUMP_FAIR of the top speed (a drawbridge's lifted span included), with a run-up of road and a sign before it, and even the longest jump off the first of two breaks lands on the bridge between", () => {
|
||||
test("Bounce Road: every hole of the first thirty stages, on many roads, is jumpable at JUMP_FAIR of the top speed (a drawbridge's lifted span included), with a run-up of road and a sign before it, and even the longest jump off the first of two breaks lands on the bridge between", () => {
|
||||
const fair = bounce.reach(bounce.JUMP_FAIR * bounce.TOP_SPEED);
|
||||
let twins = 0;
|
||||
let draws = 0;
|
||||
@@ -350,7 +363,7 @@ test("Bounce Road: every hole of the first twenty stages, on many roads, is jump
|
||||
assert.ok(bounce.MAX_HOLE + bounce.CAR_L <= fair, "the longest hole any stage may cut is jumpable");
|
||||
for (let seed = 1; seed <= 8; seed++) {
|
||||
const road = bounce.newRoad(seed);
|
||||
while (road.built < 20) bounce.buildStage(road, road.built + 1);
|
||||
while (road.built < 30) bounce.buildStage(road, road.built + 1);
|
||||
assert.ok(road.holes.length > 30, `seed ${seed} cuts holes`);
|
||||
const solid = (from, to) => {
|
||||
for (let i = Math.floor(from / bounce.ROW); i < Math.floor(to / bounce.ROW); i++) if (!road.deck[i] || road.dynOf[i]) return false;
|
||||
@@ -377,14 +390,14 @@ test("Bounce Road: every hole of the first twenty stages, on many roads, is jump
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.ok(twins > 12, `bridges with two breaks were checked (${twins})`);
|
||||
assert.ok(draws > 8, `drawbridges were checked (${draws})`);
|
||||
assert.ok(twins > 6, `bridges with two breaks were checked (${twins})`);
|
||||
assert.ok(draws > 2, `drawbridges were checked (${draws})`);
|
||||
});
|
||||
|
||||
test("Bounce Road: with a Spring held and a Nitro burning, a jump off the first of two breaks at full speed comes down on the bridge between, never in the second break", () => {
|
||||
const round = bounceRound(1);
|
||||
const road = round.road;
|
||||
bounce.ensureRoad(road, 40000);
|
||||
bounce.ensureRoad(road, 150000);
|
||||
const riverOf = (h) => road.rivers.find((r) => r.d0 <= h.d0 && r.d1 >= h.d1);
|
||||
const k = road.holes.findIndex((h, j) => j && h.kind === "span" && road.holes[j - 1].kind === "span" && riverOf(h) === riverOf(road.holes[j - 1]));
|
||||
assert.ok(k > 0, "a bridge with two breaks");
|
||||
@@ -422,7 +435,7 @@ test("Bounce Road: a life lost puts you back with RESPAWN_RUN of plain road ahea
|
||||
|
||||
test("Bounce Road: the road's edges slant from row to row the way they are drawn, never a stair step: the ground under a car eases from one row's edge to the next", () => {
|
||||
const road = bounce.newRoad(3);
|
||||
while (road.built < 4) bounce.buildStage(road, road.built + 1);
|
||||
while (road.built < 8) bounce.buildStage(road, road.built + 1);
|
||||
let checked = 0;
|
||||
for (let i = 1; i < road.rows; i++) {
|
||||
if (road.deck[i] !== 1 || road.dynOf[i] || road.ML[i] < road.MR[i] || Math.abs(road.L[i] - road.L[i - 1]) < 1) continue;
|
||||
@@ -465,29 +478,73 @@ test("Bounce Road: the rivals' list is kept in place from slice to slice, with t
|
||||
assert.equal(cars[0].id, 0, "you first");
|
||||
});
|
||||
|
||||
test("Bounce Road: the same seed builds the same road, a different one another, every stage keeps the road on the field and a flowerbed with room either side, and past the tenth the road goes round again, quicker and meaner", () => {
|
||||
test("Bounce Road: the same seed builds the same road, a different one another, every stage keeps the road on the field and a flowerbed with room either side, and past the fifteenth the run laps, quicker and meaner", () => {
|
||||
const a = bounce.newRoad(42);
|
||||
const b = bounce.newRoad(42);
|
||||
const c = bounce.newRoad(43);
|
||||
for (const r of [a, b, c]) while (r.built < 12) bounce.buildStage(r, r.built + 1);
|
||||
for (const r of [a, b, c]) while (r.built < 16) bounce.buildStage(r, r.built + 1);
|
||||
assert.deepEqual([a.L, a.R, a.ML, a.deck, a.under, a.dynOf, a.stageAt, a.hazards.map((h) => h.kind)], [b.L, b.R, b.ML, b.deck, b.under, b.dynOf, b.stageAt, b.hazards.map((h) => h.kind)]);
|
||||
assert.notDeepEqual(a.L, c.L);
|
||||
for (let i = 0; i < a.rows; i++) {
|
||||
assert.ok(a.L[i] >= 1 && a.R[i] <= bounce.FIELD_W - 1, `row ${i} on the field`);
|
||||
if (a.ML[i] < a.MR[i]) assert.ok(a.ML[i] - a.L[i] >= 15 && a.R[i] - a.MR[i] >= 15, `row ${i}: room round the flowerbed`);
|
||||
}
|
||||
assert.equal(bounce.STAGES.length, 10, "ten stages");
|
||||
assert.equal(new Set(bounce.STAGES.map((s) => s.id)).size, 10, "each with its own look");
|
||||
for (const s of bounce.STAGES) assert.ok(LOOKS[s.id], `${s.id} has a look`);
|
||||
for (let n = 1; n <= 10; n++) {
|
||||
assert.equal(bounce.STAGES.length, bounce.CYCLE, "fifteen stages a lap");
|
||||
assert.equal(new Set(bounce.STAGES.map((s) => s.id)).size, bounce.CYCLE, "each with its own look");
|
||||
for (const t of Object.values(bounce.THEMES)) assert.ok(LOOKS[t.id], `${t.id} has a look`);
|
||||
for (let n = 1; n <= bounce.CYCLE; n++) {
|
||||
const len = a.stageAt[n] - a.stageAt[n - 1];
|
||||
assert.ok(len >= bounce.STAGES[n - 1].len && len < bounce.STAGES[n - 1].len + 350, `stage ${n} is ${len} long`);
|
||||
assert.equal(Boolean(bounce.STAGES[n - 1].boss), n % bounce.WORLD === 0, `stage ${n}: a boss on every third stage only`);
|
||||
}
|
||||
assert.equal(bounce.stageFor(11), bounce.stageFor(11), "built once");
|
||||
assert.equal(bounce.stageFor(11).name, `${bounce.STAGES[bounce.LAP_FROM - 1].title} 2`);
|
||||
assert.equal(bounce.stageFor(18).name, "Monster Mash 2");
|
||||
assert.ok(bounce.stageFor(18).boss, "the Monster is back each lap");
|
||||
assert.ok(bounce.stageFor(11).pace > bounce.stageFor(bounce.LAP_FROM).pace && bounce.stageFor(40).rivals <= bounce.MAX_RIVALS && bounce.stageFor(40).crack[1] <= bounce.MAX_HOLE);
|
||||
assert.deepEqual(bounce.STAGES.filter((s) => s.boss).map((s) => s.boss), [...bounce.BOSS_ORDER], "the five bosses, each in its arena");
|
||||
assert.ok(bounce.STAGES[0].len < bounce.STAGES[13].len && bounce.STAGES[13].len < 1700, "short stages, longer as the run goes on");
|
||||
assert.equal(bounce.stageFor(16), bounce.stageFor(16), "built once");
|
||||
assert.equal(bounce.stageFor(16).lap, 2);
|
||||
assert.equal(bounce.stageFor(16).name, `${bounce.THEMES[bounce.stageFor(16).id].title} 2`);
|
||||
assert.equal(bounce.stageFor(27).name, "Monster Mash 2");
|
||||
assert.equal(bounce.stageFor(27).boss, "monster", "the bosses are back each lap");
|
||||
assert.ok(bounce.stageFor(16).pace > bounce.stageFor(1).pace && bounce.stageFor(60).rivals <= bounce.MAX_RIVALS && bounce.stageFor(60).crack[1] <= bounce.MAX_HOLE);
|
||||
});
|
||||
|
||||
test("Bounce Road: a shuffled run deals its stages afresh from the seed: Chalk Lane first, a boss arena on every third stage, every boss once a lap with the Cat last on the first, twists on plain stages only, and the same seed the same run", () => {
|
||||
const plans = new Set();
|
||||
let twists = 0;
|
||||
for (let seed = 1; seed <= 12; seed++) {
|
||||
const road = bounce.newRoad(seed, true);
|
||||
const again = bounce.newRoad(seed, true);
|
||||
const ids = [];
|
||||
const bosses = [];
|
||||
for (let n = 1; n <= 30; n++) {
|
||||
const spec = bounce.stageFor(n, road);
|
||||
assert.equal(spec, bounce.stageFor(n, road), "built once a road");
|
||||
assert.equal(spec.id, bounce.stageFor(n, again).id, `seed ${seed}: stage ${n} is the same on the same seed`);
|
||||
assert.equal(Boolean(spec.boss), n % bounce.WORLD === 0, `seed ${seed}: stage ${n}`);
|
||||
if (spec.boss) {
|
||||
bosses.push(spec.boss);
|
||||
assert.equal(spec.id, bounce.ARENAS[spec.boss], "a boss in its own arena");
|
||||
assert.equal(spec.twist, null, "no twist on a boss stage");
|
||||
} else if (spec.twist) {
|
||||
twists++;
|
||||
assert.ok(bounce.TWISTS[spec.twist], `a known twist (${spec.twist})`);
|
||||
}
|
||||
if (n <= bounce.CYCLE) ids.push(spec.id);
|
||||
}
|
||||
assert.equal(ids[0], "chalk", "Chalk Lane opens every run");
|
||||
assert.equal(bounce.stageFor(1, road).twist, null, "and with no twist");
|
||||
assert.equal(new Set(ids).size, bounce.CYCLE, `seed ${seed}: no theme twice in a lap`);
|
||||
assert.deepEqual([...bosses.slice(0, 5)].sort(), [...bounce.BOSS_ORDER].sort(), "every boss once in the first lap");
|
||||
assert.equal(bosses[4], "cat", "the Cat last");
|
||||
assert.deepEqual([...bosses.slice(5, 10)].sort(), [...bounce.BOSS_ORDER].sort(), "and once in the second");
|
||||
plans.add(ids.join(" "));
|
||||
}
|
||||
assert.ok(plans.size >= 10, `runs differ (${plans.size} of 12)`);
|
||||
assert.ok(twists > 20, `twists turn up (${twists})`);
|
||||
const rush = bounce.stageSpec(5, "beds", "rush");
|
||||
assert.equal(rush.rivals, bounce.stageSpec(5, "beds").rivals + 2, "Rush hour packs the road");
|
||||
assert.ok(bounce.stageSpec(5, "beds", "dark").dark && bounce.stageSpec(5, "beds", "rain").ice && bounce.stageSpec(5, "beds", "gold").stars === 1);
|
||||
assert.equal(bounce.newRound(5, steady).road.shuffle, false, "a round asks for the shuffle");
|
||||
assert.equal(bounce.newRound(5, steady, true).road.shuffle, true);
|
||||
});
|
||||
|
||||
test("Bounce Road: each stage brings something new: its own pieces, hazards or rivals, and later stages bring more at once", () => {
|
||||
@@ -496,31 +553,32 @@ test("Bounce Road: each stage brings something new: its own pieces, hazards or r
|
||||
for (const s of bounce.STAGES) {
|
||||
const things = [...Object.keys(s.weights).filter((k) => k !== "straight" && s.weights[k] > 0), ...s.kinds];
|
||||
const fresh = things.filter((t) => !seen.has(t));
|
||||
if (s.n !== 1) assert.ok(fresh.length > 0 || s.boss || s.id === "night", `${s.title} brings something new (Night Lights brings the dark)`);
|
||||
if (s.n !== 1) assert.ok(fresh.length > 0 || s.boss || s.dark, `${s.title} brings something new (Night Lights brings the dark)`);
|
||||
for (const t of things) seen.add(t);
|
||||
assert.ok(things.length >= before - 7, `${s.title} keeps up the mix (${things.length})`);
|
||||
assert.ok(things.length >= before - 7 || s.boss, `${s.title} keeps up the mix (${things.length})`);
|
||||
before = Math.max(before, things.length);
|
||||
}
|
||||
for (const t of Object.values(bounce.THEMES)) for (const k of Object.keys(t.weights)) seen.add(k);
|
||||
for (const piece of bounce.PIECE_NAMES) if (piece !== "straight") assert.ok(seen.has(piece), `the ${piece} turns up`);
|
||||
for (const kind of bounce.RIVAL_KINDS) if (kind !== "monster") assert.ok(seen.has(kind), `the ${kind} turns up`);
|
||||
for (const kind of bounce.RIVAL_KINDS) if (bounce.RIVALS[kind].weight > 0) assert.ok(seen.has(kind), `the ${kind} turns up`);
|
||||
const kinds = new Set();
|
||||
for (const seed of [2, 9]) {
|
||||
const road = bounce.newRoad(seed);
|
||||
while (road.built < 10) bounce.buildStage(road, road.built + 1);
|
||||
while (road.built < 30) bounce.buildStage(road, road.built + 1);
|
||||
for (const e of [...road.hazards, ...road.pads, ...road.blocks, ...road.dyn]) kinds.add(e.kind);
|
||||
}
|
||||
for (const k of ["train", "ball", "sprinkler", "drop", "wind", "boost", "ramp", "slick", "cone", "block", "draw", "sway", "crumble"]) assert.ok(kinds.has(k), `a ${k} on the road`);
|
||||
for (const k of ["train", "ball", "sprinkler", "drop", "wind", "boost", "ramp", "slick", "cone", "block", "draw", "sway", "crumble", "belt", "pop", "bumper", "laser", "stomper", "roller"]) assert.ok(kinds.has(k), `a ${k} on the road`);
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ bots */
|
||||
|
||||
test("Bounce Road: a careful bot crosses all ten stages with no rivals and no life lost, each stage taking 20 to 50 seconds", () => {
|
||||
test("Bounce Road: a careful bot crosses all fifteen stages with no rivals and no life lost, each stage taking 14 to 45 seconds", () => {
|
||||
for (const seed of [3, 21]) {
|
||||
const round = bounceRound(seed);
|
||||
const { secs, lost } = play(round, carefulBot, { stage: 11 });
|
||||
assert.equal(round.stage, 11, `seed ${seed} reaches stage 11 (${round.stage}, lost ${lost})`);
|
||||
const { secs, lost } = play(round, carefulBot, { stage: 16 });
|
||||
assert.equal(round.stage, 16, `seed ${seed} reaches stage 16 (${round.stage}, lost ${lost})`);
|
||||
assert.deepEqual(lost, [], `seed ${seed}: no life lost`);
|
||||
for (const [n, s] of secs.entries()) assert.ok(s > 20 && s < 50, `seed ${seed}: stage ${n + 1} took ${s.toFixed(0)} s`);
|
||||
for (const [n, s] of secs.entries()) assert.ok(s > 14 && s < 45, `seed ${seed}: stage ${n + 1} took ${s.toFixed(0)} s`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -528,10 +586,10 @@ test("Bounce Road: with the rivals out, the careful bot still gets far, but they
|
||||
let lostAll = 0;
|
||||
for (const seed of [11, 42]) {
|
||||
const round = bounce.newRound(seed, bounce.seeded(seed));
|
||||
const { lost } = play(round, carefulBot, { stage: 11, rivals: true, seed });
|
||||
assert.ok(round.stage >= 6, `seed ${seed}: reached stage ${round.stage}`);
|
||||
const { lost } = play(round, carefulBot, { stage: 16, rivals: true, seed });
|
||||
assert.ok(round.stage >= 3, `seed ${seed}: reached stage ${round.stage}`);
|
||||
lostAll += lost.length;
|
||||
assert.ok(round.stats.crushed + round.stats.bumped + round.stats.near > 5, "and it met them");
|
||||
assert.ok(round.stats.crushed + round.stats.bumped + round.stats.near + round.stats.hauls > 0, "and it met them");
|
||||
}
|
||||
assert.ok(lostAll >= 4, `the rivals cost lives (${lostAll})`);
|
||||
});
|
||||
@@ -560,6 +618,8 @@ test("Bounce Road: with you out of the way the rivals keep driving, never under
|
||||
const last = new Map();
|
||||
for (let ms = 0; ms < 160000; ms += 16) {
|
||||
const i = Math.floor(you.d / bounce.ROW);
|
||||
// No boss: a boss stage would last until it was beaten.
|
||||
round.bossFor = round.stage;
|
||||
Object.assign(you, { ghostMs: 1e9, air: 1000, airMax: 1000, v: 46, x: round.road.ML[i] < round.road.MR[i] ? round.road.L[i] + 3 : (round.road.L[i] + round.road.R[i]) / 2 });
|
||||
bounce.advance(round, 16, steady);
|
||||
for (const e of round.events) {
|
||||
@@ -751,10 +811,11 @@ test("Bounce Road: the Monster truck comes in Monster Mash, five landings on its
|
||||
const round = bounceRound(4);
|
||||
const road = round.road;
|
||||
bounce.ensureRoad(road, 30000);
|
||||
round.stage = 10;
|
||||
assert.equal(bounce.stageFor(12).boss, "monster", "Monster Mash is the twelfth stage of a plain run");
|
||||
round.stage = 12;
|
||||
const you = round.cars[0];
|
||||
const from = road.stageAt[9];
|
||||
const at = plainSpot(road, from + bounce.stageFor(10).len * 0.2, 30);
|
||||
const from = road.stageAt[11];
|
||||
const at = plainSpot(road, from + bounce.stageFor(12).len * 0.2, 30);
|
||||
Object.assign(you, { x: at.x, d: at.d, v: 40 });
|
||||
round.far = 1e9;
|
||||
bounce.advance(round, 16, steady);
|
||||
@@ -763,6 +824,7 @@ test("Bounce Road: the Monster truck comes in Monster Mash, five landings on its
|
||||
assert.equal(m.hp, bounce.BOSS_HP);
|
||||
assert.ok(eventsOf(round, "spawn").some((e) => e.kind === "monster"));
|
||||
round.lives = 2;
|
||||
round.lifeAt = 1e12;
|
||||
for (let n = 0; n < bounce.BOSS_HP; n++) {
|
||||
Object.assign(m, { x: you.x, d: you.d + 1, air: 0, hopIn: 1e9, dropIn: 1e9, v: you.v });
|
||||
Object.assign(you, { air: 4, airMax: 600 });
|
||||
@@ -775,8 +837,9 @@ test("Bounce Road: the Monster truck comes in Monster Mash, five landings on its
|
||||
assert.equal(eventsOf(round, "boss").length, 1);
|
||||
assert.equal(round.lives, 3, "a life back");
|
||||
assert.equal(round.stats.bosses, 1);
|
||||
assert.ok(round.feverMs > 0 && round.trophies > 0, "and a Fever, and its trophy");
|
||||
const r2 = bounceRound(4);
|
||||
r2.stage = 10;
|
||||
r2.stage = 12;
|
||||
bounce.ensureRoad(r2.road, 30000);
|
||||
const y2 = r2.cars[0];
|
||||
Object.assign(y2, { x: at.x, d: at.d, v: 50 });
|
||||
@@ -784,16 +847,16 @@ test("Bounce Road: the Monster truck comes in Monster Mash, five landings on its
|
||||
bounce.collide(r2, y2, m2);
|
||||
assert.equal(r2.phase, "crash", "its back is a wall");
|
||||
const r3 = bounceRound(4);
|
||||
r3.stage = 10;
|
||||
r3.stage = 12;
|
||||
bounce.ensureRoad(r3.road, 30000);
|
||||
const m3 = bounceRival(r3, "monster", 30, r3.road.stageAt[10] + 30, { hp: 3 });
|
||||
r3.bossFor = 10;
|
||||
const m3 = bounceRival(r3, "monster", 30, r3.road.stageAt[12] + 30, { hp: 3 });
|
||||
r3.bossFor = 12;
|
||||
const y3 = r3.cars[0];
|
||||
y3.d = r3.road.stageAt[10] - 0.5;
|
||||
y3.d = r3.road.stageAt[12] - 0.5;
|
||||
y3.x = (r3.road.L[bounce.rowOf(y3.d)] + r3.road.R[bounce.rowOf(y3.d)]) / 2;
|
||||
r3.far = 1e9;
|
||||
bounce.advance(r3, 60, steady);
|
||||
assert.equal(r3.stage, 11);
|
||||
assert.equal(r3.stage, 13);
|
||||
assert.equal(m3.outKind, "gone", "it got away");
|
||||
assert.equal(eventsOf(r3, "escape").length, 1);
|
||||
});
|
||||
@@ -924,7 +987,7 @@ test("Bounce Road: crumbling road falls away behind you once you reach it: at a
|
||||
|
||||
test("Bounce Road: a drawbridge's span is water while it lifts and road while it is down, and a swaying bridge always carries its middle line while its edge goes over the water", () => {
|
||||
const road = bounce.newRoad(2);
|
||||
bounce.ensureRoad(road, 40000);
|
||||
bounce.ensureRoad(road, 90000);
|
||||
const draw = road.dyn.find((s) => s.kind === "draw");
|
||||
assert.ok(draw, "a drawbridge");
|
||||
const mid = (draw.d0 + draw.d1) / 2;
|
||||
@@ -1146,6 +1209,11 @@ test("Bounce Road: power-ups lie on the road from Hose Creek and driving over on
|
||||
assert.ok(it.taken, "taken");
|
||||
assert.equal(eventsOf(round, "power").length, 1);
|
||||
bounce.applyPower(round, "nitro");
|
||||
assert.deepEqual(you.held, { kind: "nitro", uses: 1 }, "a gadget is held");
|
||||
assert.equal(you.nitroMs, 0, "until it is set off");
|
||||
assert.equal(bounce.usePower(round), "nitro");
|
||||
assert.equal(you.held, null, "spent");
|
||||
assert.equal(bounce.usePower(round), null, "nothing held, nothing to set off");
|
||||
round.input.up = true;
|
||||
you.v = bounce.TOP_SPEED;
|
||||
for (let ms = 0; ms < 1500; ms += 4) {
|
||||
@@ -1156,6 +1224,8 @@ test("Bounce Road: power-ups lie on the road from Hose Creek and driving over on
|
||||
const r2 = bounceRound();
|
||||
const y2 = r2.cars[0];
|
||||
bounce.applyPower(r2, "mega");
|
||||
assert.equal(y2.w, bounce.CAR_W, "Mega wheels wait for the double tap");
|
||||
bounce.usePower(r2);
|
||||
assert.ok(y2.w > bounce.CAR_W * 1.2 && y2.l > bounce.CAR_L * 1.2, "bigger");
|
||||
const at = plainSpot(r2.road, 60, 30);
|
||||
Object.assign(y2, { x: at.x, d: at.d });
|
||||
@@ -1208,7 +1278,8 @@ test("Bounce Road: a rival color too near your highlight gives way to a spare, s
|
||||
});
|
||||
|
||||
test("Bounce Road: every rival kind is drawn as one of the car art's styles, no two alike, and Planny as his own", () => {
|
||||
for (const kind of bounce.RIVAL_KINDS) assert.ok(CAR_STYLES[bounce.RIVALS[kind].style], `${kind} drawn as ${bounce.RIVALS[kind].style}`);
|
||||
for (const kind of bounce.RIVAL_KINDS) assert.ok(CAR_STYLES[bounce.RIVALS[kind].style] || CUSTOM_STYLES.includes(bounce.RIVALS[kind].style), `${kind} drawn as ${bounce.RIVALS[kind].style}`);
|
||||
assert.deepEqual(bounce.BOSS_KINDS.map((k) => bounce.RIVALS[k].style).filter((style) => !CAR_STYLES[style]).sort(), [...CUSTOM_STYLES].sort(), "only bosses are drawn by hand");
|
||||
assert.ok(CAR_STYLES.planny);
|
||||
assert.equal(new Set(bounce.RIVAL_KINDS.map((k) => bounce.RIVALS[k].style)).size, bounce.RIVAL_KINDS.length, "no two kinds look alike");
|
||||
});
|
||||
@@ -1318,9 +1389,9 @@ test("Bounce Road: the brake beats a boost strip, so a strip before a train or a
|
||||
|
||||
test("Bounce Road: a stunned Monster's back is never a wall, so running into it right after a stomp is safe", () => {
|
||||
const round = bounceRound(4);
|
||||
round.stage = 10;
|
||||
round.stage = 12;
|
||||
bounce.ensureRoad(round.road, 30000);
|
||||
const at = plainSpot(round.road, round.road.stageAt[9] + 300, 30);
|
||||
const at = plainSpot(round.road, round.road.stageAt[11] + 300, 30);
|
||||
const you = round.cars[0];
|
||||
Object.assign(you, { x: at.x, d: at.d, v: 60 });
|
||||
const m = bounceRival(round, "monster", at.x, at.d + 9.5, { v: 20, hp: 3, stunMs: 800 });
|
||||
|
||||
@@ -841,11 +841,15 @@ test("Bounce Road plays in the real window: its board's shape and cars big enoug
|
||||
await step(s, 4, 16);
|
||||
await until(async () => (await you()).stage === 2, 5000);
|
||||
await step(s, 10, 16);
|
||||
await s.page.evaluate(() => {
|
||||
await s.page.evaluate(async () => {
|
||||
const { ensureRoad } = await import("/activities/bounce.js");
|
||||
const r = window.__bounce.round;
|
||||
const me = r.cars[0];
|
||||
r.lives = 1;
|
||||
const hole = r.road.holes.find((h) => h.d0 > me.d);
|
||||
// Stages are short and dealt at random: build on to the next hole, and stay on its stage, so no stage line hands a life back on the way.
|
||||
ensureRoad(r.road, me.d + 9000);
|
||||
const hole = r.road.holes.find((h) => h.d0 > me.d && h.kind !== "draw");
|
||||
while (r.road.stageAt[r.stage] <= hole.d0) r.stage++;
|
||||
Object.assign(me, { air: 0, d: hole.d0 - 3, v: 20, bubble: false });
|
||||
});
|
||||
await step(s, 120, 16);
|
||||
@@ -2715,10 +2719,11 @@ test("Flock Dash plays in the real window: its board's shape, Enter starts a rou
|
||||
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, Flock Dash's three, 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/flock.js", "activities/flock-draw.js", "activities/flock-sfx.js", "activities.js", "tones.js", "music.js", "activities/snake.js", "activities/snake-music.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/storLine truncated
|
||||
for (const file of ["activities/flock.js", "activities/flock-draw.js", "activities/flock-sfx.js", "activities.js", "tones.js", "music.js", "activities/snake.js", "activities/snake-music.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/storLine truncated
|
||||
assert.ok(servable.includes(`"${file}"`), `SERVABLE includes ${file}`);
|
||||
}
|
||||
for (let n = 1; n <= 5; n++) {
|
||||
assert.ok(servable.includes(`"activities/flock-dash/${n}.mp3"`), `SERVABLE includes activities/flock-dash/${n}.mp3`);
|
||||
}
|
||||
assert.ok(!servable.includes("activities/bounce-road/"), "Bounce Road's music is synthesized: no mp3 of its own is served");
|
||||
});
|
||||
@@ -20,6 +20,8 @@ import { MUSIC_TRACKS as TRAILS_TRACKS } from "../src/web-console/public/activit
|
||||
import trailsSfx from "../src/web-console/public/activities/trails-sfx.js";
|
||||
import { MUSIC_TRACKS as FLOCK_TRACKS } from "../src/web-console/public/activities/flock.js";
|
||||
import flockSfx from "../src/web-console/public/activities/flock-sfx.js";
|
||||
import { MUSIC_TRACKS as BOUNCE_TRACKS } from "../src/web-console/public/activities/bounce.js";
|
||||
import bounceSfx from "../src/web-console/public/activities/bounce-sfx.js";
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const GAMES = path.join(ROOT, "src/web-console/public/activities");
|
||||
@@ -440,6 +442,43 @@ class FakeAudio {
|
||||
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
test("music: Bounce Road lists exactly the tracks it has, each a real track that no other game defines, and no recorded songs", () => {
|
||||
const tracks = new Set(musicNames());
|
||||
assert.equal(bounceSfx.songs, undefined, "its music is note data, not recordings");
|
||||
assert.deepEqual([...BOUNCE_TRACKS].sort(), Object.keys(bounceSfx.music).sort(), "the game lists the tracks its sound file has");
|
||||
for (const name of BOUNCE_TRACKS) {
|
||||
assert.ok(tracks.has(name), `track "${name}" exists`);
|
||||
assert.equal(MUSIC_TABLES.filter((t) => Object.hasOwn(t, name)).length, 1, `${name} is defined once`);
|
||||
}
|
||||
assert.ok(![...SERVABLE].some((f) => f.startsWith("activities/bounce-road/")), "no Bounce Road mp3 is served");
|
||||
});
|
||||
|
||||
test("music: a track says it is playing until it has run through, then that it ended while it loops on, and a restart takes it back to its top", async () => {
|
||||
const saved = { sound: looks.sound, ctor: globalThis.AudioContext };
|
||||
globalThis.AudioContext = AUDIO.Ctx;
|
||||
try {
|
||||
hushMusic();
|
||||
looks.sound = true;
|
||||
const name = BOUNCE_TRACKS[0];
|
||||
assert.equal(music(name, 1, 1, { restart: true }), "playing", "from its top");
|
||||
let heard = "playing";
|
||||
for (let k = 0; k < 400 && heard !== "ended"; k++) {
|
||||
await sleep(25);
|
||||
heard = music(name, 1, 1);
|
||||
}
|
||||
assert.equal(heard, "ended", "run through");
|
||||
assert.equal(music(name, 1, 1), "ended", "and it says so for as long as it loops on");
|
||||
assert.equal(music(name, 1, 1, { restart: true }), "playing", "a restart plays it again");
|
||||
assert.equal(music(name, 1, 0), undefined, "a volume of 0: nothing playing");
|
||||
looks.sound = false;
|
||||
assert.equal(music(name, 1, 1), undefined, "Play sounds off: nothing playing");
|
||||
} finally {
|
||||
hushMusic();
|
||||
looks.sound = saved.sound;
|
||||
globalThis.AudioContext = saved.ctor;
|
||||
}
|
||||
});
|
||||
|
||||
async function withSongs(fn) {
|
||||
const saved = { sound: looks.sound, Audio: globalThis.Audio };
|
||||
globalThis.Audio = FakeAudio;
|
||||
|
||||
Reference in new issue
Block a user