Split The code is public; the app answers only to the crew.

A radar in the corner: the map, your team, the sites and the bomb #23

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

Adds a radar to the HUD: your team, the bomb once it's planted, and both sites (A/B), rotated so your view's yaw points up. Never the enemy.

Notes

shipped merged

opened this

Adds a radar to the HUD: your team, the bomb once it's planted, and both sites (A/B), rotated so your view's yaw points up. Never the enemy.

What changed

  • src/client/radar.ts (new): a pure function buildRadar(world, view, radius) that turns the world into a list of blips in canvas-ready axes (−1..1, +x right, +y down), rotated by the view's yaw. Only the view's own team, the planted bomb, and the two sites — enemies are structurally excluded. A teammate beyond radius is dropped (not clamped), which is what radar.test.ts checks along with the rotation math (north-facing vs. east-facing), the person always at the centre, and the bomb only blipping once planted.
  • src/client/hud.ts: draws the radar bottom-left, clear of the money line, kill feed and clock. The walkable-cell map is baked once into an offscreen canvas (OffscreenCanvas, falling back to document.createElement where available, and skipped gracefully in the headless test environment) and turned each frame with ctx.rotate/ctx.translate instead of re-walking the 1,936 cells — same caching pattern as the existing hurt vignette, rebuilt only when the on-screen size changes.
  • src/client/hud.test.ts: extended the recording canvas mock with clip/translate/rotate/drawImage, tightened a few existing assertions that were counting all arcs/moveTos (now the radar adds its own), and added a test that the radar sits bottom-left and labels both sites.
  • README.md: documents the radar in the HUD section and the module list.

A real bug caught along the way: wiring the rotation in, I found hud.ts already had a local const rad = Math.PI / 180 (a degrees→radians multiplier) that would have silently shadowed the rad() function I imported from math.ts — calling a number as a function on every frame in any real browser, invisible in tests only because OffscreenCanvas/document aren't defined there. Fixed by dropping the local constant and using the imported rad() at both existing call sites; verified the fix explicitly by stubbing OffscreenCanvas and running drawHud end-to-end outside the test file.

Left out: I couldn't measure real frame time before/after — this sandbox has no GPU or browser (no OffscreenCanvas, no Chromium available to launch headless), so I can't report actual fps numbers on "the same machine" as asked. The added draw work is a dozen small fillRect/arc/fillText calls plus one drawImage of a small cached bitmap, which should be negligible next to the existing scoreboard/kill-feed text, but that's reasoning, not a measurement — flagging it rather than guessing numbers.

To try: run the game, the radar is bottom-left; turn and watch it rotate under your teammates' dots; plant the bomb and it shows up on the radar; nothing from the enemy team ever appears on it.

bun test passes (171 tests).

Closes #18

commented

Merged main (the footsteps/sound-panning commit #22) into this branch. The only conflict was in README.md's module list, where both sides had added a new module to the same sentence — resolved by keeping both radar and ears in the list. Rebuilt static/app.<hash>.js against the merged sources and confirmed bun test passes (178 tests, up from 171 with the merged-in footstep tests). Pushed the merge commit.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs