diff --git a/project/level/selection/LevelMenu.py b/project/level/selection/LevelMenu.py deleted file mode 100644 index 599dbed..0000000 --- a/project/level/selection/LevelMenu.py +++ /dev/null @@ -1,53 +0,0 @@ -import pygame - -from level.Level import Level -from ui_elements.ColoredRectangleUiElement import ColoredRectangleUiElement -from ui_elements.ClickEvent import ClickEvent -from ui_elements.TextLabel import TextLabel - - -class LevelMenu: - - def __init__(self, levels: [Level], x_pos: float, y_pos: float, width: float, height: float, column_count: int): - super().__init__() - self.levels = levels - self.level_select_listener = lambda selected_level: None - self.level_text_labels = [] - self.width = width - self.height = height - self.column_count = column_count - - self.position = (x_pos, y_pos) - - self.create_level_text_labels() - self.background = ColoredRectangleUiElement(self.width, self.height, (100, 100, 100, 180)) - self.background.position_scale.position = self.position - - def create_level_text_labels(self): - current_text_label_position = [self.position[0], self.position[1]] - - for index, level in enumerate(self.levels): - text_label = TextLabel(level.name, - current_text_label_position[0], - current_text_label_position[1], - 60) - - text_label.position_scale.scale = (0.5, 0.5) - text_label.add_click_listener( - lambda click_event, selected_level=level: - self.handle_level_text_label_click(click_event, selected_level) - ) - self.level_text_labels.append(text_label) - - if (index + 1) % self.column_count == 0: - current_text_label_position[0] = self.position[0] - current_text_label_position[1] += self.height / (len(self.levels) / self.column_count) - else: - current_text_label_position[0] += self.width / self.column_count - - def handle_level_text_label_click(self, click_event: ClickEvent, level: Level): - if click_event.event.type == pygame.MOUSEBUTTONUP: - self.level_select_listener(level) - - def extract_level(self): - return self diff --git a/project/level/selection/LevelSelectionScreenManager.py b/project/level/selection/LevelSelectionScreenManager.py index a7818cd..cbebd5a 100644 --- a/project/level/selection/LevelSelectionScreenManager.py +++ b/project/level/selection/LevelSelectionScreenManager.py @@ -47,6 +47,10 @@ class LevelSelectionScreenManager(ScreenManager): if click.is_click_down(ClickEvent.CLICK_LEFT): self.main_loop.select_level(level) + def go_to_menu(self, click): + if click.is_click_down(ClickEvent.CLICK_LEFT): + self.main_loop.select_main_menu() + def initialize(self): arrow_left = StaticSprite(self.spritesheet_manager.get_sheet('ui_arrow')) arrow_left.set_animation_state('left') @@ -67,7 +71,7 @@ class LevelSelectionScreenManager(ScreenManager): self.back_button = TextLabel('BACK [ESC]', 610, 430, font_size=30) self.back_button.position_scale.scale = (0.5, 0.5) self.add_element(DrawLayers.UI, self.back_button) - self.back_button.add_click_listener(lambda click: self.main_loop.select_main_menu()) + self.back_button.add_click_listener(lambda click: self.go_to_menu(click)) for i in range(0, LABEL_COUNT): label = TextLabel(str(i), OFFSET[0] + 30, OFFSET[1] + 60 + i * 50, font_size=65) diff --git a/project/level/selection/MainMenuScreenManager.py b/project/level/selection/MainMenuScreenManager.py index ac40f4d..c11fffd 100644 --- a/project/level/selection/MainMenuScreenManager.py +++ b/project/level/selection/MainMenuScreenManager.py @@ -5,7 +5,6 @@ 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 diff --git a/project/level/selection/OptionsScreenManager.py b/project/level/selection/OptionsScreenManager.py index c0579e5..c481d57 100644 --- a/project/level/selection/OptionsScreenManager.py +++ b/project/level/selection/OptionsScreenManager.py @@ -4,6 +4,7 @@ from physics.TickData import TickData from sprite.PositionScale import PositionScale from sprite.SpritesheetManager import SpritesheetManager from ui_elements import CoordinateTransform +from ui_elements.ClickEvent import ClickEvent from ui_elements.KeyManager import KeyManager from ui_elements.TextLabel import TextLabel @@ -12,6 +13,10 @@ class OptionsScreenManager(ScreenManager): 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_main_menu() + def create_label(self, name: str, x_position, y_position, font_size): label = TextLabel(name, x_position, y_position, font_size, alignment="left") self.add_element(DrawLayers.UI, label) @@ -21,7 +26,7 @@ class OptionsScreenManager(ScreenManager): self.back_button = TextLabel('BACK [ESC]', 610, 430, font_size=30) self.back_button.position_scale.scale = (0.5, 0.5) self.add_element(DrawLayers.UI, self.back_button) - self.back_button.add_click_listener(lambda click: self.main_loop.select_main_menu()) + self.back_button.add_click_listener(lambda click: self.go_to_menu(click)) def create_button(self, name: str, label: TextLabel): if name == "SMALL": diff --git a/project/level/selection/WinScreenManager.py b/project/level/selection/WinScreenManager.py new file mode 100644 index 0000000..54b1a42 --- /dev/null +++ b/project/level/selection/WinScreenManager.py @@ -0,0 +1,27 @@ +from abc import abstractmethod + +from level.selection.ScreenManager import ScreenManager +from physics.SpriteManager import SpriteManager, DrawLayers +from physics.TickData import TickData +from sprite.SpritesheetManager import SpritesheetManager +from ui_elements import CoordinateTransform +from ui_elements.TextLabel import TextLabel +from ui_elements.ClickEvent import ClickEvent + + +class WinScreenManager(ScreenManager): + 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 initialize(self): + self.back_button = TextLabel('BACK [ESC]', 610, 430, font_size=30) + self.back_button.position_scale.scale = (0.5, 0.5) + self.add_element(DrawLayers.UI, self.back_button) + self.back_button.add_click_listener(lambda click: self.go_to_menu(click)) + + def destroy(self): + super().destroy() diff --git a/project/main.py b/project/main.py index 3c1c8a4..530298b 100644 --- a/project/main.py +++ b/project/main.py @@ -10,6 +10,7 @@ from level.selection.LevelSelectionScreenManager import LevelSelectionScreenMana from level.selection.MainMenuScreenManager import MainMenuScreenManager from level.selection.OptionsScreenManager import OptionsScreenManager from level.selection.ScreenManager import ScreenManager +from level.selection.WinScreenManager import WinScreenManager from physics import ConstantsParser from physics.SpriteManager import SpriteManager from physics.TickData import TickData @@ -24,6 +25,7 @@ BACKGROUND_IMAGES_UNSCALED = { 'cave': pygame.image.load('data/sprites/cave_bg.png'), 'menu': pygame.image.load('data/sprites/intro_bg.png'), 'level_select': pygame.image.load('data/sprites/level_select_bg.png'), + 'win': pygame.image.load('data/sprites/win_bg.png'), } BACKGROUND_IMAGES_SCALED = { @@ -32,6 +34,7 @@ BACKGROUND_IMAGES_SCALED = { 'cave': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['cave'], (1, 1)), 'menu': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['menu'], (1, 1)), 'level_select': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['level_select'], (1, 1)), + 'win': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['win'], (1, 1)), } @@ -52,6 +55,7 @@ class MainLoop: self.GAME_STATE_LEVEL_SELECTION = 'level_selection' self.GAME_STATE_LEVEL = 'level' self.GAME_STATE_OPTIONS = 'options' + self.GAME_STATE_WIN = 'win' self.screen_transform: PositionScale = PositionScale((0, 0), (1.5, 1.5)) self.window_size: tuple[float, float] = (1, 1) @@ -112,8 +116,7 @@ class MainLoop: if next_level is not None: self.select_level(next_level) else: - print('WINNNNNN!!') - self.select_main_menu() + self.set_game_state(self.GAME_STATE_WIN) def select_main_menu(self): self.set_game_state(self.GAME_STATE_MENU) @@ -143,6 +146,10 @@ class MainLoop: self.screen_manager = OptionsScreenManager( self.sprite_manager, self.spritesheet_manager, self, ) + elif self.game_state == self.GAME_STATE_WIN: + self.screen_manager = WinScreenManager( + self.sprite_manager, self.spritesheet_manager, self, + ) else: print('Invalid game state', self.game_state) @@ -178,12 +185,16 @@ class MainLoop: self.screen_manager.tick(tick_data) self.sprite_manager.tick(tick_data) + if self.level is not None and self.game_state == self.GAME_STATE_LEVEL: self.screen.blit(BACKGROUND_IMAGES_SCALED[self.level.theme], (0, 0)) elif self.game_state == self.GAME_STATE_MENU: self.screen.blit(BACKGROUND_IMAGES_SCALED['menu'], (0, 0)) - elif self.game_state == self.GAME_STATE_LEVEL_SELECTION: + elif self.game_state == self.GAME_STATE_LEVEL_SELECTION or self.game_state == self.GAME_STATE_OPTIONS: self.screen.blit(BACKGROUND_IMAGES_SCALED['level_select'], (0, 0)) + elif self.game_state == self.GAME_STATE_WIN: + self.screen.blit(BACKGROUND_IMAGES_SCALED['win'], (0, 0)) + self.sprite_manager.draw(self.screen, self.screen_transform) pygame.display.update() diff --git a/project/physics/sprites/PlayerSprite.py b/project/physics/sprites/PlayerSprite.py index 11114a7..dd41f32 100644 --- a/project/physics/sprites/PlayerSprite.py +++ b/project/physics/sprites/PlayerSprite.py @@ -53,7 +53,7 @@ class PlayerSprite(DynamicSprite): self.is_potentially_stuck = 0 if self.is_potentially_stuck == 2: - self.position_scale.position = (self.position_scale.position[0] - 5, self.position_scale.position[1]) + self.position_scale.position = (self.position_scale.position[0] - 2, self.position_scale.position[1] - 5) self.is_potentially_stuck = 0 if tick_data.key_manager.is_keymap_down(KeyManager.KEY_RIGHT):