changed timing system for the game\'s end to be tick based

This commit is contained in:
Patrick Tschuchnig 2019-09-11 11:14:59 +02:00
parent 48df332b32
commit 72a08a23b6

View File

@ -361,6 +361,14 @@ def check_highscores(time):
else: else:
return return
def show_debug():
print('Game running: ' + str(game_running))
print('Game ending: ' + str(game_ending))
print('Pin status: ')
print('Start pin: ' + str(GPIO.input(pin_start)))
print('Error pin: ' + str(GPIO.input(pin_error)))
print('Shutdown pin: ' + str(GPIO.input(pin_shutdown)))
############################################ ############################################
####### END OF FUNCTION DEFINITIONS ######## ####### END OF FUNCTION DEFINITIONS ########
############################################ ############################################
@ -393,7 +401,9 @@ led_init()
game_running = False game_running = False
game_just_started = True game_just_started = True
game_ending == False
highscore_checked = False
pin_start_inhibit = False pin_start_inhibit = False
############################################ ############################################
@ -408,6 +418,7 @@ while True:
clear_screen() clear_screen()
handle_events() handle_events()
show_debug()
if game_running == False: if game_running == False:
@ -459,7 +470,7 @@ while True:
# set an inhibitor bit to stop the contact from possibly vibrating and # set an inhibitor bit to stop the contact from possibly vibrating and
# causing a stop of the game immediately after start # causing a stop of the game immediately after start
pin_start_inhibit = True pin_start_inhibit = True
pin_start_inhibit_timer_start = pygame.time.get_ticks() timer_pin_start_inhibit_starttime = pygame.time.get_ticks()
errors = 0 errors = 0
error_added = False error_added = False
@ -477,7 +488,7 @@ while True:
# if the start pin is inhibited and at least 3 seconds have passed, # if the start pin is inhibited and at least 3 seconds have passed,
# stop blocking the pin # stop blocking the pin
if pin_start_inhibit == True: if pin_start_inhibit == True:
if ((pygame.time.get_ticks()-pin_start_inhibit_timer_start)/1000) > 3: if ((pygame.time.get_ticks()-timer_pin_start_inhibit_starttime)/1000) > 3:
pin_start_inhibit = False pin_start_inhibit = False
@ -508,30 +519,38 @@ 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 GPIO.input(pin_start) == True and pin_start_inhibit == False: 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")
# change led colour to red # change led colour to red
change_led_colour(100,10,10) change_led_colour(100,10,10)
print("Game ended because start pin wasnt true") game_ending == True
timer_game_ending_timout = pygame.time.get_ticks()
check_highscores(int_time) if game_ending == True:
print("game is ending")
if highscore_checked == False:
check_highscores(int_time)
highscore_checked = True
clear_screen() clear_screen()
header_surface = pygame_font_1.render('Game over!', True, pygame_font_main_color) header_surface = pygame_font_1.render('Game over!', True, pygame_font_main_color)
screen.blit(errors_surface, errors_rectangle) #errors screen.blit(errors_surface, errors_rectangle) #errors
screen.blit(time_surface, time_rectangle) #time screen.blit(time_surface, time_rectangle) #time
screen.blit(header_surface, header_rectangle) #header screen.blit(header_surface, header_rectangle) #header
pygame.display.flip() pygame.display.flip()
time.sleep(5) #time.sleep(5)
# nach dem spiel ist vor dem spiel # nach dem spiel ist vor dem spiel
game_running = False if ((pygame.time.get_ticks()-timer_game_ending_timout)/1000) > 5:
game_just_started = True game_running = False
clear_screen() game_just_started = True
game_ending = False
highscore_checked = False
pygame.display.update() pygame.display.update()
pygame_clock.tick(pygame_fps) pygame_clock.tick(pygame_fps)