Files
spacerace/Assets/Src/PowerUnit.cs
T
2023-08-09 17:23:19 +10:00

46 lines
1.4 KiB
C#

using System;
using UnityEngine;
public class PowerUnit {
static float baseOutput = 25.0f;
float acceleration = 2f * baseOutput;
float deceleration = 4f * baseOutput;
float strafing = 1f * baseOutput;
float stablisation = 75f;
float shieldsCurrent = 5000f;
float shieldsMax = 5000f;
float shieldsRegen = 10f; // * 100 ticks per second = 5s fully recharge
public float Acceleration => acceleration;
public float Deceleration => deceleration;
public float Strafing => strafing;
public float Shields => shieldsCurrent;
public float ShieldsMax => shieldsMax;
public float Stabilisation => stablisation;
public string ShieldsPct => $"{((shieldsCurrent / shieldsMax) * 100f):0}";
public void Init() {
shieldsCurrent = shieldsMax;
shieldsRegen = (shieldsMax / 5f) * Time.fixedDeltaTime;
}
public void Reassign(float accel, float decel, float strafe, float shields) {
acceleration = baseOutput * accel;
deceleration = baseOutput * decel;
strafing = baseOutput * strafe;
shieldsRegen = shields;
}
// returns whether shields depleted
public bool ShieldsReduce(float amt) {
shieldsCurrent = shieldsCurrent - amt;
return shieldsCurrent < 0f;
}
public void ShieldsRegenerate() {
shieldsCurrent = Math.Min(shieldsCurrent + shieldsRegen, shieldsMax);
}
}