diff --git a/Assets/GameFlowManager.cs b/Assets/GameFlowManager.cs index 3a24fd4..a688d84 100644 --- a/Assets/GameFlowManager.cs +++ b/Assets/GameFlowManager.cs @@ -1,5 +1,6 @@ using UnityEngine; using UnityEngine.InputSystem; +using UnityEngine.SceneManagement; //Could be a singleton public class GameFlowManager : MonoBehaviour { @@ -11,6 +12,7 @@ public class GameFlowManager : MonoBehaviour { public bool Paused { get; private set; } = true; public BaseState CurrentState { get; private set; } = null!; bool lastStartButton; + bool lastAcceptButton; #region Unity Messages void Awake() => CurrentState = new StartFlowState(this); @@ -19,23 +21,29 @@ public class GameFlowManager : MonoBehaviour { #endregion void SetPause(bool value) { + Debug.Log($"Setting pause to {value}"); Paused = value; Time.timeScale = value ? 0f : 1f; } + public void GameOver() => SwitchState(new DeadFlowState(this)); + #region Inputs public void OnStart(InputAction.CallbackContext ctx) { - //feels pretty redundant ^^' - bool newValue = ctx.ReadValueAsButton(); - bool wasJustPressed = !lastStartButton && newValue; - lastStartButton = newValue; - - if (!wasJustPressed) + if (!ctx.WasPressedThisFrame(ref lastStartButton)) return; if (CurrentState is StartFlowState) SwitchState(new GameplayFlowState(this)); } + + public void OnAccept(InputAction.CallbackContext ctx) { + if (!ctx.WasPressedThisFrame(ref lastAcceptButton)) + return; + + if (CurrentState is DeadFlowState deadState) + deadState.ReloadGame(); + } #endregion #region States @@ -88,8 +96,15 @@ public class GameFlowManager : MonoBehaviour { public override void EnterState() { base.EnterState(); + + Debug.Log("You died!\nPress Accept to restart!"); gameFlowManager.SetPause(true); } + + public void ReloadGame() { + Debug.Log("Reloading scene..."); + SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); + } } #endregion } \ No newline at end of file diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 177a0b4..70122c9 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -428,7 +428,7 @@ PrefabInstance: m_Modifications: - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.size - value: 16 + value: 17 objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_ActionId @@ -440,7 +440,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[15].m_ActionId - value: f7e5243b-5304-4287-a2f5-0d36470450ad + value: 65aa4e67-f805-47b9-adc0-444ca0e0bec8 + objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[16].m_ActionId + value: 5017bbb1-a56a-40c6-add6-2360873a6945 objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_ActionName @@ -452,6 +456,10 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[15].m_ActionName + value: Player/Accept[/XInputControllerWindows/buttonSouth,/XInputControllerWindows/start,/Keyboard/enter] + objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[16].m_ActionName value: Player/Throw[/Keyboard/r,/XInputControllerWindows/buttonNorth] objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} @@ -466,6 +474,10 @@ PrefabInstance: propertyPath: m_ActionEvents.Array.data[15].m_PersistentCalls.m_Calls.Array.size value: 1 objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[16].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 @@ -478,6 +490,10 @@ PrefabInstance: propertyPath: m_ActionEvents.Array.data[15].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[16].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: @@ -489,6 +505,10 @@ PrefabInstance: - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[15].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[16].m_PersistentCalls.m_Calls.Array.data[0].m_Target + value: objectReference: {fileID: 330576709} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_CallState @@ -502,6 +522,10 @@ PrefabInstance: propertyPath: m_ActionEvents.Array.data[15].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[16].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 @@ -512,6 +536,10 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[15].m_PersistentCalls.m_Calls.Array.data[0].m_MethodName + value: OnAccept + objectReference: {fileID: 0} + - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: m_ActionEvents.Array.data[16].m_PersistentCalls.m_Calls.Array.data[0].m_MethodName value: ToggleThrowMode objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} @@ -524,6 +552,10 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: m_ActionEvents.Array.data[15].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[16].m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName value: MinionThrower, Assembly-CSharp objectReference: {fileID: 0} - target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} @@ -538,6 +570,10 @@ PrefabInstance: propertyPath: m_ActionEvents.Array.data[15].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[16].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: @@ -598,6 +634,10 @@ PrefabInstance: propertyPath: healthBar value: objectReference: {fileID: 1464970062} + - target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} + propertyPath: playerStats + value: + objectReference: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2} - target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} propertyPath: gameFlowManager value: diff --git a/Assets/Scripts/AIEntity.cs b/Assets/Scripts/AIEntity.cs index 81e0ab6..db0b678 100644 --- a/Assets/Scripts/AIEntity.cs +++ b/Assets/Scripts/AIEntity.cs @@ -2,11 +2,12 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Serialization; public class AIEntity : Entity { - [SerializeField] AIStats stats = null!; - public string ennemyName {get; protected set; } + [FormerlySerializedAs("stats")] [SerializeField] AIStats AIStats = null!; + public string? ennemyName {get; protected set; } abstract class BaseStateAI : BaseState{ protected AIEntity entity; @@ -59,7 +60,7 @@ public class AIEntity : Entity if(distance < lastDist){ lastDist = distance; chosenEntity = other; - if(lastDist <= entity.stats.closeEnough)break; + if(lastDist <= entity.AIStats.closeEnough)break; } } } diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index b7ebc6e..72f9457 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -7,7 +7,7 @@ using UnityEngine; public class Entity : MonoBehaviour { [SerializeField] [Required] - GameFlowManager gameFlowManager = null!; + protected GameFlowManager gameFlowManager = null!; [field: SerializeField] [field: Required] protected EntityStats stats { get; private set; } @@ -34,6 +34,8 @@ public class Entity : MonoBehaviour direction = new Vector3(1,0,0); attackTimer = attackCooldown; } + + protected virtual void Update() {} protected virtual void FixedUpdate() { //TODO sqrMagnitude? @@ -73,6 +75,7 @@ public class Entity : MonoBehaviour Health -= amount; if(Health <= 0){ isAlive = false; + OnDied(); return false; } return true; @@ -95,4 +98,6 @@ public class Entity : MonoBehaviour beingPushed = true; rb.AddForce(impulse, ForceMode2D.Impulse); } + + protected virtual void OnDied() {} } diff --git a/Assets/Scripts/Gladiator.cs b/Assets/Scripts/Gladiator.cs index 628a1d7..e7097fd 100644 --- a/Assets/Scripts/Gladiator.cs +++ b/Assets/Scripts/Gladiator.cs @@ -13,8 +13,8 @@ public class Gladiator : AIEntity } // Update is called once per frame - void Update() + protected override void Update() { - + base.Update(); } } diff --git a/Assets/Scripts/Monster.cs b/Assets/Scripts/Monster.cs index 0e3bf00..b636acd 100644 --- a/Assets/Scripts/Monster.cs +++ b/Assets/Scripts/Monster.cs @@ -19,8 +19,10 @@ public class Monster : AIEntity } // Update is called once per frame - void Update() + protected override void Update() { + base.Update(); + if(IsInAttackRange()){ if(attackTimer >= attackCooldown){ Attack(); diff --git a/Assets/Scripts/Player Stats.asset b/Assets/Scripts/Player Stats.asset index 0fa5f7f..7be6b71 100644 --- a/Assets/Scripts/Player Stats.asset +++ b/Assets/Scripts/Player Stats.asset @@ -14,5 +14,4 @@ MonoBehaviour: m_EditorClassIdentifier: movementSpeed: 3 suckSpeed: 1 - safeZoneJumpDuration: 1.2 - safeZonePosition: {x: 0, y: 0, z: 0} + bloodLossRate: 3 diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index 431f005..21dc09f 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -58,12 +58,7 @@ public class PlayerMovement : MonoBehaviour { } public void OnJump(InputAction.CallbackContext ctx) { - //feels pretty redundant ^^' - bool newValue = ctx.ReadValueAsButton(); - bool wasJustPressed = !lastJumpButton && newValue; - lastJumpButton = newValue; - - if (!wasJustPressed) + if (!ctx.WasPressedThisFrame(ref lastJumpButton)) return; if (gameFlowManager.Paused || safeZone == null) diff --git a/Assets/Scripts/PlayerStats.cs b/Assets/Scripts/PlayerStats.cs index 69f8edc..6729398 100644 --- a/Assets/Scripts/PlayerStats.cs +++ b/Assets/Scripts/PlayerStats.cs @@ -2,6 +2,12 @@ [CreateAssetMenu] public class PlayerStats : ScriptableObject { + [field: SerializeField] [Min(0f)] public float movementSpeed = 3f; + + [field: SerializeField] [Min(0f)] public float suckSpeed = 1f; + + [field: SerializeField] [Min(0f)] + public float bloodLossRate = 1f; } \ No newline at end of file diff --git a/Assets/Scripts/Utils.cs b/Assets/Scripts/Utils.cs new file mode 100644 index 0000000..32f7c6b --- /dev/null +++ b/Assets/Scripts/Utils.cs @@ -0,0 +1,11 @@ +using UnityEngine.InputSystem; + +public static class Utils { + public static bool WasPressedThisFrame(this InputAction.CallbackContext ctx, ref bool lastValue) { + bool newValue = ctx.ReadValueAsButton(); + bool wasJustPressed = !lastValue && newValue; + lastValue = newValue; + + return wasJustPressed; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Utils.cs.meta b/Assets/Scripts/Utils.cs.meta new file mode 100644 index 0000000..a11fcc2 --- /dev/null +++ b/Assets/Scripts/Utils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1e5065f064a94fed9f3cc40edc9c60af +timeCreated: 1648920968 \ No newline at end of file diff --git a/Assets/Scripts/VampireEntity.cs b/Assets/Scripts/VampireEntity.cs index 9be4fa5..57f4a2a 100644 --- a/Assets/Scripts/VampireEntity.cs +++ b/Assets/Scripts/VampireEntity.cs @@ -2,6 +2,9 @@ using UnityEngine; public class VampireEntity : Entity { + [SerializeField] [field: Required] + PlayerStats playerStats = null!; + [SerializeField] [Required] HealthBar healthBar; [Min(10f)] @@ -14,10 +17,21 @@ public class VampireEntity : Entity { initialHealth = Health; } + protected override void Update() { + base.Update(); + + if (gameFlowManager.Paused) + return; + + TakeDamage(playerStats.bloodLossRate * Time.deltaTime); + } + public override bool TakeDamage(float amount) { bool stillAlive = base.TakeDamage(amount); healthBar.SetHealthFraction(Health / initialHealth); return stillAlive; } + + protected override void OnDied() => gameFlowManager.GameOver(); } \ No newline at end of file diff --git a/Assets/Settings/ConjureLudumDare50.inputactions b/Assets/Settings/ConjureLudumDare50.inputactions index eba478a..7af29df 100644 --- a/Assets/Settings/ConjureLudumDare50.inputactions +++ b/Assets/Settings/ConjureLudumDare50.inputactions @@ -50,10 +50,19 @@ "interactions": "", "initialStateCheck": false }, + { + "name": "Accept", + "type": "Button", + "id": "65aa4e67-f805-47b9-adc0-444ca0e0bec8", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, { "name": "Throw", "type": "Button", - "id": "f7e5243b-5304-4287-a2f5-0d36470450ad", + "id": "5017bbb1-a56a-40c6-add6-2360873a6945", "expectedControlType": "Button", "processors": "", "interactions": "", @@ -327,7 +336,40 @@ }, { "name": "", - "id": "24e7587d-e2bf-41ae-8c97-29f00a7e8940", + "id": "6264d8cf-a124-4ae2-a851-5ce21b5b0306", + "path": "/buttonSouth", + "interactions": "", + "processors": "", + "groups": "Gamepad", + "action": "Accept", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "23fc3eaa-8abb-4c1a-b706-4dd2c2e2b760", + "path": "/start", + "interactions": "", + "processors": "", + "groups": "Gamepad", + "action": "Accept", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "4ce4b7b9-060f-4582-ae33-ac536c61a411", + "path": "/enter", + "interactions": "", + "processors": "", + "groups": "Keyboard&Mouse", + "action": "Accept", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "e1546881-eea2-45db-b33a-ea287fec82b3", "path": "/r", "interactions": "", "processors": "", @@ -338,7 +380,7 @@ }, { "name": "", - "id": "2bf854b2-68b4-429a-bdef-806c2897ccc0", + "id": "9da821b6-de33-4d2c-9ab9-413cf7334397", "path": "/buttonNorth", "interactions": "", "processors": "",