mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-10 21:47:08 +01:00
Soldier is a child of base
This commit is contained in:
parent
b41c920fb2
commit
f9804b48bb
@ -64,7 +64,7 @@ Rigidbody:
|
||||
m_UseGravity: 0
|
||||
m_IsKinematic: 0
|
||||
m_Interpolate: 0
|
||||
m_Constraints: 0
|
||||
m_Constraints: 126
|
||||
m_CollisionDetection: 0
|
||||
--- !u!114 &-4006122134844739070
|
||||
MonoBehaviour:
|
||||
|
||||
@ -64,7 +64,7 @@ Rigidbody:
|
||||
m_UseGravity: 0
|
||||
m_IsKinematic: 0
|
||||
m_Interpolate: 0
|
||||
m_Constraints: 0
|
||||
m_Constraints: 126
|
||||
m_CollisionDetection: 0
|
||||
--- !u!114 &1033819704020761458
|
||||
MonoBehaviour:
|
||||
@ -78,9 +78,6 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: d34caf35d0ce610f8bc87cf815ba1915, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
target: {fileID: 0}
|
||||
enemyType: 0
|
||||
ourType: 0
|
||||
maxHealthPoints: 100
|
||||
healthPoints: 100
|
||||
rangeAttack: 3
|
||||
@ -90,7 +87,13 @@ MonoBehaviour:
|
||||
lastAttackTick: -1
|
||||
nameText: {fileID: 6838251604148675782}
|
||||
healthPointsText: {fileID: 8012357605284019061}
|
||||
target: {fileID: 0}
|
||||
enemyType: 0
|
||||
ourType: 0
|
||||
movementDestination: {x: 0, y: 0}
|
||||
onDeath:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
--- !u!1 &1997457243244158843
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -10,7 +10,7 @@ public class Base : MonoBehaviour
|
||||
Ally,
|
||||
Enemy
|
||||
}
|
||||
[SerializeField] private SoldierType ourType;
|
||||
[SerializeField] protected SoldierType ourType;
|
||||
[SerializeField] private float maxHealthPoints = 100;
|
||||
[SerializeField] private float healthPoints = 100;
|
||||
|
||||
@ -23,7 +23,7 @@ public class Base : MonoBehaviour
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
protected void Start(){
|
||||
healthPoints = maxHealthPoints; // initialize health
|
||||
UpdateHPDisplay();
|
||||
|
||||
@ -51,11 +51,11 @@ public class Base : MonoBehaviour
|
||||
ourType = type;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
protected void OnDestroy()
|
||||
{
|
||||
Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject);
|
||||
}
|
||||
private void ReduceHP(float damage)
|
||||
protected void ReduceHP(float damage)
|
||||
{
|
||||
healthPoints -= damage;
|
||||
|
||||
@ -66,7 +66,7 @@ public class Base : MonoBehaviour
|
||||
Debug.Log("I took damage, my HP is now: " + healthPoints + " noooo!!!!", gameObject);
|
||||
}
|
||||
|
||||
private void UpdateHPDisplay()
|
||||
protected void UpdateHPDisplay()
|
||||
{
|
||||
healthPointsText.text = healthPoints.ToString() + "/" + maxHealthPoints.ToString();
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class Soldier : MonoBehaviour
|
||||
public class Soldier : Base
|
||||
{
|
||||
private Queue<Action> actions = new Queue<Action>();
|
||||
private Queue<Action> interrupts = new Queue<Action>();
|
||||
@ -40,26 +40,17 @@ public class Soldier : MonoBehaviour
|
||||
interrupts.Enqueue(new Movement()); // force soldier to find path to the new destination
|
||||
}
|
||||
#endregion
|
||||
public enum SoldierType
|
||||
{
|
||||
Ally,
|
||||
Enemy
|
||||
}
|
||||
|
||||
[Header("Values")]
|
||||
[SerializeField] private float maxHealthPoints = 10;
|
||||
[SerializeField] private float healthPoints = 1;
|
||||
[SerializeField] private float rangeAttack = 100;
|
||||
[SerializeField] private float rangeView = 1;
|
||||
[SerializeField] private float damageAttack = 1;
|
||||
[SerializeField] private int speedAttack = 1; // ticks between attacks
|
||||
[SerializeField] private int lastAttackTick = -1;
|
||||
[Header("References")]
|
||||
[SerializeField] private TMP_Text nameText = null;
|
||||
[SerializeField] private TMP_Text healthPointsText = null;
|
||||
[Header("Do-not-change-in-game values")]
|
||||
[SerializeField] private Soldier target;
|
||||
[SerializeField] private SoldierType enemyType;
|
||||
[SerializeField] private SoldierType ourType;
|
||||
|
||||
[SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
|
||||
|
||||
@ -67,39 +58,11 @@ public class Soldier : MonoBehaviour
|
||||
|
||||
[HideInInspector] public UnityEvent onDeath = new UnityEvent();
|
||||
|
||||
public SoldierType TempGetOwnType()
|
||||
{
|
||||
return ourType;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
healthPoints = maxHealthPoints; // initialize health
|
||||
UpdateHPDisplay();
|
||||
base.Start();
|
||||
setEnemyTag();
|
||||
|
||||
Debug.Log("Soldier: " + ourType.ToString() + " has appeared", gameObject);
|
||||
|
||||
switch (ourType)
|
||||
{
|
||||
case SoldierType.Ally:
|
||||
nameText.text = "Ally";
|
||||
nameText.color = Color.blue;
|
||||
break;
|
||||
case SoldierType.Enemy:
|
||||
nameText.text = "Enemy";
|
||||
nameText.color = Color.red;
|
||||
break;
|
||||
default:
|
||||
nameText.text = "how did we get here (forever)";
|
||||
nameText.color = new Color(255, 192, 203);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void setOwnTag(SoldierType type)
|
||||
{
|
||||
ourType = type;
|
||||
}
|
||||
|
||||
public void setEnemyTag()
|
||||
@ -115,10 +78,9 @@ public class Soldier : MonoBehaviour
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
TickSystem.OnTick -= HandleTick;
|
||||
onDeath.Invoke();
|
||||
|
||||
Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject);
|
||||
}
|
||||
|
||||
private void HandleTick(TickSystem.OnTickEventArgs tickEventArgs)
|
||||
@ -195,20 +157,4 @@ public class Soldier : MonoBehaviour
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
private void ReduceHP(float damage)
|
||||
{
|
||||
healthPoints -= damage;
|
||||
|
||||
if (healthPoints <= 0)
|
||||
Destroy(gameObject);
|
||||
|
||||
UpdateHPDisplay();
|
||||
Debug.Log("I took damage, oh my HP is now: " + healthPoints + " noooo!!!!", gameObject);
|
||||
}
|
||||
|
||||
private void UpdateHPDisplay()
|
||||
{
|
||||
healthPointsText.text = healthPoints.ToString() + "/" + maxHealthPoints.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user