While I was still making a spy game, I was researching methods on how to generate maps efficiently. The one method that stuck with me was by storing the map in chunks that are saved in the players PC. This means that they then don’t need to generate the maps again if they put the same seed. As I researched more and more into this, I found this perlin noise generator on the YoYoGames marketplace. This completely shifted the design of my game and led to what my game is like today.
Perlin noise is a way of turning noise into structures using algorithms. Perlin noise is relatively fast compared to many other methods although it does lose out to simplex. This margin was too small for me to worry about so I stuck it with perlin noise.
I first wondered what kind of map was I creating. Was I still going to make a top down game? The appeal seemed minimal for me compared to a platformer. The structures that could be created in a platformer enticed me more. So I stuck with 1-dimensional interpolated perlin noise. My first results came out like this:
It was interesting enough to whet my appetite. Although I found the structures not as organised. I started looking at other games that use procedural generation for their terrain (i.e Terraria, Starbound) and I saw that they had one thing similar. They used blocks. I tried to incorporate blocks straight away but the result was similar. Just that the different blocks were distinguishable:
I then created a macro named tile_size and set it to 32. I had envisioned my blocks to be 32×32. After this, I messed with the generation to only generate 1D heightmaps. Depending on the x value that you input into the heightmap, it passes a y value to get the height of the terrain at that x position. Anything underneath that y value was terrain as well. The results were a lot more structured.
The only problem I had now was that I needed to store the chunks so that it was possible to go back and see the same structures and to allow the terrain to be altered. I started reading on buffers and it simplified everything. I just had to check a chunk of the map, see if it was saved in memory, if it wasn’t I would generate a new part of the terrain and save it, if it was in memory I would just load it. The buffers stored the map in between saving and loading. Perfect.
After playing with a few variables (like changing the tile size from 32×32 to 16×16 until finally 8×8 tiles). I had a solid system and the prototype was starting to take shape.
If you enjoyed this post, please leave a comment below. Would appreciate a share on social media too!