Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

dungeoneer

LucianBuzzo60MIT2.1.5TypeScript support: included

A procedural dungeon generator

procedural, map, generator, dungeon, games, level, roguelike

readme



Build Status npm version Dependency Status

Dungeoneer

Procedurally generate beautiful 2d dungeons for your game.
https://lucianbuzzo.github.io/dungeoneer



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.

changelog

Change Log

All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to Semantic Versioning.

v2.1.4 - 2019-12-30

  • Fix the dungoneer.d.ts #25 [Michael Pearson]

v2.1.3 - 2018-12-09

  • Fix bug where stryker conf stopped fixtures from loading #22 [Lucian]

v2.1.2 - 2018-12-09

  • Add a .toJS() method and test against a fixture #21 [Lucian]
  • Increase test coverage #21 [Lucian]

v2.1.1 - 2018-12-06

  • Update README.md #20 [Lucian Buzzo]

v2.1.0 - 2018-12-06

  • Add functionality for seedable dungeons #19 [Lucian]

v2.0.5 - 2018-12-05

  • Use const and let in demo code #18 [Lucian]

v2.0.4 - 2018-12-05

  • Fix bug where tiles inside rooms could sometimes be filled in #16 [Lucian]

v2.0.3 - 2018-12-03

  • Fix error where rooms could go out of bounds #14 [Lucian]

v2.0.2 - 2018-12-02

  • Add test to ensure that all accessible tiles can be visited #13 [Lucian]

v2.0.1 - 2018-12-02

  • Add tests for rooms #12 [Lucian]

v2.0.0 - 2018-12-02

  • Add stryker mutation testing #11 [Lucian]
  • Improve testing #11 [Lucian]
  • Add test for width and height of tiles array #11 [Lucian]
  • Rename generator.js to index.js and generate() to build() #11 [Lucian]
  • Add ava testing and nyc reporting #11 [Lucian]
  • Simplify Tile structure #11 [Lucian]

v1.1.3 - 2018-12-01

  • Add TypeScript typings #10 [Lucian]
  • Improve documentation of generate function #10 [Lucian]

v1.1.2 - 2018-12-01

  • Add js tag to example markdown #9 [Lucian Buzzo]

v1.1.1 - 2018-12-01

  • Fix broken SVG due to minification #8 [Lucian]

v1.1.0 - 2018-12-01

  • Fix JS paths in demo #7 [Lucian]
  • Make demo page prettier #7 [Lucian]

v1.0.10 - 2018-11-30

  • Use a .png for the README icon #6 [Lucian]
  • Display version in web demo #6 [Lucian]
  • Auto deploy to gh-pages from travis #6 [Lucian]
  • Use parcel for development #6 [Lucian]

v1.0.9 - 2018-11-30

  • B64 encode the SVG icon in README #5 [Lucian]
  • Add standardJS linting and use it to fix linting errors #5 [Lucian]
  • Ignore unnecessary files when packaging for npm #5 [Lucian]
  • Add editorconfig file #5 [Lucian]
  • Make .gitignore more comprehensive #5 [Lucian]

v1.0.8 - 2018-11-30

  • Update README to include badges and icon #4 [Lucian]

v1.0.7 - 2018-11-30

  • Add travis configuration #3 [Lucian]

1.0.6 - 2016-12-26

  • Fixed issue where rooms would sometimes be generated in positions that overflowed the stage.