本文整理汇总了Python中pygame.rect.Rect.contains方法的典型用法代码示例。如果您正苦于以下问题:Python Rect.contains方法的具体用法?Python Rect.contains怎么用?Python Rect.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.rect.Rect
的用法示例。
在下文中一共展示了Rect.contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: collision_check
# 需要导入模块: from pygame.rect import Rect [as 别名]
# 或者: from pygame.rect.Rect import contains [as 别名]
def collision_check(self):
""" Destroy the rocket if it comes outside of the borders. Also make sure a rocket that collides with a tile
destroys the tile.
"""
entity_rect = Rect(self.x, self.y, self.width, self.height)
window_rect = Rect(0, 0, g.width * c.TILE_SIZE, g.height * c.TILE_SIZE)
if not window_rect.contains(entity_rect):
self.delete = True
# Make sure collision rectangles are up to date
self.update_collision_rects()
# Get the tile the entity is standing on
tile_pos = self.get_tile()
checked_tile_rects = []
checked_tiles = []
# Loop through a 3x3 tile square around the entity, to not check the entire map
for i in (range(tile_pos[0]-1, tile_pos[0]+2) if self.dir[0] == 0 else [tile_pos[0] + self.dir[0]]):
for j in (range(tile_pos[1]-1, tile_pos[1]+2) if self.dir[1] == 0 else [tile_pos[1] + self.dir[1]]):
try:
if c.IMAGES[g.map[i][j].type].collides:
checked_tiles.append((i, j))
checked_tile_rects.append(g.map[i][j].rect())
except IndexError: # That index was apparently outside of the map
pass
# Find the tile that collides
index = self.rects[(-self.dir[0], -self.dir[1])].collidelist(checked_tile_rects)
if index != -1:
# Replace that tile.
g.tile_maker_queue.insert(0, [self.tile,
checked_tiles[index][0],
checked_tiles[index][1]])
self.delete = True
return super(LauncherRocket, self).collision_check