UNPKG

ridder

Version:

A straightforward game engine for simple data-driven games in JavaScript

33 lines (32 loc) 1.15 kB
export type Grid<T> = Array<Array<T>>; /** * Create a new grid data structure. * @param width - The width of the 2D array. * @param height - The height of the 2D array. * @param fill - The function to fill each cell in the grid. */ export declare function grid<T>(width: number, height: number, fill: (x: number, y: number) => T): Grid<T>; /** * Returns true if the width and height of the grid is larger than zero. */ export declare function isGridValid<T>(grid: Grid<T>): boolean; /** * Returns true if the given position is within the grid's width and height. */ export declare function isInsideGridBounds<T>(grid: Grid<T>, x: number, y: number): boolean; /** * Set a cell in the grid to a value. */ export declare function setGridValue<T>(grid: Grid<T>, x: number, y: number, value: T): void; /** * Returns a cell value from the grid. */ export declare function getGridValue<T>(grid: Grid<T>, x: number, y: number): T; /** * Returns the width of the grid. */ export declare function getGridWidth<T>(grid: Grid<T>): number; /** * Returns the height of the grid. */ export declare function getGridHeight<T>(grid: Grid<T>): number;