Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Add Cloakroom: the playable page and its place in the catalogue, on the rules already in `cloakroom/cloak.js` #123
Check · Review · Land · Live done — Landed and live in production.
vesper/pixel-plays:vesper/108-add-cloakroom-the-playable-page-and-its → main 5 commits fork
9 files
changed +357
−3
README.md +3 −2
| @@ -47,6 +47,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am | ||
| 47 | 47 | | [](egg-basket/) | A red henhouse with a sloping tin roof and three hens on the ridge: they lay brown eggs (1 point) and rare golden ones (3) that roll down one of four roof lanes and drop off the eave; slide the basket under each before it reaches the ground, where it cracks; rolling speeds up every ten eggs laid (never so fast that the basket cannot cross three lanes in time), three cracks end the round and 25 or more wins (forged by the crew on the engine and shell above, not by the original creators) | Drag the basket; Left and Right arrows move one lane | |
| 48 | 48 | | [](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 | |
| 49 | 49 | | [](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 | |
| 50 | | [](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 | | |
| 50 | 51 | |
| 51 | 52 | ## Run |
| 52 | 53 | Requires [](https://nodejs.org/); nothing to install. |
| @@ -66,7 +67,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is | ||
| 66 | 67 | 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. |
| 67 | 68 | |
| 68 | 69 | ## Add a game |
| 69 | 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, Empire Age and Egg Basket 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`. | |
| 70 | 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, Empire Age and Egg Basket 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`. | |
| 70 | 71 | |
| 71 | 72 | - `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. |
| 72 | 73 | - `engine.js` provides the camera, depth buffer, colour ramps, shadows, edges, figures, trees and wind as globals. |
| @@ -82,7 +83,7 @@ Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules | ||
| 82 | 83 | - Depth-buffer edges: darker where an object sits in front, a warm rim on upper-left edges. |
| 83 | 84 | - Large flat surfaces use closely spaced tones; wide steps make the dither read as a checkerboard. |
| 84 | 85 | - Characters stay sharp: flat bands with no dither, a dark silhouette on their own pixels, patterns at least 3px wide. |
| 85 | - 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, and Egg Basket's hens peck and the straw in its basket stirs (its rolling eggs are play, not ambience, and still move); all of it stops under `prefers-reduced-motion`. | |
| 86 | - 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, and Egg Basket's hens peck and the straw in its basket stirs (its rolling eggs are play, not ambience, and still move); all of it stops under `prefers-reduced-motion`. | |
| 86 | 87 | |
| 87 | 88 | ## Empire Age |
| 88 | 89 |
cloakroom/index.html added +338
| @@ -0,0 +1,338 @@ | ||
| 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>Cloakroom</title> | |
| 7 | <!-- og:begin --> | |
| 8 | <meta name="description" content="Turn two tags at a time and hand back every matching coat before the dance lets out"> | |
| 9 | <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/cloakroom/"> | |
| 10 | <meta property="og:type" content="website"> | |
| 11 | <meta property="og:site_name" content="Pixel Plays"> | |
| 12 | <meta property="og:title" content="Cloakroom"> | |
| 13 | <meta property="og:description" content="Turn two tags at a time and hand back every matching coat before the dance lets out"> | |
| 14 | <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/cloakroom/"> | |
| 15 | <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/cloakroom.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="Cloakroom: 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; : #9c3d6b; } | |
| 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: 1.35em; } | |
| 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 coat check room: two rails of coats hung in rows, each with a paper tag. Turn two tags at a time to find matching coats and hand every pair back before the clock runs out. Tap a coat, or move the focus ring with the arrow keys and press Space or Enter to turn its tag. Three rounds of 6, 8 and 10 pairs; more than 12 mismatches lose."></canvas></div> | |
| 43 | <div id="scores"> | |
| 44 | <div class="row"><b id="round">1/3</b><span>round</span></div> | |
| 45 | <div class="row"><b id="pairs">6</b><span>pairs left</span></div> | |
| 46 | <div class="row"><b id="misses">0/12</b><span>mismatches</span></div> | |
| 47 | <div class="row"><b id="clock">90</b><span>seconds</span></div> | |
| 48 | <div class="row"><b id="best">-</b><span>best</span></div> | |
| 49 | </div> | |
| 50 | <div class="hud" id="bottom"> | |
| 51 | <div id="status" role="status" aria-live="polite"></div> | |
| 52 | <button id="mute" type="button" aria-pressed="false">sound on</button> | |
| 53 | </div> | |
| 54 | <script src="../shell.js"></script> | |
| 55 | <script> | |
| 56 | PixelPlays.mount({ | |
| 57 | id: 'cloakroom', | |
| 58 | rules: [ | |
| 59 | 'Tap a coat, or move the ring with the arrows and press Space, to turn its tag.', | |
| 60 | 'Turn two: a match is handed back, a mismatch turns back after a moment.', | |
| 61 | 'Clear 6, 8 and 10 pairs, 90 seconds each.', | |
| 62 | 'More than 12 mismatches in all, or a clock at zero, ends it.', | |
| 63 | ], | |
| 64 | }); | |
| 65 | </script> | |
| 66 | <script>window.PP_SCENE = { originY: 62, shadowX: 1.3, shadowY: -.12 };</script> | |
| 67 | <script src="../engine.js"></script> | |
| 68 | <script src="cloak.js"></script> | |
| 69 | <script> | |
| 70 | 'use strict'; | |
| 71 | ||
| 72 | const WOOD = [112, 82, 56], BOARD = [206, 176, 138], BOARD_ALT = [194, 164, 126], FRAME = [96, 70, 52], DRAB = [128, 120, 116]; | |
| 73 | const TAG_FRONT = [248, 242, 226], TAG_BACK = [190, 150, 98], STRING = [226, 210, 170], LIGHT = [255, 236, 150], BRASS = [196, 164, 80]; | |
| 74 | // one colour per face, told apart by eye as well as by the number on the tag | |
| 75 | const FACES = [[196, 56, 52], [232, 140, 48], [222, 196, 62], [86, 152, 78], [48, 150, 150], [56, 100, 186], [92, 76, 168], [158, 80, 168], [214, 108, 154], [120, 82, 58]]; | |
| 76 | const GLYPHS = { | |
| 77 | 0: ['111', '101', '101', '101', '111'], 1: ['010', '110', '010', '010', '111'], 2: ['111', '001', '111', '100', '111'], | |
| 78 | 3: ['111', '001', '111', '001', '111'], 4: ['101', '101', '111', '001', '001'], 5: ['111', '100', '111', '001', '111'], | |
| 79 | 6: ['111', '100', '111', '101', '111'], 7: ['111', '001', '001', '010', '010'], 8: ['111', '101', '111', '101', '111'], | |
| 80 | 9: ['111', '101', '111', '001', '111'], | |
| 81 | }; | |
| 82 | const HALF_U = 17.4, HALF_V = 9.4, BACK_V = -6.4, FRONT_V = 3.2, RAIL_Z = 9.6, HEM_Z = 2.2, TAG_Z = 6.1; | |
| 83 | const BEST_KEY = 'pixel-plays-cloakroom-best'; | |
| 84 | const INK_PIX = rgb(28, 27, 25), ACCENT_PIX = rgb(156, 61, 107), RING_PIX = rgb(255, 255, 255); | |
| 85 | ||
| 86 | const world = (u, v, z) => [(u + v) / R2, (v - u) / R2, z]; | |
| 87 | ||
| 88 | /* ---------- state ---------- */ | |
| 89 | const best0 = (() => { try { const n = parseFloat(localStorage.getItem(BEST_KEY)); return Number.isFinite(n) && n >= 0 ? n : null; } catch (e) { return null; } })(); | |
| 90 | let P = Cloak.newGame(best0, Date.now() & 0xffff); | |
| 91 | const G = { time: 0, status: '', noteUntil: 0, focus: 0, ring: false }; | |
| 92 | const nodes = {}; | |
| 93 | for (const k of ['round', 'pairs', 'misses', 'clock', 'best', 'status']) nodes[k] = document.getElementById(k); | |
| 94 | const shown = {}; | |
| 95 | function setText(key, text) { | |
| 96 | if (shown[key] === text) return; | |
| 97 | shown[key] = text; | |
| 98 | nodes[key].textContent = text; | |
| 99 | } | |
| 100 | function renderHud() { | |
| 101 | setText('round', `${P.round}/${Cloak.ROUNDS}`); | |
| 102 | setText('pairs', String(P.pairsLeft)); | |
| 103 | setText('misses', `${P.mismatches}/${Cloak.MAX_MISMATCHES}`); | |
| 104 | setText('clock', String(Math.ceil(P.clock))); | |
| 105 | setText('best', P.best === null ? '-' : String(P.best)); | |
| 106 | } | |
| 107 | function note(text) { setText('status', text); G.noteUntil = G.time + 1.6; } | |
| 108 | ||
| 109 | /* ---------- where the coats hang ---------- */ | |
| 110 | // two rails, the back one first: coat i hangs at slot i of its rail | |
| 111 | const perRail = () => P.rail.length / 2; | |
| 112 | function slot(i) { | |
| 113 | const per = perRail(), row = i < per ? 0 : 1, k = i - row * per, step = Math.min(3.5, 29 / per); | |
| 114 | return { u: (k - (per - 1) / 2) * step, v: row ? FRONT_V : BACK_V, row, k, step }; | |
| 115 | } | |
| 116 | const centre = i => { const s = slot(i), p = project(...world(s.u, s.v, TAG_Z)); return [p.sx, p.sy]; }; | |
| 117 | ||
| 118 | /* ---------- baked scene ---------- */ | |
| 119 | function groundColor(x, y, ix, iy) { | |
| 120 | const u = (x - y) / R2, v = (x + y) / R2; | |
| 121 | if (Math.abs(u) > HALF_U || Math.abs(v) > HALF_V) return 0; | |
| 122 | if (Math.abs(u) > HALF_U - .5 || Math.abs(v) > HALF_V - .5) return rgb(...FRAME); | |
| 123 | const board = Math.floor((u + 40) / 2.4) & 1; | |
| 124 | const t = .95 + (hash(ix, iy) - .5) * .07; | |
| 125 | const c = board ? BOARD : BOARD_ALT; | |
| 126 | return rgb(c[0] * t, c[1] * t, c[2] * t); | |
| 127 | } | |
| 128 | // the dance-hall door at the back of the room, its sill across the floor | |
| 129 | function bakeDoor() { | |
| 130 | for (const u of [-5.4, 5.4]) capsule(world(u, -HALF_V + .9, 0), world(u, -HALF_V + .9, 11), .5, .5, () => FRAME, 'rough'); | |
| 131 | capsule(world(-5.4, -HALF_V + .9, 11), world(5.4, -HALF_V + .9, 11), .5, .5, () => FRAME, 'rough'); | |
| 132 | capsule(world(-5, -HALF_V + .9, .1), world(5, -HALF_V + .9, .1), .25, .25, () => WOOD, 'solid'); | |
| 133 | castShadow(...world(5.4, -HALF_V + .9, 5).slice(0, 2), 5, .6, 1, 0); | |
| 134 | } | |
| 135 | function bake() { | |
| 136 | ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0); | |
| 137 | tufts.length = 0; leaves.length = 0; | |
| 138 | zb.fill(-1e9); | |
| 139 | pix.fill(rgb(255, 255, 255)); | |
| 140 | for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) { | |
| 141 | const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy); | |
| 142 | if (!c) continue; | |
| 143 | pix[i] = c; ground[i] = 1; | |
| 144 | zb[i] = (g.x + g.y) / R2 * COS; | |
| 145 | } | |
| 146 | groundZ.set(zb); | |
| 147 | bakeDoor(); | |
| 148 | bakeOcclusion(); | |
| 149 | staticShadow.set(shadowMask); | |
| 150 | applyShadows(groundZ); | |
| 151 | bakedPix.set(pix); | |
| 152 | bakedZ.set(zb); | |
| 153 | } | |
| 154 | ||
| 155 | /* ---------- the coats ---------- */ | |
| 156 | // the light under the door: a strip that breathes in whole steps, still when motion is reduced | |
| 157 | function drawLight(step) { | |
| 158 | const w = STILL ? 3.6 : 2.6 + hash(step, 3) * 2.2, shift = STILL ? 0 : (hash(step, 9) - .5) * 1.4; | |
| 159 | capsule(world(shift - w, -HALF_V + 1.5, .05), world(shift + w, -HALF_V + 1.5, .05), .3, .3, () => LIGHT, 'solid'); | |
| 160 | } | |
| 161 | function drawRails() { | |
| 162 | for (const v of [BACK_V, FRONT_V]) capsule(world(-16, v, RAIL_Z + .4), world(16, v, RAIL_Z + .4), .25, .25, () => BRASS, 'solid'); | |
| 163 | for (const v of [BACK_V, FRONT_V]) for (const u of [-16, 16]) capsule(world(u, v, RAIL_Z + .4), world(u, v, RAIL_Z + 1.6), .2, .2, () => BRASS, 'solid'); | |
| 164 | } | |
| 165 | function drawCoat(i, step) { | |
| 166 | const tag = P.rail[i]; | |
| 167 | if (tag.state === 'gone') return; | |
| 168 | const s = slot(i), up = tag.state === 'up'; | |
| 169 | const sway = STILL ? 0 : ((step + i * 3) % 8 < 4 ? 0 : .22); | |
| 170 | const body = up ? FACES[tag.face] : DRAB, w = s.step * .36; | |
| 171 | const top = world(s.u, s.v, RAIL_Z - .3), shoulder = world(s.u + sway * .3, s.v, RAIL_Z - 1.2), hem = world(s.u + sway, s.v, HEM_Z); | |
| 172 | dynamicAdd(top, shoulder, .12, .16, () => STRING); | |
| 173 | dynamicAdd(shoulder, hem, w * .8, w * 1.15, () => body); | |
| 174 | dynamicAdd(world(s.u - w * .8 + sway * .5, s.v + .2, RAIL_Z - 1.6), world(s.u - w * 1.15 + sway, s.v + .2, HEM_Z + 1.4), .3, .26, () => body); | |
| 175 | dynamicAdd(world(s.u + w * .8 + sway * .5, s.v + .2, RAIL_Z - 1.6), world(s.u + w * 1.15 + sway, s.v + .2, HEM_Z + 1.4), .3, .26, () => body); | |
| 176 | // the tag hangs on the front of the coat on a string; face down it shows its brown back | |
| 177 | dynamicAdd(world(s.u + sway * .2, s.v + 1, RAIL_Z - 1.4), world(s.u + sway * .2, s.v + 1, TAG_Z + .8), .07, .07, () => STRING); | |
| 178 | const t0 = world(s.u + sway * .2, s.v + 1.1, TAG_Z + .75), t1 = world(s.u + sway * .2, s.v + 1.1, TAG_Z - .75); | |
| 179 | dynamicAdd(t0, t1, .8, .8, () => (up ? TAG_FRONT : TAG_BACK)); | |
| 180 | } | |
| 181 | // the number on a turned tag, in the colour of its coat | |
| 182 | function drawGlyphs() { | |
| 183 | for (let i = 0; i < P.rail.length; i++) { | |
| 184 | const tag = P.rail[i]; | |
| 185 | if (tag.state !== 'up') continue; | |
| 186 | const p = project(...world(slot(i).u, slot(i).v + 1.9, TAG_Z)), c = rgb(...FACES[tag.face].map(v => v * .55)); | |
| 187 | const x0 = Math.round(p.sx) - 3, y0 = Math.round(p.sy) - 5; | |
| 188 | GLYPHS[(tag.face + 1) % 10].forEach((row, ry) => { | |
| 189 | for (let cx = 0; cx < 3; cx++) { | |
| 190 | if (row[cx] !== '1') continue; | |
| 191 | for (let dy = 0; dy < 2; dy++) for (let dx = 0; dx < 2; dx++) { | |
| 192 | const x = x0 + cx * 2 + dx, y = y0 + ry * 2 + dy; | |
| 193 | if (x >= 0 && x < W && y >= 0 && y < H) pix[y * W + x] = c; | |
| 194 | } | |
| 195 | } | |
| 196 | }); | |
| 197 | } | |
| 198 | } | |
| 199 | // the focus ring: a white box with an accent edge around the coat the keys will turn | |
| 200 | function drawRing() { | |
| 201 | if (!G.ring || P.over) return; | |
| 202 | const s = slot(G.focus), a = project(...world(s.u, s.v, RAIL_Z)), b = project(...world(s.u, s.v, HEM_Z - .6)); | |
| 203 | const hw = Math.round(Math.min(s.step * 4.2, 15)), cx = Math.round(a.sx), x0 = cx - hw, x1 = cx + hw, y0 = Math.round(a.sy) - 1, y1 = Math.round(b.sy); | |
| 204 | const put = (x, y, c) => { if (x >= 0 && x < W && y >= 0 && y < H) pix[y * W + x] = c; }; | |
| 205 | for (let x = x0 - 1; x <= x1 + 1; x++) for (const y of [y0 - 1, y1 + 1]) put(x, y, RING_PIX); | |
| 206 | for (let y = y0 - 1; y <= y1 + 1; y++) for (const x of [x0 - 1, x1 + 1]) put(x, y, RING_PIX); | |
| 207 | for (let x = x0; x <= x1; x++) { put(x, y0, ACCENT_PIX); put(x, y1, ACCENT_PIX); } | |
| 208 | for (let y = y0; y <= y1; y++) { put(x0, y, ACCENT_PIX); put(x1, y, ACCENT_PIX); } | |
| 209 | } | |
| 210 | ||
| 211 | function draw() { | |
| 212 | pix.set(bakedPix); | |
| 213 | zb.set(bakedZ); | |
| 214 | pendingShadows.length = 0; | |
| 215 | const step = STILL ? 0 : Math.floor(G.time * WIND_FPS); | |
| 216 | drawLight(step); | |
| 217 | drawRails(); | |
| 218 | for (let i = 0; i < P.rail.length; i++) drawCoat(i, step); | |
| 219 | flushShadows(); | |
| 220 | applyShadows(bakedZ); | |
| 221 | shadeEdges(); | |
| 222 | drawGlyphs(); | |
| 223 | drawRing(); | |
| 224 | ctx.putImageData(image, 0, 0); | |
| 225 | } | |
| 226 | ||
| 227 | /* ---------- game ---------- */ | |
| 228 | const HINT = 'turn two tags to find a pair'; | |
| 229 | function act(events) { | |
| 230 | for (const e of events) { | |
| 231 | if (e.type === 'turn') sound(300 + P.rail[e.id].face * 40, .08, 'triangle'); | |
| 232 | if (e.type === 'match') { sound(660 + e.face * 40, .25, 'sine'); sound(990 + e.face * 60, .35, 'sine', .08); note('a pair handed back'); } | |
| 233 | if (e.type === 'mismatch') { sound(140, .3, 'sawtooth'); note(`no match · mismatch ${e.mismatches} of ${Cloak.MAX_MISMATCHES}`); } | |
| 234 | if (e.type === 'round') { G.focus = 0; note(`round ${e.round} · ${P.pairsLeft} pairs`); } | |
| 235 | if (e.type === 'won' || e.type === 'lost') { | |
| 236 | if (e.type === 'won') { sound(520, .3, 'sine'); sound(780, .5, 'sine', .15); } else sound(110, .6, 'sawtooth'); | |
| 237 | if (P.record) try { localStorage.setItem(BEST_KEY, String(P.best)); } catch (err) { /* private window: keep it for this visit */ } | |
| 238 | const tail = P.won ? `${P.mismatches} mismatches · ${P.record ? 'new best' : `best ${P.best}`}` : `${P.pairsLeft} pairs left in round ${P.round}`; | |
| 239 | setText('status', `${P.outcome} · ${tail} · tap or press a key to play again`); | |
| 240 | G.noteUntil = 0; | |
| 241 | } | |
| 242 | } | |
| 243 | renderHud(); | |
| 244 | } | |
| 245 | function turnTag(id) { | |
| 246 | ensureAudio(); | |
| 247 | if (P.over) { | |
| 248 | const next = Cloak.again(P); | |
| 249 | if (next) { P = next; G.focus = 0; G.ring = false; note(HINT); renderHud(); } | |
| 250 | return; | |
| 251 | } | |
| 252 | act(Cloak.turn(P, id)); | |
| 253 | } | |
| 254 | function update(dt) { | |
| 255 | G.time += dt; | |
| 256 | act(Cloak.advance(P, dt)); | |
| 257 | if (P.over || G.time < G.noteUntil) return; | |
| 258 | setText('status', `round ${P.round} of ${Cloak.ROUNDS} · ${P.pairsLeft} pairs left`); | |
| 259 | } | |
| 260 | ||
| 261 | /* ---------- input ---------- */ | |
| 262 | // the coat whose tag is nearest the point, within a coat's width | |
| 263 | function coatAt(px, py) { | |
| 264 | let best = -1, reach = 20; | |
| 265 | for (let i = 0; i < P.rail.length; i++) { | |
| 266 | if (P.rail[i].state === 'gone') continue; | |
| 267 | const [cx, cy] = centre(i), d = Math.hypot(px - cx, (py - cy) * .8); | |
| 268 | if (d < reach) { reach = d; best = i; } | |
| 269 | } | |
| 270 | return best; | |
| 271 | } | |
| 272 | canvas.addEventListener('pointerdown', e => { | |
| 273 | canvas.focus({ preventScroll: true }); | |
| 274 | G.ring = false; | |
| 275 | const r = canvas.getBoundingClientRect(); | |
| 276 | const id = coatAt((e.clientX - r.left) / r.width * W, (e.clientY - r.top) / r.height * H); | |
| 277 | if (id >= 0 || P.over) { if (id >= 0) G.focus = id; turnTag(id); } | |
| 278 | }); | |
| 279 | // the ring steps by one coat or one rail, skipping coats already handed back | |
| 280 | function moveRing(by) { | |
| 281 | const n = P.rail.length; | |
| 282 | for (let i = G.focus + by; i >= 0 && i < n; i += by) if (P.rail[i].state !== 'gone') { G.focus = i; return; } | |
| 283 | } | |
| 284 | const MOVES = { ArrowLeft: () => -1, ArrowRight: () => 1, ArrowUp: () => -perRail(), ArrowDown: () => perRail() }; | |
| 285 | canvas.addEventListener('keydown', e => { | |
| 286 | const move = MOVES[e.key]; | |
| 287 | if (!move && e.key !== ' ' && e.key !== 'Enter') return; | |
| 288 | e.preventDefault(); | |
| 289 | if (e.repeat) return; | |
| 290 | if (P.rail[G.focus] && P.rail[G.focus].state === 'gone') moveRing(1); | |
| 291 | if (move) { G.ring = true; moveRing(move()); return; } | |
| 292 | G.ring = true; | |
| 293 | turnTag(G.focus); | |
| 294 | }); | |
| 295 | ||
| 296 | /* ---------- sound ---------- */ | |
| 297 | let audio = null, muted = false; | |
| 298 | function ensureAudio() { | |
| 299 | if (audio) { if (audio.state === 'suspended') audio.resume(); return; } | |
| 300 | const AC = window.AudioContext || window.webkitAudioContext; | |
| 301 | if (AC) audio = new AC(); | |
| 302 | } | |
| 303 | function sound(freq, life, type, delay = 0) { | |
| 304 | if (!audio || muted) return; | |
| 305 | const now = audio.currentTime + delay, gain = audio.createGain(), osc = audio.createOscillator(); | |
| 306 | osc.type = type; | |
| 307 | osc.frequency.setValueAtTime(freq, now); | |
| 308 | gain.gain.setValueAtTime(.0001, now); | |
| 309 | gain.gain.exponentialRampToValueAtTime(.07, now + .01); | |
| 310 | gain.gain.exponentialRampToValueAtTime(.0005, now + life); | |
| 311 | osc.connect(gain).connect(audio.destination); | |
| 312 | osc.start(now); osc.stop(now + life + .02); | |
| 313 | } | |
| 314 | const muteButton = document.getElementById('mute'); | |
| 315 | muteButton.addEventListener('click', () => { | |
| 316 | muted = !muted; | |
| 317 | muteButton.textContent = muted ? 'sound off' : 'sound on'; | |
| 318 | muteButton.setAttribute('aria-pressed', String(muted)); | |
| 319 | }); | |
| 320 | ||
| 321 | /* ---------- fit and boot ---------- */ | |
| 322 | addEventListener('resize', fit); | |
| 323 | fit(); | |
| 324 | bake(); | |
| 325 | note(HINT); | |
| 326 | renderHud(); | |
| 327 | canvas.focus({ preventScroll: true }); | |
| 328 | let last = performance.now(); | |
| 329 | function frame(now) { | |
| 330 | update(Math.min(.04, (now - last) / 1000)); | |
| 331 | last = now; | |
| 332 | draw(); | |
| 333 | requestAnimationFrame(frame); | |
| 334 | } | |
| 335 | requestAnimationFrame(frame); | |
| 336 | </script> | |
| 337 | </body> | |
| 338 | </html> |
index.html +1
| @@ -97,6 +97,7 @@ footer a::after { content: none; } | ||
| 97 | 97 | <li data-kind="Catching" data-input="Drag" style="--accent:#d08a2e"><a href="egg-basket/">Egg Basket</a><span>Slide the basket under the eave and catch the eggs before three crack</span><span>Game forged by the crew</span><span class="tags">Catching · Drag</span></li> |
| 98 | 98 | <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> |
| 99 | 99 | <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> |
| 100 | <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> | |
| 100 | 101 | </ul> |
| 101 | 102 | <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> |
| 102 | 103 | </main> |
og/cloakroom.png added
Binary file not shown.
og/home.png
Binary file not shown.
rounds.mjs +6
| @@ -30,6 +30,12 @@ export const ROUNDS = { | ||
| 30 | 30 | // pour while the cup is under the spout, and let go in time for the stream's tail to land on the line |
| 31 | 31 | // build nothing, march nowhere, and give up: the second press of R confirms |
| 32 | 32 | 'empire': { over: /victory|defeat/, outcome: /defeat · you gave up at \d+:\d\d · \d+ trained, \d+ defeated/, beat: g => { g.drag([140, 120], [220, 200], .4); g.press('r'); g.run(.5); g.press('r'); g.run(.5); } }, |
| 33 | // turn two coats that do not match, again and again, until the thirteenth mismatch | |
| 34 | 'cloakroom': { over: /play again/, outcome: /lost: too many mismatches · \d+ pairs left in round 1/, beat: g => { | |
| 35 | const pair = g.read('(() => { const d = P.rail.filter(t => t.state === "down"); const b = d.find(t => t.face !== d[0].face); return P.phase === "play" && b ? [centre(d[0].id), centre(b.id)] : null; })()'); | |
| 36 | if (pair) { g.tap(...pair[0]); g.tap(...pair[1]); } | |
| 37 | g.run(.9); | |
| 38 | } }, | |
| 33 | 39 | 'espresso-bar': { over: /pour again/, outcome: /twenty cups poured · \d+/, beat: g => { |
| 34 | 40 | const pour = g.read('R.phase === "play" && !R.done && Math.abs(R.x) <= Pour.WINDOW && R.fill + Pour.RATE * Pour.DELAY < Pour.lineOf(R.cup)'); |
| 35 | 41 | if (pour) g.keyDown(' '); else g.keyUp(' '); |
serve.mjs +1 −1
| @@ -68,7 +68,7 @@ export const server = createServer(async (req, res) => { | ||
| 68 | 68 | if ((await stat(target)).isDirectory()) return res.writeHead(308, { location: path + '/' }).end(); |
| 69 | 69 | const body = await readFile(target); |
| 70 | 70 | res.writeHead(200, { 'content-length': body.length, 'content-type': types[extname(target)] || 'application/octet-stream', 'cache-control': 'no-store', ...security }); |
| 71 | res.end(body); | |
| 71 | res.end(req.method === 'HEAD' ? undefined : body); | |
| 72 | 72 | } catch { |
| 73 | 73 | res.writeHead(404).end('not found'); |
| 74 | 74 | } |
serve.test.mjs +7
| @@ -444,6 +444,13 @@ test('Sheepdog and its rules script are served without a track', async () => { | ||
| 444 | 444 | expect((await fetch(base + '/sheepdog/flock.js')).status).toBe(200); |
| 445 | 445 | }); |
| 446 | 446 | |
| 447 | test('Cloakroom and its rules script are served without a track', async () => { | |
| 448 | const page = await fetch(base + '/cloakroom/'); | |
| 449 | expect(page.status).toBe(200); | |
| 450 | expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8'); | |
| 451 | expect((await fetch(base + '/cloakroom/cloak.js')).status).toBe(200); | |
| 452 | }); | |
| 453 | ||
| 447 | 454 | test('Hot Air Balloon and its rules script are served without a track', async () => { |
| 448 | 455 | const page = await fetch(base + '/hot-air-balloon/'); |
| 449 | 456 | expect(page.status).toBe(200); |
shell.js +1
| @@ -41,6 +41,7 @@ window.PixelPlays = (() => { | ||
| 41 | 41 | { id: 'egg-basket', title: 'Egg Basket', blurb: 'Slide the basket under the eave and catch the eggs before three crack', kind: 'Catching', input: 'Drag', accent: '#d08a2e', music: false, forged: true }, |
| 42 | 42 | { 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 }, |
| 43 | 43 | { 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 }, |
| 44 | { 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 }, | |
| 44 | 45 | ]; |
| 45 | 46 | const MUSIC_VOLUME = .4; |
| 46 | 47 | const CREDITS = [ |
new above
offline