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

Migrated from github.com/amirmushichge/pixel-plays

Add Bunting: the playable page and its place in the catalogue, on the rules in `bunting/line.js` #214

Merged opened this

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

Merged

vesper/pixel-plays:vesper/190-add-bunting-the-playable-page-and-its-pl → main 2 commits fork

  • Merged. vesper/190-add-bunting-the-playable-page-and-its-pl was merged into main as 95e8cf7.

Review

Sign in to review this change.
8 files changed +399 −2
README.md +3 −2
@@ -57,6 +57,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am
5757 | [Allotment](allotment/) | A five by five garden of raised beds with a bench holding the next seed packet: tap a bed to plant the packet there (or arrow keys to move and Space to plant); twelve packets in a season and every crop scores 1 plus its own rule for each touching bed (up, down, left, right): beans +3 per sweetcorn, sweetcorn -1 per sweetcorn, carrots -2 per onion, onion +2 per lettuce, lettuce +2 per carrots; 28 points by the last packet wins, against the best layout the rules could find (a seeded hand of eight seasons; forged by the crew on the engine and shell above, not by the original creators; rules in `allotment/plot.js`) | Tap a bed; arrows + Space |
5858 | [Shunting Yard](shunting-yard/) | A railway yard seen from above: a mixed-up train of numbered wagons waits on the arrival track, two sidings hold 3 wagons each, and the departure track takes the wagons only in order 1, 2, 3...; lift the end wagon of a track and set it down on another (nothing goes back to the arrival track), five levels of 3 to 7 wagons, each with a move target (5, 7, 9, 11, 13) that every yard solves within, and the game is won when all five are cleared within the targets' total; every wagon wears its number on a plate, so order never rests on colour (forged by the crew on the engine and shell above, not by the original creators; rules in `shunting-yard/yard.js`) | Tap a track to lift its end wagon, tap another to set it down; 1-4 pick the tracks, arrows move a ring, Space lifts or sets down |
5959 | [Ferris Wheel](ferris-wheel/) | A fairground Ferris wheel of 8 gondolas, 3 seats each, with a platform at the bottom and a queue of 20 riders of different weights and ride lengths: tap Board (or the canvas, or press B, Space or Enter) to seat the front rider in the gondola at the platform, or Skip (or S) to send them to the back of the queue, once each; the wheel steps one gondola on a steady beat, 24 steps in all, and riders step off when their ride is done; a balance needle under the hub shows the imbalance (weight times its lever arm about the hub, summed over every rider) with the jam limit marked as a line, and the wheel jams if it passes it; carry 12 riders without a jam to win, the HUD showing riders carried, steps left and the imbalance; rider weights read by size as well as colour (green, amber, red), the front rider's weight is on a plate, and the fairground lights blink (stopped under reduced motion) (forged by the crew on the engine and shell above, not by the original creators; rules in `ferris-wheel/wheel.js`) | Tap Board or Skip; B boards, S skips |
60 | [Bunting](bunting/) | Five village greens, each with more strings of bunting and more hooks (2 strings of 4 up to 6 of 8), some hooks already hung with a fixed pegged flag: hang the rest so that no two neighbours share a pattern, whether next to each other on a string or joined by a cord where two strings cross; three patterns (pennant, square, circle) and a fourth (diamond) from level 4, each differing by shape as well as colour; tap a hook to cycle its flag, or move with the arrow keys and press 1 to 4 (0 takes it down); each flag hung is a move, taking one down is free, a clash is marked by a red line as well as colour, and all five greens within 160 moves wins (forged by the crew on the engine and shell above, not by the original creators; rules in `bunting/line.js`) | Tap; arrows, 1 to 4 |
6061 | [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 |
6162 | [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 |
6263 | [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 |
@@ -84,7 +85,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is
8485 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.
8586
8687 ## Add a game
87 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, Curling Rink, Shunting Yard and Ferris Wheel play on their own sound effects). Rules that need testing go in a plain script with a `.test.mjs` beside it, as in `kite-hill/model.js`.
88 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, Curling Rink, Shunting Yard, Ferris Wheel and Bunting 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`.
8889
8990 - `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.
9091 - `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.
@@ -101,7 +102,7 @@ Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules
101102 - Depth-buffer edges: darker where an object sits in front, a warm rim on upper-left edges.
102103 - Large flat surfaces use closely spaced tones; wide steps make the dither read as a checkerboard.
103104 - Characters stay sharp: flat bands with no dither, a dark silhouette on their own pixels, patterns at least 3px wide.
104 - 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, Curling Rink's crowd breathes and its ice glints, Go-Kart Fete's chequered flags flutter and its spectators wave, Egg Basket's hens peck and the straw in its basket stirs (its rolling eggs are play, not ambience, and still move), Ferris Wheel's fairground lights blink, and Dinghy Race's water ripples come and go and its start-line flags flutter (the boats are play, and still sail), and Coconut Shy's bunting flutters and its stallholder shifts and waves (the thrown ball and wobbling coconuts are play, and still move), and Bowls Green's hedge leaves stir and a cloud shadow drifts across its green (the rolling woods are play, and still move), and Seed Packets' wall clock ticks its second hand and its watering can drips, and Hoopla Stall's bunting flutters (the tossed ring is play, and still moves), and Lock Keeper's water surface ripples (the boats, gates and rising water are play, and still move), and Ferryman's river ripples (the ferry and its passengers are play, and still move), and Tower Duel's river ripples shift and the king towers' pennants stir (the troops and the fireball are play, and still move), and Hedge Maze's fountain splashes (the walker is play, and still moves), and Allotment's planted crops sway (the planting is play), and Lily Pond's water glints shift (the frog, the sinking pads and their ripples are play, and still move), Market Barrow's stall awnings flutter (the barrow is play, and still moves) and Shunting Yard's engine puffs steam (the wagons are play, and still move); all of it stops under `prefers-reduced-motion`.
105 - 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, Curling Rink's crowd breathes and its ice glints, Go-Kart Fete's chequered flags flutter and its spectators wave, Egg Basket's hens peck and the straw in its basket stirs (its rolling eggs are play, not ambience, and still move), Ferris Wheel's fairground lights blink, and Dinghy Race's water ripples come and go and its start-line flags flutter (the boats are play, and still sail), and Coconut Shy's bunting flutters and its stallholder shifts and waves (the thrown ball and wobbling coconuts are play, and still move), and Bowls Green's hedge leaves stir and a cloud shadow drifts across its green (the rolling woods are play, and still move), and Seed Packets' wall clock ticks its second hand and its watering can drips, and Hoopla Stall's bunting flutters (the tossed ring is play, and still moves), and Lock Keeper's water surface ripples (the boats, gates and rising water are play, and still move), and Ferryman's river ripples (the ferry and its passengers are play, and still move), and Tower Duel's river ripples shift and the king towers' pennants stir (the troops and the fireball are play, and still move), and Hedge Maze's fountain splashes (the walker is play, and still moves), and Allotment's planted crops sway (the planting is play), and Lily Pond's water glints shift (the frog, the sinking pads and their ripples are play, and still move), Market Barrow's stall awnings flutter (the barrow is play, and still moves) and Shunting Yard's engine puffs steam (the wagons are play, and still move) and Bunting's flags stir in the wind; all of it stops under `prefers-reduced-motion`.
105106
106107 ## Empire Age
107108
bunting/index.html added +378
@@ -0,0 +1,378 @@
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>Bunting</title>
7 <!-- og:begin -->
8 <meta name="description" content="Hang the flags for the fete so no two neighbours match">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/bunting/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Bunting">
13 <meta property="og:description" content="Hang the flags for the fete so no two neighbours match">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/bunting/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/bunting.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="Bunting: 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: #3d7f6e; }
24 * { box-sizing: border-box; }
25 html, body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
26 html, body { height: 100%; margin: 0; background: var(--paper); color: var(--ink); }
27 body { font: 13px/1.35 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; overflow: hidden; }
28 #stage { position: fixed; inset: 0; display: grid; place-items: center; }
29 canvas { display: block; image-rendering: pixelated; touch-action: none; cursor: pointer; outline: none; }
30 .hud { position: fixed; left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; pointer-events: none; }
31 #scores { position: fixed; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); display: grid; gap: 2px; pointer-events: none; }
32 #bottom { bottom: max(14px, env(safe-area-inset-bottom)); }
33 .row { display: flex; align-items: center; gap: 8px; color: var(--accent); }
34 .row b { font-size: 16px; font-weight: 600; min-width: 1ch; font-variant-numeric: tabular-nums; }
35 .row span { color: var(--muted); }
36 #status { color: var(--muted); min-height: 1.35em; }
37 .acts { display: flex; gap: 22px; align-items: center; }
38 button { pointer-events: auto; font: inherit; color: var(--muted); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; }
39 button.act { color: var(--accent); font-weight: 600; }
40 button:hover, button:focus-visible { color: var(--ink); }
41 button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
42 noscript p { position: fixed; inset: 40% 16px auto; margin: 0; text-align: center; color: var(--muted); }
43 </style>
44 </head>
45 <body>
46 <div id="stage"><canvas id="c" tabindex="0" aria-label="A village green with strings of bunting between posts with lamps. Every hook on a string holds a flag or is bare; each pattern has its own shape as well as colour: pennant, square, circle and diamond. Neighbouring hooks along a string, or joined by a cord between strings, must not match; a clashing pair is joined by a red line. Tap a hook to cycle its pattern, or move with the arrow keys and press 1 to 4 to hang that pattern, 0 to take it down. Flags with a peg underneath are fixed. Clear 5 levels in 160 moves."></canvas></div>
47 <noscript><p>Bunting needs JavaScript to play.</p></noscript>
48 <div id="scores">
49 <div class="row"><b id="level">1 of 5</b><span>level</span></div>
50 <div class="row"><b id="moves">0 of 160</b><span>moves</span></div>
51 <div class="row"><b id="clashes">0</b><span>clashes left</span></div>
52 </div>
53 <div class="hud" id="bottom">
54 <div id="status" role="status" aria-live="polite"></div>
55 <div class="acts">
56 <button id="giveup" class="act" type="button">Give up (G)</button>
57 <button id="mute" type="button" aria-pressed="false">sound on</button>
58 </div>
59 </div>
60 <script src="../shell.js"></script>
61 <script>
62 PixelPlays.mount({
63 id: 'bunting',
64 rules: [
65 'Tap a hook to cycle its flag, or move with the arrows and press 1 to 4.',
66 'No two neighbours may match: along a string, or joined by a cord. Pegged flags are fixed.',
67 'Each flag you hang is a move; taking one down is free.',
68 'Dress all 5 greens in 160 moves to win.',
69 ],
70 });
71 </script>
72 <script>window.PP_SCENE = { originY: 30, shadowX: 1.3, shadowY: -.12 };</script>
73 <script src="../engine.js"></script>
74 <script src="line.js"></script>
75 <script>
76 'use strict';
77
78 const B = window.Bunting;
79 const HOOK_Z = 6.4, SAG = 1, DV = 5.2;
80 const eng = (u, v, z) => [(u + v) / R2, (v - u) / R2, z];
81 const scr = (u, v, z = 0) => { const p = project(...eng(u, v, z)); return [p.sx, p.sy]; };
82
83 const POST = [120, 92, 66], STRING = [236, 226, 200], CORD = [190, 176, 150], LAMP = [255, 222, 120], LAMP_CAP = [70, 66, 62];
84 const LAWN = [[104, 156, 88], [96, 148, 82]];
85 const FLAG_COLOURS = [[205, 70, 70], [236, 188, 60], [70, 124, 200], [150, 92, 176]];
86 const INK_PIX = rgb(28, 27, 25), CLASH_PIX = rgb(214, 36, 36), GRID_PIX = rgb(139, 135, 127), SIGNAL_PIX = rgb(255, 214, 10);
87 const FLAG_PIX = FLAG_COLOURS.map(c => rgb(...c));
88 // one shape per pattern, so colour is never the only way to tell them apart: pennant, square, circle, diamond
89 const SHAPES = [
90 ['#########', '.#######.', '..#####..', '...###...', '....#....'],
91 ['#######', '#######', '#######', '#######', '#######', '#######'],
92 ['..###..', '.#####.', '#######', '#######', '#######', '.#####.', '..###..'],
93 ['...#...', '..###..', '.#####.', '#######', '.#####.', '..###..', '...#...'],
94 ];
95 // each sprite as [dx, dy, edge] pixels, with a one pixel outline around the shape
96 const SPRITES = SHAPES.map(rows => {
97 const w = rows[0].length, on = (x, y) => rows[y]?.[x] === '#', out = [];
98 for (let y = -1; y <= rows.length; y++) for (let x = -1; x <= w; x++) {
99 if (on(x, y)) { out.push([x - (w >> 1), y, false]); continue; }
100 let near = false;
101 for (let dy = -1; dy <= 1; dy++) for (let dx = -1; dx <= 1; dx++) if (on(x + dx, y + dy)) near = true;
102 if (near) out.push([x - (w >> 1), y, true]);
103 }
104 return out;
105 });
106
107 /* ---------- state ---------- */
108 const nodes = {};
109 for (const k of ['level', 'moves', 'clashes', 'status']) nodes[k] = document.getElementById(k);
110 const shown = {};
111 function setText(key, text) {
112 if (shown[key] === text) return;
113 shown[key] = text;
114 nodes[key].textContent = text;
115 }
116 const fresh = () => B.start(Math.floor(Math.random() * 4294967296), 1);
117 let P = fresh();
118 // sel: the hook the keys act on; marks: the clashing pairs of the state on show
119 const G = { time: 0, noteUntil: 0, sel: 0, marks: B.clashes(P) };
120 const stringLength = () => B.lengthIn(P.level), stringCount = () => B.stringsIn(P.level);
121
122 function renderHud() {
123 G.marks = B.clashes(P);
124 setText('level', `${P.level} of ${P.last}`);
125 setText('moves', `${P.totalMoves} of ${B.WIN_MOVES}`);
126 setText('clashes', String(G.marks.length));
127 }
128 function note(text) { setText('status', text); G.noteUntil = G.time + 1.8; }
129 const REFUSED = {
130 fixed: 'that flag is pegged and cannot move', occupied: 'that hook already has a flag', empty: 'that hook is already bare',
131 'bad-pattern': 'there is no such pattern on this level', over: 'the round is over', 'bad-hook': 'no such hook',
132 };
133
134 /* ---------- layout on the green ---------- */
135 const spacing = () => Math.min(5, 28 / (stringLength() - 1));
136 function hookAt(id) {
137 const L = stringLength(), S = stringCount(), h = P.hooks[id], du = spacing();
138 const u = (h.index - (L - 1) / 2) * du, v = (h.string - (S - 1) / 2) * DV + 2;
139 const half = (L - 1) / 2 * du + du * .6, t = (u + half) / (2 * half);
140 return { u, v, z: HOOK_Z + .4 - SAG * 4 * t * (1 - t), half };
141 }
142 // a flag hangs just below its hook: the centre column and the top row of its sprite
143 const flagSpot = id => { const k = hookAt(id), [x, y] = scr(k.u, k.v, k.z); return [Math.round(x), Math.round(y) + 2]; };
144 const centreOf = id => { const [x, y] = flagSpot(id); return [x, y + 3]; };
145
146 /* ---------- baked scene ---------- */
147 const onGreen = (u, v, ix, iy) => Math.abs(u) < 17.5 + (hash(ix, iy) - .5) * 1.4 && v > -13 && v < 16 + (hash(iy, ix) - .5) * 1.2;
148 function groundColor(x, y, ix, iy) {
149 const u = (x - y) / R2, v = (x + y) / R2;
150 if (!onGreen(u, v, ix, iy)) return 0;
151 const c = LAWN[Math.floor((u + 40) / 3) & 1], t = .96 + (hash(ix, iy) - .5) * .06;
152 return rgb(c[0] * t, c[1] * t, c[2] * t);
153 }
154 function bake() {
155 ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0);
156 tufts.length = 0; leaves.length = 0;
157 zb.fill(-1e9);
158 pix.fill(rgb(255, 255, 255));
159 for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) {
160 const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy);
161 if (!c) continue;
162 pix[i] = c; ground[i] = 1;
163 zb[i] = (g.x + g.y) / R2 * COS;
164 }
165 groundZ.set(zb);
166 bakeOcclusion();
167 staticShadow.set(shadowMask);
168 applyShadows(groundZ);
169 bakedPix.set(pix);
170 bakedZ.set(zb);
171 }
172
173 /* ---------- drawing ---------- */
174 const line = (x0, y0, x1, y1) => {
175 const n = Math.max(1, Math.ceil(Math.hypot(x1 - x0, y1 - y0))), pts = [];
176 for (let i = 0; i <= n; i++) pts.push([Math.round(x0 + (x1 - x0) * i / n), Math.round(y0 + (y1 - y0) * i / n)]);
177 return pts;
178 };
179 function drawStrings() {
180 const L = stringLength(), S = stringCount();
181 for (let s = 0; s < S; s++) {
182 const first = hookAt(s * L), v = first.v, half = first.half;
183 const ends = [-half, half].map(u => eng(u, v, HOOK_Z + .4));
184 for (const u of [-half, half]) {
185 dynamicAdd(eng(u, v, 0), eng(u, v, HOOK_Z + .9), .3, .3, () => POST);
186 dynamicAdd(eng(u, v, HOOK_Z + .9), eng(u, v, HOOK_Z + 1.1), .4, .4, () => LAMP_CAP);
187 sphere(...eng(u, v, HOOK_Z + 1.6), .5, LAMP, 'solid');
188 }
189 let prev = ends[0];
190 for (let j = 0; j < L; j++) {
191 const k = hookAt(s * L + j), at = eng(k.u, k.v, k.z);
192 dynamicAdd(prev, at, .08, .08, () => STRING);
193 prev = at;
194 }
195 dynamicAdd(prev, ends[1], .08, .08, () => STRING);
196 }
197 for (const [a, b] of P.links) {
198 if (P.hooks[a].string === P.hooks[b].string) continue;
199 const ka = hookAt(a), kb = hookAt(b);
200 dynamicAdd(eng(ka.u, ka.v, ka.z), eng(kb.u, kb.v, kb.z), .05, .05, () => CORD);
201 }
202 }
203 function stamp(sprite, cx, top, edge, fill) {
204 for (const [dx, dy, isEdge] of sprite) {
205 const x = cx + dx, y = top + dy;
206 if (x >= 0 && x < W && y >= 0 && y < H) pix[y * W + x] = isEdge ? edge : fill;
207 }
208 }
209 // the bunting stirs in the wind in whole pixels, a few times a second; still under reduced motion
210 const sway = id => (STILL ? 0 : Math.round(Math.sin(Math.floor(G.time * 6) * .9 + id * 1.7) * 1.2));
211 function drawFlags() {
212 const bad = new Set(G.marks.flat());
213 for (const [a, b] of G.marks) {
214 const [ax, ay] = centreOf(a), [bx, by] = centreOf(b);
215 drawDots(line(ax, ay, bx, by), CLASH_PIX);
216 drawDots(line(ax, ay + 1, bx, by + 1), CLASH_PIX);
217 }
218 for (const h of P.hooks) {
219 const [x, y] = flagSpot(h.id), f = P.flags[h.id], dx = sway(h.id);
220 if (f === undefined) {
221 // a bare hook: a dotted square to hang something in
222 const pts = [];
223 for (let i = -4; i <= 4; i++) for (const e of [-4, 4]) if ((i + e) % 2 === 0) pts.push([x + i, y + 3 + e], [x + e, y + 3 + i]);
224 drawDots(pts, INK_PIX);
225 continue;
226 }
227 stamp(SPRITES[f], x + dx, y, bad.has(h.id) ? CLASH_PIX : INK_PIX, FLAG_PIX[f]);
228 if (h.fixed) drawDots([[x - 2, y + 9], [x - 1, y + 9], [x, y + 9], [x + 1, y + 9], [x + 2, y + 9], [x - 2, y + 10], [x - 1, y + 10], [x, y + 10], [x + 1, y + 10], [x + 2, y + 10]], INK_PIX); // the peg
229 }
230 const [x, y] = centreOf(G.sel);
231 for (const [r, c] of [[8, INK_PIX], [7, SIGNAL_PIX]]) for (const sx of [-1, 1]) for (const sy of [-1, 1]) {
232 drawDots(line(x + sx * r, y + sy * r, x + sx * (r - 3), y + sy * r), c);
233 drawDots(line(x + sx * r, y + sy * r, x + sx * r, y + sy * (r - 3)), c);
234 }
235 }
236 function draw() {
237 pix.set(bakedPix);
238 zb.set(bakedZ);
239 pendingShadows.length = 0;
240 drawStrings();
241 flushShadows();
242 applyShadows(bakedZ);
243 shadeEdges();
244 drawFlags();
245 ctx.putImageData(image, 0, 0);
246 }
247
248 /* ---------- game ---------- */
249 function finish() {
250 G.noteUntil = 0;
251 setText('status', `${P.line} · tap or press a key to play again`);
252 sound(B.clashes(P).length || P.cleared < P.last ? 90 : 523, .5, P.cleared < P.last ? 'sawtooth' : 'sine');
253 }
254 function apply(r, tone) {
255 if (!r.ok) { note(REFUSED[r.why] || 'cannot do that'); sound(110, .15, 'sawtooth'); return false; }
256 P = r.state; sound(tone, .08, 'triangle');
257 if (r.event === 'cleared') { G.sel = 0; note(`Green dressed · now level ${P.level}`); sound(660, .3, 'sine', .08); }
258 renderHud();
259 if (r.event === 'over') finish();
260 return true;
261 }
262 // hang a pattern on a hook, taking the old flag down first (free) when it holds another
263 function hang(id, pattern) {
264 ensureAudio();
265 if (P.flags[id] === pattern) { note('that flag already hangs there'); return; }
266 if (P.flags[id] !== undefined && pattern < P.patterns && !P.hooks[id].fixed) {
267 const t = B.take(P, id);
268 if (!t.ok) { apply(t); return; }
269 P = t.state;
270 }
271 apply(B.hang(P, id, pattern), 330 + pattern * 80);
272 renderHud();
273 }
274 function takeDown(id) {
275 ensureAudio();
276 apply(B.take(P, id), 200);
277 }
278 // a tap: bare -> pattern 1 -> ... -> last pattern -> bare
279 function cycle(id) {
280 const f = P.flags[id];
281 if (f === undefined) hang(id, 0);
282 else if (f + 1 < P.patterns) hang(id, f + 1);
283 else takeDown(id);
284 }
285 function restart() {
286 P = fresh(); G.sel = 0;
287 note('tap a hook to hang a flag, or use the arrow keys and 1 to 4');
288 renderHud();
289 }
290 function giveUp() {
291 if (P.status !== 'playing') return;
292 apply(B.giveUp(P), 150);
293 }
294 const act = fn => () => { if (P.status !== 'playing') restart(); else fn(); canvas.focus({ preventScroll: true }); };
295 function update(dt) {
296 G.time += dt;
297 if (P.status !== 'playing' || G.time < G.noteUntil) return;
298 setText('status', P.line);
299 }
300
301 /* ---------- input ---------- */
302 const point = e => { const r = canvas.getBoundingClientRect(); return [(e.clientX - r.left) / r.width * W, (e.clientY - r.top) / r.height * H]; };
303 function hookNear(x, y) {
304 let best = -1, far = 15 * 15;
305 for (const h of P.hooks) {
306 const [cx, cy] = centreOf(h.id), d = (cx - x) ** 2 + (cy - y) ** 2;
307 if (d < far) { far = d; best = h.id; }
308 }
309 return best;
310 }
311 canvas.addEventListener('pointerdown', e => {
312 canvas.focus({ preventScroll: true });
313 if (P.status !== 'playing') { restart(); return; }
314 const [x, y] = point(e), id = hookNear(x, y);
315 if (id < 0) { note('tap a hook to change its flag'); return; }
316 G.sel = id;
317 cycle(id);
318 });
319 document.getElementById('giveup').addEventListener('click', act(giveUp));
320 const MOVES = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] };
321 canvas.addEventListener('keydown', e => {
322 if (e.ctrlKey || e.metaKey || e.altKey || e.key === 'Tab') return;
323 e.preventDefault();
324 if (e.repeat) return;
325 if (P.status !== 'playing') { restart(); return; }
326 const L = stringLength(), s = P.hooks[G.sel].string, j = P.hooks[G.sel].index;
327 if (MOVES[e.key]) {
328 const ns = Math.min(stringCount() - 1, Math.max(0, s + MOVES[e.key][1])), nj = Math.min(L - 1, Math.max(0, j + MOVES[e.key][0]));
329 G.sel = ns * L + nj;
330 } else if (/^[1-9]$/.test(e.key)) hang(G.sel, Number(e.key) - 1);
331 else if (e.key === '0' || e.key === 'Backspace' || e.key === 'Delete') takeDown(G.sel);
332 else if (e.key === ' ' || e.key === 'Enter') cycle(G.sel);
333 else if (e.key.toLowerCase() === 'g') giveUp();
334 });
335
336 /* ---------- sound ---------- */
337 let audio = null, muted = false;
338 function ensureAudio() {
339 if (audio) { if (audio.state === 'suspended') audio.resume(); return; }
340 const AC = window.AudioContext || window.webkitAudioContext;
341 if (AC) audio = new AC();
342 }
343 function sound(freq, life, type, delay = 0) {
344 if (!audio || muted) return;
345 const now = audio.currentTime + delay, gain = audio.createGain(), osc = audio.createOscillator();
346 osc.type = type;
347 osc.frequency.setValueAtTime(freq, now);
348 gain.gain.setValueAtTime(.0001, now);
349 gain.gain.exponentialRampToValueAtTime(.07, now + .01);
350 gain.gain.exponentialRampToValueAtTime(.0005, now + life);
351 osc.connect(gain).connect(audio.destination);
352 osc.start(now); osc.stop(now + life + .02);
353 }
354 const muteButton = document.getElementById('mute');
355 muteButton.addEventListener('click', () => {
356 muted = !muted;
357 muteButton.textContent = muted ? 'sound off' : 'sound on';
358 muteButton.setAttribute('aria-pressed', String(muted));
359 });
360
361 /* ---------- fit and boot ---------- */
362 addEventListener('resize', fit);
363 fit();
364 bake();
365 note('tap a hook to hang a flag, or use the arrow keys and 1 to 4');
366 renderHud();
367 canvas.focus({ preventScroll: true });
368 let last = performance.now();
369 function frame(now) {
370 update(Math.min(.04, (now - last) / 1000));
371 last = now;
372 draw();
373 requestAnimationFrame(frame);
374 }
375 requestAnimationFrame(frame);
376 </script>
377 </body>
378 </html>
index.html +1
@@ -119,6 +119,7 @@ footer a::after { content: none; }
119119 <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>
120120 <li data-kind="Strategy" data-input="Tap" style="--accent:#b8475a"><a href="ferris-wheel/">Ferris Wheel</a><span>Seat the queue without tipping the wheel</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
121121 <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>
122 <li data-kind="Strategy" data-input="Tap" style="--accent:#3d7f6e"><a href="bunting/">Bunting</a><span>Hang the flags for the fete so no two neighbours match</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
122123 </ul>
123124 <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>
124125 </main>
og/bunting.png added
Binary file not shown.
og/home.png
Binary file not shown.
rounds.mjs +9
@@ -164,6 +164,15 @@ export const ROUNDS = {
164164 if (g.read('P.status') === 'playing') for (const k of keys) g.press(k);
165165 while (g.read('P.step') === at && g.read('P.status') === 'playing') g.run(.2);
166166 } },
167 // hang the finished hanging the rules hold for each bare hook in turn: arrow keys to the hook, then its pattern's number key
168 'bunting': { over: /play again/, outcome: /Green dressed: 5 levels, \d+ moves/, beat: g => {
169 const [id, want, sel, L, status] = g.read('(() => { const id = P.hooks.find(h => P.flags[h.id] === undefined)?.id; return [id, id === undefined ? 0 : P.solution[id], G.sel, stringLength(), P.status]; })()');
170 if (status !== 'playing' || id === undefined) { g.run(.2); return; }
171 const dj = (id % L) - (sel % L), ds = Math.floor(id / L) - Math.floor(sel / L);
172 if (dj) g.press(dj > 0 ? 'ArrowRight' : 'ArrowLeft', .02);
173 else if (ds) g.press(ds > 0 ? 'ArrowDown' : 'ArrowUp', .02);
174 else g.press(String(want + 1), .02);
175 } },
167176 // hop along the route the rules planned for this pond, one arrow key per pad
168177 'lily-pond': { over: /play again/, outcome: /Pond cleared: 6 levels, \d+ retries?/, beat: g => {
169178 const [a, b] = g.read('[P.route[P.hops], P.route[P.hops + 1]]');
serve.test.mjs +7
@@ -556,6 +556,13 @@ test('Ferris Wheel and its rules script are served without a track', async () =>
556556 expect((await fetch(base + '/ferris-wheel/wheel.js')).status).toBe(200);
557557 });
558558
559 test('Bunting and its rules script are served without a track', async () => {
560 const page = await fetch(base + '/bunting/');
561 expect(page.status).toBe(200);
562 expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8');
563 expect((await fetch(base + '/bunting/line.js')).status).toBe(200);
564 });
565
559566 test('Hedge Maze and its rules script are served without a track', async () => {
560567 const page = await fetch(base + '/hedge-maze/');
561568 expect(page.status).toBe(200);
shell.js +1
@@ -59,6 +59,7 @@ window.PixelPlays = (() => {
5959 { 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 },
6060 { id: 'ferris-wheel', title: 'Ferris Wheel', blurb: 'Seat the queue without tipping the wheel', kind: 'Strategy', input: 'Tap', accent: '#b8475a', music: false, forged: true },
6161 { 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 },
62 { id: 'bunting', title: 'Bunting', blurb: 'Hang the flags for the fete so no two neighbours match', kind: 'Strategy', input: 'Tap', accent: '#3d7f6e', music: false, forged: true },
6263 ];
6364 const MUSIC_VOLUME = .4;
6465 const CREDITS = [

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs