/** Instantiate all block types and store them in the array */ static Block() { blocks = new Block[ushort.MaxValue + 1]; blocks[AIR] = new BlockAir(); blocks[BEDROCK] = new BlockBedrock(); for (uint i = 0; i < STONE.Length; i++) { blocks[STONE[i]] = new BlockStone(i); } blocks[DIRT] = new BlockDirt(); blocks[GRASS] = new BlockGrass(); blocks[ROCKY_DIRT] = new BlockDirtStone(); blocks[SAND] = new BlockSand(); for (uint i = 0; i < WATER.Length; i++) { blocks[WATER[i]] = new BlockWater(i); } for (int i = 0; i < blocks.Length; i++) { if (blocks[i] != null) { blocks[i].id = (ushort)i; } } }
public override void GenerateLandscape(Chunk chunk, BlockOffset blockOffset) { Vector3 coord = chunk.GetAbsPosition(blockOffset); float height = _landScapeHeight - _noiseLandscape.GetSimplexFractal(coord.X, coord.Z) * (_heightGain.GetSimplexFractal(coord.X, coord.Z) * 50); IBlock block = new BlockAir(); if (coord.Y <= height) { block = new BlockGrass(); } if ((coord.Y <= height - 1) && (coord.Y > height - 5)) { block = new BlockDirt(); } if (coord.Y <= height - 5) { block = new BlockStone(); } chunk.SetBlock(blockOffset, block); }
public void Init() { //seed = UnityEngine.Random.Range(0, int.MaxValue); BLOCK_AIR = new BlockAir(); BLOCK_STONE = new BlockStone(); BLOCK_DIRT = new BlockDirt(); BLOCK_GRASS = new BlockGrass(); BLOCK_LEAF = new BlockLeaf(); BLOCK_WOOD = new BlockWood(); }
public void setup() { blocks = new Block[width, height]; for (int x = 0; x < blocks.GetLength(0); x++) { for (int y = 0; y < blocks.GetLength(1); y++) { blocks[x, y] = new BlockDirt(x, y + chunkHeight * height); } } GetComponent <MeshFilter>().sharedMesh = MeshGenerator.GenMeshFrom(blocks); }