GrafJS
Features
2D graph for chunk-based games.
- No dependencies
- Easy to use
- Lightweight
Installing
$ npm install grafjs
Example
Import
const Graf =
Creating a board where each chunk is 20 x 20.
// creates 20 x 20 grid filled with 0'sconst grid = 20// creates the board with a default value for each chunkconst board = grid// adds examplary chunkboard
Getting specified chunk and adjacent chunks.
// returns chunk at position (1, 3)const chunk = boardconst left = chunkconst right = chunkconst up = chunkconst down = chunk
Getting and setting chunk's content.
// gets valueconst content = chunk// sets valuechunk
Removing a chunk
// removes the chunk at (3, 4)board