Added start button to pause game

This commit is contained in:
Jason Durand 01 2022-04-03 00:21:51 -04:00
parent 5440c56426
commit 543ae0599b
3 changed files with 29 additions and 9 deletions

View File

@ -18,12 +18,20 @@ public class AIEntity : Entity
override protected void Update() { override protected void Update() {
base.Update(); base.Update();
if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop)
return;
if (currentState.UpdateState() is {} newState) if (currentState.UpdateState() is {} newState)
SwitchState(newState); SwitchState(newState);
} }
override protected void FixedUpdate() { override protected void FixedUpdate() {
base.FixedUpdate(); base.FixedUpdate();
if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop)
return;
if (currentState.FixedUpdateState() is {} newState) if (currentState.FixedUpdateState() is {} newState)
SwitchState(newState); SwitchState(newState);
} }

View File

@ -11,7 +11,8 @@ public class GameFlowManager : MonoBehaviour {
public enum PauseLevel { public enum PauseLevel {
NotPaused, NotPaused,
PreventActions, PreventActions,
WorldFreeze, NothingMoves,
TimeStop,
} }
[field: SerializeField] [field: SerializeField]
@ -39,7 +40,7 @@ public class GameFlowManager : MonoBehaviour {
void SetPauseLevel(PauseLevel value) { void SetPauseLevel(PauseLevel value) {
pauseLevel = value; pauseLevel = value;
Time.timeScale = value >= PauseLevel.WorldFreeze ? 0f : 1f; Time.timeScale = value >= PauseLevel.TimeStop ? 0f : 1f;
} }
public void GameOver() => SwitchState(new DeadFlowState(this)); public void GameOver() => SwitchState(new DeadFlowState(this));
@ -50,11 +51,17 @@ public class GameFlowManager : MonoBehaviour {
if (!ctx.WasPressedThisFrame(ref lastStartButton)) if (!ctx.WasPressedThisFrame(ref lastStartButton))
return; return;
if (CurrentState is StartFlowState) { switch (CurrentState) {
case StartFlowState _:
startPrompt.SetActive(false); startPrompt.SetActive(false);
SwitchState(new GameplayFlowState(this)); SwitchState(new GameplayFlowState(this));
} else if (CurrentState is GameplayFlowState) { break;
case GameplayFlowState _:
SwitchState(new PauseMenuFlowState(this)); SwitchState(new PauseMenuFlowState(this));
break;
case PauseMenuFlowState _:
SwitchState(new GameplayFlowState(this));
break;
} }
} }
@ -119,6 +126,11 @@ public class GameFlowManager : MonoBehaviour {
public PauseMenuFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {} public PauseMenuFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {}
public override void EnterState() { public override void EnterState() {
base.EnterState();
gameFlowManager.SetPauseLevel(PauseLevel.TimeStop);
}
public override void LeaveState() {
base.EnterState(); base.EnterState();
gameFlowManager.SetPauseLevel(PauseLevel.NotPaused); gameFlowManager.SetPauseLevel(PauseLevel.NotPaused);
} }

View File

@ -43,7 +43,7 @@ public class PlayerMovement : MonoBehaviour {
} }
void Update() { void Update() {
if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.WorldFreeze) if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop)
return; return;
if (currentState.UpdateState() is {} newState) if (currentState.UpdateState() is {} newState)
@ -51,7 +51,7 @@ public class PlayerMovement : MonoBehaviour {
} }
void FixedUpdate() { void FixedUpdate() {
if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.WorldFreeze) if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.TimeStop)
return; return;
if (safeZone != null && IsInSafeZone) { if (safeZone != null && IsInSafeZone) {