minor cleanup, added placeholders, changed when the border is drawn
This commit is contained in:
		@@ -68,7 +68,7 @@ pygame_clock = pygame.time.Clock()
 | 
				
			|||||||
# GPIO for Buttons
 | 
					# GPIO for Buttons
 | 
				
			||||||
pin_start = 32
 | 
					pin_start = 32
 | 
				
			||||||
pin_error = 33
 | 
					pin_error = 33
 | 
				
			||||||
pin_shutdown = 3
 | 
					pin_shutdown = 36
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# GPIO for LED
 | 
					# GPIO for LED
 | 
				
			||||||
pin_red = 22
 | 
					pin_red = 22
 | 
				
			||||||
@@ -271,10 +271,15 @@ def handle_events():
 | 
				
			|||||||
        for event in pygame.event.get():
 | 
					        for event in pygame.event.get():
 | 
				
			||||||
                if event.type == KEYDOWN and event.key == K_ESCAPE:
 | 
					                if event.type == KEYDOWN and event.key == K_ESCAPE:
 | 
				
			||||||
                        exit_application()
 | 
					                        exit_application()
 | 
				
			||||||
                elif event.type == KEYDOWN and event.key == K_q: 
 | 
					                # disabled in favour of the shutdown pin
 | 
				
			||||||
                        shutdown_raspberry()      
 | 
					                #elif event.type == KEYDOWN and event.key == K_q: 
 | 
				
			||||||
 | 
					                #        shutdown_raspberry()      
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # shutdown raspberry if shutdown pin is detected
 | 
				
			||||||
 | 
					        if (GPIO.INPUT(pin_shutdown)):
 | 
				
			||||||
 | 
					            shutdown_raspberry()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def exit_application():
 | 
					def exit_application():
 | 
				
			||||||
        pygame.quit()
 | 
					        pygame.quit()
 | 
				
			||||||
        GPIO.cleanup()
 | 
					        GPIO.cleanup()
 | 
				
			||||||
@@ -367,12 +372,14 @@ def check_highscores(time):
 | 
				
			|||||||
        return
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def show_debug():
 | 
					def show_debug():
 | 
				
			||||||
 | 
					    print('#############')
 | 
				
			||||||
    print('Game running: ' + str(game_running))
 | 
					    print('Game running: ' + str(game_running))
 | 
				
			||||||
    print('Game ending: ' + str(game_ending))
 | 
					    print('Game ending: ' + str(game_ending))
 | 
				
			||||||
    print('Pin status: ')
 | 
					    print('Pin status: ')
 | 
				
			||||||
    print('Start pin: ' + str(GPIO.input(pin_start)))
 | 
					    print('Start pin: ' + str(GPIO.input(pin_start)))
 | 
				
			||||||
    print('Error pin: ' + str(GPIO.input(pin_error)))
 | 
					    print('Error pin: ' + str(GPIO.input(pin_error)))
 | 
				
			||||||
    print('Shutdown pin: ' + str(GPIO.input(pin_shutdown)))
 | 
					    print('Shutdown pin: ' + str(GPIO.input(pin_shutdown)))
 | 
				
			||||||
 | 
					    print('#############')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
############################################
 | 
					############################################
 | 
				
			||||||
####### END OF FUNCTION DEFINITIONS ########
 | 
					####### 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_imagex = get_image_width(img_itlablogo)
 | 
				
			||||||
img_itlablogo_imagey = get_image_height(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
 | 
					# initialise led strip
 | 
				
			||||||
led_init()
 | 
					led_init()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -426,10 +439,17 @@ while True:
 | 
				
			|||||||
        handle_events()
 | 
					        handle_events()
 | 
				
			||||||
        show_debug()
 | 
					        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: 
 | 
					        if game_running == False and game_ending == False: 
 | 
				
			||||||
            # one shot for changing the led colour
 | 
					            # one shot for changing the led colour
 | 
				
			||||||
            if game_just_started == True:
 | 
					            if game_just_started == True:
 | 
				
			||||||
                print("New game starting")
 | 
					 | 
				
			||||||
                change_led_colour(10,140,10)
 | 
					                change_led_colour(10,140,10)
 | 
				
			||||||
                game_just_started = False
 | 
					                game_just_started = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -460,24 +480,18 @@ while True:
 | 
				
			|||||||
            score3_rectangle = score3_surface.get_rect()
 | 
					            score3_rectangle = score3_surface.get_rect()
 | 
				
			||||||
            score3_rectangle.topleft = (820, 720)
 | 
					            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)
 | 
					            # draw headline, highscore headline, the 3 scores, as well as the logos to the screen
 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            # add headline, highscore headline, the 3 scores, as well as the logos to the screen
 | 
					 | 
				
			||||||
            screen.blit(header_surface, header_rectangle)
 | 
					            screen.blit(header_surface, header_rectangle)
 | 
				
			||||||
            screen.blit(highscore_header_surface, highscore_header_rectangle)
 | 
					            screen.blit(highscore_header_surface, highscore_header_rectangle)
 | 
				
			||||||
            screen.blit(score1_surface, score1_rectangle)
 | 
					            screen.blit(score1_surface, score1_rectangle)
 | 
				
			||||||
            screen.blit(score2_surface, score2_rectangle)
 | 
					            screen.blit(score2_surface, score2_rectangle)
 | 
				
			||||||
            screen.blit(score3_surface, score3_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
 | 
					            # display everything
 | 
				
			||||||
            pygame.display.flip()
 | 
					            pygame.display.flip()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # event handling for if the start button is pushed
 | 
					            # 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                    
 | 
					            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
 | 
					                    # change game state to running and not ending
 | 
				
			||||||
                    game_running = True
 | 
					                    game_running = True
 | 
				
			||||||
                    game_ending = False
 | 
					                    game_ending = False
 | 
				
			||||||
@@ -501,7 +515,6 @@ while True:
 | 
				
			|||||||
                    change_led_colour(10,10,100)
 | 
					                    change_led_colour(10,10,100)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if game_running == True and game_ending == False: 
 | 
					        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,
 | 
					                # if the start pin is inhibited and at least 3 seconds have passed,
 | 
				
			||||||
                # one shot: stop blocking the pin
 | 
					                # one shot: stop blocking the pin
 | 
				
			||||||
@@ -533,7 +546,7 @@ while True:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                clear_screen()
 | 
					                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(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
 | 
				
			||||||
@@ -543,8 +556,6 @@ while True:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                # if another push of start is detected (i.e. the game is ending!)
 | 
					                # if another push of start is detected (i.e. the game is ending!)
 | 
				
			||||||
                if GPIO.input(pin_start) == True and pin_start_inhibit == False:
 | 
					                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 to red
 | 
				
			||||||
                        change_led_colour(100,10,10)
 | 
					                        change_led_colour(100,10,10)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -560,8 +571,6 @@ while True:
 | 
				
			|||||||
                        pin_start_inhibit = True
 | 
					                        pin_start_inhibit = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if game_running == False and game_ending == True:
 | 
					        if game_running == False and game_ending == True:
 | 
				
			||||||
                print("game is ending")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                # check highscores only once when game ended
 | 
					                # check highscores only once when game ended
 | 
				
			||||||
                if highscore_checked == False: 
 | 
					                if highscore_checked == False: 
 | 
				
			||||||
                    check_highscores(int_time)
 | 
					                    check_highscores(int_time)
 | 
				
			||||||
@@ -577,7 +586,7 @@ while True:
 | 
				
			|||||||
                # change the headline to game over
 | 
					                # change the headline to game over
 | 
				
			||||||
                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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                # 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(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
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user