public WorldQuad GenerateQuad(int x, int z) { const int maxHeight = 63; const int oceanHeight = 30; double height = heightNoise.NoiseGeneration (x, z); double heat = heatNoise.NoiseGeneration (x, z); WorldQuad quad = new WorldQuad(); quad.height = (int)(height * maxHeight); quad.heat = (float)heat; quad.isOcean = quad.height <= oceanHeight; return quad; }
private float GetNearestWaterDistance(int x, int z, WorldQuad[,] quads) { int shortest = Int32.MaxValue; foreach(WorldQuad quad in quads) { if(quad.isOcean) { int xd = quad.x - x; int zd = quad.z - z; int dist = (int)Math.Sqrt(xd * xd + zd * zd); if(dist < shortest) shortest = dist; } } return 1f - (1f / shortest); }
public void Generate(Chunk chunk) { WorldQuad[,] quads = new WorldQuad[Chunk.scale, Chunk.scale]; for (int x = 0; x < Chunk.scale; x++) { for (int z = 0; z < Chunk.scale; z++) { //Generate quads to quad array quads[x,z] = GenerateQuad((int)chunk.GetWorldLocation().X + x, (int)chunk.GetWorldLocation().Z + z); } } for (int x = 0; x < Chunk.scale; x++) { for (int z = 0; z < Chunk.scale; z++) { float dist = GetNearestWaterDistance(x, z, quads); quads[x,z].moisture = dist; quads[x,z].heat *= dist; //Do stuff based on surrounding quads } } for (int x = 0; x < Chunk.scale; x++) { for (int z = 0; z < Chunk.scale; z++) { //Finally set blocks int chunkYOffset = (int)chunk.GetWorldLocation().Y; WorldQuad quad = quads[x,z]; Biome biome = Biome.simple; foreach(Biome b in biomes) { if((quad.moisture <= b.moistureHigh) && (quad.moisture >= b.moistureLow) && (quad.heat <= b.heightHigh) && (quad.heat >= b.heightLow)) { biome = b; break; } } chunk.SetBlock(x, quad.height - chunkYOffset, z, biome.topBlock); if(quads[x,z].isOcean) chunk.SetBlock(x, 30 - chunkYOffset, z, Block.water); } } }