npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

2d-dungeon

v1.0.1

Published

prodecural dungeon generator for games

Downloads

39

Readme

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