Migrated player state machine

This commit is contained in:
Marco 2025-03-05 10:55:14 +01:00
commit 9c3f22760b
19 changed files with 108 additions and 69 deletions

View file

@ -3,8 +3,10 @@ using Godot;
namespace Cirno.Scripts.Components.FSM.Player;
public partial class Dead : PlayerFSMState
public partial class Dead : PlayerStateBase
{
public override PlayerState StateId => PlayerState.Dead;
[Export]
private PlayerAnimationProvider _animationProvider;
@ -13,30 +15,19 @@ public partial class Dead : PlayerFSMState
[Export]
private ActorResourceProvider _healthProvider;
private GameManager _gameManager;
private Hud _hud;
public override void Init(ActorStateMachine stateMachine)
{
base.Init(stateMachine);
_gameManager = GameManager.Instance;
_hud = Hud.Instance;
}
public override void EnterState()
{
_animationProvider.PlayDeathAnimation();
// show game over
_hud.ShowGameOver();
Hud.Instance.ShowGameOver();
}
public override void ExitState()
{
// Hide game over
_hud.HideGameOver();
Hud.Instance.HideGameOver();
}
public override void ProcessState(double delta)
@ -55,10 +46,10 @@ public partial class Dead : PlayerFSMState
public void Respawn()
{
_stateMachine.GlobalPosition = _gameManager.LastCheckpointPosition;
MainObject.GlobalPosition = GameManager.Instance.LastCheckpointPosition;
_healthProvider.FillResource();
_gameManager.ClearBullets();
GameManager.Instance.ClearBullets();
_stateMachine.SetState((int)PlayerState.Active);
ChangeState(PlayerState.Active);
}
}