https://github.com/alex-c/random-walk-map
Two-dimensional maps generator using random walk.
https://github.com/alex-c/random-walk-map
2d-map dungeon-generation dungeon-generator map-generation map-generator random-walk
Last synced: 4 months ago
JSON representation
Two-dimensional maps generator using random walk.
- Host: GitHub
- URL: https://github.com/alex-c/random-walk-map
- Owner: alex-c
- License: apache-2.0
- Created: 2018-04-20T20:06:03.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-04T16:47:07.000Z (about 8 years ago)
- Last Synced: 2025-10-14T13:23:52.167Z (8 months ago)
- Topics: 2d-map, dungeon-generation, dungeon-generator, map-generation, map-generator, random-walk
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# random-walk-map
Two-dimensional maps generator using random walk. For procedural generation using a seed, check out [procedural-map](https://github.com/alex-c/procedural-map).
## Installation
Install via npm:
$ npm install --save random-walk-map
## Usage
Call the function exposed by the package to generate a two-dimensional map with connected paths. It returns a matrix (an array of arrays), where each postion contains 0 (default) or 1 (a path).
```javascript
let generateMap = require('random-walk-map');
//Generate a map with default config
let map = generateMap();
/* Example output:
* map =[[0, 0, 0, 0, 1],
* [0, 0, 0, 0, 1],
* [0, 1, 1, 0, 1],
* [0, 0, 1, 1, 1],
* [0, 0, 0, 0, 0]]
*/
```
## Configuration
The generator can take a config object, with any of the following parameters:
```javascript
let map = generateMap({
numberOfPaths: 10, //Number of paths to draw
minPathLength: 1, //Minimal length of a path
maxPathLength: 5, //Maximal length of a path
maxWidth: 24, //Maximum width of the map - x index will go from 0 to 23
maxHeight: 18, //Maximum height of the map - y index will go from 0 to 17
startPosition: {x: 0, y: 0} //Position at which random walk is started
});
```