SupaLidlGame/State/Character/PlayerIdleState.cs

38 lines
1.1 KiB
C#
Raw Normal View History

2022-11-13 15:42:04 -08:00
using Godot;
2023-06-03 18:21:46 -07:00
namespace SupaLidlGame.State.Character;
public partial class PlayerIdleState : PlayerState
2022-11-13 15:42:04 -08:00
{
2023-06-03 18:21:46 -07:00
[Export]
public CharacterState MoveState { get; set; }
2022-11-13 15:42:04 -08:00
2023-06-03 18:21:46 -07:00
public override IState<CharacterState> Enter(IState<CharacterState> previousState)
{
GD.Print("Entered idle state");
if (previousState is not PlayerMoveState)
2022-11-13 15:42:04 -08:00
{
2023-06-03 18:21:46 -07:00
if (Character.Direction.LengthSquared() > 0.01f)
2022-11-13 15:42:04 -08:00
{
2023-06-03 18:21:46 -07: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-13 15:42:04 -08:00
}
}
2023-06-03 18:21:46 -07:00
_player.Animation = "idle";
return base.Enter(previousState);
}
2022-11-13 15:42:04 -08:00
2023-06-03 18:21:46 -07:00
public override CharacterState Process(double delta)
{
base.Process(delta);
if (Character.Direction.LengthSquared() > 0)
2022-11-13 15:42:04 -08:00
{
2023-06-03 18:21:46 -07:00
return MoveState;
2022-11-13 15:42:04 -08:00
}
2023-06-03 18:21:46 -07:00
return null;
2022-11-13 15:42:04 -08:00
}
}