Skip to content

Grid

@f0rbit/forge/grid bundles the primitives every grid-based game ends up writing: cell math, Bresenham line iteration, line-of-sight, a cell-keyed spatial index, axis-sliding tile movement, and a tick/cell-rate calibration helper. Continuous-movement games skip this import and ship zero grid code (sideEffects: false, tree-shakeable per subpath).

import {
grid,
grid_index,
grid_index_sync_system,
ticks_per_step,
} from "@f0rbit/forge/grid";
const g = grid({ cols: 20, rows: 11, tile: 16 });
// `line`, `line_of_sight`, and `move_tile` are methods on the Grid record:
for (const c of g.line({ x: 0, y: 0 }, { x: 4, y: 2 })) { /* … */ }
const visible = g.line_of_sight({ from, radius: 6, is_blocking });
const r = g.move_tile(world, id, { dx, dy }, { blocked_by });
SymbolKindPage
gridfactoryBuild a Grid record bundling cell↔world conversion, key/unkey, neighbours, distances, and the spatial methods.
grid.linemethodBresenham generator yielding every cell from a to b inclusive.
grid.line_of_sightmethodSymmetric FOV — set of visible cell-keys from from within radius.
grid_indexfactoryCell-keyed spatial index over entities with pos_c.
grid_index_sync_systemfactorySystem that refreshes the index each tick.
grid.move_tilemethodStep one cell with axis-sliding collision predicate.
ticks_per_stepfunctionConvert cells/sec → integer tick gate.
Cell, Grid, GridOptstypesReturned by grid().
FovOptstypeOptions for g.line_of_sight. (No grid field — closed over by the method.)
GridIndextypeReturned by grid_index.
TileMoveOpts, TileMoveResulttypesg.move_tile shape.

Roguelikes, sokoban, snake, tactics, match-3, factory-builder, top-down RPG — anything cell-aligned. If your game is bullet-hell, platformer, or shooter, you don’t need any of this; stay on the main entry.

For tile-step games, pair the grid primitives with presets.movement_4way (digital edges only — no axes, no diagonals) or presets.movement_8way (digital edges + axes for analog smoothing).

import { presets } from "@f0rbit/forge/presets";
import { boot } from "@f0rbit/forge/pixi";
await boot({
mount: "#root",
bindings: presets.movement_4way,
// ...
});