Merge pull request #58 from dnutiu/stop-movement
Implement a way to stop player and enemies from moving
This commit is contained in:
commit
30b97bc582
5 changed files with 20 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
|
|
@ -35,5 +35,15 @@ namespace src.Helpers
|
|||
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 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue