added error screen

This commit is contained in:
Nicholas Dyer 2023-05-12 17:34:13 -04:00
parent d8775fb1a9
commit 5b2c724882
3 changed files with 47 additions and 3 deletions

View File

@ -7,7 +7,8 @@ import importlib
valid_surfaces = [
'title',
'egg_select',
'selection_info'
'selection_info',
'error_screen'
]
surface_modules = {}
@ -65,7 +66,7 @@ def game():
next_surface = surface.next_surface
additional_args = surface.additional_args
if next_surface not in valid_surfaces:
raise Exception('Given surface is not listed in valid surfaces!')
next_surface = 'error_screen'
surface = surface_modules.get(next_surface).Surface((game_res, game_res), resources_dir,
game_fps, **additional_args)
print(surface.name)

View File

@ -0,0 +1,41 @@
import pygame
from pocket_friends.game_files.io import gpio_handler
from pocket_friends.game_files.io.input_handler import InputHandler
class Surface(pygame.Surface):
def __init__(self, window_size, resources_dir, game_fps, **kwargs):
super().__init__(window_size, pygame.SRCALPHA)
self.name = 'error_screen'
self.running = True
self.next_surface = 'title'
self.clock = pygame.time.Clock()
self.input_handler = InputHandler(self.clock)
self.additional_args = {}
self.bg = pygame.image.load(resources_dir + '/images/bg.png').convert_alpha()
self.title = pygame.image.load(resources_dir + '/images/debug/invalid.png').convert_alpha()
self.frames = 1
self.game_fps = game_fps
self.delay = 1
self.font = pygame.font.Font(resources_dir + '/fonts/5Pts5.ttf', 10)
def update(self):
self.clock.tick(self.game_fps)
self.blit(self.bg, (0, 0))
self.blit(self.title, (0, -4))
text = self.font.render('Frames: {0}'.format(self.frames), False, (64, 64, 64))
self.blit(text, (3, 68))
self.frames += 1
self.frames %= self.game_fps
self.input_handler.update()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == gpio_handler.BUTTONS.get('b'):
self.running = False
print('stop')

View File

@ -63,7 +63,9 @@ class Surface(pygame.Surface):
# Scroll up on the info screen.
self.info_text.scroll_up()
if event.key == gpio_handler.BUTTONS.get('a'):
pass
self.running = False
self.additional_args = {'selected_color': self.selected_egg}
self.next_surface = 'playground'
if event.key == gpio_handler.BUTTONS.get('b'):
self.running = False
self.additional_args = {'selected_color': self.selected_egg}