def apply_physics(self, tile_map):
"""Gravity in this case"""
# The dy should be controlled by 'gravity' only for now - jumps will impart an
# Initial up velocity (done in the keyhandler), then gravity acts here on update.
# Without some sort of gravity approximation, sprites would move at the same speed
# while in the air and seem very light, like they're walking on the moon in low gravity
# only worse. Not a problem for a top-down 2D game :)
# If not on the ground floor, just assume we're falling (for now this will be true)
if self.rect.bottom < tile_map.player_bounds_rect.bottom and self.falling == False:
self.falling = True
self.falling_frames = 1
if self.falling:
# As long as the sprite is continually falling, the 'speed' increases each
# frame by the acceleration until some terminal speed
if self.dy < self.settings.terminal_velocity:
self.dy += self.settings.gravity
self.rect.centery += self.dy
self.falling_frames += 1
评论列表
文章目录