refactor: improve keyboard input logic
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import yaml
|
||||
import pygame
|
||||
from typing import Tuple
|
||||
from typing import KeysView, Tuple
|
||||
|
||||
"""
|
||||
TODO description
|
||||
@@ -83,4 +83,23 @@ class TextGenerator:
|
||||
for char_ in text:
|
||||
if not char_.isspace():
|
||||
surface.blit(cls.sheet, (position[0] + x_position, position[1]), pygame.Rect(cls.characters[char_.upper()], (cls.glyph_size[0], cls.glyph_size[1])))
|
||||
x_position += cls.glyph_size[0]
|
||||
x_position += cls.glyph_size[0]
|
||||
|
||||
|
||||
"""
|
||||
TODO description
|
||||
"""
|
||||
class Controller:
|
||||
|
||||
keys_pressed = {}
|
||||
|
||||
@classmethod
|
||||
def key_down(cls, key: int) -> bool:
|
||||
prior_pressed_state = False if key not in cls.keys_pressed else cls.keys_pressed[key]
|
||||
cls.keys_pressed[key] = pygame.key.get_pressed()[key]
|
||||
|
||||
return cls.keys_pressed[key] and not prior_pressed_state
|
||||
|
||||
@classmethod
|
||||
def key_pressed(cls, key: int) -> bool:
|
||||
return pygame.key.get_pressed()[key]
|
||||
Reference in New Issue
Block a user