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
def on_key_press(self, key, modifiers): """ Called whenever a key is pressed. """ if key == arcade.key.UP: self.ship.change_y += 5 elif key == arcade.key.DOWN: self.ship.change_y -= 5 elif key == arcade.key.LEFT: self.ship.change_x -= 5 elif key == arcade.key.RIGHT: self.ship.change_x += 5 elif key == arcade.key.SPACE: particule = Sprite("../ressources/Life_Orb.png", center_x=self.ship.right, center_y=self.ship.center_y) particule.change_x = 3 self.particule_list.append(particule)