boost
This commit is contained in:
1 parent
fe19035cc4
commit
a5ecc6374c
2 files changed
+16
-6
No files matched your search
+13
-6
@@ -37,17 +37,20 @@ public class PowerUnit {
|
|||||||
public float Shield => shieldCurrent;
|
public float Shield => shieldCurrent;
|
||||||
public float ShieldMax => shieldMax;
|
public float ShieldMax => shieldMax;
|
||||||
public string ShieldPct => $"{((shieldCurrent / shieldMax) * 100f):0}";
|
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
|
// Boost
|
||||||
List<(Output output, double expiresAt)> boostActive = new();
|
List<(Output output, double expiresAt)> boostActive = new();
|
||||||
static double boostFullChargeSeconds = 10f;
|
static double boostFullChargeSeconds = 10f;
|
||||||
static double boostDurationSeconds = 2f;
|
static double boostDurationSeconds = 2f;
|
||||||
double boostMax = 2f * boostDurationSeconds;
|
double boostMax = 2f * boostDurationSeconds;
|
||||||
double boostAvailable = 0f;
|
double boostAvailable = 0f; // in seconds
|
||||||
|
|
||||||
// public string BoostAvailable => $"{boostAvailable}";
|
public string BoostAvailable => $"{boostAvailable / 2f:0.0}";
|
||||||
public string BoostAvailable => $"{((boostAvailable / boostMax) * 100f):0}";
|
// public string BoostAvailable => $"{((boostAvailable / boostMax) * 100f):0}";
|
||||||
|
|
||||||
public float Acceleration =>
|
public float Acceleration =>
|
||||||
acceleration + boostActive.Count(b => b.output == Output.Acceleration) * baseOutput;
|
acceleration + boostActive.Count(b => b.output == Output.Acceleration) * baseOutput;
|
||||||
@@ -61,15 +64,19 @@ public class PowerUnit {
|
|||||||
double BoostRegen => (boostMax / boostFullChargeSeconds) * Time.fixedDeltaTime;
|
double BoostRegen => (boostMax / boostFullChargeSeconds) * Time.fixedDeltaTime;
|
||||||
|
|
||||||
public void Reset() {
|
public void Reset() {
|
||||||
shieldCurrent = initialShieldMax;
|
|
||||||
acceleration = initialAcceleration;
|
acceleration = initialAcceleration;
|
||||||
deceleration = initialDeceleration;
|
deceleration = initialDeceleration;
|
||||||
strafing = initialStrafing;
|
strafing = initialStrafing;
|
||||||
|
|
||||||
boostActive = new();
|
boostActive = new();
|
||||||
|
boostAvailable = 0f;
|
||||||
|
|
||||||
|
shieldMax = initialShieldMax ;
|
||||||
|
shieldCurrent = initialShieldMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deploy(Output output) {
|
public void Deploy(Output output) {
|
||||||
|
if (boostAvailable < boostDurationSeconds * (boostActive.Count + 1)) return;
|
||||||
boostActive.Add((output, Time.timeAsDouble + boostDurationSeconds));
|
boostActive.Add((output, Time.timeAsDouble + boostDurationSeconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +88,7 @@ public class PowerUnit {
|
|||||||
// if there are no boosts active we can increase the store
|
// if there are no boosts active we can increase the store
|
||||||
0 => BoostRegen,
|
0 => BoostRegen,
|
||||||
// if there are active boosts we deplete it
|
// 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);
|
double next = Math.Min(boostAvailable + delta, boostMax);
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ public class ShipControls : MonoBehaviour {
|
|||||||
// to minimise input lag we poll for the thrust vector every frame and set it
|
// to minimise input lag we poll for the thrust vector every frame and set it
|
||||||
// same with the camera, we always look around
|
// same with the camera, we always look around
|
||||||
void Update() {
|
void Update() {
|
||||||
|
// hot reloading fks up the input
|
||||||
|
if (input == null) Start();
|
||||||
|
|
||||||
UpdateCamera();
|
UpdateCamera();
|
||||||
thrust = getThrust();
|
thrust = getThrust();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user