(Problem described on reddit[1])
You have drawn a room rectangle and place walls around the outside.
Then you draw another room and want walls around the outside. But what happens if the rooms overlap? We want to figure out where the walls should be. Some walls are erased where the rooms meet. First, the demo: drag the mouse to draw a room.
Algorithm:
- Keep track of what’s a building and what’s outdoor.
- If a tile is outdoor, draw grass.
- If a tile is building and one of its neighbors is outdoor, draw a wall.
- If a tile is building and all of its neighbors are building, draw floor.
Note that in this demo, I place the walls on building tiles. You could also design it to place the walls outside the buildings. In that case, the algorithm becomes:
- Keep track of what’s a building and what’s outdoor.
- If a tile is building, draw floor.
- If a tile is outdoor and one of its neighbors is building, draw a wall.
- If a tile is outdoor and all of its neighbors are outdoor, draw grass.
(Untested)