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?

  • \$\begingroup\$ Look for perlin noise google.com/search?q=perlin+noise+terrain+2d \$\endgroup\$
    – pabdulin
    Commented Oct 19, 2012 at 10:42
  • \$\begingroup\$ check this out codeflow.org/entries/2010/dec/09/… \$\endgroup\$ Commented Oct 19, 2012 at 12:32
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – House
    Commented Oct 19, 2012 at 14:24
  • \$\begingroup\$ 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. \$\endgroup\$
    – DampeS8N
    Commented Oct 19, 2012 at 14:56

2 Answers 2


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.

  • \$\begingroup\$ Cool i those are good game links. \$\endgroup\$ Commented Oct 19, 2012 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 that resemble those of 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?

  • \$\begingroup\$ 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. \$\endgroup\$
    – kurtzbot
    Commented Oct 19, 2012 at 16:39
  • \$\begingroup\$ 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. \$\endgroup\$
    – House
    Commented Oct 19, 2012 at 16:46
  • \$\begingroup\$ If you are reffering to this stackoverflow.com/questions/12971879/random-world-generation someone told me i would get more responses here "You -might- get more answers if you try over at gamedev.stackexchange.com =)". It was suppost to be closed " Author asked the question on gamedev, so I think it can be closed here". \$\endgroup\$ Commented Oct 19, 2012 at 18:03
  • \$\begingroup\$ I cant believe its closed. \$\endgroup\$ Commented Oct 19, 2012 at 18:04
  • 1
    \$\begingroup\$ 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? \$\endgroup\$
    – House
    Commented Oct 19, 2012 at 18:05

Not the answer you're looking for? Browse other questions tagged .