Class: Zyps::SpeedLimit
- Inherits:
-
EnvironmentalFactor
- Object
- EnvironmentalFactor
- Zyps::SpeedLimit
- Defined in:
- lib/zyps/environmental_factors.rb
Overview
Keeps all objects at/under the assigned speed.
Instance Attribute Summary collapse
-
#maximum ⇒ Object
Maximum allowed speed in units.
Instance Method Summary collapse
-
#act(environment) ⇒ Object
If object is over the speed, reduce its speed.
-
#initialize(units) ⇒ SpeedLimit
constructor
A new instance of SpeedLimit.
Constructor Details
#initialize(units) ⇒ SpeedLimit
Returns a new instance of SpeedLimit.
126 127 128 |
# File 'lib/zyps/environmental_factors.rb', line 126 def initialize(units) self.maximum = units end |
Instance Attribute Details
#maximum ⇒ Object
Maximum allowed speed in units.
124 125 126 |
# File 'lib/zyps/environmental_factors.rb', line 124 def maximum @maximum end |
Instance Method Details
#act(environment) ⇒ Object
If object is over the speed, reduce its speed.
131 132 133 134 135 |
# File 'lib/zyps/environmental_factors.rb', line 131 def act(environment) environment.objects.each do |object| object.vector.speed = Utility.constrain_value(object.vector.speed, @maximum) end end |