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
+5 -15
View File
@@ -3,30 +3,20 @@ using UnityEngine;
public class ShipPhysics : MonoBehaviour {
ShipControls ship;
float maxDmg = 150f;
float maxImpulse = 5000f;
void Awake() {
ship = GetComponent<ShipControls>();
}
void OnCollisionEnter(Collision collision) {
float totalForce = collision.impulse.magnitude / Time.fixedDeltaTime;
Debug.Log($"mag {collision.relativeVelocity.magnitude}");
Debug.Log($"impulse {collision.impulse} {collision.impulse.magnitude} {totalForce}");
// if (collision.relativeVelocity.magnitude > maxDmg) {
if (totalForce > maxImpulse) {
Debug.Log("Ddddestroyed by" + collision.gameObject.name);
ship.Respawn();
return;
}
if (collision.gameObject.tag == "TrackLimits") {
Debug.Log("Track Limits " + collision.gameObject.name);
ship.Respawn();
return;
}
float totalForce = collision.impulse.magnitude / Time.fixedDeltaTime;
Debug.Log($"mag {collision.relativeVelocity.magnitude}");
Debug.Log($"impulse {collision.impulse} {collision.impulse.magnitude} {totalForce}");
ship.Damage(totalForce, collision.gameObject.name);
}
}
+10 -3
View File
@@ -2,9 +2,16 @@
<Style src="project://database/Assets/Src/UI/TimingUi.uss?fileID=7433441132597879392&amp;guid=cf92f075876ddf7ffb4cd5c59633ad7b&amp;type=3#TimingUi" />
<ui:VisualElement name="VisualElement" style="-unity-font: url(&apos;project://database/Assets/UI%20Toolkit/Fonts/Jura-Medium.otf?fileID=12800000&amp;guid=65648a14640996362a6b0929c723b6e4&amp;type=3#Jura-Medium&apos;); -unity-font-definition: initial; flex-direction: row; flex-grow: 1;">
<ui:VisualElement name="left" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); justify-content: center; align-items: center;" />
<ui:VisualElement name="middle" style="flex-direction: row; flex-grow: 1; justify-content: center; align-self: center; margin-top: 20%; -unity-text-align: upper-center;">
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="speed" style="min-width: 5%; -unity-text-align: upper-right; flex-basis: 10%;" />
<ui:Label tabindex="-1" text="u/s" display-tooltip-when-elided="true" name="units" style="flex-basis: 10%; -unity-text-align: upper-left;" />
<ui:VisualElement name="middle" style="justify-content: flex-end;">
<ui:VisualElement name="speedCtr" style="flex-direction: row; justify-content: center;">
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="speed" style="min-width: 5%; -unity-text-align: upper-right; flex-basis: 10%;" />
<ui:Label tabindex="-1" text="u/s" display-tooltip-when-elided="true" name="units" style="flex-basis: 10%; -unity-text-align: upper-left;" />
</ui:VisualElement>
<ui:VisualElement name="shieldCtr" style="align-items: center; flex-direction: row; justify-content: center;">
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="shields" text="100" style="min-width: 5%; -unity-text-align: upper-right; flex-basis: 10%;" />
<ui:Label tabindex="-1" text="%" display-tooltip-when-elided="true" name="units" style="flex-basis: 10%; -unity-text-align: upper-left;" />
</ui:VisualElement>
<ui:VisualElement name="middleBottom" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-shrink: 0; flex-basis: 20%;" />
</ui:VisualElement>
<ui:VisualElement name="right" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); justify-content: center; align-items: center;" />
</ui:VisualElement>
+3
View File
@@ -11,6 +11,7 @@ public class ControlsUI : MonoBehaviour {
UIDocument uiDocument;
Label speed;
Label shields;
void OnEnable() {
Init();
@@ -19,6 +20,7 @@ public class ControlsUI : MonoBehaviour {
void Init() {
uiDocument = GetComponent<UIDocument>();
speed = uiDocument.rootVisualElement.Q<Label>("speed");
shields = uiDocument.rootVisualElement.Q<Label>("shields");
}
void FixedUpdate() {
@@ -29,5 +31,6 @@ public class ControlsUI : MonoBehaviour {
}
speed.text = $"{ship.Speed():0}";
shields.text = ship.Shields;
}
}
+9
View File
@@ -39,3 +39,12 @@
.hidden {
display: none;
}
.timingMiddle {
flex-direction: row;
flex-grow: 1;
justify-content: center;
align-self: center;
margin-top: 20%;
-unity-text-align: upper-center;
}