cirnogodot/Scripts/Resources/SimpleMovementPattern.cs

59 lines
1.8 KiB
C#
Raw Normal View History

2025-02-05 19:41:49 +01:00
using Cirno.Scripts.Actors;
2025-03-15 11:44:30 +01:00
using Cirno.Scripts.AttackPatterns;
2025-02-05 19:41:49 +01:00
using Godot;
namespace Cirno.Scripts.Resources;
[GlobalClass]
2025-06-03 10:11:09 +02:00
[Tool]
2025-02-05 19:41:49 +01:00
public partial class SimpleMovementPattern : 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;
2025-06-10 16:33:43 +02:00
public override IPatternMachine MakeMachine(Node parent)
2025-03-15 17:17:30 +01:00
{
return new SimpleMovementPatternMachine(this, parent);
}
2025-02-05 19:41:49 +01:00
2025-06-10 16:33:43 +02:00
public class SimpleMovementPatternMachine(SimpleMovementPattern pattern, Node parent) : IPatternMachine
2025-02-05 19:41:49 +01:00
{
2025-06-10 16:33:43 +02:00
public Node Parent => parent;
2025-03-15 11:44:30 +01:00
2025-03-15 17:17:30 +01:00
private Tween tween;
private bool isComplete = false;
2025-02-05 19:41:49 +01:00
2025-03-15 17:17:30 +01:00
protected IScriptHost Boss;
public void Start()
2025-03-06 22:09:11 +01:00
{
2025-03-15 17:17:30 +01:00
if (parent is not IScriptHost boss)
return;
Boss = boss;
tween = Parent.CreateTween();
isComplete = false;
2025-02-05 19:41:49 +01:00
2025-03-15 17:17:30 +01:00
Vector2 targetPosition = (Boss?.HomePosition ?? Parent.GlobalPosition) + pattern.relativeTargetPosition;
boss.ChangeSpriteDirection(-(Parent.GlobalPosition - targetPosition));
tween.TweenProperty(Parent, "global_position", targetPosition, pattern.moveDuration)
.SetTrans(pattern.transitionType)
.SetEase(pattern.easeType)
.Finished += () =>
{
isComplete = true;
boss.ChangeSpriteDirection(Vector2.Zero);
};
}
2025-02-05 19:41:49 +01:00
2025-03-15 17:17:30 +01:00
public void UpdatePattern(double delta) { }
public bool IsComplete()
{
return isComplete;
}
2025-02-05 19:41:49 +01:00
}
}