grafjs
v1.1.1
Published
2D graph for chunk-based games.
Downloads
1
Maintainers
Readme
GrafJS
Features
2D graph for chunk-based games.
- No dependencies
- Easy to use
- Lightweight
Installing
$ npm install grafjs
Example
Import
const Graf = require('grafjs')
Creating a board where each chunk is 20 x 20.
// creates 20 x 20 grid filled with 0's
const grid = new Array(20).fill(null).map(a => new Array(20).fill(0))
// creates the board with a default value for each chunk
const board = new Graf(grid)
// adds examplary chunk
board.addChunk(0, 0)
Getting specified chunk and adjacent chunks.
// returns chunk at position (1, 3)
const chunk = board.getChunk(1, 3)
const left = chunk.getLeft()
const right = chunk.getRight()
const up = chunk.getUp()
const down = chunk.getDown()
Getting and setting chunk's content.
// gets value
const content = chunk.getValue()
// sets value
chunk.setValue([1])
Removing a chunk
// removes the chunk at (3, 4)
board.removeChunk(3, 4)