Files
nodewars/scripts/Pip.cs
2026-05-20 16:34:39 +02:00

46 lines
783 B
C#

using System;
using Godot;
using NodeWar.scripts;
namespace NodeWar.Scripts;
public partial class Pip : Area2D
{
[Export]
public Faction Faction;
[Export]
public Vector2 Target;
[Export]
public float Speed { get; set; } = 100;
private Sprite2D _gfx;
public override void _Ready()
{
_gfx = GetNode<Sprite2D>("Gfx");
_gfx.Modulate = Faction switch
{
Faction.Neutral => Colors.Gray,
Faction.Player => Colors.DarkGreen,
Faction.Computer => Colors.DarkRed,
_ => throw new ArgumentOutOfRangeException(),
};
AreaEntered += OnAreaEntered;
}
public override void _Process(double delta)
{
var direction = Target - GlobalPosition;
Position += direction.Normalized() * Speed * delta.ToFloat();
}
private void OnAreaEntered(Node2D body)
{
}
}