2023-03-27 11:46:03 +02:00
|
|
|
from level.Level import Level
|
|
|
|
from level.elements.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):
|
|
|
|
|
2023-03-27 12:51:44 +02:00
|
|
|
def __init__(self, tile: dict, level: Level):
|
|
|
|
super().__init__(tile, level)
|
|
|
|
self.is_currently_stood_on = False
|
|
|
|
|
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')
|
2023-03-27 12:15:35 +02:00
|
|
|
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 12:51:44 +02:00
|
|
|
collisions = self.get_collides_with_direction(CollisionDirection.TOP)
|
|
|
|
|
|
|
|
# debug 1: only activate when player is standing on it
|
|
|
|
if self.tile['debug'] == '1':
|
|
|
|
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)
|
|
|
|
|
|
|
|
# debug 2: toggle active state when player is standing on it
|
|
|
|
elif self.tile['debug'] == '2':
|
|
|
|
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')
|
|
|
|
|