public string PrintBSP(Grid2DInt map) { foreach (var r in rooms) { Grid2DPaint.Rect <int>(map, r, 0); } return(map.Print()); }
public static void Division(Grid2DInt map, RectInt rect, int minSideSize = 12, int maxSideSize = 24) { if (rect.width <= maxSideSize && rect.height <= maxSideSize) { if (Random.value < 0.5f) { Grid2DPaint.Rect(map, RandomSubRect(rect), 0); return; } } if (rect.width <= minSideSize && rect.height <= minSideSize) { Grid2DPaint.Rect(map, RandomSubRect(rect), 0); return; } bool isVer = Random.value > .5f; isVer = (float)rect.width / (float)rect.height > 1.25f; int posX = Random.Range(rect.width / 4, rect.width * 3 / 4) + rect.x; int posY = Random.Range(rect.height / 4, rect.height * 3 / 4) + rect.y; if (isVer) { //map.SetBlock(posX, rect.Y, 1, rect.H, 0); Division(map, new RectInt(rect.x, rect.x, posX - rect.x, rect.height)); Division(map, new RectInt(posX + 1, rect.y, rect.x + rect.width - posX - 1, rect.height)); } else { //map.SetBlock(rect.X, posY, rect.W, 1, 0); Division(map, new RectInt(rect.x, rect.y, rect.width, posY - rect.y)); Division(map, new RectInt(rect.x, posY + 1, rect.width, rect.height - posY + rect.y - 1)); } }