minor cleanup, added placeholders, changed when the border is drawn

This commit is contained in:
Patrick Tschuchnig 2019-09-11 13:33:02 +02:00
parent ad94b1b601
commit a337c279f7

View File

@ -68,7 +68,7 @@ pygame_clock = pygame.time.Clock()
# GPIO for Buttons
pin_start = 32
pin_error = 33
pin_shutdown = 3
pin_shutdown = 36
# GPIO for LED
pin_red = 22
@ -271,10 +271,15 @@ def handle_events():
for event in pygame.event.get():
if event.type == KEYDOWN and event.key == K_ESCAPE:
exit_application()
elif event.type == KEYDOWN and event.key == K_q:
shutdown_raspberry()
# disabled in favour of the shutdown pin
#elif event.type == KEYDOWN and event.key == K_q:
# shutdown_raspberry()
return
# shutdown raspberry if shutdown pin is detected
if (GPIO.INPUT(pin_shutdown)):
shutdown_raspberry()
def exit_application():
pygame.quit()
GPIO.cleanup()
@ -367,12 +372,14 @@ def check_highscores(time):
return
def show_debug():
print('#############')
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)))
print('#############')
############################################
####### END OF FUNCTION DEFINITIONS ########
@ -401,6 +408,12 @@ img_itlablogo_image = pygame.image.load(img_itlablogo)
img_itlablogo_imagex = get_image_width(img_itlablogo)
img_itlablogo_imagey = get_image_height(img_itlablogo)
# TODO: Metallic Logo einfügen
#img_metalliclogo = 'img/metalliclogo.png'
#img_metalliclogo_image = pygame.image.load(img_metalliclogo)
#img_metalliclogo_imagex = get_image_width(img_metalliclogo)
#img_metalliclogo_imagey = get_image_height(img_metalliclogo)
# initialise led strip
led_init()
@ -426,10 +439,17 @@ while True:
handle_events()
show_debug()
# draw logos
screen.blit(img_itlablogo_image, (screen_size_x-img_itlablogo_imagex-20, screen_size_y-img_itlablogo_imagey-20))
# TODO: Metallic Logo
# draw rectangle border around everything
pygame.draw.rect(screen,pygame_color_black, (500, 200, (screen_size_x-500*2), (screen_size_y-200*2)), 5)
if game_running == False and game_ending == False:
# one shot for changing the led colour
if game_just_started == True:
print("New game starting")
change_led_colour(10,140,10)
game_just_started = False
@ -460,24 +480,18 @@ while True:
score3_rectangle = score3_surface.get_rect()
score3_rectangle.topleft = (820, 720)
pygame.draw.rect(screen,pygame_color_black, (500, 200, (screen_size_x-500*2), (screen_size_y-200*2)), 5)
# add headline, highscore headline, the 3 scores, as well as the logos to the screen
# draw headline, highscore headline, the 3 scores, as well as the logos to the screen
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)
screen.blit(img_itlablogo_image, (screen_size_x-img_itlablogo_imagex-20, screen_size_y-img_itlablogo_imagey-20))
# TODO: Metallic Logo
# display everything
pygame.display.flip()
# event handling for if the start button is pushed
if GPIO.input(pin_start) == True and pin_start_inhibit == False: #wait for the user to press start button
print("start pin has been detected, starting game")
# change game state to running and not ending
game_running = True
game_ending = False
@ -501,7 +515,6 @@ while True:
change_led_colour(10,10,100)
if game_running == True and game_ending == False:
print("Game running normally")
# if the start pin is inhibited and at least 3 seconds have passed,
# one shot: stop blocking the pin
@ -533,7 +546,7 @@ while True:
clear_screen()
# add errors, time and headline to the screen
# draw errors, time and headline to the screen
screen.blit(errors_surface, errors_rectangle) #errors
screen.blit(time_surface, time_rectangle) #time
screen.blit(header_surface, header_rectangle) #header
@ -543,8 +556,6 @@ while True:
# if another push of start is detected (i.e. the game is ending!)
if GPIO.input(pin_start) == True and pin_start_inhibit == False:
print("Game ended because start pin was detected again")
# change led colour to red
change_led_colour(100,10,10)
@ -560,8 +571,6 @@ while True:
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)
@ -577,7 +586,7 @@ while True:
# change the headline to game over
header_surface = pygame_font_1.render('Game over!', True, pygame_font_main_color)
# add errors, time, and new headline to the screen
# draw errors, time, and new headline to the screen
screen.blit(errors_surface, errors_rectangle) #errors
screen.blit(time_surface, time_rectangle) #time
screen.blit(header_surface, header_rectangle) #header