From 22fb3a3c343a27f907cae3791bd63b0df1c5db28 Mon Sep 17 00:00:00 2001 From: Skyball2000 Date: Wed, 29 Mar 2023 17:12:31 +0200 Subject: [PATCH] Added wall on left and right --- project/level/elements/LoadedLevel.py | 30 +++++++++++++++++++++++++ project/physics/SpriteManager.py | 4 +++- project/physics/sprites/PlayerSprite.py | 1 - 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/project/level/elements/LoadedLevel.py b/project/level/elements/LoadedLevel.py index 49049ab..36b3f0d 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")) 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