1.1.1 • Published 6 years ago

grafjs v1.1.1

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

GrafJS

NPM Downloads Build Status Dependency Status devDependency Status Known Vulnerabilities Maintainability

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)
1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago