I\'m working on some 2D games with Pygame. I need to place several objects at the same time randomly without them intersecting. I have tried a few obvious
an alternative pseudocode, to those already mentioned:
while not enough objects:
place object randomly
if overlaps with anything else:
reduce size until it fits or has zero size
if zero size:
remove
Or something like that.
But this has the advantage of possibly creating some smaller objects than you intended, and creating objects which almost intersect (i.e. touch).
If it's a map for the player to traverse, they may still not be able to traverse it because their path could be blocked.