A couch ARPG in a browser tab, then the same code on a phone

Console-style gamepad play with stick movement, a sticky cone auto-target and DOM-driven menu focus, then touch as a third pad, with phone sheets, tap-to-act items and a 27-step emulated-iPhone run.

A Stalker in the Scorched Dunes with a gold auto-target ring on a monster and Xbox button glyphs on the skill bar
Contents
  1. What one agent built
  2. Moving with a stick in a click-to-move game
  3. Aiming without a cursor
  4. Menus without a single line of pad code per panel
  5. The Start menu, the chat wheel and rumble
  6. Testing a controller without a controller
  7. Then the phone
  8. The stick and the skill wheel
  9. The interact plate and tapping the world
  10. pointerdown, not click
  11. Layout and input are separate switches
  12. Panels as sheets, items by tap
  13. Quality tiers and dynamic DPR
  14. The page around the game
  15. A 27-step play-through on an emulated iPhone
  16. Related posts

Gamepad play the way console ARPGs do it: the left stick moves you directly, attacks go where you face, menus are a focus ring. Not a cursor steered by a thumbstick. The same machinery then became most of the phone scheme.

A Stalker in the Scorched Dunes: the gold auto-target ring on a scorpion, Xbox glyphs on the skill bar and the pad hint strip at the bottom right
A frame from the trailer's controller capture: the auto-target ring (gold), Ⓐ on the left skill, Ⓧ Ⓨ Ⓑ on slots 1–3, and the hint strip

What one agent built

The controller agent owned src/game/input/gamepad/ and src/game/ui/controller/ (~3,700 lines with tests) and touched shared files only at // pad: hunks.

PadController's rAF callback runs before the engine's, so a stick push lands in the frame that renders it. Each frame it polls the first standard-mapping pad and runs one mode, in priority order:

  1. Rebinding capture
  2. Quick-chat wheel (View/Create held)
  3. Housing build mode
  4. Menus (any panel open)
  5. World

It calls the same gameActions as the mouse (moveTo, attack, cast, pickup, interact, useExit, stop, usePotion), so the server can't tell the difference.

Moving with a stick in a click-to-move game

Every 100 ms while held, send a predicted moveTo 1.8 tiles ahead; stop on release. Walls: bend the target up to ±75°, smallest bend first, accepting only real progress along the stick:

src/game/input/gamepad/targeting.tsTypeScript
export const MOVE_LOOKAHEAD = 1.8
const SLIDE_DEG = [0, 25, -25, 50, -50, 75, -75]
 
export function moveTargetFor(from: Vec, dir: Vec, walkable: (x: number, y: number) => boolean, lookahead = MOVE_LOOKAHEAD): Vec | null {
  const base = Math.atan2(dir.y, dir.x)
  const step = 0.25
  for (const deg of SLIDE_DEG) {
    const a = base + (deg * Math.PI) / 180
    const dx = Math.cos(a)
    const dy = Math.sin(a)
    let best = 0
    for (let d = step; d <= lookahead + 1e-6; d += step) {
      if (!walkable(from.x + dx * d, from.y + dy * d)) break
      best = d
    }
    // a bent direction must make real progress along the stick, not just scrape the wall
    const along = best * Math.cos((deg * Math.PI) / 180)
    if (best >= 0.5 && (deg === 0 || along >= 0.35))
      return { x: from.x + dx * best, y: from.y + dy * best }
  }
  return null
}
  • walkable reads the client's nav grid, so the server almost always accepts the target
  • Walking: under half deflection (or L3 toggle) sends move { walk: true }, the only wire change; the server runs it at WALK_SPEED_FACTOR 0.5 and prediction mirrors it
  • Deadzone: radial with rescale, so diagonals aren't sticky and travel doesn't jump to 18%:
src/game/input/gamepad/layout.tsTypeScript
/**
 * Radial deadzone with rescale: inside `dz` → 0; outside, magnitude remaps dz..1 → 0..1 so the
 * first bit of travel past the deadzone is still fine control (no jump to 0.18).
 */
export function radialDeadzone(x: number, y: number, dz = DEFAULT_DEADZONE): Stick {
  const m = Math.hypot(x, y)
  if (!(m > dz)) return { x: 0, y: 0, mag: 0 }
  const scaled = Math.min(1, (m - dz) / (1 - dz))
  return { x: (x / m) * scaled, y: (y / m) * scaled, mag: scaled }
}

Aiming without a cursor

A face button fires at the best hostile within 14 tiles in a 65° cone, or anything within 2.2 tiles on any side. Distance dominates; angle off facing adds up to 150%:

src/game/input/gamepad/targeting.tsTypeScript
export const DEFAULT_TARGETING: TargetOptions = { range: 14, coneDeg: 65, closeRange: 2.2, stickiness: 1.35 }
 
export function scoreTarget(from: Vec, facing: number, c: TargetCandidate, o: TargetOptions): number | null {
  const dx = c.x - from.x
  const dy = c.y - from.y
  const d = Math.hypot(dx, dy)
  if (d > o.range) return null
  const off = d < 1e-4 ? 0 : Math.abs(angleDiff(Math.atan2(dy, dx), facing))
  const cone = (o.coneDeg * Math.PI) / 180
  if (off > cone && d > o.closeRange) return null
  const angleCost = 1 + 1.5 * Math.min(1, off / Math.max(1e-3, cone))
  return (Math.max(0.3, d) * angleCost) / Math.max(0.5, c.priority ?? 1)
}
  • Priority: champions 1.15, uniques 1.3, bosses 1.6
  • Stickiness: keep the current target until something scores 35% better
  • Lock: while an attack button is held, the stick only aims
  • Repeat: every 300 ms, inside the server's 450 ms hold window
  • Skills: targeted at the target; ground skills with no target land ahead (skill range, max 8 tiles); self, buff, aura and nova just cast
  • Context Ⓐ: no hostile within 8 tiles in the cone and something usable within 2.5, so Ⓐ becomes "Talk to Captain Marrow", "Use waypoint", "Travel to…". Loot beats objects; LB cycles several items
The Xbox glyph skill bar: Ⓐ on the left skill, Ⓧ Ⓨ Ⓑ RB on slots 1–4, LT plus a face button for 5–8, RT on the right skill, D-pad potions
The bottom bar in pad mode. The key letters are replaced by glyphs; LT turns the four face buttons into slots 5–8

A dozen-plus panels by several agents. Instead of teaching each about a pad, PadNavigator works off the DOM:

src/game/ui/controller/PadNavigator.tsTypeScript
// Controller focus for every HUD panel, driven from the DOM so the kit components stay untouched:
// scopes are `.gr-panel` / `[data-pad-scope]` elements, targets are their enabled buttons plus
// `.gr-grid` item grids (navigated cell by cell, footprints respected, see nav.ts). Focus is shown
// by PadLayer's ring and mirrored as synthetic pointer hover, so the real tooltips, footprint
// previews and held-item follower all work; A / X are real click / contextmenu events, so every
// gesture runs through the same handlers (invPlan → invMove) as the mouse.
const SCOPE_SEL = '[data-pad-scope], .gr-panel'
const TARGET_SEL = 'button, [data-pad-target], .gr-grid'
const TAB_SEL = '[role="tab"], .gr-tab'
  • Grids move cell by cell with an item as one stop; a held item's footprint preview moves under a breathing gold ring
  • Button focus is a pure spatial pick (nearest in direction, angle penalty), tested in nav.test.ts
  • Holding a combat button on a skill node for 450 ms binds it

Every panel built later was navigable on day one. src/game/party/PartyPanel.tsx says so: "Plain buttons, so the pad's menu layer navigates it with no pad code".

The inventory under pad focus: the gold ring on a mana potion, its real tooltip, and the hint strip
Start → Inventory on the virtual pad: the focus ring sits on a potion and the game's own tooltip follows it, because focus is synthetic hover

The Start menu, the chat wheel and rumble

The Start menu over the Blighted Fields: Resume, Inventory, Character, Skills, Quests, Pets, Party, Map, Go home, Controller, Leave to characters
Start opens every panel, party actions and the controller settings, all reachable without a keyboard

A browser can't raise the OS keyboard from a pad, so holding View/Create for 280 ms opens a quick-chat wheel (Hi, Follow me, Need potions, Nice, Ready, GG) that sends to party or zone.

The quick-chat wheel: six phrases around a center, Follow me highlighted
Hold View, point, release. The message lands in chat as the capture shows: 'Blogwar9572: Follow me'
  • Rumble on damage (scaled, stronger on crits) and level-up
  • Settings: rebinding (conflicts swap), glyphs (Auto, Xbox, PlayStation), rumble, deadzone (18%), start in walk mode; zod-parsed from localStorage['gr.pad.v1']
  • Last device used owns the HUD: stick push shows glyphs, real mouse move restores keys

Glyphs come from Gamepad.id. Microsoft (045e) is checked first, since a DualShock 4 over USB calls itself "Wireless Controller":

src/game/input/gamepad/layout.tsTypeScript
export function detectGlyphs(id: string): GlyphSet {
  if (/xbox|045e/i.test(id)) return 'xbox'
  return /054c|playstation|dualshock|dualsense|wireless controller|ps[345]/i.test(id)
    ? 'playstation'
    : 'xbox'
}
The pet picker in PlayStation mode: Cross Select, Square Use, Triangle Drop · sell in the hint strip
Glyphs forced to PlayStation in settings. The starter-pet picker is an ordinary panel, so the pad navigates it for free

Testing a controller without a controller

No agent had a physical pad. window.__grPad feeds the exact path a real pad does:

src/game/input/gamepad/GamepadInput.tsTypeScript
//   __grPad.inject({ axes: [lx, ly, rx, ry], buttons: { a: true, rt: 1 } })   // held until changed
//   __grPad.inject({ buttons: [0, 0, 1] })                                   // standard indices work too
//   __grPad.tap('a', 120)  ·  __grPad.release()  ·  __grPad.state()

A full bx session ran through it: walking and walk pace, leaving town, auto-target fights with held Ⓐ and Ⓧ, loot, potions, talk → trade → buy, equip on the paper doll, learn and bind, map, quick chat, town portal, build mode. 34 unit tests cover deadzone, glyphs, bindings, settings parsing, stick-to-world, wall slide, target scoring, spatial pick and grid footprints.

Then the phone

A touch ARPG scheme (floating left stick, big attack button with skills around it, auto-target, hold to repeat) is a gamepad drawn on glass. So touch is a third pad: TouchInput emits the same PadFrame:

src/game/input/touch/TouchInput.tsTypeScript
// mobile: the touch "pad". Owns the floating thumbstick (touches that start on the canvas in the
// left zone), the on-screen buttons held right now (TouchControls presses / releases them), the
// skill page toggle and drag-to-aim, and turns all of it into the same PadFrame the gamepad
// produces, so PadController's world mode drives touch play with no second implementation.

Carried over unchanged: 10 Hz moveTo with wall slide, walk under half deflection, the sticky cone target and gold reticle, 300 ms repeat, aim-only while holding a skill, the context prompt.

The stick and the skill wheel

src/game/input/touch/stick.tsTypeScript
/** Knob travel for full deflection, in CSS px. */
export const STICK_RADIUS = 56
/** Radial deadzone as a fraction of STICK_RADIUS. */
export const STICK_DEADZONE = 0.12
/** Touches starting in this left fraction of the game area drive the stick. */
export const STICK_ZONE = 0.42
/** A touch shorter than this that barely moved is a tap (talk / pick up / attack what's under it). */
export const TAP_MS = 260
export const TAP_SLOP = 12
/** Under this deflection the hero walks (same threshold the pad uses). */
export const WALK_BELOW = 0.5
  • The stick drops where the thumb lands in the left 42%; past 56 px the base follows the thumb
  • Bottom right: attack button for the left skill, slots 1–4 and the right skill arced around; a 1–4 chip flips to 5–8
  • Buttons reuse SkillButton, so cooldown sweeps and no-mana tints are free
  • Drag to aim: drag a held skill more than ~20 px to cast where it points, ignoring auto-target
Touch HUD on a phone in landscape: the floating stick on the left, the attack button and skill arc at the bottom right, orbs and belt along the bottom
The floating stick appears where the left thumb lands. Everything else is where a right thumb rests

The interact plate and tapping the world

The attack button only fights. Talk, loot and travel go through a plate above the belt ("Talk to Wren", "Pick up Short Sword"), visible even near hostiles, since on a phone it's a separate thumb. A tap (≤ 260 ms, ≤ 12 px) acts on whatever is within 1.3 tiles of the finger, or walks there.

A dropped Short Sword with a tappable loot list over it and the Pick up Short Sword plate above the belt
The interact plate and the loot list. The attack button next to them never picks anything up
Fighting a Plague Rat: its name and life bar at the top, the gold reticle on it, damage numbers
Holding the attack button: the pad's cone auto-target picks the rat, and the target frame shows its life

pointerdown, not click

Browsers only synthesize click for single-finger taps, so a potion tapped while holding attack would never fire. Every touch button acts on pointerdown and captures its pointer:

src/game/ui/touch/TouchControls.tsxTypeScript
/** Pointer handlers that press / release a touch button (capture keeps the release on this node). */
function useHold(b: TouchButton) {
  const onPointerDown = useCallback(
    (e: ReactPointerEvent<HTMLElement>) => {
      e.preventDefault()
      e.stopPropagation()
      e.currentTarget.setPointerCapture(e.pointerId)
      padBridge.touch?.input.press(b, { id: e.pointerId, x: e.clientX, y: e.clientY })
    },
    [b],
  )
  // … release on pointerup / pointercancel / lostpointercapture
}

Stick and buttons track their own pointer ids: walk with one thumb, fight with the other.

Layout and input are separate switches

  • HUD follows the device: touch-first starts in touch mode; any pointerType === 'touch' switches to it, a real mouse or key to classic, a pad press to glyphs. The on-screen keyboard doesn't count.
  • Layout follows the viewport: under (max-height: 540px), (max-width: 760px), panels become full-height sheets; two-column panels split the screen.

Phone plus Bluetooth pad: sheets with Xbox glyphs. Phone plus mouse: classic bar at 60%. Touchscreen laptop: desktop layout, touch HUD while touching. Both are Tailwind variants (phone:, touch:).

Panels as sheets, items by tap

The vendor and the inventory side by side as a split phone sheet, each taking half the screen
Two-column panels split the phone screen in half: the vendor's stock on one side, your bag on the other

Tap an item to select it and dock its tooltip with actions from the same planners as mouse and pad: Equip, Use, Unequip, Move, Drop, Sell, Buy, Gamble, To stash, To bag, To belt, Socket, Identify. Long press (450 ms) or Compare adds the worn item. Skill nodes read on tap and offer Learn and Bind. Build mode: tap a piece, tap to place, Rotate and Remove buttons.

The inventory as a phone sheet with a Quarterstaff selected: its tooltip docked on the right with Unequip, Move, Drop and Close buttons
Tap to select, then act from the card. The buttons are built by the same planner as a mouse right-click
The skills sheet on a phone: the Flame tree with three nodes and the Tap a skill to read it hint
Every panel is a full-height sheet on a phone. The skill tree reads on tap and binds to the wheel from the same card

Quality tiers and dynamic DPR

src/game/engine/Engine.tsTypeScript
const TIERS: Readonly<Record<QualityTier, { samples: number; shadow: number; shadowEvery: number; pool: number; particles: number; bloom: boolean; dprFloor: number }>> = {
  high: { samples: 4, shadow: 2048, shadowEvery: 1, pool: 10, particles: 1, bloom: true, dprFloor: DPR_MIN },
  medium: { samples: 0, shadow: 1024, shadowEvery: 2, pool: 6, particles: 0.7, bloom: true, dprFloor: 1 },
  low: { samples: 0, shadow: 1024, shadowEvery: 3, pool: 4, particles: 0.45, bloom: false, dprFloor: 0.8 },
}

Touch-first devices cap DPR at 1.5 and start on medium. Dynamic resolution drops DPR by 0.2 after 1.5 s over 20 ms; the mobile work added a second stage that steps down to low at the tier floor before going below 1.0. Desktop never steps its tier.

The page around the game

  • No pinch or double-tap zoom (viewport flag plus prevented gesturestart and dblclick, since iOS ignores the flag)
  • No overscroll bounce, no HUD text selection or callouts; 16 px inputs so iOS doesn't zoom on focus
  • First finger lift requests fullscreen and landscape lock, failing silently where unsupported
  • viewport-fit=cover plus env(safe-area-inset-*) for the notch; chat opens at the top, above the keyboard
  • Phones play landscape; portrait shows a rotate card while the session keeps running. Other pages work in both orientations from 360 px.
A phone in portrait showing a Turn your phone card over the dimmed game
Portrait is a pause, not an error. The room connection stays up under the card

A 27-step play-through on an emulated iPhone

scripts/mobile-play.ts plays by CDP touch events (real pointerType: 'touch') in headless Chromium with iPhone landscape metrics. 27 of 27:

  • Movement: touch HUD active, stick moves, light push walks
  • Town: interact plate opens an NPC, vendor opens, item sells by tap
  • Items and skills: learn and bind to slot 1, unequip and equip by tap
  • Panels: every panel by tap and from More, still in touch mode after, chat focuses
  • Fields: auto-target fights, a skill spends mana, the plate loots, a potion mid-fight
  • Portal and portrait: town portal by touch, rotate card appears, connection holds

Frame rate: 60 fps headless; 57–60 fps with ~20 ms p95 frames under 4× CPU throttle at 1.5× DPR on medium. scripts/mobile-check.ts renders every page in both orientations, fails on horizontal overflow and re-checks the desktop HUD.