https://github.com/sea5kg/roads2dgenerator
algorithm for procedural generation map of roads in 2d or caves or something else
https://github.com/sea5kg/roads2dgenerator
2d caves collapse-wave-function cpp generator map procedural-generation roadmap roads
Last synced: 3 days ago
JSON representation
algorithm for procedural generation map of roads in 2d or caves or something else
- Host: GitHub
- URL: https://github.com/sea5kg/roads2dgenerator
- Owner: sea5kg
- License: mit
- Created: 2023-06-02T05:08:22.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-02T06:46:10.000Z (about 2 years ago)
- Last Synced: 2025-01-11T09:40:45.083Z (over 1 year ago)
- Topics: 2d, caves, collapse-wave-function, cpp, generator, map, procedural-generation, roadmap, roads
- Language: C++
- Homepage:
- Size: 119 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Roads2DGenerator
Implemented simularity for c++, java.
2D map of roads generation algorithm
(collapse wave function???)
Forked and improved from https://github.com/sea5kg/roadmapgen2d
Example of generated structures (30x30 points):




## Usage
1. Copy `src/Roads2DGenerator.*` into your project
```cpp
#include "Roads2DGenerator.h"
...
Roads2DGenerator road2gen;
// configure
road2gen.getConfig()
.setWidth(30)
.setHeight(30)
.setDensity(0.7)
;
// You can use the following parameter (nSeedRandom) to reproduce the results.
// If the parameters are the same, then the result will be the same on any machine.
road2gen.getConfig().setSeedInitRandom(std::time(0));
// road2gen.getConfig().setSeedInitRandom(1686154273);
road2gen.getConfig().setPresetExcludes(12, 10, 18, 15);
if (!road2gen.generate()) {
std::cerr
<< "FAILED. Could not generate. Try again or change input params and try again." << std::endl
<< "Init Seed: " << road2gen.getConfig().getSeedInitRandom() << std::endl
<< "Error Message: " << road2gen.getErrorMessage() << std::endl
<< std::endl;
return 1;
}
// use a table with true/false
std::vector> vPixelMap = road2gen.exportToPixelMap();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (vPixelMap[x][y]) {
// has road
} else {
// no road
}
}
}
// or use a table with directional elements
std::vector> vTable = exportToTable();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
std::string sRoad = vTable[x][y];
if (sRoad == "cross") {
// ╬
} else if (sRoad == "horizontal") {
// ═
} else if (sRoad == "vertical") {
// ║
} else if (sRoad == "right-down") {
// ╔
} else if (sRoad == "left-down") {
// ╗
} else if (sRoad == "right-up") {
// ╚
} else if (sRoad == "left-up") {
// ╝
} else if (sRoad == "left-up-down") {
// ╣
} else if (sRoad == "right-up-down") {
// ╠
} else if (sRoad == "left-right-down") {
// ╦
} else if (sRoad == "left-right-up") {
// ╩
} else {
// nope
}
}
}
// json examples
road2gen.exportLikeJsonPixelMapToFile("road2dgen_example_pixelmap.json");
```
## Used in games
### yourCityIsInvadedByAliens
Repo: https://github.com/sea5kg/yourCityIsInvadedByAliens
SDL 2D game
### The Guiding Thread
Description: https://itch.io/jam/sibgamejam-may-2025/rate/3530033
Gameplay: https://youtu.be/pl22Vp3yUuY?si=YqOClG28xD4-bAZ6
Unigine 3D game
## Projects with similar algorithms
### Tank_Game
https://github.com/nickolasddiaz/Tank_Game/
Generator: [core/src/main/java/io/github/nickolasddiaz/utils/TerrainGenerator.java](https://github.com/nickolasddiaz/Tank_Game/blob/master/core/src/main/java/io/github/nickolasddiaz/utils/TerrainGenerator.java)