diff --git a/project/data/levels/levels.json b/project/data/levels/levels.json index 86e3acf..319eda6 100644 --- a/project/data/levels/levels.json +++ b/project/data/levels/levels.json @@ -7,7 +7,7 @@ "file": "playground.csv" }, { - "name": "0-tutorial", + "name": "tutorial", "theme": "tutorial", "abilities": [ ], diff --git a/project/data/sprites/intro_bg.png b/project/data/sprites/intro_bg.png index 4f70965..5ec681c 100644 Binary files a/project/data/sprites/intro_bg.png and b/project/data/sprites/intro_bg.png differ diff --git a/project/data/sprites/level_select_bg.png b/project/data/sprites/level_select_bg.png new file mode 100644 index 0000000..01e5104 Binary files /dev/null and b/project/data/sprites/level_select_bg.png differ diff --git a/project/level/elements/LoadedLevel.py b/project/level/elements/LoadedLevel.py index 49049ab..d069d5b 100644 --- a/project/level/elements/LoadedLevel.py +++ b/project/level/elements/LoadedLevel.py @@ -47,6 +47,12 @@ TILES = { 'i': InvisibleElement } +BACK_LAYER = [ +] +FRONT_LAYER = [ + 'M' +] + class LoadedLevel: def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager): @@ -57,6 +63,26 @@ class LoadedLevel: self.level_screen_manager = None def load_level(self, level: Level): + # create a wall of InvisibleElement around the level left and right + # block_left = SimpleBlockLevelElement({'name': '#', 'position': (30, 300)}, self, self.level_screen_manager) + # block_left.load(self.sprite_manager, self.spritesheet_manager, level) + # self.blocks.append(block_left) + # self.sprite_manager.add_ui_element(DrawLayers.OBJECTS_BACK, block_left) + + for i in range(0, 100): + block_left = InvisibleElement({'name': 'i', 'position': (-16, i * 32)}, self, self.level_screen_manager) + block_left.load(self.sprite_manager, self.spritesheet_manager, level) + self.blocks.append(block_left) + self.sprite_manager.add_ui_element(DrawLayers.OBJECTS_BACK, block_left) + + for i in range(0, 100): + block_right = InvisibleElement({'name': 'i', 'position': + (ConstantsParser.CONFIG.block_size[0] * ConstantsParser.CONFIG.level_size[0] + 4, i * 32)}, + self, self.level_screen_manager) + block_right.load(self.sprite_manager, self.spritesheet_manager, level) + self.blocks.append(block_right) + self.sprite_manager.add_ui_element(DrawLayers.OBJECTS_BACK, block_right) + for row_number, row in enumerate(level.tiles): for tile_number, tile in enumerate(row): world_position = (tile_number, row_number) @@ -71,6 +97,10 @@ class LoadedLevel: if name in TILES: element = TILES[name](tile, self, self.level_screen_manager) + if name in BACK_LAYER: + layer = DrawLayers.OBJECTS_BACK + elif name in FRONT_LAYER: + layer = DrawLayers.OBJECTS_FRONT elif name == 'C': ghost_character = PlayerSprite(self.spritesheet_manager.get_sheet("ghost_character")) @@ -81,7 +111,7 @@ class LoadedLevel: elif not name == '': print(f"Unknown tile at {position}: {name}") - element = UnknownTileLevelElement(tile, self, self.level_screen_manager) + element = UnknownTileLevelElement(tile, self , self.level_screen_manager) if element: self.blocks.append(element) diff --git a/project/level/selection/LevelScreenManager.py b/project/level/selection/LevelScreenManager.py index f8ef26a..86248cf 100644 --- a/project/level/selection/LevelScreenManager.py +++ b/project/level/selection/LevelScreenManager.py @@ -5,10 +5,11 @@ import pygame.time from level.Level import Level from level.elements.LoadedLevel import LoadedLevel 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.KeyManager import KeyManager +from ui_elements.TextLabel import TextLabel class LevelScreenManager(ScreenManager): @@ -21,6 +22,11 @@ class LevelScreenManager(ScreenManager): self.loaded_level.level_screen_manager = self self.loaded_level.load_level(self.level) + 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()) + def initialize(self): pass @@ -30,8 +36,11 @@ class LevelScreenManager(ScreenManager): def tick(self, tick_data: TickData): if tick_data.key_manager.is_keymap_down(KeyManager.KEY_ESCAPE): - self.main_loop.select_level_selection(self.level.theme) - pygame.time.delay(200) + self.back_to_level_selection() + pygame.time.delay(250) + + def back_to_level_selection(self): + self.main_loop.select_level_selection(self.level.theme) def player_death(self): self.main_loop.player_death(self.level) diff --git a/project/level/selection/LevelSelectionScreenManager.py b/project/level/selection/LevelSelectionScreenManager.py index 0c069c2..a7818cd 100644 --- a/project/level/selection/LevelSelectionScreenManager.py +++ b/project/level/selection/LevelSelectionScreenManager.py @@ -64,6 +64,11 @@ class LevelSelectionScreenManager(ScreenManager): self.theme_label.position_scale.scale = (0.5, 0.5) self.add_element(DrawLayers.UI, self.theme_label) + 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()) + for i in range(0, LABEL_COUNT): label = TextLabel(str(i), OFFSET[0] + 30, OFFSET[1] + 60 + i * 50, font_size=65) label.position_scale.scale = (0.5, 0.5) diff --git a/project/level/selection/MainMenuScreenManager.py b/project/level/selection/MainMenuScreenManager.py index 1ec6627..af6117a 100644 --- a/project/level/selection/MainMenuScreenManager.py +++ b/project/level/selection/MainMenuScreenManager.py @@ -25,8 +25,8 @@ class MainMenuScreenManager(ScreenManager): def initialize(self): 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, 70) - self.create_button("SCREEN SIZE", size[0] * 0.5, size[1] * 0.7, 40) + self.create_button("START", size[0] * 0.495, size[1] * 0.772, 38) + self.create_button("SCREEN SIZE", size[0] * 0.85, size[1] * 0.9, 20) def create_button(self, name: str, x_position, y_position, font_size): label = TextLabel(name, x_position, y_position, font_size, alignment="center") diff --git a/project/level/selection/OptionsScreenManager.py b/project/level/selection/OptionsScreenManager.py index 2f4b5f3..c0579e5 100644 --- a/project/level/selection/OptionsScreenManager.py +++ b/project/level/selection/OptionsScreenManager.py @@ -18,6 +18,11 @@ class OptionsScreenManager(ScreenManager): label.position_scale.scale = (1, 1) self.create_button(name, label) + 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()) + def create_button(self, name: str, label: TextLabel): if name == "SMALL": label.add_click_listener(lambda click: self.make_small_screen(click)) diff --git a/project/main.py b/project/main.py index 36633ff..db5d4be 100644 --- a/project/main.py +++ b/project/main.py @@ -22,12 +22,14 @@ BACKGROUND_IMAGES_UNSCALED = { 'tutorial': pygame.image.load('data/sprites/tutorial_bg.png'), 'castle': pygame.image.load('data/sprites/castle_bg.png'), 'cave': pygame.image.load('data/sprites/cave_bg.png'), + 'menu': pygame.image.load('data/sprites/intro_bg.png'), } BACKGROUND_IMAGES_SCALED = { 'tutorial': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['tutorial'], (1, 1)), 'castle': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['castle'], (1, 1)), 'cave': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['cave'], (1, 1)), + 'menu': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['menu'], (1, 1)), } @@ -53,7 +55,7 @@ class MainLoop: self.window_size: tuple[float, float] = (1, 1) pygame.init() - pygame.display.set_caption("PM GAME") + pygame.display.set_caption("Don't Get Busted") self.update_position_scale(self.screen_transform) @@ -176,6 +178,8 @@ class MainLoop: 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)) self.sprite_manager.draw(self.screen, self.screen_transform) pygame.display.update() diff --git a/project/physics/SpriteManager.py b/project/physics/SpriteManager.py index 85ddc00..812606d 100644 --- a/project/physics/SpriteManager.py +++ b/project/physics/SpriteManager.py @@ -12,11 +12,13 @@ from ui_elements.UiElement import UiElement class DrawLayers: BACKGROUND = 'background' LEVEL = 'level' + OBJECTS_BACK = 'objects_back' OBJECTS = 'objects' + OBJECTS_FRONT = 'objects_front' PLAYER = 'player' UI = 'ui' - DRAW_ORDER = [BACKGROUND, LEVEL, OBJECTS, PLAYER, UI] + DRAW_ORDER = [BACKGROUND, LEVEL, OBJECTS_BACK, OBJECTS, OBJECTS_FRONT, PLAYER, UI] class SpriteManager: diff --git a/project/physics/sprites/PlayerSprite.py b/project/physics/sprites/PlayerSprite.py index de72bb1..11114a7 100644 --- a/project/physics/sprites/PlayerSprite.py +++ b/project/physics/sprites/PlayerSprite.py @@ -53,7 +53,6 @@ class PlayerSprite(DynamicSprite): self.is_potentially_stuck = 0 if self.is_potentially_stuck == 2: - print('stuck') self.position_scale.position = (self.position_scale.position[0] - 5, self.position_scale.position[1]) self.is_potentially_stuck = 0