Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Add Go-Kart Fete: the playable page and its place in the catalogue, on the rules already in `go-kart/lap.js` #125
Check · Review · Land · Live done — Landed and live in production.
vesper/pixel-plays:vesper/104-add-go-kart-fete-the-playable-page-and-i → main 8 commits fork 4 threads · 4 unresolved
9 files
changed +408
−6
README.md +3 −2
| @@ -49,6 +49,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am | ||
| 49 | 49 | | [](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 | |
| 50 | 50 | | [](empire/) | A real-time strategy game on a 44 by 44 map against a red bot (easy, normal or hard): four villagers and a town center each, gather food, wood, gold and stone, build houses, camps, farms and military buildings, climb the Dark, Feudal, Castle and Imperial Ages, research upgrades, train militia, spearmen, archers, knights and rams, and destroy every town center and castle of the enemy; fog of war, a minimap, attack alerts, pause, 1x/2x/4x speed, an autopilot, a save that survives a reload and a best time per level (forged by the crew on the engine and shell above, not by the original creators) | Tap or drag a box to select, tap to command, panel buttons to build and train; arrows move the view, Enter taps its centre cross, 1-9 press buttons | |
| 51 | 51 | | [](hot-air-balloon/) | Five flights over patchwork farm fields with hedgerows, a windsock and one field marked with a white cross: hold the burner and the balloon climbs slowly after a short lag, let go and it sinks; the air has three height bands that each blow their own way and a little differently each flight, shown by drifting cloud wisps, three arrows at the left and a pennant on the basket, so you steer only by choosing a height (the ready screen before each flight already shows that flight's winds, so read them first); touching the ground ends the flight and the landing scores by distance from the cross (on it 5, inside its field 3, a neighbouring field 1, trees or the pond 0), each flight from a new launch point; 15 or more of 25 wins; the balloon's shadow on the fields shows where it is over (forged by the crew on the engine and shell above, not by the original creators) | Press and hold the canvas; hold space or the up arrow | |
| 52 | | [](go-kart/) | Three races of three laps round a village track against three rivals: hold to drive, let go to brake, and a yellow board before each bend shows the fastest speed to enter it at; go in faster and you sit a second in the hay bales; first scores 3, second 2, third 1, and 6 points wins (forged by the crew on the engine and shell above, not by the original creators) | Hold; space | | |
| 52 | 53 | | [](cloakroom/) | A coat check with two rails of coats, each with a paper tag: turn two tags at a time, a matching pair is handed back and a mismatch turns back after 0.8 s; three rounds of 6, 8 and 10 pairs, 90 seconds each, and more than 12 mismatches in all (or a clock at zero) ends it; the coats sway and light moves under the door, the number and colour on a turned tag mean it plays muted too (forged by the crew on the engine and shell above, not by the original creators) | Tap a coat; arrows move a ring, space or enter turns | |
| 53 | 54 | |
| 54 | 55 | ## Run |
| @@ -69,7 +70,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is | ||
| 69 | 70 | 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. |
| 70 | 71 | |
| 71 | 72 | ## Add a game |
| 72 | 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, Empire Age, Egg Basket, Dinghy Race and Coconut Shy 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`. | |
| 73 | 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 and Coconut Shy 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`. | |
| 73 | 74 | |
| 74 | 75 | - `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. |
| 75 | 76 | - `engine.js` provides the camera, depth buffer, colour ramps, shadows, edges, figures, trees and wind as globals. |
| @@ -85,7 +86,7 @@ Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules | ||
| 85 | 86 | - Depth-buffer edges: darker where an object sits in front, a warm rim on upper-left edges. |
| 86 | 87 | - Large flat surfaces use closely spaced tones; wide steps make the dither read as a checkerboard. |
| 87 | 88 | - Characters stay sharp: flat bands with no dither, a dark silhouette on their own pixels, patterns at least 3px wide. |
| 88 | - 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, 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); all of it stops under `prefers-reduced-motion`. | |
| 89 | - 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); all of it stops under `prefers-reduced-motion`. | |
| 89 | 90 | |
| 90 | 91 | ## Empire Age |
| 91 | 92 |
go-kart/index.html added +380
| @@ -0,0 +1,380 @@ | ||
| 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>Go-Kart Fete</title> | |
| 7 | <!-- og:begin --> | |
| 8 | <meta name="description" content="Hold to race, let go for the bends: three laps round the hay bales against three rivals"> | |
| 9 | <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/go-kart/"> | |
| 10 | <meta property="og:type" content="website"> | |
| 11 | <meta property="og:site_name" content="Pixel Plays"> | |
| 12 | <meta property="og:title" content="Go-Kart Fete"> | |
| 13 | <meta property="og:description" content="Hold to race, let go for the bends: three laps round the hay bales against three rivals"> | |
| 14 | <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/go-kart/"> | |
| 15 | <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/go-kart.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="Go-Kart Fete: the opening scene of the game"> | |
| 20 | <meta name="twitter:card" content="summary_large_image"> | |
| 21 | <!-- og:end --> | |
| 22 | ||
| 23 | <style> | |
| 24 | :root { : #1c1b19; : #8b877f; : #fff; : #e0a526; } | |
| 25 | * { box-sizing: border-box; } | |
| 26 | html, body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; } | |
| 27 | html, body { height: 100%; margin: 0; background: var(); color: var(); } | |
| 28 | body { font: 13px/1.35 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; overflow: hidden; } | |
| 29 | #stage { position: fixed; inset: 0; display: grid; place-items: center; } | |
| 30 | canvas { display: block; image-rendering: pixelated; touch-action: none; cursor: pointer; outline: none; } | |
| 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; 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(14px, env(safe-area-inset-bottom)); align-items: flex-end; } | |
| 34 | .row { display: flex; align-items: center; gap: 8px; color: var(); } | |
| 35 | .row b { font-size: 16px; font-weight: 600; min-width: 1ch; font-variant-numeric: tabular-nums; } | |
| 36 | .row span { color: var(); } | |
| 37 | #status { color: var(); min-height: 1.35em; } | |
| 38 | button { pointer-events: auto; font: inherit; color: var(); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; } | |
| 39 | button:hover, button:focus-visible { color: var(); } | |
| 40 | noscript p { position: fixed; z-index: 3; inset: 40px 0 auto; margin: 0; padding: 12px 16px; background: var(); } | |
| 41 | </style> | |
| 42 | </head> | |
| 43 | <body> | |
| 44 | <noscript> | |
| 45 | <p>Go-Kart Fete needs JavaScript. It is a village kart race: hold to drive, let go to brake before each bend, three laps a race against three rivals.</p> | |
| 46 | </noscript> | |
| 47 | <div id="stage"><canvas id="c" tabindex="0" aria-label="A village go-kart track with hay bales at the bends and three rival karts. Hold space, up or W to drive, or press and hold on the screen; let go to brake. A yellow speed board before each bend shows the fastest speed you may enter it at, in metres per second: go in faster and you stop in the hay bales for a second. Three laps a race, three races, points for first, second and third, and six points wins."></canvas></div> | |
| 48 | <div id="scores"> | |
| 49 | <div class="row"><b id="score">0</b><span>points of 6</span></div> | |
| 50 | <div class="row"><b id="race">1</b><span>race of 3</span></div> | |
| 51 | <div class="row"><b id="lap">1</b><span>lap of 3</span></div> | |
| 52 | <div class="row"><b id="place">1</b><span>place</span></div> | |
| 53 | <div class="row"><b id="speed">0</b><span>m/s</span></div> | |
| 54 | <div class="row"><b id="best">0</b><span>best</span></div> | |
| 55 | </div> | |
| 56 | <div class="hud" id="bottom"> | |
| 57 | <div id="status" role="status" aria-live="polite"></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: 'go-kart', | |
| 64 | rules: [ | |
| 65 | 'Hold space, up or W (or press and hold) to drive; let go to brake.', | |
| 66 | 'A yellow board before each bend shows the fastest speed to enter it at.', | |
| 67 | 'Go in faster and you sit a second in the hay bales. Three laps a race, three races.', | |
| 68 | 'First scores 3, second 2, third 1: six points wins.', | |
| 69 | ], | |
| 70 | }); | |
| 71 | </script> | |
| 72 | <script>window.PP_SCENE = { originY: 0, shadowX: 1.3, shadowY: -.12 };</script> | |
| 73 | <script src="../engine.js"></script> | |
| 74 | <script src="lap.js"></script> | |
| 75 | <script> | |
| 76 | 'use strict'; | |
| 77 | ||
| 78 | const STEP = Math.SQRT2 / 5; // one camera step moves the track exactly 2px right and 1px down | |
| 79 | const CELL = STEP * 2, PHASES = 8; // the track repeats every 8 steps, so 8 baked frames of ground scroll it without a seam | |
| 80 | const LEAD_STEPS = 36; // the kart sits 36 steps (about 10 m) left of the screen centre so the boards show from far ahead | |
| 81 | const BOARD_AHEAD = 38; // metres before a bend that its speed board stands | |
outdated
INK3 is unused. Remove it. |
||
| 82 | const BEST_KEY = 'pixel-plays-go-kart-best'; | |
| 83 | const ROAD = 2.75, KERB = 3.2, VERGE = 6.2; | |
| 84 | const LANE_ME = -.6, LANES = [-2, .7, 1.95]; | |
| 85 | const DASH = [92, 92, 100], STRAW = [214, 178, 84], RED = [196, 52, 44], BLUE = [58, 96, 176], GREEN = [70, 150, 86], PURPLE = [140, 84, 164]; | |
| 86 | const RIVAL_BODY = [BLUE, GREEN, PURPLE], HELMETS = [[240, 240, 232], [250, 214, 60], [230, 120, 60]]; | |
| 87 | const COATS = [[200, 92, 74], [74, 120, 170], [96, 150, 104], [214, 168, 70], [140, 100, 160]]; | |
| 88 | const CHARCOAL = [40, 40, 46]; | |
| 89 | const SIGN = rgb(236, 190, 40), SIGN_INK = rgb(28, 27, 25); | |
| 90 | const GLYPHS = { | |
| 91 | 0: '111101101101111', 1: '010110010010111', 2: '111001111100111', 3: '111001111001111', 4: '101101111001001', | |
| 92 | 5: '111100111001111', 6: '111100111101111', 7: '111001001001001', 8: '111101111101111', 9: '111101111001111', | |
| 93 | }; | |
| 94 | ||
| 95 | /* ---------- state ---------- */ | |
| 96 | const best0 = (() => { try { return Number(localStorage.getItem(BEST_KEY)) || 0; } catch (e) { return 0; } })(); | |
| 97 | let R = Lap.newGame(best0, Date.now() & 0xffff); | |
| 98 | const G = { time: 0, status: '', noteUntil: 0 }; | |
| 99 | const nodes = {}; | |
| 100 | for (const id of ['score', 'race', 'lap', 'place', 'speed', 'best', 'status']) nodes[id] = document.getElementById(id); | |
| 101 | function renderHud() { | |
| 102 | nodes.score.textContent = R.total; | |
| 103 | nodes.race.textContent = R.race; | |
| 104 | nodes.lap.textContent = R.lap; | |
| 105 | nodes.place.textContent = R.place; | |
| 106 | nodes.speed.textContent = Math.round(R.speed); | |
| 107 | nodes.best.textContent = Math.max(R.best, R.total); | |
| 108 | } | |
| 109 | function setStatus(text) { | |
| 110 | if (text === G.status) return; | |
| 111 | G.status = text; | |
| 112 | nodes.status.textContent = text; | |
| 113 | } | |
| 114 | function note(text) { setStatus(text); G.noteUntil = G.time + 2.4; } | |
| 115 | const HINT = 'hold space or the screen to drive · let go for the bends · boards show the safe speed'; | |
| 116 | ||
| 117 | /* ---------- baked ground: the track at each of its eight scroll phases ---------- */ | |
| 118 | const mod = (a, n) => ((a % n) + n) % n; | |
| 119 | const phases = []; | |
| 120 | const baseZ = new Float32Array(W * H).fill(-1e9); | |
| 121 | function streetColor(xw, y) { | |
| 122 | const a = Math.abs(y); | |
| 123 | const col = Math.floor(xw / CELL); | |
| 124 | if (a < ROAD) { | |
| 125 | if (Math.abs(a - ROAD + .22) < .07) return rgb(236, 232, 220); | |
| 126 | const t = .88 + hash(mod(col, 4), Math.floor((y + 9) / .5)) * .2; | |
| 127 | return rgb(DASH[0] * t, DASH[1] * t, DASH[2] * t); | |
| 128 | } | |
| 129 | if (a < KERB) return mod(xw, STEP * 8) < STEP * 4 ? rgb(214, 70, 58) : rgb(236, 232, 220); | |
| 130 | const t = .85 + hash(mod(col, 4), Math.floor((y + 9) / .5)) * .3; | |
| 131 | return rgb(82 * t, 128 * t, 62 * t); | |
| 132 | } | |
| 133 | function bakeGround() { | |
| 134 | const member = new Uint8Array(W * H); | |
| 135 | for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) { | |
| 136 | const g = unproject(ix + .5, iy + .5), i = iy * W + ix; | |
| 137 | const e = Math.abs(g.y) / VERGE + (hash(ix, iy) - .5) * .1; | |
| 138 | if (e > 1.04 || (e > .94 && hash(iy, ix) < (e - .94) / .1)) continue; | |
| 139 | member[i] = 1; ground[i] = 1; | |
| 140 | baseZ[i] = (g.x + g.y) / R2 * COS; | |
| 141 | } | |
| 142 | groundZ.set(baseZ); | |
| 143 | for (let k = 0; k < PHASES; k++) { | |
| 144 | const buf = new Uint32Array(W * H).fill(rgb(255, 255, 255)); | |
| 145 | for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) { | |
| 146 | const i = iy * W + ix; | |
| 147 | if (!member[i]) continue; | |
| 148 | const g = unproject(ix + .5, iy + .5); | |
| 149 | buf[i] = streetColor(g.x + k * STEP, g.y); | |
| 150 | } | |
| 151 | phases.push(buf); | |
| 152 | } | |
| 153 | } | |
| 154 | ||
| 155 | /* ---------- drawing ---------- */ | |
| 156 | // paint flat colour on the track without touching depth, so shadows and edges ignore it | |
| 157 | function paint(x0, x1, y0, y1, colorOf) { | |
| 158 | for (let x = x0; x <= x1; x += .06) for (let y = y0; y <= y1; y += .06) { | |
| 159 | const p = project(x, y, 0), ix = p.sx | 0, iy = p.sy | 0; | |
| 160 | if (ix >= 0 && iy >= 0 && ix < W && iy < H && ground[iy * W + ix]) pix[iy * W + ix] = colorOf(x, y); | |
| 161 | } | |
| 162 | } | |
| 163 | const CHALK = rgb(246, 242, 228), BLACK = rgb(34, 33, 31), ENTRY = rgb(250, 246, 232); | |
| 164 | function lines(cam) { | |
| 165 | for (let l = 0; l <= Lap.LAPS; l++) { | |
| 166 | const m = l * Lap.LAP - cam; | |
| 167 | if (m > -4 && m < 44) paint(m - .5, m + .5, -ROAD, ROAD, (x, y) => ((Math.floor((x - m + .5) / .5) + Math.floor((y + ROAD) / .5)) & 1 ? BLACK : CHALK)); | |
| 168 | } | |
| 169 | for (const b of bendList(cam)) if (b.rel > -4 && b.rel < 44) paint(b.rel - .12, b.rel + .12, -ROAD, ROAD, () => ENTRY); | |
| 170 | } | |
| 171 | // the bends within sight: where each stands relative to the camera | |
| 172 | function bendList(cam) { | |
| 173 | const out = [], first = Math.max(0, Math.floor((cam - 40) / Lap.LAP)); | |
outdated
The |
||
| 174 | for (let l = first; l < Math.min(Lap.LAPS, first + 2); l++) for (const b of Lap.BENDS) out.push({ rel: l * Lap.LAP + b.at - cam, safe: b.safe }); | |
| 175 | return out; | |
| 176 | } | |
| 177 | function bales(m) { | |
| 178 | for (let k = 0; k < 3; k++) { | |
| 179 | const x = m + .6 + k * 1.25; | |
| 180 | box(x, 3.3, 0, x + 1.15, 4.2, .75, STRAW, 3 + k); | |
| 181 | box(x + .35, 3.3, 0, x + .45, 4.2, .77, [150, 108, 52], 9); | |
| 182 | castShadow(x + .55, 3.75, .8, .55, 1, .4); | |
| 183 | } | |
| 184 | box(m + 1.85, 3.4, .75, m + 3.0, 4.1, 1.45, STRAW, 14); | |
| 185 | castShadow(m + 2.4, 3.75, 1.5, .5, 1, .4); | |
| 186 | } | |
| 187 | function digitsOf(n) { return String(Math.max(0, Math.round(n))).split(''); } | |
| 188 | // a yellow board on a post with the safe speed on it, stamped upright in whole pixels so it reads at a glance | |
| 189 | function board(m, safe) { | |
| 190 | capsule([m, 4.6, 0], [m, 4.6, 2.2], .09, .09, () => [74, 78, 88], 'solid'); | |
| 191 | castShadow(m, 4.6, 2.2, .35, 1, 0); | |
| 192 | const digits = digitsOf(safe), width = digits.length * 8 - 2 + 6, height = 16; | |
| 193 | const p = project(m, 4.6, 2.9), left = Math.round(p.sx - width / 2), top = Math.round(p.sy - height / 2); | |
| 194 | for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) { | |
| 195 | const ix = left + x, iy = top + y; | |
| 196 | if (ix < 0 || iy < 0 || ix >= W || iy >= H) continue; | |
| 197 | const i = iy * W + ix; | |
| 198 | if (p.d <= zb[i]) continue; | |
| 199 | zb[i] = p.d; | |
| 200 | pix[i] = x === 0 || y === 0 || x === width - 1 || y === height - 1 ? SIGN_INK : SIGN; | |
| 201 | } | |
| 202 | digits.forEach((d, k) => { | |
| 203 | for (let r = 0; r < 5; r++) for (let c = 0; c < 3; c++) { | |
| 204 | if (GLYPHS[d][r * 3 + c] !== '1') continue; | |
| 205 | for (let dy = 0; dy < 2; dy++) for (let dx = 0; dx < 2; dx++) { | |
| 206 | const ix = left + 3 + k * 8 + c * 2 + dx, iy = top + 3 + r * 2 + dy; | |
| 207 | if (ix < 0 || iy < 0 || ix >= W || iy >= H) continue; | |
| 208 | const i = iy * W + ix; | |
| 209 | zb[i] = Math.max(zb[i], p.d + .01); | |
| 210 | pix[i] = SIGN_INK; | |
| 211 | } | |
| 212 | } | |
| 213 | }); | |
| 214 | } | |
| 215 | function kart(x, y, body, helmet) { | |
| 216 | for (const wx of [-.7, .7]) for (const wy of [-.68, .68]) box(x + wx - .28, y + wy - .14, 0, x + wx + .28, y + wy + .14, .38, [36, 36, 42], 3); | |
| 217 | box(x - 1, y - .5, .15, x + 1, y + .5, .5, body, 5); | |
| 218 | box(x + .6, y - .36, .2, x + 1.3, y + .36, .46, body, 7); | |
| 219 | box(x - 1, y - .46, .5, x - .45, y + .46, .9, [52, 52, 60], 9); | |
| 220 | capsule([x - .1, y, .5], [x - .1, y, 1.1], .3, .26, () => helmet, 'solid'); | |
| 221 | const head = [x - .1, y, 1.42]; | |
| 222 | capsule(head, head, .3, .3, () => helmet, 'gloss'); | |
| 223 | for (const [dx, dz] of [[-1, .3], [0, .3], [1, .3], [-.6, 1], [.4, 1], [0, 1.45]]) castShadow(x + dx, y, dz, .5, 1, 0); | |
| 224 | } | |
| 225 | function spectator(x, i, raised) { | |
| 226 | const j = hash(i, 5), coat = COATS[i % COATS.length]; | |
| 227 | figure(x, -4.6 - (i % 2) * .9, Math.PI / 2, { | |
outdated
gantry never uses |
||
| 228 | stance: .1 + j * .2, lean: (j - .5) * .1, armR: raised ? 2.7 : j * .15, armL: raised && j > .5 ? 2.5 : .08, | |
| 229 | }, { shirt: coat, stripe: coat.map(v => v * .8), legs: [60, 62, 78], skin: [226, 178, 140], hair: [58, 44, 36] }, dynamicAdd); | |
| 230 | } | |
| 231 | function gantry(m) { | |
| 232 | capsule([m, -3.7, 0], [m, -3.7, 5], .1, .1, () => [74, 78, 88], 'solid'); | |
| 233 | castShadow(m, -3.7, 5, .4, 1, 0); | |
| 234 | const t = STILL ? 0 : G.time; | |
| 235 | for (let k = 0; k < 6; k++) { | |
| 236 | const sway = STILL ? 0 : Math.sin(Math.floor(t * 8) * .5 + k * 1.1) * .08 * (k + 1) * .5; | |
| 237 | box(m + .1 + k * .3, -3.7 + sway, 4.1, m + .4 + k * .3, -3.62 + sway, 5, k & 1 ? CHARCOAL : [240, 238, 226], 11 + k); | |
| 238 | castShadow(m + .25 + k * .3, -3.7, 4.5, .25, 1, 0); | |
| 239 | } | |
| 240 | } | |
| 241 | ||
| 242 | const DOOR_X = -LEAD_STEPS * STEP; | |
| 243 | function draw() { | |
| 244 | const n = Math.round(R.x / STEP) + LEAD_STEPS, cam = n * STEP; // the camera moves in whole steps so the ground scrolls in whole pixels | |
| 245 | pix.set(phases[mod(n, PHASES)]); | |
| 246 | zb.set(baseZ); | |
| 247 | lines(cam); | |
| 248 | const first = Math.floor((cam - 14) / 9.3); | |
| 249 | for (let i = Math.max(0, first); i < first + 7; i++) { | |
| 250 | const x = i * 9.3 + 4 - cam; | |
| 251 | if (x > -14 && x < 46) spectator(x, i, !STILL && (Math.floor(G.time * 3 + i * 1.7) % 3 === 0 || R.phase !== 'race' && i % 2 === 0)); | |
| 252 | } | |
| 253 | for (let l = 0; l <= Lap.LAPS; l++) { const m = l * Lap.LAP - cam; if (m > -6 && m < 46) gantry(m); } | |
| 254 | for (const b of bendList(cam)) { | |
| 255 | if (b.rel > -8 && b.rel < 48) bales(b.rel); | |
| 256 | if (b.rel - BOARD_AHEAD > -6 && b.rel - BOARD_AHEAD < 48) board(b.rel - BOARD_AHEAD, b.safe); | |
| 257 | } | |
| 258 | for (let k = 0; k < Lap.RIVALS; k++) { | |
| 259 | const rel = R.paces[k] * R.time - R.x + DOOR_X; | |
| 260 | if (rel > -12 && rel < 46) kart(rel, LANES[k], RIVAL_BODY[k], HELMETS[k]); | |
| 261 | } | |
| 262 | const into = R.stuck > 0 ? Math.min(1, (Lap.BALES_STOP - R.stuck) * 5, R.stuck * 4) : 0, ease3 = into * into * (3 - 2 * into); | |
| 263 | kart(DOOR_X, LANE_ME + ease3 * 2.9, RED, [250, 250, 244]); | |
| 264 | flushShadows(); | |
| 265 | pendingShadows.length = 0; | |
| 266 | applyShadows(groundZ); | |
| 267 | shadeEdges(); | |
| 268 | ctx.putImageData(image, 0, 0); | |
| 269 | } | |
| 270 | ||
| 271 | /* ---------- game ---------- */ | |
| 272 | const ctl = { throttle: false }; | |
| 273 | const keys = new Set(), touches = new Set(); | |
| 274 | function readControls() { ctl.throttle = keys.size > 0 || touches.size > 0; } | |
| 275 | function act(events) { | |
| 276 | for (const e of events) { | |
| 277 | if (e.type === 'bales') { note(`too fast into the bend: ${Lap.BALES_STOP} second in the hay bales`); sound('thud'); } | |
| 278 | if (e.type === 'finish') { note(`race ${e.race}: place ${e.place}, +${e.points}`); sound('chime'); } | |
| 279 | if (e.type === 'start') { note(`race ${e.race} of ${Lap.RACES}: go`); sound('tick'); } | |
| 280 | if (e.type === 'won' || e.type === 'lost') { | |
| 281 | if (R.record) try { localStorage.setItem(BEST_KEY, String(R.best)); } catch (err) { /* private window: keep it for this visit */ } | |
| 282 | sound(e.type === 'won' ? 'cheer' : 'buzz'); | |
| 283 | } | |
| 284 | } | |
| 285 | } | |
| 286 | function restart() { | |
| 287 | const next = Lap.again(R); | |
| 288 | if (!next) return false; | |
| 289 | R = next; | |
| 290 | note(HINT); | |
| 291 | renderHud(); | |
| 292 | return true; | |
| 293 | } | |
| 294 | function update(dt) { | |
| 295 | G.time += dt; | |
| 296 | act(Lap.advance(R, dt, ctl)); | |
| 297 | renderHud(); | |
| 298 | if (R.over) setStatus(`${R.line}${R.record ? ' · new best' : ` · best ${R.best}`} · tap or press space to race again`); | |
| 299 | else if (G.time >= G.noteUntil) setStatus(R.stuck > 0 ? 'in the hay bales' : R.phase === 'rest' ? `race ${R.race} done · place ${R.place} · next race starting` : R.line); | |
| 300 | } | |
| 301 | ||
| 302 | /* ---------- input ---------- */ | |
| 303 | const HOLD_KEYS = { ' ': 'space', ArrowUp: 'up', w: 'up', W: 'up' }; | |
| 304 | canvas.addEventListener('keydown', e => { | |
| 305 | const k = HOLD_KEYS[e.key]; | |
| 306 | if (!k) return; | |
| 307 | e.preventDefault(); | |
| 308 | ensureAudio(); | |
| 309 | if (e.repeat) return; | |
| 310 | if (restart()) return; | |
| 311 | keys.add(k); | |
| 312 | readControls(); | |
| 313 | }); | |
| 314 | canvas.addEventListener('keyup', e => { | |
| 315 | const k = HOLD_KEYS[e.key]; | |
| 316 | if (!k) return; | |
| 317 | keys.delete(k); | |
| 318 | readControls(); | |
| 319 | }); | |
| 320 | canvas.addEventListener('blur', () => { keys.clear(); touches.clear(); readControls(); }); | |
| 321 | canvas.addEventListener('pointerdown', e => { | |
| 322 | ensureAudio(); | |
| 323 | canvas.focus({ preventScroll: true }); | |
| 324 | if (restart()) return; | |
| 325 | touches.add(e.pointerId); | |
| 326 | try { canvas.setPointerCapture(e.pointerId); } catch (err) { /* synthetic pointers have nothing to capture */ } | |
| 327 | readControls(); | |
| 328 | }); | |
| 329 | for (const type of ['pointerup', 'pointercancel']) canvas.addEventListener(type, e => { touches.delete(e.pointerId); readControls(); }); | |
| 330 | ||
| 331 | /* ---------- sound ---------- */ | |
| 332 | let audio = null, muted = false; | |
| 333 | function ensureAudio() { | |
| 334 | if (audio) { if (audio.state === 'suspended') audio.resume(); return; } | |
| 335 | const AC = window.AudioContext || window.webkitAudioContext; | |
| 336 | if (AC) audio = new AC(); | |
| 337 | } | |
| 338 | function sound(kind) { | |
| 339 | if (!audio || muted) return; | |
| 340 | const now = audio.currentTime, gain = audio.createGain(), osc = audio.createOscillator(); | |
| 341 | const spec = { | |
| 342 | thud: [160, 60, .25, .09, 'square'], | |
| 343 | tick: [440, 660, .1, .05, 'sine'], | |
| 344 | chime: [660, 990, .3, .07, 'sine'], | |
| 345 | cheer: [520, 1040, .5, .07, 'triangle'], | |
| 346 | buzz: [150, 70, .3, .06, 'sawtooth'], | |
| 347 | }[kind]; | |
| 348 | osc.type = spec[4]; | |
| 349 | osc.frequency.setValueAtTime(spec[0], now); | |
| 350 | osc.frequency.exponentialRampToValueAtTime(spec[1], now + spec[2]); | |
| 351 | gain.gain.setValueAtTime(spec[3], now); | |
| 352 | gain.gain.exponentialRampToValueAtTime(.0005, now + spec[2]); | |
| 353 | osc.connect(gain).connect(audio.destination); | |
| 354 | osc.start(now); osc.stop(now + spec[2] + .01); | |
| 355 | } | |
| 356 | const muteButton = document.getElementById('mute'); | |
| 357 | muteButton.addEventListener('click', () => { | |
| 358 | muted = !muted; | |
| 359 | muteButton.textContent = muted ? 'sound off' : 'sound on'; | |
| 360 | muteButton.setAttribute('aria-pressed', String(muted)); | |
| 361 | }); | |
| 362 | ||
| 363 | /* ---------- fit and boot ---------- */ | |
| 364 | addEventListener('resize', fit); | |
| 365 | fit(); | |
| 366 | bakeGround(); | |
| 367 | note(HINT); | |
| 368 | renderHud(); | |
| 369 | canvas.focus({ preventScroll: true }); | |
| 370 | let last = performance.now(); | |
| 371 | function frame(now) { | |
| 372 | update(Math.min(.04, (now - last) / 1000)); | |
| 373 | last = now; | |
| 374 | draw(); | |
| 375 | requestAnimationFrame(frame); | |
| 376 | } | |
| 377 | requestAnimationFrame(frame); | |
| 378 | </script> | |
| 379 | </body> | |
| 380 | </html> |
index.html +1
| @@ -99,6 +99,7 @@ footer a::after { content: none; } | ||
| 99 | 99 | <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> |
| 100 | 100 | <li data-kind="Strategy" data-input="Tap" style="--accent:#3a5fa8"><a href="empire/">Empire Age</a><span>A real-time strategy game against a bot: gather, build, climb four ages, train an army and destroy the enemy town center</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li> |
| 101 | 101 | <li data-kind="Precision" data-input="Hold" style="--accent:#d0453c"><a href="hot-air-balloon/">Hot Air Balloon</a><span>Five flights over the farms: hold the burner to climb into a different wind, land on the cross for 5</span><span>Game forged by the crew</span><span class="tags">Precision · Hold</span></li> |
| 102 | <li data-kind="Racing" data-input="Hold" style="--accent:#e0a526"><a href="go-kart/">Go-Kart Fete</a><span>Hold to race, let go for the bends: three laps round the hay bales against three rivals</span><span>Game forged by the crew</span><span class="tags">Racing · Hold</span></li> | |
| 102 | 103 | <li data-kind="Memory" data-input="Tap" style="--accent:#9c3d6b"><a href="cloakroom/">Cloakroom</a><span>Turn two tags at a time and hand back every matching coat before the dance lets out</span><span>Game forged by the crew</span><span class="tags">Memory · Tap</span></li> |
| 103 | 104 | </ul> |
| 104 | 105 | <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/go-kart.png added
Binary file not shown.
og/home.png
Binary file not shown.
playtest.test.mjs +2 −2
| @@ -80,10 +80,10 @@ for (const id of GAMES) { | ||
| 80 | 80 | expect(errors.map(e => e.message)).toEqual([]); |
| 81 | 81 | expect(ended).not.toBeNull(); |
| 82 | 82 | expect(ended).toMatch(ROUNDS[id].outcome); // the win or the loss, with its number |
| 83 | expect(seconds).toBeLessThan(100); | |
| 83 | expect(seconds).toBeLessThan(ROUNDS[id].limit ?? 100); | |
| 84 | 84 | // an untouched game does not reach that outcome in the same time (it may still end, by failing) |
| 85 | 85 | const idle = boot(id); |
| 86 | 86 | idle.run(seconds); |
| 87 | 87 | expect(idle.text()).not.toMatch(ROUNDS[id].outcome); |
| 88 | }, 120_000); // a timed round (wood-split's 60 s) is played twice in the engine's software renderer | |
| 88 | }, ROUNDS[id].budget ?? 120_000); // a timed round (wood-split's 60 s) is played twice in the engine's software renderer | |
| 89 | 89 | } |
rounds.mjs +9 −2
| @@ -61,6 +61,13 @@ export const ROUNDS = { | ||
| 61 | 61 | if (side !== null && !g.read('G.dive')) g.press(side < 0 ? 'ArrowLeft' : side > 0 ? 'ArrowRight' : 'ArrowUp'); |
| 62 | 62 | g.step(1); |
| 63 | 63 | } }, |
| 64 | // hold the pedal until the next bend's board is close enough that braking from here just makes its safe speed | |
| 65 | 'go-kart': { over: /Won with|Lost with/, outcome: /(Won|Lost) with \d+ points/, limit: 300, beat: g => { | |
| 66 | const [d, safe, v, top, accel, brake] = g.read('(() => { const a = R.x % Lap.LAP, ahead = Lap.BENDS.map(b => (b.at - a + Lap.LAP) % Lap.LAP || Lap.LAP); const d = Math.min(...ahead); return [d, Lap.BENDS[ahead.indexOf(d)].safe, R.v, Lap.MAX_SPEED, Lap.ACCEL, Lap.BRAKE]; })()'); | |
| 67 | const next = Math.min(top, v + accel * .04), target = safe - .6; | |
| 68 | if (next <= target || d > (next * next - target * target) / (2 * brake) + next * .08 + 1.5) g.keyDown(' '); else g.keyUp(' '); | |
| 69 | g.step(1); | |
| 70 | } }, | |
| 64 | 71 | 'harbour-crane': { over: /play again/, outcome: /\d+ of 10 crates/, beat: tapping(1.3) }, |
| 65 | 72 | // fire the burner for a blink, which is under the lag, so each flight sinks to a landing; tap on to the next flight |
| 66 | 73 | 'hot-air-balloon': { over: /play again/, outcome: /(good flying|blown off course) · \d+ of 25/, beat: g => { g.tap(...MID); g.run(3); } }, |
| @@ -154,7 +161,7 @@ export const ROUNDS = { | ||
| 154 | 161 | 'window-washer': { over: /play again/, outcome: /[1-9]\d* of 500/, beat: g => g.drag([60, 100], [300, 100], .6) }, |
| 155 | 162 | }; |
| 156 | 163 | |
| 157 | const LIMIT = 150; // seconds of play, a game that has not ended by then is stuck | |
| 164 | const LIMIT = 150; // seconds of play, a game that has not ended by then is stuck (a round may name its own `limit`) | |
| 158 | 165 | |
| 159 | 166 | // play one round of `id`; returns the line that ended it (null if none did) and the seconds it took |
| 160 | 167 | export function playRound(id, seed = 1) { |
| @@ -162,6 +169,6 @@ export function playRound(id, seed = 1) { | ||
| 162 | 169 | const g = boot(id, { seed }); |
| 163 | 170 | let ended = null; |
| 164 | 171 | g.watch(() => { if (!ended) { const t = g.text(); if (over.test(t)) ended = t; } }); |
| 165 | while (!ended && g.frames < LIMIT * 25) beat(g); | |
| 172 | while (!ended && g.frames < (ROUNDS[id].limit ?? LIMIT) * 25) beat(g); | |
| 166 | 173 | return { ended, seconds: g.frames / 25, errors: g.errors }; |
| 167 | 174 | } |
serve.test.mjs +12
| @@ -501,3 +501,15 @@ test('Tug of War and its rules script are served without a track', async () => { | ||
| 501 | 501 | expect(rules.headers.get('x-content-type-options')).toBe('nosniff'); |
| 502 | 502 | expect(await page.text()).toContain('canvas:focus-visible'); |
| 503 | 503 | }); |
| 504 | ||
| 505 | test('Go-Kart Fete and its rules script are served without a track', async () => { | |
| 506 | const page = await fetch(base + '/go-kart/'); | |
| 507 | expect(page.status).toBe(200); | |
| 508 | expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8'); | |
| 509 | expect((await fetch(base + '/go-kart/lap.js')).status).toBe(200); | |
| 510 | }); | |
| 511 | ||
| 512 | test('Go-Kart Fete says it needs JavaScript when scripts are off', async () => { | |
| 513 | const html = await (await fetch(base + '/go-kart/')).text(); | |
| 514 | expect(html).toMatch(/<noscript>\s*<p>Go-Kart Fete needs JavaScript\./); | |
| 515 | }); |
shell.js +1
| @@ -43,6 +43,7 @@ window.PixelPlays = (() => { | ||
| 43 | 43 | { 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 }, |
| 44 | 44 | { id: 'empire', title: 'Empire Age', blurb: 'A real-time strategy game against a bot: gather, build, climb four ages, train an army and destroy the enemy town center', kind: 'Strategy', input: 'Tap', accent: '#3a5fa8', music: false, forged: true }, |
| 45 | 45 | { id: 'hot-air-balloon', title: 'Hot Air Balloon', blurb: 'Five flights over the farms: hold the burner to climb into a different wind, land on the cross for 5', kind: 'Precision', input: 'Hold', accent: '#d0453c', music: false, forged: true }, |
| 46 | { id: 'go-kart', title: 'Go-Kart Fete', blurb: 'Hold to race, let go for the bends: three laps round the hay bales against three rivals', kind: 'Racing', input: 'Hold', accent: '#e0a526', music: false, forged: true }, | |
| 46 | 47 | { id: 'cloakroom', title: 'Cloakroom', blurb: 'Turn two tags at a time and hand back every matching coat before the dance lets out', kind: 'Memory', input: 'Tap', accent: '#9c3d6b', music: false, forged: true }, |
| 47 | 48 | ]; |
| 48 | 49 | const MUSIC_VOLUME = .4; |
new above
offline
Conflict marker left in. Keep one line (main version plus Go-Kart Fete) and delete the markers and the duplicate.