Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Add Bread Oven: slide loaves into a wood-fired oven and pull each one out golden #54
Check · Review · Land · Live done — Landed and live in production.
quill/pixel-plays:quill/39-add-bread-oven-slide-loaves-into-a-wood → main 4 commits fork 5 threads · 5 unresolved
README.md +2 −1
| @@ -30,6 +30,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am | ||
| 30 | 30 | | [](domino-run/) | Twenty dominoes to stand along a curving chalk path in three courtyards, then tip the first: a gap too wide stops the chain, too close topples one early; ringing the bell scores 10 and each domino left over 1 more (forged by the crew on the engine and shell above, not by the original creators) | Tap the path, or arrows + space; tip first button or enter | |
| 31 | 31 | | [](beekeeper/) | A 60-second hive inspection: hold the smoker to calm the bees (its fuel runs low and refills slowly), tap a frame to lift it into the crate, golden frames score 3 and half-capped 1, a dark brood frame costs a sting; three stings or a swarm end the round (forged by the crew on the engine and shell above, not by the original creators) | Tap a frame, hold the smoke button; arrows + space, hold S | |
| 32 | 32 | | [](campfire/) | A 90-second night: keep a campfire at a good height by dragging twigs, branches and logs into the ring; a log smothers a small fire and rain damps the flames (forged by the crew on the engine and shell above, not by the original creators) | Drag from the pile; arrows or 1/2/3 + space | |
| 33 | | [](bread-oven/) | A 60-second shift at a brick oven with four slots: slide dough in with the peel, crusts go pale, golden, dark, burnt, and slots nearer the fire bake faster; pulling golden scores 3, dark 1, pale 0, and a burnt loaf is a strike, three end the round (forged by the crew on the engine and shell above, not by the original creators) | Tap a slot, or arrows + space to slide in, enter to pull | | |
| 33 | 34 | |
| 34 | 35 | ## Run |
| 35 | 36 | Requires [](https://nodejs.org/); nothing to install. |
| @@ -49,7 +50,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is | ||
| 49 | 50 | 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. |
| 50 | 51 | |
| 51 | 52 | ## Add a game |
| 52 | 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 and Beekeeper 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`. | |
| 53 | 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 and Bread Oven 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`. | |
| 53 | 54 | |
| 54 | 55 | - `shell.js` provides the game menu, the Rules popup, the credits and the background music. |
| 55 | 56 | - `engine.js` provides the camera, depth buffer, colour ramps, shadows, edges, figures, trees and wind as globals. |
bread-oven/index.html added +423
| @@ -0,0 +1,423 @@ | ||
| 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>Bread Oven</title> | |
| 7 | <!-- og:begin --> | |
| 8 | <meta name="description" content="Slide loaves into a wood-fired oven and pull each one out golden: golden 3, dark 1, a burnt loaf is a strike"> | |
| 9 | <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/bread-oven/"> | |
| 10 | <meta property="og:type" content="website"> | |
| 11 | <meta property="og:site_name" content="Pixel Plays"> | |
| 12 | <meta property="og:title" content="Bread Oven"> | |
| 13 | <meta property="og:description" content="Slide loaves into a wood-fired oven and pull each one out golden: golden 3, dark 1, a burnt loaf is a strike"> | |
| 14 | <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/bread-oven/"> | |
| 15 | <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/bread-oven.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="Bread Oven: 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; : #c0612b; } | |
| 24 | * { box-sizing: border-box; } | |
| 25 | html, body { height: 100%; margin: 0; background: var(); color: var(); } | |
| 26 | body { font: 13px/1.35 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; overflow: hidden; } | |
| 27 | #stage { position: fixed; inset: 0; display: grid; place-items: center; } | |
| 28 | canvas { display: block; image-rendering: pixelated; touch-action: none; cursor: pointer; outline: none; } | |
| 29 | .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; } | |
| 30 | #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; } | |
| 31 | #bottom { bottom: max(14px, env(safe-area-inset-bottom)); align-items: flex-end; } | |
| 32 | .row { display: flex; align-items: center; gap: 8px; color: var(); } | |
| 33 | .row b { font-size: 16px; font-weight: 600; min-width: 1ch; font-variant-numeric: tabular-nums; } | |
| 34 | .row span { color: var(); } | |
| 35 | #status { color: var(); min-height: 1.35em; } | |
| 36 | button { pointer-events: auto; font: inherit; color: var(); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; } | |
| 37 | button:hover, button:focus-visible { color: var(); } | |
| 38 | </style> | |
| 39 | </head> | |
| 40 | <body> | |
| 41 | <div id="stage"><canvas id="c" tabindex="0" aria-label="A brick bread oven with four slots, a glowing fire at its left end, a counter of dough and a cooling rack. Press left and right arrows to pick a slot, space to slide the next loaf in with the peel, and enter to pull the loaf out. Or tap a slot: an empty one takes a loaf, a loaf in it is pulled. Golden scores 3, dark 1, pale 0, and a burnt loaf costs a strike. 60 seconds or three strikes."></canvas></div> | |
| 42 | <div id="scores"> | |
| 43 | <div class="row"><b id="score">0</b><span>score</span></div> | |
| 44 | <div class="row"><b id="strikes">0</b><span>strikes of 3</span></div> | |
| 45 | <div class="row"><b id="best">0</b><span>best</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: 'bread-oven', | |
| 55 | rules: [ | |
| 56 | 'Arrows pick a slot, space slides a loaf in, enter pulls it out. Or tap a slot.', | |
| 57 | 'Golden scores 3, dark 1, pale 0. Slots near the fire bake faster.', | |
| 58 | 'A burnt loaf is a strike: 60 seconds or three strikes.', | |
| 59 | ], | |
| 60 | }); | |
| 61 | </script> | |
| 62 | <script>window.PP_SCENE = { originY: 36, shadowX: 1.3, shadowY: -.12 };</script> | |
| 63 | <script src="../engine.js"></script> | |
| 64 | <script src="oven.js"></script> | |
| 65 | <script> | |
| 66 | 'use strict'; | |
| 67 | ||
| 68 | const { SLOTS } = Oven; | |
outdated
|
||
| 69 | const BRICK = [176, 88, 66], MORTAR = [214, 198, 178], CAP = [196, 186, 170], SOOT = [70, 62, 60]; | |
| 70 | const WOOD = [150, 106, 70], WOOD_DARK = [104, 72, 50], WIRE = [112, 110, 116], SACK = [236, 228, 208], TIE = [190, 70, 54]; | |
| 71 | const CRUST = { pale: [238, 218, 176], golden: [220, 156, 60], dark: [128, 76, 40], burnt: [40, 32, 30] }; | |
| 72 | const OVEN = { x0: -8, x1: 8.6, y0: -7, y1: -2, h: 7.5 }; | |
| 73 | const SLOT_X = i => -3.6 + i * 3.4, MOUTH_HALF = 1.3, MOUTH_Z0 = 3, MOUTH_Z1 = 5.2, LOAF_Z = MOUTH_Z0 + .65, LOAF_Y = -2.1; | |
| 74 | const COUNTER_Z = 2.4, DOUGH_Y = .3, DOUGH_X = k => -4 + k * 1.9; | |
| 75 | const FIRE = { x0: -7.4, x1: -5.2, z1: 3.3 }; | |
| 76 | const RACK = { x0: 9.8, x1: 13.6, y0: -.2, y1: 3.4, z: 2.2 }; | |
| 77 | const CHIMNEY = { x: -6.6, y: -5.6, top: 11.2 }; | |
| 78 | const rackSpot = k => ({ x: RACK.x0 + 1 + (k % 2) * 2, y: RACK.y0 + .7 + Math.floor(k / 2) * 1.2, z: RACK.z + .55 }); | |
| 79 | const RACK_MAX = 6; | |
| 80 | const BEST_KEY = 'pixel-plays-bread-oven-best'; | |
| 81 | ||
| 82 | /* ---------- state ---------- */ | |
| 83 | const best0 = (() => { try { return Number(localStorage.getItem(BEST_KEY)) || 0; } catch (e) { return 0; } })(); | |
| 84 | let R = Oven.newRound(best0, Date.now() & 0xffff); | |
| 85 | const G = { time: 0, sel: 0, status: '', noteUntil: 0, slide: null, flying: [], rack: [] }; | |
outdated
outdated
|
||
| 86 | const nodes = { score: document.getElementById('score'), strikes: document.getElementById('strikes'), best: document.getElementById('best'), status: document.getElementById('status') }; | |
| 87 | function renderHud() { | |
| 88 | nodes.score.textContent = R.score; | |
| 89 | nodes.strikes.textContent = R.strikes; | |
| 90 | nodes.best.textContent = Math.max(R.best, R.score); | |
| 91 | } | |
| 92 | function setStatus(text) { | |
| 93 | if (text === G.status) return; | |
| 94 | G.status = text; | |
| 95 | nodes.status.textContent = text; | |
| 96 | } | |
| 97 | function note(text) { setStatus(text); G.noteUntil = G.time + 2.2; } | |
| 98 | const HINT = 'arrows pick a slot · space slides a loaf in · enter pulls it out'; | |
| 99 | ||
| 100 | /* ---------- baked scene ---------- */ | |
| 101 | const brickAt = (a, z, shade, seed) => { | |
| 102 | const row = Math.floor(z / .42), off = (row & 1) * .5, col = Math.floor((a + off) / 1); | |
| 103 | const fz = z / .42 - row, fa = (a + off) - col; | |
| 104 | if (fz < .16 || fa < .06) return rgb(MORTAR[0] * shade, MORTAR[1] * shade, MORTAR[2] * shade); | |
| 105 | const g = .9 + hash(col + seed, row) * .2; | |
| 106 | return rgb(BRICK[0] * shade * g, BRICK[1] * shade * g, BRICK[2] * shade * g); | |
| 107 | }; | |
| 108 | function inMouth(dx, z, halfW, z0, z1) { | |
| 109 | if (z < z0) return false; | |
| 110 | if (z <= z1) return Math.abs(dx) <= halfW; | |
| 111 | return dx * dx + (z - z1) * (z - z1) <= halfW * halfW; | |
| 112 | } | |
| 113 | function slabColor(x, y, ix, iy) { | |
| 114 | const e = Math.pow(Math.pow(Math.abs(x - 1) / 14.2, 4) + Math.pow(Math.abs(y + 2.2) / 6.6, 4), .25); | |
| 115 | const rough = e + (noise(x * 1.3, y * 1.3) - .5) * .1; | |
| 116 | if (rough > 1.04) return 0; | |
| 117 | if (rough > .94 && hash(ix, iy) < (rough - .94) / .1) return 0; | |
| 118 | const fx = (x + 40) % 1.6, fy = (y + 40) % 1.6, grout = fx < .07 || fy < .07; | |
| 119 | const t = .88 + (hash(ix, iy) - .5) * .1 + (((Math.floor((x + 40) / 1.6) + Math.floor((y + 40) / 1.6)) & 1) ? .04 : 0) - (grout ? .1 : 0); | |
| 120 | return rgb(214 * t, 204 * t, 188 * t); | |
| 121 | } | |
| 122 | function logPile() { | |
| 123 | const bark = () => WOOD_DARK; | |
| 124 | capsule([-9.6, -1.6, .35], [-8.6, -4, .35], .35, .35, bark, 'rough'); | |
| 125 | capsule([-10.3, -2.4, .35], [-9.2, -4.6, .35], .35, .35, bark, 'rough'); | |
| 126 | capsule([-9.9, -2.4, .95], [-9, -4.3, .95], .33, .33, bark, 'rough'); | |
| 127 | } | |
| 128 | function sack() { | |
| 129 | sphere(-11.2, 1.6, .85, 1.0, SACK, 'rough'); | |
| 130 | sphere(-11.2, 1.6, 1.7, .55, SACK, 'rough'); | |
| 131 | sphere(-11.2, 1.6, 2.12, .22, TIE, 'solid'); | |
| 132 | castShadow(-11.2, 1.6, 1.4, 1.1, 1, .3); | |
| 133 | } | |
| 134 | function bakeOven() { | |
| 135 | const { x0, x1, y0, y1, h } = OVEN; | |
| 136 | box(x0, y0, 0, x1, y1, h, BRICK, 3); | |
| 137 | box(x0 - .3, y0 - .3, h, x1 + .3, y1 + .3, h + .5, CAP, 5); | |
| 138 | // brick courses over the front and right faces | |
| 139 | for (let x = x0; x <= x1; x += .05) for (let z = 0; z <= h; z += .05) plot(x, y1 + .02, z, brickAt(x, z, 1.04, 0)); | |
| 140 | for (let y = y0; y <= y1; y += .05) for (let z = 0; z <= h; z += .05) plot(x1 + .02, y, z, brickAt(y, z, .72, 7)); | |
| 141 | // the slot mouths: dark inside, a ring of lighter brick round each one | |
| 142 | for (let i = 0; i < SLOTS; i++) { | |
| 143 | const cx = SLOT_X(i), glow = 1 - i * .22; | |
| 144 | for (let x = cx - MOUTH_HALF - .5; x <= cx + MOUTH_HALF + .5; x += .05) for (let z = MOUTH_Z0 - .3; z <= MOUTH_Z1 + MOUTH_HALF + .5; z += .05) { | |
| 145 | const dx = x - cx; | |
| 146 | if (inMouth(dx, z, MOUTH_HALF, MOUTH_Z0, MOUTH_Z1)) { | |
| 147 | const heat = Math.max(0, 1 - (z - MOUTH_Z0) / 1.8) * glow, d = hash(Math.round(x * 20), Math.round(z * 20)) * .12; | |
| 148 | plot(x, y1 + .04, z, rgb(34 + 190 * heat, 20 + 70 * heat + d * 30, 16 + 12 * heat)); | |
| 149 | } else if (inMouth(dx, z, MOUTH_HALF + .5, MOUTH_Z0 - .3, MOUTH_Z1)) { | |
| 150 | plot(x, y1 + .04, z, rgb(224 - hash(Math.round(x * 9), Math.round(z * 9)) * 30, 196, 166)); | |
| 151 | } | |
| 152 | } | |
| 153 | } | |
| 154 | // the firebox at the left end, where the heat comes from | |
| 155 | for (let x = FIRE.x0 - .35; x <= FIRE.x1 + .35; x += .05) for (let z = .2; z <= FIRE.z1 + .9; z += .05) { | |
| 156 | const dx = x - (FIRE.x0 + FIRE.x1) / 2, half = (FIRE.x1 - FIRE.x0) / 2; | |
| 157 | if (inMouth(dx, z, half, .5, FIRE.z1)) plot(x, y1 + .04, z, rgb(30 + 120 * Math.max(0, 1 - z / 2.4), 18 + 40 * Math.max(0, 1 - z / 2.4), 14)); | |
| 158 | else if (inMouth(dx, z, half + .35, .2, FIRE.z1)) plot(x, y1 + .04, z, rgb(SOOT[0] + 60, SOOT[1] + 56, SOOT[2] + 52)); | |
| 159 | } | |
| 160 | // chimney | |
| 161 | box(CHIMNEY.x - .8, CHIMNEY.y - .8, h + .5, CHIMNEY.x + .8, CHIMNEY.y + .8, CHIMNEY.top, BRICK, 9); | |
| 162 | box(CHIMNEY.x - 1, CHIMNEY.y - 1, CHIMNEY.top, CHIMNEY.x + 1, CHIMNEY.y + 1, CHIMNEY.top + .35, CAP, 11); | |
| 163 | // counter | |
| 164 | box(-4.9, y1, 0, x1, 1.6, COUNTER_Z, WOOD, 13); | |
| 165 | for (let x = -4.9; x <= x1; x += .05) for (let z = 0; z <= COUNTER_Z; z += .05) if (Math.abs(((x + 4.9) % 3.2) - 1.6) < .04) plot(x, 1.62, z, rgb(...WOOD_DARK)); | |
| 166 | // cooling rack: four legs and a wire grid | |
| 167 | for (const x of [RACK.x0, RACK.x1]) for (const y of [RACK.y0, RACK.y1]) capsule([x, y, 0], [x, y, RACK.z], .1, .1, () => WIRE, 'solid'); | |
| 168 | for (let x = RACK.x0; x <= RACK.x1; x += .42) capsule([x, RACK.y0, RACK.z], [x, RACK.y1, RACK.z], .05, .05, () => WIRE, 'solid'); | |
| 169 | for (let y = RACK.y0; y <= RACK.y1; y += 1.2) capsule([RACK.x0, y, RACK.z], [RACK.x1, y, RACK.z], .06, .06, () => WIRE, 'solid'); | |
| 170 | logPile(); | |
| 171 | sack(); | |
| 172 | // hard shadows fall screen-right | |
| 173 | for (let y = y0; y <= 1.6; y += .5) for (let z = .5; z <= h; z += 1.2) castShadow(x1, y, z, .6, 1, 0); | |
| 174 | for (let x = x0; x <= x1; x += .6) for (let z = .5; z <= h + .5; z += 1.5) castShadow(x, y0, z, .5, 1, 0); | |
| 175 | for (let z = h; z <= CHIMNEY.top; z += .8) castShadow(CHIMNEY.x, CHIMNEY.y, z, .6, 1, 0); | |
| 176 | for (let y = RACK.y0; y <= RACK.y1; y += .6) castShadow(RACK.x1, y, RACK.z, .5, 1, 0); | |
| 177 | for (let x = RACK.x0; x <= RACK.x1; x += .8) castShadow(x, RACK.y0, RACK.z, .4, 1, 0); | |
| 178 | } | |
| 179 | function bake() { | |
| 180 | zb.fill(-1e9); | |
| 181 | pix.fill(rgb(255, 255, 255)); | |
| 182 | for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) { | |
| 183 | const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = slabColor(g.x, g.y, ix, iy); | |
| 184 | if (!c) continue; | |
| 185 | pix[i] = c; ground[i] = 1; | |
| 186 | zb[i] = (g.x + g.y) / R2 * COS; | |
| 187 | } | |
| 188 | groundZ.set(zb); | |
| 189 | bakeOven(); | |
| 190 | bakeOcclusion(); | |
| 191 | applyShadows(groundZ); | |
| 192 | bakedPix.set(pix); | |
| 193 | bakedZ.set(zb); | |
| 194 | } | |
| 195 | ||
| 196 | /* ---------- drawing ---------- */ | |
| 197 | const STAGE_INDEX = { pale: 0, golden: 1, dark: 2, burnt: 3 }; | |
| 198 | // small marks on the crust so the four stages read apart without colour: none, one slash, two slashes, a cross-hatch with ash | |
| 199 | const MARKS = { | |
| 200 | pale: [], | |
| 201 | golden: [[-2, 0], [-1, -1], [0, -2]], | |
| 202 | dark: [[-3, 0], [-2, -1], [-1, -2], [1, 0], [2, -1], [3, -2]], | |
| 203 | burnt: [[-3, -2], [-2, -1], [-1, 0], [0, 1], [-3, 1], [-2, 0], [0, -2], [1, -1], [2, 0], [3, 1]], | |
| 204 | }; | |
| 205 | const MARK_COLOR = { pale: 0, golden: rgb(255, 226, 150), dark: rgb(62, 36, 20), burnt: rgb(150, 142, 136) }; | |
| 206 | function loaf(x, y, z, stage, marks = true) { | |
| 207 | const col = CRUST[stage]; | |
| 208 | capsule([x - .45, y, z], [x + .45, y, z], .66, .66, () => col, 'solid'); | |
| 209 | if (!marks) return; | |
| 210 | const p = project(x, y, z + .5), cx = Math.round(p.sx), cy = Math.round(p.sy) - 1; | |
| 211 | for (const [dx, dy] of MARKS[stage]) { | |
| 212 | const ix = cx + dx, iy = cy + dy; | |
| 213 | if (ix >= 0 && iy >= 0 && ix < W && iy < H) pix[iy * W + ix] = MARK_COLOR[stage]; | |
| 214 | } | |
| 215 | } | |
| 216 | function dough(x, y, z) { // raw dough: a plain pale lump, no marks | |
| 217 | capsule([x - .4, y, z], [x + .4, y, z], .52, .52, () => [246, 238, 216], 'solid'); | |
| 218 | } | |
| 219 | function peel(x, y) { | |
| 220 | const z = COUNTER_Z + .12; | |
| 221 | box(x - .95, y - 1.1, z, x + .95, y + .9, z + .1, [222, 186, 132], 17); | |
| 222 | capsule([x, y + .9, z + .05], [x, y + 4.6, z + .05], .12, .12, () => WOOD_DARK, 'solid'); | |
| 223 | } | |
| 224 | function flames(t) { | |
| 225 | const step = STILL ? 0 : Math.floor(t * 8), cx = (FIRE.x0 + FIRE.x1) / 2; | |
| 226 | for (let k = 0; k < 5; k++) { | |
| 227 | const flick = STILL ? .5 : hash(k, step), x = cx - 0.9 + k * .45; | |
| 228 | const h = .8 + hash(k, 3) * .5 + flick * .6; | |
| 229 | capsule([x, OVEN.y1 + .3, .7], [x + (flick - .5) * .3, OVEN.y1 + .3, .7 + h], .3, .12, z => (z > 1.7 ? [255, 214, 92] : [244, 120, 36]), 'solid'); | |
| 230 | } | |
| 231 | } | |
| 232 | function embers(t) { | |
| 233 | const step = STILL ? 0 : Math.floor(t * 6); | |
| 234 | for (let i = 0; i < SLOTS; i++) for (let k = 0; k < 4; k++) { | |
| 235 | if (hash(i * 7 + k, step) < .5 - i * .05) continue; | |
| 236 | plot(SLOT_X(i) - 1 + hash(k, i) * 2, OVEN.y1 + .08, MOUTH_Z0 + .1 + hash(i, k) * .5, rgb(255, 168, 60)); | |
| 237 | } | |
| 238 | } | |
| 239 | function smoke(t) { | |
| 240 | const time = STILL ? 0 : t; | |
| 241 | for (let k = 0; k < 7; k++) { | |
| 242 | const ph = (time * .22 + k / 7) % 1, rise = ph * 5, drift = ph * 2.4 + Math.sin(ph * 6 + k) * .4; | |
| 243 | sphere(CHIMNEY.x + drift, CHIMNEY.y + drift * .3, CHIMNEY.top + .6 + rise, .35 + ph * .55, [214 - ph * 20, 212 - ph * 20, 210 - ph * 18], 'rough'); | |
| 244 | } | |
| 245 | } | |
| 246 | function pips() { | |
| 247 | for (let i = 0; i < SLOTS; i++) { | |
| 248 | const l = R.slots[i]; | |
| 249 | if (!l) continue; | |
| 250 | const n = STAGE_INDEX[Oven.stageOf(l.bake)] + 1, p = project(SLOT_X(i), OVEN.y1, OVEN.h - .4); | |
| 251 | for (let k = 0; k < 4; k++) { | |
| 252 | const ix = Math.round(p.sx) - 7 + k * 4, iy = Math.round(p.sy); | |
| 253 | for (let dx = 0; dx < 3; dx++) for (let dy = 0; dy < 3; dy++) pix[(iy + dy) * W + ix + dx] = k < n ? rgb(28, 27, 25) : rgb(190, 170, 150); | |
| 254 | } | |
| 255 | } | |
| 256 | } | |
| 257 | function selector() { | |
| 258 | if (R.phase !== 'play') return; | |
| 259 | const p = project(SLOT_X(G.sel), OVEN.y1, OVEN.h + .6); | |
| 260 | drawArrow(p.sx, p.sy, G.time); | |
| 261 | } | |
| 262 | function draw() { | |
| 263 | pix.set(bakedPix); | |
| 264 | zb.set(bakedZ); | |
| 265 | const t = G.time; | |
| 266 | flames(t); | |
| 267 | embers(t); | |
| 268 | // loaves in the oven, and the one sliding in on the peel | |
| 269 | const sliding = G.slide; | |
| 270 | for (let i = 0; i < SLOTS; i++) { | |
| 271 | const l = R.slots[i]; | |
| 272 | if (!l) continue; | |
| 273 | let y = LOAF_Y; | |
| 274 | if (sliding && sliding.slot === i && sliding.t < .5) y = DOUGH_Y - (DOUGH_Y - LOAF_Y) * ease(sliding.t * 2); | |
| 275 | loaf(SLOT_X(i), y, LOAF_Z, Oven.stageOf(l.bake)); | |
| 276 | } | |
| 277 | // dough waiting on the counter | |
| 278 | for (let k = 0; k < R.counter; k++) dough(DOUGH_X(k), DOUGH_Y + .9, COUNTER_Z + .6); | |
| 279 | // the peel follows the chosen slot and darts in when a loaf is slid | |
| 280 | const px = SLOT_X(G.sel), push = sliding ? Math.sin(Math.PI * sliding.t) * (DOUGH_Y - LOAF_Y + .7) : 0; | |
| 281 | peel(px, DOUGH_Y - push + .2); | |
| 282 | // the cooling rack | |
| 283 | G.rack.forEach((stage, k) => { const s = rackSpot(k); loaf(s.x, s.y, s.z, stage); }); | |
| 284 | for (const f of G.flying) { | |
| 285 | const e = ease(f.t), x = lerp(f.from.x, f.to.x, e), y = lerp(f.from.y, f.to.y, e); | |
| 286 | loaf(x, y, lerp(f.from.z, f.to.z, e) + Math.sin(Math.PI * f.t) * 2.2, f.stage); | |
| 287 | } | |
| 288 | smoke(t); | |
| 289 | shadeEdges(); | |
| 290 | pips(); | |
| 291 | selector(); | |
| 292 | ctx.putImageData(image, 0, 0); | |
| 293 | } | |
| 294 | ||
| 295 | /* ---------- game ---------- */ | |
| 296 | function act(events) { | |
| 297 | if (!events) return; | |
| 298 | for (const e of [].concat(events)) { | |
| 299 | if (e.type === 'slide') { G.slide = { slot: e.slot, t: 0 }; sound('thud'); } | |
| 300 | if (e.type === 'pull') { | |
| 301 | // every pulled loaf flies on its own, so two quick pulls both reach the rack | |
| 302 | const spot = rackSpot(Math.min(G.rack.length + G.flying.length, RACK_MAX - 1)); | |
outdated
This replaces any loaf still in flight. If a second pull happens within 0.35 s, the first loaf is never pushed to
outdated
This replaces a loaf already in flight, so a second pull within 0.35 s loses the first loaf. Land the earlier one first, e.g. |
||
| 303 | G.flying.push({ stage: e.stage, t: 0, from: { x: SLOT_X(e.slot), y: LOAF_Y, z: LOAF_Z }, to: spot }); | |
| 304 | note(e.strike ? 'burnt: a strike' : e.points ? `${e.stage}: +${e.points}` : `${e.stage}: nothing`); | |
| 305 | sound(e.strike ? 'buzz' : e.points >= 3 ? 'chime' : 'thud'); | |
| 306 | } | |
| 307 | if (e.type === 'stage' && e.stage === 'golden') sound('tick'); | |
| 308 | if (e.type === 'over') { | |
| 309 | if (R.record) try { localStorage.setItem(BEST_KEY, String(R.best)); } catch (err) { /* private window: keep it for this visit */ } | |
| 310 | setStatus(`${e.reason === 'strikes' ? 'three strikes' : 'time'} · ${R.score}${R.record ? ' · new best' : ` · best ${R.best}`} · tap or space to bake again`); | |
| 311 | } | |
| 312 | } | |
| 313 | renderHud(); | |
| 314 | } | |
| 315 | function restart() { | |
| 316 | const next = Oven.again(R); | |
| 317 | if (!next) return false; | |
| 318 | R = next; G.rack = []; G.slide = null; G.flying = []; | |
| 319 | note(HINT); | |
| 320 | renderHud(); | |
| 321 | return true; | |
| 322 | } | |
| 323 | function doSlide(slot) { act(Oven.slide(R, slot)); } | |
| 324 | function doPull(slot) { act(Oven.pull(R, slot)); } | |
| 325 | function update(dt) { | |
| 326 | G.time += dt; | |
| 327 | if (G.slide) { G.slide.t += dt / .4; if (G.slide.t >= 1) G.slide = null; } | |
| 328 | for (const f of G.flying) f.t += dt / .35; | |
| 329 | while (G.flying.length && G.flying[0].t >= 1) { | |
| 330 | if (G.rack.length >= RACK_MAX) G.rack.shift(); | |
| 331 | G.rack.push(G.flying.shift().stage); | |
| 332 | } | |
| 333 | act(Oven.advance(R, dt)); | |
| 334 | if (R.phase === 'play' && G.time >= G.noteUntil) { | |
| 335 | const l = R.slots[G.sel], what = l ? Oven.stageOf(l.bake) : 'empty'; | |
| 336 | setStatus(`slot ${G.sel + 1} ${what} · ${R.counter} dough · ${Math.ceil(Oven.timeLeft(R))}s`); | |
| 337 | } | |
| 338 | } | |
| 339 | ||
| 340 | /* ---------- input ---------- */ | |
| 341 | // the slot whose mouth is under a canvas point, or -1 | |
| 342 | function slotAt(e) { | |
| 343 | const rect = canvas.getBoundingClientRect(); | |
| 344 | const sx = (e.clientX - rect.left) / rect.width * W, sy = (e.clientY - rect.top) / rect.height * H; | |
| 345 | let best = -1, bestD = 1e9; | |
| 346 | for (let i = 0; i < SLOTS; i++) { | |
| 347 | const p = project(SLOT_X(i), OVEN.y1, (MOUTH_Z0 + MOUTH_Z1) / 2 + .6), dx = (sx - p.sx) / 12, dy = (sy - p.sy) / 20, d = dx * dx + dy * dy; | |
| 348 | if (d <= 1 && d < bestD) { best = i; bestD = d; } | |
| 349 | } | |
| 350 | return best; | |
| 351 | } | |
| 352 | canvas.addEventListener('pointerdown', e => { | |
| 353 | ensureAudio(); | |
| 354 | canvas.focus({ preventScroll: true }); | |
| 355 | if (restart() || R.phase !== 'play') return; | |
| 356 | const slot = slotAt(e); | |
| 357 | if (slot < 0) { doSlide(G.sel); return; } | |
| 358 | G.sel = slot; | |
| 359 | if (R.slots[slot]) doPull(slot); else doSlide(slot); | |
| 360 | }); | |
| 361 | canvas.addEventListener('keydown', e => { | |
| 362 | const key = e.key; | |
| 363 | if (!(key === ' ' || key === 'Enter' || key.startsWith('Arrow') || ['a', 'A', 'd', 'D'].includes(key))) return; | |
| 364 | e.preventDefault(); | |
| 365 | ensureAudio(); | |
| 366 | if (e.repeat) return; | |
| 367 | if (restart() || R.phase !== 'play') return; | |
| 368 | if (key === 'ArrowLeft' || key === 'a' || key === 'A') G.sel = (G.sel + SLOTS - 1) % SLOTS; | |
| 369 | else if (key === 'ArrowRight' || key === 'd' || key === 'D') G.sel = (G.sel + 1) % SLOTS; | |
| 370 | else if (key === ' ') doSlide(G.sel); | |
| 371 | else if (key === 'Enter') doPull(G.sel); | |
| 372 | G.noteUntil = 0; | |
| 373 | }); | |
| 374 | ||
| 375 | /* ---------- sound ---------- */ | |
| 376 | let audio = null, muted = false; | |
| 377 | function ensureAudio() { | |
| 378 | if (audio) { if (audio.state === 'suspended') audio.resume(); return; } | |
| 379 | const AC = window.AudioContext || window.webkitAudioContext; | |
| 380 | if (AC) audio = new AC(); | |
| 381 | } | |
| 382 | function sound(kind) { | |
| 383 | if (!audio || muted) return; | |
| 384 | const now = audio.currentTime, gain = audio.createGain(), osc = audio.createOscillator(); | |
| 385 | const spec = { | |
| 386 | thud: [180, 90, .12, .08, 'sine'], | |
| 387 | tick: [900, 1200, .06, .02, 'triangle'], | |
| 388 | chime: [520, 880, .25, .07, 'sine'], | |
| 389 | buzz: [150, 70, .3, .06, 'sawtooth'], | |
| 390 | }[kind]; | |
| 391 | osc.type = spec[4]; | |
| 392 | osc.frequency.setValueAtTime(spec[0], now); | |
| 393 | osc.frequency.exponentialRampToValueAtTime(spec[1], now + spec[2]); | |
| 394 | gain.gain.setValueAtTime(spec[3], now); | |
| 395 | gain.gain.exponentialRampToValueAtTime(.0005, now + spec[2]); | |
| 396 | osc.connect(gain).connect(audio.destination); | |
| 397 | osc.start(now); osc.stop(now + spec[2] + .01); | |
| 398 | } | |
| 399 | const muteButton = document.getElementById('mute'); | |
| 400 | muteButton.addEventListener('click', () => { | |
| 401 | muted = !muted; | |
| 402 | muteButton.textContent = muted ? 'sound off' : 'sound on'; | |
| 403 | muteButton.setAttribute('aria-pressed', String(muted)); | |
| 404 | }); | |
| 405 | ||
| 406 | /* ---------- fit and boot ---------- */ | |
| 407 | addEventListener('resize', fit); | |
| 408 | fit(); | |
| 409 | bake(); | |
| 410 | note(HINT); | |
| 411 | renderHud(); | |
| 412 | canvas.focus({ preventScroll: true }); | |
| 413 | let last = performance.now(); | |
| 414 | function frame(now) { | |
| 415 | update(Math.min(.04, (now - last) / 1000)); | |
| 416 | last = now; | |
| 417 | draw(); | |
| 418 | requestAnimationFrame(frame); | |
| 419 | } | |
| 420 | requestAnimationFrame(frame); | |
| 421 | </script> | |
| 422 | </body> | |
| 423 | </html> |
bread-oven/oven.js added +94
| @@ -0,0 +1,94 @@ | ||
| 1 | 'use strict'; | |
| 2 | // The bread oven rules: four slots at different distances from the fire, loaves that brown with time, | |
| 3 | // a pull that scores by crust, and a round of 60 seconds or three strikes. | |
| 4 | // Plain numbers in, plain numbers out, no DOM. The page draws what this decides. | |
| 5 | (function (root) { | |
| 6 | const SLOTS = 4; | |
| 7 | const RATES = [1.5, 1.15, .85, .6]; // baking speed per slot, slot 0 sits nearest the fire | |
| 8 | const GOLDEN_AT = 6, DARK_AT = 10, BURNT_AT = 13; // bake seconds (at rate 1) where each crust stage begins | |
| 9 | const VALUES = { pale: 0, golden: 3, dark: 1, burnt: 0 }; | |
| 10 | const STRIKE_ON = 'burnt'; | |
| 11 | const MAX_STRIKES = 3; | |
| 12 | const ROUND_TIME = 60; | |
| 13 | const LOAF_EVERY = 4, COUNTER_MAX = 3, COUNTER_START = 2; | |
| 14 | const RESTART_AFTER = .6; | |
| 15 | ||
| 16 | const finite = v => (Number.isFinite(v) ? v : 0); | |
| 17 | const isSlot = n => Number.isInteger(n) && n >= 0 && n < SLOTS; | |
| 18 | ||
| 19 | function stageOf(bake) { | |
| 20 | bake = finite(bake); | |
| 21 | return bake >= BURNT_AT ? 'burnt' : bake >= DARK_AT ? 'dark' : bake >= GOLDEN_AT ? 'golden' : 'pale'; | |
| 22 | } | |
| 23 | // seconds a loaf pushed into this slot takes to reach a stage | |
| 24 | function secondsTo(slot, stage) { | |
| 25 | const at = { golden: GOLDEN_AT, dark: DARK_AT, burnt: BURNT_AT }[stage]; | |
| 26 | return isSlot(slot) && at ? at / RATES[slot] : 0; | |
| 27 | } | |
| 28 | const valueOf = stage => VALUES[stage] || 0; | |
| 29 | ||
| 30 | function newRound(best = 0, seed = 0) { | |
| 31 | return { | |
| 32 | phase: 'play', time: 0, timer: 0, score: 0, strikes: 0, baked: 0, | |
| 33 | best: Math.max(0, finite(best)), record: false, seed: finite(seed) >>> 0, | |
| 34 | slots: Array.from({ length: SLOTS }, () => null), | |
| 35 | counter: COUNTER_START, nextLoaf: LOAF_EVERY, reason: '', | |
| 36 | }; | |
| 37 | } | |
| 38 | const timeLeft = s => Math.max(0, ROUND_TIME - s.time); | |
| 39 | ||
| 40 | function finish(s, reason, events) { | |
| 41 | s.phase = 'over'; s.reason = reason; s.timer = 0; | |
outdated
Dead code:
outdated
Still unused: delete |
||
| 42 | if (s.score > s.best) { s.best = s.score; s.record = true; } | |
| 43 | events.push({ type: 'over', reason, score: s.score, record: s.record }); | |
| 44 | } | |
| 45 | ||
| 46 | // slide the next loaf from the counter into an empty slot; null when it cannot be done | |
| 47 | function slide(s, slot) { | |
| 48 | if (s.phase !== 'play' || !isSlot(slot) || s.slots[slot] || s.counter < 1) return null; | |
| 49 | s.counter--; | |
| 50 | s.slots[slot] = { bake: 0 }; | |
| 51 | return { type: 'slide', slot }; | |
| 52 | } | |
| 53 | // pull the loaf out onto the rack: scores by crust, a burnt one is a strike; null for an empty slot | |
| 54 | function pull(s, slot) { | |
| 55 | if (s.phase !== 'play' || !isSlot(slot) || !s.slots[slot]) return null; | |
| 56 | const stage = stageOf(s.slots[slot].bake), points = valueOf(stage), strike = stage === STRIKE_ON; | |
| 57 | s.slots[slot] = null; | |
| 58 | s.score += points; s.baked++; | |
| 59 | if (strike) s.strikes++; | |
| 60 | const events = [{ type: 'pull', slot, stage, points, strike }]; | |
| 61 | if (s.strikes >= MAX_STRIKES) finish(s, 'strikes', events); | |
| 62 | return events; | |
| 63 | } | |
| 64 | function advance(s, dt) { | |
| 65 | const events = []; | |
| 66 | dt = Math.max(0, Math.min(1, finite(dt))); | |
| 67 | if (s.phase !== 'play') { s.timer += dt; return events; } | |
| 68 | s.time += dt; | |
| 69 | s.slots.forEach((loaf, i) => { | |
| 70 | if (!loaf) return; | |
| 71 | const was = stageOf(loaf.bake); | |
| 72 | loaf.bake += dt * RATES[i]; | |
| 73 | const now = stageOf(loaf.bake); | |
| 74 | if (now !== was) events.push({ type: 'stage', slot: i, stage: now }); | |
| 75 | }); | |
| 76 | s.nextLoaf -= dt; | |
| 77 | while (s.nextLoaf <= 0) { | |
| 78 | s.nextLoaf += LOAF_EVERY; | |
| 79 | if (s.counter < COUNTER_MAX) { s.counter++; events.push({ type: 'arrive', counter: s.counter }); } | |
| 80 | } | |
| 81 | if (s.time >= ROUND_TIME) { s.time = ROUND_TIME; finish(s, 'time', events); } | |
| 82 | return events; | |
| 83 | } | |
| 84 | // a tap after the round has been over for a moment starts the next one; otherwise null | |
| 85 | function again(s) { | |
| 86 | return s.phase === 'over' && s.timer > RESTART_AFTER ? newRound(s.best, s.seed + 1) : null; | |
| 87 | } | |
| 88 | ||
| 89 | const api = { | |
| 90 | SLOTS, RATES, GOLDEN_AT, DARK_AT, BURNT_AT, VALUES, MAX_STRIKES, ROUND_TIME, LOAF_EVERY, COUNTER_MAX, RESTART_AFTER, | |
| 91 | stageOf, secondsTo, valueOf, newRound, timeLeft, slide, pull, advance, again, | |
| 92 | }; | |
| 93 | if (typeof module !== 'undefined') module.exports = api; else root.Oven = api; | |
outdated
|
||
| 94 | })(typeof window !== 'undefined' ? window : globalThis); |
bread-oven/oven.test.mjs added +121
| @@ -0,0 +1,121 @@ | ||
| 1 | import { test, expect } from 'bun:test'; | |
| 2 | import { SLOTS, RATES, MAX_STRIKES, ROUND_TIME, COUNTER_MAX, LOAF_EVERY, stageOf, secondsTo, valueOf, newRound, slide, pull, advance, again, timeLeft } from './oven.js'; | |
| 3 | ||
| 4 | const bakeFor = (s, seconds) => { for (let t = 0; t < seconds - 1e-9; t += .1) advance(s, .1); }; | |
| 5 | // a loaf in this slot, baked until it shows `stage` | |
| 6 | function loafAt(s, slot, stage) { | |
| 7 | s.counter = Math.max(s.counter, 1); | |
| 8 | slide(s, slot); | |
| 9 | s.slots[slot].bake = { pale: 0, golden: 7, dark: 11, burnt: 14 }[stage]; | |
| 10 | } | |
| 11 | ||
| 12 | test('crust stages change at their thresholds', () => { | |
| 13 | expect(stageOf(5.9)).toBe('pale'); | |
| 14 | expect(stageOf(6)).toBe('golden'); | |
| 15 | expect(stageOf(10)).toBe('dark'); | |
| 16 | expect(stageOf(13)).toBe('burnt'); | |
| 17 | expect(stageOf(NaN)).toBe('pale'); | |
| 18 | }); | |
| 19 | ||
| 20 | test('a near-fire slot reaches golden sooner than a far one', () => { | |
| 21 | expect(RATES[0]).toBeGreaterThan(RATES[SLOTS - 1]); | |
| 22 | const s = newRound(0, 1); | |
| 23 | slide(s, 0); slide(s, 3); | |
| 24 | bakeFor(s, 5); | |
| 25 | expect(stageOf(s.slots[0].bake)).toBe('golden'); | |
| 26 | expect(stageOf(s.slots[3].bake)).toBe('pale'); | |
| 27 | expect(secondsTo(0, 'golden')).toBeLessThan(secondsTo(3, 'golden')); | |
| 28 | }); | |
| 29 | ||
| 30 | test('pulling a golden loaf scores 3, dark 1, pale 0', () => { | |
| 31 | const s = newRound(); | |
| 32 | loafAt(s, 1, 'golden'); | |
| 33 | expect(pull(s, 1)[0]).toMatchObject({ stage: 'golden', points: 3, strike: false }); | |
| 34 | loafAt(s, 1, 'dark'); | |
| 35 | expect(pull(s, 1)[0].points).toBe(1); | |
| 36 | loafAt(s, 1, 'pale'); | |
| 37 | expect(pull(s, 1)[0].points).toBe(0); | |
| 38 | expect(s.score).toBe(4); | |
| 39 | expect(s.strikes).toBe(0); | |
| 40 | expect(s.slots[1]).toBe(null); | |
| 41 | expect(valueOf('golden')).toBe(3); | |
| 42 | }); | |
| 43 | ||
| 44 | test('a burnt loaf adds a strike and scores nothing', () => { | |
| 45 | const s = newRound(); | |
| 46 | loafAt(s, 0, 'burnt'); | |
| 47 | expect(pull(s, 0)[0]).toMatchObject({ stage: 'burnt', points: 0, strike: true }); | |
| 48 | expect(s.strikes).toBe(1); | |
| 49 | expect(s.score).toBe(0); | |
| 50 | }); | |
| 51 | ||
| 52 | test('three strikes end the round and keep the best', () => { | |
| 53 | const s = newRound(2); | |
| 54 | for (let n = 0; n < MAX_STRIKES; n++) { | |
| 55 | expect(s.phase).toBe('play'); | |
| 56 | loafAt(s, 0, 'golden'); pull(s, 0); | |
| 57 | loafAt(s, 0, 'burnt'); | |
| 58 | const events = pull(s, 0); | |
| 59 | if (n === MAX_STRIKES - 1) expect(events.at(-1)).toMatchObject({ type: 'over', reason: 'strikes' }); | |
| 60 | } | |
| 61 | expect(s.phase).toBe('over'); | |
| 62 | expect(s.score).toBe(9); | |
| 63 | expect(s.best).toBe(9); | |
| 64 | expect(s.record).toBe(true); | |
| 65 | expect(slide(s, 1)).toBe(null); | |
| 66 | }); | |
| 67 | ||
| 68 | test('an empty slot cannot be pulled, an occupied one cannot take a second loaf', () => { | |
| 69 | const s = newRound(); | |
| 70 | expect(pull(s, 2)).toBe(null); | |
| 71 | expect(slide(s, 2)).toEqual({ type: 'slide', slot: 2 }); | |
| 72 | expect(slide(s, 2)).toBe(null); | |
| 73 | expect(pull(s, 9)).toBe(null); | |
| 74 | expect(pull(s, 1.5)).toBe(null); | |
| 75 | expect(pull(s, NaN)).toBe(null); | |
| 76 | expect(slide(s, -1)).toBe(null); | |
| 77 | }); | |
| 78 | ||
| 79 | test('a loaf needs dough on the counter, and dough arrives on a timer up to a cap', () => { | |
| 80 | const s = newRound(); | |
| 81 | slide(s, 0); slide(s, 1); | |
| 82 | expect(s.counter).toBe(0); | |
| 83 | expect(slide(s, 2)).toBe(null); | |
| 84 | const events = []; | |
| 85 | for (let n = 0; n < LOAF_EVERY; n++) events.push(...advance(s, 1)); | |
| 86 | expect(events.some(e => e.type === 'arrive')).toBe(true); | |
| 87 | expect(s.counter).toBe(1); | |
| 88 | bakeFor(s, 24); | |
| 89 | expect(s.counter).toBe(COUNTER_MAX); | |
| 90 | }); | |
| 91 | ||
| 92 | test('the round ends at 60 seconds and restarts after a pause', () => { | |
| 93 | const s = newRound(0, 5); | |
| 94 | loafAt(s, 0, 'golden'); pull(s, 0); | |
| 95 | let over; | |
| 96 | for (let t = 0; t < ROUND_TIME && !over; t++) over = advance(s, 1).find(e => e.type === 'over'); | |
| 97 | expect(over).toMatchObject({ reason: 'time', score: 3, record: true }); | |
| 98 | expect(timeLeft(s)).toBe(0); | |
| 99 | expect(again(s)).toBe(null); | |
| 100 | advance(s, 1); | |
| 101 | const next = again(s); | |
| 102 | expect(next.phase).toBe('play'); | |
| 103 | expect(next.best).toBe(3); | |
| 104 | expect(next.score).toBe(0); | |
| 105 | }); | |
| 106 | ||
| 107 | test('advance ignores bad time steps', () => { | |
| 108 | const s = newRound(); | |
| 109 | slide(s, 0); | |
| 110 | advance(s, NaN); advance(s, -5); | |
| 111 | expect(s.time).toBe(0); | |
| 112 | expect(s.slots[0].bake).toBe(0); | |
| 113 | }); | |
| 114 | ||
| 115 | test('stage events fire once as a loaf browns', () => { | |
| 116 | const s = newRound(); | |
| 117 | slide(s, 0); | |
| 118 | const seen = []; | |
| 119 | for (let t = 0; t < 12; t += .1) for (const e of advance(s, .1)) if (e.type === 'stage') seen.push(e.stage); | |
| 120 | expect(seen).toEqual(['golden', 'dark', 'burnt']); | |
| 121 | }); |
index.html +1
| @@ -80,6 +80,7 @@ footer a::after { content: none; } | ||
| 80 | 80 | <li data-kind="Precision" data-input="Tap" style="--accent:#8a5ea8"><a href="domino-run/">Domino Run</a><span>Set out a line of 20 dominoes along a chalk path and tip the first: a gap too wide stops the chain, too close topples one early, ring the bell for 10 plus 1 per domino left</span><span>Game forged by the crew</span><span class="tags">Precision · Tap</span></li> |
| 81 | 81 | <li data-kind="Timing" data-input="Hold" style="--accent:#d9a02a"><a href="beekeeper/">Beekeeper</a><span>Smoke the hive calm and lift out honey frames before the bees swarm: gold 3, half 1, a dark brood frame stings</span><span>Game forged by the crew</span><span class="tags">Timing · Hold</span></li> |
| 82 | 82 | <li data-kind="Precision" data-input="Drag" style="--accent:#e0793a"><a href="campfire/">Campfire</a><span>Keep a campfire burning through a 90 second night: drag twigs, branches and logs into the ring, a log smothers a small fire and rain damps the flames</span><span>Game forged by the crew</span><span class="tags">Precision · Drag</span></li> |
| 83 | <li data-kind="Timing" data-input="Tap" style="--accent:#c0612b"><a href="bread-oven/">Bread Oven</a><span>Slide loaves into a wood-fired oven and pull each one out golden: golden 3, dark 1, a burnt loaf is a strike</span><span>Game forged by the crew</span><span class="tags">Timing · Tap</span></li> | |
| 83 | 84 | </ul> |
| 84 | 85 | <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> |
| 85 | 86 | </main> |
og/bread-oven.png added
og/home.png
serve.test.mjs +7
| @@ -163,6 +163,13 @@ test('Campfire and its rules script are served without a track', async () => { | ||
| 163 | 163 | expect((await fetch(base + '/campfire/fire.js')).status).toBe(200); |
| 164 | 164 | }); |
| 165 | 165 | |
| 166 | test('Bread Oven and its rules script are served without a track', async () => { | |
| 167 | const page = await fetch(base + '/bread-oven/'); | |
| 168 | expect(page.status).toBe(200); | |
| 169 | expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8'); | |
| 170 | expect((await fetch(base + '/bread-oven/oven.js')).status).toBe(200); | |
| 171 | }); | |
| 172 | ||
| 166 | 173 | test('every game and the home page carry share-card tags and a served PNG card', async () => { |
| 167 | 174 | const { games, withTags, ORIGIN, CARD, HOME } = await import('./scripts/og.mjs'); |
| 168 | 175 | const { readFileSync } = await import('node:fs'); |
shell.js +1
| @@ -24,6 +24,7 @@ window.PixelPlays = (() => { | ||
| 24 | 24 | { id: 'domino-run', title: 'Domino Run', blurb: 'Set out a line of 20 dominoes along a chalk path and tip the first: a gap too wide stops the chain, too close topples one early, ring the bell for 10 plus 1 per domino left', kind: 'Precision', input: 'Tap', accent: '#8a5ea8', music: false, forged: true }, |
| 25 | 25 | { id: 'beekeeper', title: 'Beekeeper', blurb: 'Smoke the hive calm and lift out honey frames before the bees swarm: gold 3, half 1, a dark brood frame stings', kind: 'Timing', input: 'Hold', accent: '#d9a02a', music: false, forged: true }, |
| 26 | 26 | { id: 'campfire', title: 'Campfire', blurb: 'Keep a campfire burning through a 90 second night: drag twigs, branches and logs into the ring, a log smothers a small fire and rain damps the flames', kind: 'Precision', input: 'Drag', accent: '#e0793a', music: false, forged: true }, |
| 27 | { id: 'bread-oven', title: 'Bread Oven', blurb: 'Slide loaves into a wood-fired oven and pull each one out golden: golden 3, dark 1, a burnt loaf is a strike', kind: 'Timing', input: 'Tap', accent: '#c0612b', music: false, forged: true }, | |
| 27 | 28 | ]; |
| 28 | 29 | const MUSIC_VOLUME = .4; |
| 29 | 30 | const CREDITS = [ |
ROUND_TIME,MAX_STRIKESandCOUNTER_MAXare destructured here and never used on the page. OnlySLOTSis needed.