Thursday, October 5, 2017

procedural generation - Generating tile map


I am programming a tile based game and I have some basic tiles (grass, dirt, etc..), but I can't figure out how to make good random map generation, because when I do some really random selection, if the tile should be grass/dirt, I get this:


In-game picture


I understand why this is happening, but what I want is to create some random continuous areas of grass or dirt. Something that would make more sense, like this:


Desired result



Answer



What you could do is randomly generate a Voronoi map like this:




  1. Picking random center points (see the black dots) and randomly decide if they are grass or dirt.

  2. Then for over all tiles, check if it's closest to a center point of dirt or a grass.

  3. Done!


If what you did previously is "flip a coin" for each tile (noise), generating a Voronoi diagram will provide a much better result.


You could improve on this by dividing the center points into islands with an algorithm that:



  1. Picks a small group of centers points and designates them as leaders.

  2. Iteratively adds a random adjacent undecided center point each turn.


  3. Done!


enter image description here


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...