# 2d-dungeon

> prodecural dungeon generator for games

Latest version **1.0.1** (published 2023-05-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install 2d-dungeon
pnpm add 2d-dungeon
yarn add 2d-dungeon
bun add 2d-dungeon
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-05-28 |
| First published | 2020-05-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 54 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | domasx2@gmail.com, prozi85@gmail.com |
| Maintainers | jacekpietal |
| Keywords | dungeon, generator, map, procedural, games |

## Links

- npm: https://www.npmjs.com/package/2d-dungeon
- Repository: https://github.com/Prozi/dungeon-generator
- Homepage: https://github.com/Prozi/dungeon-generator#readme
- Issues: https://github.com/Prozi/dungeon-generator/issues
- npm.io page: https://npm.io/package/2d-dungeon

## Dependencies (1)

- [random-seed](https://npm.io/package/random-seed.md) ^0.3.0

## Recent versions

- 1.0.1 (latest) — 2023-05-28
- 1.0.0 — 2023-05-28
- 0.0.8 — 2023-05-28
- 0.0.7 — 2020-05-09
- 0.0.6 — 2020-05-09
- 0.0.5 — 2020-05-09
- 0.0.4 — 2020-05-09

## README

# Dungeon generator

This is a procedural dungeon generator written in javascript.

[Live demo](https://domasx2.github.io/dungeon-generator/)

## Installation

```
yarn add 2d-dungeon --save
```

## Features

1. Pre-defined, tagged rooms
2. Highly configurable
3. Seeded rng
4. Feedback about exits, perimeter, etc
5. (Optional) corridors
6. (Optional) circular paths

## Output examples

![Sample 1](https://domasx2.github.io/dungeon-generator/samples/sample1.png)
![Sample 2](https://domasx2.github.io/dungeon-generator/samples/sample2.png)
![Sample 3](https://domasx2.github.io/dungeon-generator/samples/sample3.png)
![Sample 4](https://domasx2.github.io/dungeon-generator/samples/sample4.png)

## Usage

@TODO

```javascript
import { Dungeon } from "2d-dungeon";

let dungeon = new Dungeon({
  max_iterations: 50,
  size: [100, 100],
  seed: "abcd", //omit for generated seed
  rooms: {
    initial: {
      min_size: [3, 3],
      max_size: [3, 3],
      max_exits: 1,
      position: [0, 0], //OPTIONAL pos of initial room
    },
    any: {
      min_size: [2, 2],
      max_size: [5, 5],
      max_exits: 4,
    },
  },
  max_corridor_length: 6,
  min_corridor_length: 2,
  corridor_density: 0.5, //corridors per room
  symmetric_rooms: false, // exits must be in the center of a wall if true
  interconnects: 1, //extra corridors to connect rooms and make circular paths. not 100% guaranteed
  max_interconnect_length: 10,
  room_count: 10,
});

dungeon.generate();
dungeon.print(); //outputs wall map to console.log

dungeon.size; // [width, heihgt]
dungeon.walls.get([x, y]); //return true if position is wall, false if empty

for (let piece of dungeon.children) {
  piece.position; //[x, y] position of top left corner of the piece within dungeon
  piece.tag; // 'any', 'initial' or any other key of 'rooms' options property
  piece.size; //[width, height]
  piece.walls.get([x, y]); //x, y- local position of piece, returns true if wall, false if empty
  for (let exit of piece.exits) {
    let { x, y, dest_piece } = exit; // local position of exit and piece it exits to
    piece.global_pos([x, y]); // [x, y] global pos of the exit
  }

  piece.local_pos(dungeon.start_pos); //get local position within the piece of dungeon's global position
}

dungeon.initial_room; //piece tagged as 'initial'
dungeon.start_pos; //[x, y] center of 'initial' piece
```

or

```js
import { createDungeon } from "2d-dungeon";

const size = 48; // width, height
const scale = 2; // will stretch the array
const options = {};
const dungeon = createDungeon(size, scale, options);
```

---
_Source: https://npm.io/package/2d-dungeon · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
