def basic_bounds_containment(self, tile_map):
"""Contains the sprite to the player bounds"""
# Bounds check on bottom edge
if self.rect.bottom > tile_map.player_bounds_rect.bottom:
self.rect.bottom = tile_map.player_bounds_rect.bottom
self.dy = 0.0
self.falling = False
# Left/Right bounds containment check
# RIGHT
if self.dx > 0:
self.rect.centerx += self.dx
if self.rect.right - self.margin_right > tile_map.player_bounds_rect.right:
self.rect.right = tile_map.player_bounds_rect.right + self.margin_right
self.dx = 0.0
if self.dx < 0:
self.rect.centerx += self.dx
if self.rect.left + self.margin_left < tile_map.player_bounds_rect.left:
self.rect.left = tile_map.player_bounds_rect.left - self.margin_left
self.dx = 0.0
评论列表
文章目录