sep-pm-platformer/project/level/elements/static/SimpleBlockLevelElement.py

34 lines
1.2 KiB
Python
Raw Permalink Normal View History

2023-03-27 11:46:03 +02:00
import random
from level.Level import Level
from level.elements.static.StaticLevelElement import StaticLevelElement
2023-03-27 11:46:03 +02:00
from physics.SpriteManager import SpriteManager
from sprite.SpritesheetManager import SpritesheetManager
BLOCK_TYPES = {
'#': 'block_full',
'+': 'block_top',
'-': 'block_bottom',
'l': 'block_left',
'r': 'block_right',
'~': 'block_top_left',
2023-03-29 16:41:35 +02:00
'|': 'block_top_right',
'i': 'invisible'
2023-03-27 11:46:03 +02:00
}
class SimpleBlockLevelElement(StaticLevelElement):
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
super().__init__(tile, loaded_level, level_screen_manager)
2023-03-27 11:46:03 +02:00
def load(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, level: Level):
if self.tile['name'] in BLOCK_TYPES:
block_type = BLOCK_TYPES[self.tile['name']]
else:
block_type = 'block_full'
print(f"Unknown block type: {self.tile['name']} {self.tile['position']}")
2023-03-27 11:46:03 +02:00
self.spritesheet = spritesheet_manager.get_sheet(level.theme + '_' + block_type)
self.set_animation_state(str(random.randint(1, 3)))
self.position_scale.position = self.tile['position']