aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'nGJ2019/Assets/Scripts')
-rw-r--r--nGJ2019/Assets/Scripts/DragonMovement.cs12
-rw-r--r--nGJ2019/Assets/Scripts/EnemyCollider.cs8
-rw-r--r--nGJ2019/Assets/Scripts/EventTimeline.cs10
-rw-r--r--nGJ2019/Assets/Scripts/HealthBar.cs54
-rw-r--r--nGJ2019/Assets/Scripts/ObstacleSpawner.cs12
-rw-r--r--nGJ2019/Assets/Scripts/ObstacleType.cs5
6 files changed, 89 insertions, 12 deletions
diff --git a/nGJ2019/Assets/Scripts/DragonMovement.cs b/nGJ2019/Assets/Scripts/DragonMovement.cs
index 04f1c3a..4ba179d 100644
--- a/nGJ2019/Assets/Scripts/DragonMovement.cs
+++ b/nGJ2019/Assets/Scripts/DragonMovement.cs
@@ -12,6 +12,8 @@ public class DragonMovement : MonoBehaviour
public float horizontalBound = 6f;
public float verticalBound = 4f;
+ public HealthBar healthBar;
+
private SwarmSystem swarm;
private enum State {normal, swirl, slim, spread};
@@ -198,4 +200,14 @@ public class DragonMovement : MonoBehaviour
Gizmos.DrawWireCube(Vector3.zero, new Vector3(2*horizontalBound, 2*verticalBound, 0));
}
+ void OnTriggerEnter(Collider other)
+ {
+ EnemyCollider enemy = other.gameObject.GetComponent<EnemyCollider>();
+ if(enemy != null)
+ {
+ Debug.Log(enemy.type == ObstacleType.alfa ? "alfa hit" : "beta hit");
+ healthBar.health--;
+ }
+ }
+
} \ No newline at end of file
diff --git a/nGJ2019/Assets/Scripts/EnemyCollider.cs b/nGJ2019/Assets/Scripts/EnemyCollider.cs
new file mode 100644
index 0000000..89144d9
--- /dev/null
+++ b/nGJ2019/Assets/Scripts/EnemyCollider.cs
@@ -0,0 +1,8 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class EnemyCollider : MonoBehaviour
+{
+ public ObstacleType type;
+}
diff --git a/nGJ2019/Assets/Scripts/EventTimeline.cs b/nGJ2019/Assets/Scripts/EventTimeline.cs
index 1aef359..21b0bdb 100644
--- a/nGJ2019/Assets/Scripts/EventTimeline.cs
+++ b/nGJ2019/Assets/Scripts/EventTimeline.cs
@@ -4,15 +4,13 @@ using System.Collections.Generic;
public class EventTimeline
{
- public enum SpawnEventType {alfa, beta};
-
- public class SpawnEvent
+ public class SpawnEvent
{
public float time;
public float height;
- public SpawnEventType type;
+ public ObstacleType type;
- public SpawnEvent(float time, float height, SpawnEventType type)
+ public SpawnEvent(float time, float height, ObstacleType type)
{
this.time = time;
this.height = height;
@@ -31,7 +29,7 @@ public class EventTimeline
currentTime = 0;
}
- public void Add(float time, float height, SpawnEventType type)
+ public void Add(float time, float height, ObstacleType type)
{
futureEvents.Add(new SpawnEvent(time, height, type));
futureEvents.Sort((x,y) => x.time.CompareTo(y.time));
diff --git a/nGJ2019/Assets/Scripts/HealthBar.cs b/nGJ2019/Assets/Scripts/HealthBar.cs
new file mode 100644
index 0000000..4c30b42
--- /dev/null
+++ b/nGJ2019/Assets/Scripts/HealthBar.cs
@@ -0,0 +1,54 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class HealthBar : MonoBehaviour
+{
+ public GameObject crystalPrefab;
+ public Material liveCrystal;
+ public Material deadCrystal;
+
+ public int lives;
+
+ private int currentHealth;
+ public int health
+ {
+ get{return currentHealth;}
+ set
+ {
+ currentHealth = value;
+ updateCrystals();
+ }
+ }
+
+ private List<Renderer> crystals = new List<Renderer>();
+
+ private void updateCrystals()
+ {
+ for(int i=0; i<lives; i++)
+ {
+ if(health > i)
+ crystals[i].material = liveCrystal;
+ else
+ crystals[i].material = deadCrystal;
+ }
+ }
+
+ void Start()
+ {
+ for(int i=0; i<lives; i++)
+ {
+ GameObject crystal = Instantiate(crystalPrefab, transform.position + Vector3.right*0.5f*i, Quaternion.identity);
+ crystals.Add(crystal.GetComponentInChildren<Renderer>());
+ }
+
+ health = lives;
+ updateCrystals();
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+
+ }
+}
diff --git a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs
index d007513..7d2c2a9 100644
--- a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs
+++ b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs
@@ -15,10 +15,10 @@ public class ObstacleSpawner : MonoBehaviour
{
GameObject prefab = null;
- if(e.type == EventTimeline.SpawnEventType.alfa)
+ if(e.type == ObstacleType.alfa)
prefab = alfaPrefab;
- if(e.type == EventTimeline.SpawnEventType.beta)
+ if(e.type == ObstacleType.beta)
prefab = betaPrefab;
Instantiate(prefab, new Vector3(spawnLine, e.height, 0), Quaternion.identity);
@@ -26,10 +26,10 @@ public class ObstacleSpawner : MonoBehaviour
void Start()
{
- timeline.Add(2, 2, EventTimeline.SpawnEventType.alfa);
- timeline.Add(4, 2, EventTimeline.SpawnEventType.beta);
- timeline.Add(5, -2, EventTimeline.SpawnEventType.beta);
- timeline.Add(7, -3, EventTimeline.SpawnEventType.alfa);
+ timeline.Add(2, 4, ObstacleType.alfa);
+ timeline.Add(4, 2, ObstacleType.beta);
+ timeline.Add(5, -2, ObstacleType.beta);
+ timeline.Add(7, -3, ObstacleType.alfa);
timeline.OnSpawnEvent += spawnOnEvent;
}
diff --git a/nGJ2019/Assets/Scripts/ObstacleType.cs b/nGJ2019/Assets/Scripts/ObstacleType.cs
new file mode 100644
index 0000000..c62f629
--- /dev/null
+++ b/nGJ2019/Assets/Scripts/ObstacleType.cs
@@ -0,0 +1,5 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public enum ObstacleType {alfa, beta}