mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
56 lines
No EOL
1.7 KiB
C#
56 lines
No EOL
1.7 KiB
C#
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;
|
|
}
|
|
}
|
|
} |