protected virtual IEnumerator WaitForPlayerToFinishLevel() { while (activeDeliveryPOIs.Count > 0) { yield return(null); } GameManager.Self.runTimers = false; //GameManager.Self.player.letControlPawn = false; GameManager.Self.levelTransitioner.TransitionScreen(false); if (GameManager.Self.player.possessedPawn) { GameManager.Self.DoWorldLooping = true; if (GameManager.Self.worldLooper) { GameManager.Self.worldLooper.transform.position = Vector3.zero; } } StartCoroutine(WaitToTeleportPlayerTo(Vector2.zero)); ProcRoom pr = _seedRoom.GetComponent <ProcRoom>(); while (GameManager.Self.levelTransitioner.AnimIsPlaying) { yield return(null); } pr.DestroyRoom(); }
void PaintRoom(ProcRoom room) { tileSystem.BeginBulkEdit(); // get random coordinates to attempt to place new room int originX = (int) MLib.NextGaussian(mapColumns / 2, mapColumns / 2, 2f, mapColumns); int originY = (int) MLib.NextGaussian(mapRows / 2, mapRows / 2, 2f, mapRows); // check that room will fit within map bounds if (InBounds(originX, originY, room)) { // paint room for (int x = originX; x < room.width + originX; x++) { for (int y = originY; y < room.height + originY; y++) { tileSystem.EraseTile(y, x); tileSystem.RefreshSurroundingTiles(y, x); } } } else { PaintRoom(room); } tileSystem.EndBulkEdit(); }
public virtual void DestroyNode() { if (_thisRoom) { ProcRoom pr = _thisRoom.GetComponent <ProcRoom>(); pr.DestroyRoom(); } Destroy(gameObject); }
bool RoomInBounds(int originX, int originY, ProcRoom room) { if (originX + room.width < (mapColumns - mapMarginX) && originY + room.height < (mapRows - mapMarginY)) { return(true); } return(false); }
bool WithinRoomBounds(ProcRoom room, int x, int y) { if ((x >= room.originX && x <= room.width) && (y >= room.originY && y <= room.height)) { return(true); } return(false); }
void CarveRandomRooms() { for (int i = 0; i < numberOfRooms; i++) { var roomToDraw = new ProcRoom(); GetRoom(roomToDraw); PaintRoomRandomly(roomToDraw); } }
void CarveRandomRooms() { for (int i = 0; i < numberOfRooms; i++) { ProcRoom roomToDraw = new ProcRoom(); GetRoom(roomToDraw); PaintRoomRandomly(roomToDraw); } }
bool InBounds(int x, int y, ProcRoom room) { if (x + room.width < (mapColumns - 1) && y + room.height < (mapRows - 1)) { return true; } else { return false; } }
void CarveRandomRooms() { ProcRoom roomToDraw = new ProcRoom(); for (int i = 0; i < numberOfRooms; i++) { GetRoom(roomToDraw); // Debug.Log("w = " + roomToDraw.width + ". H = " + roomToDraw.height); PaintRoom(roomToDraw); } }
protected virtual IEnumerator GenerateLevel(int expansiveness) { //Generation Setup GameManager.Self.runTimers = false; GameManager.Self.player.letControlPawn = false; GameManager.Self.levelTransitioner.TransitionScreen(false); if (_showGenerationDebug) { Debug.Log("Starting " + expansiveness + " expense generation..."); _debugTimeToGen = 0.0f; } _isGenerating = true; //Generation Proper Vector3 spawnCoord = new Vector3(Mathf.Lerp(spawnBoundaries.x, spawnBoundaries.z, 0.5f), Mathf.Lerp(spawnBoundaries.y, spawnBoundaries.w, 0.5f), 0.0f); _seedRoom = Instantiate(TileSet[Random.Range(0, TileSet.Length)], spawnCoord, Quaternion.Euler(Vector3.zero)); ProcRoom pr = _seedRoom.GetComponent <ProcRoom>(); List <POISpawn> POISpawns = new List <POISpawn>(); yield return(pr.GenerateRoom(TileSet, spawnBoundaries, expansiveness, POISpawns)); foreach (Pizza p in GameManager.Self.ActiveDeliveries) { if (p.DestinationPlanet == gameObject) { POISpawn selectedPOI = POISpawns[Random.Range(0, POISpawns.Count)]; activeDeliveryPOIs.Add(selectedPOI.GenerateAsDelivery((int)p.NumericID)); POISpawns.Remove(selectedPOI); } } foreach (POISpawn poi in POISpawns) { poi.GenerateAsDangerousObject(); } //Post-Generation Actions; if (_showGenerationDebug) { Debug.Log("... generation done.\nThis took " + _debugTimeToGen + " seconds."); } GameManager.Self.DoWorldLooping = false; StartCoroutine(WaitToTeleportPlayerTo(spawnCoord)); StartCoroutine(WaitForPlayerToFinishLevel()); }
bool TouchingRooms(int originX, int originY, ProcRoom room) { // iterate through each potential tile placement for (int x = originX - roomMarginX; x < room.width + originX + roomMarginX; x++) { for (int y = originY - roomMarginY; y < room.height + originY + roomMarginY; y++) { // if a room has already been carved out here, return true if (map.GetTileInfo(x, y) == null) { return(true); } } } return(false); }
void PaintRoomRandomly(ProcRoom room) { bool successful = false; int attempts = 0; map.BulkEditBegin(); while (!successful && attempts < 5) { // random ints divisible by four 4 — keeps some distance between elements int originX = Rand.RangeDivFour(mapMarginX, mapColumns - mapMarginX); int originY = Rand.RangeDivFour(mapMarginY, mapRows - mapMarginY); // check that room will fit within map bounds if (RoomInBounds(originX, originY, room) && !TouchingRooms(originX, originY, room)) { // paint room for (int x = 0; x < room.width; x++) { for (int y = 0; y < room.height; y++) { map.ClearTile(originX + x, originY + y); } } // with room succesfully placed, set origin then add room to List room.originX = originX; room.originY = originY; rooms.Add(room); successful = true; } attempts++; } map.BulkEditEnd(); }
void PaintRoom(ProcRoom room) { bool successful = false; int attempts = 0; map.BeginBulkEdit(); while (!successful && attempts < 5) { // get random coordinates to attempt to place new room // int originX = (int) MLib.NextGaussian(mapColumns / 2, mapColumns / 2, mapMarginX, mapColumns); // int originY = (int) MLib.NextGaussian(mapRows / 2, mapRows / 2, mapMarginY, mapRows); Random rand = new Random(); int originX = rand.DivFour(mapMarginX, mapColumns - mapMarginX); int originY = rand.DivFour(mapMarginY, mapRows - mapMarginY); // check that room will fit within map bounds if (RoomInBounds(originX, originY, room) && !TouchingRooms(originX, originY, room)) { // paint room for (int x = 0; x < room.width; x++) { for (int y = 0; y < room.height; y++) { map.EraseTile(originY + y, originX + x); map.RefreshSurroundingTiles(originY + y, originX + x); } } // with room succesfully placed, set origin then add to List room.originX = originX; room.originY = originY; rooms.Add(room); successful = true; } attempts++; } map.EndBulkEdit(); }
bool WithinRoomBounds(ProcRoom room, int x, int y) { if ((x >= room.originX && x <= room.width) && (y >= room.originY && y <= room.height)) { return true; } return false; }
bool TouchingRooms(int originX, int originY, ProcRoom room) { // iterate through each potential tile placement for (int x = originX - roomMarginX; x < room.width + originX + roomMarginX; x++) { for (int y = originY - roomMarginY; y < room.height + originY + roomMarginY; y++) { // if a room has already been carved out here, return true if (map.GetTileInfo(x, y) == null) { return true; } } } return false; }
bool RoomInBounds(int originX, int originY, ProcRoom room) { if (originX + room.width < (mapColumns - mapMarginX) && originY + room.height < (mapRows - mapMarginY)) { return true; } return false; }
void GetRoom(ProcRoom room) { room.width = Rand.GaussianDivFour(8, 8, 2, 50); room.height = Rand.GaussianDivFour(4, 8, 8, 20); }
void PaintRoomRandomly(ProcRoom room) { bool successful = false; int attempts = 0; map.BeginBulkEdit(); while (!successful && attempts < 5) { // get random coordinates to attempt to place new room int randX = (int) MLib.NextGaussian(mapColumns / 2, mapColumns / 2, mapMarginX, mapColumns); int randY = (int) MLib.NextGaussian(mapRows / 2, mapRows / 2, mapMarginY, mapRows); // convert coordinates to divisors of 4; elements from being too close to each other int originX = MLib.RoundToDivFour(randX); int originY = MLib.RoundToDivFour(randY); // check that room will fit within map bounds if (RoomInBounds(originX, originY, room) && !TouchingRooms(originX, originY, room)) { // paint room for (int x = 0; x < room.width; x++) { for (int y = 0; y < room.height; y++) { map.EraseTile(originY + y, originX + x); map.RefreshSurroundingTiles(originY + y, originX + x); } } // with room succesfully placed, set origin then add to List room.originX = originX; room.originY = originY; rooms.Add(room); successful = true; } attempts++; } map.EndBulkEdit(); }
// return various room coordinates for procedural generation public static int TopLeftX(ProcRoom room) { return room.originX; }
public static int BottomLeftX(ProcRoom room) { return room.originX; }
void GetRoom(ProcRoom room) { room.width = (int) MLib.NextGaussian(20f, 5f, 2f, 50f); room.height = (int) MLib.NextGaussian(5f, 5f, 2f, 50f); }
public static int TopRightY(ProcRoom room) { return room.originY; }
public virtual IEnumerator GenerateNewRoom(GameObject[] TileSet, Vector4 spawnBoundaries, List <POISpawn> poiStorage) { if (!_hasGenerated) { //Debug.Log("Hi I'm at " + transform.position + " and I'm doing stuff with a potency of " + potency); //Debug.DrawLine(transform.position, RoomSpawnLocation.position, Color.magenta, 1.0f); //UnityEditor.EditorApplication.isPaused = true; Vector2 worldPos = transform.position; if (worldPos.x > spawnBoundaries.x && worldPos.y > spawnBoundaries.y && worldPos.x < spawnBoundaries.z && worldPos.y < spawnBoundaries.w) { RoomSpawnNodes closestRoomNode = null; float closestRoomDistance = 1000; ProcRoom pr = null; Collider2D[] foundCols = Physics2D.OverlapCircleAll(RoomSpawnLocation.position, roomCheckRadius); //Debug.Log("OverlapCircleAll: " + foundCols.Length); //Debug.DrawLine((Vector2)RoomSpawnLocation.position + Vector2.left * roomCheckRadius, (Vector2)RoomSpawnLocation.position + Vector2.right * roomCheckRadius, Color.green); //Debug.DrawLine((Vector2)RoomSpawnLocation.position + Vector2.up * roomCheckRadius, (Vector2)RoomSpawnLocation.position + Vector2.down * roomCheckRadius, Color.green); //UnityEditor.EditorApplication.isPaused = true; //yield return null; if (foundCols.Length > 0) { foreach (Collider2D col in foundCols) { //Debug.DrawLine((Vector2)RoomSpawnLocation.position + Vector2.one, (Vector2)RoomSpawnLocation.position + Vector2.one * -1f, Color.red, 1.0f); //Debug.DrawLine((Vector2)RoomSpawnLocation.position + new Vector2(1, -1), (Vector2)RoomSpawnLocation.position + new Vector2(-1, 1), Color.red, 1.0f); ProcRoom existingPR = col.GetComponentInParent <ProcRoom>(); if (existingPR) { pr = existingPR; } } } else { _thisRoom = Instantiate(TileSet[Random.Range(0, TileSet.Length)], RoomSpawnLocation.position, RoomSpawnLocation.rotation); pr = _thisRoom.GetComponent <ProcRoom>(); } foreach (RoomSpawnNodes rsn in pr.MyRoomSpawnNodes) { float thisRoomDistance = Vector2.Distance(rsn.transform.position, transform.position); if (thisRoomDistance < closestRoomDistance) { closestRoomNode = rsn; closestRoomDistance = thisRoomDistance; } } NodeUsedForRoom(); if (closestRoomNode) { closestRoomNode.NodeUsedForRoom(); } if (_thisRoom) { yield return(pr.GenerateRoom(TileSet, spawnBoundaries, potency - 1, poiStorage)); } } _hasGenerated = true; } }
public static int BottomRightX(ProcRoom room) { return room.originX + room.width - 1; }
void GetRoom(ProcRoom room) { room.width = (int) Rand.GaussianDivFour(8, 8, 2, 50); room.height = (int) Rand.GaussianDivFour(4, 8, 8, 20); }
void GetRoom(ProcRoom room) { room.width = (int) MLib.NextGaussian(8f, 4f, 2f, 50f); room.height = (int) MLib.NextGaussian(4f, 4f, 4f, 50f); // round up to nearest even number room.width = MLib.RoundToDivFour(room.width); room.height = MLib.RoundToDivFour(room.height); }
// return various room coordinates for procedural generation public static int TopLeftX(ProcRoom room) { return(room.originX); }
public static int BottomRightY(ProcRoom room) { return room.originY + room.height - 1; }