diff options
Diffstat (limited to 'nGJ2019/Assets/Scripts/EventTimeline.cs')
-rw-r--r-- | nGJ2019/Assets/Scripts/EventTimeline.cs | 52 |
1 files changed, 52 insertions, 0 deletions
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<SpawnEvent> OnSpawnEvent; + + private List<SpawnEvent> futureEvents; + private float currentTime; + + public EventTimeline() + { + futureEvents = new List<SpawnEvent>(); + 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); + } + } +} |