Back to menu by pressing space button
This commit is contained in:
parent
7e92086601
commit
259bde81a4
|
@ -1,6 +1,7 @@
|
|||
import sys
|
||||
from typing import Any
|
||||
|
||||
from .display.display import Display
|
||||
from .display.mapdisplay import MapDisplay
|
||||
from .display.menudisplay import MenuDisplay
|
||||
from .display.texturepack import TexturePack
|
||||
|
@ -24,9 +25,16 @@ class KeyValues(Enum):
|
|||
LEFT = auto()
|
||||
RIGHT = auto()
|
||||
ENTER = auto()
|
||||
SPACE = auto()
|
||||
|
||||
|
||||
class Game:
|
||||
map: Map
|
||||
player: Player
|
||||
menu_display: MenuDisplay
|
||||
map_display: MapDisplay
|
||||
current_display: Display
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.state = GameMode.MAINMENU
|
||||
self.main_menu = menus.MainMenu()
|
||||
|
@ -36,13 +44,13 @@ class Game:
|
|||
|
||||
def new_game(self, screen: Any) -> None:
|
||||
# TODO generate a new map procedurally
|
||||
self.m = Map.load("example_map.txt")
|
||||
self.map = Map.load("example_map.txt")
|
||||
self.player = Player()
|
||||
self.player.move(1, 6)
|
||||
self.m.add_entity(self.player)
|
||||
self.map.add_entity(self.player)
|
||||
self.menu_display = MenuDisplay(screen, self.main_menu, 0, 0)
|
||||
self.map_display = MapDisplay(
|
||||
screen, self.m, self.player,
|
||||
screen, self.map, self.player,
|
||||
TexturePack.get_pack(self.settings.TEXTURE_PACK))
|
||||
self.current_display = self.menu_display
|
||||
|
||||
|
@ -75,18 +83,32 @@ class Game:
|
|||
return KeyValues.UP
|
||||
elif key == self.settings.KEY_ENTER:
|
||||
return KeyValues.ENTER
|
||||
elif key == ' ':
|
||||
return KeyValues.SPACE
|
||||
|
||||
def handle_key_pressed(self, key: KeyValues) -> None:
|
||||
if self.state == GameMode.PLAY:
|
||||
self.handle_key_pressed_play(key)
|
||||
elif self.state == GameMode.MAINMENU:
|
||||
self.handle_key_pressed_main_menu(key)
|
||||
elif self.state == GameMode.SETTINGS:
|
||||
self.handle_key_pressed_settings(key)
|
||||
self.current_display.refresh()
|
||||
|
||||
def handle_key_pressed_play(self, key: KeyValues) -> None:
|
||||
if key == KeyValues.UP:
|
||||
self.player.move_up()
|
||||
if key == KeyValues.DOWN:
|
||||
elif key == KeyValues.DOWN:
|
||||
self.player.move_down()
|
||||
if key == KeyValues.LEFT:
|
||||
elif key == KeyValues.LEFT:
|
||||
self.player.move_left()
|
||||
if key == KeyValues.RIGHT:
|
||||
elif key == KeyValues.RIGHT:
|
||||
self.player.move_right()
|
||||
if self.state == GameMode.MAINMENU:
|
||||
elif key == KeyValues.SPACE:
|
||||
self.state = GameMode.MAINMENU
|
||||
self.current_display = self.menu_display
|
||||
|
||||
def handle_key_pressed_main_menu(self, key: KeyValues) -> None:
|
||||
if key == KeyValues.DOWN:
|
||||
self.main_menu.go_down()
|
||||
if key == KeyValues.UP:
|
||||
|
@ -100,4 +122,8 @@ class Game:
|
|||
self.state = GameMode.SETTINGS
|
||||
elif option == menus.MainMenuValues.EXIT:
|
||||
sys.exit(0)
|
||||
self.current_display.refresh()
|
||||
|
||||
def handle_key_pressed_settings(self, key: KeyValues) -> None:
|
||||
if key == KeyValues.SPACE:
|
||||
self.state = GameMode.MAINMENU
|
||||
self.current_display = self.menu_display
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from enum import Enum, auto
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue