boost cooldowns
This commit is contained in:
1 parent
e10e034702
commit
ccd8e2c923
3 files changed
+91
-40
No files matched your search
@@ -38,7 +38,7 @@ RenderSettings:
|
|||||||
m_ReflectionIntensity: 1
|
m_ReflectionIntensity: 1
|
||||||
m_CustomReflection: {fileID: 0}
|
m_CustomReflection: {fileID: 0}
|
||||||
m_Sun: {fileID: 705507994}
|
m_Sun: {fileID: 705507994}
|
||||||
m_IndirectSpecularColor: {r: 0.61784047, g: 0.63485193, b: 0.64917755, a: 1}
|
m_IndirectSpecularColor: {r: 0.61786336, g: 0.6344, b: 0.64918613, a: 1}
|
||||||
m_UseRadianceAmbientProbe: 0
|
m_UseRadianceAmbientProbe: 0
|
||||||
--- !u!157 &3
|
--- !u!157 &3
|
||||||
LightmapSettings:
|
LightmapSettings:
|
||||||
@@ -328,6 +328,18 @@ PrefabInstance:
|
|||||||
propertyPath: timingDoc
|
propertyPath: timingDoc
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 1643546429}
|
objectReference: {fileID: 1643546429}
|
||||||
|
- target: {fileID: 5313449993149091347, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3}
|
||||||
|
propertyPath: controlsUI
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1628786601}
|
||||||
|
- target: {fileID: 5313449993149091347, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3}
|
||||||
|
propertyPath: controlsDoc
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1628786602}
|
||||||
|
- target: {fileID: 5313449993149091347, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3}
|
||||||
|
propertyPath: crosshairDoc
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1582941309}
|
||||||
- target: {fileID: 5313449993149091347, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3}
|
- target: {fileID: 5313449993149091347, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3}
|
||||||
propertyPath: shipControls
|
propertyPath: shipControls
|
||||||
value:
|
value:
|
||||||
@@ -1293,6 +1305,39 @@ Transform:
|
|||||||
m_CorrespondingSourceObject: {fileID: 7588376663361902483, guid: 73ab56de058af21389c312279181f856, type: 3}
|
m_CorrespondingSourceObject: {fileID: 7588376663361902483, guid: 73ab56de058af21389c312279181f856, type: 3}
|
||||||
m_PrefabInstance: {fileID: 1549479480}
|
m_PrefabInstance: {fileID: 1549479480}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!114 &1582941309 stripped
|
||||||
|
MonoBehaviour:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 8483217137784193517, guid: 217f9c8f922f2d41cac52c3699bde478, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 702758806}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!114 &1628786601 stripped
|
||||||
|
MonoBehaviour:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 3792430562793951787, guid: 217f9c8f922f2d41cac52c3699bde478, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 702758806}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 8401c141ee093632d847505914412cee, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!114 &1628786602 stripped
|
||||||
|
MonoBehaviour:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 7583115105922956764, guid: 217f9c8f922f2d41cac52c3699bde478, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 702758806}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
--- !u!1 &1643546425 stripped
|
--- !u!1 &1643546425 stripped
|
||||||
GameObject:
|
GameObject:
|
||||||
m_CorrespondingSourceObject: {fileID: 2603084029878042569, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3}
|
m_CorrespondingSourceObject: {fileID: 2603084029878042569, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3}
|
||||||
|
|||||||
+13
-12
@@ -24,7 +24,7 @@ public class PowerUnit {
|
|||||||
float shieldRegen = 10f; // * 100 ticks per second = 5s fully recharge
|
float shieldRegen = 10f; // * 100 ticks per second = 5s fully recharge
|
||||||
|
|
||||||
int boostMax = 2;
|
int boostMax = 2;
|
||||||
int boostCharges = 2;
|
int boostCharges = 0;
|
||||||
|
|
||||||
static float stablisation = 75f;
|
static float stablisation = 75f;
|
||||||
|
|
||||||
@@ -37,9 +37,10 @@ public class PowerUnit {
|
|||||||
|
|
||||||
public string ShieldPct => $"{((shieldCurrent / shieldMax) * 100f):0}";
|
public string ShieldPct => $"{((shieldCurrent / shieldMax) * 100f):0}";
|
||||||
public string BoostsAvailable => $"{boostCharges}";
|
public string BoostsAvailable => $"{boostCharges}";
|
||||||
|
public bool BoostRecharging => boostCharges < boostMax;
|
||||||
|
|
||||||
public void Init() {
|
public void Init() {
|
||||||
boostCharges = boostMax;
|
boostCharges = 0;
|
||||||
shieldCurrent = initialShieldMax;
|
shieldCurrent = initialShieldMax;
|
||||||
acceleration = initialAcceleration;
|
acceleration = initialAcceleration;
|
||||||
deceleration = initialDeceleration;
|
deceleration = initialDeceleration;
|
||||||
@@ -48,20 +49,20 @@ public class PowerUnit {
|
|||||||
|
|
||||||
// Regeneration of boosts is tracked by the ShipControls
|
// Regeneration of boosts is tracked by the ShipControls
|
||||||
// it has to handle tracking the coroutines etc
|
// it has to handle tracking the coroutines etc
|
||||||
public void BoostRegenerate() {
|
public void BoostGenerate() {
|
||||||
boostCharges = Math.Min(boostCharges + 1, boostMax);
|
boostCharges = Math.Min(boostCharges + 1, boostMax);
|
||||||
Debug.Log($"Boosts available {boostCharges}");
|
Debug.Log($"Boosts available {boostCharges}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool BoostUse(Output output) {
|
public bool BoostDeploy(Output output) {
|
||||||
if (boostCharges < 1)
|
if (boostCharges < 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
float newOutput = output switch {
|
float newOutput = output switch {
|
||||||
Output.Acceleration => BoostUseAcceleration(),
|
Output.Acceleration => BoostDeployAcceleration(),
|
||||||
Output.Deceleration => BoostUseDeceleration(),
|
Output.Deceleration => BoostDeployDeceleration(),
|
||||||
Output.Strafing => BoostUseStrafing(),
|
Output.Strafing => BoostDeployStrafing(),
|
||||||
Output.Shield => BoostUseShields(),
|
Output.Shield => BoostDeployShields(),
|
||||||
_ => 0f,
|
_ => 0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,10 +74,10 @@ public class PowerUnit {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BoostUseAcceleration() => acceleration += baseOutput;
|
float BoostDeployAcceleration() => acceleration += baseOutput;
|
||||||
float BoostUseDeceleration() => deceleration += baseOutput;
|
float BoostDeployDeceleration() => deceleration += baseOutput;
|
||||||
float BoostUseStrafing() => strafing += baseOutput;
|
float BoostDeployStrafing() => strafing += baseOutput;
|
||||||
float BoostUseShields() {
|
float BoostDeployShields() {
|
||||||
float shieldFrac = shieldMax / shieldCurrent;
|
float shieldFrac = shieldMax / shieldCurrent;
|
||||||
shieldMax = 7000f;
|
shieldMax = 7000f;
|
||||||
shieldCurrent = shieldMax * shieldFrac;
|
shieldCurrent = shieldMax * shieldFrac;
|
||||||
|
|||||||
+32
-27
@@ -27,7 +27,8 @@ public class ShipControls : MonoBehaviour {
|
|||||||
float clampAngle = 90.0f;
|
float clampAngle = 90.0f;
|
||||||
|
|
||||||
public PowerUnit powerUnit = new();
|
public PowerUnit powerUnit = new();
|
||||||
List<IEnumerator> boostLifecycles = new();
|
IEnumerator boostDuration;
|
||||||
|
IEnumerator boostCooldown;
|
||||||
int boostDurationSeconds = 2;
|
int boostDurationSeconds = 2;
|
||||||
int boostCooldownSeconds = 5;
|
int boostCooldownSeconds = 5;
|
||||||
|
|
||||||
@@ -146,9 +147,8 @@ public class ShipControls : MonoBehaviour {
|
|||||||
camPitch = initialAim.eulerAngles.x;
|
camPitch = initialAim.eulerAngles.x;
|
||||||
camYaw = initialAim.eulerAngles.y;
|
camYaw = initialAim.eulerAngles.y;
|
||||||
|
|
||||||
foreach (var cd in boostLifecycles) {
|
if (boostCooldown != null) StopCoroutine(boostCooldown);
|
||||||
StopCoroutine(cd);
|
if (boostDuration != null) StopCoroutine(boostDuration);
|
||||||
}
|
|
||||||
|
|
||||||
powerUnit.Init();
|
powerUnit.Init();
|
||||||
}
|
}
|
||||||
@@ -158,9 +158,8 @@ public class ShipControls : MonoBehaviour {
|
|||||||
timing.StartTimer();
|
timing.StartTimer();
|
||||||
|
|
||||||
// start with 0 cooldowns and regen them
|
// start with 0 cooldowns and regen them
|
||||||
var cd = BoostCdLifecycle();
|
boostCooldown = BoostCooldown();
|
||||||
boostLifecycles.Add(cd);
|
StartCoroutine(boostCooldown);
|
||||||
StartCoroutine(cd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Speed() {
|
public float Speed() {
|
||||||
@@ -177,30 +176,36 @@ public class ShipControls : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoostUse(Output output) {
|
void BoostDeploy(Output output) {
|
||||||
bool used = powerUnit.BoostUse(output);
|
bool used = powerUnit.BoostDeploy(output);
|
||||||
if (!used) return;
|
if (!used) return;
|
||||||
|
|
||||||
var boost = BoostLifecycle(output);
|
// stops the cooldown until after our boost finishes
|
||||||
boostLifecycles.Add(boost);
|
if (boostCooldown != null) StopCoroutine(boostCooldown);
|
||||||
StartCoroutine(boost);
|
boostDuration = BoostDuration(output);
|
||||||
|
StartCoroutine(boostDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoostEnd(Output output) {
|
IEnumerator BoostDuration(Output output) {
|
||||||
powerUnit.BoostEnd(output);
|
Debug.Log($"BoostDuration {output}...");
|
||||||
var cd = BoostCdLifecycle();
|
|
||||||
boostLifecycles.Add(cd);
|
|
||||||
StartCoroutine(cd);
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator BoostLifecycle(Output output) {
|
|
||||||
yield return new WaitForSeconds(boostDurationSeconds);
|
yield return new WaitForSeconds(boostDurationSeconds);
|
||||||
BoostEnd(output);
|
BoostEnd(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator BoostCdLifecycle() {
|
void BoostEnd(Output output) {
|
||||||
yield return new WaitForSeconds(boostCooldownSeconds);
|
Debug.Log($"BoostEnd {output}...");
|
||||||
powerUnit.BoostRegenerate();
|
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
|
// 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 OnQuit(InputAction.CallbackContext ctx) => Application.Quit();
|
||||||
void OnRespawn(InputAction.CallbackContext ctx) => Respawn();
|
void OnRespawn(InputAction.CallbackContext ctx) => Respawn();
|
||||||
void OnPowerUnit1 (InputAction.CallbackContext ctx) => BoostUse(Output.Acceleration);
|
void OnPowerUnit1 (InputAction.CallbackContext ctx) => BoostDeploy(Output.Acceleration);
|
||||||
void OnPowerUnit2 (InputAction.CallbackContext ctx) => BoostUse(Output.Deceleration);
|
void OnPowerUnit2 (InputAction.CallbackContext ctx) => BoostDeploy(Output.Deceleration);
|
||||||
void OnPowerUnit3 (InputAction.CallbackContext ctx) => BoostUse(Output.Strafing);
|
void OnPowerUnit3 (InputAction.CallbackContext ctx) => BoostDeploy(Output.Strafing);
|
||||||
void OnPowerUnit4 (InputAction.CallbackContext ctx) => BoostUse(Output.Shield);
|
void OnPowerUnit4 (InputAction.CallbackContext ctx) => BoostDeploy(Output.Shield);
|
||||||
|
|
||||||
void OnDrawGizmosSelected() {
|
void OnDrawGizmosSelected() {
|
||||||
if (Application.isPlaying == false)
|
if (Application.isPlaying == false)
|
||||||
|
|||||||
Reference in new issue
Block a user