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 PlayerRollState : PlayerState
|
2022-11-13 15:42:04 -08:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
private double _timeLeftToRoll = 0;
|
2022-11-13 15:42:04 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
private Vector2 _rollDirection = Vector2.Zero;
|
2022-11-13 15:42:04 -08:00
|
|
|
|
2023-07-22 20:23:48 -07:00
|
|
|
private GpuParticles2D _particles;
|
|
|
|
|
2023-09-16 22:14:23 -07:00
|
|
|
public PlayerRollState()
|
|
|
|
{
|
|
|
|
CanEnterWhileUsingItem = false;
|
|
|
|
}
|
|
|
|
|
2023-06-11 15:15:52 -07:00
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
base._Ready();
|
2023-07-22 20:23:48 -07:00
|
|
|
_particles = _player.GetNode<GpuParticles2D>("Effects/RollParticles");
|
2023-06-11 15:15:52 -07:00
|
|
|
}
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public override IState<CharacterState> Enter(IState<CharacterState> previousState)
|
|
|
|
{
|
|
|
|
_timeLeftToRoll = 0.5;
|
|
|
|
// roll the direction we were previously moving in
|
|
|
|
_rollDirection = Character.Direction;
|
|
|
|
Character.Target = Character.Direction;
|
2023-06-11 15:15:52 -07:00
|
|
|
if (Character.Direction.X >= 0)
|
|
|
|
{
|
2023-07-21 02:54:13 -07:00
|
|
|
_player.MovementAnimation.Play("roll");
|
2023-06-11 15:15:52 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-21 02:54:13 -07:00
|
|
|
_player.MovementAnimation.PlayBackwards("roll");
|
2023-06-11 15:15:52 -07:00
|
|
|
}
|
2023-07-21 02:54:13 -07:00
|
|
|
_player.MovementAnimation.Queue("idle");
|
2023-07-22 20:23:48 -07:00
|
|
|
_particles.Emitting = true;
|
2023-06-03 18:21:46 -07:00
|
|
|
return base.Enter(previousState);
|
|
|
|
}
|
2022-11-13 15:42:04 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public override void Exit(IState<CharacterState> nextState)
|
|
|
|
{
|
|
|
|
// 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;
|
2023-07-22 20:23:48 -07:00
|
|
|
_particles.Emitting = false;
|
2023-12-09 16:26:44 -08:00
|
|
|
if (_player.MovementAnimation.CurrentAnimation == "roll")
|
|
|
|
{
|
|
|
|
// prevents player's sprite from being at an angle when exiting too
|
|
|
|
// soon
|
|
|
|
_player.MovementAnimation.Stop();
|
|
|
|
}
|
2023-06-03 18:21:46 -07:00
|
|
|
base.Exit(nextState);
|
|
|
|
}
|
2022-11-13 15:42:04 -08:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public override CharacterState Process(double delta)
|
|
|
|
{
|
|
|
|
Character.Direction = _rollDirection;
|
2023-06-13 02:55:30 -07:00
|
|
|
if ((_timeLeftToRoll -= delta) <= 0 || _player.Health <= 0)
|
2022-11-13 15:42:04 -08:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
return IdleState;
|
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
|
|
|
}
|
|
|
|
}
|