Skip to content

Add ghost race: replay your best run - #4

Merged
cmalpass merged 1 commit into
mainfrom
cmalpass-potential-enigma
Aug 26, 2026
Merged

Add ghost race: replay your best run#4
cmalpass merged 1 commit into
mainfrom
cmalpass-potential-enigma

Conversation

@cmalpass

Copy link
Copy Markdown
Owner

What

A local "race yourself" mode: the game records your position each frame (decimated to ~10 Hz), and when a run beats your stored best score for a level, the track is persisted. In later runs a translucent ghost Rex replays that best run alongside you.

Details

  • src/ghost.ts (new) — GhostRecorder (trailing-sample decimation, 6000-pt cap, discards runs under 4 samples) and GhostPlayer (monotonic index walk + linear interpolation, clamped past the track's end, facing from sample direction).
  • src/store.tsgetGhostTrack/saveGhostTrack (tinyrex_ghost_0..2, tinyrex_ghost_daily), getGhostEnabled/setGhostEnabled (default on). Daily tracks are date-stamped with dailySeed() and only replay for the seed they were recorded on.
  • src/game.ts — records during play, saves on new best (hand-built + daily), draws the ghost at 40% alpha with a small "GHOST" tag before the player, G key + menu toggle button, CONTROLS row updated.
  • Tests — 10 new unit tests (decimation timing, min-length discard, cap, interpolation, facing, end state, per-level + daily-seed persistence, malformed rejection, toggle) + 2 integration tests (track saved on new best, ghost loads next run, toggle off). 123/123 passing.

Validation (local — CI is failing for pre-existing unrelated reasons)

  • npm run typecheck
  • npm test — 123/123 ✓
  • npm run build ✓ (single file, ~106 kB / 33 kB gzip)
  • npm run lint
  • Headless Playwright E2E: menu toggle, track saved on new best (~10 Hz samples), ghost active + advancing on next run, real G key toggle persists, no ghost when off, zero page errors ✓

Supersedes nothing; stacks on #3 (Daily Rex).

- GhostRecorder decimates player position to ~10 Hz tracks (capped 6000 pts)
- Track persists per level when the run sets a new best score
- Daily Rex tracks are date-stamped and only replay for the same daily seed
- Translucent ghost Rex with a small tag races alongside the player
- G key / menu button toggles the ghost (persisted, default on)
- 12 new unit tests + 2 integration tests (123 total, all passing)
@cmalpass
cmalpass merged commit 4749f5b into main Aug 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant