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 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); }