timer.jamo (built in)

timer: things that happen every so often, and things that need a rest between uses. use "timer.jamo"

A Timer fires again and again, every so many seconds, like spawning an enemy every 2 seconds. A Cooldown can be used, then needs a rest, like a gun that fires at most every 0.3 seconds. Each method has an _at version that takes the time in seconds, for a game that keeps its own clock (one that pauses, or runs in slow motion). The plain ones use seconds_since_start().

structTimer

struct Timer
    every: float
    next: float
end

structCooldown

struct Cooldown
    rest: float
    until: float
end

funcnew_timer

func new_timer(seconds: float): Timer

funcnew_timer_at

func new_timer_at(seconds: float, now: float): Timer

funcTimer.ready

func Timer.ready(): bool

funcTimer.ready_at

func Timer.ready_at(now: float): bool

True once each time it's due. A game that falls far behind gets one fire, not a burst of them

funcTimer.left

func Timer.left(): float

funcTimer.left_at

func Timer.left_at(now: float): float

Seconds until it's next due, never below 0

funcTimer.progress_at

func Timer.progress_at(now: float): float

How far it is to the next fire, from 0.0 just after one to 1.0 when it's due, for bars and flashing

funcTimer.restart

func Timer.restart()

funcTimer.restart_at

func Timer.restart_at(now: float)

funcnew_cooldown

func new_cooldown(seconds: float): Cooldown

A cooldown starts ready to use

funcCooldown.ready

func Cooldown.ready(): bool

funcCooldown.ready_at

func Cooldown.ready_at(now: float): bool

funcCooldown.try_use

func Cooldown.try_use(): bool

funcCooldown.try_use_at

func Cooldown.try_use_at(now: float): bool

Uses it if it's ready, starting its rest, and says whether it was

funcCooldown.left_at

func Cooldown.left_at(now: float): float

funcCooldown.left

func Cooldown.left(): float