Class: Zyps::Accelerator

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

Overview

A force that pushes on all objects.

Direct Known Subclasses

Gravity

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vector) ⇒ Accelerator

Returns a new instance of Accelerator.



146
147
148
149
# File 'lib/zyps/environmental_factors.rb', line 146

def initialize(vector)
	self.vector = vector
	@clock = Clock.new
end

Instance Attribute Details

#vectorObject

Vector to apply to objects.



144
145
146
# File 'lib/zyps/environmental_factors.rb', line 144

def vector
  @vector
end

Instance Method Details

#act(environment) ⇒ Object

Accelerate the target away from the actor, but limited by elapsed time.



152
153
154
155
156
157
158
# File 'lib/zyps/environmental_factors.rb', line 152

def act(environment)
	elapsed_time = @clock.elapsed_time
	environment.objects.each do |object|
		#Push on object.
		object.vector += Vector.new(@vector.speed * elapsed_time, @vector.pitch)
	end
end