Day 6: Dungeons and Dragons Part 2

From Dungeons to the Overworld ๐Ÿ—บ

This post serves as an update to the previous post: Dungeon Excavation Using a Random Walk

The focus of the project shifted from the generation of dungeons to the generation of semi-natural looking land masses such as an overworld for a DnD campaign (or other TTRPG campaign).

I implemented an object oriented programming approach for how cells and a grid are represented and drawn to the screen. The information is encapsulated in a DrawableCell and DrawableGrid2 class and reside in the assets.py file. All of the changes to the code can be viewed here: Github: landmass-gen

What's New? ๐Ÿ†•

Cell Shaders ๐ŸŒž

Cell "shaders" were implemented. Based on the number of steps taken on each cell in the grid, the RGB value for the cell is shaded by multiplying the red, green and blue component by:

(step_max - (cell_step - 1))/step_max

where step_max is stored in a field within the DrawableGrid2 class and determined during the random walk (see walker.py). So, if a cell has a step value of 1 and the highest step count recorded was 17, then cell_shader = (17 - (1 - 1))/17 = 17/17 = 1. The shader is then applied to the RGB of the cell by multiplying each color component by the shader. Therefore, cells with higher step counts will appear darker when rendered.

Biomes ๐ŸŒณ

I was not satisfied with how the cells were rendered in the previous implementation, that is, they were rendered with only one color. There was an additional color that was a product of the color_spill() method discussed in the previous post, but that color was always yellow or yellow-green. From a quick Google search, I implemented six biomes. They were represented by a dictionary in the biomes.py file in the form:

'biome_name': {

        'landscape':(R,G,B),

        'vegetation':(R,G,B),

        'mountain':(R,G,B),

        'water':(R,G,B),

        'dist':(a,b,c,d),

}

A biome has RGB colors that represent what the general landscape will look like as well as the color for the vegetation, mountains and water. A cell can be rendered in a color representing the landscape, vegetation, mountain or water based on the dist entry for the biome, where a,b,c and d represent probabilities for that color (a + b + c + d = 1.0). Example, the desert biome has a distribution of:

  • landscape = 0.9
  • vegetation = 0.06
  • mountain = 0.03
  • water = 0.01
A random float between 0 and 1 is generated and compared to the distributions in the walker class. All cells are colored and shaded prior to the main game loop in the setup() method to avoid recomputing those values for every iteration of the loop.

Biome Gallery ๐Ÿ–Œ

Here is a render for each biome on a 250-by-250 grid with 25000 cells (more cells can be rendered, but generate too big of a landmass to appreciate the random walk):

Tropical Forest Biome


Temperate Forest Biome

Desert Biome


Tundra Biome


Grassland Biome


Savanna Biome



What's Next? ๐Ÿ ž

I am currently satisfied with how this project turned out. I may add some more features later (mainly the feature to save the rendered landmass to file such as a PNG or JPEG). Feel free to add to the project and make use of it in your own applications. I hope it helps in some way, even if it is an example of how NOT to do something. Any constructive feedback is welcome.

My next DM tool will be the generation of dungeons with actual rooms. Further improvements to this idea would be the generation of optimal dungeons using a genetic algorithm. I am currently learning procedural content generation and machine learning to supplement this project idea.

A reddit user suggested I look into Perlin Noise for more natural generation of landmasses. I will keep this blog updated on my progress.


Comments