diff --git a/Assets/Scripts/src/Managers/GameManager.cs b/Assets/Scripts/src/Managers/GameManager.cs index 408849e..859af92 100644 --- a/Assets/Scripts/src/Managers/GameManager.cs +++ b/Assets/Scripts/src/Managers/GameManager.cs @@ -4,6 +4,7 @@ using src.Level; using src.Level.src.Level; using src.Player; using UnityEngine; +using UnityEngine.SceneManagement; namespace src.Managers { @@ -86,6 +87,21 @@ namespace src.Managers ApplicationActions.HandlePauseKey(); } } + + private IEnumerator GameOver() + { + yield return new WaitForSeconds(4f); + _levelManager.DestroyLevel(); + _upgradeManager.DestroyUnclaimedUpgrades(); + _gameStateManager.ResetLevel(); + StartLevel(); + _playerController.Respawn(); + } + + public void StartGameOver() + { + StartCoroutine(GameOver()); + } public void StartNextLevel() { diff --git a/Assets/Scripts/src/Managers/GameStateManager.cs b/Assets/Scripts/src/Managers/GameStateManager.cs index f45110d..1ad1cbd 100644 --- a/Assets/Scripts/src/Managers/GameStateManager.cs +++ b/Assets/Scripts/src/Managers/GameStateManager.cs @@ -27,6 +27,11 @@ namespace src.Managers Level += 1; } + public void ResetLevel() + { + Level = 1; + } + } } \ No newline at end of file diff --git a/Assets/Scripts/src/Player/PlayerController.cs b/Assets/Scripts/src/Player/PlayerController.cs index 86df39d..a4865b5 100644 --- a/Assets/Scripts/src/Player/PlayerController.cs +++ b/Assets/Scripts/src/Player/PlayerController.cs @@ -161,6 +161,9 @@ namespace src.Player public void Respawn() { DebugHelper.LogInfo("Player is re-spawning!"); + _isDead = false; + _collider2D.enabled = true; + _animator.SetBool(AnimDeath, false); transform.SetPositionAndRotation(_respawnPosition.position, Quaternion.identity); _animator.Play("IdleDown"); } @@ -174,7 +177,7 @@ namespace src.Player _isDead = true; _collider2D.enabled = false; _animator.SetBool(AnimDeath, true); - Destroy(gameObject, 0.7f); + GameManager.Instance.StartGameOver(); } public void OnTriggerExit2D(Collider2D other)