Giter Site home page Giter Site logo

justinoverton / dungeonizer.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mlknz/dungeonizer.js

0.0 2.0 0.0 606 KB

Dungeon generation + visualization.

Home Page: https://mlknz.github.io/Dungeonizer.js/

License: MIT License

JavaScript 93.09% HTML 1.52% GLSL 3.06% CSS 2.33%

dungeonizer.js's Introduction

Dungeonizer.js

Dungeon generation + visualization in javascript / webgl.
Live version here.

alt tag

The general idea is borrowed from this blog article on gamasutra.

Project builds into 2 scripts: dungeonizer.js and dungeonVisualiser.js.

Details:

  1. Whole dungeon is on integer grid.
  2. Seeded random is used, so you could reconstruct dungeon from id.

Algorithm (briefly):

  1. Room sizes are generated.
  2. Rooms are placed without collision (placing rooms one by one. Moving room in random direction until there are no collisions, after that doing a round trying to place room closer).
  3. Main rooms are chosen and placed into dungeon (room is main if its width and height is more than certain threshold).
  4. Delanay triangulation is formed from main rooms centers.
  5. Forming minimal spanning tree from triangulation + leaving some extra edges.
  6. Rooms which are connected in graph are connected with tunnels.
  7. Rooms which are intersected by tunnels are attached to dungeon.
  8. Tunnels are splited, so there are no tunnels over rooms.
  9. Walls generation is completed, walls-walls, walls-tunnels intersections are resolved.

Dungeon generator usage:

  • include dungeonizer.js to your HTML (could be found at dist/scripts).
  • var dungeon = window.dungeonizer.generateDungeon(params, withWalls, isDebug) or var dungeon = window.dungeonizer.generateDungeonById(dungeonId, withWalls, isDebug).
  • params is expected to be an object with following structure: { seed: 'your seed string', dungeonSize: Number > 0, roomSizeDistribution: 'normal' || 'uniform', roomSizeMean: Number > 0, roomSizeDeviation: Number > 0, mainRoomThreshold: Number > 0, connectivity: Number <= 1, density: Number <= 1}.
  • all parameters are optional and defaults could be found at src/scripts/config.js.
  • withWalls determines whether walls are generated and returned.
  • isDebug determines whether additional information is returned.
  • dungeonId is a string composed from params, look the structure in src/scripts/app-ui generateNewDungeonId() method.
  • returned dungeon will be an object with following structure: {rooms: [{x, y, w, h, size, x1, x2, y1, y2}, ...], tunnels: [tun1_x1, tun1_y1, tun1_x2, tun1_y2, tun2_x1, ...]}.
  • if withWalls is set, dungeon object will contain walls property with same structure as tunnels.
  • if isDebug is set, dungeon object will contain trashRooms property with same structure as rooms and delaunayTriangles, mstLines, leftAliveLines properties with arrays of lines coordinates ([line1_x1, line1_y1, line1_x2, line1_y2, line2_x1, ...]).

To launch the project locally:

  1. Install Node.js v5 or higher.
  2. Clone project to your hard drive.
  3. Run "npm install" in project root directory.
  4. Run "gulp watch" to launch dev server.
  5. Look in terminal what port is used and navigate to http://localhost:${port} (default is http://localhost:9000).
  6. To update build run gulp build.

dungeonizer.js's People

Contributors

mlknz avatar

Watchers

James Cloos avatar J 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.