asd
This commit is contained in:
42
scripts/components/SpawnerComponent.cs
Normal file
42
scripts/components/SpawnerComponent.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Godot;
|
||||
using NodeWar.Scripts;
|
||||
|
||||
namespace NodeWar.scripts.components;
|
||||
|
||||
public partial class SpawnerComponent : Node
|
||||
{
|
||||
[Export]
|
||||
public PackedScene Spawnee;
|
||||
|
||||
[Export]
|
||||
public Faction Faction;
|
||||
|
||||
[Export]
|
||||
public float BuildSpeed = 28;
|
||||
|
||||
[Export]
|
||||
public float BuildProgress = 0;
|
||||
|
||||
[Export]
|
||||
public float MaxBuildProgress = 100;
|
||||
|
||||
public Vector2 Target { get; set; }
|
||||
|
||||
public override void _Ready() { }
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
BuildProgress += BuildSpeed * delta.ToFloat();
|
||||
if (BuildProgress >= MaxBuildProgress)
|
||||
{
|
||||
BuildProgress = 0;
|
||||
var pip = Spawnee.Instantiate<Pip>();
|
||||
|
||||
pip.Faction = Faction;
|
||||
pip.Target = Target;
|
||||
|
||||
GetParent().AddChild(pip);
|
||||
pip.GlobalPosition = GetParent<Node2D>().GlobalPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user