mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-17 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
@@ -42,7 +42,7 @@ export const ACTIVITIES = Object.freeze([
|
||||
entry("rapids", "Rapids Run", "Blast up the winding river, grab charge before you run dry, smash every dam."),
|
||||
entry("fuse", "Hot Potato", "Pass the bomb before it blows. Last one standing wins."),
|
||||
entry("hop", "Crossing Rush", "Hop through traffic and rivers. Race your rivals to the top."),
|
||||
entry("bounce", "Bounce Road", "Ten wild stages of toy-car mayhem. Jump, stomp and outrun the Monster truck."),
|
||||
entry("bounce", "Bounce Road", "Toy-car mayhem: jump, stomp, fire rockets and beat five bosses. No two runs alike.", { music: 70 }),
|
||||
entry("ghoul", "Ghoul Rush", "Run and gun through a pitch-dark haunted house. Keep moving.", { music: 65, module: "/activities/ghoul-rush/ghoul.js" }),
|
||||
entry("flock", "Flock Dash", "Lead your flock through the sunset sky. Dodge everything, keep the line.", { music: 70 }),
|
||||
]);
|
||||
|
||||
@@ -127,6 +127,15 @@ export const CAR_STYLES = deep({
|
||||
taxi: { aspect: 2.05, paint: "#ffc61a", accent: "#1d1a17", body: { w: 0.85, nose: 0.72, nl: 0.12, tail: 0.8, tl: 0.09 }, wheels: { w: 0.2, l: 0.15, at: [0.19, 0.8] }, cabin: { w: 0.84, ws: 0.29, rf: 0.41, rr: 0.64, rw: 0.75 }, head: "slim", tails: "wide", sign: true, checker: true },
|
||||
jeep: { aspect: 1.62, paint: "#5b7a3a", accent: "#2b2a27", body: { w: 0.84, nose: 0.9, nl: 0.05, tail: 0.94, tl: 0.03, y1: 0.9 }, wheels: { w: 0.23, l: 0.18, at: [0.19, 0.75] }, cabin: { w: 0.86, ws: 0.3, rf: 0.36, rr: 0.84, rw: 0.86 }, head: "round", tails: "tall", open: "jeep", spare: true, grille: true },
|
||||
monster: { aspect: 1.45, paint: "#2e7d32", accent: "#ffd84a", body: { w: 0.6, nose: 0.82, nl: 0.1, tail: 0.92, tl: 0.05, y0: 0.06, y1: 0.94 }, wheels: { w: 0.32, l: 0.3, at: [0.21, 0.79] }, cabin: { w: 0.86, ws: 0.3, rf: 0.39, rr: 0.55, rw: 0.59 }, head: "square", tails: "tall", bed: [0.62, 0.91], big: true, flames: true },
|
||||
// The later rivals: a squat armored car, an open buggy, a bubble car, a long toy bus, a tiny runabout, a tow truck, the friendly supply truck (white, a green stripe) and the Big Rig's tanker.
|
||||
armor: { aspect: 1.62, paint: "#b8c2cc", accent: "#2b2f38", body: { w: 0.92, nose: 0.9, nl: 0.05, tail: 0.94, tl: 0.04 }, wheels: { w: 0.2, l: 0.21, at: [0.2, 0.8] }, cabin: { w: 0.66, ws: 0.33, rf: 0.38, rr: 0.7, rw: 0.73 }, head: "slit", tails: "bar", ridges: true, push: true, grille: true },
|
||||
buggy: { aspect: 1.68, paint: "#ffa63d", accent: "#2b2a27", body: { w: 0.66, nose: 0.5, nl: 0.26, tail: 0.84, tl: 0.08, y0: 0.03, y1: 0.95 }, wheels: { w: 0.26, l: 0.21, at: [0.2, 0.8] }, cabin: { w: 0.9, ws: 0.3, rf: 0.36, rr: 0.8, rw: 0.82 }, head: "round", tails: "round", open: "jeep" },
|
||||
bubble: { aspect: 1.81, paint: "#dfe8ff", accent: "#7f8fb5", body: { w: 0.88, nose: 0.46, nl: 0.3, tail: 0.5, tl: 0.28 }, wheels: { w: 0.18, l: 0.15, at: [0.24, 0.76] }, cabin: { w: 0.9, ws: 0.2, rf: 0.36, rr: 0.66, rw: 0.84 }, head: "round", tails: "round", sunroof: true },
|
||||
bus: { aspect: 2.2, paint: "#49b6ff", accent: "#ffd84a", body: { w: 0.9, nose: 0.86, nl: 0.05, tail: 0.92, tl: 0.03 }, wheels: { w: 0.18, l: 0.11, at: [0.14, 0.62, 0.86] }, cabin: { w: 0.92, ws: 0.04, rf: 0.1, rr: 0.95, rw: 0.975 }, head: "square", tails: "tall", ridges: true, rails: true, stripes: true },
|
||||
mini: { aspect: 1.6, paint: "#ff9ec4", accent: "#f4f1ea", body: { w: 0.86, nose: 0.7, nl: 0.16, tail: 0.84, tl: 0.08 }, wheels: { w: 0.24, l: 0.2, at: [0.21, 0.79] }, cabin: { w: 0.84, ws: 0.28, rf: 0.4, rr: 0.8, rw: 0.9 }, head: "round", tails: "round", stripes: true },
|
||||
tow: { aspect: 1.87, paint: "#ff5d3a", accent: "#ffd84a", body: { w: 0.86, nose: 0.8, nl: 0.09, tail: 0.94, tl: 0.03 }, wheels: { w: 0.21, l: 0.16, at: [0.18, 0.8] }, cabin: { w: 0.86, ws: 0.2, rf: 0.29, rr: 0.44, rw: 0.48 }, head: "square", tails: "tall", bed: [0.52, 0.95], push: true, grille: true },
|
||||
supply: { aspect: 1.96, paint: "#f4f1ea", accent: "#2fbf71", body: { w: 0.86, nose: 0.84, nl: 0.07, tail: 0.92, tl: 0.03, y0: 0, y1: 0.28 }, wheels: { w: 0.19, l: 0.13, at: [0.14, 0.82] }, cabin: { w: 0.9, ws: 0.04, rf: 0.12, rr: 0.24, rw: 0.25 }, head: "round", tails: "wide", box: [0.29, 1] },
|
||||
tanker: { aspect: 2.43, paint: "#d6dbe2", accent: "#e8483c", body: { w: 0.84, nose: 0.86, nl: 0.05, tail: 0.92, tl: 0.03, y0: 0, y1: 0.21 }, wheels: { w: 0.17, l: 0.085, at: [0.09, 0.62, 0.76, 0.9] }, cabin: { w: 0.9, ws: 0.03, rf: 0.08, rr: 0.18, rw: 0.19 }, head: "quad", tails: "bar", box: [0.225, 1], push: true },
|
||||
});
|
||||
|
||||
export const STYLE_NAMES = Object.freeze(Object.keys(CAR_STYLES));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Plan2Code Web Console - Bounce Road's drawing: the road a chunk at a time, the layers over it (from bounce-scenery.js), the cars (from bounce-cars.js, Planny's convertible and every rival's), jumps and their landing rings, the pills, the stage bar, the banners and the start and end screens, from a view bounce.js refills.
|
||||
// Plan2Code Web Console - Bounce Road's drawing: the road a chunk at a time, the layers over it (from bounce-scenery.js), the cars (from bounce-cars.js, Planny's convertible and every rival's; the three bosses that are no car, and what the rivals carry, from bounce-extras.js), the weapons, jumps and their landing rings, the pills and the Fever meter, the stage bar, a boss's health bar, the banners and the start and end screens with their logo, from a view bounce.js refills.
|
||||
//
|
||||
// Drawing only: no rules and no state of its own beyond the chunks of road
|
||||
// it keeps. bounce.js hands drawScene() one view object of the moment (the
|
||||
@@ -19,9 +19,10 @@
|
||||
|
||||
import { drawPill, LIVES, livesText } from "./pills.js";
|
||||
import { drawCarBody, drawCarShadow } from "./bounce-cars.js";
|
||||
import { DARK_INK, LIGHT_INK, LOOKS, better, circle, contrast, drawBlocks, drawFireflies, drawHazardsHigh, drawHazardsLow, drawItems, drawNight, drawPads, drawRow, drawSigns, drawStars, drawTimed, ellipse, luminance, lookOf, roundRect, star, stageColor } from "./bounce-scenery.js";
|
||||
import { DARK_INK, LIGHT_INK, LOOKS, better, circle, contrast, drawBeams, drawBlocks, drawFireflies, drawHazardsHigh, drawHazardsLow, drawItems, drawLava, drawNight, drawPads, drawRain, drawRow, drawSheen, drawSigns, drawStars, drawTimed, ellipse, luminance, lookOf, roundRect, star, stageColor } from "./bounce-scenery.js";
|
||||
import { CUSTOM_STYLES, drawBossBar, drawBossBody, drawBossShadow, drawCarExtras, drawFever, drawPulls, drawScanlines, drawSpills, drawThreatsHigh, drawThreatsLow, drawTitle, drawYouOver, drawYouUnder } from "./bounce-extras.js";
|
||||
|
||||
export { DARK_INK, LIGHT_INK, LOOKS, contrast, luminance, lookOf, stageColor };
|
||||
export { CUSTOM_STYLES, DARK_INK, LIGHT_INK, LOOKS, contrast, luminance, lookOf, stageColor };
|
||||
|
||||
const FALLBACK_COLORS = Object.freeze({ board: "#ffffff", line: "#e4ddd1", you: "#206cc3", ink: "#1d1a17" });
|
||||
|
||||
@@ -45,6 +46,8 @@ export function readColors(canvas) {
|
||||
export const GOLD = "#f5b301";
|
||||
export const DANGER = "#e2553f";
|
||||
const SHADE = "rgba(0, 0, 0, 0.55)";
|
||||
// Where a power-up's name flashes, in units down the field.
|
||||
export const TOAST_Y = 7;
|
||||
const BANNER_SHADE = "rgba(0, 0, 0, 0.32)";
|
||||
const EDGE_DARK = "rgba(0, 0, 0, 0.75)";
|
||||
|
||||
@@ -202,12 +205,18 @@ function carOpts(car, v) {
|
||||
if (car.mode === "chase") o.siren = v.clock;
|
||||
}
|
||||
if (car.kind === "racer") o.number = 1 + (car.id % 9);
|
||||
if (car.kind === "brick") o.brake = car.mode === "brake";
|
||||
if (car.kind === "monster") o.damage = 1 - car.hp / 5;
|
||||
if (car.kind === "racer" || car.kind === "nudge") o.boost = car.mode === "chase";
|
||||
if (car.kind === "brick" || car.kind === "tanker") o.brake = car.mode === "brake";
|
||||
// A boss shows its hits; the three that are no car take their own state.
|
||||
if (spec.boss) o.damage = Math.max(0, 1 - car.hp / (car.hpMax || spec.hp || 1));
|
||||
if (car.kind === "racer" || car.kind === "nudge" || car.kind === "slasher") o.boost = car.mode === "chase";
|
||||
if (CUSTOM_STYLES.includes(spec.style)) o.mode = car.mode;
|
||||
return [spec.style, o];
|
||||
}
|
||||
|
||||
// How far the Whirlybird's body is drawn up the board from its shadow at
|
||||
// its full height.
|
||||
const LIFT_RISE = 7;
|
||||
|
||||
// Where a car is drawn, or null off the board: its middle, its tumble's
|
||||
// spin and fade.
|
||||
function placeOf(car, v) {
|
||||
@@ -227,43 +236,60 @@ function placeOf(car, v) {
|
||||
alpha = car.id === 0 ? 1 : Math.max(0, 1 - out * 1.1);
|
||||
} else if (how === "gone") alpha = Math.max(0, 1 - out);
|
||||
if (car.id === 0 && car.ghostMs > 0 && Math.floor(v.clock / 90) % 2 === 0) alpha *= 0.45;
|
||||
// A rival spinning on your oil turns as it slides; a Phantom out of reach
|
||||
// and the Robo-Vac driving back through things are see-through.
|
||||
if (!how && car.spinMs > 0) spin = car.spinMs * 0.012;
|
||||
if (car.phased && car.out <= 0) alpha *= 0.28;
|
||||
else if (car.thru && car.out <= 0) alpha *= 0.5;
|
||||
return alpha > 0 ? { x: car.x, y, spin, alpha, scale } : null;
|
||||
}
|
||||
|
||||
// A car where it is, in one of two passes: its shadow on the road (placed
|
||||
// upright, only its footprint turned with a tumble), or its body (lifted
|
||||
// for a jump by bounce-cars.js), turned and faded through its tumble once
|
||||
// it is out: tipping, sinking, falling or flattened.
|
||||
// it is out: tipping, sinking, falling or flattened. The three bosses that
|
||||
// are no car (CUSTOM_STYLES) go to bounce-extras.js, which also draws what
|
||||
// a rival carries over its body. The Whirlybird's shadow stays on the road
|
||||
// where it is; its body is drawn up the board and bigger by its `lift`.
|
||||
function drawCar(ctx, car, v, pass) {
|
||||
const at = placeOf(car, v);
|
||||
if (!at) return;
|
||||
const [style, o] = carOpts(car, v);
|
||||
const custom = CUSTOM_STYLES.includes(style);
|
||||
const lift = car.kind === "chopper" && car.out <= 0 ? Math.max(0, Math.min(1, car.lift || 0)) : 0;
|
||||
const was = ctx.globalAlpha;
|
||||
ctx.globalAlpha = was * at.alpha;
|
||||
ctx.save();
|
||||
ctx.translate(at.x, at.y);
|
||||
ctx.translate(at.x, at.y - (pass === "shadow" ? 0 : lift * LIFT_RISE));
|
||||
if (pass !== "shadow" && at.spin && typeof ctx.rotate === "function") ctx.rotate(at.spin);
|
||||
if (at.scale !== 1) ctx.scale(at.scale, at.scale);
|
||||
if (pass === "shadow") {
|
||||
o.turn = at.spin;
|
||||
drawCarShadow(ctx, style, o);
|
||||
if (lift) o.fade = lift;
|
||||
if (custom) drawBossShadow(ctx, style, o);
|
||||
else drawCarShadow(ctx, style, o);
|
||||
} else {
|
||||
o.shadow = false;
|
||||
drawCarBody(ctx, style, o);
|
||||
if (lift) o.air = Math.max(o.air, lift);
|
||||
if (custom) drawBossBody(ctx, style, o);
|
||||
else drawCarBody(ctx, style, o);
|
||||
drawCarExtras(ctx, car, v, o, was);
|
||||
}
|
||||
ctx.restore();
|
||||
ctx.globalAlpha = was;
|
||||
if (car.kind === "monster" && pass !== "shadow" && car.out <= 0) drawBossLives(ctx, car, v, at);
|
||||
if (car.id !== 0 && pass !== "shadow" && car.out <= 0 && v.rivals[car.kind].boss) drawBossLives(ctx, car, v, at, lift * LIFT_RISE);
|
||||
}
|
||||
|
||||
// The Monster's lives: a pip each above it, lit while it has them.
|
||||
function drawBossLives(ctx, car, v, at) {
|
||||
const n = 5;
|
||||
const y = at.y - car.l / 2 - 2.4 - v.heightOf(car) * 4;
|
||||
// A boss's lives: a pip each above it (a star each for the Monster), lit
|
||||
// while it has them. `rise` is how far up the board its body is drawn.
|
||||
function drawBossLives(ctx, car, v, at, rise = 0) {
|
||||
const n = car.hpMax || v.rivals[car.kind].hp || 0;
|
||||
const y = Math.max(6.4, at.y - rise - car.l / 2 - 2.4 - v.heightOf(car) * 4);
|
||||
for (let k = 0; k < n; k++) {
|
||||
const x = at.x + (k - (n - 1) / 2) * 2.2;
|
||||
star(ctx, x, y, 0.95, 0.42);
|
||||
ctx.fillStyle = k < car.hp ? GOLD : "rgba(0, 0, 0, 0.4)";
|
||||
if (car.kind === "monster") star(ctx, x, y, 0.95, 0.42);
|
||||
else roundRect(ctx, x - 0.75, y - 0.6, 1.5, 1.2, 0.35);
|
||||
ctx.fillStyle = k < car.hp ? (car.kind === "monster" ? GOLD : DANGER) : "rgba(0, 0, 0, 0.4)";
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = EDGE_DARK;
|
||||
ctx.lineWidth = 0.2;
|
||||
@@ -274,22 +300,40 @@ function drawBossLives(ctx, car, v, at) {
|
||||
// Where a car in the air comes down (its speed holds up there): a ring on
|
||||
// the road, in red for a rival, so a landing on you never comes from
|
||||
// nowhere, and in your highlight, the size of your car, for you, so you can
|
||||
// see whether a jump ends on a rival, the road or the water.
|
||||
// see whether a jump ends on a rival, the road or the water. Yours turns
|
||||
// red, crossed out, while it sits over a Spike: its roof is no place to
|
||||
// land.
|
||||
function drawLandings(ctx, v) {
|
||||
for (const car of v.round.cars) {
|
||||
if (car.air <= 0 || car.out > 0) continue;
|
||||
const y = v.yOf(car.d + (car.v * car.air) / 1000);
|
||||
const secs = car.air / 1000;
|
||||
const y = v.yOf(car.d + car.v * secs);
|
||||
if (y < -3 || y > v.g.FIELD_H + 3) continue;
|
||||
const mine = car.id === 0;
|
||||
const big = car.kind === "monster";
|
||||
const big = car.kind === "monster" || car.kind === "cat";
|
||||
const r = mine ? car.w / 2 : big ? car.w / 2 : 1.6 + (car.air / Math.max(1, car.airMax)) * 1.6;
|
||||
let spiked = false;
|
||||
if (mine) {
|
||||
for (const o of v.round.cars) {
|
||||
if (o.id === 0 || o.out > 0 || o.phased || !v.rivals[o.kind].spiky) continue;
|
||||
if (Math.abs(o.x - car.x) < o.w / 2 + 1 && Math.abs(o.d + o.v * secs - (car.d + car.v * secs)) < o.l / 2 + 1.5) spiked = true;
|
||||
}
|
||||
}
|
||||
ellipse(ctx, car.x, y, r, mine || big ? car.l / 2 : r * 0.8);
|
||||
ctx.strokeStyle = EDGE_DARK;
|
||||
ctx.lineWidth = 0.7;
|
||||
ctx.stroke();
|
||||
ctx.strokeStyle = mine ? v.colors.you : DANGER;
|
||||
ctx.lineWidth = 0.35;
|
||||
ctx.strokeStyle = mine && !spiked ? v.colors.you : DANGER;
|
||||
ctx.lineWidth = spiked ? 0.5 : 0.35;
|
||||
ctx.stroke();
|
||||
if (spiked) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(car.x - r * 0.6, y - car.l * 0.3);
|
||||
ctx.lineTo(car.x + r * 0.6, y + car.l * 0.3);
|
||||
ctx.moveTo(car.x + r * 0.6, y - car.l * 0.3);
|
||||
ctx.lineTo(car.x - r * 0.6, y + car.l * 0.3);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,6 +402,7 @@ function drawHud(ctx, v) {
|
||||
ctx.fillRect(0, 0, g.W, g.HUD_H);
|
||||
ctx.fillStyle = colors.line;
|
||||
ctx.fillRect(0, g.HUD_H - 0.25, g.W, 0.25);
|
||||
drawFever(ctx, v);
|
||||
}
|
||||
|
||||
// The pills, painted after the field so a row spilled below the strip (the
|
||||
@@ -458,14 +503,16 @@ function drawTally(ctx, v, lines) {
|
||||
// the state, the pill numbers and the lines for the start and end screens.
|
||||
export function drawScene(ctx, v) {
|
||||
const { g, round } = v;
|
||||
v.night = v.stageFor(round.stage).id === "night";
|
||||
const spec = v.stageFor(round.stage);
|
||||
// Dark for Night Lights and for any stage with its lights out.
|
||||
v.night = spec.dark === true;
|
||||
ctx.save();
|
||||
ctx.scale(v.u, v.u);
|
||||
ctx.fillStyle = v.colors.board;
|
||||
ctx.fillRect(0, 0, g.W, g.H);
|
||||
drawHud(ctx, v);
|
||||
drawBar(ctx, v);
|
||||
if (!v.lines || v.lines.road !== v.road || v.lines.count !== v.road.stageAt.length) v.lines = linesOf(v.road, g.ROW);
|
||||
if (!v.lines || v.lines.road !== v.road || v.lines.count !== v.road.stageAt.length || v.lines.last !== v.road.stageAt.at(-1)) v.lines = linesOf(v.road, g.ROW);
|
||||
ctx.translate(g.PAD, g.HUD_H);
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
@@ -473,14 +520,20 @@ export function drawScene(ctx, v) {
|
||||
if (typeof ctx.clip === "function") ctx.clip();
|
||||
if (v.shake) ctx.translate(v.shake.x, v.shake.y);
|
||||
drawRoad(ctx, v);
|
||||
drawLava(ctx, v);
|
||||
drawTimed(ctx, v);
|
||||
drawPads(ctx, v);
|
||||
drawSpills(ctx, v);
|
||||
drawSheen(ctx, v);
|
||||
drawSigns(ctx, v);
|
||||
drawItems(ctx, v);
|
||||
drawBlocks(ctx, v);
|
||||
drawHazardsLow(ctx, v);
|
||||
drawThreatsLow(ctx, v);
|
||||
drawStars(ctx, v);
|
||||
drawLandings(ctx, v);
|
||||
const mine = placeOf(round.cars[0], v);
|
||||
if (mine) drawYouUnder(ctx, v, mine);
|
||||
// Cars further up the road first, those in the air over the rest; every
|
||||
// shadow before any car, so no car's shadow falls across another car.
|
||||
const order = v.order;
|
||||
@@ -489,6 +542,8 @@ export function drawScene(ctx, v) {
|
||||
order.sort((a, b) => (a.air > 0) - (b.air > 0) || b.d - a.d);
|
||||
for (const car of order) drawCar(ctx, car, v, "shadow");
|
||||
for (const car of order) drawCar(ctx, car, v, "body");
|
||||
if (mine) drawYouOver(ctx, v, mine);
|
||||
drawPulls(ctx, v);
|
||||
drawHazardsHigh(ctx, v);
|
||||
for (const p of v.fx.parts) {
|
||||
ctx.globalAlpha = Math.max(0, p.life / p.max);
|
||||
@@ -507,10 +562,15 @@ export function drawScene(ctx, v) {
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.globalAlpha = 1;
|
||||
drawRain(ctx, v);
|
||||
if (v.night) {
|
||||
drawNight(ctx, v);
|
||||
drawFireflies(ctx, v);
|
||||
if (spec.id === "night") drawFireflies(ctx, v);
|
||||
// A laser's beam again, over the dark, so it never hides in it.
|
||||
drawBeams(ctx, v);
|
||||
}
|
||||
// What flies and what blows up, bright over everything, the dark too.
|
||||
drawThreatsHigh(ctx, v);
|
||||
if (v.shake) ctx.translate(-v.shake.x, -v.shake.y);
|
||||
for (const f of v.fx.floats) {
|
||||
ctx.globalAlpha = Math.min(1, (f.life / f.max) * 1.6);
|
||||
@@ -535,8 +595,19 @@ export function drawScene(ctx, v) {
|
||||
ctx.fillRect(0, 0, g.FIELD_W, g.FIELD_H);
|
||||
ctx.globalAlpha = 1;
|
||||
}
|
||||
drawBossBar(ctx, v, label);
|
||||
if (v.state === "running" && v.banner) drawBanner(ctx, v, v.banner);
|
||||
// A power-up just taken: its name, flashed near the top of the field.
|
||||
if (v.state === "running" && v.toast) {
|
||||
const p = 1 - v.toast.life / v.toast.max;
|
||||
const pop = p < 0.15 ? 0.6 + (p / 0.15) * 0.6 : p < 0.28 ? 1.2 - ((p - 0.15) / 0.13) * 0.2 : 1;
|
||||
ctx.globalAlpha = p > 0.75 ? Math.max(0, (1 - p) / 0.25) : 1;
|
||||
label(ctx, v.toast.text.toUpperCase(), g.FIELD_W / 2, v.hud.boss ? TOAST_Y + 7 : TOAST_Y, 4 * pop, v.toast.color, "center", g.FIELD_W - 4);
|
||||
ctx.globalAlpha = 1;
|
||||
}
|
||||
if (v.title) drawTitle(ctx, v, label);
|
||||
if (v.tally) drawTally(ctx, v, v.tally);
|
||||
drawScanlines(ctx, v);
|
||||
ctx.restore();
|
||||
ctx.translate(-g.PAD, -g.HUD_H);
|
||||
drawPills(ctx, v);
|
||||
@@ -550,5 +621,6 @@ function linesOf(road, row) {
|
||||
for (const d of road.stageAt) if (d > 0) set.add(Math.floor(d / row));
|
||||
set.road = road;
|
||||
set.count = road.stageAt.length;
|
||||
set.last = road.stageAt.at(-1);
|
||||
return set;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,610 @@
|
||||
// Plan2Code Web Console - bounce: its music, twenty chip tracks built from short scores, merged into bounce-sfx.js beside the sounds; defines only.
|
||||
//
|
||||
// The car's radio: twenty fast arcade tunes, dealt in a new order each run
|
||||
// (MUSIC_TRACKS and dealMusic in bounce.js). Nothing is recorded: each is note
|
||||
// data for music.js's sequencer, the shape it documents,
|
||||
// { bpm, rush, voices, patterns, order }. Writing twenty of those out step by
|
||||
// step would be a wall of text, so each tune is a short score (SCORES) that
|
||||
// build() turns into a track when the file loads:
|
||||
//
|
||||
// { title, key, scale, bpm, kit, bass, arp, drums, A: { chords, lead }, B: { chords, lead } }
|
||||
//
|
||||
// `key` is the tonic as a MIDI note for the bass (36 is C2, 47 is B2) and
|
||||
// `scale` a name in SCALES. A part's `chords` is a chord a bar, each a scale
|
||||
// degree ("1 6 3 7"; the triad on it is built from the scale), cycled over the
|
||||
// part. `lead` is the tune: bars of sixteen characters, a sixteenth each, split
|
||||
// by spaces. "1" to "7" are the scale's degrees from the tonic, "a" to "g" the
|
||||
// same seven an octave up, "A" to "G" an octave down, "-" holds the note before
|
||||
// and "." rests. `bass`, `arp` and `drums` name a bar's pattern in BASS, ARP and
|
||||
// DRUMS (a part may name its own).
|
||||
//
|
||||
// Every tune plays the same way: four bars in, the tune without and then with
|
||||
// its arpeggio, the second tune twice, a four bar break and both tunes again.
|
||||
// The game sends how hot play is: an echo of the lead joins for a boss and a
|
||||
// harmony under it in a Fever, and the tempo climbs a little with both.
|
||||
// A name may be defined only once across tones.js and every game's file. No
|
||||
// imports.
|
||||
|
||||
const SCALES = {
|
||||
major: [0, 2, 4, 5, 7, 9, 11],
|
||||
minor: [0, 2, 3, 5, 7, 8, 10],
|
||||
dorian: [0, 2, 3, 5, 7, 9, 10],
|
||||
phrygian: [0, 1, 3, 5, 7, 8, 10],
|
||||
mixo: [0, 2, 4, 5, 7, 9, 10],
|
||||
harmonic: [0, 2, 3, 5, 7, 8, 11],
|
||||
};
|
||||
|
||||
const NOTES = ["C", "C#", "D", "Eb", "E", "F", "F#", "G", "Ab", "A", "Bb", "B"];
|
||||
const noteName = (midi) => NOTES[midi % 12] + (Math.floor(midi / 12) - 1);
|
||||
|
||||
// A scale degree (0 is the tonic; it may run below or past the octave) in semitones.
|
||||
const semis = (scale, d) => scale[((d % 7) + 7) % 7] + 12 * Math.floor(d / 7);
|
||||
|
||||
// A bar of bass: r the chord's root, R the root an octave up, t its third, f
|
||||
// its fifth.
|
||||
const BASS = {
|
||||
drive: "r.r.r.r.r.r.r.r.",
|
||||
octave: "r.R.r.R.r.R.r.R.",
|
||||
gallop: "r.rrr.rrr.rrr.rr",
|
||||
sixteen: "rrrrrrrrrrrrRrrr",
|
||||
synco: "r..r..r.r..r..R.",
|
||||
walk: "r.r.t.t.f.f.t.t.",
|
||||
funk: "r..r.r..R.r..rf.",
|
||||
rock: "r.r.r.r.r.r.f.R.",
|
||||
oom: "r.R.f.R.r.R.f.R.",
|
||||
};
|
||||
|
||||
// A bar of arpeggio: 0 the chord's root, 1 its third, 2 its fifth, 3 to 5 the
|
||||
// same an octave up, x the whole chord as a chip arpeggio on one note.
|
||||
const ARP = {
|
||||
up: "0123012301230123",
|
||||
updown: "0123432101234321",
|
||||
alberti: "0.2.1.2.0.2.1.2.",
|
||||
high: "3.5.4.5.3.5.4.5.",
|
||||
roll: "0120120120120123",
|
||||
stab: "x-..x-..x-.x-...",
|
||||
off: "..x...x...x...x.",
|
||||
skank: "..x-..x-..x-..x-",
|
||||
};
|
||||
|
||||
// A bar of drums: k kick, s snare, h hat, o open hat, K kick and hat, S snare
|
||||
// and hat, O kick and open hat, B kick and snare.
|
||||
const DRUMS = {
|
||||
rock: "K.h.S.h.K.K.S.h.",
|
||||
four: "K.o.B.o.K.o.B.o.",
|
||||
dnb: "K.h.S.h.h.K.S.h.",
|
||||
gallop: "K.hkS.hkK.hkS.hk",
|
||||
sixteen: "KhhhShhhKhKhShhh",
|
||||
half: "K.h.h.h.S.h.h.k.",
|
||||
hats: "h.h.h.h.h.h.h.h.",
|
||||
fill: "K.h.S.h.K.s.ssss",
|
||||
build: "k.k.k.k.kkkkssss",
|
||||
};
|
||||
|
||||
const DRUM_TOKENS = { k: "k", s: "s", h: "h", o: "o", K: "kh", S: "sh", O: "ko", B: "ks", ".": "." };
|
||||
|
||||
// The chips: a bass, a lead and an arpeggio voice each.
|
||||
const VIBRATO = { rate: 6, depth: 0.012, delay: 0.14 };
|
||||
const KITS = {
|
||||
// The triangle bass and thin squares of a grey home console.
|
||||
nes: {
|
||||
bass: { wave: "triangle", gain: 0.9, decay: 0.08, sustain: 0.55 },
|
||||
lead: { wave: "pulse", duty: 0.25, gain: 0.3, decay: 0.07, sustain: 0.7, vibrato: VIBRATO },
|
||||
arp: { wave: "pulse", duty: 0.125, gain: 0.13, decay: 0.05, sustain: 0.3 },
|
||||
},
|
||||
// Three square waves and nothing else.
|
||||
sms: {
|
||||
bass: { wave: "pulse", duty: 0.5, gain: 0.42, decay: 0.07, sustain: 0.45 },
|
||||
lead: { wave: "pulse", duty: 0.125, gain: 0.3, decay: 0.07, sustain: 0.7, vibrato: VIBRATO },
|
||||
arp: { wave: "pulse", duty: 0.25, gain: 0.12, decay: 0.05, sustain: 0.3 },
|
||||
},
|
||||
// Saw waves: an arcade cabinet's synth board.
|
||||
saw: {
|
||||
bass: { wave: "sawtooth", gain: 0.3, decay: 0.09, sustain: 0.5 },
|
||||
lead: { wave: "sawtooth", gain: 0.2, decay: 0.08, sustain: 0.75, vibrato: VIBRATO },
|
||||
arp: { wave: "pulse", duty: 0.25, gain: 0.12, decay: 0.05, sustain: 0.3 },
|
||||
},
|
||||
// A rounder board: a full square lead over a plucked triangle.
|
||||
fm: {
|
||||
bass: { wave: "triangle", gain: 0.9, decay: 0.07, sustain: 0.5 },
|
||||
lead: { wave: "square", gain: 0.22, decay: 0.06, sustain: 0.65, vibrato: VIBRATO },
|
||||
arp: { wave: "triangle", gain: 0.32, decay: 0.04, sustain: 0.2 },
|
||||
},
|
||||
// A home computer: a hollow pulse bass under a buzzing saw.
|
||||
c64: {
|
||||
bass: { wave: "pulse", duty: 0.25, gain: 0.42, decay: 0.08, sustain: 0.5 },
|
||||
lead: { wave: "sawtooth", gain: 0.19, decay: 0.08, sustain: 0.7, vibrato: { rate: 6.5, depth: 0.016, delay: 0.1 } },
|
||||
arp: { wave: "pulse", duty: 0.125, gain: 0.14, decay: 0.05, sustain: 0.3 },
|
||||
},
|
||||
};
|
||||
|
||||
// How hot play must be for the echo and the harmony to join, and how far
|
||||
// behind the lead the echo runs, in steps.
|
||||
const ECHO_FROM = 0.7;
|
||||
const HARMONY_FROM = 0.9;
|
||||
const ECHO_STEPS = 3;
|
||||
|
||||
// The beats a minute a track gains at full heat.
|
||||
const RUSH = 14;
|
||||
|
||||
const LEAD_CHARS = "ABCDEFG1234567abcdefg";
|
||||
|
||||
function build(score) {
|
||||
const scale = SCALES[score.scale];
|
||||
const kit = KITS[score.kit];
|
||||
// The lead's tonic sits two octaves over the bass's, so a tune tops out
|
||||
// around the top of a chip's sweet range, and the arpeggio in the octave
|
||||
// around middle C, whatever the key.
|
||||
const top = score.key + 24;
|
||||
const mid = score.key + (score.key < 43 ? 24 : 12);
|
||||
// A chord's root above `base`, kept within a fifth of it either way.
|
||||
const rootOf = (base, chord) => {
|
||||
const up = semis(scale, chord - 1);
|
||||
return base + (up > 7 ? up - 12 : up);
|
||||
};
|
||||
const tone = (chord, i) => semis(scale, chord - 1 + 2 * (i % 3)) - semis(scale, chord - 1) + 12 * Math.floor(i / 3);
|
||||
const chordsOf = (part, bars) => {
|
||||
const list = part.chords.split(/\s+/).filter(Boolean).map(Number);
|
||||
return Array.from({ length: bars }, (_, k) => list[k % list.length]);
|
||||
};
|
||||
const line = (bars) => bars.map((steps) => steps.join(" ")).join(" | ");
|
||||
const bassBars = (chords, name) =>
|
||||
chords.map((chord) =>
|
||||
[...(BASS[name] || name)].map((ch) => {
|
||||
if (ch === "." || ch === "-") return ch;
|
||||
const root = rootOf(score.key, chord);
|
||||
return noteName(root + (ch === "R" ? 12 : ch === "t" ? tone(chord, 1) : ch === "f" ? tone(chord, 2) : 0));
|
||||
}),
|
||||
);
|
||||
const arpBars = (chords, name) =>
|
||||
chords.map((chord) =>
|
||||
[...(ARP[name] || name)].map((ch) => {
|
||||
if (ch === "." || ch === "-") return ch;
|
||||
const root = rootOf(mid, chord);
|
||||
if (ch === "x") return `${noteName(root)}^0${tone(chord, 1)}${tone(chord, 2)}`;
|
||||
return noteName(root + tone(chord, Number(ch)));
|
||||
}),
|
||||
);
|
||||
const drumBars = (names) => names.map((name) => [...(DRUMS[name] || name)].map((ch) => DRUM_TOKENS[ch]));
|
||||
const leadSteps = (part) => [...part.lead.replace(/\s+/g, "")];
|
||||
const leadLine = (steps, shift) =>
|
||||
steps
|
||||
.map((ch) => {
|
||||
if (ch === "." || ch === "-") return ch;
|
||||
return noteName(top + semis(scale, LEAD_CHARS.indexOf(ch) - 7 + shift));
|
||||
})
|
||||
.join(" ");
|
||||
const echoOf = (steps) => [...steps.slice(-ECHO_STEPS), ...steps.slice(0, -ECHO_STEPS)];
|
||||
|
||||
// A tune's part: every voice, with a drum fill in its last bar.
|
||||
const tune = (part, withArp) => {
|
||||
const steps = leadSteps(part);
|
||||
const bars = steps.length / 16;
|
||||
const chords = chordsOf(part, bars);
|
||||
const beat = part.drums || score.drums;
|
||||
const out = {
|
||||
bass: line(bassBars(chords, part.bass || score.bass)),
|
||||
lead: leadLine(steps, 0),
|
||||
echo: leadLine(echoOf(steps), 0),
|
||||
harmony: leadLine(steps, -5),
|
||||
drums: line(drumBars(chords.map((_, k) => (k === bars - 1 ? "fill" : beat)))),
|
||||
};
|
||||
if (withArp) out.arp = line(arpBars(chords, part.arp || score.arp));
|
||||
return out;
|
||||
};
|
||||
// Four bars in: the bass and the hats, then the beat, then a roll.
|
||||
const intro = () => {
|
||||
const chords = chordsOf(score.A, 4);
|
||||
return {
|
||||
bass: line(bassBars(chords, score.A.bass || score.bass)),
|
||||
arp: line(arpBars(chords, score.A.arp || score.arp)),
|
||||
drums: line(drumBars(["hats", "hats", score.drums, "build"])),
|
||||
};
|
||||
};
|
||||
// The break: the tune drops out, the arpeggio climbs over a held bass and
|
||||
// the drums roll back in.
|
||||
const breakdown = () => {
|
||||
const chords = chordsOf(score.B, 4);
|
||||
return {
|
||||
bass: line(bassBars(chords, "r-------r---r-r-")),
|
||||
arp: line(arpBars(chords, "0123432101234321")),
|
||||
drums: line(drumBars(["half", "half", "half", "build"])),
|
||||
};
|
||||
};
|
||||
// The lead's chip again, quieter and without its vibrato.
|
||||
const quiet = ({ vibrato, ...voice }, from, gain) => ({ ...voice, gain: voice.gain * gain, from });
|
||||
const voices = {
|
||||
bass: kit.bass,
|
||||
lead: kit.lead,
|
||||
arp: kit.arp,
|
||||
drums: { kit: true, gain: 0.6 },
|
||||
echo: quiet(kit.lead, ECHO_FROM, 0.35),
|
||||
harmony: quiet(kit.lead, HARMONY_FROM, 0.5),
|
||||
};
|
||||
return {
|
||||
title: score.title,
|
||||
bpm: score.bpm,
|
||||
rush: RUSH,
|
||||
voices,
|
||||
patterns: { I: intro(), A1: tune(score.A, false), A: tune(score.A, true), B: tune(score.B, true), C: breakdown() },
|
||||
order: ["I", "A1", "A", "B", "B", "C", "A", "B"],
|
||||
};
|
||||
}
|
||||
|
||||
export const SCORES = [
|
||||
{
|
||||
title: "Turbo Sunrise",
|
||||
key: 45,
|
||||
scale: "minor",
|
||||
bpm: 160,
|
||||
kit: "nes",
|
||||
bass: "drive",
|
||||
arp: "up",
|
||||
drums: "rock",
|
||||
A: {
|
||||
chords: "1 6 3 7",
|
||||
lead: "5.5.3.5-..a-5.3. 6.6.3.6-..a-6.3. 5.5.3.5-..g-5.3. 4.4.2.4-..7-4.2. a.a.5.a-..c-b.a. a.a.6.a-..c-b.a. g.g.5.g-..b-a.g. g-..b-..d-..b-g-",
|
||||
},
|
||||
B: {
|
||||
chords: "6 7 1 1",
|
||||
bass: "octave",
|
||||
lead: "c-b-a-6-a-..6.a. b-a-g-5-g-..4.g. a-..5-..a.b.c-b- a-------..5.a.c. c-d-c-a-6-..a.c. d-c-b-g-b-..g.b. c-..a-..e-..c-b- a-------........",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Neon Overpass",
|
||||
key: 40,
|
||||
scale: "minor",
|
||||
bpm: 150,
|
||||
kit: "saw",
|
||||
bass: "sixteen",
|
||||
arp: "updown",
|
||||
drums: "four",
|
||||
A: {
|
||||
chords: "1 1 6 7",
|
||||
lead: "5-----3-5-----a- a---g-5-3---5--- 6-----a-c-----a- b-----g-b---d--- e-----c-e-----a- e---d-c-a---c--- c-----a-c---d-c- b-------g-..b.d.",
|
||||
},
|
||||
B: {
|
||||
chords: "4 4 6 7",
|
||||
lead: "d.d.d-c-a-..6-a- d.d.d-c-a-..c-d- c.c.c-a-6-..a-c- b.b.b-d-b-..g-b- f.f.f-d-a-..d-f- f-d-a-d-f-d-a-d- c.c.e-c-a-..a-c- b-..d-..g-b-d-g-",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Pixel Pursuit",
|
||||
key: 38,
|
||||
scale: "dorian",
|
||||
bpm: 168,
|
||||
kit: "sms",
|
||||
bass: "gallop",
|
||||
arp: "stab",
|
||||
drums: "gallop",
|
||||
A: {
|
||||
chords: "1 4",
|
||||
lead: "1.13.35.5.31.3.5 6.64.46.a.64.6.a 5.53.35.a.53.5.a a-6-4-6-a-..6.4. 1.13.35.5.31.3.5 6.64.46.a.64.6.a c.ca.a5.a.5a.c.e d-..a-..6-4-6-a-",
|
||||
},
|
||||
B: {
|
||||
chords: "7 4 1 1",
|
||||
bass: "drive",
|
||||
lead: "b-..g-..b-d-b-g- a-..6-..a-d-a-6- a.5.a.c-..a.5.3. 5-------..3.5.a. d-..b-..d-b-g-b- d-..a-..d-a-6-a- c.a.c.e-..c.a.5. a-------........",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Checkered Flag",
|
||||
key: 36,
|
||||
scale: "major",
|
||||
bpm: 172,
|
||||
kit: "nes",
|
||||
bass: "octave",
|
||||
arp: "alberti",
|
||||
drums: "rock",
|
||||
A: {
|
||||
chords: "1 5 6 4",
|
||||
lead: "3.5.a.c-..a.5.3. 2.5.7.b-..7.5.2. 3.6.a.c-..a.6.3. 4.6.a.d-..c.a.6. c-..a.5.c-..a.5. b-..g.5.b-..g.5. a-..6.3.a-..c.e. d-..c-..a-6-a-c-",
|
||||
},
|
||||
B: {
|
||||
chords: "4 5 3 6",
|
||||
bass: "drive",
|
||||
lead: "f-e-d-c-a-..c.d. e-d-b-g-b-..d.e. e-..g-..e-c-b-g- a-..c-..a-c-a-6- f-e-d-c-a-..c.d. e-d-b-g-b-..d.e. g-..e-..c-..e-g- a-------..5.6.7.",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Rocket Skates",
|
||||
key: 43,
|
||||
scale: "mixo",
|
||||
bpm: 156,
|
||||
kit: "fm",
|
||||
bass: "octave",
|
||||
arp: "off",
|
||||
drums: "four",
|
||||
A: {
|
||||
chords: "1 7 4 1",
|
||||
lead: "5.5.6.5.3-..5-.. 4.4.5.4.2-..4-.. 6.6.a.6.4-..6-.. 5-3-5-a-..5.3.1. a.a.b.a.5-..a-.. b.b.d.b.g-..b-.. d.d.c.a.6-..a-.. a-..5-..3-5-a-c-",
|
||||
},
|
||||
B: {
|
||||
chords: "4 1 7 1",
|
||||
lead: "d-..d.c.a-..6-a- c-..c.a.5-..3-5- b-..b.d.b-..g-b- a---5---a-b-c-b- d-..d.f.d-..a-d- e-..e.c.a-..c-e- d-..b-..g-..b-d- c-..a-..5-..a---",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Boss Rush",
|
||||
key: 40,
|
||||
scale: "phrygian",
|
||||
bpm: 176,
|
||||
kit: "c64",
|
||||
bass: "sixteen",
|
||||
arp: "roll",
|
||||
drums: "dnb",
|
||||
A: {
|
||||
chords: "1 2",
|
||||
lead: "1.1.5.1.1.5.1.3. 2.2.6.2.2.6.2.4. 1.1.5.1.a.5.3.1. 2-4-6-4-2-..4.2. 5.5.a.5.5.a.5.c. 6.6.b.6.6.b.6.d. c.a.5.3.c.a.5.3. b-..6-..4-6-b-d-",
|
||||
},
|
||||
B: {
|
||||
chords: "1 2 3 2",
|
||||
drums: "gallop",
|
||||
lead: "a-------5-a-b-a- b-------6-b-d-b- c-------g-c-e-c- d-..b-..6-..b-.. e-------c-e-c-a- f-------d-f-d-b- g-..e-..c-..e-g- f-d-b-6-b-d-f-d-",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Hairpin",
|
||||
key: 42,
|
||||
scale: "minor",
|
||||
bpm: 164,
|
||||
kit: "sms",
|
||||
bass: "synco",
|
||||
arp: "up",
|
||||
drums: "sixteen",
|
||||
A: {
|
||||
chords: "1 7 6 7",
|
||||
lead: "a-5.a-5.c-a.5-3. b-g.b-g.d-b.g-4. a-6.a-6.c-a.6-3. b-g.b-g.d---b--- a-5.a-5.c-a.5-3. b-g.b-g.d-b.g-4. c-a.c-a.f-c.a-6. d-------b-g-b-d-",
|
||||
},
|
||||
B: {
|
||||
chords: "4 6 7 1",
|
||||
bass: "drive",
|
||||
lead: "f.d.a.d.f.d.a.d. f.c.a.c.f.c.a.c. g.d.b.d.g.d.b.d. e---c---a-c-e-c- f.d.a.d.f.d.a.d. f.c.a.c.f.c.a.c. g-..d-..b-d-g-d- e-------c---a---",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Arcade Royale",
|
||||
key: 41,
|
||||
scale: "major",
|
||||
bpm: 152,
|
||||
kit: "nes",
|
||||
bass: "synco",
|
||||
arp: "high",
|
||||
drums: "sixteen",
|
||||
A: {
|
||||
chords: "4 5 3 6",
|
||||
lead: "6-a-d-c-..a.6.a. 7-b-e-d-..b.7.b. 5-g-c-b-..g.5.g. 6-a-c-e-..c.a.6. d-..c.a.d-..c.a. e-..d.b.e-..d.b. e-..c.g.e-..c.g. c-..a-..6-a-c-e-",
|
||||
},
|
||||
B: {
|
||||
chords: "2 5 1 6",
|
||||
bass: "octave",
|
||||
lead: "4.6.b.d-..b.6.4. 5.7.b.e-..b.7.5. 5.a.c.e-..c.a.5. 6.a.c.e-..c.a.6. d-b-6-b-d-..f-d- e-b-g-b-e-..g-e- e-c-a-c-e-..c-a- a-------..c.d.e.",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Nitro Boost",
|
||||
key: 47,
|
||||
scale: "minor",
|
||||
bpm: 174,
|
||||
kit: "saw",
|
||||
bass: "synco",
|
||||
arp: "roll",
|
||||
drums: "dnb",
|
||||
A: {
|
||||
chords: "1 3 7 6",
|
||||
lead: "5---..3.5---..a. g---..5.g---..c. b---..g.b---..d. c---a---6-a-c-a- e---..c.e---..a. e---..c.g---..e. d---..b.d---..g. f---c---a---c-..",
|
||||
},
|
||||
B: {
|
||||
chords: "4 1 6 7",
|
||||
bass: "sixteen",
|
||||
lead: "d..d..a.d..d..f. c..c..a.c..c..e. c..c..a.c..c..f. d..d..b.d..b.g.b f..f..d.f..f..a. e..e..c.e..e..a. f..f..c.f..c.a.c g---d---b---d---",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Dashboard Lights",
|
||||
key: 36,
|
||||
scale: "harmonic",
|
||||
bpm: 148,
|
||||
kit: "c64",
|
||||
bass: "rock",
|
||||
arp: "updown",
|
||||
drums: "rock",
|
||||
A: {
|
||||
chords: "1 4 5 1",
|
||||
lead: "1.3.5.a.c.a.5.3. 4.6.a.d.f.d.a.6. 5.7.b.e.g.e.b.7. a-..5-..3-5-a-.. c.a.5.a.c.a.5.a. d.a.6.a.d.a.6.a. e.b.g.b.e.b.g.b. c-------a-..5-..",
|
||||
},
|
||||
B: {
|
||||
chords: "6 4 5 5",
|
||||
lead: "c-a-6-a-c-..e-c- d-a-6-a-d-..f-d- e-b-g-b-e-..d-b- g-------e-d-b-g- c-a-6-a-c-..e-c- d-a-6-a-d-..f-d- e-..g-..b-..d-.. e-------g-------",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Speed Bump Boogie",
|
||||
key: 45,
|
||||
scale: "major",
|
||||
bpm: 160,
|
||||
kit: "fm",
|
||||
bass: "walk",
|
||||
arp: "stab",
|
||||
drums: "rock",
|
||||
A: {
|
||||
chords: "1 1 4 1 5 4 1 5",
|
||||
lead: "1.3.5.6.a.6.5.3. 1.3.5.6.a.6.5.3. 4.6.a.b.d.b.a.6. 1.3.5.6.a.6.5.3. 5.7.b.c.e.c.b.7. 4.6.a.b.d.b.a.6. a-..5.6.a-..c-.. b-..7-..5.7.b.e.",
|
||||
},
|
||||
B: {
|
||||
chords: "4 4 1 1 5 4 1 1",
|
||||
lead: "d-d.d-c.a-..6.a. d-d.d-f.d-..a.d. c-c.c-a.5-..3.5. c-c.c-e.c-..a.c. e-e.e-d.b-..g.b. d-d.d-c.a-..6.a. a.5.3.5.a.c.e.c. a-------........",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Jump Start",
|
||||
key: 38,
|
||||
scale: "major",
|
||||
bpm: 166,
|
||||
kit: "sms",
|
||||
bass: "octave",
|
||||
arp: "skank",
|
||||
drums: "rock",
|
||||
A: {
|
||||
chords: "1 4 5 1",
|
||||
lead: "5-a-c-a-5-..3.5. 6-a-d-a-6-..4.6. 7-b-e-b-7-..5.7. a---c-a-5---.... c-e-c-a-c-..a.c. d-f-d-a-d-..a.d. e-g-e-b-e-..d.b. a-------..5.a.c.",
|
||||
},
|
||||
B: {
|
||||
chords: "6 4 1 5",
|
||||
lead: "c.c.a.6.c.c.a.6. d.d.a.6.d.d.a.6. e.e.c.a.e.e.c.a. e.e.b.g.e-d-b-.. c.c.a.6.c.c.e.c. d.d.a.6.d.d.f.d. e-..c-..a-..5-.. 7-..b-..e-d-b-7-",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Tunnel Vision",
|
||||
key: 43,
|
||||
scale: "minor",
|
||||
bpm: 158,
|
||||
kit: "saw",
|
||||
bass: "sixteen",
|
||||
arp: "alberti",
|
||||
drums: "four",
|
||||
A: {
|
||||
chords: "1 1 3 7",
|
||||
lead: "a-..a.5.a-..c-a- 5-..5.3.5-..a-5- g-..g.5.g-..c-g- b-..b.g.b-..d-b- c-..c.a.c-..e-c- e-..d.c.a-..5-a- c-..c.g.c-..e-c- d-------b-..g-..",
|
||||
},
|
||||
B: {
|
||||
chords: "6 6 7 7",
|
||||
lead: "a-c-f-c-a-c-f-c- a-c-f-c-a-..c-a- b-d-g-d-b-d-g-d- b-d-g-d-b-..d-b- f---c---a---c--- f-e-c-a-c-..a-c- g---d---b---d--- g-..d-..b-d-g-..",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Rubber Burner",
|
||||
key: 40,
|
||||
scale: "minor",
|
||||
bpm: 170,
|
||||
kit: "c64",
|
||||
bass: "rock",
|
||||
arp: "stab",
|
||||
drums: "rock",
|
||||
A: {
|
||||
chords: "1 3 4 1",
|
||||
lead: "1.1.3.1.5.3.1.G. 3.3.5.3.7.5.3.2. 4.4.6.4.a.6.4.3. 1-3-5-3-1-..G.1. a.a.c.a.e.c.a.g. c.c.e.c.g.e.c.b. d.d.f.d.f.d.a.6. a-..5-..3-5-a-..",
|
||||
},
|
||||
B: {
|
||||
chords: "3 7 6 5",
|
||||
bass: "gallop",
|
||||
lead: "e-..c-..g-e-c-e- d-..b-..g-d-b-d- c-..a-..f-c-a-c- b-..g-..e-b-g-b- g-e-c-e-g-..e-c- g-d-b-d-g-..d-b- f-c-a-c-f-..c-a- e-------b-..g-..",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Coin-Op Carnival",
|
||||
key: 46,
|
||||
scale: "major",
|
||||
bpm: 154,
|
||||
kit: "nes",
|
||||
bass: "oom",
|
||||
arp: "off",
|
||||
drums: "gallop",
|
||||
A: {
|
||||
chords: "1 1 5 5 5 5 1 1",
|
||||
lead: "5.5.6.5.3.5.a-.. c.c.d.c.a.c.e-.. e.e.f.e.b.e.g-.. b.b.c.b.7.b.e-.. e.d.b.7.5.7.b.d. e-..b-..g-e-b-7- a.5.3.5.a.c.e.c. a-..5-..a-......",
|
||||
},
|
||||
B: {
|
||||
chords: "4 4 1 1 5 5 1 1",
|
||||
lead: "d-a-6-a-d-a-f-d- d.c.a.6.a-..6-a- c-a-5-a-c-a-e-c- c.a.5.3.5-..3-5- b-7-5-7-b-7-e-b- b.d.e.g.e-..d-b- a.c.e.c.a.5.3.5. a-------........",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Midnight Lane Change",
|
||||
key: 41,
|
||||
scale: "dorian",
|
||||
bpm: 146,
|
||||
kit: "fm",
|
||||
bass: "funk",
|
||||
arp: "stab",
|
||||
drums: "sixteen",
|
||||
A: {
|
||||
chords: "1 4",
|
||||
lead: "5..5.3.5..a.5.3. 6..6.4.6..a.6.4. 5..5.3.5..a.c.a. a-..6-..4.6.a.d. c..c.a.c..e.c.a. d..d.a.d..f.d.a. e..c.a.5..a.c.e. d-------a-6-4-..",
|
||||
},
|
||||
B: {
|
||||
chords: "7 4 1 1",
|
||||
lead: "b-d-b-g-..g.b.d. a-d-a-6-..6.a.d. c-..a.5.c-..a.5. a-------..5.a.c. d-b-g-b-d-..b-d- f-d-a-d-f-..d-f- e-c-a-c-e-c-a-5- a-------........",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Thunder Alley",
|
||||
key: 38,
|
||||
scale: "harmonic",
|
||||
bpm: 178,
|
||||
kit: "saw",
|
||||
bass: "gallop",
|
||||
arp: "up",
|
||||
drums: "gallop",
|
||||
A: {
|
||||
chords: "1 6 4 5",
|
||||
lead: "a.aa5.55a.aac.a. a.aa6.66a.aac.a. a.aa6.66d.ddf.d. b.bbg.gge.eeg.e. e-..c-..a-c-e-c- f-..c-..a-c-f-c- f-..d-..a-d-f-d- e-g-b-g-e-..g-..",
|
||||
},
|
||||
B: {
|
||||
chords: "4 5 1 1 6 5 1 1",
|
||||
bass: "sixteen",
|
||||
lead: "d.a.6.a.d.a.6.a. e.b.g.b.e.b.g.b. e.c.a.c.e.c.a.c. a-..5-..a-c-e-.. f.c.a.c.f.c.a.c. g.e.b.e.g.e.b.e. a.c.e.c.a.c.e.c. a-------........",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Sky Ramp",
|
||||
key: 39,
|
||||
scale: "major",
|
||||
bpm: 162,
|
||||
kit: "fm",
|
||||
bass: "drive",
|
||||
arp: "high",
|
||||
drums: "four",
|
||||
A: {
|
||||
chords: "1 3 4 5",
|
||||
lead: "3-5-a---..5.a.c. 5-7-b---..7.b.e. 6-a-d---..a.d.f. 7-b-e---b-e-b-7- c-e-c---..a.c.e. e-g-e---..c.e.g. f-d-a---..a.d.f. e-------b-..g-..",
|
||||
},
|
||||
B: {
|
||||
chords: "6 5 4 5",
|
||||
bass: "octave",
|
||||
lead: "a.c.a.6.a.c.e.c. b.d.b.7.b.d.e.d. a.d.a.6.a.d.f.d. b-..e-..g-e-b-.. c.e.c.a.c.e.f.e. b.e.b.g.b.e.g.e. d-..f-..d-a-6-a- b-------..5.7.b.",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Laser Lanes",
|
||||
key: 47,
|
||||
scale: "minor",
|
||||
bpm: 154,
|
||||
kit: "c64",
|
||||
bass: "octave",
|
||||
arp: "roll",
|
||||
drums: "four",
|
||||
A: {
|
||||
chords: "1 5 6 4",
|
||||
lead: "1.5.a.5.1.5.a.5. 2.5.b.5.2.5.b.5. 3.6.a.6.3.6.a.6. 4.6.a.6.d-a-6-4- c---a-5-c---e-c- b---g-5-b---e-b- c---a-6-c---f-c- d---a---f-d-a-..",
|
||||
},
|
||||
B: {
|
||||
chords: "6 7 5 1",
|
||||
bass: "sixteen",
|
||||
lead: "f-..f.c.a-..c-f- g-..g.d.b-..d-g- e-..e.b.7-..b-e- e---c---a-c-e-c- f.c.a.c.f.c.a.c. g.d.b.d.g.d.b.d. e.b.7.b.e.b.7.b. a-------..5-a-..",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Victory Lap",
|
||||
key: 43,
|
||||
scale: "major",
|
||||
bpm: 168,
|
||||
kit: "nes",
|
||||
bass: "drive",
|
||||
arp: "up",
|
||||
drums: "rock",
|
||||
A: {
|
||||
chords: "1 5 6 3 4 1 4 5",
|
||||
lead: "c-b-a-5-a-..5.a. b-a-7-5-7-..5.7. a-7-6-3-6-..3.6. 7-6-5-3-5-..3.5. 6-a-d-a-6-..a.d. 5-a-c-a-5-..a.c. 6-a-d-f-d-..a.d. e-..d-..b-d-e-g-",
|
||||
},
|
||||
B: {
|
||||
chords: "6 4 1 5",
|
||||
bass: "octave",
|
||||
lead: "c.c.c-a.c-..a-c- d.d.d-a.d-..a-d- e.e.e-c.e-..c-e- e.e.e-b.e-..b-d- f.f.f-c.a-..c-f- f.f.f-d.a-..d-f- e-c-a-c-e-..c-a- b-------..5.7.b.",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// bounceSong1 to bounceSong20, in the scores' order.
|
||||
export const BOUNCE_MUSIC = Object.fromEntries(SCORES.map((score, k) => [`bounceSong${k + 1}`, build(score)]));
|
||||
@@ -1,4 +1,4 @@
|
||||
// Plan2Code Web Console - Bounce Road's rivals: the kinds and what each is like, a car's starting state, where a new rival goes on the road, which kind comes next, and each rival's choice of speed and line every slice (blocking, ramming, chasing, dodging your landings, littering, hopping the holes, and the Monster truck's chase).
|
||||
// Plan2Code Web Console - Bounce Road's rivals: the kinds and what each is like (the plain cars, the ones with a trick of their own, the friendly supply truck and the five bosses), a car's starting state, where a new rival goes on the road, which kind comes next, and each rival's choice of speed and line every slice (blocking, ramming, chasing, dodging your landings, littering, shooting, hopping the holes, and each boss's fight).
|
||||
//
|
||||
// Rules only: bounce.js moves the cars, bumps them and settles their
|
||||
// landings; this file decides what a rival wants. Every rival keeps to the
|
||||
@@ -8,7 +8,7 @@
|
||||
// slower car's speed, so no rival stops or sticks. How keenly it blocks,
|
||||
// rams and dodges grows with the stage's `sharp`.
|
||||
|
||||
import { CAR_L, CAR_W, FIELD_W, GROUND, JUMP_MIN, MAX_SPEED, ROW, SPAN, ensureRoad, firstAt, rowGone, rowIn, spanAt, stageFor, swayOff, trainAt } from "./bounce-road.js";
|
||||
import { CAR_L, CAR_W, FIELD_W, GROUND, JUMP_MIN, MAX_SPEED, ROW, SPAN, ballX, ensureRoad, firstAt, laserAt, rowGone, rowIn, spanAt, stageFor, swayOff, trainAt } from "./bounce-road.js";
|
||||
|
||||
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
||||
|
||||
@@ -18,7 +18,13 @@ const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
||||
// under your landing (times the stage's sharpness), `weight` how often it
|
||||
// comes, `style` the car it is drawn as, and `behind` true for one that
|
||||
// comes up from under the board. A rival with no `points` cannot be
|
||||
// flattened: its roof is a trampoline.
|
||||
// flattened: its roof is a trampoline. The later kinds each have a trick:
|
||||
// the Blaster shoots back down the road, the Slasher's blades cut you when
|
||||
// it leans in, the Spike's roof is a crash to land on (`spiky`), the Bomber
|
||||
// leaves lit bombs, the Phantom fades out of reach, the Splitter bursts into
|
||||
// two Minis when flattened, the Magnet drags you toward it, and the Supply
|
||||
// truck is a friend (`friend`): land on its roof for a power-up. A `boss`
|
||||
// has `hp` landings in it and its own fight.
|
||||
export const RIVALS = Object.freeze({
|
||||
zigzag: Object.freeze({ name: "Zigzag", w: 4.2, l: 6.8, mass: 1, speed: 42, points: 100, dodge: 0.45, weight: 3, style: "hatch" }),
|
||||
brick: Object.freeze({ name: "Brick", w: 4.6, l: 8.6, mass: 1.4, speed: 37, points: 100, dodge: 0.25, weight: 2.4, style: "van" }),
|
||||
@@ -29,9 +35,24 @@ export const RIVALS = Object.freeze({
|
||||
bruiser: Object.freeze({ name: "Bruiser", w: 4.8, l: 10.4, mass: 2.6, speed: 40, points: 180, dodge: 0.3, weight: 1, style: "pickup" }),
|
||||
racer: Object.freeze({ name: "Racer", w: 4, l: 7.6, mass: 0.9, speed: 64, points: 300, dodge: 0.9, weight: 0.8, style: "racer", behind: true }),
|
||||
cop: Object.freeze({ name: "Cop", w: 4.2, l: 8.6, mass: 1.6, speed: 52, points: 250, dodge: 0.65, weight: 0.9, style: "police", behind: true }),
|
||||
monster: Object.freeze({ name: "Monster", w: 9, l: 13, mass: 12, speed: 52, points: 0, dodge: 0, weight: 0, style: "monster" }),
|
||||
monster: Object.freeze({ name: "Monster", w: 9, l: 13, mass: 12, speed: 52, points: 0, dodge: 0, weight: 0, style: "monster", boss: true, hp: 5, hint: "Land on its roof" }),
|
||||
blaster: Object.freeze({ name: "Blaster", w: 4.2, l: 8.2, mass: 1.1, speed: 44, points: 200, dodge: 0.5, weight: 1, style: "coupe", hint: "It shoots back. Jump the bolts" }),
|
||||
slasher: Object.freeze({ name: "Slasher", w: 4.2, l: 8.6, mass: 1.3, speed: 48, points: 250, dodge: 0.6, weight: 0.9, style: "sedan", behind: true, hint: "Blades out: keep off its sides" }),
|
||||
spike: Object.freeze({ name: "Spike", w: 4.8, l: 7.8, mass: 1.5, speed: 36, points: 200, dodge: 0, weight: 1.1, style: "armor", spiky: true, hint: "Never land on it. Bump it off" }),
|
||||
bomber: Object.freeze({ name: "Bomber", w: 4.4, l: 7.4, mass: 1.1, speed: 45, points: 220, dodge: 0.6, weight: 1, style: "buggy", hint: "Steer round its bombs, or jump them" }),
|
||||
phantom: Object.freeze({ name: "Phantom", w: 4.2, l: 7.6, mass: 1, speed: 43, points: 220, dodge: 0.5, weight: 0.9, style: "bubble", hint: "Hit it while you can see it" }),
|
||||
splitter: Object.freeze({ name: "Splitter", w: 5, l: 11, mass: 2.2, speed: 35, points: 150, dodge: 0.15, weight: 0.9, style: "bus", hint: "Flatten it and two Minis pop out" }),
|
||||
mini: Object.freeze({ name: "Mini", w: 3, l: 4.8, mass: 0.6, speed: 54, points: 80, dodge: 0.3, weight: 0, style: "mini" }),
|
||||
magnet: Object.freeze({ name: "Magnet", w: 4.6, l: 8.6, mass: 1.6, speed: 42, points: 220, dodge: 0.4, weight: 0.9, style: "tow", hint: "It drags you over. Steer away" }),
|
||||
supply: Object.freeze({ name: "Supply truck", w: 5.6, l: 11, mass: 3, speed: 40, points: 0, dodge: 0, weight: 0, style: "supply", friend: true }),
|
||||
tanker: Object.freeze({ name: "Big Rig", w: 7, l: 17, mass: 12, speed: 52, points: 0, dodge: 0, weight: 0, style: "tanker", boss: true, hp: 4, hint: "Dodge the barrels. Land on its roof" }),
|
||||
vac: Object.freeze({ name: "Robo-Vac", w: 10, l: 10, mass: 10, speed: 52, points: 0, dodge: 0, weight: 0, style: "vac", boss: true, hp: 4, hint: "Jump on it when it charges" }),
|
||||
chopper: Object.freeze({ name: "Whirlybird", w: 8, l: 11, mass: 6, speed: 52, points: 0, dodge: 0, weight: 0, style: "chopper", boss: true, hp: 4, hint: "Dodge the bombs. Stomp it when it swoops" }),
|
||||
cat: Object.freeze({ name: "The Cat", w: 11, l: 12, mass: 14, speed: 52, points: 0, dodge: 0, weight: 0, style: "paw", boss: true, hp: 6, hint: "Jump its paw as it sweeps, and land on it" }),
|
||||
});
|
||||
export const RIVAL_KINDS = Object.freeze(Object.keys(RIVALS));
|
||||
export const BOSS_KINDS = Object.freeze(RIVAL_KINDS.filter((k) => RIVALS[k].boss));
|
||||
export const isBoss = (car) => car.kind !== "you" && RIVALS[car.kind].boss === true;
|
||||
// A car this heavy gives no ground to a ram, and its back is a wall.
|
||||
export const HEAVY = 4;
|
||||
|
||||
@@ -95,6 +116,75 @@ export const BOSS_HOP_MS = 3600;
|
||||
export const BOSS_AIR = 1000;
|
||||
const BOSS_DROP_MS = 2600;
|
||||
export const BOSS_HP = 5;
|
||||
// The Blaster lines up on you from BLAST_NEAR to BLAST_FAR ahead, glows for
|
||||
// AIM_MS and fires a bolt back down the road, then reloads for RELOAD_MS.
|
||||
const BLAST_NEAR = 26;
|
||||
const BLAST_FAR = 76;
|
||||
export const AIM_MS = 650;
|
||||
const RELOAD_MS = 2300;
|
||||
export const BOLT_SPEED = 62;
|
||||
// The Slasher chases like a Nudge for up to SLASH_MS; once alongside, its
|
||||
// blades glint for BLADE_WARN_MS, then stay out for BLADE_MS (a side touch
|
||||
// is a crash) and rest for BLADE_REST_MS.
|
||||
const SLASH_MS = 10000;
|
||||
export const BLADE_WARN_MS = 550;
|
||||
export const BLADE_MS = 1500;
|
||||
const BLADE_REST_MS = 1700;
|
||||
// The Bomber drops a bomb every BOMBER_MS while you follow BOMB_NEAR to
|
||||
// BOMB_FAR behind it, up to BOMBER_DROPS; each blows BOMB_FUSE_MS after it
|
||||
// lands, BOMB_R round.
|
||||
const BOMBER_MS = 1700;
|
||||
export const BOMBER_DROPS = 4;
|
||||
const BOMB_NEAR = 34;
|
||||
const BOMB_FAR = 96;
|
||||
export const BOMB_FUSE_MS = 1350;
|
||||
export const BOMB_R = 8;
|
||||
// The Phantom is solid for PHASE_ON_MS, then out of reach for PHASE_OFF_MS.
|
||||
export const PHASE_ON_MS = 2500;
|
||||
export const PHASE_OFF_MS = 1500;
|
||||
// The Magnet holds your speed within MAG_RANGE for up to MAG_MS, keeping to
|
||||
// the road's edge so its pull drags you toward it.
|
||||
export const MAG_RANGE = 26;
|
||||
const MAG_MS = 6500;
|
||||
// The Supply truck keeps SUPPLY_AHEAD in front of you for SUPPLY_MS, then
|
||||
// drives off.
|
||||
const SUPPLY_AHEAD = 30;
|
||||
const SUPPLY_MS = 14000;
|
||||
// The bosses. The Big Rig keeps TANKER_AHEAD in front and lobs a barrel at
|
||||
// where you are heading every TANKER_DROP_MS (an oil spill in between). The
|
||||
// Robo-Vac sweeps from edge to edge VAC_AHEAD in front, then warns for
|
||||
// VAC_WARN_MS and charges back down the road at you, VAC_CHARGE slower than
|
||||
// you, every VAC_EVERY_MS. The Whirlybird flies out of reach for
|
||||
// CHOPPER_HIGH_MS, bombing where you are heading every CHOPPER_BOMB_MS, then
|
||||
// swoops down to the road for CHOPPER_LOW_MS. The Cat's paw slams down like
|
||||
// the Monster every CAT_HOP_MS, then sweeps across the road for CAT_SWIPE_MS.
|
||||
// A thing lobbed lands LOB_MS after it is thrown.
|
||||
export const TANKER_AHEAD = 44;
|
||||
const TANKER_DROP_MS = 2500;
|
||||
// A boss that kept your speed could never be landed on (a jump holds your
|
||||
// speed), so each comes back to you in its own way. The Big Rig brake-checks
|
||||
// every TANKER_BRAKE_EVERY_MS: TANKER_BRAKE slower than you for
|
||||
// TANKER_BRAKE_MS, its back a wall and its roof in reach. The Whirlybird's
|
||||
// swoop drifts back at CHOPPER_DRIFT, and the Cat's paw sweeps CAT_DRIFT
|
||||
// slower than you.
|
||||
export const TANKER_BRAKE_MS = 1200;
|
||||
const TANKER_BRAKE_EVERY_MS = 5200;
|
||||
const TANKER_BRAKE = 26;
|
||||
const CHOPPER_DRIFT = 16;
|
||||
const CAT_DRIFT = 6;
|
||||
export const VAC_AHEAD = 42;
|
||||
export const VAC_WARN_MS = 850;
|
||||
const VAC_CHARGE = 46;
|
||||
const VAC_EVERY_MS = 4200;
|
||||
export const CHOPPER_AHEAD = 38;
|
||||
export const CHOPPER_HIGH_MS = 4400;
|
||||
export const CHOPPER_LOW_MS = 3000;
|
||||
const CHOPPER_BOMB_MS = 1150;
|
||||
export const CAT_HOP_MS = 2900;
|
||||
export const CAT_SWIPE_MS = 1700;
|
||||
const CAT_STEER = 36;
|
||||
export const LOB_MS = 950;
|
||||
export const LOB_R = 7;
|
||||
|
||||
// A car's state. `kind` is "you" or a rival's.
|
||||
export function makeCar(id, kind, x, d, v) {
|
||||
@@ -143,8 +233,29 @@ export function makeCar(id, kind, x, d, v) {
|
||||
nearDone: false,
|
||||
dropIn: SNEAK_MS,
|
||||
drops: 0,
|
||||
hp: kind === "monster" ? BOSS_HP : 0,
|
||||
hp: spec && spec.hp ? spec.hp : 0,
|
||||
stunMs: 0,
|
||||
// The later kinds' own state: how fast the car may steer, a Blaster's
|
||||
// aim, a Slasher's blades ("", "warn" or "out"), a Phantom out of reach,
|
||||
// a boss flying (`lift` 0 on the road to 1 up high), a car zapped or
|
||||
// spinning on oil, and a boss driving through you on its way back.
|
||||
steer: RIVAL_STEER,
|
||||
aimMs: 0,
|
||||
blade: "",
|
||||
bladeMs: 0,
|
||||
phased: false,
|
||||
phaseIn: PHASE_ON_MS,
|
||||
lift: 0,
|
||||
high: false,
|
||||
thru: false,
|
||||
zapMs: 0,
|
||||
spinMs: 0,
|
||||
wasAir: false,
|
||||
gave: false,
|
||||
// You: the gadget held ({ kind, uses } or null) and what is running.
|
||||
held: null,
|
||||
magnetMs: 0,
|
||||
pounding: false,
|
||||
// You: the power-ups held, and what your jump flew over.
|
||||
spring: false,
|
||||
bubble: false,
|
||||
@@ -223,9 +334,41 @@ function thingAhead(round, car, nose, look) {
|
||||
const tr = trainAt(h, round.clock + ((h.d - nose) / Math.max(car.v, 1)) * 1000);
|
||||
if (tr.warn) return h.d + h.half;
|
||||
}
|
||||
// A laser that will be on, or a roller that will be across the car's
|
||||
// line, by the time it gets there.
|
||||
for (let k = firstAt(road.hazards, "d", nose - 4); k < road.hazards.length && road.hazards[k].d < nose + look + 12; k++) {
|
||||
const h = road.hazards[k];
|
||||
if (h.d < nose - 1 || h.d - 2 > nose + look + car.v * 0.1) continue;
|
||||
const at = round.clock + ((h.d - nose) / Math.max(car.v, 1)) * 1000;
|
||||
if (h.kind === "laser" && laserAt(h, at).warn) return h.d + h.half;
|
||||
if (h.kind === "roller" && Math.abs(ballX(h, at) - car.x) < h.half + car.w / 2 + 1.5) return h.d + h.r;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// A thing thrown at where you are heading: it lands LOB_MS on, on the road
|
||||
// just ahead of you (`boom`: it blows up LOB_R round; else it lies there).
|
||||
export function lob(round, from, what, boom = 0) {
|
||||
const you = round.cars[0];
|
||||
const road = round.road;
|
||||
const d = you.d + Math.max(you.v, 20) * (LOB_MS / 1000) + 2;
|
||||
ensureRoad(road, d);
|
||||
const i = rowIn(road, d);
|
||||
const x = clamp(you.x + you.vx * 0.3, road.L[i] + 3, road.R[i] - 3);
|
||||
round.lobs.push({ x, d, at: round.clock + LOB_MS, what, boom, w: boom ? 4 : 4.4, l: boom ? 4 : 4.4, fx: from.x, fd: from.d });
|
||||
round.events.push({ type: "lob", id: from.id, what, x, d });
|
||||
}
|
||||
|
||||
// A boss's speed to sit `ahead` of you.
|
||||
const paceTo = (you, car, ahead) => you.v + clamp((you.d + ahead - car.d) * 1.4, -26, 26);
|
||||
|
||||
// A boss sweeping from edge to edge between `lo` and `hi`.
|
||||
function sweep(car, lo, hi) {
|
||||
if (car.offside > 0 && car.x > hi - 1.5) car.offside = -1;
|
||||
else if (car.offside < 0 && car.x < lo + 1.5) car.offside = 1;
|
||||
return car.offside > 0 ? hi : lo;
|
||||
}
|
||||
|
||||
// Whether the road from `d` to `look` ahead is plain enough for a Frog to
|
||||
// hop on: no hole, water, flowerbed, timed part or narrowing to land off.
|
||||
function plainAhead(road, d, look) {
|
||||
@@ -274,11 +417,23 @@ export function think(round, car, ms, random = Math.random) {
|
||||
if (car.out > 0) return;
|
||||
const you = round.cars[0];
|
||||
const spec = RIVALS[car.kind];
|
||||
const stage = stageFor(round.stage);
|
||||
const stage = stageFor(round.stage, round.road);
|
||||
const sharp = stage.sharp || 0;
|
||||
const behind = car.d - you.d;
|
||||
let base = spec.speed * stage.pace * car.pace;
|
||||
if (car.kind !== "racer" && car.kind !== "monster") {
|
||||
// Zapped, or spinning on your oil: it coasts where it points, sees nothing
|
||||
// and hops nothing, so a hole or the road's edge takes it.
|
||||
if (car.zapMs > 0 || car.spinMs > 0) {
|
||||
car.zapMs = Math.max(0, car.zapMs - ms);
|
||||
car.spinMs = Math.max(0, car.spinMs - ms);
|
||||
car.tv = Math.max(RIVAL_MIN_SPEED, base * 0.6);
|
||||
car.tx = car.x;
|
||||
car.gain = 0;
|
||||
car.blade = "";
|
||||
car.aimMs = 0;
|
||||
return;
|
||||
}
|
||||
if (car.kind !== "racer" && car.kind !== "mini" && !spec.boss && !spec.friend) {
|
||||
if (behind < -BAND_BEHIND) base *= 1 + Math.min(BAND_MAX, (-behind - BAND_BEHIND) / 120);
|
||||
else if (behind > BAND_AHEAD) base *= 1 - Math.min(BAND_MAX, (behind - BAND_AHEAD) / 300);
|
||||
}
|
||||
@@ -291,7 +446,10 @@ export function think(round, car, ms, random = Math.random) {
|
||||
let tx = car.lane;
|
||||
let tv = base;
|
||||
let gain = RIVAL_GAIN;
|
||||
car.steer = RIVAL_STEER;
|
||||
const youHere = you.out === 0 && round.phase === "drive" && you.ghostMs <= 0;
|
||||
const landed = car.wasAir && car.air <= 0;
|
||||
car.wasAir = car.air > 0;
|
||||
car.modeMs = Math.max(0, car.modeMs - ms);
|
||||
car.stunMs = Math.max(0, car.stunMs - ms);
|
||||
car.brakeIn = Math.max(0, car.brakeIn - ms);
|
||||
@@ -379,6 +537,233 @@ export function think(round, car, ms, random = Math.random) {
|
||||
tx = you.x;
|
||||
gain = 0.5 + sharp;
|
||||
}
|
||||
} else if (car.kind === "spike") {
|
||||
// It sits in your lane and dares you to jump on it.
|
||||
if (youHere && behind > 0 && behind < 46 && you.air <= 0) {
|
||||
tx = you.x;
|
||||
gain = 0.9 + sharp;
|
||||
tv = clamp(you.v - 6, base * 0.8, base * 1.3);
|
||||
}
|
||||
} else if (car.kind === "splitter") {
|
||||
if (youHere && behind > 0 && behind < 60) {
|
||||
tx = you.x;
|
||||
gain = 0.5 + 0.6 * sharp;
|
||||
}
|
||||
} else if (car.kind === "mini") {
|
||||
tx = mid + ((hi - lo) / 2) * Math.sin(round.clock / 420 + car.seed);
|
||||
gain = 4;
|
||||
} else if (car.kind === "blaster") {
|
||||
const inRange = youHere && behind > BLAST_NEAR && behind < BLAST_FAR;
|
||||
if (inRange) {
|
||||
tx = you.x;
|
||||
gain = 1.2 + sharp;
|
||||
tv = clamp(you.v + (behind < 44 ? 6 : -4), base * 0.8, base * 1.4);
|
||||
}
|
||||
car.dropIn -= ms;
|
||||
if (car.aimMs > 0) {
|
||||
car.aimMs -= ms;
|
||||
if (car.aimMs <= 0) {
|
||||
car.aimMs = 0;
|
||||
car.dropIn = RELOAD_MS * (1.3 - 0.5 * sharp);
|
||||
if (car.air <= 0) {
|
||||
round.bolts.push({ x: car.x, d: car.d - car.l / 2 - 1, v: car.v - BOLT_SPEED, from: car.id });
|
||||
round.events.push({ type: "bolt", id: car.id, x: car.x, d: car.d });
|
||||
}
|
||||
}
|
||||
} else if (inRange && car.dropIn <= 0 && car.air <= 0 && Math.abs(you.x - car.x) < 9) {
|
||||
car.aimMs = AIM_MS;
|
||||
round.events.push({ type: "aim", id: car.id, x: car.x, d: car.d });
|
||||
}
|
||||
} else if (car.kind === "slasher") {
|
||||
car.chaseMs += ms;
|
||||
if (car.mode === "chase" && (!youHere || behind > 16 || car.chaseMs > SLASH_MS)) {
|
||||
car.mode = "calm";
|
||||
car.blade = "";
|
||||
}
|
||||
if (car.mode === "chase") {
|
||||
tv = Math.min(you.v + NUDGE_CATCH, MAX_SPEED - 2);
|
||||
if (behind > -2) tv = you.v + 1;
|
||||
const beside = you.x + car.offside * ((you.w + car.w) / 2 + 1.8);
|
||||
if (beside < lo || beside > hi) car.offside = -car.offside;
|
||||
const along = Math.abs(behind) < (you.l + car.l) * 0.45;
|
||||
// Alongside: the blades glint, come out, and it leans in; then a rest.
|
||||
car.bladeMs -= ms;
|
||||
if (car.blade === "" && along && car.bladeMs <= 0) {
|
||||
car.blade = "warn";
|
||||
car.bladeMs = BLADE_WARN_MS;
|
||||
round.events.push({ type: "blade", id: car.id, x: car.x, d: car.d });
|
||||
} else if (car.blade === "warn" && car.bladeMs <= 0) {
|
||||
car.blade = "out";
|
||||
car.bladeMs = BLADE_MS;
|
||||
} else if (car.blade === "out" && car.bladeMs <= 0) {
|
||||
car.blade = "";
|
||||
car.bladeMs = BLADE_REST_MS * (1.2 - 0.4 * sharp);
|
||||
}
|
||||
tx = along && car.blade === "out" && you.air <= 0 ? you.x + car.offside * (car.w / 2) : beside;
|
||||
gain = 2.6;
|
||||
} else tv = base * 1.3;
|
||||
} else if (car.kind === "bomber") {
|
||||
if (youHere && behind > 12 && behind < BOMB_FAR) {
|
||||
tx = you.x;
|
||||
gain = 1 + sharp;
|
||||
tv = Math.max(base, you.v + 3);
|
||||
car.dropIn -= ms;
|
||||
if (car.dropIn <= 0 && car.drops < BOMBER_DROPS && car.air <= 0 && behind > BOMB_NEAR) {
|
||||
car.dropIn = BOMBER_MS * (1.3 - 0.5 * sharp);
|
||||
car.drops++;
|
||||
round.bombs.push({ x: car.x, d: car.d - car.l / 2 - 2, at: round.clock + BOMB_FUSE_MS, t0: round.clock, r: BOMB_R });
|
||||
round.events.push({ type: "bomb", id: car.id, x: car.x, d: car.d });
|
||||
}
|
||||
}
|
||||
} else if (car.kind === "phantom") {
|
||||
tx = mid + ((hi - lo) / 2) * Math.sin((round.clock / 1000) * 0.9 + car.seed);
|
||||
if (youHere && behind > 0 && behind < 46) tx += (you.x - tx) * (0.5 + 0.4 * sharp);
|
||||
car.phaseIn -= ms;
|
||||
if (car.phaseIn <= 0) {
|
||||
car.phased = !car.phased;
|
||||
car.phaseIn = car.phased ? PHASE_OFF_MS : PHASE_ON_MS * (1.2 - 0.3 * sharp);
|
||||
round.events.push({ type: "phase", id: car.id, x: car.x, d: car.d, on: car.phased });
|
||||
}
|
||||
} else if (car.kind === "magnet") {
|
||||
car.chaseMs += youHere && Math.abs(behind) < MAG_RANGE ? ms : 0;
|
||||
if (car.mode !== "calm" && car.chaseMs > MAG_MS) car.mode = "calm";
|
||||
// Hard against the nearer edge, and at your speed while it has you.
|
||||
tx = car.x < mid ? lo : hi;
|
||||
gain = 2;
|
||||
if (car.mode === "calm") tv = base * 1.3;
|
||||
else if (youHere && Math.abs(behind) < MAG_RANGE + 14) tv = clamp(you.v + (behind < 0 ? 8 : -4), RIVAL_MIN_SPEED, MAX_SPEED - 2);
|
||||
} else if (car.kind === "supply") {
|
||||
car.chaseMs += ms;
|
||||
tx = mid;
|
||||
gain = 1.2;
|
||||
if (car.gave || car.chaseMs > SUPPLY_MS) tv = MAX_SPEED - 4;
|
||||
else if (youHere) tv = clamp(paceTo(you, car, SUPPLY_AHEAD), RIVAL_MIN_SPEED, MAX_SPEED - 4);
|
||||
} else if (car.kind === "tanker") {
|
||||
tv = paceTo(you, car, TANKER_AHEAD);
|
||||
if (car.stunMs > 0) tv = Math.max(RIVAL_MIN_SPEED, you.v - 20);
|
||||
if (youHere) {
|
||||
tx = you.x;
|
||||
gain = 0.5 + 0.4 * sharp;
|
||||
}
|
||||
// The brake check: its brake lights on, and back it comes.
|
||||
if (car.mode === "brake" && car.modeMs > 0 && behind > car.l / 2 + 4) tv = Math.max(RIVAL_MIN_SPEED, you.v - TANKER_BRAKE);
|
||||
else if (car.mode === "brake") car.mode = "";
|
||||
else if (youHere && car.brakeIn <= 0 && car.stunMs <= 0 && car.air <= 0 && behind > 30) {
|
||||
car.mode = "brake";
|
||||
car.modeMs = TANKER_BRAKE_MS;
|
||||
car.brakeIn = TANKER_BRAKE_MS + TANKER_BRAKE_EVERY_MS * (1.2 - 0.3 * sharp);
|
||||
round.events.push({ type: "brake", id: car.id, kind: car.kind, x: car.x, d: car.d });
|
||||
}
|
||||
car.dropIn -= ms;
|
||||
if (youHere && car.dropIn <= 0 && car.air <= 0 && car.stunMs <= 0 && car.mode !== "brake" && behind > 16) {
|
||||
const rage = car.hp <= 2 ? 0.7 : 1;
|
||||
car.dropIn = TANKER_DROP_MS * (1.25 - 0.4 * sharp) * rage;
|
||||
car.drops++;
|
||||
if (car.drops % 3 === 0) {
|
||||
round.spills.push({ x: car.x, d: car.d - car.l / 2 - 5, w: 9, l: 11, until: round.clock + 7000, foe: true });
|
||||
round.events.push({ type: "litter", id: car.id, x: car.x, d: car.d, what: "oil" });
|
||||
} else lob(round, car, "barrel");
|
||||
}
|
||||
} else if (car.kind === "vac") {
|
||||
car.thru = false;
|
||||
if (car.stunMs > 0 && car.mode !== "back") car.mode = "back";
|
||||
if (car.mode === "warn") {
|
||||
tv = paceTo(you, car, VAC_AHEAD);
|
||||
tx = you.x;
|
||||
gain = 2.4;
|
||||
if (car.modeMs <= 0) {
|
||||
car.mode = "charge";
|
||||
car.lane = car.x;
|
||||
round.events.push({ type: "bossCharge", id: car.id, x: car.x, d: car.d });
|
||||
}
|
||||
} else if (car.mode === "charge") {
|
||||
tv = Math.max(RIVAL_MIN_SPEED, you.v - VAC_CHARGE);
|
||||
tx = clamp(car.lane, lo, hi);
|
||||
if (!youHere || behind < -14) car.mode = "back";
|
||||
} else if (car.mode === "back") {
|
||||
// Back up the road, through anything, to sweep again.
|
||||
car.thru = behind < 20;
|
||||
tv = car.stunMs > 0 ? Math.max(RIVAL_MIN_SPEED, you.v - 12) : you.v + 30;
|
||||
tx = you.x > mid ? lo : hi;
|
||||
gain = 2.5;
|
||||
if (behind > VAC_AHEAD - 8 && car.stunMs <= 0) {
|
||||
car.mode = "sweep";
|
||||
car.hopIn = VAC_EVERY_MS * (1.2 - 0.4 * sharp) + random() * 800;
|
||||
}
|
||||
} else {
|
||||
car.mode = "sweep";
|
||||
tv = paceTo(you, car, VAC_AHEAD);
|
||||
tx = sweep(car, lo, hi);
|
||||
gain = 3;
|
||||
car.hopIn -= ms;
|
||||
if (youHere && car.hopIn <= 0 && car.air <= 0 && behind > 20) {
|
||||
car.mode = "warn";
|
||||
car.modeMs = VAC_WARN_MS;
|
||||
round.events.push({ type: "bossWarn", id: car.id, kind: car.kind, x: car.x, d: car.d });
|
||||
}
|
||||
}
|
||||
} else if (car.kind === "chopper") {
|
||||
if (car.mode !== "low") {
|
||||
// Up high: over your line, bombing where you are heading.
|
||||
car.mode = "high";
|
||||
car.lift = Math.min(1, car.lift + ms / 500);
|
||||
tv = paceTo(you, car, CHOPPER_AHEAD);
|
||||
if (youHere) {
|
||||
tx = you.x;
|
||||
gain = 1.4;
|
||||
}
|
||||
car.dropIn -= ms;
|
||||
car.hopIn -= ms;
|
||||
if (youHere && car.dropIn <= 0 && car.lift >= 1) {
|
||||
car.dropIn = CHOPPER_BOMB_MS * (1.25 - 0.4 * sharp);
|
||||
lob(round, car, "bomb", LOB_R);
|
||||
}
|
||||
if (youHere && car.hopIn <= 0 && car.stunMs <= 0) {
|
||||
car.mode = "low";
|
||||
car.modeMs = CHOPPER_LOW_MS;
|
||||
round.events.push({ type: "bossWarn", id: car.id, kind: car.kind, x: car.x, d: car.d });
|
||||
}
|
||||
} else {
|
||||
// Down on the road: sweeping across as it drifts back to you, there
|
||||
// to be stomped; past you, or out of time, up it goes.
|
||||
car.lift = Math.max(0, car.lift - ms / 450);
|
||||
tv = Math.max(RIVAL_MIN_SPEED, you.v - CHOPPER_DRIFT);
|
||||
tx = sweep(car, lo, hi);
|
||||
gain = 2.4;
|
||||
if (car.modeMs <= 0 || car.stunMs > 0 || behind < 4) {
|
||||
car.mode = "high";
|
||||
car.hopIn = CHOPPER_HIGH_MS * (1.15 - 0.3 * sharp);
|
||||
car.dropIn = 700;
|
||||
}
|
||||
}
|
||||
car.high = car.lift > 0.35;
|
||||
} else if (car.kind === "cat") {
|
||||
tv = paceTo(you, car, BOSS_AHEAD - 6);
|
||||
if (car.stunMs > 0) tv = Math.max(RIVAL_MIN_SPEED, you.v - 22);
|
||||
if (landed && car.stunMs <= 0) {
|
||||
car.mode = "swipe";
|
||||
car.modeMs = CAT_SWIPE_MS;
|
||||
car.offside = car.x < mid ? 1 : -1;
|
||||
round.events.push({ type: "swipe", id: car.id, x: car.x, d: car.d });
|
||||
}
|
||||
if (car.mode === "swipe" && car.modeMs > 0 && car.stunMs <= 0) {
|
||||
tx = sweep(car, lo, hi);
|
||||
gain = 4;
|
||||
car.steer = CAT_STEER;
|
||||
if (behind > 8) tv = Math.max(RIVAL_MIN_SPEED, you.v - CAT_DRIFT);
|
||||
} else {
|
||||
car.mode = "stalk";
|
||||
if (youHere) {
|
||||
tx = you.x;
|
||||
gain = 0.8 + 0.5 * sharp;
|
||||
}
|
||||
car.hopIn -= ms;
|
||||
if (youHere && car.air <= 0 && car.hopIn <= 0 && car.stunMs <= 0 && Math.abs(behind) < 60) {
|
||||
car.hopIn = CAT_HOP_MS * (1.2 - 0.4 * sharp) + random() * 700;
|
||||
hop(round, car, BOSS_AIR * 0.9, "bossHop");
|
||||
car.v = clamp((you.d + you.v * ((BOSS_AIR * 0.9) / 1000) + 6 - car.d) / ((BOSS_AIR * 0.9) / 1000), RIVAL_MIN_SPEED, MAX_SPEED);
|
||||
}
|
||||
}
|
||||
} else if (car.kind === "monster") {
|
||||
tv = you.v + clamp((you.d + BOSS_AHEAD - car.d) * 1.4, -26, 26);
|
||||
if (car.stunMs > 0) tv = Math.max(RIVAL_MIN_SPEED, you.v - 22);
|
||||
@@ -401,7 +786,7 @@ export function think(round, car, ms, random = Math.random) {
|
||||
}
|
||||
}
|
||||
// Your landing: a sharp enough rival under it swerves away (a Frog hops).
|
||||
if (youHere && you.air > 0 && spec.dodge > 0 && car.air <= 0) {
|
||||
if (youHere && you.air > 0 && spec.dodge > 0 && car.air <= 0 && !car.phased) {
|
||||
const t = you.air / 1000;
|
||||
const landD = you.d + you.v * t;
|
||||
const carD = car.d + car.v * t;
|
||||
@@ -424,18 +809,18 @@ export function think(round, car, ms, random = Math.random) {
|
||||
// A slower car in the way, just ahead: hold its speed, and a Frog edges its
|
||||
// lane round it. One that means to hit you never holds back for you.
|
||||
for (const o of round.cars) {
|
||||
if (o === car || o.out > 0 || o.air > 0) continue;
|
||||
if (o === car || o.out > 0 || o.air > 0 || o.high || o.phased || o.thru || car.high || car.thru || car.phased) continue;
|
||||
const ahead = o.d - car.d;
|
||||
if (ahead <= 0 || ahead > (o.l + car.l) / 2 + 6 || Math.abs(o.x - car.x) > (o.w + car.w) / 2 + 0.5) continue;
|
||||
if (o.id === 0 && (car.mode === "chase" || car.kind === "bruiser" || car.kind === "monster")) continue;
|
||||
if (o.id === 0 && (car.mode === "chase" || car.kind === "bruiser" || spec.boss)) continue;
|
||||
if (o.v < tv) tv = Math.max(RIVAL_MIN_SPEED, o.v);
|
||||
if (car.kind === "frog") car.lane = clamp(car.lane + (o.x < car.x ? 1 : -1) * 24 * (ms / 1000), lo, hi);
|
||||
}
|
||||
car.tx = clamp(tx, lo, hi);
|
||||
car.tv = Math.max(RIVAL_MIN_SPEED, tv);
|
||||
car.gain = gain;
|
||||
// A hole, a barrier or a train just ahead: hop it.
|
||||
if (car.air <= 0) {
|
||||
// A hole, a barrier or a train just ahead: hop it (never a boss in flight).
|
||||
if (car.air <= 0 && !car.high) {
|
||||
const nose = car.d + car.l / 2;
|
||||
const len = holeAhead(round.road, nose, HOP_LOOK, round.clock);
|
||||
const v = Math.max(car.v, RIVAL_MIN_SPEED);
|
||||
@@ -468,11 +853,18 @@ export function spawnRival(round, kind, random = Math.random, at = null) {
|
||||
if (room < 0) continue;
|
||||
const x = span.lo + spec.w / 2 + 2 + random() * room;
|
||||
if (round.cars.some((o) => o.out === 0 && Math.abs(o.d - d) < (o.l + spec.l) / 2 + 8 && Math.abs(o.x - x) < (o.w + spec.w) / 2 + 3)) continue;
|
||||
const car = makeCar(round.nextId++, kind, clamp(x, spec.w / 2, FIELD_W - spec.w / 2), d, spec.speed * stageFor(round.stage).pace);
|
||||
const car = makeCar(round.nextId++, kind, clamp(x, spec.w / 2, FIELD_W - spec.w / 2), d, spec.speed * stageFor(round.stage, round.road).pace);
|
||||
car.pace = 0.92 + random() * 0.16;
|
||||
car.seed = random() * 6.28;
|
||||
car.hopIn = kind === "monster" ? BOSS_HOP_MS * 0.6 : FROG_EVERY * random() + 600;
|
||||
car.dropIn = kind === "monster" ? BOSS_DROP_MS : SNEAK_MS * (0.5 + random());
|
||||
car.hopIn = kind === "monster" ? BOSS_HOP_MS * 0.6 : kind === "cat" ? CAT_HOP_MS * 0.7 : kind === "vac" ? VAC_EVERY_MS * 0.7 : kind === "chopper" ? CHOPPER_HIGH_MS : FROG_EVERY * random() + 600;
|
||||
car.dropIn = kind === "monster" ? BOSS_DROP_MS : kind === "tanker" ? TANKER_DROP_MS * 0.8 : kind === "chopper" ? CHOPPER_BOMB_MS * 1.6 : kind === "blaster" ? RELOAD_MS * 0.5 : kind === "bomber" ? BOMBER_MS * 0.6 : SNEAK_MS * (0.5 + random());
|
||||
car.phaseIn = PHASE_ON_MS * (0.5 + random() * 0.6);
|
||||
if (kind === "tanker") car.brakeIn = TANKER_BRAKE_EVERY_MS * 0.6;
|
||||
if (kind === "chopper") {
|
||||
car.lift = 1;
|
||||
car.high = true;
|
||||
car.mode = "high";
|
||||
}
|
||||
car.offside = x < you.x ? -1 : 1;
|
||||
if (spec.behind) car.v = kind === "racer" ? you.v + RACER_CATCH : you.v;
|
||||
round.cars.push(car);
|
||||
@@ -484,11 +876,13 @@ export function spawnRival(round, kind, random = Math.random, at = null) {
|
||||
|
||||
// Kinds only one of which is on the road at a time, and those that come up
|
||||
// from behind only once you are quick enough to chase.
|
||||
const ONE_AT_A_TIME = Object.freeze(new Set(["hauler", "nudge", "cop", "racer", "bruiser", "sneak"]));
|
||||
const ONE_AT_A_TIME = Object.freeze(new Set(["hauler", "nudge", "cop", "racer", "bruiser", "sneak", "blaster", "slasher", "spike", "bomber", "phantom", "splitter", "magnet"]));
|
||||
// A kind new to the stage comes this much more often.
|
||||
const FRESH_WEIGHT = 2.6;
|
||||
|
||||
// The kind to spawn next: weighted among the stage's.
|
||||
export function pickKind(round, random) {
|
||||
const spec = stageFor(round.stage);
|
||||
const spec = stageFor(round.stage, round.road);
|
||||
const you = round.cars[0];
|
||||
let total = 0;
|
||||
const ok = (k) => {
|
||||
@@ -496,11 +890,12 @@ export function pickKind(round, random) {
|
||||
if (RIVALS[k].behind && you.v < 30) return false;
|
||||
return true;
|
||||
};
|
||||
for (const k of spec.kinds) if (ok(k)) total += RIVALS[k].weight;
|
||||
const weight = (k) => RIVALS[k].weight * (spec.fresh && spec.fresh.includes(k) ? FRESH_WEIGHT : 1);
|
||||
for (const k of spec.kinds) if (ok(k)) total += weight(k);
|
||||
let roll = random() * total;
|
||||
for (const k of spec.kinds) {
|
||||
if (!ok(k)) continue;
|
||||
roll -= RIVALS[k].weight;
|
||||
roll -= weight(k);
|
||||
if (roll < 0) return k;
|
||||
}
|
||||
return spec.kinds[0];
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
// the round's clock, so a paused round holds still and a test can ask where
|
||||
// anything will be.
|
||||
|
||||
import { FIELD_H, FIELD_W, LAP_FROM, MAX_HOLE, ROW, STAGES } from "./bounce-roads.js";
|
||||
import { ARENAS, BOSS_ORDER, CYCLE, FIELD_H, FIELD_W, KIND_FROM, MAX_HOLE, MAX_RIVALS, REGULAR, REGULAR_PER_CYCLE, ROW, STAGES, THEMES, TWISTS, TWIST_NAMES, TWIST_SHARE, WILD, WORLD, classicTheme, slotFor, stageSpec } from "./bounce-roads.js";
|
||||
|
||||
export { FIELD_H, FIELD_W, LAP_FROM, MAX_HOLE, ROW, STAGES };
|
||||
export { ARENAS, BOSS_ORDER, CYCLE, FIELD_H, FIELD_W, KIND_FROM, MAX_HOLE, MAX_RIVALS, REGULAR, ROW, STAGES, THEMES, TWISTS, WILD, WORLD, slotFor, stageSpec };
|
||||
|
||||
const TAU = Math.PI * 2;
|
||||
|
||||
@@ -44,9 +44,6 @@ export const reach = (v) => (v * airMs(v)) / 1000;
|
||||
// shorter).
|
||||
export const LONGEST_JUMP = reach(MAX_SPEED) * Math.max(SPRING_AIR, RAMP_AIR);
|
||||
|
||||
// At most this many rivals on the road at once, however far you get.
|
||||
export const MAX_RIVALS = 7;
|
||||
|
||||
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
||||
const smooth = (t) => t * t * (3 - 2 * t);
|
||||
|
||||
@@ -64,42 +61,74 @@ export function seeded(seed) {
|
||||
|
||||
/* ------------------------------------------------------------- stages */
|
||||
|
||||
// A stage's numbers, built once each: the first ten from bounce-roads.js,
|
||||
// and past the last, the road goes round again from LAP_FROM, the rivals
|
||||
// quicker, keener and more of them each lap, the holes a little longer
|
||||
// (never past MAX_HOLE), the Monster truck back at every Monster Mash.
|
||||
// A run's plan: which theme each stage is, and the twist on it. With no
|
||||
// road, or a road made with no shuffle, the classic order of
|
||||
// bounce-roads.js. A shuffled road deals each lap of CYCLE stages from its
|
||||
// seed: the plain themes picked and ordered afresh (the first lap opens on
|
||||
// Chalk Lane and runs roughly from the gentle themes to the hard ones; a
|
||||
// later lap is any order), the bosses in a new order (the Cat always last
|
||||
// on the first lap), and a twist on some of the plain stages.
|
||||
function shuffled(list, random) {
|
||||
const out = [...list];
|
||||
for (let i = out.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(random() * (i + 1));
|
||||
[out[i], out[j]] = [out[j], out[i]];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function deckFor(road, cycle) {
|
||||
if (road.decks[cycle]) return road.decks[cycle];
|
||||
const random = seeded((road.seed ^ Math.imul(cycle + 1, 0x9e3779b1)) >>> 0);
|
||||
let regular;
|
||||
let bosses;
|
||||
if (cycle === 0) {
|
||||
const rest = shuffled(REGULAR.filter((id) => id !== "chalk"), random).slice(0, REGULAR_PER_CYCLE - 1);
|
||||
regular = ["chalk", ...rest.map((id) => [id, THEMES[id].tier + random() * 1.3]).sort((p, q) => p[1] - q[1]).map((e) => e[0])];
|
||||
bosses = [...shuffled(BOSS_ORDER.filter((k) => k !== "cat"), random), "cat"];
|
||||
} else {
|
||||
regular = shuffled(REGULAR, random).slice(0, REGULAR_PER_CYCLE);
|
||||
bosses = shuffled(BOSS_ORDER, random);
|
||||
}
|
||||
return (road.decks[cycle] = { regular, bosses });
|
||||
}
|
||||
|
||||
// The theme id and the twist of stage `n` on `road`.
|
||||
export function planAt(road, n) {
|
||||
if (!road || !road.shuffle) return { theme: classicTheme(n), twist: null };
|
||||
const cycle = Math.floor((n - 1) / CYCLE);
|
||||
const k = 1 + ((n - 1) % CYCLE);
|
||||
const deck = deckFor(road, cycle);
|
||||
if (k % WORLD === 0) return { theme: ARENAS[deck.bosses[k / WORLD - 1]], twist: null };
|
||||
const theme = deck.regular[k - Math.floor(k / WORLD) - 1];
|
||||
let twist = null;
|
||||
if (n > 1) {
|
||||
const random = seeded((road.seed + n * 104729) >>> 0);
|
||||
if (random() < TWIST_SHARE) {
|
||||
const spec = THEMES[theme];
|
||||
const fits = TWIST_NAMES.filter((t) => !(t === "dark" && spec.dark) && !(t === "rain" && spec.ice));
|
||||
twist = fits[Math.floor(random() * fits.length)];
|
||||
}
|
||||
}
|
||||
return { theme, twist };
|
||||
}
|
||||
|
||||
// A stage's numbers, built once each (per road when it shuffles): its slot's
|
||||
// difficulty with its theme's pieces, from bounce-roads.js.
|
||||
const BUILT_STAGES = new Map();
|
||||
|
||||
export function stageFor(n) {
|
||||
export function stageFor(n, road = null) {
|
||||
const k = Math.max(1, Math.floor(n) || 1);
|
||||
if (BUILT_STAGES.has(k)) return BUILT_STAGES.get(k);
|
||||
let spec;
|
||||
if (k <= STAGES.length) spec = { ...STAGES[k - 1], n: k, lap: 1, name: STAGES[k - 1].title };
|
||||
else {
|
||||
const loop = STAGES.length - LAP_FROM + 1;
|
||||
const past = k - STAGES.length - 1;
|
||||
const base = STAGES[LAP_FROM - 1 + (past % loop)];
|
||||
const lap = 2 + Math.floor(past / loop);
|
||||
const longer = (r) => (r ? Object.freeze([r[0], Math.min(MAX_HOLE, r[1] + 3 * (lap - 1))]) : r);
|
||||
spec = {
|
||||
...base,
|
||||
n: k,
|
||||
lap,
|
||||
name: `${base.title} ${lap}`,
|
||||
rivals: Math.min(MAX_RIVALS, base.rivals + lap - 1),
|
||||
pace: Math.min(1.45, base.pace + 0.07 * (lap - 1)),
|
||||
sharp: 1,
|
||||
crack: longer(base.crack),
|
||||
gap: longer(base.gap),
|
||||
};
|
||||
}
|
||||
const frozen = Object.freeze(spec);
|
||||
BUILT_STAGES.set(k, frozen);
|
||||
return frozen;
|
||||
const cache = road && road.shuffle ? road.specs : BUILT_STAGES;
|
||||
if (cache.has(k)) return cache.get(k);
|
||||
const plan = planAt(road, k);
|
||||
const spec = stageSpec(k, plan.theme, plan.twist);
|
||||
cache.set(k, spec);
|
||||
return spec;
|
||||
}
|
||||
|
||||
// "Kitchen Floor (stage 3)".
|
||||
export const stageName = (n) => `${stageFor(n).name} (stage ${n})`;
|
||||
export const stageName = (n, road = null) => `${stageFor(n, road).name} (stage ${n})`;
|
||||
|
||||
/* --------------------------------------------------------------- road */
|
||||
|
||||
@@ -125,11 +154,15 @@ export const rowOf = (d) => Math.floor(d / ROW);
|
||||
// (a drop's aim), so a road belongs to one round.
|
||||
let roadSerial = 0;
|
||||
|
||||
export function newRoad(seed = 1) {
|
||||
export function newRoad(seed = 1, shuffle = false) {
|
||||
const spec = STAGES[0];
|
||||
const road = {
|
||||
id: ++roadSerial,
|
||||
seed: seed >>> 0,
|
||||
shuffle: Boolean(shuffle),
|
||||
decks: [],
|
||||
specs: new Map(),
|
||||
forceItem: null,
|
||||
rows: 0,
|
||||
L: [],
|
||||
R: [],
|
||||
@@ -192,14 +225,34 @@ export const roadEnd = (road) => road.rows * ROW;
|
||||
const between = (random, [lo, hi]) => lo + random() * (hi - lo);
|
||||
// A hole's length, a whole number of rows.
|
||||
const holeLen = (random, range, more = 0) => ROW * Math.round(clamp(between(random, range) + more, MIN_HOLE, MAX_HOLE) / ROW);
|
||||
// The power-ups, and how often each turns up.
|
||||
const POWER_ROLL = Object.freeze([
|
||||
["spring", 0.3],
|
||||
["bubble", 0.25],
|
||||
["nitro", 0.25],
|
||||
["mega", 0.2],
|
||||
// The power-ups, how often each turns up, and the stage each waits for.
|
||||
export const POWER_ROLL = Object.freeze([
|
||||
["rocket", 0.17, 2],
|
||||
["spring", 0.11, 2],
|
||||
["bubble", 0.13, 2],
|
||||
["nitro", 0.11, 2],
|
||||
["mega", 0.09, 2],
|
||||
["oil", 0.1, 3],
|
||||
["pound", 0.1, 4],
|
||||
["magnet", 0.08, 3],
|
||||
["zap", 0.08, 5],
|
||||
["heart", 0.03, 6],
|
||||
]);
|
||||
|
||||
// A power-up for stage `n`, from a roll of 0 to 1.
|
||||
export function rollPower(n, roll) {
|
||||
let total = 0;
|
||||
for (const [, share, from] of POWER_ROLL) if (n >= from) total += share;
|
||||
let left = roll * total;
|
||||
let kind = "spring";
|
||||
for (const [k, share, from] of POWER_ROLL) {
|
||||
if (n < from) continue;
|
||||
kind = k;
|
||||
if ((left -= share) < 0) break;
|
||||
}
|
||||
return kind;
|
||||
}
|
||||
|
||||
// Plain road, with a power-up on it when one is due.
|
||||
function plain(road, spec, random, len, c1, w1) {
|
||||
const from = road.rows;
|
||||
@@ -207,14 +260,10 @@ function plain(road, spec, random, len, c1, w1) {
|
||||
if (!spec.pickups || roadEnd(road) < road.nextItem) return;
|
||||
const j = from + Math.floor((road.rows - from) / 2);
|
||||
const half = (road.R[j] - road.L[j]) / 2 - 4;
|
||||
let roll = random();
|
||||
let kind = "spring";
|
||||
for (const [k, share] of POWER_ROLL) {
|
||||
kind = k;
|
||||
if ((roll -= share) < 0) break;
|
||||
}
|
||||
const kind = road.forceItem || rollPower(spec.n, random());
|
||||
road.forceItem = null;
|
||||
road.items.push({ d: j * ROW + ROW / 2, x: (road.L[j] + road.R[j]) / 2 + (random() * 2 - 1) * Math.max(0, half), kind, taken: false });
|
||||
road.nextItem = roadEnd(road) + ITEM_GAP + random() * ITEM_SPREAD;
|
||||
road.nextItem = roadEnd(road) + (ITEM_GAP + random() * ITEM_SPREAD) / (spec.itemRate || 1);
|
||||
}
|
||||
|
||||
// The road is built a stage at a time, at least BUILD_AHEAD units ahead of
|
||||
@@ -239,8 +288,8 @@ const SLOPE = 0.28;
|
||||
// A field edge no road comes nearer than.
|
||||
const EDGE = 3;
|
||||
// Power-ups lie ITEM_GAP to ITEM_GAP + ITEM_SPREAD units apart.
|
||||
const ITEM_GAP = 300;
|
||||
const ITEM_SPREAD = 120;
|
||||
const ITEM_GAP = 230;
|
||||
const ITEM_SPREAD = 110;
|
||||
// Stars over a hole, STAR_STEP apart.
|
||||
const STAR_STEP = 4;
|
||||
|
||||
@@ -462,7 +511,7 @@ function ball(road, spec, random) {
|
||||
sign(road, d0 - 10, "ball");
|
||||
plain(road, spec, random, len, road.c, road.w);
|
||||
const i = rowOf(d0 + len / 2);
|
||||
road.hazards.push({ kind: "ball", d: d0 + len / 2, c: (road.L[i] + road.R[i]) / 2, amp: (road.R[i] - road.L[i]) / 2 - 3, r: 3, period: (2300 + random() * 900) / (spec.pace || 1), phase: random() * TAU });
|
||||
road.hazards.push({ kind: "ball", what: spec.roll || "orange", d: d0 + len / 2, c: (road.L[i] + road.R[i]) / 2, amp: (road.R[i] - road.L[i]) / 2 - 3, r: 3, period: (2300 + random() * 900) / (spec.pace || 1), phase: random() * TAU });
|
||||
}
|
||||
|
||||
function sprinkler(road, spec, random) {
|
||||
@@ -489,7 +538,183 @@ function wind(road, spec, random) {
|
||||
road.hazards.push({ kind: "wind", d: d0, d1: roadEnd(road), dir: random() < 0.5 ? -1 : 1, period: 2600 + random() * 600, onMs: 1300, phase: random() * 3000 });
|
||||
}
|
||||
|
||||
const PIECES = Object.freeze({ straight, crack, river, split, ramp, chicane, crumble, train, sway, boost, slick, ball, sprinkler, drop, wind });
|
||||
// A conveyor or two right across the road, each carrying whatever is on it
|
||||
// toward one edge, with stars along the edge it carries you away from.
|
||||
function belt(road, spec, random) {
|
||||
const n = random() < 0.5 ? 1 : 2;
|
||||
const each = 34 + random() * 14;
|
||||
const w = clamp(road.w, spec.width[0], spec.width[1]);
|
||||
const c = clamp(road.c, w / 2 + EDGE, FIELD_W - w / 2 - EDGE);
|
||||
plain(road, spec, random, 30, c, w);
|
||||
let dir = random() < 0.5 ? -1 : 1;
|
||||
sign(road, roadEnd(road) - 16, "belt");
|
||||
for (let k = 0; k < n; k++) {
|
||||
const d0 = roadEnd(road);
|
||||
lay(road, each, c, w);
|
||||
road.pads.push({ kind: "belt", x: c, d: d0 + each / 2, w, l: each, dir });
|
||||
for (let d = d0 + 6; d < d0 + each - 4; d += 7) road.stars.push({ x: c - dir * (w / 2 - 4), d, taken: false });
|
||||
lay(road, 16, c, w);
|
||||
dir = -dir;
|
||||
}
|
||||
plain(road, spec, random, 20, c, w);
|
||||
}
|
||||
|
||||
// A spring pad on plain road: it throws any car that crosses it up, POP_AIR
|
||||
// the usual jump, through an arc of stars.
|
||||
function pop(road, spec, random) {
|
||||
const len = 110 + random() * 30;
|
||||
const d0 = roadEnd(road);
|
||||
plain(road, spec, random, len, road.c, road.w);
|
||||
const d = d0 + 24;
|
||||
const i = rowOf(d);
|
||||
const x = (road.L[i] + road.R[i]) / 2 + (random() * 2 - 1) * Math.max(0, (road.R[i] - road.L[i]) / 2 - 6);
|
||||
road.pads.push({ kind: "pop", x, d, w: 6.5, l: 5 });
|
||||
starLine(road, x, d + 8, d + Math.min(len - 40, reach(JUMP_FAIR * TOP_SPEED) * POP_AIR - 6));
|
||||
}
|
||||
|
||||
// Pinball bumpers scattered over a wide stretch, never two so close that no
|
||||
// car fits between them or between one and the road's edge.
|
||||
function bumpers(road, spec, random) {
|
||||
const w = Math.max(road.w, spec.width[1] - 2);
|
||||
const c = clamp(road.c, w / 2 + EDGE, FIELD_W - w / 2 - EDGE);
|
||||
plain(road, spec, random, 30, c, w);
|
||||
const d0 = roadEnd(road);
|
||||
sign(road, d0 - 14, "bumper");
|
||||
const n = 4 + Math.floor(random() * 4);
|
||||
const step = 20;
|
||||
lay(road, n * step + 14, c, w);
|
||||
let last = 0;
|
||||
for (let k = 0; k < n; k++) {
|
||||
// Three lanes across; never the lane the last one took.
|
||||
let lane = Math.floor(random() * 3) - 1;
|
||||
if (lane === last) lane = lane >= 1 ? -1 : lane + 1;
|
||||
last = lane;
|
||||
road.blocks.push({ kind: "bumper", x: c + lane * (w / 2 - BUMPER_R - CAR_W - 2.5), d: d0 + 10 + k * step, w: BUMPER_R * 2, l: BUMPER_R * 2, hit: 0, lit: -1e9 });
|
||||
}
|
||||
plain(road, spec, random, 20, c, w);
|
||||
}
|
||||
|
||||
// A beam across the road between two posts, on for `onMs` of every
|
||||
// `period`, the posts blinking LASER_WARN_MS before: wait for it, or jump it.
|
||||
function laser(road, spec, random) {
|
||||
plain(road, spec, random, 56, road.c, road.w);
|
||||
const n = random() < 0.4 ? 2 : 1;
|
||||
sign(road, roadEnd(road) - 36, "laser");
|
||||
for (let k = 0; k < n; k++) {
|
||||
const d = roadEnd(road) + 2;
|
||||
lay(road, 4, road.c, road.w);
|
||||
const i = rowOf(d);
|
||||
road.hazards.push({ kind: "laser", d, half: 0.9, x0: road.L[i] - 1.5, x1: road.R[i] + 1.5, period: 2300 + random() * 600, onMs: 950, phase: random() * 3000 });
|
||||
if (k < n - 1) lay(road, 36, road.c, road.w);
|
||||
}
|
||||
plain(road, spec, random, 34, road.c, road.w);
|
||||
}
|
||||
|
||||
// Something heavy slamming down on one side of the road on a timer, then
|
||||
// the other: its shadow grows STOMP_WARN_MS before it lands, it stays down
|
||||
// `downMs` (a block while it does) and lifts again.
|
||||
function stomper(road, spec, random) {
|
||||
const w = clamp(road.w, spec.width[0], spec.width[1]);
|
||||
const c = clamp(road.c, w / 2 + EDGE, FIELD_W - w / 2 - EDGE);
|
||||
plain(road, spec, random, 44, c, w);
|
||||
const d0 = roadEnd(road);
|
||||
sign(road, d0 - 24, "stomper");
|
||||
const n = 2 + Math.floor(random() * 2);
|
||||
const gap = 38;
|
||||
lay(road, n * gap + 6, c, w);
|
||||
let side = random() < 0.5 ? -1 : 1;
|
||||
const period = 2300 + random() * 500;
|
||||
for (let k = 0; k < n; k++) {
|
||||
const sw = w * 0.5;
|
||||
road.hazards.push({ kind: "stomper", d: d0 + 14 + k * gap, x: c + side * (w / 2 - sw / 2), w: sw, l: 7, what: spec.stomp || "book", period, downMs: 850, phase: random() * 500 + k * (period / 2) });
|
||||
side = -side;
|
||||
}
|
||||
plain(road, spec, random, 26, c, w);
|
||||
}
|
||||
|
||||
// A long thing rolling from edge to edge and back: a crash to drive into,
|
||||
// points to jump.
|
||||
function roller(road, spec, random) {
|
||||
const len = 84 + random() * 30;
|
||||
const d0 = roadEnd(road);
|
||||
sign(road, d0 - 8, "ball");
|
||||
plain(road, spec, random, len, road.c, road.w);
|
||||
const i = rowOf(d0 + len / 2);
|
||||
const half = (road.R[i] - road.L[i]) * 0.2;
|
||||
road.hazards.push({ kind: "roller", d: d0 + len / 2, c: (road.L[i] + road.R[i]) / 2, amp: (road.R[i] - road.L[i]) / 2 - half - 0.5, r: 1.5, half, what: spec.roller || "pin", period: (3000 + random() * 900) / (spec.pace || 1), phase: random() * TAU });
|
||||
}
|
||||
|
||||
// A kicker: a big ramp in one lane that throws you KICKER_AIR the usual
|
||||
// jump, over a whole chicane of barriers and through a long line of stars,
|
||||
// with clear road to come down on. Miss it and the chicane is there to weave.
|
||||
function kicker(road, spec, random) {
|
||||
const w = clamp(road.w, spec.width[0], spec.width[1]);
|
||||
const c = clamp(road.c, w / 2 + EDGE, FIELD_W - w / 2 - EDGE);
|
||||
plain(road, spec, random, 50, c, w);
|
||||
const d0 = roadEnd(road);
|
||||
sign(road, d0 - 30, "chicane");
|
||||
const x = c + (random() * 2 - 1) * Math.max(0, w / 2 - 7);
|
||||
road.pads.push({ kind: "kicker", x, d: d0 - 5, w: 9, l: 8, air: KICKER_AIR });
|
||||
const n = 3;
|
||||
const gap = 30;
|
||||
lay(road, n * gap + 16, c, w);
|
||||
const kind = spec.barrier || "cone";
|
||||
const first = random() < 0.5 ? -1 : 1;
|
||||
for (let k = 0; k < n; k++) {
|
||||
const side = k % 2 ? -first : first;
|
||||
const bw = Math.min(w * 0.46, w - CAR_W - 7);
|
||||
const d = d0 + 16 + k * gap;
|
||||
const i = rowOf(d);
|
||||
road.blocks.push({ kind, x: side < 0 ? road.L[i] + bw / 2 : road.R[i] - bw / 2, d, w: bw, l: 3, side, hit: 0 });
|
||||
}
|
||||
starLine(road, x, d0 + 2, d0 + reach(JUMP_FAIR * TOP_SPEED) * KICKER_AIR - 8);
|
||||
lay(road, 96, c, w);
|
||||
}
|
||||
|
||||
// A row of blocks right across the road, after a run-up and a sign: there
|
||||
// is no way round, only over.
|
||||
function wall(road, spec, random) {
|
||||
plain(road, spec, random, 64, road.c, road.w);
|
||||
const d0 = roadEnd(road);
|
||||
sign(road, d0 - 44, "chicane");
|
||||
lay(road, 8, road.c, road.w);
|
||||
const i = rowOf(d0 + 3);
|
||||
road.blocks.push({ kind: "block", x: (road.L[i] + road.R[i]) / 2, d: d0 + 3, w: road.R[i] - road.L[i] - 0.6, l: 3, side: 1, hit: 0, wall: true });
|
||||
if (random() < (spec.stars || 0)) starLine(road, road.c + (random() * 2 - 1) * (road.w / 2 - 5), d0 - 4, d0 + 12);
|
||||
plain(road, spec, random, 30, road.c, road.w);
|
||||
}
|
||||
|
||||
// Spring pads right across the road, one after another: each throws every
|
||||
// car on it up, so the stretch is three bounces long.
|
||||
function trampoline(road, spec, random) {
|
||||
const w = clamp(road.w, spec.width[0], spec.width[1]);
|
||||
const c = clamp(road.c, w / 2 + EDGE, FIELD_W - w / 2 - EDGE);
|
||||
plain(road, spec, random, 34, c, w);
|
||||
for (let k = 0; k < 3; k++) {
|
||||
const d = roadEnd(road) + 4;
|
||||
lay(road, 56, c, w);
|
||||
road.pads.push({ kind: "pop", x: c, d, w: w - 2, l: 4 });
|
||||
starLine(road, c + (random() * 2 - 1) * (w / 2 - 5), d + 10, d + 38);
|
||||
}
|
||||
plain(road, spec, random, 34, c, w);
|
||||
}
|
||||
|
||||
// A narrow lane of boost strips, one after another, with a star after each.
|
||||
function turbo(road, spec, random) {
|
||||
const w1 = between(random, spec.width);
|
||||
const c = clamp(road.c, w1 / 2 + EDGE, FIELD_W - w1 / 2 - EDGE);
|
||||
lay(road, 26, c, TURBO_W);
|
||||
const d0 = roadEnd(road);
|
||||
lay(road, 96, c, TURBO_W);
|
||||
for (let k = 0; k < 4; k++) {
|
||||
const d = d0 + 8 + k * 24;
|
||||
road.pads.push({ kind: "boost", x: c, d, w: 5, l: 8 });
|
||||
for (let s = 1; s <= 3; s++) road.stars.push({ x: c, d: d + 4 + s * 4, taken: false });
|
||||
}
|
||||
lay(road, 26, c, w1);
|
||||
}
|
||||
|
||||
const PIECES = Object.freeze({ kicker, wall, trampoline, turbo, straight, crack, river, split, ramp, chicane, crumble, train, sway, boost, slick, ball, sprinkler, drop, wind, belt, pop, bumpers, laser, stomper, roller });
|
||||
export const PIECE_NAMES = Object.freeze(Object.keys(PIECES));
|
||||
|
||||
// Lays stage `n` on the end of the road, from its own seeded random, so the
|
||||
@@ -498,33 +723,54 @@ export const PIECE_NAMES = Object.freeze(Object.keys(PIECES));
|
||||
// is `len` long. stageAt[n - 1] is where it starts, stageAt[n] where the
|
||||
// next one will.
|
||||
export function buildStage(road, n, random = seeded(road.seed + n * 7919)) {
|
||||
const spec = stageFor(n);
|
||||
const spec = stageFor(n, road);
|
||||
road.building = n;
|
||||
const start = roadEnd(road);
|
||||
road.stageAt[n - 1] = start;
|
||||
if (n === 1) road.nextItem = 0;
|
||||
// A boss stage opens with rockets on the road: something to fight with.
|
||||
if (spec.boss) {
|
||||
road.nextItem = 0;
|
||||
road.forceItem = "rocket";
|
||||
}
|
||||
plain(road, spec, random, n === 1 ? START_RUN : LINE_RUN, road.c, road.w);
|
||||
let last = "straight";
|
||||
while (roadEnd(road) - start < spec.len) {
|
||||
const far = (roadEnd(road) - start) / spec.len;
|
||||
let total = 0;
|
||||
for (const name of PIECE_NAMES) total += pieceWeight(spec, name, far, last);
|
||||
let roll = random() * total;
|
||||
let pick = "straight";
|
||||
for (const name of PIECE_NAMES) {
|
||||
roll -= pieceWeight(spec, name, far, last);
|
||||
if (roll < 0) {
|
||||
pick = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
PIECES[pick](road, spec, random);
|
||||
last = pick;
|
||||
}
|
||||
while (roadEnd(road) - start < spec.len) last = layPiece(road, spec, random, (roadEnd(road) - start) / spec.len, last);
|
||||
road.built = n;
|
||||
road.stageAt[n] = roadEnd(road);
|
||||
}
|
||||
|
||||
// One more piece on the end of the road, by the stage's weights.
|
||||
function layPiece(road, spec, random, far, last) {
|
||||
let total = 0;
|
||||
for (const name of PIECE_NAMES) total += pieceWeight(spec, name, far, last);
|
||||
let roll = random() * total;
|
||||
let pick = "straight";
|
||||
for (const name of PIECE_NAMES) {
|
||||
roll -= pieceWeight(spec, name, far, last);
|
||||
if (roll < 0) {
|
||||
pick = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
PIECES[pick](road, spec, random);
|
||||
return pick;
|
||||
}
|
||||
|
||||
// More of stage `n`, the last one built, until the road reaches `to`: its
|
||||
// line moves to the new end. bounce.js calls this while a boss is still
|
||||
// alive, so a boss stage lasts until its boss is beaten.
|
||||
export function extendStage(road, n, to) {
|
||||
if (road.built !== n || roadEnd(road) >= to) return false;
|
||||
const spec = stageFor(n, road);
|
||||
road.building = n;
|
||||
const random = seeded((road.seed + n * 7919 + road.rows * 31) >>> 0);
|
||||
let last = "straight";
|
||||
while (roadEnd(road) < to) last = layPiece(road, spec, random, 0.5, last);
|
||||
road.stageAt[n] = roadEnd(road);
|
||||
return true;
|
||||
}
|
||||
|
||||
// A piece's weight: no crack before `crackFrom` of the stage, and never the
|
||||
// same piece but a straight twice in a row.
|
||||
function pieceWeight(spec, name, far, last) {
|
||||
@@ -696,6 +942,40 @@ export function trainAt(h, t) {
|
||||
// A ball's middle across the road at `t`, and its roll (for its stripes).
|
||||
export const ballX = (h, t) => h.c + h.amp * Math.sin((t / h.period) * TAU + h.phase);
|
||||
|
||||
// A spring pad throws a car up POP_AIR the usual jump; a bumper is BUMPER_R
|
||||
// round.
|
||||
export const POP_AIR = 1.25;
|
||||
// A kicker throws a car KICKER_AIR the usual jump; a turbo lane is TURBO_W wide.
|
||||
export const KICKER_AIR = 1.9;
|
||||
export const TURBO_W = 20;
|
||||
export const BUMPER_R = 2.6;
|
||||
|
||||
// A laser's beam at `t`: on for `onMs` of each `period`, its posts
|
||||
// blinking for LASER_WARN_MS before. Into LASER.
|
||||
export const LASER_WARN_MS = 600;
|
||||
export const LASER = { on: false, warn: false };
|
||||
export function laserAt(h, t) {
|
||||
const c = (t + h.phase) % h.period;
|
||||
LASER.on = c < h.onMs;
|
||||
LASER.warn = LASER.on || c > h.period - LASER_WARN_MS;
|
||||
return LASER;
|
||||
}
|
||||
|
||||
// A stomper at `t`: down (on the road, a block) for `downMs` of each
|
||||
// `period`, its shadow growing for STOMP_WARN_MS before it lands (`fall`
|
||||
// 0 to 1), and `hit` true only in the STOMP_HIT_MS it comes down in. Into
|
||||
// STOMP.
|
||||
export const STOMP_WARN_MS = 800;
|
||||
export const STOMP_HIT_MS = 90;
|
||||
export const STOMP = { down: false, hit: false, fall: 0 };
|
||||
export function stomperAt(h, t) {
|
||||
const c = (t + h.phase) % h.period;
|
||||
STOMP.down = c < h.downMs;
|
||||
STOMP.hit = c < STOMP_HIT_MS;
|
||||
STOMP.fall = STOMP.down ? 1 : Math.max(0, 1 - (h.period - c) / STOMP_WARN_MS);
|
||||
return STOMP;
|
||||
}
|
||||
|
||||
// A sprinkler's spray at `t`: the end of its jet, sweeping SPRAY_SWEEP each
|
||||
// way of straight across the road. Into SPRAY.
|
||||
export const SPRAY_SWEEP = 1.05;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,11 +1,12 @@
|
||||
// Plan2Code Web Console - Bounce Road's stages as data: each stage's length, the road's widths, the pieces it lays and how often, the holes it may cut and how long, the hazards it brings, and the rivals on it.
|
||||
// Plan2Code Web Console - Bounce Road's stages as data: the themes (each one's road widths, the pieces it lays and how often, its bridges, barriers and hazards), the difficulty of each stage by its place in the run (length, par, holes, rivals), the boss arenas, the twists, and how a run deals them.
|
||||
//
|
||||
// Data only (no imports): bounce-road.js builds the road from these numbers,
|
||||
// a stage at a time from a seed, and bounce-scenery.js draws each stage in
|
||||
// the look named by its id. Every stage keeps most of what the earlier ones
|
||||
// brought and adds something of its own; past the last, the road goes round
|
||||
// again from LAP_FROM, quicker and meaner (bounce-road.js's stageFor makes
|
||||
// the numbers for that).
|
||||
// Data and plain arithmetic only (no imports): bounce-road.js builds the road
|
||||
// from these numbers, a stage at a time from a seed, and bounce-scenery.js
|
||||
// draws each stage in the look named by its theme's id. A stage is a theme
|
||||
// (what it looks like and what it throws at you) in a slot (how hard: the
|
||||
// slot sets the length, the holes and the rivals), so a run can deal the
|
||||
// themes in a new order every time and stay fair. Every third stage is a
|
||||
// boss stage, in that boss's arena.
|
||||
|
||||
// The field: FIELD_W units across, FIELD_H of road on the board at once. The
|
||||
// road is laid in rows ROW units long.
|
||||
@@ -18,12 +19,17 @@ export const ROW = 2;
|
||||
// suite does too. A drawbridge's open span counts as a hole.
|
||||
export const MAX_HOLE = 30;
|
||||
|
||||
// Past the last stage, the road goes round again from this stage.
|
||||
export const LAP_FROM = 3;
|
||||
// Every WORLD-th stage is a boss stage; CYCLE stages make one lap of the
|
||||
// run, after which the themes and the bosses are dealt again, quicker.
|
||||
export const WORLD = 3;
|
||||
export const CYCLE = 15;
|
||||
// At most this many rivals on the road at once, however far you get.
|
||||
export const MAX_RIVALS = 7;
|
||||
|
||||
// Per stage:
|
||||
// - `len`: units of road from its line to the next stage's; `par`: the
|
||||
// seconds a quick run takes, the time bonus counting from it.
|
||||
const freeze = (s) => Object.freeze(Object.fromEntries(Object.entries(s).map(([k, v]) => [k, typeof v === "object" && v ? Object.freeze(v) : v])));
|
||||
|
||||
// A theme:
|
||||
// - `tier`: how late in a run it belongs (0 always opens, 1 early, 3 late).
|
||||
// - `width`: the road's narrowest and widest, in units.
|
||||
// - `weights`: how often each piece is laid: `straight`, `crack` (a hole
|
||||
// across the road), `river` (water crossed on a bridge, some broken, some
|
||||
@@ -33,9 +39,12 @@ export const LAP_FROM = 3;
|
||||
// `train` (a toy train crossing), `sway` (a bridge that sways), and the
|
||||
// hazards laid on a straight: `boost` (speed strips), `slick` (oil and
|
||||
// water), `ball` (a ball rolling across), `sprinkler` (a sweeping spray),
|
||||
// `drop` (something falling where you are heading) and `wind` (gusts).
|
||||
// `drop` (something falling where you are heading), `wind` (gusts), `belt`
|
||||
// (a conveyor carrying you across), `pop` (a spring pad that throws you
|
||||
// up), `bumpers` (pinball bumpers that kick you away, for points), `laser`
|
||||
// (a beam across the road on a timer), `stomper` (something heavy slamming
|
||||
// down on a timer) and `roller` (a long thing rolling across: a crash).
|
||||
// A crack waits for `crackFrom` of the stage.
|
||||
// - `crack` and `gap`: the shortest and longest crack, and broken span.
|
||||
// - `bridge`: the bridge's narrowest and widest; `river` its length.
|
||||
// - `broken`: the share of bridges with a broken span; `double`: the share
|
||||
// of those with two; `drawbridge`: the share of the rest with a span that
|
||||
@@ -43,251 +52,133 @@ export const LAP_FROM = 3;
|
||||
// - `median`: a flowerbed's shortest and longest; `medianWidth`: its
|
||||
// narrowest and widest; `splitWidth`: the road's whole width round it.
|
||||
// - `barrier`: what a chicane is made of, "cone" (knocked flying, it slows
|
||||
// you) or "block" (solid: nose first is a crash). `drops`: what falls.
|
||||
// - `rivals`: how many on the road at once; `kinds`: which; `pace`: their
|
||||
// speed, times their own; `sharp`: how keenly they block, ram and dodge.
|
||||
// - `pickups`: whether power-ups lie on the road; `stars`: the share of
|
||||
// holes with a line of stars over them; `boss`: the Monster truck comes.
|
||||
// Every list and table in a stage is frozen with it.
|
||||
const stage = (s) => Object.freeze(Object.fromEntries(Object.entries(s).map(([k, v]) => [k, typeof v === "object" && v ? Object.freeze(v) : v])));
|
||||
// you) or "block" (solid: nose first is a crash). `drops`: what falls;
|
||||
// `roll`, `roller` and `stomp`: what the ball, the roller and the stomper
|
||||
// are drawn as.
|
||||
// - `ice`: the whole road has little grip; `dark`: only your headlights.
|
||||
// - `boss`: the boss whose arena this is (a boss stage only).
|
||||
const BRIDGES = { bridge: [17, 21], river: [36, 56], broken: 0.7, double: 0.2, drawbridge: 0.3 };
|
||||
const BEDS = { median: [70, 120], medianWidth: [8, 13], splitWidth: [48, 58] };
|
||||
|
||||
export const STAGES = Object.freeze([
|
||||
stage({
|
||||
id: "chalk",
|
||||
title: "Chalk Lane",
|
||||
sub: "Bump them off, jump the cracks, hit the boost",
|
||||
len: 1500,
|
||||
par: 29,
|
||||
width: [32, 44],
|
||||
weights: { straight: 2, crack: 1.2, boost: 1, chicane: 0.7 },
|
||||
crackFrom: 0.2,
|
||||
crack: [8, 14],
|
||||
barrier: "cone",
|
||||
rivals: 3,
|
||||
kinds: ["zigzag", "brick"],
|
||||
pace: 1,
|
||||
sharp: 0.25,
|
||||
pickups: false,
|
||||
stars: 0.6,
|
||||
}),
|
||||
stage({
|
||||
id: "hose",
|
||||
title: "Hose Creek",
|
||||
sub: "Broken bridges and a sprinkler on the loose",
|
||||
len: 1700,
|
||||
par: 32,
|
||||
width: [30, 44],
|
||||
weights: { straight: 2, crack: 1, river: 1.6, sprinkler: 1, boost: 0.6 },
|
||||
export const THEMES = Object.freeze({
|
||||
chalk: freeze({ id: "chalk", title: "Chalk Lane", sub: "Bump them off, jump the cracks, hit the boost", tier: 0, width: [32, 44], weights: { straight: 2, crack: 1.2, boost: 1, chicane: 0.7, pop: 0.5 }, crackFrom: 0.2, barrier: "cone" }),
|
||||
hose: freeze({ id: "hose", title: "Hose Creek", sub: "Broken bridges and a sprinkler on the loose", tier: 1, width: [30, 44], weights: { straight: 2, crack: 1, river: 1.6, sprinkler: 1, boost: 0.6 }, bridge: [18, 22], river: [36, 56], broken: 0.7, double: 0, drawbridge: 0 }),
|
||||
kitchen: freeze({ id: "kitchen", title: "Kitchen Floor", sub: "Oil slicks, a rolling orange and the rolling pin", tier: 1, width: [30, 42], weights: { straight: 1.8, crack: 1, slick: 1.3, ball: 1.1, chicane: 0.8, boost: 0.6, roller: 0.8 }, barrier: "cone", roll: "orange", roller: "pin" }),
|
||||
bath: freeze({ id: "bath", title: "Bubble Bath", sub: "Soap slicks, faucet jets and a wobbly bath mat", tier: 1, width: [30, 42], weights: { straight: 1.7, crack: 0.8, river: 1.1, sway: 0.7, slick: 1, pop: 1.2, sprinkler: 0.6, boost: 0.5 }, bridge: [18, 22], river: [36, 52], broken: 0.6, double: 0, drawbridge: 0 }),
|
||||
beds: freeze({ id: "beds", title: "Flowerbed Fork", sub: "Ramps, forks in the road and falling flowerpots", tier: 2, width: [30, 42], weights: { straight: 1.6, crack: 0.8, river: 0.9, split: 1.4, ramp: 1.1, drop: 1, slick: 0.4 }, ...BRIDGES, double: 0, drawbridge: 0, ...BEDS, drops: "pot" }),
|
||||
pinball: freeze({ id: "pinball", title: "Pinball Alley", sub: "Bumpers pay out. Conveyors do not care where you were going", tier: 2, width: [32, 44], weights: { straight: 1.3, crack: 0.9, bumpers: 1.7, belt: 1.1, boost: 1, ramp: 0.8, ball: 0.8, pop: 0.6 }, barrier: "cone", roll: "steel" }),
|
||||
desk: freeze({ id: "desk", title: "Homework Desk", sub: "Rolling pencils, slamming books and spilled ink", tier: 2, width: [30, 42], weights: { straight: 1.5, crack: 1, roller: 1.2, stomper: 1.2, slick: 0.7, chicane: 0.7, boost: 0.5 }, barrier: "block", roller: "pencil", stomp: "book" }),
|
||||
sand: freeze({ id: "sand", title: "Sandbox Run", sub: "The road crumbles behind you. Keep your foot down", tier: 2, width: [27, 38], weights: { straight: 1.5, crack: 0.9, river: 0.8, split: 0.8, crumble: 1.2, chicane: 1, drop: 0.6, ramp: 0.6 }, bridge: [16, 20], river: [40, 60], broken: 0.8, double: 0.3, drawbridge: 0, ...BEDS, medianWidth: [8, 12], splitWidth: [48, 56], barrier: "block", drops: "bucket" }),
|
||||
toys: freeze({ id: "toys", title: "Toy Room", sub: "Mind the train, and the mallet", tier: 2, width: [28, 40], weights: { straight: 1.4, crack: 0.9, train: 1.4, chicane: 1, ball: 0.9, ramp: 0.7, boost: 0.7, slick: 0.4, pop: 0.5, stomper: 0.5 }, barrier: "block", roll: "ball", stomp: "mallet" }),
|
||||
ice: freeze({ id: "ice", title: "Freezer Aisle", sub: "No grip anywhere, and the snowballs are rolling", tier: 3, width: [30, 42], weights: { straight: 1.7, crack: 1, ball: 1.1, river: 0.7, chicane: 0.6, wind: 0.6, crumble: 0.6, boost: 0.5 }, bridge: [18, 22], river: [36, 52], broken: 0.6, double: 0.2, drawbridge: 0, barrier: "block", roll: "snow", ice: true }),
|
||||
pond: freeze({ id: "pond", title: "Garden Pond", sub: "Swaying bridges and drawbridges over deep water", tier: 3, width: [28, 40], weights: { straight: 1.2, crack: 0.6, river: 1.4, sway: 1.7, split: 0.6, sprinkler: 0.7, drop: 0.5 }, bridge: [17, 21], river: [40, 64], broken: 0.5, double: 0.4, drawbridge: 0.9, ...BEDS, medianWidth: [8, 12], drops: "acorn" }),
|
||||
gutter: freeze({ id: "gutter", title: "Rooftop Gutter", sub: "Gusts, a crumbling gutter, and nowhere to hide", tier: 3, width: [25, 34], weights: { straight: 1.2, crack: 1, wind: 1.4, crumble: 1.1, chicane: 0.8, drop: 0.7, boost: 0.6, river: 0.6 }, bridge: [16, 19], river: [40, 60], broken: 0.7, double: 0.4, drawbridge: 0.7, barrier: "block", drops: "cone" }),
|
||||
lava: freeze({ id: "lava", title: "The Floor Is Lava", sub: "Cushion to cushion. Do not touch the floor", tier: 3, width: [28, 40], weights: { straight: 1.2, crack: 1.6, crumble: 1.1, pop: 1, ramp: 0.9, roller: 0.7, drop: 0.6, split: 0.5, boost: 0.6 }, ...BEDS, barrier: "block", drops: "rock", roller: "ember" }),
|
||||
night: freeze({ id: "night", title: "Night Lights", sub: "Everything at once, in the dark", tier: 3, width: [26, 38], weights: { straight: 1.2, crack: 1, river: 1, split: 0.8, ramp: 0.7, chicane: 0.7, crumble: 0.7, train: 0.8, sway: 0.7, ball: 0.7, sprinkler: 0.5, drop: 0.6, wind: 0.5, slick: 0.5, boost: 0.6, laser: 0.6, pop: 0.4 }, bridge: [16, 20], river: [44, 64], broken: 0.7, double: 0.5, drawbridge: 0.7, ...BEDS, medianWidth: [8, 12], barrier: "block", drops: "pot", roll: "ball", dark: true }),
|
||||
// The arenas: roomier roads with less in the way, so the fight is the boss.
|
||||
garage: freeze({ id: "garage", title: "Grease Pit", sub: "The Big Rig hauls oil and barrels. Land on its roof", tier: 4, boss: "tanker", width: [32, 42], weights: { straight: 2.2, crack: 0.8, slick: 0.6, chicane: 0.5, boost: 0.9, ramp: 0.6, pop: 0.6 }, barrier: "cone" }),
|
||||
hall: freeze({ id: "hall", title: "Hallway Runner", sub: "The Robo-Vac sweeps the hall. Jump on it when it charges", tier: 4, boss: "vac", width: [32, 42], weights: { straight: 2.3, crack: 0.9, pop: 0.8, boost: 0.8, ball: 0.5, ramp: 0.5 }, roll: "ball" }),
|
||||
attic: freeze({ id: "attic", title: "Attic Airspace", sub: "The Whirlybird bombs from above. Stomp it when it swoops", tier: 4, boss: "chopper", width: [32, 42], weights: { straight: 2.2, crack: 0.9, ramp: 0.8, pop: 0.8, boost: 0.8, laser: 0.5, chicane: 0.4 }, barrier: "block" }),
|
||||
giant: freeze({ id: "giant", title: "Monster Mash", sub: "The Monster truck. Land on its roof to beat it", tier: 4, boss: "monster", width: [30, 40], weights: { straight: 1.8, crack: 1, ramp: 1, chicane: 0.5, ball: 0.5, drop: 0.4, boost: 0.8, slick: 0.4, pop: 0.5 }, barrier: "block", drops: "tire", roll: "ball" }),
|
||||
couch: freeze({ id: "couch", title: "The Cat's Couch", sub: "The Cat. Jump its paw when it sweeps, and land on it", tier: 4, boss: "cat", width: [32, 42], weights: { straight: 2, crack: 1, ball: 0.8, ramp: 0.9, pop: 0.8, boost: 0.8 }, roll: "yarn" }),
|
||||
});
|
||||
|
||||
// The stunt pieces every theme lays besides its own: `kicker` (a big ramp
|
||||
// that flies you over a whole chicane), `wall` (a row of blocks right
|
||||
// across the road: jump it), `trampoline` (spring pads right across, one
|
||||
// after another) and `turbo` (a narrow lane of boost strips). The opening
|
||||
// stage lays half as many.
|
||||
export const WILD = Object.freeze({ kicker: 0.75, wall: 0.6, trampoline: 0.65, turbo: 0.55 });
|
||||
|
||||
// The themes a run deals its plain stages from, in the order a run with no
|
||||
// shuffle plays them, and the bosses in theirs with each one's arena.
|
||||
export const REGULAR = Object.freeze(["chalk", "hose", "kitchen", "beds", "sand", "toys", "pond", "gutter", "night", "lava", "bath", "pinball", "desk", "ice"]);
|
||||
export const BOSS_ORDER = Object.freeze(["tanker", "vac", "chopper", "monster", "cat"]);
|
||||
export const ARENAS = Object.freeze({ tanker: "garage", vac: "hall", chopper: "attic", monster: "giant", cat: "couch" });
|
||||
// How many plain stages a lap holds: the rest of the themes sit that lap out.
|
||||
export const REGULAR_PER_CYCLE = CYCLE - CYCLE / WORLD;
|
||||
|
||||
// A twist a shuffled run may put on a plain stage: `rush` (more rivals),
|
||||
// `gold` (stars over every hole, each worth double), `dark` (lights out),
|
||||
// `rain` (a wet road, little grip), `crates` (power-ups three times as
|
||||
// often) and `turbo` (boost strips everywhere).
|
||||
export const TWISTS = Object.freeze({
|
||||
rush: Object.freeze({ name: "Rush hour", blurb: "The road is packed" }),
|
||||
gold: Object.freeze({ name: "Gold rush", blurb: "Stars everywhere, worth double" }),
|
||||
dark: Object.freeze({ name: "Lights out", blurb: "Only your headlights" }),
|
||||
rain: Object.freeze({ name: "Downpour", blurb: "A wet road has little grip" }),
|
||||
crates: Object.freeze({ name: "Supply drop", blurb: "Crates all over the road" }),
|
||||
turbo: Object.freeze({ name: "Turbo lane", blurb: "Boost strips everywhere" }),
|
||||
});
|
||||
export const TWIST_NAMES = Object.freeze(Object.keys(TWISTS));
|
||||
export const TWIST_SHARE = 0.4;
|
||||
|
||||
// The stage each rival kind first comes in (its slot in a lap; every kind is
|
||||
// out from the second lap). A kind new within FRESH_SLOTS comes more often.
|
||||
export const KIND_FROM = Object.freeze({ zigzag: 1, brick: 1, frog: 2, sneak: 3, nudge: 4, spike: 4, splitter: 5, hauler: 5, bruiser: 7, racer: 7, blaster: 8, cop: 8, bomber: 10, phantom: 10, slasher: 11, magnet: 14 });
|
||||
export const FRESH_SLOTS = 3;
|
||||
|
||||
const round1 = (v) => Math.round(v * 10) / 10;
|
||||
|
||||
// The numbers a stage takes from its place in the run: stage `n` is slot
|
||||
// `k` (1 to CYCLE) of lap `lap`. Longer, quicker, keener and busier as the
|
||||
// run goes on, with longer holes (never past MAX_HOLE); a boss stage is
|
||||
// longer, with fewer rivals in the way.
|
||||
export function slotFor(n) {
|
||||
const lap = 1 + Math.floor((n - 1) / CYCLE);
|
||||
const k = 1 + ((n - 1) % CYCLE);
|
||||
const boss = k % WORLD === 0;
|
||||
const hard = k + (lap - 1) * 5;
|
||||
const len = 1060 + 36 * k + (boss ? 260 : 0) + (lap > 1 ? 100 : 0);
|
||||
const rivals = Math.min(MAX_RIVALS, 3 + Math.floor(k / 4) + (lap - 1));
|
||||
const kinds = Object.keys(KIND_FROM).filter((kind) => lap > 1 || KIND_FROM[kind] <= k);
|
||||
return {
|
||||
lap,
|
||||
slot: k,
|
||||
len,
|
||||
par: Math.round(len / 52),
|
||||
pace: round1(Math.min(1.45, 1 + 0.02 * (k - 1) + 0.07 * (lap - 1)) * 100) / 100,
|
||||
sharp: lap > 1 ? 1 : round1(Math.min(1, 0.25 + 0.055 * (k - 1)) * 100) / 100,
|
||||
rivals: boss ? Math.max(2, rivals - 2) : rivals,
|
||||
kinds: Object.freeze(kinds),
|
||||
fresh: Object.freeze(kinds.filter((kind) => lap === 1 && k - KIND_FROM[kind] < FRESH_SLOTS && KIND_FROM[kind] > 1)),
|
||||
crackFrom: 0,
|
||||
crack: [10, 16],
|
||||
gap: [12, 18],
|
||||
bridge: [18, 22],
|
||||
river: [36, 56],
|
||||
broken: 0.7,
|
||||
double: 0,
|
||||
drawbridge: 0,
|
||||
rivals: 3,
|
||||
kinds: ["zigzag", "brick", "frog"],
|
||||
pace: 1.03,
|
||||
sharp: 0.35,
|
||||
pickups: true,
|
||||
stars: 0.6,
|
||||
}),
|
||||
stage({
|
||||
id: "kitchen",
|
||||
title: "Kitchen Floor",
|
||||
sub: "Oil slicks, a rolling orange, and a Sneak dropping cones",
|
||||
len: 1800,
|
||||
par: 33,
|
||||
width: [30, 42],
|
||||
weights: { straight: 1.8, crack: 1, slick: 1.3, ball: 1.1, chicane: 0.8, boost: 0.6 },
|
||||
crackFrom: 0,
|
||||
crack: [12, 18],
|
||||
barrier: "cone",
|
||||
rivals: 4,
|
||||
kinds: ["zigzag", "brick", "frog", "sneak"],
|
||||
pace: 1.06,
|
||||
sharp: 0.45,
|
||||
pickups: true,
|
||||
stars: 0.65,
|
||||
}),
|
||||
stage({
|
||||
id: "beds",
|
||||
title: "Flowerbed Fork",
|
||||
sub: "Ramps, falling flowerpots, and the Nudge",
|
||||
len: 1900,
|
||||
par: 35,
|
||||
width: [30, 42],
|
||||
weights: { straight: 1.6, crack: 0.8, river: 0.9, split: 1.4, ramp: 1.1, drop: 1, slick: 0.4 },
|
||||
crackFrom: 0,
|
||||
crack: [12, 20],
|
||||
gap: [14, 20],
|
||||
bridge: [17, 21],
|
||||
river: [36, 56],
|
||||
broken: 0.7,
|
||||
double: 0,
|
||||
drawbridge: 0,
|
||||
median: [70, 130],
|
||||
medianWidth: [8, 14],
|
||||
splitWidth: [50, 60],
|
||||
drops: "pot",
|
||||
rivals: 4,
|
||||
kinds: ["zigzag", "brick", "frog", "nudge", "sneak"],
|
||||
pace: 1.09,
|
||||
sharp: 0.55,
|
||||
pickups: true,
|
||||
stars: 0.7,
|
||||
}),
|
||||
stage({
|
||||
id: "sand",
|
||||
title: "Sandbox Run",
|
||||
sub: "The road crumbles. Trucks too heavy to bump",
|
||||
len: 2000,
|
||||
par: 36,
|
||||
width: [27, 38],
|
||||
weights: { straight: 1.5, crack: 0.9, river: 0.8, split: 0.8, crumble: 1.2, chicane: 1, drop: 0.6, ramp: 0.6 },
|
||||
crackFrom: 0,
|
||||
crack: [12, 22],
|
||||
gap: [16, 22],
|
||||
bridge: [16, 20],
|
||||
river: [40, 60],
|
||||
broken: 0.8,
|
||||
double: 0.3,
|
||||
drawbridge: 0,
|
||||
median: [70, 130],
|
||||
medianWidth: [8, 12],
|
||||
splitWidth: [48, 56],
|
||||
barrier: "block",
|
||||
drops: "bucket",
|
||||
rivals: 5,
|
||||
kinds: ["zigzag", "brick", "frog", "nudge", "hauler", "bruiser"],
|
||||
pace: 1.12,
|
||||
sharp: 0.62,
|
||||
pickups: true,
|
||||
stars: 0.7,
|
||||
}),
|
||||
stage({
|
||||
id: "toys",
|
||||
title: "Toy Room",
|
||||
sub: "Mind the train. Catch the Racer",
|
||||
len: 2100,
|
||||
par: 37,
|
||||
width: [28, 40],
|
||||
weights: { straight: 1.4, crack: 0.9, train: 1.4, chicane: 1, ball: 0.9, ramp: 0.7, boost: 0.7, slick: 0.4 },
|
||||
crackFrom: 0,
|
||||
crack: [14, 22],
|
||||
barrier: "block",
|
||||
rivals: 5,
|
||||
kinds: ["zigzag", "brick", "frog", "nudge", "sneak", "racer", "bruiser"],
|
||||
pace: 1.15,
|
||||
sharp: 0.7,
|
||||
pickups: true,
|
||||
stars: 0.75,
|
||||
}),
|
||||
stage({
|
||||
id: "pond",
|
||||
title: "Garden Pond",
|
||||
sub: "Swaying bridges and drawbridges. The cops are out",
|
||||
len: 2200,
|
||||
par: 39,
|
||||
width: [28, 40],
|
||||
weights: { straight: 1.3, crack: 0.6, river: 1.4, sway: 1.3, split: 0.7, sprinkler: 0.7, drop: 0.5 },
|
||||
crackFrom: 0,
|
||||
crack: [14, 22],
|
||||
gap: [16, 24],
|
||||
bridge: [17, 21],
|
||||
river: [40, 64],
|
||||
broken: 0.75,
|
||||
double: 0.4,
|
||||
drawbridge: 0.8,
|
||||
median: [70, 130],
|
||||
medianWidth: [8, 12],
|
||||
splitWidth: [48, 58],
|
||||
drops: "acorn",
|
||||
rivals: 5,
|
||||
kinds: ["zigzag", "brick", "frog", "nudge", "cop", "racer"],
|
||||
pace: 1.18,
|
||||
sharp: 0.78,
|
||||
pickups: true,
|
||||
stars: 0.75,
|
||||
}),
|
||||
stage({
|
||||
id: "gutter",
|
||||
title: "Rooftop Gutter",
|
||||
sub: "Gusts, a crumbling gutter, and nowhere to hide",
|
||||
len: 2300,
|
||||
par: 40,
|
||||
width: [25, 34],
|
||||
weights: { straight: 1.2, crack: 1, wind: 1.4, crumble: 1.1, chicane: 0.8, drop: 0.7, boost: 0.6, river: 0.6 },
|
||||
crackFrom: 0,
|
||||
crack: [14, 24],
|
||||
gap: [16, 24],
|
||||
bridge: [16, 19],
|
||||
river: [40, 60],
|
||||
broken: 0.9,
|
||||
double: 0.4,
|
||||
drawbridge: 0.5,
|
||||
barrier: "block",
|
||||
drops: "cone",
|
||||
rivals: 5,
|
||||
kinds: ["zigzag", "brick", "frog", "nudge", "hauler", "cop", "bruiser", "sneak"],
|
||||
pace: 1.21,
|
||||
sharp: 0.85,
|
||||
pickups: true,
|
||||
stars: 0.8,
|
||||
}),
|
||||
stage({
|
||||
id: "night",
|
||||
title: "Night Lights",
|
||||
sub: "Everything at once, in the dark",
|
||||
len: 2400,
|
||||
par: 42,
|
||||
width: [26, 38],
|
||||
weights: { straight: 1.2, crack: 1, river: 1, split: 0.8, ramp: 0.7, chicane: 0.7, crumble: 0.7, train: 0.8, sway: 0.7, ball: 0.7, sprinkler: 0.5, drop: 0.6, wind: 0.5, slick: 0.5, boost: 0.6 },
|
||||
crackFrom: 0,
|
||||
crack: [16, 26],
|
||||
gap: [18, 26],
|
||||
bridge: [16, 20],
|
||||
river: [44, 64],
|
||||
broken: 0.9,
|
||||
double: 0.5,
|
||||
drawbridge: 0.6,
|
||||
median: [70, 130],
|
||||
medianWidth: [8, 12],
|
||||
splitWidth: [48, 58],
|
||||
barrier: "block",
|
||||
drops: "pot",
|
||||
rivals: 6,
|
||||
kinds: ["zigzag", "brick", "frog", "nudge", "hauler", "cop", "racer", "bruiser", "sneak"],
|
||||
pace: 1.24,
|
||||
sharp: 0.92,
|
||||
pickups: true,
|
||||
stars: 0.8,
|
||||
}),
|
||||
stage({
|
||||
id: "giant",
|
||||
title: "Monster Mash",
|
||||
sub: "The Monster truck. Land on its roof five times",
|
||||
len: 2600,
|
||||
par: 46,
|
||||
width: [28, 40],
|
||||
weights: { straight: 1.4, crack: 1, river: 0.8, ramp: 1, chicane: 0.6, crumble: 0.6, train: 0.5, ball: 0.6, drop: 0.5, boost: 0.8, slick: 0.4 },
|
||||
crackFrom: 0,
|
||||
crack: [16, 26],
|
||||
gap: [18, 26],
|
||||
bridge: [17, 21],
|
||||
river: [40, 60],
|
||||
broken: 0.9,
|
||||
double: 0.4,
|
||||
drawbridge: 0.5,
|
||||
barrier: "block",
|
||||
drops: "tire",
|
||||
rivals: 4,
|
||||
kinds: ["zigzag", "brick", "frog", "nudge", "cop", "racer", "bruiser", "sneak"],
|
||||
pace: 1.26,
|
||||
sharp: 1,
|
||||
pickups: true,
|
||||
stars: 0.85,
|
||||
boss: true,
|
||||
}),
|
||||
]);
|
||||
crack: Object.freeze([Math.min(18, 8 + Math.round(hard * 0.6)), Math.min(MAX_HOLE - 4, 14 + Math.round(hard * 0.85))]),
|
||||
gap: Object.freeze([Math.min(18, 12 + Math.round(hard * 0.45)), Math.min(MAX_HOLE - 4, 18 + Math.round(hard * 0.6))]),
|
||||
pickups: n > 1,
|
||||
stars: round1(Math.min(0.9, 0.58 + 0.02 * k)),
|
||||
};
|
||||
}
|
||||
|
||||
// Stage `n` as theme `id`, with `twist` on it or none: the slot's numbers,
|
||||
// then the theme's own, then what the twist changes.
|
||||
export function stageSpec(n, id, twist = null) {
|
||||
const theme = THEMES[id] || THEMES.chalk;
|
||||
const slot = slotFor(n);
|
||||
const spec = { ...slot, ...theme, n, name: slot.lap > 1 ? `${theme.title} ${slot.lap}` : theme.title, boss: theme.boss || null, twist: null, itemRate: 1 };
|
||||
if (theme.crackFrom && n === 1) spec.crackFrom = theme.crackFrom;
|
||||
const wild = Object.fromEntries(Object.entries(WILD).map(([k, v]) => [k, n === 1 ? v / 2 : v]));
|
||||
spec.weights = Object.freeze({ ...wild, ...theme.weights });
|
||||
if (twist && TWISTS[twist]) {
|
||||
spec.twist = twist;
|
||||
if (twist === "rush") spec.rivals = Math.min(MAX_RIVALS, spec.rivals + 2);
|
||||
else if (twist === "gold") {
|
||||
spec.stars = 1;
|
||||
spec.gold = true;
|
||||
} else if (twist === "dark") spec.dark = true;
|
||||
else if (twist === "rain") spec.ice = true;
|
||||
else if (twist === "crates") spec.itemRate = 3;
|
||||
else if (twist === "turbo") spec.weights = Object.freeze({ ...spec.weights, boost: (theme.weights.boost || 0) + 1.6, turbo: WILD.turbo + 1.4 });
|
||||
}
|
||||
return Object.freeze(spec);
|
||||
}
|
||||
|
||||
// The theme of stage `n` in a run with no shuffle: the bosses in order on
|
||||
// every third stage, the plain themes in order on the rest.
|
||||
export function classicTheme(n) {
|
||||
if (n % WORLD === 0) return ARENAS[BOSS_ORDER[(n / WORLD - 1) % BOSS_ORDER.length]];
|
||||
return REGULAR[(n - Math.floor(n / WORLD) - 1) % REGULAR.length];
|
||||
}
|
||||
|
||||
// The first lap of a run with no shuffle, for the lists that name stages.
|
||||
export const STAGES = Object.freeze(Array.from({ length: CYCLE }, (_, i) => stageSpec(i + 1, classicTheme(i + 1))));
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,12 +1,82 @@
|
||||
// Plan2Code Web Console - bounce: its own sound effects, merged into tones.js beside the shared kit; defines only.
|
||||
// Plan2Code Web Console - bounce: its own sound effects and music, merged into tones.js beside the shared kit; defines only.
|
||||
//
|
||||
// `tones` are one-shot sounds played with tone(name, level, pitch); `hums` are
|
||||
// held sounds kept going with hum(id, name, level, pitch). Both take the shapes
|
||||
// tones.js documents, as plain objects (tones.js freezes them). A name may be
|
||||
// defined only once across tones.js and every game's file. No imports.
|
||||
// defined only once across tones.js and every game's file. The music is in
|
||||
// bounce-music.js, merged in below as `music`: that file is the only import.
|
||||
|
||||
import { BOUNCE_MUSIC } from "./bounce-music.js";
|
||||
|
||||
export default {
|
||||
music: BOUNCE_MUSIC,
|
||||
tones: {
|
||||
// A pinball bumper: a bright bell with a solenoid's thwack.
|
||||
bounceBumper: {
|
||||
layers: [
|
||||
{ type: "triangle", from: 1568, to: 1560, seconds: 0.22, gain: 0.6 },
|
||||
{ type: "sine", from: 3136, to: 3120, seconds: 0.12, gain: 0.25 },
|
||||
{ type: "noise", seconds: 0.03, gain: 0.5, filter: { type: "bandpass", from: 2200, to: 1400, q: 2 } },
|
||||
],
|
||||
},
|
||||
// A rocket leaving its rail: a hiss that climbs away.
|
||||
bounceRocket: {
|
||||
layers: [
|
||||
{ type: "noise", seconds: 0.42, attack: 0.01, filter: { type: "bandpass", from: 900, to: 3600, q: 1.4 } },
|
||||
{ type: "sawtooth", from: 180, to: 620, seconds: 0.3, gain: 0.35, filter: { type: "lowpass", from: 1400, to: 2600 } },
|
||||
],
|
||||
},
|
||||
// Oil hitting the road: a thick glug.
|
||||
bounceOilSplat: {
|
||||
layers: [
|
||||
{ type: "sine", from: 260, to: 70, seconds: 0.22, gain: 0.8, vibrato: { rate: 18, depth: 0.12 } },
|
||||
{ type: "brown", seconds: 0.2, gain: 0.5, filter: { type: "lowpass", from: 700, to: 200 } },
|
||||
],
|
||||
},
|
||||
// A ground pound: the car slamming down and the road ringing with it.
|
||||
bouncePound: {
|
||||
layers: [
|
||||
{ type: "sine", from: 120, to: 30, seconds: 0.5, gain: 1 },
|
||||
{ type: "brown", seconds: 0.45, gain: 0.9, filter: { type: "lowpass", from: 1500, to: 100 } },
|
||||
{ type: "noise", seconds: 0.08, gain: 0.5, filter: { type: "highpass", from: 2400, to: 1200 } },
|
||||
{ type: "triangle", from: 420, to: 180, seconds: 0.3, delay: 0.04, gain: 0.3 },
|
||||
],
|
||||
},
|
||||
// Fever lit: an arcade run up the scale.
|
||||
bounceFever: {
|
||||
layers: [
|
||||
{ type: "square", notes: [523, 659, 784, 1047, 1319, 1568], seconds: 0.5, gain: 0.4, filter: { type: "lowpass", from: 2600, to: 4200 } },
|
||||
{ type: "triangle", notes: [262, 330, 392, 523, 659, 784], seconds: 0.5, gain: 0.5 },
|
||||
],
|
||||
},
|
||||
// A Slasher's blades snapping out: steel on steel.
|
||||
bounceBlade: {
|
||||
layers: [
|
||||
{ type: "noise", seconds: 0.18, filter: { type: "bandpass", from: 5200, to: 7400, q: 6 } },
|
||||
{ type: "triangle", from: 2400, to: 3600, seconds: 0.16, gain: 0.3 },
|
||||
],
|
||||
},
|
||||
// The Cat: a toy's idea of a yowl.
|
||||
bounceMeow: {
|
||||
layers: [
|
||||
{ type: "sawtooth", from: 520, to: 880, seconds: 0.18, gain: 0.5, filter: { type: "bandpass", from: 1200, to: 2200, q: 3 } },
|
||||
{ type: "sawtooth", from: 880, to: 420, seconds: 0.4, delay: 0.18, gain: 0.5, vibrato: { rate: 9, depth: 0.04 }, filter: { type: "bandpass", from: 2200, to: 900, q: 3 } },
|
||||
],
|
||||
},
|
||||
// The Robo-Vac winding up to charge: a motor's whine climbing.
|
||||
bounceVacCharge: {
|
||||
layers: [
|
||||
{ type: "sawtooth", from: 140, to: 720, seconds: 0.7, attack: 0.05, gain: 0.5, filter: { type: "lowpass", from: 800, to: 3200, q: 3 } },
|
||||
{ type: "pink", seconds: 0.7, attack: 0.1, gain: 0.5, filter: { type: "bandpass", from: 600, to: 2400, q: 1.2 } },
|
||||
],
|
||||
},
|
||||
// A gadget picked up and loaded: a clack and two rising notes.
|
||||
bounceArmed: {
|
||||
layers: [
|
||||
{ type: "noise", seconds: 0.04, gain: 0.6, filter: { type: "bandpass", from: 1800, to: 1200, q: 2 } },
|
||||
{ type: "square", notes: [392, 784], seconds: 0.2, delay: 0.05, gain: 0.4, filter: { type: "lowpass", from: 2400, to: 2400 } },
|
||||
],
|
||||
},
|
||||
// A landing on plastic wheels: a soft body thump, the knock of the
|
||||
// chassis and the toy suspension's little rattle. The game makes it
|
||||
// louder and lower the longer the fall.
|
||||
@@ -110,6 +180,10 @@ export default {
|
||||
bounceMotor: { parts: [{ type: "square", freq: 104 }, { type: "square", freq: 104.9, gain: 0.5 }, { type: "sawtooth", freq: 312, gain: 0.12 }], noise: { color: "brown", gain: 0.12 }, filter: { type: "lowpass", freq: 900, q: 2.5, follow: 1 }, pulse: { rate: 22, depth: 0.35 }, peak: 0.035 },
|
||||
// The Monster truck's big engine: a low, lumpy V8 burble.
|
||||
bounceMonster: { parts: [{ type: "sawtooth", freq: 40 }, { type: "sawtooth", freq: 40.6, gain: 0.7 }, { type: "square", freq: 20, gain: 0.6 }], noise: { color: "brown", gain: 0.3 }, filter: { type: "lowpass", freq: 300, q: 5, follow: 0.9 }, pulse: { rate: 8, depth: 0.55 }, peak: 0.06 },
|
||||
// The Whirlybird's rotor: a fast chop.
|
||||
bounceChopper: { parts: [{ type: "sawtooth", freq: 62 }, { type: "square", freq: 31, gain: 0.5 }], noise: { color: "pink", gain: 0.5 }, filter: { type: "lowpass", freq: 700, q: 2, follow: 0.6 }, pulse: { rate: 17, depth: 0.8 }, peak: 0.05 },
|
||||
// The Robo-Vac: a steady suction whine.
|
||||
bounceVac: { parts: [{ type: "sawtooth", freq: 190 }, { type: "sawtooth", freq: 193, gain: 0.6 }], noise: { color: "pink", gain: 0.8 }, filter: { type: "bandpass", freq: 900, q: 1.4, follow: 0.7 }, pulse: { rate: 30, depth: 0.2 }, peak: 0.04 },
|
||||
// Crumbling road falling away behind you: a low, gritty rumble.
|
||||
bounceCrumbling: { noise: { color: "brown", gain: 1 }, parts: [{ type: "sine", freq: 48, gain: 0.4 }], filter: { type: "lowpass", freq: 380, q: 1, follow: 0.6 }, pulse: { rate: 7, depth: 0.6 }, peak: 0.045 },
|
||||
// A sprinkler nearby: a soft, ticking hiss of water.
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -11,7 +11,12 @@ import { MUSIC_TABLES, SONG_TABLES, audioOut } from "./tones.js";
|
||||
third argument, the game's music volume); stop calling and it
|
||||
fades out within MUSIC_HOLD_MS, the way a hum does, so a paused, closed or
|
||||
finished game falls quiet by itself, and hushMusic() quiets it at once. A
|
||||
track picks up again where it left off, at the start of that bar.
|
||||
track picks up again where it left off, at the start of that bar. A track
|
||||
loops for as long as it is asked for, and music() says how far along it
|
||||
is: "playing", then "ended" once it has run through to its last bar, the
|
||||
cue for a game that plays its tracks one after another (Bounce Road) to
|
||||
ask for the next, and { restart: true } as the fourth argument starts it
|
||||
from its top. It returns nothing while it plays nothing.
|
||||
|
||||
A track is:
|
||||
|
||||
@@ -467,8 +472,10 @@ function playSong(name, level, options) {
|
||||
// different track crossfades from the last one to this one over
|
||||
// CROSSFADE_S. `volume` (0 to 1) scales the whole track; at 0 it is not
|
||||
// asked for, so it fades out. Silence, never an error, while Play sounds is
|
||||
// off or audio cannot play. A song (above) plays instead when `name` is one,
|
||||
// and what it returns is the song's "playing" or "ended".
|
||||
// off or audio cannot play. It returns "playing", or "ended" once the track
|
||||
// has run through (it keeps looping), and `options.restart` starts it from
|
||||
// its top. A song (above) plays instead when `name` is one, and what it
|
||||
// returns is the song's "playing" or "ended".
|
||||
export function music(name, intensity = 0.5, volume = 1, options = undefined) {
|
||||
try {
|
||||
const level = Math.min(1, Math.max(0, Number(volume) || 0));
|
||||
@@ -478,6 +485,10 @@ export function music(name, intensity = 0.5, volume = 1, options = undefined) {
|
||||
const a = audioOut();
|
||||
if (!a) return;
|
||||
let ramp = 0.25;
|
||||
if (options && options.restart) {
|
||||
if (now && now.name === name) now.step = 0;
|
||||
else positions.delete(name);
|
||||
}
|
||||
if (now && now.name !== name) {
|
||||
crossOut(a, now);
|
||||
now = null;
|
||||
@@ -499,6 +510,7 @@ export function music(name, intensity = 0.5, volume = 1, options = undefined) {
|
||||
ticker = setInterval(tick, TICK_MS);
|
||||
book(a, now);
|
||||
}
|
||||
return now.step >= now.song.length ? "ended" : "playing";
|
||||
} catch {}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user