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 partial class ActorFreeMovement : MovementHandler
|
|
|
|
|
{
|
2025-02-18 17:40:33 +01:00
|
|
|
public override Vector2 FacingDirection
|
|
|
|
|
{
|
|
|
|
|
get => _parent.FacingDirection;
|
|
|
|
|
set => _parent.FacingDirection = value;
|
|
|
|
|
}
|
2025-02-17 21:53:05 +01:00
|
|
|
|
2025-02-18 17:40:33 +01:00
|
|
|
public override Vector2 MovementDirection
|
|
|
|
|
{
|
|
|
|
|
get => _parent.MovementDirection;
|
|
|
|
|
set => _parent.MovementDirection = value;
|
|
|
|
|
}
|
2025-02-17 21:53:05 +01:00
|
|
|
|
|
|
|
|
public override void Init(Actor parent)
|
|
|
|
|
{
|
2025-02-18 17:40:33 +01:00
|
|
|
base.Init(parent);
|
|
|
|
|
|
2025-02-17 21:53:05 +01:00
|
|
|
MovementDirection = Vector2.Zero;
|
2025-02-18 17:40:33 +01:00
|
|
|
FacingDirection = Vector2.Down;
|
2025-02-17 21:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Move(double delta)
|
|
|
|
|
{
|
2025-02-18 18:18:13 +01:00
|
|
|
MovementDirection = AggregateInputProviders().Normalized();
|
|
|
|
|
|
|
|
|
|
var aimingDirection = GetAimingDirection().Normalized();
|
|
|
|
|
var isStrafing = GetStrafing();
|
|
|
|
|
|
|
|
|
|
if (!isStrafing && aimingDirection.Length() > 0.1f)
|
|
|
|
|
{
|
|
|
|
|
FacingDirection = aimingDirection;
|
|
|
|
|
}
|
|
|
|
|
else if (MovementDirection != Vector2.Zero)
|
|
|
|
|
{
|
|
|
|
|
FacingDirection = MovementDirection;
|
|
|
|
|
}
|
2025-02-18 17:40:33 +01:00
|
|
|
|
2025-02-17 21:53:05 +01:00
|
|
|
_parent.Velocity = MovementDirection * _parent.MovementSpeed;
|
|
|
|
|
|
|
|
|
|
_parent.MoveAndSlide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|