SupaLidlGame/State/Character/PlayerRollState.cs

40 lines
1.2 KiB
C#
Raw Normal View History

2022-11-13 15:42:04 -08:00
using Godot;
2023-05-25 15:28:33 -07:00
namespace SupaLidlGame.State.Character
2022-11-13 15:42:04 -08:00
{
public partial class PlayerRollState : PlayerState
{
private double _timeLeftToRoll = 0;
private Vector2 _rollDirection = Vector2.Zero;
2023-05-25 15:28:33 -07:00
public override IState<CharacterState> Enter(IState<CharacterState> previousState)
2022-11-13 15:42:04 -08:00
{
_timeLeftToRoll = 0.5;
// roll the direction we were previously moving in
_rollDirection = Character.Direction;
2022-11-19 21:21:12 -08:00
Character.Target = Character.Direction;
2022-11-13 15:42:04 -08:00
return base.Enter(previousState);
}
2023-05-25 15:28:33 -07:00
public override void Exit(IState<CharacterState> nextState)
2022-11-13 15:42:04 -08:00
{
// we want to reset our state variables in case we are forced out of
// this state (e.g. from death)
_timeLeftToRoll = 0;
_rollDirection = Character.Direction;
base.Exit(nextState);
}
public override CharacterState Process(double delta)
{
Character.Direction = _rollDirection;
if ((_timeLeftToRoll -= delta) <= 0)
{
return IdleState;
}
return null;
}
}
}