mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 00:45:55 +00:00
4 way animation handler for new actors
This commit is contained in:
parent
0e15d2acba
commit
335f4d5430
8 changed files with 260 additions and 117 deletions
29
Scripts/Components/Actors/FourWayAnimationHandler.cs
Normal file
29
Scripts/Components/Actors/FourWayAnimationHandler.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue