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
Did you try:
Until there are enough objects:
create new object
if it doesn't collide with anything in the list:
add it to the list
No sense recreating the entire list, or taking out everything that's involved in a collision.
Another idea is to "fix" collisions by either of the following approaches:
1) Find the center of the region of intersection, and adjust the appropriate corner of each intersecting rect to that point, such that they now touch on corner/edge instead of intersecting.
2) When a rectangle collides with something, randomly generate a sub-region of that rectangle and try that instead.