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 });Exports
Section titled “Exports”| Symbol | Kind | Page |
|---|---|---|
grid | factory | Build a Grid record bundling cell↔world conversion, key/unkey, neighbours, distances, and the spatial methods. |
grid.line | method | Bresenham generator yielding every cell from a to b inclusive. |
grid.line_of_sight | method | Symmetric FOV — set of visible cell-keys from from within radius. |
grid_index | factory | Cell-keyed spatial index over entities with pos_c. |
grid_index_sync_system | factory | System that refreshes the index each tick. |
grid.move_tile | method | Step one cell with axis-sliding collision predicate. |
ticks_per_step | function | Convert cells/sec → integer tick gate. |
Cell, Grid, GridOpts | types | Returned by grid(). |
FovOpts | type | Options for g.line_of_sight. (No grid field — closed over by the method.) |
GridIndex | type | Returned by grid_index. |
TileMoveOpts, TileMoveResult | types | g.move_tile shape. |
When to import /grid
Section titled “When to import /grid”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.
Pairing with the input layer
Section titled “Pairing with the input layer”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, // ...});