From 2bc88f34f4e30e5692a3d12cd851e22e28bc3e57 Mon Sep 17 00:00:00 2001 From: Skyball2000 Date: Wed, 29 Mar 2023 14:01:55 +0200 Subject: [PATCH] Background image --- project/level/elements/LoadedLevel.py | 7 +++++-- project/main.py | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/project/level/elements/LoadedLevel.py b/project/level/elements/LoadedLevel.py index a019263..611ac21 100644 --- a/project/level/elements/LoadedLevel.py +++ b/project/level/elements/LoadedLevel.py @@ -61,6 +61,7 @@ class LoadedLevel: name = tile['name'] element = None + layer = DrawLayers.OBJECTS if name in TILES: element = TILES[name](tile, self) @@ -68,7 +69,9 @@ class LoadedLevel: elif name == 'C': ghost_character = PlayerSprite(self.spritesheet_manager.get_sheet("ghost_character")) ghost_character.position_scale = PositionScale((position[0], position[1]), (1, 1)) - self.sprite_manager.add_ui_element(DrawLayers.OBJECTS, ghost_character) + layer = DrawLayers.PLAYER + self.blocks.append(ghost_character) + self.sprite_manager.add_ui_element(layer, ghost_character) elif not name == '': print(f"Unknown tile at {position}: {name}") @@ -76,7 +79,7 @@ class LoadedLevel: if element: self.blocks.append(element) - self.sprite_manager.add_ui_element(DrawLayers.OBJECTS, element) + self.sprite_manager.add_ui_element(layer, element) element.load(self.sprite_manager, self.spritesheet_manager, level) self.elements_by_id[element.id] = element diff --git a/project/main.py b/project/main.py index 8097e6f..76d3839 100644 --- a/project/main.py +++ b/project/main.py @@ -4,7 +4,6 @@ import pygame from level.Level import Level from level.LevelManager import LevelManager -from level.elements.LoadedLevel import LoadedLevel from level.selection.LevelScreenManager import LevelScreenManager from level.selection.LevelSelectionScreenManager import LevelSelectionScreenManager from level.selection.MainMenuScreenManager import MainMenuScreenManager @@ -17,18 +16,17 @@ from sprite.SpritesheetManager import SpritesheetManager from ui_elements.ClickEvent import ClickEvent from ui_elements.KeyManager import KeyManager -what_to_run = 'level' - DEPRECATED_WIDTH = 12 * 71 * 1.5 DEPRECATED_HEIGHT = 12 * 40 * 1.5 -# Background to test for level design -test_background_castle = pygame.transform.scale(pygame.image.load('data/sprites/castle_bg.png'), - (DEPRECATED_WIDTH, DEPRECATED_HEIGHT)) - - -# test_background_castle = pygame.transform.scale(pygame.image.load('data/sprites/cave_bg.png'), (DEPRECATED_WIDTH, DEPRECATED_WIDTH)) -# test_background_tutorial = pygame.transform.scale(pygame.image.load('data/sprites/tutorial_bg.png'), (DEPRECATED_WIDTH, DEPRECATED_WIDTH)) +BACKGROUND_IMAGES = { + 'tutorial': pygame.transform.scale(pygame.image.load('data/sprites/tutorial_bg.png'), + (DEPRECATED_WIDTH, DEPRECATED_HEIGHT)), + 'castle': pygame.transform.scale(pygame.image.load('data/sprites/castle_bg.png'), + (DEPRECATED_WIDTH, DEPRECATED_HEIGHT)), + 'cave': pygame.transform.scale(pygame.image.load('data/sprites/cave_bg.png'), + (DEPRECATED_WIDTH, DEPRECATED_HEIGHT)), +} def apply_frame_rate(number: float, frame_rate: float = 30): @@ -145,6 +143,8 @@ class MainLoop: self.screen_manager.tick(tick_data) self.sprite_manager.tick(tick_data) + if self.level is not None: + self.screen.blit(BACKGROUND_IMAGES[self.level.theme], (0, 0)) self.sprite_manager.draw(self.screen, self.screen_transform) pygame.display.update()