Implement a way to stop player and enemies from moving
This commit is contained in:
parent
929045a7b9
commit
a8320b2b3f
5 changed files with 20 additions and 3 deletions
|
@ -1,11 +1,13 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using src.Helpers;
|
using src.Helpers;
|
||||||
|
using src.Managers;
|
||||||
|
|
||||||
public abstract class EnemyBase : MonoBehaviour, IExplosable
|
public abstract class EnemyBase : MonoBehaviour, IExplosable
|
||||||
{
|
{
|
||||||
|
|
||||||
protected Vector2[] _directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right };
|
protected Vector2[] _directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right };
|
||||||
|
protected readonly GameStateManager gameStateManager = GameStateManager.Instance;
|
||||||
|
|
||||||
protected Rigidbody2D Rigidbody2d { get; set; }
|
protected Rigidbody2D Rigidbody2d { get; set; }
|
||||||
protected float Speed { get; set; }
|
protected float Speed { get; set; }
|
||||||
protected Vector2 Direction { get; set; }
|
protected Vector2 Direction { get; set; }
|
||||||
|
@ -20,6 +22,7 @@ public abstract class EnemyBase : MonoBehaviour, IExplosable
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
protected void FixedUpdate()
|
protected void FixedUpdate()
|
||||||
{
|
{
|
||||||
|
if (gameStateManager.IsGamePaused || gameStateManager.IsPlayerMovementForbidden) {return;}
|
||||||
Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime);
|
Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ public class DumbEnemy : EnemyBase
|
||||||
|
|
||||||
protected new void FixedUpdate()
|
protected new void FixedUpdate()
|
||||||
{
|
{
|
||||||
|
if (gameStateManager.IsGamePaused || gameStateManager.IsPlayerMovementForbidden) {return;}
|
||||||
if (transform.position.x == Mathf.Floor(transform.position.x) &&
|
if (transform.position.x == Mathf.Floor(transform.position.x) &&
|
||||||
transform.position.y == Mathf.Floor(transform.position.y))
|
transform.position.y == Mathf.Floor(transform.position.y))
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,5 +35,15 @@ namespace src.Helpers
|
||||||
PauseGame();
|
PauseGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ForbidPlayerMovement()
|
||||||
|
{
|
||||||
|
_gameStateManager.IsPlayerMovementForbidden = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AllowPlayerMovement()
|
||||||
|
{
|
||||||
|
_gameStateManager.IsPlayerMovementForbidden = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ namespace src.Managers
|
||||||
{
|
{
|
||||||
public static GameStateManager Instance { get; } = new GameStateManager();
|
public static GameStateManager Instance { get; } = new GameStateManager();
|
||||||
public bool IsGamePaused { get; internal set; }
|
public bool IsGamePaused { get; internal set; }
|
||||||
|
public bool IsPlayerMovementForbidden { get; internal set; }
|
||||||
public int Level { get; private set; } = 1;
|
public int Level { get; private set; } = 1;
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,5 +12,7 @@ namespace src.Managers
|
||||||
{
|
{
|
||||||
Level += 1;
|
Level += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -35,13 +35,13 @@ namespace src.Player
|
||||||
|
|
||||||
private void FixedUpdate()
|
private void FixedUpdate()
|
||||||
{
|
{
|
||||||
if (_gameStateManager.IsGamePaused) {return;}
|
if (_gameStateManager.IsGamePaused || _gameStateManager.IsPlayerMovementForbidden) {return;}
|
||||||
HandleMovement();
|
HandleMovement();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (_gameStateManager.IsGamePaused) {return;}
|
if (_gameStateManager.IsGamePaused || _gameStateManager.IsPlayerMovementForbidden) {return;}
|
||||||
HandleBomb();
|
HandleBomb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue