diff --git a/Assets/Scripts/Entities/Collectable.cs b/Assets/Scripts/Entities/Collectable.cs index 4194668..707ab5d 100644 --- a/Assets/Scripts/Entities/Collectable.cs +++ b/Assets/Scripts/Entities/Collectable.cs @@ -4,5 +4,5 @@ using UnityEngine; public class Collectable : Entity{ - public Collectable (EntityObjective referringObjective, GameObject entityPrefab) : base(referringObjective, entityPrefab) {} + public Collectable (EntityObjective referringObjective) : base(referringObjective) {} } diff --git a/Assets/Scripts/Entities/Entity.cs b/Assets/Scripts/Entities/Entity.cs index f640f49..9c91404 100644 --- a/Assets/Scripts/Entities/Entity.cs +++ b/Assets/Scripts/Entities/Entity.cs @@ -2,31 +2,19 @@ using System.Collections.Generic; using UnityEngine; -public abstract class Entity { +public abstract class Entity : MonoBehaviour{ EntityObjective referringObjective; - GameObject entityPrefab; - GameObject instance; // Constructor - public Entity(EntityObjective referringObjective, GameObject entityPrefab) + public Entity(EntityObjective referringObjective) { this.referringObjective = referringObjective; - this.entityPrefab = entityPrefab; - } - - // spawns the entity - public void Spawn(Transform spawnPoint) - { - // instance = GameObject.Instantiate (entityPrefab); - // instance.transform = spawnPoint; } // kills the entity public void Kill() { - GameObject.Destroy (instance); - referringObjective.Remove (this); - - instance = null; + if(referringObjective != null) + referringObjective.Remove (this.gameObject); } } diff --git a/Assets/Scripts/Entities/Mob.cs b/Assets/Scripts/Entities/Mob.cs index 0534e14..a8ef325 100644 --- a/Assets/Scripts/Entities/Mob.cs +++ b/Assets/Scripts/Entities/Mob.cs @@ -2,15 +2,35 @@ using System.Collections.Generic; using UnityEngine; -public class Mob : MonoBehaviour { +public abstract class Mob : Entity { + readonly int maxHP; + int currentHP; + bool isDead; - // Use this for initialization - void Start () { - + // Constructor + public Mob(EntityObjective referringObjective, int maxHP) : base(referringObjective) + { + this.maxHP = maxHP; + currentHP = maxHP; + + isDead = false; } - - // Update is called once per frame - void Update () { - + + // inflicts damage to this mob + public void InflictDamage(int damage) + { + currentHP -= damage; + if (!isDead && currentHP <= 0) + { + base.Kill (); + isDead = true; + } + } + + // Heals the mob + public void Heal(int healAmount) + { + if (!isDead) + currentHP = (currentHP + healAmount > currentHP) ? maxHP : currentHP + healAmount; } } diff --git a/Assets/Scripts/Objectives/EntityObjective.cs b/Assets/Scripts/Objectives/EntityObjective.cs index f454c08..9871471 100644 --- a/Assets/Scripts/Objectives/EntityObjective.cs +++ b/Assets/Scripts/Objectives/EntityObjective.cs @@ -3,13 +3,14 @@ using System.Collections.Generic; using UnityEngine; public class EntityObjective : Objective{ - List entityList; + List prefabList; + List entityList; List spawnPointList; // Constructor - public EntityObjective(Room objectiveCaller, List entityList) : base(objectiveCaller) + public EntityObjective(Room objectiveCaller, List prefabList) : base(objectiveCaller) { - this.entityList = entityList; + this.prefabList = prefabList; spawnPointList = objectiveCaller.GetSpawnpoints (); } @@ -18,14 +19,17 @@ public class EntityObjective : Objective{ { Random newRand = new Random (); - foreach (Entity i in entityList) - i.Spawn(spawnPointList[Random.Range(0, spawnPointList.Count)]); + foreach (GameObject i in prefabList) + { + GameObject tempObject = GameObject.Instantiate (i); + tempObject.transform.position = spawnPointList [Random.Range (0, spawnPointList.Count)].position; + } objectiveCaller.Lock(); } // Removes the entity from the list and completes the objective, if the list is empty - public void Remove(Entity inputEntity) + public void Remove(GameObject inputEntity) { entityList.Remove (inputEntity); if (entityList.Count == 0)