Lose blood overtime and switch to Dead state

This commit is contained in:
Jason Durand 01 2022-04-02 13:22:38 -04:00
parent bd5efcb31a
commit 172345c2ad
6 changed files with 36 additions and 3 deletions

View File

@ -19,10 +19,13 @@ public class GameFlowManager : MonoBehaviour {
#endregion #endregion
void SetPause(bool value) { void SetPause(bool value) {
Debug.Log($"Setting pause to {value}");
Paused = value; Paused = value;
Time.timeScale = value ? 0f : 1f; Time.timeScale = value ? 0f : 1f;
} }
public void GameOver() => SwitchState(new DeadFlowState(this));
#region Inputs #region Inputs
public void OnStart(InputAction.CallbackContext ctx) { public void OnStart(InputAction.CallbackContext ctx) {
//feels pretty redundant ^^' //feels pretty redundant ^^'
@ -88,6 +91,8 @@ public class GameFlowManager : MonoBehaviour {
public override void EnterState() { public override void EnterState() {
base.EnterState(); base.EnterState();
Debug.Log("You died!");
gameFlowManager.SetPause(true); gameFlowManager.SetPause(true);
} }
} }

View File

@ -542,6 +542,10 @@ PrefabInstance:
propertyPath: healthBar propertyPath: healthBar
value: value:
objectReference: {fileID: 1464970062} 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} - target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
propertyPath: gameFlowManager propertyPath: gameFlowManager
value: value:

View File

@ -7,7 +7,7 @@ using UnityEngine;
public class Entity : MonoBehaviour public class Entity : MonoBehaviour
{ {
[SerializeField] [Required] [SerializeField] [Required]
GameFlowManager gameFlowManager = null!; protected GameFlowManager gameFlowManager = null!;
[field: SerializeField] [field: Required] [field: SerializeField] [field: Required]
protected EntityStats stats { get; private set; } protected EntityStats stats { get; private set; }
@ -34,6 +34,8 @@ public class Entity : MonoBehaviour
attackTimer = attackCooldown; attackTimer = attackCooldown;
} }
protected virtual void Update() {}
protected virtual void FixedUpdate() { protected virtual void FixedUpdate() {
//TODO sqrMagnitude? //TODO sqrMagnitude?
if (beingPushed && rb.velocity.magnitude < stats.MinVelocityWhenPushed) { if (beingPushed && rb.velocity.magnitude < stats.MinVelocityWhenPushed) {
@ -72,6 +74,7 @@ public class Entity : MonoBehaviour
Health -= amount; Health -= amount;
if(Health <= 0){ if(Health <= 0){
isAlive = false; isAlive = false;
OnDied();
return false; return false;
} }
return true; return true;
@ -94,4 +97,6 @@ public class Entity : MonoBehaviour
beingPushed = true; beingPushed = true;
rb.AddForce(impulse, ForceMode2D.Impulse); rb.AddForce(impulse, ForceMode2D.Impulse);
} }
protected virtual void OnDied() {}
} }

View File

@ -14,5 +14,4 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
movementSpeed: 3 movementSpeed: 3
suckSpeed: 1 suckSpeed: 1
safeZoneJumpDuration: 1.2 bloodLossRate: 1
safeZonePosition: {x: 0, y: 0, z: 0}

View File

@ -2,6 +2,12 @@
[CreateAssetMenu] [CreateAssetMenu]
public class PlayerStats : ScriptableObject { public class PlayerStats : ScriptableObject {
[field: SerializeField] [Min(0f)]
public float movementSpeed = 3f; public float movementSpeed = 3f;
[field: SerializeField] [Min(0f)]
public float suckSpeed = 1f; public float suckSpeed = 1f;
[field: SerializeField] [Min(0f)]
public float bloodLossRate = 1f;
} }

View File

@ -2,6 +2,9 @@
using UnityEngine; using UnityEngine;
public class VampireEntity : Entity { public class VampireEntity : Entity {
[SerializeField] [field: Required]
PlayerStats playerStats = null!;
[SerializeField] [Required] [SerializeField] [Required]
HealthBar healthBar; HealthBar healthBar;
[Min(10f)] [Min(10f)]
@ -14,10 +17,21 @@ public class VampireEntity : Entity {
initialHealth = Health; initialHealth = Health;
} }
protected override void Update() {
base.Update();
if (gameFlowManager.Paused)
return;
TakeDamage(playerStats.bloodLossRate * Time.deltaTime);
}
public override bool TakeDamage(float amount) { public override bool TakeDamage(float amount) {
bool stillAlive = base.TakeDamage(amount); bool stillAlive = base.TakeDamage(amount);
healthBar.SetHealthFraction(Health / initialHealth); healthBar.SetHealthFraction(Health / initialHealth);
return stillAlive; return stillAlive;
} }
protected override void OnDied() => gameFlowManager.GameOver();
} }