diff --git a/project/level/Level.py b/project/level/Level.py index 3fb7a0c..73eeaa7 100644 --- a/project/level/Level.py +++ b/project/level/Level.py @@ -19,7 +19,7 @@ class Level: tiles.append([]) for item_number, item in enumerate(line): if item_number <= LEVEL_SIZE[0]: - tiles[line_number].append({'tile': item}) + tiles[line_number].append({'name': item}) else: print('Level is too wide:', item_number, '>', LEVEL_SIZE[0]) break diff --git a/project/level/LevelElementSymbols.py b/project/level/LevelElementSymbols.py index 6673b7d..f00a2b4 100644 --- a/project/level/LevelElementSymbols.py +++ b/project/level/LevelElementSymbols.py @@ -6,9 +6,51 @@ DYNAMIC = 'dynamic' class LevelElementSymbols: SOLID_BLOCK = { 'symbol': '#', - 'type': STATIC + 'type': STATIC, + 'sprite_id': '_block' + } + SOLID_BLOCK_LEFT = { + 'type': STATIC, + 'sprite_id': '_block_left' + } + SOLID_BLOCK_RIGHT = { + 'type': STATIC, + 'sprite_id': '_block_right' } AIR = { - 'symbol': '', - 'type': STATIC + 'type': STATIC, + 'sprite_id': '_air' } + GATE = { + 'type':STATIC, + 'sprite_id': '_gate' + } + GOAL_DOOR = { + 'type':STATIC, + 'sprite_id': '_goal_door' + } + SMALL_SPIKE = { + 'type': STATIC, + 'sprite_id': '_small_spike' + } + LEVER = { + 'type':STATIC, + 'sprite_id': '_lever' + } + PLAYER = { + 'type': DYNAMIC, + 'sprite_id': '_player' + } + + dict = { + '#': SOLID_BLOCK, + 'l': SOLID_BLOCK_RIGHT, + 'r': SOLID_BLOCK_LEFT, + '': AIR, + 'g': GATE, + 'd': GOAL_DOOR, + 'x': SMALL_SPIKE, + 'h': LEVER, + 'P': PLAYER + } + diff --git a/project/level/elements/BlockElement.py b/project/level/elements/BlockElement.py index 17dfc38..e1c346d 100644 --- a/project/level/elements/BlockElement.py +++ b/project/level/elements/BlockElement.py @@ -1,5 +1,7 @@ from level.elements.LevelElement import LevelElement +from sprite.StaticSprite import StaticSprite class BlockElement(LevelElement): - pass + def __init__(self, x_position : int, y_position : int, sprite : StaticSprite): + super().__init__(x_position, y_position, sprite) diff --git a/project/level/elements/InteractableElement.py b/project/level/elements/InteractableElement.py new file mode 100644 index 0000000..125d4fb --- /dev/null +++ b/project/level/elements/InteractableElement.py @@ -0,0 +1,9 @@ +from LevelElement import LevelElement +from sprite.StaticSprite import StaticSprite + + +class InteractableElement(LevelElement): + def __init__(self, x_position : int, y_position : int, sprite : StaticSprite, block_id : str, requires : list[str]): + super().__init__(x_position, y_position, sprite) + self.block_id = block_id + self.requires = requires diff --git a/project/level/elements/LevelElement.py b/project/level/elements/LevelElement.py index 522506d..951cd3a 100644 --- a/project/level/elements/LevelElement.py +++ b/project/level/elements/LevelElement.py @@ -1,2 +1,9 @@ +from sprite.StaticSprite import StaticSprite + class LevelElement: - pass + def __init__(self,x_position : int, y_position : int, sprite : StaticSprite): + self.x_position = x_position + self.y_position = y_position + self.sprite = sprite + + diff --git a/project/level/elements/LoadedLevel.py b/project/level/elements/LoadedLevel.py index 8c95cd1..e8ca47c 100644 --- a/project/level/elements/LoadedLevel.py +++ b/project/level/elements/LoadedLevel.py @@ -1,23 +1,39 @@ from level.Level import Level +from level.LevelElementSymbols import LevelElementSymbols +from level.elements.BlockElement import BlockElement +from level.elements.InteractableElement import InteractableElement from physics.SpriteManager import SpriteManager, DrawLayers from sprite.SpritesheetManager import SpritesheetManager from sprite.StaticSprite import StaticSprite -BLOCK_SIZE = (16, 16) - - +BLOCK_SIZE = (12, 12) class LoadedLevel: def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager): self.sprite_manager = sprite_manager self.spritesheet_manager = spritesheet_manager + self.blocks = [] def load_level(self, level: Level): - for row in level.tiles: - for tile in row: - pass + for row_number, row in enumerate(level.tiles): + self.blocks.append([]) + for tile_number, tile in enumerate(row): + x_position = row_number * BLOCK_SIZE[0] + y_position = tile_number * BLOCK_SIZE[1] + if LevelElementSymbols.dict[tile] != LevelElementSymbols.PLAYER and LevelElementSymbols.dict[tile] != LevelElementSymbols.AIR: + sprite = StaticSprite(self.spritesheet_manager.get_sheet(level.theme + LevelElementSymbols.dict[tile]['sprite_id'])) + sprite.position_scale.position = (x_position, y_position) + sprite.set_animation_state('1') + self.sprite_manager.add_ui_element(DrawLayers.OBJECTS, sprite) + if(tile['id'] is None): + self.blocks[row_number].append(BlockElement(x_position, y_position, sprite)) + else: + self.blocks[row_number].append(InteractableElement(x_position, y_position, sprite,tile['id'], tile['requirements'])) - sprite = StaticSprite(self.spritesheet_manager.get_sheet('test_1')) - sprite.position_scale.position = (1, 1) - sprite.set_animation_state('idle') - self.sprite_manager.add_ui_element(DrawLayers.OBJECTS, None) + + + + + + def destroy_level(self): + del self.blocks \ No newline at end of file