This is a small project to show how a open world 2D game can be made with random and customizable terrain generation.
It includes:
- Chunk System which loads and unloads the map in chunks
- Custom Autotiling (only Minimal 3x3 and Full 3x3 possible atm)
- Terrain rendering rules to avoid perfomance issues
- Customizable worlds with configurable biomes and terrains
One Biome:
Godot.Engine.2024.09.30.-.18.21.38.04.mp4
Two Biomes
Godot.Engine.2024.09.30.-.18.22.15.05.mp4
The main class which controls the chunks is the ChunkController.cs. It distributes each chunk to a different state depending on its distance to the player. The chunk controller makes sure that each chunk goes through each state to prepare it for the next possible state.
Depending on your needs you can change the radius of each chunk state area.
ChunkController Inspector (Example)
Each chunk state has got 2 Processors. For example state "Loaded" is assigned to processor "Unrender" and "Load". The difference is that one processor is for upgrading the chunk and the other is responsible for downgrading it.
You can apply some settings in the inspector of the processor nodes to adapt to performance issues or lag spikes. Batch Size is the size of chunks processed per frame.
Example of Inspector
As the set_cells_terrain_connect method in Godot is not optimized for running during runtime I had to write my own custom autotiling. I used bitmasks to find out what tile I need at which position. For a better explanation how bitmasks work check this link: https://code.tutsplus.com/how-to-use-tile-bitmasking-to-auto-tile-your-level-layouts--cms-25673t
Only working minimal 3x3 and full 3x3 atm
All classes belonging to the AutoTiling system are "StrategyTile... .cs" classes.
It is configured in each TileMapLayer Node
As you can see at the top there is the StrategyTileSet. It is the counterpart to Godots "TileSet". Also "TileSetAtlasSource" and "TileData" have their counterparts in my autotiling system. The StrategyTileset is a TOOL Script which automatically reads the given TileSet atlas sources and tile data and creates the needed resources for the autotiling system.
If you want to have a minimal 3x3 autotiling you need the 8Bit bitmask, for a full 3x3 autotiling the 5Bit bitmask. Just exchange it in the StrategyTileSet. It will automatically update every tile. Be aware that you still have to paint the terrains in the TileSet Editor in Godot to work correctly.
This is the most complicated part.
Each world can have (in theory) an infinite number of biomes. You can set up worlds using the WorldConfig.cs and exchange it in the "World" Node.
You can use the WorldConfig.cs to configure the amount of biomes and the location of those.
Just add a new BiomeConfig to the BiomeConfig Array in the WorldConfig.cs
The location is defined by 3 Noises. Each noise is representive for a abiotic factor (temperature, humidity and elevation). To define the location you have to define the abiotic factor VALUES (not noises, but you can also exchange noises). Each biome also has got a reference to its own abiotic factor values.
In simple: The algorithm now subtracts VALUES from the Noise Value and checks which biome has got the smallest difference.