we poppin

This commit is contained in:
ntr committed 2023-09-27 01:34:36 +10:00
1 parent 336945533b
commit 9f6e615653
88 files changed
+979 -170

No files matched your search

+4 -7
View File
@@ -54,6 +54,7 @@ public class PowerUnit {
public List<(Output output, double expiresAt)> BoostActive = new();
public double BoostProgress => boostProgress / boostMax;
public int BoostCharges => (int)(boostMax / boostDurationSeconds);
public int BoostChargesAvailable => (int)(boostAvailable / boostDurationSeconds);
public float Acceleration =>
acceleration + BoostActive.Count(b => b.output == Output.Acceleration) * baseOutput;
@@ -78,12 +79,13 @@ public class PowerUnit {
shieldCurrent = initialShieldMax;
}
public void Deploy(Output output) {
if (boostAvailable < boostDurationSeconds) return;
public bool Deploy(Output output) {
if (boostAvailable < boostDurationSeconds) return false;
BoostActive.Add((output, Time.timeAsDouble + boostDurationSeconds));
boostAvailable -= boostDurationSeconds;
if (output == Output.Shield) ShieldsBoost();
return true;
}
public void Tick() {
@@ -99,11 +101,6 @@ public class PowerUnit {
int count => count * Time.fixedDeltaTime * -1f,
};
// boost available gets dragged up by the clock
// when the delta is positive
// which can only happen when there are no active boosts
// check it vvvv
// Debug.Log($"Progress={boostProgress} actualAvailability={boostAvailable}");
double next = Math.Min(boostProgress + delta, boostMax);
boostProgress = Math.Max(0f, next);
if (delta > 0f) boostAvailable = boostProgress;
+49 -101
View File
@@ -13,11 +13,11 @@ public enum Sound {
Decelerate,
Strafe,
Damage,
Respawn,
Damage, // noise pop
Respawn, // noise pop
BoostAcceleration,
BoostDeceleration,
BoostAccelerate,
BoostDecelerate,
BoostStrafe,
BoostShield,
@@ -30,55 +30,64 @@ public enum Sound {
public class ShipAudio : MonoBehaviour {
// Match these two up
[SerializeField]
Sound[] soundNames;
Sound[] powerUnitSounds;
[SerializeField]
AudioClip[] clips;
AudioClip[] powerUnitClips;
[SerializeField]
AudioClip[] noiseClips;
[SerializeField]
AudioClip[] bigNoiseClips;
Dictionary<Sound, AudioClip> sounds = new();
AudioSource srcAccel;
AudioSource srcDecel;
AudioSource srcStrafe;
AudioSource srcShipAccel;
AudioSource srcShipDecel;
AudioSource srcShipStrafe;
AudioSource src;
SpaceRaceInput input;
ShipControls ship;
void Awake() {
for (int i = 0; i < clips.Length; i++) {
sounds.Add(soundNames[i], clips[i]);
for (int i = 0; i < powerUnitClips.Length; i++) {
sounds.Add(powerUnitSounds[i], powerUnitClips[i]);
}
ship = GetComponentInParent<ShipControls>();
srcAccel = gameObject.AddComponent<AudioSource>();
srcAccel.clip = sounds[Sound.Accelerate];
srcAccel.loop = true;
srcAccel.volume = 0f;
srcAccel.Play();
src = gameObject.AddComponent<AudioSource>();
srcDecel = gameObject.AddComponent<AudioSource>();
srcDecel.clip = sounds[Sound.Decelerate];
srcDecel.loop = true;
srcDecel.volume = 0f;
srcDecel.Play();
srcShipAccel = gameObject.AddComponent<AudioSource>();
srcShipAccel.clip = sounds[Sound.Accelerate];
srcShipAccel.loop = true;
srcShipAccel.volume = 0f;
srcShipAccel.Play();
srcStrafe = gameObject.AddComponent<AudioSource>();
srcStrafe.clip = sounds[Sound.Strafe];
srcStrafe.loop = true;
srcStrafe.volume = 0f;
srcStrafe.Play();
srcShipDecel = gameObject.AddComponent<AudioSource>();
srcShipDecel.clip = sounds[Sound.Decelerate];
srcShipDecel.loop = true;
srcShipDecel.volume = 0f;
srcShipDecel.Play();
srcShipStrafe = gameObject.AddComponent<AudioSource>();
srcShipStrafe.clip = sounds[Sound.Strafe];
srcShipStrafe.loop = true;
srcShipStrafe.volume = 0f;
srcShipStrafe.Play();
RegisterEvents();
}
void Update() {
srcAccel.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
srcDecel.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
srcStrafe.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
srcShipAccel.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
srcShipDecel.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
srcShipStrafe.pitch = Math.Min(1f, (1f / 500f) * ship.Speed);
// Super fucking annoying
// stops all the clicks and pops of starting / stopping the clips
// stops all the clicks and pops of starting / stopping the powerUnitClips
// 0.125s to get max volume
// == 8x per second...
float volumeDelta = Time.deltaTime * 8;
@@ -89,96 +98,35 @@ public class ShipAudio : MonoBehaviour {
bool strafing = input.ship.strafe.ReadValue<Vector2>().magnitude > 0;
if (accelerating) {
srcAccel.volume = Math.Min(1f, srcAccel.volume + volumeDelta);
srcShipAccel.volume = Math.Min(1f, srcShipAccel.volume + volumeDelta);
} else {
srcAccel.volume = Math.Max(0f, srcAccel.volume - decelDelta);
srcShipAccel.volume = Math.Max(0f, srcShipAccel.volume - decelDelta);
}
if (decelerating) {
srcDecel.volume = Math.Min(1f, srcDecel.volume + volumeDelta);
srcShipDecel.volume = Math.Min(1f, srcShipDecel.volume + volumeDelta);
} else {
srcDecel.volume = Math.Max(0f, srcDecel.volume - decelDelta);
srcShipDecel.volume = Math.Max(0f, srcShipDecel.volume - decelDelta);
}
if (strafing) {
srcStrafe.volume = Math.Min(1f, srcStrafe.volume + volumeDelta);
srcShipStrafe.volume = Math.Min(1f, srcShipStrafe.volume + volumeDelta);
} else {
srcStrafe.volume = Math.Max(0f, srcStrafe.volume - decelDelta);
srcShipStrafe.volume = Math.Max(0f, srcShipStrafe.volume - decelDelta);
}
}
// public void PlaySound(Sound s) {
// AudioSource src = sounds[s];
// src.Play(0);
// }
public void PlayNoise() {
int noiseIndex = UnityEngine.Random.Range(0, noiseClips.Length);
src.PlayOneShot(noiseClips[noiseIndex]);
}
void RegisterEvents() {
if (input == null)
input = new SpaceRaceInput();
input.ship.Enable();
// input.ship.accelerate.started += OnAccelerateStart;
// input.ship.accelerate.canceled += OnAccelerateCancel;
// input.ship.decelerate.started += OnDecelerateStart;
// input.ship.decelerate.canceled += OnDecelerateCancel;
// input.ship.strafe.started += OnStrafeStart;
// input.ship.strafe.canceled += OnStrafeCancel;
// these we only care about the initial press
// input.ship.respawn.started += OnRespawn;
// input.ship.quit.started += OnQuit;
// input.ship.powerUnit1.started += OnPowerUnit1;
// input.ship.powerUnit2.started += OnPowerUnit2;
// input.ship.powerUnit3.started += OnPowerUnit3;
// input.ship.powerUnit4.started += OnPowerUnit4;
}
// void OnDestroy() {
// input.ship.accelerate.started -= OnAccelerateStart;
// input.ship.accelerate.canceled -= OnAccelerateCancel;
// input.ship.decelerate.started -= OnDecelerateStart;
// input.ship.decelerate.canceled -= OnDecelerateCancel;
// input.ship.strafe.started -= OnStrafeStart;
// input.ship.strafe.canceled -= OnStrafeCancel;
// // these we only care about the initial press
// input.ship.respawn.started -= OnRespawn;
// input.ship.quit.started -= OnQuit;
// input.ship.powerUnit1.started -= OnPowerUnit1;
// input.ship.powerUnit2.started -= OnPowerUnit2;
// input.ship.powerUnit3.started -= OnPowerUnit3;
// input.ship.powerUnit4.started -= OnPowerUnit4;
// }
// void OnAcceleratePerformed(InputAction.CallbackContext _ctx) {
// Debug.Log(_ctx.duration);
// }
// void OnAccelerateStart(InputAction.CallbackContext _ctx) {
// srcAccel.Play();
// }
// void OnAccelerateCancel(InputAction.CallbackContext _ctx) {
// srcAccel.Stop();
// }
// void OnDecelerateStart(InputAction.CallbackContext _ctx) {
// srcDecel.Play();
// }
// void OnDecelerateCancel(InputAction.CallbackContext _ctx) {
// srcDecel.Stop();
// }
// void OnStrafeStart(InputAction.CallbackContext _ctx) {
// srcStrafe.Play();
// }
// void OnStrafeCancel(InputAction.CallbackContext _ctx) {
// srcStrafe.Stop();
// }
}
+16 -1
View File
@@ -9,6 +9,7 @@ public class ShipControls : MonoBehaviour {
public Camera aim;
public Timing timing;
ShipAudio audio;
SpaceRaceInput input;
Rigidbody rigidBody;
@@ -54,6 +55,7 @@ public class ShipControls : MonoBehaviour {
void Start() {
Cursor.lockState = CursorLockMode.Locked;
rigidBody = GetComponent<Rigidbody>();
audio = GetComponentInChildren<ShipAudio>();
// just stop the body from being affected by rotation for now
// until the 3p camera is in to explain why
@@ -115,7 +117,10 @@ public class ShipControls : MonoBehaviour {
rigidBody.rotation = Quaternion.RotateTowards(transform.rotation, aim.transform.rotation, step);
if (timing.timerEnabled) {
int boostBefore = powerUnit.BoostChargesAvailable;
powerUnit.Tick();
if (powerUnit.BoostChargesAvailable > boostBefore) OnBoostCharge();
}
}
@@ -160,6 +165,7 @@ public class ShipControls : MonoBehaviour {
}
public void Respawn() {
audio.PlayNoise();
// IMPORTANT
// stop the timer before we move the ship or anything
// otherwise it might generate a checkpoint time
@@ -188,15 +194,19 @@ public class ShipControls : MonoBehaviour {
public void Damage(float amt, string src) {
Debug.Log($"Damage {amt} from {src}");
audio.PlayNoise();
bool destroyed = powerUnit.ShieldReduce(amt);
if (destroyed) {
Debug.Log($"Ddddestroyed by {src}");
// play big noise!
Respawn();
}
}
void Deploy(Output output) {
powerUnit.Deploy(output);
bool deployed = powerUnit.Deploy(output);
if (deployed) audio.PlayNoise();
}
// I prefer doing it this way than registering the callbacks etc
@@ -250,6 +260,11 @@ public class ShipControls : MonoBehaviour {
void OnPowerUnit3(InputAction.CallbackContext ctx) => Deploy(Output.Strafing);
void OnPowerUnit4(InputAction.CallbackContext ctx) => Deploy(Output.Shield);
void OnBoostCharge() {
// audio.PlayNoise();
// do some ui fx whatever
}
void OnDrawGizmosSelected() {
if (Application.isPlaying == false)
return;
+7
View File
@@ -16,6 +16,9 @@ public class Timing: MonoBehaviour {
public List<SectorTime> sectorTimes;
public bool timerEnabled;
[SerializeField]
ShipAudio audio;
public string mapName;
public double sectorTime;
public double lapTime;
@@ -106,9 +109,13 @@ public class Timing: MonoBehaviour {
sectorTimes.Add(s);
Debug.Log($"{sectorTimes.Count} / {sectors.Length}");
// play a sound :)
if (audio != null) audio.PlayNoise();
// restart the timer for the next sector
sectorStart = Time.timeAsDouble;
// they finished a lap!
if (sectorTimes.Count == sectors.Length) {
EndLap();
+1
View File
@@ -110,6 +110,7 @@ public class MenuControls : MonoBehaviour {
}
void OnToggleMenu(InputAction.CallbackContext _ctx) {
audio.PlayNoise();
visible = !visible;
if (visible) {