From 26972abbe2dd670d2afac067c548cfaf1da73b2d Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 9 Nov 2026 11:46:51 +0100 Subject: boos room --- DungeonSystem/scripts/ZoneEntrance.cs | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 DungeonSystem/scripts/ZoneEntrance.cs (limited to 'DungeonSystem/scripts/ZoneEntrance.cs') 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"); + 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; + } + } +} -- cgit v1.2.3