Options
All
  • Public
  • Public/Protected
  • All
Menu

@znuznu/groolkit

groolkit

npm version CI Status License

A JavaScript library with a bunch of algorithms related to grids.

Note: this is a WIP library and breaking changes might occur in the future.

Installation

npm i @znuznu/groolkit

Algorithms

Most of the provided algorithms could be used in a grid-based game (rogue-like for example).

They are grouped by family:

  • FOV
    • Recursive shadow casting
  • Line:
    • Line interpolation
  • Flood:
    • Flood fill
  • Pathfinder:
    • A* (4 or 8 directions)
    • Dijkstra (4 or 8 directions)

Usage

Just import the lib:

import * as Groolkit from '@znuznu/groolkit';

or

const Groolkit = require('@znuznu/groolkit');

What type of grid can I use ?

Any type of two-dimensional arrays. Groolkit doesn't mutate your grids.

What needs Groolkit ?

The only thing required alongside the grid is a callback function to checks the cell property of the grid.

For example, Groolkit needs to know what makes a cell of your array a blocking one in order to avoid it during a shortest path computation.

blockCallbackFn: return true if the cell is a blocking one (line of sight, shortest path, ...)
lightCallbackFn: return true if the cell doesn't let the light passes through (FOV, ...)
floodCallbackFn: return true if the cell is a one to flood (flood, ...)

Documentation

See the full documentation with examples here.

Playground

You can try Groolkit on the playground.

Generated using TypeDoc