2023-03-29 14:09:05 +02:00
|
|
|
from level.Level import Level
|
|
|
|
from level.elements.static.StaticLevelElement import StaticLevelElement
|
|
|
|
from physics.SpriteManager import SpriteManager
|
|
|
|
from sprite.SpritesheetManager import SpritesheetManager
|
|
|
|
|
2023-03-29 15:50:00 +02:00
|
|
|
from project.physics.TickData import TickData
|
|
|
|
|
2023-03-29 14:09:05 +02:00
|
|
|
BLOCK_TYPES = {
|
|
|
|
'A': 'staubsauger'
|
|
|
|
}
|
|
|
|
|
2023-03-29 15:50:00 +02:00
|
|
|
|
2023-03-29 15:19:37 +02:00
|
|
|
class VacuumCleanerElement(StaticLevelElement):
|
2023-03-29 14:09:05 +02:00
|
|
|
|
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-29 15:50:00 +02:00
|
|
|
self.animation_state_counter = 0
|
|
|
|
self.danger = True
|
|
|
|
self.danger_time = 30
|
|
|
|
self.off_time = 50
|
|
|
|
|
|
|
|
def tick(self, tick_data: TickData):
|
|
|
|
super().tick(tick_data)
|
|
|
|
self.animation_state_counter += tick_data.dt
|
|
|
|
if self.danger:
|
|
|
|
if self.animation_state_counter >= self.danger_time:
|
|
|
|
self.set_animation_state('off')
|
|
|
|
self.animation_state_counter = 0
|
|
|
|
self.danger = not self.danger
|
|
|
|
else:
|
|
|
|
if self.animation_state_counter >= self.off_time:
|
|
|
|
self.set_animation_state('on')
|
|
|
|
self.animation_state_counter = 0
|
|
|
|
self.danger = not self.danger
|
2023-03-29 14:09:05 +02:00
|
|
|
|
|
|
|
def load(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, level: Level):
|
|
|
|
block_type = BLOCK_TYPES[self.tile['name']]
|
|
|
|
self.spritesheet = spritesheet_manager.get_sheet(block_type)
|
2023-03-29 15:19:37 +02:00
|
|
|
self.set_animation_state('on')
|
2023-03-29 15:50:00 +02:00
|
|
|
|
|
|
|
self.position_scale.position = self.tile['position']
|