Ejemplo n.º 1
0
        public void GenerateRooms(MT19337 rng)
        {
            // this function generates all the rooms and hallways for this BSPMapNode and all of its children.
            if (LeftChild == null && RightChild == null)
            {
                if (WalkableSpace != null)
                {
                    return;
                }

                // the room can be between 3 x 3 tiles to the size of the leaf - 2.
                var roomWidth  = rng.Between(BSPTreeEngine.MIN_ROOM_WIDTH, Width - 2);
                var roomHeight = rng.Between(BSPTreeEngine.MIN_ROOM_HEIGHT, Height - 2);

                // place the room within the BSPMapNode, but don't put it right
                // against the side of the BSPMapNode (that would merge rooms together)
                var roomStartX = rng.Between(1, Width - roomWidth - 1);
                var roomStartY = rng.Between(1, Height - roomHeight - 1);
                WalkableSpace = new Rectangle(X + roomStartX, Y + roomStartY, roomWidth, roomHeight);
                return;
            }

            // subleafs:
            LeftChild?.GenerateRooms(rng);
            RightChild?.GenerateRooms(rng);

            // both leafs exist. we know their GetRandomRoom shouldn't return null, because we just called GenerateRooms.
            if (LeftChild != null && RightChild != null)
            {
                MakeHallway(rng, (Rectangle)LeftChild.GetRandomRoom(rng), (Rectangle)RightChild.GetRandomRoom(rng));
            }
        }
Ejemplo n.º 2
0
        private Point PointInAnyRandomRoom(MT19337 rng)
        {
            var some_room = (Rectangle)root.GetRandomRoom(rng);

            return(new Point(some_room.X + rng.Between(1, some_room.Width - 1), some_room.Y + rng.Between(1, some_room.Height - 1)));
        }