Enemies now have HP values

They give points on destruction
Points update on UI based on GameManager info
This commit is contained in:
TheDaringDan 2022-05-15 11:28:52 -04:00
parent 686e543b56
commit 989f2ef6fc
13 changed files with 174 additions and 40 deletions

View File

@ -99,8 +99,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3d66a652767ef0249ae03fc7183790d7, type: 3}
m_Name:
m_EditorClassIdentifier:
explosion: {fileID: 0}
explosionDebris: {fileID: 0}
landingPoint: {fileID: 0}
body: {fileID: 0}
flyingSpeed: 25
maxHP: 1
--- !u!111 &2748099788876613564
Animation:
m_ObjectHideFlags: 0

View File

@ -418,6 +418,7 @@ MonoBehaviour:
landingPoint: {fileID: 0}
body: {fileID: 4916962407531476031}
flyingSpeed: 50
maxHP: 1
--- !u!54 &3119225800646921348
Rigidbody:
m_ObjectHideFlags: 0

View File

@ -299,6 +299,7 @@ MonoBehaviour:
landingPoint: {fileID: 0}
body: {fileID: 6601239271941144557}
flyingSpeed: 50
maxHP: 2
--- !u!135 &1871861664620959488
SphereCollider:
m_ObjectHideFlags: 0

View File

@ -189,6 +189,63 @@ Transform:
m_Father: {fileID: 24694198}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &149397357
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1039445016908976971, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1039445016908976971, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_LocalPosition.x
value: 4.92
objectReference: {fileID: 0}
- target: {fileID: 1039445016908976971, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1039445016908976971, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_LocalPosition.z
value: 69.91
objectReference: {fileID: 0}
- target: {fileID: 1039445016908976971, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1039445016908976971, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1039445016908976971, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1039445016908976971, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1039445016908976971, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1039445016908976971, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1039445016908976971, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4677231174284622268, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
propertyPath: m_Name
value: Meteorite
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b9d1df034f0e64d49bb6cee268acbb3a, type: 3}
--- !u!1 &157775445
GameObject:
m_ObjectHideFlags: 0
@ -224,7 +281,7 @@ Transform:
- {fileID: 416476323}
- {fileID: 720696128}
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &160686337
GameObject:
@ -339,7 +396,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 20.367, y: -442.989, z: 350.052}
--- !u!1 &191659641
GameObject:
@ -567,7 +624,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 9
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 122.92801, y: -899.931, z: -13.550995}
--- !u!1 &249981357
GameObject:
@ -685,7 +742,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &256704238
GameObject:
@ -2426,7 +2483,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &893114646
GameObject:
@ -2903,7 +2960,7 @@ Transform:
- {fileID: 777216979}
- {fileID: 746849842}
m_Father: {fileID: 0}
m_RootOrder: 10
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1007592126
GameObject:
@ -3869,6 +3926,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: cbbe9406db76ed447bdc7c36883ee139, type: 3}
m_Name:
m_EditorClassIdentifier:
_controls: {fileID: 2089817556}
_state: 0
--- !u!4 &1461729127
Transform:
m_ObjectHideFlags: 0
@ -3882,7 +3941,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 12
m_RootOrder: 13
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1556790003
GameObject:
@ -4426,7 +4485,7 @@ Transform:
m_Children:
- {fileID: 1335518417}
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1752478143
GameObject:
@ -4766,7 +4825,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 127.08, y: -729.385, z: 146.565}
--- !u!1 &1770109362
GameObject:
@ -5661,6 +5720,7 @@ MonoBehaviour:
cannonForce: 600
fireRate: 0.5
fireTimer: 0
damage: 1
--- !u!65 &2089817558
BoxCollider:
m_ObjectHideFlags: 0
@ -5740,7 +5800,7 @@ Transform:
- {fileID: 1752478144}
- {fileID: 1030989722}
m_Father: {fileID: 0}
m_RootOrder: 11
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1002961340066712741
PrefabInstance:
@ -5751,7 +5811,7 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 1002961339065835566, guid: 3c33f37ff1cce2d48b88e476df2d47a0, type: 3}
propertyPath: m_RootOrder
value: 8
value: 9
objectReference: {fileID: 0}
- target: {fileID: 1002961339065835566, guid: 3c33f37ff1cce2d48b88e476df2d47a0, type: 3}
propertyPath: m_LocalPosition.x

View File

@ -44,9 +44,9 @@ public class CannonScript : MonoBehaviour
{
GameObject hitObject = hit.collider.gameObject;
if (hitObject.tag == "Enemy")
if (hitObject.CompareTag("Enemy"))
{
hitObject.GetComponent<Enemy>().IsShot(hit.distance);
hitObject.GetComponent<Enemy>().IsShot(hit.distance, damage);
}
}
}

View File

@ -18,7 +18,7 @@ public class DimensionController : MonoBehaviour
if (ReferenceEquals(enemy, null)) return;
// Update HP (temp for now)
_hp -= 1;
_hp -= enemy.DamageDealt();
// Destroy projectile
Destroy(other.gameObject);

View File

