cirnogodot/Scripts/Components/FSM/Player/Dead.cs
2025-03-31 18:28:33 +02:00

72 lines
No EOL
1.7 KiB
C#

using Cirno.Scripts.Components.Actors;
using Godot;
namespace Cirno.Scripts.Components.FSM.Player;
public partial class Dead : PlayerStateBase
{
public override PlayerState StateId => PlayerState.Dead;
[Export]
private PlayerAnimationProvider _animationProvider;
[Export]
private InputProvider _inputProvider;
[Export]
private ActorResourceProvider _healthProvider;
[Export]
private ActorResourceProvider _motivationProvider;
public override void EnterState()
{
_animationProvider.PlayDeathAnimation();
if (_motivationProvider.CurrentResource < 100f)
{
// If motivation is not enough show game over scene
GD.Print("Game over");
}
else
{
// Else show respawn notification
Hud.Instance.ShowGameOver();
}
}
public override void ExitState()
{
// Hide game over
Hud.Instance.HideGameOver();
}
public override void ProcessState(double delta)
{
// wait for button
if (_inputProvider.GetShootJustPressed())
{
Respawn();
}
}
public override void PhysicsProcessState(double delta)
{
}
public void Respawn()
{
MainObject.GlobalPosition = GameManager.Instance.LastCheckpointPosition;
_healthProvider.FillResource();
GameManager.Instance.ClearBullets();
_motivationProvider.CurrentResource -= 100f;
if (_motivationProvider.CurrentResource <= 1f)
{
_motivationProvider.CurrentResource = 1f;
}
ChangeState(PlayerState.Active);
}
}