Nature's Particle Manager

    grafjs

    1.1.1 • Public • Published

    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)

    Install

    npm i grafjs

    DownloadsWeekly Downloads

    1

    Version

    1.1.1

    License

    ISC

    Unpacked Size

    6.08 kB

    Total Files

    4

    Last publish

    Collaborators

    • konradlinkowski