/** 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(); }
Block GetCurrentBlock() { Block block = null; switch (blockID) { case 0:block = new BlockStone(); break; case 1:block = new BlockGrass(); break; } return block; }
public static void showBlock(int id) { string blockName = "null"; switch (id) { case 0:blockName = new BlockStone().GetName(); break; case 1:blockName = new BlockGrass().GetName(); break; } GUI.Label (new Rect(100, 100, 100, 40), "currentBlock: " + blockName); }
private bool CheckBlockCollide(PlayerLocation location) { var bbox = GetBoundingBox(); var pos = location.ToVector3(); var coords = new Vector3( (int)Math.Floor(KnownPosition.X), (int)Math.Floor((bbox.Max.Y + bbox.Min.Y) / 2.0), (int)Math.Floor(KnownPosition.Z)); var blocks = new Dictionary <double, Block>(); for (var x = -1; x < 2; x++) { for (var z = -1; z < 2; z++) { for (var y = -1; y < 2; y++) { var block = Level.GetBlock(new Vector3(coords.X + x, coords.Y + y, coords.Z + z)); if (block is BlockAir) { continue; } var blockbox = block.GetBoundingBox() + 0.3; if (blockbox.Intersects(GetBoundingBox())) { //if (!blockbox.Contains(KnownPosition.ToVector3())) continue; if (block is BlockFlowingLava || block is BlockStationaryLava) { //HealthManager.Ignite(1200); //Unimplemented should be done tho... continue; } if (!block.IsSolid) { continue; } blockbox = block.GetBoundingBox(); var midPoint = blockbox.Min + 0.5; blocks.Add((pos - Velocity).DistanceTo(midPoint), block); } } } } if (blocks.Count == 0) { return(false); } var firstBlock = blocks.OrderBy(pair => pair.Key).First().Value; var boundingBox = firstBlock.GetBoundingBox(); if (!SetIntersectLocation(boundingBox, KnownPosition)) { // No real hit return(false); } // Use to debug hits, makes visual impressions (can be used for paintball too) var substBlock = new BlockStone { Coordinates = firstBlock.Coordinates }; Level.SetBlock(substBlock); // End debug block Velocity = Vector3.Zero; return(true); }