using Godot; using System; public partial class LevelManager : Node { Node2D StartNode; Node2D EndNode; Node2D Player; string EndType = "nothing"; public override void _Ready() { GetTree().Root.GetNode("CommonData").CurrentHealth = GetTree().Root.GetNode("CommonData").MaxHealth; StartNode = GetParent().GetNode("StartNode"); EndNode = GetParent().GetNode("EndNode"); Player = GetParent().GetNode("Player"); // Play into animation GetParent().GetNode("ScreenAnimations").GetNode("LevelStartAssets").GetNode("LevelStart").CurrentAnimation = "default"; GetParent().GetNode("ScreenAnimations").GetNode("LevelStartAssets").Reparent(GetTree().Root.GetNode("Camera").GetNode("Camera2D")); GetTree().Root.GetNode("Camera").GetNode("Camera2D").GetNode("LevelStartAssets").GlobalPosition = GetTree().Root.GetNode("Camera").GetNode("Camera2D").GlobalPosition; GetTree().Root.GetNode("Camera").GetNode("Camera2D").GetNode("LevelStartAssets").Visible = true; } public override void _Process(double delta) { // Manage conditions to end the level if (EndType == "nothing") { // Death if (GetTree().Root.GetNode("CommonData").CurrentHealth <= 0) { EndManager("Death"); EndType = "Death"; } // Success if (GetParent().HasNode("Player") && Player.GlobalPosition.DistanceTo(EndNode.GlobalPosition) <= 16) { EndManager("Success"); EndType = "Success"; } } } public void EndManager(string EndType) { switch (EndType) { case "Death": // Player Died //Player.QueueFree(); // Go back to main menu (Replace with proper ending screen and then send back to main menu) GetNode("ChangeMenuInitiator").ChangeMenu("FAST", "MainMenu", GetParent()); break; case "Success": // Success // Remove the player to stop checking //Player.QueueFree(); // Add level completed to the hash set GetTree().Root.GetNode("CommonData").LevelsCompleted.Add(GetParent().Name); // Play exit animation GetParent().GetNode("ScreenAnimations").GetNode("LevelCompleteAssets").GetNode("LevelComplete").CurrentAnimation = "default"; GetParent().GetNode("ScreenAnimations").GetNode("LevelCompleteAssets").Reparent(GetTree().Root.GetNode("Camera").GetNode("Camera2D")); GetTree().Root.GetNode("Camera").GetNode("Camera2D").GetNode("LevelCompleteAssets").GlobalPosition = GetTree().Root.GetNode("Camera").GetNode("Camera2D").GlobalPosition; GetTree().Root.GetNode("Camera").GetNode("Camera2D").GetNode("LevelCompleteAssets").Visible = true; // Go to exit cutscene after exit animation is complete var LevelName = (string)GetParent().Name; var LevelNumber = LevelName.Split("Level"); GetNode("ChangeMenuInitiator").ChangeMenu("SLOW", $"Cutscenes/ExitCutscene{LevelNumber[0]}", GetParent()); break; default: break; } } }