public void PostGenerateOne(Canvas twoDMap, int seed, int aiSeed) { Random.seed = seed; IntVector2 newSize = new IntVector2(size.x / 2, size.z / 2); IntVector2 offset = new IntVector2(-newSize.x - 1, (size.z - newSize.z) / 2); postOneCells = new LevelCell[newSize.x, newSize.z]; List <LevelCell> activeCells = new List <LevelCell>(); IntVector2 coordinates = new IntVector2(offset.x + newSize.x - 1, ((newSize.z - 1) / 2) + offset.z); IntVector2 roomCoordinates = new IntVector2(coordinates.x + 2, coordinates.z); DoFirstPostGenerationStep(postOneCells, activeCells, coordinates, roomCoordinates, twoDMap, offset, newSize); while (activeCells.Count > 0) { DoNextGenerationStep(postOneCells, activeCells, twoDMap, offset, newSize); } Destroy(postOneCells[coordinates.x - offset.x, coordinates.z - offset.z].GetEdge(LevelDirection.East).image.gameObject); Destroy(this.cells[roomCoordinates.x, roomCoordinates.z].GetEdge(LevelDirection.West).image.gameObject); Destroy(postOneCells[coordinates.x - offset.x, coordinates.z - offset.z].GetEdge(LevelDirection.East).gameObject); Destroy(this.cells[roomCoordinates.x, roomCoordinates.z].GetEdge(LevelDirection.West).gameObject); LevelCell cell = CreateHallwayCell(new IntVector2(roomCoordinates.x - 1, roomCoordinates.z), new IntVector2(1, 1), twoDMap); cell.InitializeCell(this.cells[roomCoordinates.x, roomCoordinates.z].room); CreateTwoDCell(cell, twoDMap); CreateWall(cell, null, LevelDirection.North, twoDMap); CreateWall(cell, null, LevelDirection.South, twoDMap); CreatePassageInSameRoom(cell, postOneCells[coordinates.x - offset.x, coordinates.z - offset.z], LevelDirection.West, twoDMap); CreatePassageInSameRoom(cell, this.cells[roomCoordinates.x, roomCoordinates.z], LevelDirection.East, twoDMap); CleanLevel(postOneCells, offset); Random.seed = aiSeed; StartCoroutine(CreatePostConnections()); }
private void DoFirstPostGenerationStep(LevelCell[,] cells, List <LevelCell> activeCells, IntVector2 coordinates, IntVector2 roomCoordinates, Canvas twoDMap, IntVector2 offset, IntVector2 size) { tempNodeList = new List <Node>(); LevelCell cell = CreateCell(cells, coordinates, twoDMap, offset); cell.InitializeCell(this.cells[roomCoordinates.x, roomCoordinates.z].room); CreateTwoDCell(cell, twoDMap); activeCells.Add(cell); }
private void DoFirstGenerationStep(LevelCell [,] cells, List <LevelCell> activeCells, IntVector2 coordinates, Canvas twoDMap, IntVector2 offset, IntVector2 size) { tempNodeList = new List <Node>(); coordinates = new IntVector2(coordinates.x + offset.x, coordinates.z + offset.z); LevelCell cell = CreateCell(cells, coordinates, twoDMap, offset); cell.InitializeCell(CreateRoom(-1)); CreateTwoDCell(cell, twoDMap); activeCells.Add(cell); }
private void CreatePassage(LevelCell cell, LevelCell otherCell, LevelDirection direction, Canvas twoDMap, bool existingCell) { LevelPassage passage = Instantiate(passagePrefab) as LevelPassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(passagePrefab) as LevelPassage; if (!existingCell) { if (Random.value < newRoomProbability) { otherCell.InitializeCell(CreateRoom(cell.room.matIndex)); } else { otherCell.InitializeCell(cell.room); } CreateTwoDCell(otherCell, twoDMap); } passage.Initialize(otherCell, cell, direction.GetOpposite()); CreateTwoDPassage(cell, twoDMap, direction); }