SupaLidlGame/Characters/States/PlayerIdleState.cs

39 lines
1.2 KiB
C#
Raw Normal View History

2022-11-13 15:42:04 -08:00
using Godot;
namespace SupaLidlGame.Characters.State
{
public partial class PlayerIdleState : PlayerState
{
[Export]
public CharacterState MoveState { get; set; }
public override CharacterState Enter(CharacterState previousState)
{
GD.Print("Entered idle state");
if (previousState is not PlayerMoveState)
{
2022-11-19 21:21:12 -08:00
if (Character.Direction.LengthSquared() > 0.01f)
2022-11-13 15:42:04 -08:00
{
// other states like attacking or rolling can just delegate
// the work of checking if the player is moving to this idle
// state, so they do not have to manually check if the player
// wants to move to switch to the move state.
return MoveState;
}
}
2022-11-19 21:21:12 -08:00
_player.Animation = "idle";
2022-11-13 15:42:04 -08:00
return base.Enter(previousState);
}
public override CharacterState Process(double delta)
{
base.Process(delta);
if (Character.Direction.LengthSquared() > 0)
{
return MoveState;
}
return null;
}
}
}