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':
- Fill the terrain in with all grass
- Go back and add some random spurts of gravel
- Round out the gravel
- Draw Mountain Landscape on second layer
- Round out mountains
- etc. etc.
Now, take a look at this picture below:
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