From a5ecc6374c9e17b60552a90328b32e80fa74e7a8 Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 15 Aug 2023 16:45:13 +1000 Subject: [PATCH] boost --- Assets/Src/PowerUnit.cs | 19 +++++++++++++------ Assets/Src/ShipControls.cs | 3 +++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Assets/Src/PowerUnit.cs b/Assets/Src/PowerUnit.cs index a0533da..ac9e554 100644 --- a/Assets/Src/PowerUnit.cs +++ b/Assets/Src/PowerUnit.cs @@ -37,17 +37,20 @@ public class PowerUnit { public float Shield => shieldCurrent; public float ShieldMax => shieldMax; public string ShieldPct => $"{((shieldCurrent / shieldMax) * 100f):0}"; - float ShieldRegen => (shieldMax / 5f) * Time.fixedDeltaTime; + float ShieldRegen => boostActive.Count switch { + 0 => (shieldMax / 5f) * Time.fixedDeltaTime, + _ => 0f, + }; // Boost List<(Output output, double expiresAt)> boostActive = new(); static double boostFullChargeSeconds = 10f; static double boostDurationSeconds = 2f; double boostMax = 2f * boostDurationSeconds; - double boostAvailable = 0f; + double boostAvailable = 0f; // in seconds - // public string BoostAvailable => $"{boostAvailable}"; - public string BoostAvailable => $"{((boostAvailable / boostMax) * 100f):0}"; + public string BoostAvailable => $"{boostAvailable / 2f:0.0}"; + // public string BoostAvailable => $"{((boostAvailable / boostMax) * 100f):0}"; public float Acceleration => acceleration + boostActive.Count(b => b.output == Output.Acceleration) * baseOutput; @@ -61,15 +64,19 @@ public class PowerUnit { double BoostRegen => (boostMax / boostFullChargeSeconds) * Time.fixedDeltaTime; public void Reset() { - shieldCurrent = initialShieldMax; acceleration = initialAcceleration; deceleration = initialDeceleration; strafing = initialStrafing; boostActive = new(); + boostAvailable = 0f; + + shieldMax = initialShieldMax ; + shieldCurrent = initialShieldMax; } public void Deploy(Output output) { + if (boostAvailable < boostDurationSeconds * (boostActive.Count + 1)) return; boostActive.Add((output, Time.timeAsDouble + boostDurationSeconds)); } @@ -81,7 +88,7 @@ public class PowerUnit { // if there are no boosts active we can increase the store 0 => BoostRegen, // if there are active boosts we deplete it - int count => count * Time.fixedDeltaTime, + int count => count * Time.fixedDeltaTime * -1f, }; double next = Math.Min(boostAvailable + delta, boostMax); diff --git a/Assets/Src/ShipControls.cs b/Assets/Src/ShipControls.cs index 06a2df2..f82a7f8 100755 --- a/Assets/Src/ShipControls.cs +++ b/Assets/Src/ShipControls.cs @@ -56,6 +56,9 @@ public class ShipControls : MonoBehaviour { // to minimise input lag we poll for the thrust vector every frame and set it // same with the camera, we always look around void Update() { + // hot reloading fks up the input + if (input == null) Start(); + UpdateCamera(); thrust = getThrust(); }