You can do that by setting spacing to zero, and removing all path objects that have a width greater than the room sizes
If you’d like to have all rooms be connected, you can try using a different randomizing method in order to achieve this.
2nd randomizing method
For example, this map here:
Has an array of:
[
1,0,1,1,0,
0,1,0,0,1,
0,1,1,0,0,
1,1,0,0,1,
1,0,1,1,0
]
Which is set through this code:
for(var i=0;i<rooms.maxRows*rooms.maxCols;i++){
rooms.arr.push(random.choice([0,1]));
}
This is setting every value inside the array to a random number- but what if you were to set the entire array equal to an empty string, have one point be set to 1, then have the points around this 1 be set to either 0 or 1 randomly, and repeat the same step for all the 1’s until all the 1’s are surrounded by 0’s or reach the ends. That way, you won’t have any squares like these ones:
To demonstrate, let’s say this 1 here is the first part of the array:
"","","","","",
"","","","","",
"","",1,"","",
"","","","","",
"","","","",""
The points with a “_” are the ones that will be randomized next, with either a 0 or 1
"","","","","",
"","",_ ,"","",
"", _,1 ,_ ,"",
"","",_ ,"","",
"","","","",""
Let’s say you got this:
"","","","","",
"","",0 ,"","",
"", 0,1 ,1 ,"",
"","",1 ,"","",
"","","","",""
Then the blank points around the 1’s will be checked next, which are marked here again with a _:
"","","","","",
"","",0 ,_ ,"",
"", 0,1 ,1 ,_ ,
"", _,1 ,_ ,"",
"","",_ ,"",""
Next, something like this:
"","","","","",
"","",0 ,1 ,"",
"", 0,1 ,1 ,1 ,
"", 1,1 ,0 ,"",
"","",0 ,"",""
Then:
"","","",0 ,"",
"","",0 ,1 ,0 ,
"", 0,1 ,1 ,1 ,
1 , 1,1 ,0 ,0 ,
"", 0,0 ,"",""
And lastly, here’s how it’d end:
"","","",0 ,"",
"","",0 ,1 ,0 ,
0 , 0,1 ,1 ,1 ,
1 , 1,1 ,0 ,0 ,
0 , 0,0 ,"",""
All the squares are connected, this is completely random, and you won’t generate a map that has disconnected rooms like this:
(Fun fact: I wrote this entire explanation before actually trying to code it, but now I’ll try to implement this idea into my code to make sure it works)