Used settings for keys
This commit is contained in:
parent
6e5cd9084b
commit
e3a1bf96c2
|
@ -4,6 +4,22 @@ from .interfaces import Map
|
|||
from .mapdisplay import MapDisplay
|
||||
from .settings import Settings
|
||||
from .term_manager import TermManager
|
||||
from enum import Enum, auto
|
||||
|
||||
|
||||
class GameMode(Enum):
|
||||
MAINMENU = auto()
|
||||
PLAY = auto()
|
||||
SETTINGS = auto()
|
||||
INVENTORY = auto()
|
||||
|
||||
|
||||
class KeyValues(Enum):
|
||||
UP = auto()
|
||||
DOWN = auto()
|
||||
LEFT = auto()
|
||||
RIGHT = auto()
|
||||
ENTER = auto()
|
||||
|
||||
|
||||
class Game:
|
||||
|
@ -11,6 +27,7 @@ class Game:
|
|||
|
||||
def init(self) -> None:
|
||||
Game.INSTANCE = self
|
||||
self.state = GameMode.MAINMENU
|
||||
self.settings = Settings()
|
||||
self.settings.load_settings()
|
||||
self.settings.write_settings()
|
||||
|
@ -34,17 +51,27 @@ class Game:
|
|||
screen.refresh()
|
||||
self.d.display(self.player.y, self.player.x)
|
||||
key = screen.getkey()
|
||||
self.handle_key_pressed(key)
|
||||
self.handle_key_pressed(self.translate_key(key))
|
||||
|
||||
def handle_key_pressed(self, key: str) -> None:
|
||||
# TODO load keys from settings
|
||||
if key == 'z' or key == 'KEY_UP':
|
||||
def translate_key(self, key:str) -> KeyValues:
|
||||
if key in (self.settings.KEY_DOWN_SECONDARY, self.settings.KEY_DOWN_PRIMARY):
|
||||
return KeyValues.DOWN
|
||||
elif key in (self.settings.KEY_LEFT_PRIMARY, self.settings.KEY_LEFT_SECONDARY):
|
||||
return KeyValues.LEFT
|
||||
elif key in (self.settings.KEY_RIGHT_PRIMARY, self.settings.KEY_RIGHT_SECONDARY):
|
||||
return KeyValues.RIGHT
|
||||
elif key in (self.settings.KEY_UP_PRIMARY, self.settings.KEY_UP_SECONDARY):
|
||||
return KeyValues.UP
|
||||
|
||||
def handle_key_pressed(self, key: KeyValues) -> None:
|
||||
|
||||
if key == KeyValues.UP:
|
||||
self.player.move_up()
|
||||
if key == 's' or key == 'KEY_DOWN':
|
||||
if key == KeyValues.DOWN:
|
||||
self.player.move_down()
|
||||
if key == 'q' or key == 'KEY_LEFT':
|
||||
if key == KeyValues.LEFT:
|
||||
self.player.move_left()
|
||||
if key == 'd' or key == 'KEY_RIGHT':
|
||||
if key == KeyValues.RIGHT:
|
||||
self.player.move_right()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue