From 1f569181f9a9a533015c32136ecef77eaa6e75c4 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 19 Oct 2026 18:23:13 +0200 Subject: mob spwaning, corridors, node -v 22 --- DungeonSystem/scripts/Door.cs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'DungeonSystem/scripts/Door.cs') diff --git a/DungeonSystem/scripts/Door.cs b/DungeonSystem/scripts/Door.cs index 0a970b3..c30c462 100644 --- a/DungeonSystem/scripts/Door.cs +++ b/DungeonSystem/scripts/Door.cs @@ -11,17 +11,27 @@ public partial class Door : Node2D 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!; + private CollisionShape2D? _barrierCollision; + private Area2D? _triggerArea; + private AnimationPlayer? _animPlayer; public override void _Ready() { - _barrierCollision = GetNode("Barrier/CollisionShape2D"); - _triggerArea = GetNode("TriggerArea"); - _animPlayer = GetNode("AnimationPlayer"); + _barrierCollision = GetNodeOrNull("Barrier/CollisionShape2D") + ?? GetNodeOrNull("StaticBody2D/CollisionShape2D"); + _triggerArea = GetNodeOrNull("TriggerArea") + ?? GetNodeOrNull("Area2D"); + _animPlayer = GetNodeOrNull("AnimationPlayer"); + + if (_triggerArea != null) + { + _triggerArea.CollisionMask |= 1u << 1; + _triggerArea.Monitoring = true; + } + + if (_triggerArea != null) + _triggerArea.BodyEntered += OnBodyEntered; - _triggerArea.BodyEntered += OnBodyEntered; UnlockDoor(); } @@ -30,18 +40,18 @@ public partial class Door : Node2D if (CurrentState == DoorState.Locked) return; CurrentState = DoorState.Locked; - _barrierCollision.SetDeferred(CollisionShape2D.PropertyName.Disabled, false); + _barrierCollision?.SetDeferred(CollisionShape2D.PropertyName.Disabled, false); - if (_animPlayer.HasAnimation("lock")) + if (_animPlayer != null && _animPlayer.HasAnimation("lock")) _animPlayer.Play("lock"); } public void UnlockDoor() { CurrentState = DoorState.Open; - _barrierCollision.SetDeferred(CollisionShape2D.PropertyName.Disabled, true); + _barrierCollision?.SetDeferred(CollisionShape2D.PropertyName.Disabled, true); - if (_animPlayer.HasAnimation("unlock")) + if (_animPlayer != null && _animPlayer.HasAnimation("unlock")) _animPlayer.Play("unlock"); } @@ -52,4 +62,4 @@ public partial class Door : Node2D EmitSignal(SignalName.PlayerEnteredDoorway, this); } } -} \ No newline at end of file +} -- cgit v1.2.3