# Aurora / Relay — native Squeak endless runner

A complete original three-lane perspective runner and ten-stage Smalltalk workshop.
The web page teaches and distributes it; the game itself runs in native Squeak 6.1.
No JavaScript gameplay, game-engine package, external art, network service or audio is required.

## Run the game

1. Save a copy of a Squeak 6.1 learning image.
2. Use File List → fileIn on `endless-runner-final.st`. Do not paste the chunk file into a Workspace.
3. In a Workspace, Do It: `ARApp open`.
4. Enter starts or pauses. A/D or Left/Right changes one lane per tap. W/Up/Space jumps. S/Down slides. Escape pauses. R restarts in ready state.
5. The scene owns keyboard focus; clicking it restores focus. Losing focus pauses and clears keys. Start/Pause and Restart also restore scene focus.
6. Close the native window to stop stepping and clear focus. About 1000×735 pixels accommodates its frame and shadow.

Orange hurdles can be jumped. Violet arches require a centered slide; their support posts collide too. Coral walls require a lane change. Gold sparks mark the guaranteed open lane. Score is floor(distance) + 25 per spark. The first central rows are hurdle, arch and wall; the right lane is their safe route. Restart replays seed 314159. To use a different deterministic route, evaluate `app game seed: 98765` on an app reference, then `app refresh`; this resets the model to ready. Prefer doing this while paused.

## Build it cumulatively

`endless-runner-01.st` through `endless-runner-10.st` are full, runnable checkpoints. The final file has the same game implementation as checkpoint 10. Each stage’s exact method replacements, Workspace block, expected result, explanations, pitfalls and native image appear in `content/endless-runner.json` and the tutorial.

1. Coordinates before pixels
2. Camera perspective and three-lane road
3. Polymorphic obstacle geometry
4. Continuous movement to target lanes
5. Jump/slide physics and relative forward travel
6. Swept contacts and one-shot scoring
7. Fair seeded endless generation and bounded speed
8. Native keys, focus and session states
9. Single native scheduler and lifecycle
10. Complete dashboard and playable relay

Close the old window before filing in the next source. Move forward in order. To revisit an earlier stage, use a fresh image: filing older methods into a newer image does not remove later classes or methods.

## Objects and message flow

- ARVector: XYZ value and arithmetic
- ARCamera: world-to-camera transform, depth guards and perspective projection
- ARObstacle: geometry, movement, swept-box contact and one-shot contact dispatch
- ARWall / ARHurdle / ARArch / ARSpark: obstacle and collectible specializations; arch checks its raised beam and both posts
- ARRunner: actual X, target lane, feet, jump velocity and slide duration
- ARGenerator: seeded choices, row spacing, open-lane invariant and ahead-of-player refill
- ARRun: state, active objects, distance, score, four-slice physics and contact resolution
- ARController: key-down edges, repeat suppression and intentions
- ARView: native events, side-effect-free perspective rendering and HUD
- ARApp: native controls, focus, one clock and cleanup
- ARWindow: fixed layout and native window integration

Native KeyboardEvent → ARView → ARController → a model intention.
Morphic scheduler → ARApp step → ARRun tick → four 0.01-second slices → ARRunner advance / swept contacts / cleanup / generation → refresh.
Paint only reads state. Only ARApp steps. `wantsStepsIn:` answers false and `isStepping` guards startStepping.

## Fairness and endless storage

Lane centers are 2.5 units apart; lateral speed is 18 units/s, so an adjacent change takes 0.139s. Rows are 28 units apart, maximum forward speed 22 units/s. Excluding the full 1.6-unit longitudinal collision envelope leaves 1.2s to change between rows. Safe lanes differ by at most one lane. Following them never requires jumping or sliding. This guarantees an available route, not recovery after a late decision.

Rows are generated less than 155 units ahead. Objects farther than 12 units behind or already spent are discarded. With four objects per row and the second spark 3.5 units farther along the course than its row center, at most seven partially visible/live rows can remain: a conservative 28-object bound. There is no stored obstacle history; only scalar distance, score, seed state and counters grow. The VM garbage collector reclaims replaced vectors and discarded collections.

## Run the tests

File in the final game, then `endless-runner-tests.st` and `endless-runner-independent-tests.st`.
Print It each expression:

- `ARRunnerTest suite run` → 38 passes, zero failures/errors
- `ARIndependentTests suite run` → 24 passes, zero failures/errors

The independent suite uses test-only fast/capped run subclasses. It temporarily uses Squeak’s bundled X11 virtual-key map for native event replay and restores the previous map in tearDown. Mouse tests remove initial welcome/progress overlays in the test image so actual HandMorph routing can reach the sidebar. Run tests in a disposable learning image with unrelated applications closed.

Verified on Squeak 6.1 build 23976, 64-bit Linux x64, using isolated pristine image/changes copies and the shipped SqueakV60 sources. The VM ran with null display/sound; screenshots were still rendered by native Morphic.

## Verified outcomes

- 62 SUnit tests passed: 38 primary + 24 independent; no failures or errors
- Ten exact checkpoint method sets and Workspace blocks passed and produced native PNGs
- Three exact exercise solutions and behavioral checks passed
- Independent long route: 12,000 ticks / 480 simulated seconds / 9,497.614m / 678 sparks / 149 lane changes; max 24 live objects; reached 22m/s
- Maximum-speed route replay: 12 seeds, 19,200 total ticks, 16,896m, all survived
- Seeded fairness audit: 20,000 rows across 100 seeds; all safe lanes empty and adjacent
- Actual native scheduler: 10 ticks/440ms; exactly one active step entry; stopped on pause, close and game over
- Media replay: 1,100 successful ticks / 529.193m / 32 sparks /  score 1329 / jump apex 1.68 / max 25 objects; explicit jump, slide, dodge, collect, pause, restart, legal no-input crash and restart
- Independent review found and verified fixes for sidebar focus recovery, offscreen opening placement and jump/slide input arriving before the next tick

Final source SHA-256:
e38cba8ed7d7735cb3990af360720982fecc16a03e69d436b208bdaa8f61e5c0

Detailed machine-readable coverage, reviewed hashes and media checksums are in `verification.json` and `tests/independent-review.json`. Review narrative: `tests/independent-review.md`.

## Native media provenance

Every stage PNG is an actual `ARApp window imageForm` export, 998×731 pixels including the native frame/shadow. Ten frames form `endless-runner-construction.gif`. The gameplay GIF contains 120 native frames. Early play is sampled every 3 ticks and later play every 25 ticks, so it is deliberately accelerated. Posters are byte-identical to their cited native frame. The GIFs are assembled from PNGs with Pillow; game graphics are not generated or retouched in Python.

The legal media replay sends native KeyboardEvent down/up messages into ARView; the independent suite dispatches native KeyboardEvent and MouseButtonEvent through the active HandMorph. This verifies native event handling, not a human physical keyboard recording. Long runs advance simulated time faster than wall time; native scheduler cadence is measured separately.

## Limits

Software projection with fixed camera orientation, flat shaded cuboids and painter order; no GPU, textures, rotating colliders, rigid-body solver or full polygon clipping. Shapes crossing a near/far guard can pop out. Jump collision uses 10 ms linear chords and conservative height across posture changes. Slow machines slow the fixed-step game instead of doing a dangerous catch-up leap. No saved leaderboard, networking, audio, touch controls or imported franchise assets.

The three optional solutions are full game files followed by one policy change: wider camera, higher spark value, lower speed cap. Re-file the final game between exercises to restore defaults. Their exact code and checks are included in the tutorial.
