libmapgen
Edit: This project is dead. This website is left as an archive. See README.
C# library for procedural map generation
libmapgen is going to be a library that can be used to generate 2d tile-based maps procedurally, with ease. Using a series of passes, you can build a ruleset for generating a map by giving instructions like so:
- generate a heightmap using simplex algorithm at 20x20
- simplify the heightmap to tiles of these types:
- water (lowest 35%)
- grass (36%-70%)
- hills (71%-90%)
- mountains (91%-100%)
- generate trees on grass and hills at a frequency of 60%
- generate rivers running from higher to lower places, in between the tiles
- generate towns, more common at rivers and coasts
- generate roads, made by pathfinding from town to town within a radius
Something like that. Unity game engine integration is also being worked at on Terrainstorm. Initial implementation will be in C#, afterwards porting to C++ if there's enough time. libmapgen is part of my final school project.
Usage
using libmapgen; Ruleset ruleset = new Ruleset(new RandomGenerator(10, 10, 0.0f, 1.0f)); // add initial generator ruleset.passes.Add(new FlattenPass()); // add 1 or more map passes MapArea map = ruleset.generate(); // generate map // use MapArea here
Status
Basic generator/passes system is currently working. These generators are currently working:
- RandomHeightmap (creates a map where every tile is a random height between a min and a max
- FlatHeightmap (creates a flat map)
These passes are implemented:
- DummyPass (does nothing)
- FlattenPass (flattens terrain below or above a certain threshold)
Testing is currently badly done because I've been focusing more on functionality and I'll need to sit down to think about how I want it done a bit more. There's no guarantee of API stability at all, though the current structure seems like it could be a good one. I'll stabilize it some more when I have good results with this and Terrainstorm.
Contributing
The easiest way to contribute is to add a new IInitialGenerator or IMapPass.