Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Add Curling Rink: the playable page and its place in the catalogue, on the rules in `curling/rink.js` #210
Check · Review · Land · Live done — Landed and live in production.
vesper/pixel-plays:vesper/179-add-curling-rink-the-playable-page-and-i → main 3 commits fork 2 threads · 2 unresolved
9 files
changed +403
−2
README.md +3 −2
| @@ -63,6 +63,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am | ||
| 63 | 63 | | [](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 | |
| 64 | 64 | | [](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 | |
| 65 | 65 | | [](lily-pond/) | Six levels on a six-by-six pond: the frog starts on a lily pad and hops north, east, south or west to the nearest pad in that line, up to three squares away, and the pad it leaves sinks; land on every pad once (level n has n + 3 pads) and the level is cleared, but a frog with no pad left in reach loses the level, which restarts as the same pond and costs a retry; clearing all six levels with three retries or fewer wins, and a seventh retry ends the game (forged by the crew on the engine and shell above, not by the original creators; rules in `lily-pond/pond.js`) | Swipe or tap beside the frog; arrow keys | |
| 66 | | [](curling/) | One end on a sheet of ice: eight stones slid from the hack toward the house, against four opponent stones already in play (two guards, two in the rings); drag back to set power, tilt the drag to set curl (arrow keys nudge the aim and curl, hold Enter to charge a throw), and hold anywhere or Space to sweep while the stone runs, which lowers the friction so it carries further; stones that touch exchange speed, and one past the back line or over a side line is out; when the last stone stops, your stones in the house nearer the button than every opponent stone score, and 2 or more win; the crowd breathes and the ice glints (forged by the crew on the engine and shell above, not by the original creators; rules in `curling/rink.js`) | Drag back, hold to sweep; arrow keys, Enter, Space | | |
| 66 | 67 | | [](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 | |
| 67 | 68 | |
| 68 | 69 | ## Run |
| @@ -83,7 +84,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is | ||
| 83 | 84 | 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. |
| 84 | 85 | |
| 85 | 86 | ## Add a game |
| 86 | 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, 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`. | |
| 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`. | |
| 87 | 88 | |
| 88 | 89 | - `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. |
| 89 | 90 | - `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. |
| @@ -100,7 +101,7 @@ Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules | ||
| 100 | 101 | - Depth-buffer edges: darker where an object sits in front, a warm rim on upper-left edges. |
| 101 | 102 | - Large flat surfaces use closely spaced tones; wide steps make the dither read as a checkerboard. |
| 102 | 103 | - Characters stay sharp: flat bands with no dither, a dark silhouette on their own pixels, patterns at least 3px wide. |
| 103 | - 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), 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`. | |
| 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`. | |
| 104 | 105 | |
| 105 | 106 | ## Empire Age |
| 106 | 107 |
curling/index.html added +349
| @@ -0,0 +1,349 @@ | ||
| 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>Curling Rink</title> | |
| 7 | <!-- og:begin --> | |
| 8 | <meta name="description" content="Slide and sweep your stones closest to the button"> | |
| 9 | <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/curling/"> | |
| 10 | <meta property="og:type" content="website"> | |
| 11 | <meta property="og:site_name" content="Pixel Plays"> | |
| 12 | <meta property="og:title" content="Curling Rink"> | |
| 13 | <meta property="og:description" content="Slide and sweep your stones closest to the button"> | |
| 14 | <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/curling/"> | |
| 15 | <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/curling.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="Curling Rink: 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; : #4a7bb7; } | |
| 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 | canvas:focus-visible { outline: 2px solid var(); outline-offset: -2px; } | |
| 31 | .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; } | |
| 32 | #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; } | |
| 33 | #bottom { bottom: max(14px, env(safe-area-inset-bottom)); } | |
| 34 | .row { display: flex; align-items: center; gap: 8px; color: var(); } | |
| 35 | .row b { font-size: 16px; font-weight: 600; min-width: 1ch; font-variant-numeric: tabular-nums; } | |
| 36 | .row span { color: var(); } | |
| 37 | #status { color: var(); min-height: 1.35em; } | |
| 38 | button { pointer-events: auto; font: inherit; color: var(); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; } | |
| 39 | button:hover, button:focus-visible { color: var(); } | |
| 40 | button:focus-visible { outline: 2px solid var(); outline-offset: 2px; } | |
| 41 | noscript { position: fixed; inset: 0; display: grid; place-items: center; padding: 48px 16px; pointer-events: none; } | |
| 42 | noscript p { margin: 0; text-align: center; color: var(); } | |
| 43 | </style> | |
| 44 | </head> | |
| 45 | <body> | |
| 46 | <div id="stage"><canvas id="c" tabindex="0" aria-label="A curling sheet with the hack at the top left and the house at the bottom right. Drag back to throw, hold to sweep; the rules list the keyboard controls."></canvas></div> | |
| 47 | <noscript><p>Curling Rink needs JavaScript to play.</p></noscript> | |
| 48 | <div id="scores"> | |
| 49 | <div class="row"><b id="left">8</b><span>stones left</span></div> | |
| 50 | <div class="row"><b id="points">0</b><span>points now</span></div> | |
| 51 | </div> | |
| 52 | <div class="hud" id="bottom"> | |
| 53 | <div id="status" role="status" aria-live="polite"></div> | |
| 54 | <button id="mute" type="button" aria-pressed="false">sound on</button> | |
| 55 | </div> | |
outdated
Rules list omits the keyboard controls (arrows aim/curl, hold Enter to throw, Space sweeps). Add a line so keyboard players find them. |
||
| 56 | <script src="../shell.js"></script> | |
| 57 | <script> | |
| 58 | PixelPlays.mount({ | |
| 59 | id: 'curling', | |
| 60 | rules: [ | |
| 61 | 'Drag back from the hack to aim and set power; tilt the drag to set curl.', | |
| 62 | 'Hold anywhere (or Space) to sweep while the stone runs: it carries further.', | |
| 63 | 'Keys: arrows aim and curl, hold Enter to charge and release to throw, Space sweeps.', | |
| 64 | 'Eight stones; yours nearest the button score, and 2 or more win.', | |
| 65 | ], | |
| 66 | }); | |
| 67 | </script> | |
| 68 | <script>window.PP_SCENE = { originY: 6, shadowX: 1.3, shadowY: -.12 };</script> | |
| 69 | <script src="../engine.js"></script> | |
| 70 | <script src="rink.js"></script> | |
| 71 | <script> | |
| 72 | 'use strict'; | |
| 73 | ||
| 74 | const K = 1.05, WIDTH = Curling.WIDTH, LENGTH = Curling.LENGTH; // engine units per metre | |
| 75 | const BUTTON = [WIDTH / 2, Curling.BUTTON_Y], HOUSE = Curling.HOUSE; | |
| 76 | const DRAW_R = .36; // stones are drawn larger than life, or they would be specks | |
| 77 | const MAX_DRAG = 110, MIN_POWER = .08, MAX_TILT = 20; // canvas pixels for full power; degrees of tilt for full curl | |
| 78 | const BACK = [-.894, -.447], SIDE = [-.447, .894]; // the drag's way back up the ice, and across it, on the canvas | |
| 79 | const CHARGE_TIME = 1.2; // seconds holding Enter for full power | |
| 80 | const ICE = [[204, 228, 244], [192, 218, 238]], BOARD = [124, 90, 58], STAND = [88, 76, 104]; | |
| 81 | const RINGS = [[70, 122, 204], [240, 246, 252], [204, 66, 66], [244, 248, 252]], LINE = [60, 90, 160]; | |
| 82 | const YOURS = [48, 92, 178], YOURS_HANDLE = [236, 240, 248], OPP = [232, 184, 40], OPP_HANDLE = [60, 40, 30]; | |
| 83 | const SKIN = [236, 190, 150], COATS = [[196, 70, 70], [70, 140, 90], [220, 170, 60], [120, 90, 170], [60, 60, 70], [200, 110, 50]]; | |
| 84 | const DOT_PIX = rgb(40, 70, 140); | |
| 85 | ||
| 86 | // a place on the ice (across, down) to engine units and the canvas | |
| 87 | const eng = (rx, ry, z = 0) => [(ry - LENGTH / 2) * K, (rx - WIDTH / 2) * K, z]; | |
| 88 | const scr = (rx, ry, z = 0) => { const p = project(...eng(rx, ry, z)); return [p.sx, p.sy]; }; | |
| 89 | ||
| 90 | /* ---------- state ---------- */ | |
| 91 | const nodes = {}; | |
| 92 | for (const k of ['left', 'points', 'status']) nodes[k] = document.getElementById(k); | |
| 93 | const shown = {}; | |
| 94 | function setText(key, text) { | |
| 95 | if (shown[key] === text) return; | |
| 96 | shown[key] = text; | |
| 97 | nodes[key].textContent = text; | |
| 98 | } | |
| 99 | const fresh = () => Curling.start(Math.floor(Math.random() * 4294967296)); | |
| 100 | let P = fresh(); | |
| 101 | // down/cur: the canvas points of a drag; space/pointer: sweeping inputs; charge: seconds Enter has been held (or -1) | |
| 102 | const G = { time: 0, noteUntil: 0, down: null, cur: null, space: false, pointer: false, charge: -1, aim: 0, curl: 0, moving: new Set(), end: '' }; | |
| 103 | const REFUSED = { sliding: 'wait for the stone to stop', over: 'the end is done', 'no-stones': 'no stones left' }; | |
| 104 | ||
| 105 | const sliding = () => P.stones.some(s => s.vx || s.vy); | |
| 106 | const sweeping = () => (G.space || G.pointer) && sliding(); | |
| 107 | function note(text) { setText('status', text); G.noteUntil = G.time + 1.8; } | |
| 108 | const endLine = () => `${P.line} · tap or press a key to play again`; | |
| 109 | function renderHud() { | |
| 110 | setText('left', String(P.left)); | |
| 111 | setText('points', String(Curling.score(P.stones))); | |
| 112 | } | |
| 113 | ||
| 114 | /* ---------- baked scene ---------- */ | |
| 115 | function groundColor(x, y, ix, iy) { | |
| 116 | const ry = x / K + LENGTH / 2, rx = y / K + WIDTH / 2; | |
| 117 | if (rx < -1.8 || rx > WIDTH + .4 || ry < -.8 || ry > LENGTH + .4) return 0; | |
| 118 | const t = .97 + (hash(ix, iy) - .5) * .05; | |
| 119 | const shade = c => rgb(c[0] * t, c[1] * t, c[2] * t); | |
| 120 | if (rx < -.4) return shade(STAND); | |
| 121 | if (rx < 0 || rx > WIDTH || ry < 0 || ry > LENGTH) return shade(BOARD); | |
| 122 | const d = Math.hypot(rx - BUTTON[0], ry - BUTTON[1]); | |
| 123 | if (ry < .5 && Math.abs(rx - WIDTH / 2) > .15 && Math.abs(rx - WIDTH / 2) < .55) return shade([40, 40, 44]); // the hack | |
| 124 | if (d <= HOUSE) return shade(d > 1.22 ? RINGS[0] : d > .61 ? RINGS[1] : d > .3 ? RINGS[2] : RINGS[3]); | |
| 125 | if (Math.abs(ry - BUTTON[1]) < .07 || ry > LENGTH - .12 || Math.abs(rx - WIDTH / 2) < .04) return shade(LINE); | |
| 126 | if (ry > 23 && ry < 23.25) return shade(RINGS[2]); // the hog line | |
| 127 | return shade(ICE[(ix + iy) & 4 ? 0 : 1]); | |
| 128 | } | |
| 129 | function bake() { | |
| 130 | ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0); | |
| 131 | tufts.length = 0; leaves.length = 0; | |
| 132 | zb.fill(-1e9); | |
| 133 | pix.fill(rgb(255, 255, 255)); | |
| 134 | for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) { | |
| 135 | const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy); | |
| 136 | if (!c) continue; | |
| 137 | pix[i] = c; ground[i] = 1; | |
| 138 | zb[i] = (g.x + g.y) / R2 * COS; | |
| 139 | } | |
| 140 | groundZ.set(zb); | |
| 141 | bakeOcclusion(); | |
| 142 | staticShadow.set(shadowMask); | |
| 143 | applyShadows(groundZ); | |
| 144 | bakedPix.set(pix); | |
| 145 | bakedZ.set(zb); | |
| 146 | } | |
| 147 | ||
| 148 | /* ---------- drawing ---------- */ | |
| 149 | // yours stand tall on a post with a knob; the opponent's lie low under a flat bar across the stone | |
| 150 | function drawStone(s, lift = 0) { | |
| 151 | const mine = s.team === 'you', body = mine ? YOURS : OPP, handle = mine ? YOURS_HANDLE : OPP_HANDLE; | |
| 152 | dynamicAdd(eng(s.x, s.y, .05 + lift), eng(s.x, s.y, .3 + lift), DRAW_R, DRAW_R, () => body); | |
| 153 | if (mine) { | |
| 154 | dynamicAdd(eng(s.x, s.y, .3 + lift), eng(s.x, s.y, .75 + lift), .09, .09, () => handle); | |
| 155 | dynamicAdd(eng(s.x, s.y, .75 + lift), eng(s.x, s.y, .85 + lift), .17, .17, () => handle); | |
| 156 | } else { | |
| 157 | dynamicAdd(eng(s.x - .32, s.y, .42 + lift), eng(s.x + .32, s.y, .42 + lift), .08, .08, () => handle); | |
| 158 | } | |
| 159 | } | |
| 160 | // the sweeper walks beside the stone and works the broom across the ice in front of it | |
| 161 | function drawSweeper(s) { | |
| 162 | const bx = s.x + .75, by = s.y + 1.2, act = sweeping(), swing = act ? Math.sin(G.time * 22) * .45 : 0; | |
| 163 | dynamicAdd(eng(bx, by, 0), eng(bx, by, .8), .22, .22, () => [40, 60, 90]); | |
| 164 | dynamicAdd(eng(bx, by, .8), eng(bx, by, 1.5), .3, .26, () => [214, 70, 60]); | |
| 165 | dynamicAdd(eng(bx, by, 1.5), eng(bx, by, 1.85), .22, .22, () => SKIN); | |
| 166 | dynamicAdd(eng(bx - .3, by + .3, 1.1), eng(bx - .3 + swing, by + 1.0, .05), .06, .09, () => [150, 110, 60]); | |
| 167 | } | |
| 168 | // the crowd on the stand behind the far side line; each breathes a pixel up and down, out of step with the next | |
| 169 | function drawCrowd() { | |
| 170 | for (let i = 0; i < 16; i++) { | |
| 171 | const ry = 1.6 + i * 2.2, rx = -1.1, up = STILL ? 0 : (Math.floor(G.time * 2 + hash(i, 3) * 4) & 1) * .12; | |
| 172 | const coat = COATS[Math.floor(hash(i, 8) * COATS.length)]; | |
| 173 | dynamicAdd(eng(rx, ry, 0), eng(rx, ry, .8 + up), .3, .26, () => coat); | |
| 174 | dynamicAdd(eng(rx, ry, 1 + up), eng(rx, ry, 1.2 + up), .2, .2, () => SKIN); | |
| 175 | } | |
| 176 | } | |
| 177 | // bright flecks on the ice shift four times a second; under reduced motion they stay put | |
| 178 | function drawGlints() { | |
| 179 | const step = STILL ? 0 : Math.floor(G.time * 4) % 7; | |
| 180 | for (let i = 0; i < 14; i++) { | |
| 181 | const [sx, sy] = scr(.2 + hash(i, step) * (WIDTH - .4), .5 + hash(step, i + 9) * (LENGTH - 1)); | |
| 182 | for (let d = 0; d < 3; d++) { const x = Math.round(sx) + d, y = Math.round(sy); if (x >= 0 && x < W && y >= 0 && y < H && ground[y * W + x] && zb[y * W + x] === bakedZ[y * W + x]) pix[y * W + x] = rgb(250, 252, 255); } | |
| 183 | } | |
| 184 | } | |
| 185 | // the aim: dots from the hack down the ice, as far as the power would send a stone, bent the way the curl would | |
| 186 | function drawAim(power, angle, curl) { | |
| 187 | const a = angle * Math.PI / 180, reach = power * power * 38 * 1.1, pts = []; | |
| 188 | for (let d = 1; d < reach; d += 1.1) { | |
| 189 | const t = d / 38, [sx, sy] = scr(WIDTH / 2 + Math.sin(a) * d - curl * 1.4 * t * t, Math.cos(a) * d); | |
| 190 | pts.push([Math.round(sx), Math.round(sy)]); | |
| 191 | } | |
| 192 | drawDots(pts, DOT_PIX); | |
| 193 | } | |
| 194 | function dragPlan() { | |
| 195 | if (!G.down || !G.cur) return null; | |
| 196 | const dx = G.cur[0] - G.down[0], dy = G.cur[1] - G.down[1]; | |
| 197 | const back = dx * BACK[0] + dy * BACK[1], side = dx * SIDE[0] + dy * SIDE[1]; | |
| 198 | const power = Math.min(1, Math.max(0, back / MAX_DRAG)); | |
| 199 | const curl = back > 4 ? Math.max(-1, Math.min(1, Math.atan2(side, back) * 180 / Math.PI / MAX_TILT)) : 0; | |
| 200 | return { power, curl }; | |
| 201 | } | |
| 202 | function draw() { | |
| 203 | pix.set(bakedPix); | |
| 204 | zb.set(bakedZ); | |
| 205 | pendingShadows.length = 0; | |
| 206 | drawCrowd(); | |
| 207 | for (const s of P.stones) drawStone(s); | |
| 208 | const live = P.stones.filter(s => s.vx || s.vy).find(s => s.team === 'you'); | |
| 209 | if (live) drawSweeper(live); | |
| 210 | else if (P.status === 'playing' && P.left > 0) drawStone({ team: 'you', x: WIDTH / 2, y: 0 }); | |
| 211 | flushShadows(); | |
| 212 | applyShadows(bakedZ); | |
| 213 | shadeEdges(); | |
| 214 | drawGlints(); | |
| 215 | if (P.status === 'playing' && !sliding() && P.left > 0) { | |
| 216 | const plan = dragPlan(); | |
| 217 | if (plan) drawAim(plan.power, G.aim, plan.curl); | |
| 218 | else if (G.charge >= 0) drawAim(Math.min(1, G.charge / CHARGE_TIME), G.aim, G.curl); | |
| 219 | else drawAim(.5, G.aim, G.curl); | |
| 220 | } | |
| 221 | ctx.putImageData(image, 0, 0); | |
| 222 | } | |
| 223 | ||
| 224 | /* ---------- game ---------- */ | |
| 225 | function release(power, curl) { | |
| 226 | ensureAudio(); | |
| 227 | const r = Curling.throw(P, { angle: G.aim, power, curl }); | |
| 228 | if (!r.ok) { note(REFUSED[r.why] || 'cannot throw'); sound(120, .08, 'square'); return; } | |
| 229 | P = r.state; | |
| 230 | sound(180 + power * 120, .2, 'triangle'); | |
| 231 | renderHud(); | |
| 232 | } | |
| 233 | function restart() { | |
| 234 | P = fresh(); G.end = ''; G.down = G.cur = null; G.charge = -1; G.aim = 0; G.curl = 0; G.moving.clear(); | |
| 235 | note('drag back from the hack, then hold to sweep'); | |
| 236 | renderHud(); | |
| 237 | } | |
| 238 | // what the keys have set: shown whenever it is not the default, so arrow-key play can be read off the status line | |
| 239 | function keyLine() { | |
| 240 | if (sliding() || P.left <= 0) return ''; | |
| 241 | if (G.charge >= 0) return `charge ${Math.round(Math.min(1, G.charge / CHARGE_TIME) * 100)}%, aim ${G.aim.toFixed(1)}°, curl ${signed(G.curl)}: release Enter to throw`; | |
| 242 | return G.aim || G.curl ? `${P.line} · aim ${G.aim.toFixed(1)}°, curl ${signed(G.curl)}` : ''; | |
| 243 | } | |
| 244 | const signed = v => (v > 0 ? '+' : '') + v.toFixed(2); | |
| 245 | function update(dt) { | |
| 246 | G.time += dt; | |
| 247 | if (G.charge >= 0) G.charge += dt; | |
| 248 | const before = P, hadStones = P.stones.length; | |
| 249 | P = Curling.tick(P, dt, sweeping()); | |
| 250 | const now = new Set(P.stones.filter(s => s.vx || s.vy).map(s => s.id)); | |
| 251 | for (const id of now) if (!G.moving.has(id) && before.stones.find(s => s.id === id)) sound(520, .05, 'square'); // a struck stone sets off | |
| 252 | G.moving = now; | |
| 253 | if (P.stones.length < hadStones && P.status === 'playing') { note('A stone is out of play'); sound(140, .2, 'sawtooth'); } | |
| 254 | if (before.status === 'playing' && P.status !== 'playing') { G.end = endLine(); sound(P.status === 'won' ? 780 : 110, .5, 'sine'); } | |
| 255 | renderHud(); | |
| 256 | if (P.status !== 'playing') { setText('status', endLine()); return; } | |
| 257 | if (G.time < G.noteUntil) return; | |
| 258 | setText('status', keyLine() || P.line); | |
| 259 | } | |
| 260 | ||
| 261 | /* ---------- input ---------- */ | |
| 262 | const point = e => { const r = canvas.getBoundingClientRect(); return [(e.clientX - r.left) / r.width * W, (e.clientY - r.top) / r.height * H]; }; | |
| 263 | canvas.addEventListener('pointerdown', e => { | |
| 264 | canvas.focus({ preventScroll: true }); | |
| 265 | canvas.setPointerCapture?.(e.pointerId); | |
| 266 | ensureAudio(); | |
| 267 | const p = point(e); | |
| 268 | if (P.status !== 'playing') { G.down = p; G.cur = null; return; } | |
| 269 | if (sliding()) { G.pointer = true; return; } | |
| 270 | G.down = p; G.cur = p; | |
| 271 | }); | |
| 272 | canvas.addEventListener('pointermove', e => { if (G.down && P.status === 'playing') G.cur = point(e); }); | |
| 273 | canvas.addEventListener('pointerup', e => { | |
| 274 | G.pointer = false; | |
| 275 | const from = G.down; | |
| 276 | if (!from) return; | |
| 277 | if (P.status !== 'playing') { G.down = G.cur = null; restart(); return; } | |
| 278 | G.cur = point(e); | |
| 279 | const plan = dragPlan(); | |
| 280 | G.down = G.cur = null; | |
| 281 | if (!plan || plan.power < MIN_POWER) { note('drag back from the hack to throw'); return; } | |
| 282 | release(plan.power, plan.curl); | |
| 283 | }); | |
| 284 | canvas.addEventListener('pointercancel', () => { G.down = G.cur = null; G.pointer = false; }); | |
| 285 | canvas.addEventListener('keydown', e => { | |
| 286 | const k = e.key; | |
| 287 | if (![' ', 'Enter', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(k)) return; | |
| 288 | e.preventDefault(); | |
| 289 | if (P.status !== 'playing') { if (!e.repeat && (k === ' ' || k === 'Enter')) restart(); return; } | |
| 290 | if (k === ' ') { G.space = true; return; } | |
| 291 | if (k === 'Enter') { if (!e.repeat && !sliding() && G.charge < 0) { G.charge = 0; G.noteUntil = 0; } return; } | |
| 292 | const aim = k === 'ArrowLeft' ? -.5 : k === 'ArrowRight' ? .5 : 0, curl = k === 'ArrowUp' ? .25 : k === 'ArrowDown' ? -.25 : 0; | |
| 293 | G.aim = Math.max(-Curling.MAX_ANGLE, Math.min(Curling.MAX_ANGLE, G.aim + aim)); | |
| 294 | G.curl = Math.max(-1, Math.min(1, G.curl + curl)); | |
| 295 | G.noteUntil = 0; | |
| 296 | }); | |
| 297 | canvas.addEventListener('keyup', e => { | |
| 298 | if (e.key === ' ') G.space = false; | |
| 299 | if (e.key === 'Enter' && G.charge >= 0) { | |
| 300 | const power = Math.min(1, G.charge / CHARGE_TIME); | |
| 301 | G.charge = -1; | |
| 302 | if (P.status === 'playing' && !sliding()) { if (power < MIN_POWER) note('hold Enter longer to throw'); else release(power, G.curl); } | |
| 303 | } | |
| 304 | }); | |
| 305 | addEventListener('blur', () => { G.space = G.pointer = false; G.charge = -1; }); | |
| 306 | ||
| 307 | /* ---------- sound ---------- */ | |
| 308 | let audio = null, muted = false; | |
| 309 | function ensureAudio() { | |
| 310 | if (audio) { if (audio.state === 'suspended') audio.resume(); return; } | |
| 311 | const AC = window.AudioContext || window.webkitAudioContext; | |
| 312 | if (AC) audio = new AC(); | |
| 313 | } | |
| 314 | function sound(freq, life, type, delay = 0) { | |
| 315 | if (!audio || muted) return; | |
| 316 | const now = audio.currentTime + delay, gain = audio.createGain(), osc = audio.createOscillator(); | |
| 317 | osc.type = type; | |
| 318 | osc.frequency.setValueAtTime(freq, now); | |
| 319 | gain.gain.setValueAtTime(.0001, now); | |
| 320 | gain.gain.exponentialRampToValueAtTime(.07, now + .01); | |
| 321 | gain.gain.exponentialRampToValueAtTime(.0005, now + life); | |
| 322 | osc.connect(gain).connect(audio.destination); | |
| 323 | osc.start(now); osc.stop(now + life + .02); | |
| 324 | } | |
| 325 | const muteButton = document.getElementById('mute'); | |
| 326 | muteButton.addEventListener('click', () => { | |
| 327 | muted = !muted; | |
| 328 | muteButton.textContent = muted ? 'sound off' : 'sound on'; | |
| 329 | muteButton.setAttribute('aria-pressed', String(muted)); | |
| 330 | }); | |
| 331 | ||
| 332 | /* ---------- fit and boot ---------- */ | |
| 333 | addEventListener('resize', fit); | |
| 334 | fit(); | |
| 335 | bake(); | |
| 336 | note('drag back from the hack, then hold to sweep'); | |
| 337 | renderHud(); | |
| 338 | canvas.focus({ preventScroll: true }); | |
| 339 | let last = performance.now(); | |
| 340 | function frame(now) { | |
| 341 | update(Math.min(.04, (now - last) / 1000)); | |
| 342 | last = now; | |
| 343 | draw(); | |
| 344 | requestAnimationFrame(frame); | |
| 345 | } | |
| 346 | requestAnimationFrame(frame); | |
| 347 | </script> | |
| 348 | </body> | |
| 349 | </html> |
curling/page.test.mjs added +37
| @@ -0,0 +1,37 @@ | ||
| 1 | import { test, expect, setDefaultTimeout } from 'bun:test'; | |
| 2 | import { boot } from '../playtest.mjs'; | |
| 3 | setDefaultTimeout(60000); | |
| 4 | ||
| 5 | test('curling: the arrow keys aim and curl, clamp, and the status line says so', () => { | |
| 6 | const g = boot('curling'); | |
| 7 | for (let i = 0; i < 30; i++) g.press('ArrowRight', .02); | |
| 8 | g.press('ArrowUp', .02); g.press('ArrowUp', .02); | |
| 9 | g.run(.1); | |
| 10 | expect(g.read('G.aim')).toBe(5); | |
| 11 | expect(g.read('G.curl')).toBe(.5); | |
| 12 | expect(g.text()).toContain('aim 5.0°, curl +0.50'); | |
| 13 | for (let i = 0; i < 6; i++) g.press('ArrowDown', .02); | |
| 14 | expect(g.read('G.curl')).toBe(-1); | |
| 15 | }); | |
| 16 | ||
| 17 | test('curling: holding Enter charges and releasing throws at that power', () => { | |
| 18 | const g = boot('curling'); | |
| 19 | g.keyDown('Enter'); | |
| 20 | g.run(.6); | |
| 21 | expect(g.text()).toContain('charge 5'); | |
| 22 | g.keyUp('Enter'); | |
| 23 | g.run(.1); | |
| 24 | expect(g.read('P.left')).toBe(7); | |
| 25 | const vy = g.read('P.stones.find(s => s.team === "you").vy'); | |
| 26 | expect(vy).toBeGreaterThan(1.9); | |
| 27 | expect(vy).toBeLessThan(2.3); | |
| 28 | expect(g.errors.map(e => e.message)).toEqual([]); | |
| 29 | }); | |
| 30 | ||
| 31 | test('curling: a tap of Enter is too light to throw, and Space sweeps only while a stone runs', () => { | |
| 32 | const g = boot('curling'); | |
| 33 | g.press('Enter', .05); | |
| 34 | expect(g.read('P.left')).toBe(8); | |
| 35 | g.press(' ', .2); | |
| 36 | expect(g.read('P.left')).toBe(8); | |
| 37 | }); |
index.html +1
| @@ -115,6 +115,7 @@ footer a::after { content: none; } | ||
| 115 | 115 | <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> |
| 116 | 116 | <li data-kind="Strategy" data-input="Tap" style="--accent:#8a3b3b"><a href="tower-duel/">Tower Duel</a><span>Tap a card, tap your half: send troops over the bridges and topple the rival king tower</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li> |
| 117 | 117 | <li data-kind="Puzzle" data-input="Keys" style="--accent:#2f7a6a"><a href="lily-pond/">Lily Pond</a><span>Hop the frog onto every lily pad once before they sink</span><span>Game forged by the crew</span><span class="tags">Puzzle · Keys</span></li> |
| 118 | <li data-kind="Sport" data-input="Drag" style="--accent:#4a7bb7"><a href="curling/">Curling Rink</a><span>Slide and sweep your stones closest to the button</span><span>Game forged by the crew</span><span class="tags">Sport · Drag</span></li> | |
| 118 | 119 | <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> |
| 119 | 120 | <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> |
| 120 | 121 | <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> |
og/curling.png added
Binary file not shown.
og/home.png
Binary file not shown.
rounds.mjs +5
| @@ -152,6 +152,11 @@ export const ROUNDS = { | ||
| 152 | 152 | if (index >= 0) { g.press(String(index + 1)); g.tap(...g.read(`scr(${x}, 9)`)); } |
| 153 | 153 | g.run(.2); |
| 154 | 154 | } }, |
| 155 | // drag back for about the weight that reaches the house, then sweep while the stone runs, eight times over | |
| 156 | 'curling': { over: /play again/, outcome: /You scored \d+: a (win|loss)/, limit: 240, beat: g => { | |
| 157 | if (g.read('P.stones.some(s => s.vx || s.vy)')) g.hold(...MID, .5); | |
| 158 | else g.drag([100, 80], [100 - .894 * 60, 80 - .447 * 60], .3); | |
| 159 | } }, | |
| 155 | 160 | // plan the whole round on the rules' own `board`, `skip` and `step` (a depth-first search that seats as many riders as it can without a jam), then play it one step per beat |
| 156 | 161 | 'ferris-wheel': { over: /play again/, outcome: /Wheel balanced: \d+ riders carried/, beat: g => { |
| 157 | 162 | g.plan ??= wheelPlan(structuredClone(g.read('P'))); |
serve.test.mjs +7
| @@ -528,6 +528,13 @@ test('Tower Duel and its rules script are served without a track', async () => { | ||
| 528 | 528 | expect((await fetch(base + '/tower-duel/duel.js')).status).toBe(200); |
| 529 | 529 | }); |
| 530 | 530 | |
| 531 | test('Curling Rink and its rules script are served without a track', async () => { | |
| 532 | const page = await fetch(base + '/curling/'); | |
| 533 | expect(page.status).toBe(200); | |
| 534 | expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8'); | |
| 535 | expect((await fetch(base + '/curling/rink.js')).status).toBe(200); | |
| 536 | }); | |
| 537 | ||
| 531 | 538 | test('Lily Pond and its rules script are served without a track', async () => { |
| 532 | 539 | const page = await fetch(base + '/lily-pond/'); |
| 533 | 540 | expect(page.status).toBe(200); |
shell.js +1
| @@ -55,6 +55,7 @@ window.PixelPlays = (() => { | ||
| 55 | 55 | { 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 }, |
| 56 | 56 | { id: 'tower-duel', title: 'Tower Duel', blurb: 'Tap a card, tap your half: send troops over the bridges and topple the rival king tower', kind: 'Strategy', input: 'Tap', accent: '#8a3b3b', music: false, forged: true }, |
| 57 | 57 | { id: 'lily-pond', title: 'Lily Pond', blurb: 'Hop the frog onto every lily pad once before they sink', kind: 'Puzzle', input: 'Keys', accent: '#2f7a6a', music: false, forged: true }, |
| 58 | { id: 'curling', title: 'Curling Rink', blurb: 'Slide and sweep your stones closest to the button', kind: 'Sport', input: 'Drag', accent: '#4a7bb7', music: false, forged: true }, | |
| 58 | 59 | { 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 }, |
| 59 | 60 | { id: 'ferris-wheel', title: 'Ferris Wheel', blurb: 'Seat the queue without tipping the wheel', kind: 'Strategy', input: 'Tap', accent: '#b8475a', music: false, forged: true }, |
| 60 | 61 | { 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 }, |
new above
offline
canvas { outline: none } with no :focus-visible rule hides keyboard focus. Add
canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }.