private Rect GetRoomLeft() { if (IAmLeaf()) { return(_room); } Rect lRoom = _left.GetRoomLeft(); return(lRoom); }
// 복도 공간을 만드는 함수 private void CreateCorrider(SubDungeon left, SubDungeon right) { Rect lRoom = left.GetRoomRight(); Rect rRoom = right.GetRoomLeft(); Vector2 lPoint = new Vector2((int)lRoom.x + ((int)lRoom.width / 2), (int)lRoom.y + ((int)lRoom.height / 2)); Vector2 rPoint = new Vector2((int)rRoom.x + ((int)rRoom.width / 2), (int)rRoom.y + ((int)rRoom.height / 2)); int w = (int)lPoint.x - (int)rPoint.x; int h = (int)lPoint.y - (int)rPoint.y; int centerPosH = (int)((lPoint.y + rPoint.y) / 2 - 1); int centerPosW = (int)((lPoint.x + rPoint.x) / 2 - 1); bool state = false; if ((rPoint.x - lPoint.x) < 0) { state = true; } if (state) { centerPosH = (int)(right._rect.height + right._rect.y - 1); } else { centerPosW = (int)(left._rect.width + left._rect.x - 1); } if (Mathf.Abs(h) <= rRoom.height / 2 - 1) { corridors.Add(new Rect(lPoint.x, lPoint.y, Mathf.Abs(w), 1)); } else if (Mathf.Abs(w) <= lRoom.width / 2 - 1) { corridors.Add(new Rect(rPoint.x, rPoint.y, 1, Mathf.Abs(h))); } else if (rPoint.x - lPoint.x > 0 && rPoint.y - lPoint.y < 0) { if (lRoom.xMax - 1 > rRoom.x) { corridors.Add(new Rect(rRoom.x + 1, rRoom.y, 1, Mathf.Abs(h))); } else { Vector2 hPos; hPos = new Vector2((int)(rPoint.x + lPoint.x) / 2, rPoint.y); int rW = (int)(hPos.x - rPoint.x); int lW = (int)(lRoom.xMax - hPos.x); corridors.Add(new Rect(hPos.x, hPos.y, 1, Mathf.Abs(h) + 1)); corridors.Add(new Rect(hPos.x, rPoint.y, Mathf.Abs(rW), 1)); corridors.Add(new Rect(lRoom.xMax, lPoint.y, Mathf.Abs(lW), 1)); } } else { Vector2 corYPos; Vector2 corXPos; // startPoint = rPoint; corYPos = state ? rPoint : new Vector2(centerPosW, centerPosH); corXPos = state ? new Vector2(rPoint.x, centerPosH) : new Vector2(centerPosW, rPoint.y); AddCorridors(corXPos, corYPos, rPoint, centerPosW, centerPosH); // startPoint = lPoint; corYPos = state ? new Vector2(lPoint.x, centerPosH) : new Vector2(centerPosW, lPoint.y); corXPos = state ? new Vector2(centerPosW, centerPosH) : lPoint; AddCorridors(corXPos, corYPos, lPoint, centerPosW, centerPosH); } }