BSP(int x, int y, int w, int h, BSP father) { this.x = x; this.y = y; width = w; height = h; leaf = true; level = (byte)(father.level + 1); this.father = father; }
private void GenRoom(BSP bsp) { if (bsp.Leaf) { int x = bsp.X+1; int y = bsp.Y+1; int w = bsp.Width-2; int h = bsp.Height-2; for (int i = x; i < x + w; i++) for (int j = y; j < y + h; j++) { tiles[i, j] = true; } } else { GenRoom(bsp.Left); GenRoom(bsp.Right); } }
public Dungeon(int seed) { rand = new Random(seed); rooms = new BSP(0, 0, WIDTH, HEIGHT); tiles = new bool[WIDTH, HEIGHT]; }
/// <summary> /// Once you have the root node, you can split it into two smaller non-overlapping nodes. /// </summary> /// <param name="horizontal">If true, the node will be splitted horizontally, else, vertically.</param> /// <param name="position">Coordinate of the splitting position.</param> public void SplitOnce(bool horizontal, int position) { if (horizontal) { ls = new BSP(x, y, position - x, height, this); rs = new BSP(position, y, width + x - position, height, this); } else { ls = new BSP(x, y, width, position - y, this); rs = new BSP(x, position, width, height + y - position, this); } leaf = false; this.horizontal = horizontal; this.position = position; }