Class: RichEngine::Cooldown
- Inherits:
-
Object
- Object
- RichEngine::Cooldown
- Defined in:
- lib/rich_engine/cooldown.rb
Overview
Tracks a fixed delay and reports when it has elapsed.
Instance Method Summary collapse
-
#finished? ⇒ Boolean
(also: #ready?)
Whether the cooldown has elapsed.
-
#get ⇒ Float
The remaining time in seconds (negative once finished).
-
#initialize(target_time) ⇒ Cooldown
constructor
A new instance of Cooldown.
-
#reset! ⇒ Integer, Float
Restarts the cooldown at its full duration.
-
#update(dt) ⇒ Float
Counts down by the elapsed time.
Constructor Details
#initialize(target_time) ⇒ Cooldown
Returns a new instance of Cooldown.
15 16 17 18 |
# File 'lib/rich_engine/cooldown.rb', line 15 def initialize(target_time) @target_time = target_time @timer = target_time end |
Instance Method Details
#finished? ⇒ Boolean Also known as: ready?
Returns whether the cooldown has elapsed.
41 42 43 |
# File 'lib/rich_engine/cooldown.rb', line 41 def finished? @timer <= 0 end |
#get ⇒ Float
Returns the remaining time in seconds (negative once finished).
29 30 31 |
# File 'lib/rich_engine/cooldown.rb', line 29 def get @timer end |
#reset! ⇒ Integer, Float
Restarts the cooldown at its full duration.
36 37 38 |
# File 'lib/rich_engine/cooldown.rb', line 36 def reset! @timer = @target_time end |
#update(dt) ⇒ Float
Counts down by the elapsed time.
24 25 26 |
# File 'lib/rich_engine/cooldown.rb', line 24 def update(dt) @timer -= dt end |