mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Add Bounce Road music, extras and arcade tests
AI Assisted
This commit is contained in:
1 parent
a0300d4ac2
commit
5679101487
23 files changed
+6004
-624
No files matched your search
@@ -1,12 +1,12 @@
|
||||
# Architecture: Activities (the games)
|
||||
> Part of [AGENTS.md](../AGENTS.md) and the [Architecture index](./AGENTS-architecture.md): project guidance for AI coding agents.
|
||||
|
||||
One row per file of every game but Ghoul Rush (which has its own files: [core](./AGENTS-architecture-ghoul-core.md), [stages](./AGENTS-architecture-ghoul-stages.md), [rides](./AGENTS-architecture-ghoul-rides.md)), then the rules every game follows.
|
||||
One row per file of every game but Ghoul Rush (which has its own files: [core](./AGENTS-architecture-ghoul-core.md), [stages](./AGENTS-architecture-ghoul-stages.md), [rides](./AGENTS-architecture-ghoul-rides.md)) and Bounce Road ([its own file](./AGENTS-architecture-bounce.md)), then the rules every game follows.
|
||||
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| `public/activities.js` | the list of activities (`ACTIVITIES`: each game's id, title, picker row line `blurb` and module path) an optional `courses` list (Mini golf's six course ids, which open a course dashboard), `bestKey(id, course?)`, the flat looks.json key for its best score (`activityBestSnake`, one per golf course `activityBestGolfPirate` to `activityBestGolfFrost`, `activityBestTrails`, `activityBestBugs`, `activityBestDrive`, `activityBestStack`, `activityBestBumper`, `activityBestRapids`, `activityBestFuse`, `activityBestHop`, `activityBestBounce`, `activityBestGhoul`, `activityBestFlock`); lists Snake, Mini golf, Light Trails, Bug Hunt, Sunset Drive, Stack Deploy, Bumper Ring, Rapids Run, Hot Potato, Crossing Rush, Bounce Road, Ghoul Rush and Flock Dash, `bestKeys(entry)`, every best key a game keeps, `playedKey(id)` (`activityPlayedSnake`, the epoch ms a game was last picked, 0 for never) and `orderGames(list, looks, order)` (the picker's `{ played, unplayed }`), and documents the game contract including the course parts (`courses` and `preview()` on the export, `setCourse()` and `course` on the game), the optional `pointer(type, x, y)`, `release(name)` (a game key let go) and `lowerIsBetter`; data only, imported by the page and by Node |
|
||||
| `public/activities/snake.js` | Snake: its rules as plain exported functions and the game contract (`create({ canvas, tone, onScore })` returning `start`, `pause`, `resume`, `key`, `tick`, `resize`, `score`, `state`); it never runs a timer or listens for keys, so the Activities window drives it; it also holds the music's rules: `MUSIC_TRACKS`, `dealMusic(random, last)` (a round's shuffle of the ten tracks, never opening on the last round's opener), `trackFor(deck, level)` and `heat(round)` (the snake's speed as 0.3 to 1, so the lead and drums are in from the first step) |
|
||||
| `public/activities/snake.js` | Snake: lives (`START_LIVES` 3, `MAX_LIVES` 9, `lifeMark(n)`, `awardLives`, `GRACE_MS` of free passage after a crash puts the snake back mid-board via `respawn`; `cheat(on)` sets `round.infinite`) and the bosses (`BOSSES` by the level that opens with one: 4 Grumpy Golem, 6 Comet Queen, 8 Thunder Toad; `round.boss`, whose orbs are the food, `hitBoss`, `ageBoss`); its rules as plain exported functions and the game contract (`create({ canvas, tone, onScore })` returning `start`, `pause`, `resume`, `key`, `tick`, `resize`, `score`, `state`); it never runs a timer or listens for keys, so the Activities window drives it; it also holds the music's rules: `MUSIC_TRACKS`, `dealMusic(random, last)` (a round's shuffle of the ten tracks, never opening on the last round's opener), `trackFor(deck, level)` and `heat(round)` (the snake's speed as 0.3 to 1, so the lead and drums are in from the first step) |
|
||||
| `public/activities/trails.js` | Light Trails: its rules as plain exported functions (`newRound`, `newHeat`, `turn`, `boost`, `advance` in 8 ms slices (where your crash is held for `GRACE_MS`, a turn in that time riding out of it; rivals get no grace), `choose` and `room` for the rivals' flood-fill steering, `applyPower` (a Mystery becoming another pad), `pickPower` (by each pad's `from` arena, a Heart only under `MAX_LIVES`), `fireLaser`, `hyperjump`, `awardLives` (a life every `LIFE_SCORE` points, the mark moving on at the cap), `spawnItem`, `closeRing`), the `ARENAS` (rivals, sharpness and what each adds), the `POWERS` pads (Boost, Phase, Eraser, Slow-mo, Coin, Heart, Shield held across heats until a crash in your grace pops it, Laser with `LASER_SHOTS`, Score x2 through one `gain()` every score goes through, Wide Trail with its side cells in `rider.wide`, Coin Rain whose `rain` coins never hold back a pad, Hyperjump, Mystery) and the game contract; `START_LIVES` is 5; memo is the furthest arena reached; a read-only `round` getter for the tests only; it also holds the music's rules: `MUSIC_TRACKS` (its five songs) and `dealMusic(random, last)` (a shuffle of them, never opening on `last`); a run plays the deal one song after another, each in full from the top (asking with `{ restart: true }` until the music takes it), moves on when `music()` answers `"ended"`, deals again after the last, and a new run deals afresh, never opening on the song the last run was playing; its tones and hums play `SFX_LOUDER` times as loud through tones.js's `louder`, all but the engine drones (`DRONES`), kept low under the songs |
|
||||
| `public/activities/bugs.js` | Bug Hunt: its rules as plain exported functions (`newRound`, `spawnWave`, `slotPos`, `advance` in 8 ms slices over `round.input`, which `key()` and `release()` set, `hurtBug`, `hurtBoss`, `hitShip`, `applyPower`, `ghostly`, `tentacleTip`, `bossRadius`), the `BUGS` by first wave, the `BOSSES` every `BOSS_EVERY` waves, the `POWERS`, the `SECTORS` scenery and the game contract with `release()`; memo is the tally of `DISCOVERIES` as bits; a read-only `round` getter for the tests only |
|
||||
| `public/activities/drive.js` | Sunset Drive: its rules as plain exported functions (`newRound`, `buildStage`, which appends a stage of road and returns its `forkAt`, `gateAt` and `fork`, `segAt`, `advance` in 8 ms slices over `round.input`, which `key()` and `release()` set, `boost`, `usePower` (the oldest queued power-up, which space fires ahead of `boost`), `hopHeight`, `checkTime`), the `POWERS` in `POWER_ORDER`, the `REGIONS` (roads with their bonus, bends, hills, traffic, colors and props) in `REGION_ORDER`, the projection and drawing (sky, road far to near, props, traffic, Planny's car) and the game contract with `release()`; the next road is built only when the fork is chosen, and `FORK_LEN` must stay at least `DRAW` so it is built before it comes into view; memo is the roads found as bits; a read-only `round` getter for the tests only |
|
||||
@@ -21,13 +21,6 @@ One row per file of every game but Ghoul Rush (which has its own files: [core](.
|
||||
| `public/activities/fuse-draw.js` | Hot Potato's drawing: `drawScene(ctx, view)` from one view object `fuse.js` refills each frame, in arena units: the strip above the arena in the page's colors with the pills (laid out by `hudLayout`, which starts a second row rather than run into the fuse and centers its rows in the strip), each venue's floor in its fixed palette (`themeFor`, `venueColor`), ice, running belts, the Rooftop's open edge, the things to run round, pickups, the runners (Planny on his feet with his star eye and stick arms, flailing while he holds a bomb, and still Planny when charred; arms and feet on the floor in `limbInk(level)`, the ink that stands out from that venue's tiles; rivals with a mark per personality; a white ring with a dark edge at the feet of a runner safe from a tag-back; the charred waddle to the nearest wall and the fall from the roof), the bomb over its holder (a red ball with a `<<<` band, growing and glowing as it burns, flashing white while it cannot be passed, its fuse a shortening curl with a spark, the last seconds in big numbers (under the holder's feet when there is no room above, `countY`), a hop across on a pass), blast clouds, the Blackout's dark worked out once a frame in cells, the red edge pulse in a fuse's last second, banners and the start and end strip with the big final score, and `readColors(canvas)`; decides nothing |
|
||||
| `public/activities/hop.js` | Crossing Rush: its rules as plain exported functions over a round on a strip `COLS` (11) cells wide of 30 to 40 lanes, `VIEW_ROWS` (14) on the board at once (`newRound`, `newHeat(round, zone)`, which builds the heat's lanes from the round's seed, kept when a heat runs again, `buildLanes(zone, seed)` (groups of road, highway, ice, river, turtle, rapids or rail lanes with a grass row between each two, the zone's new thing first; the same seed builds the same lanes), `advance` in 8 ms slices (lanes flow, riders drift with their log, rivals choose, everyone is checked where they stand before any hop moves on, then hops and flights; hoppers home in the same slice finish by the moment each landed, a dead heat to you), `hop(round, hopper, dir)` (one cell, two with a Spring; a hopper counts in the cell it leaves for the first half and the one it lands on for the second; an icy lane slides it a cell more), `laneAt`, `occupied(round, row, col, atMs)` (a car or a train on it, or in a river no float or the edge, `atMs` ahead through `shiftAt`, which follows a lane's flips, surges and a Horn exactly), `sendBack` (to the last grass row, `safeBelow`, crediting a shove within `SHOVE_CREDIT_MS`), `shove(round, from, to)` (a cell the way `from` faces, only on a hopper `inReach` and never on one past the half of its hop home, once every `SHOVE_MS`), `plan(round, hopper, random, power)` (a look ahead of `LOOKAHEAD` to `LOOKAHEAD_SHARP` hops over the lanes as they will move, each hop followed by the hopper's wait where it lands; never a hop where it would be hit or fall in at full sharpness; a sloppy rival now and then hops on regardless), `applyPower`, `zoneFor` and `rivalPower` (each built once per zone), `rivalColors(you)`, `standings`), the `ZONES`, `RIVALS` and `POWERS`, and the game contract with `release()` (`key(name, repeat)` hops once a press: never on a repeat, never again until the arrow is let go, never with the press that plays on, and with one hop queued behind the one in the air; a pause drops what is held and the queue); rivals wait `REACT_MS` down to a sharp rival's after each landing, a Bruiser shoves anyone beside it into a lane, a Tagalong follows a row behind you and shoves near the top, and a rival that lets a shove go weighs the next one only after `SHOVE_LOOK_MS`; memo is the furthest zone reached, which can pass 9; a read-only `round` getter for the tests only. Tuned by a scratch sim |
|
||||
| `public/activities/hop-draw.js` | Crossing Rush's drawing: `drawScene(ctx, view)` from one view object `hop.js` refills each frame, in board units: the strip above the field in the page's colors with the pills (laid out by `hudLayout`, which starts a second row rather than run into your place and centers its rows in the strip), the lanes in fixed colors (`LANES`, `lookOf`; pavement, grass with tufts, bushes and rocks, the checkered finish, roads with dashes and surge chevrons, icy roads, rivers with ripples and Rapids arrows, tracks with a signal that flashes while a train is coming), cars, vans, trucks, logs, turtles that sink and dive, the train, pickups, the hoppers (Planny on his stick feet with his star eye in every state: stretching mid-hop, spinning as he flies back, cheering, slumped when beaten; rival critters with a Hopper's ears, a Daredevil's goggles, a Bruiser's brow and a Tagalong's beak; arms and feet, and each rival's body edge, in `limbInk(look)`, the ink that stands out from that lane), a Shield's ring and a Spring's coil, staggered stars, arrows at the edge for hoppers out of view, the Night Market's dark (soft lights cut from a layer the size of the field with one gradient made with the layer, or in steps with no second canvas), the race bar in the page's colors, banners, and the start and end strip with the big final score; every word kept on the field by `labelSpot`, and `readColors(canvas)`, `zoneColor`; decides nothing |
|
||||
| `public/activities/bounce.js` | Bounce Road: the cars, the hazards against them, the scoring and the round, as plain exported functions over a round on a road scrolling up a 72 unit wide field, 90 units of it on the board (it re-exports every rule of `bounce-road.js` and `bounce-rivals.js`, so the suite imports one module): `newRound(seed, random)`, `advance` in 4 ms slices over `round.input`, which `key()` and `release()` set (a jump press first, then your `move`, the rivals' `think` and `move`, the pads (a boost strip pushes you to `NITRO_TOP` for `BOOST_MS` even off the throttle, and the brake cuts it; a ramp launches any car crossing its lip quick enough `RAMP_AIR` the usual jump; a slick eases the steering at `SLICK_EASE` and makes a knock last for `SLICK_MS`), the bumps (`collide`: boxes pushed apart along the shallower overlap, side on a knock split by mass and harder for the car that did not steer in, end on speed passed forward, into a `HEAVY` truck's back at `CRASH_CLOSE` a crash; with Mega wheels a touch flattens; a close shave, `NEAR_GAP` or less between the boxes at speed and no touch, scores once), the barriers (a cone or a tire knocked flying slows you to `CONE_SLOW`; a block, pot or bucket nose first is a crash, from the side a push out), the hazards placed by the round's clock (a train hits a car on its track, a ball knocks a car by `BALL_KICK`, a sprinkler's jet pushes at `SPRAY_PUSH`, a drop falls `DROP_FALL_MS` after you come within `DROP_TRIGGER`, aimed at your line, and lies there after, a gust pushes at `WIND_PUSH`), then the ground (water or a hole under your middle a life, a flowerbed nose first a crash, a rival off the road out and yours within `CREDIT_MS`)), `jump`, `land` (on a car: flattened for its `points` times the chain up to `MAX_CHAIN`, a truck's roof `HAUL_POINTS`, the Monster a stomp, `STOMP_POINTS`, and on its last of `BOSS_HP` `BOSS_POINTS` times the lap and a life; on the road the chain ends, and the holes, trains, balls and barriers flown over and a ramp's big air score), `stunt` (a stunt's points times `comboOf(streak)`: every `COMBO_STEP` stunts within `STREAK_MS` of each other one more, up to `MAX_COMBO`), `lose` (a Bubble throws you clear instead), `applyPower`, `underBanner(round, y, cam)` (a rival, a coming train, a ball or a thing still falling in the strip) and `BANNER_Y`, `rivalColors(you)`), the `POWERS` (Spring, Bubble, Nitro, Mega wheels) and the game contract with `release()` (`key(name, repeat)`: held arrows drive and steer, space jumps once a press, never on a repeat or with the press that plays on, and a press up to `JUMP_BUFFER_MS` before a landing jumps on it; a pause lets go of every key and drops a press). A stage line scores `STAGE_POINTS` times the stage, `TIME_POINTS` a second under its par and, flawless, `FLAWLESS_POINTS` and a life back up to `MAX_LIVES`. Memo is the furthest stage reached, which can pass 10. A read-only `round` getter is for the tests only. Tuned by scratch bots: a careful bot clears all ten stages with no rivals on every seed tried (23 to 42 s a stage), and a bot with 150 ms reactions and 80 ms jump timing error reaches a median of stage 5 with the rivals out, stage 10 without |
|
||||
| `public/activities/bounce-draw.js` | Bounce Road's drawing: `drawScene(ctx, view)` from one view object `bounce.js` refills each frame, in field units: the strip above the field in the page's colors with the pills (laid out by `hudLayout`: stage, lives, Spring, Bubble, Nitro and Mega with their timers, the chain and the combo with its timer; a pill that would run off the board starts a second row), the road a chunk of `CHUNK_ROWS` rows at a time, drawn off screen once per road and scale, a few kept and copied each frame (rows from `bounce-scenery.js`), the layers over it (`bounce-scenery.js`), the landing rings (yours in your highlight, a rival's in red, the Monster's its own size), the cars through `bounce-cars.js` (every shadow first, upright, then every body with its tumble: Planny in your highlight with his box in the page's panel color and his star eye, arms to the wheel, up in the air or cheering, down at the end; each rival kind in its own style and color, the Cop's siren while it chases, the Monster's dents and a star per life left above it, headlights at Night Lights), sparks, rings, the dark of Night Lights, the chain's big number, the stage bar beside the field, banners, and the start and end strip with the big final score and a dot per stage reached; every word kept on the field by `labelSpot`, and `readColors(canvas)`, `limbInk`, `inkOn`; decides nothing |
|
||||
| `public/activities/bounce-cars.js` | Bounce Road's cars, drawing only and no imports: `drawCarBody(ctx, style, opts)` draws one top-down toy car about the origin, nose up, filling `w` by `h` field units exactly (tires on the box's corners), in one of `CAR_STYLES` (`STYLE_NAMES`: Planny's convertible with his star eye and arms to the wheel, hatch, sedan, coupe, muscle, pickup, van, box truck, police, racer, taxi, jeep, monster) with flat-fill shading worked out from `color` and `accent` (`shade`, `rgbOf`), and options for roll (`tilt`), a jump (`air`: it draws the shadow and the lift itself), a pancake (`squash`), night beams, a siren bar, damage, a boost flame and brake lights, all moving parts on `opts.clock`; `drawCarShadow` and `shadow: false` for a shadows-first pass in screen space; `carLength(style, w)` for a style's natural length and `carReach(style, opts)` (with `MARGINS`) for what reaches outside the box |
|
||||
| `public/activities/bounce-scenery.js` | Bounce Road's scenery, drawing only: each stage's look in fixed colors (`LOOKS`: patio slabs, lawn stripes, kitchen tiles, garden, sand, a toy room's rug, a pond with lily pads, roof shingles, the night lawn with lamps and the Monster's dirt; `lookOf`, `stageColor`, `contrast`, `better`), `drawRow` (one row of the road in three passes over a chunk: the yard, the road's surface, the details: edges slanting from row to row, rivers, plank bridges with jagged broken ends, cracks, flowerbeds, rails across a crossing, cracked road over a pit, checkered stage lines, verge decor), and the layers drawn fresh each frame from the round's clock: `drawTimed` (a drawbridge lifting with its red lights, a swaying bridge where it is now, crumbled road gone to the pit), `drawPads` (running boost chevrons, ramps, slicks), `drawBlocks` (cones, toy blocks, pots, buckets, acorns and tires, knocked ones tumbling off), `drawStars`, `drawSigns` (a mark per hazard), `drawItems`, `drawHazardsLow` (crossing lights, the train, a rolling ball, a falling thing's growing shadow, a sprinkler's head), `drawHazardsHigh` (the jet, gust streaks, the thing still falling), `drawNight` and `drawFireflies`; decides nothing |
|
||||
| `public/activities/bounce-road.js` | Bounce Road's road, rules only: the jump math every hole is sized by (`airMs(v)`, `reach(v)`, `LONGEST_JUMP`, `JUMP_FAIR`, `TOP_SPEED`, `MAX_SPEED`), `stageFor(n)` (built once a stage: the ten of `bounce-roads.js`, then laps from `LAP_FROM`, quicker, keener, busier, the Monster at every Monster Mash) and `stageName`, `newRoad(seed)` and `buildStage(road, n, random)` (a stage's rows from its own seed, by the stage's piece weights: straights, cracks, rivers on bridges with one or two broken spans or a drawbridge, splits round flowerbeds, ramps before a crack with stars beyond, cone or block chicanes, crumbling road, train crossings, swaying bridges, boost strips, slicks, balls, sprinklers, drops and gusts; every hole after a `RUNUP` with a sign and no longer than `MAX_HOLE`, the bridge between two breaks long enough to land `LONGEST_JUMP` on), `ensureRoad`, `groundAt(road, x, d, t)` (a row's edges eased from the row before's; a drawbridge water while lifted, a swaying bridge shifted, crumbled road a hole), `rowGone`, `spanAt`, `holesIn`, `firstAt`, `plainRow`, `safeSpot` (no hole, water, timed part or rails for `RESPAWN_RUN` ahead), and where each timed thing is at a moment: `swayOff`, `drawLift`, `crumbleAt` (falling away `CRUMBLE_DELAY` after you reach it, at `CRUMBLE_SPEED`, under a fair speed), `trainAt` (on, and lit `TRAIN_WARN_MS` before), `ballX`, `sprayAt`, `gustAt`; plus `seeded`, `GROUND`, `MARK`, `SPAN` |
|
||||
| `public/activities/bounce-rivals.js` | Bounce Road's rivals, rules only: `RIVALS` (the Zigzag, Brick, Frog, Nudge, Hauler, Sneak, Bruiser, Racer, Cop and Monster: box, mass, speed, points, how readily each dodges, how often each comes, its car style and whether it comes from behind), `makeCar`, `think(round, car, ms, random)` (each kind's choice of speed and line: the Zigzag's weave, into your path when you follow; the Brick holding your lane and brake-checking from in front, then resting `BRAKE_REST_MS` or more; the Frog's hops toward you; the Nudge's chase and up to 1 + 2 times the stage's `sharp` swipes; the Hauler drifting to block; the Sneak dropping up to `SNEAK_DROPS` cones while you follow; the Bruiser slamming you within `BRUISER_RANGE`; the Racer passing then fleeing; the Cop sitting on your roomier side and leaning in to push you to the near edge for `COP_MS`, never on a bridge or by the water (`nearWater`), nor the Bruiser; the Monster keeping `BOSS_AHEAD` in front, hopping every `BOSS_HOP_MS` to come down where you will be and dropping tires; every rival rubber-banded to stay near you, swerving from under your landing as sharply as its stage allows, keeping to the narrowest road just ahead and the band a swaying bridge always covers, holding a slower car's speed, and hopping any hole, drawbridge, barrier or coming train, or flying off a ramp), `spawnRival`, `pickKind` (one of each special kind at a time), `HEAVY`, `RIVAL_MIN_SPEED` |
|
||||
| `public/activities/bounce-roads.js` | Bounce Road's ten stages as data (no imports): `FIELD_W`, `FIELD_H`, `ROW`, `MAX_HOLE`, `LAP_FROM`, and per stage its length, par time, road widths, piece weights (straights, holes, rivers, splits, ramps, chicanes, crumbling road, trains, swaying bridges, boost strips, slicks, balls, sprinklers, drops, gusts), crack and broken span lengths, bridge widths and shares of broken, double and drawbridge spans, flowerbed sizes, barrier and drop kinds, the rivals' count, kinds, pace and sharpness, power-ups, stars, and whether the Monster comes |
|
||||
| `public/activities/pills.js` | The pills every game but Mini golf draws along its top (no imports): `drawPill(ctx, x, y, w, h, text, color, fill, textY)` on one opaque dark backing, `PILL`, the same in light and dark and over any scene, a timer's share still left tinted at `PILL_TINT`, and the text in `pillInk(color, tinted)`: the pill's own color when it reads at `PILL_CONTRAST` (4.5:1) on the backing (and on the tint while a timer runs), else the least step toward white that does, so warnings stay red; lives are the one solid pill: a pill in the `LIVES` color is drawn on `LIVES_BACK` in white (`LIVES_INK`), its text from `livesText(n)` (a heart per life up to five, `♥ xN` past that, `♡` at none); `pillTint` and `pillContrast` for the unit suite |
|
||||
| `public/activities/golf.js` | Mini golf: six eighteen-hole courses, one round at a time; its rules and physics as plain exported functions (`newRound(courseId)`, `holesOf`, `coursePar`, `strike`, `advance` on a fixed 4 ms sub-step, `nextHole`, `total`, `toPar`, `predictPath` for the spyglass, `moverAt`, `gateShut`, plus ice that barely slows the ball and wells that pull it in or push it away), the `POWERUPS` held for the next putt (`round.held`, then `round.active` for that putt), the arcade swing (`startSwing`, `setPower`, `meterAt`, `meterZone`, `swingShot`: a ping-pong power meter, slow at the bottom and fast at the top, with a MAX band that boosts and an overswing band that shanks; a shot clock in `advance()` that starts the meter after `SHOT_CLOCK_MS` and dribbles the ball after `METER_TRIPS` trips; all on the round's own clock), the pop-up gags, and the game contract with `pointer()` (the aim follows the pointer, a press swings, a press held on a roll fast-forwards), `release()` (held arrows turn the aim, held space fast-forwards) and `lowerIsBetter`, `courses` (the dashboard's cards), `preview(canvas, id, w, h)` (a course's card art) and `setCourse(id)`; deterministic (no `Math.random()`), a read-only `round` getter for the unit suite only |
|
||||
| `public/activities/golf-draw.js` | Mini golf's drawing: `drawCourse(ctx, view)` from a plain view `golf.js` builds, each hole in its theme's fixed palette (`pirate`, `cave` with its darkness and glows, or a newer course's look from `golf-looks.js`, asked first for its grounds, water, tunnels, gates and wells), ice, the scorecard and banners in the course's voice, a bare view for the dashboard's card art, `knownGround`/`knownLiquid` for the unit suite, and `readColors(canvas)`, which reads the `--golf-*` properties `styles/activities.css` mixes from the tokens for the ball, pills and scorecard; decides nothing |
|
||||
@@ -47,7 +40,7 @@ One row per file of every game but Ghoul Rush (which has its own files: [core](.
|
||||
| `public/activities/golf-look-frost.js` | How Frosty Peaks is drawn: its palette, ground, water, props and scenery; drawing only, moving with the round's clock |
|
||||
| `public/activities/golf-paint.js` | Mini golf's shared canvas helpers (`polygon`, `circle`, `ellipse`, `radial`, `fill`, `stroke`, `line`, `label`, `turned`, `t`, `scatter`, `bounds`), no imports, so the drawing files and the looks share them without import loops |
|
||||
| `public/tones.js` | the activities' sound engine, all synthesized in the browser. Three parts: a shared kit of rich one-shot sounds (`RICH`: `layers` of parts played together, each a wave or a noise (`noise`, `pink`, `brown`) with its own `delay`, `gain`, `attack`, a sweeping `filter` and `vibrato`: `explode`, `smash`, `skid`, `whoosh`, `splashBig`, `fanfare`, `gameOver` and some fifty more, up to 1.2 s, at most `MAX_VOICES` parts sounding at once), held **hums** (`hum(id, name, level, pitch)`, called every frame a game wants it: oscillators and noise through one filter that follows the pitch, pulsed for an engine's strokes; a hum not asked for within `HUM_HOLD_MS` fades by itself, so a paused or closed game goes quiet without saying so, `hushTones()` quiets every one and the Activities window calls it whenever it stops ticking; at most `MAX_HUMS`; shared ones `car`, `toycar`, `electric`, `outboard`, `river`, `wind`, `cycle`, `fuse`, `haunt`, `squeal`, `meter`, `swarm`, `train`, `crowd`), and each game's own extras in `public/activities/<id>-sfx.js` (`{ tones, hums }`, plain objects, names prefixed with the game id, merged and frozen here; a name may be defined once across all of them, which `scripts/test-web-console-tones.mjs` checks along with every spec's shape and every name a game's source asks for). Everything plays through one compressor. The older single blips (`BLIPS`): `tone(name, level, pitch)` with an optional loudness from 0 to 1 and an optional pitch that scales every frequency, kept between 0.25 and 4, and an optional fourth `louder` (a game lifting its sounds as a whole, up to `LOUDER_MAX`, also the fifth argument of `hum()`), `unlockTones()`; Snake's blips plus golf's `putt`, `wall`, `bump`, `cup`, `ace` (a three-note rise), `splash`, `power` (a power-up, three notes), `tunnel`, `boom` (a cannon putt), `sizzle` (lava) and `fall` (the pit), the countdown's `count` and `go`, Stack Deploy's `thunk`, `slice` and `perfect`, which it pitches up a scale step for each perfect in a row, and Bumper Ring's `ram`, pitched and leveled by how hard the hit, and `rev`, a rival winding up a dash, and Hot Potato's `tick`, the fuse, which it ticks quicker and pitches higher as the fuse burns down, and `pop`, a pass, and Crossing Rush's `hop`, which it pitches up a step for each quick hop forward in a row, `boing`, a send-back, `bell`, a train coming, and `horn`, and Bounce Road's `engine`, a soft low triangle hum it plays every few frames while you pick up speed (quiet once you cruise or coast), pitched up with your speed, `spring`, a jump, pitched with your speed, and `squash`, a rival flattened, pitched up a step for each in a chain, and `beat`, a low thump while your wheels run on the verge (it borrows the other games' blips for its hazards and rivals), and Rapids Run's `pew` (a shot, a short soft triangle played quietly about seven times a second while fire is held), `charge` (a buoy taken), `lowcell` (the low battery's two-note beep, quicker the lower it runs), `dambreak` (a dam bursting) and `skim` (a bank skimmed at speed, pitched up the more you have skimmed), and Ghoul Rush's `ghoulBlast` (the blaster's bolt, a short soft triangle repeated while fire is held), `zombiePop` (a kill, pitched up a step for each in the chain), `ghoulStomp`, `ghoulBoo`, `ghoulRoar` and `zombieGroan` (now kept for the other games and the tests: Ghoul Rush's monsters speak with their own voices from `ghoul-sfx.js`), `ghoulCandy` (pitched up for candy in quick succession), `batSwoop` (a bat's kill), `doorUnlock` (the key), `doorThrough` (the door to the next room) and `creakBoard` (a crawler coming up, a chandelier or a crumbling board about to go), all soft triangles and sines), silent while Play sounds is off; separate from `sound.js`'s cue queue |
|
||||
| `public/music.js` | the games' chiptune music: a small sequencer over `tones.js`'s context and compressor (`audioOut()`). A game calls `music(name, intensity)` from its `tick`; the track fades out within `MUSIC_HOLD_MS` once it stops being asked for, picks up again on the bar it left, asking for a different track crossfades the two over `CROSSFADE_S` (the old one keeps playing as it fades, so a new level is not a cut), and `hushMusic()` stops it at once. Tracks are note data under `music` in each game's `activities/<id>-sfx.js` (`{ bpm, rush, bar, voices, patterns, order }`, `bar` the steps in a bar when it is not 16, so the track resumes on a bar start and each pattern is whole bars: pulse, triangle and noise-drum voices, each joining once the intensity reaches its `from`; a step a token, `A4`, `-` to hold, `.` a rest, `A3^037` an arpeggio, drums `k s h o`), read by `compileTrack()` and booked `LOOKAHEAD_S` ahead on the audio clock. It also plays recorded **songs**: mp3s a game names under `songs` in its sfx file (a name to a served path, merged by `tones.js` as `SONG_TABLES`, listed by `songNames()`), asked for the same way, one `<audio>` element each made on first use, at `SONG_PEAK` times the volume, faded over `SONG_FADE_MS`; a song plays once, never looped, `music()` returning `"playing"` or `"ended"` (which the window's wrapper passes back to the game), `{ restart: true }` taking it back to the top with `load()` (no seeking, since the server sends no byte ranges), and a song no longer asked for fades and pauses where it was. The window plays it only while Play sounds, Play game sounds and Play game music (`looks.gameMusic`, off by default) are all on |
|
||||
| `public/music.js` | the games' chiptune music: a small sequencer over `tones.js`'s context and compressor (`audioOut()`). A game calls `music(name, intensity)` from its `tick`; the track fades out within `MUSIC_HOLD_MS` once it stops being asked for, picks up again on the bar it left, asking for a different track crossfades the two over `CROSSFADE_S` (the old one keeps playing as it fades, so a new level is not a cut), and `hushMusic()` stops it at once. A track loops while asked for, and `music()` returns `"playing"`, then `"ended"` once it has run through to its last bar (Bounce Road's cue to ask for the next of its twenty), with `{ restart: true }` starting it from its top. Tracks are note data under `music` in each game's `activities/<id>-sfx.js` (`{ bpm, rush, bar, voices, patterns, order }`, `bar` the steps in a bar when it is not 16, so the track resumes on a bar start and each pattern is whole bars: pulse, triangle and noise-drum voices, each joining once the intensity reaches its `from`; a step a token, `A4`, `-` to hold, `.` a rest, `A3^037` an arpeggio, drums `k s h o`), read by `compileTrack()` and booked `LOOKAHEAD_S` ahead on the audio clock. It also plays recorded **songs**: mp3s a game names under `songs` in its sfx file (a name to a served path, merged by `tones.js` as `SONG_TABLES`, listed by `songNames()`), asked for the same way, one `<audio>` element each made on first use, at `SONG_PEAK` times the volume, faded over `SONG_FADE_MS`; a song plays once, never looped, `music()` returning `"playing"` or `"ended"` (which the window's wrapper passes back to the game), `{ restart: true }` taking it back to the top with `load()` (no seeking, since the server sends no byte ranges), and a song no longer asked for fades and pauses where it was. The window plays it only while Play sounds, Play game sounds and Play game music (`looks.gameMusic`, off by default) are all on |
|
||||
| `public/activities/<game>-sfx.js` | each game's own sound effects (`bounce`, `bugs`, `bumper`, `drive`, `flock`, `fuse`, `golf`, `hop`, `rapids`, `snake`, `stack`, `trails`): `tones` (one-shots played with `tone(name, level, pitch)`) and `hums` (held sounds kept going with `hum(id, name, level, pitch)`), merged into `tones.js` beside the shared kit; definitions only |
|
||||
| `public/activities/snake-music.js` | Snake's ten music tracks as data (no imports): `SNAKE_MUSIC`, `{ bpm, rush, voices, patterns, order }` each, named `snake<Place>` and listed in `MUSIC_TRACKS` in `snake.js`. A round deals them in a fresh order, one to each level, so a run hears a different track at every level and none twice. They were picked on the pages in `prototypes/music/snake` (rhythm-first folk and world tunes led by something plucked or reedy, mostly dark or modal), and their bars are not all sixteen steps: 6/8 is 12, 7/8 is 14, ten beats is 20, twelve beats is 24, each pattern a whole number of its bars; merged by `snake-sfx.js` |
|
||||
| `public/activities/light-trails/1.mp3` to `5.mp3` | Light Trails' five background songs, named `trailsSong1` to `trailsSong5` under `songs` in `trails-sfx.js` and listed in `SERVABLE`; re-encoded for size with ffmpeg (80 kbps stereo MP3 at 44.1 kHz, loudness-normalized to -16 LUFS with `loudnorm`, metadata stripped), about 7.6 MB together, and copied into every skill with the rest of the console. The server leaves them out of its start-up cache warm |
|
||||
@@ -58,7 +51,7 @@ One row per file of every game but Ghoul Rush (which has its own files: [core](.
|
||||
**Building an Activities game:** the rules every game follows, so a new one plays like the rest.
|
||||
|
||||
- **Lives are prominent.** A game with lives draws them as the lives pill: `livesText(round.lives)` in the `LIVES` color from `pills.js`, placed right after the level/stage pill, which `drawPill()` draws solid pink with a heart per life. Never a plain `♥ N` on the dark backing: that was hard to read at a glance. The unit suite checks every game with lives for it.
|
||||
- **Every game adds looks.json keys, and `cleanLooks()` keeps at most 120.** A new game adds a best (one per course for a game with courses), a memo, a played time (`activityPlayed<Id>`) and, with music, a music volume; the picker adds `activityOrder`. About 76 keys are in use, so raise the cap (or fold keys) before the games that would pass 120.
|
||||
- **Every game adds looks.json keys, and `cleanLooks()` keeps at most 120.** A new game adds a best (one per course for a game with courses), a memo, a played time (`activityPlayed<Id>`) and, with music, a music volume; the picker adds `activityOrder`. About 77 keys are in use, so raise the cap (or fold keys) before the games that would pass 120.
|
||||
- **Every game with lives takes the endless-lives code.** Typing up, down, up, down, left, right, left, right, B, A, space on the board gives endless lives until the round starts over or the person leaves the game (`CHEAT_CODE` in `screens/activities.js`, which calls the game's `cheat(true)` and `cheat(false)` on leaving for the picker or closing). A game with lives answers `cheat(on)` by setting `round.infinite`, never takes a life while it is set (`if (!round.infinite) round.lives -= 1`), lets `start()` make a new round without it, and shows `livesText(Infinity)` ("♥ x∞") in its lives pill. `scripts/test-web-console-activities.mjs` checks every listed game whose round has `lives`.
|
||||
- **Banners never get in the way.** A banner over the board (`"Hit!"`, a new level, a power-up) is placed on the frame it first shows, on the part of the board away from the player, and fades to `BANNER_SEE_THROUGH` (0.12) over `BANNER_FADE_MS` while the player, or anything the player must react to (a diving bug, a bomb, a rival, a hazard, the road over a hill), is in its strip; Snake's `bannerRow()` and `underBanner()` are the model. Give the banner object a `see` field, multiply the draw's alpha by it, and export the strip check (`underBanner`) for the unit suite.
|
||||
- **The window owns pausing.** A game never resumes itself; `screens/activities.js` decides when a key or click plays on, including the hold on a question or finish (see the row above), so a game needs nothing of its own for it. Full screen is the window's too (`setFull()`: the button, `F`, and a turn or finish putting it back; `fitFull()` sizes the game to the whole screen (black bars where its shape leaves room) and docks the overlaid panel in a bar that holds it, `data-dock="side"` or `"below"`, or floats it, `"float"`, shrunk to the score while a round plays and the pointer is still; and tells the desktop app `activities-full`); a game only sees a bigger `resize()`, so a new game needs nothing for it, as long as its `resize()` sets the canvas's CSS size.
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Architecture: Bounce Road
|
||||
> Part of [AGENTS.md](../AGENTS.md) and the [Architecture index](./AGENTS-architecture.md): project guidance for AI coding agents.
|
||||
|
||||
Bounce Road's files under `src/web-console/public/activities/`. The other games and the rules every game follows are in [Activities](./AGENTS-architecture-activities.md).
|
||||
|
||||
How it fits together: a **stage** is a theme (its look and what it lays on the road) in a slot (how hard: length, holes, rivals), so a run can deal the themes in a new order and stay fair. Every third stage is a boss stage in that boss's arena; fifteen stages make a lap. Rules never draw and drawing never decides: `bounce.js` refills one view object a frame and `bounce-draw.js` draws from it.
|
||||
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| `public/activities/bounce.js` | the cars, the hazards against them, the gadgets, the scoring and the round, as plain exported functions over a round on a road scrolling up a 72 unit wide field, 90 units of it on the board (it re-exports every rule of `bounce-road.js` and `bounce-rivals.js`, so a suite imports one module). `newRound(seed, random, shuffle)` (the game passes `shuffle` true; the suites leave it off for the classic stage order), `advance` in 4 ms slices over `round.input` (a jump press first, then a `fire`, your `move`, the rivals' `think` and `move`, the pads, the bumps, the barriers, the hazards, `threats`, the ground, progress and traffic). **Driving:** `move`, `jump`, `land` (a landing on a rival flattens it for its points times the chain up to `MAX_CHAIN`; a truck's or the Supply truck's roof is `HAUL_POINTS` and a trampoline; a Spike's roof is a life; a boss takes a hit, `hurtBoss`), `collide` (side knocks split by mass, end on speed passed forward, a heavy back at `CRASH_CLOSE` a crash, a Slasher's blades out a crash, Mega wheels or a Fever flatten on touch), `stunt` (points times `comboOf(streak)`, doubled in a Fever, and it fills the Fever), `lose` (a Bubble saves instead), `underBanner`. **Power-ups** (`POWERS`): Spring, Bubble, Star magnet and a heart work as taken (`applyPower`); the ones with `uses` are gadgets (`GADGETS`: Nitro, Mega wheels, Rockets, Oil slick, Ground pound, Zapper), held one at a time in `you.held` until `usePower`. **The double tap:** `key("action")` jumps at once on the first press and sets `input.fire` on a second within `DOUBLE_TAP_MS` while a gadget is held (never on a repeat, never across a pause), so a jump never waits. **Weapons and the rivals' fire** (`threats`): `round.shots` (rockets: the first rival, boss or barrier in the way), `round.bolts` (a Blaster's: a knock and a slide, never a life), `round.bombs` (a Bomber's, blowing `BOMB_FUSE_MS` on), `round.lobs` (what a boss threw, landing `LOB_MS` on: a barrel lies there as a block, a bomb blows), `round.spills` (oil: yours spins a rival, a boss's takes your grip), the pull of a Magnet rival and the Robo-Vac. **Fever:** `round.fever` fills by `FEVER_GAIN` a stunt; full, `startFever` burns `FEVER_MS` of double points; a life lost halves the meter. **Lives and ranks:** a life every `LIFE_SCORE` points, for a flawless stage and for a boss; a stage line scores `STAGE_POINTS` times the stage, `TIME_POINTS` a second under par and `FLAWLESS_POINTS`, and ranks the stage S to C into `round.ranks`. **The boss hold:** while a boss is alive and the next stage is not yet built, `progress` calls `extendStage` instead of `ensureRoad`, so a boss stage lasts until its boss is beaten (on a road built far ahead, as the suites do, the boss gets away at the line instead). **Road things it settles:** boost strips, ramps, slicks, conveyors (`BELT_PUSH`), spring pads, cones and blocks, bumpers (`BUMPER_POINTS`, a kick, never a life), trains, balls, rollers, sprinklers, drops, gusts, lasers and stompers; an icy or wet stage (`spec.ice`) has less grip everywhere. **The game contract** with `release()`, `cheat(on)`, the events each frame turns into sounds, sparks, floats and banners (`handle`), a power-up's name flashed near the top of the field for `TOAST_MS` (`fx.toast`), the pills (`hudOf`: stage, lives, effects with their timers, the gadget held as `TAP x2: NAME`, the Fever meter, a boss's hp), and the music: `MUSIC_TRACKS` (the twenty chip tracks, a radio in random order), `dealMusic(random, last)` and `MUSIC_HEAT` (the intensity the game asks for: 0.5 on the road, 0.8 while a boss lives, 1 in a Fever), each track played through (`music()` says `"ended"`), a new deal after the last. Memo is the furthest stage reached. A read-only `round` getter is for the tests only. Tuned by scratch bots: a careful bot clears all fifteen classic stages with no rivals on every seed tried, 17 to 35 s a stage |
|
||||
| `public/activities/bounce-roads.js` | the stages as data and plain arithmetic (no imports): `FIELD_W`, `FIELD_H`, `ROW`, `MAX_HOLE`, `WORLD` (every third stage a boss), `CYCLE` (fifteen stages a lap), `MAX_RIVALS`; `THEMES` (fourteen plain themes and five boss arenas: each one's road widths, piece weights, bridges, flowerbeds, barrier and drop kinds, what its ball, roller and stomper are drawn as, `ice`, `dark`, `boss`, and a `tier` for where in a run it belongs), `REGULAR`, `BOSS_ORDER`, `ARENAS`, `TWISTS` (Rush hour, Gold rush, Lights out, Downpour, Supply drop, Turbo lane) with `TWIST_SHARE`, `KIND_FROM` (the slot each rival kind first comes in), `slotFor(n)` (a stage's difficulty from its place: length, par, pace, sharpness, rivals, kinds, crack and gap lengths), `stageSpec(n, id, twist)` (slot, then theme, then what the twist changes), `classicTheme(n)` and `STAGES` (the first lap of an unshuffled run). The place to tune the difficulty |
|
||||
| `public/activities/bounce-road.js` | the road, rules only: the jump math every hole is sized by (`airMs(v)`, `reach(v)`, `LONGEST_JUMP`, `JUMP_FAIR`, `TOP_SPEED`, `MAX_SPEED`); the run's plan, `planAt(road, n)` and `stageFor(n, road)` (with no road, or one made with no shuffle, the classic order; a shuffled road deals each lap from its seed: Chalk Lane first, ten of the plain themes roughly gentle to hard, the bosses in a new order with the Cat last on the first lap, a twist on some plain stages; built once a road) and `stageName`; `newRoad(seed, shuffle)` and `buildStage(road, n, random)` (a stage's rows from its own seed by its piece weights: straights, cracks, rivers on bridges, splits, ramps, chicanes, crumbling road, trains, swaying bridges, boost strips, slicks, balls, sprinklers, drops, gusts, conveyors, spring pads, bumpers, lasers, stompers and rollers; every hole after a `RUNUP` with a sign and no longer than `MAX_HOLE`; a boss stage opens with rockets on the road); `POWER_ROLL` and `rollPower(n, roll)` (which power-up, by stage); `extendStage(road, n, to)` (more of the last stage built, its line moving to the new end: the boss hold); the stunt pieces every theme lays (`WILD` in `bounce-roads.js`): `kicker` (a big ramp, `KICKER_AIR` the usual jump, over a chicane), `wall` (blocks right across the road), `trampoline` (three rows of spring pads) and `turbo` (a `TURBO_W` wide lane of boost strips); `ensureRoad`, `groundAt(road, x, d, t)`, `rowGone`, `spanAt`, `holesIn`, `firstAt`, `plainRow`, `safeSpot`; and where each timed thing is at a moment: `swayOff`, `drawLift`, `crumbleAt`, `trainAt`, `ballX` (a ball's and a roller's middle), `sprayAt`, `gustAt`, `laserAt` (on, and blinking `LASER_WARN_MS` before), `stomperAt` (down, the slice it lands in, and its shadow growing `STOMP_WARN_MS` before); plus `seeded`, `GROUND`, `MARK`, `SPAN` |
|
||||
| `public/activities/bounce-rivals.js` | the rivals, rules only: `RIVALS` (box, mass, speed, points, dodge, weight, car style, and the flags `behind`, `spiky`, `friend`, `boss` with `hp` and a `hint`), `BOSS_KINDS`, `isBoss`, `makeCar`, `think(round, car, ms, random)`, `spawnRival`, `pickKind` (weighted among the stage's kinds, a kind new to the stage more often, one of each special kind at a time), `lob` (a thing thrown at where you are heading). The plain kinds: the Zigzag weaves, the Brick holds your lane and brake-checks, the Frog hops at you, the Sneak drops cones, the Nudge and the Cop chase and shove (never by the water), the Hauler blocks, the Bruiser slams, the Racer passes and flees. The ones with a trick: the Blaster lines up ahead, glows for `AIM_MS` and fires a bolt back down the road; the Slasher pulls alongside, glints for `BLADE_WARN_MS`, then its blades are out for `BLADE_MS`; the Spike sits in your lane, a crash to land on; the Bomber drops bombs while you follow; the Phantom is out of reach for `PHASE_OFF_MS` of every cycle; the Splitter bursts into two Minis; the Magnet hugs an edge and holds your speed; the Supply truck (a friend) keeps ahead for a while, then drives off. The bosses: the Big Rig (`tanker`: lobs barrels, leaks oil), the Robo-Vac (`vac`: sweeps, warns `VAC_WARN_MS`, charges back at you, then drives back up the road through anything), the Whirlybird (`chopper`: `lift` 1 and `high` while it bombs out of reach, then down on the road for `CHOPPER_LOW_MS`), the Monster (hops to come down where you will be, drops tires) and the Cat (`cat`: slams like the Monster, then sweeps across the road for `CAT_SWIPE_MS`). A zapped or oil-spun rival coasts blind (no steering, tricks or hops). Every other rival is rubber-banded to stay near you, swerves from under your landing as sharply as its stage allows, keeps to the narrowest road just ahead, and hops any hole, barrier, coming train, laser or roller |
|
||||
| `public/activities/bounce-draw.js` | Bounce Road's drawing: `drawScene(ctx, view)` from one view object `bounce.js` refills each frame, in field units: the strip above the field in the page's colors with the pills (laid out by `hudLayout`: stage, lives, Spring, Bubble, Nitro and Mega with their timers, the chain and the combo with its timer; a pill that would run off the board starts a second row), the road a chunk of `CHUNK_ROWS` rows at a time, drawn off screen once per road and scale, a few kept and copied each frame (rows from `bounce-scenery.js`), the layers over it (`bounce-scenery.js`), the landing rings (yours in your highlight, a rival's in red, the Monster's its own size), the cars through `bounce-cars.js` (every shadow first, upright, then every body with its tumble: Planny in your highlight with his box in the page's panel color and his star eye, arms to the wheel, up in the air or cheering, down at the end; each rival kind in its own style and color, the Cop's siren while it chases, the Monster's dents and a star per life left above it, headlights at Night Lights), sparks, rings, the dark of Night Lights, the chain's big number, the stage bar beside the field, banners, and the start and end strip with the big final score and a dot per stage reached; every word kept on the field by `labelSpot`, and `readColors(canvas)`, `limbInk`, `inkOn`; decides nothing; since the arcade layer: a boss routed to its own drawer, the Whirlybird lifted over its shadow, a Phantom faded, your landing ring red and crossed over a Spike, the Fever meter along the strip, a boss's health bar across the top of the field, the title and over screens, a CRT scanline pass, and the dark whenever a stage's `dark` is set (Night Lights or a Lights out twist), with lasers, rockets, bolts and blasts drawn over it; it re-exports `CUSTOM_STYLES` |
|
||||
| `public/activities/bounce-extras.js` | the arcade layer's drawing, no rules: `CUSTOM_STYLES` (`vac`, `chopper`, `paw`: the three bosses that are not car styles) with `drawBossBody` and `drawBossShadow`; `drawCarExtras` (a Blaster's turret, a Slasher's blades, a Spike's spikes, a Bomber's rack, a Phantom's shimmer, a Magnet's horseshoe, the Supply truck's crate, zap sparks, an oil spin, a boss dazed); `drawPulls` (a Magnet's and the Robo-Vac's pull), `drawYouUnder` and `drawYouOver` (the Fever's rings, the Star magnet's ring, the gadget held); `drawSpills`, `drawThreatsLow` (bombs, a lob's shadow) and `drawThreatsHigh` (rockets, bolts, lobs in flight, pixel fireballs from `fx.booms`); `drawFever`, `drawBossBar`, `drawTitle` (the logo, PRESS SPACE, GAME OVER, the last fifteen rank badges) and `drawScanlines`. Words are drawn through a `label` handed in by `bounce-draw.js`, which it may not import |
|
||||
| `public/activities/bounce-cars.js` | Bounce Road's cars, drawing only and no imports: `drawCarBody(ctx, style, opts)` draws one top-down toy car about the origin, nose up, filling `w` by `h` field units exactly (tires on the box's corners), in one of `CAR_STYLES` (`STYLE_NAMES`: Planny's convertible with his star eye and arms to the wheel, hatch, sedan, coupe, muscle, pickup, van, box truck, police, racer, taxi, jeep, monster) with flat-fill shading worked out from `color` and `accent` (`shade`, `rgbOf`), and options for roll (`tilt`), a jump (`air`: it draws the shadow and the lift itself), a pancake (`squash`), night beams, a siren bar, damage, a boost flame and brake lights, all moving parts on `opts.clock`; `drawCarShadow` and `shadow: false` for a shadows-first pass in screen space; `carLength(style, w)` for a style's natural length and `carReach(style, opts)` (with `MARGINS`) for what reaches outside the box; plus the newer styles as data rows: armor, buggy, bubble, bus, mini, tow, supply and tanker |
|
||||
| `public/activities/bounce-scenery.js` | Bounce Road's scenery, drawing only: each stage's look in fixed colors (`LOOKS`: patio slabs, lawn stripes, kitchen tiles, garden, sand, a toy room's rug, a pond with lily pads, roof shingles, the night lawn with lamps and the Monster's dirt; `lookOf`, `stageColor`, `contrast`, `better`), `drawRow` (one row of the road in three passes over a chunk: the yard, the road's surface, the details: edges slanting from row to row, rivers, plank bridges with jagged broken ends, cracks, flowerbeds, rails across a crossing, cracked road over a pit, checkered stage lines, verge decor), and the layers drawn fresh each frame from the round's clock: `drawTimed` (a drawbridge lifting with its red lights, a swaying bridge where it is now, crumbled road gone to the pit), `drawPads` (running boost chevrons, ramps, slicks), `drawBlocks` (cones, toy blocks, pots, buckets, acorns and tires, knocked ones tumbling off), `drawStars`, `drawSigns` (a mark per hazard), `drawItems`, `drawHazardsLow` (crossing lights, the train, a rolling ball, a falling thing's growing shadow, a sprinkler's head), `drawHazardsHigh` (the jet, gust streaks, the thing still falling), `drawNight` and `drawFireflies`; decides nothing; plus the nine newer looks (bath, pinball, desk, ice, lava, garage, hall, attic, couch) with their patterns, lava drawn fresh each frame (`drawLava`), an icy sheen and rain (`drawSheen`, `drawRain`), conveyors, spring pads, bumpers, barrels, the balls by kind, rollers, lasers (`drawBeams`), stompers, the newer signs, and every power-up's mark (`itemMark`, `drawPickup`: a gadget is a square crate, the rest round) |
|
||||
| `public/activities/bounce-sfx.js` | its own sounds, merged into `tones.js`: `music` (the twenty tracks of `bounce-music.js`, its only import), `tones` (landings, the Monster, the siren, the crossing, a bumper, a rocket, oil, the ground pound, the Fever, a Slasher's blades, the Cat, the Robo-Vac's charge, a gadget loaded) and `hums` (your motor, the Monster, the Whirlybird's rotor, the Robo-Vac, crumbling road, a sprinkler); definitions only |
|
||||
| `public/activities/bounce-music.js` | its music, all synthesized (no mp3): `SCORES`, twenty short scores (`{ title, key, scale, bpm, kit, bass, arp, drums, A: { chords, lead }, B: { chords, lead } }`: `key` the tonic as a MIDI note for the bass, `chords` a scale degree a bar, `lead` eight bars of sixteen characters, `1` to `7` the scale's degrees, `a` to `g` an octave up, `A` to `G` an octave down, `-` a hold, `.` a rest), and `BOUNCE_MUSIC`, `bounceSong1` to `bounceSong20`, each score turned by `build()` into a `music.js` track when the file loads: a bass, a lead and an arpeggio on one of five chip kits (`KITS`), drums, an echo of the lead (`from` 0.7, a boss) and a harmony under it (`from` 0.9, a Fever), in the order intro, tune, tune with its arpeggio, second tune twice, break, both tunes again (56 bars, 73 to 88 seconds at 146 to 178 bpm, `rush` 14). The bar patterns are `BASS`, `ARP` and `DRUMS`. No imports |
|
||||
|
||||
**Tests.** `scripts/test-web-console-activities-bounce.mjs` (driving, the road and its fairness, the stage plan, the older rivals, the bots), `scripts/test-web-console-activities-bounce-arcade.mjs` (gadgets, the Fever, ranks, the newer hazards and rivals, the bosses, the double tap, the music), `scripts/test-web-console-activities-bounce-game.mjs` (the game contract, pills, tones, drawing) and `scripts/test-web-console-activities-bounce-cars.mjs` (the car art). Changing only Bounce Road: run those four.
|
||||
@@ -0,0 +1,983 @@
|
||||
// Web console tests, Bounce Road's arcade layer: the gadgets a double tap sets off (rockets, oil, the ground pound, the zapper) and the power-ups that work as taken, the Fever, the lives a score earns and a stage's rank, the newer things on the road (conveyors, spring pads, bumpers, lasers, stompers, rollers), the rivals with a trick of their own, the five bosses, and the music's deal.
|
||||
// Run with: node --test scripts/test-web-console-activities-bounce-arcade.mjs
|
||||
//
|
||||
// The driving, the road and the older rivals have their own suite,
|
||||
// scripts/test-web-console-activities-bounce.mjs, whose helpers this file
|
||||
// copies. No browser and no server: a stub canvas stands in for the page.
|
||||
|
||||
import "./seed-random.mjs";
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as bounce from "../src/web-console/public/activities/bounce.js";
|
||||
import { BOUNCE_MUSIC, SCORES } from "../src/web-console/public/activities/bounce-music.js";
|
||||
|
||||
const game = bounce.default;
|
||||
|
||||
/* ------------------------------------------------------------- helpers */
|
||||
|
||||
// A random source that always says the same, so no rival guesses.
|
||||
const steady = () => 0.5;
|
||||
const eventsOf = (round, type) => round.events.filter((e) => e.type === type);
|
||||
|
||||
// A 2D context whose every method is a no-op.
|
||||
function stubCanvas() {
|
||||
const ctx = new Proxy({}, {
|
||||
get: (target, name) => (name in target ? target[name] : () => {}),
|
||||
set: (target, name, value) => { target[name] = value; return true; },
|
||||
});
|
||||
return { width: 0, height: 0, getContext: () => ctx };
|
||||
}
|
||||
|
||||
// A round on the road from `seed`, with only you on it and no rival coming.
|
||||
function bounceRound(seed = 7) {
|
||||
const round = bounce.newRound(seed, steady);
|
||||
round.cars.length = 1;
|
||||
round.spawnMs = 1e12;
|
||||
round.supplyMs = 1e12;
|
||||
round.far = 1e9;
|
||||
return round;
|
||||
}
|
||||
|
||||
// A rival of `kind` put at (x, d), still and on the ground, going nowhere on
|
||||
// its own.
|
||||
function bounceRival(round, kind, x, d, over = {}) {
|
||||
let car = null;
|
||||
for (let at = round.cars[0].d + 300; !car && at < round.cars[0].d + 3000; at += 40) car = bounce.spawnRival(round, kind, steady, at);
|
||||
assert.ok(car, `a ${kind} spawns`);
|
||||
Object.assign(car, { x, d, v: 0, tv: 0, vx: 0, kx: 0, air: 0, tx: x, lane: x, hopIn: 1e9, dropIn: 1e9, phaseIn: 1e9, mode: "calm", ...over });
|
||||
return car;
|
||||
}
|
||||
|
||||
// A spot on plain road: the middle of the first row at or after `d` with
|
||||
// nothing to catch you out for `clear` units either side.
|
||||
function plainSpot(road, d = 40, clear = 20) {
|
||||
bounce.ensureRoad(road, d + 9000);
|
||||
const busy = (lo, hi) => [road.pads, road.blocks, road.hazards, road.items, road.stars].some((list) => list.some((e) => e.d > lo - 12 && (e.d1 ?? e.d) > lo - 12 && e.d < hi + 12));
|
||||
for (let i = Math.floor(d / bounce.ROW); i < road.rows; i++) {
|
||||
let ok = true;
|
||||
for (let j = i - clear / bounce.ROW; ok && j <= i + clear / bounce.ROW; j++) ok = bounce.plainRow(road, j);
|
||||
if (ok && !busy(i * bounce.ROW - clear, i * bounce.ROW + clear)) return { x: (road.L[i] + road.R[i]) / 2, d: i * bounce.ROW + 1, i };
|
||||
}
|
||||
throw new Error("no plain road");
|
||||
}
|
||||
|
||||
// A round with you at speed on a long stretch of plain road.
|
||||
function onPlain(seed = 7, clear = 50) {
|
||||
const round = bounceRound(seed);
|
||||
const at = plainSpot(round.road, 80, clear);
|
||||
const you = round.cars[0];
|
||||
Object.assign(you, { x: at.x, d: at.d, v: 40, pnose: at.d + you.l / 2 });
|
||||
// On the spot's own stage, so no stage line is crossed on the way to it.
|
||||
while (round.road.stageAt[round.stage] <= at.d) round.stage++;
|
||||
return { round, you, at };
|
||||
}
|
||||
|
||||
// The first entry of `list` on the road matching `pick`, with the round set
|
||||
// to its stage and you put `before` it, on the ground.
|
||||
function onto(round, list, pick, before = 30) {
|
||||
const road = round.road;
|
||||
bounce.ensureRoad(road, 60000);
|
||||
const e = road[list].find(pick);
|
||||
assert.ok(e, `a ${list} entry on the road`);
|
||||
const d0 = e.d ?? e.d0;
|
||||
while (road.stageAt[round.stage] <= d0) round.stage++;
|
||||
const you = round.cars[0];
|
||||
const d = d0 - before;
|
||||
Object.assign(you, { d, x: e.x ?? (road.L[bounce.rowOf(d)] + road.R[bounce.rowOf(d)]) / 2, v: 40, air: 0, pnose: d + you.l / 2 });
|
||||
round.far = 1e9;
|
||||
return e;
|
||||
}
|
||||
|
||||
// Lands you on `car` in the next slice.
|
||||
function landOn(round, car) {
|
||||
const you = round.cars[0];
|
||||
Object.assign(car, { x: you.x, d: you.d + 1, air: 0 });
|
||||
Object.assign(you, { air: 4, airMax: 600 });
|
||||
bounce.advance(round, 4, steady);
|
||||
}
|
||||
|
||||
// The round's clock put where `h`'s own cycle is `at` ms in.
|
||||
const cycleTo = (round, h, at) => (round.clock = h.period * 3 - (h.phase % h.period) + at);
|
||||
|
||||
/* ------------------------------------------------------- the gadgets */
|
||||
|
||||
test("Bounce Road arcade: a gadget taken is held until it is set off, one at a time; the rest work as they are taken", () => {
|
||||
const { round, you } = onPlain();
|
||||
assert.deepEqual([...bounce.GADGETS].sort(), ["mega", "nitro", "oil", "pound", "rocket", "zap"]);
|
||||
for (const kind of bounce.GADGETS) {
|
||||
bounce.applyPower(round, kind);
|
||||
assert.deepEqual(you.held, { kind, uses: bounce.POWERS[kind].uses }, `${kind} is held`);
|
||||
}
|
||||
assert.equal(you.held.kind, bounce.GADGETS.at(-1), "a new one takes the old one's place");
|
||||
bounce.applyPower(round, "spring");
|
||||
bounce.applyPower(round, "bubble");
|
||||
bounce.applyPower(round, "magnet");
|
||||
assert.ok(you.spring && you.bubble && you.magnetMs === bounce.MAGNET_MS, "a Spring, a Bubble and a Magnet work at once");
|
||||
assert.equal(you.held.kind, bounce.GADGETS.at(-1), "and leave the gadget held");
|
||||
round.lives = 2;
|
||||
bounce.applyPower(round, "heart");
|
||||
assert.equal(round.lives, 3, "a heart is a life");
|
||||
round.lives = bounce.MAX_LIVES;
|
||||
bounce.applyPower(round, "heart");
|
||||
assert.equal(round.lives, bounce.MAX_LIVES, "never past MAX_LIVES");
|
||||
for (const [kind, , from] of bounce.POWER_ROLL) {
|
||||
assert.ok(bounce.POWERS[kind], `${kind} is a power-up`);
|
||||
assert.ok(from >= 2, "none on the first stage");
|
||||
}
|
||||
assert.equal(new Set(bounce.POWER_ROLL.map((r) => r[0])).size, Object.keys(bounce.POWERS).length, "every power-up turns up");
|
||||
for (let n = 2; n <= 8; n++) for (let r = 0; r < 1; r += 0.05) assert.ok(bounce.POWER_ROLL.find((e) => e[0] === bounce.rollPower(n, r))[2] <= n, `stage ${n} rolls only what has come`);
|
||||
const road = bounce.newRoad(5);
|
||||
bounce.ensureRoad(road, 9000);
|
||||
const arena = road.items.find((it) => it.d > road.stageAt[2]);
|
||||
assert.equal(arena.kind, "rocket", "a boss stage opens with rockets on the road");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a rocket blows up the first rival in its way for its points, takes a hit off a boss, smashes a barrier, and three are a load", () => {
|
||||
const { round, you, at } = onPlain();
|
||||
bounce.applyPower(round, "rocket");
|
||||
const brick = bounceRival(round, "brick", at.x, at.d + 30);
|
||||
assert.equal(bounce.usePower(round), "rocket");
|
||||
assert.equal(you.held.uses, 2);
|
||||
assert.equal(round.shots.length, 1);
|
||||
bounce.advance(round, 500, steady);
|
||||
assert.equal(brick.outKind, "blast", "blown up");
|
||||
const [blast] = eventsOf(round, "blast");
|
||||
assert.equal(blast.points, Math.max(bounce.BLAST_POINTS, bounce.RIVALS.brick.points));
|
||||
assert.equal(round.stats.blasted, 1);
|
||||
assert.equal(round.shots.length, 0, "the rocket is spent");
|
||||
const m = bounceRival(round, "monster", you.x, you.d + 34, { hp: 5, v: you.v, tv: you.v });
|
||||
bounce.usePower(round);
|
||||
bounce.advance(round, 500, steady);
|
||||
assert.equal(m.hp, 4, "a hit off the Monster");
|
||||
assert.ok(eventsOf(round, "stomp").some((e) => e.how === "rocket" && e.points === bounce.ROCKET_BOSS_POINTS));
|
||||
m.out = 1;
|
||||
m.outKind = "gone";
|
||||
bounce.advance(round, 16, steady);
|
||||
const block = { kind: "block", x: you.x, d: you.d + 26, w: 5, l: 3, hit: 0 };
|
||||
round.drops.push(block);
|
||||
bounce.usePower(round);
|
||||
assert.equal(you.held, null, "the third was the last");
|
||||
bounce.advance(round, 400, steady);
|
||||
assert.ok(block.hit > 0, "a barrier smashed");
|
||||
// A rocket that meets nothing runs out of road.
|
||||
bounce.applyPower(round, "rocket");
|
||||
bounce.usePower(round);
|
||||
bounce.advance(round, 1500, steady);
|
||||
assert.equal(round.shots.length, 0);
|
||||
assert.equal(round.stats.fired, 4);
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: oil lies behind you and spins the rival that crosses it, which is yours when the road's edge takes it; a boss's oil only takes your grip", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
bounce.applyPower(round, "oil");
|
||||
bounce.usePower(round);
|
||||
assert.equal(you.held.uses, 1);
|
||||
const [spill] = round.spills;
|
||||
assert.ok(spill.d < you.d && !spill.foe, "behind you");
|
||||
const brick = bounceRival(round, "brick", spill.x + 1, spill.d - 7, { v: 30, tv: 30 });
|
||||
let spun = false;
|
||||
for (let ms = 0; ms < 1200 && !spun; ms += 16) {
|
||||
bounce.advance(round, 16, steady);
|
||||
spun = brick.spinMs > 0;
|
||||
}
|
||||
assert.ok(spun, "it spins");
|
||||
assert.equal(eventsOf(round, "spin").length, 1);
|
||||
assert.ok(brick.credit > 0 && Math.abs(brick.kx) > 10, "thrown sideways, and yours");
|
||||
bounce.think(round, brick, 16, steady);
|
||||
assert.equal(brick.gain, 0, "it cannot steer out of it");
|
||||
assert.equal(round.stats.spun, 1);
|
||||
// A boss's spill: no life, no spin, only a slide.
|
||||
const r2 = onPlain(7, 60);
|
||||
r2.round.spills.push({ x: r2.at.x, d: r2.at.d + 6, w: 9, l: 11, until: r2.round.clock + 5000, foe: true });
|
||||
for (let ms = 0; ms < 400; ms += 16) bounce.advance(r2.round, 16, steady);
|
||||
assert.ok(r2.you.slickMs > 0 || eventsOf(r2.round, "slick").length === 1, "your grip goes");
|
||||
assert.equal(r2.round.lives, bounce.START_LIVES);
|
||||
bounce.advance(r2.round, bounce.OIL_MS + 2000, steady);
|
||||
assert.equal(r2.round.spills.length, 0, "and it dries up");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a ground pound slams you down, flattens what is near, throws what is further and smashes barriers; on the road it goes off at once", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
bounce.applyPower(round, "pound");
|
||||
const near = bounceRival(round, "zigzag", at.x + 2, at.d + 6);
|
||||
const mid = bounceRival(round, "brick", at.x + 8, at.d + 16);
|
||||
const far = bounceRival(round, "frog", at.x, at.d + 60);
|
||||
const block = { kind: "block", x: at.x - 6, d: at.d + 8, w: 5, l: 3, hit: 0 };
|
||||
round.drops.push(block);
|
||||
round.bolts.push({ x: at.x, d: at.d + 10, v: 0 });
|
||||
assert.equal(bounce.usePower(round), "pound");
|
||||
assert.equal(near.outKind, "flat", "flattened");
|
||||
assert.ok(eventsOf(round, "crush").some((e) => e.pound && e.kind === "zigzag"));
|
||||
assert.ok(mid.out === 0 && mid.kx > 5 && mid.credit > 0, "thrown outward, and yours if it goes off");
|
||||
assert.ok(far.out === 0 && far.kx === 0, "out of reach");
|
||||
assert.ok(block.hit > 0, "the barrier is gone");
|
||||
assert.equal(round.bolts.length, 0, "and the bolts");
|
||||
assert.equal(eventsOf(round, "pound").length, 1);
|
||||
assert.equal(you.held.uses, 1);
|
||||
// In the air it brings you down first.
|
||||
Object.assign(you, { air: 500, airMax: 600 });
|
||||
bounce.usePower(round);
|
||||
assert.ok(you.pounding && you.air <= bounce.POUND_DROP_MS, "down in POUND_DROP_MS");
|
||||
assert.equal(eventsOf(round, "pound").length, 1, "nothing until you land");
|
||||
bounce.advance(round, bounce.POUND_DROP_MS + 8, steady);
|
||||
assert.equal(eventsOf(round, "pound").length, 2, "the shockwave on landing");
|
||||
assert.equal(you.pounding, false);
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a zap leaves every rival near coasting blind for ZAP_MS (no steering, no tricks, no hops), stuns a boss and brings the Whirlybird down", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
const frog = bounceRival(round, "frog", at.x + 6, at.d + 20, { hopIn: 0 });
|
||||
const away = bounceRival(round, "zigzag", at.x, at.d + bounce.ZAP_RANGE + 30);
|
||||
const m = bounceRival(round, "monster", at.x - 12, at.d + 40, { hp: 5 });
|
||||
const chopper = bounceRival(round, "chopper", at.x + 12, at.d + 50, { mode: "high", lift: 1, high: true });
|
||||
round.bolts.push({ x: at.x, d: at.d + 30, v: 0 });
|
||||
bounce.applyPower(round, "zap");
|
||||
bounce.usePower(round);
|
||||
assert.equal(you.held, null);
|
||||
assert.equal(frog.zapMs, bounce.ZAP_MS);
|
||||
assert.ok(frog.credit > bounce.ZAP_MS, "the road's edge or a hole makes it yours");
|
||||
assert.equal(away.zapMs, 0, "out of range");
|
||||
assert.ok(m.stunMs > 1000, "a boss is stunned");
|
||||
assert.equal(chopper.mode, "low", "the Whirlybird comes down");
|
||||
assert.equal(round.bolts.length, 0);
|
||||
bounce.think(round, frog, 16, steady);
|
||||
assert.equal(frog.air, 0, "no hop");
|
||||
assert.equal(frog.gain, 0, "no steering");
|
||||
for (let ms = 0; ms < bounce.ZAP_MS + 100; ms += 16) bounce.think(round, frog, 16, steady);
|
||||
assert.equal(frog.zapMs, 0, "it wears off");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a Magnet pulls in the stars and power-ups within MAGNET_R, in the air too, for MAGNET_MS", () => {
|
||||
const { round, you } = onPlain(7, 60);
|
||||
const road = round.road;
|
||||
road.stars.length = 0;
|
||||
road.items.length = 0;
|
||||
const star = { x: you.x + bounce.MAGNET_R - 2, d: you.d + 4, taken: false };
|
||||
const item = { x: you.x - bounce.MAGNET_R + 2, d: you.d + 6, kind: "bubble", taken: false };
|
||||
road.stars.push(star);
|
||||
road.items.push(item);
|
||||
bounce.advance(round, 8, steady);
|
||||
assert.ok(!star.taken && !item.taken, "out of reach without one");
|
||||
bounce.applyPower(round, "magnet");
|
||||
Object.assign(you, { air: 300, airMax: 600 });
|
||||
bounce.advance(round, 8, steady);
|
||||
assert.ok(star.taken && item.taken && you.bubble, "pulled in");
|
||||
for (let ms = 0; ms < bounce.MAGNET_MS + 100; ms += 4) bounce.move(round, you, 4);
|
||||
assert.equal(you.magnetMs, 0, "it runs out");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------- fever, lives, rank */
|
||||
|
||||
test("Bounce Road arcade: stunts fill the Fever; full, it burns for FEVER_MS with every point doubled and a touch flattening a rival; a life lost puts it out", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
const need = Math.ceil(bounce.FEVER_FULL / bounce.FEVER_GAIN);
|
||||
for (let k = 0; k < need - 1; k++) bounce.stunt(round, 10);
|
||||
assert.equal(round.feverMs, 0, "not yet");
|
||||
assert.ok(round.fever > bounce.FEVER_FULL * 0.9);
|
||||
bounce.stunt(round, 10);
|
||||
assert.equal(round.feverMs, bounce.FEVER_MS, "lit");
|
||||
assert.equal(eventsOf(round, "fever").length, 1);
|
||||
assert.equal(bounce.stunt(round, 10), 10 * bounce.MAX_COMBO * 2, "double points");
|
||||
const zig = bounceRival(round, "zigzag", at.x + 4, at.d + 1);
|
||||
assert.equal(bounce.collide(round, you, zig), "mega");
|
||||
assert.equal(zig.outKind, "flat", "a touch flattens");
|
||||
assert.ok(eventsOf(round, "crush").at(-1).fever);
|
||||
const spike = bounceRival(round, "spike", at.x, at.d + 40);
|
||||
landOn(round, spike);
|
||||
assert.equal(spike.outKind, "flat", "even a Spike, from above");
|
||||
you.air = 0;
|
||||
bounce.advance(round, bounce.FEVER_MS + 50, steady);
|
||||
assert.equal(round.feverMs, 0);
|
||||
assert.equal(round.fever, 0, "burnt out");
|
||||
assert.equal(eventsOf(round, "feverEnd").length, 1);
|
||||
for (let k = 0; k < 10; k++) bounce.stunt(round, 10);
|
||||
const held = round.fever;
|
||||
bounce.lose(round, "crash");
|
||||
assert.equal(round.fever, Math.floor(held / 2), "a life lost halves the meter");
|
||||
const r2 = onPlain(7, 60).round;
|
||||
bounce.startFever(r2);
|
||||
bounce.lose(r2, "crash");
|
||||
assert.ok(r2.feverMs === 0 && r2.fever === 0, "and puts a Fever out");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: every LIFE_SCORE points is a life, up to MAX_LIVES", () => {
|
||||
const { round } = onPlain();
|
||||
round.lives = 2;
|
||||
round.score = bounce.LIFE_SCORE - 1;
|
||||
bounce.advance(round, 8, steady);
|
||||
assert.equal(round.lives, 2);
|
||||
round.score = bounce.LIFE_SCORE + 5;
|
||||
bounce.advance(round, 8, steady);
|
||||
assert.equal(round.lives, 3);
|
||||
assert.equal(eventsOf(round, "life").length, 1);
|
||||
bounce.advance(round, 200, steady);
|
||||
assert.equal(round.lives, 3, "once a mark");
|
||||
round.lives = bounce.MAX_LIVES;
|
||||
round.score = bounce.LIFE_SCORE * 2 + 5;
|
||||
bounce.advance(round, 8, steady);
|
||||
assert.equal(round.lives, bounce.MAX_LIVES);
|
||||
assert.equal(round.lifeAt, bounce.LIFE_SCORE * 3, "the mark still moves on");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a stage line ranks the stage: C for a slow run with a life lost, A for a flawless run under par, S with a combo of three on top", () => {
|
||||
const cross = (setup) => {
|
||||
const round = bounceRound(7);
|
||||
const road = round.road;
|
||||
const you = round.cars[0];
|
||||
const d = road.stageAt[1] - 0.5;
|
||||
Object.assign(you, { d, x: (road.L[bounce.rowOf(d)] + road.R[bounce.rowOf(d)]) / 2, v: 40 });
|
||||
setup(round);
|
||||
bounce.advance(round, 60, steady);
|
||||
assert.equal(round.stage, 2);
|
||||
return eventsOf(round, "stage")[0].rank;
|
||||
};
|
||||
assert.equal(cross((r) => { r.stageLost = true; r.clock = 500000; }), "C");
|
||||
assert.equal(cross((r) => { r.clock = 500000; }), "B", "flawless but slow");
|
||||
assert.equal(cross(() => {}), "A");
|
||||
assert.equal(cross((r) => { r.stageCombo = 3; }), "S");
|
||||
const round = bounceRound(7);
|
||||
assert.deepEqual(round.ranks, []);
|
||||
});
|
||||
|
||||
/* --------------------------------------------- new things on the road */
|
||||
|
||||
test("Bounce Road arcade: a conveyor carries you across at BELT_PUSH, a spring pad throws you up POP_AIR the usual jump, and a bumper kicks you away for points, never a life", () => {
|
||||
const round = bounceRound(9);
|
||||
const belt = onto(round, "pads", (p) => p.kind === "belt", 0);
|
||||
const you = round.cars[0];
|
||||
const x0 = you.x;
|
||||
for (let ms = 0; ms < 400; ms += 4) bounce.advance(round, 4, steady);
|
||||
assert.ok((you.x - x0) * belt.dir > bounce.BELT_PUSH * 0.3, `carried ${belt.dir > 0 ? "right" : "left"} (${(you.x - x0).toFixed(1)})`);
|
||||
assert.equal(eventsOf(round, "belt").length, 1);
|
||||
const r2 = bounceRound(9);
|
||||
const pop = onto(r2, "pads", (p) => p.kind === "pop", 5);
|
||||
const y2 = r2.cars[0];
|
||||
y2.v = 50;
|
||||
for (let ms = 0; ms < 300 && y2.air <= 0; ms += 4) bounce.advance(r2, 4, steady);
|
||||
assert.ok(y2.air > 0, "thrown up");
|
||||
assert.ok(Math.abs(y2.airMax - bounce.airMs(y2.v) * bounce.POP_AIR) < 30, "POP_AIR the usual jump");
|
||||
assert.ok(y2.ramped, "big air to land");
|
||||
assert.equal(eventsOf(r2, "pop").length, 1);
|
||||
assert.ok(pop.w > bounce.CAR_W);
|
||||
const r3 = bounceRound(9);
|
||||
const bumper = onto(r3, "blocks", (b) => b.kind === "bumper", 6);
|
||||
const y3 = r3.cars[0];
|
||||
y3.x = bumper.x - 1;
|
||||
const before = r3.score;
|
||||
for (let ms = 0; ms < 400; ms += 4) bounce.advance(r3, 4, steady);
|
||||
const [hit] = eventsOf(r3, "bumper");
|
||||
assert.ok(hit, "it rings");
|
||||
assert.equal(hit.points, bounce.BUMPER_POINTS);
|
||||
assert.ok(r3.score >= before + bounce.BUMPER_POINTS);
|
||||
assert.equal(r3.lives, bounce.START_LIVES, "no life");
|
||||
assert.equal(bumper.hit, 0, "and it stays where it is");
|
||||
assert.ok(y3.x < bumper.x, "kicked to its side");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a laser is a crash while its beam is on and nothing while it is off, and a car in the air goes over it for points", () => {
|
||||
const through = (cycle, air) => {
|
||||
const round = bounceRound(3);
|
||||
const h = onto(round, "hazards", (e) => e.kind === "laser", 2);
|
||||
const you = round.cars[0];
|
||||
cycleTo(round, h, cycle(h));
|
||||
if (air) Object.assign(you, { air: 500, airMax: 600, jumpFrom: you.d });
|
||||
for (let ms = 0; ms < 240; ms += 4) bounce.advance(round, 4, steady);
|
||||
return { round, you, h };
|
||||
};
|
||||
const on = through(() => 10, false);
|
||||
assert.equal(on.round.phase, "crash");
|
||||
assert.equal(eventsOf(on.round, "lose")[0].cause, "laser");
|
||||
const off = through((h) => h.onMs + 200, false);
|
||||
assert.equal(off.round.phase, "drive", "off, it is nothing");
|
||||
assert.ok(off.you.d > off.h.d);
|
||||
const over = through(() => 10, true);
|
||||
assert.equal(over.round.phase, "drive", "over it in the air");
|
||||
assert.ok(over.you.overs.includes(over.h), "to score on landing");
|
||||
const lz = bounce.laserAt(on.h, on.h.period * 5 - (on.h.phase % on.h.period) - 100);
|
||||
assert.ok(lz.warn && !lz.on, "its posts blink before it comes on");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a stomper squashes what is under it as it lands, is a block while it is down, and lets you by while it is up", () => {
|
||||
const under = (at, place) => {
|
||||
const round = bounceRound(3);
|
||||
const h = onto(round, "hazards", (e) => e.kind === "stomper", 0);
|
||||
const you = round.cars[0];
|
||||
place(you, h);
|
||||
cycleTo(round, h, at(h));
|
||||
bounce.advance(round, 60, steady);
|
||||
return { round, h, you };
|
||||
};
|
||||
const hit = under((h) => h.period - 20, (you, h) => Object.assign(you, { x: h.x, d: h.d - 1, v: 16 }));
|
||||
assert.equal(hit.round.phase, "crash");
|
||||
assert.equal(eventsOf(hit.round, "lose")[0].cause, "squash");
|
||||
assert.equal(eventsOf(hit.round, "stompLand").length, 1);
|
||||
const wall = under(() => bounce.STOMP_HIT_MS + 60, (you, h) => Object.assign(you, { x: h.x, d: h.d - h.l / 2 - you.l / 2 - 0.6, v: 40, pnose: h.d - h.l / 2 - 0.6 }));
|
||||
assert.equal(wall.round.phase, "crash", "nose first into it while it is down");
|
||||
assert.equal(eventsOf(wall.round, "lose")[0].cause, "crash");
|
||||
const clear = under((h) => h.downMs + 150, (you, h) => Object.assign(you, { x: h.x, d: h.d - 3, v: 40 }));
|
||||
assert.equal(clear.round.phase, "drive", "up, it lets you by");
|
||||
const st = bounce.stomperAt(hit.h, hit.h.period * 4 - (hit.h.phase % hit.h.period) - bounce.STOMP_WARN_MS / 2);
|
||||
assert.ok(st.fall > 0.3 && st.fall < 0.7 && !st.down, "its shadow grows before it lands");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a roller is a crash to drive into and points to jump", () => {
|
||||
const round = bounceRound(3);
|
||||
const h = onto(round, "hazards", (e) => e.kind === "roller", 1);
|
||||
const you = round.cars[0];
|
||||
you.x = bounce.ballX(h, round.clock);
|
||||
bounce.advance(round, 40, steady);
|
||||
assert.equal(round.phase, "crash");
|
||||
const r2 = bounceRound(3);
|
||||
const h2 = onto(r2, "hazards", (e) => e.kind === "roller", 1);
|
||||
const y2 = r2.cars[0];
|
||||
Object.assign(y2, { x: bounce.ballX(h2, r2.clock), air: 300, airMax: 600, jumpFrom: y2.d });
|
||||
bounce.advance(r2, 40, steady);
|
||||
assert.equal(r2.phase, "drive");
|
||||
assert.ok(y2.overs.includes(h2), "jumped");
|
||||
assert.ok(h2.half > h2.r * 2, "long across the road, thin along it");
|
||||
});
|
||||
|
||||
/* --------------------------------------------- the rivals with a trick */
|
||||
|
||||
test("Bounce Road arcade: a Spike's roof costs a life and its side is a plain bump, a Splitter flattened bursts into two Minis, and the Supply truck's roof hands over a gadget once", () => {
|
||||
const a = onPlain(7, 60);
|
||||
const spike = bounceRival(a.round, "spike", a.at.x, a.at.d + 40);
|
||||
landOn(a.round, spike);
|
||||
assert.equal(a.round.phase, "crash");
|
||||
assert.equal(eventsOf(a.round, "lose")[0].cause, "spike");
|
||||
assert.equal(spike.out, 0, "it drives on");
|
||||
const b = onPlain(7, 60);
|
||||
const spike2 = bounceRival(b.round, "spike", b.at.x + 4.3, b.at.d + 1);
|
||||
assert.equal(bounce.collide(b.round, b.you, spike2), "side");
|
||||
assert.equal(b.round.phase, "drive");
|
||||
const splitter = bounceRival(b.round, "splitter", b.at.x, b.at.d + 60);
|
||||
landOn(b.round, splitter);
|
||||
assert.equal(splitter.outKind, "flat");
|
||||
const minis = b.round.cars.filter((c) => c.kind === "mini");
|
||||
assert.equal(minis.length, 2, "two Minis");
|
||||
assert.ok(minis[0].x < splitter.x && minis[1].x > splitter.x && minis.every((m) => m.v > splitter.v), "one either side, off up the road");
|
||||
assert.equal(eventsOf(b.round, "split").length, 1);
|
||||
const c = onPlain(7, 60);
|
||||
const truck = bounceRival(c.round, "supply", c.at.x, c.at.d + 40);
|
||||
landOn(c.round, truck);
|
||||
assert.ok(c.you.held && bounce.GADGETS.includes(c.you.held.kind), "a gadget");
|
||||
assert.ok(truck.gave && truck.out === 0);
|
||||
assert.equal(eventsOf(c.round, "haul").length, 1, "its roof is a trampoline");
|
||||
c.you.held = null;
|
||||
c.you.air = 0;
|
||||
landOn(c.round, truck);
|
||||
assert.equal(c.you.held, null, "once");
|
||||
assert.ok(bounce.RIVALS.supply.friend && bounce.RIVALS.spike.spiky);
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a Blaster glows, then fires a bolt back down the road that knocks and slows you without a life; in the air it passes under you", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const blaster = bounceRival(round, "blaster", at.x, at.d + 40, { dropIn: 0, v: 40, tv: 40, mode: "" });
|
||||
let aimed = 0;
|
||||
for (let ms = 0; ms < 3000 && !eventsOf(round, "shot").length; ms += 4) {
|
||||
bounce.advance(round, 4, steady);
|
||||
if (blaster.aimMs > 0) aimed += 4;
|
||||
}
|
||||
assert.equal(eventsOf(round, "aim").length >= 1, true, "it takes aim");
|
||||
assert.ok(aimed >= bounce.AIM_MS - 12, `for AIM_MS (${aimed})`);
|
||||
assert.ok(eventsOf(round, "bolt").length >= 1, "and fires");
|
||||
assert.equal(eventsOf(round, "shot").length, 1, "the bolt finds you");
|
||||
assert.equal(round.lives, bounce.START_LIVES, "no life");
|
||||
assert.ok(Math.abs(you.kx) > 5 && you.slickMs > 0, "knocked, and sliding");
|
||||
const r2 = onPlain(11, 90);
|
||||
r2.round.bolts.push({ x: r2.you.x, d: r2.you.d + 4, v: -bounce.BOLT_SPEED });
|
||||
Object.assign(r2.you, { air: 400, airMax: 600 });
|
||||
bounce.advance(r2.round, 300, steady);
|
||||
assert.equal(eventsOf(r2.round, "shot").length, 0, "under a car in the air");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a Slasher alongside glints, then its blades come out and its side is a crash; with them in it is a plain bump", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
const slasher = bounceRival(round, "slasher", at.x + 6, at.d, { mode: "chase", v: 40, tv: 40, offside: 1 });
|
||||
bounce.think(round, slasher, 16, steady);
|
||||
assert.equal(slasher.blade, "warn", "a glint first");
|
||||
assert.equal(eventsOf(round, "blade").length, 1);
|
||||
for (let ms = 0; ms <= bounce.BLADE_WARN_MS; ms += 16) bounce.think(round, slasher, 16, steady);
|
||||
assert.equal(slasher.blade, "out");
|
||||
slasher.x = you.x + 4.1;
|
||||
slasher.d = you.d;
|
||||
assert.equal(bounce.collide(round, you, slasher), "side");
|
||||
assert.equal(round.phase, "crash");
|
||||
assert.equal(eventsOf(round, "lose")[0].cause, "slash");
|
||||
const r2 = onPlain(7, 60);
|
||||
const calm = bounceRival(r2.round, "slasher", r2.at.x + 4.1, r2.at.d, { blade: "" });
|
||||
bounce.collide(r2.round, r2.you, calm);
|
||||
assert.equal(r2.round.phase, "drive", "blades in: a bump");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a Bomber drops a bomb while you follow, which blows BOMB_FUSE_MS on: a life for a car on the ground within BOMB_R, nothing for one clear of it", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const bomber = bounceRival(round, "bomber", at.x, at.d + 50, { dropIn: 0, v: 40, tv: 40, mode: "" });
|
||||
bounce.think(round, bomber, 16, steady);
|
||||
assert.equal(round.bombs.length, 1, "a bomb on the road");
|
||||
assert.equal(eventsOf(round, "bomb").length, 1);
|
||||
assert.equal(round.bombs[0].at, round.clock + bounce.BOMB_FUSE_MS);
|
||||
round.bombs.length = 0;
|
||||
bomber.out = 1;
|
||||
bomber.outKind = "gone";
|
||||
round.bombs.push({ x: you.x + bounce.BOMB_R + you.w, d: you.d + 3, at: round.clock + 40, t0: round.clock, r: bounce.BOMB_R });
|
||||
bounce.advance(round, 80, steady);
|
||||
assert.equal(eventsOf(round, "boom").length, 1);
|
||||
assert.equal(round.phase, "drive", "clear of the blast");
|
||||
round.bombs.push({ x: you.x + 2, d: you.d + 4, at: round.clock + 40, t0: round.clock, r: bounce.BOMB_R });
|
||||
bounce.advance(round, 80, steady);
|
||||
assert.equal(round.phase, "crash");
|
||||
assert.equal(eventsOf(round, "lose")[0].cause, "blast");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a Phantom out of reach cannot be bumped or landed on; a Magnet rival drags you toward it while it is near", () => {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
const phantom = bounceRival(round, "phantom", at.x + 3, at.d, { phased: true });
|
||||
bounce.advance(round, 16, steady);
|
||||
assert.equal(eventsOf(round, "bump").length, 0, "nothing to bump");
|
||||
landOn(round, phantom);
|
||||
assert.equal(phantom.out, 0, "nothing to land on");
|
||||
phantom.phased = false;
|
||||
you.air = 0;
|
||||
Object.assign(phantom, { x: you.x + 3, d: you.d });
|
||||
bounce.advance(round, 16, steady);
|
||||
assert.ok(eventsOf(round, "bump").length > 0, "solid again");
|
||||
const m = onPlain(7, 60);
|
||||
const magnet = bounceRival(m.round, "magnet", m.at.x + 12, m.at.d + 4, { mode: "", v: 40, tv: 40 });
|
||||
for (let ms = 0; ms < 300; ms += 4) bounce.advance(m.round, 4, steady);
|
||||
assert.ok(m.you.kx > 3, `dragged toward it (${m.you.kx.toFixed(1)})`);
|
||||
assert.ok(eventsOf(m.round, "magnet").length >= 1);
|
||||
assert.ok(magnet.pulling);
|
||||
const calm = onPlain(7, 60);
|
||||
bounceRival(calm.round, "magnet", calm.at.x + 12, calm.at.d + bounce.MAG_RANGE + 30, { mode: "" });
|
||||
bounce.advance(calm.round, 100, steady);
|
||||
assert.equal(calm.you.kx, 0, "too far to pull");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ bosses */
|
||||
|
||||
test("Bounce Road arcade: each boss comes in its own arena with its own hp, more of it each lap, and is named as it comes", () => {
|
||||
for (const [k, kind] of bounce.BOSS_ORDER.entries()) {
|
||||
const stage = (k + 1) * bounce.WORLD;
|
||||
assert.equal(bounce.stageFor(stage).boss, kind);
|
||||
const round = bounceRound(4);
|
||||
const road = round.road;
|
||||
bounce.ensureRoad(road, 40000);
|
||||
round.stage = stage;
|
||||
const at = plainSpot(road, road.stageAt[stage - 1] + bounce.stageFor(stage).len * 0.2, 30);
|
||||
Object.assign(round.cars[0], { x: at.x, d: at.d, v: 40 });
|
||||
bounce.advance(round, 16, steady);
|
||||
const boss = round.cars.find((c) => c.kind === kind);
|
||||
assert.ok(boss, `the ${kind} is out`);
|
||||
assert.equal(boss.hp, bounce.RIVALS[kind].hp);
|
||||
assert.ok(bounce.isBoss(boss) && bounce.RIVALS[kind].hint, "with a word on how to beat it");
|
||||
assert.ok(eventsOf(round, "spawn").some((e) => e.kind === kind));
|
||||
bounce.advance(round, 400, steady);
|
||||
assert.equal(round.cars.filter((c) => c.kind === kind).length, 1, "once a stage");
|
||||
}
|
||||
assert.deepEqual([...bounce.BOSS_KINDS].sort(), [...bounce.BOSS_ORDER].sort());
|
||||
const lap2 = bounceRound(4);
|
||||
bounce.ensureRoad(lap2.road, 90000);
|
||||
lap2.stage = 18;
|
||||
const at = plainSpot(lap2.road, lap2.road.stageAt[17] + bounce.stageFor(18).len * 0.2, 30);
|
||||
Object.assign(lap2.cars[0], { x: at.x, d: at.d, v: 40 });
|
||||
bounce.advance(lap2, 16, steady);
|
||||
const again = lap2.cars.find((c) => bounce.isBoss(c));
|
||||
assert.equal(again.hp, bounce.RIVALS[again.kind].hp + 1, "one more hp on the second lap");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: any boss is beaten by landings, rockets or a ground pound: its last hp is BOSS_POINTS, a life, a trophy and a Fever", () => {
|
||||
for (const kind of bounce.BOSS_ORDER) {
|
||||
const { round, you, at } = onPlain(7, 60);
|
||||
round.lives = 2;
|
||||
const boss = bounceRival(round, kind, at.x, at.d + 30, { hp: 3, lift: 0, high: false, mode: kind === "chopper" ? "low" : "calm", modeMs: 1e9 });
|
||||
landOn(round, boss);
|
||||
assert.equal(boss.hp, 2, `${kind}: a landing`);
|
||||
assert.ok(boss.stunMs > 0, "and it reels");
|
||||
you.air = 0;
|
||||
assert.equal(bounce.hurtBoss(round, boss, "rocket"), "stomp");
|
||||
assert.equal(boss.hp, 1, "a rocket");
|
||||
assert.equal(bounce.hurtBoss(round, boss, "pound"), "boss");
|
||||
assert.equal(boss.outKind, "flat");
|
||||
const [beat] = eventsOf(round, "boss");
|
||||
assert.equal(beat.kind, kind);
|
||||
assert.ok(beat.points >= bounce.BOSS_POINTS && beat.life);
|
||||
assert.equal(round.lives, 3);
|
||||
assert.equal(round.trophies, 1 << bounce.BOSS_ORDER.indexOf(kind), "its trophy");
|
||||
assert.ok(round.feverMs > 0, "and a Fever");
|
||||
assert.equal(bounce.hurtBoss(round, boss, "rocket"), "", "nothing more from a beaten boss");
|
||||
}
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: the Big Rig lobs a barrel at where you are heading, which lands LOB_MS on as a block and squashes what is under it", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const rig = bounceRival(round, "tanker", at.x, at.d + bounce.TANKER_AHEAD, { dropIn: 0, v: 40, tv: 40, mode: "", hp: 4 });
|
||||
bounce.think(round, rig, 16, steady);
|
||||
assert.equal(round.lobs.length, 1);
|
||||
const lob = round.lobs[0];
|
||||
assert.equal(lob.what, "barrel");
|
||||
assert.equal(lob.at, round.clock + bounce.LOB_MS);
|
||||
assert.ok(lob.d > you.d + 20 && lob.d < rig.d, "ahead of you, short of the truck");
|
||||
assert.equal(eventsOf(round, "lob").length, 1);
|
||||
assert.ok(bounce.underBanner(round, bounce.FIELD_H - (lob.d - (you.d - 18)), you.d - 18), "a banner gives way to it");
|
||||
rig.dropIn = 1e9;
|
||||
// Keep still: it lands ahead of you and lies there.
|
||||
you.v = 16;
|
||||
round.input.down = true;
|
||||
bounce.advance(round, bounce.LOB_MS + 20, steady);
|
||||
assert.equal(round.lobs.length, 0);
|
||||
assert.ok(round.drops.some((b) => b.what === "barrel" && b.kind === "block"), "a block on the road");
|
||||
assert.equal(round.phase, "drive");
|
||||
// Under it as it lands.
|
||||
const r2 = onPlain(11, 90);
|
||||
r2.round.lobs.push({ x: r2.you.x, d: r2.you.d + 1, at: r2.round.clock + 8, what: "barrel", boom: 0, w: 4.4, l: 4.4, fx: 0, fd: 0 });
|
||||
bounce.advance(r2.round, 16, steady);
|
||||
assert.equal(eventsOf(r2.round, "lose")[0].cause, "squash");
|
||||
// Now and then it brake-checks: back it comes, its roof in reach.
|
||||
const r4 = onPlain(11, 90);
|
||||
r4.you.v = 60;
|
||||
const rig4 = bounceRival(r4.round, "tanker", r4.at.x, r4.at.d + bounce.TANKER_AHEAD, { brakeIn: 0, v: 60, tv: 60, mode: "", hp: 4 });
|
||||
bounce.think(r4.round, rig4, 16, steady);
|
||||
assert.equal(rig4.mode, "brake");
|
||||
assert.ok(eventsOf(r4.round, "brake").some((e) => e.kind === "tanker"));
|
||||
bounce.think(r4.round, rig4, 16, steady);
|
||||
assert.ok(rig4.tv < r4.you.v - 20, "slower than you, so a jump can reach it");
|
||||
assert.equal(r4.round.lobs.length, 0, "and nothing thrown while it brakes");
|
||||
for (let ms = 0; ms <= bounce.TANKER_BRAKE_MS + 32; ms += 16) bounce.think(r4.round, rig4, 16, steady);
|
||||
assert.equal(rig4.mode, "", "then off it goes again");
|
||||
// Every third thing it drops is oil.
|
||||
const r3 = onPlain(11, 90);
|
||||
const rig3 = bounceRival(r3.round, "tanker", r3.at.x, r3.at.d + bounce.TANKER_AHEAD, { dropIn: 0, drops: 2, v: 40, tv: 40, mode: "", hp: 4 });
|
||||
bounce.think(r3.round, rig3, 16, steady);
|
||||
assert.ok(r3.round.spills.length === 1 && r3.round.spills[0].foe, "an oil spill behind it");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: the Robo-Vac sweeps from edge to edge, warns, then charges back down the road: its nose is a crash, its top a stomp, and it goes back up the road through you", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const vac = bounceRival(round, "vac", at.x, at.d + bounce.VAC_AHEAD, { mode: "sweep", hopIn: 0, v: 40, tv: 40, hp: 4 });
|
||||
bounce.think(round, vac, 16, steady);
|
||||
assert.equal(vac.mode, "warn");
|
||||
assert.ok(eventsOf(round, "bossWarn").some((e) => e.kind === "vac"));
|
||||
for (let ms = 0; ms <= bounce.VAC_WARN_MS + 16; ms += 16) bounce.think(round, vac, 16, steady);
|
||||
assert.equal(vac.mode, "charge");
|
||||
assert.equal(eventsOf(round, "bossCharge").length, 1);
|
||||
assert.ok(vac.tv < you.v - 20, "coming back at you");
|
||||
// Its nose.
|
||||
Object.assign(vac, { x: you.x, d: you.d + (you.l + vac.l) / 2 - 0.2, v: vac.tv });
|
||||
assert.equal(bounce.collide(round, you, vac), "end");
|
||||
assert.equal(round.phase, "crash");
|
||||
// Its top.
|
||||
const r2 = onPlain(11, 90);
|
||||
const vac2 = bounceRival(r2.round, "vac", r2.at.x, r2.at.d + 20, { mode: "charge", hp: 4 });
|
||||
landOn(r2.round, vac2);
|
||||
assert.equal(vac2.hp, 3, "a stomp");
|
||||
bounce.think(r2.round, vac2, 16, steady);
|
||||
assert.equal(vac2.mode, "back");
|
||||
// On its way back up the road it passes through you.
|
||||
r2.you.air = 0;
|
||||
Object.assign(vac2, { x: r2.you.x, d: r2.you.d - 2, stunMs: 0 });
|
||||
bounce.think(r2.round, vac2, 16, steady);
|
||||
assert.ok(vac2.thru, "through anything");
|
||||
r2.round.events.length = 0;
|
||||
bounce.advance(r2.round, 16, steady);
|
||||
assert.equal(eventsOf(r2.round, "bump").length, 0);
|
||||
assert.equal(r2.round.phase, "drive");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: the Whirlybird flies out of reach and bombs where you are heading, then swoops down to the road where a landing is a stomp", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const bird = bounceRival(round, "chopper", at.x, at.d + bounce.CHOPPER_AHEAD, { mode: "high", lift: 1, high: true, dropIn: 0, hopIn: 1e9, v: 40, tv: 40, hp: 4 });
|
||||
bounce.think(round, bird, 16, steady);
|
||||
assert.equal(round.lobs.length, 1);
|
||||
assert.ok(round.lobs[0].boom > 0 && round.lobs[0].what === "bomb", "a bomb on its way");
|
||||
round.lobs.length = 0;
|
||||
bird.dropIn = 1e9;
|
||||
landOn(round, bird);
|
||||
assert.equal(bird.hp, 4, "out of reach up high");
|
||||
assert.equal(round.phase, "drive");
|
||||
you.air = 0;
|
||||
Object.assign(bird, { x: you.x, d: you.d });
|
||||
bounce.advance(round, 16, steady);
|
||||
assert.equal(eventsOf(round, "bump").length, 0, "nothing to bump up there");
|
||||
bird.d = you.d + bounce.CHOPPER_AHEAD;
|
||||
bird.hopIn = 0;
|
||||
bounce.think(round, bird, 16, steady);
|
||||
assert.equal(bird.mode, "low");
|
||||
assert.ok(eventsOf(round, "bossWarn").some((e) => e.kind === "chopper"));
|
||||
for (let ms = 0; ms < 600; ms += 16) bounce.think(round, bird, 16, steady);
|
||||
assert.ok(bird.lift === 0 && !bird.high, "down on the road");
|
||||
assert.ok(bird.tv < you.v, "drifting back to you, so a jump can reach it");
|
||||
landOn(round, bird);
|
||||
assert.equal(bird.hp, 3, "a stomp");
|
||||
bounce.think(round, bird, 16, steady);
|
||||
assert.equal(bird.mode, "high", "and up it goes");
|
||||
// A bomb landing on you.
|
||||
const r2 = onPlain(11, 90);
|
||||
r2.round.lobs.push({ x: r2.you.x + 2, d: r2.you.d + 2, at: r2.round.clock + 8, what: "bomb", boom: bounce.LOB_R, w: 4, l: 4, fx: 0, fd: 0 });
|
||||
bounce.advance(r2.round, 16, steady);
|
||||
assert.equal(eventsOf(r2.round, "lose")[0].cause, "blast");
|
||||
assert.equal(r2.round.drops.length, 0, "nothing left lying");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: the Cat's paw slams down with a quake, then sweeps across the road, there to be jumped on", () => {
|
||||
const { round, you, at } = onPlain(11, 90);
|
||||
const cat = bounceRival(round, "cat", at.x - 8, at.d + 24, { mode: "stalk", hopIn: 0, v: 40, tv: 40, hp: 6 });
|
||||
bounce.think(round, cat, 16, steady);
|
||||
assert.ok(cat.air > 0, "up it goes");
|
||||
assert.equal(eventsOf(round, "bossHop").length, 1);
|
||||
for (let ms = 0; ms < 1400 && cat.mode !== "swipe"; ms += 4) {
|
||||
bounce.think(round, cat, 4, steady);
|
||||
bounce.move(round, cat, 4);
|
||||
}
|
||||
assert.equal(cat.mode, "swipe", "then it sweeps");
|
||||
assert.equal(eventsOf(round, "quake").length, 1);
|
||||
assert.equal(eventsOf(round, "swipe").length, 1);
|
||||
const x0 = cat.x;
|
||||
for (let ms = 0; ms < 600; ms += 4) {
|
||||
bounce.think(round, cat, 4, steady);
|
||||
bounce.move(round, cat, 4);
|
||||
}
|
||||
assert.ok(Math.abs(cat.x - x0) > 8, `across the road (${(cat.x - x0).toFixed(1)})`);
|
||||
for (let ms = 0; ms < bounce.CAT_SWIPE_MS; ms += 16) bounce.think(round, cat, 16, steady);
|
||||
assert.equal(cat.mode, "stalk", "and back to stalking");
|
||||
you.air = 0;
|
||||
cat.air = 0;
|
||||
landOn(round, cat);
|
||||
assert.equal(cat.hp, 5, "a stomp");
|
||||
});
|
||||
|
||||
/* ------------------------------------------- the double tap, the music */
|
||||
|
||||
test("Bounce Road arcade game: the first press of space jumps at once; a second within DOUBLE_TAP_MS sets off the gadget held, a slower one or a key repeat never does", () => {
|
||||
const g = game.create({ canvas: stubCanvas() });
|
||||
g.resize(900, 900);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
const round = g.round;
|
||||
round.cars.length = 1;
|
||||
round.spawnMs = 1e12;
|
||||
round.supplyMs = 1e12;
|
||||
const you = round.cars[0];
|
||||
const at = plainSpot(round.road, 80, 60);
|
||||
Object.assign(you, { x: at.x, d: at.d, v: 40 });
|
||||
const settle = () => {
|
||||
for (let ms = 0; ms < 1200; ms += 16) {
|
||||
Object.assign(you, { x: at.x, d: at.d, v: 40 });
|
||||
g.tick(16);
|
||||
}
|
||||
you.air = 0;
|
||||
};
|
||||
bounce.applyPower(round, "rocket");
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.ok(you.air > 0, "the first press jumps, with no wait");
|
||||
assert.equal(round.stats.fired, 0);
|
||||
g.tick(64);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1, "the second fires");
|
||||
assert.equal(you.held.uses, 2);
|
||||
// A third press right after is a first press again.
|
||||
g.tick(64);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1);
|
||||
settle();
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
g.tick(bounce.DOUBLE_TAP_MS + 40);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1, "too slow to be a double tap");
|
||||
settle();
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
g.key("action", true);
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1, "a held key's repeat never fires");
|
||||
settle();
|
||||
you.held = null;
|
||||
g.key("action");
|
||||
g.tick(32);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1, "nothing held, nothing to fire");
|
||||
assert.equal(round.input.fire, false);
|
||||
bounce.applyPower(round, "oil");
|
||||
settle();
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
g.pause();
|
||||
g.resume();
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
assert.equal(round.stats.fired, 1, "a pause forgets the first press");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade game: a run shuffles its stages; the music deals every track, never opening on the last one, and the game asks for one each tick, hotter in a Fever", () => {
|
||||
assert.equal(bounce.MUSIC_TRACKS.length, 20);
|
||||
for (let k = 0; k < 40; k++) {
|
||||
const last = bounce.MUSIC_TRACKS[k % 20];
|
||||
const deck = bounce.dealMusic(Math.random, last);
|
||||
assert.deepEqual([...deck].sort(), [...bounce.MUSIC_TRACKS].sort());
|
||||
assert.notEqual(deck[0], last);
|
||||
}
|
||||
const asked = [];
|
||||
const heats = [];
|
||||
const g = game.create({ canvas: stubCanvas(), music: (name, level, opts) => { asked.push([name, opts]); heats.push(level); return "playing"; } });
|
||||
g.resize(900, 900);
|
||||
g.key("action");
|
||||
assert.equal(g.round.road.shuffle, true, "a real round shuffles");
|
||||
g.tick(16);
|
||||
g.tick(16);
|
||||
assert.equal(asked.length, 2);
|
||||
assert.ok(bounce.MUSIC_TRACKS.includes(asked[0][0]));
|
||||
assert.deepEqual(asked[0][1], { restart: true }, "from the top");
|
||||
assert.equal(asked[1][1], undefined);
|
||||
assert.deepEqual(heats, [bounce.MUSIC_HEAT.road, bounce.MUSIC_HEAT.road], "the open road's heat");
|
||||
g.round.feverMs = 5000;
|
||||
g.tick(16);
|
||||
assert.equal(heats.at(-1), bounce.MUSIC_HEAT.fever, "a Fever plays it at full heat");
|
||||
assert.ok(bounce.MUSIC_HEAT.road < bounce.MUSIC_HEAT.boss && bounce.MUSIC_HEAT.boss < bounce.MUSIC_HEAT.fever);
|
||||
const ended = [];
|
||||
const g2 = game.create({ canvas: stubCanvas(), music: (name) => { ended.push(name); return "ended"; } });
|
||||
g2.resize(900, 900);
|
||||
g2.key("action");
|
||||
for (let k = 0; k < 30; k++) g2.tick(16);
|
||||
assert.deepEqual([...new Set(ended.slice(0, 20))].sort(), [...bounce.MUSIC_TRACKS].sort(), "every track once, in a random order");
|
||||
assert.notEqual(ended[20], ended[19], "a new deal never opens on the track that just ended");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade music: twenty synthesized tracks, each fast, a whole tune in whole bars, with an echo for a boss and a harmony for a Fever", () => {
|
||||
assert.deepEqual(Object.keys(BOUNCE_MUSIC).sort(), [...bounce.MUSIC_TRACKS].sort(), "the game lists the tracks its music file has");
|
||||
assert.equal(SCORES.length, 20);
|
||||
assert.equal(new Set(SCORES.map((s) => s.title)).size, 20, "twenty titles");
|
||||
assert.equal(new Set(SCORES.map((s) => s.A.lead + s.B.lead)).size, 20, "twenty tunes");
|
||||
const stepsOf = (line) => line.split(/\s+/).filter((t) => t !== "|").length;
|
||||
SCORES.forEach((score, k) => {
|
||||
const track = BOUNCE_MUSIC[`bounceSong${k + 1}`];
|
||||
assert.ok(track.bpm >= 140 && track.bpm <= 180, `${score.title} is fast`);
|
||||
assert.ok(track.rush > 0, "and faster as play heats up");
|
||||
for (const part of [score.A, score.B]) {
|
||||
const bars = part.lead.split(/\s+/);
|
||||
assert.equal(bars.length, 8, `${score.title}: eight bars a tune`);
|
||||
for (const bar of bars) assert.match(bar, /^[A-Ga-g1-7.\-]{16}$/, `${score.title}: a bar is sixteen steps`);
|
||||
}
|
||||
for (const [id, pattern] of Object.entries(track.patterns)) {
|
||||
for (const [voice, line] of Object.entries(pattern)) {
|
||||
assert.ok(track.voices[voice], `${score.title} ${id}: ${voice} is a voice`);
|
||||
assert.equal(stepsOf(line) % 16, 0, `${score.title} ${id}.${voice} runs whole bars`);
|
||||
}
|
||||
}
|
||||
const steps = track.order.reduce((n, id) => n + stepsOf(track.patterns[id].drums), 0);
|
||||
const seconds = (steps / 4) * (60 / track.bpm);
|
||||
assert.ok(seconds > 60 && seconds < 100, `${score.title} runs a minute or so (${Math.round(seconds)} s)`);
|
||||
const { road, boss, fever } = bounce.MUSIC_HEAT;
|
||||
for (const v of ["bass", "lead", "arp", "drums"]) assert.ok((track.voices[v].from ?? 0) <= road, `${v} plays on the open road`);
|
||||
assert.ok(track.voices.echo.from > road && track.voices.echo.from <= boss, "the echo joins for a boss");
|
||||
assert.ok(track.voices.harmony.from > boss && track.voices.harmony.from <= fever, "the harmony joins in a Fever");
|
||||
});
|
||||
});
|
||||
|
||||
/* ----------------------------------- the boss hold, the stunt pieces */
|
||||
|
||||
test("Bounce Road arcade: a boss stage lasts until its boss is beaten: more of it is laid ahead while the boss lives, and its line comes once it is flattened", () => {
|
||||
const round = bounceRound(4);
|
||||
round.infinite = true;
|
||||
const road = round.road;
|
||||
const you = round.cars[0];
|
||||
const drive = (ms, until = () => false) => {
|
||||
for (let t = 0; t < ms && !until(); t += 16) {
|
||||
const i = bounce.rowIn(road, you.d + 6);
|
||||
Object.assign(you, { x: (road.L[i] + road.R[i]) / 2, v: 50, ghostMs: 1000 });
|
||||
if (bounce.groundAt(road, you.x, you.d + 4, round.clock) !== bounce.GROUND.road) Object.assign(you, { air: 200, airMax: 400 });
|
||||
bounce.advance(round, 16, steady);
|
||||
}
|
||||
};
|
||||
bounce.buildStage(road, 2);
|
||||
bounce.buildStage(road, 3);
|
||||
you.d = road.stageAt[2] - 1;
|
||||
drive(200);
|
||||
assert.equal(round.stage, 3);
|
||||
drive(20000, () => round.cars.some((c) => bounce.isBoss(c)));
|
||||
const boss = round.cars.find((c) => bounce.isBoss(c));
|
||||
assert.ok(boss, "its boss comes");
|
||||
const line = road.stageAt[3];
|
||||
drive(60000);
|
||||
assert.equal(round.stage, 3, "still on the boss stage a minute on");
|
||||
assert.ok(road.stageAt[3] > line + 1000, "its line moved on with the road");
|
||||
assert.equal(road.built, 3, "and nothing past it is built");
|
||||
assert.ok(road.stageAt[3] - you.d > bounce.FIELD_H, "the line never comes into view");
|
||||
assert.equal(eventsOf(round, "escape").length, 0, "it does not get away");
|
||||
boss.hp = 1;
|
||||
bounce.hurtBoss(round, boss, "rocket");
|
||||
const end = road.stageAt[3];
|
||||
drive(30000, () => round.stage === 4);
|
||||
assert.equal(round.stage, 4, "beaten, the line comes");
|
||||
assert.equal(road.stageAt[3], end, "where the road then ended");
|
||||
assert.equal(eventsOf(round, "stage").at(-1).rank !== "C", true, "and the boss counts toward the rank");
|
||||
});
|
||||
|
||||
test("Bounce Road arcade: a kicker flies you KICKER_AIR the usual jump over its whole chicane, a wall right across the road can only be jumped, a trampoline is three bounces, and a turbo lane is one boost after another", () => {
|
||||
const round = bounceRound(9);
|
||||
const kicker = onto(round, "pads", (p) => p.kind === "kicker", 8);
|
||||
const you = round.cars[0];
|
||||
you.v = 55;
|
||||
for (let ms = 0; ms < 400 && you.air <= 0; ms += 4) bounce.advance(round, 4, steady);
|
||||
assert.ok(you.air > 0 && Math.abs(you.airMax - bounce.airMs(you.v) * bounce.KICKER_AIR) < 40, "a long flight");
|
||||
assert.ok(bounce.KICKER_AIR > bounce.RAMP_AIR);
|
||||
const walls = round.road.blocks.filter((b) => b.d > kicker.d && b.d < kicker.d + 110);
|
||||
assert.equal(walls.length, 3, "a chicane under it");
|
||||
for (let ms = 0; ms < 3000 && you.air > 0; ms += 4) bounce.advance(round, 4, steady);
|
||||
assert.equal(round.phase, "drive", "down on clear road");
|
||||
assert.ok(you.d > walls.at(-1).d, "past every barrier");
|
||||
assert.ok(eventsOf(round, "land").at(-1).big, "for big air");
|
||||
const r2 = bounceRound(9);
|
||||
const wall = onto(r2, "blocks", (b) => b.wall, 12);
|
||||
const i = bounce.rowOf(wall.d);
|
||||
assert.ok(wall.w > r2.road.R[i] - r2.road.L[i] - 2, "right across the road");
|
||||
for (let ms = 0; ms < 800 && r2.phase === "drive"; ms += 4) bounce.advance(r2, 4, steady);
|
||||
assert.equal(r2.phase, "crash", "no way round");
|
||||
const r3 = bounceRound(9);
|
||||
onto(r3, "blocks", (b) => b.wall, 6);
|
||||
r3.input.jump = bounce.JUMP_BUFFER_MS;
|
||||
for (let ms = 0; ms < 1500; ms += 4) bounce.advance(r3, 4, steady);
|
||||
assert.equal(r3.phase, "drive", "only over");
|
||||
assert.ok(eventsOf(r3, "land").some((e) => e.overs.includes("block")));
|
||||
const road = bounce.newRoad(9);
|
||||
bounce.ensureRoad(road, 60000);
|
||||
const wide = road.pads.filter((p) => p.kind === "pop" && p.w > 20);
|
||||
assert.ok(wide.length >= 3 && wide[1].d - wide[0].d < 70, "trampolines come in a row");
|
||||
const strips = road.pads.filter((p) => p.kind === "boost");
|
||||
const lane = strips.find((p, k) => strips[k + 3] && strips[k + 3].d - p.d < 80 && strips[k + 3].x === p.x);
|
||||
assert.ok(lane, "a turbo lane");
|
||||
const j = bounce.rowOf(lane.d + 20);
|
||||
assert.ok(Math.abs(road.R[j] - road.L[j] - bounce.TURBO_W) < 0.01, "and narrow");
|
||||
for (const s of bounce.STAGES) for (const k of Object.keys(bounce.WILD)) assert.ok(s.weights[k] > 0, `${s.title} lays a ${k}`);
|
||||
});
|
||||
|
||||
test("Bounce Road arcade game: a power-up taken flashes its name near the top of the field for TOAST_MS, at once, whatever banner is showing", () => {
|
||||
const texts = [];
|
||||
const ctx = new Proxy({}, {
|
||||
get: (target, name) => (name === "fillText" ? (text, x, y) => texts.push([String(text), y]) : name in target ? target[name] : () => {}),
|
||||
set: (target, name, value) => { target[name] = value; return true; },
|
||||
});
|
||||
const g = game.create({ canvas: { width: 0, height: 0, getContext: () => ctx } });
|
||||
g.resize(900, 900);
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
g.round.cars.length = 1;
|
||||
g.round.spawnMs = 1e12;
|
||||
const you = g.round.cars[0];
|
||||
g.round.events.push({ type: "power", kind: "rocket", x: you.x, d: you.d });
|
||||
texts.length = 0;
|
||||
g.tick(16);
|
||||
g.tick(16);
|
||||
const flash = texts.filter(([t]) => t === "ROCKETS");
|
||||
assert.ok(flash.length > 0, "its name, while the stage's banner is still up");
|
||||
assert.ok(flash.every(([, y]) => y < bounce.FIELD_H * 0.2), `near the top of the field (${flash[0][1]})`);
|
||||
for (let ms = 0; ms < bounce.TOAST_MS + 50; ms += 16) g.tick(16);
|
||||
texts.length = 0;
|
||||
g.tick(16);
|
||||
assert.equal(texts.filter(([t]) => t === "ROCKETS").length, 0, "and gone");
|
||||
});
|
||||
@@ -247,6 +247,21 @@ test("Bounce Road: every pill's text reads at 4.5:1 on its backing and its timer
|
||||
});
|
||||
});
|
||||
|
||||
test("Bounce Road: the gadget held, a Magnet and a Fever each show as a pill that reads, every gadget in its own color", () => {
|
||||
for (const kind of bounce.GADGETS) {
|
||||
checkPills({
|
||||
setup: (r) => {
|
||||
const you = r.cars[0];
|
||||
bounce.applyPower(r, kind);
|
||||
you.magnetMs = bounce.MAGNET_MS / 2;
|
||||
r.feverMs = bounce.FEVER_MS / 2;
|
||||
r.fever = bounce.FEVER_FULL;
|
||||
},
|
||||
expect: [`TAP x2: ${bounce.POWERS[kind].tag}`, "~MAGNET", "~FEVER x2"],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("Bounce Road game: held arrows drive and steer until let go; space jumps once a press, never on its key repeat, never with the press that plays on; a pause lets go of every key, drops an early press and holds a jump mid-air; and the board refuses a tiny window", () => {
|
||||
const { canvas } = stubCanvas();
|
||||
const t = game.create({ canvas });
|
||||
@@ -279,7 +294,7 @@ test("Bounce Road game: held arrows drive and steer until let go; space jumps on
|
||||
g.key("left");
|
||||
g.key("action");
|
||||
g.pause();
|
||||
assert.deepEqual(Object.values(g.round.input), [false, false, false, false, 0], "a pause holds nothing, the early press dropped");
|
||||
assert.deepEqual(Object.values(g.round.input), [false, false, false, false, 0, false], "a pause holds nothing, the early press dropped");
|
||||
g.key("action");
|
||||
assert.equal(g.state, "paused", "space never plays on by itself: the window resumes through resume()");
|
||||
g.resume();
|
||||
@@ -316,7 +331,8 @@ test("Bounce Road game: the start screen names the furthest stage, the memo only
|
||||
const scores = [];
|
||||
const g = game.create({ canvas: { width: 0, height: 0, getContext: () => ctx }, memo, onScore: (n) => scores.push(n) });
|
||||
g.resize(900, 900);
|
||||
assert.ok(texts.some(([t]) => t.includes(`Furthest: ${bounce.STAGES[2].title} (stage 3)`)), "the start screen names the furthest stage");
|
||||
assert.ok(texts.some(([t]) => t.includes("Furthest: stage 3")), "the start screen names the furthest stage");
|
||||
assert.ok(texts.some(([t]) => t.includes("double-tap space")), "and how to set off a gadget");
|
||||
g.key("action");
|
||||
g.tick(16);
|
||||
g.round.cars.length = 1;
|
||||
@@ -347,7 +363,7 @@ test("Bounce Road game: the start screen names the furthest stage, the memo only
|
||||
texts.length = 0;
|
||||
g.resize(900, 900);
|
||||
assert.ok(texts.some(([t, f]) => t === String(g.score) && /\b7px/.test(f)), "the score, big");
|
||||
assert.ok(texts.some(([t]) => t.includes(`Reached ${bounce.STAGES[3].title} (stage 4). New furthest!`)));
|
||||
assert.ok(texts.some(([t]) => t.includes(`Reached ${bounce.stageName(4, g.round.road)}. New furthest!`)));
|
||||
g.tick(1000);
|
||||
assert.equal(scores.length, 1, "once");
|
||||
});
|
||||
@@ -384,7 +400,7 @@ test("Bounce Road game: a jump springs, a crush squashes higher up the chain, pa
|
||||
g.tick(16);
|
||||
g.tick(16);
|
||||
assert.equal(tones.filter(([n]) => n === "best").length, 1);
|
||||
for (let n = 1; n <= 12; n++) {
|
||||
for (let n = 1; n <= 31; n++) {
|
||||
while (g.round.road.built < n + 1) bounce.buildStage(g.round.road, g.round.road.built + 1);
|
||||
g.round.stage = n;
|
||||
you.d = g.round.road.stageAt[n - 1] + 400;
|
||||
@@ -412,6 +428,16 @@ test("Bounce Road game: every event plays a tone that tones.js has (its blips, i
|
||||
{ type: "spawn", id: 5, kind: "monster", ...at }, { type: "power", kind: "mega", ...at }, { type: "crush", ...at, kind: "cop", id: 3, chain: 2, points: 500 },
|
||||
{ type: "copGone", id: 3, ...at }, { type: "bubble", ...at, cause: "crash" }, { type: "bump", a: 0, b: 3, ...at, speed: 30, kind: "zigzag" },
|
||||
{ type: "bumped", ...at, id: 3, kind: "zigzag", how: "splash", points: 50 }, { type: "haul", ...at, kind: "truck", id: 3, chain: 1, points: 50 },
|
||||
// The arcade layer: the newer things on the road, the gadgets, the Fever, the rivals' tricks and the bosses.
|
||||
{ type: "pop", id: 0, ...at, v: 50 }, { type: "belt", ...at, dir: 1 }, { type: "bumper", ...at, points: 20 }, { type: "laserWarn", ...at }, { type: "stompWarn", ...at, what: "book" },
|
||||
{ type: "stompLand", ...at, what: "book" }, ...bounce.GADGETS.map((kind) => ({ type: "use", kind, ...at, left: 1 })), { type: "pound", ...at, hit: 2 }, { type: "zap", ...at, hit: 2 },
|
||||
{ type: "fever", ...at }, { type: "feverEnd" }, { type: "life", ...at }, { type: "blast", ...at, kind: "brick", id: 3, points: 100 }, { type: "boom", ...at, r: 8, what: "bomb", near: true },
|
||||
{ type: "lob", id: 3, what: "barrel", ...at }, { type: "aim", id: 3, ...at }, { type: "bolt", id: 3, ...at }, { type: "shot", ...at, tough: false }, { type: "shot", ...at, tough: true },
|
||||
{ type: "blade", id: 3, ...at }, { type: "bomb", id: 3, ...at }, { type: "phase", id: 3, ...at, on: true }, { type: "phase", id: 3, ...at, on: false }, { type: "magnet", id: 3, ...at },
|
||||
{ type: "spin", id: 3, kind: "brick", ...at }, { type: "split", ...at }, { type: "spiked", id: 3, ...at }, { type: "meet", kind: "spike", ...at }, { type: "bossWarn", id: 3, kind: "vac", ...at },
|
||||
{ type: "bossWarn", id: 3, kind: "chopper", ...at }, { type: "bossCharge", id: 3, ...at }, { type: "swipe", id: 3, ...at }, { type: "power", kind: "rocket", ...at }, { type: "power", kind: "heart", ...at },
|
||||
...["tanker", "vac", "chopper", "cat", "supply"].map((kind, k) => ({ type: "spawn", id: 6 + k, kind, ...at })), { type: "stomp", ...at, id: 3, kind: "cat", hp: 2, chain: 1, points: 150, how: "rocket" },
|
||||
{ type: "boss", ...at, kind: "vac", points: 2000, life: false }, { type: "escape", ...at, kind: "tanker" }, { type: "lose", cause: "laser", ...at, lives: 2 },
|
||||
];
|
||||
for (const e of events) {
|
||||
tones.length = 0;
|
||||
@@ -456,7 +482,9 @@ test("Bounce Road game: Planny keeps his star eye in your highlight driving, in
|
||||
},
|
||||
"at the end": (g, you) => {
|
||||
g.round.lives = 1;
|
||||
bounce.ensureRoad(g.round.road, 9000);
|
||||
const hole = g.round.road.holes.find((h) => h.kind === "crack");
|
||||
while (g.round.road.stageAt[g.round.stage] <= hole.d0) g.round.stage++;
|
||||
you.d = hole.d0 - 6;
|
||||
g.round.far = you.d;
|
||||
for (let ms = 0; ms < bounce.CRASH_MS + 2000 && g.state === "running"; ms += 16) g.tick(16);
|
||||
@@ -681,7 +709,12 @@ test("Bounce Road game: Night Lights is dark but for your headlights' reach", ()
|
||||
g.tick(16);
|
||||
assert.ok(!fills.includes("evenodd"), "by day, no dark");
|
||||
bounce.ensureRoad(g.round.road, 30000);
|
||||
const night = bounce.STAGES.findIndex((s) => s.id === "night") + 1;
|
||||
// The real game shuffles its stages: the first dark one on this road (Night Lights, or a Lights out twist).
|
||||
let night = 1;
|
||||
while (night < 90 && !bounce.stageFor(night, g.round.road).dark) night++;
|
||||
assert.ok(bounce.stageFor(night, g.round.road).dark, "a dark stage in the run");
|
||||
bounce.ensureRoad(g.round.road, g.round.road.stageAt.at(-1) + 1);
|
||||
while (g.round.road.built < night + 1) bounce.buildStage(g.round.road, g.round.road.built + 1);
|
||||
g.round.stage = night;
|
||||
const you = g.round.cars[0];
|
||||
you.d = g.round.road.stageAt[night - 1] + 30;
|
||||
|
||||
@@ -9,7 +9,7 @@ import "./seed-random.mjs";
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as bounce from "../src/web-console/public/activities/bounce.js";
|
||||
import { hudLayout, labelSpot, LOOKS, limbInk, contrast, inkOn } from "../src/web-console/public/activities/bounce-draw.js";
|
||||
import { CUSTOM_STYLES, hudLayout, labelSpot, LOOKS, limbInk, contrast, inkOn } from "../src/web-console/public/activities/bounce-draw.js";
|
||||
import { CAR_STYLES } from "../src/web-console/public/activities/bounce-cars.js";
|
||||
import { ACCENTS } from "../src/web-console/public/palette.js";
|
||||
|
||||
@@ -31,7 +31,9 @@ function bounceRound(seed = 7, rivals = false) {
|
||||
// A rival of `kind` put at (x, d), still and on the ground, going nowhere on
|
||||
// its own.
|
||||
function bounceRival(round, kind, x, d, over = {}) {
|
||||
const car = bounce.spawnRival(round, kind, steady, round.cars[0].d + 300);
|
||||
// A rival only spawns on plain road: try further along until one takes. It is moved anyway.
|
||||
let car = null;
|
||||
for (let at = round.cars[0].d + 300; !car && at < round.cars[0].d + 3000; at += 40) car = bounce.spawnRival(round, kind, steady, at);
|
||||
assert.ok(car, `a ${kind} spawns`);
|
||||
Object.assign(car, { x, d, v: 0, tv: 0, vx: 0, kx: 0, air: 0, tx: x, lane: x, hopIn: 1e9, dropIn: 1e9, mode: "calm", ...over });
|
||||
return car;
|
||||
@@ -101,7 +103,11 @@ function carefulBot(round) {
|
||||
let tx = (lo + hi) / 2;
|
||||
const things = [];
|
||||
for (const list of [road.blocks, round.drops]) for (const o of list) if (!o.hit && o.d - you.d > -2 && o.d - you.d < 40) things.push(o);
|
||||
for (const h of road.hazards) if (h.kind === "drop" && h.at && !h.landed && h.d - you.d > -4 && h.d - you.d < 70) things.push(h);
|
||||
for (const h of road.hazards) {
|
||||
if (h.kind === "drop" && h.at && !h.landed && h.d - you.d > -4 && h.d - you.d < 70) things.push(h);
|
||||
// A stomper on its way down, or down, is a thing to steer round.
|
||||
if (h.kind === "stomper" && h.d - you.d > -5 && h.d - you.d < 60) things.push(h);
|
||||
}
|
||||
for (const c of round.cars) if (c.id !== 0 && c.out === 0 && c.d - you.d > 0 && c.d - you.d < 24) things.push(c);
|
||||
things.sort((p, q) => p.d - q.d);
|
||||
const o = things[0];
|
||||
@@ -116,7 +122,8 @@ function carefulBot(round) {
|
||||
const soon = (d) => d > you.d && d - you.d < 3 + you.v * 0.02 + you.l / 2;
|
||||
for (let k = bounce.firstAt(road.holes, "d0", you.d); k < road.holes.length && road.holes[k].d0 < you.d + 20; k++) if (soon(road.holes[k].d0)) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
for (const h of road.hazards) {
|
||||
if (h.kind === "ball" && soon(h.d - h.r - 1)) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
if ((h.kind === "ball" || h.kind === "roller") && soon(h.d - h.r - 1)) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
if (h.kind === "laser" && soon(h.d - h.half - 1) && bounce.laserAt(h, round.clock + 150).warn) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
if (h.kind === "train" && soon(h.d - h.half - 1) && bounce.trainAt(h, round.clock + 150).warn) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
}
|
||||
for (const b of things) if (b.l && b.kind && b.id === undefined && soon(b.d - b.l / 2) && Math.abs(b.x - you.x) < (b.w + you.w) / 2) inp.jump = bounce.JUMP_BUFFER_MS;
|
||||
@@ -124,7 +131,7 @@ function carefulBot(round) {
|
||||
|
||||
// Plays `round` with `bot` until `stage` or the end, `ms` at most, a rival's
|
||||
// random seeded; returns the seconds each stage took and the lives lost.
|
||||
function play(round, bot, { stage = 11, ms = 900000, rivals = false, seed = 1 } = {}) {
|
||||
function play(round, bot, { stage = 16, ms = 900000, rivals = false, seed = 1 } = {}) {
|
||||
const random = rivals ? bounce.seeded(seed * 13) : steady;
|
||||
const secs = [];
|
||||
const lost = [];
|
||||
@@ -290,7 +297,10 @@ test("Bounce Road: a rival bumped past the road's edge is out, and yours for BUM
|
||||
test("Bounce Road: water or a hole under your wheels costs a life, flying over it does not, and a Bubble throws you clear instead", () => {
|
||||
const round = bounceRound();
|
||||
const you = round.cars[0];
|
||||
bounce.ensureRoad(round.road, 9000);
|
||||
const hole = round.road.holes.find((h) => h.kind === "crack");
|
||||
while (round.road.stageAt[round.stage] <= hole.d0) round.stage++;
|
||||
round.far = 1e9;
|
||||
Object.assign(you, { d: hole.d0 + 2, v: 40, air: 300, airMax: 600 });
|
||||
bounce.advance(round, 100, steady);
|
||||
assert.equal(round.phase, "drive", "in the air over it, nothing");
|
||||
@@ -304,6 +314,9 @@ test("Bounce Road: water or a hole under your wheels costs a life, flying over i
|
||||
assert.ok(you.d < hole.d0 - bounce.RESPAWN_BACK / 2, `back before the hole (${you.d.toFixed(0)} < ${hole.d0})`);
|
||||
assert.equal(bounce.groundAt(round.road, you.x, you.d), bounce.GROUND.road, "on the road");
|
||||
const saved = bounceRound();
|
||||
bounce.ensureRoad(saved.road, 9000);
|
||||
saved.stage = round.stage;
|
||||
saved.far = 1e9;
|
||||
const s = saved.cars[0];
|
||||
s.bubble = true;
|
||||
Object.assign(s, { d: hole.d0 + 2, v: 40 });
|
||||
@@ -342,7 +355,7 @@ test("Bounce Road: a broken span the Bubble's throw carries you over is the Bubb
|
||||
|
||||
/* ---------------------------------------------------- the road is fair */
|
||||
|
||||
test("Bounce Road: every hole of the first twenty stages, on many roads, is jumpable at JUMP_FAIR of the top speed (a drawbridge's lifted span included), with a run-up of road and a sign before it, and even the longest jump off the first of two breaks lands on the bridge between", () => {
|
||||
test("Bounce Road: every hole of the first thirty stages, on many roads, is jumpable at JUMP_FAIR of the top speed (a drawbridge's lifted span included), with a run-up of road and a sign before it, and even the longest jump off the first of two breaks lands on the bridge between", () => {
|
||||
const fair = bounce.reach(bounce.JUMP_FAIR * bounce.TOP_SPEED);
|
||||
let twins = 0;
|
||||
let draws = 0;
|
||||
@@ -350,7 +363,7 @@ test("Bounce Road: every hole of the first twenty stages, on many roads, is jump
|
||||
assert.ok(bounce.MAX_HOLE + bounce.CAR_L <= fair, "the longest hole any stage may cut is jumpable");
|
||||
for (let seed = 1; seed <= 8; seed++) {
|
||||
const road = bounce.newRoad(seed);
|
||||
while (road.built < 20) bounce.buildStage(road, road.built + 1);
|
||||
while (road.built < 30) bounce.buildStage(road, road.built + 1);
|
||||
assert.ok(road.holes.length > 30, `seed ${seed} cuts holes`);
|
||||
const solid = (from, to) => {
|
||||
for (let i = Math.floor(from / bounce.ROW); i < Math.floor(to / bounce.ROW); i++) if (!road.deck[i] || road.dynOf[i]) return false;
|
||||
@@ -377,14 +390,14 @@ test("Bounce Road: every hole of the first twenty stages, on many roads, is jump
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.ok(twins > 12, `bridges with two breaks were checked (${twins})`);
|
||||
assert.ok(draws > 8, `drawbridges were checked (${draws})`);
|
||||
assert.ok(twins > 6, `bridges with two breaks were checked (${twins})`);
|
||||
assert.ok(draws > 2, `drawbridges were checked (${draws})`);
|
||||
});
|
||||
|
||||
test("Bounce Road: with a Spring held and a Nitro burning, a jump off the first of two breaks at full speed comes down on the bridge between, never in the second break", () => {
|
||||
const round = bounceRound(1);
|
||||
const road = round.road;
|
||||
bounce.ensureRoad(road, 40000);
|
||||
bounce.ensureRoad(road, 150000);
|
||||
const riverOf = (h) => road.rivers.find((r) => r.d0 <= h.d0 && r.d1 >= h.d1);
|
||||
const k = road.holes.findIndex((h, j) => j && h.kind === "span" && road.holes[j - 1].kind === "span" && riverOf(h) === riverOf(road.holes[j - 1]));
|
||||
assert.ok(k > 0, "a bridge with two breaks");
|
||||
@@ -422,7 +435,7 @@ test("Bounce Road: a life lost puts you back with RESPAWN_RUN of plain road ahea
|
||||
|
||||
test("Bounce Road: the road's edges slant from row to row the way they are drawn, never a stair step: the ground under a car eases from one row's edge to the next", () => {
|
||||
const road = bounce.newRoad(3);
|
||||
while (road.built < 4) bounce.buildStage(road, road.built + 1);
|
||||
while (road.built < 8) bounce.buildStage(road, road.built + 1);
|
||||
let checked = 0;
|
||||
for (let i = 1; i < road.rows; i++) {
|
||||
if (road.deck[i] !== 1 || road.dynOf[i] || road.ML[i] < road.MR[i] || Math.abs(road.L[i] - road.L[i - 1]) < 1) continue;
|
||||
@@ -465,29 +478,73 @@ test("Bounce Road: the rivals' list is kept in place from slice to slice, with t
|
||||
assert.equal(cars[0].id, 0, "you first");
|
||||
});
|
||||
|
||||
test("Bounce Road: the same seed builds the same road, a different one another, every stage keeps the road on the field and a flowerbed with room either side, and past the tenth the road goes round again, quicker and meaner", () => {
|
||||
test("Bounce Road: the same seed builds the same road, a different one another, every stage keeps the road on the field and a flowerbed with room either side, and past the fifteenth the run laps, quicker and meaner", () => {
|
||||
const a = bounce.newRoad(42);
|
||||
const b = bounce.newRoad(42);
|
||||
const c = bounce.newRoad(43);
|
||||
for (const r of [a, b, c]) while (r.built < 12) bounce.buildStage(r, r.built + 1);
|
||||
for (const r of [a, b, c]) while (r.built < 16) bounce.buildStage(r, r.built + 1);
|
||||
assert.deepEqual([a.L, a.R, a.ML, a.deck, a.under, a.dynOf, a.stageAt, a.hazards.map((h) => h.kind)], [b.L, b.R, b.ML, b.deck, b.under, b.dynOf, b.stageAt, b.hazards.map((h) => h.kind)]);
|
||||
assert.notDeepEqual(a.L, c.L);
|
||||
for (let i = 0; i < a.rows; i++) {
|
||||
assert.ok(a.L[i] >= 1 && a.R[i] <= bounce.FIELD_W - 1, `row ${i} on the field`);
|
||||
if (a.ML[i] < a.MR[i]) assert.ok(a.ML[i] - a.L[i] >= 15 && a.R[i] - a.MR[i] >= 15, `row ${i}: room round the flowerbed`);
|
||||
}
|
||||
assert.equal(bounce.STAGES.length, 10, "ten stages");
|
||||
assert.equal(new Set(bounce.STAGES.map((s) => s.id)).size, 10, "each with its own look");
|
||||
for (const s of bounce.STAGES) assert.ok(LOOKS[s.id], `${s.id} has a look`);
|
||||
for (let n = 1; n <= 10; n++) {
|
||||
assert.equal(bounce.STAGES.length, bounce.CYCLE, "fifteen stages a lap");
|
||||
assert.equal(new Set(bounce.STAGES.map((s) => s.id)).size, bounce.CYCLE, "each with its own look");
|
||||
for (const t of Object.values(bounce.THEMES)) assert.ok(LOOKS[t.id], `${t.id} has a look`);
|
||||
for (let n = 1; n <= bounce.CYCLE; n++) {
|
||||
const len = a.stageAt[n] - a.stageAt[n - 1];
|
||||
assert.ok(len >= bounce.STAGES[n - 1].len && len < bounce.STAGES[n - 1].len + 350, `stage ${n} is ${len} long`);
|
||||
assert.equal(Boolean(bounce.STAGES[n - 1].boss), n % bounce.WORLD === 0, `stage ${n}: a boss on every third stage only`);
|
||||
}
|
||||
assert.equal(bounce.stageFor(11), bounce.stageFor(11), "built once");
|
||||
assert.equal(bounce.stageFor(11).name, `${bounce.STAGES[bounce.LAP_FROM - 1].title} 2`);
|
||||
assert.equal(bounce.stageFor(18).name, "Monster Mash 2");
|
||||
assert.ok(bounce.stageFor(18).boss, "the Monster is back each lap");
|
||||
assert.ok(bounce.stageFor(11).pace > bounce.stageFor(bounce.LAP_FROM).pace && bounce.stageFor(40).rivals <= bounce.MAX_RIVALS && bounce.stageFor(40).crack[1] <= bounce.MAX_HOLE);
|
||||
assert.deepEqual(bounce.STAGES.filter((s) => s.boss).map((s) => s.boss), [...bounce.BOSS_ORDER], "the five bosses, each in its arena");
|
||||
assert.ok(bounce.STAGES[0].len < bounce.STAGES[13].len && bounce.STAGES[13].len < 1700, "short stages, longer as the run goes on");
|
||||
assert.equal(bounce.stageFor(16), bounce.stageFor(16), "built once");
|
||||
assert.equal(bounce.stageFor(16).lap, 2);
|
||||
assert.equal(bounce.stageFor(16).name, `${bounce.THEMES[bounce.stageFor(16).id].title} 2`);
|
||||
assert.equal(bounce.stageFor(27).name, "Monster Mash 2");
|
||||
assert.equal(bounce.stageFor(27).boss, "monster", "the bosses are back each lap");
|
||||
assert.ok(bounce.stageFor(16).pace > bounce.stageFor(1).pace && bounce.stageFor(60).rivals <= bounce.MAX_RIVALS && bounce.stageFor(60).crack[1] <= bounce.MAX_HOLE);
|
||||
});
|
||||
|
||||
test("Bounce Road: a shuffled run deals its stages afresh from the seed: Chalk Lane first, a boss arena on every third stage, every boss once a lap with the Cat last on the first, twists on plain stages only, and the same seed the same run", () => {
|
||||
const plans = new Set();
|
||||
let twists = 0;
|
||||
for (let seed = 1; seed <= 12; seed++) {
|
||||
const road = bounce.newRoad(seed, true);
|
||||
const again = bounce.newRoad(seed, true);
|
||||
const ids = [];
|
||||
const bosses = [];
|
||||
for (let n = 1; n <= 30; n++) {
|
||||
const spec = bounce.stageFor(n, road);
|
||||
assert.equal(spec, bounce.stageFor(n, road), "built once a road");
|
||||
assert.equal(spec.id, bounce.stageFor(n, again).id, `seed ${seed}: stage ${n} is the same on the same seed`);
|
||||
assert.equal(Boolean(spec.boss), n % bounce.WORLD === 0, `seed ${seed}: stage ${n}`);
|
||||
if (spec.boss) {
|
||||
bosses.push(spec.boss);
|
||||
assert.equal(spec.id, bounce.ARENAS[spec.boss], "a boss in its own arena");
|
||||
assert.equal(spec.twist, null, "no twist on a boss stage");
|
||||
} else if (spec.twist) {
|
||||
twists++;
|
||||
assert.ok(bounce.TWISTS[spec.twist], `a known twist (${spec.twist})`);
|
||||
}
|
||||
if (n <= bounce.CYCLE) ids.push(spec.id);
|
||||
}
|
||||
assert.equal(ids[0], "chalk", "Chalk Lane opens every run");
|
||||
assert.equal(bounce.stageFor(1, road).twist, null, "and with no twist");
|
||||
assert.equal(new Set(ids).size, bounce.CYCLE, `seed ${seed}: no theme twice in a lap`);
|
||||
assert.deepEqual([...bosses.slice(0, 5)].sort(), [...bounce.BOSS_ORDER].sort(), "every boss once in the first lap");
|
||||
assert.equal(bosses[4], "cat", "the Cat last");
|
||||
assert.deepEqual([...bosses.slice(5, 10)].sort(), [...bounce.BOSS_ORDER].sort(), "and once in the second");
|
||||
plans.add(ids.join(" "));
|
||||
}
|
||||
assert.ok(plans.size >= 10, `runs differ (${plans.size} of 12)`);
|
||||
assert.ok(twists > 20, `twists turn up (${twists})`);
|
||||
const rush = bounce.stageSpec(5, "beds", "rush");
|
||||
assert.equal(rush.rivals, bounce.stageSpec(5, "beds").rivals + 2, "Rush hour packs the road");
|
||||
assert.ok(bounce.stageSpec(5, "beds", "dark").dark && bounce.stageSpec(5, "beds", "rain").ice && bounce.stageSpec(5, "beds", "gold").stars === 1);
|
||||
assert.equal(bounce.newRound(5, steady).road.shuffle, false, "a round asks for the shuffle");
|
||||
assert.equal(bounce.newRound(5, steady, true).road.shuffle, true);
|
||||
});
|
||||
|
||||
test("Bounce Road: each stage brings something new: its own pieces, hazards or rivals, and later stages bring more at once", () => {
|
||||
@@ -496,31 +553,32 @@ test("Bounce Road: each stage brings something new: its own pieces, hazards or r
|
||||
for (const s of bounce.STAGES) {
|
||||
const things = [...Object.keys(s.weights).filter((k) => k !== "straight" && s.weights[k] > 0), ...s.kinds];
|
||||
const fresh = things.filter((t) => !seen.has(t));
|
||||
if (s.n !== 1) assert.ok(fresh.length > 0 || s.boss || s.id === "night", `${s.title} brings something new (Night Lights brings the dark)`);
|
||||
if (s.n !== 1) assert.ok(fresh.length > 0 || s.boss || s.dark, `${s.title} brings something new (Night Lights brings the dark)`);
|
||||
for (const t of things) seen.add(t);
|
||||
assert.ok(things.length >= before - 7, `${s.title} keeps up the mix (${things.length})`);
|
||||
assert.ok(things.length >= before - 7 || s.boss, `${s.title} keeps up the mix (${things.length})`);
|
||||
before = Math.max(before, things.length);
|
||||
}
|
||||
for (const t of Object.values(bounce.THEMES)) for (const k of Object.keys(t.weights)) seen.add(k);
|
||||
for (const piece of bounce.PIECE_NAMES) if (piece !== "straight") assert.ok(seen.has(piece), `the ${piece} turns up`);
|
||||
for (const kind of bounce.RIVAL_KINDS) if (kind !== "monster") assert.ok(seen.has(kind), `the ${kind} turns up`);
|
||||
for (const kind of bounce.RIVAL_KINDS) if (bounce.RIVALS[kind].weight > 0) assert.ok(seen.has(kind), `the ${kind} turns up`);
|
||||
const kinds = new Set();
|
||||
for (const seed of [2, 9]) {
|
||||
const road = bounce.newRoad(seed);
|
||||
while (road.built < 10) bounce.buildStage(road, road.built + 1);
|
||||
while (road.built < 30) bounce.buildStage(road, road.built + 1);
|
||||
for (const e of [...road.hazards, ...road.pads, ...road.blocks, ...road.dyn]) kinds.add(e.kind);
|
||||
}
|
||||
for (const k of ["train", "ball", "sprinkler", "drop", "wind", "boost", "ramp", "slick", "cone", "block", "draw", "sway", "crumble"]) assert.ok(kinds.has(k), `a ${k} on the road`);
|
||||
for (const k of ["train", "ball", "sprinkler", "drop", "wind", "boost", "ramp", "slick", "cone", "block", "draw", "sway", "crumble", "belt", "pop", "bumper", "laser", "stomper", "roller"]) assert.ok(kinds.has(k), `a ${k} on the road`);
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ bots */
|
||||
|
||||
test("Bounce Road: a careful bot crosses all ten stages with no rivals and no life lost, each stage taking 20 to 50 seconds", () => {
|
||||
test("Bounce Road: a careful bot crosses all fifteen stages with no rivals and no life lost, each stage taking 14 to 45 seconds", () => {
|
||||
for (const seed of [3, 21]) {
|
||||
const round = bounceRound(seed);
|
||||
const { secs, lost } = play(round, carefulBot, { stage: 11 });
|
||||
assert.equal(round.stage, 11, `seed ${seed} reaches stage 11 (${round.stage}, lost ${lost})`);
|
||||
const { secs, lost } = play(round, carefulBot, { stage: 16 });
|
||||
assert.equal(round.stage, 16, `seed ${seed} reaches stage 16 (${round.stage}, lost ${lost})`);
|
||||
assert.deepEqual(lost, [], `seed ${seed}: no life lost`);
|
||||
for (const [n, s] of secs.entries()) assert.ok(s > 20 && s < 50, `seed ${seed}: stage ${n + 1} took ${s.toFixed(0)} s`);
|
||||
for (const [n, s] of secs.entries()) assert.ok(s > 14 && s < 45, `seed ${seed}: stage ${n + 1} took ${s.toFixed(0)} s`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -528,10 +586,10 @@ test("Bounce Road: with the rivals out, the careful bot still gets far, but they
|
||||
let lostAll = 0;
|
||||
for (const seed of [11, 42]) {
|
||||
const round = bounce.newRound(seed, bounce.seeded(seed));
|
||||
const { lost } = play(round, carefulBot, { stage: 11, rivals: true, seed });
|
||||
assert.ok(round.stage >= 6, `seed ${seed}: reached stage ${round.stage}`);
|
||||
const { lost } = play(round, carefulBot, { stage: 16, rivals: true, seed });
|
||||
assert.ok(round.stage >= 3, `seed ${seed}: reached stage ${round.stage}`);
|
||||
lostAll += lost.length;
|
||||
assert.ok(round.stats.crushed + round.stats.bumped + round.stats.near > 5, "and it met them");
|
||||
assert.ok(round.stats.crushed + round.stats.bumped + round.stats.near + round.stats.hauls > 0, "and it met them");
|
||||
}
|
||||
assert.ok(lostAll >= 4, `the rivals cost lives (${lostAll})`);
|
||||
});
|
||||
@@ -560,6 +618,8 @@ test("Bounce Road: with you out of the way the rivals keep driving, never under
|
||||
const last = new Map();
|
||||
for (let ms = 0; ms < 160000; ms += 16) {
|
||||
const i = Math.floor(you.d / bounce.ROW);
|
||||
// No boss: a boss stage would last until it was beaten.
|
||||
round.bossFor = round.stage;
|
||||
Object.assign(you, { ghostMs: 1e9, air: 1000, airMax: 1000, v: 46, x: round.road.ML[i] < round.road.MR[i] ? round.road.L[i] + 3 : (round.road.L[i] + round.road.R[i]) / 2 });
|
||||
bounce.advance(round, 16, steady);
|
||||
for (const e of round.events) {
|
||||
@@ -751,10 +811,11 @@ test("Bounce Road: the Monster truck comes in Monster Mash, five landings on its
|
||||
const round = bounceRound(4);
|
||||
const road = round.road;
|
||||
bounce.ensureRoad(road, 30000);
|
||||
round.stage = 10;
|
||||
assert.equal(bounce.stageFor(12).boss, "monster", "Monster Mash is the twelfth stage of a plain run");
|
||||
round.stage = 12;
|
||||
const you = round.cars[0];
|
||||
const from = road.stageAt[9];
|
||||
const at = plainSpot(road, from + bounce.stageFor(10).len * 0.2, 30);
|
||||
const from = road.stageAt[11];
|
||||
const at = plainSpot(road, from + bounce.stageFor(12).len * 0.2, 30);
|
||||
Object.assign(you, { x: at.x, d: at.d, v: 40 });
|
||||
round.far = 1e9;
|
||||
bounce.advance(round, 16, steady);
|
||||
@@ -763,6 +824,7 @@ test("Bounce Road: the Monster truck comes in Monster Mash, five landings on its
|
||||
assert.equal(m.hp, bounce.BOSS_HP);
|
||||
assert.ok(eventsOf(round, "spawn").some((e) => e.kind === "monster"));
|
||||
round.lives = 2;
|
||||
round.lifeAt = 1e12;
|
||||
for (let n = 0; n < bounce.BOSS_HP; n++) {
|
||||
Object.assign(m, { x: you.x, d: you.d + 1, air: 0, hopIn: 1e9, dropIn: 1e9, v: you.v });
|
||||
Object.assign(you, { air: 4, airMax: 600 });
|
||||
@@ -775,8 +837,9 @@ test("Bounce Road: the Monster truck comes in Monster Mash, five landings on its
|
||||
assert.equal(eventsOf(round, "boss").length, 1);
|
||||
assert.equal(round.lives, 3, "a life back");
|
||||
assert.equal(round.stats.bosses, 1);
|
||||
assert.ok(round.feverMs > 0 && round.trophies > 0, "and a Fever, and its trophy");
|
||||
const r2 = bounceRound(4);
|
||||
r2.stage = 10;
|
||||
r2.stage = 12;
|
||||
bounce.ensureRoad(r2.road, 30000);
|
||||
const y2 = r2.cars[0];
|
||||
Object.assign(y2, { x: at.x, d: at.d, v: 50 });
|
||||
@@ -784,16 +847,16 @@ test("Bounce Road: the Monster truck comes in Monster Mash, five landings on its
|
||||
bounce.collide(r2, y2, m2);
|
||||
assert.equal(r2.phase, "crash", "its back is a wall");
|
||||
const r3 = bounceRound(4);
|
||||
r3.stage = 10;
|
||||
r3.stage = 12;
|
||||
bounce.ensureRoad(r3.road, 30000);
|
||||
const m3 = bounceRival(r3, "monster", 30, r3.road.stageAt[10] + 30, { hp: 3 });
|
||||
r3.bossFor = 10;
|
||||
const m3 = bounceRival(r3, "monster", 30, r3.road.stageAt[12] + 30, { hp: 3 });
|
||||
r3.bossFor = 12;
|
||||
const y3 = r3.cars[0];
|
||||
y3.d = r3.road.stageAt[10] - 0.5;
|
||||
y3.d = r3.road.stageAt[12] - 0.5;
|
||||
y3.x = (r3.road.L[bounce.rowOf(y3.d)] + r3.road.R[bounce.rowOf(y3.d)]) / 2;
|
||||
r3.far = 1e9;
|
||||
bounce.advance(r3, 60, steady);
|
||||
assert.equal(r3.stage, 11);
|
||||
assert.equal(r3.stage, 13);
|
||||
assert.equal(m3.outKind, "gone", "it got away");
|
||||
assert.equal(eventsOf(r3, "escape").length, 1);
|
||||
});
|
||||
@@ -924,7 +987,7 @@ test("Bounce Road: crumbling road falls away behind you once you reach it: at a
|
||||
|
||||
test("Bounce Road: a drawbridge's span is water while it lifts and road while it is down, and a swaying bridge always carries its middle line while its edge goes over the water", () => {
|
||||
const road = bounce.newRoad(2);
|
||||
bounce.ensureRoad(road, 40000);
|
||||
bounce.ensureRoad(road, 90000);
|
||||
const draw = road.dyn.find((s) => s.kind === "draw");
|
||||
assert.ok(draw, "a drawbridge");
|
||||
const mid = (draw.d0 + draw.d1) / 2;
|
||||
@@ -1146,6 +1209,11 @@ test("Bounce Road: power-ups lie on the road from Hose Creek and driving over on
|
||||
assert.ok(it.taken, "taken");
|
||||
assert.equal(eventsOf(round, "power").length, 1);
|
||||
bounce.applyPower(round, "nitro");
|
||||
assert.deepEqual(you.held, { kind: "nitro", uses: 1 }, "a gadget is held");
|
||||
assert.equal(you.nitroMs, 0, "until it is set off");
|
||||
assert.equal(bounce.usePower(round), "nitro");
|
||||
assert.equal(you.held, null, "spent");
|
||||
assert.equal(bounce.usePower(round), null, "nothing held, nothing to set off");
|
||||
round.input.up = true;
|
||||
you.v = bounce.TOP_SPEED;
|
||||
for (let ms = 0; ms < 1500; ms += 4) {
|
||||
@@ -1156,6 +1224,8 @@ test("Bounce Road: power-ups lie on the road from Hose Creek and driving over on
|
||||
const r2 = bounceRound();
|
||||
const y2 = r2.cars[0];
|
||||
bounce.applyPower(r2, "mega");
|
||||
assert.equal(y2.w, bounce.CAR_W, "Mega wheels wait for the double tap");
|
||||
bounce.usePower(r2);
|
||||
assert.ok(y2.w > bounce.CAR_W * 1.2 && y2.l > bounce.CAR_L * 1.2, "bigger");
|
||||
const at = plainSpot(r2.road, 60, 30);
|
||||
Object.assign(y2, { x: at.x, d: at.d });
|
||||
@@ -1208,7 +1278,8 @@ test("Bounce Road: a rival color too near your highlight gives way to a spare, s
|
||||
});
|
||||
|
||||
test("Bounce Road: every rival kind is drawn as one of the car art's styles, no two alike, and Planny as his own", () => {
|
||||
for (const kind of bounce.RIVAL_KINDS) assert.ok(CAR_STYLES[bounce.RIVALS[kind].style], `${kind} drawn as ${bounce.RIVALS[kind].style}`);
|
||||
for (const kind of bounce.RIVAL_KINDS) assert.ok(CAR_STYLES[bounce.RIVALS[kind].style] || CUSTOM_STYLES.includes(bounce.RIVALS[kind].style), `${kind} drawn as ${bounce.RIVALS[kind].style}`);
|
||||
assert.deepEqual(bounce.BOSS_KINDS.map((k) => bounce.RIVALS[k].style).filter((style) => !CAR_STYLES[style]).sort(), [...CUSTOM_STYLES].sort(), "only bosses are drawn by hand");
|
||||
assert.ok(CAR_STYLES.planny);
|
||||
assert.equal(new Set(bounce.RIVAL_KINDS.map((k) => bounce.RIVALS[k].style)).size, bounce.RIVAL_KINDS.length, "no two kinds look alike");
|
||||
});
|
||||
@@ -1318,9 +1389,9 @@ test("Bounce Road: the brake beats a boost strip, so a strip before a train or a
|
||||
|
||||
test("Bounce Road: a stunned Monster's back is never a wall, so running into it right after a stomp is safe", () => {
|
||||
const round = bounceRound(4);
|
||||
round.stage = 10;
|
||||
round.stage = 12;
|
||||
bounce.ensureRoad(round.road, 30000);
|
||||
const at = plainSpot(round.road, round.road.stageAt[9] + 300, 30);
|
||||
const at = plainSpot(round.road, round.road.stageAt[11] + 300, 30);
|
||||
const you = round.cars[0];
|
||||
Object.assign(you, { x: at.x, d: at.d, v: 60 });
|
||||
const m = bounceRival(round, "monster", at.x, at.d + 9.5, { v: 20, hp: 3, stunMs: 800 });
|
||||
|
||||
@@ -841,11 +841,15 @@ test("Bounce Road plays in the real window: its board's shape and cars big enoug
|
||||
await step(s, 4, 16);
|
||||
await until(async () => (await you()).stage === 2, 5000);
|
||||
await step(s, 10, 16);
|
||||
await s.page.evaluate(() => {
|
||||
await s.page.evaluate(async () => {
|
||||
const { ensureRoad } = await import("/activities/bounce.js");
|
||||
const r = window.__bounce.round;
|
||||
const me = r.cars[0];
|
||||
r.lives = 1;
|
||||
const hole = r.road.holes.find((h) => h.d0 > me.d);
|
||||
// Stages are short and dealt at random: build on to the next hole, and stay on its stage, so no stage line hands a life back on the way.
|
||||
ensureRoad(r.road, me.d + 9000);
|
||||
const hole = r.road.holes.find((h) => h.d0 > me.d && h.kind !== "draw");
|
||||
while (r.road.stageAt[r.stage] <= hole.d0) r.stage++;
|
||||
Object.assign(me, { air: 0, d: hole.d0 - 3, v: 20, bubble: false });
|
||||
});
|
||||
await step(s, 120, 16);
|
||||
@@ -2715,10 +2719,11 @@ test("Flock Dash plays in the real window: its board's shape, Enter starts a rou
|
||||
test("the server serves the activities' scripts, golf's seventeen, Light Trails, Bug Hunt, Sunset Drive, Stack Deploy, Bumper Ring's two, Rapids Run's two, Hot Potato's two, Crossing Rush's two, Bounce Road's seven, Ghoul Rush's ninety-five, Flock Dash's three, every game's sound effects and the shared pills included", () => {
|
||||
const server = fs.readFileSync(new URL("../src/web-console/static.mjs", import.meta.url), "utf8");
|
||||
const servable = server.slice(server.indexOf("const SERVABLE = new Set(["), server.indexOf("]);", server.indexOf("const SERVABLE = new Set([")));
|
||||
for (const file of ["activities/flock.js", "activities/flock-draw.js", "activities/flock-sfx.js", "activities.js", "tones.js", "music.js", "activities/snake.js", "activities/snake-music.js", "screens/activities.js", "activities/golf.js", "activities/golf-holes.js", "activities/golf-draw.js", "activities/golf-decor.js", "activities/golf-kit.js", "activities/golf-paint.js", "activities/golf-looks.js", "activities/golf-course-pirate.js", "activities/golf-course-cave.js", "activities/golf-course-dino.js", "activities/golf-course-candy.js", "activities/golf-course-space.js", "activities/golf-course-frost.js", "activities/golf-look-dino.js", "activities/golf-look-candy.js", "activities/golf-look-space.js", "activities/golf-look-frost.js", "activities/trails.js", "activities/bugs.js", "activities/drive.js", "activities/stack.js", "activities/bumper.js", "activities/bumper-draw.js", "activities/rapids.js", "activities/rapids-draw.js", "activities/fuse.js", "activities/fuse-draw.js", "activities/hop.js", "activities/hop-draw.js", "activities/bounce.js", "activities/bounce-draw.js", "activities/bounce-roads.js", "activities/bounce-road.js", "activities/bounce-rivals.js", "activities/bounce-scenery.js", "activities/bounce-cars.js", "activities/ghoul-rush/ghoul.js", "activities/ghoul-rush/draw/ghoul-draw.js", "activities/ghoul-rush/core/ghoul-rooms.js", "activities/ghoul-rush/stages/wing/ghoul-bones.js", "activities/ghoul-rush/stages/wing/ghoul-bones-draw.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard-draw.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds-draw.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel-draw.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium-draw.js", "activities/ghoul-rush/stages/village/ghoul-village.js", "activities/ghoul-rush/stages/village/ghoul-village-draw.js", "activities/ghoul-rush/stages/village/ghoul-village-world.js", "activities/ghoul-rush/stages/village/ghoul-village-wolf.js", "activities/ghoul-rush/stages/mine/ghoul-mine.js", "activities/ghoul-rush/stages/mine/ghoul-mine-draw.js", "activities/ghoul-rush/stages/mine/ghoul-mine-world.js", "activities/ghoul-rush/stages/mine/ghoul-mine-tommy.js", "activities/ghoul-rush/rides/cart/ghoul-cart.js", "activities/ghoul-rush/rides/cart/ghoul-cart-draw.js", "activities/ghoul-rush/rides/sled/ghoul-sled.js", "activities/ghoul-rush/rides/sled/ghoul-sled-draw.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney-draw.js", "activities/ghoul-rush/rides/banister/ghoul-banister.js", "activities/ghoul-rush/rides/banister/ghoul-banister-draw.js", "activities/ghoul-rush/rides/banister/ghoul-sfx-banister.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse-draw.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew.js", "activities/ghoul-rush/rides/pew/ghoul-pew-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew-course.js", "activities/ghoul-rush/rides/pew/ghoul-pew-world.js", "activities/ghoul-rush/rides/mower/ghoul-mower.js", "activities/ghoul-rush/rides/mower/ghoul-mower-draw.js", "activities/ghoul-rush/rides/tray/ghoul-tray.js", "activities/ghoul-rush/rides/tray/ghoul-tray-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-world.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-draw.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-world.js", "activities/ghoul-rush/arms/ghoul-flare.js", "activities/ghoul-rush/stages/bog/ghoul-bog.js", "activities/ghoul-rush/stages/bog/ghoul-bog-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-draw.js", "activities/ghoul-rush/rides/mat/ghoul-mat-room.js", "activities/ghoul-rush/rides/mat/ghoul-mat.js", "activities/ghoul-rush/rides/mat/ghoul-mat-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-dollhouse-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-room.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-pit-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart-draw.js", "activities/ghoul-rush/story/ghoul-ending.js", "activities/ghoul-rush/storLine truncated
|
||||
for (const file of ["activities/flock.js", "activities/flock-draw.js", "activities/flock-sfx.js", "activities.js", "tones.js", "music.js", "activities/snake.js", "activities/snake-music.js", "screens/activities.js", "activities/golf.js", "activities/golf-holes.js", "activities/golf-draw.js", "activities/golf-decor.js", "activities/golf-kit.js", "activities/golf-paint.js", "activities/golf-looks.js", "activities/golf-course-pirate.js", "activities/golf-course-cave.js", "activities/golf-course-dino.js", "activities/golf-course-candy.js", "activities/golf-course-space.js", "activities/golf-course-frost.js", "activities/golf-look-dino.js", "activities/golf-look-candy.js", "activities/golf-look-space.js", "activities/golf-look-frost.js", "activities/trails.js", "activities/bugs.js", "activities/drive.js", "activities/stack.js", "activities/bumper.js", "activities/bumper-draw.js", "activities/rapids.js", "activities/rapids-draw.js", "activities/fuse.js", "activities/fuse-draw.js", "activities/hop.js", "activities/hop-draw.js", "activities/bounce.js", "activities/bounce-draw.js", "activities/bounce-roads.js", "activities/bounce-road.js", "activities/bounce-rivals.js", "activities/bounce-scenery.js", "activities/bounce-cars.js", "activities/ghoul-rush/ghoul.js", "activities/ghoul-rush/draw/ghoul-draw.js", "activities/ghoul-rush/core/ghoul-rooms.js", "activities/ghoul-rush/stages/wing/ghoul-bones.js", "activities/ghoul-rush/stages/wing/ghoul-bones-draw.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard.js", "activities/ghoul-rush/stages/graveyard/ghoul-graveyard-draw.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds.js", "activities/ghoul-rush/stages/grounds/ghoul-grounds-draw.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel.js", "activities/ghoul-rush/stages/chapel/ghoul-chapel-draw.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium.js", "activities/ghoul-rush/stages/sanatorium/ghoul-sanatorium-draw.js", "activities/ghoul-rush/stages/village/ghoul-village.js", "activities/ghoul-rush/stages/village/ghoul-village-draw.js", "activities/ghoul-rush/stages/village/ghoul-village-world.js", "activities/ghoul-rush/stages/village/ghoul-village-wolf.js", "activities/ghoul-rush/stages/mine/ghoul-mine.js", "activities/ghoul-rush/stages/mine/ghoul-mine-draw.js", "activities/ghoul-rush/stages/mine/ghoul-mine-world.js", "activities/ghoul-rush/stages/mine/ghoul-mine-tommy.js", "activities/ghoul-rush/rides/cart/ghoul-cart.js", "activities/ghoul-rush/rides/cart/ghoul-cart-draw.js", "activities/ghoul-rush/rides/sled/ghoul-sled.js", "activities/ghoul-rush/rides/sled/ghoul-sled-draw.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney.js", "activities/ghoul-rush/rides/gurney/ghoul-gurney-draw.js", "activities/ghoul-rush/rides/banister/ghoul-banister.js", "activities/ghoul-rush/rides/banister/ghoul-banister-draw.js", "activities/ghoul-rush/rides/banister/ghoul-sfx-banister.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse.js", "activities/ghoul-rush/rides/hearse/ghoul-hearse-draw.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon.js", "activities/ghoul-rush/rides/wagon/ghoul-wagon-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew.js", "activities/ghoul-rush/rides/pew/ghoul-pew-draw.js", "activities/ghoul-rush/rides/pew/ghoul-pew-course.js", "activities/ghoul-rush/rides/pew/ghoul-pew-world.js", "activities/ghoul-rush/rides/mower/ghoul-mower.js", "activities/ghoul-rush/rides/mower/ghoul-mower-draw.js", "activities/ghoul-rush/rides/tray/ghoul-tray.js", "activities/ghoul-rush/rides/tray/ghoul-tray-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-draw.js", "activities/ghoul-rush/stages/carnival/ghoul-carnival-world.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-draw.js", "activities/ghoul-rush/stages/frozen/ghoul-frozen-world.js", "activities/ghoul-rush/arms/ghoul-flare.js", "activities/ghoul-rush/stages/bog/ghoul-bog.js", "activities/ghoul-rush/stages/bog/ghoul-bog-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-draw.js", "activities/ghoul-rush/rides/mat/ghoul-mat-room.js", "activities/ghoul-rush/rides/mat/ghoul-mat.js", "activities/ghoul-rush/rides/mat/ghoul-mat-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-dollhouse-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-eye-draw.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-room.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair.js", "activities/ghoul-rush/rides/bonestair/ghoul-bonestair-draw.js", "activities/ghoul-rush/stages/marrow/ghoul-pit-room.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart.js", "activities/ghoul-rush/stages/marrow/ghoul-marrow-heart-draw.js", "activities/ghoul-rush/story/ghoul-ending.js", "activities/ghoul-rush/storLine truncated
|
||||
assert.ok(servable.includes(`"${file}"`), `SERVABLE includes ${file}`);
|
||||
}
|
||||
for (let n = 1; n <= 5; n++) {
|
||||
assert.ok(servable.includes(`"activities/flock-dash/${n}.mp3"`), `SERVABLE includes activities/flock-dash/${n}.mp3`);
|
||||
}
|
||||
assert.ok(!servable.includes("activities/bounce-road/"), "Bounce Road's music is synthesized: no mp3 of its own is served");
|
||||
});
|
||||
@@ -20,6 +20,8 @@ import { MUSIC_TRACKS as TRAILS_TRACKS } from "../src/web-console/public/activit
|
||||
import trailsSfx from "../src/web-console/public/activities/trails-sfx.js";
|
||||
import { MUSIC_TRACKS as FLOCK_TRACKS } from "../src/web-console/public/activities/flock.js";
|
||||
import flockSfx from "../src/web-console/public/activities/flock-sfx.js";
|
||||
import { MUSIC_TRACKS as BOUNCE_TRACKS } from "../src/web-console/public/activities/bounce.js";
|
||||
import bounceSfx from "../src/web-console/public/activities/bounce-sfx.js";
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const GAMES = path.join(ROOT, "src/web-console/public/activities");
|
||||
@@ -440,6 +442,43 @@ class FakeAudio {
|
||||
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
test("music: Bounce Road lists exactly the tracks it has, each a real track that no other game defines, and no recorded songs", () => {
|
||||
const tracks = new Set(musicNames());
|
||||
assert.equal(bounceSfx.songs, undefined, "its music is note data, not recordings");
|
||||
assert.deepEqual([...BOUNCE_TRACKS].sort(), Object.keys(bounceSfx.music).sort(), "the game lists the tracks its sound file has");
|
||||
for (const name of BOUNCE_TRACKS) {
|
||||
assert.ok(tracks.has(name), `track "${name}" exists`);
|
||||
assert.equal(MUSIC_TABLES.filter((t) => Object.hasOwn(t, name)).length, 1, `${name} is defined once`);
|
||||
}
|
||||
assert.ok(![...SERVABLE].some((f) => f.startsWith("activities/bounce-road/")), "no Bounce Road mp3 is served");
|
||||
});
|
||||
|
||||
test("music: a track says it is playing until it has run through, then that it ended while it loops on, and a restart takes it back to its top", async () => {
|
||||
const saved = { sound: looks.sound, ctor: globalThis.AudioContext };
|
||||
globalThis.AudioContext = AUDIO.Ctx;
|
||||
try {
|
||||
hushMusic();
|
||||
looks.sound = true;
|
||||
const name = BOUNCE_TRACKS[0];
|
||||
assert.equal(music(name, 1, 1, { restart: true }), "playing", "from its top");
|
||||
let heard = "playing";
|
||||
for (let k = 0; k < 400 && heard !== "ended"; k++) {
|
||||
await sleep(25);
|
||||
heard = music(name, 1, 1);
|
||||
}
|
||||
assert.equal(heard, "ended", "run through");
|
||||
assert.equal(music(name, 1, 1), "ended", "and it says so for as long as it loops on");
|
||||
assert.equal(music(name, 1, 1, { restart: true }), "playing", "a restart plays it again");
|
||||
assert.equal(music(name, 1, 0), undefined, "a volume of 0: nothing playing");
|
||||
looks.sound = false;
|
||||
assert.equal(music(name, 1, 1), undefined, "Play sounds off: nothing playing");
|
||||
} finally {
|
||||
hushMusic();
|
||||
looks.sound = saved.sound;
|
||||
globalThis.AudioContext = saved.ctor;
|
||||
}
|
||||
});
|
||||
|
||||
async function withSongs(fn) {
|
||||
const saved = { sound: looks.sound, Audio: globalThis.Audio };
|
||||
globalThis.Audio = FakeAudio;
|
||||
|
||||
@@ -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