本文整理汇总了Python中pygame.Rect.collidelistall方法的典型用法代码示例。如果您正苦于以下问题:Python Rect.collidelistall方法的具体用法?Python Rect.collidelistall怎么用?Python Rect.collidelistall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.Rect
的用法示例。
在下文中一共展示了Rect.collidelistall方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: grow_rect
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import collidelistall [as 别名]
def grow_rect(self, rect, growth, rects, direction):
"""Tries to grow a rectangle in the specified direction
Returns whether the growth succeeded"""
changed = False
if growth[direction]:
left, top, width, height = rect.x, rect.y, rect.w, rect.h
if direction == LEFT:
left -= 1
width += 1
elif direction == RIGHT:
width += 1
elif direction == DOWN:
height += 1
elif direction == UP:
top -= 1
height += 1
new = Rect(left, top, width, height)
if not (set(util.points_in(new)) - self.space) and len(new.collidelistall(rects)) == 1:
rect.left = left
rect.width = width
rect.top = top
rect.height = height
changed = True
#if rect.width >= 8 and rect.height >= 8 and random.randrange(5) == 0:
# growth[direction] = False
else:
growth[direction] = False
return changed
示例2: grow_rect
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import collidelistall [as 别名]
def grow_rect(self, i, rect, growth, adjacency, rects, direction):
"""Tries to grow a rectangle in the specified direction
Returns whether the growth succeeded"""
if rect.w > 100 or rect.h > 100:
growth[direction] = False
return False
if growth[direction]:
left, top, width, height = rect.x, rect.y, rect.w, rect.h
if direction == LEFT:
left -= 1
width += 1
if height > 1:
collision = Rect(rect.x, rect.y+1, 1, rect.h-2)
else:
collision = Rect(rect.x, rect.y, 1, 1)
elif direction == RIGHT:
width += 1
if height > 1:
collision = Rect(rect.right-1, rect.y+1, 1, rect.h-2)
else:
collision = Rect(rect.right-1, rect.y, 1, 1)
elif direction == DOWN:
height += 1
if width > 1:
collision = Rect(rect.x+1, rect.bottom-1, rect.w-2, 1)
else:
collision = Rect(rect.x, rect.bottom-1, 1, 1)
elif direction == UP:
top -= 1
height += 1
if width > 1:
collision = Rect(rect.x+1, rect.y, rect.w-2, 1)
else:
collision = Rect(rect.x, rect.y, 1, 1)
building_collisions = collision.collidelistall(rects)
try:
building_collisions.remove(i)
except ValueError:
pass
if not (set(Generator.get_rect(collision)) - self.space) and len(building_collisions) == 0:
rect.left = left
rect.width = width
rect.top = top
rect.height = height
#if rect.width >= 8 and rect.height >= 8 and random.randrange(5) == 0:
# growth[direction] = False
return True
else:
growth[direction] = False
if building_collisions:
care_about = [j for j in building_collisions if j < len(self.points)]
# If we collided with a building, make a note.
adjacency[i] += care_about
for j in care_about:
adjacency[j].append(i)
return False
示例3: test_collidelistall
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import collidelistall [as 别名]
def test_collidelistall(self):
# __doc__ (as of 2008-08-02) for pygame.rect.Rect.collidelistall:
# Rect.collidelistall(list): return indices
# test if all rectangles in a list intersect
#
# Returns a list of all the indices that contain rectangles that
# collide with the Rect. If no intersecting rectangles are found, an
# empty list is returned.
r = Rect(1, 1, 10, 10)
l = [Rect(1, 1, 10, 10), Rect(5, 5, 10, 10), Rect(15, 15, 1, 1), Rect(2, 2, 1, 1)]
self.assertEqual(r.collidelistall(l), [0, 1, 3])
f = [Rect(50, 50, 1, 1), Rect(20, 20, 5, 5)]
self.assertFalse(r.collidelistall(f))
示例4: grow_room
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import collidelistall [as 别名]
def grow_room(self, room, growing, max_size, pad_v=0, pad_h=0, space=None):
"""Tries to grow a room in the specified direction
Returns whether the growth succeeded"""
space = space if space is not None else self.interior_space
for d, grow in enumerate(growing):
if not grow:
continue
if (((d == LEFT or d == RIGHT) and room.w > max_size) or
((d == UP or d == DOWN) and room.h > max_size)):
growing[d] = False
continue
left, top, width, height = room.x, room.y, room.w, room.h
if d == LEFT:
left -= 1
width += 1
if room.w <= 1:
collision = None
else:
collision = Rect(room.x - pad_h, room.y + 1 - pad_v,
1 + pad_h, max(1, room.h + 2 * pad_v - 2))
elif d == RIGHT:
width += 1
if room.w <= 1:
collision = None
else:
collision = Rect(room.right - 1 - pad_h, room.y + 1,
1 + pad_h, max(1, room.h + 2 * pad_v - 2))
elif d == DOWN:
height += 1
if room.h <= 1:
collision = None
else:
collision = Rect(room.x + 1 - pad_h, room.bottom - 1,
max(1, room.w - 2 + 2 * pad_h), 1 + pad_v)
elif d == UP:
top -= 1
height += 1
if room.h <= 1:
collision = None
else:
collision = Rect(room.x + 1 - pad_h, room.y - pad_v,
max(1, room.w - 2 + 2 * pad_h), 1 + pad_v)
if collision is not None:
building_collisions = collision.collidelistall([r.rect for r in self.shapes if isinstance(r, Room)])
else:
building_collisions = []
if not (set(Generator.get_rect(collision)) - space) and len(building_collisions) == 0:
room.left = left
room.width = width
room.top = top
room.height = height
else:
print room.rect, collision, d, building_collisions, (set(Generator.get_rect(collision)) - space)
growing[d] = False