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

Migrated from github.com/amirmushichge/pixel-plays

Add Rain Barrel: the playable page and its place in the catalogue, on the rules in `rain-barrel/gutter.js` #246

Merged opened this

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

Merged

quill/pixel-plays:quill/220-add-rain-barrel-the-playable-page-and-it → main 3 commits fork 2 threads · 2 unresolved

  • Merged. quill/220-add-rain-barrel-the-playable-page-and-it was merged into main as b716d15.

Review

Sign in to review this change.
8 files changed +399 −2
README.md +3 −2

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

View file
index.html +1
@@ -121,6 +121,7 @@ footer a::after { content: none; }
121121 <li data-kind="Puzzle" data-input="Keys" style="--accent:#3d6e4f"><a href="hedge-maze/">Hedge Maze</a><span>Find the way through the hedges to the fountain before the gardener rings the bell</span><span>Game forged by the crew</span><span class="tags">Puzzle · Keys</span></li>
122122 <li data-kind="Memory" data-input="Tap" style="--accent:#6b8f3a"><a href="bird-watch/">Bird Watch</a><span>Remember where each bird perched</span><span>Game forged by the crew</span><span class="tags">Memory · Tap</span></li>
123123 <li data-kind="Strategy" data-input="Tap" style="--accent:#3d7f6e"><a href="bunting/">Bunting</a><span>Hang the flags for the fete so no two neighbours match</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
124 <li data-kind="Catching" data-input="Tap" style="--accent:#5f86a3"><a href="rain-barrel/">Rain Barrel</a><span>Slide the barrel under each spout before the yard floods</span><span>Game forged by the crew</span><span class="tags">Catching · Tap</span></li>
124125 <li data-kind="Puzzle" data-input="Tap" style="--accent:#b5656b"><a href="quilt/">Patchwork Quilt</a><span>Turn and swap the patches until every stitch lines up</span><span>Game forged by the crew</span><span class="tags">Puzzle · Tap</span></li>
125126 </ul>
126127 <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/home.png
Binary file not shown.
og/rain-barrel.png added
Binary file not shown.
rain-barrel/index.html added +379
@@ -0,0 +1,379 @@
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>Rain Barrel</title>
7 <!-- og:begin -->
8 <meta name="description" content="Slide the barrel under each spout before the yard floods">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/rain-barrel/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Rain Barrel">
13 <meta property="og:description" content="Slide the barrel under each spout before the yard floods">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/rain-barrel/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/rain-barrel.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="Rain Barrel: 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: #5f86a3; }
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 .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; }
31 #scores { position: fixed; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); display: grid; gap: 2px; pointer-events: none; }
32 #bottom { bottom: max(20px, env(safe-area-inset-bottom)); }
33 .row { display: flex; align-items: center; gap: 8px; color: var(--accent); }
34 .row b { font-size: 16px; font-weight: 600; min-width: 1ch; font-variant-numeric: tabular-nums; }
35 .row span { color: var(--muted); }
36 #left { display: grid; gap: 2px; }
37 #line, #status { color: var(--muted); min-height: 1.35em; }
38 button { pointer-events: auto; font: inherit; color: var(--muted); background: none; border: 0; padding: 13px 10px; margin: -13px -10px; min-height: 44px; cursor: pointer; }
39 button:hover, button:focus-visible { color: var(--ink); }
40 button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
41 noscript p { position: fixed; inset: 40% 16px auto; margin: 0; text-align: center; color: var(--muted); }
42 </style>
43 </head>
44 <body>
45 <div id="stage"><canvas id="c" tabindex="0" aria-label="A cottage wall with a row of five gutter spouts, a rain barrel on the paving beneath them and a puddle growing in the yard. Rain drips from one spout at a time. Tap a spout, or press the left and right arrow keys, to slide the barrel under the falling drops; tap the barrel, or press Space, to empty it when it is full, under its lid. If the puddle reaches the line, the yard floods."></canvas></div>
46 <noscript><p>Rain Barrel needs JavaScript to play.</p></noscript>
47 <div id="scores">
48 <div class="row"><b id="time">40</b><span>ticks of rain left</span></div>
49 <div class="row"><b id="barrel">0</b><span id="barrelOf"></span></div>
outdated

'of 4' and 'of 8' are hard-coded; set barrelOf and puddleOf from P.capacity and P.limit in renderHud.

50 <div class="row"><b id="puddle">0</b><span id="puddleOf"></span></div>
51 <div class="row"><b id="score">0</b><span>points</span></div>
52 </div>
53 <div class="hud" id="bottom">
54 <div id="left"><div id="line"></div><div id="status" role="status" aria-live="polite"></div></div>
55 <button id="mute" type="button" aria-pressed="false">sound on</button>
outdated

This role=status aria-live=polite element is rewritten by setText('status', P.line) every tick (update(), about line 190), so it announces twice a second. Limit live announcements to event notes and the end line.

56 </div>
57 <script src="../shell.js"></script>
58 <script>
59 PixelPlays.mount({
60 id: 'rain-barrel',
61 rules: [
62 'Rain drips from one spout at a time: tap it, or use left and right, to slide the barrel under it.',
63 'Each drop caught scores; any other drop adds to the yard puddle.',
64 'A full barrel wears its lid: tap it or press Space to empty it, which costs two ticks of rain.',
65 'Keep the puddle under its line until the rain stops.',
66 ],
67 });
68 </script>
69 <script>window.PP_SCENE = { originY: 18, shadowX: 1.3, shadowY: -.12 };</script>
70 <script src="../engine.js"></script>
71 <script src="gutter.js"></script>
72 <script>
73 'use strict';
74
75 /* ---------- the cottage and its yard ---------- */
76 const SPOUT_X = [-6, -3, 0, 3, 6];
77 const WALL = { x: 8.3, y0: -5.6, y1: -4.6, h: 3.3 }, PIPE_Y = -4.4, DROP_Y = -3.7, DROP_TOP = 2.4;
78 const PUDDLE_AT = { x: 0, y: 3.2 }, PUDDLE_MIN = .5, PUDDLE_LIMIT_R = 4.9;
79 const LAWN = [[70, 120, 70], [78, 130, 74]], FLAGS = [190, 184, 170];
80 const PLASTER = [226, 212, 186], ROOF = [150, 82, 70], ZINC = [150, 160, 170], DOOR = [96, 112, 140], GLASS = [150, 190, 214];
81 const STAVE = [166, 118, 76], HOOP = [70, 74, 84], WATER = [96, 160, 226], CLOUD = [246, 246, 250], DROP = [140, 196, 240];
82 const INK_PIX = rgb(28, 27, 25), WHITE_PIX = rgb(255, 255, 255), LIMIT_PIX = rgb(200, 60, 50);
83 const DARK_PIX = rgb(40, 52, 70), WATER_PIX = rgb(96, 160, 226), WOOD_PIX = rgb(176, 128, 84), SPLASH_PIX = rgb(190, 224, 250);
84 const PUDDLE = [92, 150, 214];
85 const BARREL_Y = DROP_Y, BARREL_R = .72;
86
87 function groundColor(x, y, ix, iy) {
88 const edge = Math.pow(Math.abs(x) / 11, 6) + Math.pow(Math.abs(y - .4) / 8.2, 6);
89 const rough = Math.pow(edge, 1 / 6) + (noise(x * 1.3, y * 1.3) - .5) * .06;
90 if (rough > 1) return 0;
91 if (rough > .95 && hash(ix, iy) < (rough - .95) / .05) return 0;
92 const t = .96 + (hash(ix, iy) - .5) * .08;
93 const paved = y < -2.7 && y > WALL.y1 && Math.abs(x) < 8.6;
94 const c = paved ? FLAGS : LAWN[Math.floor((x + y) / 2.5) & 1];
95 return rgb(c[0] * t, c[1] * t, c[2] * t);
96 }
97 const solid = (a, b, r0, r1, c) => capsule(a, b, r0, r1, () => c, 'rough');
98 function bakeCottage() {
99 const { x, y0, y1, h } = WALL;
100 box(-x, y0, 0, x, y1, h, PLASTER, 3);
101 box(1.1, y1, 0, 2, y1 + .12, 2.3, DOOR, 6); // door between spouts 2 and 3
102 for (const wx of [-5, 4.5]) box(wx - .5, y1, 1.2, wx + .5, y1 + .12, 2.4, GLASS, 9);
103 box(-5.1, -6.7, 3.6, -4.2, -5.8, 6.4, [160, 120, 100], 5); // chimney
104 for (let cx = -x - .2; cx <= x + .2; cx += .22) solid([cx, PIPE_Y, h], [cx, -7.1, 5.4], .17, .17, ROOF);
105 solid([-x - .3, PIPE_Y, h - .05], [x + .3, PIPE_Y, h - .05], .16, .16, ZINC); // the gutter
106 for (const sx of SPOUT_X) {
107 solid([sx, PIPE_Y, h - .05], [sx, PIPE_Y, DROP_TOP + .3], .13, .13, ZINC);
108 solid([sx, PIPE_Y, DROP_TOP + .3], [sx, DROP_Y, DROP_TOP + .1], .13, .13, ZINC);
109 }
110 for (let sx = -x; sx <= x; sx += .7) for (let z = 0; z <= h; z += .9) castShadow(sx, (y0 + y1) / 2, z, .4, 1, 0);
111 }
112 function bake() {
113 ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0);
114 tufts.length = 0; leaves.length = 0;
115 zb.fill(-1e9);
116 pix.fill(rgb(255, 255, 255));
117 for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) {
118 const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy);
119 if (!c) continue;
120 pix[i] = c; ground[i] = 1;
121 zb[i] = (g.x + g.y) / R2 * COS;
122 }
123 groundZ.set(zb);
124 bakeCottage();
125 bakeOcclusion();
126 staticShadow.set(shadowMask);
127 applyShadows(groundZ);
128 bakedPix.set(pix);
129 bakedZ.set(zb);
130 }
131
132 /* ---------- state ---------- */
133 const nodes = {};
134 for (const k of ['time', 'barrel', 'barrelOf', 'puddle', 'puddleOf', 'score', 'line', 'status']) nodes[k] = document.getElementById(k);
135 const shown = {};
136 function setText(key, text) {
137 if (shown[key] === text) return;
138 shown[key] = text;
139 nodes[key].textContent = text;
140 }
141 const fresh = () => RainBarrel.start(Math.floor(Math.random() * 4294967296));
142
143 // presentation only: the rules know nothing of seconds
144 const TICK = .5, LEAD = .8, SLIDE = 18, SPLASH = .3;
145 let P = fresh();
146 const G = { time: 0, acc: -LEAD, bx: SPOUT_X[P.at], splashes: [], noteUntil: 0 };
147 const endLine = () => `${P.line} · tap or press a key to play again`;
148
149 function renderHud() {
150 setText('time', String(P.length - P.time));
151 setText('barrel', String(P.barrel));
152 setText('puddle', String(P.puddle));
153 setText('score', String(P.score));
154 setText('barrelOf', `of ${P.capacity} in the barrel`);
155 setText('puddleOf', `of ${P.limit} in the puddle`);
156 }
157 // events (and the end line) go to the live region; the per-tick line is plain text, so a screen reader is not read to twice a second
158 function note(text) { setText('status', text); G.noteUntil = G.time + 1.6; }
159 const barrelPoint = () => { const p = project(G.bx, BARREL_Y, 1); return [p.sx, p.sy]; };
160 const spoutPoint = i => { const p = project(SPOUT_X[i], DROP_Y, 1.2); return [p.sx, p.sy]; };
161
162 /* ---------- drawing ---------- */
163 function fillEllipse(cx, cy, rx, ry, color) {
164 const y0 = Math.floor(cy - ry), y1 = Math.ceil(cy + ry);
165 for (let iy = y0; iy <= y1; iy++) {
166 const k = 1 - ((iy + .5 - cy) / ry) ** 2;
167 if (k < 0) continue;
168 const half = rx * Math.sqrt(k);
169 for (let ix = Math.floor(cx - half); ix <= Math.ceil(cx + half); ix++) {
170 if (ix >= 0 && iy >= 0 && ix < W && iy < H && Math.abs(ix + .5 - cx) <= half) pix[iy * W + ix] = color;
171 }
172 }
173 }
174 function drawClouds(t) {
175 for (const [i, cz] of [8.2, 9, 8.6].entries()) {
176 const x = ((i * 9.5 + t * .5 + 14) % 30) - 15, y = -6.5 + i * .9;
177 for (const [dx, dy, r] of [[0, 0, 1.1], [1.2, .2, .9], [-1.1, -.1, .8], [.3, .5, .8]]) sphere(x + dx, y + dy, cz, r, CLOUD);
178 }
179 }
180 function drawBarrel() {
181 const add = (a, b, r, c) => dynamicAdd(a, b, r, r, () => c);
182 add([G.bx, BARREL_Y, BARREL_R], [G.bx, BARREL_Y, 1.2], BARREL_R, STAVE);
183 for (const z of [.45, 1.05]) add([G.bx, BARREL_Y, z], [G.bx, BARREL_Y, z + .02], BARREL_R + .015, HOOP);
184 }
185 // the barrel's open top shows the water; a full barrel wears its lid
186 function drawBarrelTop() {
187 const p = project(G.bx, BARREL_Y, 1.78), rx = BARREL_R * S * .86, ry = rx * SIN;
188 fillEllipse(p.sx, p.sy, rx + 1, ry + 1, INK_PIX);
189 fillEllipse(p.sx, p.sy, rx, ry, DARK_PIX);
190 const level = P.barrel / P.capacity;
191 if (level > 0) fillEllipse(p.sx, p.sy, rx * (.3 + .7 * level), ry * (.3 + .7 * level), WATER_PIX);
192 if (P.barrel >= P.capacity) {
193 const lid = project(G.bx, BARREL_Y, 2.15);
194 fillEllipse(lid.sx, lid.sy, rx + 3, ry + 3, INK_PIX);
195 fillEllipse(lid.sx, lid.sy, rx + 2, ry + 2, WOOD_PIX);
196 fillEllipse(lid.sx, lid.sy - 1, 2.5, 1.5, INK_PIX);
197 }
198 }
199 // the puddle on the yard, and the line it must not reach
200 const puddleRadius = () => PUDDLE_MIN + (PUDDLE_LIMIT_R - PUDDLE_MIN) * P.puddle / P.limit;
201 function drawPuddle() {
202 if (!P.puddle) return;
203 const r = puddleRadius(), ramp = rampOf(PUDDLE);
204 const lo = project(PUDDLE_AT.x - r, PUDDLE_AT.y - r, 0), hi = project(PUDDLE_AT.x + r, PUDDLE_AT.y + r, 0);
205 const x0 = Math.max(0, Math.floor(lo.sx - r * S)), x1 = Math.min(W - 1, Math.ceil(lo.sx + r * S));
206 const y0 = Math.max(0, Math.floor(lo.sy)), y1 = Math.min(H - 1, Math.ceil(hi.sy));
207 for (let iy = y0; iy <= y1; iy++) for (let ix = x0; ix <= x1; ix++) {
208 const i = iy * W + ix;
209 if (!ground[i] || zb[i] !== bakedZ[i]) continue;
210 const g = unproject(ix + .5, iy + .5), d = Math.hypot(g.x - PUDDLE_AT.x, (g.y - PUDDLE_AT.y) * 1.15);
211 if (d > r - (hash(ix, iy) - .5) * .25) continue;
212 pix[i] = ramp[bayerAt(ix, iy) > .5 ? 3 : 2];
213 }
214 }
215 function drawLimit() {
216 for (let k = 0; k < 96; k++) {
217 if (k % 3 === 2) continue;
218 const a = k / 96 * Math.PI * 2, p = project(PUDDLE_AT.x + Math.cos(a) * PUDDLE_LIMIT_R, PUDDLE_AT.y + Math.sin(a) * PUDDLE_LIMIT_R / 1.15, 0);
219 drawDots([[p.sx, p.sy]], LIMIT_PIX);
220 }
221 }
222 function drawDrop() {
223 if (P.status !== 'playing' || G.acc < 0) return;
224 const spout = P.schedule[P.time];
225 if (spout === undefined || spout < 0) return;
226 const k = Math.min(1, G.acc / TICK), floor = spout === P.at && P.barrel < P.capacity ? 1.8 : 0.1;
227 const z = DROP_TOP - (DROP_TOP - floor) * k * k;
228 sphere(SPOUT_X[spout], DROP_Y, z, .13, DROP, 'gloss');
229 sphere(SPOUT_X[spout], DROP_Y, z + .25, .08, DROP, 'gloss');
230 }
231 function drawSplashes() {
232 for (const s of G.splashes) {
233 const k = (G.time - s.at) / SPLASH, r = .3 + k * .9;
234 for (let n = 0; n < 8; n++) {
235 const a = n / 8 * Math.PI * 2, p = project(s.x + Math.cos(a) * r, DROP_Y + Math.sin(a) * r, .05 + (1 - Math.abs(k * 2 - 1)) * .3);
236 drawDots([[p.sx, p.sy]], SPLASH_PIX);
237 }
238 }
239 }
240 function draw() {
241 pix.set(bakedPix);
242 zb.set(bakedZ);
243 pendingShadows.length = 0;
244 drawClouds(STILL ? 0 : Math.floor(G.time * WIND_FPS) / WIND_FPS);
245 drawBarrel();
246 drawDrop();
247 flushShadows();
248 applyShadows(bakedZ);
249 drawPuddle();
250 shadeEdges();
251 drawLimit();
252 drawBarrelTop();
253 drawSplashes();
254 ctx.putImageData(image, 0, 0);
255 }
256
257 /* ---------- game ---------- */
258 function cue(event) {
259 if (event === 'caught') sound(520 + P.barrel * 90, .09, 'triangle');
260 else if (event === 'missed') sound(130, .12, 'square');
261 else if (event === 'bonus') sound(740, .2, 'sine');
262 else if (event === 'won') sound(780, .5, 'sine');
263 else if (event === 'lost') sound(110, .5, 'sawtooth');
264 }
265 function advance() {
266 const spout = P.schedule[P.time], r = RainBarrel.tick(P);
267 if (!r.ok) return;
268 P = r.state;
269 if (r.event === 'missed' && spout >= 0) G.splashes.push({ x: SPOUT_X[spout], at: G.time });
270 cue(r.event);
271 renderHud();
272 }
273 function slide(spout) {
274 ensureAudio();
275 const r = RainBarrel.move(P, spout);
276 if (r.ok) P = r.state;
277 }
278 function tip() {
279 ensureAudio();
280 const r = RainBarrel.empty(P);
281 if (!r.ok) { if (r.why === 'already-empty') note('the barrel is already empty'); return; }
282 P = r.state; G.acc = 0;
283 cue(r.event);
284 note(r.event === 'bonus' ? `Full barrel tipped out: +${RainBarrel.FULL_BONUS}` : 'Barrel tipped out');
285 renderHud();
286 }
287 function restart() {
288 P = fresh(); G.bx = SPOUT_X[P.at]; G.acc = -LEAD; G.splashes.length = 0;
289 note('Rain is coming');
290 renderHud();
291 }
292 function update(dt) {
293 G.time += dt;
294 G.bx += (SPOUT_X[P.at] - G.bx) * Math.min(1, dt * SLIDE);
295 G.splashes = G.splashes.filter(s => G.time - s.at < SPLASH);
296 if (P.status === 'playing') {
297 G.acc += dt;
298 while (G.acc >= TICK && P.status === 'playing') { G.acc -= TICK; advance(); }
299 }
300 renderHud();
301 if (P.status === 'over') { setText('line', ''); setText('status', endLine()); }
302 else { setText('line', P.line); if (G.time >= G.noteUntil) setText('status', ''); }
303 }
304
305 /* ---------- input ---------- */
306 const point = e => { const r = canvas.getBoundingClientRect(); return [(e.clientX - r.left) / r.width * W, (e.clientY - r.top) / r.height * H]; };
307 const onBarrel = (px, py) => { const [bx, by] = barrelPoint(); return Math.abs(px - bx) <= 15 && py >= by - 24 && py <= by + 14; };
308 // the spout whose falling line is nearest a canvas point, or -1 when none is near enough
309 function nearestSpout(px, py, reach = 36) {
310 let best = -1, gap = reach;
311 SPOUT_X.forEach((x, i) => {
312 const a = project(x, DROP_Y, DROP_TOP), b = project(x, DROP_Y, 0);
313 const t = Math.max(0, Math.min(1, ((px - a.sx) * (b.sx - a.sx) + (py - a.sy) * (b.sy - a.sy)) / ((b.sx - a.sx) ** 2 + (b.sy - a.sy) ** 2)));
314 const d = Math.hypot(px - (a.sx + (b.sx - a.sx) * t), py - (a.sy + (b.sy - a.sy) * t));
315 if (d < gap) { gap = d; best = i; }
316 });
317 return best;
318 }
319 canvas.addEventListener('pointerdown', e => {
320 canvas.focus({ preventScroll: true });
321 ensureAudio();
322 if (P.status === 'over') { restart(); return; }
323 const [px, py] = point(e);
324 if (onBarrel(px, py)) { tip(); return; }
325 const spout = nearestSpout(px, py);
326 if (spout >= 0) slide(spout); else note('tap a spout, or the barrel to empty it');
327 });
328 canvas.addEventListener('keydown', e => {
329 const step = e.key === 'ArrowLeft' ? -1 : e.key === 'ArrowRight' ? 1 : 0, pour = e.key === ' ' || e.key === 'Enter' || e.key === 'ArrowDown';
330 if (!step && !pour) return;
331 e.preventDefault();
332 if (P.status === 'over') { if (!e.repeat) restart(); return; }
333 if (step) slide(Math.max(0, Math.min(P.spouts - 1, P.at + step)));
334 else if (!e.repeat) tip();
335 });
336
337 /* ---------- sound ---------- */
338 let audio = null, muted = false;
339 function ensureAudio() {
340 if (audio) { if (audio.state === 'suspended') audio.resume(); return; }
341 const AC = window.AudioContext || window.webkitAudioContext;
342 if (AC) audio = new AC();
343 }
344 function sound(freq, life, type, delay = 0) {
345 if (!audio || muted) return;
346 const now = audio.currentTime + delay, gain = audio.createGain(), osc = audio.createOscillator();
347 osc.type = type;
348 osc.frequency.setValueAtTime(freq, now);
349 gain.gain.setValueAtTime(.0001, now);
350 gain.gain.exponentialRampToValueAtTime(.07, now + .01);
351 gain.gain.exponentialRampToValueAtTime(.0005, now + life);
352 osc.connect(gain).connect(audio.destination);
353 osc.start(now); osc.stop(now + life + .02);
354 }
355 const muteButton = document.getElementById('mute');
356 muteButton.addEventListener('click', () => {
357 muted = !muted;
358 muteButton.textContent = muted ? 'sound off' : 'sound on';
359 muteButton.setAttribute('aria-pressed', String(muted));
360 });
361
362 /* ---------- fit and boot ---------- */
363 addEventListener('resize', fit);
364 fit();
365 bake();
366 note('Rain is coming: slide the barrel under each spout');
367 renderHud();
368 canvas.focus({ preventScroll: true });
369 let last = performance.now();
370 function frame(now) {
371 update(Math.min(.04, (now - last) / 1000));
372 last = now;
373 draw();
374 requestAnimationFrame(frame);
375 }
376 requestAnimationFrame(frame);
377 </script>
378 </body>
379 </html>
rounds.mjs +8
@@ -190,6 +190,14 @@ export const ROUNDS = {
190190 if (g.read('G.phase') === 'ask') g.tap(...g.read('perchPoint(P.asking.perch)'));
191191 else g.run(.2);
192192 } },
193 // slide the barrel under the spout about to drip, and tip it out as soon as it is full
194 'rain-barrel': { over: /play again/, outcome: /Yard dry: \d+ points/, beat: g => {
195 const s = g.read('P'), next = s.schedule[s.time];
196 if (s.status !== 'playing') g.run(.5);
197 else if (s.barrel >= s.capacity) g.tap(...g.read('barrelPoint()'));
198 else if (next >= 0 && next !== s.at) g.tap(...g.read(`spoutPoint(${next})`));
199 else g.run(.1);
200 } },
193201 // walk the one path to the fountain by the arrow keys, maze after maze; once five are solved, wait out the bell
194202 'hedge-maze': { over: /play again/, outcome: /\d+ mazes solved, best \d+\. You win!/, beat: g => {
195203 const s = g.read('P');
serve.test.mjs +7
@@ -579,6 +579,13 @@ test('Bird Watch and its rules script are served without a track', async () => {
579579 expect((await fetch(base + '/bird-watch/watch.js')).status).toBe(200);
580580 });
581581
582 test('Rain Barrel and its rules script are served without a track', async () => {
583 const page = await fetch(base + '/rain-barrel/');
584 expect(page.status).toBe(200);
585 expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8');
586 expect((await fetch(base + '/rain-barrel/gutter.js')).status).toBe(200);
587 });
588
582589 test('Patchwork Quilt and its rules script are served without a track', async () => {
583590 const page = await fetch(base + '/quilt/');
584591 expect(page.status).toBe(200);
shell.js +1
@@ -61,6 +61,7 @@ window.PixelPlays = (() => {
6161 { id: 'hedge-maze', title: 'Hedge Maze', blurb: 'Find the way through the hedges to the fountain before the gardener rings the bell', kind: 'Puzzle', input: 'Keys', accent: '#3d6e4f', music: false, forged: true },
6262 { id: 'bird-watch', title: 'Bird Watch', blurb: 'Remember where each bird perched', kind: 'Memory', input: 'Tap', accent: '#6b8f3a', music: false, forged: true },
6363 { id: 'bunting', title: 'Bunting', blurb: 'Hang the flags for the fete so no two neighbours match', kind: 'Strategy', input: 'Tap', accent: '#3d7f6e', music: false, forged: true },
64 { id: 'rain-barrel', title: 'Rain Barrel', blurb: 'Slide the barrel under each spout before the yard floods', kind: 'Catching', input: 'Tap', accent: '#5f86a3', music: false, forged: true },
6465 { id: 'quilt', title: 'Patchwork Quilt', blurb: 'Turn and swap the patches until every stitch lines up', kind: 'Puzzle', input: 'Tap', accent: '#b5656b', music: false, forged: true },
6566 ];
6667 const MUSIC_VOLUME = .4;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs