void Start() { GameState = GAMESTATE.NONE; DirtBlock.SetActive(false); FarmLand.SetActive(false); Seed.SetActive(false); }
public static void Init() { DIRT = new DirtBlock(); GRASS = new GrassBlock(); STONE = new StoneBlock(); SAND = new SandBlock(); WATER = new WaterBlock(); LOG_OAK = new OakLogBlock(); LEAVES_OAK = new LeavesOakBlock(); PLANKS_OAK = new OakWoodPlanks(); }
public Block BuildBlock(string code) { Block b = new Block(); setIdFromCode(code); setSubIdFromCode(code); switch (id) { case 0: AirBlock airBlock = new AirBlock(subId); b.TexturePath = airBlock.TexturePath; b.IsCollidable = airBlock.IsCollidable; break; case 1: GroundBlock groundBlock = new GroundBlock(subId); b.TexturePath = groundBlock.TexturePath; b.IsCollidable = groundBlock.IsCollidable; break; case 2: GrassBlock grassBlock = new GrassBlock(subId); b.TexturePath = grassBlock.TexturePath; b.IsCollidable = grassBlock.IsCollidable; break; case 3: BridgeBlock bridgeBlock = new BridgeBlock(subId); b.TexturePath = bridgeBlock.TexturePath; b.IsCollidable = bridgeBlock.IsCollidable; break; case 4: DirtBlock dirtBlock = new DirtBlock(subId); b.TexturePath = dirtBlock.TexturePath; b.IsCollidable = dirtBlock.IsCollidable; break; default: AirBlock derivedBlock = new AirBlock(subId); b.TexturePath = derivedBlock.TexturePath; b.IsCollidable = derivedBlock.IsCollidable; break; } return(b); }
// Use this for initialization void Start() { GetComponent <MeshFilter>().mesh = MeshUtility.CreateCube(1f, Vector3.zero); BlockManager.Init(chunkPrefab); TextureManager.Init(texMap, tileSize); for (int x = 0; x < 100; x++) { for (int y = 0; y < 100; y++) { IBlock block = new GrassBlock(Vector3.left * x + (Vector3.up * TerrainUtility.GetBlockHeight(x, y)) + Vector3.forward * y); for (int i = 0; i < block.Position.y; i++) { IBlock block1 = new DirtBlock(new Vector3(block.Position.x, i, block.Position.z)); BlockManager.AddBlock(block1); } BlockManager.AddBlock(block); } } //Block block = new Block(Vector3.one); //BlockManager.AddBlock(block); }
/// <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(); }
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; } } } }