Lose blood overtime and switch to Dead state
This commit is contained in:
parent
bd5efcb31a
commit
172345c2ad
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
attackTimer = attackCooldown;
|
||||
}
|
||||
|
||||
protected virtual void Update() {}
|
||||
|
||||
protected virtual void FixedUpdate() {
|
||||
//TODO sqrMagnitude?
|
||||
if (beingPushed && rb.velocity.magnitude < stats.MinVelocityWhenPushed) {
|
||||
@ -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() {}
|
||||
}
|
||||
|
||||
@ -14,5 +14,4 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
movementSpeed: 3
|
||||
suckSpeed: 1
|
||||
safeZoneJumpDuration: 1.2
|
||||
safeZonePosition: {x: 0, y: 0, z: 0}
|
||||
bloodLossRate: 1
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user