Jump to content
  • Advertisement
suliman

Simple 2D map generation? (tiles)

Recommended Posts

Posted (edited)

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

Edited by suliman

Share this post


Link to post
Share on other sites
Advertisement
Posted (edited)

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.

Edited by Engi

Share this post


Link to post
Share on other sites
Posted (edited)

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.

Edited by suliman

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Posted (edited)

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

Edited by suliman

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Posted (edited)
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.

Edited by Engi

Share this post


Link to post
Share on other sites

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

Thanks a lot!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!