mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Bad tank movement
This commit is contained in:
parent
12f0062fe8
commit
90d2a95fa8
10 changed files with 514 additions and 8 deletions
60
Scripts/Components/Actors/AnimationHandler.cs
Normal file
60
Scripts/Components/Actors/AnimationHandler.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class AnimationHandler : Node2D
|
||||
{
|
||||
[Export]
|
||||
public AnimatedSprite2D _animatedSprite { get; protected set; }
|
||||
|
||||
protected Actor _parent;
|
||||
|
||||
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 void Update(double delta)
|
||||
{
|
||||
|
||||
var direction = _parent.FacingDirection; //GetSnappedDirection();
|
||||
|
||||
if (_parent.Velocity.Length() > 0)
|
||||
{
|
||||
_animatedSprite.Play("walk_" + DirectionToString(direction));
|
||||
_animatedSprite.SpeedScale = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//_animatedSprite.Play("idle_" + DirectionToString(direction));
|
||||
_animatedSprite.Play("walk_" + DirectionToString(direction));
|
||||
_animatedSprite.SpeedScale = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private string DirectionToString(Vector2 direction)
|
||||
{
|
||||
var angle = Mathf.RadToDeg(direction.Angle());
|
||||
angle = Mathf.PosMod(angle, 360);
|
||||
|
||||
if (angle >= 337.5 || angle < 22.5) return "right";
|
||||
if (angle >= 22.5 && angle < 67.5) return "up_right";
|
||||
if (angle >= 67.5 && angle < 112.5) return "up";
|
||||
if (angle >= 112.5 && angle < 157.5) return "up_left";
|
||||
if (angle >= 157.5 && angle < 202.5) return "left";
|
||||
if (angle >= 202.5 && angle < 247.5) return "down_left";
|
||||
if (angle >= 247.5 && angle < 292.5) return "down";
|
||||
if (angle >= 292.5 && angle < 337.5) return "down_right";
|
||||
|
||||
return "up";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue