diff --git a/gametest.py b/gametest.py index b0455d7..833ef66 100644 --- a/gametest.py +++ b/gametest.py @@ -95,6 +95,34 @@ def shutdown_raspberry(): os.system("sudo shutdown -h now") return +def enterName(): + clearScreen() + print('text entry started') + name = '' + while True: + clearScreen() + textbox_surface = font1.render('Enter name: ' + str(name), True, mainFontColor) + textbox_rectangle = textbox_surface.get_rect() + textbox_rectangle.topleft = (10, 30) + screen.blit(textbox_surface, textbox_rectangle) + pygame.display.flip() + for event in pygame.event.get(): + if len(name) < MAX_NAME_LENGTH: + if event.type == KEYDOWN: + if event.key == pygame.K_BACKSPACE: + name = name[:-1] + else: + name += event.unicode + elif event.key == pygame.K_BACKSPACE: + name = name[:-1] + + elif event.type == KEYDOWN and event.key == pygame.K_RETURN: + clearScreen() + return name + clearScreen() + name = 'Error' + return name + #signal handing for controlled exit via ctrl+c signal.signal(signal.SIGINT, signal_handler) @@ -105,6 +133,15 @@ screen = pygame.display.set_mode((screenSizeX, screenSizeY), pygame.FULLSCREEN) #screen = toggle_fullscreen() +# preset highscores + +hs1_name = "Fritz" +hs2_name = "Bernd" +hs3_name = "Max" + +hs1_time = 100 +hs2_time = 200 +hs3_time = 300 while True: # main loop @@ -117,15 +154,34 @@ while True: # main loop header_surface = font.render('Dr' + u'ΓΌ' + 'cken Sie Start!', True, mainFontColor) header_rectangle = header_surface.get_rect() - header_rectangle.topleft = (0, 100) + header_rectangle.topleft = (10, 100) + + highscore_header_surface = font.render('Highscores:', True, mainFontColor) + highscore_header_rectangle = highscore_header_surface.get_rect() + highscore_header_rectangle = (10,190) + + score1_surface = font1.render(hs1_name + ": " + str(hs1_time) + 's', True, mainFontColor) + score1_rectangle = score1_surface.get_rect() + score1_rectangle.topleft = (10, 270) + + score2_surface = font1.render(hs2_name + ": " + str(hs2_time) + 's', True, mainFontColor) + score2_rectangle = score2_surface.get_rect() + score2_rectangle.topleft = (10, 360) + + score3_surface = font1.render(hs3_name + ": " + str(hs3_time) + 's', True, mainFontColor) + score3_rectangle = score3_surface.get_rect() + score3_rectangle.topleft = (10, 450) screen.blit(header_surface, header_rectangle) + screen.blit(highscore_header_surface, highscore_header_rectangle) + screen.blit(score1_surface, score1_rectangle) + screen.blit(score2_surface, score2_rectangle) + screen.blit(score3_surface, score3_rectangle) pygame.display.flip() while GPIO.input(startPin) == False: #wait for the user to press start button handle_events() - errors = 0 errorAdded = False @@ -153,11 +209,11 @@ while True: # main loop time_surface = font.render('Zeit: ' + str(int_time) + 's', True, mainFontColor) time_rectangle = time_surface.get_rect() - time_rectangle.topleft = (0, 300) + time_rectangle.topleft = (10, 300) errors_surface = font.render('Fehler: ' + str(errors), True, mainFontColor) errors_rectangle = errors_surface.get_rect() - errors_rectangle.topleft = (0, 400) + errors_rectangle.topleft = (10, 400) clearScreen() screen.blit(errors_surface, errors_rectangle) #errors