diff --git a/Resources/BossPhases/Marisa/marisa_ns1.tres b/Resources/BossPhases/Marisa/marisa_ns1.tres index 02b15971..4735ea43 100644 --- a/Resources/BossPhases/Marisa/marisa_ns1.tres +++ b/Resources/BossPhases/Marisa/marisa_ns1.tres @@ -15,6 +15,8 @@ Continuous = false [sub_resource type="Resource" id="Resource_q4pcc"] script = ExtResource("1_ys2v3") BulletScene = ExtResource("1_0bb8a") +_bulletLifeTime = 20.0 +_destroyOnCollision = false bulletSpeed = 30.0 bulletCount = 16 rotationSpeed = 4.0 diff --git a/Scenes/test.tscn b/Scenes/test.tscn index 293941ee..4e6eec67 100644 --- a/Scenes/test.tscn +++ b/Scenes/test.tscn @@ -122,7 +122,7 @@ ActivationType = 0 Targets = Array[NodePath]([NodePath("../Rumia")]) WaitForCompletion = true -[sub_resource type="Resource" id="Resource_sf3bq"] +[sub_resource type="Resource" id="Resource_o7jyd"] resource_local_to_scene = true script = ExtResource("49_0si7g") Target = NodePath(".") @@ -586,7 +586,7 @@ Events = Array[Object]([SubResource("Resource_068l7"), SubResource("Resource_l3n [node name="BossBattleStartScript" parent="." instance=ExtResource("43_kf3qc")] position = Vector2(-1487, -396) -Events = Array[Object]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_sf3bq")]) +Events = Array[Object]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_o7jyd")]) [node name="Enemy8" parent="." instance=ExtResource("47_u1ve6")] position = Vector2(-968, 206) diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index 5c4364bb..697a29be 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -8,6 +8,7 @@ using Godot.Collections; public partial class GameManager : Node2D { + public static GameManager Instance { get; private set;} private Hud _hud; private PlayerMovement _player; @@ -30,6 +31,8 @@ public partial class GameManager : Node2D private InventoryManager _inventoryManager { get; set; } + public MapStartData MapStartData { get; set; } + //private AlarmManager _alarmManager { get; set; } //public InventoryManager Inventory => _inventoryManager; @@ -45,6 +48,8 @@ public partial class GameManager : Node2D // Called when the node enters the scene tree for the first time. public override void _Ready() { + Instance = this; + _hud = GetNodeOrNull("HUD"); if (_hud == null) GD.Print("No HUD in scene."); @@ -73,7 +78,7 @@ public partial class GameManager : Node2D //_ = DelayPlayerSpawn(); - CallDeferred(nameof(DelayPlayerSpawn)); + CallDeferred(MethodName.DelayPlayerSpawn); } // Called every frame. 'delta' is the elapsed time since the previous frame. diff --git a/Scripts/GlobalState.cs b/Scripts/GlobalState.cs new file mode 100644 index 00000000..5371711f --- /dev/null +++ b/Scripts/GlobalState.cs @@ -0,0 +1,57 @@ +using Godot; + +public partial class GlobalState : Node +{ + public static GlobalState Instance { get; private set; } + + public Node CurrentScene { get; set; } + + public override void _Ready() + { + Instance = this; + + Viewport root = GetTree().Root; + // Using a negative index counts from the end, so this gets the last child node of `root`. + CurrentScene = root.GetChild(-1); + + + } + + public void GotoScene(string path) + { + // This function will usually be called from a signal callback, + // or some other function from the current scene. + // Deleting the current scene at this point is + // a bad idea, because it may still be executing code. + // This will result in a crash or unexpected behavior. + + // The solution is to defer the load to a later time, when + // we can be sure that no code from the current scene is running: + + CallDeferred(MethodName.DeferredGotoScene, path); + } + + public void DeferredGotoScene(string path) + { + // It is now safe to remove the current scene. + CurrentScene.Free(); + + // Load a new scene. + var nextScene = GD.Load(path); + + // Instance the new scene. + CurrentScene = nextScene.Instantiate(); + + // Add it to the active scene, as child of root. + GetTree().Root.AddChild(CurrentScene); + + // Optionally, to make it compatible with the SceneTree.change_scene_to_file() API. + GetTree().CurrentScene = CurrentScene; + } +} + +public class MapStartData +{ + public int EggIndex = 0; + +} \ No newline at end of file diff --git a/Scripts/PlayerMovement.cs b/Scripts/PlayerMovement.cs index 05a816b4..4586de9d 100644 --- a/Scripts/PlayerMovement.cs +++ b/Scripts/PlayerMovement.cs @@ -168,7 +168,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible _rightStickInput = Vector2.Zero; _isStrafing = false; - _gameManager = this.GetGameManager(); + _gameManager = GameManager.Instance; + + //_gameManager = this.GetGameManager(); _inventoryManager = this.GetInventoryManager(); _gameManager.GameStateChange += GameManagerOnGameStateChange; diff --git a/Scripts/UI/DebugMenu.cs b/Scripts/UI/DebugMenu.cs index 06471b78..a05dbdba 100644 --- a/Scripts/UI/DebugMenu.cs +++ b/Scripts/UI/DebugMenu.cs @@ -37,7 +37,8 @@ public partial class DebugMenu : Control private void ButtonOnPressed(string scene) { GD.Print("Button was pressed, now what"); - GetTree().ChangeSceneToFile(scene); + GlobalState.Instance.GotoScene(scene); + //GetTree().ChangeSceneToFile(scene); } diff --git a/project.godot b/project.godot index b4a1f076..2cdf2551 100644 --- a/project.godot +++ b/project.godot @@ -30,6 +30,7 @@ config/icon="res://icon.svg" DebugStats="res://Scenes/debug_stats.tscn" DebugGUI="*res://addons/DebugGUI/DebugGUI.cs" Dialogic="*res://addons/dialogic/Core/DialogicGameHandler.gd" +GlobalState="*res://Scripts/GlobalState.cs" [dialogic]