cirnogodot/Scripts/Components/FSM/3DPlayer/Dead.cs

91 lines
2.2 KiB
C#
Raw Normal View History

2025-07-02 15:15:47 +02:00
using Cirno.Scripts.Components.Actors;
using Cirno.Scripts.Components.Actors._3D;
using Cirno.Scripts.Controllers;
using Godot;
2025-06-23 09:19:41 +02:00
namespace Cirno.Scripts.Components.FSM._3DPlayer;
public partial class Dead : BaseState<PlayerState, CharacterBody3D>
{
public override PlayerState StateId => PlayerState.Dead;
2025-07-02 15:15:47 +02:00
[Export]
private ActorResourceProvider _motivationProvider;
[Export]
private InputProvider _inputProvider;
2025-06-23 09:19:41 +02:00
2025-07-02 15:15:47 +02:00
[Export]
private ActorResourceProvider _healthProvider;
[Export]
private PlayerAnimationProvider3D _animationProvider;
private bool _isGameOver = false;
2025-06-23 09:19:41 +02:00
public override void EnterState()
{
base.EnterState();
2025-07-02 15:15:47 +02:00
//MainObject.Hide();
_animationProvider.PlayDeathAnimation();
if (_motivationProvider.CurrentResource < 100f)
{
// If motivation is not enough show game over scene
Hud.Instance.ShowGameOver();
_isGameOver = true;
}
else
{
// Else show respawn notification
Hud.Instance.ShowTerminated();
_isGameOver = false;
}
2025-06-23 09:19:41 +02:00
}
public override void ExitState()
{
base.ExitState();
2025-07-02 15:15:47 +02:00
Hud.Instance.HideTerminated();
2025-06-23 09:19:41 +02:00
}
public override void PhysicsProcessState(double delta)
{
base.PhysicsProcessState(delta);
}
public override void ProcessState(double delta)
{
base.ProcessState(delta);
2025-07-02 15:15:47 +02:00
if (_inputProvider.GetShootJustPressed())
{
if (_isGameOver)
{
// Restart Level
GlobalState.Instance.RestartLevel();
}
else
{
Respawn();
}
}
}
public void Respawn()
{
MainObject.GlobalPosition = GameController.Instance.LastCheckPointPosition;
_healthProvider.FillResource();
PoolingManager.Instance.ClearBullets();
_motivationProvider.CurrentResource -= 100f;
if (_motivationProvider.CurrentResource <= 1f)
{
_motivationProvider.CurrentResource = 1f;
}
ChangeState(PlayerState.Active);
2025-06-23 09:19:41 +02:00
}
}