integrated dev menu into game with secret code
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import pygame
|
||||
|
||||
from collections import deque
|
||||
|
||||
class InputHandler:
|
||||
"""
|
||||
@@ -24,6 +24,12 @@ class InputHandler:
|
||||
self.clock = pygame_clock
|
||||
self.tick_check = tick_check
|
||||
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):
|
||||
"""
|
||||
@@ -37,6 +43,9 @@ class InputHandler:
|
||||
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.KEYUP, {'key': pressed_button}))
|
||||
self.dev_check.append(pressed_button)
|
||||
if len(self.dev_check) > len(self.dev_code):
|
||||
self.dev_check.popleft()
|
||||
else:
|
||||
pygame.event.post(pygame.event.Event(pygame.KEYDOWN, {'key': pressed_button}))
|
||||
pygame.event.post(pygame.event.Event(pygame.KEYUP, {'key': pressed_button}))
|
||||
@@ -70,3 +79,5 @@ class InputHandler:
|
||||
def update(self):
|
||||
"""Run either the GPIO handler or the keyboard handler to check for input and create events."""
|
||||
self.handle_keyboard()
|
||||
if self.dev_code == self.dev_check:
|
||||
self.dev_found = True
|
||||
|
Reference in New Issue
Block a user