diff --git a/Assets/Prefabs/Vampire.prefab b/Assets/Prefabs/Vampire.prefab index 53d9a27..e5c3f87 100644 --- a/Assets/Prefabs/Vampire.prefab +++ b/Assets/Prefabs/Vampire.prefab @@ -54,6 +54,8 @@ MonoBehaviour: m_EditorClassIdentifier: gameFlowManager: {fileID: 0} stats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2} + globalCamera: {fileID: 0} + safeZonePrompt: {fileID: 0} --- !u!114 &3126145803593047825 MonoBehaviour: m_ObjectHideFlags: 0 @@ -91,6 +93,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 56c3e06ea5db48a40a7f55e72291cb0d, type: 3} m_Name: m_EditorClassIdentifier: + gameFlowManager: {fileID: 0} minionPrefabs: - {fileID: 2399377275812995974, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3} aimArrow: {fileID: 5124059627794595469} @@ -335,7 +338,7 @@ Rigidbody2D: m_LinearDrag: 0 m_AngularDrag: 0.05 m_GravityScale: 0 - m_Material: {fileID: 0} + m_Material: {fileID: 6200000, guid: 72c8b57001d325c418a78771641a077f, type: 2} m_Interpolate: 0 m_SleepingMode: 1 m_CollisionDetection: 0 diff --git a/Assets/Scripts/Arena.cs b/Assets/Scripts/Arena.cs index 995c266..365cd9a 100644 --- a/Assets/Scripts/Arena.cs +++ b/Assets/Scripts/Arena.cs @@ -31,7 +31,7 @@ public class Arena : MonoBehaviour { void Start() => StartCoroutine(SpawnEnemies()); void SpawnEnemy(int spawnerIndex) { - if (gameFlowManager.Paused) + if (!gameFlowManager.CanDoAction) return; var entity = Instantiate(entityPrefab, spawners[spawnerIndex].position, Quaternion.identity).GetComponent(); diff --git a/Assets/Scripts/GameFlowManager.cs b/Assets/Scripts/GameFlowManager.cs index a7cd120..22d2339 100644 --- a/Assets/Scripts/GameFlowManager.cs +++ b/Assets/Scripts/GameFlowManager.cs @@ -8,12 +8,16 @@ public class GameFlowManager : MonoBehaviour { [SerializeField] [Required] GameTimer gameTimer = null!; - /// - /// True if time is frozen (Start, Pause Menu, Dead) - /// - /// Could be renamed appropriately + public enum PauseLevel { + NotPaused, + PreventActions, + WorldFreeze, + } + [field: SerializeField] - public bool Paused { get; private set; } = true; + public PauseLevel pauseLevel { get; private set; } = PauseLevel.PreventActions; + + public bool CanDoAction => pauseLevel <= PauseLevel.NotPaused; public BaseState CurrentState { get; private set; } = null!; bool lastStartButton; @@ -33,10 +37,9 @@ public class GameFlowManager : MonoBehaviour { #endregion - void SetPause(bool value) { - Debug.Log($"Setting pause to {value}"); - Paused = value; - Time.timeScale = value ? 0f : 1f; + void SetPauseLevel(PauseLevel value) { + pauseLevel = value; + Time.timeScale = value >= PauseLevel.WorldFreeze ? 0f : 1f; } public void GameOver() => SwitchState(new DeadFlowState(this)); @@ -85,8 +88,7 @@ public class GameFlowManager : MonoBehaviour { public override void EnterState() { base.EnterState(); - Debug.Log("Press Start to start...!"); - gameFlowManager.SetPause(true); + gameFlowManager.SetPauseLevel(PauseLevel.PreventActions); } public override void LeaveState() { @@ -101,7 +103,7 @@ public class GameFlowManager : MonoBehaviour { base.EnterState(); gameFlowManager.gameTimer.StartTimer(); - gameFlowManager.SetPause(false); + gameFlowManager.SetPauseLevel(PauseLevel.NotPaused); } public override void LeaveState() { @@ -116,7 +118,7 @@ public class GameFlowManager : MonoBehaviour { public override void EnterState() { base.EnterState(); - gameFlowManager.SetPause(true); + gameFlowManager.SetPauseLevel(PauseLevel.NotPaused); } } @@ -127,7 +129,7 @@ public class GameFlowManager : MonoBehaviour { base.EnterState(); Debug.Log("You died!\nPress Accept to restart!"); - gameFlowManager.SetPause(true); + gameFlowManager.SetPauseLevel(PauseLevel.PreventActions); } public void ReloadGame() { diff --git a/Assets/Scripts/MinionThrower.cs b/Assets/Scripts/MinionThrower.cs index 325f862..94c0b9b 100644 --- a/Assets/Scripts/MinionThrower.cs +++ b/Assets/Scripts/MinionThrower.cs @@ -41,7 +41,7 @@ public class MinionThrower : MonoBehaviour { } public void ToggleThrowMode(InputAction.CallbackContext context) { - if (gameFlowManager.Paused) + if (!gameFlowManager.CanDoAction) return; if (context.performed) { diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index b48b0a5..424b41f 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -38,7 +38,7 @@ public class PlayerMovement : MonoBehaviour { } void Update() { - if (gameFlowManager.Paused) + if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.WorldFreeze) return; if (currentState.UpdateState() is {} newState) @@ -46,7 +46,7 @@ public class PlayerMovement : MonoBehaviour { } void FixedUpdate() { - if (gameFlowManager.Paused) + if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.WorldFreeze) return; if (safeZone != null && IsInSafeZone) { @@ -70,16 +70,19 @@ public class PlayerMovement : MonoBehaviour { #region Inputs public void OnMove(InputAction.CallbackContext ctx) { - moveDirection = ctx.ReadValue(); - if (moveDirection.sqrMagnitude > 1.0f) - moveDirection.Normalize(); + if (gameFlowManager.CanDoAction) { + moveDirection = ctx.ReadValue(); + if (moveDirection.sqrMagnitude > 1.0f) + moveDirection.Normalize(); + }else //TODO Should set to zero via event or callback + moveDirection = Vector2.zero; } public void OnJump(InputAction.CallbackContext ctx) { if (!ctx.WasPressedThisFrame(ref lastJumpButton)) return; - if (gameFlowManager.Paused || safeZone == null) + if (!gameFlowManager.CanDoAction || safeZone == null) return; if (IsInSafeZone) { diff --git a/Assets/Scripts/VampireEntity.cs b/Assets/Scripts/VampireEntity.cs index d0f390a..35642c7 100644 --- a/Assets/Scripts/VampireEntity.cs +++ b/Assets/Scripts/VampireEntity.cs @@ -18,10 +18,8 @@ public class VampireEntity : Entity { protected override void Update() { base.Update(); - if (gameFlowManager.Paused) - return; - - TakeDamage(playerStats.bloodLossRate * Time.deltaTime); + if (gameFlowManager.CanDoAction) + TakeDamage(playerStats.bloodLossRate * Time.deltaTime); } // public override void TakeDamage(float amount) { diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index ccc6b96..abbedcb 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -76,7 +76,7 @@ PlayerSettings: androidFullscreenMode: 1 defaultIsNativeResolution: 1 macRetinaSupport: 1 - runInBackground: 0 + runInBackground: 1 captureSingleScreen: 0 muteOtherAudioSources: 0 Prepare IOS For Recording: 0