From cc973b9f0db187803e82450dfa6d47dba3b2ecd1 Mon Sep 17 00:00:00 2001 From: Minimata Date: Wed, 28 Jan 2026 19:14:05 +0100 Subject: [PATCH] fixed spawners --- components/health/CHealthbar.cs | 2 +- maps/level1.tscn | 13 +++++++------ scenes/spawners/Spawner.cs | 32 +++++++++++--------------------- scenes/spawners/spawner.tscn | 2 ++ 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/components/health/CHealthbar.cs b/components/health/CHealthbar.cs index b6ffddae..03ce4bb1 100644 --- a/components/health/CHealthbar.cs +++ b/components/health/CHealthbar.cs @@ -1,7 +1,7 @@ using Godot; using System; -[GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_heart.png")] +[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_heart.png")] public partial class CHealthbar : Sprite3D { private Healthbar _healthbar; diff --git a/maps/level1.tscn b/maps/level1.tscn index 63b8e4c2..1e81f39a 100644 --- a/maps/level1.tscn +++ b/maps/level1.tscn @@ -26,10 +26,10 @@ metadata/_custom_type_script = "uid://baiapod3csndf" [node name="Main" unique_id=1551129541 instance=ExtResource("1_w4y6q")] -[node name="BackgroundMusicPlayer" parent="." index="0"] +[node name="BackgroundMusicPlayer" parent="." index="0" unique_id=879496303] autoplay = false -[node name="Player" parent="." index="5"] +[node name="Player" parent="." index="5" unique_id=1309399929] transform = Transform3D(0.99999994, 0, 0, 0, 1, 0, 0, 0, 0.99999994, 2, 1.5, 9.5) [node name="Greybox" type="CSGCombiner3D" parent="." index="7" unique_id=646927976] @@ -125,18 +125,19 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 7, -16) Target = NodePath("../Player") RMovement = SubResource("Resource_xixm3") -[node name="GroundedSpawner" parent="." index="14" unique_id=557145011 instance=ExtResource("7_ba7rw")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 12, 2.5, -15) +[node name="GroundedSpawner" parent="." index="14" unique_id=557145011 node_paths=PackedStringArray("Target") instance=ExtResource("7_ba7rw")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 2.5, -15) EnemyToSpawn = ExtResource("4_5mjy0") MovementInputs = ExtResource("8_cdhvi") HealthInputs = SubResource("Resource_epn1o") DamageInputs = ExtResource("10_xyaoo") +Target = NodePath("../Player") IsActiveOnStart = false -[node name="FlyingSpawner" parent="." index="15" unique_id=974076606 instance=ExtResource("7_ba7rw")] +[node name="FlyingSpawner" parent="." index="15" unique_id=974076606 node_paths=PackedStringArray("Target") instance=ExtResource("7_ba7rw")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 18, 11, -14) EnemyToSpawn = ExtResource("6_xuqf0") MovementInputs = ExtResource("11_yug0s") HealthInputs = ExtResource("12_qgrw7") DamageInputs = ExtResource("13_qulje") -IsActiveOnStart = false +Target = NodePath("../Player") diff --git a/scenes/spawners/Spawner.cs b/scenes/spawners/Spawner.cs index 4c701742..fcdc6944 100644 --- a/scenes/spawners/Spawner.cs +++ b/scenes/spawners/Spawner.cs @@ -22,21 +22,14 @@ public partial class Spawner : Node3D [Export] public bool IsActiveOnStart { get; set; } = true; - private float _spawnTimer; - private bool _isActive; + private Timer _timer; public override void _Ready() { - _isActive = IsActiveOnStart; - _spawnTimer = SpawnInterval; - } - - public override void _Process(double delta) - { - if (!_isActive) return; - - _spawnTimer -= (float) delta; - if (_spawnTimer <= 0) Spawn(); + _timer = GetNode("Timer"); + _timer.WaitTime = SpawnInterval; + _timer.Timeout += Spawn; + if (IsActiveOnStart) StartSpawning(); } public void Spawn() @@ -44,27 +37,24 @@ public partial class Spawner : Node3D if (EnemyToSpawn == null || !EnemyToSpawn.CanInstantiate()) return; if (EnemyToSpawn.Instantiate() is not Enemy spawnedInstance) return; - + + GetTree().GetCurrentScene().AddChild(spawnedInstance); + spawnedInstance.GlobalPosition = GlobalPosition; + spawnedInstance.Target = Target; spawnedInstance.RMovement = MovementInputs; spawnedInstance.RDamage = DamageInputs; spawnedInstance.RHealth = HealthInputs; spawnedInstance.Initialize(); - - GetTree().GetCurrentScene().AddChild(spawnedInstance); - spawnedInstance.GlobalPosition = GlobalPosition; - - _spawnTimer = SpawnInterval; } public void StartSpawning() { - _isActive = true; - _spawnTimer = SpawnInterval; + _timer.Start(); } public void StopSpawning() { - _isActive = false; + _timer.Stop(); } } diff --git a/scenes/spawners/spawner.tscn b/scenes/spawners/spawner.tscn index a10a8186..e61f23e4 100644 --- a/scenes/spawners/spawner.tscn +++ b/scenes/spawners/spawner.tscn @@ -6,3 +6,5 @@ script = ExtResource("1_2otbo") [node name="Marker3D" type="Marker3D" parent="." unique_id=610854505] + +[node name="Timer" type="Timer" parent="." unique_id=1842357493]