diff --git a/Assets/Scripts/src/Base/EnemyBase.cs b/Assets/Scripts/src/Base/EnemyBase.cs index 8c5434a..cf322e6 100644 --- a/Assets/Scripts/src/Base/EnemyBase.cs +++ b/Assets/Scripts/src/Base/EnemyBase.cs @@ -1,11 +1,13 @@ using UnityEngine; using src.Helpers; +using src.Managers; public abstract class EnemyBase : MonoBehaviour, IExplosable { protected Vector2[] _directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right }; - + protected readonly GameStateManager gameStateManager = GameStateManager.Instance; + protected Rigidbody2D Rigidbody2d { get; set; } protected float Speed { get; set; } protected Vector2 Direction { get; set; } @@ -20,6 +22,7 @@ public abstract class EnemyBase : MonoBehaviour, IExplosable // Update is called once per frame protected void FixedUpdate() { + if (gameStateManager.IsGamePaused || gameStateManager.IsPlayerMovementForbidden) {return;} Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime); } diff --git a/Assets/Scripts/src/Enemy/DumbEnemy.cs b/Assets/Scripts/src/Enemy/DumbEnemy.cs index 5a41c97..6701752 100644 --- a/Assets/Scripts/src/Enemy/DumbEnemy.cs +++ b/Assets/Scripts/src/Enemy/DumbEnemy.cs @@ -11,6 +11,7 @@ public class DumbEnemy : EnemyBase protected new void FixedUpdate() { + if (gameStateManager.IsGamePaused || gameStateManager.IsPlayerMovementForbidden) {return;} if (transform.position.x == Mathf.Floor(transform.position.x) && transform.position.y == Mathf.Floor(transform.position.y)) { diff --git a/Assets/Scripts/src/Helpers/ApplicationActions.cs b/Assets/Scripts/src/Helpers/ApplicationActions.cs index 1b91e34..39da0f5 100644 --- a/Assets/Scripts/src/Helpers/ApplicationActions.cs +++ b/Assets/Scripts/src/Helpers/ApplicationActions.cs @@ -35,5 +35,15 @@ namespace src.Helpers PauseGame(); } } + + public static void ForbidPlayerMovement() + { + _gameStateManager.IsPlayerMovementForbidden = true; + } + + public static void AllowPlayerMovement() + { + _gameStateManager.IsPlayerMovementForbidden = false; + } } } \ No newline at end of file diff --git a/Assets/Scripts/src/Managers/GameStateManager.cs b/Assets/Scripts/src/Managers/GameStateManager.cs index 2c620e5..3533686 100644 --- a/Assets/Scripts/src/Managers/GameStateManager.cs +++ b/Assets/Scripts/src/Managers/GameStateManager.cs @@ -4,6 +4,7 @@ namespace src.Managers { public static GameStateManager Instance { get; } = new GameStateManager(); public bool IsGamePaused { get; internal set; } + public bool IsPlayerMovementForbidden { get; internal set; } public int Level { get; private set; } = 1; @@ -11,5 +12,7 @@ namespace src.Managers { 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 5314ab4..309d850 100644 --- a/Assets/Scripts/src/Player/PlayerController.cs +++ b/Assets/Scripts/src/Player/PlayerController.cs @@ -35,13 +35,13 @@ namespace src.Player private void FixedUpdate() { - if (_gameStateManager.IsGamePaused) {return;} + if (_gameStateManager.IsGamePaused || _gameStateManager.IsPlayerMovementForbidden) {return;} HandleMovement(); } private void Update() { - if (_gameStateManager.IsGamePaused) {return;} + if (_gameStateManager.IsGamePaused || _gameStateManager.IsPlayerMovementForbidden) {return;} HandleBomb(); }