예제 #1
0
        public void CreateRooms()
        {
            // this function generates all the rooms and hallways for this cell and all of its children.
            if (LeftChild != null || RightChild != null)
            {
                // this cell has been split, so go into the children cells
                if (LeftChild != null)
                {
                    LeftChild.CreateRooms();
                }
                if (RightChild != null)
                {
                    RightChild.CreateRooms();
                }

                // Check if there's rooms on both sides, and connect those specific rooms
                var room1 = LeftChild.GetRoom();
                var room2 = RightChild.GetRoom();
                if (room1 != null && room2 != null && this.halls.Count == 0)
                {
                    this.ConnectRooms(room1.Value, room2.Value);
                }
            }
            else
            {
                // this cell needs a room
                Point roomSize;
                Point roomPos;
                // the room can be between 3 x 3 up to the size of the cell - 2.
                roomSize = new Point(rand.Next(3, Width - 2), rand.Next(3, Height - 2));

                roomPos = new Point(rand.Next(1, Width - roomSize.X - 1), rand.Next(1, Height - roomSize.Y - 1));
                Room    = new Rectangle(X + roomPos.X, Y + roomPos.Y, roomSize.X, roomSize.Y);
            }
        }
예제 #2
0
    public void CreateRooms()
    {
        if (LeftChild != null || RightChild != null)
        {
            if (LeftChild != null)
            {
                LeftChild.CreateRooms();
            }

            if (RightChild != null)
            {
                RightChild.CreateRooms();
            }

            if (LeftChild != null && RightChild != null)
            {
                CreateHall(LeftChild.GetRoom(), RightChild.GetRoom());
            }
        }

        else
        {
            Point roomSize;
            Point roomPos;

            roomSize = new Point(Random.Range(3, Width - 2), Random.Range(3, Height - 2));
            roomPos  = new Point(Random.Range(1, Width - roomSize.X - 1), Random.Range(1, Height - roomSize.Y - 1));
            Room     = new Rect(Position.X + roomPos.X, Position.Y + roomPos.Y, roomSize.X, roomSize.Y);
        }
    }
예제 #3
0
            /// <summary>
            /// Generates all rooms and hallways for this Leaf and all its children.
            /// </summary>
            public void CreateRooms(int minRoomSize, bool tightFill)
            {
                if (LeftChild != null || RightChild != null)
                {
                    if (LeftChild != null)
                    {
                        LeftChild.CreateRooms(minRoomSize, tightFill);
                    }
                    if (RightChild != null)
                    {
                        RightChild.CreateRooms(minRoomSize, tightFill);
                    }

                    if (LeftChild != null && RightChild != null)
                    {
                        CreateHall(LeftChild.GetRoom(), RightChild.GetRoom());
                    }
                }
                else
                {
                    Vector2Int roomSize;
                    Vector2Int roomPos;

                    if (tightFill)
                    {
                        roomSize = new Vector2Int(Width - 1, Height - 1);
                    }
                    else
                    {
                        roomSize = new Vector2Int(
                            RangeInclusive(minRoomSize, Width - 2),
                            RangeInclusive(minRoomSize, Height - 2));
                    }

                    roomPos = new Vector2Int(
                        RangeInclusive(1, Width - roomSize.x - 1),
                        RangeInclusive(1, Height - roomSize.y - 1));
                    Room = new LevelRect(
                        new Vector2Int(X + roomPos.x, Y + roomPos.y),
                        new Vector2Int(roomSize.x, roomSize.y));
                }
            }