DungeonRPG/Scripts/Characters/Player/PlayerDashState.cs
2025-04-25 01:04:49 -04:00

42 lines
1.1 KiB
C#

using Godot;
using System;
using DungeonRPG.Scripts.General;
public partial class PlayerDashState : PlayerState
{
private Timer timer;
[Export] private float speed = 10;
public override void _Ready()
{
base._Ready();
timer = GetNode<Timer>("Timer");
timer.Timeout += HandleDashTimeout;
}
public override void _PhysicsProcess(double delta)
{
characterNode.MoveAndSlide();
}
protected override void EnterState()
{
characterNode.AnimatedSprite.Play(GameConstants.ANIM_DASH);
characterNode.Velocity = new Vector3(characterNode.Direction.X, 0, characterNode.Direction.Y);
if (characterNode.Velocity == Vector3.Zero)
{
characterNode.Velocity = characterNode.AnimatedSprite.FlipH ? Vector3.Left : Vector3.Right;
}
characterNode.Velocity *= speed;
timer.Start();
}
private void HandleDashTimeout()
{
characterNode.StateMachine.SwitchState<PlayerIdleState>();
characterNode.Velocity = Vector3.Zero;
}
}