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

Migrated from github.com/amirmushichge/pixel-plays

Add Hedge Maze: the playable page and its place in the catalogue, on the rules in `hedge-maze/maze.js` #184

Merged opened this

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

Merged

vesper/pixel-plays:vesper/151-add-hedge-maze-the-playable-page-and-its → main 4 commits fork

  • Merged. vesper/151-add-hedge-maze-the-playable-page-and-its was merged into main as 9435c25.

Review

Sign in to review this change.
8 files changed +357 −4
README.md +3 −2
@@ -59,6 +59,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am
5959 | [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 |
6060 | [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 |
6161 | [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 |
62 | [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 |
6263
6364 ## Run
6465 Requires [Node.js](https://nodejs.org/); nothing to install.
@@ -78,7 +79,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is
7879 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.
7980
8081 ## Add a game
81 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 and Allotment 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`.
82 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 and Allotment 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`.
8283
8384 - `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.
8485 - `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.
@@ -95,7 +96,7 @@ Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules
9596 - Depth-buffer edges: darker where an object sits in front, a warm rim on upper-left edges.
9697 - Large flat surfaces use closely spaced tones; wide steps make the dither read as a checkerboard.
9798 - Characters stay sharp: flat bands with no dither, a dark silhouette on their own pixels, patterns at least 3px wide.
98 - 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 Allotment's planted crops sway (the planting is play); all of it stops under `prefers-reduced-motion`.
99 - 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); all of it stops under `prefers-reduced-motion`.
99100
100101 ## Empire Age
101102
hedge-maze/index.html added +330
@@ -0,0 +1,330 @@
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>Hedge Maze</title>
7 <!-- og:begin -->
8 <meta name="description" content="Find the way through the hedges to the fountain before the gardener rings the bell">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/hedge-maze/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Hedge Maze">
13 <meta property="og:description" content="Find the way through the hedges to the fountain before the gardener rings the bell">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/hedge-maze/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/hedge-maze.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="Hedge Maze: 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: #3d6e4f; }
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" width="360" height="280" tabindex="0" aria-label="A hedge maze seen from above at an angle: a walker in a red shirt starts at one corner and a stone fountain with a water jet stands at the far end. Swipe or tap beside the walker to step that way, or use the arrow keys, and reach the fountain before the gardener rings the bell; each solved maze is larger."></canvas></div>
43 <div id="scores">
44 <div class="row"><b id="maze">1</b><span>maze</span></div>
45 <div class="row"><b id="clock">45</b><span>seconds on the bell</span></div>
46 <div class="row"><b id="solved">0/5</b><span>solved</span></div>
47 <div class="row"><b id="best">0</b><span>best</span></div>
48 </div>
49 <div class="hud" id="bottom">
50 <div id="status" role="status" aria-live="polite"></div>
51 <button id="mute" type="button" aria-pressed="false">sound on</button>
52 </div>
53 <script src="../shell.js"></script>
54 <script>
55 PixelPlays.mount({
56 id: 'hedge-maze',
57 rules: [
58 'Swipe, or tap beside the walker, to step that way; the arrow keys step too.',
59 'Reach the fountain before the gardener rings the bell, 45 seconds a maze.',
60 'Each solved maze is a size larger; solve 5 to win.',
61 ],
62 });
63 </script>
64 <script>window.PP_SCENE = { originY: 14, shadowX: 1.3, shadowY: -.12 };</script>
65 <script src="../engine.js"></script>
66 <script src="maze.js"></script>
67 <script>
68 'use strict';
69
70 const HEDGE = [50, 104, 62], GRAVEL = [216, 198, 152], GATE = [176, 168, 154], LAWN = [96, 138, 70];
71 const STONE = [208, 204, 198], WATER = [96, 170, 226], SPLASH = [214, 238, 255];
72 const SHIRT = { shirt: [204, 58, 48], stripe: [244, 226, 196], legs: [58, 58, 92], skin: [232, 190, 150], hair: [58, 40, 30] };
73 const SPAN = 18, HEDGE_H = .8, WALKER = .4, BEST_KEY = 'pixel-plays-hedge-maze-best';
74 const BODY_Z = .55;
75
76 /* ---------- state ---------- */
77 const best0 = (() => { try { const n = parseInt(localStorage.getItem(BEST_KEY), 10); return Number.isFinite(n) && n > 0 ? n : 0; } catch (e) { return 0; } })();
78 let P = HedgeMaze.newGame(Date.now() & 0xffff, best0);
79 const G = { time: 0, noteUntil: 0, maze: null, x: 0, y: 0, yaw: Math.PI / 4, moving: 0, pointer: null, saved: best0 };
80 const nodes = {};
81 for (const k of ['maze', 'clock', 'solved', 'best', 'status']) nodes[k] = document.getElementById(k);
82 const shown = {};
83 function setText(key, text) {
84 if (shown[key] === text) return;
85 shown[key] = text;
86 nodes[key].textContent = text;
87 }
88 function renderHud() {
89 setText('maze', String(P.solved + 1));
90 setText('clock', String(Math.ceil(P.time)));
91 setText('solved', `${P.solved}/${P.target}`);
92 setText('best', String(P.best));
93 if (P.status !== 'playing') setText('status', `${P.line} · tap or press a key to play again`);
94 else if (G.time >= G.noteUntil) setText('status', P.line);
95 }
96 function note(text) { setText('status', text); G.noteUntil = G.time + .9; }
97
98 /* ---------- where the cells are ---------- */
99 const cellSize = () => SPAN / P.maze.w;
100 const centreOf = i => {
101 const w = P.maze.w, c = cellSize();
102 return [-SPAN / 2 + (i % w + .5) * c, -SPAN / 2 + (Math.floor(i / w) + .5) * c];
103 };
104
105 /* ---------- baked scene ---------- */
106 function groundColor(x, y, ix, iy) {
107 const half = SPAN / 2;
108 if (Math.abs(x) > half + .6 || Math.abs(y) > half + .6) return 0;
109 const t = .95 + (hash(ix, iy) - .5) * .09;
110 const inside = Math.abs(x) <= half && Math.abs(y) <= half;
111 let c = inside ? GRAVEL : LAWN;
112 if (inside) {
113 const c0 = cellSize(), cx = Math.min(P.maze.w - 1, Math.floor((x + half) / c0)), cy = Math.min(P.maze.h - 1, Math.floor((y + half) / c0));
114 if (cx === 0 && cy === 0) c = GATE;
115 }
116 return rgb(c[0] * t, c[1] * t, c[2] * t);
117 }
118 // every closed side of every cell is a hedge: north and west for all cells, south and east on the outer rim
119 function hedgeWalls() {
120 const { w, h, cells } = P.maze, c = cellSize(), t = Math.min(.28, c * .16), half = SPAN / 2, walls = [];
121 for (let cy = 0; cy < h; cy++) for (let cx = 0; cx < w; cx++) {
122 const m = cells[cy * w + cx], x = -half + cx * c, y = -half + cy * c;
123 if (!(m & HedgeMaze.N)) walls.push([x - t / 2, y - t / 2, x + c + t / 2, y + t / 2]);
124 if (!(m & HedgeMaze.W)) walls.push([x - t / 2, y - t / 2, x + t / 2, y + c + t / 2]);
125 if (cy === h - 1 && !(m & HedgeMaze.S)) walls.push([x - t / 2, y + c - t / 2, x + c + t / 2, y + c + t / 2]);
126 if (cx === w - 1 && !(m & HedgeMaze.E)) walls.push([x + c - t / 2, y - t / 2, x + c + t / 2, y + c + t / 2]);
127 }
128 return walls;
129 }
130 function bakeHedges() {
131 const walls = hedgeWalls();
132 walls.forEach(([x0, y0, x1, y1], k) => {
133 box(x0, y0, 0, x1, y1, HEDGE_H, HEDGE, k);
134 const long = Math.max(x1 - x0, y1 - y0), n = Math.max(1, Math.round(long / .5));
135 for (let s = 0; s <= n; s++) {
136 const x = x0 + (x1 - x0) * s / n, y = y0 + (y1 - y0) * s / n;
137 castShadow(x, y, HEDGE_H, .22, 1, 0);
138 castShadow(x, y, HEDGE_H * .5, .22, 1, 0);
139 }
140 });
141 }
142 function bake() {
143 ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0);
144 tufts.length = 0; leaves.length = 0;
145 zb.fill(-1e9);
146 pix.fill(rgb(255, 255, 255));
147 for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) {
148 const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy);
149 if (!c) continue;
150 pix[i] = c; ground[i] = 1;
151 zb[i] = (g.x + g.y) / R2 * COS;
152 }
153 groundZ.set(zb);
154 bakeHedges();
155 bakeOcclusion();
156 staticShadow.set(shadowMask);
157 applyShadows(groundZ);
158 bakedPix.set(pix);
159 bakedZ.set(zb);
160 }
161
162 /* ---------- the walker and the fountain ---------- */
163 function drawWalker(step) {
164 const gait = G.moving ? Math.sin(G.time * 22) : 0;
165 figure(G.x, G.y, G.yaw, { scale: Math.min(.7, Math.max(WALKER, cellSize() * .2)), stance: .2 + gait * .28, armL: gait * .5, armR: -gait * .5 }, SHIRT, dynamicAdd);
166 }
167 // a round stone basin, a column and a bowl: round and pale among the square green hedges, with a jet that splashes
168 function drawFountain(step) {
169 const [fx, fy] = centreOf(P.fountain), rb = Math.min(1, cellSize() * .36);
170 for (let k = 0; k < 12; k++) {
171 const a = k / 12 * Math.PI * 2, b = (k + 1) / 12 * Math.PI * 2;
172 dynamicAdd([fx + Math.cos(a) * rb, fy + Math.sin(a) * rb, .22], [fx + Math.cos(b) * rb, fy + Math.sin(b) * rb, .22], .11, .11, () => STONE);
173 }
174 for (let j = -3; j <= 3; j++) {
175 const d = j * rb * .24, half = Math.sqrt(Math.max(0, (rb * .9) ** 2 - d * d));
176 dynamicAdd([fx - half, fy + d, .2], [fx + half, fy + d, .2], .1, .1, () => WATER);
177 }
178 dynamicAdd([fx, fy, .2], [fx, fy, 1.1], .13, .09, () => STONE);
179 dynamicAdd([fx - .22, fy, 1.12], [fx + .22, fy, 1.12], .1, .1, () => STONE);
180 dynamicAdd([fx, fy, 1.1], [fx, fy, 1.5], .05, .05, () => SPLASH);
181 // droplets leave the top and fall into the basin, stepped at 8 fps; one fixed ring of them when motion is reduced
182 for (let k = 0; k < 6; k++) {
183 const phase = STILL ? (k % 3) / 3 : ((step + k * 2) % 6) / 6, a = k / 6 * Math.PI * 2 + (STILL ? 0 : hash(k, 5) * .4);
184 const out = rb * .85 * phase, z = 1.5 - 1.3 * phase * phase;
185 const p = [fx + Math.cos(a) * out, fy + Math.sin(a) * out, z];
186 dynamicAdd(p, p, .07, .07, () => SPLASH);
187 }
188 }
189
190 function draw() {
191 pix.set(bakedPix);
192 zb.set(bakedZ);
193 pendingShadows.length = 0;
194 const step = STILL ? 0 : Math.floor(G.time * WIND_FPS);
195 drawFountain(step);
196 drawWalker(step);
197 flushShadows();
198 applyShadows(bakedZ);
199 shadeEdges();
200 ctx.putImageData(image, 0, 0);
201 }
202
203 /* ---------- game ---------- */
204 const HINT = 'swipe or tap beside the walker to step';
205 function enterMaze() {
206 G.maze = P.maze;
207 [G.x, G.y] = centreOf(P.pos);
208 G.moving = 0;
209 bake();
210 }
211 function saveBest() {
212 if (P.best <= G.saved) return;
213 G.saved = P.best;
214 try { localStorage.setItem(BEST_KEY, String(P.best)); } catch (e) { /* private window: keep it for this visit */ }
215 }
216 function stepTo(dir) {
217 ensureAudio();
218 if (P.status !== 'playing') {
219 P = HedgeMaze.newGame(Date.now() & 0xffff, P.best);
220 enterMaze(); note(HINT); renderHud();
221 return;
222 }
223 const r = HedgeMaze.step(P, dir);
224 if (!r.ok) { if (r.why === 'hedge') { sound(130, .12, 'sawtooth'); note('a hedge'); } return; }
225 const fresh = r.state.maze !== P.maze;
226 P = r.state;
227 if (fresh) {
228 sound(660, .25, 'sine'); sound(990, .35, 'sine', .08);
229 enterMaze(); note(`maze solved · ${P.solved} of ${P.target}`);
230 } else {
231 sound(300 + (P.pos % 5) * 20, .06, 'triangle');
232 G.yaw = Math.atan2(HedgeMaze.DIRS[dir].dy, HedgeMaze.DIRS[dir].dx);
233 }
234 saveBest();
235 renderHud();
236 }
237 function update(dt) {
238 G.time += dt;
239 const was = P.status;
240 P = HedgeMaze.tick(P, dt);
241 if (was === 'playing' && P.status !== 'playing') {
242 if (P.status === 'won') { sound(520, .3, 'sine'); sound(780, .5, 'sine', .15); } else sound(110, .6, 'sawtooth');
243 saveBest();
244 }
245 // the walker eases to the middle of its cell; its feet move only while it does
246 const [tx, ty] = centreOf(P.pos), k = Math.min(1, dt * 16);
247 G.x += (tx - G.x) * k; G.y += (ty - G.y) * k;
248 G.moving = Math.hypot(tx - G.x, ty - G.y) > .04 ? 1 : 0;
249 renderHud();
250 }
251
252 /* ---------- input ---------- */
253 // a point on the screen, relative to the walker, as one of the four ways along the paths
254 function dirFromScreen(dx, dy) {
255 const u = dx / S, v = dy / (S * SIN), gx = (u + v) / R2, gy = (v - u) / R2;
256 if (Math.hypot(gx, gy) < .05) return null;
257 return Math.abs(gx) > Math.abs(gy) ? (gx > 0 ? 'east' : 'west') : (gy > 0 ? 'south' : 'north');
258 }
259 const toCanvas = e => {
260 const r = canvas.getBoundingClientRect();
261 return { x: (e.clientX - r.left) / r.width * W, y: (e.clientY - r.top) / r.height * H };
262 };
263 canvas.addEventListener('pointerdown', e => {
264 canvas.focus({ preventScroll: true });
265 canvas.setPointerCapture(e.pointerId);
266 G.pointer = toCanvas(e);
267 });
268 canvas.addEventListener('pointerup', e => {
269 const from = G.pointer;
270 G.pointer = null;
271 if (!from) return;
272 const to = toCanvas(e), swiped = Math.hypot(to.x - from.x, to.y - from.y) >= 14;
273 if (swiped) { const d = dirFromScreen(to.x - from.x, to.y - from.y); if (d) stepTo(d); return; }
274 const me = project(G.x, G.y, BODY_Z), d = dirFromScreen(to.x - me.sx, to.y - me.sy);
275 if (d || P.status !== 'playing') stepTo(d || 'north');
276 });
277 canvas.addEventListener('pointercancel', () => { G.pointer = null; });
278 // up is the way up the screen to the right, and so on round: the arrows turn with the picture
279 const KEYS = { ArrowUp: 'north', ArrowRight: 'east', ArrowDown: 'south', ArrowLeft: 'west' };
280 canvas.addEventListener('keydown', e => {
281 const dir = KEYS[e.key];
282 if (!dir && e.key !== ' ' && e.key !== 'Enter') return;
283 e.preventDefault();
284 if (e.repeat) return;
285 stepTo(dir || 'north');
286 });
287
288 /* ---------- sound ---------- */
289 let audio = null, muted = false;
290 function ensureAudio() {
291 if (audio) { if (audio.state === 'suspended') audio.resume(); return; }
292 const AC = window.AudioContext || window.webkitAudioContext;
293 if (AC) audio = new AC();
294 }
295 function sound(freq, life, type, delay = 0) {
296 if (!audio || muted) return;
297 const now = audio.currentTime + delay, gain = audio.createGain(), osc = audio.createOscillator();
298 osc.type = type;
299 osc.frequency.setValueAtTime(freq, now);
300 gain.gain.setValueAtTime(.0001, now);
301 gain.gain.exponentialRampToValueAtTime(.07, now + .01);
302 gain.gain.exponentialRampToValueAtTime(.0005, now + life);
303 osc.connect(gain).connect(audio.destination);
304 osc.start(now); osc.stop(now + life + .02);
305 }
306 const muteButton = document.getElementById('mute');
307 muteButton.addEventListener('click', () => {
308 muted = !muted;
309 muteButton.textContent = muted ? 'sound off' : 'sound on';
310 muteButton.setAttribute('aria-pressed', String(muted));
311 });
312
313 /* ---------- fit and boot ---------- */
314 addEventListener('resize', fit);
315 fit();
316 enterMaze();
317 note(HINT);
318 renderHud();
319 canvas.focus({ preventScroll: true });
320 let last = performance.now();
321 function frame(now) {
322 update(Math.min(.04, (now - last) / 1000));
323 last = now;
324 draw();
325 requestAnimationFrame(frame);
326 }
327 requestAnimationFrame(frame);
328 </script>
329 </body>
330 </html>
index.html +1
@@ -113,6 +113,7 @@ footer a::after { content: none; }
113113 <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>
114114 <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>
115115 <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>
116 <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>
116117 </ul>
117118 <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>
118119 </main>
og/hedge-maze.png added
Binary file not shown.
og/home.png
Binary file not shown.
rounds.mjs +13
@@ -128,6 +128,19 @@ 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 // walk the one path to the fountain by the arrow keys, maze after maze; once five are solved, wait out the bell
132 'hedge-maze': { over: /play again/, outcome: /\d+ mazes solved, best \d+\. You win!/, beat: g => {
133 const s = g.read('P');
134 if (s.status !== 'playing' || s.solved >= s.target) { g.run(5); return; }
135 const { w, cells } = s.maze, keys = [['ArrowUp', 1, -w], ['ArrowRight', 2, 1], ['ArrowDown', 4, w], ['ArrowLeft', 8, -1]];
136 const from = new Map([[s.pos, null]]), queue = [s.pos];
137 for (let q = 0; q < queue.length && !from.has(s.fountain); q++) {
138 for (const [key, bit, by] of keys) if (cells[queue[q]] & bit && !from.has(queue[q] + by)) { from.set(queue[q] + by, [queue[q], key]); queue.push(queue[q] + by); }
139 }
140 const path = [];
141 for (let at = s.fountain; from.get(at); at = from.get(at)[0]) path.unshift(from.get(at)[1]);
142 for (const key of path) g.press(key);
143 } },
131144 'free-throw': { over: /play again/, outcome: /\d+ of 30/, beat: g => { g.hold(...MID, .6); g.run(.45); g.tap(...MID); g.run(1.5); g.tap(...MID); } },
132145 // dive the way the taker leans, once the tell shows
133146 'goalkeeper': { over: /play again/, outcome: /you win: \d+ saves/, beat: g => {
serve.test.mjs +9 −2
@@ -328,8 +328,8 @@ test('every game has a kind, input and accent, and the static list carries them'
328328 delete globalThis.PixelPlays;
329329 }
330330 for (const g of games) {
331 expect(['Sport', 'Throwing', 'Timing', 'Catching', 'Precision', 'Racing', 'Memory', 'Strategy']).toContain(g.kind);
332 expect(['Tap', 'Hold', 'Drag']).toContain(g.input);
331 expect(['Sport', 'Throwing', 'Timing', 'Catching', 'Precision', 'Racing', 'Memory', 'Strategy', 'Puzzle']).toContain(g.kind);
332 expect(['Tap', 'Hold', 'Drag', 'Keys']).toContain(g.input);
333333 expect(g.accent).toMatch(/^#[0-9a-f]{6}$/i);
334334 expect(html).toContain(`<li data-kind="${g.kind}" data-input="${g.input}" style="--accent:${g.accent}"><a href="${g.id}/">`);
335335 expect(html).toContain(`<span class="tags">${g.kind} · ${g.input}</span>`);
@@ -521,6 +521,13 @@ test('Tower Duel and its rules script are served without a track', async () => {
521521 expect((await fetch(base + '/tower-duel/duel.js')).status).toBe(200);
522522 });
523523
524 test('Hedge Maze and its rules script are served without a track', async () => {
525 const page = await fetch(base + '/hedge-maze/');
526 expect(page.status).toBe(200);
527 expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8');
528 expect((await fetch(base + '/hedge-maze/maze.js')).status).toBe(200);
529 });
530
524531 test('Hot Air Balloon and its rules script are served without a track', async () => {
525532 const page = await fetch(base + '/hot-air-balloon/');
526533 expect(page.status).toBe(200);
shell.js +1
@@ -53,6 +53,7 @@ window.PixelPlays = (() => {
5353 { 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 },
5454 { 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 },
5555 { 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 },
56 { 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 },
5657 ];
5758 const MUSIC_VOLUME = .4;
5859 const CREDITS = [

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs