2.1.5 • Published 4 years ago

dungeoneer v2.1.5

Weekly downloads
16
License
MIT
Repository
github
Last release
4 years ago

Build Status npm version Dependency Status

This module is a tool for generating random dungeons as a two-dimensional array. It is largely based on the excellent work of Bob Nystrom and his game Hauberk, which you can read about here.

A demo of this module can be seen here https://lucianbuzzo.github.io/dungeoneer/

Installation

Install dungeoneer by running:

$ npm install --save dungeoneer

Usage

const dungeoneer = require('dungeoneer')

const dungeon = dungeoneer.build({
  width: 21,
  height: 21
})

The build method accepts width and height options that define the size of the dungeon and will return a dungeon object. The smallest possible size for a dungeon is 5 x 5. Dungeons are always an odd size due to the way walls and floors are generated. If you supply even-sized dimensions, they will be rounded up to the nearest odd number. The shape of the dungeon object is defined below:

type Tile = {
  // An object containing the tiles immediately surrounding this tile.
  neighbours: {
    n?: Tile;
    ne?: Tile;
    e?: Tile;
    se?: Tile;
    s?: Tile;
    sw?: Tile;
    w?: Tile;
    nw?: Tile;
  };
  x: number;
  y: number;

  // 'floor' and 'door' are passable terrain and a wall is impassable terrain.
  type: 'wall' | 'floor' | 'door';
}

type Room = {
  height: number;
  width: number;
  x: number;
  y: number;
}

type Dungeon = {
  rooms: Room[];
  tiles: Array<Tile[]>;
  seed: string | number;
}

Seeding

A dungeon can be seeded using the seed option. A dungeon created with a seed and the same options can be repeatably created. Dungeons always return the seed they were created with.

const dungeoneer = require('dungeoneer')

const dungeon = dungeoneer.build({
  width: 21,
  height: 21,
  seed: 'foobarbaz'
})

License

The project is licensed under the MIT license.

The icon at the top of this file is provided by svgrepo.com and is licensed under Creative Commons BY 4.0.

2.1.5

4 years ago

2.1.4

4 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago