From 84a6e58ba3ad6a92212312a6f082237f5468088b Mon Sep 17 00:00:00 2001 From: Patrick Tschuchnig Date: Wed, 11 Sep 2019 12:02:41 +0200 Subject: [PATCH] fixed a bug where starting the game while displaying the end screen was allowed, causing an undefined state in the engine and softlocking the player. now causing an inhibit state to block the start pin and also only allow checking for the game start if the game is not currently ending --- gametest_rev1.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gametest_rev1.py b/gametest_rev1.py index 103dab6..eb799ac 100644 --- a/gametest_rev1.py +++ b/gametest_rev1.py @@ -311,11 +311,14 @@ def enter_name(): if event.type == KEYDOWN: if event.key == pygame.K_BACKSPACE: name = name[:-1] - elif event.key == pygame.K_RETURN: - # do nothing elif event.key == pygame.K_RETURN and len(name) > 0: clear_screen() return name + elif event.key == pygame.K_RETURN: + # do nothing + pass + elif event.key == pygame.K_ESCAPE: + exit_application() else: name += event.unicode elif event.key == pygame.K_BACKSPACE: @@ -466,7 +469,7 @@ while True: pygame.display.flip() - if GPIO.input(pin_start) == True and pin_start_inhibit == False and game_running == False: #wait for the user to press start button + if GPIO.input(pin_start) == True and pin_start_inhibit == False and game_running == False and game_ending != True: #wait for the user to press start button print("start pin has been detected, starting game") game_running = True @@ -522,6 +525,7 @@ while True: pygame.display.flip() # if the start input is gone and the start pin isnt inhibited + if game_running == True and GPIO.input(pin_start) == True and pin_start_inhibit == False and game_ending != True: print("Game ended because start pin was detected again") @@ -531,13 +535,17 @@ while True: timer_game_ending_started = False game_ending = True game_running = False + pin_start_inhibit = True if game_running == False and game_ending == True: print("game is ending") + + # check highscores only once when game ended if highscore_checked == False: check_highscores(int_time) highscore_checked = True + # timer for ending the game after 5 seconds if timer_game_ending_started == False: timer_game_ending_timout = pygame.time.get_ticks() timer_game_ending_started = True @@ -560,6 +568,7 @@ while True: game_ending = False highscore_checked = False timer_game_ending_started = False + pin_start_inhibit = False pygame.display.update() pygame_clock.tick(pygame_fps)