public void split(int[][] dungeon) { // try to favor one way if ratio is way out of whack if (Rect.Width / Rect.Height > max_partition_ratio) { split_dir = "vert"; } else if (Rect.Height / Rect.Width > max_partition_ratio) { split_dir = "horiz"; } else split_dir = (Meta.random.Next(2) == 1) ? "vert" : "horiz"; // split the node if (split_dir == "vert") { // get split position splitPos = Rect.Left + (int)(HomogenizedRandomValue() * Rect.Width); // create kiddos leftChild = new Node(Rect.Left, Rect.Top, splitPos - Rect.Left, Rect.Height); rightChild = new Node(splitPos + 1, Rect.Top, Rect.Left + Rect.Width - splitPos - 1, Rect.Height); // if not too small, split if (leftChild.shouldSplit(leftChild.Rect.Width)) leftChild.split(dungeon); if (rightChild.shouldSplit(rightChild.Rect.Width)) rightChild.split(dungeon); } else // horiz split { splitPos = Rect.Top + (int)(HomogenizedRandomValue() * Rect.Height); leftChild = new Node(Rect.Left, Rect.Top, Rect.Width, splitPos - Rect.Top); rightChild = new Node(Rect.Left, splitPos + 1, Rect.Width, Rect.Top + Rect.Height - splitPos - 1); if (leftChild.shouldSplit(leftChild.Rect.Height)) leftChild.split(dungeon); if (rightChild.shouldSplit(rightChild.Rect.Height)) rightChild.split(dungeon); } }
public int[][] createDungeon() { torchList = new List<Entity>(); roomList = new List<Rectangle>(); manager = new EntityManager(); // initialize size of dungeon array and sets everything to unvisited (0) floor = new int[dwidth][]; for (int a = 0; a < floor.Length; a++) { floor[a] = new int[dheight]; } for (int x = 0; x < floor.Length; x++) { for (int y = 0; y < floor[x].Length; y++) { floor[x][y] = 0; } } // start with single node then recursively split into areas until done Node wholeDungeon = new Node(1, 1, dwidth - 2, dheight - 2); wholeDungeon.split(floor); // now add rooms roomList = wholeDungeon.addRooms(floor); // now connect the rooms wholeDungeon.connectRooms(floor); // now draw walls paintWalls(); // now add doors addDoors(); // now add torches addTorches(); // now add stairs up and down addStairs(); // add mobs addMobs(); return floor; }