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
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);
}
}

View File

@ -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:

View File

@ -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() {}
}

View File

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

View File

@ -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;
}

View File

@ -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();
}