From 172345c2ad551edd0c6ec8a008fa70530787e59a Mon Sep 17 00:00:00 2001 From: Jason Durand 01 Date: Sat, 2 Apr 2022 13:22:38 -0400 Subject: [PATCH] Lose blood overtime and switch to Dead state --- Assets/GameFlowManager.cs | 5 +++++ Assets/Scenes/SampleScene.unity | 4 ++++ Assets/Scripts/Entity.cs | 7 ++++++- Assets/Scripts/Player Stats.asset | 3 +-- Assets/Scripts/PlayerStats.cs | 6 ++++++ Assets/Scripts/VampireEntity.cs | 14 ++++++++++++++ 6 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Assets/GameFlowManager.cs b/Assets/GameFlowManager.cs index 3a24fd4..a65382d 100644 --- a/Assets/GameFlowManager.cs +++ b/Assets/GameFlowManager.cs @@ -19,10 +19,13 @@ 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 ^^' @@ -88,6 +91,8 @@ public class GameFlowManager : MonoBehaviour { public override void EnterState() { base.EnterState(); + + Debug.Log("You died!"); gameFlowManager.SetPause(true); } } diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 3d38c30..15bc654 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -542,6 +542,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/Entity.cs b/Assets/Scripts/Entity.cs index de73b9d..990992a 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; } @@ -33,6 +33,8 @@ public class Entity : MonoBehaviour direction = new Vector3(1,0,0); attackTimer = attackCooldown; } + + protected virtual void Update() {} protected virtual void FixedUpdate() { //TODO sqrMagnitude? @@ -72,6 +74,7 @@ public class Entity : MonoBehaviour Health -= amount; if(Health <= 0){ isAlive = false; + OnDied(); return false; } return true; @@ -94,4 +97,6 @@ public class Entity : MonoBehaviour beingPushed = true; rb.AddForce(impulse, ForceMode2D.Impulse); } + + protected virtual void OnDied() {} } diff --git a/Assets/Scripts/Player Stats.asset b/Assets/Scripts/Player Stats.asset index 0fa5f7f..86973b8 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: 1 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/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