integrated dev menu into game with secret code
This commit is contained in:
parent
8a34ed7c01
commit
1c467371a8
@ -30,6 +30,7 @@ class GameSurface(pygame.Surface):
|
|||||||
self.game_fps = game_fps
|
self.game_fps = game_fps
|
||||||
self._input_handler = InputHandler(self._clock)
|
self._input_handler = InputHandler(self._clock)
|
||||||
self.additional_args = {}
|
self.additional_args = {}
|
||||||
|
self.dev_override = False
|
||||||
|
|
||||||
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()
|
||||||
@ -45,3 +46,7 @@ class GameSurface(pygame.Surface):
|
|||||||
self.sprites.draw(self)
|
self.sprites.draw(self)
|
||||||
|
|
||||||
self._input_handler.update()
|
self._input_handler.update()
|
||||||
|
if self._input_handler.dev_found:
|
||||||
|
self.next_surface = 'dev_menu'
|
||||||
|
self.dev_override = True
|
||||||
|
self.running = False
|
||||||
|
@ -4,6 +4,7 @@ import pocket_friends
|
|||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
valid_surfaces = [
|
valid_surfaces = [
|
||||||
|
'dev_menu',
|
||||||
'title',
|
'title',
|
||||||
'egg_select',
|
'egg_select',
|
||||||
'selection_info',
|
'selection_info',
|
||||||
@ -13,7 +14,8 @@ 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 = {'dev_menu': importlib.import_module('pocket_friends.development.{0}'.format('dev_menu'))}
|
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))
|
if module != 'dev_menu':
|
||||||
|
surface_modules[module] = importlib.import_module('pocket_friends.surfaces.{0}'.format(module))
|
||||||
starting_surface = 'title'
|
starting_surface = 'title'
|
||||||
|
|
||||||
# FPS for the game to run at.
|
# FPS for the game to run at.
|
||||||
@ -62,9 +64,13 @@ def start_game(resolution=240):
|
|||||||
window.blit(frame, frame.get_rect())
|
window.blit(frame, frame.get_rect())
|
||||||
|
|
||||||
if not surface.running:
|
if not surface.running:
|
||||||
next_surface = surface.next_surface
|
if surface.dev_override:
|
||||||
|
next_surface = 'dev_menu'
|
||||||
|
else:
|
||||||
|
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:
|
||||||
|
print(next)
|
||||||
next_surface = 'error_screen'
|
next_surface = 'error_screen'
|
||||||
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)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
from collections import deque
|
||||||
|
|
||||||
class InputHandler:
|
class InputHandler:
|
||||||
"""
|
"""
|
||||||
@ -24,6 +24,12 @@ class InputHandler:
|
|||||||
self.clock = pygame_clock
|
self.clock = pygame_clock
|
||||||
self.tick_check = tick_check
|
self.tick_check = tick_check
|
||||||
self.last_input_tick = 0
|
self.last_input_tick = 0
|
||||||
|
self.dev_check = deque()
|
||||||
|
self.dev_code = deque()
|
||||||
|
for button in [pygame.K_DOWN, pygame.K_DOWN, pygame.K_UP, pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT,
|
||||||
|
pygame.K_RIGHT, pygame.K_LEFT, pygame.K_a]:
|
||||||
|
self.dev_code.append(button)
|
||||||
|
self.dev_found = False
|
||||||
|
|
||||||
def create_event(self, pressed_button):
|
def create_event(self, pressed_button):
|
||||||
"""
|
"""
|
||||||
@ -37,6 +43,9 @@ class InputHandler:
|
|||||||
if pygame.time.get_ticks() - self.last_input_tick > self.clock.get_time() * 2:
|
if pygame.time.get_ticks() - self.last_input_tick > self.clock.get_time() * 2:
|
||||||
pygame.event.post(pygame.event.Event(pygame.KEYDOWN, {'key': pressed_button}))
|
pygame.event.post(pygame.event.Event(pygame.KEYDOWN, {'key': pressed_button}))
|
||||||
pygame.event.post(pygame.event.Event(pygame.KEYUP, {'key': pressed_button}))
|
pygame.event.post(pygame.event.Event(pygame.KEYUP, {'key': pressed_button}))
|
||||||
|
self.dev_check.append(pressed_button)
|
||||||
|
if len(self.dev_check) > len(self.dev_code):
|
||||||
|
self.dev_check.popleft()
|
||||||
else:
|
else:
|
||||||
pygame.event.post(pygame.event.Event(pygame.KEYDOWN, {'key': pressed_button}))
|
pygame.event.post(pygame.event.Event(pygame.KEYDOWN, {'key': pressed_button}))
|
||||||
pygame.event.post(pygame.event.Event(pygame.KEYUP, {'key': pressed_button}))
|
pygame.event.post(pygame.event.Event(pygame.KEYUP, {'key': pressed_button}))
|
||||||
@ -70,3 +79,5 @@ class InputHandler:
|
|||||||
def update(self):
|
def update(self):
|
||||||
"""Run either the GPIO handler or the keyboard handler to check for input and create events."""
|
"""Run either the GPIO handler or the keyboard handler to check for input and create events."""
|
||||||
self.handle_keyboard()
|
self.handle_keyboard()
|
||||||
|
if self.dev_code == self.dev_check:
|
||||||
|
self.dev_found = True
|
||||||
|
Loading…
Reference in New Issue
Block a user