Wednesday, June 1, 2016

procedural generation - Correct way to "randomly" generate flowing terrain



I'm creating a simple top down RTS game. I plan on it "randomly" generating maps on the fly when I need to. I plan on it all working in 'passes':



  1. Fill the terrain in with all grass

  2. Go back and add some random spurts of gravel

  3. Round out the gravel

  4. Draw Mountain Landscape on second layer

  5. Round out mountains

  6. etc. etc.


Now, take a look at this picture below:



enter image description here


I hand created this using my map editor but I plan on this basically being the result after hopefully pass/step 3.


How should I go about deciding when and were to place my gravel so that it is at least irregularly shaped and sporadic enough to look natural?


Thanks if you can! Any and all help is appreciated!


As a side note:


Each pass is basically me iterating through all of my tiles (The map is divided into 40x40 tiles) similar to this:


for (int x = 0; x <= GRIDMAX - 1; x++) {
for (int y = 0; y <= GRIDMAX - 1; y++) {
//Terrain(x, y, 0) = SomethingHere;
}

}

Answer



You can play around with Perlin Noise (see my StackOverflow answer for an implementation), to generate a height map. From the height map, you can map certain height ranges to different tiles. Something like:



  • Top 20% Snow

  • Next 20% Gravel

  • Next 40% Grass

  • Last 20% Water


You will have to play with the Perlin Noise generator values to get a terrain that can be generated and look nice.



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...