sep-pm-platformer/project/level/elements/dynamic/PushableLevelElement.py

29 lines
994 B
Python
Raw Normal View History

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):
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
super().__init__(tile, loaded_level, level_screen_manager)
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])