Advertisement

Simple 2D map generation? (tiles)

Started by July 31, 2018 12:21 PM
13 comments, last by Lynix 6 years, 2 months ago

Hi!

Im looking for a simple way to generate random maps with some different terrain (open, forest, water, hills, mountains and swamp).

The map is a topdown 2d grid. See (these tiles manually edited) example of grid below

image.png.e743d491c4caf1373e9cd0ccf5e31ddd.png

I want something similar but generated. My other option is to manually make sections (map-pieces) and place these next to each other but that is worse for the project i think (and hard to make sections back to back without the map looking unnaturally composed of boxes (the sections).

The maps doesn't need to be huge, maybe 5x5 of what is shown above. I need to add "forests", "lakes", "ridges" (simply a somewhat natural grouping of tiles) to the flat plains somehow but dont know how to do that. Also there is NO terrain height (just different types of terrain).

Thank you for your help
Erik

Hi there

If you are looking to tile it yourself procedurally, you'd probably want to check out perlin noise, used commonly to generate 3D heightmaps that you'd use to define lakes, ground, hills and mountains by defining height ranges for each.

As for scattering of vegetation and other elements you might want to check out 3D distribution algorithms such as Poisson Disk and then move trees a random amount to fit a distribution that would look compelling/realistic to you. Also check for Teleological vs. Ontogenetic forest algorithms.

If it's a 2D map you're after, by tuning perlin noise parameters values you coulg generale everything you need.

Advertisement

Thanks for your answer. I saw perlin noise when researching this, but how would that get me to forests and swamps and coastlines? It seems to generate "cloud" looking heightmaps. 

128px-Perlin.png

I understand i can interpret different ranges of the heightmap as different terrain types such as

0 to 0.2 = water
0.2 to 0.4 = forest
0.4 to 0.6 = swamp
0.6 to 0.8 = hills
0.8 to 1.0 = mountains

but that would always make mountains surrounded by hills then a ring of swamp etc right? Also tweaking the amount of different things you want (such as more forest, larger swamps etc) is that doable?

I know this is a super large field so maybe this is too complicated for what i need to achieve.

You can use perlin in any dimension. It has the potencial to make it look like in this example:

Main Map

It can be a matter of you deciding how many dimensions and what they mean for your use case.

Also, you'll know in your grid system which areas are eligible for terrain assets such as trees and such. So you apply a followup algorythm to fill in the gaps (like 2D poisson disc).

Here's a link that I bookmarked that lists several algorithms used in games in several scenarios:

http://pcg.wikidot.com/category-pcg-algorithms

But was my assumption correct? That is how I would use it? (interpret ranges as different distinct terrain types?

And wouldnt I get the problem with terrain such as swamp always surrounding the next terrain type, in my example hills?
I just find (loads of) tutorials for terrain height, i need something for distinct terrain types.

I found this example (which seem to support my fear that all terrains would be hiarchical/surrround the next terrain type):

0.0f to 0.4f water 
0.4f to 0.45f beach
0.45f to 0.6f plains
0.6f to 0.8f light forest
0.6f to 0.8f dark forest

image.png.9f915288f13136170f74136252110241.png

If you're limiting yourself to just one noise channel, just one dimension... then yes, any continuous function will only produce continuous values. But if you have, for example, an "A" and a "B" channel, and make decisions based on both...

A < 0.40, B anything: lake/ocean

A < 0.45, B < 0.6: beach

A < 0.45, B >= 0.6: cliff/rocks

A < 0.60, B < 0.3: grass/plains

A < 0.60, B >= 0.3: savanah

A < 0.9, B < 0.4; deep forest

A >= 0.9, B >= 0.8: mountains

Otherwise: light forest

 

Now you can have several different kinds of terrain butt up against another, while still being able to define which ones may be adjacent. Diagrammatically:

 

image.png

RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Advertisement
21 minutes ago, suliman said:

But was my assumption correct? That is how I would use it? (interpret ranges as different distinct terrain types?

And wouldnt I get the problem with terrain such as swamp always surrounding the next terrain type, in my example hills?
I just find (loads of) tutorials for terrain height, i need something for distinct terrain types.

Perlin and Simplex noise are just raw noise functions.  The only thing they really do is give you a repeatable noise map given a particular seed. You typically have to overlay different frequencies of noise perhaps with offsets and run them though various filters to get something useful out of them.  There are a ton of different things you can do with them but you will probably have to look around the web and even do some experimentation.

That being said you don't really have to use a noise function for what you are doing. One of the main advantages of nose is that it gives you a value at any given coordinates without storing any data other than the seeds and filter functions.  If you are storing tiles anyway you can use any sort of procedural generation, noise based or otherwise.

1 hour ago, suliman said:

But was my assumption correct? That is how I would use it? (interpret ranges as different distinct terrain types?

And wouldnt I get the problem with terrain such as swamp always surrounding the next terrain type, in my example hills?
I just find (loads of) tutorials for terrain height, i need something for distinct terrain types.

I found this example (which seem to support my fear that all terrains would be hiarchical/surrround the next terrain type):

0.0f to 0.4f water 
0.4f to 0.45f beach
0.45f to 0.6f plains
0.6f to 0.8f light forest
0.6f to 0.8f dark forest

For your scenario I'd say it would be achieved doing it with a basic noise based approach. It is just a matter of understanding the noise algorithm behavior and use it according to your requirements. Like @Wyrframe mentioned,output can be tailored in a way that you can then add your semantics (what range means rock, what means coast, etc). Check http://libnoise.sourceforge.net, it's a rich noise library, and their website that has pretty good incremental tutorials on this topic.

Cool ill look into libnoise. (And wyrframe that was a very clear explanation:)

Thanks a lot!

(question no longer relevant)

This topic is closed to new replies.

Advertisement