2023-03-27 11:46:03 +02:00
|
|
|
import random
|
|
|
|
|
|
|
|
from level.Level import Level
|
2023-03-27 18:37:30 +02:00
|
|
|
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 = {
|
2023-03-27 12:15:35 +02:00
|
|
|
'#': '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):
|
2023-03-29 15:40:15 +02:00
|
|
|
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):
|
2023-03-27 12:15:35 +02:00
|
|
|
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)))
|
2023-03-27 12:15:35 +02:00
|
|
|
self.position_scale.position = self.tile['position']
|