diff options
author | Mikkel Bybjerg <mikkel.bybjerg@hotmail.com> | 2019-04-27 11:14:45 +0200 |
---|---|---|
committer | Mikkel Bybjerg <mikkel.bybjerg@hotmail.com> | 2019-04-27 11:14:45 +0200 |
commit | 12f21516ffd7caacfec259d6771677769384ffe8 (patch) | |
tree | 31ddc0544f39934e3780b96d145c7525cf3d6704 /nGJ2019/Assets/Scripts | |
parent | 0ef7e7d16e955401131fb2110c3b3dda66ccc0e3 (diff) |
enemy collision and health
Diffstat (limited to 'nGJ2019/Assets/Scripts')
-rw-r--r-- | nGJ2019/Assets/Scripts/DragonMovement.cs | 12 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/EnemyCollider.cs | 8 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/EventTimeline.cs | 10 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/HealthBar.cs | 54 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/ObstacleSpawner.cs | 12 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/ObstacleType.cs | 5 |
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} |