diff options
| author | alex <[email protected]> | 2026-11-09 11:46:51 +0100 |
|---|---|---|
| committer | alex <[email protected]> | 2026-11-09 11:46:51 +0100 |
| commit | 26972abbe2dd670d2afac067c548cfaf1da73b2d (patch) | |
| tree | 8d286077301ed39646c8ebaf9589a33c2f19c7ea /DungeonSystem/scripts/ZoneEntrance.cs | |
| parent | 5bc1a8224bb73dcac910e1f05f5e036b4f89ceb8 (diff) | |
| download | godot-testing-26972abbe2dd670d2afac067c548cfaf1da73b2d.tar.xz godot-testing-26972abbe2dd670d2afac067c548cfaf1da73b2d.zip | |
boos room
Diffstat (limited to 'DungeonSystem/scripts/ZoneEntrance.cs')
| -rw-r--r-- | DungeonSystem/scripts/ZoneEntrance.cs | 49 |
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; + } + } +} |
