Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Add Beekeeper: smoke the hive calm and lift out honey frames before the bees swarm #53
Check · Review · Land · Live done — Landed and live in production.
quill/pixel-plays:quill/36-add-beekeeper-smoke-the-hive-calm-and-li → main 3 commits fork 4 threads · 4 unresolved
README.md +2 −1
| @@ -28,6 +28,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am | ||
| 28 | 28 | | [](window-washer/) | Five grimy windows, twelve seconds each: wipe the glass clean with a squeegee before the cradle drops a floor, bird droppings need two passes, score the percentage clean (forged by the crew on the engine and shell above, not by the original creators) | Drag; arrows + space | |
| 29 | 29 | | [](market-scale/) | Five customers, 15 seconds each: weigh fruit onto a hanging pan scale to match the weight on the chalk slate, exact scores 3 and within 50 g scores 1 (forged by the crew on the engine and shell above, not by the original creators) | Drag or tap fruit, tap the bell; arrows + enter, space | |
| 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 | | [](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 | | |
| 31 | 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 | |
| 32 | 33 | |
| 33 | 34 | ## Run |
| @@ -48,7 +49,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is | ||
| 48 | 49 | 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. |
| 49 | 50 | |
| 50 | 51 | ## Add a game |
| 51 | 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 and Campfire 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`. | |
| 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`. | |
| 52 | 53 | |
| 53 | 54 | - `shell.js` provides the game menu, the Rules popup, the credits and the background music. |
| 54 | 55 | - `engine.js` provides the camera, depth buffer, colour ramps, shadows, edges, figures, trees and wind as globals. |
beekeeper/hive.js added +106
| @@ -0,0 +1,106 @@ | ||
| 1 | 'use strict'; | |
| 2 | // The beekeeper rules: a hive whose agitation rises on its own, a smoker that calms it while fuel lasts, | |
| 3 | // frames that lift out for honey (or a sting), and the three ways a round ends. | |
| 4 | // Plain numbers in, plain numbers out, no DOM. The page draws what this decides. | |
| 5 | (function (root) { | |
| 6 | const SLOTS = 6; // frames hanging in the box | |
| 7 | const ROUND_TIME = 60, MAX_STINGS = 3; | |
| 8 | const RISE = .012, RISE_GROWTH = .00035; // agitation per second, plus a little more every second played | |
| 9 | const LIFT_JUMP = .12, STING_JUMP = .08; // lifting a frame disturbs the hive; a sting angers it further | |
| 10 | const SMOKE_CALM = .2; // agitation per second a puff takes away, on top of the rise it holds back | |
| 11 | const FUEL_USE = .3, FUEL_REFILL = .07;// fuel (0..1) burnt per second of puffing, regained per second of rest | |
| 12 | const REFILL_AFTER = 3; // seconds before an empty slot gets a new frame | |
| 13 | const RESTART_AFTER = .6; | |
| 14 | const GOLD = 'gold', HALF = 'half', BROOD = 'brood', EMPTY = 'empty'; | |
| 15 | const VALUE = { [GOLD]: 3, [HALF]: 1, [BROOD]: 0, [EMPTY]: 0 }; | |
| 16 | ||
| 17 | const finite = v => (Number.isFinite(v) ? v : 0); | |
| 18 | const clamp = (v, a, b) => Math.max(a, Math.min(b, v)); | |
| 19 | // small seeded generator: state in, [value, state] out | |
| 20 | function roll(seed) { | |
| 21 | const t = (seed + 0x6D2B79F5) >>> 0; | |
| 22 | const out = Math.imul(t ^ (t >>> 15), 1 | t); | |
| 23 | const mixed = (out + Math.imul(out ^ (out >>> 7), 61 | out)) ^ out; | |
| 24 | return [((mixed ^ (mixed >>> 14)) >>> 0) / 4294967296, t]; | |
| 25 | } | |
| 26 | const kindFor = v => (v < .3 ? GOLD : v < .65 ? HALF : BROOD); | |
| 27 | ||
| 28 | function newRound(best = 0, seed = 1) { | |
| 29 | const s = { | |
| 30 | seed: finite(seed) >>> 0, phase: 'play', reason: '', time: 0, agitation: .08, fuel: 1, smoking: false, | |
| 31 | score: 0, stings: 0, best: Math.max(0, finite(best)), record: false, frames: [], draws: 0, since: 0, | |
| 32 | }; | |
| 33 | for (let i = 0; i < SLOTS; i++) s.frames.push({ kind: draw(s), wait: 0 }); | |
| 34 | return s; | |
| 35 | } | |
| 36 | function draw(s) { | |
| 37 | const [v] = roll(s.seed + s.draws * 7919); | |
| 38 | s.draws++; | |
| 39 | return kindFor(v); | |
| 40 | } | |
| 41 | const timeLeft = s => (s.phase === 'play' ? Math.max(0, ROUND_TIME - s.time) : 0); | |
| 42 | const value = kind => VALUE[kind] || 0; | |
| 43 | // bees circling the hive: more and faster as agitation grows | |
| 44 | const beeCount = a => 6 + Math.round(clamp(finite(a), 0, 1) * 34); | |
| 45 | const beeSpeed = a => 1 + clamp(finite(a), 0, 1) * 3; | |
| 46 | ||
| 47 | function finish(s, reason, events) { | |
| 48 | s.phase = 'over'; s.reason = reason; s.smoking = false; | |
| 49 | if (s.score > s.best) { s.best = s.score; s.record = true; } | |
| 50 | events.push({ type: 'over', reason, score: s.score, record: s.record }); | |
| 51 | } | |
| 52 | // hold the smoker: it only works while the round is on | |
| 53 | function smoke(s, on) { s.smoking = s.phase === 'play' && !!on; } | |
| 54 | ||
| 55 | // lift frame `slot` out into the crate: honey scores, brood stings, either one stirs the hive | |
| 56 | function lift(s, slot) { | |
| 57 | if (s.phase !== 'play' || !Number.isInteger(slot) || slot < 0 || slot >= SLOTS) return null; | |
| 58 | const f = s.frames[slot]; | |
| 59 | if (f.kind === EMPTY) return null; | |
| 60 | const kind = f.kind, pts = value(kind), events = []; | |
| 61 | f.kind = EMPTY; f.wait = 0; | |
| 62 | s.agitation = clamp(s.agitation + LIFT_JUMP, 0, 1); | |
| 63 | if (kind === BROOD) { | |
| 64 | s.stings++; | |
| 65 | s.agitation = clamp(s.agitation + STING_JUMP, 0, 1); | |
| 66 | events.push({ type: 'sting', slot, stings: s.stings }); | |
| 67 | } else { | |
| 68 | s.score += pts; | |
| 69 | events.push({ type: 'honey', slot, kind, points: pts, score: s.score }); | |
| 70 | } | |
| 71 | if (s.stings >= MAX_STINGS) finish(s, 'stings', events); | |
| 72 | else if (s.agitation >= 1) finish(s, 'swarm', events); | |
| 73 | return events; | |
| 74 | } | |
| 75 | ||
| 76 | // time passes: agitation rises, smoke holds it down while fuel lasts, spent fuel refills, empty slots refill | |
| 77 | function advance(s, dt) { | |
| 78 | const events = []; | |
| 79 | const d = clamp(finite(dt), 0, 1); | |
| 80 | if (s.phase !== 'play') { s.since += d; return events; } | |
| 81 | const left = ROUND_TIME - s.time, step = Math.min(d, left); | |
| 82 | const puff = s.smoking ? Math.min(step, s.fuel / FUEL_USE) : 0; | |
| 83 | const rise = RISE + RISE_GROWTH * s.time; | |
| 84 | s.agitation = clamp(s.agitation + rise * (step - puff) - SMOKE_CALM * puff, 0, 1); | |
| 85 | s.fuel = clamp(s.fuel - FUEL_USE * puff + (s.smoking ? 0 : FUEL_REFILL * step), 0, 1); | |
| 86 | s.time += step; | |
| 87 | for (const f of s.frames) { | |
| 88 | if (f.kind !== EMPTY) continue; | |
| 89 | f.wait += step; | |
| 90 | if (f.wait >= REFILL_AFTER) { f.kind = draw(s); f.wait = 0; events.push({ type: 'frame' }); } | |
| 91 | } | |
| 92 | if (s.agitation >= 1) finish(s, 'swarm', events); | |
| 93 | else if (s.time >= ROUND_TIME) finish(s, 'time', events); | |
| 94 | return events; | |
| 95 | } | |
| 96 | // a tap after the round has been over for a moment starts the next one; otherwise null | |
| 97 | function again(s) { | |
| 98 | return s.phase === 'over' && s.since > RESTART_AFTER ? newRound(s.best, s.seed + 1) : null; | |
| 99 | } | |
| 100 | ||
| 101 | const api = { | |
| 102 | SLOTS, ROUND_TIME, MAX_STINGS, RISE, LIFT_JUMP, STING_JUMP, SMOKE_CALM, FUEL_USE, FUEL_REFILL, REFILL_AFTER, RESTART_AFTER, | |
| 103 | GOLD, HALF, BROOD, EMPTY, value, beeCount, beeSpeed, newRound, timeLeft, smoke, lift, advance, again, | |
| 104 | }; | |
| 105 | if (typeof module !== 'undefined') module.exports = api; else root.Hive = api; | |
| 106 | })(typeof window !== 'undefined' ? window : globalThis); |
beekeeper/hive.test.mjs added +206
| @@ -0,0 +1,206 @@ | ||
| 1 | import { test, expect } from 'bun:test'; | |
| 2 | import { SLOTS, ROUND_TIME, MAX_STINGS, LIFT_JUMP, STING_JUMP, RISE, SMOKE_CALM, FUEL_USE, FUEL_REFILL, REFILL_AFTER, GOLD, HALF, BROOD, EMPTY, value, beeCount, beeSpeed, newRound, timeLeft, smoke, lift, advance, again } from './hive.js'; | |
| 3 | ||
| 4 | const withFrames = (kinds, seed = 1) => { | |
| 5 | const s = newRound(0, seed); | |
| 6 | kinds.forEach((k, i) => { s.frames[i].kind = k; }); | |
| 7 | return s; | |
| 8 | }; | |
| 9 | ||
| 10 | test('a new round has a calm hive, full fuel and a full box of frames', () => { | |
| 11 | const s = newRound(5, 3); | |
| 12 | expect(s.phase).toBe('play'); | |
| 13 | expect(s.stings).toBe(0); | |
| 14 | expect(s.score).toBe(0); | |
| 15 | expect(s.fuel).toBe(1); | |
| 16 | expect(s.best).toBe(5); | |
| 17 | expect(s.frames.length).toBe(SLOTS); | |
| 18 | expect(s.frames.every(f => [GOLD, HALF, BROOD].includes(f.kind))).toBe(true); | |
| 19 | expect(timeLeft(s)).toBe(ROUND_TIME); | |
| 20 | }); | |
| 21 | ||
| 22 | test('the same seed hangs the same frames', () => { | |
| 23 | expect(newRound(0, 9).frames).toEqual(newRound(0, 9).frames); | |
| 24 | }); | |
| 25 | ||
| 26 | test('agitation rises on its own and faster as the round goes on', () => { | |
| 27 | const s = newRound(); | |
| 28 | const a0 = s.agitation; | |
| 29 | advance(s, .5); | |
| 30 | const early = s.agitation - a0; | |
| 31 | expect(early).toBeGreaterThan(0); | |
| 32 | s.time = 40; const a1 = s.agitation; | |
| 33 | advance(s, .5); | |
| 34 | expect(s.agitation - a1).toBeGreaterThan(early); | |
| 35 | }); | |
| 36 | ||
| 37 | test('smoke lowers agitation and burns fuel', () => { | |
| 38 | const s = newRound(); | |
| 39 | s.agitation = .5; | |
| 40 | smoke(s, true); | |
| 41 | advance(s, .5); | |
| 42 | expect(s.agitation).toBeLessThan(.5); | |
| 43 | expect(s.fuel).toBeCloseTo(1 - FUEL_USE * .5, 6); | |
| 44 | }); | |
| 45 | ||
| 46 | test('smoke with no fuel does nothing', () => { | |
| 47 | const s = newRound(); | |
| 48 | s.fuel = 0; s.agitation = .5; | |
| 49 | const quiet = newRound(); | |
| 50 | quiet.fuel = 0; quiet.agitation = .5; | |
| 51 | smoke(s, true); | |
| 52 | advance(s, .5); advance(quiet, .5); | |
| 53 | expect(s.agitation).toBe(quiet.agitation); | |
| 54 | expect(s.agitation).toBeGreaterThan(.5); | |
| 55 | expect(s.fuel).toBe(0); | |
| 56 | }); | |
| 57 | ||
| 58 | test('fuel that runs out mid-step only calms for the part it had', () => { | |
| 59 | const s = newRound(); | |
| 60 | s.fuel = FUEL_USE * .1; s.agitation = .5; | |
| 61 | smoke(s, true); | |
| 62 | advance(s, 1); | |
| 63 | expect(s.fuel).toBe(0); | |
| 64 | expect(s.agitation).toBeCloseTo(.5 + RISE * .9 - SMOKE_CALM * .1, 6); | |
outdated
This assertion holds without the |
||
| 65 | }); | |
| 66 | ||
| 67 | test('fuel refills slowly while the smoker rests and never past full', () => { | |
| 68 | const s = newRound(); | |
| 69 | s.fuel = .2; | |
| 70 | advance(s, 1); | |
| 71 | expect(s.fuel).toBeCloseTo(.2 + FUEL_REFILL, 6); | |
| 72 | advance(s, 1); advance(s, 1); | |
| 73 | s.fuel = .99; advance(s, 1); | |
| 74 | expect(s.fuel).toBe(1); | |
| 75 | }); | |
| 76 | ||
| 77 | test('lifting honey scores 3 for gold and 1 for half-capped and stirs the hive', () => { | |
| 78 | const s = withFrames([GOLD, HALF, BROOD]); | |
| 79 | const a = s.agitation; | |
| 80 | const ev = lift(s, 0); | |
| 81 | expect(ev[0]).toMatchObject({ type: 'honey', kind: GOLD, points: 3 }); | |
| 82 | expect(s.score).toBe(3); | |
| 83 | expect(s.agitation).toBeCloseTo(a + LIFT_JUMP, 6); | |
| 84 | lift(s, 1); | |
| 85 | expect(s.score).toBe(4); | |
| 86 | expect(s.frames[0].kind).toBe(EMPTY); | |
| 87 | expect(value(GOLD)).toBe(3); | |
| 88 | expect(value(HALF)).toBe(1); | |
| 89 | }); | |
| 90 | ||
| 91 | test('lifting a brood frame adds a sting and scores nothing', () => { | |
| 92 | const s = withFrames([BROOD]); | |
| 93 | const a = s.agitation; | |
| 94 | const ev = lift(s, 0); | |
| 95 | expect(s.agitation).toBeCloseTo(a + LIFT_JUMP + STING_JUMP, 6); | |
| 96 | expect(ev[0]).toMatchObject({ type: 'sting', stings: 1 }); | |
outdated
Add an agitation check here: a brood lift should raise it by |
||
| 97 | expect(s.stings).toBe(1); | |
| 98 | expect(s.score).toBe(0); | |
| 99 | }); | |
| 100 | ||
| 101 | test('three stings end the round', () => { | |
| 102 | const s = withFrames([BROOD, BROOD, BROOD]); | |
| 103 | s.agitation = 0; | |
| 104 | lift(s, 0); lift(s, 1); | |
| 105 | expect(s.phase).toBe('play'); | |
| 106 | const ev = lift(s, 2); | |
| 107 | expect(s.stings).toBe(MAX_STINGS); | |
| 108 | expect(s.phase).toBe('over'); | |
| 109 | expect(s.reason).toBe('stings'); | |
| 110 | expect(ev.at(-1)).toMatchObject({ type: 'over', reason: 'stings' }); | |
| 111 | }); | |
| 112 | ||
| 113 | test('a swarm ends the round, from time passing or from a lift', () => { | |
| 114 | const s = newRound(); | |
| 115 | s.agitation = .999; | |
| 116 | const ev = advance(s, .5); | |
| 117 | expect(s.phase).toBe('over'); | |
| 118 | expect(s.reason).toBe('swarm'); | |
| 119 | expect(ev.at(-1).type).toBe('over'); | |
| 120 | const t = withFrames([GOLD]); | |
| 121 | t.agitation = 1 - LIFT_JUMP / 2; | |
| 122 | lift(t, 0); | |
| 123 | expect(t.reason).toBe('swarm'); | |
| 124 | }); | |
| 125 | ||
| 126 | test('lifting an empty slot or a bad slot does nothing', () => { | |
| 127 | const s = withFrames([GOLD]); | |
| 128 | lift(s, 0); | |
| 129 | const a = s.agitation; | |
| 130 | expect(lift(s, 0)).toBe(null); | |
| 131 | expect(lift(s, -1)).toBe(null); | |
| 132 | expect(lift(s, SLOTS)).toBe(null); | |
| 133 | expect(lift(s, 1.5)).toBe(null); | |
| 134 | expect(lift(s, NaN)).toBe(null); | |
| 135 | expect(s.agitation).toBe(a); | |
| 136 | }); | |
| 137 | ||
| 138 | test('an emptied slot gets a new frame after a few seconds', () => { | |
| 139 | const s = withFrames([GOLD]); | |
| 140 | lift(s, 0); | |
| 141 | s.agitation = 0; | |
| 142 | advance(s, 1); advance(s, 1); | |
| 143 | expect(s.frames[0].kind).toBe(EMPTY); | |
| 144 | smoke(s, true); | |
| 145 | advance(s, 1); | |
| 146 | expect(s.frames[0].kind).not.toBe(EMPTY); | |
| 147 | }); | |
| 148 | ||
| 149 | test('sixty seconds end the round and a better score is a record', () => { | |
| 150 | const s = newRound(2); | |
| 151 | s.score = 7; | |
| 152 | for (let i = 0; i < 70 && s.phase === 'play'; i++) { smoke(s, i % 4 !== 0); advance(s, 1); } | |
| 153 | expect(s.phase).toBe('over'); | |
| 154 | expect(s.reason).toBe('time'); | |
| 155 | expect(s.record).toBe(true); | |
| 156 | expect(s.best).toBe(7); | |
| 157 | expect(timeLeft(s)).toBe(0); | |
| 158 | }); | |
| 159 | ||
| 160 | test('nothing changes after the round is over, and smoke is refused', () => { | |
| 161 | const s = withFrames([GOLD, GOLD]); | |
| 162 | s.agitation = 1; advance(s, .1); | |
| 163 | const score = s.score; | |
| 164 | expect(lift(s, 0)).toBe(null); | |
| 165 | smoke(s, true); | |
| 166 | expect(s.smoking).toBe(false); | |
| 167 | expect(advance(s, 1)).toEqual([]); | |
| 168 | expect(s.score).toBe(score); | |
| 169 | }); | |
| 170 | ||
| 171 | test('a tap restarts only after a moment, keeping the best', () => { | |
| 172 | const s = newRound(0, 4); | |
| 173 | s.score = 5; s.agitation = 1; advance(s, .1); | |
| 174 | expect(again(s)).toBe(null); | |
| 175 | advance(s, 1); | |
| 176 | const next = again(s); | |
| 177 | expect(next.phase).toBe('play'); | |
| 178 | expect(next.best).toBe(5); | |
| 179 | expect(next.score).toBe(0); | |
| 180 | expect(again(next)).toBe(null); | |
| 181 | }); | |
| 182 | ||
| 183 | test('bad numbers do not break the clock', () => { | |
| 184 | const s = newRound(); | |
| 185 | advance(s, NaN); advance(s, -5); advance(s, Infinity); | |
| 186 | expect(Number.isFinite(s.agitation)).toBe(true); | |
| 187 | expect(Number.isFinite(s.time)).toBe(true); | |
| 188 | expect(beeCount(NaN)).toBe(6); | |
| 189 | }); | |
| 190 | ||
| 191 | test('more and faster bees as agitation grows', () => { | |
| 192 | expect(beeCount(1)).toBeGreaterThan(beeCount(.5)); | |
| 193 | expect(beeCount(.5)).toBeGreaterThan(beeCount(0)); | |
| 194 | expect(beeSpeed(1)).toBeGreaterThan(beeSpeed(0)); | |
| 195 | }); | |
| 196 | ||
| 197 | test('a calm round can be played to the bell with steady smoking and lifting', () => { | |
| 198 | const s = newRound(0, 11); | |
| 199 | for (let t = 0; t < 600 && s.phase === 'play'; t++) { | |
| 200 | smoke(s, s.agitation > .35 && s.fuel > 0); | |
| 201 | advance(s, .1); | |
| 202 | if (t % 15 === 0) { const i = s.frames.findIndex(f => f.kind === GOLD); if (i >= 0) lift(s, i); } | |
| 203 | } | |
| 204 | expect(s.reason).not.toBe('swarm'); | |
| 205 | expect(s.score).toBeGreaterThan(0); | |
| 206 | }); |
beekeeper/index.html added +445
| @@ -0,0 +1,445 @@ | ||
| 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>Beekeeper</title> | |
| 7 | <!-- og:begin --> | |
| 8 | <meta name="description" content="Smoke the hive calm and lift out honey frames before the bees swarm: gold 3, half 1, a dark brood frame stings"> | |
| 9 | <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/beekeeper/"> | |
| 10 | <meta property="og:type" content="website"> | |
| 11 | <meta property="og:site_name" content="Pixel Plays"> | |
| 12 | <meta property="og:title" content="Beekeeper"> | |
| 13 | <meta property="og:description" content="Smoke the hive calm and lift out honey frames before the bees swarm: gold 3, half 1, a dark brood frame stings"> | |
| 14 | <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/beekeeper/"> | |
| 15 | <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/beekeeper.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="Beekeeper: 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; : #d9a02a; : #c4503f; } | |
| 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; align-items: flex-end; 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)); } | |
| 32 | .row { display: flex; align-items: center; gap: 8px; color: var(); } | |
| 33 | .row b { font-size: 16px; font-weight: 600; min-width: 3ch; font-variant-numeric: tabular-nums; } | |
| 34 | .row span { color: var(); } | |
| 35 | .row.hot { color: var(); } | |
| 36 | .meter { display: block; width: 3ch; height: 4px; background: #ece9e2; overflow: hidden; } | |
| 37 | .meter i { display: block; height: 100%; width: 100%; background: currentColor; transform-origin: left; transform: scaleX(0); } | |
| 38 | #status { color: var(); } | |
| 39 | button { pointer-events: auto; font: inherit; color: var(); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; } | |
| 40 | button:hover, button:focus-visible, button.on { color: var(); } | |
| 41 | #smoke { color: var(); border: 1px solid var(); padding: 10px 16px; margin: -10px 0; min-width: 12ch; } | |
| 42 | #smoke.on { background: var(); color: var(); } | |
| 43 | </style> | |
| 44 | </head> | |
| 45 | <body> | |
| 46 | <div id="stage"><canvas id="c" tabindex="0" aria-label="A small meadow with a wooden beehive on a stand, a clover patch, a smoker and a honey crate. Tap a frame in the hive, or pick one with the left and right arrow keys and press space, to lift it into the crate: a golden frame is worth 3, a half-capped one 1, and a dark brood frame costs a sting. Hold the smoke button, or hold S, to calm the bees. Lifting frames stirs them, and a full buzz is a swarm. Sixty seconds, three stings."></canvas></div> | |
| 47 | <div id="scores"> | |
| 48 | <div class="row"><b id="score">0</b><span>honey</span></div> | |
| 49 | <div class="row" id="stingRow"><b id="stings">0/3</b><span>stings</span></div> | |
| 50 | <div class="row"><b id="fuel">100%</b><span>smoke</span></div> | |
| 51 | <div class="row" id="buzzRow"><span class="meter"><i id="buzz"></i></span><span>buzz</span></div> | |
| 52 | <div class="row"><b id="best">0</b><span>best</span></div> | |
| 53 | </div> | |
| 54 | <div class="hud" id="bottom"> | |
| 55 | <div id="status" role="status" aria-live="polite"></div> | |
| 56 | <button id="smoke" type="button" aria-pressed="false">hold to smoke</button> | |
| 57 | <button id="mute" type="button" aria-pressed="false">sound on</button> | |
| 58 | </div> | |
| 59 | <script src="../shell.js"></script> | |
| 60 | <script> | |
| 61 | PixelPlays.mount({ | |
| 62 | id: 'beekeeper', | |
| 63 | rules: [ | |
| 64 | 'Tap a frame to lift it out: gold 3, half 1.', | |
| 65 | 'Dark brood frames sting; three stings end it.', | |
| 66 | 'Hold the smoker (or S) to calm the bees.', | |
| 67 | 'Lifting stirs them: a full buzz is a swarm.', | |
| 68 | ], | |
| 69 | }); | |
| 70 | </script> | |
| 71 | <script>window.PP_SCENE = { originY: 4, shadowX: 1.3, shadowY: -.12 };</script> | |
| 72 | <script src="../engine.js"></script> | |
| 73 | <script src="hive.js"></script> | |
| 74 | <script> | |
| 75 | 'use strict'; | |
| 76 | ||
| 77 | const HIVE = window.Hive; | |
| 78 | const { SLOTS, GOLD, HALF, BROOD, EMPTY, MAX_STINGS } = HIVE; | |
outdated
|
||
| 79 | ||
| 80 | const WOOD = [190, 146, 92], WOOD_DARK = [120, 88, 62], INSIDE = [62, 44, 36]; | |
| 81 | const COMB = [212, 172, 98], CAPPED = [244, 184, 48], BROOD_C = [88, 56, 42]; | |
| 82 | const SHEEN = rgb(255, 232, 140), CELL_DARK = rgb(150, 104, 40), BROOD_CELL = rgb(40, 26, 22), CELL_OPEN = rgb(176, 132, 62); | |
| 83 | const TIN = [156, 160, 168], LEATHER = [150, 92, 60], SMOKE_C = [230, 228, 224]; | |
| 84 | const LEAF = [[52, 104, 58], [76, 130, 64], [104, 150, 72]], BLOOM = [[250, 246, 236], [240, 170, 190], [232, 140, 176]]; | |
| 85 | const BEE = rgb(28, 24, 18), BEE_PALE = rgb(255, 238, 150); | |
| 86 | ||
| 87 | /* ---------- where things stand ---------- */ | |
| 88 | const FRAME_X = i => (i - (SLOTS - 1) / 2) * .9, FRAME_Y0 = -1.6, FRAME_Y1 = 1.6; | |
| 89 | const FRAME_TOP = 1.8, FRAME_BOT = 1.15, LIFT = .35; | |
| 90 | const CRATE = { x0: 4.1, x1: 6.5, y0: .1, y1: 3.9 }; | |
| 91 | const crateSlot = n => CRATE.x0 + .4 + n * .34; | |
| 92 | const SMOKER = { x: -3.4, y: 4.4 }, CLOVER = { x: 4.4, y: 5.6 }; | |
| 93 | ||
| 94 | function groundColor(x, y, ix, iy, i) { | |
| 95 | const u = (x - y) / R2, v = (x + y) / R2; | |
| 96 | const edge = Math.pow(Math.pow(Math.abs(u) / 11, 4) + Math.pow(Math.abs(v - 1) / 9, 4), .25); | |
| 97 | const rough = edge + (noise(x * 1.3, y * 1.3) - .5) * .13; | |
| 98 | if (rough > 1.04) return 0; | |
| 99 | if (rough > .93 && hash(ix, iy) < (rough - .93) / .11) return 0; | |
| 100 | kinds[i] = KIND_GRASS; | |
| 101 | const t = noise(x * .9, y * .9) * 1.15 + (hash(ix, iy) - .5) * .55 - .08; | |
| 102 | return rgb(...GRASS[clamp(Math.floor(t * 4.2), 0, 3)]); | |
| 103 | } | |
| 104 | ||
| 105 | /* ---------- the baked scene ---------- */ | |
| 106 | const plants = []; | |
| 107 | function growClover() { | |
| 108 | for (let n = 0; n < 80; n++) { | |
| 109 | const a = hash(n, 11) * Math.PI * 2, r = Math.sqrt(hash(n, 12)) * 2, bloom = n % 4 === 0; | |
| 110 | const x = CLOVER.x + Math.cos(a) * r * 1.2, y = CLOVER.y + Math.sin(a) * r * .8; | |
| 111 | const z = .08 + hash(n, 13) * (bloom ? .35 : .18); | |
| 112 | const color = bloom ? BLOOM[n % 3] : LEAF[n % 3]; | |
| 113 | capture = []; | |
| 114 | sphere(x, y, z, bloom ? .2 : .27, color, 'rough'); | |
| 115 | plants.push({ k: n, x, y, z, r: bloom ? .2 : .27, pixels: capture }); | |
| 116 | capture = null; | |
| 117 | } | |
| 118 | } | |
| 119 | function growHive() { | |
| 120 | const wall = (x0, y0, x1, y1, seed) => box(x0, y0, .9, x1, y1, 2.05, WOOD, seed); | |
| 121 | box(-3.1, -2, .9, 3.1, 2, 1.3, INSIDE, 1); | |
| 122 | wall(-3.2, -2.1, -3, 2.1, 2); wall(3, -2.1, 3.2, 2.1, 3); | |
| 123 | wall(-3.2, -2.1, 3.2, -1.9, 4); wall(-3.2, 1.9, 3.2, 2.1, 5); | |
| 124 | for (const [x, y] of [[-2.9, -1.8], [2.9, -1.8], [-2.9, 1.8], [2.9, 1.8]]) capsule([x, y, 0], [x, y, .9], .13, .13, () => WOOD_DARK, 'rough'); | |
| 125 | box(-3, -2, .55, 3, 2, .9, WOOD_DARK, 6); | |
| 126 | } | |
| 127 | function growCrate() { | |
| 128 | const { x0, x1, y0, y1 } = CRATE; | |
| 129 | box(x0, y0, .1, x1, y1, .35, WOOD_DARK, 7); | |
| 130 | box(x0, y0, .1, x0 + .12, y1, 1.1, WOOD, 8); | |
| 131 | box(x1 - .12, y0, .1, x1, y1, 1.1, WOOD, 9); | |
| 132 | box(x0, y0, .1, x1, y0 + .12, 1.1, WOOD, 10); | |
| 133 | box(x0, y1 - .12, .1, x1, y1, 1.1, WOOD, 11); | |
| 134 | } | |
| 135 | function growSmoker() { | |
| 136 | const { x, y } = SMOKER, tin = () => TIN, leather = () => LEATHER; | |
| 137 | capsule([x, y, .1], [x, y, 1.1], .5, .44, tin, 'solid'); | |
| 138 | capsule([x, y, 1.1], [x + .35, y - .35, 1.6], .42, .14, tin, 'solid'); | |
| 139 | capsule([x + .5, y + .45, .6], [x + 1.3, y + 1.1, 1.05], .42, .3, leather, 'solid'); | |
| 140 | } | |
| 141 | function bake() { | |
| 142 | zb.fill(-1e9); | |
| 143 | pix.fill(rgb(255, 255, 255)); | |
| 144 | for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) { | |
| 145 | const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy, i); | |
| 146 | if (!c) continue; | |
| 147 | pix[i] = c; ground[i] = 1; | |
| 148 | zb[i] = (g.x + g.y) / R2 * COS; | |
| 149 | } | |
| 150 | growGrass(); | |
| 151 | groundZ.set(zb); | |
| 152 | growHive(); | |
| 153 | growCrate(); | |
| 154 | growSmoker(); | |
| 155 | growClover(); | |
| 156 | for (let x = -3.2; x <= 3.2; x += .6) for (let y = -2.1; y <= 2.1; y += .6) for (const z of [.4, 1.3, 2]) castShadow(x, y, z, .4, 1, 0); | |
| 157 | for (let y = CRATE.y0; y <= CRATE.y1; y += .6) castShadow(CRATE.x1, y, .7, .35, 1, 0); | |
| 158 | for (const z of [.3, .8, 1.3]) castShadow(SMOKER.x, SMOKER.y, z, .45, 1, 0); | |
| 159 | bakeOcclusion(); | |
| 160 | staticShadow.set(shadowMask); | |
| 161 | applyShadows(groundZ); | |
| 162 | bakedPix.set(pix); | |
| 163 | bakedZ.set(zb); | |
| 164 | } | |
| 165 | ||
| 166 | /* ---------- game state ---------- */ | |
| 167 | const nodes = { | |
| 168 | score: document.getElementById('score'), best: document.getElementById('best'), stings: document.getElementById('stings'), | |
| 169 | fuel: document.getElementById('fuel'), buzz: document.getElementById('buzz'), buzzRow: document.getElementById('buzzRow'), | |
| 170 | stingRow: document.getElementById('stingRow'), status: document.getElementById('status'), smoke: document.getElementById('smoke'), | |
| 171 | }; | |
| 172 | const G = { time: 0, status: '', noteUntil: 0, sel: 2, flights: [], crate: 0, pointerSmoke: false, keySmoke: false }; | |
| 173 | const BEST_KEY = 'pixel-plays-beekeeper-best'; | |
| 174 | const best0 = (() => { try { return Number(localStorage.getItem(BEST_KEY)) || 0; } catch (e) { return 0; } })(); | |
| 175 | let R = HIVE.newRound(best0, Date.now() & 0xffff); | |
| 176 | const hudText = {}; | |
| 177 | function put(key, node, text) { if (hudText[key] !== text) { hudText[key] = text; node.textContent = text; } } | |
| 178 | function renderHud() { | |
| 179 | put('score', nodes.score, String(R.score)); | |
| 180 | put('best', nodes.best, String(Math.max(R.best, R.score))); | |
| 181 | put('stings', nodes.stings, `${R.stings}/${MAX_STINGS}`); | |
| 182 | put('fuel', nodes.fuel, `${Math.round(R.fuel * 100)}%`); | |
| 183 | nodes.buzz.style.transform = `scaleX(${R.agitation.toFixed(3)})`; | |
| 184 | nodes.buzzRow.classList.toggle('hot', R.agitation > .7); | |
| 185 | nodes.stingRow.classList.toggle('hot', R.stings > 0); | |
| 186 | } | |
| 187 | function setStatus(text) { | |
| 188 | if (text === G.status) return; | |
| 189 | G.status = text; | |
| 190 | nodes.status.textContent = text; | |
| 191 | } | |
| 192 | function note(text) { setStatus(text); G.noteUntil = G.time + 2.2; } | |
| 193 | const HINT = 'tap a frame to lift it, hold to smoke'; | |
| 194 | function restart() { | |
| 195 | const next = HIVE.again(R); | |
| 196 | if (!next) return false; | |
| 197 | R = next; G.flights = []; G.crate = 0; G.sel = 2; | |
| 198 | note(HINT); | |
| 199 | renderHud(); | |
| 200 | return true; | |
| 201 | } | |
| 202 | function lift(slot) { | |
| 203 | const kind = R.frames[slot] && R.frames[slot].kind; | |
| 204 | const events = HIVE.lift(R, slot); | |
| 205 | if (!events) return; | |
| 206 | G.flights.push({ slot, kind, t: 0 }); | |
| 207 | for (const e of events) { | |
| 208 | if (e.type === 'honey') { note(e.kind === HIVE.GOLD ? 'golden frame: +3' : 'half-capped frame: +1'); sound('lift'); } | |
| 209 | if (e.type === 'sting') { note(`brood frame: sting ${e.stings} of ${MAX_STINGS}`); sound('sting'); } | |
| 210 | } | |
| 211 | finishIfOver(events); | |
| 212 | renderHud(); | |
| 213 | } | |
| 214 | function finishIfOver(events) { | |
| 215 | const over = events.find(e => e.type === 'over'); | |
| 216 | if (!over) return; | |
| 217 | if (R.record) try { localStorage.setItem(BEST_KEY, String(R.best)); } catch (e) { /* private window: keep it for this visit */ } | |
| 218 | const why = { swarm: 'the bees swarmed', stings: 'three stings', time: 'time is up' }[over.reason]; | |
| 219 | setStatus(`${why} · ${R.score} honey${R.record ? ' · new best' : ` · best ${R.best}`} · tap or space to play again`); | |
| 220 | sound(over.reason === 'time' ? 'lift' : 'swarm'); | |
| 221 | } | |
| 222 | function update(dt) { | |
| 223 | G.time += dt; | |
| 224 | for (const f of G.flights) f.t += dt / .45; | |
| 225 | G.flights = G.flights.filter(f => { | |
| 226 | if (f.t < 1) return true; | |
| 227 | if (f.kind !== BROOD) G.crate++; | |
| 228 | return false; | |
| 229 | }); | |
| 230 | HIVE.smoke(R, G.pointerSmoke || G.keySmoke); | |
| 231 | nodes.smoke.classList.toggle('on', R.smoking); | |
| 232 | nodes.smoke.setAttribute('aria-pressed', String(R.smoking)); | |
| 233 | const events = HIVE.advance(R, dt); | |
| 234 | if (R.phase === 'play' || events.length) renderHud(); | |
| 235 | finishIfOver(events); | |
| 236 | if (R.phase === 'play' && G.time >= G.noteUntil) { | |
| 237 | const mood = R.agitation > .75 ? 'furious' : R.agitation > .45 ? 'restless' : 'calm'; | |
| 238 | setStatus(`${Math.ceil(HIVE.timeLeft(R))}s · the bees are ${mood}`); | |
| 239 | } | |
| 240 | } | |
| 241 | ||
| 242 | /* ---------- drawing ---------- */ | |
| 243 | const FRAME_STYLE = { [GOLD]: CAPPED, [HALF]: CAPPED, [BROOD]: BROOD_C }; | |
| 244 | function drawFrameAt(x, y, lift, kind, seed) { | |
| 245 | const x0 = x - .35, x1 = x + .35, y0 = y + FRAME_Y0, y1 = y + FRAME_Y1, z0 = FRAME_BOT + lift, z1 = FRAME_TOP + lift; | |
| 246 | const mid = y + (kind === HALF ? 0 : FRAME_Y1); | |
| 247 | box(x0, y0, z0, x1, mid, z1, FRAME_STYLE[kind], seed); | |
| 248 | if (kind === HALF) box(x0, mid, z0, x1, y1, z1, COMB, seed + 20); | |
| 249 | for (let b = y0 + .2; b < y1; b += .32) for (const a of [x - .17, x + .17]) { | |
| 250 | const open = kind === HALF && b > mid, c = kind === BROOD ? BROOD_CELL : open ? CELL_OPEN : (((a * 7 + b * 5) | 0) & 1 ? SHEEN : CELL_DARK); | |
| 251 | plot(a, b, z1 + .02, c); | |
| 252 | } | |
| 253 | } | |
| 254 | function drawFrames() { | |
| 255 | for (let i = 0; i < SLOTS; i++) { | |
| 256 | const kind = R.frames[i].kind; | |
| 257 | if (kind === EMPTY) continue; | |
| 258 | const up = i === G.sel && R.phase === 'play' ? LIFT : 0; | |
| 259 | drawFrameAt(FRAME_X(i), 0, up, kind, i); | |
| 260 | if (up) castShadow(FRAME_X(i), 0, FRAME_TOP + up, .5, 1, 0); | |
| 261 | } | |
| 262 | } | |
| 263 | const ease3 = t => t * t * (3 - 2 * t); | |
| 264 | function drawFlights() { | |
| 265 | for (const f of G.flights) { | |
| 266 | const t = ease3(Math.min(1, f.t)), fx = FRAME_X(f.slot), tx = crateSlot(Math.min(5, G.crate)), ty = (CRATE.y0 + CRATE.y1) / 2; | |
| 267 | if (f.kind === BROOD) { // brood never goes in the honey crate: it lifts a little and drops back into its slot | |
| 268 | const lift = LIFT + Math.sin(t * Math.PI) * 1.2; | |
| 269 | drawFrameAt(fx, 0, lift, f.kind, 30); | |
| 270 | castShadow(fx, 0, FRAME_TOP + lift, .5, 1, 0); | |
| 271 | continue; | |
| 272 | } | |
| 273 | const x = lerp(fx, tx, t), y = lerp(0, ty, t), lift = LIFT + Math.sin(t * Math.PI) * 2.2 - t * (FRAME_TOP + LIFT - 1.25); | |
| 274 | drawFrameAt(x, y, lift, f.kind, 30); | |
| 275 | castShadow(x, y, FRAME_TOP + lift, .5, 1, 0); | |
| 276 | } | |
| 277 | } | |
| 278 | function drawCrate() { | |
| 279 | const n = Math.min(G.crate, 6); | |
| 280 | for (let k = 0; k < n; k++) { | |
| 281 | const x = crateSlot(k), y0 = CRATE.y0 + .3, y1 = CRATE.y1 - .3; | |
| 282 | box(x - .12, y0, .35, x + .12, y1, 1.25, CAPPED, 40 + k); | |
| 283 | for (let b = y0 + .2; b < y1; b += .32) plot(x, b, 1.27, k & 1 ? SHEEN : CELL_DARK); | |
| 284 | } | |
| 285 | } | |
| 286 | function drawClover(t) { | |
| 287 | for (const p of plants) { | |
| 288 | const sway = (Math.sin(t * 1.3 + p.x * .8) + .5 * Math.sin(t * 2.7 + p.k * 1.3)) * .9; | |
| 289 | const dx = Math.round(sway * .7), dy = Math.round(Math.sin(t * 1.7 + p.k) * .4); | |
| 290 | const px = p.pixels; | |
| 291 | for (let n = 0; n < px.length; n += 4) { | |
| 292 | const ix = px[n] + dx, iy = px[n + 1] + dy; | |
| 293 | if (ix < 0 || iy < 0 || ix >= W || iy >= H) continue; | |
| 294 | const i = iy * W + ix; | |
| 295 | if (px[n + 2] <= zb[i]) continue; | |
| 296 | zb[i] = px[n + 2]; | |
| 297 | pix[i] = px[n + 3]; | |
| 298 | } | |
| 299 | } | |
| 300 | } | |
| 301 | function drawSmoke(t) { | |
| 302 | if (!R.smoking) return; | |
| 303 | const step = Math.floor(t * 10) / 10; | |
| 304 | for (let k = 0; k < 7; k++) { | |
| 305 | const age = (step * 1.4 + k / 7) % 1; | |
| 306 | const x = SMOKER.x + .35 + age * 3.4, y = SMOKER.y - .35 - age * .7, z = 1.7 + age * 1.6 + Math.sin(k * 2 + age * 4) * .15; | |
| 307 | sphere(x, y, z, .12 + age * .26, SMOKE_C, 'solid'); | |
| 308 | } | |
| 309 | } | |
| 310 | function drawBees(t) { | |
| 311 | const n = HIVE.beeCount(R.agitation), speed = HIVE.beeSpeed(R.agitation); | |
| 312 | for (let b = 0; b < n; b++) { | |
| 313 | const dir = hash(b, 5) > .5 ? 1 : -1, theta = hash(b, 1) * 6.283 + dir * (.5 + hash(b, 4)) * speed * t; | |
| 314 | const rx = 2.2 + hash(b, 2) * 2, ry = 1.6 + hash(b, 6) * 1.6; | |
| 315 | const z = 1.8 + hash(b, 3) * 2.2 + (STILL ? 0 : Math.sin(t * 6 * speed / 2 + b) * .12); | |
| 316 | const p = project(Math.cos(theta) * rx, Math.sin(theta) * ry, z), ix = Math.round(p.sx), iy = Math.round(p.sy); | |
| 317 | if (ix < 0 || iy < 0 || ix >= W || iy >= H) continue; | |
| 318 | const under = pix[iy * W + ix]; // dark on white or sand, pale on the dark grass | |
| 319 | pix[iy * W + ix] = (under & 255) + (under >> 8 & 255) + (under >> 16 & 255) < 330 ? BEE_PALE : BEE; | |
| 320 | } | |
| 321 | } | |
| 322 | function drawCue() { | |
| 323 | if (R.phase !== 'play' || R.frames[G.sel].kind === EMPTY) return; | |
| 324 | const p = project(FRAME_X(G.sel), 0, FRAME_TOP + LIFT + .1); | |
| 325 | drawArrow(p.sx, p.sy - 1, STILL ? 0 : G.time); | |
| 326 | } | |
| 327 | function draw() { | |
| 328 | pix.set(bakedPix); | |
| 329 | zb.set(bakedZ); | |
| 330 | const windT = STILL ? 0 : Math.floor(G.time * WIND_FPS) / WIND_FPS; | |
| 331 | drawCrate(); | |
| 332 | drawFrames(); | |
| 333 | drawFlights(); | |
| 334 | drawSmoke(G.time); | |
| 335 | drawClover(windT); | |
| 336 | drawTufts(windT); | |
| 337 | applyShadows(bakedZ); | |
| 338 | shadeEdges(); | |
| 339 | drawBees(windT); | |
| 340 | drawCue(); | |
| 341 | ctx.putImageData(image, 0, 0); | |
| 342 | } | |
| 343 | ||
| 344 | /* ---------- input ---------- */ | |
| 345 | // the frame whose slab passes closest to a canvas point, within a few pixels | |
| 346 | function slotAt(e) { | |
| 347 | const rect = canvas.getBoundingClientRect(); | |
| 348 | const sx = (e.clientX - rect.left) / rect.width * W, sy = (e.clientY - rect.top) / rect.height * H; | |
| 349 | let best = -1, bestD = 7; | |
| 350 | for (let i = 0; i < SLOTS; i++) { | |
| 351 | const a = project(FRAME_X(i), FRAME_Y0, FRAME_TOP), b = project(FRAME_X(i), FRAME_Y1, FRAME_TOP); | |
| 352 | const dx = b.sx - a.sx, dy = b.sy - a.sy, t = clamp(((sx - a.sx) * dx + (sy - a.sy) * dy) / (dx * dx + dy * dy), 0, 1); | |
| 353 | const d = Math.hypot(sx - (a.sx + dx * t), sy - (a.sy + dy * t)); | |
| 354 | if (d < bestD) { bestD = d; best = i; } | |
| 355 | } | |
| 356 | return best; | |
| 357 | } | |
| 358 | canvas.addEventListener('pointerdown', e => { | |
| 359 | ensureAudio(); | |
| 360 | canvas.focus({ preventScroll: true }); | |
| 361 | if (restart()) return; | |
| 362 | if (R.phase !== 'play') return; | |
| 363 | const slot = slotAt(e); | |
| 364 | if (slot < 0) return; | |
| 365 | G.sel = slot; | |
| 366 | lift(slot); | |
| 367 | }); | |
| 368 | canvas.addEventListener('pointermove', e => { | |
| 369 | if (R.phase !== 'play' || e.pointerType !== 'mouse') return; | |
| 370 | const slot = slotAt(e); | |
| 371 | if (slot >= 0) G.sel = slot; | |
| 372 | }); | |
| 373 | const pick = d => { G.sel = (G.sel + d + SLOTS) % SLOTS; }; | |
| 374 | canvas.addEventListener('keydown', e => { | |
| 375 | const k = e.key; | |
| 376 | if (k === ' ' || k === 'Enter') { | |
| 377 | e.preventDefault(); | |
| 378 | ensureAudio(); | |
| 379 | if (e.repeat) return; | |
| 380 | if (restart()) return; | |
| 381 | if (R.phase === 'play') lift(G.sel); | |
| 382 | } else if (k === 'ArrowLeft' || k === 'a' || k === 'A') { e.preventDefault(); pick(-1); } | |
| 383 | else if (k === 'ArrowRight' || k === 'd' || k === 'D') { e.preventDefault(); pick(1); } | |
| 384 | else if (k === 's' || k === 'S' || k === 'ArrowDown') { e.preventDefault(); ensureAudio(); G.keySmoke = true; } | |
| 385 | }); | |
| 386 | canvas.addEventListener('keyup', e => { | |
| 387 | if (e.key === 's' || e.key === 'S' || e.key === 'ArrowDown') G.keySmoke = false; | |
| 388 | }); | |
| 389 | canvas.addEventListener('blur', () => { G.keySmoke = false; }); | |
| 390 | const smokeOn = e => { e.preventDefault(); ensureAudio(); if (restart()) return; nodes.smoke.setPointerCapture(e.pointerId); G.pointerSmoke = true; }; | |
| 391 | const smokeOff = () => { G.pointerSmoke = false; }; | |
| 392 | nodes.smoke.addEventListener('pointerdown', smokeOn); | |
| 393 | nodes.smoke.addEventListener('pointerup', smokeOff); | |
| 394 | nodes.smoke.addEventListener('pointercancel', smokeOff); | |
| 395 | nodes.smoke.addEventListener('lostpointercapture', smokeOff); | |
| 396 | nodes.smoke.addEventListener('contextmenu', e => e.preventDefault()); | |
| 397 | ||
| 398 | /* ---------- sound ---------- */ | |
| 399 | let audio = null, muted = false; | |
| 400 | function ensureAudio() { | |
| 401 | if (audio) { if (audio.state === 'suspended') audio.resume(); return; } | |
| 402 | const AC = window.AudioContext || window.webkitAudioContext; | |
| 403 | if (AC) audio = new AC(); | |
| 404 | } | |
| 405 | function sound(kind) { | |
| 406 | if (!audio || muted) return; | |
| 407 | const now = audio.currentTime, gain = audio.createGain(), osc = audio.createOscillator(); | |
| 408 | const spec = { | |
| 409 | lift: [330, 520, .14, .06, 'sine'], | |
| 410 | sting: [180, 90, .3, .07, 'sawtooth'], | |
| 411 | swarm: [140, 260, .6, .06, 'sawtooth'], | |
| 412 | }[kind]; | |
| 413 | osc.type = spec[4]; | |
| 414 | osc.frequency.setValueAtTime(spec[0], now); | |
| 415 | osc.frequency.exponentialRampToValueAtTime(spec[1], now + spec[2]); | |
| 416 | gain.gain.setValueAtTime(spec[3], now); | |
| 417 | gain.gain.exponentialRampToValueAtTime(.0005, now + spec[2]); | |
| 418 | osc.connect(gain).connect(audio.destination); | |
| 419 | osc.start(now); osc.stop(now + spec[2] + .01); | |
| 420 | } | |
| 421 | const muteButton = document.getElementById('mute'); | |
| 422 | muteButton.addEventListener('click', () => { | |
| 423 | muted = !muted; | |
| 424 | muteButton.textContent = muted ? 'sound off' : 'sound on'; | |
| 425 | muteButton.setAttribute('aria-pressed', String(muted)); | |
| 426 | }); | |
| 427 | ||
| 428 | /* ---------- fit and boot ---------- */ | |
| 429 | addEventListener('resize', fit); | |
| 430 | fit(); | |
| 431 | bake(); | |
| 432 | note(HINT); | |
| 433 | renderHud(); | |
| 434 | canvas.focus({ preventScroll: true }); | |
| 435 | let last = performance.now(); | |
| 436 | function frame(now) { | |
| 437 | update(Math.min(.04, (now - last) / 1000)); | |
| 438 | last = now; | |
| 439 | draw(); | |
| 440 | requestAnimationFrame(frame); | |
| 441 | } | |
| 442 | requestAnimationFrame(frame); | |
| 443 | </script> | |
| 444 | </body> | |
| 445 | </html> |
index.html +1
| @@ -78,6 +78,7 @@ footer a::after { content: none; } | ||
| 78 | 78 | <li data-kind="Precision" data-input="Drag" style="--accent:#5fa3c4"><a href="window-washer/">Window Washer</a><span>Squeegee a grimy window clean before the cradle drops a floor: drag across it, bird droppings need two passes</span><span>Game forged by the crew</span><span class="tags">Precision · Drag</span></li> |
| 79 | 79 | <li data-kind="Precision" data-input="Drag" style="--accent:#c4503f"><a href="market-scale/">Market Scale</a><span>Weigh fruit onto a hanging pan scale to match each order: exact scores 3, within 50 g scores 1</span><span>Game forged by the crew</span><span class="tags">Precision · Drag</span></li> |
| 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 | <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> | |
| 81 | 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> |
| 82 | 83 | </ul> |
| 83 | 84 | <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> |
og/beekeeper.png added
og/home.png
serve.test.mjs +7
| @@ -338,3 +338,10 @@ test('the home page sets the js class in the head, uses a get form and one statu | ||
| 338 | 338 | expect(html).toContain('role="status"'); |
| 339 | 339 | expect(html).not.toContain('aria-live'); |
| 340 | 340 | }); |
| 341 | ||
| 342 | test('Beekeeper and its rules script are served without a track', async () => { | |
| 343 | const page = await fetch(base + '/beekeeper/'); | |
| 344 | expect(page.status).toBe(200); | |
| 345 | expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8'); | |
| 346 | expect((await fetch(base + '/beekeeper/hive.js')).status).toBe(200); | |
| 347 | }); |
shell.js +1
| @@ -22,6 +22,7 @@ window.PixelPlays = (() => { | ||
| 22 | 22 | { id: 'window-washer', title: 'Window Washer', blurb: 'Squeegee a grimy window clean before the cradle drops a floor: drag across it, bird droppings need two passes', kind: 'Precision', input: 'Drag', accent: '#5fa3c4', music: false, forged: true }, |
| 23 | 23 | { id: 'market-scale', title: 'Market Scale', blurb: 'Weigh fruit onto a hanging pan scale to match each order: exact scores 3, within 50 g scores 1', kind: 'Precision', input: 'Drag', accent: '#c4503f', music: false, forged: true }, |
| 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 | { 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 }, | |
| 25 | 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 }, |
| 26 | 27 | ]; |
| 27 | 28 | const MUSIC_VOLUME = .4; |
No test covers this line; removing it changes nothing in the suite.