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
In my case I had a similar problem except that I had some pre-exiting rectangles inside the overall rectangle. So new rectangles had to be placed around those existing ones.
I used a greedy approach:
This requires a conversion from your original coordinate space to/from the grid space but straightforward to do.
(Note that running Kadene directly on the original, global rectangle takes to long. Going via a grid approximation is plenty fast for my application)