Class: Zyps::TimedAction
- Inherits:
-
Action
- Object
- Action
- Zyps::TimedAction
- Defined in:
- lib/zyps/actions.rb
Overview
Superclass for actions that need to happen at a specific rate.
Direct Known Subclasses
AccelerateAction, ApproachAction, BlendAction, FleeAction, PullAction, PushAction, TurnAction
Instance Attribute Summary collapse
-
#clock ⇒ Object
A Clock that tracks time between actions.
-
#rate ⇒ Object
Units per second for action.
Instance Method Summary collapse
-
#copy ⇒ Object
Make a deep copy.
-
#delta ⇒ Object
Units to add to the attribute being changed.
-
#initialize(rate, *arguments) ⇒ TimedAction
constructor
A new instance of TimedAction.
-
#start(actor, targets) ⇒ Object
Begin tracking time between actions.
-
#stop(actor, targets) ⇒ Object
Halt tracking time between actions.
Constructor Details
#initialize(rate, *arguments) ⇒ TimedAction
Returns a new instance of TimedAction.
32 33 34 35 |
# File 'lib/zyps/actions.rb', line 32 def initialize(rate, *arguments) self.rate = rate @clock = Clock.new end |
Instance Attribute Details
#clock ⇒ Object
A Clock that tracks time between actions.
28 29 30 |
# File 'lib/zyps/actions.rb', line 28 def clock @clock end |
#rate ⇒ Object
Units per second for action.
30 31 32 |
# File 'lib/zyps/actions.rb', line 30 def rate @rate end |
Instance Method Details
#copy ⇒ Object
Make a deep copy.
38 39 40 41 42 43 |
# File 'lib/zyps/actions.rb', line 38 def copy copy = super #Copies should have their own Clock. copy.clock = Clock.new copy end |
#delta ⇒ Object
Units to add to the attribute being changed.
46 47 48 |
# File 'lib/zyps/actions.rb', line 46 def delta @clock.elapsed_time * rate end |
#start(actor, targets) ⇒ Object
Begin tracking time between actions.
51 52 53 54 |
# File 'lib/zyps/actions.rb', line 51 def start(actor, targets) super @clock.reset_elapsed_time end |
#stop(actor, targets) ⇒ Object
Halt tracking time between actions.
57 58 59 60 |
# File 'lib/zyps/actions.rb', line 57 def stop(actor, targets) super @clock.reset_elapsed_time end |