changed timing system for the game\'s end to be tick based
This commit is contained in:
parent
48df332b32
commit
72a08a23b6
@ -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,14 +519,20 @@ 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()
|
||||||
|
|
||||||
|
if game_ending == True:
|
||||||
|
print("game is ending")
|
||||||
|
if highscore_checked == False:
|
||||||
check_highscores(int_time)
|
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)
|
||||||
@ -526,12 +543,14 @@ while True:
|
|||||||
|
|
||||||
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
|
||||||
|
if ((pygame.time.get_ticks()-timer_game_ending_timout)/1000) > 5:
|
||||||
game_running = False
|
game_running = False
|
||||||
game_just_started = True
|
game_just_started = True
|
||||||
clear_screen()
|
game_ending = False
|
||||||
|
highscore_checked = 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