summaryrefslogtreecommitdiff
path: root/DungeonSystem/scripts/Door.cs
diff options
context:
space:
mode:
authoralex <[email protected]>2026-10-19 18:23:13 +0200
committeralex <[email protected]>2026-10-19 18:23:13 +0200
commit1f569181f9a9a533015c32136ecef77eaa6e75c4 (patch)
treebb1438d25dce0d6096eed27edad1aca2a44a66b2 /DungeonSystem/scripts/Door.cs
parenta5ae904a8b3a8f0f02889942b4ee81e85bd271d2 (diff)
downloadgodot-testing-1f569181f9a9a533015c32136ecef77eaa6e75c4.tar.xz
godot-testing-1f569181f9a9a533015c32136ecef77eaa6e75c4.zip
mob spwaning, corridors, node -v 22
Diffstat (limited to 'DungeonSystem/scripts/Door.cs')
-rw-r--r--DungeonSystem/scripts/Door.cs34
1 files changed, 22 insertions, 12 deletions
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<CollisionShape2D>("Barrier/CollisionShape2D");
- _triggerArea = GetNode<Area2D>("TriggerArea");
- _animPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
+ _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.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
+}