2023-03-26 11:21:22 +02:00
|
|
|
from level.Level import Level
|
2023-03-26 14:12:46 +02:00
|
|
|
from level.LevelElementSymbols import LevelElementSymbols
|
|
|
|
from level.elements.BlockElement import BlockElement
|
2023-03-26 11:21:22 +02:00
|
|
|
from physics.SpriteManager import SpriteManager, DrawLayers
|
|
|
|
from sprite.SpritesheetManager import SpritesheetManager
|
|
|
|
|
2023-03-26 14:12:46 +02:00
|
|
|
BLOCK_SIZE = (12, 12)
|
2023-03-26 15:14:06 +02:00
|
|
|
|
|
|
|
|
2023-03-26 11:21:22 +02:00
|
|
|
class LoadedLevel:
|
|
|
|
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager):
|
|
|
|
self.sprite_manager = sprite_manager
|
|
|
|
self.spritesheet_manager = spritesheet_manager
|
2023-03-26 14:12:46 +02:00
|
|
|
self.blocks = []
|
2023-03-26 11:21:22 +02:00
|
|
|
|
|
|
|
def load_level(self, level: Level):
|
2023-03-26 14:12:46 +02:00
|
|
|
for row_number, row in enumerate(level.tiles):
|
|
|
|
for tile_number, tile in enumerate(row):
|
2023-03-26 15:14:06 +02:00
|
|
|
position = (tile_number * BLOCK_SIZE[0], row_number * BLOCK_SIZE[1])
|
2023-03-26 14:12:46 +02:00
|
|
|
|
2023-03-26 15:14:06 +02:00
|
|
|
tile_element = LevelElementSymbols.dict[tile['name']]
|
2023-03-26 14:12:46 +02:00
|
|
|
|
2023-03-26 15:14:06 +02:00
|
|
|
sprite = None
|
2023-03-26 14:12:46 +02:00
|
|
|
|
2023-03-26 15:14:06 +02:00
|
|
|
if tile_element in LevelElementSymbols.BLOCKS_LIST:
|
|
|
|
spritesheet = self.spritesheet_manager.get_sheet(level.theme + tile_element['sprite_id'])
|
|
|
|
sprite = BlockElement(spritesheet)
|
|
|
|
sprite.set_animation_state('1')
|
|
|
|
sprite.position_scale.position = position
|
2023-03-26 14:12:46 +02:00
|
|
|
|
2023-03-26 15:14:06 +02:00
|
|
|
# tile['id'], tile['requirements']
|
2023-03-26 11:21:22 +02:00
|
|
|
|
2023-03-26 15:14:06 +02:00
|
|
|
if sprite is not None:
|
|
|
|
self.sprite_manager.add_ui_element(DrawLayers.OBJECTS, sprite)
|
2023-03-26 11:21:22 +02:00
|
|
|
|
2023-03-26 14:12:46 +02:00
|
|
|
def destroy_level(self):
|
2023-03-26 15:14:06 +02:00
|
|
|
for block in self.blocks:
|
|
|
|
self.sprite_manager.remove_ui_element(block)
|
|
|
|
del self.blocks
|