def dash( sprite: arcade.Sprite, dir_x: int, dir_y: int, collide_with: arcade.SpriteList, ) -> None: """Move sprite until it reaches something.""" sprite.bottom += 1 prev_x = sprite.left prev_y = sprite.bottom default_x = sprite.left default_y = sprite.bottom for x, y in zip_longest( range(floor(sprite.left), floor(sprite.left + dir_x), weird_sign(dir_x)), range(floor(sprite.bottom), floor(sprite.bottom + dir_y), weird_sign(dir_y)), ): sprite.left = x if x else prev_x sprite.bottom = y if y else prev_y if sprite.collides_with_list(collide_with): sprite.left = prev_x sprite.bottom = prev_y break if x: prev_x = x if y: prev_y = y
def _move_sprite(moving_sprite: arcade.Sprite, platforms: arcade.SpriteList, dt): if moving_sprite.bottom <= 0 and moving_sprite.change_y < 0: moving_sprite.change_y = 0 moving_sprite.bottom = 0 moving_sprite.center_y += moving_sprite.change_y * moving_sprite.speed_multiplier * ( dt / (1 / 60)) hit_list_y = arcade.check_for_collision_with_list(moving_sprite, platforms) for platform in hit_list_y: if platform.color != moving_sprite.current_background: if moving_sprite.change_y > 0: if not platform.change_y: moving_sprite.top = platform.bottom moving_sprite.change_y = 0 elif moving_sprite.change_y < 0: moving_sprite.bottom = platform.top if platform.change_y: if platform.change_y < 0: moving_sprite.center_y -= 2 moving_sprite.change_y = -3 else: moving_sprite.change_y = 0 else: moving_sprite.change_y = 0 if platform.change_x: moving_sprite.momentum = platform.change_x moving_sprite.center_x += (moving_sprite.change_x + moving_sprite.momentum ) * moving_sprite.speed_multiplier * (dt / (1 / 60)) hit_list_x = arcade.check_for_collision_with_list(moving_sprite, platforms) for platform in hit_list_x: if platform.color != moving_sprite.current_background and platform not in hit_list_y: if moving_sprite.change_x > 0 and not platform.change_x: moving_sprite.right = platform.left elif moving_sprite.change_x < 0 and not platform.change_x: moving_sprite.left = platform.right if platform.change_y: if platform.change_y >= 0: moving_sprite.change_x = 0 else: moving_sprite.change_x = 0 if len(hit_list_y) <= 0 and moving_sprite.momentum != 0: moving_sprite.change_x += moving_sprite.momentum moving_sprite.momentum = 0