diff --git a/src/Scene.bf b/src/Scene.bf index 576fb9e..b87703c 100644 --- a/src/Scene.bf +++ b/src/Scene.bf @@ -5,6 +5,8 @@ namespace Strawberry { public class Scene { + public float TimeStarted { get; private set; } + private List entities; private HashSet toRemove; private HashSet toAdd; @@ -33,7 +35,7 @@ namespace Strawberry public virtual void Started() { - + TimeStarted = Time.Elapsed; } public virtual void Update() @@ -95,6 +97,36 @@ namespace Strawberry } } + // Time + + public float TimeElapsed + { + [Inline] + get + { + return Time.Elapsed - TimeStarted; + } + } + + public float PreviousTimeElapsed + { + [Inline] + get + { + return Time.PreviousElapsed - TimeStarted; + } + } + + public bool TimeOnInterval(float interval, float offset = 0) + { + return (int)((TimeElapsed - offset) / interval) != (int)((PreviousTimeElapsed - offset) / interval); + } + + public bool TimeBetweenInterval(float interval, float offset = 0) + { + return (TimeElapsed - offset) % (interval * 2) >= interval; + } + // Finding Entities public T First() where T : Entity diff --git a/src/Time.bf b/src/Time.bf index b86bd2a..8537dc2 100644 --- a/src/Time.bf +++ b/src/Time.bf @@ -5,5 +5,15 @@ namespace Strawberry static public float Elapsed; static public float PreviousElapsed; static public float Delta = 1 / 60f; + + static public bool OnInterval(float interval, float offset = 0) + { + return (int)((Elapsed - offset) / interval) != (int)((PreviousElapsed - offset) / interval); + } + + static public bool BetweenInterval(float interval, float offset = 0) + { + return (Elapsed - offset) % (interval * 2) >= interval; + } } }