Sunday 19 June 2011

Maincraft Dev Diaries, part Un

Random Terrain Generation (or pseudorandom, more accurately) is a staple of many popular games, like Minecraft. And rightly so, because it adds realism to the game. It also adds variation, because the RTG is unpredictable.

The one I use in Maincraft is very simple:

  • Create a row of bedrock at the bottom of the map.
  • Make the bedrock randomly go up and down, to make it 'bumpy'
  • Place a seed block of stone. X and Y are generated from an algorithm based on the CPU time.
  • Allow the seed block to grow, by making everything in its von Neumann neighborhood turn into stone, for 5 steps.
  • Randomly turn stone into ores by checking a number generated from an algorithm based on the CPU time.
  • Create dirt in all empty spaces up to 3 blocks above the stone.
  • Turn dirt that is not in the shade (underneath a stone block) into grass.*
  • Create lava above any block of bedrock exposed to
  • Create two seed blocks of saplings. X and Y are generated from an algorithm based on the CPU time.
  • Allow the saplings to move downwards, until it collides with a block. If that block is grass, then it grows into a tree. Otherwise, it teleports to a random position.
  • Place a seed block of water. X and Y are generated from an algorithm based on the CPU time.
  • Allow the water and lava to grow in the same way it does in Minecraft classic.*
  • Turn all grass near water into sand, and kill plants that are underwater. *
* = Repeat this once every 1-2 seconds.

This creates a nice looking 2D world, as you can see from this screenshot:

Post any methods you might have in the comments!

--Thomas

No comments:

Post a Comment