06-24-2024, 07:57 PM
In the process of putting together some examples and tutorials for upcoming updates to the GX game engine project I've been working on for a bit, I thought it might be cool to look at some procedural map generation examples. Historically, I've primarily worked with games that use "hand-drawn" maps. GX has a map maker program that can be used for this. There are a whole host of games types though that use procedural generated maps, so that for each play you have a new world to explore.
Anyway, in the process of looking into this further I began experimenting with the wave function collapse algorithm. It's a pretty neat way to generate maps from a sample one that is created manually. That map is then analyzed and used as a template or rule set for then generating new maps that have the same basic features. For a more in depth discussion of how this all works I would recommend this article.
Here is my initial attempt at implementing the algorithm in QB64/QBJS. You can run it from the embedded version below. If you want more room to see the output you can also launch it in a new tab from this link.
To try it out in QB64 just download and unzip the wfc.zip file that is attached to a location on your filesystem. Then compile and run the main.bas file. (This program uses relative paths, so make sure you have the "Create exe in same directory as source" option selected.)
This is definitely still a work in progress. For this to be used for generating very large maps, some additional optimization will need to be applied. I would also like to look at being able to render multiple layers, as well as potentially just generating a specific region of the map at a time which would allow you to potentially create different "biomes".
If it works out and seems useful I may add it as an optional include in future releases of GX.
Anyway, in the process of looking into this further I began experimenting with the wave function collapse algorithm. It's a pretty neat way to generate maps from a sample one that is created manually. That map is then analyzed and used as a template or rule set for then generating new maps that have the same basic features. For a more in depth discussion of how this all works I would recommend this article.
Here is my initial attempt at implementing the algorithm in QB64/QBJS. You can run it from the embedded version below. If you want more room to see the output you can also launch it in a new tab from this link.
To try it out in QB64 just download and unzip the wfc.zip file that is attached to a location on your filesystem. Then compile and run the main.bas file. (This program uses relative paths, so make sure you have the "Create exe in same directory as source" option selected.)
This is definitely still a work in progress. For this to be used for generating very large maps, some additional optimization will need to be applied. I would also like to look at being able to render multiple layers, as well as potentially just generating a specific region of the map at a time which would allow you to potentially create different "biomes".
If it works out and seems useful I may add it as an optional include in future releases of GX.