From ab2df3864351e775981d59b47193b4477aac1169 Mon Sep 17 00:00:00 2001 From: Mikkel Bybjerg Date: Fri, 26 Apr 2019 20:31:54 +0200 Subject: Add spawn timeline --- nGJ2019/Assets/Scripts/EventTimeline.cs | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 nGJ2019/Assets/Scripts/EventTimeline.cs diff --git a/nGJ2019/Assets/Scripts/EventTimeline.cs b/nGJ2019/Assets/Scripts/EventTimeline.cs new file mode 100644 index 0000000..c6f2c24 --- /dev/null +++ b/nGJ2019/Assets/Scripts/EventTimeline.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +public class EventTimeline +{ + public enum SpawnEventType {wall, enemy}; + + public class SpawnEvent + { + public float time; + public float height; + public SpawnEventType type; + + public SpawnEvent(float time, float height, SpawnEventType type) + { + this.time = time; + this.height = height; + this.type = type; + } + } + + public event Action OnSpawnEvent; + + private List futureEvents; + private float currentTime; + + public EventTimeline() + { + futureEvents = new List(); + currentTime = 0; + } + + public void Add(float time, float height, SpawnEventType type) + { + futureEvents.Add(new SpawnEvent(time, height, type)); + futureEvents.Sort((x,y) => x.time.CompareTo(y.time)); + } + + public void timeTick(float deltaTime) + { + currentTime += deltaTime; + + while(futureEvents.Count > 0 && currentTime > futureEvents[0].time) + { + SpawnEvent e = futureEvents[0]; + futureEvents.RemoveAt(0); + if(OnSpawnEvent != null) + OnSpawnEvent(e); + } + } +} -- cgit v1.2.3