From 4249a7c3f1346bad51db5a0b2bd390180e92f18c Mon Sep 17 00:00:00 2001 From: Nicholas Dyer Date: Sun, 14 May 2023 17:47:56 -0400 Subject: [PATCH] added preliminary dev menu --- pocket_friends/development/dev_menu.py | 26 +++++++++++++++++++++ pocket_friends/elements/surface.py | 5 ++-- pocket_friends/game.py | 4 ++-- pocket_friends/resources/images/dev_bg.png | Bin 0 -> 2127 bytes 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 pocket_friends/development/dev_menu.py create mode 100644 pocket_friends/resources/images/dev_bg.png diff --git a/pocket_friends/development/dev_menu.py b/pocket_friends/development/dev_menu.py new file mode 100644 index 0000000..2c10f0c --- /dev/null +++ b/pocket_friends/development/dev_menu.py @@ -0,0 +1,26 @@ +import pygame +from pocket_friends.elements import surface + + +class Surface(surface.GameSurface): + def __init__(self, game_res, resources_dir, game_fps, **kwargs): + super().__init__(game_res, resources_dir, game_fps) + self.frames = 1 + self.game_fps = game_fps + self.delay = 1 + self.font = pygame.font.Font(resources_dir + '/fonts/5Pts5.ttf', 10) + self.bg = pygame.image.load(self.resource_dir + '/images/dev_bg.png').convert_alpha() + + def update(self): + self.preprocess() + + text = self.font.render('f: {0}'.format(self.frames), False, (128, 128, 128)) + self.blit(text, (3, 68)) + + self.frames += 1 + self.frames %= self.game_fps + + for event in pygame.event.get(): + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_b: + self.running = False diff --git a/pocket_friends/elements/surface.py b/pocket_friends/elements/surface.py index 663f499..8749834 100644 --- a/pocket_friends/elements/surface.py +++ b/pocket_friends/elements/surface.py @@ -12,6 +12,7 @@ class GameSurface(pygame.Surface): resource_dir (:obj:`str`): The path of the game's main resource directory. game_fps (int): How many frames per second the game will run at. additional_args (dict): Additional arguments to send to the next surface after halting. + bg (:obj:`pygame.Surface`): The background of the surface. """ def __init__(self, game_res, resources_dir, game_fps): """ @@ -30,7 +31,7 @@ class GameSurface(pygame.Surface): self._input_handler = InputHandler(self._clock) self.additional_args = {} - self._bg = pygame.image.load(self.resource_dir + '/images/bg.png').convert_alpha() + self.bg = pygame.image.load(self.resource_dir + '/images/bg.png').convert_alpha() self.sprites = pygame.sprite.Group() def preprocess(self): @@ -39,7 +40,7 @@ class GameSurface(pygame.Surface): """ self._clock.tick(self.game_fps) - self.blit(self._bg, (0, 0)) + self.blit(self.bg, (0, 0)) self.sprites.update() self.sprites.draw(self) diff --git a/pocket_friends/game.py b/pocket_friends/game.py index f4019ca..d0a6041 100644 --- a/pocket_friends/game.py +++ b/pocket_friends/game.py @@ -12,7 +12,7 @@ valid_surfaces = [ ] # Add all the surface modules to a dictionary for easy switching -surface_modules = {} +surface_modules = {'dev_menu': importlib.import_module('pocket_friends.development.{0}'.format('dev_menu'))} for module in valid_surfaces: surface_modules[module] = importlib.import_module('pocket_friends.surfaces.{0}'.format(module)) starting_surface = 'title' @@ -66,7 +66,7 @@ def start_game(resolution=240): next_surface = surface.next_surface additional_args = surface.additional_args if next_surface not in valid_surfaces: - next_surface = 'error_screen' + next_surface = 'dev_menu' surface = surface_modules.get(next_surface).Surface((game_res, game_res), resources_dir, game_fps, **additional_args) pygame.display.flip() diff --git a/pocket_friends/resources/images/dev_bg.png b/pocket_friends/resources/images/dev_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..eb80ae137c21eb0998bab9266f823043ab46d100 GIT binary patch literal 2127 zcmV-V2(b5wP)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00*~8L_t(|+U;9emzz2a#@J@f z#QFdKazYX?i@6UvRds}M3}L3z-uR(snh>l{o3%Mf-s`>osU_I|wbp5xCQ0I)8;0TE z1FYEp%d*@AIG#auUBe&u`~4{DKR!OBlu43I)6_K09>73-k|aWinBQkvrj$yOWE@8? zU}Ma0brJ%o?EBtY`#NBx7XR1`7}q?{ky`?c<(6exW?6=e!xu^^^E^kud7c+V0Xh;X zrI&cL_C??KQ9j@o9;Oj_o@=e?hm?c#b9hV$5ig}L0URUYJkOCz_Iyzk6u>;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