2023-07-23 23:39:20 -07:00
|
|
|
using Godot;
|
|
|
|
using SupaLidlGame.Extensions;
|
|
|
|
|
|
|
|
namespace SupaLidlGame.State.Character;
|
|
|
|
|
|
|
|
public partial class CharacterDashState : CharacterState
|
|
|
|
{
|
|
|
|
[Export]
|
|
|
|
public CharacterState IdleState { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public double TimeToDash { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public float VelocityModifier { get; set; }
|
|
|
|
|
|
|
|
private double _timeLeftToDash = 0;
|
|
|
|
|
|
|
|
public Vector2 DashDirection = Vector2.Zero;
|
|
|
|
|
2023-09-16 22:14:23 -07:00
|
|
|
public CharacterDashState()
|
|
|
|
{
|
|
|
|
CanEnterWhileUsingItem = true;
|
|
|
|
}
|
|
|
|
|
2023-07-23 23:39:20 -07:00
|
|
|
public override IState<CharacterState> Enter(IState<CharacterState> previousState)
|
|
|
|
{
|
|
|
|
_timeLeftToDash = TimeToDash;
|
|
|
|
// dash the direction we were previously moving in
|
|
|
|
DashDirection = Character.Direction;
|
2023-08-16 21:02:37 -07:00
|
|
|
Character.MovementAnimation.TryPlay("dash");
|
2023-07-23 23:39:20 -07:00
|
|
|
Character.MovementAnimation.Queue("idle");
|
|
|
|
|
|
|
|
// create ghost effect
|
|
|
|
var ghost = Character.Sprite.CloneOnWorld<Sprite2D>();
|
|
|
|
ghost.GlobalPosition = Character.Sprite.GlobalPosition;
|
|
|
|
var tween = ghost.GetTree().CreateTween();
|
|
|
|
tween.TweenProperty(ghost, "self_modulate", Colors.Transparent, 0.5);
|
|
|
|
tween.TweenCallback(new Callable(ghost, "queue_free"));
|
|
|
|
tween.Play();
|
|
|
|
|
|
|
|
return base.Enter(previousState);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Exit(IState<CharacterState> nextState)
|
|
|
|
{
|
|
|
|
_timeLeftToDash = 0;
|
|
|
|
DashDirection = Character.Direction;
|
|
|
|
base.Exit(nextState);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override CharacterState Process(double delta)
|
|
|
|
{
|
|
|
|
Character.Direction = DashDirection;
|
|
|
|
if ((_timeLeftToDash -= delta) <= 0 || Character.Health <= 0)
|
|
|
|
{
|
|
|
|
return IdleState;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|