45 lines
947 B
C#
45 lines
947 B
C#
using Godot;
|
|
|
|
namespace Newlon.Components.Plants;
|
|
|
|
public partial class SnipachBehaviour : BaseBehaviour
|
|
{
|
|
[Export] public AreaAttack attackBox;
|
|
[Export] public Timer timer;
|
|
[Export] public Timer guardTimer;
|
|
private bool dragging = false;
|
|
|
|
public void OnDragBegin()
|
|
{
|
|
if (timer.TimeLeft > 0 || guardTimer.TimeLeft > 0) return;
|
|
dragging = true;
|
|
attackBox.Visible = dragging;
|
|
}
|
|
|
|
public void OnDragEnd(bool aborted)
|
|
{
|
|
if (dragging == false) return;
|
|
dragging = false;
|
|
attackBox.Visible = dragging;
|
|
if (aborted) return;
|
|
attackBox.Attack();
|
|
timer.Start();
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
if (dragging)
|
|
{
|
|
attackBox.GlobalPosition = (Cursor.GetCursorPosition() / FieldParams.Tile).Ceil() * FieldParams.Tile - new Vector2(20, 14);
|
|
}
|
|
if (timer.TimeLeft > 0)
|
|
{
|
|
GetParent<Node2D>().Modulate = Colors.DeepSkyBlue;
|
|
}
|
|
else
|
|
{
|
|
GetParent<Node2D>().Modulate = Colors.White;
|
|
}
|
|
}
|
|
|
|
}
|