IEnumerator DoNextGenerationStep(ArrayList activeList) { int currentIndex = activeList.Count - 1; BackgroundTile currentTile = (BackgroundTile)activeList[currentIndex]; GeneratorDirections direction = CellDirection.getRandomDirection; Vector2 coordinates = currentTile.mapCoordinate + CellDirection.toVector(direction); if (ContainsCoordinates(coordinates) && mapGameObjects[(int)coordinates.x, (int)coordinates.y] == null) { activeList.Add(CreateCell(coordinates)); cellCount++; } else { activeList.RemoveAt(currentIndex); } yield return(new WaitForSeconds(1.0f)); }
public IEnumerator CreateCorridorWalls() { foreach (GeneratorCorridor corridor in grid.CorridorList) { foreach (GeneratorChunk chunk in corridor.chunks) { Vector2i currPos = chunk.Location; Vector2i posUp = grid.GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Up); Vector2i posDown = grid.GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Down); Vector2i posOnRight = grid.GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Right); Vector2i posOnLeft = grid.GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Left); CreateWall(posUp, currPos, "up", false); CreateWall(posDown, currPos, "down", false); CreateWall(posOnLeft, currPos, "left", false); CreateWall(posOnRight, currPos, "right", false); yield return(0); } } }
public IEnumerator CreateRoomWalls() { foreach (GeneratorRoom room in grid.RoomList) { foreach (GeneratorChunk chunk in room.chunks) { Vector2i currPos = chunk.Location; Vector2i posUp = grid.GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Up); Vector2i posDown = grid.GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Down); Vector2i posOnRight = grid.GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Right); Vector2i posOnLeft = grid.GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Left); CreateWall(posUp, currPos, "up"); CreateWall(posDown, currPos, "down"); CreateWall(posOnLeft, currPos, "left"); CreateWall(posOnRight, currPos, "right"); yield return(0); } } }
public GeneratorChunk GetNeighbor(GeneratorDirection dir) { Vector2i loc = location + GeneratorDirections.ToVector2i(dir); return(grid.GetChunk(loc.x, loc.y)); }
public GeneratorCorridor CreateCorridor(GeneratorChunk groundPrefab, Vector2i room1Pos, Vector2i room2Pos) { GeneratorCorridor newCorridor = new GeneratorCorridor(); Color testColor = new Color(0.9f, 0.9f, 0.9f, 1.0f); Vector2i currPos = room1Pos; GameObject corridor = new GameObject(); corridor.transform.SetParent(parent.transform); corridor.name = "Corridor"; while (currPos.x != room2Pos.x || currPos.y != room2Pos.y) { while (currPos.y != room2Pos.y) { if (!IsRoom(currPos.x, currPos.y) && IsCoordValid(currPos.x, currPos.y)) { GeneratorChunk c = CreateChunk(currPos, groundPrefab, testColor, corridor); if (c != null) { newCorridor.chunks.Add(c); } } // Bug appen if (GetChunk(currPos.x, currPos.y) == null) { Debug.LogError("Bug possible with Corridor"); return(null); } if (room2Pos.y > currPos.y) { currPos = GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Up); } else if (room2Pos.y < currPos.y) { currPos = GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Down); } else { break; } // } if (!IsRoom(currPos.x, currPos.y) && IsCoordValid(currPos.x, currPos.y)) { GeneratorChunk c = CreateChunk(currPos, groundPrefab, testColor, corridor); if (c != null) { newCorridor.chunks.Add(c); } } //Bug appen if (GetChunk(currPos.x, currPos.y) == null) { Debug.LogError("Bug possible with Corridor"); return(null); } if (room2Pos.x > currPos.x) { currPos = GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Right); } else if (room2Pos.x < currPos.x) { currPos = GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Left); } else { break; } // } if (corridor.transform.childCount < 1) { Destroy(corridor); } corridorList.Add(newCorridor); return(newCorridor); }
public static Vector2 toVector(GeneratorDirections direction) { return(directionVectors[(int)direction]); }