node framework for real time generation of grid/tiled maps based on a previously defined set of constraints/rules
This project goal is to provide an open framework to ease the generation of game worlds using predefined rules in a semi-automatic approach joining the benefits of procedural generation with manual art work creation. By other words, this framework generates structured maps in real time handling expansions when needed respecting game design rules in order to create additive game worlds.
See a video demonstration here: https://youtu.be/-yyQ-vyKdYw
$ npm install rule-based-map-generator
You can design your maps using different rules. They are:
- Initial map size (mandatory)
- Horizontal and vertical bounds
- Map center
- Evaluation period (not yet implemented)
- Maximum occupation
- Maximum occupation by percentage
- Minimum distance between other blocks
- square grid
- hexagonal grid (not yet implemented)
Below is a minimal example of how to configure and create a world.
First require rule-based-map-generator module.
var ruleBasedMapGenerator = ;
Here we create a strategy of generation. In these case we will choose a strategy for square grid maps.
var strategyName = 'squareGrid';var worldSeed = 1337;var strategy = ruleBasedMapGenerator;
In order to create blocks, we need to create a block factory for the previously created strategy. Then we create 3 blocks without constraints for the sake of simplicity.
var blockFactory = ruleBasedMapGenerator;var block1 = ;var block2 = ;var block3 = ;
To define how blocks connect between each other in the world we need to create connectors.
var connector1 = ruleBasedMapGenerator;var connector2 = ruleBasedMapGenerator;
Now we can attach the connector to the desired blocks sides.
block1;block1;block1;block1;block2;block2;// and so on...
Before creating the world instance we need to create the world constraints.
var initialMapSize = 4;var bounds = horizontal: 10 vertical: 10 ;var mapCenter = 'B2';var worldConstraints = ruleBasedMapGenerator;
Now we are ready to create our world.
var world = ruleBasedMapGenerator;
But wait! There is more. Instead of setting up the world using all these API methods you can take advantage of the World Parser to create a world based on a single configuration.
var worldParser = parser;var configuration = ;var world = worldParser;
You can see examples of world configurations here.
We can retrieve map using the following world methods:
var minX = 0 minY = 0 maxX = 4 maxY = 4;var partialMap = world;
var map = world;
Both result in a matrix representing the world. An example can be seen below:
You can see examples here.
There is still a lot to be done from adding new rules to adding new generation strategies. If you want to contribute, don't be shy and create a pull request.