DarkTornado

World Generator V1.0

May 25th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. public void Generate()
  2.         {
  3.             Random rnd = new Random();
  4.             int lastHeight = rnd.Next(1, _height);
  5.             for (int k = 0; k < _depth; k++)
  6.             {
  7.                 int currentHeight = lastHeight + rnd.Next(-1, 2);
  8.                 currentHeight = Math.Min(_height, Math.Max(1, currentHeight));
  9.                 for (int j = 0; j < currentHeight; j++)
  10.                 {
  11.                     cubes[0, j, k] = new BlockGrass(new Vector3(0, 10 * j, 10 * k));
  12.                 }
  13.                 lastHeight = currentHeight;
  14.             }
  15.             lastHeight = GetHeight(0, 0);
  16.             for (int i = 1; i < _width; i++)
  17.             {
  18.                 int currentHeight = lastHeight + rnd.Next(-1, 2);
  19.                 currentHeight = Math.Min(_height, Math.Max(1, currentHeight));
  20.                 for (int j = 0; j < currentHeight; j++)
  21.                 {
  22.                     cubes[i, j, 0] = new BlockGrass(new Vector3(10 * i, 10 * j, 0));
  23.                 }
  24.                 lastHeight = currentHeight;
  25.             }
  26.             for (int i = 1; i < _width; i++)
  27.             {
  28.                 for (int k = 1; k < _depth; k++)
  29.                 {
  30.                     int currentHeight = (GetHeight(i - 1, k) + GetHeight(i, k - 1)) / 2 + rnd.Next(-1, 2);
  31.                     currentHeight = Math.Min(_height, Math.Max(1, currentHeight));
  32.                     for (int j = 0; j < currentHeight; j++)
  33.                     {
  34.                         if (j < currentHeight - 1)
  35.                         {
  36.                             cubes[i, j, k] = new BlockGround(new Vector3(10 * i, 10 * j, 10 * k));
  37.                         }
  38.                         else
  39.                         {
  40.                             cubes[i, j, k] = new BlockGrass(new Vector3(10 * i, 10 * j, 10 * k));
  41.                         }
  42.                     }
  43.                     lastHeight = currentHeight;
  44.                 }
  45.             }
  46.             AddAllCubes();
  47.         }
Advertisement
Add Comment
Please, Sign In to add comment