Example #1
0
        public void CreateRooms(MessyBSPTreeMap map)
        {
            if (Child1 != null || Child2 != null)
            {
                // recursively search for children until you hit the end of the branch
                if (Child1 != null)
                {
                    Child1.CreateRooms(map);
                }
                if (Child2 != null)
                {
                    Child2.CreateRooms(map);
                }

                if (Child1 != null && Child2 != null)
                {
                    map.CreateHall(Child1.GetRoom().Value, Child2.GetRoom().Value);
                }
            }
            else
            {
                // Create rooms in the end branches of the bsp tree
                var w = Nez.Random.range(MessyBSPTreeMapGenerator.RoomMinSize, Math.Min(MessyBSPTreeMapGenerator.RoomMaxSize, Width - 1));
                var h = Nez.Random.range(MessyBSPTreeMapGenerator.RoomMinSize, Math.Min(MessyBSPTreeMapGenerator.RoomMaxSize, Height - 1));
                var x = Nez.Random.range(X, X + (Width - 1) - w);
                var y = Nez.Random.range(Y, Y + (Height - 1) - h);
                Room = new Rectangle(x, y, w, h);
                map.CreateRoom(Room.Value);
            }
        }
Example #2
0
        public MessyBSPTreeMap CreateMap(int w = 0, int h = 0)
        {
            _map = new MessyBSPTreeMap(w > 0 ? w : Width, h > 0 ? h : Height);
            Clear();

            _rootLeaf = new Leaf(0, 0, Width, Height);
            _leafs.Add(_rootLeaf);

            SplitLeafs();

            _rootLeaf.CreateRooms(_map);

            if (SmoothEdges)
            {
                CleanUpMap();
            }

            return(_map);
        }