summaryrefslogtreecommitdiff
path: root/DungeonSystem/scripts/ZoneEntrance.cs
diff options
context:
space:
mode:
Diffstat (limited to 'DungeonSystem/scripts/ZoneEntrance.cs')
-rw-r--r--DungeonSystem/scripts/ZoneEntrance.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/DungeonSystem/scripts/ZoneEntrance.cs b/DungeonSystem/scripts/ZoneEntrance.cs
new file mode 100644
index 0000000..0bb0911
--- /dev/null
+++ b/DungeonSystem/scripts/ZoneEntrance.cs
@@ -0,0 +1,49 @@
+using Godot;
+
+namespace DungeonSystem;
+
+public partial class ZoneEntrance : Node2D
+{
+ [Export] public string NextZoneScenePath { get; set; } = "res://zones/zone2/world.tscn";
+
+ private Area2D? _triggerArea;
+ private bool _isTransitioning;
+
+ public override void _Ready()
+ {
+ _triggerArea = GetNodeOrNull<Area2D>("Area2D");
+ if (_triggerArea == null)
+ {
+ GD.PrintErr("[ZoneEntrance] Missing Area2D trigger.");
+ return;
+ }
+
+ _triggerArea.CollisionMask |= 1u << 1;
+ _triggerArea.Monitoring = true;
+ _triggerArea.BodyEntered += OnBodyEntered;
+ }
+
+ private void OnBodyEntered(Node2D body)
+ {
+ if (_isTransitioning || !body.IsInGroup("player"))
+ {
+ return;
+ }
+
+ _isTransitioning = true;
+
+ if (!ResourceLoader.Exists(NextZoneScenePath))
+ {
+ GD.PrintErr($"[ZoneEntrance] Next zone scene does not exist: {NextZoneScenePath}");
+ _isTransitioning = false;
+ return;
+ }
+
+ Error changeResult = GetTree().ChangeSceneToFile(NextZoneScenePath);
+ if (changeResult != Error.Ok)
+ {
+ GD.PrintErr($"[ZoneEntrance] Failed to change scene to {NextZoneScenePath}. Error: {changeResult}");
+ _isTransitioning = false;
+ }
+ }
+}