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

33 lines
1.1 KiB
Python
Raw Normal View History

2023-03-27 11:46:03 +02:00
import random
from level.Level import Level
from level.elements.StaticLevelElement import StaticLevelElement
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',
'|': 'block_top_right'
2023-03-27 11:46:03 +02:00
}
class SimpleBlockLevelElement(StaticLevelElement):
def __init__(self, tile: dict, loaded_level):
super().__init__(tile, loaded_level)
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']