@tamb/gamegrid — a TypeScript library for 2D grid-based web games and interactive matrices.
Also see: site home · interactive demo · GitHub README
Browse the full API on the exports index:
Movement and state use [x, y]: column (x), then row (y). The backing matrix is matrix[row][col] → matrix[y][x].
import GameGrid, { gridEventsEnum, type GameGridDOMEvent } from "@tamb/gamegrid";
const grid = new GameGrid(
{
matrix: myMatrix,
state: { activeCoords: [0, 0] },
options: { wasdControls: true },
},
document.querySelector("#root")!,
);
grid.moveDown();
window.addEventListener(gridEventsEnum.MOVE_LAND, (e: Event) => {
const ce = e as GameGridDOMEvent;
console.log(ce.detail.gameGridInstance.getState());
});
Omit the container argument for headless use, then call render(element) when you need DOM.