Git Product home page Git Product logo

dungeon-generator's Introduction

Dungeon generator

This is a procedural dungeon generator written in javascript.

Live demo

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 Sample 2 Sample 3 Sample 4

Usage

@TODO

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

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);

dungeon-generator's People

Contributors

domasx2 avatar prozi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.