private void GenerateSandLayer() { List <PerlinNoise2D> noiseFunctions = new List <PerlinNoise2D>(); noiseFunctions.Add(new PerlinNoise2D(4, 2f)); noiseFunctions.Add(new PerlinNoise2D(8, .5f)); noiseFunctions.Add(new PerlinNoise2D(12, .25f)); noiseFunctions.Add(new PerlinNoise2D(26, .125f)); noiseFunctions.Add(new PerlinNoise2D(34, .0625f)); noiseFunctions.Add(new PerlinNoise2D(64, .0425f)); double[,] data = MapTools.SumNoiseFunctions(WorldSettings.MAPWIDTH, WorldSettings.MAPLENGTH, noiseFunctions); for (int x = 0; x < WorldSettings.MAPWIDTH; x++) { for (int z = 0; z < WorldSettings.MAPLENGTH; z++) { int height = (int)(data[x, z] * 5) + 20 + WorldSettings.SEALEVEL; for (int y = 0; y < height; y++) { if (_map[x, y, z] == BlockType.None) { _map[x, y, z] = BlockType.Sand; } } } } }
private void GenerateDirtLayer(int offset, bool trees) { List <PerlinNoise2D> noiseFunctions = new List <PerlinNoise2D>(); noiseFunctions.Add(new PerlinNoise2D(4, 2f)); noiseFunctions.Add(new PerlinNoise2D(8, .5f)); noiseFunctions.Add(new PerlinNoise2D(12, .25f)); noiseFunctions.Add(new PerlinNoise2D(26, .125f)); noiseFunctions.Add(new PerlinNoise2D(34, .0625f)); noiseFunctions.Add(new PerlinNoise2D(64, .0125f)); double[,] data = MapTools.SumNoiseFunctions(WorldSettings.MAPWIDTH, WorldSettings.MAPLENGTH, noiseFunctions); for (int x = 0; x < WorldSettings.MAPWIDTH; x++) { for (int z = 0; z < WorldSettings.MAPLENGTH; z++) { int height = (int)(data[x, z] * 20) + offset + WorldSettings.SEALEVEL; for (int y = 0; y < height; y++) { if (_map[x, y, z] == BlockType.None) { if (y == height - 1) { if (r.Next(250) == 1 && trees) { BuildTree(x, y, z); } else { _map[x, y, z] = BlockType.Grass; } } else { if (r.Next(20) == 1) { _map[x, y, z] = BlockType.Gravel; } else { _map[x, y, z] = BlockType.Dirt; } } } } } } }
private void CarveLandscape() { List <PerlinNoise2D> heightFunctions1 = new List <PerlinNoise2D>(); heightFunctions1.Add(new PerlinNoise2D(1, 2f)); heightFunctions1.Add(new PerlinNoise2D(8, 1.5f)); heightFunctions1.Add(new PerlinNoise2D(12, .25f)); heightFunctions1.Add(new PerlinNoise2D(26, 2.625f)); heightFunctions1.Add(new PerlinNoise2D(34, .0625f)); heightFunctions1.Add(new PerlinNoise2D(64, 0.1425f)); List <PerlinNoise2D> heightFunctions2 = new List <PerlinNoise2D>(); heightFunctions2.Add(new PerlinNoise2D(2, 2f)); heightFunctions2.Add(new PerlinNoise2D(8, .5f)); heightFunctions2.Add(new PerlinNoise2D(12, .25f)); heightFunctions2.Add(new PerlinNoise2D(26, 3.125f)); heightFunctions2.Add(new PerlinNoise2D(34, .0625f)); heightFunctions2.Add(new PerlinNoise2D(64, 0.1425f)); double[,] heightData1 = MapTools.SumNoiseFunctions(WorldSettings.MAPWIDTH, WorldSettings.MAPLENGTH, heightFunctions1); double[,] heightData2 = MapTools.SumNoiseFunctions(WorldSettings.MAPWIDTH, WorldSettings.MAPLENGTH, heightFunctions2); for (int x = 0; x < WorldSettings.MAPWIDTH; x++) { for (int z = 0; z < WorldSettings.MAPLENGTH; z++) { int height1 = (int)(heightData1[x, z] * 10) + 3 + WorldSettings.SEALEVEL; int height2 = (int)(heightData2[x, z] * 15) + 5 + WorldSettings.SEALEVEL; if (height2 > WorldSettings.MAPHEIGHT) { height2 = WorldSettings.MAPHEIGHT; } if (height2 > height1) { for (int y = height1; y < height2; y++) { _map[x, y, z] = BlockType.None; } } } } }
private void GenerateRockLayer() { List <PerlinNoise2D> noiseFunctions = new List <PerlinNoise2D>(); noiseFunctions.Add(new PerlinNoise2D(4, 5f)); noiseFunctions.Add(new PerlinNoise2D(8, .5f)); noiseFunctions.Add(new PerlinNoise2D(12, .25f)); noiseFunctions.Add(new PerlinNoise2D(26, .125f)); noiseFunctions.Add(new PerlinNoise2D(34, .0625f)); noiseFunctions.Add(new PerlinNoise2D(64, .3825f)); double[,] data = MapTools.SumNoiseFunctions(WorldSettings.MAPWIDTH, WorldSettings.MAPLENGTH, noiseFunctions); for (int x = 0; x < WorldSettings.MAPWIDTH; x++) { for (int z = 0; z < WorldSettings.MAPLENGTH; z++) { int height = (int)(data[x, z] * 10) + 15 + WorldSettings.SEALEVEL; for (int y = 0; y < height; y++) { if (y > WorldSettings.SNOWLINE + r.Next(3)) { _map[x, y, z] = BlockType.Snow; } else if (r.Next(8) == 1) { _map[x, y, z] = BlockType.Gravel; } else { _map[x, y, z] = BlockType.Rock; } } } } }