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

38 lines
1.5 KiB
Python

from level.Level import Level
from level.elements.InputLevelElement import InputLevelElement
from physics.CollisionDirection import CollisionDirection
from physics.SpriteManager import SpriteManager
from physics.TickData import TickData
from sprite.SpritesheetManager import SpritesheetManager
class LeverInputLevelElement(InputLevelElement):
def __init__(self, tile: dict, level: Level):
super().__init__(tile, level)
self.is_currently_stood_on = False
self.is_collider = False
self.register_collisions = True
def load(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, level: Level):
self.spritesheet = spritesheet_manager.get_sheet('lever')
self.set_animation_state('on' if self.emitter_state else 'off')
self.position_scale.position = self.tile['position']
def tick(self, tick_data: TickData):
super().tick(tick_data)
collisions = self.get_collides_with_direction(CollisionDirection.INSIDE)
# toggle active state when player/object is standing on it
if collisions and not self.is_currently_stood_on:
self.is_currently_stood_on = True
self.set_active(not self.emitter_state)
elif not collisions and self.is_currently_stood_on:
self.is_currently_stood_on = False
def set_active(self, active: bool):
self.emitter_state = active
self.set_animation_state('on' if self.emitter_state else 'off')