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
This commit is contained in:
parent
60f0545878
commit
84a6e58ba3
@ -311,11 +311,14 @@ def enter_name():
|
|||||||
if event.type == KEYDOWN:
|
if event.type == KEYDOWN:
|
||||||
if event.key == pygame.K_BACKSPACE:
|
if event.key == pygame.K_BACKSPACE:
|
||||||
name = name[:-1]
|
name = name[:-1]
|
||||||
elif event.key == pygame.K_RETURN:
|
|
||||||
# do nothing
|
|
||||||
elif event.key == pygame.K_RETURN and len(name) > 0:
|
elif event.key == pygame.K_RETURN and len(name) > 0:
|
||||||
clear_screen()
|
clear_screen()
|
||||||
return name
|
return name
|
||||||
|
elif event.key == pygame.K_RETURN:
|
||||||
|
# do nothing
|
||||||
|
pass
|
||||||
|
elif event.key == pygame.K_ESCAPE:
|
||||||
|
exit_application()
|
||||||
else:
|
else:
|
||||||
name += event.unicode
|
name += event.unicode
|
||||||
elif event.key == pygame.K_BACKSPACE:
|
elif event.key == pygame.K_BACKSPACE:
|
||||||
@ -466,7 +469,7 @@ while True:
|
|||||||
|
|
||||||
pygame.display.flip()
|
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")
|
print("start pin has been detected, starting game")
|
||||||
game_running = True
|
game_running = True
|
||||||
|
|
||||||
@ -522,6 +525,7 @@ while True:
|
|||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
# if the start input is gone and the start pin isnt inhibited
|
# 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:
|
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")
|
print("Game ended because start pin was detected again")
|
||||||
|
|
||||||
@ -531,13 +535,17 @@ while True:
|
|||||||
timer_game_ending_started = False
|
timer_game_ending_started = False
|
||||||
game_ending = True
|
game_ending = True
|
||||||
game_running = False
|
game_running = False
|
||||||
|
pin_start_inhibit = True
|
||||||
|
|
||||||
if game_running == False and game_ending == True:
|
if game_running == False and game_ending == True:
|
||||||
print("game is ending")
|
print("game is ending")
|
||||||
|
|
||||||
|
# check highscores only once when game ended
|
||||||
if highscore_checked == False:
|
if highscore_checked == False:
|
||||||
check_highscores(int_time)
|
check_highscores(int_time)
|
||||||
highscore_checked = True
|
highscore_checked = True
|
||||||
|
|
||||||
|
# timer for ending the game after 5 seconds
|
||||||
if timer_game_ending_started == False:
|
if timer_game_ending_started == False:
|
||||||
timer_game_ending_timout = pygame.time.get_ticks()
|
timer_game_ending_timout = pygame.time.get_ticks()
|
||||||
timer_game_ending_started = True
|
timer_game_ending_started = True
|
||||||
@ -560,6 +568,7 @@ while True:
|
|||||||
game_ending = False
|
game_ending = False
|
||||||
highscore_checked = False
|
highscore_checked = False
|
||||||
timer_game_ending_started = False
|
timer_game_ending_started = False
|
||||||
|
pin_start_inhibit = False
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
pygame_clock.tick(pygame_fps)
|
pygame_clock.tick(pygame_fps)
|
||||||
|
Loading…
Reference in New Issue
Block a user