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 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 System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public abstract class Entity {
|
public abstract class Entity : MonoBehaviour{
|
||||||
EntityObjective referringObjective;
|
EntityObjective referringObjective;
|
||||||
GameObject entityPrefab;
|
|
||||||
GameObject instance;
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public Entity(EntityObjective referringObjective, GameObject entityPrefab)
|
public Entity(EntityObjective referringObjective)
|
||||||
{
|
{
|
||||||
this.referringObjective = 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
|
// kills the entity
|
||||||
public void Kill()
|
public void Kill()
|
||||||
{
|
{
|
||||||
GameObject.Destroy (instance);
|
if(referringObjective != null)
|
||||||
referringObjective.Remove (this);
|
referringObjective.Remove (this.gameObject);
|
||||||
|
|
||||||
instance = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,35 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Mob : MonoBehaviour {
|
public abstract class Mob : Entity {
|
||||||
|
readonly int maxHP;
|
||||||
|
int currentHP;
|
||||||
|
bool isDead;
|
||||||
|
|
||||||
// Use this for initialization
|
// Constructor
|
||||||
void Start () {
|
public Mob(EntityObjective referringObjective, int maxHP) : base(referringObjective)
|
||||||
|
{
|
||||||
|
this.maxHP = maxHP;
|
||||||
|
currentHP = maxHP;
|
||||||
|
|
||||||
|
isDead = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// inflicts damage to this mob
|
||||||
void Update () {
|
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;
|
using UnityEngine;
|
||||||
|
|
||||||
public class EntityObjective : Objective{
|
public class EntityObjective : Objective{
|
||||||
List<Entity> entityList;
|
List<GameObject> prefabList;
|
||||||
|
List<GameObject> entityList;
|
||||||
List<Transform> spawnPointList;
|
List<Transform> spawnPointList;
|
||||||
|
|
||||||
// Constructor
|
// 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 ();
|
spawnPointList = objectiveCaller.GetSpawnpoints ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,14 +19,17 @@ public class EntityObjective : Objective{
|
||||||
{
|
{
|
||||||
Random newRand = new Random ();
|
Random newRand = new Random ();
|
||||||
|
|
||||||
foreach (Entity i in entityList)
|
foreach (GameObject i in prefabList)
|
||||||
i.Spawn(spawnPointList[Random.Range(0, spawnPointList.Count)]);
|
{
|
||||||
|
GameObject tempObject = GameObject.Instantiate (i);
|
||||||
|
tempObject.transform.position = spawnPointList [Random.Range (0, spawnPointList.Count)].position;
|
||||||
|
}
|
||||||
|
|
||||||
objectiveCaller.Lock();
|
objectiveCaller.Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes the entity from the list and completes the objective, if the list is empty
|
// 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);
|
entityList.Remove (inputEntity);
|
||||||
if (entityList.Count == 0)
|
if (entityList.Count == 0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue