The pack
gridMove
function gridMove(opts: GridMoveOptions = {}): Pack<{ grid: GridMoveApi }, {}, { grid: GridData }>
Lane movement on a tile grid. Runs before physics-2d: with a body it sets body.vx/vy, without one it moves x/y itself.
Types
GridData
interface GridData
The grid columns: the direction moving and the direction wanted, each −1, 0 or 1 per axis.
readonly dx: number— x direction moving: −1, 0, 1.readonly dy: number— y direction moving: −1, 0, 1.readonly wx: number— x direction wanted: −1, 0, 1.readonly wy: number— y direction wanted: −1, 0, 1.
GridKeys
interface GridKeys
Key codes per direction for a lane read from the keyboard.
up?: string[]— Keys that steer up (y −1).down?: string[]— Keys that steer down (y +1).left?: string[]— Keys that steer left (x −1).right?: string[]— Keys that steer right (x +1).
GridMoveApi
interface GridMoveApi
game.grid. Every call but lane throws grid-move: <id> is not on a lane for a handle that was never laned.
createGridWalker: typeof createGridWalker— Pure, renderer-independent arcade lane walker; positions use tile centres.lane(h: Handle, spec: LaneSpec): void— Put a handle on the lanes. Undone when the scene exits or the handle dies.want(h: Handle, dx: number, dy: number): void— Set the wanted direction (forinput: 'manual'; withkeysit holds only while no key is down). Signs are taken.halt(h: Handle): void— Stop (zeroing the body's velocity if it has one) and forget the wanted direction.cell(h: Handle): { c: number; r: number }— The tile the handle's nearest lane centre is in.centre(h: Handle, c: number, r: number): { x: number; y: number }— The world position of a tile's centre.free(h: Handle, dx: number, dy: number): boolean— Could the handle move one tile that way from its nearest lane? (the game's walls, not the physics)canGo(h: Handle, dx: number, dy: number): boolean— May it move that way from where it is right now?free, or the lane centre is still ahead.laneX(h: Handle): number— Nearest lane centre x to the handle, world units.laneY(h: Handle): number— Nearest lane centre y to the handle, world units.
GridMoveOptions
interface GridMoveOptions
Manifest options; every one may be overridden per lane.
tile?: number— Tile size in px. Default 16.originX?: number— World x of tile (0,0)'s top-left corner. Default 0.originY?: number— World y of tile (0,0)'s top-left corner. Default 0.turnTolerance?: number— How far off the lane (px) a turn is still taken. Default 3.assist?: number— Cornering assist reach: slide toward the lane when within this many px of it. 0 disables. Default tile/2.
LaneSpec
interface LaneSpec
What lane() takes: the walls, the speed and how it is steered.
walls: (c: number, r: number) => boolean— Is tile (c, r) solid? Called every step, for cells outside the grid too.speed: number— px/s.mode?: 'remember' | 'held'—remember: a press keeps going until a wall (Pac-Man).held: move while held, stop on release. Defaultremember.input?: 'keys' | 'manual'—keys: the pack steers from the keyboard itself (most recent key wins;keysnames them, default arrows and WASD).manual: the game callswant(). Defaultkeys.tile?: number— Tile size in px, overriding the pack option.originX?: number— World x of tile (0,0)'s top-left, overriding the pack option.originY?: number— World y of tile (0,0)'s top-left, overriding the pack option.turnTolerance?: number— Turn tolerance in px, overriding the pack option.assist?: number— Cornering assist reach in px, overriding the pack option.keys?: GridKeys— The key codes (KeyboardEvent.code) for each direction wheninputiskeys. Default arrows plus WASD; a direction left out has no keys.


