mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Movement for nodes patterns
This commit is contained in:
parent
36df2274c0
commit
e4d7a9159f
6 changed files with 172 additions and 96 deletions
56
Scripts/AttackPatterns/NodeMovementPattern.cs
Normal file
56
Scripts/AttackPatterns/NodeMovementPattern.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.AttackPatterns;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class NodeMovementPattern : AttackPattern
|
||||
{
|
||||
[Export] private Vector2 relativeTargetPosition;
|
||||
[Export] private float moveDuration = 2f;
|
||||
[Export] private Tween.TransitionType transitionType = Tween.TransitionType.Linear;
|
||||
[Export] private Tween.EaseType easeType = Tween.EaseType.InOut;
|
||||
|
||||
public override IPatternMachine MakeMachine(Node2D parent)
|
||||
{
|
||||
return new NodeMovementPatternMachine(this, parent);
|
||||
}
|
||||
|
||||
public class NodeMovementPatternMachine(NodeMovementPattern pattern, Node2D parent) : IPatternMachine
|
||||
{
|
||||
public Node2D Parent => parent;
|
||||
|
||||
private Tween tween;
|
||||
private bool isComplete = false;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (Parent is not IScriptHost scriptHost)
|
||||
{
|
||||
GD.PrintErr("Parent was not a script host");
|
||||
isComplete = true;
|
||||
return;
|
||||
}
|
||||
|
||||
tween = Parent.CreateTween();
|
||||
isComplete = false;
|
||||
|
||||
Vector2 targetPosition = (scriptHost?.HomePosition ?? Parent.GlobalPosition) + pattern.relativeTargetPosition;
|
||||
|
||||
tween.TweenProperty(Parent, "global_position", targetPosition, pattern.moveDuration)
|
||||
.SetTrans(pattern.transitionType)
|
||||
.SetEase(pattern.easeType)
|
||||
.Finished += () =>
|
||||
{
|
||||
isComplete = true;
|
||||
};
|
||||
}
|
||||
|
||||
public void UpdatePattern(double delta) { }
|
||||
|
||||
public bool IsComplete()
|
||||
{
|
||||
return isComplete;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue