From e64111b0c26bb7f2d8e362c2072c51519c7ad78e Mon Sep 17 00:00:00 2001 From: Fabian Hoppe Date: Wed, 29 Mar 2023 14:59:37 +0200 Subject: [PATCH 1/3] Implement Main Menu and connection to level selection --- .../selection/LevelSelectionScreenManager.py | 6 ++++ .../level/selection/MainMenuScreenManager.py | 30 +++++++++++++++++-- project/main.py | 5 +++- 3 files changed, 37 insertions(+), 4 deletions(-) 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 From ebfa89e3748576cc44a6f29e7232f3f62fc00f0e Mon Sep 17 00:00:00 2001 From: Skyball2000 Date: Wed, 29 Mar 2023 15:01:46 +0200 Subject: [PATCH 2/3] Fixed level selection --- .../selection/LevelSelectionScreenManager.py | 55 ++++++++++++++++++- project/main.py | 2 +- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/project/level/selection/LevelSelectionScreenManager.py b/project/level/selection/LevelSelectionScreenManager.py index c36c520..4b659be 100644 --- a/project/level/selection/LevelSelectionScreenManager.py +++ b/project/level/selection/LevelSelectionScreenManager.py @@ -77,9 +77,58 @@ class LevelSelectionScreenManager(ScreenManager): label.set_text('') label.click_listeners = [] - for id, level in enumerate(self.levels_by_theme[self.selected_theme]): - self.level_labels[id].set_text(level.name) - self.level_labels[id].add_click_listener(lambda click: self.select_level(click, level)) + levels = self.levels_by_theme[self.selected_theme] + + if len(levels) > 0: + self.level_labels[0].set_text(levels[0].name) + self.level_labels[0].add_click_listener( + lambda click: self.select_level(click, levels[0]) + ) + if len(levels) > 1: + self.level_labels[1].set_text(levels[1].name) + self.level_labels[1].add_click_listener( + lambda click: self.select_level(click, levels[1]) + ) + if len(levels) > 2: + self.level_labels[2].set_text(levels[2].name) + self.level_labels[2].add_click_listener( + lambda click: self.select_level(click, levels[2]) + ) + if len(levels) > 3: + self.level_labels[3].set_text(levels[3].name) + self.level_labels[3].add_click_listener( + lambda click: self.select_level(click, levels[3]) + ) + if len(levels) > 4: + self.level_labels[4].set_text(levels[4].name) + self.level_labels[4].add_click_listener( + lambda click: self.select_level(click, levels[4]) + ) + if len(levels) > 5: + self.level_labels[5].set_text(levels[5].name) + self.level_labels[5].add_click_listener( + lambda click: self.select_level(click, levels[5]) + ) + if len(levels) > 6: + self.level_labels[6].set_text(levels[6].name) + self.level_labels[6].add_click_listener( + lambda click: self.select_level(click, levels[6]) + ) + if len(levels) > 7: + self.level_labels[7].set_text(levels[7].name) + self.level_labels[7].add_click_listener( + lambda click: self.select_level(click, levels[7]) + ) + if len(levels) > 8: + self.level_labels[8].set_text(levels[8].name) + self.level_labels[8].add_click_listener( + lambda click: self.select_level(click, levels[8]) + ) + if len(levels) > 9: + self.level_labels[9].set_text(levels[9].name) + self.level_labels[9].add_click_listener( + lambda click: self.select_level(click, levels[9]) + ) def destroy(self): super().destroy() diff --git a/project/main.py b/project/main.py index 03ffede..f22b1d6 100644 --- a/project/main.py +++ b/project/main.py @@ -138,7 +138,7 @@ class MainLoop: for event in pygame_events: if event.type == pygame.QUIT: pygame.quit() - quit() + exit() self.screen.fill((0, 0, 0)) From e85b19686d505118771daa014864b21642ca8f7e Mon Sep 17 00:00:00 2001 From: Erenando Date: Wed, 29 Mar 2023 15:04:22 +0200 Subject: [PATCH 3/3] Jumping is now possible with spacebar --- project/data/levels/level-06.csv | 2 +- project/data/levels/levels.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/project/data/levels/level-06.csv b/project/data/levels/level-06.csv index a7c6c9e..5ab0a42 100644 --- a/project/data/levels/level-06.csv +++ b/project/data/levels/level-06.csv @@ -36,7 +36,7 @@ #,#,#,#,#,#,#,#,#,#,#,,,,,,,,,,,,,#,#,#,#,#,#,#,#,#,#,#,,,,,,,,,,,,,,,,,,,,,,,,,,# #,#,#,#,#,#,#,#,#,#,#,,,,,,,,,,,,,#,#,#,#,#,#,#,#,#,#,#,,,,,,,,,,,,,,,,,,,,,,,,,,# #,#,#,#,#,#,#,#,#,#,#,,,,,,,,,,,,,#,#,#,#,#,#,#,#,#,#,#,,,,,,,,,,,,,,,,,,,,,,,,,,# -#,#,#,#,#,#,#,#,#,#,#,S,S,S,S,S,S,S,S,S,S,S,S,S,#,#,#,#,#,#,#,#,#,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,# +#,#,#,#,#,#,#,#,#,#,#,S,S,S,S,S,S,S,S,S,S,S,S,#,#,#,#,#,#,#,#,#,#,#,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,# #,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,# ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, AG,11,id=lever_1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, diff --git a/project/data/levels/levels.json b/project/data/levels/levels.json index c99a025..9fb032a 100644 --- a/project/data/levels/levels.json +++ b/project/data/levels/levels.json @@ -8,7 +8,7 @@ }, { "name": "level-01", - "theme": "castle", + "theme": "cave", "abilities": [ ], "file": "level-01.csv" @@ -22,14 +22,14 @@ }, { "name": "level-03", - "theme": "castle", + "theme": "cave", "abilities": [ ], "file": "level-03.csv" }, { "name": "level-04", - "theme": "castle", + "theme": "cave", "abilities": [ ], "file": "level-04.csv"