/// <summary> /// This method takes in a list of candidate blocks to move to and selects the best one depending on the ant's role and pheromones. /// </summary> /// <param name="candidateBlocks"></param> /// <returns></returns> private AirBlock DecideMovementBlock(List <AirBlock> candidateBlocks) { // Select a random block first AirBlock result = candidateBlocks[RNG.Next(candidateBlocks.Count)]; // Then depending on the task see if there's a better block foreach (AirBlock block in candidateBlocks) { if (!queen) { if (status == "Foraging") { // Go where the food concentration is the highest, and the acid levels the lowest if (block.pheromoneDeposits["food"] - block.pheromoneDeposits["acid"] > result.pheromoneDeposits["food"] - result.pheromoneDeposits["acid"] && block.pheromoneDeposits["food"] > 0.5 && block.pheromoneDeposits["food"] < foodPheromoneDetectionLimit) { result = block; } } if (status == "TendingQueen") { // Go where the queen concentration is the highest, and the acid levels the lowest if (block.pheromoneDeposits["queen"] - block.pheromoneDeposits["acid"] > result.pheromoneDeposits["queen"] - result.pheromoneDeposits["acid"] && block.pheromoneDeposits["queen"] > 0.5) { result = block; } try { // If a potential movement space is near the queen, go to that one if (Mathf.Abs((int)block.worldXCoordinate - (int)worldScript.Ants[0].transform.position.x) <= 1 && Mathf.Abs((int)block.worldYCoordinate - (int)worldScript.Ants[0].transform.position.y) <= 1 && Mathf.Abs((int)block.worldZCoordinate - (int)worldScript.Ants[0].transform.position.z) <= 1) { result = block; break; } } catch (ArgumentOutOfRangeException) { // Thrown because the queen is dead, ignore } } } else // The queen's actions { // Go where the nest concentration is the highest if (block.pheromoneDeposits["nest"] - block.pheromoneDeposits["acid"] > result.pheromoneDeposits["nest"] - result.pheromoneDeposits["acid"] && block.pheromoneDeposits["nest"] > 0.5 && block.pheromoneDeposits["nest"] < nestPheromoneDetectionLimit) { result = block; } } } return(result); }
public IEnumerator BlockTypeIsAir() { AirBlock testCandidate = AirBlock.GetInstance(); yield return(null); Assert.That(testCandidate, Is.Not.Null); Assert.That(testCandidate.GetBlockType(), Is.EqualTo(BlockTypes.AIR)); }
public static AirBlock GetInstance() { if (null != instance) { return(instance); } instance = new AirBlock(); return(instance); }
public IEnumerator BlockFacesAreNotCoveringAnything() { AirBlock testCandidate = AirBlock.GetInstance(); yield return(null); Assert.IsFalse(testCandidate.GetFrontFaceIsCovering()); Assert.IsFalse(testCandidate.GetRightFaceIsCovering()); Assert.IsFalse(testCandidate.GetBackFaceIsCovering()); Assert.IsFalse(testCandidate.GetLeftFaceIsCovering()); Assert.IsFalse(testCandidate.GetBottomFaceIsCovering()); Assert.IsFalse(testCandidate.GetTopFaceIsCovering()); }
public IEnumerator LeftFaceIsShownWhenItsNotCovering() { SolidBlockFaceHidingStrategy testCandidate = new SolidBlockFaceHidingStrategy(); Block coveredBlock = AirBlock.GetInstance(); Block coveringBlock = EarthBlock.GetInstance(); bool result = testCandidate.FaceIsHidden(coveredBlock, coveringBlock, BlockFaceDirections.LEFT); yield return(null); Assert.IsFalse(result); }
public bool TryGetBlock(Vector3Int pos, out Block block) { if (pos == origin) { block = expectedBlock; return(true); } else { block = new AirBlock(); return(false); } }
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); }
public IEnumerator TopFaceOfBlockIsVisibleWhenNotFullyCovering() { Island testCandidate = new Island(64); BlockPosition blockPositionOne = new BlockPosition(0, 4, 0); BlockPosition blockPositionTwo = new BlockPosition(0, 5, 0); Block testBlock = AirBlock.GetInstance(); Block neighbor = RockBlock.GetInstance(); testCandidate.PlaceBlockAt(testBlock, blockPositionOne); testCandidate.PlaceBlockAt(neighbor, blockPositionTwo); bool result = testCandidate.BlockFaceAtPositionIsHidden(BlockFaceDirections.TOP, blockPositionOne); yield return(null); Assert.That(result, Is.EqualTo(false)); }
public IEnumerator RightFaceOfBlockIsVisibleWhenNotCovered() { Island testCandidate = new Island(64); BlockPosition blockPositionOne = new BlockPosition(46, 0, 0); BlockPosition blockPositionTwo = new BlockPosition(45, 0, 0); Block testBlock = GrassyEarthBlock.GetInstance(); Block neighbor = AirBlock.GetInstance(); testCandidate.PlaceBlockAt(testBlock, blockPositionOne); testCandidate.PlaceBlockAt(neighbor, blockPositionTwo); bool result = testCandidate.BlockFaceAtPositionIsHidden(BlockFaceDirections.RIGHT, blockPositionOne); yield return(null); Assert.That(result, Is.EqualTo(false)); }
void Start() { if (useChunks) { for (int x = 0; x < worldSize; x++) { for (int y = 0; y < worldSize; y++) { for (int z = 0; z < worldSize; z++) { CreateChunk(x * Chunk.chunkSize, y * Chunk.chunkSize, z * Chunk.chunkSize); } } } } else { for (int x = 0; x < worldBlockSize; x++) { for (int y = 0; y < worldBlockSize; y++) { for (int z = 0; z < worldBlockSize; z++) { blocks[x, y, z] = new AirBlock(); } } } } }
public static void UseEntity(MinecraftClient client, MinecraftServer server, IPacket _packet) { var packet = (UseEntityPacket)_packet; var target = server.EntityManager.GetEntity(packet.Target); if (target == null || server.EntityManager.GetEntityWorld(target) != server.EntityManager.GetEntityWorld(client.Entity) || target.Position.DistanceTo(client.Entity.Position) > client.Reach) { return; } target.UsedByEntity(client.World, packet.LeftClick, client.Entity); if (target is LivingEntity) { // Do damage // TODO: Move to Craft.Net.Data? if (packet.LeftClick) { var livingEntity = target as LivingEntity; if (livingEntity.Invulnerable) { return; } var item = client.Entity.SelectedItem.AsItem(); if (item == null) { item = new AirBlock(); } client.Entity.FoodExhaustion += 0.3f; livingEntity.Damage(item.AttackDamage); // TODO: Knockback enchantment livingEntity.Velocity /*+*/ = MathHelper.RotateY(new Vector3(0, 0, client.Entity.IsSprinting ? 10 : 3), MathHelper.DegreesToRadians(client.Entity.Yaw)); if (livingEntity is PlayerEntity) { (livingEntity as PlayerEntity).LastDamageType = DamageType.Combat; (livingEntity as PlayerEntity).LastAttackingEntity = client.Entity; } // TODO: Physics } } }
/// <summary> /// This method decides where, how, and why the ant should move, and then moves the ant there. /// </summary> public void Move() { if (!(worldScript.GetBlock((int)transform.position.x, (int)transform.position.y - 1, (int)transform.position.z) is AirBlock)) // Only move if on solid ground { // Get the possible movement blocks candidateBlocks = GetCandidateMovementBlocks((int)transform.position.x, (int)transform.position.y, (int)transform.position.z); if (candidateBlocks.Count > 0) { // Decide on a movement block AirBlock destination = DecideMovementBlock(candidateBlocks); // Rotate and move to the block transform.Rotate(0, (destination.worldYCoordinate - transform.position.y) * 90, 0); transform.position = new Vector3((int)destination.worldXCoordinate, (int)destination.worldYCoordinate, (int)destination.worldZCoordinate); // If you're foraging check if the block you're standing on is a mulch block // If it is, dig it up if (status == "Foraging" && !queen) { if (worldScript.GetBlock((int)transform.position.x, (int)transform.position.y - 1, (int)transform.position.z) is MulchBlock) { Dig(); } } // Otherwise try to tend to the queen else if (status == "TendingQueen" && !queen) { TendQueen(); } // If you're the queen decide whether and where you should build a nest block else if (queen) { BuildingNest(); } } } else { transform.position += Vector3.down; // Fall } }
static private void ShootDeathLaser(Vector3 origin) { Vector3Int blockPosition; bool success = BlockLaser.GetBlockPositionAtMouse(origin, out blockPosition); if (success) { Block block; GridMap.Instance.TryGetBlock(blockPosition, out block); print("Blockpos at " + blockPosition); if (block != null) { print("Destroyed a " + block.GetName()); Block newBlock = new AirBlock(); GridMap.Instance.SetBlock(blockPosition, newBlock); } else { Debug.LogError("Hit block, but no block was found at that position"); } } }
private void PrepareLevel(bool spawnPlayer) { Level level = new Level(LEVEL_WIDTH, LEVEL_HEIGHT); BOUNDRY_BLOCKS[0] = new Vector3(0, 0); BOUNDRY_BLOCKS[1] = new Vector3(LEVEL_WIDTH * 2.65f, 0); BOUNDRY_BLOCKS[2] = new Vector3(0, LEVEL_HEIGHT * 2.65f); BOUNDRY_BLOCKS[3] = new Vector3(0, 0); for (int x = 0; x < LEVEL_WIDTH; x++) { for (int y = 0; y < LEVEL_HEIGHT; y++) { Color color = currentLevelTex.GetPixel(x, y); if (ColorMap.MatchesColor(color, ColorMap.THEME_FOREST)) // read in theme { ThemeLoader.LoadForestTheme(); } else if (ColorMap.MatchesColor(color, ColorMap.THEME_DESERT)) { ThemeLoader.LoadDesertTheme(); } else if (ColorMap.MatchesColor(color, ColorMap.DULL_BLOCK)) { DullBlock block = Instantiate(defaultBlock); block.block = Block.init(x, y, level, block.gameObject); } else if (ColorMap.MatchesColor(color, ColorMap.CHECKPOINT)) { CheckpointBlock block = Instantiate(checkpointBlock); block.block = Block.init(x, y, level, block.gameObject); CheckpointManager.AddCheckpoint(block); } else if (ColorMap.MatchesColor(color, ColorMap.AIR_BLOCK)) { AirBlock block = Instantiate(airBlock); block.block = Block.init(x, y, level, block.gameObject); } else if (ColorMap.MatchesColor(color, ColorMap.SPEED_BLOCK)) { SpeedBlock block = Instantiate(speedBlock); block.block = Block.init(x, y, level, block.gameObject); } else if (ColorMap.MatchesColor(color, ColorMap.CRUMBLY_BLOCK)) { CrumblyBlock block = Instantiate(crumblyBlock); block.block = Block.init(x, y, level, block.gameObject); } else if (ColorMap.MatchesColor(color, ColorMap.FINISH)) { FinishBlock block = Instantiate(finishBlock); block.block = Block.init(x, y, level, block.gameObject); } else if (ColorMap.MatchesColor(color, ColorMap.LEAP_BOOST_BLOCK)) { LeapBoostBlock block = Instantiate(leapBoostBlock); block.block = Block.init(x, y, level, block.gameObject); } else if (ColorMap.MatchesColor(color, ColorMap.AUTO_LEAP_BOOST_BLOCK)) { AutoLeapBoostBlock block = Instantiate(autoLeapBoostBlock); block.block = Block.init(x, y, level, block.gameObject); } else if (ColorMap.MatchesColor(color, ColorMap.DISGUISED_CRUMBLY_BLOCK)) { CrumblyBlock block = Instantiate(crumblyBlock); Disguise disguise = block.gameObject.AddComponent <Disguise>(); disguise.identity = crumblyBlock.GetComponent <SpriteRenderer>().sprite; disguise.camouflage = defaultBlock.GetComponent <SpriteRenderer>().sprite; disguise.HideIdentity(); block.block = Block.init(x, y, level, block.gameObject); } else if (ColorMap.MatchesColor(color, ColorMap.DISGUISED_AUTO_LEAP_BOOST_BLOCK)) { AutoLeapBoostBlock block = Instantiate(autoLeapBoostBlock); Disguise disguise = block.gameObject.AddComponent <Disguise>(); disguise.identity = autoLeapBoostBlock.GetComponent <SpriteRenderer>().sprite; disguise.camouflage = defaultBlock.GetComponent <SpriteRenderer>().sprite; disguise.HideIdentity(); block.block = Block.init(x, y, level, block.gameObject); } else if (ColorMap.MatchesColor(color, ColorMap.DISGUISED_DULL_BLOCK)) { DullBlock block = Instantiate(defaultBlock); Disguise disguise = block.gameObject.AddComponent <Disguise>(); disguise.identity = defaultBlock.GetComponent <SpriteRenderer>().sprite; disguise.camouflage = null; disguise.HideIdentity(); block.block = Block.init(x, y, level, block.gameObject); } else if (ColorMap.MatchesColor(color, ColorMap.GHOST_BLOCK)) { DullBlock block = Instantiate(defaultBlock); Disguise disguise = block.gameObject.AddComponent <Disguise>(); disguise.identity = null; disguise.camouflage = null; disguise.HideIdentity(); block.block = Block.init(x, y, level, block.gameObject); } else if (ColorMap.MatchesColor(color, ColorMap.ENEMY_SUKAMON)) { // spawn sukamon EnemyControl ec = Instantiate(sukamon); ec.transform.position = new Vector3(x * 2.65f, y * 2.65f + 0.5f); } else if (ColorMap.MatchesColor(color, ColorMap.DIGIVICE)) { } else if (ColorMap.MatchesColor(color, ColorMap.ENEMY_KINGETEMON)) { EnemyControl ec = Instantiate(kingetemon); ec.transform.position = new Vector3(x * 2.65f, y * 2.65f + 0.5f); } else if (ColorMap.MatchesColor(color, ColorMap.ENEMY_SUKAMON_STATIC)) { EnemyControl ec = Instantiate(sukamon); ec.blockRadius = 0; ec.transform.position = new Vector3(x * 2.65f, y * 2.65f + 0.5f); } else if (ColorMap.MatchesColor(color, ColorMap.ENEMY_GIGANTIC_SUKAMON)) { EnemyControl ec = Instantiate(giganticSukamon); ec.blockRadius = 20; ec.moveSpeed = 8; //ec.health *= 5; ec.transform.position = new Vector3(x * 2.65f, y * 2.65f + 0.5f); } else if (ColorMap.MatchesColor(color, ColorMap.WOODEN_SIGN)) { SignDialogue sd = Instantiate(signDialogue); sd.transform.position = new Vector3(x * 2.65f, y * 2.65f + 0.5f); } } } currentLevel = level; foreach (var observer in OBSERVERS) { observer.OnLevelLoaded(level); } if (spawnPlayer) { int score = 1; if (currentPlayerInstance != null) { score = currentPlayerInstance.score; } Vector3 pos = CheckpointManager.ActiveCheckpoint.transform.position; Player p = Instantiate(player); p.transform.position = new Vector3(pos.x, pos.y + 5, pos.z); currentPlayerInstance = p; p.score = score; Debug.Log(p.score); Camera.main.GetComponent <CamCapture>().player = p; Camera.main.GetComponent <CamCapture>().boundryBlocks = BOUNDRY_BLOCKS; } }
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; } } } }
/// <summary> /// This method checks whether a nest block should be placed, and where. /// </summary> public void BuildingNest() { if (queen) // Double check this is the queen { // Make sure the queen has enough health to produce a block if (health >= nestHealthThreshold) { // Remove a grass or mulch block to build first nest block if ((worldScript.GetBlock((int)transform.position.x, (int)transform.position.y - 1, (int)transform.position.z) is GrassBlock || worldScript.GetBlock((int)transform.position.x, (int)transform.position.y - 1, (int)transform.position.z) is MulchBlock) && !builtFirstNestBlock) { // Build the first nest block builtFirstNestBlock = true; Dig(); ProduceNestBlock((int)transform.position.x, (int)transform.position.y - 1, (int)transform.position.z); // Debug.Log("Produced first nest block"); } else if (builtFirstNestBlock) { for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { for (int k = -1; k < 2; k++) { if (!(i == 0 && j == 0 && k == 0)) // Skip the block the queen occupies { // If this adjacent block is a nest block, get its neighbours if (worldScript.GetBlock((int)transform.position.x + i, (int)transform.position.y + j, (int)transform.position.z + k) is NestBlock) { List <AbstractBlock> neighbours = new List <AbstractBlock>(); neighbours = worldScript.GetNeighbours(worldScript.GetBlock((int)transform.position.x + i, (int)transform.position.y + j, (int)transform.position.z + k)); AirBlock toReplace = new AirBlock { worldYCoordinate = 10000 }; // For all of the nestblock's neighbours which are air blocks... foreach (AbstractBlock neighbour in neighbours) { if (neighbour is AirBlock) { // Check if that neighbour is also adjacent to the queen ant if (Mathf.Abs((int)neighbour.worldXCoordinate - (int)transform.position.x) <= 1 && Mathf.Abs((int)neighbour.worldYCoordinate - (int)transform.position.y) <= 1 && Mathf.Abs((int)neighbour.worldZCoordinate - (int)transform.position.z) <= 1) { // Then see which one is the lowest so the queen can build from bottom up if (neighbour.worldYCoordinate < toReplace.worldYCoordinate) { toReplace = neighbour as AirBlock; } } } } // We have an elegible spot if (toReplace.worldYCoordinate < 10000) { // Make sure another ant doesn't currently occupy it bool occupied = false; foreach (AgentManager ant in worldScript.Ants) { if (ant.transform.position.x == toReplace.worldXCoordinate && ant.transform.position.y == toReplace.worldYCoordinate && ant.transform.position.z == toReplace.worldZCoordinate) { occupied = true; } } if (!occupied) { // Now we have the block to replace ProduceNestBlock(toReplace.worldXCoordinate, toReplace.worldYCoordinate, toReplace.worldZCoordinate); return; } } } } } } } } } } }
/// <summary> /// Replaces all the blocks with air blocks /// </summary> public void ClearWorld() { if (useChunks) { foreach (Chunk c in chunks.Values) { c.ClearChunk(); } } else { Block[,,] air = new Block[worldBlockSize, worldBlockSize, worldBlockSize]; for (int x = 0; x < worldBlockSize; x++) { for (int y = 0; y < worldBlockSize; y++) { for (int z = 0; z < worldBlockSize; z++) { air[x, y, z] = new AirBlock(); } } } SetAllBlocks(air); } }
/// <summary> /// Reads a level to a block array /// </summary> /// <param name="reader">BinaryReader to read with</param> /// <returns>Block array of level</returns> public static Block[,,] LoadLevel(BinaryReader reader) { //Read version number reader.ReadInt32(); //Read thumbnail int thumbnailSize = reader.ReadInt32(); reader.ReadBytes(thumbnailSize); //Read camera position CameraOrbit.instance.x = reader.ReadSingle(); CameraOrbit.instance.y = reader.ReadSingle(); CameraOrbit.instance.distance = reader.ReadSingle(); CameraOrbit.instance.smoothX = CameraOrbit.instance.x; CameraOrbit.instance.smoothY = CameraOrbit.instance.y; CameraOrbit.instance.smoothDistance = CameraOrbit.instance.distance; float cameraX = reader.ReadSingle(); float cameraZ = reader.ReadSingle(); CameraMove.instance.floor = reader.ReadInt32(); CameraMove.instance.transform.position = new Vector3(cameraX, CameraMove.instance.floor, cameraZ); //Read block ids List<Block> blockList = new List<Block>(); short blockListCount = reader.ReadInt16(); for (short i = 0; i < blockListCount; i++) { blockList.Add(BlockManager.GetBlock(reader.ReadString())); } //Read number of blocks int blockCount = reader.ReadInt32(); //Read blocks Block[,,] blocks = new Block[World.worldBlockSize, World.worldBlockSize, World.worldBlockSize]; for (int x = 0; x < World.worldBlockSize; x++) { for (int y = 0; y < World.worldBlockSize; y++) { for (int z = 0; z < World.worldBlockSize; z++) { blocks[x, y, z] = new AirBlock(); } } } for (int i = 0; i < blockCount; i++) { byte x = reader.ReadByte(); byte y = reader.ReadByte(); byte z = reader.ReadByte(); byte rotation = reader.ReadByte(); short blockId = reader.ReadInt16(); blocks[x, y, z] = blockList[blockId].Copy(); blocks[x, y, z].rotation = rotation; } reader.Close(); return blocks; }
/// <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 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); }