Jump to content
  • Advertisement
Sign in to follow this  
lockandstrike

2D Terrain Random Generation

This topic is 1438 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm writing an 2D RPG in Java and my idea is somewhat different from the normal. There will be cities that will always be the same and placed in the same area and the rest of the world is randomnly generated with ores and other resources so the player can mine and then pay the artisans of the city to craft what he wants. 

 

My question is: how do I do the random terrain generation(I've been looking into perl noise algorithms) and then place the cities?

 

 

Many thanks in advance,

GreyGameStudio

Share this post


Link to post
Share on other sites
Advertisement

Is this a sidescroller, or top-down (45 degrees), or straight top view, or something else?

 

Can the player destroy "blocks" to reach inaccessible areas?

Share this post


Link to post
Share on other sites

It is a straight top view and the player can only certain blocks, being these the ores or the trees in the random terrain. Anything inside the cities is utterly unbreakble.

 

Many thanks in advance,

GreyGameStudio

Share this post


Link to post
Share on other sites

So, it sounds like you really just want a flat terrain with randomly scattered items the player character can harvest?

 

If that's the case, you just need to loop through your tiles and randomly place or not place resources based on prevalence.

 

If you want something other than flat terrain, then this becomes much more complicated, because any obstacles can not be placed trivially (either randomly, or by any noise function).

 

Do you need it to look the same when the player returns to the same map area?

Share this post


Link to post
Share on other sites

I would first start by generating the main random part of the map. This would be the base of the map. Then I'd add in the parts that weren't random, like the cities and any roads you wanted connecting them, for example. This would mean that you have a definite randomness all around EXCEPT from the areas that you need access to.

 

As to how I'd do this, I'm not sure. I'm relatively new to games programming, and haven't worked with randomly generated environments before, but this is how I'll do it when the time comes.

Share this post


Link to post
Share on other sites

First things first you must understand that in games nothing is every completely random. there's always rules to how things are generated. Perlin noise is a great way to generate the information you need to create these random maps. but you will need to define a set of rules that ultimately define your map.

 

For me, I've always thought of things spatially when it comes to random maps. Certain features should only occur withing a specific distance of other things.

 

If you could be more specific about what you think or want your world to contain, it would be easier to find a solution and I'm sure you might even find it on your own.

 

If your trying to just define regions or areas of mountains, plans or deserts... the basic types that you fins in almost any overworld map type game. You could simply define an order of importance for each type of terrain. Find a random coord in you map and randomly spread that point as the given type. Think how a drop of water hits a surface and spreads out. Each iteration just isn't aloud to claim a coordinate that is already defined.

 

If you could be a little more specific on the types and how you vision it looking in the end, I'd love to help you further. Random generation or what you should consider procedural generation is a favorite of mine smile.png

 

 

 

I would first start by generating the main random part of the map. This would be the base of the map. Then I'd add in the parts that weren't random, like the cities and any roads you wanted connecting them, for example. This would mean that you have a definite randomness all around EXCEPT from the areas that you need access to.

 

As to how I'd do this, I'm not sure. I'm relatively new to games programming, and haven't worked with randomly generated environments before, but this is how I'll do it when the time comes.

 

I feel for what you're looking for the opposite is desired. You don't want to randomly generate a map that has mountains where a city should be.

Edited by coremarq

Share this post


Link to post
Share on other sites

I want to add some information to Coremaqs post,

 

and we do need more information. If your map changes every time why do the cities have to be in the same place? I mean the environment is not the same - does this rule then make sense? Wouldn`t it be enough to place the needed cities also with rules ( they have to be x apart from another, favorite places are at rivers or plateaus .. ) ? Just a thought.

 

Since you will have rules (like we always have x cities, n mines per city, mines only on hills .. ) you could look into contraint satisfaction/propagation. Here is a great paper/tutorial on the subject:

http://www.cs.northwestern.edu/~ian/GDCConstraintsHowTo.pdf

It is basically a set of algorithms helping you to automatically solve such problems involving rules. They were bult with respect to games.

I also want to post a paid resource (a great one) because in one interview there was a pretty interessting talk about procedural map generation:

http://aigamedev.com/premium/interview/sir-you-are-being-hunted

Share this post


Link to post
Share on other sites

I feel for what you're looking for the opposite is desired. You don't want to randomly generate a map that has mountains where a city should be.

 

Sorry, I should've made myself clearer.

 

What I meant was, I'd make up the randomness first, then adjust specific areas. If there were mountains where the city should be, I'd get rid of the mountains and put the city there, and maybe adjust the surrounding areas to make it a little more realistic. Of course, this would only work if the map was the same every time, which is what I thought the OP meant.

 

If the map needed to be randomized every time, I'd start by implementing a way to reserve parts of the map, place the cities and roads etc, and then generate the random parts of the map around this based on a set of conditions to stop things like a forest being directly next to the sea with no beach-area in between.
 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!