Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Block[, ,] CreateLandscape(int chunkX, int chunkZ)
- {
- Block[, ,] blocks = new Block[Settings.CHUNK_SIZE, Settings.WORLD_HEIGHT, Settings.CHUNK_SIZE];
- ChunkNoise noise = new ChunkNoise(seed: 12345);
- // Calculate heightmap
- float[,] heightmap = new float[Settings.CHUNK_SIZE, Settings.CHUNK_SIZE];
- noise.FillMap2D(heightmap, chunkX, chunkZ, octaves: 5, startFrequency: .03f, startAmplitude: 5);
- // Fill chunk with blocks
- for (int localX = 0; localX < Settings.CHUNK_SIZE; localX++)
- {
- for (int localZ = 0; localZ < Settings.CHUNK_SIZE; localZ++)
- {
- // Create ground
- int height = Mathf.RoundToInt(Settings.SEA_LEVEL + heightmap[localX, localZ]);
- for (int y = 0; y < height; y++)
- {
- blocks[localX, y, localZ] = Block.Stone;
- }
- // Create mountains
- int worldX = localX + chunkX * Settings.CHUNK_SIZE;
- int worldZ = localZ + chunkZ * Settings.CHUNK_SIZE;
- for (int y = height; y < Settings.WORLD_HEIGHT; y++)
- {
- float noiseValue3D = noise.GetValue3D(worldX, y, worldZ, octaves: 6, startFrequency: .05f, startAmplitude: 1);
- if (noiseValue3D > 0)
- {
- blocks[localX, y, localZ] = Block.Sand;
- }
- else
- {
- blocks[localX, y, localZ] = Block.Empty;
- }
- }
- }
- }
- return blocks;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement