Initial Checkin of Code
This commit is contained in:
parent
19b557ee9b
commit
0bee2ee47b
44 changed files with 7965 additions and 0 deletions
69
Library/Characters/CharacterAnimation.cs
Normal file
69
Library/Characters/CharacterAnimation.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
using Godot;
|
||||
using PokemonLike.Library.Support;
|
||||
|
||||
namespace PokemonLike.Library.Characters;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class CharacterAnimation : AnimatedSprite2D
|
||||
{
|
||||
[ExportCategory("Nodes")]
|
||||
[Export] public CharacterInput CharacterInput;
|
||||
[Export] public CharacterMovement CharacterMovement;
|
||||
|
||||
[ExportCategory("Animation Vars")]
|
||||
[Export] public ECharacterAnimation ECharacterAnimation = ECharacterAnimation.IdleDown;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CharacterMovement.Animation += PlayAnimation;
|
||||
Logger.Info("Loading player animation component ...");
|
||||
}
|
||||
|
||||
public void PlayAnimation(string animationType)
|
||||
{
|
||||
ECharacterAnimation previousAnimation = ECharacterAnimation;
|
||||
|
||||
if (CharacterMovement.IsMoving()) return;
|
||||
|
||||
switch (animationType)
|
||||
{
|
||||
case "walk":
|
||||
if (CharacterInput.Direction == Vector2.Up)
|
||||
ECharacterAnimation = ECharacterAnimation.WalkUp;
|
||||
else if (CharacterInput.Direction == Vector2.Left)
|
||||
ECharacterAnimation = ECharacterAnimation.WalkLeft;
|
||||
else if (CharacterInput.Direction == Vector2.Right)
|
||||
ECharacterAnimation = ECharacterAnimation.WalkRight;
|
||||
else if (CharacterInput.Direction == Vector2.Down)
|
||||
ECharacterAnimation = ECharacterAnimation.WalkDown;
|
||||
break;
|
||||
case "turn":
|
||||
if (CharacterInput.Direction == Vector2.Up)
|
||||
ECharacterAnimation = ECharacterAnimation.TurnUp;
|
||||
else if (CharacterInput.Direction == Vector2.Left)
|
||||
ECharacterAnimation = ECharacterAnimation.TurnLeft;
|
||||
else if (CharacterInput.Direction == Vector2.Right)
|
||||
ECharacterAnimation = ECharacterAnimation.TurnRight;
|
||||
else if (CharacterInput.Direction == Vector2.Down)
|
||||
ECharacterAnimation = ECharacterAnimation.TurnDown;
|
||||
break;
|
||||
case "idle":
|
||||
if (CharacterInput.Direction == Vector2.Up)
|
||||
ECharacterAnimation = ECharacterAnimation.IdleUp;
|
||||
else if (CharacterInput.Direction == Vector2.Left)
|
||||
ECharacterAnimation = ECharacterAnimation.IdleLeft;
|
||||
else if (CharacterInput.Direction == Vector2.Right)
|
||||
ECharacterAnimation = ECharacterAnimation.IdleRight;
|
||||
else if (CharacterInput.Direction == Vector2.Down)
|
||||
ECharacterAnimation = ECharacterAnimation.IdleDown;
|
||||
break;
|
||||
}
|
||||
|
||||
if (previousAnimation != ECharacterAnimation)
|
||||
{
|
||||
Logger.Debug($"Playing animation {ECharacterAnimation}");
|
||||
Play(ECharacterAnimation.ToString().ToSnakeCase());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue