Designing and painting an entire world by hand would be an enormously time consuming task. Therefore all planets of Nimbatus are procedurally generated, this means instead of painting the terrain by myself it gets generated using different mathematical functions. This technique allows me to generate the world piece by piece while the palyer moves around, without the need to load the entire world at once.
The visible terrain in Nimbatus is basically just an array of floating point numbers between 0 and 1, where 0 stands for air and 1 for solid terrain. So the only thing needed to generate a landscape is a function that takes a point on the screen and returns a number between 0 and 1.
Here are some examples using different functions to calculate the landscape (Flat, Sine, Perlin Noise, Ridged Multifractal Noise) :
I use a combination of all these functions to calculate the landscape of the planets. Multiple iterations of two dimensional Perlin Noise combined with a sine function are used to define the surface of a planet. For the cave system I use Ridged Multifractal Noise. For the generation of the different climate zones I’m currently using a Voronoi diagram. However this generates hard borders between the different climate zones. So I will most likely combine it with another noise function to achieve a more natural look.
The terrain in Nimbatus consists out of two layers, a destroyable foreground layer and a static background layer. The background is not destructible and is filled with objects like trees or other background items that do not collide with the anything. The foreground layer has physically reacting objects like falling stones or living creatures. Additionaly the landscape of the foreground layer can be destroyed.
In order to render this destructible terrain, it’s necessary to generate triangles at runtime which can be processed by the graphics card. For this task I took the Marching Cubes algorithm by Paul Bourke and simplified it to work only in two dimensions. I will explain my implementation of the algorithm in a later post. Here are two images giving an idea how it works.
As you can see, generating a planet in Nimbatus is requires alot of calculation while playing the game. To provide smooth and fluid gamplay, a game needs to run at least at 60 frames per second. Because of this reason, all the calculation is done within multiple background threads using a thread pool.
There is alot more to the whole terrain generation (different climate zones, item distribution, floating point precision, …) , but this would exceed the scope of this post. If you are interested into this kind of technical posts, I will continue to write them.