Skip to content

feat(site/src/pages/CoderCupPage): add difficulty levels to the Codernauts game - #31612

Merged
bartekgatzcoder merged 3 commits into
mainfrom
codernauts-difficulty-levels
Nov 10, 2026
Merged

bartekgatzcoder merged 3 commits into
mainfrom
codernauts-difficulty-levels

Conversation

@bartekgatzcoder

@bartekgatzcoder bartekgatzcoder commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

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.

Level Max velocity Max yaw
Easy 50 30°
Moderate 30 20°
Hard (original physics) 15 10°

The levels are real buttons (shared Button) over the canvas, so they are focusable and announced by screen readers. The canvas gets role="img", an accessible name, and a hidden description of the flight controls.

Implementation notes
  • LANDING_MAX_SPEED and LANDING_ANGLE_TOL are replaced by a DIFFICULTIES array of LandingLimits (label, shortcut key, max speed, max angle), in button order. tryLanding and drawDashboard take the chosen limits, so the crash check and HUD warnings cannot drift apart.
  • The choice lives in React state, which renders the button row until a level is picked, plus a ref that the game loop reads, since the loop runs outside React renders. The loop draws the title and controls help behind the buttons while no level is chosen.
  • The button row uses the dark theme scope because the game always renders light on black.
  • Shortcuts are case-insensitive and ignored with Ctrl, Cmd, or Alt held.
  • Tests use userEvent and 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.
  • Ran pnpm check, pnpm lint, pnpm lint:design-system (on this folder), tsc, and the CoderCupPage Vitest suite locally. main is merged in.

Generated by Coder Agents on behalf of @bartekgatzcoder.

…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.
@bartekgatzcoder

Copy link
Copy Markdown
Collaborator Author

@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 (site/src/pages/CoderCupPage). CI is green apart from the advisory doc-check bot, which timed out; the game has no user docs, so no doc changes are needed.

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 jeremyruppel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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°.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (FE4): "The original physics" describes history. Suggest describing the rule only, e.g. // One lander height per second and 10°.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (FE4): this repeats the limits parameter comment on drawDashboard; one of them can go.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" : "";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this writes cvs.style.cursor every frame. Harmless, but setting it from onMouseMove would be enough. Moot if the buttons become DOM elements.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (FE4): "No countdown:" describes removed behavior. Suggest // The start screen stays up until a difficulty is chosen.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 })).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@bartekgatzcoder
bartekgatzcoder temporarily deployed to main November 10, 2026 10:23 — with GitHub Actions Inactive
@bartekgatzcoder
bartekgatzcoder temporarily deployed to main November 10, 2026 10:24 — with GitHub Actions Inactive
@bartekgatzcoder

Copy link
Copy Markdown
Collaborator Author

@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?

  • Blocking: the levels are now shared Buttons over the canvas ("Easy (E)" and so on), so they're focusable and named for screen readers. The canvas has a hidden description of the controls. The E/M/H shortcuts still work.
  • Hand-rolled hit test: removed, along with the hover and cursor code.
  • Tests: they use userEvent and role queries now.
  • Compatibility: main is merged in, and the conflict with fix: make use of tailwind size- class #31893 (size-full) is resolved.

The follow-up fixes for the rewind are in #31613.


Generated by Coder Agents on behalf of @bartekgatzcoder.

@jeremyruppel jeremyruppel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)] and w-[calc(100%-200px)] hardcode DASHBOARD_H and SIDEBAR_W; an inline style built from the constants would keep them in sync.
  • onKeyDown repeats the body of selectDifficulty instead of calling it.
  • The clicked button unmounts, so focus drops to <body>.
  • The queryByRole(...).toBeNull() assertions are redundant with sidebarDrawn().

Generated by Coder Agents on behalf of @jeremyruppel.

@bartekgatzcoder
bartekgatzcoder merged commit d347486 into main Nov 10, 2026
32 checks passed
@bartekgatzcoder
bartekgatzcoder deleted the codernauts-difficulty-levels branch November 10, 2026 18:01
@bartekgatzcoder
bartekgatzcoder temporarily deployed to main November 10, 2026 18:01 — with GitHub Actions Inactive
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 10, 2026

This branch was previously deployed

1 inactive deployment
main — 7f9377ef Deployed Nov 10, 2026 by bartekgatzcoder via cla #253641
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants