sep-pm-platformer/project/level/elements/static/ButtonInputLevelElement.py

39 lines
1.6 KiB
Python
Raw Normal View History

2023-03-27 11:46:03 +02:00
from level.Level import Level
from level.elements.static.InputLevelElement import InputLevelElement
2023-03-27 12:51:44 +02:00
from physics.CollisionDirection import CollisionDirection
2023-03-27 11:46:03 +02:00
from physics.SpriteManager import SpriteManager
from physics.TickData import TickData
from sprite.SpritesheetManager import SpritesheetManager
class ButtonInputLevelElement(InputLevelElement):
def __init__(self, tile: dict, level: Level, level_screen_manager: 'LevelScreenManager'):
super().__init__(tile, level, level_screen_manager)
2023-03-27 12:51:44 +02:00
self.is_currently_stood_on = False
2023-03-27 14:38:52 +02:00
self.is_collider = False
self.register_collisions = True
2023-03-27 11:46:03 +02:00
def load(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, level: Level):
self.spritesheet = spritesheet_manager.get_sheet('pressureplate')
self.set_animation_state('on' if self.emitter_state else 'off')
self.position_scale.position = self.tile['position']
2023-03-27 11:46:03 +02:00
def tick(self, tick_data: TickData):
2023-03-27 11:57:35 +02:00
super().tick(tick_data)
2023-03-27 14:38:52 +02:00
collisions = self.get_collides_with_direction(CollisionDirection.INSIDE)
# set active state only 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(True)
elif not collisions and self.is_currently_stood_on:
self.is_currently_stood_on = False
self.set_active(False)
2023-03-27 12:51:44 +02:00
def set_active(self, active: bool):
self.emitter_state = active
self.set_animation_state('on' if self.emitter_state else 'off')