2023-03-29 10:45:48 +02:00
|
|
|
from abc import abstractmethod
|
|
|
|
|
2023-03-29 16:20:54 +02:00
|
|
|
import pygame.time
|
|
|
|
|
2023-03-29 13:50:48 +02:00
|
|
|
from level.Level import Level
|
|
|
|
from level.elements.LoadedLevel import LoadedLevel
|
2023-03-29 10:45:48 +02:00
|
|
|
from level.selection.ScreenManager import ScreenManager
|
2023-03-29 17:44:53 +02:00
|
|
|
from physics.SpriteManager import SpriteManager, DrawLayers
|
2023-03-29 13:50:48 +02:00
|
|
|
from physics.TickData import TickData
|
2023-03-29 10:45:48 +02:00
|
|
|
from sprite.SpritesheetManager import SpritesheetManager
|
2023-03-29 13:50:48 +02:00
|
|
|
from ui_elements.KeyManager import KeyManager
|
2023-03-29 17:44:53 +02:00
|
|
|
from ui_elements.TextLabel import TextLabel
|
2023-03-29 10:45:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
class LevelScreenManager(ScreenManager):
|
2023-03-29 13:50:48 +02:00
|
|
|
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, main_loop,
|
|
|
|
level: Level):
|
2023-03-29 10:45:48 +02:00
|
|
|
super().__init__(sprite_manager, spritesheet_manager, main_loop)
|
|
|
|
|
2023-03-29 13:50:48 +02:00
|
|
|
self.level = level
|
|
|
|
self.loaded_level = LoadedLevel(sprite_manager, spritesheet_manager)
|
2023-03-29 15:40:15 +02:00
|
|
|
self.loaded_level.level_screen_manager = self
|
2023-03-29 13:50:48 +02:00
|
|
|
self.loaded_level.load_level(self.level)
|
|
|
|
|
2023-03-29 17:44:53 +02:00
|
|
|
self.back_button = TextLabel('BACK [ESC]', 635, 460, 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.back_to_level_selection())
|
|
|
|
|
2023-03-29 10:45:48 +02:00
|
|
|
def initialize(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def destroy(self):
|
|
|
|
super().destroy()
|
2023-03-29 13:50:48 +02:00
|
|
|
self.loaded_level.destroy_level()
|
|
|
|
|
|
|
|
def tick(self, tick_data: TickData):
|
|
|
|
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_ESCAPE):
|
2023-03-29 17:44:53 +02:00
|
|
|
self.back_to_level_selection()
|
|
|
|
pygame.time.delay(250)
|
|
|
|
|
|
|
|
def back_to_level_selection(self):
|
|
|
|
self.main_loop.select_level_selection(self.level.theme)
|
2023-03-29 15:40:15 +02:00
|
|
|
|
|
|
|
def player_death(self):
|
|
|
|
self.main_loop.player_death(self.level)
|
2023-03-29 16:08:12 +02:00
|
|
|
|
|
|
|
def player_success(self):
|
|
|
|
self.main_loop.player_success(self.level)
|