Repository navigation
feat(site/src/pages/CoderCupPage): add difficulty levels to the Codernauts game - #31612
Conversation
…nauts game Replace the intro countdown with a start screen that waits for the player to choose Easy, Moderate, or Hard by clicking a button or pressing E, M, or H. Hard keeps the original landing limits (speed 15, yaw 10 degrees); Moderate allows 30 and 20 degrees; Easy allows 50 and 30 degrees. The HUD velocity and yaw warnings use the chosen level's limits.
|
@DanielleMaywood @jeremyruppel could one of you take a look at this when you have a moment? It is a small change to the Codernauts easter egg game ( This PR adds Easy, Moderate, and Hard difficulty levels. The stacked follow-up, #31613, adds a 5-second rewind on the R key. @jeremyruppel, a question: could the reviewer skill you built for A11Y topics be used to review frontend PRs like this one? If yes, @bartekgatzcoder would like to trigger it himself on future PRs. How should he run it? Generated by Coder Agents on behalf of @bartekgatzcoder. |
jeremyruppel
left a comment
There was a problem hiding this comment.
Reviewed the difficulty levels change. Game logic looks correct: Hard keeps the original limits, the radian yaw comparison matches the old degree conversion since yaw is normalized, start-screen frames keep lastTs current so there is no dt jump after picking, and E/M/H never leak into keys. CoderCupPage Vitest suite (6/6) and biome pass locally.
Main ask is accessibility: the game now blocks on a choice that only exists as canvas pixels. Details inline.
Generated by Coder Agents on behalf of @jeremyruppel.
| ref={canvasRef} | ||
| className="block" | ||
| role="img" | ||
| aria-label="Save all Codernauts lunar lander game" |
There was a problem hiding this comment.
blocking (a11y, ARIA rule 5): Before this PR the game started on its own; now it waits for a choice whose only instructions ("press E") are drawn on the canvas. A screen reader user hears "Save all Codernauts lunar lander game, image" with no hint that input is expected, and role="img" also signals the surface is non-interactive even though it takes clicks.
Preferred fix: while limits is null, render the three levels as real <button>s (shared Button from components/Button) overlaid on the canvas, with visible text like "Easy (E)". Keep the E/M/H shortcuts. Minimum fix if it stays canvas-only: expose the instructions via the accessible name or an aria-describedby hint, e.g. "Press E, M, or H to choose Easy, Moderate, or Hard".
There was a problem hiding this comment.
Fixed in 7f9377e. The three levels are now shared Buttons over the canvas ("Easy (E)", "Moderate (M)", "Hard (H)"), so they are focusable, have a role and name, and work with Enter/Space. E/M/H still work. The canvas also gets aria-describedby pointing at visually hidden text that explains the flight controls.
Coder Agents on behalf of @bartekgatzcoder.
| * Draw the title, controls help, and difficulty buttons. The game | ||
| * waits on this screen until the player picks a difficulty. | ||
| */ | ||
| function drawStartScreen( |
There was a problem hiding this comment.
should-fix (a11y, ARIA rule 1 / FE6): These buttons are pixels plus a hand-rolled hit test (difficultyButtons / difficultyHitTest), so they are not focusable, have no role or name, and need custom hover/cursor handling. Native <button>s over the canvas would remove difficultyButtons, difficultyHitTest, the hover branch in the loop, and the cursor bookkeeping, and make the tests simpler (see test comments).
There was a problem hiding this comment.
Fixed in 7f9377e: native buttons replaced difficultyButtons, difficultyHitTest, the hover branch in the loop, and the cursor bookkeeping. The button row uses the dark theme scope, since the game always renders light on black, so no raw colors are needed (lint:design-system is clean).
Coder Agents on behalf of @bartekgatzcoder.
| maxSpeed: 30, | ||
| maxAngle: (20 * Math.PI) / 180, | ||
| }, | ||
| // The original physics: one lander height per second and 10°. |
There was a problem hiding this comment.
nit (FE4): "The original physics" describes history. Suggest describing the rule only, e.g. // One lander height per second and 10°.
There was a problem hiding this comment.
Fixed in 7f9377e: now // One lander height per second and 10°.
Coder Agents on behalf of @bartekgatzcoder.
| let victoryTimer = 0; | ||
| let victoryBursts: ExplosionParticle[][] = []; | ||
| let introTimer = INTRO_DURATION; | ||
| // Chosen on the start screen; null until the player picks one. |
There was a problem hiding this comment.
nit (FE4): this repeats the limits parameter comment on drawDashboard; one of them can go.
There was a problem hiding this comment.
Fixed in 7f9377e: the closure variable and its comment are gone. The choice now lives in React state (for the buttons) plus a ref read by the game loop, with one comment explaining the pair.
Coder Agents on behalf of @bartekgatzcoder.
| } | ||
| const hovered = difficultyHitTest(mouseX, mouseY, dashW, playH); | ||
| drawStartScreen(cx, dashW, playH, hovered); | ||
| cvs.style.cursor = hovered ? "pointer" : ""; |
There was a problem hiding this comment.
nit: this writes cvs.style.cursor every frame. Harmless, but setting it from onMouseMove would be enough. Moot if the buttons become DOM elements.
There was a problem hiding this comment.
Moot after 7f9377e: the canvas no longer sets the cursor; the DOM buttons handle it.
Coder Agents on behalf of @bartekgatzcoder.
| frame(timestamp); | ||
| } | ||
| runFrame(1); | ||
| fireEvent.keyDown(window, { key: "h" }); |
There was a problem hiding this comment.
should-fix (FE1): repo guidance is Vitest + userEvent for behavior tests. fireEvent is used for every key and click in this file (here and lines 92, 98, 110, 129). await user.keyboard("h") dispatches on the active element and bubbles to window, so it works with the existing listener.
There was a problem hiding this comment.
Fixed in 7f9377e: every key press and click goes through userEvent (user.keyboard, user.click).
Coder Agents on behalf of @bartekgatzcoder.
| const sidebarDrawn = () => | ||
| fillText.mock.calls.some(([text]) => text === "Employee"); | ||
|
|
||
| // No countdown: the start screen stays up indefinitely. |
There was a problem hiding this comment.
nit (FE4): "No countdown:" describes removed behavior. Suggest // The start screen stays up until a difficulty is chosen.
There was a problem hiding this comment.
Fixed in 7f9377e: // The start screen stays up until a difficulty is chosen.
Coder Agents on behalf of @bartekgatzcoder.
| expect(sidebarDrawn()).toBe(false); | ||
|
|
||
| // Clicking the Easy button (drawn first) starts the game. | ||
| const easy = buttons[0]; |
There was a problem hiding this comment.
nit (FE10): click coordinates come from captured roundRect args, which couples the test to draw order (buttons[0] is Easy only because it is drawn first) and to geometry. With DOM buttons this becomes await user.click(screen.getByRole("button", { name: /easy/i })).
There was a problem hiding this comment.
Fixed in 7f9377e: the test clicks screen.getByRole("button", { name: "Easy (E)" }) and checks the buttons are gone afterwards. The roundRect capture and stub are removed.
Coder Agents on behalf of @bartekgatzcoder.
…-levels # Conflicts: # site/src/pages/CoderCupPage/LunarLander.tsx
… picker Address review feedback: render Easy, Moderate, and Hard as shared Button components over the canvas instead of canvas-drawn pixels with a hand-written hit test, so they are focusable and announced to screen readers. Describe the flight controls to assistive technology, switch the tests to userEvent and role queries, and reword comments that described history.
|
@jeremyruppel thanks for the thorough review. I've addressed every blocking and should-fix item, plus the nits, and replied in each thread. Could you take another look?
The follow-up fixes for the rewind are in #31613. Generated by Coder Agents on behalf of @bartekgatzcoder. |
jeremyruppel
left a comment
There was a problem hiding this comment.
All earlier feedback is addressed in 7f9377e. The difficulty picker is now real Buttons with visible names, the canvas describes the controls via aria-describedby, and the tests use userEvent and role queries. CoderCupPage Vitest (6/6), biome, lint:design-system, and tsc pass locally, and CI is green.
Optional nits, fine as follow-ups:
- The button row's
top-[calc((100%-84px)*0.74)]andw-[calc(100%-200px)]hardcodeDASHBOARD_HandSIDEBAR_W; an inlinestylebuilt from the constants would keep them in sync. onKeyDownrepeats the body ofselectDifficultyinstead of calling it.- The clicked button unmounts, so focus drops to
<body>. - The
queryByRole(...).toBeNull()assertions are redundant withsidebarDrawn().
Generated by Coder Agents on behalf of @jeremyruppel.
Replaces the Codernauts intro countdown with a start screen that waits for the player to pick a difficulty, by clicking a button or pressing E, M, or H. The chosen level sets the touchdown limits that decide whether a landing crashes, and the HUD velocity and yaw warnings use the same limits.
The levels are real buttons (shared
Button) over the canvas, so they are focusable and announced by screen readers. The canvas getsrole="img", an accessible name, and a hidden description of the flight controls.Implementation notes
LANDING_MAX_SPEEDandLANDING_ANGLE_TOLare replaced by aDIFFICULTIESarray ofLandingLimits(label, shortcut key, max speed, max angle), in button order.tryLandinganddrawDashboardtake the chosen limits, so the crash check and HUD warnings cannot drift apart.darktheme scope because the game always renders light on black.userEventand cover: no auto-start after 60 s, clicking the Easy button by role, the uppercase shortcut, and the velocity warning at 20 px/s appearing on Hard only.pnpm check,pnpm lint,pnpm lint:design-system(on this folder),tsc, and the CoderCupPage Vitest suite locally.mainis merged in.Generated by Coder Agents on behalf of @bartekgatzcoder.