public Chunk Create() { var chunk = new Chunk(dimension, address); var heightMap = new HeightMap(dimension.Seed.Dimension.Value, address, MaxHeight); var biomeMap = new BiomeMap(dimension.Seed.Temperature.Value, dimension.Seed.Humidity.Value, address); heightMap.Generate(); biomeMap.Generate(); for (int x = 0; x < Chunk.Size; x++) { for (int z = 0; z < Chunk.Size; z++) { var yMax = heightMap[x, z]; var yMaxValue = Mathf.RoundToInt(yMax); if (yMaxValue > MaxHeight) { yMaxValue = MaxHeight; } for (int y = 0; y <= yMaxValue; y++) { BaseBlock block; if (y > WaterHeight + 10) { block = new StoneBlock(); } else if (y > WaterHeight + 0) { block = new GrassBlock(); } else { block = new SandBlock(); } if (y >= WaterHeight) { var biome = biomeMap[x, z]; if (biome == "desert") { block = new SandBlock(); } else if (biome == "stone") { block = new StoneBlock(); } else if (biome == "grass") { block = new GrassBlock(); } else { block = new GrassBlock(); } } else { block = new SandBlock(); } chunk[x, y, z] = block; } for (int y = yMaxValue + 1; y < Chunk.Depth; y++) { BaseBlock block; if (y < WaterHeight) { block = new WaterBlock(); } else { block = new AirBlock(); } chunk[x, y, z] = block; } } } return(chunk); }
/// <summary> /// Creates a Chunk. /// Populates the Chunk based on Fractal Brownian Motion /// </summary> private void BuildChunk() { bool fileData = false; // fileData = Load(); m_ChunkData = new Block[World.CHUNKSIZE, 2, World.CHUNKSIZE]; for (int y = 0; y < 2; y++) { for (int z = 0; z < World.CHUNKSIZE; z++) { for (int x = 0; x < World.CHUNKSIZE; x++) { // Block position Vector3 pos = new Vector3(x, y, z); // Block position in the World to compare to NoiseMap int worldX = (int)(x + m_Chunk.transform.position.x); int worldY = (int)(y + m_Chunk.transform.position.y); int worldZ = (int)(z + m_Chunk.transform.position.z); if (fileData) { m_ChunkData[x, y, z] = new Block(m_blockData.Matrix[x, y, z], pos, m_Chunk.gameObject, this, m_CubeAtlas); continue; } else if (y == 1) { //m_ChunkData[x, y, z] = new PropPoint(m_ChunkData[x, y - 1, z].m_BlockType, pos, m_Chunk.gameObject, this, m_CubeAtlas); continue; } // World Layers from bottom to top // if (Utils.FBM3D(worldX, worldY, worldZ, 0.1f, 4) < 0.40f) // m_ChunkData[x, y, z] = new Block(Block.EBlockType.AIR, pos, // m_Chunk.gameObject, this); //if (worldY <= Utils.GenerateCliffHeight(worldX, worldZ)) // m_ChunkData[x, y, z] = new Block(Block.EBlockType.AIR, pos, // m_Chunk.gameObject, this); // if (worldY == 1) // m_ChunkData[x, y, z] = new Block(Block.EBlockType.AIR, pos, // m_Chunk.gameObject, this); //else if (worldY == 0) // m_ChunkData[x, y, z] = new Block(Block.EBlockType.BEDROCK, pos, // m_Chunk.gameObject, this); else if (worldY <= Utils.GenerateStoneHeight(worldX, worldZ)) { if (Utils.FBM3D(worldX, worldY, worldZ, 0.02f, 4) < 0.42f && worldY < 16) { m_ChunkData[x, y, z] = new DiamondBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas); m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.DIAMOND, pos, m_Chunk.gameObject, this, m_CubeAtlas); } else if (Utils.FBM3D(worldX, worldY, worldZ, 0.02f, 2) < 0.40f && worldY < 16) { m_ChunkData[x, y, z] = new RedstoneBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas); m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.REDSTONE, pos, m_Chunk.gameObject, this, m_CubeAtlas); } else { m_ChunkData[x, y, z] = new StoneBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas); m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.STONE, pos, m_Chunk.gameObject, this, m_CubeAtlas); } } else if (worldY == Utils.GenerateHeight(worldX - 1, worldZ - 1)) // Grass equals the heightvalue returned by the function { m_ChunkData[x, y, z] = new GrassBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas); m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.GRASS, pos, m_Chunk.gameObject, this, m_CubeAtlas); } else if (worldY < Utils.GenerateHeight(worldX, worldZ)) { m_ChunkData[x, y, z] = new DirtBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas); m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.DIRT, pos, m_Chunk.gameObject, this, m_CubeAtlas); } else { m_ChunkData[x, y, z] = new AirBlock(pos, m_Chunk.gameObject, this, m_CubeAtlas); m_ChunkData[x, y + 1, z] = new PropPoint(Block.EBlockType.AIR, pos, m_Chunk.gameObject, this, m_CubeAtlas); } m_CurrentStatus = EStatus.DRAW; } } } // Save(); }
public void Init() { _contentManager = new TestContentManager(); _level = new Level(); _stoneBlock = new StoneBlock(1, 1, _level, _contentManager); }
void BuildChunk() { bool dataFromFile = Load(); chunkData = new Block[World.chunkSize, World.chunkSize, World.chunkSize]; for (int z = 0; z < World.chunkSize; z++) { for (int y = 0; y < World.chunkSize; y++) { for (int x = 0; x < World.chunkSize; x++) { Vector3 pos = new Vector3(x, y, z); int worldX = (int)(x + chunk.transform.position.x); int worldY = (int)(y + chunk.transform.position.y); int worldZ = (int)(z + chunk.transform.position.z); if (dataFromFile) { chunkData[x, y, z] = new Block(bd.matrix[x, y, z], pos, chunk.gameObject, this); continue; } int surfaceHeight = Utils.GenHeight(worldX, worldZ); if (worldY < 5) { chunkData[x, y, z] = new BedRockBlock(pos, chunk.gameObject, this); } else if (worldY <= Utils.GenStoneHeight(worldX, worldZ)) { if (Utils.fBM3D(worldX, worldY, worldZ, 0.01f, 2) < 0.4f && worldY < 40) { chunkData[x, y, z] = new DiamondBlock(pos, chunk.gameObject, this); } if (Utils.fBM3D(worldX, worldY, worldZ, 0.03f, 3) < 0.41f && worldY < 20) { chunkData[x, y, z] = new RedStoneBlock(pos, chunk.gameObject, this); } else { chunkData[x, y, z] = new StoneBlock(pos, chunk.gameObject, this); } } else if (worldY == surfaceHeight) { if (Utils.fBM3D(worldX, worldY, worldZ, 0.175f, 2) < 0.35f && worldY >= 65) { chunkData[x, y, z] = new TreeBlock(TreeBlock.TreeType.PINE, false, true, pos, chunk.gameObject, this); } else { chunkData[x, y, z] = new GrassBlock(pos, chunk.gameObject, this); } // chunkData[x, y, z] = new GrassBlock(pos, chunk.gameObject, this); } else if (worldY < surfaceHeight) { chunkData[x, y, z] = new DirtBlock(pos, chunk.gameObject, this); } else { chunkData[x, y, z] = new AirBlock(pos, chunk.gameObject, this); } if (chunkData[x, y, z].bType != Block.BlockType.WATER && Utils.fBM3D(worldX, worldY, worldZ, 0.08f, 3) < 0.42f) { chunkData[x, y, z] = new AirBlock(pos, chunk.gameObject, this); } if (worldY < 65 && chunkData[x, y, z].bType == Block.BlockType.AIR) { chunkData[x, y, z] = new WaterBlock(pos, fluid.gameObject, this); } if (worldY == 0) { chunkData[x, y, z] = new BedRockBlock(pos, chunk.gameObject, this); } status = ChunkStatus.DRAW; } } } }