This commit is contained in:
ntr committed 2023-08-08 17:13:44 +10:00
1 parent 01e7df7a14
commit b65238e422
5 files changed
+53 -18

No files matched your search

+26
View File
@@ -1,3 +1,4 @@
using System;
using UnityEngine;
using UnityEngine.InputSystem;
@@ -30,6 +31,11 @@ public class ShipControls : MonoBehaviour, SpaceRaceInput.IShipActions {
float camYaw;
float clampAngle = 90.0f;
// Power Unit / Shields
float shields = 5000f;
float shieldsMax = 5000f;
float shieldsRegen = 10f; // * 100 ticks per second = 5s fully recharge
void Start() {
Cursor.lockState = CursorLockMode.Locked;
rigidBody = GetComponent<Rigidbody>();
@@ -102,6 +108,8 @@ public class ShipControls : MonoBehaviour, SpaceRaceInput.IShipActions {
// stop the ship jiggling because of micro camera movement
if (Quaternion.Angle(aim.transform.rotation, rigidBody.rotation) > 1f)
rigidBody.rotation = Quaternion.RotateTowards(transform.rotation, aim.transform.rotation, step);
RegenerateShields();
}
void UpdateCamera() {
@@ -172,6 +180,8 @@ public class ShipControls : MonoBehaviour, SpaceRaceInput.IShipActions {
camPitch = initialAim.eulerAngles.x;
camYaw = initialAim.eulerAngles.y;
shields = shieldsMax;
}
void OnDrawGizmosSelected() {
@@ -202,6 +212,22 @@ public class ShipControls : MonoBehaviour, SpaceRaceInput.IShipActions {
return rigidBody.velocity.magnitude;
}
public string Shields => $"{((shields / shieldsMax) * 100f):0}";
public void Damage(float amt, string src) {
Debug.Log($"Damage {amt} from {src}");
shields = shields - amt;
if (shields < 0f) {
Debug.Log($"Ddddestroyed by {src}");
Respawn();
}
}
void RegenerateShields() {
shields = Math.Min(shields + shieldsRegen, shieldsMax);
}
// We don't use these because we poll instead
// the callbacks are only invoked when the value changes
// aka if you hold accelerate it doesn't do what you expect