Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How are voxel terrain engines made?

I'm making a game like minecraft (although a different idea) but I need a random world generator for a 1024 block wide and 256 block tall map. Basically so far I have a multidimensional array for each layer of blocks (a total of 262,114 blocks).

This is the code I have now:

Block[,] BlocksInMap = new Block[1024, 256];

public bool IsWorldGenerated = false;

Random r = new Random();

private void RunThread()
    for (int BH = 0; BH <= 256; BH++)
        for (int BW = 0; BW <= 1024; BW++)
            Block b = new Block();
            if (BH >= 192)

            BlocksInMap[BW, BH] = b;

    IsWorldGenerated = true;

public void GenWorld()
    new Thread(new ThreadStart(RunThread)).Start();

I want to make tunnels and water but the way blocks are set is like this:

Block MyBlock = new Block();
MyBlock.BlockType = Block.BlockTypes.Air;

How would I manage to connect blocks so the land is not a bunch of floating dirt and stone?

share|improve this question

marked as duplicate by MichaelHouse 'Byte56', Martin Sojka, Tetrad Oct 19 '12 at 16:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Look for perlin noise – Petr Abdulin Oct 19 '12 at 10:42
check this out… – user1075940 Oct 19 '12 at 12:32
Please search the site before asking questions. This question is a common one. There are plenty of resources on this site about creating random worlds. – MichaelHouse 'Byte56' Oct 19 '12 at 14:24
If you are willing to have a terribly long load time like Dwarf Fortress has, you can get rid of floating islands like that game does. Brute force. – DampeS8N Oct 19 '12 at 14:56

For a Minecraft-like world it will be tremendously beneficial to do some research on the topic of coherent noise. Such noise will form a heightmap for your terrain that will be connected and have actual transitions between heights. However, applying noise allows you to do more amazing things.

The most common type of noise used is probably Perlin noise and Simplex noise. There are a lot of things that can be done with these two alone, as demonstrated by the open source libary libnoise.

Refer to the following links for more info on how to apply coherent noise for terrain generation.

Minecraft like world generation. -- especially relevant.

More procedural voxel world generation -- Shows how to do material distribution with noise

libnoise tutorial -- Shows terrain generation but also explains the noise library libnoise

As for actual noise implementation I would recommend checking out:

Ken Perlin's reference implementation

Stefan Gustavson's article on Simplex noise including an implementation

Diamon Square algorithm

libnoise and its source code

If you base your generation algorithm on coherent noise the "roughness" of the terrain highly depends on your specification of the noise map's attributes. Within normal range, problems like having some tiles of the world floating about without any connection to the ground will not occur. Additionally, since coherent noise basically has no boundaries the scale of the world does not have any either. Increasing terrain size is therefore less of an issue.

share|improve this answer
Cool i those are good game links. – Alex Larsen Oct 19 '12 at 18:05

Allow me to answer this for you, by searching the site for you:

How are voxel terrain engines made?

Random map generation

How is a 3d perlin noise function used to generate terrain?

Procedural terrains in 3D: what has been done ? Are there common algo and/or theories about it?

Voxel heightmap terrain editor

How to generate random level from a seed?

Random World Generator

How to generate caves like minecraft?

How to remove floating terrain when generated with 3D Perlin Noise?

Correct way to "randomly" generate flowing terrain

Simple noise generation

Huge procedurally generated 'wilderness' worlds

C# Perlin noise - generating “endless” terrain chunks?

How can I generate a terrain heightmap from the perlin algorithm?

share|improve this answer
Why wasn't this question closed for being a duplicate? I am not sure which one I would report this question as a duplicate of, but your list here would suggest this question be closed. – kurtzbot Oct 19 '12 at 16:39
I suggested it be closed as a duplicate a few hours ago. You can't see it, but there are two votes to close. However, since I said it was a duplicate, the question and answer have both received multiple votes. This question is still open because: 1. The asker didn't search the site first. 2. The people that are up-voting it don't care or don't know it's a duplicate 3. The first answerer didn't check if it was a duplicate first and answered anyway. – MichaelHouse 'Byte56' Oct 19 '12 at 16:46
If you are reffering to this someone told me i would get more responses here "You -might- get more answers if you try over at =)". It was suppost to be closed " Author asked the question on gamedev, so I think it can be closed here". – Alex Larsen Oct 19 '12 at 18:03
I cant believe its closed. – Alex Larsen Oct 19 '12 at 18:04
You did get answers, it's just that they were already here. Do you really feel like you can't get the information you need from the answers in the questions linked? – MichaelHouse 'Byte56' Oct 19 '12 at 18:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.