Class: Zyps::SpeedLimit

Inherits:
EnvironmentalFactor
  • Object
show all
Defined in:
lib/zyps/environmental_factors.rb

Overview

Keeps all objects at/under the assigned speed.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#maximumObject

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