diff --git a/project/level/selection/LevelSelectionScreenManager.py b/project/level/selection/LevelSelectionScreenManager.py index c36c520..d676e12 100644 --- a/project/level/selection/LevelSelectionScreenManager.py +++ b/project/level/selection/LevelSelectionScreenManager.py @@ -4,10 +4,12 @@ from level.Level import Level from level.LevelManager import LevelManager from level.selection.ScreenManager import ScreenManager from physics.SpriteManager import SpriteManager, DrawLayers +from physics.TickData import TickData from sprite.PositionScale import PositionScale from sprite.SpritesheetManager import SpritesheetManager from sprite.StaticSprite import StaticSprite from ui_elements.ClickEvent import ClickEvent +from ui_elements.KeyManager import KeyManager from ui_elements.TextLabel import TextLabel LABEL_COUNT = 10 @@ -83,3 +85,7 @@ class LevelSelectionScreenManager(ScreenManager): def destroy(self): super().destroy() + + def tick(self, tick_data: TickData): + if tick_data.key_manager.is_keymap_down(KeyManager.KEY_ESCAPE): + self.main_loop.select_main_menu() \ No newline at end of file diff --git a/project/level/selection/MainMenuScreenManager.py b/project/level/selection/MainMenuScreenManager.py index 726e599..a364539 100644 --- a/project/level/selection/MainMenuScreenManager.py +++ b/project/level/selection/MainMenuScreenManager.py @@ -1,16 +1,40 @@ from abc import abstractmethod from level.selection.ScreenManager import ScreenManager -from physics.SpriteManager import SpriteManager +from physics.SpriteManager import SpriteManager, DrawLayers +from physics.TickData import TickData from sprite.SpritesheetManager import SpritesheetManager +from ui_elements import CoordinateTransform +from ui_elements.KeyManager import KeyManager +from ui_elements.TextLabel import TextLabel +from ui_elements.ClickEvent import ClickEvent class MainMenuScreenManager(ScreenManager): - def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager,main_loop): + def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, main_loop): super().__init__(sprite_manager, spritesheet_manager, main_loop) + def go_to_menu(self, click): + if click.is_click_down(ClickEvent.CLICK_LEFT): + self.main_loop.select_level_selection() + + def go_to_options_screen(self, click): + self.destroy() + def initialize(self): - pass + size = CoordinateTransform.transform_screen_to_world(self.main_loop.window_size, self.main_loop.screen_transform) + + self.create_button("START", size[0] * 0.5, size[1] * 0.5) + self.create_button("OPTIONS", size[0] * 0.5, size[1] * 0.65) + + def create_button(self, name: str, x_position, y_position): + label = TextLabel(name, x_position, y_position, font_size=70, alignment="center") + self.add_element(DrawLayers.UI, label) + label.position_scale.scale = (1, 1) + if name == "START": + label.add_click_listener(lambda click: self.go_to_menu(click)) + elif name == "OPTIONS": + label.add_click_listener(lambda click: self.go_to_options_screen(click)) def destroy(self): super().destroy() diff --git a/project/main.py b/project/main.py index 03ffede..4520452 100644 --- a/project/main.py +++ b/project/main.py @@ -67,7 +67,7 @@ class MainLoop: self.screen_manager: Optional[ScreenManager] = None self.game_state = self.GAME_STATE_MENU - self.set_game_state(self.GAME_STATE_LEVEL_SELECTION) + self.set_game_state(self.GAME_STATE_MENU) self.level: Optional[Level] = None @@ -97,6 +97,9 @@ class MainLoop: if self.screen_manager is not None and isinstance(self.screen_manager, LevelSelectionScreenManager): self.screen_manager.select_theme(theme) + def select_main_menu(self): + self.set_game_state(self.GAME_STATE_MENU) + def set_game_state(self, game_state: str): self.game_state = game_state