public void PositionEnemies() { var unoccupiedPosition = getRandomUnoccupiedPosition(); Debug.Log("Worm: " + unoccupiedPosition.x + ", " + unoccupiedPosition.y); CaveWorm cw = caveWormGameObject.GetComponent <CaveWorm> (); cw.x = (int)unoccupiedPosition.x; cw.y = (int)unoccupiedPosition.y; maze[cw.x][cw.y] = CaveWorm; unoccupiedPosition = getRandomUnoccupiedPosition(); Debug.Log("Alien: " + unoccupiedPosition.x + ", " + unoccupiedPosition.y); var alien = alienGameObject.GetComponent <Alien> (); alien.x = (int)unoccupiedPosition.x; alien.y = (int)unoccupiedPosition.y; maze[alien.x][alien.y] = Alien; unoccupiedPosition = getRandomUnoccupiedPosition(); Debug.Log("Spider: " + unoccupiedPosition.x + ", " + unoccupiedPosition.y); var spider = spiderGameObject.GetComponent <Spider> (); spider.x = (int)unoccupiedPosition.x; spider.y = (int)unoccupiedPosition.y; maze[spider.x][spider.y] = Spider; }
/// <summary> /// Generates caves for this chunk. /// </summary> private void GenerateCaves() { // TODO: Base number of caves off Y value of chunk so fewer caves generate the higher you go. int posOffset = 1000; int numWorms = Mathf.RoundToInt(GameManager.Instance.CaveWormPositionNoiseGenerator.GetNoise(this.ChunkPos.x, this.ChunkPos.y, this.ChunkPos.z).Remap(-1, 1, GameManager.Instance.MinimumCaveWorms, GameManager.Instance.MaximumCaveWorms)); for (int i = 0; i < numWorms; i++) { int posX = Mathf.RoundToInt(GameManager.Instance.CaveWormPositionNoiseGenerator.GetNoise((this.ChunkPos.x * this.ChunkPos.x) + (posOffset * 1 * i), this.ChunkPos.y + (posOffset * 1 * i), this.ChunkPos.z + (posOffset * 1 * i)).Remap(-1, 1, 0, GameManager.ChunkSize)); int posY = Mathf.RoundToInt(GameManager.Instance.CaveWormPositionNoiseGenerator.GetNoise(this.ChunkPos.x + (posOffset * 2 * i), (this.ChunkPos.y * this.ChunkPos.y) + (posOffset * 2 * i), this.ChunkPos.z + (posOffset * 2 * i)).Remap(-1, 1, 0, GameManager.ChunkSize)); int posZ = Mathf.RoundToInt(GameManager.Instance.CaveWormPositionNoiseGenerator.GetNoise(this.ChunkPos.x + (posOffset * 3 * i), this.ChunkPos.y + (posOffset * 3 * i), (this.ChunkPos.z * this.ChunkPos.z) + (posOffset * 3 * i)).Remap(-1, 1, 0, GameManager.ChunkSize)); Vector3Int newWormPos = new Vector3Int(posX, posY, posZ).InternalPosToWorldPos(this.ChunkPos); CaveWorm newWorm = new CaveWorm(newWormPos); this.CaveWorms.Add(newWorm); } Dictionary <Vector3Int, List <Block.BlockUpdate> > chunkUpdates = new Dictionary <Vector3Int, List <Block.BlockUpdate> >(); foreach (CaveWorm worm in this.CaveWorms) { foreach (CaveWorm.Segment segment in worm.Segments) { foreach (Vector3Int point in segment.Points) { Vector3Int chunkPos = point.WorldPosToChunkPos(); if (chunkUpdates.ContainsKey(chunkPos) == true) { chunkUpdates[chunkPos].Add(new Block.BlockUpdate(point.WorldPosToInternalPos(), new Block(BlockType.Air))); } else { chunkUpdates.Add(chunkPos, new List <Block.BlockUpdate>() { new Block.BlockUpdate(point.WorldPosToInternalPos(), new Block(BlockType.Air)) }); } } } } foreach (KeyValuePair <Vector3Int, List <Block.BlockUpdate> > chunkUpdate in chunkUpdates) { if (World.TryGetChunk(chunkUpdate.Key, out Chunk chunk) == true && chunk.HasGeneratedChunkData == true) { chunk.SetBlock(chunkUpdate.Value); } else { World.AddUnloadedChunkBlockUpdates(chunkUpdate.Key, chunkUpdate.Value); } } }
/// <summary> /// Generates cave worms for this chunk. Works by looping through the amount of worms to create and getting /// a random position for each worm to start using remapped 3d noise, then starts a cave worm at that position. /// </summary> public void GenerateCaveWorms() { int posOffset = 1000; // TODO: Change number of worms to be based on noise and not the same value for every chunk. int numWorms = GameManager.Instance.MinimumCaveWorms; for (int i = 0; i < numWorms; i++) { int posX = Mathf.RoundToInt(GameManager.Instance.CaveWormPositionNoiseGenerator.GetNoise((this.ChunkPos.x * this.ChunkPos.x) + (posOffset * 1 * i), this.ChunkPos.y + (posOffset * 1 * i), this.ChunkPos.z + (posOffset * 1 * i)).Map(-1, 1, 0, GameManager.Instance.ChunkSize)); int posY = Mathf.RoundToInt(GameManager.Instance.CaveWormPositionNoiseGenerator.GetNoise(this.ChunkPos.x + (posOffset * 2 * i), (this.ChunkPos.y * this.ChunkPos.y) + (posOffset * 2 * i), this.ChunkPos.z + (posOffset * 2 * i)).Map(-1, 1, 0, GameManager.Instance.ChunkSize)); int posZ = Mathf.RoundToInt(GameManager.Instance.CaveWormPositionNoiseGenerator.GetNoise(this.ChunkPos.x + (posOffset * 3 * i), this.ChunkPos.y + (posOffset * 3 * i), (this.ChunkPos.z * this.ChunkPos.z) + (posOffset * 3 * i)).Map(-1, 1, 0, GameManager.Instance.ChunkSize)); Vector3Int newWormPos = new Vector3Int(posX, posY, posZ).InternalPosToWorldPos(this.ChunkPos); CaveWorm newWorm = new CaveWorm(newWormPos, GameManager.Instance.CaveWormRadius); this.CaveWorms.Add(newWorm); } this.HasGeneratedCaveWorms = true; }