title screen moves on now to sprite selection
This commit is contained in:
parent
2ffd9bd929
commit
296b6df4a0
@ -2,7 +2,17 @@ import pygame
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import pocket_friends
|
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.
|
# FPS for the entire game to run at.
|
||||||
game_fps = 16
|
game_fps = 16
|
||||||
@ -30,7 +40,7 @@ def game():
|
|||||||
pygame.mouse.set_visible(False)
|
pygame.mouse.set_visible(False)
|
||||||
pygame.display.set_caption('Pocket Friends {0}'.format(pocket_friends.__version__))
|
pygame.display.set_caption('Pocket Friends {0}'.format(pocket_friends.__version__))
|
||||||
window = pygame.display.set_mode((screen_size, screen_size))
|
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.
|
# Add an icon to the pygame window.
|
||||||
icon = pygame.image.load(script_dir + '/icon/icon.png').convert_alpha()
|
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))
|
frame = pygame.transform.scale(surface, (screen_size, screen_size))
|
||||||
window.blit(frame, frame.get_rect())
|
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()
|
pygame.display.flip()
|
||||||
|
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
|
17
pocket_friends/game_files/surfaces/egg_select.py
Normal file
17
pocket_friends/game_files/surfaces/egg_select.py
Normal file
@ -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)
|
@ -1,16 +1,25 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
class Surface(pygame.Surface):
|
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)
|
super().__init__(window_size, pygame.SRCALPHA)
|
||||||
|
self.name = 'title'
|
||||||
self.running = True
|
self.running = True
|
||||||
self.next_surface = None
|
self.next_surface = None
|
||||||
|
|
||||||
self.bg = pygame.image.load(resources_dir + '/images/bg.png').convert_alpha()
|
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.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):
|
def update(self):
|
||||||
self.blit(self.bg, (0, 0))
|
self.blit(self.bg, (0, 0))
|
||||||
self.blit(self.title, (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
|
||||||
|
Loading…
Reference in New Issue
Block a user