/// <summary> /// Generates the preliminary world data based on perlin noise. /// </summary> private void GeneratePreliminaryWorld() { for (int x = 0; x < Blocks.GetLength(0); x++) { for (int z = 0; z < Blocks.GetLength(2); z++) { /** * These numbers have been fine-tuned and tweaked through trial and error. * Altering these numbers may produce weird looking worlds. **/ int stoneCeiling = SimplexNoise.GetPerlinNoise(x, 0, z, 10, 3, 1.2) + SimplexNoise.GetPerlinNoise(x, 300, z, 20, 4, 0) + 10; int grassHeight = SimplexNoise.GetPerlinNoise(x, 100, z, 30, 10, 0); int foodHeight = SimplexNoise.GetPerlinNoise(x, 200, z, 20, 5, 1.5); Topography[x, z] = stoneCeiling + grassHeight + foodHeight; for (int y = 0; y < Blocks.GetLength(1); y++) { if (y <= stoneCeiling) { Blocks[x, y, z] = new StoneBlock(); } else if (y <= stoneCeiling + grassHeight) { Blocks[x, y, z] = new GrassBlock(); } else if (y <= stoneCeiling + grassHeight + foodHeight) { Blocks[x, y, z] = new MulchBlock(); } else { Blocks[x, y, z] = new AirBlock(); } if ( x == 0 || x >= Blocks.GetLength(0) - 1 || z == 0 || z >= Blocks.GetLength(2) - 1 || y == 0 ) { Blocks[x, y, z] = new ContainerBlock(); } } } } }
/// <summary> /// This method performs a deep copy of the initial world state to a backup array for later restoration. /// </summary> private void CopyBlocks() { for (int x = 0; x < Blocks.GetLength(0); x++) { for (int y = 0; y < Blocks.GetLength(1); y++) { for (int z = 0; z < Blocks.GetLength(2); z++) { if (Blocks[x, y, z] is AirBlock) { InitialBlocks[x, y, z] = new AirBlock(); } else if (Blocks[x, y, z] is MulchBlock) { InitialBlocks[x, y, z] = new MulchBlock(); } else if (Blocks[x, y, z] is ContainerBlock) { InitialBlocks[x, y, z] = new ContainerBlock(); } else if (Blocks[x, y, z] is GrassBlock) { InitialBlocks[x, y, z] = new GrassBlock(); } else if (Blocks[x, y, z] is StoneBlock) { InitialBlocks[x, y, z] = new StoneBlock(); } else if (Blocks[x, y, z] is AcidicBlock) { InitialBlocks[x, y, z] = new AcidicBlock(); } else if (Blocks[x, y, z] is NestBlock) { InitialBlocks[x, y, z] = new NestBlock(); } InitialBlocks[x, y, z].worldXCoordinate = x; InitialBlocks[x, y, z].worldYCoordinate = y; InitialBlocks[x, y, z].worldZCoordinate = z; } } } }