mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
29 lines
1.3 KiB
C#
29 lines
1.3 KiB
C#
|
|
using Godot;
|
|||
|
|
|
|||
|
|
namespace Cirno.Scripts.Components.Actors;
|
|||
|
|
|
|||
|
|
public partial class FourWayAnimationHandler : AnimationHandler
|
|||
|
|
{
|
|||
|
|
public override void Update(double delta)
|
|||
|
|
{
|
|||
|
|
_animatedSprite.Play(DirectionToString(_parent.FacingDirection));
|
|||
|
|
_animatedSprite.SpeedScale = _parent.Velocity.Length() > 0 ? 1 : 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected override string DirectionToString(Vector2 direction)
|
|||
|
|
{
|
|||
|
|
var angle = Mathf.RadToDeg(direction.Angle());
|
|||
|
|
angle = Mathf.PosMod(angle, 360);
|
|||
|
|
|
|||
|
|
if (angle >= 337.5 || angle < 22.5) return _directionsTable[FacingDirection.Right];
|
|||
|
|
if (angle >= 22.5 && angle < 67.5) return _directionsTable[FacingDirection.Right];
|
|||
|
|
if (angle >= 67.5 && angle < 112.5) return _directionsTable[FacingDirection.Down];
|
|||
|
|
if (angle >= 112.5 && angle < 157.5) return _directionsTable[FacingDirection.Left];
|
|||
|
|
if (angle >= 157.5 && angle < 202.5) return _directionsTable[FacingDirection.Left];
|
|||
|
|
if (angle >= 202.5 && angle < 247.5) return _directionsTable[FacingDirection.Left];
|
|||
|
|
if (angle >= 247.5 && angle < 292.5) return _directionsTable[FacingDirection.Up];
|
|||
|
|
if (angle >= 292.5 && angle < 337.5) return _directionsTable[FacingDirection.Right];
|
|||
|
|
|
|||
|
|
return _directionsTable[FacingDirection.Up];
|
|||
|
|
}
|
|||
|
|
}
|