Advertisement
Guest User

Untitled

a guest
Jul 21st, 2011
1,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. public static Block[, ,] CreateLandscape(int chunkX, int chunkZ)
  2. {
  3.     Block[, ,] blocks = new Block[Settings.CHUNK_SIZE, Settings.WORLD_HEIGHT, Settings.CHUNK_SIZE];
  4.     ChunkNoise noise = new ChunkNoise(seed: 12345);
  5.  
  6.     // Calculate heightmap
  7.     float[,] heightmap = new float[Settings.CHUNK_SIZE, Settings.CHUNK_SIZE];
  8.     noise.FillMap2D(heightmap, chunkX, chunkZ, octaves: 5, startFrequency: .03f, startAmplitude: 5);
  9.  
  10.     // Fill chunk with blocks
  11.     for (int localX = 0; localX < Settings.CHUNK_SIZE; localX++)
  12.     {
  13.         for (int localZ = 0; localZ < Settings.CHUNK_SIZE; localZ++)
  14.         {
  15.             // Create ground
  16.             int height = Mathf.RoundToInt(Settings.SEA_LEVEL + heightmap[localX, localZ]);
  17.  
  18.             for (int y = 0; y < height; y++)
  19.             {
  20.                 blocks[localX, y, localZ] = Block.Stone;
  21.             }
  22.  
  23.             // Create mountains
  24.             int worldX = localX + chunkX * Settings.CHUNK_SIZE;
  25.             int worldZ = localZ + chunkZ * Settings.CHUNK_SIZE;
  26.  
  27.             for (int y = height; y < Settings.WORLD_HEIGHT; y++)
  28.             {
  29.                 float noiseValue3D = noise.GetValue3D(worldX, y, worldZ, octaves: 6, startFrequency: .05f, startAmplitude: 1);
  30.                 if (noiseValue3D > 0)
  31.                 {
  32.                     blocks[localX, y, localZ] = Block.Sand;
  33.                 }
  34.                 else
  35.                 {
  36.                     blocks[localX, y, localZ] = Block.Empty;
  37.                 }
  38.             }
  39.         }
  40.     }
  41.  
  42.     return blocks;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement