Done some Stuff, and some more ...
This commit is contained in:
parent
09116b9b54
commit
bd9f61a671
4 changed files with 43 additions and 31 deletions
|
@ -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) {}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,14 @@ using System.Collections.Generic;
|
|||
using UnityEngine;
|
||||
|
||||
public class EntityObjective : Objective{
|
||||
List<Entity> entityList;
|
||||
List<GameObject> prefabList;
|
||||
List<GameObject> entityList;
|
||||
List<Transform> spawnPointList;
|
||||
|
||||
// Constructor
|
||||
public EntityObjective(Room objectiveCaller, List<Entity> entityList) : base(objectiveCaller)
|
||||
public EntityObjective(Room objectiveCaller, List<GameObject> 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)
|
||||
|
|
Loading…
Add table
Reference in a new issue