SupaLidlGame/State/Character/PlayerIdleState.cs

94 lines
2.3 KiB
C#
Raw Permalink 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-08-02 01:59:37 -07:00
[Export]
public PlayerEmoteState EmoteState { get; set; }
2023-09-09 22:33:57 -07:00
[Export]
public PlayerHealState HealState { get; set; }
2023-06-03 18:21:46 -07:00
public override IState<CharacterState> Enter(IState<CharacterState> previousState)
{
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-07-21 02:54:13 -07:00
2023-07-22 20:23:48 -07:00
// must be moving at least 4 u/s for more than 0.5 seconds
bool shouldPlayStopAnim = false;
if (previousState is PlayerMoveState move)
{
shouldPlayStopAnim = move.MoveDuration > 0.5;
// NOTE: more conditions may be added soon
}
2023-09-10 17:08:14 -07:00
if (Godot.Input.IsActionPressed("ability"))
{
if (CanHeal())
{
return HealState;
}
}
2023-07-22 20:23:48 -07:00
if (shouldPlayStopAnim)
2023-07-21 02:54:13 -07:00
{
_player.MovementAnimation.Play("stop");
_player.MovementAnimation.Queue("idle");
}
else
{
_player.MovementAnimation.Play("idle");
}
2023-06-03 18:21:46 -07:00
return base.Enter(previousState);
}
2022-11-13 15:42:04 -08:00
2023-08-02 01:59:37 -07:00
public override CharacterState Input(InputEvent @event)
{
if (@event.IsActionPressed("emote"))
{
return EmoteState;
}
2023-09-09 22:33:57 -07:00
2023-08-02 01:59:37 -07:00
return base.Input(@event);
}
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-09-09 22:33:57 -07:00
if (Godot.Input.IsActionPressed("ability"))
{
2023-09-10 17:08:14 -07:00
if (CanHeal())
2023-09-09 22:33:57 -07:00
{
return HealState;
}
}
2023-06-03 18:21:46 -07:00
return null;
2022-11-13 15:42:04 -08:00
}
2023-09-10 17:08:14 -07:00
private bool CanHeal()
{
return !_player.Inventory.IsUsingItem && _player.Stats.Level.Value > 0;
}
2022-11-13 15:42:04 -08:00
}