Spinach
This commit is contained in:
parent
805226d9eb
commit
87f841e8e1
24 changed files with 203 additions and 57 deletions
32
scripts/entities/plants/DragAction.cs
Normal file
32
scripts/entities/plants/DragAction.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Plants;
|
||||
|
||||
public partial class DragAction : Node
|
||||
{
|
||||
[Signal] public delegate void DragBeginEventHandler();
|
||||
[Signal] public delegate void DragEndEventHandler();
|
||||
private bool dragging = false;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
GetParent<Area2D>().InputEvent += OnInputEvent;
|
||||
}
|
||||
public void OnInputEvent(Node viewport, InputEvent @event, long shape_index)
|
||||
{
|
||||
if (@event.IsActionPressed("primary_action"))
|
||||
{
|
||||
dragging = true;
|
||||
EmitSignal(SignalName.DragBegin);
|
||||
}
|
||||
}
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (dragging && @event.IsActionReleased("primary_action"))
|
||||
{
|
||||
dragging = false;
|
||||
EmitSignal(SignalName.DragEnd);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1
scripts/entities/plants/DragAction.cs.uid
Normal file
1
scripts/entities/plants/DragAction.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cu63aiowp5bqd
|
||||
36
scripts/entities/plants/behaviours/SnipachBehaviour.cs
Normal file
36
scripts/entities/plants/behaviours/SnipachBehaviour.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
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()
|
||||
{
|
||||
if (dragging == false) return;
|
||||
attackBox.Attack();
|
||||
dragging = false;
|
||||
attackBox.Visible = dragging;
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (dragging)
|
||||
{
|
||||
attackBox.GlobalPosition = (attackBox.GetGlobalMousePosition() / FieldParams.Tile).Ceil() * FieldParams.Tile - new Vector2(20, 14);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://csgksiyma0h4t
|
||||
Loading…
Add table
Add a link
Reference in a new issue