Public: anyone can read this; the crew can change it.

Migrated from github.com/amirmushichge/pixel-plays

Add Chimney Sweep: the playable page and its place in the catalogue, on the rules in `chimney-sweep/roofs.js` #313

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

vesper/pixel-plays:vesper/288-add-chimney-sweep-the-playable-page-and → main 1 commit fork

  • Merged. vesper/288-add-chimney-sweep-the-playable-page-and was merged into main as 92dbb3d.

Review

Sign in to review this change.
9 files changed +545 −4
README.md +3 −2

Diff not shown — a line 2,945 characters wide (limit 2,000). +3 −2

View file
chimney-sweep/index.html added +431
@@ -0,0 +1,431 @@
1 <!doctype html>
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>Chimney Sweep</title>
7 <!-- og:begin -->
8 <meta name="description" content="Climb the flues with your brush and duck the rising smoke">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/chimney-sweep/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Chimney Sweep">
13 <meta property="og:description" content="Climb the flues with your brush and duck the rising smoke">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/chimney-sweep/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/chimney-sweep.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="Chimney Sweep: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
22 <style>
23 :root { --ink: #1c1b19; --muted: #6b675f; --paper: #fff; --accent: #4a4a4a; }
24 * { box-sizing: border-box; }
25 html, body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
26 html, body { height: 100%; margin: 0; background: var(--paper); color: var(--ink); }
27 body { font: 13px/1.35 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; overflow: hidden; }
28 #stage { position: fixed; inset: 0; display: grid; place-items: center; }
29 canvas { display: block; image-rendering: pixelated; touch-action: none; cursor: pointer; outline: none; }
30 canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
31 .hud { position: fixed; left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; pointer-events: none; }
32 #scores { position: fixed; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); display: grid; gap: 2px; pointer-events: none; }
33 #bottom { bottom: max(20px, env(safe-area-inset-bottom)); }
34 .line { display: flex; flex-wrap: wrap; gap: 0 12px; }
35 .row { display: flex; align-items: center; gap: 8px; color: var(--accent); }
36 .row b { font-size: 16px; font-weight: 600; min-width: 1ch; font-variant-numeric: tabular-nums; }
37 .row span { color: var(--muted); }
38 #brushes { display: inline-flex; align-items: flex-end; gap: 4px; height: 20px; }
39 .brush { position: relative; display: block; width: 10px; height: 20px; }
40 .brush::before { content: ""; position: absolute; left: 4px; top: 0; width: 2px; height: 13px; background: var(--ink); }
41 .brush::after { content: ""; position: absolute; left: 0; bottom: 0; width: 10px; height: 8px; background: var(--ink); }
42 .brush.gone::before, .brush.gone::after { background: none; border: 1px solid var(--muted); }
43 .brush.gone::before { border-width: 0 0 0 1px; left: 4px; width: 0; }
44 #status { color: var(--muted); min-height: 2.7em; max-width: 60ch; }
45 button { pointer-events: auto; font: inherit; color: var(--muted); background: none; border: 0; padding: 13px 10px; margin: -13px -10px; min-height: 44px; min-width: 44px; cursor: pointer; }
46 button:hover, button:focus-visible { color: var(--ink); }
47 button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
48 noscript p { position: fixed; inset: 40% 16px auto; margin: 0; text-align: center; color: var(--muted); }
49 </style>
50 </head>
51 <body>
52 <div id="stage"><canvas id="c" tabindex="0" aria-label="Chimney Sweep: a cut-away brick chimney stack with four flues side by side, a sweep with a brush, round grey smoke puffs rising up the flues and rooftops at the top. Tap or press space to pull the brush up; use the left and right arrow keys or swipe to change flue and dodge the smoke. Each puff that hits knocks you down and costs a brush; reach the roof within 60 seconds to win."></canvas></div>
53 <noscript><p>Chimney Sweep needs JavaScript to play.</p></noscript>
54 <div id="scores">
55 <div class="line">
56 <div class="row"><b id="height">0.0</b><span id="of">of 20 m</span></div>
57 <div class="row"><b id="flue">2</b><span id="offlue">of 4 flues</span></div>
58 <div class="row"><b id="time">0.0</b><span id="oftime">of 60 s</span></div>
59 </div>
60 <div class="line">
61 <div class="row"><span id="brushes" role="img" aria-label="3 brushes left"></span><b id="lives">3</b><span>brushes</span></div>
62 <div class="row"><b id="score">0</b><span>points</span></div>
63 <div class="row"><b id="best">0</b><span>best</span></div>
64 </div>
65 </div>
66 <div class="hud" id="bottom">
67 <div id="status" role="status" aria-live="polite"></div>
68 <button id="mute" type="button" aria-pressed="false">sound on</button>
69 </div>
70 <script src="../shell.js"></script>
71 <script>
72 PixelPlays.mount({
73 id: 'chimney-sweep',
74 rules: [
75 'Pull your brush up the flues: tap or press space. The brush must cool for half a second between pulls, then you slide back down.',
76 'Change flue with the left and right arrow keys or a swipe, to dodge the round grey puffs of smoke rising from below.',
77 'A puff knocks you down 3 m and costs a brush; with no brushes left the climb is lost.',
78 'Reach the roof, 20 m up, within 60 seconds; speed and spare brushes add to the score.',
79 ],
80 });
81 </script>
82 <script>window.PP_SCENE = { originY: 108, shadowX: 1.3, shadowY: -.12 };</script>
83 <script src="../engine.js"></script>
84 <script src="roofs.js"></script>
85 <script>
86 'use strict';
87
88 const M = window.ChimneySweep;
89 const BEST_KEY = 'pixel-plays-chimney-sweep-best';
90 const BRICK = [176, 92, 70], MORTAR = [206, 194, 172], SOOT = [88, 80, 92], STONE = [192, 182, 166];
91 const PLASTER = [226, 212, 186], SLATE = [96, 108, 140], TILE = [186, 104, 76], POT = [200, 120, 84], BRASS = [214, 170, 60];
92 const SMOKE = [212, 214, 224], SMOKE_DARK = [150, 154, 170], CINDER = [60, 56, 62];
93 const PAVING = [[130, 126, 132], [146, 142, 146], [162, 158, 160], [178, 174, 172]];
94 const SWEEP = { shirt: [74, 74, 92], stripe: [176, 176, 192], legs: [40, 40, 50], hair: [50, 38, 30], skin: [222, 170, 132] };
95 // the stack in local space: a runs across (screen right is +), b toward the camera, z up; the world axes sit 45 degrees off
96 const toWorld = (a, b, z) => [(a + b) / R2, (b - a) / R2, z];
97 const PITCH = 2.6, HALF = 1.0; // flue spacing and half width, in metres
98 const flueA = i => (i - (M.FLUES - 1) / 2) * PITCH;
99 const WALLS = [[-5.8, -4.9], [-2.9, -2.3], [-.3, .3], [2.3, 2.9], [4.9, 5.8]];
100 const SWEEP_B = .2, PUFF_B = .5;
101 const YAW = Math.PI / 4; // facing the camera
102
103 /* ---------- state ---------- */
104 const nodes = {};
105 for (const k of ['height', 'of', 'flue', 'offlue', 'time', 'oftime', 'brushes', 'lives', 'score', 'best', 'status']) nodes[k] = document.getElementById(k);
106 const shown = {};
107 function setText(key, text) {
108 if (shown[key] === text) return;
109 shown[key] = text;
110 nodes[key].textContent = text;
111 }
112 function setBrushes(n) {
113 if (shown.brushes === n) return;
114 shown.brushes = n;
115 let html = '';
116 for (let k = 0; k < M.LIVES; k++) html += `<span class="brush${k < n ? '' : ' gone'}"></span>`;
117 nodes.brushes.innerHTML = html;
118 nodes.brushes.setAttribute('aria-label', `${n} ${n === 1 ? 'brush' : 'brushes'} left`);
119 }
120 const best0 = (() => { try { return Number(localStorage.getItem(BEST_KEY)) || 0; } catch (e) { return 0; } })();
121 let P = M.start(Math.floor(Math.random() * 4294967296));
122 // pullAt: when the last pull began; bursts: soot clouds where puffs hit; swipe: the pointer drag in progress;
123 // dirty: the picture needs repainting; overAt: when the game ended
124 const G = { time: 0, pullAt: -9, bursts: [], swipe: null, dirty: true, wind: -1, overAt: 0, best: best0 };
125
126 function renderHud() {
127 const h = M.sweepHeight(P.sweep, P.time);
128 setText('height', h.toFixed(1));
129 setText('of', `of ${M.HEIGHT} m`);
130 setText('flue', String(P.sweep.flue + 1));
131 setText('offlue', `of ${M.FLUES} flues`);
132 setText('time', P.time.toFixed(1));
133 setText('oftime', `of ${M.TIME_LIMIT} s`);
134 setBrushes(P.lives);
135 setText('lives', String(P.lives));
136 setText('score', String(P.score));
137 setText('best', String(G.best));
138 }
139 function say(text) { setText('status', text); }
140
141 /* ---------- ground, stack and roofs ---------- */
142 function groundColor(x, y, ix, iy) {
143 const a = (x - y) / R2 - 4, b = (x + y) / R2 - 1;
144 const edge = Math.pow(Math.pow(Math.abs(a) / 15, 4) + Math.pow(Math.abs(b) / 3.9, 4), .25);
145 const rough = edge + (noise(a * 1.3, b * 1.3) - .5) * .1;
146 if (rough > 1.04) return 0;
147 if (rough > .94 && hash(ix, iy) < (rough - .94) / .1) return 0;
148 const joint = Math.abs(((a + 30) % 1.6) - .8) > .72 || Math.abs(((b + 30) % 1.6) - .8) > .72;
149 const t = noise(a * .7, b * .7) * .7 + (hash(ix, iy) - .5) * .3 + (bayerAt(ix, iy) - .5) * .2 - (joint ? .45 : 0);
150 return rgb(...PAVING[clamp(Math.floor(t * 3.6), 0, 3)]);
151 }
152 // paint one world point if it is nearer than what is there; fn gives its colour, or 0 to leave it out
153 function paintAt(a, b, z, fn) {
154 const w = toWorld(a, b, z), p = project(w[0], w[1], z), ix = p.sx | 0, iy = p.sy | 0;
155 if (ix < 0 || iy < 0 || ix >= W || iy >= H) return;
156 const i = iy * W + ix;
157 if (p.d <= zb[i]) return;
158 const c = fn(ix, iy, a, z);
159 if (!c) return;
160 zb[i] = p.d;
161 pix[i] = c;
162 }
163 // a block in local space: only its front (toward the camera) and top can be seen from a 30-degree camera
164 function slab(a0, a1, b0, b1, z0, z1, front, top) {
165 if (front) for (let a = a0; a <= a1; a += .09) for (let z = z0; z <= z1; z += .1) paintAt(a, b1, z, front);
166 if (top) for (let a = a0; a <= a1; a += .09) for (let b = b0; b <= b1; b += .15) paintAt(a, b, z1, top);
167 }
168 const cell = (x, y) => (Math.imul(x, 73856093) ^ Math.imul(y, 19349663)) >>> 0;
169 // courses of staggered bricks (or tiles) laid in screen pixels, so every brick is a whole number of pixels
170 function courses(colour, mortar, rowH, brickW, shade) {
171 const ramp = rampOf(colour), joint = rampOf(mortar)[2];
172 return (ix, iy) => {
173 const row = Math.floor(iy / rowH), off = (row & 1) * (brickW >> 1);
174 if (iy % rowH === 0 || (ix + off) % brickW === 0) return joint;
175 const h = cell(Math.floor((ix + off) / brickW), row) % 100;
176 return ramp[clamp(shade + (h < 12 ? -1 : h > 88 ? 1 : 0), 0, 4)];
177 };
178 }
179 function soot(ix, iy, a, z) {
180 const ramp = rampOf(SOOT), f = ((a + 1000 * PITCH + HALF) % PITCH) / (2 * HALF); // 0 at a flue's left wall, 1 at its right
181 const streak = noise(a * 3.1, z * .25) + (bayerAt(ix, iy) - .5) * .5;
182 return ramp[f < .3 ? 0 : streak > .6 ? 2 : 1];
183 }
184 function bakeStack() {
185 const brick = courses(BRICK, MORTAR, 4, 8, 2), brickTop = courses(BRICK, MORTAR, 4, 8, 4), stone = courses(STONE, MORTAR, 6, 12, 3);
186 const flag = ix => rampOf(SOOT)[1 + (ix & 1)];
187 slab(-5.8, 5.8, -1, -.2, 0, M.HEIGHT, soot, null); // the flues' back wall, black with soot
188 slab(-5.8, 5.8, -1, 1.2, 0, .06, null, flag); // the hearth floor
189 for (const [w0, w1] of WALLS) {
190 slab(w0, w1, -1, 1, 0, M.HEIGHT, brick, null); // the cut face of each wall
191 slab(w0 - .2, w1 + .2, -1.2, 1.2, M.HEIGHT, M.HEIGHT + .6, stone, brickTop); // its stone cap
192 }
193 for (let i = 0; i < M.FLUES; i++) { // a pot behind each flue's mouth
194 const w = toWorld(flueA(i), -.6, M.HEIGHT);
195 capsule([w[0], w[1], M.HEIGHT], [w[0], w[1], M.HEIGHT + 1.2], .42, .34, () => POT, 'solid');
196 capsule([w[0], w[1], M.HEIGHT + 1.2], [w[0], w[1], M.HEIGHT + 1.35], .5, .5, () => BRASS, 'solid');
197 }
198 }
199 function bakeRoofs() {
200 const plaster = rampOf(PLASTER), slate = courses(SLATE, MORTAR, 3, 6, 2), tile = courses(TILE, MORTAR, 3, 6, 2);
201 for (const [c, roof] of [[-13, tile], [0, slate], [13, tile]]) {
202 const body = (ix, iy, a, z) => {
203 if (hash(ix, iy) < (14.8 - z) / 2.4) return 0; // the walls dissolve into white below
204 const wa = Math.abs(a - c);
205 if (z > 16.1 && z < 17.9 && wa > 1.4 && wa < 2.7) return z > 16.4 && z < 17.6 && wa > 1.6 && wa < 2.5 ? rgb(70, 90, 128) : rgb(250, 246, 236);
206 return plaster[2 + (noise(a * 2, z * 2) > .62 ? 1 : 0)];
207 };
208 slab(c - 4, c + 4, -5, -3, 12.5, 19.6, body, null);
209 for (let k = 0; k < 4; k++) slab(c - 4.5 + k * .9, c + 4.5 - k * .9, -5.4, -2.6, 19.6 + k * .8, 20.4 + k * .8, roof, roof);
210 const w = toWorld(c + 2.2, -3.4, 22.6);
211 capsule([w[0], w[1], 21.4], [w[0], w[1], 23.2], .4, .32, () => POT, 'solid');
212 }
213 }
214 function bake() {
215 ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0);
216 zb.fill(-1e9);
217 pix.fill(PAPER);
218 for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) {
219 const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy);
220 if (!c) continue;
221 pix[i] = c; ground[i] = 1;
222 zb[i] = (g.x + g.y) / R2 * COS;
223 }
224 groundZ.set(zb);
225 bakeStack();
226 bakeRoofs();
227 for (const a of [-5.3, -2.6, 0, 2.6, 5.3]) for (let z = 0; z <= M.HEIGHT + .6; z += .9) {
228 const w = toWorld(a, 0, z);
229 castShadow(w[0], w[1], z, 1, 1, .4);
230 }
231 bakeOcclusion();
232 staticShadow.set(shadowMask);
233 applyShadows(groundZ);
234 bakedPix.set(pix);
235 bakedZ.set(zb);
236 }
237
238 /* ---------- the sweep, the smoke and the weathervane ---------- */
239 const dynamicSolid = (a, b, r0, r1, c) => dynamicAdd(a, b, r0, r1, () => c);
240 function drawSweep() {
241 const h = M.sweepHeight(P.sweep, P.time), w = toWorld(flueA(P.sweep.flue), SWEEP_B, 0);
242 const pulse = clamp(1 - (G.time - G.pullAt) / .25, 0, 1), k = .78;
243 const hand = figure(w[0], w[1], YAW, { z: h, scale: k, armR: 2.6 + pulse * .3, armL: .3, stance: .1 }, SWEEP, dynamicAdd);
244 const head = [hand[0], hand[1], hand[2] + 1.0 * k + pulse * .5];
245 dynamicSolid(hand, head, .06, .06, [120, 90, 60]); // the brush pole
246 for (const [dz, r] of [[.1, .26], [.3, .22]]) sphere(head[0], head[1], head[2] + dz, r, CINDER, 'rough'); // bristles
247 const top = [w[0] + .04, w[1] - .04, h + 1.55 * k + .1]; // a top hat with a brass band
248 dynamicSolid([top[0], top[1], top[2]], [top[0], top[1], top[2] + .02], .27 * k + .1, .27 * k + .1, [36, 34, 40]);
249 dynamicSolid([top[0], top[1], top[2] + .02], [top[0], top[1], top[2] + .5 * k], .17, .17, [36, 34, 40]);
250 dynamicSolid([top[0], top[1], top[2] + .05], [top[0], top[1], top[2] + .13], .18, .18, BRASS);
251 }
252 // a puff is a lumpy cloud: three overlapping balls that swell as it rises and wobble from side to side
253 function drawPuff(p) {
254 const h = M.puffHeight(p, P.time);
255 if (h === null || p.hit || h > M.HEIGHT + 3) return;
256 const age = P.time - p.at, wob = Math.sin(age * 2.6 + p.id * 1.7) * .26, r = .36 + age * .045;
257 const w = toWorld(flueA(p.flue) + wob, PUFF_B, h + .3);
258 sphere(w[0], w[1], w[2], r, SMOKE, 'rough');
259 const l = toWorld(flueA(p.flue) + wob - r * .8, PUFF_B, h + .1), n = toWorld(flueA(p.flue) + wob + r * .7, PUFF_B, h + .45);
260 sphere(l[0], l[1], l[2], r * .72, SMOKE_DARK, 'rough');
261 sphere(n[0], n[1], n[2], r * .66, SMOKE, 'rough');
262 }
263 function drawBursts() {
264 G.bursts = G.bursts.filter(b => G.time - b.t < .5);
265 for (const b of G.bursts) {
266 const k = (G.time - b.t) / .5;
267 for (let n = 0; n < 5; n++) {
268 const ang = n * 1.26 + b.h, w = toWorld(flueA(b.flue) + Math.cos(ang) * k * .8, SWEEP_B + .3, b.h + .8 + Math.sin(ang) * k * .8);
269 sphere(w[0], w[1], w[2], .22 * (1 - k * .5), CINDER, 'rough');
270 }
271 }
272 }
273 function drawVane(t) {
274 const base = toWorld(0, -3.8, 23.4), tip = toWorld(0, -3.8, 25.4), ang = t * .7;
275 capsule([base[0], base[1], 23.4], [tip[0], tip[1], 25.4], .09, .07, () => [60, 56, 62], 'solid');
276 const reach = [Math.cos(ang), Math.sin(ang)];
277 const a = toWorld(reach[0] * .9, -3.8 + reach[1] * .9, 25.2), b = toWorld(-reach[0] * .9, -3.8 - reach[1] * .9, 25.2);
278 capsule([a[0], a[1], 25.2], [b[0], b[1], 25.2], .07, .07, () => BRASS, 'solid');
279 sphere(a[0], a[1], 25.2, .2, BRASS, 'solid');
280 }
281 function draw() {
282 pix.set(bakedPix);
283 zb.set(bakedZ);
284 pendingShadows.length = 0;
285 const t = STILL ? 0 : Math.floor(G.time * WIND_FPS) / WIND_FPS;
286 for (const p of P.puffs) drawPuff(p);
287 drawSweep();
288 drawBursts();
289 drawVane(t);
290 flushShadows();
291 applyShadows(bakedZ);
292 shadeEdges();
293 ctx.putImageData(image, 0, 0);
294 }
295
296 /* ---------- game: every rule is the rules script's ---------- */
297 function saveBest() {
298 if (P.score <= G.best) return;
299 G.best = P.score;
300 try { localStorage.setItem(BEST_KEY, String(G.best)); } catch (e) { /* private window: keep it for this visit */ }
301 }
302 function finish(before) {
303 G.overAt = G.time;
304 saveBest();
305 say(`${P.line}. Tap or press space to play again.`);
306 sound(P.status === 'won' ? 880 : 110, .4, P.status === 'won' ? 'triangle' : 'sawtooth', .15);
307 }
308 function update(dt) {
309 G.time += dt;
310 if (P.status === 'playing') {
311 const before = P, r = M.tick(P, dt);
312 if (r.ok) {
313 P = r.state;
314 G.dirty = true;
315 if (P.lives < before.lives) {
316 for (const p of P.puffs) if (p.hit && !before.puffs[p.id].hit) G.bursts.push({ t: G.time, flue: p.flue, h: M.sweepHeight(before.sweep, P.time) });
317 sound(130, .25, 'sawtooth');
318 if (P.status === 'playing') say(`Smoke hit! ${P.line}.`);
319 }
320 if (P.status !== 'playing') finish(before);
321 }
322 }
323 const wind = STILL ? 0 : Math.floor(G.time * WIND_FPS);
324 if (wind !== G.wind) { G.wind = wind; G.dirty = true; }
325 renderHud();
326 }
327 function begin() {
328 say(`${P.line}. Tap or press space to pull, left and right to change flue.`);
329 }
330 function restart() {
331 P = M.start(Math.floor(Math.random() * 4294967296));
332 G.bursts = []; G.pullAt = -9; G.dirty = true;
333 begin();
334 }
335 function pull() {
336 ensureAudio();
337 G.dirty = true;
338 if (P.status !== 'playing') { if (G.time - G.overAt > .6) restart(); return; }
339 const r = M.pull(P);
340 if (!r.ok) { say(r.why === 'cooldown' ? 'The brush is still cooling.' : `Cannot pull: ${r.why}.`); return; }
341 P = r.state;
342 G.pullAt = G.time;
343 sound(300 + 25 * P.sweep.h, .07, 'triangle');
344 if (P.status === 'playing') say(`Pull. ${P.line}.`); else finish(P);
345 }
346 function change(dir) {
347 ensureAudio();
348 G.dirty = true;
349 if (P.status !== 'playing') return;
350 const r = M.shift(P, dir);
351 if (!r.ok) { say(r.why === 'wall' ? 'The wall stops you.' : `Cannot move: ${r.why}.`); return; }
352 P = r.state;
353 sound(440, .05, 'square');
354 say(`${dir < 0 ? 'Left' : 'Right'}. ${P.line}.`);
355 }
356
357 /* ---------- input: a tap pulls, a swipe changes flue ---------- */
358 const SWIPE = 22;
359 const point = e => { const r = canvas.getBoundingClientRect(); return [(e.clientX - r.left) / r.width * W, (e.clientY - r.top) / r.height * H]; };
360 canvas.addEventListener('pointerdown', e => {
361 canvas.focus({ preventScroll: true });
362 const [x, y] = point(e);
363 G.swipe = { x, y, moved: false };
364 });
365 canvas.addEventListener('pointermove', e => {
366 const s = G.swipe;
367 if (!s || s.moved) return; // one flue change per swipe
368 const [x, y] = point(e), dx = x - s.x;
369 if (Math.abs(dx) < SWIPE || Math.abs(dx) < Math.abs(y - s.y)) return;
370 s.moved = true;
371 change(dx > 0 ? 1 : -1);
372 });
373 canvas.addEventListener('pointerup', () => {
374 const s = G.swipe;
375 G.swipe = null;
376 if (s && !s.moved) pull();
377 });
378 canvas.addEventListener('pointercancel', () => { G.swipe = null; });
379 canvas.addEventListener('contextmenu', e => e.preventDefault());
380 canvas.addEventListener('keydown', e => {
381 if (e.ctrlKey || e.metaKey || e.altKey) return;
382 if (e.key === 'ArrowLeft') change(-1);
383 else if (e.key === 'ArrowRight') change(1);
384 else if (e.key === ' ' || e.key === 'Enter' || e.key === 'ArrowUp') { if (!e.repeat) pull(); }
385 else return;
386 e.preventDefault();
387 });
388
389 /* ---------- sound ---------- */
390 let audio = null, muted = false;
391 function ensureAudio() {
392 if (audio) { if (audio.state === 'suspended') audio.resume(); return; }
393 const AC = window.AudioContext || window.webkitAudioContext;
394 if (AC) audio = new AC();
395 }
396 function sound(freq, life, type, delay = 0) {
397 if (!audio || muted) return;
398 const now = audio.currentTime + delay, gain = audio.createGain(), osc = audio.createOscillator();
399 osc.type = type;
400 osc.frequency.setValueAtTime(freq, now);
401 gain.gain.setValueAtTime(.0001, now);
402 gain.gain.exponentialRampToValueAtTime(.06, now + .01);
403 gain.gain.exponentialRampToValueAtTime(.0005, now + life);
404 osc.connect(gain).connect(audio.destination);
405 osc.start(now); osc.stop(now + life + .02);
406 }
407 const muteButton = document.getElementById('mute');
408 muteButton.addEventListener('click', () => {
409 muted = !muted;
410 muteButton.textContent = muted ? 'sound off' : 'sound on';
411 muteButton.setAttribute('aria-pressed', String(muted));
412 });
413
414 /* ---------- fit and boot ---------- */
415 addEventListener('resize', fit);
416 fit();
417 bake();
418 renderHud();
419 begin();
420 canvas.focus({ preventScroll: true });
421 let last = performance.now();
422 function frame(now) {
423 update(Math.min(.04, (now - last) / 1000));
424 last = now;
425 if (G.dirty) { G.dirty = false; draw(); }
426 requestAnimationFrame(frame);
427 }
428 requestAnimationFrame(frame);
429 </script>
430 </body>
431 </html>
chimney-sweep/page.test.mjs added +85
@@ -0,0 +1,85 @@
1 import { test, expect } from 'bun:test';
2 import { boot } from '../playtest.mjs';
3
4 test('space and a tap pull through the rules, and the HUD and the live region report the rules state', () => {
5 const g = boot('chimney-sweep');
6 expect(g.el('height').textContent).toBe('0.0');
7 g.press(' ');
8 expect(g.read('P.sweep.h')).toBeGreaterThan(0.9);
9 expect(g.el('status').textContent).toContain(g.read('P.line'));
10 expect(g.el('status').textContent).toMatch(/^Pull\./);
11 g.run(.6);
12 const before = g.read('P.sweep.h');
13 g.tap(180, 140);
14 expect(g.read('P.sweep.h')).toBeGreaterThan(before);
15 expect(g.el('height').textContent).toBe(g.read('ChimneySweep.sweepHeight(P.sweep, P.time).toFixed(1)'));
16 });
17
18 test('a pull inside the cooldown is refused and says so', () => {
19 const g = boot('chimney-sweep');
20 g.press(' ', .02);
21 const h = g.read('P.sweep.h');
22 g.press(' ', .02);
23 expect(g.read('P.sweep.h')).toBeLessThan(h + .5);
24 expect(g.el('status').textContent).toContain('cooling');
25 });
26
27 test('the arrow keys and a swipe change flue, and a wall stops you', () => {
28 const g = boot('chimney-sweep');
29 expect(g.read('P.sweep.flue')).toBe(1);
30 g.press('ArrowRight');
31 expect(g.read('P.sweep.flue')).toBe(2);
32 expect(g.el('flue').textContent).toBe('3');
33 expect(g.el('status').textContent).toMatch(/^Right\./);
34 g.drag([200, 140], [100, 142], .3);
35 expect(g.read('P.sweep.flue')).toBe(1);
36 g.press('ArrowLeft'); g.press('ArrowLeft');
37 expect(g.read('P.sweep.flue')).toBe(0);
38 expect(g.el('status').textContent).toContain('wall');
39 expect(g.read('P.sweep.h')).toBe(0); // a swipe is not a pull
40 });
41
42 test('a puff that hits costs a brush, shows in the HUD and is announced', () => {
43 const g = boot('chimney-sweep');
44 const flue = g.read('P.sweep.flue');
45 g.run(30 / 25);
46 let hit = false;
47 for (let i = 0; i < 25 * 20 && !hit; i++) { g.step(1); hit = g.read('P.lives') < 3; }
48 expect(hit).toBe(true);
49 expect(g.el('lives').textContent).toBe(String(g.read('P.lives')));
50 expect(g.el('brushes').innerHTML.match(/class="brush gone"/g).length).toBe(3 - g.read('P.lives'));
51 expect(g.el('brushes').innerHTML.match(/class="brush"/g).length).toBe(g.read('P.lives'));
52 expect(g.el('status').textContent).toContain('Smoke hit!');
53 expect(flue).toBe(1);
54 });
55
56 test('the end shows the rules line and a tap plays again', () => {
57 const g = boot('chimney-sweep');
58 g.run(61);
59 expect(g.read('P.status')).toBe('lost');
60 expect(g.el('status').textContent).toContain(g.read('P.line'));
61 g.run(1);
62 g.tap(180, 140);
63 expect(g.read('P.status')).toBe('playing');
64 expect(g.read('P.time')).toBeLessThan(1);
65 });
66
67 test('mute toggles its label and aria-pressed', () => {
68 const g = boot('chimney-sweep');
69 g.el('mute').fire('click');
70 expect(g.el('mute').textContent).toBe('sound off');
71 expect(g.el('mute').attrs['aria-pressed']).toBe('true');
72 });
73
74 test('the page source says how to play, stills the vane, shows lives as brushes, holds the rules to four lines and names no .mp3', async () => {
75 const html = await Bun.file(new URL('./index.html', import.meta.url)).text();
76 expect(html).toMatch(/<canvas id="c"[^>]*aria-label="[^"]*space[^"]*arrow keys[^"]*swipe/);
77 expect(html).toMatch(/min-height: 44px; min-width: 44px/);
78 expect(html).toMatch(/id="mute"[^>]*aria-pressed="false"/);
79 expect(html).toContain('const t = STILL ? 0');
80 expect(html).toMatch(/role="status" aria-live="polite"/);
81 expect(html).toContain('class="brush');
82 expect(html).not.toContain('.mp3');
83 const rules = html.match(/rules: \[([\s\S]*?)\]/)[1].split('\n').filter(l => l.trim());
84 expect(rules.length).toBeLessThanOrEqual(4);
85 });
index.html +1
@@ -131,6 +131,7 @@ footer a::after { content: none; }
131131 <li data-kind="Sport" data-input="Tap" style="--accent:#8a4b22"><a href="conkers/">Conkers</a><span>Time your swing to crack every rival conker in the playground</span><span>Game forged by the crew</span><span class="tags">Sport · Tap</span></li>
132132 <li data-kind="Timing" data-input="Tap" style="--accent:#d0573c"><a href="skipping-rope/">Skipping Rope</a><span>Jump the turning rope as it quickens and friends join the line</span><span>Game forged by the crew</span><span class="tags">Timing · Tap</span></li>
133133 <li data-kind="Memory" data-input="Tap" style="--accent:#c98aa0"><a href="tea-party/">Tea Party</a><span>Remember every guest's order and pour it right as the table grows</span><span>Game forged by the crew</span><span class="tags">Memory · Tap</span></li>
134 <li data-kind="Climbing" data-input="Tap" style="--accent:#4a4a4a"><a href="chimney-sweep/">Chimney Sweep</a><span>Climb the flues with your brush and duck the rising smoke</span><span>Game forged by the crew</span><span class="tags">Climbing · Tap</span></li>
134135 </ul>
135136 <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>
136137 </main>
og/chimney-sweep.png added
Binary file not shown.
og/home.png
Binary file not shown.
rounds.mjs +15
@@ -10,6 +10,7 @@ import Wheel from './ferris-wheel/wheel.js';
1010 import Quilt from './quilt/patch.js';
1111 import Jars from './jam-jars/shelf.js';
1212 import Shelf from './library-shelf/shelf.js';
13 import Sweep from './chimney-sweep/roofs.js';
1314
1415 const MID = [180, 140];
1516 const tapping = (wait = .3) => g => { g.tap(...MID); g.run(wait); };
@@ -461,6 +462,20 @@ export const ROUNDS = {
461462 else if (cup.cake !== want.cake) tap('cake');
462463 else tap(guest);
463464 } },
465 // pull whenever the brush is cool; before each pull, look half a second ahead in the rules' own `tick` and change flue if smoke would hit
466 'chimney-sweep': { over: /play again/, outcome: /You win: reached the roof with \d lives? left in [\d.]+ s, score \d+/, beat: g => {
467 const s = JSON.parse(g.read('JSON.stringify(P)'));
468 if (s.status !== 'playing') { g.run(.3); return; }
469 if (s.time < s.sweep.restUntil) { g.step(Math.max(1, Math.round((s.sweep.restUntil - s.time) * 25))); return; }
470 const safe = st => Sweep.tick(st, .6).state.lives === st.lives;
471 const here = Sweep.pull(s).state;
472 if (safe(here)) { g.press(' ', .02); return; }
473 for (const dir of [-1, 1]) {
474 const moved = Sweep.shift(s, dir);
475 if (moved.ok && safe(Sweep.pull(moved.state).state)) { g.press(dir < 0 ? 'ArrowLeft' : 'ArrowRight', .02); return; }
476 }
477 g.press(' ', .02);
478 } },
464479 'window-washer': { over: /play again/, outcome: /[1-9]\d* of 500/, beat: g => g.drag([60, 100], [300, 100], .6) },
465480 };
466481
serve.test.mjs +8 −1
@@ -330,7 +330,7 @@ test('every game has a kind, input and accent, and the static list carries them'
330330 delete globalThis.PixelPlays;
331331 }
332332 for (const g of games) {
333 expect(['Sport', 'Throwing', 'Timing', 'Catching', 'Precision', 'Racing', 'Memory', 'Strategy', 'Puzzle']).toContain(g.kind);
333 expect(['Sport', 'Throwing', 'Timing', 'Catching', 'Precision', 'Racing', 'Memory', 'Strategy', 'Puzzle', 'Climbing']).toContain(g.kind);
334334 expect(['Tap', 'Hold', 'Drag', 'Keys']).toContain(g.input);
335335 expect(g.accent).toMatch(/^#[0-9a-f]{6}$/i);
336336 expect(html).toContain(`<li data-kind="${g.kind}" data-input="${g.input}" style="--accent:${g.accent}"><a href="${g.id}/">`);
@@ -719,3 +719,10 @@ test('Tea Party and its rules script are served without a track', async () => {
719719 expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8');
720720 expect((await fetch(base + '/tea-party/table.js')).status).toBe(200);
721721 });
722
723 test('Chimney Sweep and its rules script are served without a track', async () => {
724 const page = await fetch(base + '/chimney-sweep/');
725 expect(page.status).toBe(200);
726 expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8');
727 expect((await fetch(base + '/chimney-sweep/roofs.js')).status).toBe(200);
728 });
shell.js +2 −1
@@ -1,7 +1,7 @@
11 'use strict';
22 // Shared chrome for every game: game menu (top centre) and rules popup (top right).
33 window.PixelPlays = (() => {
4 // add a game here and give it a folder, a one-line `blurb`, a `kind` (Sport, Throwing, Timing, Catching, Precision, Racing, Memory, Strategy, Puzzle), an `input` (Tap, Hold, Drag, Keys) and an `accent` colour for its card (the home page lists it from here) (`music: false` when it has no track, `forged: true` when it was made on the forge rather than by the original creators); `soon` entries show in the menu but do not link
4 // add a game here and give it a folder, a one-line `blurb`, a `kind` (Sport, Throwing, Timing, Catching, Precision, Racing, Memory, Strategy, Puzzle, Climbing), an `input` (Tap, Hold, Drag, Keys) and an `accent` colour for its card (the home page lists it from here) (`music: false` when it has no track, `forged: true` when it was made on the forge rather than by the original creators); `soon` entries show in the menu but do not link
55 const GAMES = [
66 { id: 'balote', title: 'Balote', blurb: 'Bocce against a bot, first to 5', kind: 'Throwing', input: 'Drag', accent: '#d9a441' },
77 { id: 'stari-most', title: 'Stari Most', blurb: 'Five dives off the old bridge, flip and enter the water vertically', kind: 'Timing', input: 'Hold', accent: '#3f8fb5' },
@@ -71,6 +71,7 @@ window.PixelPlays = (() => {
7171 { id: 'conkers', title: 'Conkers', blurb: 'Time your swing to crack every rival conker in the playground', kind: 'Sport', input: 'Tap', accent: '#8a4b22', music: false, forged: true },
7272 { id: 'skipping-rope', title: 'Skipping Rope', blurb: 'Jump the turning rope as it quickens and friends join the line', kind: 'Timing', input: 'Tap', accent: '#d0573c', music: false, forged: true },
7373 { id: 'tea-party', title: 'Tea Party', blurb: 'Remember every guest\'s order and pour it right as the table grows', kind: 'Memory', input: 'Tap', accent: '#c98aa0', music: false, forged: true },
74 { id: 'chimney-sweep', title: 'Chimney Sweep', blurb: 'Climb the flues with your brush and duck the rising smoke', kind: 'Climbing', input: 'Tap', accent: '#4a4a4a', music: false, forged: true },
7475 ];
7576 const MUSIC_VOLUME = .4;
7677 const CREDITS = [

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs