protected void CarveRoom() { var roomToDraw = new ProcSpace(); GetRoom(roomToDraw); PaintRoomRandomly(roomToDraw, 100000); }
protected void CarveRoom() { ProcSpace roomToDraw = new ProcSpace(); GetRoom(roomToDraw); PaintRoomRandomly(roomToDraw, 100000); }
protected void CarveCrawlspaces() { map.BulkEditBegin(); int originX; int originY; int x; foreach (ProcSpace room in roomList) { int rand2 = Rand.Range(0, 1); if (rand2 == 0) { var crawlspace = new ProcSpace(); direction = RIGHT; originX = room.TopRightX(); originY = room.TopRightY() + 1; x = 1; // get random height to make hallList either two or four tiles tall rand2 = Rand.Range(0, 10); int i = (rand2 == 0 ? 2 : 4); while (map.GetTileInfo(originX + x, originY) != null && TileInBounds(originX + x, originY)) { if (i == 2) { map.ClearTile(originX + x, originY); map.ClearTile(originX + x, originY - 1); } else { map.ClearTile(originX + x, originY); map.ClearTile(originX + x, originY - 1); map.ClearTile(originX + x, originY - 2); map.ClearTile(originX + x, originY - 3); } x = (direction == RIGHT ? x + 1 : x - 1); } // with hall succesfully placed, set its origin, width, and height, then add to List crawlspace.width = Math.Abs(x) - 1; crawlspace.height = i; crawlspace.originY = originY - (i - 1); crawlspace.originX = (direction == RIGHT ? originX + 1 : originX - crawlspace.width); crawlspaceList.Add(crawlspace); } } map.BulkEditEnd(); }
//******************* // previous iteration protected void CarveRandomRooms(int numberOfRooms) { for (int i = 0; i < numberOfRooms; i++) { var roomToDraw = new ProcSpace(); GetRoom(roomToDraw); PaintRoomRandomly(roomToDraw, 5); } }
protected bool WithinRoomBounds(ProcSpace room, int x, int y) { if ((x >= room.originX && x <= room.width) && (y >= room.originY && y <= room.height)) { return(true); } return(false); }
protected bool RoomInBounds(int originX, int originY, ProcSpace room) { if (originX + room.width < (mapColumns - mapMarginX) && originY + room.height < (mapRows - mapMarginY)) { return(true); } return(false); }
protected bool TouchingRooms(int originX, int originY, ProcSpace 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); }
protected void PaintRoomRandomly(ProcSpace room, int maxAttempts) { bool successful = false; int attempts = 0; map.BulkEditBegin(); while (!successful && attempts < maxAttempts) { // 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; roomList.Add(room); currentRoom = room; successful = true; } attempts++; } map.BulkEditEnd(); }
protected void GetRoom(ProcSpace room) { room.width = Rand.GaussianDivFour(8, 8, 2, 50); room.height = Rand.GaussianDivFour(4, 8, 8, 20); }
protected void CarveCrawlspaces() { map.BulkEditBegin(); int originX; int originY; int x; foreach (ProcSpace room in roomList) { int rand2 = Rand.Range(0, 1); if (rand2 == 0) { ProcSpace crawlspace = new ProcSpace(); direction = RIGHT; originX = room.TopRightX(); originY = room.TopRightY() + 1; x = 1; // get random height to make hallList either two or four tiles tall rand2 = Rand.Range(0, 10); int i = (rand2 == 0 ? 2 : 4); while (map.GetTileInfo(originX + x, originY) != null && TileInBounds(originX + x, originY)) { if (i == 2) { map.ClearTile(originX + x, originY); map.ClearTile(originX + x, originY - 1); } else { map.ClearTile(originX + x, originY); map.ClearTile(originX + x, originY - 1); map.ClearTile(originX + x, originY - 2); map.ClearTile(originX + x, originY - 3); } x = (direction == RIGHT ? x + 1 : x - 1); } // with hall succesfully placed, set its origin, width, and height, then add to List crawlspace.width = Math.Abs(x) - 1; crawlspace.height = i; crawlspace.originY = originY - (i - 1); crawlspace.originX = (direction == RIGHT ? originX + 1 : originX - crawlspace.width); crawlspaceList.Add(crawlspace); } } map.BulkEditEnd(); }
protected void CarveHalls() { map.BulkEditBegin(); int originX; int originY; int x; foreach (ProcSpace room in roomList) { ProcSpace hall = new ProcSpace(); // get random direction int rand = Rand.Range(0, 1); direction = (rand == 0 ? RIGHT : LEFT); // set origin point if (direction == RIGHT) { originX = room.BottomRightX(); originY = room.BottomRightY(); x = 1; } else { originX = room.BottomLeftX(); originY = room.BottomLeftY(); x = -1; } // get random height to make hallList either two or four tiles tall int rand2 = Rand.Range(0, 10); int i = (rand2 == 0 ? 2 : 4); while (map.GetTileInfo(originX + x, originY) != null && TileInBounds(originX + x, originY)) { if (i == 2) { map.ClearTile(originX + x, originY); map.ClearTile(originX + x, originY - 1); } else { map.ClearTile(originX + x, originY); map.ClearTile(originX + x, originY - 1); map.ClearTile(originX + x, originY - 2); map.ClearTile(originX + x, originY - 3); } x = (direction == RIGHT ? x + 1 : x - 1); } // with hall succesfully placed, set its origin, width, and height, then add to List hall.width = Math.Abs(x) - 1; hall.height = i; hall.originY = originY - (i - 1); hall.originX = (direction == RIGHT ? originX + 1 : originX - hall.width); hallList.Add(hall); } map.BulkEditEnd(); }
protected void CarveHalls() { map.BulkEditBegin(); int originX; int originY; int x; foreach (ProcSpace room in roomList) { var hall = new ProcSpace(); // get random direction int rand = Rand.Range(0, 1); direction = (rand == 0 ? RIGHT : LEFT); // set origin point if (direction == RIGHT) { originX = room.BottomRightX(); originY = room.BottomRightY(); x = 1; } else { originX = room.BottomLeftX(); originY = room.BottomLeftY(); x = -1; } // get random height to make hallList either two or four tiles tall int rand2 = Rand.Range(0, 10); int i = (rand2 == 0 ? 2 : 4); while (map.GetTileInfo(originX + x, originY) != null && TileInBounds(originX + x, originY)) { if (i == 2) { map.ClearTile(originX + x, originY); map.ClearTile(originX + x, originY - 1); } else { map.ClearTile(originX + x, originY); map.ClearTile(originX + x, originY - 1); map.ClearTile(originX + x, originY - 2); map.ClearTile(originX + x, originY - 3); } x = (direction == RIGHT ? x + 1 : x - 1); } // with hall succesfully placed, set its origin, width, and height, then add to List hall.width = Math.Abs(x) - 1; hall.height = i; hall.originY = originY - (i - 1); hall.originX = (direction == RIGHT ? originX + 1 : originX - hall.width); hallList.Add(hall); } map.BulkEditEnd(); }
protected bool WithinRoomBounds(ProcSpace room, int x, int y) { if ((x >= room.originX && x <= room.width) && (y >= room.originY && y <= room.height)) { return true; } return false; }
protected bool TouchingRooms(int originX, int originY, ProcSpace 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; }
protected bool RoomInBounds(int originX, int originY, ProcSpace room) { if (originX + room.width < (mapColumns - mapMarginX) && originY + room.height < (mapRows - mapMarginY)) { return true; } return false; }
//******************* // previous iteration protected void CarveRandomRooms(int numberOfRooms) { for (int i = 0; i < numberOfRooms; i++) { ProcSpace roomToDraw = new ProcSpace(); GetRoom(roomToDraw); PaintRoomRandomly(roomToDraw, 5); } }