Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Add Ice Fishing: drop a line through the ice and reel each fish up before the line snaps #58
Check · Review · Land · Live done — Landed and live in production.
quill/pixel-plays:quill/40-add-ice-fishing-drop-a-line-through-the → main 3 commits fork 2 threads · 2 unresolved
9 files
changed +781
−0
README.md +1
| @@ -31,6 +31,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am | ||
| 31 | 31 | | [](beekeeper/) | A 60-second hive inspection: hold the smoker to calm the bees (its fuel runs low and refills slowly), tap a frame to lift it into the crate, golden frames score 3 and half-capped 1, a dark brood frame costs a sting; three stings or a swarm end the round (forged by the crew on the engine and shell above, not by the original creators) | Tap a frame, hold the smoke button; arrows + space, hold S | |
| 32 | 32 | | [](campfire/) | A 90-second night: keep a campfire at a good height by dragging twigs, branches and logs into the ring; a log smothers a small fire and rain damps the flames (forged by the crew on the engine and shell above, not by the original creators) | Drag from the pile; arrows or 1/2/3 + space | |
| 33 | 33 | | [](bread-oven/) | A 60-second shift at a brick oven with four slots: slide dough in with the peel, crusts go pale, golden, dark, burnt, and slots nearer the fire bake faster; pulling golden scores 3, dark 1, pale 0, and a burnt loaf is a strike, three end the round (forged by the crew on the engine and shell above, not by the original creators) | Tap a slot, or arrows + space to slide in, enter to pull | |
| 34 | | [](ice-fishing/) | A 60-second round on a frozen lake: hold to let line out through the hole and watch the hook sink in the cut-away, a perch (1), trout (2) or pike (3) crossing the hook at its depth bites, then hold to reel and ease off to let the tension fall; full tension snaps the line and three snaps end the round (forged by the crew on the engine and shell above, not by the original creators) | Hold the canvas; hold space | | |
| 34 | 35 | |
| 35 | 36 | ## Run |
| 36 | 37 | Requires [](https://nodejs.org/); nothing to install. |
ice-fishing/hole.js added +145
| @@ -0,0 +1,145 @@ | ||
| 1 | 'use strict'; | |
| 2 | // Ice Fishing rules as plain data in, plain data out: the line and its hook depth, the fish that swim across at three depths, | |
| 3 | // the bite, the fight (tension rises while reeling, falls at rest), a snapped line, landing, and the end of the round. | |
| 4 | // Depths are in world units below the ice; x runs across the lake from 0 to WIDTH. The page draws from this state. | |
| 5 | (function (root) { | |
| 6 | const ROUND = 60; // seconds | |
| 7 | const MAX_STRIKES = 3; | |
| 8 | const WIDTH = 16, HOOK_X = 9.7; // the hole sits a little right of the middle of the cut-away | |
| 9 | const DEPTH_MAX = 9; | |
| 10 | const LET_OUT = 3.4; // units of line per second while holding with nothing on the hook | |
| 11 | const REEL = 2.4; // units gained per second while reeling a fish | |
| 12 | const BITE_BAND = .7, BITE_REACH = .55; // how close in depth and across a crossing fish must be to take the hook | |
| 13 | const TENSION_MAX = 100, REEL_RISE = 18, REST_FALL = 45; // tension per second; each fish adds its own pull while reeling | |
| 14 | const MAX_FISH = 7, SPAWN_EVERY = .9; | |
| 15 | // value: points when landed. depth: where it swims. speed: units across per second. pull: extra tension per second while reeling. run: depth it drags the hook per second when you ease off. | |
| 16 | const KINDS = { | |
| 17 | perch: { value: 1, depth: 2, speed: 3.4, pull: 14, run: .3, weight: 5 }, | |
| 18 | trout: { value: 2, depth: 4.5, speed: 2.8, pull: 28, run: .45, weight: 3.2 }, | |
| 19 | pike: { value: 3, depth: 7, speed: 2.2, pull: 42, run: .55, weight: 1.8 }, | |
| 20 | }; | |
| 21 | const NAMES = Object.keys(KINDS); | |
| 22 | const STEP = 1 / 30; | |
| 23 | const clamp = (v, a, b) => Math.max(a, Math.min(b, v)); | |
| 24 | ||
| 25 | function pickKind(rng) { | |
| 26 | const total = NAMES.reduce((n, k) => n + KINDS[k].weight, 0); | |
| 27 | let r = rng() * total; | |
| 28 | for (const k of NAMES) { r -= KINDS[k].weight; if (r <= 0) return k; } | |
| 29 | return NAMES[0]; | |
| 30 | } | |
| 31 | // a new fish enters from a side (or, for the first few, anywhere along the lake); rng() is 0..1 | |
| 32 | function spawn(rng, anywhere) { | |
| 33 | const kind = pickKind(rng), dir = rng() < .5 ? 1 : -1; | |
| 34 | const x = anywhere ? rng() * WIDTH : dir > 0 ? -1 : WIDTH + 1; | |
| 35 | return { kind, depth: KINDS[kind].depth, x, dir }; | |
| 36 | } | |
| 37 | function newState(best = 0, rng = Math.random) { | |
| 38 | const fish = []; | |
| 39 | for (let i = 0; i < 4; i++) fish.push(spawn(rng, true)); | |
| 40 | return { | |
| 41 | phase: 'play', time: 0, fish, spawnIn: SPAWN_EVERY, rng, | |
| 42 | hook: 0, dir: 1, holding: false, hooked: null, tension: 0, | |
| 43 | score: 0, strikes: 0, caught: { perch: 0, trout: 0, pike: 0 }, outcome: null, | |
| 44 | best: Math.max(0, Math.floor(best) || 0), record: false, | |
| 45 | lastBite: -99, lastSnap: -99, lastLand: null, landedAt: -99, | |
| 46 | }; | |
| 47 | } | |
| 48 | function setHold(state, on) { state.holding = !!on; return state; } | |
| 49 | const fighting = state => !!state.hooked; | |
| 50 | const tensionRatio = state => clamp(state.tension / TENSION_MAX, 0, 1); | |
| 51 | ||
| 52 | function end(state, outcome) { | |
| 53 | state.phase = 'over'; | |
| 54 | state.outcome = outcome; | |
| 55 | state.holding = false; | |
| 56 | if (state.score > state.best) { state.best = state.score; state.record = true; } | |
| 57 | } | |
| 58 | // the first free fish at the hook's depth that crosses it takes the bait | |
| 59 | function biteCheck(state) { | |
| 60 | for (const f of state.fish) { | |
| 61 | if (Math.abs(f.depth - state.hook) <= BITE_BAND && Math.abs(f.x - HOOK_X) <= BITE_REACH) { | |
| 62 | state.hooked = f; | |
| 63 | state.fish = state.fish.filter(g => g !== f); | |
| 64 | f.x = HOOK_X; | |
| 65 | state.tension = Math.max(state.tension, 10); | |
| 66 | state.lastBite = state.time; | |
| 67 | return f; | |
| 68 | } | |
| 69 | } | |
| 70 | return null; | |
| 71 | } | |
| 72 | function land(state) { | |
| 73 | const f = state.hooked, k = KINDS[f.kind]; | |
| 74 | state.score += k.value; | |
| 75 | state.caught[f.kind]++; | |
| 76 | state.lastLand = f.kind; | |
| 77 | state.landedAt = state.time; | |
| 78 | state.hooked = null; | |
| 79 | state.hook = 0; state.dir = 1; state.tension = 0; | |
| 80 | } | |
| 81 | function snap(state) { | |
| 82 | state.strikes++; | |
| 83 | state.lastSnap = state.time; | |
| 84 | state.hooked = null; | |
| 85 | state.hook = 0; state.dir = 1; state.tension = 0; | |
| 86 | if (state.strikes >= MAX_STRIKES) end(state, 'snapped'); | |
| 87 | } | |
| 88 | function swim(state, dt) { | |
| 89 | for (const f of state.fish) f.x += f.dir * KINDS[f.kind].speed * dt; | |
| 90 | state.fish = state.fish.filter(f => f.x > -2 && f.x < WIDTH + 2); | |
| 91 | state.spawnIn -= dt; | |
| 92 | if (state.spawnIn <= 0) { | |
| 93 | state.spawnIn += SPAWN_EVERY; | |
| 94 | if (state.fish.length < MAX_FISH) state.fish.push(spawn(state.rng, false)); | |
| 95 | } | |
| 96 | } | |
| 97 | function tick(state, dt) { | |
| 98 | state.time += dt; | |
| 99 | swim(state, dt); | |
| 100 | if (state.hooked) { | |
| 101 | const k = KINDS[state.hooked.kind]; | |
| 102 | if (state.holding) { | |
| 103 | state.tension += (REEL_RISE + k.pull) * dt; | |
| 104 | state.hook -= REEL * dt; | |
| 105 | } else { | |
| 106 | state.tension -= REST_FALL * dt; | |
| 107 | state.hook = Math.min(DEPTH_MAX, state.hook + k.run * dt); | |
| 108 | } | |
| 109 | state.tension = Math.max(0, state.tension); | |
| 110 | state.hooked.depth = state.hook; | |
| 111 | if (state.tension >= TENSION_MAX) snap(state); | |
| 112 | else if (state.hook <= 0) land(state); | |
| 113 | } else { | |
| 114 | state.tension = Math.max(0, state.tension - REST_FALL * dt); | |
| 115 | if (state.holding) { // out to the bottom, then back up, and so on while held | |
| 116 | state.hook += state.dir * LET_OUT * dt; | |
| 117 | if (state.hook >= DEPTH_MAX) { state.hook = DEPTH_MAX; state.dir = -1; } | |
| 118 | else if (state.hook <= 0) { state.hook = 0; state.dir = 1; } | |
| 119 | } | |
| 120 | biteCheck(state); | |
| 121 | } | |
| 122 | if (state.phase === 'play' && state.time >= ROUND) { state.time = ROUND; end(state, 'time'); } | |
| 123 | } | |
| 124 | function step(state, dt) { | |
| 125 | if (state.phase !== 'play' || !(dt > 0)) return state; | |
| 126 | let left = Math.min(dt, 1); | |
| 127 | while (left > 1e-9 && state.phase === 'play') { | |
| 128 | const h = Math.min(STEP, left); | |
| 129 | tick(state, h); | |
| 130 | left -= h; | |
| 131 | } | |
| 132 | return state; | |
| 133 | } | |
| 134 | function restart(state) { | |
| 135 | Object.assign(state, newState(state.best, state.rng)); | |
| 136 | return state; | |
| 137 | } | |
| 138 | ||
| 139 | const api = { | |
| 140 | ROUND, MAX_STRIKES, WIDTH, HOOK_X, DEPTH_MAX, LET_OUT, REEL, BITE_BAND, BITE_REACH, TENSION_MAX, MAX_FISH, KINDS, NAMES, | |
| 141 | newState, setHold, step, restart, fighting, tensionRatio, | |
| 142 | }; | |
| 143 | if (typeof module !== 'undefined' && module.exports) module.exports = api; | |
| 144 | else root.IceFishing = api; | |
| 145 | })(typeof window !== 'undefined' ? window : globalThis); |
ice-fishing/hole.test.mjs added +170
| @@ -0,0 +1,170 @@ | ||
| 1 | import { test, expect } from 'bun:test'; | |
| 2 | import { createRequire } from 'node:module'; | |
| 3 | ||
| 4 | const I = createRequire(import.meta.url)('./hole.js'); | |
| 5 | const empty = () => { const s = I.newState(0, () => .5); s.fish = []; s.spawnIn = 1e9; return s; }; | |
| 6 | const run = (s, seconds) => { for (let i = 0; i < Math.round(seconds * 30) && s.phase === 'play'; i++) I.step(s, 1 / 30); return s; }; | |
| 7 | // a small seeded LCG, so a run that spawns fish can be reproduced | |
| 8 | const seeded = (seed = 7) => () => (seed = (seed * 1664525 + 1013904223) >>> 0) / 4294967296; | |
| 9 | const fishAt = (kind, x = I.HOOK_X) => ({ kind, depth: I.KINDS[kind].depth, x, dir: 1 }); | |
| 10 | // a state with the hook on a fish of `kind` | |
| 11 | const hooked = kind => { const s = empty(); s.hook = I.KINDS[kind].depth; s.hooked = fishAt(kind); s.tension = 10; return s; }; | |
| 12 | ||
| 13 | test('holding lets line out and releasing stops the hook', () => { | |
| 14 | const s = empty(); | |
| 15 | I.setHold(s, true); | |
| 16 | run(s, 1); | |
| 17 | expect(s.hook).toBeCloseTo(I.LET_OUT, 1); | |
| 18 | I.setHold(s, false); | |
| 19 | const at = s.hook; | |
| 20 | run(s, 1); | |
| 21 | expect(s.hook).toBe(at); | |
| 22 | }); | |
| 23 | ||
| 24 | test('the line turns at the bottom and comes back up while held', () => { | |
| 25 | const s = empty(); | |
| 26 | I.setHold(s, true); | |
| 27 | run(s, I.DEPTH_MAX / I.LET_OUT + 1); | |
| 28 | expect(s.hook).toBeLessThan(I.DEPTH_MAX); | |
| 29 | expect(s.hook).toBeGreaterThan(0); | |
| 30 | }); | |
| 31 | ||
| 32 | test('a fish bites only at its depth', () => { | |
| 33 | const near = empty(); | |
| 34 | near.fish = [fishAt('trout')]; | |
| 35 | near.hook = I.KINDS.trout.depth + 0.2; | |
| 36 | run(near, 0.05); | |
| 37 | expect(near.hooked && near.hooked.kind).toBe('trout'); | |
| 38 | const far = empty(); | |
| 39 | far.fish = [fishAt('trout')]; | |
| 40 | far.hook = I.KINDS.perch.depth; | |
| 41 | run(far, 0.05); | |
| 42 | expect(far.hooked).toBe(null); | |
| 43 | }); | |
| 44 | ||
| 45 | test('a fish crossing the hook bites, one far along the lake does not', () => { | |
| 46 | const s = empty(); | |
| 47 | s.hook = I.KINDS.perch.depth; | |
| 48 | s.fish = [{ ...fishAt('perch', I.HOOK_X - 3), dir: 1 }]; | |
| 49 | run(s, 0.3); | |
| 50 | expect(s.hooked).toBe(null); | |
| 51 | run(s, 1.2); | |
| 52 | expect(s.hooked && s.hooked.kind).toBe('perch'); | |
| 53 | expect(s.fish.length).toBe(0); | |
| 54 | }); | |
| 55 | ||
| 56 | test('reeling raises tension and resting lowers it', () => { | |
| 57 | const s = hooked('trout'); | |
| 58 | I.setHold(s, true); | |
| 59 | run(s, .5); | |
| 60 | const high = s.tension; | |
| 61 | expect(high).toBeGreaterThan(10); | |
| 62 | I.setHold(s, false); | |
| 63 | run(s, .3); | |
| 64 | expect(s.tension).toBeLessThan(high); | |
| 65 | }); | |
| 66 | ||
| 67 | test('a bigger fish pulls harder', () => { | |
| 68 | const rise = kind => { const s = hooked(kind); I.setHold(s, true); run(s, .3); return s.tension; }; | |
| 69 | expect(rise('pike')).toBeGreaterThan(rise('trout')); | |
| 70 | expect(rise('trout')).toBeGreaterThan(rise('perch')); | |
| 71 | }); | |
| 72 | ||
| 73 | test('tension at the top snaps the line and adds a strike', () => { | |
| 74 | const s = hooked('pike'); | |
| 75 | I.setHold(s, true); | |
| 76 | while (s.strikes === 0 && s.time < 10) I.step(s, 1 / 30); | |
| 77 | expect(s.strikes).toBe(1); | |
| 78 | expect(s.hooked).toBe(null); | |
| 79 | expect(s.tension).toBe(0); | |
| 80 | expect(s.hook).toBe(0); | |
| 81 | expect(s.score).toBe(0); | |
| 82 | expect(s.phase).toBe('play'); | |
| 83 | }); | |
| 84 | ||
| 85 | test('a landed pike scores 3 and is counted in the bucket', () => { | |
| 86 | const s = hooked('pike'); | |
| 87 | s.hook = .5; | |
| 88 | s.fish = []; | |
| 89 | I.setHold(s, true); | |
| 90 | run(s, .5); | |
| 91 | expect(s.score).toBe(3); | |
| 92 | expect(s.caught.pike).toBe(1); | |
| 93 | expect(s.lastLand).toBe('pike'); | |
| 94 | expect(s.hooked).toBe(null); | |
| 95 | }); | |
| 96 | ||
| 97 | test('a perch is worth 1 and a trout 2', () => { | |
| 98 | expect(I.KINDS.perch.value).toBe(1); | |
| 99 | expect(I.KINDS.trout.value).toBe(2); | |
| 100 | const s = hooked('trout'); | |
| 101 | s.hook = .3; | |
| 102 | I.setHold(s, true); | |
| 103 | run(s, .3); | |
| 104 | expect(s.score).toBe(2); | |
| 105 | }); | |
| 106 | ||
| 107 | test('easing off lets a big fish be landed without a snap', () => { | |
| 108 | const s = hooked('pike'); | |
| 109 | for (let i = 0; i < 400 && s.phase === 'play' && s.hooked; i++) { | |
| 110 | I.setHold(s, s.tension < 60); | |
| 111 | I.step(s, 1 / 30); | |
| 112 | } | |
| 113 | expect(s.strikes).toBe(0); | |
| 114 | expect(s.score).toBe(3); | |
| 115 | }); | |
| 116 | ||
| 117 | test('easing off lets the fish run the hook deeper', () => { | |
| 118 | const s = hooked('pike'); | |
| 119 | s.hook = 3; | |
| 120 | run(s, 1); | |
| 121 | expect(s.hook).toBeGreaterThan(3); | |
| 122 | }); | |
| 123 | ||
| 124 | test('three strikes end the round', () => { | |
| 125 | const s = empty(); | |
| 126 | for (let n = 0; n < 3; n++) { | |
| 127 | s.hooked = fishAt('pike'); | |
| 128 | s.hook = 7; | |
| 129 | s.tension = 99; | |
| 130 | I.setHold(s, true); | |
| 131 | run(s, .2); | |
| 132 | } | |
| 133 | expect(s.strikes).toBe(3); | |
| 134 | expect(s.phase).toBe('over'); | |
| 135 | expect(s.outcome).toBe('snapped'); | |
| 136 | }); | |
| 137 | ||
| 138 | test('the round ends after 60 seconds and keeps the best', () => { | |
| 139 | const s = I.newState(2, () => .5); | |
| 140 | s.score = 5; | |
| 141 | run(s, 61); | |
| 142 | expect(s.phase).toBe('over'); | |
| 143 | expect(s.outcome).toBe('time'); | |
| 144 | expect(s.time).toBe(I.ROUND); | |
| 145 | expect(s.best).toBe(5); | |
| 146 | expect(s.record).toBe(true); | |
| 147 | I.restart(s); | |
| 148 | expect(s.phase).toBe('play'); | |
| 149 | expect(s.best).toBe(5); | |
| 150 | expect(s.score).toBe(0); | |
| 151 | }); | |
| 152 | ||
| 153 | test('fish swim across at their kind depth and new ones arrive', () => { | |
| 154 | const s = I.newState(0, seeded()); | |
| 155 | run(s, 20); | |
| 156 | expect(s.fish.length).toBeGreaterThan(0); | |
| 157 | expect(s.fish.length).toBeLessThanOrEqual(I.MAX_FISH); | |
| 158 | for (const f of s.fish) expect(f.depth).toBe(I.KINDS[f.kind].depth); | |
| 159 | expect(I.KINDS.perch.depth).toBeLessThan(I.KINDS.trout.depth); | |
| 160 | expect(I.KINDS.trout.depth).toBeLessThan(I.KINDS.pike.depth); | |
| 161 | }); | |
| 162 | ||
| 163 | test('nothing moves once the round is over', () => { | |
| 164 | const s = empty(); | |
| 165 | s.phase = 'over'; | |
| 166 | I.setHold(s, true); | |
| 167 | I.step(s, 1); | |
| 168 | expect(s.hook).toBe(0); | |
| 169 | expect(s.time).toBe(0); | |
| 170 | }); |
ice-fishing/index.html added +456
| @@ -0,0 +1,456 @@ | ||
| 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>Ice Fishing</title> | |
| 7 | <!-- og:begin --> | |
| 8 | <meta name="description" content="Drop a line through the ice and reel each fish up before it snaps: hold to let out line, a fish at the hook depth bites, hold to reel but ease off as the tension rises"> | |
| 9 | <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/ice-fishing/"> | |
| 10 | <meta property="og:type" content="website"> | |
| 11 | <meta property="og:site_name" content="Pixel Plays"> | |
| 12 | <meta property="og:title" content="Ice Fishing"> | |
| 13 | <meta property="og:description" content="Drop a line through the ice and reel each fish up before it snaps: hold to let out line, a fish at the hook depth bites, hold to reel but ease off as the tension rises"> | |
| 14 | <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/ice-fishing/"> | |
| 15 | <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/ice-fishing.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="Ice Fishing: the opening scene of the game"> | |
| 20 | <meta name="twitter:card" content="summary_large_image"> | |
| 21 | <!-- og:end --> | |
| 22 | <style> | |
| 23 | :root { : #1c1b19; : #8b877f; : #fff; : #d6452f; } | |
| 24 | * { box-sizing: border-box; } | |
| 25 | html, body { height: 100%; margin: 0; background: var(); color: var(); } | |
| 26 | body { font: 13px/1.35 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; overflow: hidden; } | |
| 27 | #stage { position: fixed; inset: 0; display: grid; place-items: center; } | |
| 28 | canvas { display: block; image-rendering: pixelated; touch-action: none; cursor: pointer; outline: none; user-select: none; -webkit-user-select: none; } | |
| 29 | .hud { position: fixed; left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); display: flex; justify-content: space-between; gap: 16px; pointer-events: none; } | |
| 30 | #scores { position: fixed; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); display: grid; gap: 2px; pointer-events: none; } | |
| 31 | #scores b { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 5ch; } | |
| 32 | #scores span { color: var(); font-variant-numeric: tabular-nums; min-height: 1.35em; } | |
| 33 | #tension { width: 120px; height: 8px; margin-top: 4px; border: 1px solid var(); position: relative; overflow: hidden; } | |
| 34 | #tension i { position: absolute; inset: 0; background: var(); transform: scaleX(0); transform-origin: left; } | |
| 35 | #tension.high i { background: var(); } | |
| 36 | #tension::after { content: ""; position: absolute; top: 0; bottom: 0; left: 75%; border-left: 1px dotted var(); } | |
| 37 | #bottom { bottom: max(14px, env(safe-area-inset-bottom)); align-items: flex-end; } | |
| 38 | #notes { display: grid; gap: 2px; } | |
| 39 | #notes span { color: var(); min-height: 1.35em; } | |
| 40 | #actions { display: flex; gap: 22px; align-items: flex-end; } | |
| 41 | button { pointer-events: auto; font: inherit; color: var(); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; } | |
| 42 | button:hover, button:focus-visible, button[aria-pressed="true"] { color: var(); } | |
| 43 | </style> | |
| 44 | </head> | |
| 45 | <body> | |
| 46 | <div id="stage"><canvas id="c" tabindex="0" aria-label="Ice Fishing. Press and hold the canvas, or hold space, to let line out; release to stop. Keep holding and at the bottom the line turns and comes back up. When a fish bites, hold to reel and let go to ease the tension, because a line at full tension snaps. Land as many fish as you can in 60 seconds; three snapped lines end the round."></canvas></div> | |
| 47 | <div id="scores"> | |
| 48 | <b id="score">0</b><span id="meta"></span><span id="bucket"></span> | |
| 49 | <div id="tension" role="meter" aria-label="Line tension" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><i id="tension-fill"></i></div> | |
| 50 | </div> | |
| 51 | <div class="hud" id="bottom"> | |
| 52 | <div id="notes"><span id="status" role="status" aria-live="polite"></span><span>hold to let out line, then to reel</span></div> | |
| 53 | <div id="actions"><button id="mute" type="button" aria-pressed="false">sound on</button></div> | |
| 54 | </div> | |
| 55 | <script src="../shell.js"></script> | |
| 56 | <script> | |
| 57 | PixelPlays.mount({ | |
| 58 | id: 'ice-fishing', | |
| 59 | rules: [ | |
| 60 | 'Hold the canvas or space to let line out; release to stop. Keep holding: at the bottom the line turns and comes back up. A fish crossing the hook at its depth bites.', | |
outdated
Tell the player how to bring an empty hook back up: something like 'keep holding: at the bottom the line turns and comes back up'. Make the same change in the canvas aria-label on line 46. |
||
| 61 | 'Perch swim shallow (1 point), trout in the middle (2), pike deep (3).', | |
| 62 | 'Once hooked, hold to reel. Tension climbs while you reel, faster for a bigger fish: let go to let it fall.', | |
| 63 | 'Full tension snaps the line and costs a strike. 60 seconds, or three snaps.', | |
| 64 | ], | |
| 65 | }); | |
| 66 | </script> | |
| 67 | <script>window.PP_SCENE = { originY: -38, shadowX: 1.2, shadowY: -.2 };</script> | |
| 68 | <script src="../engine.js"></script> | |
| 69 | <script src="hole.js"></script> | |
| 70 | <script> | |
| 71 | 'use strict'; | |
| 72 | ||
| 73 | const BEST_KEY = 'pixel-plays-ice-fishing-best'; | |
| 74 | const HALF = 8, FACE_Z = 10.2, ICE_T = .8; // the lake block: half-width, depth of the water face, thickness of the ice | |
| 75 | const ICE = [[168, 204, 226], [184, 216, 234], [202, 228, 242]], FROST = [236, 245, 251], CRACK = [120, 156, 190]; | |
| 76 | const HOLE_R = 1.2, HOLE_AT = [0, HALF - 1.7]; | |
| 77 | const WATER = [[96, 176, 200], [64, 140, 176], [44, 108, 156], [30, 78, 128], [20, 52, 98]]; | |
| 78 | const SILT = [[96, 88, 108], [78, 72, 96]], OUTLINE = [22, 36, 64]; | |
| 79 | const HOLE_WATER = rgb(18, 46, 84), RIM = rgb(150, 188, 212); | |
| 80 | const INK3 = rgb(28, 27, 25), LINE_FREE = [236, 242, 250], LINE_ICE = [44, 62, 96]; | |
| 81 | const FLASH = rgb(255, 214, 10), SNAP = rgb(214, 69, 47); | |
| 82 | const KIND_COLOR = { | |
| 83 | perch: { body: [196, 170, 58], belly: [232, 222, 150], fin: [214, 96, 44], len: 8, half: 2, stripe: [86, 88, 40] }, | |
| 84 | trout: { body: [188, 120, 118], belly: [240, 216, 206], fin: [150, 84, 100], len: 11, half: 2.4, stripe: [110, 66, 80] }, | |
| 85 | pike: { body: [70, 134, 86], belly: [190, 214, 150], fin: [48, 96, 70], len: 15, half: 2.4, stripe: [34, 78, 58] }, | |
| 86 | }; | |
| 87 | const HOOK_FACE_X = IceFishing.HOOK_X - IceFishing.WIDTH / 2; | |
| 88 | const facePoint = (xLake, depth) => project(xLake - IceFishing.WIDTH / 2, HALF, -(depth + ICE_T)); | |
| 89 | const holeAt = project(HOLE_AT[0], HOLE_AT[1], 0); | |
| 90 | const faceMask = new Uint8Array(W * H); | |
| 91 | ||
| 92 | /* ---------- state ---------- */ | |
| 93 | const best0 = (() => { try { return Number(localStorage.getItem(BEST_KEY)) || 0; } catch (e) { return 0; } })(); | |
| 94 | const G = IceFishing.newState(best0); | |
| 95 | let time = 0, status = '', overFor = 0, lastOver = false, seen = { bite: -99, snap: -99, land: -99 }; | |
| 96 | const nodes = { | |
| 97 | score: document.getElementById('score'), meta: document.getElementById('meta'), bucket: document.getElementById('bucket'), | |
| 98 | status: document.getElementById('status'), tension: document.getElementById('tension'), fill: document.getElementById('tension-fill'), | |
| 99 | }; | |
| 100 | ||
| 101 | /* ---------- the lake block ---------- */ | |
| 102 | const mix = (a, b, t) => rgb(lerp(a[0], b[0], t), lerp(a[1], b[1], t), lerp(a[2], b[2], t)); | |
| 103 | function topColor(x, y, ix, iy) { | |
| 104 | if (x > HALF || y > HALF) return 0; | |
| 105 | // the two back sides are ragged and dissolve into the white | |
| 106 | const back = Math.max(-x, -y) / HALF; | |
| 107 | const rough = back + (noise(x * 1.3, y * 1.3) - .5) * .1; | |
| 108 | if (rough > 1.04) return 0; | |
| 109 | if (rough > .94 && hash(ix, iy) < (rough - .94) / .1) return 0; | |
| 110 | const d = Math.hypot(x - HOLE_AT[0], y - HOLE_AT[1]) + (noise(x * 2, y * 2) - .5) * .12; | |
| 111 | if (d < HOLE_R) return HOLE_WATER; | |
| 112 | if (d < HOLE_R + .3) return RIM; | |
| 113 | if (Math.abs(noise(x * .55 + 4, y * .55) - .5) < .011 && hash(ix, iy) > .15) return rgb(...CRACK); | |
| 114 | const t = noise(x * .8, y * .8) * 1.1 + (hash(ix, iy) - .5) * .35; | |
| 115 | if (noise(x * .5 + 9, y * .5 + 3) > .72 && t > .55) return rgb(...FROST); // a drift of snow settled on the ice | |
| 116 | return rgb(...ICE[clamp(Math.floor(t * 3), 0, 2)]); | |
| 117 | } | |
| 118 | // the cut-away faces: pixels are traced back onto the plane y = HALF (front left, water) and x = HALF (front right, darker) | |
| 119 | function faceColor(ix, iy, ix0, shade) { | |
| 120 | const sx = ix + .5, sy = iy + .5, u = (sx - OX) / S; | |
| 121 | let x, y, v; | |
| 122 | if (u <= 0) { x = u * R2 + HALF; y = HALF; if (x < -HALF || x > HALF) return 0; v = (x + y) / R2; } | |
| 123 | else { y = HALF - u * R2; x = HALF; if (y < -HALF || y > HALF) return 0; v = (x + y) / R2; } | |
| 124 | const z = (v * SIN - (sy - OY) / S) / COS; | |
| 125 | if (z > 0 || z < -FACE_Z) return 0; | |
| 126 | const side = u > 0 ? .7 : 1; | |
| 127 | const depth = -z, b = bayerAt(ix, iy); | |
| 128 | let c; | |
| 129 | if (depth < ICE_T) c = rgb(...ICE[depth < .15 ? 2 : 1]); | |
| 130 | else if (depth > FACE_Z - .7) c = rgb(...SILT[b > .5 ? 0 : 1]); | |
| 131 | else { | |
| 132 | const t = clamp((depth - ICE_T) / (FACE_Z - .7 - ICE_T), 0, 1) * 4; | |
| 133 | c = rgb(...WATER[clamp(Math.floor(t + (b - .5) * .8 + .1), 0, 4)]); | |
| 134 | } | |
| 135 | if (side < 1) c = rgb((c & 255) * .62, (c >> 8 & 255) * .62, (c >> 16 & 255) * .8); | |
| 136 | return [c, v * COS + z * SIN]; | |
| 137 | } | |
| 138 | function bakeBlock() { | |
| 139 | for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) { | |
| 140 | const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = topColor(g.x, g.y, ix, iy); | |
| 141 | if (c) { pix[i] = c; ground[i] = 1; zb[i] = (g.x + g.y) / R2 * COS; continue; } | |
| 142 | const f = faceColor(ix, iy); | |
| 143 | if (f) { pix[i] = f[0]; zb[i] = f[1]; faceMask[i] = 1; } | |
| 144 | } | |
| 145 | // a dark line round the cut-away, and small depth ticks down its left edge | |
| 146 | const edge = []; | |
| 147 | for (let iy = 1; iy < H - 1; iy++) for (let ix = 1; ix < W - 1; ix++) { | |
| 148 | const i = iy * W + ix; | |
| 149 | if (!faceMask[i]) continue; | |
| 150 | if ([i - 1, i + 1, i - W, i + W].some(j => !faceMask[j] && !ground[j])) edge.push(i); | |
| 151 | } | |
| 152 | for (const i of edge) pix[i] = rgb(...OUTLINE); | |
| 153 | for (let d = 1; d <= IceFishing.DEPTH_MAX; d++) { | |
| 154 | const p = facePoint(0, d), sy = Math.round(p.sy), sx = Math.round(project(-HALF, HALF, 0).sx); | |
| 155 | for (let k = 1; k <= (d % 3 === 0 ? 5 : 3); k++) if (faceMask[sy * W + sx + k]) pix[sy * W + sx + k] = rgb(190, 226, 240); | |
| 156 | } | |
| 157 | } | |
| 158 | ||
| 159 | /* ---------- baked scenery ---------- */ | |
| 160 | const colorOf = c => () => c; | |
| 161 | function stool([x, y]) { | |
| 162 | const wood = [150, 104, 70]; | |
| 163 | for (const a of [0, 2.1, 4.2]) capsule([x + Math.cos(a) * .4, y + Math.sin(a) * .4, .85], [x + Math.cos(a) * .55, y + Math.sin(a) * .55, .05], .1, .08, colorOf(wood), 'solid'); | |
| 164 | capsule([x - .12, y, .95], [x + .12, y, .95], .58, .58, colorOf([196, 70, 58]), 'solid'); | |
| 165 | castShadow(x, y, .9, .65, 1, .2); castShadow(x, y, .2, .5, 1, .2); | |
| 166 | } | |
| 167 | function tackleBox([x, y]) { | |
| 168 | box(x - .65, y - .4, 0, x + .65, y + .4, .55, [58, 118, 164], 3); | |
| 169 | capsule([x - .35, y, .6], [x + .35, y, .6], .09, .09, colorOf([230, 210, 120]), 'solid'); | |
| 170 | castShadow(x, y, .3, .75, 1, .2); castShadow(x + .3, y, .6, .5, 1, .2); | |
| 171 | } | |
| 172 | function bucket([x, y]) { | |
| 173 | capsule([x, y, .08], [x, y, .95], .55, .7, colorOf([84, 108, 150]), 'solid'); | |
| 174 | sphere(x, y, .98, .6, [24, 40, 70], 'solid'); | |
| 175 | castShadow(x, y, .4, .8, 1, .2); castShadow(x, y, .9, .65, 1, .2); | |
| 176 | } | |
| 177 | const STOOL = [-3.6, 2.6], BOX = [3.2, 2.9], BUCKET = [5.4, 4.7]; | |
| 178 | const bucketAt = project(BUCKET[0], BUCKET[1], 1); | |
| 179 | function bake() { | |
| 180 | ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0); faceMask.fill(0); | |
| 181 | zb.fill(-1e9); | |
| 182 | pix.fill(rgb(255, 255, 255)); | |
| 183 | bakeBlock(); | |
| 184 | groundZ.set(zb); | |
| 185 | stool(STOOL); tackleBox(BOX); bucket(BUCKET); | |
| 186 | bakeOcclusion(); | |
| 187 | staticShadow.set(shadowMask); | |
| 188 | applyShadows(groundZ); | |
| 189 | bakedPix.set(pix); | |
| 190 | bakedZ.set(zb); | |
| 191 | } | |
| 192 | ||
| 193 | /* ---------- fish ---------- */ | |
| 194 | // each kind is a sprite facing right, built once: [dx, dy, colour] with a dark outline round it | |
| 195 | function buildFish(k) { | |
| 196 | const { body, belly, fin, len, half, stripe } = KIND_COLOR[k], cells = new Map(), put = (x, y, c) => cells.set(x + ',' + y, [x, y, c]); | |
| 197 | for (let dx = 0; dx < len; dx++) { | |
| 198 | const t = (dx - len * .5) / (len * .5), hh = Math.round(half * Math.sqrt(Math.max(0, 1 - t * t * .9))); | |
| 199 | for (let dy = -hh; dy <= hh; dy++) { | |
| 200 | let c = dy >= hh && hh > 0 ? belly : body; | |
| 201 | if (k === 'perch' && dx % 3 === 1 && dy < hh) c = stripe; | |
| 202 | if (k === 'trout' && hash(dx, dy + 3) > .78) c = stripe; | |
| 203 | if (k === 'pike' && dx > 2 && dx % 4 === 0 && dy < hh) c = stripe; | |
| 204 | put(dx, dy, c); | |
| 205 | } | |
| 206 | } | |
| 207 | for (let t = 1; t <= 3; t++) for (let dy = -t; dy <= t; dy++) put(-t, dy, fin); | |
| 208 | put(Math.round(len * .4), -Math.ceil(half) - 1, fin); | |
| 209 | const out = [...cells.values()]; | |
| 210 | for (const [x, y] of [...cells.values()]) for (const [ox, oy] of [[-1, 0], [1, 0], [0, -1], [0, 1]]) if (!cells.has(x + ox + ',' + (y + oy))) cells.set(x + ox + ',' + (y + oy), [x + ox, y + oy, 'ink']); | |
| 211 | return [...cells.values()].map(([x, y, c]) => [x, y, c === 'ink' ? INK3 : rgb(...c)]); | |
| 212 | } | |
| 213 | const SPRITES = Object.fromEntries(IceFishing.NAMES.map(k => [k, buildFish(k)])); | |
| 214 | const dotAt = (sx, sy, c) => { | |
| 215 | const ix = sx | 0, iy = sy | 0; | |
| 216 | if (ix >= 0 && iy >= 0 && ix < W && iy < H && faceMask[iy * W + ix]) pix[iy * W + ix] = c; | |
| 217 | }; | |
| 218 | // the face slopes down to the right, so the sprite is sheared to lie along it | |
| 219 | function drawFish(f, sx, sy, dir, jitter) { | |
| 220 | const len = KIND_COLOR[f.kind].len; | |
| 221 | for (const [dx, dy, c] of SPRITES[f.kind]) { | |
| 222 | const rel = dir > 0 ? dx - len / 2 : len / 2 - dx; | |
| 223 | dotAt(sx + rel, sy + dy + Math.round(rel * .5) + jitter, c); | |
| 224 | } | |
| 225 | } | |
| 226 | function swimBob(f) { return STILL ? 0 : Math.round(Math.sin(time * 3 + f.x * .9)); } | |
| 227 | function drawFishes() { | |
| 228 | for (const f of G.fish) { | |
| 229 | const p = facePoint(f.x, f.depth); | |
| 230 | drawFish(f, Math.round(p.sx), Math.round(p.sy), f.dir, swimBob(f)); | |
| 231 | } | |
| 232 | if (G.hooked) { | |
| 233 | const p = facePoint(IceFishing.HOOK_X, G.hook), shake = STILL ? 0 : (Math.floor(time * 14) % 2 ? 1 : -1) * (G.holding ? 1 : 0); | |
| 234 | drawFish(G.hooked, Math.round(p.sx), Math.round(p.sy) + 3, 1, shake); | |
| 235 | } | |
| 236 | } | |
| 237 | ||
| 238 | /* ---------- line, rod, hook ---------- */ | |
| 239 | const lineDots = (x0, y0, x1, y1) => { | |
| 240 | const pts = [], n = Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0), 1); | |
| 241 | for (let k = 0; k <= n; k++) pts.push([Math.round(lerp(x0, x1, k / n)), Math.round(lerp(y0, y1, k / n))]); | |
| 242 | return pts; | |
| 243 | }; | |
| 244 | function rodTip() { | |
| 245 | const sag = G.hooked ? .35 + IceFishing.tensionRatio(G) * .8 + (STILL || !G.holding ? 0 : (Math.floor(time * 14) % 2) * .12) : 0; | |
| 246 | return [.2, HALF - 2.4, 2.3 - sag]; | |
| 247 | } | |
| 248 | function drawRod() { | |
| 249 | const tip = rodTip(), base = [STOOL[0] + .7, STOOL[1] + .4, 1.1]; | |
| 250 | capsule(base, tip, .1, .05, colorOf([50, 44, 56]), 'solid'); | |
| 251 | castShadow(base[0], base[1], 1, .2, 1, 0); castShadow(tip[0], tip[1], tip[2], .12, 1, 0); | |
| 252 | sphere(base[0], base[1], 1.1, .22, [120, 120, 130], 'solid'); | |
| 253 | return project(tip[0], tip[1], tip[2]); | |
| 254 | } | |
| 255 | function drawLine(tip) { | |
| 256 | const hook = facePoint(IceFishing.HOOK_X, G.hook), hx = Math.round(holeAt.sx), hy = Math.round(holeAt.sy), by = Math.round(hook.sy); | |
| 257 | const k = IceFishing.tensionRatio(G), taut = lerp(LINE_FREE[1], 70, k); | |
| 258 | const water = rgb(LINE_FREE[0], taut, lerp(LINE_FREE[2], 70, k)), air = rgb(...LINE_ICE); | |
| 259 | const down = []; | |
| 260 | for (let y = hy; y <= by; y++) down.push([hx, y]); | |
| 261 | const upper = lineDots(Math.round(tip.sx), Math.round(tip.sy), hx, hy); | |
| 262 | haloDots(upper); | |
| 263 | drawDots(upper, air); | |
| 264 | for (const [x, y] of down) { | |
| 265 | const i = (y | 0) * W + x; | |
| 266 | pix[i] = faceMask[i] ? water : air; | |
| 267 | } | |
| 268 | // the hook: a small bent wire with the bait on it | |
| 269 | const hs = Math.round(hook.sx), hv = by; | |
| 270 | const wire = rgb(240, 236, 220); | |
| 271 | for (const [dx, dy] of [[0, 1], [0, 2], [0, 3], [1, 4], [2, 3], [2, 2]]) dotAt(hs + dx, hv + dy, wire); | |
| 272 | dotAt(hs, hv + 1, rgb(232, 120, 90)); | |
| 273 | } | |
| 274 | function drawFlashes() { | |
| 275 | const since = G.time - G.lastBite; | |
| 276 | if (since >= 0 && since < .7 && G.hooked) { // a ring of yellow round the hook the moment a fish takes it | |
| 277 | const p = facePoint(IceFishing.HOOK_X, G.hook), r = 5 + since * 22, ring = []; | |
| 278 | for (let a = 0; a < 20; a++) ring.push([Math.round(p.sx + Math.cos(a * Math.PI / 10) * r), Math.round(p.sy + Math.sin(a * Math.PI / 10) * r * .8)]); | |
| 279 | for (const [x, y] of ring) dotAt(x, y, FLASH); | |
| 280 | const bang = [[0, -2], [0, -1], [0, 0], [0, 2]].map(([dx, dy]) => [holeAt.sx + dx - 8, holeAt.sy + dy - 22]); | |
| 281 | haloDots(bang); | |
| 282 | drawDots(bang, FLASH); | |
| 283 | } | |
| 284 | const snapped = G.time - G.lastSnap; | |
| 285 | if (snapped >= 0 && snapped < .6) { // the line parts above the water: two red ends flying apart | |
| 286 | const fly = Math.round(snapped * 30), hx = Math.round(holeAt.sx), hy = Math.round(holeAt.sy); | |
| 287 | const bits = []; | |
| 288 | for (let k = 0; k < 6; k++) { bits.push([hx - 2 - fly * .6 - k, hy - 6 - k + fly * .2], [hx + 2 + fly * .6 + k, hy - 6 - k + fly * .2]); } | |
| 289 | haloDots(bits); | |
| 290 | drawDots(bits, SNAP); | |
| 291 | } | |
| 292 | const landed = G.time - G.landedAt; | |
| 293 | if (landed >= 0 && landed < .6 && G.lastLand) { // the fish arcs from the hole into the bucket | |
| 294 | const t = landed / .6, sx = lerp(holeAt.sx, bucketAt.sx, t), sy = lerp(holeAt.sy, bucketAt.sy, t) - Math.sin(t * Math.PI) * 26; | |
| 295 | const f = G.lastLand, c = rgb(...KIND_COLOR[f].body), dots = []; | |
| 296 | for (let k = 0; k < KIND_COLOR[f].len / 2; k++) dots.push([sx + k - 3, sy + Math.round(k * .3)], [sx + k - 3, sy + 1 + Math.round(k * .3)]); | |
| 297 | haloDots(dots); | |
| 298 | drawDots(dots, c); | |
| 299 | } | |
| 300 | } | |
| 301 | function drawBucketFish() { // the catch sticking out of the bucket, one tick per fish | |
| 302 | const total = G.caught.perch + G.caught.trout + G.caught.pike, dots = []; | |
| 303 | for (let n = 0; n < Math.min(total, 6); n++) dots.push([bucketAt.sx - 5 + n * 2, bucketAt.sy - 3 - (n % 2)]); | |
| 304 | const colors = []; | |
| 305 | for (const k of ['pike', 'trout', 'perch']) for (let n = 0; n < G.caught[k]; n++) colors.push(rgb(...KIND_COLOR[k].body)); | |
| 306 | dots.forEach((d, n) => drawDots([d, [d[0], d[1] + 1]], colors[n])); | |
| 307 | } | |
| 308 | ||
| 309 | /* ---------- snow ---------- */ | |
| 310 | const FLAKES = Array.from({ length: 46 }, (_, n) => ({ | |
| 311 | x: hash(n, 1) * 230, y: hash(n, 2) * 120, speed: 1 + (n % 3), wobble: n * 1.7, | |
| 312 | })); | |
| 313 | function drawSnow() { | |
| 314 | const frame = STILL ? 0 : Math.floor(time * 8), left = OX - 115, top = OY - 58; | |
| 315 | for (const f of FLAKES) { | |
| 316 | const sx = Math.floor(left + (f.x + frame * f.speed * .5) % 230), sy = Math.floor(top + f.y + (STILL ? 0 : Math.round(Math.sin(frame * .4 + f.wobble)))); | |
| 317 | if (sx < 0 || sy < 0 || sx >= W - 1 || sy >= H - 1) continue; | |
| 318 | const i = sy * W + sx; | |
| 319 | if (!ground[i] || bakedPix[i] === 0xffffffff) continue; | |
| 320 | pix[i] = 0xffffffff; | |
| 321 | const j = i + W + 1; // a hard shadow, screen-right | |
| 322 | if (ground[j]) tint(j, .8, .82, .92); | |
| 323 | } | |
| 324 | } | |
| 325 | ||
| 326 | /* ---------- hud ---------- */ | |
| 327 | let shown = ''; | |
| 328 | function renderHud() { | |
| 329 | const pct = Math.round(IceFishing.tensionRatio(G) * 100), left = Math.max(0, Math.ceil(IceFishing.ROUND - G.time)); | |
| 330 | const text = [G.score, G.best, G.strikes, pct, left, G.phase, G.caught.perch, G.caught.trout, G.caught.pike].join('|'); | |
| 331 | if (text === shown) return; | |
| 332 | shown = text; | |
| 333 | nodes.score.textContent = G.score + (G.score === 1 ? ' point' : ' points'); | |
| 334 | nodes.meta.textContent = 'strikes ' + G.strikes + ' of ' + IceFishing.MAX_STRIKES + (G.best ? ' · best ' + G.best : '') + ' · ' + (G.phase === 'play' ? left + ' s' : 'over'); | |
| 335 | nodes.bucket.textContent = 'bucket: ' + G.caught.perch + ' perch · ' + G.caught.trout + ' trout · ' + G.caught.pike + ' pike'; | |
| 336 | nodes.fill.style.transform = 'scaleX(' + (pct / 100).toFixed(2) + ')'; | |
| 337 | nodes.tension.classList.toggle('high', pct >= 75); | |
| 338 | nodes.tension.setAttribute('aria-valuenow', String(pct)); | |
| 339 | } | |
| 340 | function setStatus(text) { | |
| 341 | if (text === status) return; | |
| 342 | status = text; | |
| 343 | nodes.status.textContent = text; | |
| 344 | } | |
| 345 | function statusFor() { | |
| 346 | if (G.phase === 'over') { | |
| 347 | return (G.outcome === 'snapped' ? 'three lines snapped' : 'time') + ' · ' + G.score + (G.score === 1 ? ' point' : ' points') + (G.record ? ' · new best' : '') + ' · tap to play again'; | |
| 348 | } | |
| 349 | if (G.hooked) return G.tension >= 75 ? 'fish on · ease off, the line is about to snap' : 'fish on · hold to reel, let go to ease the tension'; | |
| 350 | if (G.hook > 0 && !G.holding) return 'line at ' + G.hook.toFixed(1) + ' · hold to let out more'; | |
| 351 | return G.holding ? 'letting out line' : 'hold to let out line'; | |
| 352 | } | |
| 353 | ||
| 354 | /* ---------- loop ---------- */ | |
| 355 | function again() { | |
| 356 | if (G.phase === 'over' && overFor > .8) { IceFishing.restart(G); time = 0; overFor = 0; lastOver = false; seen = { bite: -99, snap: -99, land: -99 }; } | |
| 357 | } | |
| 358 | function update(dt) { | |
| 359 | time += dt; | |
| 360 | IceFishing.step(G, dt); | |
| 361 | if (G.lastBite !== seen.bite) { seen.bite = G.lastBite; sound('bite'); } | |
| 362 | if (G.lastSnap !== seen.snap) { seen.snap = G.lastSnap; sound('snap'); } | |
| 363 | if (G.landedAt !== seen.land) { seen.land = G.landedAt; sound('land'); } | |
| 364 | if (G.phase === 'over') { | |
| 365 | overFor += dt; | |
| 366 | if (!lastOver) { | |
| 367 | lastOver = true; | |
| 368 | if (G.record) try { localStorage.setItem(BEST_KEY, String(G.best)); } catch (e) { /* private window: keep it for this visit */ } | |
| 369 | } | |
| 370 | } | |
| 371 | setStatus(statusFor()); | |
| 372 | renderHud(); | |
| 373 | } | |
| 374 | function draw() { | |
| 375 | pix.set(bakedPix); | |
| 376 | zb.set(bakedZ); | |
| 377 | const tip = drawRod(); | |
| 378 | applyShadows(bakedZ); | |
| 379 | shadeEdges(); | |
| 380 | drawBucketFish(); | |
| 381 | drawFishes(); | |
| 382 | drawLine(tip); | |
| 383 | drawFlashes(); | |
| 384 | drawSnow(); | |
| 385 | ctx.putImageData(image, 0, 0); | |
| 386 | } | |
| 387 | ||
| 388 | /* ---------- input ---------- */ | |
| 389 | function hold(on) { | |
| 390 | if (on && G.phase !== 'play') { again(); return; } | |
| 391 | IceFishing.setHold(G, on); | |
| 392 | } | |
| 393 | canvas.addEventListener('pointerdown', e => { | |
| 394 | canvas.focus({ preventScroll: true }); | |
| 395 | ensureAudio(); | |
| 396 | try { canvas.setPointerCapture(e.pointerId); } catch (err) { /* synthetic pointers have nothing to capture */ } | |
| 397 | hold(true); | |
| 398 | }); | |
| 399 | for (const kind of ['pointerup', 'pointercancel']) canvas.addEventListener(kind, () => hold(false)); | |
| 400 | canvas.addEventListener('lostpointercapture', () => hold(false)); | |
| 401 | canvas.addEventListener('contextmenu', e => e.preventDefault()); | |
| 402 | canvas.addEventListener('keydown', e => { | |
| 403 | if (e.key !== ' ' && e.key !== 'Enter') return; | |
| 404 | e.preventDefault(); | |
| 405 | if (!e.repeat) { ensureAudio(); hold(true); } | |
| 406 | }); | |
| 407 | canvas.addEventListener('keyup', e => { if (e.key === ' ' || e.key === 'Enter') hold(false); }); | |
| 408 | addEventListener('blur', () => hold(false)); | |
| 409 | ||
| 410 | /* ---------- sound ---------- */ | |
| 411 | let audio = null, muted = false; | |
| 412 | function ensureAudio() { | |
| 413 | if (audio) { if (audio.state === 'suspended') audio.resume(); return; } | |
| 414 | const AC = window.AudioContext || window.webkitAudioContext; | |
| 415 | if (AC) audio = new AC(); | |
| 416 | } | |
| 417 | function tone(type, from, to, len, vol) { | |
| 418 | const now = audio.currentTime, gain = audio.createGain(), osc = audio.createOscillator(); | |
| 419 | osc.type = type; | |
| 420 | osc.frequency.setValueAtTime(from, now); | |
| 421 | osc.frequency.exponentialRampToValueAtTime(to, now + len); | |
| 422 | gain.gain.setValueAtTime(vol, now); | |
| 423 | gain.gain.exponentialRampToValueAtTime(.0005, now + len); | |
| 424 | osc.connect(gain).connect(audio.destination); | |
| 425 | osc.start(now); osc.stop(now + len + .01); | |
| 426 | } | |
| 427 | function sound(kind) { | |
| 428 | if (!audio || muted) return; | |
| 429 | if (kind === 'bite') { tone('square', 520, 900, .09, .05); tone('square', 900, 1300, .09, .04); } | |
| 430 | else if (kind === 'snap') tone('sawtooth', 900, 120, .25, .08); | |
| 431 | else if (kind === 'land') { tone('triangle', 520, 780, .12, .1); tone('triangle', 780, 1040, .18, .08); } | |
| 432 | } | |
| 433 | const muteButton = document.getElementById('mute'); | |
| 434 | muteButton.addEventListener('click', () => { | |
| 435 | muted = !muted; | |
| 436 | muteButton.textContent = muted ? 'sound off' : 'sound on'; | |
| 437 | muteButton.setAttribute('aria-pressed', String(muted)); | |
| 438 | }); | |
| 439 | ||
| 440 | /* ---------- boot ---------- */ | |
| 441 | addEventListener('resize', fit); | |
| 442 | fit(); | |
| 443 | bake(); | |
| 444 | setStatus(statusFor()); | |
| 445 | renderHud(); | |
| 446 | let last = performance.now(); | |
| 447 | function frame(now) { | |
| 448 | update(Math.min(.04, (now - last) / 1000)); | |
| 449 | last = now; | |
| 450 | draw(); | |
| 451 | requestAnimationFrame(frame); | |
| 452 | } | |
| 453 | requestAnimationFrame(frame); | |
| 454 | </script> | |
| 455 | </body> | |
| 456 | </html> |
index.html +1
| @@ -81,6 +81,7 @@ footer a::after { content: none; } | ||
| 81 | 81 | <li data-kind="Timing" data-input="Hold" style="--accent:#d9a02a"><a href="beekeeper/">Beekeeper</a><span>Smoke the hive calm and lift out honey frames before the bees swarm: gold 3, half 1, a dark brood frame stings</span><span>Game forged by the crew</span><span class="tags">Timing · Hold</span></li> |
| 82 | 82 | <li data-kind="Precision" data-input="Drag" style="--accent:#e0793a"><a href="campfire/">Campfire</a><span>Keep a campfire burning through a 90 second night: drag twigs, branches and logs into the ring, a log smothers a small fire and rain damps the flames</span><span>Game forged by the crew</span><span class="tags">Precision · Drag</span></li> |
| 83 | 83 | <li data-kind="Timing" data-input="Tap" style="--accent:#c0612b"><a href="bread-oven/">Bread Oven</a><span>Slide loaves into a wood-fired oven and pull each one out golden: golden 3, dark 1, a burnt loaf is a strike</span><span>Game forged by the crew</span><span class="tags">Timing · Tap</span></li> |
| 84 | <li data-kind="Timing" data-input="Hold" style="--accent:#6fb3d2"><a href="ice-fishing/">Ice Fishing</a><span>Drop a line through the ice and reel each fish up before it snaps: hold to let out line, a fish at the hook depth bites, hold to reel but ease off as the tension rises</span><span>Game forged by the crew</span><span class="tags">Timing · Hold</span></li> | |
| 84 | 85 | </ul> |
| 85 | 86 | <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> |
| 86 | 87 | </main> |
og/home.png
Binary file not shown.
og/ice-fishing.png added
Binary file not shown.
serve.test.mjs +7
| @@ -170,6 +170,13 @@ test('Bread Oven and its rules script are served without a track', async () => { | ||
| 170 | 170 | expect((await fetch(base + '/bread-oven/oven.js')).status).toBe(200); |
| 171 | 171 | }); |
| 172 | 172 | |
| 173 | test('Ice Fishing and its rules script are served without a track', async () => { | |
| 174 | const page = await fetch(base + '/ice-fishing/'); | |
| 175 | expect(page.status).toBe(200); | |
| 176 | expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8'); | |
| 177 | expect((await fetch(base + '/ice-fishing/hole.js')).status).toBe(200); | |
| 178 | }); | |
| 179 | ||
| 173 | 180 | test('every game and the home page carry share-card tags and a served PNG card', async () => { |
| 174 | 181 | const { games, withTags, ORIGIN, CARD, HOME } = await import('./scripts/og.mjs'); |
| 175 | 182 | const { readFileSync } = await import('node:fs'); |
shell.js +1
| @@ -25,6 +25,7 @@ window.PixelPlays = (() => { | ||
| 25 | 25 | { id: 'beekeeper', title: 'Beekeeper', blurb: 'Smoke the hive calm and lift out honey frames before the bees swarm: gold 3, half 1, a dark brood frame stings', kind: 'Timing', input: 'Hold', accent: '#d9a02a', music: false, forged: true }, |
| 26 | 26 | { id: 'campfire', title: 'Campfire', blurb: 'Keep a campfire burning through a 90 second night: drag twigs, branches and logs into the ring, a log smothers a small fire and rain damps the flames', kind: 'Precision', input: 'Drag', accent: '#e0793a', music: false, forged: true }, |
| 27 | 27 | { id: 'bread-oven', title: 'Bread Oven', blurb: 'Slide loaves into a wood-fired oven and pull each one out golden: golden 3, dark 1, a burnt loaf is a strike', kind: 'Timing', input: 'Tap', accent: '#c0612b', music: false, forged: true }, |
| 28 | { id: 'ice-fishing', title: 'Ice Fishing', blurb: 'Drop a line through the ice and reel each fish up before it snaps: hold to let out line, a fish at the hook depth bites, hold to reel but ease off as the tension rises', kind: 'Timing', input: 'Hold', accent: '#6fb3d2', music: false, forged: true }, | |
| 28 | 29 | ]; |
| 29 | 30 | const MUSIC_VOLUME = .4; |
| 30 | 31 | const CREDITS = [ |
new above
offline
Unseeded
Math.random: if this fails it can't be reproduced. Pass a seeded rng, as the other tests do with() => .5.