Exemplo n.º 1
0
    void GenCorridors(BinaryNode node)
    {
        if (node.IsLeaf())
        {
            return;
        }

        if (!node.Children[0].IsLeaf())
        {
            GenCorridors(node.Children[0]);
        }
        if (!node.Children[1].IsLeaf())
        {
            GenCorridors(node.Children[1]);
        }

        BinaryNode leaf1 = node.Children[0];
        BinaryNode leaf2 = node.Children[1];

        var rooms1 = new List <Room>();
        var rooms2 = new List <Room>();

        leaf1.FillRoomsRecursively(rooms1);
        leaf2.FillRoomsRecursively(rooms2);

        Room[] roomsToConnect = FindRoomPairToConnect(rooms1, rooms2);
        Room   room1          = roomsToConnect[0];
        Room   room2          = roomsToConnect[1];

        //make a corridor
        if (leaf1.GlobalPos.Y == leaf2.GlobalPos.Y)
        {
            this.corridors.Add(DigCorridorRightTo(room1, room2));
        }
        else
        {
            this.corridors.Add(DigCorridorUpTo(room1, room2));
        }
    }