From b8abacd4cc6502514453e235f66fea34ec8d9824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 26 Apr 2020 14:13:27 +0200 Subject: [PATCH] Add picking random target for A* algorithm When user clicks "u" key target is being picked. --- src/game/EventManager.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 08c8a59..1ec7c4d 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -91,8 +91,13 @@ class EventManager: if keys[pygame.K_d]: self.player.move(Movement.ROTATE_R) + # Pick random target for A* algorithm if keys[pygame.K_u]: - self.game.movement.gotoToTarget(self.game.map.entities[Random().randint(0, len(self.game.map.entities))]) - + while True: + try: + self.game.movement.gotoToTarget(self.game.map.entities[Random().randint(0, len(self.game.map.entities))]) + break + except Exception: + pass