place in rect
This commit is contained in:
parent
6bb83d5790
commit
f623b143cc
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue