Added wall on left and right

main
Skyball2000 2023-03-29 17:12:31 +02:00
parent 10e6ae1260
commit 22fb3a3c34
3 changed files with 33 additions and 2 deletions

View File

@ -47,6 +47,12 @@ TILES = {
'i': InvisibleElement 'i': InvisibleElement
} }
BACK_LAYER = [
]
FRONT_LAYER = [
'M'
]
class LoadedLevel: class LoadedLevel:
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager): def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager):
@ -57,6 +63,26 @@ class LoadedLevel:
self.level_screen_manager = None self.level_screen_manager = None
def load_level(self, level: Level): 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 row_number, row in enumerate(level.tiles):
for tile_number, tile in enumerate(row): for tile_number, tile in enumerate(row):
world_position = (tile_number, row_number) world_position = (tile_number, row_number)
@ -71,6 +97,10 @@ class LoadedLevel:
if name in TILES: if name in TILES:
element = TILES[name](tile, self, self.level_screen_manager) 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': elif name == 'C':
ghost_character = PlayerSprite(self.spritesheet_manager.get_sheet("ghost_character")) ghost_character = PlayerSprite(self.spritesheet_manager.get_sheet("ghost_character"))

View File

@ -12,11 +12,13 @@ from ui_elements.UiElement import UiElement
class DrawLayers: class DrawLayers:
BACKGROUND = 'background' BACKGROUND = 'background'
LEVEL = 'level' LEVEL = 'level'
OBJECTS_BACK = 'objects_back'
OBJECTS = 'objects' OBJECTS = 'objects'
OBJECTS_FRONT = 'objects_front'
PLAYER = 'player' PLAYER = 'player'
UI = 'ui' UI = 'ui'
DRAW_ORDER = [BACKGROUND, LEVEL, OBJECTS, PLAYER, UI] DRAW_ORDER = [BACKGROUND, LEVEL, OBJECTS_BACK, OBJECTS, OBJECTS_FRONT, PLAYER, UI]
class SpriteManager: class SpriteManager:

View File

@ -53,7 +53,6 @@ class PlayerSprite(DynamicSprite):
self.is_potentially_stuck = 0 self.is_potentially_stuck = 0
if self.is_potentially_stuck == 2: if self.is_potentially_stuck == 2:
print('stuck')
self.position_scale.position = (self.position_scale.position[0] - 5, self.position_scale.position[1]) self.position_scale.position = (self.position_scale.position[0] - 5, self.position_scale.position[1])
self.is_potentially_stuck = 0 self.is_potentially_stuck = 0