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

Migrated from github.com/amirmushichge/pixel-plays

Add Ferryman: the playable page and its place in the catalogue, on the rules in `ferryman/ferry.js` #160

Merged opened this

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

Merged

vesper/pixel-plays:vesper/139-add-ferryman-the-playable-page-and-its-p → main 2 commits fork

  • Merged. vesper/139-add-ferryman-the-playable-page-and-its-p was merged into main as c673ad1.

Review

Sign in to review this change.
8 files changed +423 −2
README.md +3 −2
@@ -50,6 +50,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am
5050 | [Bowls Green](bowls-green/) | A flat lawn bowls green floating on white, a white jack at the far end, a mat at the near end, two rival woods already resting near the jack and a low hedge behind: drag back from the mat and release to roll (or Left and Right to set the line, hold Space to build weight, release to roll); weight sets how far the wood runs (quadratic in weight, against a pace that is one seeded constant per game) and each wood bends towards its bias side as it slows, so aiming straight at the jack misses; a wood off the back of the green (or into the ditch at the side) is dead; one end of four woods, and one or more resting nearer the jack than the nearest rival wood wins (forged by the crew on the engine and shell above, not by the original creators; rules in `bowls-green/bowls.js`) | Drag back and release; Left and Right to aim, hold Space |
5151 | [Dinghy Race](dinghy-race/) | A bay with a square course of three buoys and back over a start line, the wind from the south-east and shifting a little at each buoy: the boat steers itself buoy to buoy and you trim the sail; it drives best at half the angle between boat and wind, and loses speed quadratically as the trim drifts from that, so every leg and every wind shift asks for a new setting; two seeded rivals sail at a steady pace, first or second place is a win (forged by the crew on the engine and shell above, not by the original creators; rules in `dinghy-race/dinghy.js`) | Drag left and right along the sheet; Up and Down arrows trim in and out |
5252 | [Seed Packets](seed-packets/) | A potting-shed bench with sixteen face-down seed packets in a 4x4 grid, a watering can and a clock on the wall: tap a packet to turn it face up to show its flower, then a second; a matching pair stays face up and a mismatch turns both back after 0.8 s (taps in that beat are ignored); the layout is a seeded shuffle of eight pairs and the gardener returns after 16 turns (a turn is two packets), so you can afford eight mismatches; the end shows pairs found and turns used, and the best is the fewest turns in a win (forged by the crew on the engine and shell above, not by the original creators) | Tap; arrows + space |
53 | [Ferryman](ferryman/) | A river with a near bank, a far bank and a ferry moored at the near landing: tap a passenger to load or unload it, then tap the ferry to cross (or press 1-4 to pick a passenger and Space to cross); the fox, the goose and the grain start on the near bank, and left alone together on a bank the fox eats the goose and the goose eats the grain, so the ferry carries one at a time; three levels, the later ones add a dog, a two-seat ferry and a crossing limit, and a round is won by getting everyone across in par crossings or fewer, the HUD showing level, crossings and par as the rules report them (forged by the crew on the engine and shell above, not by the original creators; rules in `ferryman/ferry.js`) | Tap; 1-4 and Space |
5354 | [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 |
5455 | [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 |
5556 | [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 |
@@ -74,7 +75,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is
7475 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.
7576
7677 ## Add a game
77 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 and Lock Keeper 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`.
78 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 and Lock Keeper and Ferryman 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`.
7879
7980 - `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.
8081 - `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.
@@ -91,7 +92,7 @@ Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules
9192 - Depth-buffer edges: darker where an object sits in front, a warm rim on upper-left edges.
9293 - Large flat surfaces use closely spaced tones; wide steps make the dither read as a checkerboard.
9394 - Characters stay sharp: flat bands with no dither, a dark silhouette on their own pixels, patterns at least 3px wide.
94 - 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); all of it stops under `prefers-reduced-motion`.
95 - 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); all of it stops under `prefers-reduced-motion`.
9596
9697 ## Empire Age
9798
ferryman/index.html added +403
@@ -0,0 +1,403 @@
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>Ferryman</title>
7 <!-- og:begin -->
8 <meta name="description" content="Row the fox, the goose and the grain across without leaving the wrong pair alone">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/ferryman/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Ferryman">
13 <meta property="og:description" content="Row the fox, the goose and the grain across without leaving the wrong pair alone">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/ferryman/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/ferryman.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="Ferryman: 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: #4f7f6a; }
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; 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)); align-items: flex-end; }
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 button { pointer-events: auto; font: inherit; color: var(--muted); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; }
38 button:hover, button:focus-visible { color: var(--ink); }
39 </style>
40 </head>
41 <body>
42 <div id="stage"><canvas id="c" tabindex="0" aria-label="A river with a near bank on the left, a far bank on the right and a ferry moored at the near bank, with a few numbered passengers waiting on the bank. Tap a passenger to load or unload it, then tap the ferry to cross; or press 1 to 4 to pick a passenger and Space to cross. Never leave a hunter alone with its prey on a bank, and get everyone across in par crossings."></canvas></div>
43 <div id="scores">
44 <div class="row"><b id="level">-</b><span>level</span></div>
45 <div class="row"><b id="crossings">0</b><span>crossings</span></div>
46 <div class="row"><b id="par">-</b><span>par</span></div>
47 </div>
48 <div class="hud" id="bottom">
49 <div id="status" role="status" aria-live="polite"></div>
50 <button id="mute" type="button" aria-pressed="false">sound on</button>
51 </div>
52 <script src="../shell.js"></script>
53 <script>
54 PixelPlays.mount({
55 id: 'ferryman',
56 rules: [
57 'Tap a passenger to load or unload it, or press 1 to 4; tap the ferry or press Space to cross.',
58 'Left alone together on a bank, a hunter eats its prey.',
59 'Get everyone across in par crossings or fewer.',
60 ],
61 });
62 </script>
63 <script>window.PP_SCENE = { originY: 8, shadowX: 1.3, shadowY: -.12 };</script>
64 <script src="../engine.js"></script>
65 <script src="ferry.js"></script>
66 <script>
67 'use strict';
68
69 const GRASS_BANK = [96, 142, 78], SAND = [212, 194, 142], WATER = [86, 150, 184], PLANK = [166, 124, 82], PLANK_DARK = [120, 88, 58];
70 const FOX = [222, 112, 40], DARK = [58, 40, 36], WHITE = [246, 244, 236], BEAK = [236, 150, 40], SACK = [204, 172, 112], SACK_TIE = [148, 108, 64];
71 const EAR = [236, 198, 62], DOG = [152, 112, 82], BONE = [240, 236, 220], REED = [74, 120, 70], STONE = [150, 148, 142];
72 const HALF_U = 17, HALF_V = 12, SHORE = 5.4, DOCK = 6.9, RAFT_U = 2.2, RAFT_V = 3.6, RAFT_Z = .5, STOP = 3.2, SPEED = 10;
73 const LEVEL_KEY = 'pixel-plays-ferryman-level';
74 const LOOKS = {
75 fox: { c: FOX }, goose: { c: WHITE }, grain: { c: SACK }, dog: { c: DOG },
76 };
77 const GLYPHS = { 1: '010110010010111', 2: '111001111100111', 3: '111001111001111', 4: '101101111001001' };
78 const INK_PIX = rgb(28, 27, 25), LABEL_PIX = rgb(255, 255, 255), LOST_PIX = rgb(214, 48, 40);
79
80 const world = (u, v, z) => [(u + v) / R2, (v - u) / R2, z];
81 const lastLevel = Ferry.LEVELS.length - 1;
82 const saved = (() => { try { const n = parseInt(localStorage.getItem(LEVEL_KEY), 10); return Number.isInteger(n) && n >= 0 && n <= lastLevel ? n : 0; } catch (e) { return 0; } })();
83
84 /* ---------- state ---------- */
85 let R = Ferry.newGame(saved);
86 const G = { time: 0, noteUntil: 0, ferryU: -STOP, load: [], riding: [], status: '' };
87 const nodes = {};
88 for (const k of ['level', 'crossings', 'par', 'status']) nodes[k] = document.getElementById(k);
89 const shown = {};
90 function setText(key, text) {
91 if (shown[key] === text) return;
92 shown[key] = text;
93 nodes[key].textContent = text;
94 }
95 const crew = () => Ferry.LEVELS[R.level].passengers;
96 const seats = () => Ferry.LEVELS[R.level].seats;
97 const targetU = () => (R.at.ferry === Ferry.NEAR ? -STOP : STOP);
98 const busy = () => Math.abs(G.ferryU - targetU()) > .01;
99 function renderHud() {
100 setText('level', `${R.level + 1}: ${Ferry.LEVELS[R.level].name}`);
101 setText('crossings', R.limit == null ? String(R.crossings) : `${R.crossings} of ${R.limit}`);
102 setText('par', String(R.par));
103 }
104 function note(text) { setText('status', text); G.noteUntil = G.time + 2; }
105
106 /* ---------- painting ---------- */
107 function put(ramp, u, v, z, tone) {
108 const p = project((u + v) / R2, (v - u) / R2, z), ix = p.sx | 0, iy = p.sy | 0;
109 if (ix < 0 || iy < 0 || ix >= W || iy >= H) return;
110 const i = iy * W + ix;
111 if (p.d <= zb[i]) return;
112 zb[i] = p.d;
113 pix[i] = ramp[clamp(Math.floor(tone + (bayerAt(ix, iy) - .5) * .5), 0, 4)];
114 }
115 function top(ramp, u0, u1, v0, v1, z, tone, step = .08) {
116 for (let u = u0; u <= u1; u += step) for (let v = v0; v <= v1; v += step) put(ramp, u, v, z, typeof tone === 'function' ? tone(u, v) : tone);
117 }
118 function front(ramp, u0, u1, v, z0, z1, tone, step = .08) {
119 for (let u = u0; u <= u1; u += step) for (let z = z0; z <= z1; z += step) put(ramp, u, v, z, typeof tone === 'function' ? tone(u, z) : tone);
120 }
121
122 /* ---------- baked scene: the river, both banks, the landings and the reeds ---------- */
123 const water = new Uint8Array(W * H);
124 function groundColor(x, y, ix, iy) {
125 const u = (x - y) / R2, v = (x + y) / R2;
126 if (Math.max(Math.abs(u) - HALF_U, Math.abs(v) - HALF_V) > -hash(ix, iy) * 1.2) return 0; // a ragged edge into the white
127 const a = Math.abs(u), t = .96 + (hash(ix, iy) - .5) * .08 + (noise(u * .5, v * .9) - .5) * .12;
128 if (a < SHORE - .5 - noise(v * .6, 4) * .5) { water[iy * W + ix] = 1; return rgb(WATER[0] * (t + (a < 2 ? .04 : 0)), WATER[1] * t, WATER[2] * t); }
129 const c = a < SHORE + .3 ? SAND : GRASS_BANK;
130 return rgb(c[0] * t, c[1] * t, c[2] * t);
131 }
132 function bakeLandings() {
133 const plank = rampOf(PLANK), dark = rampOf(PLANK_DARK);
134 for (const side of [-1, 1]) {
135 const u0 = Math.min(side * SHORE, side * DOCK), u1 = Math.max(side * SHORE, side * DOCK);
136 top(plank, u0 - 1.2, u1, -RAFT_V, RAFT_V, .2, (u, v) => 2.6 + (Math.floor((v + 40) / .9) & 1) * .5);
137 front(dark, u0 - 1.2, u1, RAFT_V, 0, .2, 2);
138 for (const pv of [-RAFT_V, RAFT_V]) { // mooring posts at the water's edge
139 const a = world(side * (SHORE - 1.3), pv, 0), b = world(side * (SHORE - 1.3), pv, 1.5);
140 capsule(a, b, .28, .28, () => PLANK_DARK, 'solid');
141 castShadow(a[0], a[1], 1.5, .5, 1, 0);
142 }
143 }
144 }
145 function bakeReeds() {
146 for (let k = 0; k < 24; k++) {
147 const side = k % 2 ? 1 : -1, v = -HALF_V + 1 + hash(k, 5) * (HALF_V * 2 - 2);
148 if (Math.abs(v) < RAFT_V + .6) continue;
149 const u = side * (SHORE - .2 - hash(k, 9) * .5), h = 1.4 + hash(k, 3) * 1.2;
150 capsule(world(u, v, 0), world(u + side * .15, v, h), .1, .06, () => REED, 'solid');
151 }
152 for (let k = 0; k < 14; k++) { // stones and tufts on the banks
153 const side = k % 2 ? 1 : -1, u = side * (SHORE + 2 + hash(k, 21) * 8), v = -HALF_V + 1.5 + hash(k, 23) * (HALF_V * 2 - 3);
154 sphere(...world(u, v, .15), .35 + hash(k, 25) * .35, k % 3 ? STONE : REED, 'solid');
155 castShadow(...world(u, v, 0).slice(0, 2), .4, .5, 1, 0);
156 }
157 }
158 function bake() {
159 ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0); water.fill(0);
160 tufts.length = 0; leaves.length = 0;
161 zb.fill(-1e9);
162 pix.fill(rgb(255, 255, 255));
163 for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) {
164 const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy);
165 if (!c) { water[i] = 0; continue; }
166 pix[i] = c; ground[i] = 1;
167 zb[i] = (g.x + g.y) / R2 * COS;
168 }
169 groundZ.set(zb);
170 bakeLandings();
171 bakeReeds();
172 bakeOcclusion();
173 staticShadow.set(shadowMask);
174 applyShadows(groundZ);
175 bakedPix.set(pix);
176 bakedZ.set(zb);
177 }
178
179 /* ---------- drawn each frame ---------- */
180 // the river's ripples: short pale dashes that come and go on a slow beat; one fixed frame under reduced motion
181 const RIPPLES = Array.from({ length: 80 }, (_, k) => ({ ix: Math.floor(hash(k, 3) * W), iy: Math.floor(hash(k, 7) * H), len: 3 + Math.floor(hash(k, 11) * 3), phase: Math.floor(hash(k, 13) * 4) }));
182 const FOAM = rgb(190, 226, 238);
183 function ripples() {
184 const beat = STILL ? 0 : Math.floor(G.time * 1.5);
185 for (const r of RIPPLES) {
186 if ((beat + r.phase) % 4 > 1) continue;
187 const dx = STILL ? 0 : (beat + r.phase) % 4;
188 for (let n = 0; n < r.len; n++) {
189 const ix = r.ix + n + dx;
190 if (ix >= W) break;
191 const i = r.iy * W + ix;
192 if (water[i] && zb[i] === bakedZ[i]) pix[i] = FOAM;
193 }
194 }
195 }
196 function drawFerry() {
197 const c = G.ferryU, plank = rampOf(PLANK), dark = rampOf(PLANK_DARK);
198 top(plank, c - RAFT_U, c + RAFT_U, -RAFT_V, RAFT_V, RAFT_Z, (u, v) => 3 + (Math.floor((v + 40) / .9) & 1) * .5 - .3, .1);
199 front(dark, c - RAFT_U, c + RAFT_U, RAFT_V, .1, RAFT_Z, 2, .1);
200 for (let v = -RAFT_V; v <= RAFT_V; v += .1) for (let z = .1; z <= RAFT_Z; z += .1) put(dark, c + RAFT_U, v, z, 1.2);
201 for (const pv of [-RAFT_V + .3, RAFT_V - .3]) { // a rail post at each end
202 const a = world(c - RAFT_U + .3, pv, RAFT_Z), b = world(c - RAFT_U + .3, pv, 1.6);
203 capsule(a, b, .16, .16, () => PLANK_DARK, 'solid');
204 }
205 for (let k = -3; k <= 3; k++) castShadow(...world(c, k * 1.1, 0).slice(0, 2), RAFT_Z, 1.5, 1, 0);
206 }
207 // where a passenger stands: its slot on a bank, or its seat on the ferry
208 function standing(name) {
209 const i = crew().indexOf(name), riding = G.load.indexOf(name) >= 0 ? G.load.indexOf(name) : G.riding.indexOf(name);
210 if (riding >= 0) {
211 const n = G.load.indexOf(name) >= 0 ? G.load.length : G.riding.length;
212 return { u: G.ferryU + (n > 1 ? .4 : 0), v: (riding - (Math.max(n, seats() === 1 ? 1 : n) - 1) / 2) * 3.2, z: RAFT_Z, dir: R.at.ferry === Ferry.NEAR ? -1 : 1 };
213 }
214 const side = R.at[name] === Ferry.NEAR ? -1 : 1;
215 return { u: side * (SHORE + 3.2 + (i % 2) * 2.2), v: (i - (crew().length - 1) / 2) * 5.4, z: 0, dir: -side };
216 }
217 function drawAnimal(name, s, eaten) {
218 const at = (du, dv, z) => world(s.u + du * s.dir, s.v + dv, s.z + z), part = (a, b, r0, r1, col) => { capsule(a, b, r0, r1, () => col, 'solid'); pendingShadows.push(a, r0, b, r1); };
219 const ball = (p, r, col) => { sphere(...p, r, col, 'solid'); pendingShadows.push(p, r, p, r); };
220 if (name === 'fox') {
221 for (const du of [-.5, .4]) part(at(du, 0, 0), at(du, 0, .7), .16, .14, DARK);
222 part(at(-.9, 0, .95), at(.5, 0, 1), .5, .45, FOX);
223 ball(at(1, 0, 1.4), .42, FOX); ball(at(1.4, 0, 1.3), .18, DARK);
224 ball(at(.85, -.2, 1.8), .15, FOX); ball(at(.85, .2, 1.8), .15, FOX);
225 part(at(-.9, 0, .95), at(-1.8, 0, 1.3), .25, .2, FOX); ball(at(-1.9, 0, 1.35), .22, WHITE);
226 } else if (name === 'goose') {
227 for (const du of [-.1, .3]) part(at(du, 0, 0), at(du, 0, .5), .1, .1, BEAK);
228 part(at(-.6, 0, 1.1), at(.4, 0, 1.1), .65, .6, WHITE);
229 part(at(.5, 0, 1.4), at(.85, 0, 2.5), .22, .2, WHITE);
230 ball(at(.9, 0, 2.7), .3, WHITE); part(at(1.1, 0, 2.65), at(1.6, 0, 2.55), .13, .09, BEAK);
231 ball(at(-1.1, 0, 1.4), .3, WHITE);
232 } else if (name === 'grain') {
233 ball(at(0, 0, .85), .85, SACK); ball(at(0, 0, 1.6), .32, SACK_TIE);
234 for (const du of [-.55, 0, .55]) part(at(0, 0, 1.7), at(du, 0, 2.9), .13, .1, EAR);
235 } else {
236 for (const du of [-.6, .6]) part(at(du, 0, 0), at(du, 0, .7), .17, .15, DOG);
237 part(at(-.8, 0, 1), at(.6, 0, 1.05), .55, .5, DOG);
238 ball(at(1.1, 0, 1.6), .46, DOG); ball(at(1.55, 0, 1.45), .22, DARK);
239 ball(at(.95, .3, 1.55), .22, DARK);
240 part(at(-.8, 0, 1.1), at(-1.4, 0, 1.9), .16, .12, DOG);
241 }
242 if (eaten) for (const dz of [0, .7]) ball(at(.3 - dz * .3, 0, 3.4 + dz), .22, BONE);
243 }
244 function glyph(sx, sy, ch, pixel) {
245 const g = GLYPHS[ch];
246 for (let k = 0; k < 15; k++) if (g[k] === '1') for (let dy = 0; dy < 2; dy++) for (let dx = 0; dx < 2; dx++) {
247 const x = sx + (k % 3) * 2 + dx, y = sy + Math.floor(k / 3) * 2 + dy;
248 if (x >= 0 && y >= 0 && x < W && y < H) pix[y * W + x] = pixel;
249 }
250 }
251 function label(name, ch) {
252 const s = standing(name), p = project(...world(s.u, s.v, s.z + 4));
253 const x = Math.round(p.sx) - 3, y = Math.round(p.sy) - 5;
254 for (const [dx, dy] of [[-1, 0], [1, 0], [0, -1], [0, 1], [-1, -1], [1, 1], [-1, 1], [1, -1]]) glyph(x + dx, y + dy, ch, INK_PIX);
255 glyph(x, y, ch, LABEL_PIX);
256 }
257 function draw() {
258 pix.set(bakedPix);
259 zb.set(bakedZ);
260 pendingShadows.length = 0;
261 ripples();
262 drawFerry();
263 const names = crew();
264 names.forEach(name => { if (!(R.eaten && R.eaten.prey === name)) drawAnimal(name, standing(name), false); });
265 flushShadows();
266 applyShadows(groundZ);
267 shadeEdges();
268 names.forEach((name, i) => label(name, i + 1));
269 if (R.eaten) { // a red cross over the bank where it happened
270 const s = standing(R.eaten.hunter), p = project(...world(s.u, s.v, s.z + 5.6)), x = Math.round(p.sx), y = Math.round(p.sy);
271 for (let k = -3; k <= 3; k++) for (const [a, b] of [[k, k], [k, -k]]) for (const d of [0, 1]) { const px = x + a + d, py = y + b; if (px >= 0 && py >= 0 && px < W && py < H) pix[py * W + px] = LOST_PIX; }
272 }
273 ctx.putImageData(image, 0, 0);
274 }
275
276 /* ---------- game ---------- */
277 const STATUS_HINT = 'tap a passenger to load it, then tap the ferry to cross';
278 function line() {
279 if (R.over) return `${R.line} · tap or press a key to ${R.outcome === 'won' && R.level < lastLevel ? 'go on to the next level' : 'play again'}`;
280 const aboard = G.load.length ? `on the ferry: ${G.load.join(' and ')} · ` : '';
281 return aboard + R.line;
282 }
283 function finish(report) {
284 if (report.outcome === 'won') {
285 sound(520, .3, 'sine'); sound(780, .5, 'sine', .15);
286 try { localStorage.setItem(LEVEL_KEY, String(Math.min(R.level + 1, lastLevel))); } catch (err) { /* private window: keep it for this visit */ }
287 } else sound(110, .6, 'sawtooth');
288 }
289 function begin(next) {
290 R = next; G.load = []; G.riding = []; G.ferryU = targetU();
291 renderHud();
292 note(STATUS_HINT);
293 }
294 function restart() {
295 ensureAudio();
296 const next = R.outcome === 'won' && R.level < lastLevel ? Ferry.newGame(R.level + 1) : Ferry.again(R);
297 if (next) begin(next);
298 }
299 // pick or put down a passenger; the ferry's seat count is read from the level, the crossing is judged by the rules
300 function toggle(name) {
301 ensureAudio();
302 if (R.over) { restart(); return; }
303 if (busy() || !name) return;
304 if (G.load.includes(name)) { G.load = G.load.filter(n => n !== name); sound(300, .08, 'triangle'); note(`the ${name} steps off`); return; }
305 if (R.at[name] !== R.at.ferry) { sound(140, .15, 'sawtooth'); note(`the ${name} is on the other bank`); return; }
306 if (G.load.length >= seats()) { sound(140, .15, 'sawtooth'); note(`the ferry has ${seats()} ${seats() === 1 ? 'seat' : 'seats'}`); return; }
307 G.load.push(name); sound(420, .08, 'triangle'); note(`the ${name} steps aboard`);
308 }
309 function sail() {
310 ensureAudio();
311 if (R.over) { restart(); return; }
312 if (busy()) return;
313 const riders = G.load.slice(), out = Ferry.cross(R, riders.length ? riders : null);
314 if (out.event.type === 'refused') { sound(140, .2, 'sawtooth'); note(out.event.reason); return; }
315 R = out.state; G.riding = riders; G.load = [];
316 sound(200, .25, 'triangle');
317 renderHud();
318 if (R.over) { finish(Ferry.report(R)); G.noteUntil = 0; }
319 setText('status', line());
320 }
321 function update(dt) {
322 G.time += dt;
323 const to = targetU(), step = SPEED * dt;
324 G.ferryU = Math.abs(to - G.ferryU) <= step ? to : G.ferryU + Math.sign(to - G.ferryU) * step;
325 if (!busy()) G.riding = [];
326 if (R.over || G.time >= G.noteUntil) setText('status', line());
327 }
328
329 /* ---------- input ---------- */
330 // the passenger whose body is nearest the point, or null; the ferry counts when the point is on its deck
331 function passengerAt(px, py) {
332 let best = null, reach = 13;
333 for (const name of crew()) {
334 const s = standing(name), p = project(...world(s.u, s.v, s.z + 1.4)), d = Math.hypot(px - p.sx, py - p.sy);
335 if (d < reach) { reach = d; best = name; }
336 }
337 return best;
338 }
339 function onFerry(px, py) {
340 const g = unproject(px, py + RAFT_Z * S * COS), u = (g.x - g.y) / R2, v = (g.x + g.y) / R2;
341 return Math.abs(u - G.ferryU) <= RAFT_U + .8 && Math.abs(v) <= RAFT_V + .8;
342 }
343 const centreOf = name => { const s = standing(name), p = project(...world(s.u, s.v, s.z + 1.4)); return [p.sx, p.sy]; };
344 const ferryAt = () => { const p = project(...world(G.ferryU, RAFT_V - .6, RAFT_Z)); return [p.sx, p.sy]; };
345 canvas.addEventListener('pointerdown', e => {
346 canvas.focus({ preventScroll: true });
347 const r = canvas.getBoundingClientRect(), px = (e.clientX - r.left) / r.width * W, py = (e.clientY - r.top) / r.height * H;
348 if (R.over) { restart(); return; }
349 const name = passengerAt(px, py);
350 if (name) toggle(name); else if (onFerry(px, py)) sail();
351 });
352 canvas.addEventListener('keydown', e => {
353 const n = parseInt(e.key, 10);
354 const pick = n >= 1 && n <= 4 && e.key.length === 1, cross = e.key === ' ' || e.key === 'Enter';
355 if (!pick && !cross) return;
356 e.preventDefault();
357 if (e.repeat) return;
358 if (pick) toggle(crew()[n - 1]); else sail();
359 });
360
361 /* ---------- sound ---------- */
362 let audio = null, muted = false;
363 function ensureAudio() {
364 if (audio) { if (audio.state === 'suspended') audio.resume(); return; }
365 const AC = window.AudioContext || window.webkitAudioContext;
366 if (AC) audio = new AC();
367 }
368 function sound(freq, life, type, delay = 0) {
369 if (!audio || muted) return;
370 const now = audio.currentTime + delay, gain = audio.createGain(), osc = audio.createOscillator();
371 osc.type = type;
372 osc.frequency.setValueAtTime(freq, now);
373 gain.gain.setValueAtTime(.0001, now);
374 gain.gain.exponentialRampToValueAtTime(.07, now + .01);
375 gain.gain.exponentialRampToValueAtTime(.0005, now + life);
376 osc.connect(gain).connect(audio.destination);
377 osc.start(now); osc.stop(now + life + .02);
378 }
379 const muteButton = document.getElementById('mute');
380 muteButton.addEventListener('click', () => {
381 muted = !muted;
382 muteButton.textContent = muted ? 'sound off' : 'sound on';
383 muteButton.setAttribute('aria-pressed', String(muted));
384 });
385
386 /* ---------- fit and boot ---------- */
387 addEventListener('resize', fit);
388 fit();
389 bake();
390 note(STATUS_HINT);
391 renderHud();
392 canvas.focus({ preventScroll: true });
393 let last = performance.now();
394 function frame(now) {
395 update(Math.min(.04, (now - last) / 1000));
396 last = now;
397 draw();
398 requestAnimationFrame(frame);
399 }
400 requestAnimationFrame(frame);
401 </script>
402 </body>
403 </html>
index.html +1
@@ -104,6 +104,7 @@ footer a::after { content: none; }
104104 <li data-kind="Sport" data-input="Drag" style="--accent:#4f7f3f"><a href="bowls-green/">Bowls Green</a><span>Drag back to set line and weight and curve your woods in close to the jack</span><span>Game forged by the crew</span><span class="tags">Sport · Drag</span></li>
105105 <li data-kind="Racing" data-input="Drag" style="--accent:#2e8a7a"><a href="dinghy-race/">Dinghy Race</a><span>Drag to trim the sail to the wind and round three buoys ahead of the fleet</span><span>Game forged by the crew</span><span class="tags">Racing · Drag</span></li>
106106 <li data-kind="Memory" data-input="Tap" style="--accent:#7d9a4a"><a href="seed-packets/">Seed Packets</a><span>Tap to turn over seed packets and match every pair before the gardener comes back</span><span>Game forged by the crew</span><span class="tags">Memory · Tap</span></li>
107 <li data-kind="Strategy" data-input="Tap" style="--accent:#4f7f6a"><a href="ferryman/">Ferryman</a><span>Row the fox, the goose and the grain across without leaving the wrong pair alone</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
107108 <li data-kind="Strategy" data-input="Tap" style="--accent:#5a6e8a"><a href="lock-keeper/">Lock Keeper</a><span>Work the paddles and gates to bring every narrowboat through the flight of locks</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
108109 <li data-kind="Strategy" data-input="Tap" style="--accent:#3a5fa8"><a href="empire/">Empire Age</a><span>A real-time strategy game against a bot: gather, build, climb four ages, train an army and destroy the enemy town center</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
109110 <li data-kind="Precision" data-input="Hold" style="--accent:#d0453c"><a href="hot-air-balloon/">Hot Air Balloon</a><span>Five flights over the farms: hold the burner to climb into a different wind, land on the cross for 5</span><span>Game forged by the crew</span><span class="tags">Precision · Hold</span></li>
og/ferryman.png added
Binary file not shown.
og/home.png
Binary file not shown.
rounds.mjs +8
@@ -144,6 +144,14 @@ export const ROUNDS = {
144144 if (pair) { g.tap(...pair[0]); g.tap(...pair[1]); }
145145 g.run(.9);
146146 } },
147 // follow the rules' own shortest solution: load who it names, then take the ferry across
148 'ferryman': { over: /Everyone is across/, outcome: /Everyone is across in \d+ of par \d+/, beat: g => {
149 if (g.read('busy()')) { g.run(.3); return; }
150 const load = g.read('Ferry.solve(R.level)[R.crossings]');
151 for (const name of [].concat(load ?? [])) { g.tap(...g.read(`centreOf(${JSON.stringify(name)})`)); g.run(.1); }
152 g.tap(...g.read('ferryAt()'));
153 g.run(.3);
154 } },
147155 // work the fewest operations that win (found by a search from the state on the page), each by the keys: Left and Right to the lock, then 1 to 5
148156 'lock-keeper': { over: /play again/, outcome: /All \d+ boats through in \d+ operations/, beat: g => {
149157 for (const op of solve(g.read('R'))) {
serve.test.mjs +7
@@ -458,6 +458,13 @@ test('Dinghy Race and its rules script are served without a track', async () =>
458458 expect((await fetch(base + '/dinghy-race/dinghy.js')).status).toBe(200);
459459 });
460460
461 test('Ferryman and its rules script are served without a track', async () => {
462 const page = await fetch(base + '/ferryman/');
463 expect(page.status).toBe(200);
464 expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8');
465 expect((await fetch(base + '/ferryman/ferry.js')).status).toBe(200);
466 });
467
461468 test('Seed Packets and its rules script are served without a track', async () => {
462469 const page = await fetch(base + '/seed-packets/');
463470 expect(page.status).toBe(200);
shell.js +1
@@ -44,6 +44,7 @@ window.PixelPlays = (() => {
4444 { id: 'bowls-green', title: 'Bowls Green', blurb: 'Drag back to set line and weight and curve your woods in close to the jack', kind: 'Sport', input: 'Drag', accent: '#4f7f3f', music: false, forged: true },
4545 { id: 'dinghy-race', title: 'Dinghy Race', blurb: 'Drag to trim the sail to the wind and round three buoys ahead of the fleet', kind: 'Racing', input: 'Drag', accent: '#2e8a7a', music: false, forged: true },
4646 { id: 'seed-packets', title: 'Seed Packets', blurb: 'Tap to turn over seed packets and match every pair before the gardener comes back', kind: 'Memory', input: 'Tap', accent: '#7d9a4a', music: false, forged: true },
47 { id: 'ferryman', title: 'Ferryman', blurb: 'Row the fox, the goose and the grain across without leaving the wrong pair alone', kind: 'Strategy', input: 'Tap', accent: '#4f7f6a', music: false, forged: true },
4748 { id: 'lock-keeper', title: 'Lock Keeper', blurb: 'Work the paddles and gates to bring every narrowboat through the flight of locks', kind: 'Strategy', input: 'Tap', accent: '#5a6e8a', music: false, forged: true },
4849 { id: 'empire', title: 'Empire Age', blurb: 'A real-time strategy game against a bot: gather, build, climb four ages, train an army and destroy the enemy town center', kind: 'Strategy', input: 'Tap', accent: '#3a5fa8', music: false, forged: true },
4950 { id: 'hot-air-balloon', title: 'Hot Air Balloon', blurb: 'Five flights over the farms: hold the burner to climb into a different wind, land on the cross for 5', kind: 'Precision', input: 'Hold', accent: '#d0453c', music: false, forged: true },

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs