wave behavior and fixed explosion
This commit is contained in:
@@ -1,11 +1,20 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Movementtests.managers;
|
||||
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_duplicate.png")]
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_duplicate.png"), Meta(typeof(IAutoNode))]
|
||||
public partial class Spawner : Node3D
|
||||
{
|
||||
[Export(PropertyHint.NodeType)]
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Dependency] public WaveManager WaveManager => this.DependOn<WaveManager>();
|
||||
|
||||
[Export(PropertyHint.NodeType)]
|
||||
public PackedScene? EnemyToSpawn { get; set; }
|
||||
|
||||
[Export] public Godot.Collections.Array<EnemyDescription.EnemyType> SupportedEnemyTypes { get; set; } = [];
|
||||
|
||||
[Export]
|
||||
public RMovement? MovementInputs { get; set; }
|
||||
@@ -18,37 +27,56 @@ public partial class Spawner : Node3D
|
||||
[Export]
|
||||
public bool IsActiveOnStart { get; set; } = true;
|
||||
|
||||
private Timer _timer;
|
||||
[Node("Timer")] private Timer SpawnTimer { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
public void OnReady()
|
||||
{
|
||||
_timer = GetNode<Timer>("Timer");
|
||||
_timer.WaitTime = SpawnInterval;
|
||||
_timer.Timeout += Spawn;
|
||||
SpawnTimer.WaitTime = SpawnInterval;
|
||||
SpawnTimer.Timeout += Spawn;
|
||||
if (IsActiveOnStart) StartSpawning();
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
WaveManager.RegisterSpawner(this);
|
||||
}
|
||||
|
||||
public void Spawn()
|
||||
{
|
||||
if (EnemyToSpawn == null || !EnemyToSpawn.CanInstantiate()) return;
|
||||
|
||||
if (EnemyToSpawn.Instantiate() is not Enemy spawnedInstance) return;
|
||||
spawnedInstance.RequestReady();
|
||||
|
||||
spawnedInstance.Target = Target;
|
||||
spawnedInstance.RMovement = MovementInputs;
|
||||
if (MovementInputs != null)
|
||||
spawnedInstance.RMovement = MovementInputs;
|
||||
spawnedInstance.Init();
|
||||
|
||||
GetTree().GetCurrentScene().AddChild(spawnedInstance);
|
||||
spawnedInstance.GlobalPosition = GlobalPosition;
|
||||
}
|
||||
|
||||
public Enemy? SpawnEnemy(EnemyDescription description)
|
||||
{
|
||||
if (description.Scene.Instantiate() is not Enemy spawnedInstance) return null;
|
||||
|
||||
spawnedInstance.Target = Target;
|
||||
if (description.MovementOverride is not null)
|
||||
spawnedInstance.RMovement = description.MovementOverride;
|
||||
spawnedInstance.Init();
|
||||
|
||||
GetTree().GetCurrentScene().AddChild(spawnedInstance);
|
||||
spawnedInstance.GlobalPosition = GlobalPosition;
|
||||
return spawnedInstance;
|
||||
}
|
||||
|
||||
public void StartSpawning()
|
||||
{
|
||||
_timer.Start();
|
||||
SpawnTimer.Start();
|
||||
}
|
||||
|
||||
public void StopSpawning()
|
||||
{
|
||||
_timer.Stop();
|
||||
SpawnTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user