7 replies to this topic

Posted 15 April 2014 - 01:08 PM

So I am fairly new to game dev and programming altogether and to further build my skills I wanted to try and generate a random world for a simple 2d platformer. I read that the options are typically Perlin, or some other type of noise or midpoint displacement. I chose to give Perlin noise a try and within minutes of reading up on it I was frustrated beyond belief. Is there anyone at all who can give me a relatively easy to understand explanation on how to go about terrain generation?? A good example would be like Terraria's.

Any help would be much appreciated.

Any help would be much appreciated.

Posted 15 April 2014 - 04:12 PM

I use JTippets' Accidental Noise Library. I'm not sure what would be involved in using the library in an XNA project but he describes applying noise in various steps to generate procedural islands. If you can make use of the library or find another one that generates noise for you, the general steps might be of help.

Relevant links that I have bookmarked are:

http://accidentalnoise.sourceforge.net/minecraftworlds.html

http://www.gamedev.net/blog/33/entry-1765059-more-islands/

http://www.gamedev.net/blog/33/entry-2227887-more-on-minecraft-type-world-gen/

http://www.gamedev.net/blog/33/entry-2249260-procedural-islands-redux/

A couple other bookmarks I have:

http://libnoise.sourceforge.net/index.html

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

Posted 15 April 2014 - 05:06 PM

Midpoint displacement is simple & I've used it in my game with success. So when you say 2D, are you talking about a vector shape terrain, or tiles, or what?

In any case, midpoint displacement is a recursive algorithm, where you initially pass it two points - left & right most, with preset heights.

Then:

1) Find the middle point between the two points

2) Give middle point a height which is the average of the left & right points, plus/minus a random amount - this random amount should tend towards zero the smaller the X gap between the two points. The max randomness value will govern how rough your terrain will be.

3) Pass the left & middle points back into this algorithm

4) Pass the middle & right points back into this algorithm

You will then have a fractal looking terrain. You probably want to stop recursing once the gap between the two points is less than e.g. 10 pixels.

**Edited by xbattlestation, 15 April 2014 - 06:33 PM.**

Storm Clouds over the Western Front - 2D aerial combat WIP | DarklightXNA on Twitter | 2DFlightSim on Youtube

Posted 15 April 2014 - 09:27 PM

OK well first off I am making a 2d tile based 2d platformer. Its just for a learning experience so I can apply the skills I learn on the way to future projects. Now seeing the simplicity of midpoint displacement, I am curious as to how I can implement it into a game such as the one I am working on. I looked at an algorithm that used midpoint displacement to create a terrain with lines but I still struggled to understand the math and structure behind the code. So how would this work with tiles? Would it be easier or more difficult to implement?

P.s

Sorry for the lengthy topic

P.s

Sorry for the lengthy topic

Posted 15 April 2014 - 10:18 PM

Tiles actually makes things easier. I'm assuming when you say platformer you mean a side scroller. What you'll want is an array of heights at each tile position along the X axis of your gameworld. You fill in the first and the last heights with whatever random / predetermined values you want. Then pass pointers / indexes of those array positions into the mid-point algorithm, which should stop recursing when the left point is right next to the right point.

If you have tiles, then you probably have integer height values.

Hope that helps.

Storm Clouds over the Western Front - 2D aerial combat WIP | DarklightXNA on Twitter | 2DFlightSim on Youtube

Posted 16 April 2014 - 12:31 AM

As far as I know midpoint displacement does not help with the caves ... there is an article with some more text: http://www.gameprogrammer.com/fractal.html

You will probably have to combine several algorithms to get the result you want.

Midpoint displacement can be used to create the base terrain ... then, for example, cellular automata to create caves inside that terrain!?

This is an art rather than a skill, meaning that learning to think the right way is more important than finding the right tutorial.

You should feed Google with those algorithms (http://pcg.wikidot.com/category-pcg-algorithms), pick the ones that inspire you and do simple things with them.

If you have a hard time coming up with a data structure and algorithms for populating a game world, maybe you should work on those basics some more ... for example with some Code Jam exercises.

Given enough eyeballs, all mysteries are shallow.

Posted 16 April 2014 - 04:55 PM

Argh I didn't see the reference to Terraria! As DareDeveloper says, mid-point would only be useful for generating the surface terrain. You could use mid-point to generate a 2D grid (use 4 x/y points, find the middle, then recurse for top left, top right, bottom left & bottom right squares), but honestly I think fractal generation is probably overkill for your needs.

A simple random up slope / down slope / level with hard upper & lower height limits will generate a terrain with similar properties, and as DareDeveloper points out, there are simple algorithms to generate caves too.

**Edited by xbattlestation, 16 April 2014 - 04:56 PM.**

Storm Clouds over the Western Front - 2D aerial combat WIP | DarklightXNA on Twitter | 2DFlightSim on Youtube