/** 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 Block BuildBlock(Vector3Int pos) { Block newBlock = null; float noise = (MyUtil.Get3DNoise(pos.x, pos.y, pos.z, frequency, octave, persistence) + 1.0f) * 0.5f; noise = Mathf.Clamp01(noise); if (noise <= blockRate) { newBlock = new Block(); } else if (noise <= desertRate) { newBlock = new BlockDesert(); } else if (noise <= grassRate) { newBlock = new BlockGrass(); } else if (noise <= cloudRate) { newBlock = new BlockCloud(); } else { newBlock = new BlockAir(); } return(newBlock); }
public override Block BuildBlock(Vector3Int pos) { Block newBlock = null; if (blockType == FillArea.BlockType.BLOCK) { newBlock = new Block(); } else if (blockType == FillArea.BlockType.GRASS) { newBlock = new BlockGrass(); } else if (blockType == FillArea.BlockType.DESERT) { newBlock = new BlockDesert(); } else if (blockType == FillArea.BlockType.CLOUD) { newBlock = new BlockCloud(); } else if (blockType == FillArea.BlockType.WATER) { newBlock = new BlockWater(); } else { newBlock = new BlockAir(); } return(newBlock); }
/** * @brief 지형 블럭을 생성한다. * @return 만들어진 지형을 반환한다. */ private Block CreateBlock(Vector3Int worldPos) { Block newBlock = null; var info = planetInfo.terrainInfo; float coreRange = info.radius * info.coreRate; //코어의 표면은 블럭으로 생성 int isInVertCnt = MyUtil.IsCubeInRange(worldPos, 1, coreRange); if (isInVertCnt > 0 && isInVertCnt < 8) { newBlock = new Block(); newBlock.isLock = true; } //코어 외부는 Mode에 따라 함수를 통해 생성 else if (isInVertCnt == 0) { if (MyUtil.GetSNoise(worldPos.x, worldPos.y, worldPos.z, 0.05f, 50) > 20) { float noise = (MyUtil.Get3DNoise(worldPos.x, worldPos.y, worldPos.z, info.frequency, info.octave, info.persistence) + 1.0f) * 0.5f; //int holeChance = MyUtil.GetSNoise(worldPos.x, worldPos.y, worldPos.z, 0.05f, 50); noise = Mathf.Clamp01(noise); if (noise <= info.blockRate) { newBlock = new Block(); } else if (noise <= info.desertRate) { newBlock = new BlockDesert(); } else if (noise <= info.grassRate) { newBlock = new BlockGrass(); } } } //Ocean BLock if (newBlock == null) { float height = Mathf.Max(Mathf.Abs(worldPos.x + 0.5f), Mathf.Abs(worldPos.y + 0.5f), Mathf.Abs(worldPos.z + 0.5f)); if (height <= info.oceanHeight && height > info.oceanHeight - info.oceanDepth) { newBlock = new BlockWater(); newBlock.isLock = true; } } if (newBlock == null) { newBlock = new BlockAir(); } return(newBlock); }
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); }
public bool SetBlock(Block.BlockName name, Vector2f pos) { bool setted; Block block = null; if (IsFree(pos)) { switch (name) { case Block.BlockName.grass: block = new BlockGrass(pos); break; } } setted = block != null && AddBlock(block); return(setted); }
void Start() { _filter = gameObject.GetComponent <MeshFilter>(); _collider = gameObject.GetComponent <MeshCollider>(); _blocks = new Block[ChunkSize, ChunkSize, ChunkSize]; for (var x = 0; x < ChunkSize; x++) { for (var y = 0; y < ChunkSize; y++) { for (var z = 0; z < ChunkSize; z++) { _blocks[x, y, z] = new BlockAir(); } } } _blocks[3, 5, 2] = new Block(); _blocks[4, 5, 2] = new BlockGrass(); UpdateChunk(); }
Block CreateBlock() { string blockType = GetComponent <PrefabBlockTexture>().blockType; Block block; switch (blockType) { case "Stone": block = new Block(); break; case "Grass": block = new BlockGrass(); break; case "BrownWood": block = new BlockBrownWood(); break; case "Lava": block = new BlockLava(); break; case "GreenLeaves": block = new BlockGreenLeaves(); break; case "OrangeLeaves": block = new BlockOrangeLeaves(); break; case "StoneSnow": block = new BlockStoneSnow(); break; case "Ice": block = new BlockIce(); break; case "Glass": block = new BlockGlass(); break; case "WhiteWood": block = new BlockWhiteWood(); break; case "Apple": block = new BlockApple(); break; case "Alphabet": block = new BlockAlphabet(); break; case "Amazon": block = new BlockAmazon(); break; case "Facebook": block = new BlockFacebook(); break; case "IBM": block = new BlockIBM(); break; case "Intel": block = new BlockIntel(); break; case "Microsoft": block = new BlockMicrosoft(); break; case "Netflix": block = new BlockNetflix(); break; case "Twitter": block = new BlockTwitter(); break; case "Yahoo": block = new BlockYahoo(); break; default: block = new BlockAir(); break; } block.upsideDown = GetComponent <PrefabBlockTexture>().upsideDown; return(block); }
public virtual Block.Tile TexturePosition(Block.Direction direction) { Block.Tile tile = new Block.Tile(); switch (blockType) { case "Stone": Block blockStone = new Block(); blockStone.upsideDown = upsideDown; tile = blockStone.TexturePosition(direction); return(tile); case "Grass": BlockGrass blockGrass = new BlockGrass(); blockGrass.upsideDown = upsideDown; tile = blockGrass.TexturePosition(direction); return(tile); case "BrownWood": BlockBrownWood blockBrownWood = new BlockBrownWood(); blockBrownWood.upsideDown = upsideDown; tile = blockBrownWood.TexturePosition(direction); return(tile); case "Lava": BlockLava blockLava = new BlockLava(); blockLava.upsideDown = upsideDown; tile = blockLava.TexturePosition(direction); return(tile); case "GreenLeaves": BlockGreenLeaves blockGreenLeaves = new BlockGreenLeaves(); blockGreenLeaves.upsideDown = upsideDown; tile = blockGreenLeaves.TexturePosition(direction); return(tile); case "OrangeLeaves": BlockOrangeLeaves blockOrangeLeaves = new BlockOrangeLeaves(); blockOrangeLeaves.upsideDown = upsideDown; tile = blockOrangeLeaves.TexturePosition(direction); return(tile); case "StoneSnow": BlockStoneSnow blockStoneSnow = new BlockStoneSnow(); blockStoneSnow.upsideDown = upsideDown; tile = blockStoneSnow.TexturePosition(direction); return(tile); case "Ice": BlockIce blockIce = new BlockIce(); blockIce.upsideDown = upsideDown; tile = blockIce.TexturePosition(direction); return(tile); case "Glass": BlockGlass blockGlass = new BlockGlass(); blockGlass.upsideDown = upsideDown; tile = blockGlass.TexturePosition(direction); return(tile); case "WhiteWood": BlockWhiteWood blockWhiteWood = new BlockWhiteWood(); blockWhiteWood.upsideDown = upsideDown; tile = blockWhiteWood.TexturePosition(direction); return(tile); case "Apple": BlockApple blockApple = new BlockApple(); blockApple.upsideDown = upsideDown; tile = blockApple.TexturePosition(direction); return(tile); case "Alphabet": BlockAlphabet blockAlphabet = new BlockAlphabet(); blockAlphabet.upsideDown = upsideDown; tile = blockAlphabet.TexturePosition(direction); return(tile); case "Amazon": BlockAmazon blockAmazon = new BlockAmazon(); blockAmazon.upsideDown = upsideDown; tile = blockAmazon.TexturePosition(direction); return(tile); case "Facebook": BlockFacebook blockFacebook = new BlockFacebook(); blockFacebook.upsideDown = upsideDown; tile = blockFacebook.TexturePosition(direction); return(tile); case "IBM": BlockIBM blockIBM = new BlockIBM(); blockIBM.upsideDown = upsideDown; tile = blockIBM.TexturePosition(direction); return(tile); case "Intel": BlockIntel blockIntel = new BlockIntel(); blockIntel.upsideDown = upsideDown; tile = blockIntel.TexturePosition(direction); return(tile); case "Microsoft": BlockMicrosoft blockMicrosoft = new BlockMicrosoft(); blockMicrosoft.upsideDown = upsideDown; tile = blockMicrosoft.TexturePosition(direction); return(tile); case "Netflix": BlockNetflix blockNetflix = new BlockNetflix(); blockNetflix.upsideDown = upsideDown; tile = blockNetflix.TexturePosition(direction); return(tile); case "Twitter": BlockTwitter blockTwitter = new BlockTwitter(); blockTwitter.upsideDown = upsideDown; tile = blockTwitter.TexturePosition(direction); return(tile); case "Yahoo": BlockYahoo blockYahoo = new BlockYahoo(); blockYahoo.upsideDown = upsideDown; tile = blockYahoo.TexturePosition(direction); return(tile); case "Leaves0": BlockLeaves0 blockLeaves0 = new BlockLeaves0(); blockLeaves0.upsideDown = upsideDown; tile = blockLeaves0.TexturePosition(direction); return(tile); case "Leaves1": BlockLeaves1 blockLeaves1 = new BlockLeaves1(); blockLeaves1.upsideDown = upsideDown; tile = blockLeaves1.TexturePosition(direction); return(tile); case "Leaves2": BlockLeaves2 blockLeaves2 = new BlockLeaves2(); blockLeaves2.upsideDown = upsideDown; tile = blockLeaves2.TexturePosition(direction); return(tile); case "Leaves3": BlockLeaves3 blockLeaves3 = new BlockLeaves3(); blockLeaves3.upsideDown = upsideDown; tile = blockLeaves3.TexturePosition(direction); return(tile); case "Leaves4": BlockLeaves4 blockLeaves4 = new BlockLeaves4(); blockLeaves4.upsideDown = upsideDown; tile = blockLeaves4.TexturePosition(direction); return(tile); } //just in case it's not registered Block blockAir = new BlockAir(); tile = blockAir.TexturePosition(direction); return(tile); }