diff --git a/pocket_friends/game_files/game.py b/pocket_friends/game_files/game.py index e329a32..9fc4d6e 100644 --- a/pocket_friends/game_files/game.py +++ b/pocket_friends/game_files/game.py @@ -2,7 +2,17 @@ import pygame import os from pathlib import Path import pocket_friends -from pocket_friends.game_files.surfaces import title +import importlib + +valid_surfaces = [ + 'title', + 'egg_select' +] +surface_modules = {} + +for module in valid_surfaces: + surface_modules[module] = importlib.import_module('pocket_friends.game_files.surfaces.{0}'.format(module)) + print('imported ' + module) # FPS for the entire game to run at. game_fps = 16 @@ -30,7 +40,7 @@ def game(): pygame.mouse.set_visible(False) pygame.display.set_caption('Pocket Friends {0}'.format(pocket_friends.__version__)) window = pygame.display.set_mode((screen_size, screen_size)) - surface = globals()[starting_surface].Surface((game_res, game_res), resources_dir) + surface = surface_modules.get(starting_surface).Surface((game_res, game_res), resources_dir, game_fps) # Add an icon to the pygame window. icon = pygame.image.load(script_dir + '/icon/icon.png').convert_alpha() @@ -53,6 +63,12 @@ def game(): frame = pygame.transform.scale(surface, (screen_size, screen_size)) window.blit(frame, frame.get_rect()) + if not surface.running: + next_surface = surface.next_surface + if next_surface not in valid_surfaces: + raise Exception('Given surface is not listed in valid surfaces!') + surface = surface_modules.get(next_surface).Surface((game_res, game_res), resources_dir, game_fps) + print(surface.name) pygame.display.flip() diff --git a/pocket_friends/game_files/surfaces/__init__.py b/pocket_friends/game_files/surfaces/__init__.py index e69de29..6867d8e 100644 --- a/pocket_friends/game_files/surfaces/__init__.py +++ b/pocket_friends/game_files/surfaces/__init__.py @@ -0,0 +1,6 @@ +import os +__all__ = [] +for module in os.listdir(os.path.dirname(os.path.abspath(__file__))): + if module != '__init__.py' and module[-3:] == '.py': + __all__.append(module) + diff --git a/pocket_friends/game_files/surfaces/egg_select.py b/pocket_friends/game_files/surfaces/egg_select.py new file mode 100644 index 0000000..691276f --- /dev/null +++ b/pocket_friends/game_files/surfaces/egg_select.py @@ -0,0 +1,17 @@ +import pygame + + +class Surface(pygame.Surface): + def __init__(self, window_size, resources_dir, game_fps): + super().__init__(window_size, pygame.SRCALPHA) + self.name = 'egg_select' + self.running = True + self.next_surface = None + + self.bg = pygame.image.load(resources_dir + '/images/bg.png').convert_alpha() + self.sprites = pygame.sprite.Group() + + def update(self): + self.blit(self.bg, (0, 0)) + self.sprites.update() + self.sprites.draw(self) diff --git a/pocket_friends/game_files/surfaces/title.py b/pocket_friends/game_files/surfaces/title.py index 4bf0594..2fade0b 100644 --- a/pocket_friends/game_files/surfaces/title.py +++ b/pocket_friends/game_files/surfaces/title.py @@ -1,16 +1,25 @@ import pygame +import time class Surface(pygame.Surface): - def __init__(self, window_size, resources_dir): + def __init__(self, window_size, resources_dir, game_fps): super().__init__(window_size, pygame.SRCALPHA) + self.name = 'title' self.running = True self.next_surface = None self.bg = pygame.image.load(resources_dir + '/images/bg.png').convert_alpha() self.title = pygame.image.load(resources_dir + '/images/title.png').convert_alpha() + self.frames = 1 + self.game_fps = game_fps + self.delay = 1 def update(self): self.blit(self.bg, (0, 0)) self.blit(self.title, (0, 0)) + self.frames += 1 + if self.frames > self.game_fps * self.delay: + self.next_surface = 'egg_select' + self.running = False