sep-pm-platformer/project/level/elements/LoadedLevel.py

39 lines
1.8 KiB
Python

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 = (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_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']))
def destroy_level(self):
del self.blocks