diff --git a/Assets/GameFlowManager.cs b/Assets/GameFlowManager.cs index 792f185..a8ad5f2 100644 --- a/Assets/GameFlowManager.cs +++ b/Assets/GameFlowManager.cs @@ -1,11 +1,91 @@ using UnityEngine; +using UnityEngine.InputSystem; //Could be a singleton public class GameFlowManager : MonoBehaviour { - [field: SerializeField] public bool Paused { get; private set; } = true; + [field: SerializeField] + public bool Paused { get; private set; } = true; + public BaseState CurrentState { get; private set; } = null!; + bool lastStartButton; + + #region Unity Messages + void Awake() => CurrentState = new StartFlowState(this); + + void Start() => CurrentState.EnterState(); + #endregion void SetPause(bool value) { Paused = value; Time.timeScale = value ? 0f : 1f; } + + #region Inputs + public void OnStart(InputAction.CallbackContext ctx) { + //feels pretty redundant ^^' + bool newValue = ctx.ReadValueAsButton(); + bool wasJustPressed = !lastStartButton && newValue; + lastStartButton = newValue; + + if (!wasJustPressed) + return; + + if (CurrentState is StartFlowState) + SwitchState(new GameplayFlowState(this)); + } + #endregion + + #region States + void SwitchState(BaseState newState) { + CurrentState.LeaveState(); + CurrentState = newState; + newState.EnterState(); + } + + abstract class GameFlowState : BaseState { + readonly protected GameFlowManager gameFlowManager; + + protected GameFlowState(GameFlowManager gameFlowManager) { + this.gameFlowManager = gameFlowManager; + } + } + + class StartFlowState : GameFlowState { + public StartFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {} + + public override void EnterState() { + base.EnterState(); + + Debug.Log("Press Start to start...!"); + gameFlowManager.SetPause(true); + } + + public override void LeaveState() { + Debug.Log("Let the games begin!!"); + } + } + class GameplayFlowState : GameFlowState { + public GameplayFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {} + + public override void EnterState() { + base.EnterState(); + gameFlowManager.SetPause(false); + } + } + class PauseMenuFlowState : GameFlowState { + public PauseMenuFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {} + + public override void EnterState() { + base.EnterState(); + gameFlowManager.SetPause(true); + } + } + class DeadFlowState : GameFlowState { + public DeadFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {} + + public override void EnterState() { + base.EnterState(); + gameFlowManager.SetPause(true); + } + } + #endregion } \ No newline at end of file diff --git a/Assets/Prefabs/Arena.prefab b/Assets/Prefabs/Arena.prefab index 0a3af7b..6498ff6 100644 --- a/Assets/Prefabs/Arena.prefab +++ b/Assets/Prefabs/Arena.prefab @@ -246,7 +246,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 63e66d66543b37e419694ac22a2941fd, type: 3} m_Name: m_EditorClassIdentifier: - stats: {fileID: 11400000, guid: 188711c0b201b1a45ad601ee20233b20, type: 2} + k__BackingField: {fileID: 11400000, guid: 188711c0b201b1a45ad601ee20233b20, type: 2} moatCollider: {fileID: 9196727423716235687} --- !u!1 &9196727423754814335 GameObject: @@ -1752,6 +1752,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 72794012913ccd840a73788b90573212, type: 3} m_Name: m_EditorClassIdentifier: + gameFlowManager: {fileID: 0} spawners: - {x: -10, y: 10, z: 0} - {x: 10, y: 10, z: 0} diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 762f234..3d38c30 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -408,44 +408,80 @@ PrefabInstance: m_Modifications: - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.size - value: 14 + value: 15 objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_ActionId value: d0405457-c534-4103-a0b6-cf113432b467 objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[14].m_ActionId + value: 01a06960-a379-49e3-9d58-9b7c8effcb3d + objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_ActionName value: Player/SwitchMinion[/Keyboard/q,/Keyboard/e,/XInputControllerWindows/leftShoulder,/XInputControllerWindows/rightShoulder] objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[14].m_ActionName + value: Player/Start[/XInputControllerWindows/start,/Keyboard/enter] + objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.size value: 1 objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.size + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_Mode value: 0 objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_Mode + value: 0 + objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_Target value: objectReference: {fileID: 1551362087} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_Target + value: + objectReference: {fileID: 1359990806} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_CallState value: 2 objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_CallState + value: 2 + objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_MethodName value: ChangeSelectedIcon objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_MethodName + value: OnStart + objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName value: MinionBar, Assembly-CSharp objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName + value: GameFlowManager, Assembly-CSharp + objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName value: UnityEngine.Object, UnityEngine objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName + value: UnityEngine.Object, UnityEngine + objectReference: {fileID: 0} - target: {fileID: 1214567908930553592, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: gameFlowManager value: diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index 43d2536..e0ac5b2 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -167,7 +167,7 @@ public class PlayerMovement : MonoBehaviour { class EnterSafeZoneMovementState : JumpingMovementState { readonly SafeZone safeZone; - public EnterSafeZoneMovementState(PlayerMovement playerMovement, SafeZone safeZone) : base(playerMovement, safeZone.stats.JumpDuration, safeZone.transform.position) { + public EnterSafeZoneMovementState(PlayerMovement playerMovement, SafeZone safeZone) : base(playerMovement, safeZone.Stats.JumpDuration, safeZone.transform.position) { this.safeZone = safeZone; } @@ -185,7 +185,7 @@ public class PlayerMovement : MonoBehaviour { class ExitSafeZoneMovementState : JumpingMovementState { readonly SafeZone safeZone; - public ExitSafeZoneMovementState(PlayerMovement playerMovement, SafeZone safeZone, Vector2 direction) : base(playerMovement, safeZone.stats.JumpDuration, safeZone.GetOutsidePosition(direction)) { + public ExitSafeZoneMovementState(PlayerMovement playerMovement, SafeZone safeZone, Vector2 direction) : base(playerMovement, safeZone.Stats.JumpDuration, safeZone.GetOutsidePosition(direction)) { this.safeZone = safeZone; } diff --git a/Assets/Settings/ConjureLudumDare50.inputactions b/Assets/Settings/ConjureLudumDare50.inputactions index 92bc982..1f0a6b1 100644 --- a/Assets/Settings/ConjureLudumDare50.inputactions +++ b/Assets/Settings/ConjureLudumDare50.inputactions @@ -40,6 +40,15 @@ "processors": "", "interactions": "", "initialStateCheck": false + }, + { + "name": "Start", + "type": "Button", + "id": "01a06960-a379-49e3-9d58-9b7c8effcb3d", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -284,6 +293,28 @@ "action": "SwitchMinion", "isComposite": false, "isPartOfComposite": true + }, + { + "name": "", + "id": "4715f838-717a-4f10-a668-05a6d761a7bc", + "path": "/start", + "interactions": "", + "processors": "", + "groups": "Gamepad", + "action": "Start", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "025fe243-6da7-4b27-9c02-f353d7a121df", + "path": "/enter", + "interactions": "", + "processors": "", + "groups": "Keyboard&Mouse", + "action": "Start", + "isComposite": false, + "isPartOfComposite": false } ] },