Hey everyone,
This week, I worked on implementing a first version of a random terrain generator, based on tiles. Here are the results:
The general idea is that my terrain is separated in ground layers, which are presented in form of a tree, telling me which kind of terrain can go over which. It also contains additionnal data, like the probability to spawn the concerned ground layer and the probability that it expands to its neighborhood:
Then, I use these data to generate a “terrain type grid”, where each cell contain a ground layer type. I fill it by reading my tree from root to leafs, spawning and expanding only over cells containing the parent layer. Finally, I reduce the noise by applying a couple of iterations of a cellular automata similar to this one. This gives my a grid of desired terrain type, which I need to convert to tiles sprites from my tileset:
In order to do this, I consider each cell of my “terrain type grid” as the shared corner of 4 tile sprites. Furthermore, I consider that under a terrain type lies all parent types. Thus, all my grid is considered to contain "dirt" in each cell. Then some cell contain grass or gravel, and the cells containing grass can also contain greener grass or flowers. Depending on the number of corners containing the chosen terrain type, I draw either nothing, a ¼corner, a side, a ¾ corner, two opposite ¼ corners or a full tile:
Finally, I share this over the network for multiplayer by simply sending the generation parameters and the seed.
My plan for the future will be to generate different entities depending on the terrain type (for example, no tree on the dirt and more trees on the greener grass). I will also add “points of interest”, which are special handcrafted world elements (that could be for example a farm, a dungeon entrance, some special tree, etc), which would be placed on the map before the terrain generation. I'll also experiment with random caves and dungeon generation.