mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-06 06:45:55 +00:00
FSM Player input
This commit is contained in:
parent
c59a480ffd
commit
cc0d698bb5
7 changed files with 180 additions and 106 deletions
48
Scripts/Components/Actors/PlayerAnimationProvider.cs
Normal file
48
Scripts/Components/Actors/PlayerAnimationProvider.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using Godot;
|
||||
|
||||
public partial class PlayerAnimationProvider : Node2D
|
||||
{
|
||||
[Export]
|
||||
public AnimatedSprite2D _animatedSprite {get; private set;}
|
||||
|
||||
[ExportCategory("Animation Names")]
|
||||
[Export]
|
||||
public string WalkRightAnimationName {get; private set;} = "walk_right";
|
||||
|
||||
[Export]
|
||||
public string WalkLeftAnimationName {get; private set;} = "walk_left";
|
||||
[Export]
|
||||
public string WalkDownAnimationName {get; private set;} = "walk_down";
|
||||
[Export]
|
||||
public string WalkUpAnimationName {get; private set;} = "walk_up";
|
||||
|
||||
public void SetAnimation(Vector2 velocity)
|
||||
{
|
||||
if (velocity.X == 0 && velocity.Y == 0)
|
||||
{
|
||||
_animatedSprite.SpeedScale = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_animatedSprite.SpeedScale = 1;
|
||||
}
|
||||
|
||||
if (velocity.X > 0)
|
||||
{
|
||||
_animatedSprite.Play(WalkRightAnimationName);
|
||||
}
|
||||
else if (velocity.X < 0)
|
||||
{
|
||||
_animatedSprite.Play(WalkLeftAnimationName);
|
||||
}
|
||||
else if (velocity.Y > 0)
|
||||
{
|
||||
_animatedSprite.Play(WalkDownAnimationName);
|
||||
}
|
||||
else if (velocity.Y < 0)
|
||||
{
|
||||
_animatedSprite.Play(WalkUpAnimationName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue