Cellular Atomata is another algorithm once can use to generate procedural levels - perfect when you want to create a map for a rogue-like, Zelda or even Civilization like maps.

Roguebasin provides an excellent description on how this level generation works.

The code is briefly commented out and includes some tips to how you can adjust the level generation to fit it in your game. In short, the code does the following:

  1.  Initialize an array with zeroes. 0-es are floors, while 1-s are an impassable terrain (walls, trees, etc.);
  2. Loop through the entire array and randomly set 1-s into the array.  Slider "Chance of walls" allows you to set it to the percentage you want;
  3. Now, loop through the entire array several times and imlement 4-5 Rule - we pick one cell and evaluate all adjacent cells (9 cells total). If we have 5 or more 1's in this area, the central cell also becomes 1. Else, it becomes a 0. This process smoothes out our level, making it more cave-like and reducing the "noise" of the level. "Number of Passes" slider allows you adjust this value. "4-5 Rule" slider allows you to adjust this value (I would recommend leaving it as is, and just play with it to see how the level changes because of it).
  4. Once we are done we will create set values of the tileset accordingly.


Additional settings:
Two additional sliders allows you to adjust width and height of the generated level. Recommended is 24 and higher.

The "Create Borders" checkbox creates a border on the outer edge of the level - checking it will confine the cave within the tilemap. Unchecking it will dramatically change the way a level is created - I encourage you try it out yourself.

Distribution license:

All materials here are free to use for both personal and commersial projects.  Selling it (adjusted or not) is not permitted.

Tileset and fonts are by awesome @KenneyNL

PS

If you need help with the code, have found a bug, have some ideas on how to make it better please reach out to me on twitter @AtwoodPer

Tagging me on Twitter or just linking to this itch.io page would be very nice, but not mandatory. Consider donating if this helped you out and you would want me to make more of similar things.

Download

Download NowName your own price

Click download now to get access to the following files:

Cellular Automata.c3p 63 kB

Comments

Log in with itch.io to leave a comment.

(+1)

hello i would like some help with customizing this code to my project and i would also like to pay you for the help, i basically want to know how to create loot/ certain objects, change the size 

(+1)

Gg