diff options
Diffstat (limited to 'DungeonSystem/scripts/Door.cs')
| -rw-r--r-- | DungeonSystem/scripts/Door.cs | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/DungeonSystem/scripts/Door.cs b/DungeonSystem/scripts/Door.cs index c30c462..e3ec5d6 100644 --- a/DungeonSystem/scripts/Door.cs +++ b/DungeonSystem/scripts/Door.cs @@ -5,61 +5,61 @@ namespace DungeonSystem; [GlobalClass] public partial class Door : Node2D { - [Signal] - public delegate void PlayerEnteredDoorwayEventHandler(Door door); + [Signal] + public delegate void PlayerEnteredDoorwayEventHandler(Door door); - public enum DoorState { Open, Locked } - public DoorState CurrentState { get; private set; } = DoorState.Open; + public enum DoorState { Open, Locked } + public DoorState CurrentState { get; private set; } = DoorState.Open; - private CollisionShape2D? _barrierCollision; - private Area2D? _triggerArea; - private AnimationPlayer? _animPlayer; + private CollisionShape2D? _barrierCollision; + private Area2D? _triggerArea; + private AnimationPlayer? _animPlayer; - public override void _Ready() - { - _barrierCollision = GetNodeOrNull<CollisionShape2D>("Barrier/CollisionShape2D") - ?? GetNodeOrNull<CollisionShape2D>("StaticBody2D/CollisionShape2D"); - _triggerArea = GetNodeOrNull<Area2D>("TriggerArea") - ?? GetNodeOrNull<Area2D>("Area2D"); - _animPlayer = GetNodeOrNull<AnimationPlayer>("AnimationPlayer"); + public override void _Ready() + { + _barrierCollision = GetNodeOrNull<CollisionShape2D>("Barrier/CollisionShape2D") + ?? GetNodeOrNull<CollisionShape2D>("StaticBody2D/CollisionShape2D"); + _triggerArea = GetNodeOrNull<Area2D>("TriggerArea") + ?? GetNodeOrNull<Area2D>("Area2D"); + _animPlayer = GetNodeOrNull<AnimationPlayer>("AnimationPlayer"); - if (_triggerArea != null) - { - _triggerArea.CollisionMask |= 1u << 1; - _triggerArea.Monitoring = true; - } + if (_triggerArea != null) + { + _triggerArea.CollisionMask |= 1u << 1; + _triggerArea.Monitoring = true; + } - if (_triggerArea != null) - _triggerArea.BodyEntered += OnBodyEntered; + if (_triggerArea != null) + _triggerArea.BodyEntered += OnBodyEntered; - UnlockDoor(); - } + UnlockDoor(); + } - public void LockDoor() - { - if (CurrentState == DoorState.Locked) return; + public void LockDoor() + { + if (CurrentState == DoorState.Locked) return; - CurrentState = DoorState.Locked; - _barrierCollision?.SetDeferred(CollisionShape2D.PropertyName.Disabled, false); + CurrentState = DoorState.Locked; + _barrierCollision?.SetDeferred(CollisionShape2D.PropertyName.Disabled, false); - if (_animPlayer != null && _animPlayer.HasAnimation("lock")) - _animPlayer.Play("lock"); - } + if (_animPlayer != null && _animPlayer.HasAnimation("lock")) + _animPlayer.Play("lock"); + } - public void UnlockDoor() - { - CurrentState = DoorState.Open; - _barrierCollision?.SetDeferred(CollisionShape2D.PropertyName.Disabled, true); + public void UnlockDoor() + { + CurrentState = DoorState.Open; + _barrierCollision?.SetDeferred(CollisionShape2D.PropertyName.Disabled, true); - if (_animPlayer != null && _animPlayer.HasAnimation("unlock")) - _animPlayer.Play("unlock"); - } + if (_animPlayer != null && _animPlayer.HasAnimation("unlock")) + _animPlayer.Play("unlock"); + } - private void OnBodyEntered(Node2D body) - { - if (CurrentState == DoorState.Open && body.IsInGroup("player")) - { - EmitSignal(SignalName.PlayerEnteredDoorway, this); - } - } + private void OnBodyEntered(Node2D body) + { + if (CurrentState == DoorState.Open && body.IsInGroup("player")) + { + EmitSignal(SignalName.PlayerEnteredDoorway, this); + } + } } |