@ -1,5 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
@ -8,17 +7,22 @@ public class Enemy : MonoBehaviour
public ParticleSystem explosionDebris;
public Transform landingPoint;
public GameObject body;
[Header("Enemy Stats")]
public float flyingSpeed;
[SerializeField] private float maxHP = 1;
[SerializeField] private float damage = 1;
private float _health;
private void Update()
private void Start()
{
//Debug.DrawRay(transform.position, launchDirection, Color.red);
_health = maxHP;
}
public void SetLandingPoint(Transform landingPoint)
{
this.landingPoint = landingPoint;
gameObject.transform.LookAt(landingPoint);
}
void SpawnFinished()
@ -32,21 +36,28 @@ public class Enemy : MonoBehaviour
gameObject.GetComponent<Rigidbody>().velocity = gameObject.transform.forward * flyingSpeed;
}
public void IsShot(float distance)
public void IsShot(float distance, float turretDamage)
{
float destroyDelay = Mathf.Sqrt(distance)/(500/5);
Debug.Log(distance+" : "+destroyDelay);
StartCoroutine(Destroy(destroyDelay));
_health -= turretDamage;
if (_health <= 0) StartCoroutine(Destroy(destroyDelay));
}
private IEnumerator Destroy(float waitTime)
{
GameManager.Instance.GainPoints(maxHP);
gameObject.GetComponent<Rigidbody>().velocity = gameObject.transform.forward * (flyingSpeed / 3);
yield return new WaitForSeconds(waitTime);
body.SetActive(false);
explosion.Emit(100);
explosionDebris.Emit(40);
explosionDebris.Emit(40);
yield return new WaitForSeconds(3f);
Destroy(gameObject);
}
public float DamageDealt()
{
return damage;
}
}

View File

@ -3,8 +3,13 @@ using UnityEngine.InputSystem;
public class GameManager : MonoBehaviour
{
[SerializeField] private PlayerInput _controls;
[SerializeField, ReadOnly] private GameState _state;
[SerializeField] private PlayerInput controls;
[SerializeField] private CannonScript[] cannonList;
[SerializeField] private UIController uiController;
[Header("Game Variables")]
[SerializeField, ReadOnly] private GameState state;
[SerializeField, ReadOnly] private float points;
public static GameManager Instance { get; private set; }
@ -17,22 +22,81 @@ public class GameManager : MonoBehaviour
else
{
Instance = this;
_state = GameState.InGame;
state = GameState.InGame;
points = 0f;
uiController.UpdatePointsText(points);
}
}
public void TriggerGameOver(int dimensionID)
{
if (_state == GameState.Loss) return;
if (state == GameState.Loss) return;
// Stop controls
_controls.SwitchCurrentActionMap("UI");
controls.SwitchCurrentActionMap("UI");
// Show Game Over Message
Debug.Log("Game Over: Dimension " + dimensionID + " has been destroyed");
// Show Options (Return to Menu / Retry)
_state = GameState.Loss;
state = GameState.Loss;
}
public bool OnUpgrade(Upgrade selectedUpgrade)
{
if (!(points >= selectedUpgrade.GetCost())) return false;
points -= selectedUpgrade.GetCost();
uiController.UpdatePointsText(points);
return true;
}
public void UpgradeFireRate(FireRateUpgrade upgrade)
{
foreach (var cannon in cannonList)
{
cannon.SetFireRate(upgrade.GetFireRate());
}
}
public void UpgradeDamage(DamageUpgrade upgrade)
{
foreach (var cannon in cannonList)
{
cannon.SetDamage(upgrade.GetDamage());
}
}
public void UpgradeBullets(BulletsAmountUpgrade upgrade)
{
foreach (var cannon in cannonList)
{
cannon.SetBullets(upgrade.GetBullets());
}
}
public float GetPoints()
{
return points;
}
public void SetPoints(float nPoints)
{
points = nPoints;
uiController.UpdatePointsText(points);
}
public void SpendPoints(float amount)
{
if (amount > points) return;
points -= amount;
uiController.UpdatePointsText(points);
}
public void GainPoints(float amount)
{
points += amount;
uiController.UpdatePointsText(points);
}
}

View File

@ -5,17 +5,10 @@ using TMPro;
public class UIController : MonoBehaviour
{
[SerializeField]private PlayerController player;
[SerializeField]private TMP_Text pointsTxt;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
public void UpdatePointsText(float points)
{
pointsTxt.text = player.GetPoints().ToString();
pointsTxt.text = points.ToString("0");
}
}

View File

@ -21,7 +21,7 @@ public class BulletsAmountUpgrade : Upgrade
public override void Activate(){
if(base.UpgradeAttempt()){
player.UpgradeBullets(this);
GameManager.Instance.UpgradeBullets(this);
}
}
}

View File

@ -21,7 +21,7 @@ public class DamageUpgrade : Upgrade
public override void Activate(){
if(base.UpgradeAttempt()){
player.UpgradeDamage(this);
GameManager.Instance.UpgradeDamage(this);
}
}
}

View File

@ -21,7 +21,7 @@ public class FireRateUpgrade : Upgrade
public override void Activate(){
if(base.UpgradeAttempt()){
player.UpgradeFireRate(this);
GameManager.Instance.UpgradeFireRate(this);
}
}
}

View File

@ -45,7 +45,7 @@ public abstract class Upgrade : MonoBehaviour
}
protected bool UpgradeAttempt(){
if(lvlUnlocked < imgs.Length && player.OnUpgrade(this)){
if(lvlUnlocked < imgs.Length && GameManager.Instance.OnUpgrade(this)){
imgs[lvlUnlocked].sprite = unlockedSprite;
lvlUnlocked++;
if(lvlUnlocked < imgs.Length){