From be7856168c790ef9dc6478cc429633b032ca09b5 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 15 Oct 2026 10:07:47 +0200 Subject: zas vela veci --- DungeonSystem/scripts/Door.cs | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 DungeonSystem/scripts/Door.cs (limited to 'DungeonSystem/scripts/Door.cs') diff --git a/DungeonSystem/scripts/Door.cs b/DungeonSystem/scripts/Door.cs new file mode 100644 index 0000000..0a970b3 --- /dev/null +++ b/DungeonSystem/scripts/Door.cs @@ -0,0 +1,55 @@ +using Godot; + +namespace DungeonSystem; + +[GlobalClass] +public partial class Door : Node2D +{ + [Signal] + public delegate void PlayerEnteredDoorwayEventHandler(Door door); + + public enum DoorState { Open, Locked } + public DoorState CurrentState { get; private set; } = DoorState.Open; + + private CollisionShape2D _barrierCollision = null!; + private Area2D _triggerArea = null!; + private AnimationPlayer _animPlayer = null!; + + public override void _Ready() + { + _barrierCollision = GetNode("Barrier/CollisionShape2D"); + _triggerArea = GetNode("TriggerArea"); + _animPlayer = GetNode("AnimationPlayer"); + + _triggerArea.BodyEntered += OnBodyEntered; + UnlockDoor(); + } + + public void LockDoor() + { + if (CurrentState == DoorState.Locked) return; + + CurrentState = DoorState.Locked; + _barrierCollision.SetDeferred(CollisionShape2D.PropertyName.Disabled, false); + + if (_animPlayer.HasAnimation("lock")) + _animPlayer.Play("lock"); + } + + public void UnlockDoor() + { + CurrentState = DoorState.Open; + _barrierCollision.SetDeferred(CollisionShape2D.PropertyName.Disabled, true); + + if (_animPlayer.HasAnimation("unlock")) + _animPlayer.Play("unlock"); + } + + private void OnBodyEntered(Node2D body) + { + if (CurrentState == DoorState.Open && body.IsInGroup("player")) + { + EmitSignal(SignalName.PlayerEnteredDoorway, this); + } + } +} \ No newline at end of file -- cgit v1.2.3