This commit is contained in:
ntr committed 2023-08-10 17:57:29 +10:00
1 parent 716da3b146
commit fc20f6e197
7 files changed
+258 -98

No files matched your search

+95 -22
View File
@@ -1,45 +1,118 @@
using System;
using UnityEngine;
public enum Output {
Acceleration,
Deceleration,
Strafing,
Shield,
}
public class PowerUnit {
static float baseOutput = 25.0f;
static float initialAcceleration = 2f * baseOutput;
static float initialDeceleration = 4f * baseOutput;
static float initialStrafing = 1f * baseOutput;
float acceleration = 2f * baseOutput;
float deceleration = 4f * baseOutput;
float strafing = 1f * baseOutput;
float stablisation = 75f;
float acceleration = initialAcceleration;
float deceleration = initialDeceleration;
float strafing = initialStrafing;
float shieldsCurrent = 5000f;
float shieldsMax = 5000f;
float shieldsRegen = 10f; // * 100 ticks per second = 5s fully recharge
static float initialShieldMax = 5000f;
float shieldCurrent = initialShieldMax;
float shieldMax = initialShieldMax;
float shieldRegen = 10f; // * 100 ticks per second = 5s fully recharge
int boostMax = 2;
int boostCharges = 0;
static float stablisation = 75f;
public float Acceleration => acceleration;
public float Deceleration => deceleration;
public float Strafing => strafing;
public float Shields => shieldsCurrent;
public float ShieldsMax => shieldsMax;
public float Shield => shieldCurrent;
public float ShieldMax => shieldMax;
public float Stabilisation => stablisation;
public string ShieldsPct => $"{((shieldsCurrent / shieldsMax) * 100f):0}";
public string ShieldPct => $"{((shieldCurrent / shieldMax) * 100f):0}";
public string BoostsAvailable => $"{boostCharges}";
public void Init() {
shieldsCurrent = shieldsMax;
shieldsRegen = (shieldsMax / 5f) * Time.fixedDeltaTime;
boostCharges = 0;
shieldCurrent = initialShieldMax;
acceleration = initialAcceleration;
deceleration = initialDeceleration;
strafing = initialStrafing;
}
public void Reassign(float accel, float decel, float strafe) {
acceleration = baseOutput * accel;
deceleration = baseOutput * decel;
strafing = baseOutput * strafe;
// Regeneration of boosts is tracked by the ShipControls
// it has to handle tracking the coroutines etc
public void BoostRegenerate() {
boostCharges = Math.Min(boostCharges + 1, boostMax);
Debug.Log($"Boosts available {boostCharges}");
}
// returns whether shields depleted
public bool ShieldsReduce(float amt) {
shieldsCurrent = shieldsCurrent - amt;
return shieldsCurrent < 0f;
public bool BoostUse(Output output) {
if (boostCharges < 1)
return false;
float newOutput = output switch {
Output.Acceleration => BoostUseAcceleration(),
Output.Deceleration => BoostUseDeceleration(),
Output.Strafing => BoostUseStrafing(),
Output.Shield => BoostUseShields(),
_ => 0f,
};
// Boosts are immediately used and tracked here
boostCharges--;
Debug.Log($"Set {output} to {newOutput}");
return true;
}
public void ShieldsRegenerate() {
shieldsCurrent = Math.Min(shieldsCurrent + shieldsRegen, shieldsMax);
float BoostUseAcceleration() => acceleration += baseOutput;
float BoostUseDeceleration() => deceleration += baseOutput;
float BoostUseStrafing() => strafing += baseOutput;
float BoostUseShields() {
float shieldFrac = shieldMax / shieldCurrent;
shieldMax = 7000f;
shieldCurrent = shieldMax * shieldFrac;
ShieldRegenRecalculate();
return shieldMax;
}
public void BoostEnd(Output output) {
float newOutput = output switch {
Output.Acceleration => BoostEndAcceleration(),
Output.Deceleration => BoostEndDeceleration(),
Output.Strafing => BoostEndStrafing(),
Output.Shield => BoostEndShields(),
_ => 0f,
};
Debug.Log($"Set {output} to {newOutput}");
}
float BoostEndAcceleration() => acceleration -= baseOutput;
float BoostEndDeceleration() => deceleration -= baseOutput;
float BoostEndStrafing() => strafing -= baseOutput;
float BoostEndShields() {
float shieldFrac = shieldMax / shieldCurrent;
shieldMax = 5000f;
shieldCurrent = shieldMax * shieldFrac;
ShieldRegenRecalculate();
return shieldMax;
}
// returns whether shield depleted
public bool ShieldReduce(float amt) {
shieldCurrent = shieldCurrent - amt;
return shieldCurrent < 0f;
}
public void ShieldRegenerate() => shieldCurrent = Math.Min(shieldCurrent + shieldRegen, shieldMax);
void ShieldRegenRecalculate() => shieldRegen = (shieldMax / 5f) * Time.fixedDeltaTime;
}