SpringJam2026/Assets/Scripts/State/Game/GameRunningState.cs
2026-04-25 15:29:44 -05:00

50 lines
1.7 KiB
C#

using System.Collections;
using Management;
using UnityEngine;
namespace State.Game
{
public class GameRunningState : MainGameState
{
public override void OnEnter(Machine machine)
{
base.OnEnter(machine);
MainStateMachine.Respawn();
MainStateMachine.PlayerMovement.OnDeath += HandleDeath;
MainStateMachine.PlayerMovement.GetPickup += HandleTutorial;
MainStateMachine.PlayerMovement.EnterSpring += HandleTutorial;
}
private void HandleTutorial()
{
MainStateMachine.ShowTutorial(true);
}
private void HandleDeath()
{
MainStateMachine.StartCoroutine(DeathRoutine());
}
private IEnumerator DeathRoutine()
{
// Hide the guts
MainStateMachine.ShowDeathScreen(true);
Services.Instance.SFX.PlayOneShot(MainStateMachine.DeathSound);
// Cleanup before we remove player and fruits
MainStateMachine.PlayerMovement.OnDeath -= HandleDeath;
MainStateMachine.PlayerMovement.GetPickup -= HandleTutorial;
MainStateMachine.PlayerMovement.EnterSpring -= HandleTutorial;
MainStateMachine.Respawn();
// Reregister events
MainStateMachine.PlayerMovement.OnDeath += HandleDeath;
MainStateMachine.PlayerMovement.GetPickup += HandleTutorial;
MainStateMachine.PlayerMovement.EnterSpring += HandleTutorial;
// Wait a moment then restart the game
yield return new WaitForSeconds(2f);
MainStateMachine.ShowDeathScreen(false);
}
}
}