From 2baa5e4e7b7caeee7f0748731392eb7bca1ed04a Mon Sep 17 00:00:00 2001 From: Patrick Tschuchnig Date: Thu, 19 Sep 2019 08:08:18 +0200 Subject: [PATCH 1/3] added sound effects, changed screen resolution setup to be detection based rather than manually entered --- gametest_rev2.py | 8 ++++---- pud_test.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 pud_test.py diff --git a/gametest_rev2.py b/gametest_rev2.py index 17cd567..0c67755 100644 --- a/gametest_rev2.py +++ b/gametest_rev2.py @@ -454,7 +454,7 @@ def handle_events(): exit_application() # shutdown raspberry if shutdown pin is detected - if GPIO.input(pin_shutdown): + if not GPIO.input(pin_shutdown): shutdown_raspberry() def exit_application(): @@ -715,7 +715,7 @@ while True: # event handling for if the start button is pushed #wait for the user to press start button - if GPIO.input(pin_start) and not pin_start_inhibit: + if not GPIO.input(pin_start) and not pin_start_inhibit: # change game state to running and not ending game_running = True game_ending = False @@ -753,7 +753,7 @@ while True: pin_start_inhibit = False # add errors if error pin is detected, only once per 500 ms - if GPIO.input(pin_error): + if not GPIO.input(pin_error): if not error_added: errors += 1 error_added = True @@ -791,7 +791,7 @@ while True: #pygame.display.flip() # if another push of start is detected (i.e. the game is ending!) - if GPIO.input(pin_stop): + if not GPIO.input(pin_stop): # change led colour to red change_led_colour(200, 0, 200) diff --git a/pud_test.py b/pud_test.py new file mode 100644 index 0000000..9e5e6ab --- /dev/null +++ b/pud_test.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +#coding=utf-8 + +import signal +import sys +import os +import time +import RPi.GPIO as GPIO + +############################################ +############## END OF IMPORTS ############## + +# GPIO for Buttons +pin_start = 36 + + +# initialise gpio +GPIO.setmode(GPIO.BOARD) +GPIO.setup(pin_start, GPIO.IN) + +while True: + print(GPIO.input(pin_start)) + time.sleep(1) + From 37ab165bfca749da8eeffdf370bfd8f7f2c7baed Mon Sep 17 00:00:00 2001 From: Patrick Tschuchnig Date: Thu, 16 Jul 2020 08:22:56 +0200 Subject: [PATCH 2/3] test for performance added FPS counter --- fps_counter.py | 27 +++++++++++++++++++++++++++ gametest_rev2.py | 19 ++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 fps_counter.py diff --git a/fps_counter.py b/fps_counter.py new file mode 100644 index 0000000..3750233 --- /dev/null +++ b/fps_counter.py @@ -0,0 +1,27 @@ +import sys +import pygame as pg + +def main(): + pg.init() + screen = pg.display.set_mode((320, 240)) + font = pg.font.Font(None, 30) + clock = pg.time.Clock() + done = False + + while not done: + for event in pg.event.get(): + if event.type == pg.QUIT: + done = True + + screen.fill(pg.Color('black')) + fps = font.render(str(int(clock.get_fps())), True, pg.Color('white')) + screen.blit(fps, (50, 50)) + pg.display.flip() + clock.tick(30) + + pg.quit() + sys.exit() + +if __name__ == "__main__": + main() + diff --git a/gametest_rev2.py b/gametest_rev2.py index 18a2107..60192ee 100644 --- a/gametest_rev2.py +++ b/gametest_rev2.py @@ -282,6 +282,10 @@ hs3_time = 300000 # initialise the game pygame.init() +#fps counter definitions +#font = pygame.font.Font('freesansbold.ttf', 30) +#clock = pygame.time.Clock() + # screen settings - autodetermined based on the initialised pygame video instance screen_size_x = pygame.display.Info().current_w screen_size_y = pygame.display.Info().current_h @@ -486,7 +490,7 @@ def enter_name(): highscore_rectangle.topleft = (700, 350) screen.blit(highscore_surface, highscore_rectangle) - + textbox_text_surface = pygame_font_2.render('Enter Name:', True, pygame_font_main_color) textbox_text_rectangle = textbox_text_surface.get_rect() textbox_text_rectangle.topleft = (700, 500) @@ -636,17 +640,17 @@ screen = pygame.display.set_mode((screen_size_x, screen_size_y), pygame.FULLSCRE # define image variables img_itlablogo = 'img/itlablogo.png' -img_itlablogo_image = pygame.image.load(img_itlablogo) +img_itlablogo_image = pygame.image.load(img_itlablogo).convert_alpha() img_itlablogo_imagex = get_image_width(img_itlablogo) img_itlablogo_imagey = get_image_height(img_itlablogo) img_metalliclogo = 'img/metalliclogo.png' -img_metalliclogo_image = pygame.image.load(img_metalliclogo) +img_metalliclogo_image = pygame.image.load(img_metalliclogo).convert_alpha() img_metalliclogo_imagex = get_image_width(img_metalliclogo) img_metalliclogo_imagey = get_image_height(img_metalliclogo) img_background = 'img/bg.jpg' -img_background_image = pygame.image.load(img_background) +img_background_image = pygame.image.load(img_background).convert() img_background_imagex = get_image_width(img_background) img_background_imagey = get_image_height(img_background) @@ -718,7 +722,7 @@ while True: screen.blit(score1_surface, score1_rectangle) screen.blit(score2_surface, score2_rectangle) screen.blit(score3_surface, score3_rectangle) - + # event handling for if the start button is pushed #wait for the user to press start button if not GPIO.input(pin_start) and not pin_start_inhibit: @@ -782,6 +786,11 @@ while True: time_rectangle = time_surface.get_rect() time_rectangle.topleft = (640, 480) + # fps = font.render(str(int(clock.get_fps())), True, pygame.Color('white')) + # screen.blit(fps, (50, 50)) + # pygame.display.flip() + # clock.tick(30) + errors_surface = pygame_font_2.render('Fehler: ' + str(errors), True, pygame_font_main_color) errors_rectangle = errors_surface.get_rect() errors_rectangle.topleft = (640, 560) From be9838af5c1dc8ce35f2de10ad282d1a2babfdd0 Mon Sep 17 00:00:00 2001 From: Moris Krajnc Date: Thu, 16 Jul 2020 10:58:01 +0200 Subject: [PATCH 3/3] cleaned code --- gametest_rev2.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/gametest_rev2.py b/gametest_rev2.py index 60192ee..6f8b78f 100644 --- a/gametest_rev2.py +++ b/gametest_rev2.py @@ -282,10 +282,6 @@ hs3_time = 300000 # initialise the game pygame.init() -#fps counter definitions -#font = pygame.font.Font('freesansbold.ttf', 30) -#clock = pygame.time.Clock() - # screen settings - autodetermined based on the initialised pygame video instance screen_size_x = pygame.display.Info().current_w screen_size_y = pygame.display.Info().current_h @@ -299,6 +295,7 @@ logoff_sound = pygame.mixer.Sound('snd/winxplogoff.wav') pygame_font_1 = pygame.font.Font('freesansbold.ttf', 90) pygame_font_2 = pygame.font.Font('freesansbold.ttf', 65) pygame_font_3 = pygame.font.Font('freesansbold.ttf', 45) +pygame_font_4 = pygame.font.Font('freesansbold.ttf', 16) # colors pygame_color_green = pygame.Color(42, 217, 13) @@ -786,11 +783,6 @@ while True: time_rectangle = time_surface.get_rect() time_rectangle.topleft = (640, 480) - # fps = font.render(str(int(clock.get_fps())), True, pygame.Color('white')) - # screen.blit(fps, (50, 50)) - # pygame.display.flip() - # clock.tick(30) - errors_surface = pygame_font_2.render('Fehler: ' + str(errors), True, pygame_font_main_color) errors_rectangle = errors_surface.get_rect() errors_rectangle.topleft = (640, 560) @@ -801,10 +793,11 @@ while True: screen.blit(errors_surface, errors_rectangle) #errors screen.blit(time_surface, time_rectangle) #time screen.blit(header_surface, header_rectangle) #header - - # display everything - #pygame.display.flip() - + + + fps = pygame_font_4.render(str(int(pygame_clock.get_fps())), True, pygame.Color('white')) + screen.blit(fps, (50, 50)) + # if another push of start is detected (i.e. the game is ending!) if not GPIO.input(pin_stop): # change led colour to red