Add next level command and refactor player retrieval in GameManager; update scene files for consistency
This commit is contained in:
@@ -148,5 +148,11 @@ public partial class ConsoleManager : Node
|
||||
}
|
||||
LimboConsole.Info("All skills have been deactivated.");
|
||||
}
|
||||
|
||||
[ConsoleCommand("next_level", "Advances the game to the next level.")]
|
||||
private void GoToNextLevelCommand()
|
||||
{
|
||||
_gameManager.OnLevelComplete();
|
||||
}
|
||||
|
||||
}
|
@@ -11,9 +11,13 @@ public partial class GameManager : Node
|
||||
{
|
||||
[Export] public Array<PackedScene> LevelScenes { get; set; } = [];
|
||||
|
||||
public PlayerController Player { get; set; }
|
||||
public PlayerController Player {
|
||||
get => GetPlayer();
|
||||
private set => _player = value;
|
||||
}
|
||||
|
||||
private List<Node> _sceneNodes = [];
|
||||
private PlayerController _player;
|
||||
|
||||
[Export]
|
||||
public Dictionary PlayerState { get; set; } = new()
|
||||
@@ -227,14 +231,14 @@ public partial class GameManager : Node
|
||||
|
||||
public PlayerController GetPlayer()
|
||||
{
|
||||
if (Player != null) return Player;
|
||||
if (_player != null) return _player;
|
||||
|
||||
foreach (var node in _sceneNodes)
|
||||
{
|
||||
if (node is not PlayerController player) continue;
|
||||
|
||||
Player = player;
|
||||
return Player;
|
||||
_player = player;
|
||||
return _player;
|
||||
}
|
||||
|
||||
GD.PrintErr("PlayerController not found in the scene tree.");
|
||||
|
@@ -54,14 +54,11 @@ VisibilityNotifier = NodePath("../VisibleOnScreenNotifier2D")
|
||||
[node name="LaunchComponent" type="Node2D" parent="."]
|
||||
script = ExtResource("7_67bn4")
|
||||
Speed = 200.0
|
||||
metadata/_custom_type_script = "uid://873un8agkyja"
|
||||
|
||||
[node name="StraightMotionComponent" type="Node" parent="." node_paths=PackedStringArray("LaunchComponent")]
|
||||
script = ExtResource("8_5ybdf")
|
||||
LaunchComponent = NodePath("../LaunchComponent")
|
||||
metadata/_custom_type_script = "uid://cvcnfrr1udco5"
|
||||
|
||||
[node name="ProjectileInitComponent" type="Node" parent="." node_paths=PackedStringArray("LaunchComponent")]
|
||||
script = ExtResource("9_b1kpf")
|
||||
LaunchComponent = NodePath("../LaunchComponent")
|
||||
metadata/_custom_type_script = "uid://bgty7040ams6s"
|
||||
|
@@ -1,9 +1,10 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://bcmx07k12gcsc"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://bcmx07k12gcsc"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_xusxl"]
|
||||
[ext_resource type="Script" uid="uid://cfw8nbrarex0i" path="res://scripts/components/BulletComponent.cs" id="2_xvjl0"]
|
||||
[ext_resource type="Script" uid="uid://2i7p7v135u7c" path="res://scripts/components/DamageComponent.cs" id="3_22hnt"]
|
||||
[ext_resource type="Script" uid="uid://xjq33vj0rol0" path="res://scripts/components/EffectInflictorComponent.cs" id="4_22hnt"]
|
||||
[ext_resource type="Resource" uid="uid://02l4nbnf2aft" path="res://resources/status_effect/ice.tres" id="4_xvjl0"]
|
||||
[ext_resource type="Script" uid="uid://cs6u3sh68f43j" path="res://scripts/components/OutOfScreenComponent.cs" id="5_xvjl0"]
|
||||
[ext_resource type="Script" uid="uid://c7p06t0eax8am" path="res://scripts/components/StraightMotionComponent.cs" id="6_6nrp8"]
|
||||
[ext_resource type="Script" uid="uid://cbexrnnj47f87" path="res://scripts/components/LaunchComponent.cs" id="7_oml3k"]
|
||||
@@ -36,9 +37,11 @@ scale = Vector2(0.8, 0.5)
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
|
||||
[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("Area")]
|
||||
[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("Area", "DamageTimer")]
|
||||
script = ExtResource("3_22hnt")
|
||||
Area = NodePath("..")
|
||||
StatusEffectData = ExtResource("4_xvjl0")
|
||||
DamageTimer = NodePath("../Timer")
|
||||
|
||||
[node name="EffectInflictorComponent" type="Node" parent="." node_paths=PackedStringArray("Damage")]
|
||||
script = ExtResource("4_22hnt")
|
||||
@@ -51,14 +54,11 @@ VisibilityNotifier = NodePath("../VisibleOnScreenNotifier2D")
|
||||
[node name="StraightMotionComponent" type="Node" parent="." node_paths=PackedStringArray("LaunchComponent")]
|
||||
script = ExtResource("6_6nrp8")
|
||||
LaunchComponent = NodePath("../LaunchComponent")
|
||||
metadata/_custom_type_script = "uid://cvcnfrr1udco5"
|
||||
|
||||
[node name="LaunchComponent" type="Node2D" parent="."]
|
||||
script = ExtResource("7_oml3k")
|
||||
Speed = 170.0
|
||||
metadata/_custom_type_script = "uid://873un8agkyja"
|
||||
|
||||
[node name="ProjectileInitComponent" type="Node" parent="." node_paths=PackedStringArray("LaunchComponent")]
|
||||
script = ExtResource("8_22hnt")
|
||||
LaunchComponent = NodePath("../LaunchComponent")
|
||||
metadata/_custom_type_script = "uid://bgty7040ams6s"
|
||||
|
@@ -29,7 +29,7 @@ public partial class MagneticSkillComponent : Node, ISkill
|
||||
|
||||
private void OnBodyEntered(Node2D body)
|
||||
{
|
||||
if (!HasComponentInChildren(body, "Collectable")) return;
|
||||
if (!HasComponentInChildren(body, "CollectableComponent")) return;
|
||||
|
||||
if (_collectablesToPickUp.Contains(body)) return;
|
||||
_collectablesToPickUp.Add(body);
|
||||
@@ -37,7 +37,7 @@ public partial class MagneticSkillComponent : Node, ISkill
|
||||
|
||||
private void OnAreaEntered(Area2D area)
|
||||
{
|
||||
if (!HasComponentInChildren(area, "Collectable")) return;
|
||||
if (!HasComponentInChildren(area, "CollectableComponent")) return;
|
||||
|
||||
if (_collectablesToPickUp.Contains(area)) return;
|
||||
_collectablesToPickUp.Add(area);
|
||||
@@ -77,16 +77,38 @@ public partial class MagneticSkillComponent : Node, ISkill
|
||||
{
|
||||
GD.PushWarning("MagneticSkillComponent: Owner is not a Node2D.");
|
||||
}
|
||||
|
||||
if (MagneticArea == null)
|
||||
{
|
||||
if (owner is Area2D area2D) MagneticArea = area2D;
|
||||
else
|
||||
{
|
||||
MagneticArea = owner.GetNodeOrNull<Area2D>("MagneticArea");
|
||||
if (MagneticArea == null)
|
||||
{
|
||||
GD.PushError("MagneticSkillComponent: MagneticArea is not set.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
if (MagneticArea == null)
|
||||
{
|
||||
GD.PushError("MagneticSkillComponent: MagneticArea is not set.");
|
||||
return;
|
||||
}
|
||||
|
||||
MagneticArea.BodyEntered += OnBodyEntered;
|
||||
MagneticArea.AreaEntered += OnAreaEntered;
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
if (MagneticArea == null) return;
|
||||
|
||||
MagneticArea.BodyEntered -= OnBodyEntered;
|
||||
MagneticArea.AreaEntered -= OnAreaEntered;
|
||||
}
|
||||
|
Reference in New Issue
Block a user