def handle_collision(self, collision_list, group):
"""Given a list of sprites that collide with the sprite, alter state such as position, velocity, etc"""
# If there's only 1 block, then we're over an edge, so do nothing in that case
# and just let the sprite fall, otherwise, clamp to the top of the block
if collision_list:
if len(collision_list) > 1:
self.falling = False
self.falling_frames = 1
self.dy = 0
self.rect.bottom = collision_list[0].rect.top
elif len(collision_list) == 1:
if self.facing_left and self.rect.right > collision_list[0].rect.left:
self.falling = False
self.falling_frames = 1
self.dy = 0
self.rect.bottom = collision_list[0].rect.top
elif not self.facing_left and self.rect.left < collision_list[0].rect.right:
self.falling = False
self.falling_frames = 1
self.dy = 0
self.rect.bottom = collision_list[0].rect.top
评论列表
文章目录