private void GenerateCaves(Chunk C, float[,] Perlin) { for (int y = -2; y < 18; y++) { for (int x = -2; x < 18; x++) { if (Perlin[x + 2, y + 2] > 0.32f) { int Radius; if (Perlin[x + 2, y + 2] < 0.37) { Radius = 3; } else { Radius = 4; } for (int y1 = 0; y1 < 16; y1++) { for (int x1 = 0; x1 < 16; x1++) { if (Math.Pow(x1 - x, 2) + Math.Pow(y1 - y, 2) <= Math.Pow(Radius, 2)) { C.Blocks[(int)MathHelper.Clamp(x1, 0, 15), (int)MathHelper.Clamp(y1, 0, 15)] = Block.GetBlock(0); } } } } } } for (int y = 0; y < 16; y++) { for (int x = 0; x < 16; x++) { if (C.Blocks[(int)MathHelper.Clamp(x - 1, 0, 15), (int)MathHelper.Clamp(y, 0, 15)].Id == 0 && C.Blocks[(int)MathHelper.Clamp(x + 1, 0, 15), (int)MathHelper.Clamp(y, 0, 15)].Id == 0) { C.Blocks[(int)MathHelper.Clamp(x, 0, 15), (int)MathHelper.Clamp(y, 0, 15)] = Block.GetBlock(0); } } } for (int y = 0; y < 16; y++) { for (int x = 0; x < 16; x++) { if (C.Blocks[(int)MathHelper.Clamp(x - 1, 0, 15), (int)MathHelper.Clamp(y, 0, 15)].Id == 1 && C.Blocks[(int)MathHelper.Clamp(x + 1, 0, 15), (int)MathHelper.Clamp(y, 0, 15)].Id == 1 && C.Blocks[(int)MathHelper.Clamp(x - 1, 0, 15), (int)MathHelper.Clamp(y - 1, 0, 15)].Id == 1 && C.Blocks[(int)MathHelper.Clamp(x + 1, 0, 15), (int)MathHelper.Clamp(y + 1, 0, 15)].Id == 1) { C.Blocks[(int)MathHelper.Clamp(x, 0, 15), (int)MathHelper.Clamp(y, 0, 15)] = Block.GetBlock(2); } } } }
public void Generate(Vector2 Pos) { if (!_world.Chunks.ContainsKey(Pos)) { Chunk C = new Chunk(_world, Pos); _world.Chunks.Add(Pos, C); foreach (Generator G in Generators) { G.Generate(C); } if (_world.Chunks.ContainsKey(Pos - new Vector2(0, 1))) { for (int i = 0; i < GameWorld.ChunkSize; i++) { _world.Chunks[Pos - new Vector2(0, 1)].CheckEdges(i, 15); _world.Chunks[Pos - new Vector2(0, 1)].CheckEdgesBackground(i, 15); } _world.Chunks[Pos - new Vector2(0, 1)].CalcLights(); } if (_world.Chunks.ContainsKey(Pos - new Vector2(1, 0))) { for (int i = 0; i < GameWorld.ChunkSize; i++) { _world.Chunks[Pos - new Vector2(1, 0)].CheckEdges(15, i); _world.Chunks[Pos - new Vector2(1, 0)].CheckEdgesBackground(15, i); } _world.Chunks[Pos - new Vector2(1, 0)].CalcLights(); } if (_world.Chunks.ContainsKey(Pos - new Vector2(0, -1))) { for (int i = 0; i < GameWorld.ChunkSize; i++) { _world.Chunks[Pos - new Vector2(0, -1)].CheckEdges(0, i); _world.Chunks[Pos - new Vector2(0, -1)].CheckEdgesBackground(0, i); } _world.Chunks[Pos - new Vector2(0, -1)].CalcLights(); } if (_world.Chunks.ContainsKey(Pos - new Vector2(-1, 0))) { for (int i = 0; i < GameWorld.ChunkSize; i++) { _world.Chunks[Pos - new Vector2(-1, 0)].CheckEdges(i, 0); _world.Chunks[Pos - new Vector2(-1, 0)].CheckEdgesBackground(i, 0); } _world.Chunks[Pos - new Vector2(-1, 0)].CalcLights(); } } }
public override void Generate(Chunk C) { for (int y = 1; y < 15; y++) { for (int x = 1; x < 15; x++) { if (C.Blocks[x - 1,y] == Block.GetBlock(0) && C.Blocks[x - 1,y] == Block.GetBlock(0) && C.Blocks[x - 1,y] == Block.GetBlock(0)) { //World.SetBlock(new Vector2(x - 11 , y - 2) + C.Position * 32, new TreeTE(World, new Vector2(x - 11, y - 2) + C.Position * 32)); World.SetBlock(new Vector2(x , y) + C.Position * 32, new CraftingTableTE(new Vector2(x , y ) + C.Position * 32, World)); } } } }
public override void Generate(Chunk C) { //Perlin Gen float[,] Perlin = new float[20, 20]; PerlinNoise PNoise = new PerlinNoise(16); for (int y = 0; y < 20; y++) { for (int x = 0; x < 20; x++) { Perlin[x, y] = (float)PNoise.Noise((double)(x + C.Position.X * 16 - 2) / 10, (double)(y + C.Position.Y * 16 - 2) / 10, 0); } } if (C.Position.Y >= -1) { GenerateCaves(C, Perlin); } }
public abstract void Generate(Chunk C);