Class: ShatteredPack::Timer::TimedEvent
- Inherits:
-
Object
- Object
- ShatteredPack::Timer::TimedEvent
- Defined in:
- lib/shattered_pack/timer/timed_event.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#time_remaining ⇒ Object
Returns the value of attribute time_remaining.
Instance Method Summary collapse
-
#initialize(context, seconds, options = {}, &block) ⇒ TimedEvent
constructor
A new instance of TimedEvent.
- #processed? ⇒ Boolean
- #reset ⇒ Object
-
#stop ⇒ Object
Stop the timer.
- #stopped? ⇒ Boolean
- #update(time_elapsed) ⇒ Object
Constructor Details
#initialize(context, seconds, options = {}, &block) ⇒ TimedEvent
Returns a new instance of TimedEvent.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/shattered_pack/timer/timed_event.rb', line 31 def initialize(context, seconds, ={}, &block) @context=context @event = block @options = if(seconds != :frame) @time_remaining = seconds @initial_time = @time_remaining else @time_remaining = 0 @initial_time = 0 end end |
Instance Attribute Details
#time_remaining ⇒ Object
Returns the value of attribute time_remaining.
30 31 32 |
# File 'lib/shattered_pack/timer/timed_event.rb', line 30 def time_remaining @time_remaining end |
Instance Method Details
#processed? ⇒ Boolean
51 52 53 |
# File 'lib/shattered_pack/timer/timed_event.rb', line 51 def processed? return @processed == true end |
#reset ⇒ Object
54 55 56 |
# File 'lib/shattered_pack/timer/timed_event.rb', line 54 def reset @time_remaining = @initial_time end |
#stop ⇒ Object
Stop the timer
58 59 60 |
# File 'lib/shattered_pack/timer/timed_event.rb', line 58 def stop @stopped = true end |
#stopped? ⇒ Boolean
61 62 63 |
# File 'lib/shattered_pack/timer/timed_event.rb', line 61 def stopped? !@stopped.nil? end |
#update(time_elapsed) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/shattered_pack/timer/timed_event.rb', line 43 def update(time_elapsed) return if processed? || stopped? @time_remaining -= time_elapsed if time_up? process_event @processed=true end end |