Files
nodewars/scripts/Pip.cs
2026-05-13 18:52:00 +02:00

39 lines
633 B
C#

using Godot;
namespace NodeWar.Scripts;
public partial class Pip : Area2D
{
[Export]
public Faction Faction;
[Export]
public Base Target;
[Export]
public float Speed { get; set; } = 100;
public override void _Ready()
{
AreaEntered += OnAreaEntered;
}
public override void _Process(double delta)
{
if (Target == null)
return;
var direction = Target.Position - GlobalPosition;
Position += direction.Normalized() * Speed * delta.ToFloat();
}
private void OnAreaEntered(Node2D body)
{
if (body is Base { Faction: Faction.Computer } enteredBase)
{
enteredBase.Health -= 1;
QueueFree();
}
}
}