Compare commits
2 Commits
187baf6f3e
...
b6432e233a
Author | SHA1 | Date | |
---|---|---|---|
b6432e233a | |||
4249a7c3f1 |
26
pocket_friends/development/dev_menu.py
Normal file
26
pocket_friends/development/dev_menu.py
Normal file
@ -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
|
@ -12,6 +12,7 @@ class GameSurface(pygame.Surface):
|
|||||||
resource_dir (:obj:`str`): The path of the game's main resource directory.
|
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.
|
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.
|
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):
|
def __init__(self, game_res, resources_dir, game_fps):
|
||||||
"""
|
"""
|
||||||
@ -30,7 +31,7 @@ class GameSurface(pygame.Surface):
|
|||||||
self._input_handler = InputHandler(self._clock)
|
self._input_handler = InputHandler(self._clock)
|
||||||
self.additional_args = {}
|
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()
|
self.sprites = pygame.sprite.Group()
|
||||||
|
|
||||||
def preprocess(self):
|
def preprocess(self):
|
||||||
@ -39,7 +40,7 @@ class GameSurface(pygame.Surface):
|
|||||||
"""
|
"""
|
||||||
self._clock.tick(self.game_fps)
|
self._clock.tick(self.game_fps)
|
||||||
|
|
||||||
self.blit(self._bg, (0, 0))
|
self.blit(self.bg, (0, 0))
|
||||||
self.sprites.update()
|
self.sprites.update()
|
||||||
self.sprites.draw(self)
|
self.sprites.draw(self)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ valid_surfaces = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
# Add all the surface modules to a dictionary for easy switching
|
# 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:
|
for module in valid_surfaces:
|
||||||
surface_modules[module] = importlib.import_module('pocket_friends.surfaces.{0}'.format(module))
|
surface_modules[module] = importlib.import_module('pocket_friends.surfaces.{0}'.format(module))
|
||||||
starting_surface = 'title'
|
starting_surface = 'title'
|
||||||
@ -66,7 +66,7 @@ def start_game(resolution=240):
|
|||||||
next_surface = surface.next_surface
|
next_surface = surface.next_surface
|
||||||
additional_args = surface.additional_args
|
additional_args = surface.additional_args
|
||||||
if next_surface not in valid_surfaces:
|
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,
|
surface = surface_modules.get(next_surface).Surface((game_res, game_res), resources_dir,
|
||||||
game_fps, **additional_args)
|
game_fps, **additional_args)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
BIN
pocket_friends/resources/images/dev_bg.png
Normal file
BIN
pocket_friends/resources/images/dev_bg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
Loading…
Reference in New Issue
Block a user