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

Migrated from github.com/amirmushichge/pixel-plays

Add Lily Pond: the playable page and its place in the catalogue, on the rules in `lily-pond/pond.js` #186

Merged opened this

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

Merged

vesper/pixel-plays:vesper/167-add-lily-pond-the-playable-page-and-its → main 7 commits fork

  • Merged. vesper/167-add-lily-pond-the-playable-page-and-its was merged into main as 6826f87.

Review

Sign in to review this change.
8 files changed +328 −3
README.md +3 −2
@@ -61,6 +61,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am
6161 | [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 |
6262 | [Cloakroom](cloakroom/) | A coat check with two rails of coats, each with a paper tag: turn two tags at a time, a matching pair is handed back and a mismatch turns back after 0.8 s; three rounds of 6, 8 and 10 pairs, 90 seconds each, and more than 12 mismatches in all (or a clock at zero) ends it; the coats sway and light moves under the door, the number and colour on a turned tag mean it plays muted too (forged by the crew on the engine and shell above, not by the original creators) | Tap a coat; arrows move a ring, space or enter turns |
6363 | [Tower Duel](tower-duel/) | A 90-second two-lane card battle against a seeded rival on a field split by a river with a bridge in each lane: elixir fills over time (twice as fast in the last 30 seconds), pick a card from a hand of four (Knight, Archers, Giant, Goblins, Brute, Fireball) and put its troops on your half, and they walk over a bridge to fight and hit the rival towers; Fireball lands anywhere; toppling the rival king tower wins at once, otherwise more towers down, then more tower health, wins on the clock; a homage to Supercell's Clash Royale in idea only (forged by the crew on the engine and shell above, not by the original creators; rules in `tower-duel/duel.js`) | Tap a card, then tap your half; 1-4 to pick, arrows move a ring, Space plays |
64 | [Lily Pond](lily-pond/) | Six levels on a six-by-six pond: the frog starts on a lily pad and hops north, east, south or west to the nearest pad in that line, up to three squares away, and the pad it leaves sinks; land on every pad once (level n has n + 3 pads) and the level is cleared, but a frog with no pad left in reach loses the level, which restarts as the same pond and costs a retry; clearing all six levels with three retries or fewer wins, and a seventh retry ends the game (forged by the crew on the engine and shell above, not by the original creators; rules in `lily-pond/pond.js`) | Swipe or tap beside the frog; arrow keys |
6465 | [Hedge Maze](hedge-maze/) | A garden maze of hedges carved from a seed, 5 by 5 cells for the first and one cell larger for each one solved, up to 12 by 12: walk from the gate to the stone fountain at the far end of the only path, one cell a step, before the gardener's bell rings 45 seconds after each maze begins (the bell starts afresh with every maze); solving 5 or more by the last bell wins, rules in `hedge-maze/maze.js`; the fountain splashes (forged by the crew on the engine and shell above, not by the original creators) | Swipe or tap beside the walker; arrow keys |
6566
6667 ## Run
@@ -81,7 +82,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is
8182 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.
8283
8384 ## Add a game
84 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, 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`.
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`.
8586
8687 - `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.
8788 - `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.
@@ -98,7 +99,7 @@ Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules
9899 - Depth-buffer edges: darker where an object sits in front, a warm rim on upper-left edges.
99100 - Large flat surfaces use closely spaced tones; wide steps make the dither read as a checkerboard.
100101 - Characters stay sharp: flat bands with no dither, a dark silhouette on their own pixels, patterns at least 3px wide.
101 - 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), 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`.
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`.
102103
103104 ## Empire Age
104105
index.html +1
@@ -114,6 +114,7 @@ footer a::after { content: none; }
114114 <li data-kind="Racing" data-input="Hold" style="--accent:#e0a526"><a href="go-kart/">Go-Kart Fete</a><span>Hold to race, let go for the bends: three laps round the hay bales against three rivals</span><span>Game forged by the crew</span><span class="tags">Racing · Hold</span></li>
115115 <li data-kind="Memory" data-input="Tap" style="--accent:#9c3d6b"><a href="cloakroom/">Cloakroom</a><span>Turn two tags at a time and hand back every matching coat before the dance lets out</span><span>Game forged by the crew</span><span class="tags">Memory · Tap</span></li>
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>
117 <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>
117118 <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>
118119 <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>
119120 </ul>
lily-pond/index.html added +309
@@ -0,0 +1,309 @@
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>Lily Pond</title>
7 <!-- og:begin -->
8 <meta name="description" content="Hop the frog onto every lily pad once before they sink">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/lily-pond/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Lily Pond">
13 <meta property="og:description" content="Hop the frog onto every lily pad once before they sink">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/lily-pond/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/lily-pond.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="Lily Pond: 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: #2f7a6a; }
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 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 button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
40 noscript p { position: fixed; inset: 40% 16px auto; margin: 0; text-align: center; color: var(--muted); }
41 </style>
42 </head>
43 <body>
44 <div id="stage"><canvas id="c" tabindex="0" aria-label="A pond of lily pads with a frog on one of them. Swipe or tap beside the frog, or use the arrow keys, to hop north, east, south or west to the nearest pad within three squares; the pad you leave sinks. Land on every pad once before you are stuck, six levels."></canvas></div>
45 <noscript><p>Lily Pond needs JavaScript to play.</p></noscript>
46 <div id="scores">
47 <div class="row"><b id="level">1</b><span>level of 6</span></div>
48 <div class="row"><b id="pads">3</b><span>pads left</span></div>
49 <div class="row"><b id="retries">0</b><span>retries</span></div>
50 </div>
51 <div class="hud" id="bottom">
52 <div id="status" role="status" aria-live="polite"></div>
53 <button id="mute" type="button" aria-pressed="false">sound on</button>
54 </div>
55 <script src="../shell.js"></script>
56 <script>
57 PixelPlays.mount({
58 id: 'lily-pond',
59 rules: [
60 'Swipe or tap beside the frog, or press an arrow key, to hop that way.',
61 'A hop lands on the nearest pad in that line, up to 3 squares off; the pad behind sinks.',
62 'Land on every pad once to clear the level; stuck means a retry.',
63 'Clear all 6 levels with 3 retries or fewer to win.',
64 ],
65 });
66 </script>
67 <script>window.PP_SCENE = { originY: 8, shadowX: 1.3, shadowY: -.12 };</script>
68 <script src="../engine.js"></script>
69 <script src="pond.js"></script>
70 <script>
71 'use strict';
72
73 const K = 4.4, SIZE = LilyPond.SIZE, MID = SIZE / 2; // engine units per square; the pond is SIZE squares each way
74 const PAD_R = .38, RIPPLE_LIFE = .8, HOP_LIFE = .16; // pad radius in squares; seconds
75 const WATER = [64, 134, 172], WATER_ALT = [72, 144, 182], BANK = [196, 180, 132], REED = [96, 132, 84];
76 const PAD = [74, 160, 92], PAD_LIT = [112, 190, 104], PAD_RIM = [30, 84, 62], FROG = [186, 220, 60], FLOWER = [236, 120, 160];
77 const INK_PIX = rgb(28, 27, 25), EYE_PIX = rgb(255, 255, 255), RING_PIX = rgb(214, 238, 250);
78 const FACING = { north: [0, -1], east: [1, 0], south: [0, 1], west: [-1, 0] };
79 const KEY_DIR = { ArrowUp: 'north', ArrowRight: 'east', ArrowDown: 'south', ArrowLeft: 'west' };
80
81 // a square (or point between squares) of the pond to engine units and back; squares are centred on the half
82 const eng = (gx, gy, z) => { const u = (gx - MID) * K, v = (gy - MID) * K; return [(u + v) / R2, (v - u) / R2, z]; };
83 const scr = (gx, gy, z = 0) => { const p = project(...eng(gx, gy, z)); return [p.sx, p.sy]; };
84 const cell = (x, y) => [x + .5, y + .5];
85
86 /* ---------- state ---------- */
87 const nodes = {};
88 for (const k of ['level', 'pads', 'retries', '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 fresh = () => LilyPond.start(Math.floor(Math.random() * 4294967296));
96 let P = fresh();
97 // from: where the frog was drawn when the last hop began; ripples: the pads that have sunk; face: the way it looks
98 const G = { time: 0, noteUntil: 0, hopAge: HOP_LIFE, from: cell(P.frog.x, P.frog.y), face: 'south', ripples: [], down: null, end: '' };
99 const REFUSED = { 'no-pad': 'no pad that way, within 3 squares', over: 'the pond is done', 'bad-direction': 'swipe or use the arrows' };
100
101 function renderHud() {
102 setText('level', String(P.level));
103 setText('pads', String(P.pads.length - 1));
104 setText('retries', String(P.retries));
105 }
106 function note(text) { setText('status', text); G.noteUntil = G.time + 1.8; }
107 const endLine = () => `${P.line} · tap or press a key to play again`;
108
109 /* ---------- baked scene ---------- */
110 function groundColor(x, y, ix, iy) {
111 const u = (x - y) / R2, v = (x + y) / R2, gx = MID + u / K, gy = MID + v / K;
112 const e = .55; // the bank around the water, in squares
113 if (gx < -e || gx > SIZE + e || gy < -e || gy > SIZE + e) return 0;
114 const t = .96 + (hash(ix, iy) - .5) * .06;
115 const shade = c => rgb(c[0] * t, c[1] * t, c[2] * t);
116 if (gx < 0 || gx > SIZE || gy < 0 || gy > SIZE) return shade(hash(ix >> 1, iy >> 1) < .3 ? REED : BANK);
117 return shade((ix + iy) & 4 ? WATER : WATER_ALT);
118 }
119 function bake() {
120 ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0);
121 tufts.length = 0; leaves.length = 0;
122 zb.fill(-1e9);
123 pix.fill(rgb(255, 255, 255));
124 for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) {
125 const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy);
126 if (!c) continue;
127 pix[i] = c; ground[i] = 1;
128 zb[i] = (g.x + g.y) / R2 * COS;
129 }
130 groundZ.set(zb);
131 bakeOcclusion();
132 staticShadow.set(shadowMask);
133 applyShadows(groundZ);
134 bakedPix.set(pix);
135 bakedZ.set(zb);
136 }
137
138 /* ---------- drawing ---------- */
139 // a flat lily pad, painted straight into the buffers: a disc with a wedge cut out, a lit upper-left and a dark rim
140 function drawPad(gx, gy, flower) {
141 const [cx, cy] = scr(gx, gy, .2), d = project(...eng(gx, gy, .2)).d;
142 const rx = PAD_R * K * S, ry = rx * SIN;
143 for (let iy = Math.floor(cy - ry); iy <= Math.ceil(cy + ry); iy++) for (let ix = Math.floor(cx - rx); ix <= Math.ceil(cx + rx); ix++) {
144 if (ix < 0 || iy < 0 || ix >= W || iy >= H) continue;
145 const dx = (ix + .5 - cx) / rx, dy = (iy + .5 - cy) / ry, n = dx * dx + dy * dy;
146 if (n > 1) continue;
147 if (dx > 0 && dy > 0 && dy < dx * .5 && dy > dx * .1) continue; // the notch, open to the right
148 const i = iy * W + ix;
149 zb[i] = d;
150 const rim = n > .72, lit = dx + dy < -.35;
151 pix[i] = rim ? rgb(...PAD_RIM) : lit ? rgb(...PAD_LIT) : rgb(...PAD);
152 }
153 if (flower) dynamicAdd(eng(gx - .1, gy - .05, .2), eng(gx - .1, gy - .05, .5), .3, .22, () => FLOWER);
154 }
155 // the frog: a squat body and two eyes that stand above its head, looking the way it last hopped
156 function drawFrog(gx, gy, lift) {
157 const [fx, fy] = FACING[G.face];
158 dynamicAdd(eng(gx, gy, .3 + lift), eng(gx, gy, .7 + lift), .9, .75, () => FROG);
159 for (const side of [-1, 1]) {
160 const ex = gx + side * .2 + fx * .1, ey = gy + fy * .14;
161 dynamicAdd(eng(ex, ey, 1.2 + lift), eng(ex, ey, 1.25 + lift), .32, .32, () => FROG);
162 dynamicAdd(eng(ex + fx * .08, ey + fy * .08 + .05, 1.35 + lift), eng(ex + fx * .08, ey + fy * .08 + .05, 1.4 + lift), .17, .17, () => [250, 250, 250]);
163 }
164 }
165 function ring(gx, gy, r, color) {
166 const pts = [], n = Math.max(24, Math.round(r * 60));
167 for (let i = 0; i < n; i++) { const a = i / n * Math.PI * 2, [sx, sy] = scr(gx + Math.cos(a) * r, gy + Math.sin(a) * r); pts.push([Math.round(sx), Math.round(sy)]); }
168 drawDots(pts, color);
169 }
170 // bright dashes ride the water and shift four times a second; under reduced motion they stay put
171 function drawGlints() {
172 const step = STILL ? 0 : Math.floor(G.time * 4);
173 for (let i = 0; i < 12; i++) {
174 const gx = .2 + hash(i, step % 7) * (SIZE - .4), gy = .2 + hash(step % 7, i + 9) * (SIZE - .4);
175 const [sx, sy] = scr(gx, gy);
176 for (let d = 0; d < 3; d++) { const x = Math.round(sx) + d, y = Math.round(sy); if (x >= 0 && x < W && y >= 0 && y < H && ground[y * W + x] && zb[y * W + x] === bakedZ[y * W + x]) pix[y * W + x] = rgb(206, 232, 246); }
177 }
178 }
179 // the sinking pad's ripple: two rings widening from where it was; it is play, so it moves under reduced motion too
180 function drawRipples() {
181 for (const r of G.ripples) {
182 const k = r.age / RIPPLE_LIFE;
183 ring(r.x, r.y, PAD_R + k * 1.1, RING_PIX);
184 if (k > .25) ring(r.x, r.y, PAD_R + (k - .25) * 1.1, RING_PIX);
185 }
186 }
187 function draw() {
188 pix.set(bakedPix);
189 zb.set(bakedZ);
190 pendingShadows.length = 0;
191 for (const p of P.pads) { const [gx, gy] = cell(p.x, p.y); drawPad(gx, gy, hash(p.x + 3, p.y) < .35 && !(p.x === P.frog.x && p.y === P.frog.y)); }
192 const k = Math.min(1, G.hopAge / HOP_LIFE), [tx, ty] = cell(P.frog.x, P.frog.y);
193 drawFrog(G.from[0] + (tx - G.from[0]) * k, G.from[1] + (ty - G.from[1]) * k, Math.sin(k * Math.PI) * 1.6);
194 flushShadows();
195 applyShadows(bakedZ);
196 shadeEdges();
197 drawGlints();
198 drawRipples();
199 ctx.putImageData(image, 0, 0);
200 }
201
202 /* ---------- game ---------- */
203 function hop(dir) {
204 ensureAudio();
205 if (P.status !== 'playing') return;
206 const before = cell(P.frog.x, P.frog.y), r = LilyPond.hop(P, dir);
207 if (!r.ok) { note(REFUSED[r.why] || 'cannot hop that way'); sound(120, .08, 'square'); return; }
208 const seen = G.hopAge >= HOP_LIFE ? before : [G.from[0] + (before[0] - G.from[0]) * Math.min(1, G.hopAge / HOP_LIFE), G.from[1] + (before[1] - G.from[1]) * Math.min(1, G.hopAge / HOP_LIFE)];
209 P = r.state; G.face = dir;
210 G.ripples.push({ x: before[0], y: before[1], age: 0 });
211 sound(r.event === 'cleared' ? 660 : 380, .1, 'sine');
212 if (r.event === 'cleared') { G.from = cell(P.frog.x, P.frog.y); G.hopAge = HOP_LIFE; note(`Level ${P.level - 1} cleared`); sound(880, .25, 'sine', .1); }
213 else if (r.event === 'lost') { G.from = cell(P.frog.x, P.frog.y); G.hopAge = HOP_LIFE; note('Stuck: the pads sank. Same pond, try again'); sound(110, .4, 'sawtooth'); }
214 else { G.from = seen; G.hopAge = 0; }
215 if (r.event === 'over') { G.end = endLine(); G.noteUntil = 0; sound(P.line.startsWith('Pond cleared') ? 780 : 110, .5, 'sine'); }
216 renderHud();
217 }
218 function restart() {
219 P = fresh(); G.ripples.length = 0; G.from = cell(P.frog.x, P.frog.y); G.hopAge = HOP_LIFE; G.face = 'south'; G.end = '';
220 note('swipe, tap beside the frog, or use the arrows');
221 renderHud();
222 }
223 function update(dt) {
224 G.time += dt;
225 G.hopAge += dt;
226 for (const r of G.ripples) r.age += dt;
227 G.ripples = G.ripples.filter(r => r.age < RIPPLE_LIFE);
228 renderHud();
229 if (P.status !== 'playing') { setText('status', endLine()); return; }
230 if (G.time < G.noteUntil) return;
231 setText('status', P.line);
232 }
233
234 /* ---------- input ---------- */
235 const point = e => { const r = canvas.getBoundingClientRect(); return [(e.clientX - r.left) / r.width * W, (e.clientY - r.top) / r.height * H]; };
236 // the way from one canvas point to another, on the pond's own squares; null when it is too short to mean anything
237 function direction(dx, dy, min) {
238 const ax = dx / (K * S), ay = dy / (K * S * SIN);
239 if (Math.max(Math.abs(ax), Math.abs(ay)) < min) return null;
240 return Math.abs(ax) >= Math.abs(ay) ? (ax > 0 ? 'east' : 'west') : (ay > 0 ? 'south' : 'north');
241 }
242 canvas.addEventListener('pointerdown', e => {
243 canvas.focus({ preventScroll: true });
244 canvas.setPointerCapture?.(e.pointerId);
245 G.down = point(e);
246 });
247 canvas.addEventListener('pointerup', e => {
248 const from = G.down;
249 G.down = null;
250 if (!from) return;
251 if (P.status !== 'playing') { restart(); return; }
252 const to = point(e), swipe = Math.hypot(to[0] - from[0], to[1] - from[1]) >= 14;
253 let dir;
254 if (swipe) dir = direction(to[0] - from[0], to[1] - from[1], .1);
255 else { const [fx, fy] = scr(...cell(P.frog.x, P.frog.y)); dir = direction(to[0] - fx, to[1] - fy, .35); }
256 if (dir) hop(dir); else note('tap beside the frog, or swipe');
257 });
258 canvas.addEventListener('pointercancel', () => { G.down = null; });
259 canvas.addEventListener('keydown', e => {
260 const dir = KEY_DIR[e.key], play = e.key === ' ' || e.key === 'Enter';
261 if (!dir && !play) return;
262 e.preventDefault();
263 if (P.status !== 'playing') { if (!e.repeat) restart(); return; }
264 if (dir && !e.repeat) hop(dir);
265 });
266
267 /* ---------- sound ---------- */
268 let audio = null, muted = false;
269 function ensureAudio() {
270 if (audio) { if (audio.state === 'suspended') audio.resume(); return; }
271 const AC = window.AudioContext || window.webkitAudioContext;
272 if (AC) audio = new AC();
273 }
274 function sound(freq, life, type, delay = 0) {
275 if (!audio || muted) return;
276 const now = audio.currentTime + delay, gain = audio.createGain(), osc = audio.createOscillator();
277 osc.type = type;
278 osc.frequency.setValueAtTime(freq, now);
279 gain.gain.setValueAtTime(.0001, now);
280 gain.gain.exponentialRampToValueAtTime(.07, now + .01);
281 gain.gain.exponentialRampToValueAtTime(.0005, now + life);
282 osc.connect(gain).connect(audio.destination);
283 osc.start(now); osc.stop(now + life + .02);
284 }
285 const muteButton = document.getElementById('mute');
286 muteButton.addEventListener('click', () => {
287 muted = !muted;
288 muteButton.textContent = muted ? 'sound off' : 'sound on';
289 muteButton.setAttribute('aria-pressed', String(muted));
290 });
291
292 /* ---------- fit and boot ---------- */
293 addEventListener('resize', fit);
294 fit();
295 bake();
296 note('swipe, tap beside the frog, or use the arrows');
297 renderHud();
298 canvas.focus({ preventScroll: true });
299 let last = performance.now();
300 function frame(now) {
301 update(Math.min(.04, (now - last) / 1000));
302 last = now;
303 draw();
304 requestAnimationFrame(frame);
305 }
306 requestAnimationFrame(frame);
307 </script>
308 </body>
309 </html>
og/home.png
Binary file not shown.
og/lily-pond.png added
Binary file not shown.
rounds.mjs +6
@@ -128,6 +128,12 @@ export const ROUNDS = {
128128 if (index >= 0) { g.press(String(index + 1)); g.tap(...g.read(`scr(${x}, 9)`)); }
129129 g.run(.2);
130130 } },
131 // hop along the route the rules planned for this pond, one arrow key per pad
132 'lily-pond': { over: /play again/, outcome: /Pond cleared: 6 levels, \d+ retries?/, beat: g => {
133 const [a, b] = g.read('[P.route[P.hops], P.route[P.hops + 1]]');
134 if (b) g.press(b.x > a.x ? 'ArrowRight' : b.x < a.x ? 'ArrowLeft' : b.y > a.y ? 'ArrowDown' : 'ArrowUp', .04);
135 else g.run(.1);
136 } },
131137 // lift and set down along the rules' own shortest solution of the yard, with the number keys
132138 'shunting-yard': { over: /play again/, outcome: /Won: 5 levels cleared in \d+ moves/, beat: g => {
133139 const [from, to] = g.read('Yard.solve(P)[0]');
serve.test.mjs +7
@@ -528,6 +528,13 @@ test('Tower Duel and its rules script are served without a track', async () => {
528528 expect((await fetch(base + '/tower-duel/duel.js')).status).toBe(200);
529529 });
530530
531 test('Lily Pond and its rules script are served without a track', async () => {
532 const page = await fetch(base + '/lily-pond/');
533 expect(page.status).toBe(200);
534 expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8');
535 expect((await fetch(base + '/lily-pond/pond.js')).status).toBe(200);
536 });
537
531538 test('Shunting Yard and its rules script are served without a track', async () => {
532539 const page = await fetch(base + '/shunting-yard/');
533540 expect(page.status).toBe(200);
shell.js +2 −1
@@ -1,7 +1,7 @@
11 'use strict';
22 // Shared chrome for every game: game menu (top centre) and rules popup (top right).
33 window.PixelPlays = (() => {
4 // add a game here and give it a folder, a one-line `blurb`, a `kind` (Sport, Throwing, Timing, Catching, Precision, Racing, Memory, Strategy), an `input` (Tap, Hold, Drag) and an `accent` colour for its card (the home page lists it from here) (`music: false` when it has no track, `forged: true` when it was made on the forge rather than by the original creators); `soon` entries show in the menu but do not link
4 // add a game here and give it a folder, a one-line `blurb`, a `kind` (Sport, Throwing, Timing, Catching, Precision, Racing, Memory, Strategy, Puzzle), an `input` (Tap, Hold, Drag, Keys) and an `accent` colour for its card (the home page lists it from here) (`music: false` when it has no track, `forged: true` when it was made on the forge rather than by the original creators); `soon` entries show in the menu but do not link
55 const GAMES = [
66 { id: 'balote', title: 'Balote', blurb: 'Bocce against a bot, first to 5', kind: 'Throwing', input: 'Drag', accent: '#d9a441' },
77 { id: 'stari-most', title: 'Stari Most', blurb: 'Five dives off the old bridge, flip and enter the water vertically', kind: 'Timing', input: 'Hold', accent: '#3f8fb5' },
@@ -54,6 +54,7 @@ window.PixelPlays = (() => {
5454 { id: 'go-kart', title: 'Go-Kart Fete', blurb: 'Hold to race, let go for the bends: three laps round the hay bales against three rivals', kind: 'Racing', input: 'Hold', accent: '#e0a526', music: false, forged: true },
5555 { id: 'cloakroom', title: 'Cloakroom', blurb: 'Turn two tags at a time and hand back every matching coat before the dance lets out', kind: 'Memory', input: 'Tap', accent: '#9c3d6b', music: false, forged: true },
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 },
57 { 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 },
5758 { 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 },
5859 { 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 },
5960 ];

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs