Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Add Hoopla Stall: the playable page and its place in the catalogue, on the rules in `hoopla/hoop.js` #155
Check · Review · Land · Live done — Landed and live in production.
vesper/pixel-plays:vesper/135-add-hoopla-stall-the-playable-page-and-i → main 2 commits fork
8 files
changed +395
−2
README.md +3 −2
| @@ -46,6 +46,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am | ||
| 46 | 46 | | [](firefly-jar/) | A 90-second summer night in a back garden: tap a firefly while it glows to catch it into the jar (+1, golden +3), a dim one is scared off and breaks the streak, shoo the moths before they reach the lantern; the third moth ends the night (forged by the crew on the engine and shell above, not by the original creators) | Tap; Tab or arrows + space | |
| 47 | 47 | | [](egg-basket/) | A red henhouse with a sloping tin roof and three hens on the ridge: they lay brown eggs (1 point) and rare golden ones (3) that roll down one of four roof lanes and drop off the eave; slide the basket under each before it reaches the ground, where it cracks; rolling speeds up every ten eggs laid (never so fast that the basket cannot cross three lanes in time), three cracks end the round and 25 or more wins (forged by the crew on the engine and shell above, not by the original creators) | Drag the basket; Left and Right arrows move one lane | |
| 48 | 48 | | [](coconut-shy/) | A village-fete stall with bunting and a stallholder, five coconuts on wooden posts: drag back and release to throw (or Left and Right to aim, hold Space for power, release to throw); a ball inside the square window knocks a coconut off its post, two glancing hits knock it too, and clearing all five wins a bonus ball; five balls a round, three rounds with the posts moved further back each time, and nine down or more of the game wins (forged by the crew on the engine and shell above, not by the original creators; rules in `coconut-shy/shy.js`) | Drag back and release; Left and Right to aim, hold Space | |
| 49 | | [](hoopla/) | A fairground stall with nine prize blocks on a three-step table under a striped awning and eight wooden rings: drag back and release to toss (or Left and Right to aim, hold Space to build power, release to toss); a ring that settles over a block scores its row, 1, 2 or 3 with further back worth more, and takes the prize; a ring that touches a block's edge bounces off, and 12 points or more wins (forged by the crew on the engine and shell above, not by the original creators) | Drag back and release; arrows + space | | |
| 49 | 50 | | [](bowls-green/) | A flat lawn bowls green floating on white, a white jack at the far end, a mat at the near end, two rival woods already resting near the jack and a low hedge behind: drag back from the mat and release to roll (or Left and Right to set the line, hold Space to build weight, release to roll); weight sets how far the wood runs (quadratic in weight, against a pace that is one seeded constant per game) and each wood bends towards its bias side as it slows, so aiming straight at the jack misses; a wood off the back of the green (or into the ditch at the side) is dead; one end of four woods, and one or more resting nearer the jack than the nearest rival wood wins (forged by the crew on the engine and shell above, not by the original creators; rules in `bowls-green/bowls.js`) | Drag back and release; Left and Right to aim, hold Space | |
| 50 | 51 | | [](dinghy-race/) | A bay with a square course of three buoys and back over a start line, the wind from the south-east and shifting a little at each buoy: the boat steers itself buoy to buoy and you trim the sail; it drives best at half the angle between boat and wind, and loses speed quadratically as the trim drifts from that, so every leg and every wind shift asks for a new setting; two seeded rivals sail at a steady pace, first or second place is a win (forged by the crew on the engine and shell above, not by the original creators; rules in `dinghy-race/dinghy.js`) | Drag left and right along the sheet; Up and Down arrows trim in and out | |
| 51 | 52 | | [](seed-packets/) | A potting-shed bench with sixteen face-down seed packets in a 4x4 grid, a watering can and a clock on the wall: tap a packet to turn it face up to show its flower, then a second; a matching pair stays face up and a mismatch turns both back after 0.8 s (taps in that beat are ignored); the layout is a seeded shuffle of eight pairs and the gardener returns after 16 turns (a turn is two packets), so you can afford eight mismatches; the end shows pairs found and turns used, and the best is the fewest turns in a win (forged by the crew on the engine and shell above, not by the original creators) | Tap; arrows + space | |
| @@ -72,7 +73,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is | ||
| 72 | 73 | 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. |
| 73 | 74 | |
| 74 | 75 | ## Add a game |
| 75 | Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules })`, set `window.PP_SCENE`, load `../engine.js`, then add the game to `GAMES` in `shell.js` with a one-line `blurb`; the home page lists every `GAMES` entry as a card with its `kind`, `input` and `accent`, searchable and filterable by kind (a static fallback list for no-JS is kept in sync by `serve.test.mjs`, so add the matching `<li>` to `index.html` too, with the same `data-kind`, `data-input`, `--accent` and tags line). Then run `bun scripts/og.mjs` to make its share card and tags. The page needs a `#mute` button. Put its background track at `<id>/<id>.mp3`, or set `music: false` on its `GAMES` entry when it has none (Stone Skip, Kite Hill, Paper Route, Harbour Crane, Pizza Toss, Sled Run, Pottery Wheel, Row Home, Orchard, Lighthouse, Market Scale, Window Washer, Domino Run, Campfire, Beekeeper, Bread Oven, Ice Fishing, Tightrope, Tram Line, Archery, Bell Tower, Espresso Bar, Goalkeeper, Wood Split, Signal Box, Soapbox Derby, Sheepdog, Firefly Jar, Hot Air Balloon, Cloakroom, Go-Kart Fete, Empire Age, Egg Basket, Dinghy Race, Coconut Shy, Bowls Green and Seed Packets 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`. | |
| 76 | Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules })`, set `window.PP_SCENE`, load `../engine.js`, then add the game to `GAMES` in `shell.js` with a one-line `blurb`; the home page lists every `GAMES` entry as a card with its `kind`, `input` and `accent`, searchable and filterable by kind (a static fallback list for no-JS is kept in sync by `serve.test.mjs`, so add the matching `<li>` to `index.html` too, with the same `data-kind`, `data-input`, `--accent` and tags line). Then run `bun scripts/og.mjs` to make its share card and tags. The page needs a `#mute` button. Put its background track at `<id>/<id>.mp3`, or set `music: false` on its `GAMES` entry when it has none (Stone Skip, Kite Hill, Paper Route, Harbour Crane, Pizza Toss, Sled Run, Pottery Wheel, Row Home, Orchard, Lighthouse, Market Scale, Window Washer, Domino Run, Campfire, Beekeeper, Bread Oven, Ice Fishing, Tightrope, Tram Line, Archery, Bell Tower, Espresso Bar, Goalkeeper, Wood Split, Signal Box, Soapbox Derby, Sheepdog, Firefly Jar, Hot Air Balloon, Cloakroom, Go-Kart Fete, Empire Age, Egg Basket, Dinghy Race, Coconut Shy, Bowls Green, Seed Packets and Hoopla Stall 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`. | |
| 76 | 77 | |
| 77 | 78 | - `town.js` is the town's layout, pure data with no drawing: `window.PixelTown.layout(GAMES)` gives one isometric building per game (plot, screen position under the fixed 30-degree camera, accent, id) with trees in the spare plots, and `pick(town, x, y, filter)` gives the id of the front-most building under a screen point, or null. Nothing loads it yet; the drawing and the page are the second half of #99. |
| 78 | 79 | - `shell.js` provides the game menu, the Rules popup, the credits and the background music. The menu lists the games grouped under their kind (the not-yet-made ones last, under Soon) and scrolls within the screen; type in its find box to narrow it by a word of the title, kind, input or blurb (keys typed there never reach the game), and press Escape to close it. |
| @@ -89,7 +90,7 @@ Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules | ||
| 89 | 90 | - Depth-buffer edges: darker where an object sits in front, a warm rim on upper-left edges. |
| 90 | 91 | - Large flat surfaces use closely spaced tones; wide steps make the dither read as a checkerboard. |
| 91 | 92 | - Characters stay sharp: flat bands with no dither, a dark silhouette on their own pixels, patterns at least 3px wide. |
| 92 | - Ambient motion only where the scene names it: grass and leaves sway in whole pixels at 8 fps, Tram Line's waiting passengers shift their weight, Espresso Bar's machine steam and awning fringe move, Sheepdog's crow on the wall shifts and dips its head, Hot Air Balloon's windsock and cloud wisps drift, Cloakroom's coats sway and the light under its door moves, Go-Kart Fete's chequered flags flutter and its spectators wave, Egg Basket's hens peck and the straw in its basket stirs (its rolling eggs are play, not ambience, and still move), and Dinghy Race's water ripples come and go and its start-line flags flutter (the boats are play, and still sail), and Coconut Shy's bunting flutters and its stallholder shifts and waves (the thrown ball and wobbling coconuts are play, and still move), and Bowls Green's hedge leaves stir and a cloud shadow drifts across its green (the rolling woods are play, and still move), and Seed Packets' wall clock ticks its second hand and its watering can drips; all of it stops under `prefers-reduced-motion`. | |
| 93 | - Ambient motion only where the scene names it: grass and leaves sway in whole pixels at 8 fps, Tram Line's waiting passengers shift their weight, Espresso Bar's machine steam and awning fringe move, Sheepdog's crow on the wall shifts and dips its head, Hot Air Balloon's windsock and cloud wisps drift, Cloakroom's coats sway and the light under its door moves, Go-Kart Fete's chequered flags flutter and its spectators wave, Egg Basket's hens peck and the straw in its basket stirs (its rolling eggs are play, not ambience, and still move), and Dinghy Race's water ripples come and go and its start-line flags flutter (the boats are play, and still sail), and Coconut Shy's bunting flutters and its stallholder shifts and waves (the thrown ball and wobbling coconuts are play, and still move), and Bowls Green's hedge leaves stir and a cloud shadow drifts across its green (the rolling woods are play, and still move), and Seed Packets' wall clock ticks its second hand and its watering can drips, and Hoopla Stall's bunting flutters (the tossed ring is play, and still moves); all of it stops under `prefers-reduced-motion`. | |
| 93 | 94 | |
| 94 | 95 | ## Empire Age |
| 95 | 96 |
hoopla/index.html added +366
| @@ -0,0 +1,366 @@ | ||
| 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>Hoopla Stall</title> | |
| 7 | <!-- og:begin --> | |
| 8 | <meta name="description" content="Drag and release to toss rings over the prize blocks, eight rings a round"> | |
| 9 | <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/hoopla/"> | |
| 10 | <meta property="og:type" content="website"> | |
| 11 | <meta property="og:site_name" content="Pixel Plays"> | |
| 12 | <meta property="og:title" content="Hoopla Stall"> | |
| 13 | <meta property="og:description" content="Drag and release to toss rings over the prize blocks, eight rings a round"> | |
| 14 | <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/hoopla/"> | |
| 15 | <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/hoopla.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="Hoopla Stall: the opening scene of the game"> | |
| 20 | <meta name="twitter:card" content="summary_large_image"> | |
| 21 | <!-- og:end --> | |
| 22 | <style> | |
| 23 | :root { : #1c1b19; : #6b675f; : #fff; : #b0533a; } | |
| 24 | * { box-sizing: border-box; } | |
| 25 | html, body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; 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; } | |
| 29 | canvas:focus-visible { outline: 2px solid var(); outline-offset: -2px; } | |
| 30 | .hud { position: fixed; left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); display: flex; justify-content: space-between; gap: 16px; pointer-events: none; } | |
| 31 | #scores { position: fixed; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); display: grid; gap: 2px; pointer-events: none; } | |
| 32 | #bottom { bottom: max(14px, env(safe-area-inset-bottom)); align-items: flex-end; } | |
| 33 | .row { display: flex; align-items: center; gap: 8px; color: var(); } | |
| 34 | .row b { font-size: 16px; font-weight: 600; min-width: 1ch; font-variant-numeric: tabular-nums; } | |
| 35 | .row span { color: var(); } | |
| 36 | #power { width: 72px; height: 4px; margin-top: 4px; background: rgba(176, 83, 58, .16); } | |
| 37 | #power i { display: block; height: 100%; background: var(); transform-origin: left; transform: scaleX(0); } | |
| 38 | #line { color: var(); min-height: 1.35em; } | |
| 39 | button { pointer-events: auto; font: inherit; color: var(); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; } | |
| 40 | button:hover, button:focus-visible { color: var(); } | |
| 41 | button:focus-visible { outline: 2px solid var(); } | |
| 42 | noscript p { position: fixed; z-index: 3; inset: 40px 0 auto; margin: 0; padding: 12px 16px; background: var(); } | |
| 43 | </style> | |
| 44 | </head> | |
| 45 | <body> | |
| 46 | <noscript> | |
| 47 | <p>Hoopla Stall needs JavaScript. It is a fairground hoopla stall: toss eight wooden rings over nine prize blocks on a stepped table, further back is worth more, and 12 points or more wins.</p> | |
| 48 | </noscript> | |
| 49 | <div id="stage"><canvas id="c" tabindex="0" aria-label="A hoopla stall at a fairground: nine prize blocks on a three-step table under a striped awning with bunting. Drag back on the canvas and release to toss a ring, or press Left and Right to aim, hold Space to build power and release it to toss. Eight rings; a ring that settles over a block scores its row, one, two or three, and 12 or more wins."></canvas></div> | |
| 50 | <div id="scores"> | |
| 51 | <div class="row"><b id="score">0</b><span>points, 12 wins</span></div> | |
| 52 | <div class="row"><b id="rings">8</b><span>rings left</span><span id="aimed"></span></div> | |
| 53 | <div class="row"><b id="best">0</b><span>best</span></div> | |
| 54 | <div id="power"><i></i></div> | |
| 55 | </div> | |
| 56 | <div class="hud" id="bottom"> | |
| 57 | <div id="line"><span id="status" role="status" aria-live="polite"></span></div> | |
| 58 | <button id="mute" type="button" aria-pressed="false">sound on</button> | |
| 59 | </div> | |
| 60 | <script src="../shell.js"></script> | |
| 61 | <script> | |
| 62 | PixelPlays.mount({ | |
| 63 | id: 'hoopla', | |
| 64 | rules: [ | |
| 65 | 'Drag back and release to toss, or Left and Right to aim and hold Space for power.', | |
| 66 | 'Eight rings. A ring that settles over a block scores its row: 1, 2 or 3, further back is worth more.', | |
| 67 | 'A prize block is taken once won. 12 points or more wins.', | |
| 68 | ], | |
| 69 | }); | |
| 70 | </script> | |
| 71 | <script>window.PP_SCENE = { originY: 6, shadowX: 1.3, shadowY: -.12 };</script> | |
| 72 | <script src="../engine.js"></script> | |
| 73 | <script src="hoop.js"></script> | |
| 74 | <script> | |
| 75 | 'use strict'; | |
| 76 | ||
| 77 | const BEST_KEY = 'pixel-plays-hoopla-best'; | |
| 78 | const POWER_TIME = 2, PULL = 90, AIM_STEP = 1; // seconds to full power; canvas pixels to full power; degrees per key press | |
| 79 | const OFF = 3.5, BACK = 6.7, HALF = 2.6, BUNT_H = 2.7; // the stall line sits at world y = OFF; a distance d is world y = OFF - d | |
| 80 | const WOOD = [198, 160, 112], WOOD_DARK = [104, 70, 46], CREAM = [240, 228, 200], AWN_RED = [196, 62, 52], PLANK = [206, 168, 112]; | |
| 81 | const COUNTER = [172, 120, 72], CHALK = [250, 246, 236], RING = [226, 186, 80]; | |
| 82 | const PRIZE = [[66, 120, 176], [240, 196, 60], [196, 62, 52]]; | |
| 83 | const FLAGS = [[214, 70, 58], [240, 196, 60], [66, 120, 176], [240, 232, 212]]; | |
| 84 | const THROWER = { shirt: [74, 112, 172], stripe: [60, 96, 154], legs: [30, 38, 56], hair: [40, 28, 24], skin: [200, 142, 108] }; | |
| 85 | const earth = rampOf([186, 156, 112]); | |
| 86 | const wy = d => OFF - d; // a distance from the stall line, in world y | |
| 87 | const tierTop = row => .1 + row * Hoop.STEP_HEIGHT; // the table's surface under a row | |
| 88 | const KEY_AIM = { ArrowLeft: -1, ArrowDown: -1, a: -1, A: -1, s: -1, ArrowRight: 1, ArrowUp: 1, d: 1, D: 1, w: 1 }; | |
| 89 | ||
| 90 | /* ---------- state: what the page itself keeps; every rule is in Hoop ---------- */ | |
| 91 | const best0 = (() => { try { return Number(localStorage.getItem(BEST_KEY)) || 0; } catch (e) { return 0; } })(); | |
| 92 | let R = Hoop.newGame(best0, (Math.random() * 1e9) | 0); | |
| 93 | const G = { time: 0, status: '', aim: 0, held: 0, charging: false, pull: null, drag: null, flight: null, pending: null, settle: 9, rings: [] }; | |
| 94 | const nodes = {}; | |
| 95 | for (const id of ['score', 'rings', 'best', 'status', 'aimed']) nodes[id] = document.getElementById(id); | |
| 96 | nodes.power = document.querySelector('#power i'); | |
| 97 | const powerNow = () => G.pull ? G.pull.power : G.charging ? clamp(G.held / POWER_TIME, 0, 1) : 0; | |
| 98 | function renderHud() { | |
| 99 | nodes.score.textContent = R.score; | |
| 100 | nodes.rings.textContent = R.ringsLeft; | |
| 101 | nodes.best.textContent = R.best; | |
| 102 | nodes.aimed.textContent = 'aim ' + (G.aim > 0 ? 'right ' : G.aim < 0 ? 'left ' : '') + Math.abs(G.aim) + '°'; | |
| 103 | } | |
| 104 | function setStatus(text) { | |
| 105 | if (text === G.status) return; | |
| 106 | G.status = text; | |
| 107 | nodes.status.textContent = text; | |
| 108 | } | |
| 109 | const tail = () => R.over ? ' · tap or press space to play again' : ''; | |
| 110 | const HINT = 'drag back and release, or Left and Right, hold space, release'; | |
| 111 | ||
| 112 | /* ---------- baked scene: the grass, the stall, the table ---------- */ | |
| 113 | function groundColor(x, y, ix, iy) { | |
| 114 | const edge = Math.pow(Math.pow(Math.abs(x) / 5.4, 6) + Math.pow(Math.abs(y - .1) / 4.9, 6), 1 / 6); | |
| 115 | const rough = edge + (noise(x * 1.1, y * 1.1) - .5) * .12; | |
| 116 | if (rough > 1.04) return 0; | |
| 117 | if (rough > .93 && hash(ix, iy) < (rough - .93) / .11) return 0; | |
| 118 | if (Math.abs(y - OFF) < .07 && Math.abs(x) < 1.4) return rgb(...CHALK); | |
| 119 | if (y > OFF - .4 && Math.abs(x) < 1.6) return earth[clamp(Math.floor(2.4 + (noise(x * 2, y * 2) - .5) * 1.3 + (bayerAt(ix, iy) - .5) * .5), 1, 3)]; | |
| 120 | const g = GRASS[clamp(Math.floor(noise(x * .6, y * .6) * 2.4 + hash(ix, iy) * .8 + .5), 0, 3)]; | |
| 121 | return rgb(g[0] * (.92 + hash(ix, iy) * .12), g[1] * (.92 + hash(ix, iy) * .12), g[2] * (.92 + hash(ix, iy) * .12)); | |
| 122 | } | |
| 123 | function stall() { | |
| 124 | const yb = wy(BACK); | |
| 125 | box(-HALF, yb - .25, 0, HALF, yb + .05, 2.5, PLANK, 3); // the back boards | |
| 126 | for (const x of [-HALF, HALF]) box(x - .12, yb, 0, x + .12, yb + .24, 3.0, WOOD, 7); // the posts | |
| 127 | for (let x = -HALF, k = 0; x < HALF - .01; x += 1, k++) { // the striped awning and its valance | |
| 128 | const c = k & 1 ? CREAM : AWN_RED; | |
| 129 | box(x, yb - .1, 2.5, Math.min(HALF, x + 1), yb + 1.4, 2.75, c, k); | |
| 130 | box(x, yb + 1.4, 2.2, Math.min(HALF, x + 1), yb + 1.52, 2.75, c, k + 11); | |
| 131 | } | |
| 132 | for (let x = -HALF; x <= HALF; x += .5) { castShadow(x, yb, 1.5, .45, 1, 0); castShadow(x, yb + 1.4, 2.4, .5, 1, 0); } | |
| 133 | for (let r = 0; r < Hoop.ROWS; r++) { // the stepped table, one tier per row | |
| 134 | const yc = wy(3 + r * .8); | |
| 135 | box(-1.15, yc - .4, 0, 1.15, yc + .4, tierTop(r) - .02, r & 1 ? COUNTER : WOOD, 5 + r); | |
| 136 | for (let x = -1.15; x <= 1.15; x += .5) castShadow(x, yc, tierTop(r), .35, 1, 0); | |
| 137 | } | |
| 138 | for (const x of [-HALF, HALF]) { box(x - .1, wy(5.2) - .1, 0, x + .1, wy(5.2) + .1, BUNT_H + .3, WOOD_DARK, 9); for (let z = 0; z < 3; z += .5) castShadow(x, wy(5.2), z, .2, 1, 0); } // the bunting poles | |
| 139 | } | |
| 140 | function bake() { | |
| 141 | ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); | |
| 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); | |
| 146 | if (!c) continue; | |
| 147 | pix[i] = c; ground[i] = 1; | |
| 148 | zb[i] = (g.x + g.y) / R2 * COS; | |
| 149 | } | |
| 150 | groundZ.set(zb); | |
| 151 | stall(); | |
| 152 | bakeOcclusion(); | |
| 153 | staticShadow.set(shadowMask); | |
| 154 | applyShadows(groundZ); | |
| 155 | bakedPix.set(pix); | |
| 156 | bakedZ.set(zb); | |
| 157 | } | |
| 158 | ||
| 159 | /* ---------- figures ---------- */ | |
| 160 | function bunting() { | |
| 161 | const t = STILL ? 0 : Math.floor(G.time * 8) / 8, n = 18, yb = wy(5.2); | |
| 162 | for (let k = 1; k < n; k++) { | |
| 163 | const f = k / n, x = -HALF + 2 * HALF * f, sag = Math.sin(f * Math.PI) * .5; | |
| 164 | const sway = Math.round(Math.sin(t * 2.2 + k * .9) * 2) * .06; | |
| 165 | sphere(x, yb + sway, BUNT_H + .1 - sag, .06, WOOD_DARK, 'solid'); | |
| 166 | sphere(x, yb + sway, BUNT_H - .1 - sag, .2, FLAGS[k % 4], 'solid'); | |
| 167 | sphere(x, yb + sway * 1.5, BUNT_H - .28 - sag, .11, FLAGS[k % 4], 'solid'); | |
| 168 | } | |
| 169 | } | |
| 170 | function blocks() { | |
| 171 | R.blocks.forEach(b => { | |
| 172 | if (b.gone) return; | |
| 173 | const x = b.x, y = wy(b.z), h = tierTop(b.row); | |
| 174 | box(x - Hoop.BLOCK_RADIUS, y - Hoop.BLOCK_RADIUS, h, x + Hoop.BLOCK_RADIUS, y + Hoop.BLOCK_RADIUS, h + .3, PRIZE[b.row], Math.round(b.x * 10) + b.row); | |
| 175 | castShadow(x, y, h + .3, .12, 1, 0); | |
| 176 | }); | |
| 177 | } | |
| 178 | function ring(x, y, z, shadow) { | |
| 179 | for (let k = 0; k < 10; k++) { | |
| 180 | const a = k / 10 * Math.PI * 2; | |
| 181 | sphere(x + Math.cos(a) * .23, y + Math.sin(a) * .23, z, .045, RING, 'gloss'); | |
| 182 | } | |
| 183 | if (shadow) castShadow(x, y, z, .25, 1, 0); | |
| 184 | } | |
| 185 | function throwerPose() { | |
| 186 | if (G.flight) { const f = clamp(G.flight.t / G.flight.T, 0, 1); return { stance: .24, lean: .2, armR: lerp(2.7, 1.5, f), armL: .5 }; } | |
| 187 | if (G.settle < 1) return { stance: .2, lean: .1, armR: 1.4, armL: .5 }; | |
| 188 | const p = powerNow(); | |
| 189 | return { stance: .22, lean: .05 + p * .25, crouch: p * .2, armR: G.charging || G.pull ? -.5 - p * 1.1 : .4, armL: .5 }; | |
| 190 | } | |
| 191 | function aimDots(hand) { | |
| 192 | const a = G.aim * Math.PI / 180, p = powerNow(), pts = [], len = .8 + p * 3; | |
| 193 | for (let k = 1; k <= 7; k++) { | |
| 194 | const s = len * k / 7 + .5, q = project(hand[0] + Math.sin(a) * s, hand[1] - Math.cos(a) * s, hand[2]); | |
| 195 | pts.push([q.sx, q.sy]); | |
| 196 | } | |
| 197 | drawDots(pts, SIGNAL); | |
| 198 | } | |
| 199 | function flying() { | |
| 200 | const f = G.flight; | |
| 201 | if (!f) return null; | |
| 202 | const u = clamp(f.t / f.T, 0, 1); | |
| 203 | return [lerp(f.from[0], f.x, u), lerp(f.from[1], wy(f.z), u), lerp(1.6, f.h, u) + f.apex * 4 * u * (1 - u)]; | |
| 204 | } | |
| 205 | function draw() { | |
| 206 | pix.set(bakedPix); | |
| 207 | zb.set(bakedZ); | |
| 208 | pendingShadows.length = 0; | |
| 209 | bunting(); | |
| 210 | const hand = figure(0, OFF + .5, -Math.PI / 2, throwerPose(), THROWER, dynamicAdd); | |
| 211 | blocks(); | |
| 212 | for (const r of G.rings) ring(r.x, r.y, r.h, true); | |
| 213 | const air = flying(); | |
| 214 | if (air) ring(...air, false), castShadow(air[0], air[1], air[2], .22, 1, 0); | |
| 215 | flushShadows(); | |
| 216 | applyShadows(bakedZ); | |
| 217 | shadeEdges(); | |
| 218 | if (!G.flight && !R.over) aimDots(hand); | |
| 219 | ctx.putImageData(image, 0, 0); | |
| 220 | } | |
| 221 | ||
| 222 | /* ---------- game: the page turns input into Hoop.toss and shows what the rules answer ---------- */ | |
| 223 | const tierAt = d => { for (let r = 0; r < Hoop.ROWS; r++) if (Math.abs(d - (3 + r * .8)) < .4) return r; return -1; }; | |
| 224 | function release(power, aim) { | |
| 225 | const res = Hoop.toss(R, { aim, power }); | |
| 226 | if (!res.event) return; | |
| 227 | const e = res.event, row = tierAt(e.z); | |
| 228 | G.pending = res; | |
| 229 | G.flight = { t: 0, T: .45 + power * .4, from: [0, OFF - .3, 1.6], x: e.x, z: e.z, h: row < 0 ? .06 : tierTop(row) + .04, apex: .8 + power }; | |
| 230 | G.charging = false; G.held = 0; G.pull = null; G.drag = null; | |
| 231 | setStatus(''); | |
| 232 | sound('throw', power); | |
| 233 | } | |
| 234 | function land() { | |
| 235 | const { state, event } = G.pending, was = R; | |
| 236 | const f = G.flight; | |
| 237 | G.pending = null; G.flight = null; G.settle = 0; | |
| 238 | R = state; | |
| 239 | G.rings.push({ x: event.x, y: wy(event.z), h: f.h }); | |
| 240 | sound(event.type === 'scored' ? 'score' : event.type === 'bounced' ? 'bounce' : 'miss'); | |
| 241 | if (R.over) { | |
| 242 | if (R.best > was.best) try { localStorage.setItem(BEST_KEY, String(R.best)); } catch (err) { /* private window: the best lives for this visit */ } | |
| 243 | sound(R.outcome === 'won' ? 'win' : 'miss'); | |
| 244 | } | |
| 245 | setStatus(R.line + tail()); | |
| 246 | renderHud(); | |
| 247 | } | |
| 248 | function advance() { // a tap after the game: the rules say what comes next | |
| 249 | const next = Hoop.again(R); | |
| 250 | if (!next) return false; | |
| 251 | if (G.settle < .5) return true; | |
| 252 | R = next; G.rings.length = 0; G.aim = 0; | |
| 253 | bake(); | |
| 254 | setStatus(R.line); | |
| 255 | renderHud(); | |
| 256 | return true; | |
| 257 | } | |
| 258 | function update(dt) { | |
| 259 | G.time += dt; | |
| 260 | G.settle += dt; | |
| 261 | if (G.charging) G.held += dt; | |
| 262 | if (G.flight) { G.flight.t += dt; if (G.flight.t >= G.flight.T) land(); } | |
| 263 | nodes.power.style.transform = 'scaleX(' + powerNow() + ')'; | |
| 264 | } | |
| 265 | ||
| 266 | /* ---------- input ---------- */ | |
| 267 | const busy = () => !!G.flight || G.settle < .35; | |
| 268 | // dragging back from the press: the pull's direction on screen, split along the toss direction and across it, is the aim | |
| 269 | const FWD = () => { const a = project(0, OFF, 0), b = project(0, OFF - 1, 0); return [b.sx - a.sx, b.sy - a.sy]; }; | |
| 270 | const SIDE = () => { const a = project(0, OFF, 0), b = project(1, OFF, 0); return [b.sx - a.sx, b.sy - a.sy]; }; | |
| 271 | function pullTo(e) { | |
| 272 | const r = canvas.getBoundingClientRect(), x = (e.clientX - r.left) / (r.width || W) * W, y = (e.clientY - r.top) / (r.height || H) * H; | |
| 273 | const dx = G.drag.x - x, dy = G.drag.y - y, f = FWD(), s = SIDE(), det = f[0] * s[1] - f[1] * s[0] || 1; | |
| 274 | const along = (dx * s[1] - dy * s[0]) / det, across = (f[0] * dy - f[1] * dx) / det; | |
| 275 | const len = Math.hypot(dx, dy); | |
| 276 | if (len > 4) G.aim = clamp(Math.round(Math.atan2(across, Math.max(along, 1e-6)) * 180 / Math.PI), -Hoop.MAX_AIM, Hoop.MAX_AIM); | |
| 277 | G.pull = { power: clamp(len / PULL, 0, 1) }; | |
| 278 | renderHud(); | |
| 279 | } | |
| 280 | canvas.addEventListener('pointerdown', e => { | |
| 281 | ensureAudio(); | |
| 282 | canvas.focus({ preventScroll: true }); | |
| 283 | if (advance() || busy() || R.over) return; | |
| 284 | const r = canvas.getBoundingClientRect(); | |
| 285 | G.drag = { id: e.pointerId, x: (e.clientX - r.left) / (r.width || W) * W, y: (e.clientY - r.top) / (r.height || H) * H }; | |
| 286 | try { canvas.setPointerCapture(e.pointerId); } catch (err) { /* synthetic pointers have nothing to capture */ } | |
| 287 | G.pull = { power: 0 }; | |
| 288 | }); | |
| 289 | canvas.addEventListener('pointermove', e => { if (G.drag && G.drag.id === e.pointerId) pullTo(e); }); | |
| 290 | canvas.addEventListener('pointerup', e => { | |
| 291 | if (!G.drag || G.drag.id !== e.pointerId) return; | |
| 292 | pullTo(e); | |
| 293 | const power = G.pull.power; | |
| 294 | G.drag = null; G.pull = null; | |
| 295 | if (power >= .05) release(power, G.aim); | |
| 296 | }); | |
| 297 | canvas.addEventListener('pointercancel', () => { G.drag = null; G.pull = null; }); | |
| 298 | canvas.addEventListener('keydown', e => { | |
| 299 | const k = KEY_AIM[e.key]; | |
| 300 | if (!k && e.key !== ' ' && e.key !== 'Enter') return; | |
| 301 | e.preventDefault(); | |
| 302 | ensureAudio(); | |
| 303 | if (k) { if (!busy() && !R.over) G.aim = clamp(G.aim + k * AIM_STEP, -Hoop.MAX_AIM, Hoop.MAX_AIM); renderHud(); return; } | |
| 304 | if (e.repeat) return; | |
| 305 | if (advance() || busy() || R.over) return; | |
| 306 | G.charging = true; G.held = 0; G.drag = null; G.pull = null; | |
| 307 | }); | |
| 308 | canvas.addEventListener('keyup', e => { | |
| 309 | if (e.key !== ' ' && e.key !== 'Enter') return; | |
| 310 | if (!G.charging) return; | |
| 311 | const power = clamp(G.held / POWER_TIME, 0, 1); | |
| 312 | G.charging = false; G.held = 0; | |
| 313 | if (power >= .05) release(power, G.aim); | |
| 314 | }); | |
| 315 | canvas.addEventListener('blur', () => { G.charging = false; G.held = 0; G.drag = null; G.pull = null; }); | |
| 316 | ||
| 317 | /* ---------- sound ---------- */ | |
| 318 | let audio = null, muted = false; | |
| 319 | function ensureAudio() { | |
| 320 | if (audio) { if (audio.state === 'suspended') audio.resume(); return; } | |
| 321 | const AC = window.AudioContext || window.webkitAudioContext; | |
| 322 | if (AC) audio = new AC(); | |
| 323 | } | |
| 324 | function sound(kind, n = 0) { | |
| 325 | if (!audio || muted) return; | |
| 326 | const now = audio.currentTime, gain = audio.createGain(), osc = audio.createOscillator(); | |
| 327 | const spec = { | |
| 328 | throw: [200 + n * 300, 480 + n * 400, .16, .05, 'triangle'], | |
| 329 | score: [520, 880, .2, .08, 'triangle'], | |
| 330 | bounce: [300, 160, .12, .07, 'square'], | |
| 331 | miss: [180, 70, .2, .08, 'sine'], | |
| 332 | win: [520, 1040, .3, .07, 'triangle'], | |
| 333 | }[kind]; | |
| 334 | osc.type = spec[4]; | |
| 335 | osc.frequency.setValueAtTime(spec[0], now); | |
| 336 | osc.frequency.exponentialRampToValueAtTime(spec[1], now + spec[2]); | |
| 337 | gain.gain.setValueAtTime(spec[3], now); | |
| 338 | gain.gain.exponentialRampToValueAtTime(.0005, now + spec[2]); | |
| 339 | osc.connect(gain).connect(audio.destination); | |
| 340 | osc.start(now); osc.stop(now + spec[2] + .01); | |
| 341 | } | |
| 342 | const muteButton = document.getElementById('mute'); | |
| 343 | muteButton.addEventListener('click', () => { | |
| 344 | muted = !muted; | |
| 345 | muteButton.textContent = muted ? 'sound off' : 'sound on'; | |
| 346 | muteButton.setAttribute('aria-pressed', String(muted)); | |
| 347 | }); | |
| 348 | ||
| 349 | /* ---------- fit and boot ---------- */ | |
| 350 | addEventListener('resize', fit); | |
| 351 | fit(); | |
| 352 | bake(); | |
| 353 | setStatus(R.line + ' · ' + HINT); | |
| 354 | renderHud(); | |
| 355 | canvas.focus({ preventScroll: true }); | |
| 356 | let last = performance.now(); | |
| 357 | function frame(now) { | |
| 358 | update(Math.min(.04, (now - last) / 1000)); | |
| 359 | last = now; | |
| 360 | draw(); | |
| 361 | requestAnimationFrame(frame); | |
| 362 | } | |
| 363 | requestAnimationFrame(frame); | |
| 364 | </script> | |
| 365 | </body> | |
| 366 | </html> |
index.html +1
| @@ -96,6 +96,7 @@ footer a::after { content: none; } | ||
| 96 | 96 | <li data-kind="Catching" data-input="Tap" style="--accent:#c9b43a"><a href="firefly-jar/">Firefly Jar</a><span>Tap the fireflies into a jar while they glow, a dim one flies off, shoo the moths before they reach the lantern</span><span>Game forged by the crew</span><span class="tags">Catching · Tap</span></li> |
| 97 | 97 | <li data-kind="Catching" data-input="Drag" style="--accent:#d08a2e"><a href="egg-basket/">Egg Basket</a><span>Slide the basket under the eave and catch the eggs before three crack</span><span>Game forged by the crew</span><span class="tags">Catching · Drag</span></li> |
| 98 | 98 | <li data-kind="Throwing" data-input="Drag" style="--accent:#7a4a2a"><a href="coconut-shy/">Coconut Shy</a><span>Drag and release to knock the coconuts off their posts, five balls a round</span><span>Game forged by the crew</span><span class="tags">Throwing · Drag</span></li> |
| 99 | <li data-kind="Throwing" data-input="Drag" style="--accent:#b0533a"><a href="hoopla/">Hoopla Stall</a><span>Drag and release to toss rings over the prize blocks, eight rings a round</span><span>Game forged by the crew</span><span class="tags">Throwing · Drag</span></li> | |
| 99 | 100 | <li data-kind="Sport" data-input="Drag" style="--accent:#4f7f3f"><a href="bowls-green/">Bowls Green</a><span>Drag back to set line and weight and curve your woods in close to the jack</span><span>Game forged by the crew</span><span class="tags">Sport · Drag</span></li> |
| 100 | 101 | <li data-kind="Racing" data-input="Drag" style="--accent:#2e8a7a"><a href="dinghy-race/">Dinghy Race</a><span>Drag to trim the sail to the wind and round three buoys ahead of the fleet</span><span>Game forged by the crew</span><span class="tags">Racing · Drag</span></li> |
| 101 | 102 | <li data-kind="Memory" data-input="Tap" style="--accent:#7d9a4a"><a href="seed-packets/">Seed Packets</a><span>Tap to turn over seed packets and match every pair before the gardener comes back</span><span>Game forged by the crew</span><span class="tags">Memory · Tap</span></li> |
og/home.png
Binary file not shown.
og/hoopla.png added
Binary file not shown.
rounds.mjs +17
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | import { boot } from './playtest.mjs'; |
| 4 | 4 | import { powerFor, MAX_SPEED, GRAVITY } from './coconut-shy/shy.js'; |
| 5 | 5 | import { bestThrow, LINE_MAX } from './bowls-green/bowls.js'; |
| 6 | import { toss, MAX_AIM } from './hoopla/hoop.js'; | |
| 6 | 7 | |
| 7 | 8 | const MID = [180, 140]; |
| 8 | 9 | const tapping = (wait = .3) => g => { g.tap(...MID); g.run(wait); }; |
| @@ -33,6 +34,22 @@ export const ROUNDS = { | ||
| 33 | 34 | g.keyUp(' '); |
| 34 | 35 | g.run(2); |
| 35 | 36 | } }, |
| 37 | // simulate every aim (whole degrees) and power (whole frames of the 2 s hold) on the rules and toss the one that scores most, then hold Space for those frames | |
| 38 | 'hoopla': { over: /play again/, outcome: /You win with \d+!/, beat: g => { | |
| 39 | if (g.read('R.over')) { g.press(' ', .6); return; } | |
| 40 | if (g.read('busy()')) { g.run(.5); return; } | |
| 41 | const R = g.read('R'); | |
| 42 | let best = { points: -1, aim: 0, frames: 1 }; | |
| 43 | for (let aim = -MAX_AIM; aim <= MAX_AIM; aim++) for (let frames = 1; frames <= 50; frames++) { | |
| 44 | const e = toss(R, { aim, power: frames / 50 }).event; | |
| 45 | if (e.points > best.points) best = { points: e.points, aim, frames }; | |
| 46 | } | |
| 47 | for (let n = best.aim - g.read('G.aim'); n !== 0; n -= Math.sign(n)) g.press(n < 0 ? 'ArrowLeft' : 'ArrowRight', .04); | |
| 48 | g.keyDown(' '); | |
| 49 | g.step(best.frames); | |
| 50 | g.keyUp(' '); | |
| 51 | g.run(1); | |
| 52 | } }, | |
| 36 | 53 | // find the line and weight whose wood rests nearest the jack (lines in half degrees, weights in whole frames of the 1.6 s hold), set the line, hold Space and let go |
| 37 | 54 | 'bowls-green': { over: /play again/, outcome: /You win: \d+ woods? nearer/, beat: g => { |
| 38 | 55 | if (g.read('R.over')) { g.press(' ', .6); return; } |
serve.test.mjs +7
| @@ -437,6 +437,13 @@ test('Coconut Shy and its rules script are served without a track', async () => | ||
| 437 | 437 | expect((await fetch(base + '/coconut-shy/shy.js')).status).toBe(200); |
| 438 | 438 | }); |
| 439 | 439 | |
| 440 | test('Hoopla Stall and its rules script are served without a track', async () => { | |
| 441 | const page = await fetch(base + '/hoopla/'); | |
| 442 | expect(page.status).toBe(200); | |
| 443 | expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8'); | |
| 444 | expect((await fetch(base + '/hoopla/hoop.js')).status).toBe(200); | |
| 445 | }); | |
| 446 | ||
| 440 | 447 | test('Bowls Green and its rules script are served without a track', async () => { |
| 441 | 448 | const page = await fetch(base + '/bowls-green/'); |
| 442 | 449 | expect(page.status).toBe(200); |
shell.js +1
| @@ -40,6 +40,7 @@ window.PixelPlays = (() => { | ||
| 40 | 40 | { id: 'firefly-jar', title: 'Firefly Jar', blurb: 'Tap the fireflies into a jar while they glow, a dim one flies off, shoo the moths before they reach the lantern', kind: 'Catching', input: 'Tap', accent: '#c9b43a', music: false, forged: true }, |
| 41 | 41 | { id: 'egg-basket', title: 'Egg Basket', blurb: 'Slide the basket under the eave and catch the eggs before three crack', kind: 'Catching', input: 'Drag', accent: '#d08a2e', music: false, forged: true }, |
| 42 | 42 | { id: 'coconut-shy', title: 'Coconut Shy', blurb: 'Drag and release to knock the coconuts off their posts, five balls a round', kind: 'Throwing', input: 'Drag', accent: '#7a4a2a', music: false, forged: true }, |
| 43 | { id: 'hoopla', title: 'Hoopla Stall', blurb: 'Drag and release to toss rings over the prize blocks, eight rings a round', kind: 'Throwing', input: 'Drag', accent: '#b0533a', music: false, forged: true }, | |
| 43 | 44 | { id: 'bowls-green', title: 'Bowls Green', blurb: 'Drag back to set line and weight and curve your woods in close to the jack', kind: 'Sport', input: 'Drag', accent: '#4f7f3f', music: false, forged: true }, |
| 44 | 45 | { id: 'dinghy-race', title: 'Dinghy Race', blurb: 'Drag to trim the sail to the wind and round three buoys ahead of the fleet', kind: 'Racing', input: 'Drag', accent: '#2e8a7a', music: false, forged: true }, |
| 45 | 46 | { id: 'seed-packets', title: 'Seed Packets', blurb: 'Tap to turn over seed packets and match every pair before the gardener comes back', kind: 'Memory', input: 'Tap', accent: '#7d9a4a', music: false, forged: true }, |
new above
offline