init
This commit is contained in:
38
scripts/Pip.cs
Normal file
38
scripts/Pip.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user