boost cooldowns
This commit is contained in:
1 parent
bcd2bc884b
commit
b35905da2d
3 files changed
+91
-40
No files matched your search
+13
-12
@@ -24,7 +24,7 @@ public class PowerUnit {
|
||||
float shieldRegen = 10f; // * 100 ticks per second = 5s fully recharge
|
||||
|
||||
int boostMax = 2;
|
||||
int boostCharges = 2;
|
||||
int boostCharges = 0;
|
||||
|
||||
static float stablisation = 75f;
|
||||
|
||||
@@ -37,9 +37,10 @@ public class PowerUnit {
|
||||
|
||||
public string ShieldPct => $"{((shieldCurrent / shieldMax) * 100f):0}";
|
||||
public string BoostsAvailable => $"{boostCharges}";
|
||||
public bool BoostRecharging => boostCharges < boostMax;
|
||||
|
||||
public void Init() {
|
||||
boostCharges = boostMax;
|
||||
boostCharges = 0;
|
||||
shieldCurrent = initialShieldMax;
|
||||
acceleration = initialAcceleration;
|
||||
deceleration = initialDeceleration;
|
||||
@@ -48,20 +49,20 @@ public class PowerUnit {
|
||||
|
||||
// Regeneration of boosts is tracked by the ShipControls
|
||||
// it has to handle tracking the coroutines etc
|
||||
public void BoostRegenerate() {
|
||||
public void BoostGenerate() {
|
||||
boostCharges = Math.Min(boostCharges + 1, boostMax);
|
||||
Debug.Log($"Boosts available {boostCharges}");
|
||||
}
|
||||
|
||||
public bool BoostUse(Output output) {
|
||||
public bool BoostDeploy(Output output) {
|
||||
if (boostCharges < 1)
|
||||
return false;
|
||||
|
||||
float newOutput = output switch {
|
||||
Output.Acceleration => BoostUseAcceleration(),
|
||||
Output.Deceleration => BoostUseDeceleration(),
|
||||
Output.Strafing => BoostUseStrafing(),
|
||||
Output.Shield => BoostUseShields(),
|
||||
Output.Acceleration => BoostDeployAcceleration(),
|
||||
Output.Deceleration => BoostDeployDeceleration(),
|
||||
Output.Strafing => BoostDeployStrafing(),
|
||||
Output.Shield => BoostDeployShields(),
|
||||
_ => 0f,
|
||||
};
|
||||
|
||||
@@ -73,10 +74,10 @@ public class PowerUnit {
|
||||
return true;
|
||||
}
|
||||
|
||||
float BoostUseAcceleration() => acceleration += baseOutput;
|
||||
float BoostUseDeceleration() => deceleration += baseOutput;
|
||||
float BoostUseStrafing() => strafing += baseOutput;
|
||||
float BoostUseShields() {
|
||||
float BoostDeployAcceleration() => acceleration += baseOutput;
|
||||
float BoostDeployDeceleration() => deceleration += baseOutput;
|
||||
float BoostDeployStrafing() => strafing += baseOutput;
|
||||
float BoostDeployShields() {
|
||||
float shieldFrac = shieldMax / shieldCurrent;
|
||||
shieldMax = 7000f;
|
||||
shieldCurrent = shieldMax * shieldFrac;
|
||||
|
||||
+32
-27
@@ -27,7 +27,8 @@ public class ShipControls : MonoBehaviour {
|
||||
float clampAngle = 90.0f;
|
||||
|
||||
public PowerUnit powerUnit = new();
|
||||
List<IEnumerator> boostLifecycles = new();
|
||||
IEnumerator boostDuration;
|
||||
IEnumerator boostCooldown;
|
||||
int boostDurationSeconds = 2;
|
||||
int boostCooldownSeconds = 5;
|
||||
|
||||
@@ -146,9 +147,8 @@ public class ShipControls : MonoBehaviour {
|
||||
camPitch = initialAim.eulerAngles.x;
|
||||
camYaw = initialAim.eulerAngles.y;
|
||||
|
||||
foreach (var cd in boostLifecycles) {
|
||||
StopCoroutine(cd);
|
||||
}
|
||||
if (boostCooldown != null) StopCoroutine(boostCooldown);
|
||||
if (boostDuration != null) StopCoroutine(boostDuration);
|
||||
|
||||
powerUnit.Init();
|
||||
}
|
||||
@@ -158,9 +158,8 @@ public class ShipControls : MonoBehaviour {
|
||||
timing.StartTimer();
|
||||
|
||||
// start with 0 cooldowns and regen them
|
||||
var cd = BoostCdLifecycle();
|
||||
boostLifecycles.Add(cd);
|
||||
StartCoroutine(cd);
|
||||
boostCooldown = BoostCooldown();
|
||||
StartCoroutine(boostCooldown);
|
||||
}
|
||||
|
||||
public float Speed() {
|
||||
@@ -177,30 +176,36 @@ public class ShipControls : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
void BoostUse(Output output) {
|
||||
bool used = powerUnit.BoostUse(output);
|
||||
void BoostDeploy(Output output) {
|
||||
bool used = powerUnit.BoostDeploy(output);
|
||||
if (!used) return;
|
||||
|
||||
var boost = BoostLifecycle(output);
|
||||
boostLifecycles.Add(boost);
|
||||
StartCoroutine(boost);
|
||||
// stops the cooldown until after our boost finishes
|
||||
if (boostCooldown != null) StopCoroutine(boostCooldown);
|
||||
boostDuration = BoostDuration(output);
|
||||
StartCoroutine(boostDuration);
|
||||
}
|
||||
|
||||
void BoostEnd(Output output) {
|
||||
powerUnit.BoostEnd(output);
|
||||
var cd = BoostCdLifecycle();
|
||||
boostLifecycles.Add(cd);
|
||||
StartCoroutine(cd);
|
||||
}
|
||||
|
||||
IEnumerator BoostLifecycle(Output output) {
|
||||
IEnumerator BoostDuration(Output output) {
|
||||
Debug.Log($"BoostDuration {output}...");
|
||||
yield return new WaitForSeconds(boostDurationSeconds);
|
||||
BoostEnd(output);
|
||||
}
|
||||
|
||||
IEnumerator BoostCdLifecycle() {
|
||||
yield return new WaitForSeconds(boostCooldownSeconds);
|
||||
powerUnit.BoostRegenerate();
|
||||
void BoostEnd(Output output) {
|
||||
Debug.Log($"BoostEnd {output}...");
|
||||
powerUnit.BoostEnd(output);
|
||||
|
||||
if (boostCooldown != null) StopCoroutine(boostCooldown);
|
||||
boostCooldown = BoostCooldown();
|
||||
StartCoroutine(boostCooldown);
|
||||
}
|
||||
|
||||
IEnumerator BoostCooldown() {
|
||||
while (powerUnit.BoostRecharging) {
|
||||
yield return new WaitForSeconds(boostCooldownSeconds);
|
||||
powerUnit.BoostGenerate();
|
||||
}
|
||||
}
|
||||
|
||||
// I prefer doing it this way than registering the callbacks etc
|
||||
@@ -234,10 +239,10 @@ public class ShipControls : MonoBehaviour {
|
||||
|
||||
void OnQuit(InputAction.CallbackContext ctx) => Application.Quit();
|
||||
void OnRespawn(InputAction.CallbackContext ctx) => Respawn();
|
||||
void OnPowerUnit1 (InputAction.CallbackContext ctx) => BoostUse(Output.Acceleration);
|
||||
void OnPowerUnit2 (InputAction.CallbackContext ctx) => BoostUse(Output.Deceleration);
|
||||
void OnPowerUnit3 (InputAction.CallbackContext ctx) => BoostUse(Output.Strafing);
|
||||
void OnPowerUnit4 (InputAction.CallbackContext ctx) => BoostUse(Output.Shield);
|
||||
void OnPowerUnit1 (InputAction.CallbackContext ctx) => BoostDeploy(Output.Acceleration);
|
||||
void OnPowerUnit2 (InputAction.CallbackContext ctx) => BoostDeploy(Output.Deceleration);
|
||||
void OnPowerUnit3 (InputAction.CallbackContext ctx) => BoostDeploy(Output.Strafing);
|
||||
void OnPowerUnit4 (InputAction.CallbackContext ctx) => BoostDeploy(Output.Shield);
|
||||
|
||||
void OnDrawGizmosSelected() {
|
||||
if (Application.isPlaying == false)
|
||||
|
||||
Reference in new issue
Block a user