diff --git a/src/scenes/game.py b/src/scenes/game.py index 77e16a2..5b97ae0 100644 --- a/src/scenes/game.py +++ b/src/scenes/game.py @@ -528,10 +528,15 @@ def _update_bot(world: World): Fonction qui update les mouvement du bot """ # On récupère la balle la plus proche du bot - ball_query = world.query(Position, Velocity, CollisionHandler) - if ball_query == set(): + balls = world.query(Position, Velocity, CollisionHandler) + if balls == set(): return None - ball = max(ball_query, key=lambda entity: entity[Position].y) + right_balls = [ball for ball in balls if ball[Velocity].x > 0] + left_balls = [ball for ball in balls if ball[Velocity].x < 0] + if len(right_balls) != 0: + ball = max(right_balls, key=lambda entity: entity[Position].x) + else: + ball = min(left_balls, key=lambda entity: entity[Position].x) # On récupère le bot et le joueur bot = world.query(Player2).pop()