2023-03-27 18:37:30 +02:00
|
|
|
from abc import ABC
|
|
|
|
|
|
|
|
from level.elements.dynamic.DynamicLevelElement import DynamicLevelElement
|
|
|
|
from physics.CollisionDirection import CollisionDirection
|
|
|
|
from physics.TickData import TickData
|
|
|
|
|
|
|
|
|
|
|
|
class PushableLevelElement(DynamicLevelElement, ABC):
|
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 18:37:30 +02:00
|
|
|
|
|
|
|
if 'weight' in self.tile:
|
|
|
|
self.weight = float(self.tile['weight'])
|
|
|
|
else:
|
|
|
|
self.weight = 1.0
|
|
|
|
|
|
|
|
def tick(self, tick_data: TickData):
|
|
|
|
super().tick(tick_data)
|
|
|
|
|
|
|
|
collides_element = self.get_collides_with_direction(CollisionDirection.LEFT)
|
|
|
|
|
|
|
|
if collides_element:
|
|
|
|
self.motion = (self.motion[0] + self.weight, self.motion[1])
|
|
|
|
|
|
|
|
collides_element = self.get_collides_with_direction(CollisionDirection.RIGHT)
|
|
|
|
|
|
|
|
if collides_element:
|
|
|
|
self.motion = (self.motion[0] - self.weight, self.motion[1])
|