place in rect

This commit is contained in:
Frank 2015-06-23 00:57:18 -04:00
parent 6bb83d5790
commit f623b143cc
1 changed files with 12 additions and 0 deletions

View File

@ -44,3 +44,15 @@ def get_range_steps(start, end, count):
def get_distance(p0, p1):
return sqrt((p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2)
def place_in_rect(rect, incoming, contain=True, *args):
while True:
incoming.center = randint(0, rect.w), randint(0, rect.h)
if not contain or rect.contains(incoming):
collides = False
for inner in args:
if inner.colliderect(incoming):
collides = True
break
if not collides:
break