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.
80 81 82 |
# File 'lib/zyps/environmental_factors.rb', line 80 def initialize(units) self.maximum = units end |
Instance Attribute Details
#maximum ⇒ Object
Maximum allowed speed in units.
78 79 80 |
# File 'lib/zyps/environmental_factors.rb', line 78 def maximum @maximum end |
Instance Method Details
#act(environment) ⇒ Object
If object is over the speed, reduce its speed.
85 86 87 88 89 |
# File 'lib/zyps/environmental_factors.rb', line 85 def act(environment) environment.objects.each do |object| object.vector.speed = Utility.constrain_value(object.vector.speed, @maximum) end end |