shields
This commit is contained in:
1 parent
bc0b39c575
commit
6b3f1f5338
5 files changed
+51
-16
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
@@ -30,6 +31,11 @@ public class ShipControls : MonoBehaviour, SpaceRaceInput.IShipActions {
|
|||||||
float camYaw;
|
float camYaw;
|
||||||
float clampAngle = 90.0f;
|
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() {
|
void Start() {
|
||||||
Cursor.lockState = CursorLockMode.Locked;
|
Cursor.lockState = CursorLockMode.Locked;
|
||||||
rigidBody = GetComponent<Rigidbody>();
|
rigidBody = GetComponent<Rigidbody>();
|
||||||
@@ -102,6 +108,8 @@ public class ShipControls : MonoBehaviour, SpaceRaceInput.IShipActions {
|
|||||||
// stop the ship jiggling because of micro camera movement
|
// stop the ship jiggling because of micro camera movement
|
||||||
if (Quaternion.Angle(aim.transform.rotation, rigidBody.rotation) > 1f)
|
if (Quaternion.Angle(aim.transform.rotation, rigidBody.rotation) > 1f)
|
||||||
rigidBody.rotation = Quaternion.RotateTowards(transform.rotation, aim.transform.rotation, step);
|
rigidBody.rotation = Quaternion.RotateTowards(transform.rotation, aim.transform.rotation, step);
|
||||||
|
|
||||||
|
RegenerateShields();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateCamera() {
|
void UpdateCamera() {
|
||||||
@@ -172,6 +180,8 @@ public class ShipControls : MonoBehaviour, SpaceRaceInput.IShipActions {
|
|||||||
|
|
||||||
camPitch = initialAim.eulerAngles.x;
|
camPitch = initialAim.eulerAngles.x;
|
||||||
camYaw = initialAim.eulerAngles.y;
|
camYaw = initialAim.eulerAngles.y;
|
||||||
|
|
||||||
|
shields = shieldsMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDrawGizmosSelected() {
|
void OnDrawGizmosSelected() {
|
||||||
@@ -202,6 +212,22 @@ public class ShipControls : MonoBehaviour, SpaceRaceInput.IShipActions {
|
|||||||
return rigidBody.velocity.magnitude;
|
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
|
// We don't use these because we poll instead
|
||||||
// the callbacks are only invoked when the value changes
|
// the callbacks are only invoked when the value changes
|
||||||
// aka if you hold accelerate it doesn't do what you expect
|
// aka if you hold accelerate it doesn't do what you expect
|
||||||
|
|||||||
@@ -3,30 +3,20 @@ using UnityEngine;
|
|||||||
public class ShipPhysics : MonoBehaviour {
|
public class ShipPhysics : MonoBehaviour {
|
||||||
ShipControls ship;
|
ShipControls ship;
|
||||||
|
|
||||||
float maxDmg = 150f;
|
|
||||||
float maxImpulse = 5000f;
|
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
ship = GetComponent<ShipControls>();
|
ship = GetComponent<ShipControls>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnCollisionEnter(Collision collision) {
|
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") {
|
if (collision.gameObject.tag == "TrackLimits") {
|
||||||
Debug.Log("Track Limits " + collision.gameObject.name);
|
Debug.Log("Track Limits " + collision.gameObject.name);
|
||||||
ship.Respawn();
|
ship.Respawn();
|
||||||
return;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,17 @@
|
|||||||
<Style src="project://database/Assets/Src/UI/TimingUi.uss?fileID=7433441132597879392&guid=cf92f075876ddf7ffb4cd5c59633ad7b&type=3#TimingUi" />
|
<Style src="project://database/Assets/Src/UI/TimingUi.uss?fileID=7433441132597879392&guid=cf92f075876ddf7ffb4cd5c59633ad7b&type=3#TimingUi" />
|
||||||
<ui:VisualElement name="VisualElement" style="-unity-font: url('project://database/Assets/UI%20Toolkit/Fonts/Jura-Medium.otf?fileID=12800000&guid=65648a14640996362a6b0929c723b6e4&type=3#Jura-Medium'); -unity-font-definition: initial; flex-direction: row; flex-grow: 1;">
|
<ui:VisualElement name="VisualElement" style="-unity-font: url('project://database/Assets/UI%20Toolkit/Fonts/Jura-Medium.otf?fileID=12800000&guid=65648a14640996362a6b0929c723b6e4&type=3#Jura-Medium'); -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="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: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" 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: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>
|
||||||
|
<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 name="right" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); justify-content: center; align-items: center;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
@@ -11,6 +11,7 @@ public class ControlsUI : MonoBehaviour {
|
|||||||
|
|
||||||
UIDocument uiDocument;
|
UIDocument uiDocument;
|
||||||
Label speed;
|
Label speed;
|
||||||
|
Label shields;
|
||||||
|
|
||||||
void OnEnable() {
|
void OnEnable() {
|
||||||
Init();
|
Init();
|
||||||
@@ -19,6 +20,7 @@ public class ControlsUI : MonoBehaviour {
|
|||||||
void Init() {
|
void Init() {
|
||||||
uiDocument = GetComponent<UIDocument>();
|
uiDocument = GetComponent<UIDocument>();
|
||||||
speed = uiDocument.rootVisualElement.Q<Label>("speed");
|
speed = uiDocument.rootVisualElement.Q<Label>("speed");
|
||||||
|
shields = uiDocument.rootVisualElement.Q<Label>("shields");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate() {
|
void FixedUpdate() {
|
||||||
@@ -29,5 +31,6 @@ public class ControlsUI : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
speed.text = $"{ship.Speed():0}";
|
speed.text = $"{ship.Speed():0}";
|
||||||
|
shields.text = ship.Shields;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,3 +39,12 @@
|
|||||||
.hidden {
|
.hidden {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.timingMiddle {
|
||||||
|
flex-direction: row;
|
||||||
|
flex-grow: 1;
|
||||||
|
justify-content: center;
|
||||||
|
align-self: center;
|
||||||
|
margin-top: 20%;
|
||||||
|
-unity-text-align: upper-center;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user