cirnogodot/Scripts/Components/Actors/MovementHandler.cs

36 lines
965 B
C#
Raw Normal View History

2025-02-18 17:40:33 +01:00
using System.Collections.Generic;
using System.Linq;
using Cirno.Scripts.Components.Actors;
2025-02-17 21:53:05 +01:00
using Godot;
public abstract partial class MovementHandler : Node2D
{
2025-02-18 17:40:33 +01:00
protected Actor _parent;
public abstract Vector2 MovementDirection { get; set; }
public abstract Vector2 FacingDirection { get; set; }
2025-02-17 21:53:05 +01:00
2025-02-18 17:40:33 +01:00
protected readonly List<InputProvider> _inputProviders = new();
public virtual void Init(Actor parent)
{
_parent = parent;
var children = GetChildren();
foreach (var child in children) {
if (child is InputProvider inputProvider)
{
_inputProviders.Add(inputProvider);
}
}
}
public virtual Vector2 AggregateInputProviders()
{
return _inputProviders.Aggregate(Vector2.Zero, (current, inputProvider) => current + inputProvider.GetMovementInput().Normalized());
}
2025-02-17 21:53:05 +01:00
public abstract void Move(double delta);
}