Public: anyone can read this; the crew can change it.

Migrated from github.com/amirmushichge/pixel-plays

Add Ferris Wheel: the playable page and its place in the catalogue, on the rules in `ferris-wheel/wheel.js` #209

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

vesper/pixel-plays:vesper/177-add-ferris-wheel-the-playable-page-and-i → main 2 commits fork

  • Merged. vesper/177-add-ferris-wheel-the-playable-page-and-i was merged into main as 5bdecf5.

Review

Sign in to review this change.
9 files changed +396 −3
README.md +3 −2
@@ -56,6 +56,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am
5656 | [Lock Keeper](lock-keeper/) | A flight of three canal locks climbing left to right, red narrowboats waiting at the bottom to go up and blue ones at the top to come down, in a seeded order (three rounds shipped, each with a par): tap a paddle or gate to work it and a boat to move it into or out of its lock, or Left and Right to pick a lock and 1 to 5 for its top paddle, bottom paddle, top gate, bottom gate and a boat; a gate opens only on level water, a paddle fills or empties the lock but not while the far gate is open, two open paddles flood the lock and lose the round, a refusal says why, and the end shows operations against par (forged by the crew on the engine and shell above, not by the original creators; rules in `lock-keeper/lock.js`) | Tap; Left and Right, 1 to 5 |
5757 | [Allotment](allotment/) | A five by five garden of raised beds with a bench holding the next seed packet: tap a bed to plant the packet there (or arrow keys to move and Space to plant); twelve packets in a season and every crop scores 1 plus its own rule for each touching bed (up, down, left, right): beans +3 per sweetcorn, sweetcorn -1 per sweetcorn, carrots -2 per onion, onion +2 per lettuce, lettuce +2 per carrots; 28 points by the last packet wins, against the best layout the rules could find (a seeded hand of eight seasons; forged by the crew on the engine and shell above, not by the original creators; rules in `allotment/plot.js`) | Tap a bed; arrows + Space |
5858 | [Shunting Yard](shunting-yard/) | A railway yard seen from above: a mixed-up train of numbered wagons waits on the arrival track, two sidings hold 3 wagons each, and the departure track takes the wagons only in order 1, 2, 3...; lift the end wagon of a track and set it down on another (nothing goes back to the arrival track), five levels of 3 to 7 wagons, each with a move target (5, 7, 9, 11, 13) that every yard solves within, and the game is won when all five are cleared within the targets' total; every wagon wears its number on a plate, so order never rests on colour (forged by the crew on the engine and shell above, not by the original creators; rules in `shunting-yard/yard.js`) | Tap a track to lift its end wagon, tap another to set it down; 1-4 pick the tracks, arrows move a ring, Space lifts or sets down |
59 | [Ferris Wheel](ferris-wheel/) | A fairground Ferris wheel of 8 gondolas, 3 seats each, with a platform at the bottom and a queue of 20 riders of different weights and ride lengths: tap Board (or the canvas, or press B, Space or Enter) to seat the front rider in the gondola at the platform, or Skip (or S) to send them to the back of the queue, once each; the wheel steps one gondola on a steady beat, 24 steps in all, and riders step off when their ride is done; a balance needle under the hub shows the imbalance (weight times its lever arm about the hub, summed over every rider) with the jam limit marked as a line, and the wheel jams if it passes it; carry 12 riders without a jam to win, the HUD showing riders carried, steps left and the imbalance; rider weights read by size as well as colour (green, amber, red), the front rider's weight is on a plate, and the fairground lights blink (stopped under reduced motion) (forged by the crew on the engine and shell above, not by the original creators; rules in `ferris-wheel/wheel.js`) | Tap Board or Skip; B boards, S skips |
5960 | [Empire Age](empire/) | A real-time strategy game on a 44 by 44 map against a red bot (easy, normal or hard): four villagers and a town center each, gather food, wood, gold and stone, build houses, camps, farms and military buildings, climb the Dark, Feudal, Castle and Imperial Ages, research upgrades, train militia, spearmen, archers, knights and rams, and destroy every town center and castle of the enemy; fog of war, a minimap, attack alerts, pause, 1x/2x/4x speed, an autopilot, a save that survives a reload and a best time per level (forged by the crew on the engine and shell above, not by the original creators) | Tap or drag a box to select, tap to command, panel buttons to build and train; arrows move the view, Enter taps its centre cross, 1-9 press buttons |
6061 | [Hot Air Balloon](hot-air-balloon/) | Five flights over patchwork farm fields with hedgerows, a windsock and one field marked with a white cross: hold the burner and the balloon climbs slowly after a short lag, let go and it sinks; the air has three height bands that each blow their own way and a little differently each flight, shown by drifting cloud wisps, three arrows at the left and a pennant on the basket, so you steer only by choosing a height (the ready screen before each flight already shows that flight's winds, so read them first); touching the ground ends the flight and the landing scores by distance from the cross (on it 5, inside its field 3, a neighbouring field 1, trees or the pond 0), each flight from a new launch point; 15 or more of 25 wins; the balloon's shadow on the fields shows where it is over (forged by the crew on the engine and shell above, not by the original creators) | Press and hold the canvas; hold space or the up arrow |
6162 | [Go-Kart Fete](go-kart/) | Three races of three laps round a village track against three rivals: hold to drive, let go to brake, and a yellow board before each bend shows the fastest speed to enter it at; go in faster and you sit a second in the hay bales; first scores 3, second 2, third 1, and 6 points wins (forged by the crew on the engine and shell above, not by the original creators) | Hold; space |
@@ -82,7 +83,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is
8283 Every page carries Open Graph and Twitter tags (between `og:begin` and `og:end`), and `og/<id>.png` is a 1200x630 card: the game's own opening frame, scaled 2x on white; `og/home.png` is a grid of all of them. Because the games are static, `bun scripts/og.mjs` makes them without a browser: it runs each page's scripts in a `vm` against a stub DOM, captures the canvas pixels and writes the PNG (zlib only, no dependency) and the tags. Run it after adding a game or changing a scene; `serve.test.mjs` fails when a card or its tags are missing or stale. Scenes are rendered with a seeded `Math.random`, so the cards are byte-for-byte reproducible. Absolute URLs use `ORIGIN` at the top of the script (the forge production site), so change it there if the site moves.
8384
8485 ## Add a game
85 Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules })`, set `window.PP_SCENE`, load `../engine.js`, then add the game to `GAMES` in `shell.js` with a one-line `blurb`; the home page lists every `GAMES` entry as a card with its `kind`, `input` and `accent`, searchable and filterable by kind (a static fallback list for no-JS is kept in sync by `serve.test.mjs`, so add the matching `<li>` to `index.html` too, with the same `data-kind`, `data-input`, `--accent` and tags line). Then run `bun scripts/og.mjs` to make its share card and tags. The page needs a `#mute` button. Put its background track at `<id>/<id>.mp3`, or set `music: false` on its `GAMES` entry when it has none (Stone Skip, Kite Hill, Paper Route, Harbour Crane, Pizza Toss, Sled Run, Pottery Wheel, Row Home, Orchard, Lighthouse, Market Scale, Window Washer, Domino Run, Campfire, Beekeeper, Bread Oven, Ice Fishing, Tightrope, Tram Line, Archery, Bell Tower, Espresso Bar, Goalkeeper, Wood Split, Signal Box, Soapbox Derby, Sheepdog, Firefly Jar, Hot Air Balloon, Cloakroom, Go-Kart Fete, Empire Age, Egg Basket, Dinghy Race, Coconut Shy, Bowls Green, Seed Packets, Hoopla Stall, Lock Keeper, Ferryman, Tower Duel, Sandcastle Tide, Hedge Maze, Allotment, Lily Pond, Market Barrow and Shunting Yard play on their own sound effects). Rules that need testing go in a plain script with a `.test.mjs` beside it, as in `kite-hill/model.js`.
86 Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules })`, set `window.PP_SCENE`, load `../engine.js`, then add the game to `GAMES` in `shell.js` with a one-line `blurb`; the home page lists every `GAMES` entry as a card with its `kind`, `input` and `accent`, searchable and filterable by kind (a static fallback list for no-JS is kept in sync by `serve.test.mjs`, so add the matching `<li>` to `index.html` too, with the same `data-kind`, `data-input`, `--accent` and tags line). Then run `bun scripts/og.mjs` to make its share card and tags. The page needs a `#mute` button. Put its background track at `<id>/<id>.mp3`, or set `music: false` on its `GAMES` entry when it has none (Stone Skip, Kite Hill, Paper Route, Harbour Crane, Pizza Toss, Sled Run, Pottery Wheel, Row Home, Orchard, Lighthouse, Market Scale, Window Washer, Domino Run, Campfire, Beekeeper, Bread Oven, Ice Fishing, Tightrope, Tram Line, Archery, Bell Tower, Espresso Bar, Goalkeeper, Wood Split, Signal Box, Soapbox Derby, Sheepdog, Firefly Jar, Hot Air Balloon, Cloakroom, Go-Kart Fete, Empire Age, Egg Basket, Dinghy Race, Coconut Shy, Bowls Green, Seed Packets, Hoopla Stall, Lock Keeper, Ferryman, Tower Duel, Sandcastle Tide, Hedge Maze, Allotment, Lily Pond, Market Barrow, Shunting Yard and Ferris Wheel play on their own sound effects). Rules that need testing go in a plain script with a `.test.mjs` beside it, as in `kite-hill/model.js`.
8687
8788 - `town.js` is the town's layout, pure data with no drawing: `window.PixelTown.layout(GAMES)` gives one isometric building per game (plot, screen position under the fixed 30-degree camera, accent, id) with trees in the spare plots, and `pick(town, x, y, filter)` gives the id of the front-most building under a screen point, or null. Nothing loads it yet; the drawing and the page are the second half of #99.
8889 - `shell.js` provides the game menu, the Rules popup, the credits and the background music. The menu lists the games grouped under their kind (the not-yet-made ones last, under Soon) and scrolls within the screen; type in its find box to narrow it by a word of the title, kind, input or blurb (keys typed there never reach the game), and press Escape to close it.
@@ -99,7 +100,7 @@ Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules
99100 - Depth-buffer edges: darker where an object sits in front, a warm rim on upper-left edges.
100101 - Large flat surfaces use closely spaced tones; wide steps make the dither read as a checkerboard.
101102 - Characters stay sharp: flat bands with no dither, a dark silhouette on their own pixels, patterns at least 3px wide.
102 - Ambient motion only where the scene names it: grass and leaves sway in whole pixels at 8 fps, Tram Line's waiting passengers shift their weight, Espresso Bar's machine steam and awning fringe move, Sheepdog's crow on the wall shifts and dips its head, Hot Air Balloon's windsock and cloud wisps drift, Cloakroom's coats sway and the light under its door moves, Go-Kart Fete's chequered flags flutter and its spectators wave, Egg Basket's hens peck and the straw in its basket stirs (its rolling eggs are play, not ambience, and still move), and Dinghy Race's water ripples come and go and its start-line flags flutter (the boats are play, and still sail), and Coconut Shy's bunting flutters and its stallholder shifts and waves (the thrown ball and wobbling coconuts are play, and still move), and Bowls Green's hedge leaves stir and a cloud shadow drifts across its green (the rolling woods are play, and still move), and Seed Packets' wall clock ticks its second hand and its watering can drips, and Hoopla Stall's bunting flutters (the tossed ring is play, and still moves), and Lock Keeper's water surface ripples (the boats, gates and rising water are play, and still move), and Ferryman's river ripples (the ferry and its passengers are play, and still move), and Tower Duel's river ripples shift and the king towers' pennants stir (the troops and the fireball are play, and still move), and Hedge Maze's fountain splashes (the walker is play, and still moves), and Allotment's planted crops sway (the planting is play), and Lily Pond's water glints shift (the frog, the sinking pads and their ripples are play, and still move), Market Barrow's stall awnings flutter (the barrow is play, and still moves) and Shunting Yard's engine puffs steam (the wagons are play, and still move); all of it stops under `prefers-reduced-motion`.
103 - Ambient motion only where the scene names it: grass and leaves sway in whole pixels at 8 fps, Tram Line's waiting passengers shift their weight, Espresso Bar's machine steam and awning fringe move, Sheepdog's crow on the wall shifts and dips its head, Hot Air Balloon's windsock and cloud wisps drift, Cloakroom's coats sway and the light under its door moves, Go-Kart Fete's chequered flags flutter and its spectators wave, Egg Basket's hens peck and the straw in its basket stirs (its rolling eggs are play, not ambience, and still move), Ferris Wheel's fairground lights blink, and Dinghy Race's water ripples come and go and its start-line flags flutter (the boats are play, and still sail), and Coconut Shy's bunting flutters and its stallholder shifts and waves (the thrown ball and wobbling coconuts are play, and still move), and Bowls Green's hedge leaves stir and a cloud shadow drifts across its green (the rolling woods are play, and still move), and Seed Packets' wall clock ticks its second hand and its watering can drips, and Hoopla Stall's bunting flutters (the tossed ring is play, and still moves), and Lock Keeper's water surface ripples (the boats, gates and rising water are play, and still move), and Ferryman's river ripples (the ferry and its passengers are play, and still move), and Tower Duel's river ripples shift and the king towers' pennants stir (the troops and the fireball are play, and still move), and Hedge Maze's fountain splashes (the walker is play, and still moves), and Allotment's planted crops sway (the planting is play), and Lily Pond's water glints shift (the frog, the sinking pads and their ripples are play, and still move), Market Barrow's stall awnings flutter (the barrow is play, and still moves) and Shunting Yard's engine puffs steam (the wagons are play, and still move); all of it stops under `prefers-reduced-motion`.
103104
104105 ## Empire Age
105106
ferris-wheel/index.html added +352
@@ -0,0 +1,352 @@
1 <!doctype html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
6 <title>Ferris Wheel</title>
7 <!-- og:begin -->
8 <meta name="description" content="Seat the queue without tipping the wheel">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/ferris-wheel/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Ferris Wheel">
13 <meta property="og:description" content="Seat the queue without tipping the wheel">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/ferris-wheel/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/ferris-wheel.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Ferris Wheel: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
22 <style>
23 :root { --ink: #1c1b19; --muted: #8b877f; --paper: #fff; --accent: #b8475a; }
24 * { box-sizing: border-box; }
25 html, body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
26 html, body { height: 100%; margin: 0; background: var(--paper); color: var(--ink); }
27 body { font: 13px/1.35 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; overflow: hidden; }
28 #stage { position: fixed; inset: 0; display: grid; place-items: center; }
29 canvas { display: block; image-rendering: pixelated; touch-action: none; cursor: pointer; outline: none; }
30 .hud { position: fixed; left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; pointer-events: none; }
31 #scores { position: fixed; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); display: grid; gap: 2px; pointer-events: none; }
32 #bottom { bottom: max(14px, env(safe-area-inset-bottom)); }
33 .row { display: flex; align-items: center; gap: 8px; color: var(--accent); }
34 .row b { font-size: 16px; font-weight: 600; min-width: 1ch; font-variant-numeric: tabular-nums; }
35 .row span { color: var(--muted); }
36 #status { color: var(--muted); min-height: 1.35em; }
37 .acts { display: flex; gap: 22px; align-items: center; }
38 button { pointer-events: auto; font: inherit; color: var(--muted); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; }
39 button.act { color: var(--accent); font-weight: 600; }
40 button:hover, button:focus-visible { color: var(--ink); }
41 button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
42 noscript p { position: fixed; inset: 40% 16px auto; margin: 0; text-align: center; color: var(--muted); }
43 </style>
44 </head>
45 <body>
46 <div id="stage"><canvas id="c" tabindex="0" aria-label="A Ferris wheel with eight gondolas turning one gondola on a steady beat, a platform at the bottom and a queue of riders waiting on the left; riders are drawn bigger and redder the heavier they are. A balance needle under the hub swings with the wheel's imbalance and a marked line shows the jam limit. Tap the canvas or press B to board the front rider into the gondola at the platform, press S to skip the front rider to the back of the queue, once each. Keep the needle inside the limit and carry 12 riders in 24 steps."></canvas></div>
47 <noscript><p>Ferris Wheel needs JavaScript to play.</p></noscript>
48 <div id="scores">
49 <div class="row"><b id="carried">0 of 12</b><span>riders carried</span></div>
50 <div class="row"><b id="steps">24</b><span>steps left</span></div>
51 <div class="row"><b id="imbalance">0 of 260</b><span>imbalance kg*m</span></div>
52 </div>
53 <div class="hud" id="bottom">
54 <div id="status" role="status" aria-live="polite"></div>
55 <div class="acts">
56 <button id="board" class="act" type="button">Board (B)</button>
57 <button id="skip" class="act" type="button">Skip (S)</button>
58 <button id="mute" type="button" aria-pressed="false">sound on</button>
59 </div>
60 </div>
61 <script src="../shell.js"></script>
62 <script>
63 PixelPlays.mount({
64 id: 'ferris-wheel',
65 rules: [
66 'Board (B) seats the front rider in the gondola at the platform; Skip (S) sends them to the back, once each.',
67 'The wheel steps on a steady beat and riders get off when their ride is done.',
68 'If the imbalance passes the marked line, the wheel jams.',
69 'Carry 12 riders in 24 steps to win.',
70 ],
71 });
72 </script>
73 <script>window.PP_SCENE = { originY: 30, shadowX: .6, shadowY: -.1 };</script>
74 <script src="../engine.js"></script>
75 <script src="wheel.js"></script>
76 <script>
77 'use strict';
78
79 const Wheel = window.FerrisWheel;
80 const BEAT = 1.6, TURN = .4; // seconds per step, and how long the wheel takes to swing round
81 const HUB = 10.2, RADIUS = 8, GAP = 1.3, DROP = 1.5;
82 const eng = (u, v, z) => [(u + v) / R2, (v - u) / R2, z];
83 const scr = (u, v, z = 0) => { const p = project(...eng(u, v, z)); return [p.sx, p.sy]; };
84 const spot = a => [RADIUS * Math.sin(a), HUB - RADIUS * Math.cos(a)]; // u and z of a point on the rim, a radians clockwise from the platform
85 const QUEUE_U = -4.6, QUEUE_V = 2.6, QUEUE_STEP = 1.5, SHOWN = 8;
86
87 const STEEL = [150, 150, 164], LEG = [96, 90, 110], BULB_ON = [255, 222, 110], BULB_OFF = [150, 130, 100], CABIN = [236, 224, 200], ROOF = [184, 71, 90];
88 const SKIN = [226, 184, 150], PAVE = [200, 192, 172], PAVE_ALT = [190, 182, 164], PLANK = [172, 128, 88], PLANK_ALT = [156, 114, 78];
89 const CLASSES = [[45, [120, 190, 140]], [70, [226, 176, 70]], [95, [196, 70, 70]]]; // light, middling, heavy: colour as well as size
90 const tone = w => CLASSES.find(c => w <= c[0])[1];
91 const girth = w => .2 + w / 95 * .3;
92 const INK_PIX = rgb(28, 27, 25), ACCENT_PIX = rgb(184, 71, 90), PLATE_PIX = rgb(255, 255, 255), GRID_PIX = rgb(139, 135, 127);
93 const GLYPHS = { 0: '111101101101111', 1: '010110010010111', 2: '111001111100111', 3: '111001111001111', 4: '101101111001001', 5: '111100111001111', 6: '111100111101111', 7: '111001001001001', 8: '111101111101111', 9: '111101111001111' };
94
95 /* ---------- state ---------- */
96 const nodes = {};
97 for (const k of ['carried', 'steps', 'imbalance', 'status']) nodes[k] = document.getElementById(k);
98 const shown = {};
99 function setText(key, text) {
100 if (shown[key] === text) return;
101 shown[key] = text;
102 nodes[key].textContent = text;
103 }
104 const fresh = () => Wheel.start(Math.floor(Math.random() * 4294967296));
105 let P = fresh();
106 // since: seconds into the beat; swing: seconds since the last step; needle: the drawn imbalance
107 const G = { time: 0, since: 0, swing: TURN, needle: 0, noteUntil: 0, end: '' };
108
109 function renderHud() {
110 setText('carried', `${P.carried} of ${P.winRiders}`);
111 setText('steps', String(P.steps - P.step));
112 setText('imbalance', `${P.imbalance} of ${P.limit}`);
113 }
114 function note(text) { setText('status', text); G.noteUntil = G.time + 1.8; }
115 const REFUSED = {
116 full: 'that gondola is full: skip or wait for the next', 'empty-queue': 'nobody is waiting', 'already-skipped': 'that rider has already skipped once', over: 'the round is over',
117 };
118 const waiting = () => (P.queue.length ? `Next: ${P.queue[0].weight} kg for ${P.queue[0].turns} steps · ${P.queue.length} waiting` : 'The queue is empty');
119
120 /* ---------- baked scene ---------- */
121 const inPlaza = (u, v, ix, iy) => Math.abs(u) < 17 + (hash(ix, iy) - .5) * 1.6 && v > -5.5 && v < 8.5 + (hash(iy, ix) - .5) * 1.4;
122 const onPlatform = (u, v) => Math.abs(u) < 3.2 && v > 1.3 && v < 4.2;
123 function groundColor(x, y, ix, iy) {
124 const u = (x - y) / R2, v = (x + y) / R2;
125 if (!inPlaza(u, v, ix, iy)) return 0;
126 const t = .96 + (hash(ix, iy) - .5) * .06;
127 const shade = c => rgb(c[0] * t, c[1] * t, c[2] * t);
128 if (onPlatform(u, v)) return shade(Math.floor((u + 3.2) * 2.5) % 2 ? PLANK : PLANK_ALT);
129 return shade((ix + iy) & 4 ? PAVE : PAVE_ALT);
130 }
131 function bakeWheel() {
132 const rimAt = (k, side) => { const [u, z] = spot(k / 16 * Math.PI * 2); return eng(u, side * GAP, z); };
133 for (const side of [-1, 1]) {
134 for (let k = 0; k < 16; k++) dynamicAdd(rimAt(k, side), rimAt(k + 1, side), .18, .18, () => STEEL);
135 for (let k = 0; k < 8; k++) dynamicAdd(eng(0, side * GAP, HUB), rimAt(k * 2, side), .12, .12, () => STEEL);
136 for (const s of [-1, 1]) dynamicAdd(eng(s * 6, side * GAP * 1.6, 0), eng(0, side * GAP, HUB), .3, .3, () => LEG);
137 }
138 dynamicAdd(eng(0, -GAP, HUB), eng(0, GAP, HUB), .45, .45, () => ROOF);
139 for (const s of [-1, 1]) dynamicAdd(eng(s * 6, -GAP * 1.6, .4), eng(s * 6, GAP * 1.6, .4), .3, .3, () => LEG);
140 for (const s of [-1, 1]) dynamicAdd(eng(s * 3.4, 4.2, 0), eng(s * 3.4, 4.2, 1.1), .2, .2, () => LEG);
141 flushShadows();
142 pendingShadows.length = 0;
143 }
144 function bake() {
145 ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0);
146 tufts.length = 0; leaves.length = 0;
147 zb.fill(-1e9);
148 pix.fill(rgb(255, 255, 255));
149 for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) {
150 const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy);
151 if (!c) continue;
152 pix[i] = c; ground[i] = 1;
153 zb[i] = (g.x + g.y) / R2 * COS;
154 }
155 groundZ.set(zb);
156 bakeWheel();
157 bakeOcclusion();
158 staticShadow.set(shadowMask);
159 applyShadows(groundZ);
160 bakedPix.set(pix);
161 bakedZ.set(zb);
162 }
163
164 /* ---------- drawing the wheel ---------- */
165 const plates = []; // the weight plate to stamp once the 3D is down: [weight, u, v, z]
166 function drawGondola(g, angle) {
167 const [u, zp] = spot(angle), zc = zp - DROP;
168 for (const s of [-1, 1]) dynamicAdd(eng(u, s * GAP, zp), eng(u, s * .95, zc + .3), .08, .08, () => STEEL);
169 dynamicAdd(eng(u, -GAP, zp), eng(u, GAP, zp), .1, .1, () => STEEL);
170 dynamicAdd(eng(u, -1.05, zc), eng(u, 1.05, zc), .45, .45, () => CABIN);
171 dynamicAdd(eng(u, -1.15, zc + .55), eng(u, 1.15, zc + .55), .12, .12, () => ROOF);
172 P.gondolas[g].forEach((r, i) => {
173 const rad = girth(r.weight);
174 dynamicAdd(eng(u, (i - 1) * .75, zc + .35 + rad), eng(u, (i - 1) * .75, zc + .4 + rad), rad, rad, () => tone(r.weight));
175 });
176 }
177 // the fairground lights: alternate bulbs blink twice a second; under reduced motion they all stay lit
178 function drawBulbs() {
179 const phase = STILL ? 0 : Math.floor(G.time * 2) % 2;
180 for (let k = 0; k < 16; k++) for (const side of [-1, 1]) {
181 const [u, z] = spot(k / 16 * Math.PI * 2 + Math.PI / 16);
182 sphere(...eng(u, side * (GAP + .2), z), .2, (k + phase) % 2 === 0 ? BULB_ON : BULB_OFF, 'solid');
183 }
184 }
185 function drawQueue() {
186 P.queue.slice(0, SHOWN).forEach((r, i) => {
187 const u = QUEUE_U - i * QUEUE_STEP, rad = girth(r.weight);
188 dynamicAdd(eng(u, QUEUE_V, .2), eng(u, QUEUE_V, .2 + rad * 2.4), rad, rad * .8, () => tone(r.weight));
189 dynamicAdd(eng(u, QUEUE_V, .4 + rad * 2.4 + .3), eng(u, QUEUE_V, .45 + rad * 2.4 + .3), .24, .24, () => (r.skipped ? ROOF : SKIN));
190 if (!i) plates.push([r.weight, u, QUEUE_V, 1.4 + rad * 2.4]);
191 });
192 }
193 function stamp(ch, left, top, scale, color) {
194 const g = GLYPHS[ch];
195 for (let k = 0; k < 15; k++) if (g[k] === '1') for (let dy = 0; dy < scale; dy++) for (let dx = 0; dx < scale; dx++) {
196 const x = left + (k % 3) * scale + dx, y = top + Math.floor(k / 3) * scale + dy;
197 if (x >= 0 && x < W && y >= 0 && y < H) pix[y * W + x] = color;
198 }
199 }
200 // the front rider's weight on a white plate above their head
201 function drawPlates() {
202 for (const [w, u, v, z] of plates) {
203 const p = project(...eng(u, v, z)), left = Math.round(p.sx) - 8, top = Math.round(p.sy) - 12;
204 for (let y = 0; y < 11; y++) for (let x = 0; x < 16; x++) {
205 const px = left + x, py = top + y;
206 if (px >= 0 && px < W && py >= 0 && py < H) pix[py * W + px] = x === 0 || y === 0 || x === 15 || y === 10 ? INK_PIX : PLATE_PIX;
207 }
208 const digits = String(w);
209 for (let i = 0; i < digits.length; i++) stamp(digits[i], left + 3 + i * 5, top + 3, 1, INK_PIX);
210 }
211 plates.length = 0;
212 }
213 const line = (x0, y0, x1, y1) => {
214 const n = Math.max(1, Math.ceil(Math.hypot(x1 - x0, y1 - y0))), pts = [];
215 for (let i = 0; i <= n; i++) pts.push([Math.round(x0 + (x1 - x0) * i / n), Math.round(y0 + (y1 - y0) * i / n)]);
216 return pts;
217 };
218 // the balance needle under the hub: a white plate, a scale with the jam limit marked at both ends, and the needle swinging between
219 function drawNeedle() {
220 const [hx, hy] = scr(0, 0, HUB), cx = Math.round(hx), top = Math.round(hy) + 22, reach = 26, wide = 34;
221 for (let y = 0; y < 18; y++) for (let x = -wide - 3; x <= wide + 3; x++) {
222 const px = cx + x, py = top + y;
223 if (px >= 0 && px < W && py >= 0 && py < H) pix[py * W + px] = y === 0 || y === 17 || Math.abs(x) === wide + 3 ? INK_PIX : PLATE_PIX;
224 }
225 drawDots(line(cx - wide, top + 13, cx + wide, top + 13), GRID_PIX);
226 drawDots(line(cx, top + 10, cx, top + 15), INK_PIX);
227 for (const s of [-1, 1]) drawDots(line(cx + s * reach, top + 3, cx + s * reach, top + 15), ACCENT_PIX); // the jam limit
228 const tip = Math.max(-wide, Math.min(wide, G.needle / P.limit * reach)), hot = Math.abs(G.needle) > P.limit * .75;
229 drawDots(line(cx, top + 14, cx + tip, top + 4), hot ? ACCENT_PIX : INK_PIX);
230 drawDots(line(cx + 1, top + 14, cx + tip + 1, top + 4), hot ? ACCENT_PIX : INK_PIX);
231 // the beat to the next step, along the foot of the plate
232 if (P.status === 'playing') drawDots(line(cx - wide, top + 16, cx - wide + Math.round(G.since / BEAT * wide * 2), top + 16), GRID_PIX);
233 }
234
235 function draw() {
236 pix.set(bakedPix);
237 zb.set(bakedZ);
238 pendingShadows.length = 0;
239 const turns = STILL ? P.turns : P.turns - 1 + ease(Math.min(1, G.swing / TURN));
240 for (let g = 0; g < P.count; g++) drawGondola(g, (g + turns) / P.count * Math.PI * 2);
241 drawQueue();
242 flushShadows();
243 drawBulbs();
244 applyShadows(bakedZ);
245 shadeEdges();
246 drawPlates();
247 drawNeedle();
248 ctx.putImageData(image, 0, 0);
249 }
250
251 /* ---------- game ---------- */
252 function finish(e) {
253 G.end = `${P.line} · tap or press a key to play again`; G.noteUntil = 0;
254 setText('status', G.end);
255 sound(e === 'jam' ? 90 : 523, .5, e === 'jam' ? 'sawtooth' : 'sine');
256 }
257 function board() {
258 ensureAudio();
259 const r = Wheel.board(P);
260 if (!r.ok) { note(REFUSED[r.why] || 'cannot do that'); sound(110, .15, 'sawtooth'); return; }
261 P = r.state; sound(392, .09, 'triangle');
262 note(`${P.carried} riders carried`);
263 renderHud();
264 }
265 function skip() {
266 ensureAudio();
267 const r = Wheel.skip(P);
268 if (!r.ok) { note(REFUSED[r.why] || 'cannot do that'); sound(110, .15, 'sawtooth'); return; }
269 P = r.state; sound(262, .08, 'square');
270 note('sent to the back of the queue');
271 renderHud();
272 }
273 function turn() {
274 const r = Wheel.step(P);
275 if (!r.ok) return;
276 P = r.state; G.swing = 0; G.since = 0;
277 sound(196, .05, 'square');
278 renderHud();
279 if (r.event) finish(r.event);
280 }
281 function restart() {
282 P = fresh(); G.end = ''; G.since = 0; G.swing = TURN; G.needle = 0;
283 note('board the front rider, or skip them');
284 renderHud();
285 }
286 const act = fn => () => { if (P.status !== 'playing') restart(); else fn(); canvas.focus({ preventScroll: true }); };
287 function update(dt) {
288 G.time += dt; G.swing += dt;
289 const aim = P.imbalance;
290 G.needle = STILL ? aim : G.needle + (aim - G.needle) * Math.min(1, dt * 9);
291 if (P.status === 'playing') {
292 G.since += dt;
293 if (G.since >= BEAT) turn();
294 }
295 if (P.status !== 'playing' || G.time < G.noteUntil) return;
296 setText('status', waiting());
297 }
298
299 /* ---------- input ---------- */
300 canvas.addEventListener('pointerdown', () => { canvas.focus({ preventScroll: true }); act(board)(); });
301 document.getElementById('board').addEventListener('click', act(board));
302 document.getElementById('skip').addEventListener('click', act(skip));
303 canvas.addEventListener('keydown', e => {
304 const key = e.key.toLowerCase(), pick = key === 'b' || key === ' ' || key === 'enter' ? board : key === 's' ? skip : null;
305 if (!pick) return;
306 e.preventDefault();
307 if (!e.repeat) act(pick)();
308 });
309
310 /* ---------- sound ---------- */
311 let audio = null, muted = false;
312 function ensureAudio() {
313 if (audio) { if (audio.state === 'suspended') audio.resume(); return; }
314 const AC = window.AudioContext || window.webkitAudioContext;
315 if (AC) audio = new AC();
316 }
317 function sound(freq, life, type, delay = 0) {
318 if (!audio || muted) return;
319 const now = audio.currentTime + delay, gain = audio.createGain(), osc = audio.createOscillator();
320 osc.type = type;
321 osc.frequency.setValueAtTime(freq, now);
322 gain.gain.setValueAtTime(.0001, now);
323 gain.gain.exponentialRampToValueAtTime(.07, now + .01);
324 gain.gain.exponentialRampToValueAtTime(.0005, now + life);
325 osc.connect(gain).connect(audio.destination);
326 osc.start(now); osc.stop(now + life + .02);
327 }
328 const muteButton = document.getElementById('mute');
329 muteButton.addEventListener('click', () => {
330 muted = !muted;
331 muteButton.textContent = muted ? 'sound off' : 'sound on';
332 muteButton.setAttribute('aria-pressed', String(muted));
333 });
334
335 /* ---------- fit and boot ---------- */
336 addEventListener('resize', fit);
337 fit();
338 bake();
339 note('board the front rider, or skip them');
340 renderHud();
341 canvas.focus({ preventScroll: true });
342 let last = performance.now();
343 function frame(now) {
344 update(Math.min(.04, (now - last) / 1000));
345 last = now;
346 draw();
347 requestAnimationFrame(frame);
348 }
349 requestAnimationFrame(frame);
350 </script>
351 </body>
352 </html>
ferris-wheel/wheel.js +1 −1
@@ -11,7 +11,7 @@
1111 (function (root) {
1212 const GONDOLAS = 8, SEATS = 3, STEPS = 24, QUEUE = 20;
1313 const ARM = [0, 3, 4, 3, 0, -3, -4, -3]; // m, per position clockwise from the platform: 4 m radius, 45 degrees apart, rounded
14 const LIMIT = 40; // kg*m
14 const LIMIT = 260; // kg*m: a lone 20-95 kg rider swings 60-285 east of the hub, so a heavy rider needs company on the west side
1515 const WIN_RIDERS = 12; // the win line: this many riders carried
1616 const MIN_WEIGHT = 20, MAX_WEIGHT = 95, MIN_TURNS = 2, MAX_TURNS = 6;
1717
index.html +1
@@ -116,6 +116,7 @@ footer a::after { content: none; }
116116 <li data-kind="Strategy" data-input="Tap" style="--accent:#8a3b3b"><a href="tower-duel/">Tower Duel</a><span>Tap a card, tap your half: send troops over the bridges and topple the rival king tower</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
117117 <li data-kind="Puzzle" data-input="Keys" style="--accent:#2f7a6a"><a href="lily-pond/">Lily Pond</a><span>Hop the frog onto every lily pad once before they sink</span><span>Game forged by the crew</span><span class="tags">Puzzle · Keys</span></li>
118118 <li data-kind="Puzzle" data-input="Tap" style="--accent:#8a4b2f"><a href="shunting-yard/">Shunting Yard</a><span>Shunt the wagons through the sidings until the train leaves in order</span><span>Game forged by the crew</span><span class="tags">Puzzle · Tap</span></li>
119 <li data-kind="Strategy" data-input="Tap" style="--accent:#b8475a"><a href="ferris-wheel/">Ferris Wheel</a><span>Seat the queue without tipping the wheel</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
119120 <li data-kind="Puzzle" data-input="Keys" style="--accent:#3d6e4f"><a href="hedge-maze/">Hedge Maze</a><span>Find the way through the hedges to the fountain before the gardener rings the bell</span><span>Game forged by the crew</span><span class="tags">Puzzle · Keys</span></li>
120121 </ul>
121122 <footer>Concept by <a href="https://x.com/awwbhi2">abhi</a>. Game by <a href="https://x.com/AmirMushich">AmirMushich</a>. Visual reference for the style: shawn.'s <a href="https://x.com/zzzzshawn/status/2111546123546661289">Small plays</a>; no assets or subjects were copied.<br><a href="stats/">Most played</a></footer>
og/ferris-wheel.png added
Binary file not shown.
og/home.png
Binary file not shown.
rounds.mjs +31
@@ -6,6 +6,7 @@ import Lock from './lock-keeper/lock.js';
66 import { bestThrow, LINE_MAX } from './bowls-green/bowls.js';
77 import Allotment from './allotment/plot.js';
88 import { toss, MAX_AIM } from './hoopla/hoop.js';
9 import Wheel from './ferris-wheel/wheel.js';
910
1011 const MID = [180, 140];
1112 const tapping = (wait = .3) => g => { g.tap(...MID); g.run(wait); };
@@ -36,6 +37,29 @@ function solve(start) {
3637 return [];
3738 }
3839
40 // the keys to press before each step ('b' board, 's' skip) of a round that ends balanced with the rider line reached, found by search
41 function wheelPlan(start) {
42 const dead = new Set(), key = s => JSON.stringify([s.step, s.turns, s.carried, s.queue.map(r => [r.id, r.skipped]), s.gondolas.map(g => g.map(r => [r.id, r.left]))]);
43 const tries = ['bb', 'b', 'sb', 'bbb', 's', '']; // the keys to try before a step, most promising first
44 function go(s, plan) {
45 if (s.status === 'over') return s.status === 'over' && !s.jammed && Wheel.verdict(s) === 'won' ? plan : null;
46 const k = key(s);
47 if (dead.has(k)) return null;
48 for (const keys of tries) {
49 let t = s, ok = true;
50 for (const c of keys) { const r = c === 'b' ? Wheel.board(t) : Wheel.skip(t); if (!r.ok) { ok = false; break; } t = r.state; }
51 if (!ok) continue;
52 const r = Wheel.step(t);
53 if (r.event === 'jam') continue;
54 const found = go(r.state, [...plan, keys]);
55 if (found) return found;
56 }
57 dead.add(k);
58 return null;
59 }
60 return go(start, []) ?? [];
61 }
62
3963 export const ROUNDS = {
4064 // plant each packet in the bed that leaves the most points (a greedy pass over the rules' own `plant` and `score`), by tapping that bed
4165 'allotment': { over: /play again/, outcome: /Harvest in: \d+ points/, beat: g => {
@@ -128,6 +152,13 @@ export const ROUNDS = {
128152 if (index >= 0) { g.press(String(index + 1)); g.tap(...g.read(`scr(${x}, 9)`)); }
129153 g.run(.2);
130154 } },
155 // plan the whole round on the rules' own `board`, `skip` and `step` (a depth-first search that seats as many riders as it can without a jam), then play it one step per beat
156 'ferris-wheel': { over: /play again/, outcome: /Wheel balanced: \d+ riders carried/, beat: g => {
157 g.plan ??= wheelPlan(structuredClone(g.read('P')));
158 const at = g.read('P.step'), keys = g.plan[at] ?? '';
159 if (g.read('P.status') === 'playing') for (const k of keys) g.press(k);
160 while (g.read('P.step') === at && g.read('P.status') === 'playing') g.run(.2);
161 } },
131162 // hop along the route the rules planned for this pond, one arrow key per pad
132163 'lily-pond': { over: /play again/, outcome: /Pond cleared: 6 levels, \d+ retries?/, beat: g => {
133164 const [a, b] = g.read('[P.route[P.hops], P.route[P.hops + 1]]');
serve.test.mjs +7
@@ -542,6 +542,13 @@ test('Shunting Yard and its rules script are served without a track', async () =
542542 expect((await fetch(base + '/shunting-yard/yard.js')).status).toBe(200);
543543 });
544544
545 test('Ferris Wheel and its rules script are served without a track', async () => {
546 const page = await fetch(base + '/ferris-wheel/');
547 expect(page.status).toBe(200);
548 expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8');
549 expect((await fetch(base + '/ferris-wheel/wheel.js')).status).toBe(200);
550 });
551
545552 test('Hedge Maze and its rules script are served without a track', async () => {
546553 const page = await fetch(base + '/hedge-maze/');
547554 expect(page.status).toBe(200);
shell.js +1
@@ -56,6 +56,7 @@ window.PixelPlays = (() => {
5656 { id: 'tower-duel', title: 'Tower Duel', blurb: 'Tap a card, tap your half: send troops over the bridges and topple the rival king tower', kind: 'Strategy', input: 'Tap', accent: '#8a3b3b', music: false, forged: true },
5757 { id: 'lily-pond', title: 'Lily Pond', blurb: 'Hop the frog onto every lily pad once before they sink', kind: 'Puzzle', input: 'Keys', accent: '#2f7a6a', music: false, forged: true },
5858 { id: 'shunting-yard', title: 'Shunting Yard', blurb: 'Shunt the wagons through the sidings until the train leaves in order', kind: 'Puzzle', input: 'Tap', accent: '#8a4b2f', music: false, forged: true },
59 { id: 'ferris-wheel', title: 'Ferris Wheel', blurb: 'Seat the queue without tipping the wheel', kind: 'Strategy', input: 'Tap', accent: '#b8475a', music: false, forged: true },
5960 { id: 'hedge-maze', title: 'Hedge Maze', blurb: 'Find the way through the hedges to the fountain before the gardener rings the bell', kind: 'Puzzle', input: 'Keys', accent: '#3d6e4f', music: false, forged: true },
6061 ];
6162 const MUSIC_VOLUME = .4;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs