# Item `practice`: PEPE RUN free-practice view ## Entry point - **`web/index.html`** loads `web/js/main.mjs`, which imports the engine at **`../game/engine.mjs`** (relative to the page; `new URL('../../game/engine.mjs', import.meta.url)` from the module). It starts each run with `createRun(seed, false)`. - Serve the **repository root** (`python3 -m http.server 8080`) and open `/web/`. Add `?perf=1` for the frame overlay. ## What changed (all under `web/`) | File | Content | | --- | --- | | `web/index.html` | Headline `PEPE RUN` and slogan `RUN. SURVIVE. WIN.`, a 4-cell HUD (distance m, speed m/s, time, best), the playfield canvas with an overlay holding **Play practice**, a touch pad (▲ JUMP / ▼ DUCK), the local practice ranking, and a disabled "Weekly jackpot play — coming soon" panel. Paid actions are reserved: no wallet prompt and no payment. | | `web/css/practice.css` | Mobile-first black/neon-green/gold pixel arcade. The stage height is `min(52vw, 42dvh)`, so the header, HUD, playfield, Play practice and pad fit on the first phone screen. Also covers landscape-phone and desktop layouts, safe-area insets, focus rings and reduced motion. | | `web/js/main.mjs` | Loads the engine and media and wires everything together. Pauses on `visibilitychange`/`pagehide`/`blur`. Uses a ResizeObserver. Exposes `peperunPerf.stats()`. If the engine is missing, shows a red alert naming the URL it tried. | | `web/js/session.mjs` | Fixed 60 Hz accumulator capped at 8 ticks per frame (a stall slows the game instead of teleporting). Snapshots each state, so engines that return a new state and engines that change it in place both work. Interpolates the runner's height and obstacle `xPx` by `id`. Phases: ready / running / paused / countdown (3 s) / dead. Death records the score. A replay grace of 450 ms stops a held key from restarting; seeds come from `crypto.getRandomValues`. | | `web/js/controls.mjs` | Space/↑/W → mask 1, ↓/S → mask 2. Holds are combined with OR and taps are latched, so a tap between ticks still lands on one tick. Multi-touch pointer pads use `aria-pressed`. The key or touch that starts a run is swallowed, so starting does not also jump. P/Esc pause, Enter start, M sound. | | `web/js/hud.mjs` | Pure HUD state: `distanceMm`→m, `speedMmPerSec`→m/s, ticks→m:ss, plus overlay and live-region text for each phase. | | `web/js/storage.mjs` | Local personal best, top-10 practice ranking (a tie goes to the earlier run) and play count. Falls back to memory storage if `localStorage` fails and resets cleanly if the stored data is corrupt. Kept separate from any verified leaderboard. | | `web/js/render.mjs` | Canvas with no image smoothing and DPR awareness. Logical height is 192 px with the ground at y=168 and the runner's front foot at x=112; `obstacle.xPx` is added to that x. Characters: row 0 (Classic), frames 0–3 run, 4–5 duck, 6 rise, 7 fall. Obstacles: row 0 ground, row 1 overhead (`bottomPx>0`), stretched over the exact hitbox. Backgrounds: 320×128 cells, the row is the world (every 500 m, wrapping), columns far/mid/near drawn as parallax. Scroll speed is learned from obstacle motion. If a sprite sheet is missing, vector blocks are drawn instead. | | `web/js/audio.mjs` | Opt-in only: nothing is fetched until the player presses Sound. Plays `run.ogg` looped and slices `cues.wav` using `cues.json` `[startMs,endMs]`, with aliases for the cue names. | | `web/js/perf.mjs` | Ring-buffer frame meter: fps, avg/p95/p99 ms, frames over 20 ms, ticks per frame. | | `web/tests/practice.test.mjs`, `web/tests/fake-engine.mjs` | `node:test` suite. The fake engine has the same contract as the real one and is used only by the tests. | | `web/README.md` | How to serve the merged tree, measure frames, and exercise desktop and touch play. | ## Checks run 1. `node --test web/tests/*.test.mjs` passed **21 of 22, 0 failed, 1 skipped**. The skipped test is the merged-tree one ("game/engine.mjs not in this checkout"). - Controls: key map, tap latching, held duck, jump+duck combined, key repeat, blur release, both touch pads plus two-finger use, start press not sent as a jump, unbind. - HUD state for ready, running, paused, countdown and dead (meters, m/s, best, overlay action labels, live-region text). - Session: `createRun` called with `(seed, false)`; 496 ms → 29 ticks; a 5 s stall is capped at 8 ticks per frame; interpolation; buttons reaching `stepRun`; no ticks while hidden; 3 s countdown with no fast-forward; death → personal best and rank #1; replay grace and a fresh seed; an engine that changes state in place. - Also: sprite frame choice, world index, cue lookup, frame meter, page structure (headline, slogan, Play practice and canvas before the ranking, no inline handlers), and the `../game` and `../media` paths. - The first run had one failure: a floating-point accumulator gave 7 ticks instead of 8 (`web/tests/practice.test.mjs:185`). I fixed it with an epsilon in `web/js/session.mjs` and the suite now passes. 2. `node --check` on every `web/js/*.mjs`: no errors. 3. Scratch smoke test (`test/scratch/smoke.mjs`, not submitted). It copies `web/` beside a stand-in `game/engine.mjs`, then boots `main.mjs` with a stubbed DOM and requestAnimationFrame: - ready shows "PRACTICE | Play practice"; - Space starts the run and does not jump (height 0); - HUD shows "1 m 8.1 m/s"; - visibilitychange moves to paused, Resume click to countdown "3", then running; - the run ended dead at "6 m | New personal best! Practice rank #1.", with one ranking entry and the live region updated; - perf stats: `fps 60, avg 16.67 ms, p95 16.67 ms, long 0/29, ticksPerFrame 1`. This is simulated time, not a real-browser measurement; - a touch Jump after death replayed the run with a new seed. ## Still to verify on the merged tree - That `game/engine.mjs` and `media/**` are present: the last test in `node --test web/tests/*.test.mjs` runs automatically once the engine exists, checks every state and obstacle field, and plays a run through. - Real-browser frame timing (`/web/?perf=1`, `peperunPerf.stats()`) and touch play on a device or in DevTools device mode, as described in `web/README.md`. There was no browser on this machine, so no real FPS was measured. - Sprite cell alignment against the final sheets. `FRONT_FOOT_IN_CELL = 44` in `render.mjs` is an assumption about where the front foot sits in a 64 px cell; change it if the art differs. - That `cues.json` names match the aliases in `audio.mjs`. - Safari before version 17 cannot play `.ogg`; in that case only the music is silent. - No dependencies were added and no file outside `web/` was changed.