Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Add Allotment: the playable page and its place in the catalogue, on the rules in `allotment/plot.js` #182
Check · Review · Land · Live done — Landed and live in production.
vesper/pixel-plays:vesper/158-add-allotment-the-playable-page-and-its → main 8 commits fork
9 files
changed +350
−5
README.md +4 −3
| @@ -53,6 +53,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am | ||
| 53 | 53 | | [](ferryman/) | A river with a near bank, a far bank and a ferry moored at the near landing: tap a passenger to load or unload it, then tap the ferry to cross (or press 1-4 to pick a passenger and Space to cross); the fox, the goose and the grain start on the near bank, and left alone together on a bank the fox eats the goose and the goose eats the grain, so the ferry carries one at a time; three levels, the later ones add a dog, a two-seat ferry and a crossing limit, and a round is won by getting everyone across in par crossings or fewer, the HUD showing level, crossings and par as the rules report them (forged by the crew on the engine and shell above, not by the original creators; rules in `ferryman/ferry.js`) | Tap; 1-4 and Space | |
| 54 | 54 | | [](sandcastle/) | A square beach with a sandcastle on the far edge, rocks scattered over the sand and the sea along the near edge: tap a sand square to pat down a wall (or move a cursor with the arrow keys and press Space), four walls before each tide, then tap tide (or press Enter) and the water floods every square it can reach from the sea, a little further each time, never through a wall or a rock, and washes away half the walls it touches; keep the castle dry through five tides, the HUD showing the tide, the walls left and the dry squares; input is ignored while the water spreads, the surf line ripples (stopped under reduced motion), and sand, water, walls and rocks differ by texture as well as colour (forged by the crew on the engine and shell above, not by the original creators; rules in `sandcastle/tide.js`) | Tap a sand square, then tide; arrows and Space to build, Enter for the tide | |
| 55 | 55 | | [](lock-keeper/) | A flight of three canal locks climbing left to right, red narrowboats waiting at the bottom to go up and blue ones at the top to come down, in a seeded order (three rounds shipped, each with a par): tap a paddle or gate to work it and a boat to move it into or out of its lock, or Left and Right to pick a lock and 1 to 5 for its top paddle, bottom paddle, top gate, bottom gate and a boat; a gate opens only on level water, a paddle fills or empties the lock but not while the far gate is open, two open paddles flood the lock and lose the round, a refusal says why, and the end shows operations against par (forged by the crew on the engine and shell above, not by the original creators; rules in `lock-keeper/lock.js`) | Tap; Left and Right, 1 to 5 | |
| 56 | | [](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 | | |
| 56 | 57 | | [](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 | |
| 57 | 58 | | [](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 | |
| 58 | 59 | | [](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 | |
| @@ -77,7 +78,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is | ||
| 77 | 78 | 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. |
| 78 | 79 | |
| 79 | 80 | ## Add a game |
| 80 | 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 and Sandcastle Tide 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`. | |
| 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`. | |
| 81 | 82 | |
| 82 | 83 | - `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. |
| 83 | 84 | - `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. |
| @@ -94,7 +95,7 @@ Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules | ||
| 94 | 95 | - Depth-buffer edges: darker where an object sits in front, a warm rim on upper-left edges. |
| 95 | 96 | - Large flat surfaces use closely spaced tones; wide steps make the dither read as a checkerboard. |
| 96 | 97 | - Characters stay sharp: flat bands with no dither, a dark silhouette on their own pixels, patterns at least 3px wide. |
| 97 | - 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); all of it stops under `prefers-reduced-motion`. | |
| 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`. | |
| 98 | 99 | |
| 99 | 100 | ## Empire Age |
| 100 | 101 | |
| @@ -123,4 +124,4 @@ The code is under the [MIT License](LICENSE). The music is not: see [MUSIC.md](M | ||
| 123 | 124 | `rounds.mjs` holds one scripted round per game (a table keyed by game id: a beat of taps, drags, holds or keys, repeated until the HUD line that ends the round appears, watched after every frame). `playtest.test.mjs` plays each script, asserts the end line matches the row's `outcome` pattern (the win or loss, with its number), and that an untouched twin run for as long does not reach that outcome, and fails when a game folder has no script. A new game must add its row there. |
| 124 | 125 | |
| 125 | 126 | ## The town |
| 126 | The home page opens on a small isometric town above the list: one building per game in its accent colour, laid out by `town.js` (pure data, tested) and drawn by `plaza.js` with the colour ramp and dither of the engine (a small copy in `ramp.js`, so the home page loads no renderer; `ramp.test.mjs` fails if the two drift). The look follows the engine and shawn.'s [](https://x.com/zzzzshawn/status/2111546123546661289) reference, as the footer credits. Tap or click a building to play its game; hover it, or hover or focus its card, to lift it and see its name. Search and the kind filter grey out the buildings that no longer match, and those cannot be tapped. The list underneath is the same as ever and remains the way in without scripts and from the keyboard; the canvas is `aria-hidden`, hidden without JavaScript, has its space reserved with `aspect-ratio` (and on a phone is at least 600px wide and scrolls sideways inside the page, so a building stays about thumb-sized), and redraws only when something changes. `plaza.test.mjs` runs the real scripts against a stand-in canvas. | |
| 127 | The home page opens on a small isometric town above the list: one building per game in its accent colour, laid out by `town.js` (pure data, tested) and drawn by `plaza.js` with the colour ramp and dither of the engine (a small copy in `ramp.js`, so the home page loads no renderer; `ramp.test.mjs` fails if the two drift). The look follows the engine and shawn.'s [](https://x.com/zzzzshawn/status/2111546123546661289) reference, as the footer credits. Tap or click a building to play its game; hover it, or hover or focus its card, to lift it and see its name. Search and the kind filter grey out the buildings that no longer match, and those cannot be tapped. The list underneath is the same as ever and remains the way in without scripts and from the keyboard; the canvas is `aria-hidden`, hidden without JavaScript, has its space reserved with `aspect-ratio` (and on a phone is at least 800px wide and scrolls sideways inside the page, so a building stays about thumb-sized), and redraws only when something changes. `plaza.test.mjs` runs the real scripts against a stand-in canvas. |
allotment/index.html added +323
| @@ -0,0 +1,323 @@ | ||
| 1 | ||
| 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>Allotment</title> | |
| 7 | <!-- og:begin --> | |
| 8 | <meta name="description" content="Plant a season of crops where each one scores by its neighbours"> | |
| 9 | <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/allotment/"> | |
| 10 | <meta property="og:type" content="website"> | |
| 11 | <meta property="og:site_name" content="Pixel Plays"> | |
| 12 | <meta property="og:title" content="Allotment"> | |
| 13 | <meta property="og:description" content="Plant a season of crops where each one scores by its neighbours"> | |
| 14 | <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/allotment/"> | |
| 15 | <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/allotment.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="Allotment: the opening scene of the game"> | |
| 20 | <meta name="twitter:card" content="summary_large_image"> | |
| 21 | <!-- og:end --> | |
| 22 | <style> | |
| 23 | :root { : #1c1b19; : #8b877f; : #fff; : #7a8f3a; } | |
| 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(); color: var(); } | |
| 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(); } | |
| 34 | .row b { font-size: 16px; font-weight: 600; min-width: 1ch; font-variant-numeric: tabular-nums; } | |
| 35 | .row span { color: var(); } | |
| 36 | #status { color: var(); min-height: 2.7em; white-space: pre-line; max-width: calc(100% - 100px); } | |
| 37 | button { pointer-events: auto; font: inherit; color: var(); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; } | |
| 38 | button:hover, button:focus-visible { color: var(); } | |
| 39 | </style> | |
| 40 | </head> | |
| 41 | <body> | |
| 42 | <div id="stage"><canvas id="c" tabindex="0" aria-label="A five by five garden of raised beds with a bench to the right holding the next seed packet. Tap a bed to plant the packet there, or move with the arrow keys and press Space. Each crop scores 1 plus its own rule for every touching bed: beans +3 beside sweetcorn, sweetcorn -1 beside sweetcorn, carrots -2 beside onion, onion +2 beside lettuce, lettuce +2 beside carrots. Twelve packets in a season, reach 28 points to win."></canvas></div> | |
| 43 | <div id="scores"> | |
| 44 | <div class="row"><b id="turns">12</b><span>turns left</span></div> | |
| 45 | <div class="row"><b id="score">0</b><span id="goal">points</span></div> | |
| 46 | </div> | |
| 47 | <div class="hud" id="bottom"> | |
| 48 | <div id="status" role="status" aria-live="polite"></div> | |
| 49 | <button id="mute" type="button" aria-pressed="false">sound on</button> | |
| 50 | </div> | |
| 51 | <script src="../shell.js"></script> | |
| 52 | <script> | |
| 53 | PixelPlays.mount({ | |
| 54 | id: 'allotment', | |
| 55 | rules: [ | |
| 56 | 'Tap a bed to plant the next packet there, or move with the arrow keys and press Space. One packet a turn.', | |
| 57 | 'Every crop scores 1, plus its own rule for each touching bed (up, down, left, right; not diagonal).', | |
| 58 | 'Beans +3 per sweetcorn, sweetcorn -1 per sweetcorn, carrots -2 per onion, onion +2 per lettuce, lettuce +2 per carrots.', | |
| 59 | 'Reach the target score by the last packet to win.', | |
| 60 | ], | |
| 61 | }); | |
| 62 | </script> | |
| 63 | <script>window.PP_SCENE = { originY: -6, shadowX: 1.3, shadowY: -.12 };</script> | |
| 64 | <script src="../engine.js"></script> | |
| 65 | <script src="plot.js"></script> | |
| 66 | <script> | |
| 67 | 'use strict'; | |
| 68 | ||
| 69 | const Plot = window.Allotment; | |
| 70 | const EARTH = [92, 66, 48], BOARD = [150, 112, 70], SEEDPAPER = [244, 238, 220], POLE = [150, 112, 70]; | |
| 71 | const GRASS_C = [104, 148, 74]; | |
| 72 | const TONES = { // the colours of each crop, light to dark ramps are made by the engine | |
| 73 | beans: { leaf: [84, 168, 72], pod: [150, 210, 90] }, | |
| 74 | sweetcorn: { leaf: [112, 172, 62], cob: [244, 204, 64] }, | |
| 75 | carrots: { leaf: [96, 170, 78], root: [234, 128, 44] }, | |
| 76 | onion: { leaf: [126, 176, 76], bulb: [214, 170, 196] }, | |
| 77 | lettuce: { heart: [164, 214, 108], leaf: [100, 168, 74] }, | |
| 78 | }; | |
| 79 | const ACCENT_PIX = rgb(122, 143, 58), RING_PIX = rgb(255, 255, 255); | |
| 80 | const PITCH = 3.2, BED = 2.8, FIELD = 9, BENCH = [10.6, 0]; // bed spacing, bed edge, half the ground, where the packet stands | |
| 81 | const cellX = i => (i - (Plot.W - 1) / 2) * PITCH, cellY = j => (j - (Plot.H - 1) / 2) * PITCH; | |
| 82 | ||
| 83 | /* ---------- state ---------- */ | |
| 84 | const SEEDS = [1, 4, 5, 6, 8, 9, 11, 12]; | |
| 85 | let R = Plot.start(SEEDS[0]); | |
| 86 | const G = { time: 0, round: 0, cx: 2, cy: 2, ring: false, noteUntil: 0 }; | |
| 87 | const nodes = {}; | |
| 88 | for (const k of ['turns', 'score', 'goal', '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 | function note(text) { setText('status', text); G.noteUntil = G.time + 3; } | |
| 96 | const nextCrop = () => R.hand[R.planted]; | |
| 97 | ||
| 98 | /* ---------- baked scene: the ground, the beds and the bench ---------- */ | |
| 99 | function groundColor(x, y, ix, iy) { | |
| 100 | const main = Math.max(Math.abs(x), Math.abs(y)) / FIELD; | |
| 101 | const bench = x > FIELD - 1 ? Math.max(Math.abs(x - 10.3) / 2.4, Math.abs(y) / 3.4) : 9; | |
| 102 | const edge = Math.min(main, bench) + (noise(x * 1.1, y * 1.1) - .5) * .06; | |
| 103 | if (edge > 1.03) return 0; | |
| 104 | if (edge > .94 && hash(ix, iy) < (edge - .94) / .09) return 0; | |
| 105 | const t = .95 + (hash(ix, iy) - .5) * .1 + (noise(x * .6, y * .6) - .5) * .14; | |
| 106 | return rgb(GRASS_C[0] * t, GRASS_C[1] * t, GRASS_C[2] * t); | |
| 107 | } | |
| 108 | function bake() { | |
| 109 | ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0); | |
| 110 | tufts.length = 0; leaves.length = 0; | |
| 111 | zb.fill(-1e9); | |
| 112 | pix.fill(rgb(255, 255, 255)); | |
| 113 | for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) { | |
| 114 | const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy); | |
| 115 | if (!c) continue; | |
| 116 | pix[i] = c; ground[i] = 1; | |
| 117 | zb[i] = (g.x + g.y) / R2 * COS; | |
| 118 | } | |
| 119 | groundZ.set(zb); | |
| 120 | for (let j = 0; j < Plot.H; j++) for (let i = 0; i < Plot.W; i++) { | |
| 121 | const x = cellX(i), y = cellY(j), h = BED / 2; | |
| 122 | box(x - h, y - h, 0, x + h, y + h, .34, BOARD, i * 7 + j); | |
| 123 | box(x - h + .22, y - h + .22, .1, x + h - .22, y + h - .22, .4, EARTH, i * 3 + j * 11); | |
| 124 | } | |
| 125 | box(BENCH[0] - 1.6, -2.4, 0, BENCH[0] + 1.6, 2.4, .5, BOARD, 5); | |
| 126 | bakeOcclusion(); | |
| 127 | staticShadow.set(shadowMask); | |
| 128 | applyShadows(groundZ); | |
| 129 | bakedPix.set(pix); | |
| 130 | bakedZ.set(zb); | |
| 131 | } | |
| 132 | ||
| 133 | /* ---------- crops: each its own shape, swaying in whole steps ---------- */ | |
| 134 | const stick = (a, b, r0, r1, c) => dynamicAdd(a, b, r0, r1, () => c); | |
| 135 | function drawCrop(name, x, y, sc = 1) { | |
| 136 | const phase = STILL ? 0 : Math.floor(G.time * WIND_FPS) * .45 + x * .7 + y * 1.1; | |
| 137 | const sw = STILL ? 0 : Math.round(Math.sin(phase) * 3) * .05; // lean at the top, in steps of a twentieth of a bed | |
| 138 | const t = TONES[name], z = k => k * sc; | |
| 139 | if (name === 'beans') { // a teepee of poles with climbing vines and pods | |
| 140 | const top = [x + sw, y, z(2.5)]; | |
| 141 | for (let k = 0; k < 3; k++) { | |
| 142 | const a = k * 2.094 + .5, base = [x + Math.cos(a) * .75, y + Math.sin(a) * .75, .3]; | |
| 143 | stick(base, top, .07, .05, POLE); | |
| 144 | for (const f of [.3, .6]) sphere(base[0] + (top[0] - base[0]) * f, base[1] + (top[1] - base[1]) * f, z(.3 + 2.2 * f), .3 * sc, t.leaf, 'solid'); | |
| 145 | sphere(base[0] + (top[0] - base[0]) * .45, base[1] + (top[1] - base[1]) * .45 + .15, z(1.25), .14 * sc, t.pod, 'solid'); | |
| 146 | } | |
| 147 | sphere(top[0], top[1], top[2], .28 * sc, t.leaf, 'solid'); | |
| 148 | } else if (name === 'sweetcorn') { // a tall stalk, long drooping blades and a cob | |
| 149 | stick([x, y, .3], [x + sw, y, z(3.2)], .16, .1, t.leaf); | |
| 150 | for (const [h, dx, dy] of [[1.1, 1, 0], [1.1, -1, .2], [1.9, .8, -.7], [1.9, -.8, .7], [2.5, .6, .5]]) | |
| 151 | stick([x + sw * h / 3.2, y, z(h)], [x + dx * sc + sw, y + dy * sc, z(h - .5)], .1, .04, t.leaf); | |
| 152 | stick([x + .2, y + .2, z(1.6)], [x + .25 + sw * .5, y + .25, z(2.4)], .24, .2, t.cob); | |
| 153 | sphere(x + sw, y, z(3.3), .2 * sc, t.cob, 'solid'); | |
| 154 | } else if (name === 'carrots') { // an orange shoulder under a low fan of fine fronds | |
| 155 | sphere(x, y, .3, .32 * sc, t.root, 'solid'); | |
| 156 | sphere(x + .55, y - .3, .28, .22 * sc, t.root, 'solid'); | |
| 157 | for (const [dx, dy, h] of [[-.5, .1, 1.1], [-.2, -.5, 1.4], [.2, .3, 1.3], [.6, -.1, 1.0], [0, .55, 1.0]]) | |
| 158 | stick([x + dx * .3, y + dy * .3, .4], [x + dx + sw, y + dy, z(h)], .07, .03, t.leaf); | |
| 159 | } else if (name === 'onion') { // a round pale bulb with a few straight quills | |
| 160 | sphere(x, y, .5, .58 * sc, t.bulb, 'solid'); | |
| 161 | for (const [dx, dy, h] of [[-.2, 0, 2], [.15, .1, 1.7], [0, -.2, 1.5]]) | |
| 162 | stick([x + dx, y + dy, .7], [x + dx + sw, y + dy, z(h)], .08, .03, t.leaf); | |
| 163 | } else { // lettuce: a wide flat rosette round a pale heart | |
| 164 | for (let k = 0; k < 7; k++) { | |
| 165 | const a = k * .897 + .3; | |
| 166 | sphere(x + Math.cos(a) * .85 * sc + sw * .5, y + Math.sin(a) * .85 * sc, .35, .5 * sc, t.leaf, 'solid'); | |
| 167 | } | |
| 168 | sphere(x + sw * .5, y, .6, .55 * sc, t.heart, 'solid'); | |
| 169 | } | |
| 170 | } | |
| 171 | function drawPacket() { | |
| 172 | const next = nextCrop(); | |
| 173 | if (!next) return; | |
| 174 | box(BENCH[0] - .9, -1.1, .5, BENCH[0] - .7, 1.1, 2.6, SEEDPAPER, 9); | |
| 175 | box(BENCH[0] - .7, -.9, 1.3, BENCH[0] - .6, .9, 2.1, TONES[next].leaf, 3); | |
| 176 | for (const y of [-.7, 0, .7]) castShadow(BENCH[0] - .8, y, 2, .35); | |
| 177 | drawCrop(next, BENCH[0] + .6, 0, .8); | |
| 178 | } | |
| 179 | ||
| 180 | /* ---------- drawn each frame ---------- */ | |
| 181 | function drawRing() { | |
| 182 | if (!G.ring || R.status !== 'playing') return; | |
| 183 | const x = cellX(G.cx), y = cellY(G.cy), h = BED / 2 + .1; | |
| 184 | const dot = (sx, sy, c) => { sx |= 0; sy |= 0; if (sx >= 0 && sx < W && sy >= 0 && sy < H) pix[sy * W + sx] = c; }; | |
| 185 | for (let a = -h; a <= h; a += .08) for (const [px, py] of [[x + a, y - h], [x + a, y + h], [x - h, y + a], [x + h, y + a]]) { | |
| 186 | const p = project(px, py, .45); | |
| 187 | dot(p.sx, p.sy - 1, RING_PIX); dot(p.sx, p.sy, ACCENT_PIX); | |
| 188 | } | |
| 189 | } | |
| 190 | function draw() { | |
| 191 | pix.set(bakedPix); | |
| 192 | zb.set(bakedZ); | |
| 193 | pendingShadows.length = 0; | |
| 194 | for (let j = 0; j < Plot.H; j++) for (let i = 0; i < Plot.W; i++) { | |
| 195 | const c = R.grid[j * Plot.W + i]; | |
| 196 | if (c) drawCrop(c, cellX(i), cellY(j)); | |
| 197 | } | |
| 198 | drawPacket(); | |
| 199 | flushShadows(); | |
| 200 | applyShadows(groundZ); | |
| 201 | shadeEdges(); | |
| 202 | drawRing(); | |
| 203 | ctx.putImageData(image, 0, 0); | |
| 204 | } | |
| 205 | ||
| 206 | /* ---------- game ---------- */ | |
| 207 | const WHY = { filled: 'that bed is already planted', 'off-grid': 'that is off the beds', 'season-over': 'the season is over' }; | |
| 208 | const END_HINT = ' · tap or press a key to play again'; | |
| 209 | const HINT = 'tap a bed to plant the next packet'; | |
| 210 | function renderHud() { | |
| 211 | setText('turns', String(R.turns - R.planted)); | |
| 212 | setText('score', String(Plot.score(R))); | |
| 213 | setText('goal', `points, ${R.target} to win`); | |
| 214 | } | |
| 215 | const line = () => `${R.line}\n${Plot.CROPS[nextCrop()]?.text || ''}`; | |
| 216 | function finish() { setText('status', R.line + END_HINT); G.noteUntil = 0; } | |
| 217 | function plant(i, j) { | |
| 218 | ensureAudio(); | |
| 219 | if (R.status !== 'playing') { again(); return; } | |
| 220 | G.cx = i; G.cy = j; | |
| 221 | const before = Plot.score(R), crop = nextCrop(), r = Plot.plant(R, i, j); | |
| 222 | if (!r.ok) { | |
| 223 | sound(130, .25, 'sawtooth'); | |
| 224 | note(`Bed ${i + 1},${j + 1}: ${WHY[r.why] || r.why}`); | |
| 225 | return; | |
| 226 | } | |
| 227 | R = r.state; | |
| 228 | const gain = Plot.score(R) - before; | |
| 229 | sound(gain > 1 ? 520 : 260, .18, 'triangle'); | |
| 230 | renderHud(); | |
| 231 | if (R.status !== 'playing') { | |
| 232 | sound(R.status === 'won' ? 780 : 150, .5, R.status === 'won' ? 'sine' : 'sawtooth', .15); | |
| 233 | finish(); | |
| 234 | } else note(`${crop} planted: ${gain >= 0 ? '+' : ''}${gain} points`); | |
| 235 | } | |
| 236 | function again() { | |
| 237 | G.round++; | |
| 238 | R = Plot.start(SEEDS[G.round % SEEDS.length]); | |
| 239 | G.cx = 2; G.cy = 2; | |
| 240 | G.noteUntil = 0; | |
| 241 | renderHud(); | |
| 242 | note(HINT); | |
| 243 | } | |
| 244 | function update(dt) { | |
| 245 | G.time += dt; | |
| 246 | if (R.status === 'playing' && G.time >= G.noteUntil) setText('status', line()); | |
| 247 | } | |
| 248 | ||
| 249 | // where a bed is on screen, in canvas pixels: the point a tap would land on | |
| 250 | function bedPoint(i, j) { | |
| 251 | const p = project(cellX(i), cellY(j), .4); | |
| 252 | return [Math.round(p.sx), Math.round(p.sy)]; | |
| 253 | } | |
| 254 | ||
| 255 | /* ---------- input ---------- */ | |
| 256 | function bedAt(px, py) { | |
| 257 | const g = unproject(px, py), i = Math.floor((g.x + PITCH * Plot.W / 2) / PITCH), j = Math.floor((g.y + PITCH * Plot.H / 2) / PITCH); | |
| 258 | const inside = i >= 0 && j >= 0 && i < Plot.W && j < Plot.H && Math.abs(g.x - cellX(i)) <= BED / 2 && Math.abs(g.y - cellY(j)) <= BED / 2; | |
| 259 | return inside ? [i, j] : null; | |
| 260 | } | |
| 261 | canvas.addEventListener('pointerdown', e => { | |
| 262 | canvas.focus({ preventScroll: true }); | |
| 263 | G.ring = false; | |
| 264 | const r = canvas.getBoundingClientRect(), bed = bedAt((e.clientX - r.left) / r.width * W, (e.clientY - r.top) / r.height * H); | |
| 265 | if (bed) plant(bed[0], bed[1]); else if (R.status !== 'playing') again(); | |
| 266 | }); | |
| 267 | canvas.addEventListener('focus', () => { if (canvas.matches(':focus-visible')) G.ring = true; }); | |
| 268 | const MOVES = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }; | |
| 269 | canvas.addEventListener('keydown', e => { | |
| 270 | const move = MOVES[e.key], space = e.key === ' ' || e.key === 'Enter'; | |
| 271 | if (!move && !space) return; | |
| 272 | e.preventDefault(); | |
| 273 | if (e.repeat) return; | |
| 274 | if (R.status !== 'playing') { again(); return; } | |
| 275 | G.ring = true; | |
| 276 | if (space) { plant(G.cx, G.cy); return; } | |
| 277 | G.cx = clamp(G.cx + move[0], 0, Plot.W - 1); | |
| 278 | G.cy = clamp(G.cy + move[1], 0, Plot.H - 1); | |
| 279 | }); | |
| 280 | ||
| 281 | /* ---------- sound ---------- */ | |
| 282 | let audio = null, muted = false; | |
| 283 | function ensureAudio() { | |
| 284 | if (audio) { if (audio.state === 'suspended') audio.resume(); return; } | |
| 285 | const AC = window.AudioContext || window.webkitAudioContext; | |
| 286 | if (AC) audio = new AC(); | |
| 287 | } | |
| 288 | function sound(freq, life, type, delay = 0) { | |
| 289 | if (!audio || muted) return; | |
| 290 | const now = audio.currentTime + delay, gain = audio.createGain(), osc = audio.createOscillator(); | |
| 291 | osc.type = type; | |
| 292 | osc.frequency.setValueAtTime(freq, now); | |
| 293 | gain.gain.setValueAtTime(.0001, now); | |
| 294 | gain.gain.exponentialRampToValueAtTime(.07, now + .01); | |
| 295 | gain.gain.exponentialRampToValueAtTime(.0005, now + life); | |
| 296 | osc.connect(gain).connect(audio.destination); | |
| 297 | osc.start(now); osc.stop(now + life + .02); | |
| 298 | } | |
| 299 | const muteButton = document.getElementById('mute'); | |
| 300 | muteButton.addEventListener('click', () => { | |
| 301 | muted = !muted; | |
| 302 | muteButton.textContent = muted ? 'sound off' : 'sound on'; | |
| 303 | muteButton.setAttribute('aria-pressed', String(muted)); | |
| 304 | }); | |
| 305 | ||
| 306 | /* ---------- fit and boot ---------- */ | |
| 307 | addEventListener('resize', fit); | |
| 308 | fit(); | |
| 309 | bake(); | |
| 310 | note(HINT); | |
| 311 | renderHud(); | |
| 312 | canvas.focus({ preventScroll: true }); | |
| 313 | let last = performance.now(); | |
| 314 | function frame(now) { | |
| 315 | update(Math.min(.04, (now - last) / 1000)); | |
| 316 | last = now; | |
| 317 | draw(); | |
| 318 | requestAnimationFrame(frame); | |
| 319 | } | |
| 320 | requestAnimationFrame(frame); | |
| 321 | </script> | |
| 322 | </body> | |
| 323 | </html> |
index.html +2 −1
| @@ -43,7 +43,7 @@ li .tags { order: -1; font-size: .75rem; letter-spacing: .06em; text-transform: | ||
| 43 | 43 | li a { order: 0; } |
| 44 | 44 | #town { display: none; } |
| 45 | 45 | .js #town { display: block; overflow-x: auto; max-width: 44rem; margin: 0 auto 1.5rem; } |
| 46 | .js #c { display: block; width: 100%; min-width: 600px; aspect-ratio: 2 / 1; image-rendering: pixelated; touch-action: pan-x pan-y; } | |
| 46 | .js #c { display: block; width: 100%; min-width: 800px; aspect-ratio: 2 / 1; image-rendering: pixelated; touch-action: pan-x pan-y; } | |
| 47 | 47 | #status { margin: 0 0 1rem; min-height: 1.5em; } |
| 48 | 48 | #status { visibility: hidden; } |
| 49 | 49 | .js #status { visibility: visible; } |
| @@ -107,6 +107,7 @@ footer a::after { content: none; } | ||
| 107 | 107 | <li data-kind="Strategy" data-input="Tap" style="--accent:#4f7f6a"><a href="ferryman/">Ferryman</a><span>Row the fox, the goose and the grain across without leaving the wrong pair alone</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li> |
| 108 | 108 | <li data-kind="Strategy" data-input="Tap" style="--accent:#d8b25a"><a href="sandcastle/">Sandcastle Tide</a><span>Pat down sand walls between tides and keep the castle dry through five high waters</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li> |
| 109 | 109 | <li data-kind="Strategy" data-input="Tap" style="--accent:#5a6e8a"><a href="lock-keeper/">Lock Keeper</a><span>Work the paddles and gates to bring every narrowboat through the flight of locks</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li> |
| 110 | <li data-kind="Strategy" data-input="Tap" style="--accent:#7a8f3a"><a href="allotment/">Allotment</a><span>Plant a season of crops where each one scores by its neighbours</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li> | |
| 110 | 111 | <li data-kind="Strategy" data-input="Tap" style="--accent:#3a5fa8"><a href="empire/">Empire Age</a><span>A real-time strategy game against a bot: gather, build, climb four ages, train an army and destroy the enemy town center</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li> |
| 111 | 112 | <li data-kind="Precision" data-input="Hold" style="--accent:#d0453c"><a href="hot-air-balloon/">Hot Air Balloon</a><span>Five flights over the farms: hold the burner to climb into a different wind, land on the cross for 5</span><span>Game forged by the crew</span><span class="tags">Precision · Hold</span></li> |
| 112 | 113 | <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> |
og/allotment.png added
Binary file not shown.
og/home.png
Binary file not shown.
plaza.js +1 −1
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | // Needs ramp.js and town.js loaded first. Sets window.PixelPlaza. |
| 4 | 4 | (() => { |
| 5 | 5 | const Town = window.PixelTown, { rgb, rampOf, bayerAt } = window.PixelRamp; |
| 6 | const MIN_CSS_WIDTH = 600; // the canvas is never drawn narrower than this in CSS pixels (a phone scrolls it sideways), so a building stays about thumb-sized | |
| 6 | const MIN_CSS_WIDTH = 800; // the canvas is never drawn narrower than this in CSS pixels (a phone scrolls it sideways), so a building stays about thumb-sized | |
| 7 | 7 | const BUF_W = 640, BUF_H = 320; // the canvas's pixel size; CSS reserves the same aspect ratio, so the town fits it rather than the other way round |
| 8 | 8 | const PAD = 12, LIFT = 7; // buffer margin around the town; how far a hovered building rises, world units |
| 9 | 9 | const GRASS = [[52, 88, 52], [82, 118, 54], [34, 62, 50]]; |
rounds.mjs +12
| @@ -4,6 +4,7 @@ import { boot } from './playtest.mjs'; | ||
| 4 | 4 | import { powerFor, MAX_SPEED, GRAVITY } from './coconut-shy/shy.js'; |
| 5 | 5 | import Lock from './lock-keeper/lock.js'; |
| 6 | 6 | import { bestThrow, LINE_MAX } from './bowls-green/bowls.js'; |
| 7 | import Allotment from './allotment/plot.js'; | |
| 7 | 8 | import { toss, MAX_AIM } from './hoopla/hoop.js'; |
| 8 | 9 | |
| 9 | 10 | const MID = [180, 140]; |
| @@ -36,6 +37,17 @@ function solve(start) { | ||
| 36 | 37 | } |
| 37 | 38 | |
| 38 | 39 | export const ROUNDS = { |
| 40 | // plant each packet in the bed that leaves the most points (a greedy pass over the rules' own `plant` and `score`), by tapping that bed | |
| 41 | 'allotment': { over: /play again/, outcome: /Harvest in: \d+ points/, beat: g => { | |
| 42 | if (g.read('R.status') !== 'playing') { g.tap(5, 5); g.run(.2); return; } | |
| 43 | let best = null; | |
| 44 | for (let y = 0; y < Allotment.H; y++) for (let x = 0; x < Allotment.W; x++) { | |
| 45 | const r = Allotment.plant(g.read('R'), x, y); | |
| 46 | if (r.ok && (!best || Allotment.score(r.state) > best.points)) best = { points: Allotment.score(r.state), x, y }; | |
| 47 | } | |
| 48 | g.tap(...g.read(`bedPoint(${best.x}, ${best.y})`)); | |
| 49 | g.run(.2); | |
| 50 | } }, | |
| 39 | 51 | 'balote': { over: /you win|rival wins/, outcome: /(you win|rival wins) \d+–\d+/, beat: g => { g.drag([180, 140], [150, 120], .4); g.run(2); g.tap(...MID); } }, |
| 40 | 52 | 'beekeeper': { over: /play again/, outcome: /swarmed · \d+ honey/, beat: tapping() }, |
| 41 | 53 | // ring the wrong bell on purpose: three wrong peals end the game |
serve.test.mjs +7
| @@ -479,6 +479,13 @@ test('Seed Packets and its rules script are served without a track', async () => | ||
| 479 | 479 | expect((await fetch(base + '/seed-packets/packets.js')).status).toBe(200); |
| 480 | 480 | }); |
| 481 | 481 | |
| 482 | test('Allotment and its rules script are served without a track', async () => { | |
| 483 | const page = await fetch(base + '/allotment/'); | |
| 484 | expect(page.status).toBe(200); | |
| 485 | expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8'); | |
| 486 | expect((await fetch(base + '/allotment/plot.js')).status).toBe(200); | |
| 487 | }); | |
| 488 | ||
| 482 | 489 | test('Lock Keeper and its rules script are served without a track', async () => { |
| 483 | 490 | const page = await fetch(base + '/lock-keeper/'); |
| 484 | 491 | expect(page.status).toBe(200); |
shell.js +1
| @@ -47,6 +47,7 @@ window.PixelPlays = (() => { | ||
| 47 | 47 | { id: 'ferryman', title: 'Ferryman', blurb: 'Row the fox, the goose and the grain across without leaving the wrong pair alone', kind: 'Strategy', input: 'Tap', accent: '#4f7f6a', music: false, forged: true }, |
| 48 | 48 | { id: 'sandcastle', title: 'Sandcastle Tide', blurb: 'Pat down sand walls between tides and keep the castle dry through five high waters', kind: 'Strategy', input: 'Tap', accent: '#d8b25a', music: false, forged: true }, |
| 49 | 49 | { id: 'lock-keeper', title: 'Lock Keeper', blurb: 'Work the paddles and gates to bring every narrowboat through the flight of locks', kind: 'Strategy', input: 'Tap', accent: '#5a6e8a', music: false, forged: true }, |
| 50 | { id: 'allotment', title: 'Allotment', blurb: 'Plant a season of crops where each one scores by its neighbours', kind: 'Strategy', input: 'Tap', accent: '#7a8f3a', music: false, forged: true }, | |
| 50 | 51 | { id: 'empire', title: 'Empire Age', blurb: 'A real-time strategy game against a bot: gather, build, climb four ages, train an army and destroy the enemy town center', kind: 'Strategy', input: 'Tap', accent: '#3a5fa8', music: false, forged: true }, |
| 51 | 52 | { id: 'hot-air-balloon', title: 'Hot Air Balloon', blurb: 'Five flights over the farms: hold the burner to climb into a different wind, land on the cross for 5', kind: 'Precision', input: 'Hold', accent: '#d0453c', music: false, forged: true }, |
| 52 | 53 | { 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 }, |
new above
offline