Class: Zyps::WrapAround
- Inherits:
-
EnvironmentalFactor
- Object
- EnvironmentalFactor
- Zyps::WrapAround
- Defined in:
- lib/zyps/environmental_factors.rb
Overview
When an object crosses its boundary, warps object to opposite boundary.
Instance Attribute Summary collapse
-
#bottom ⇒ Object
Y coordinate of bottom boundary.
-
#left ⇒ Object
X coordinate of left boundary.
-
#right ⇒ Object
X coordinate of right boundary.
-
#top ⇒ Object
Y coordinate of top boundary.
Instance Method Summary collapse
-
#act(environment) ⇒ Object
If object is beyond a boundary, set its position to that of opposite boundary.
-
#initialize(options = {}) ⇒ WrapAround
constructor
Takes a hash with these keys and defaults: :left => 0 :top => 0 :right => 0 :bottom => 0.
Constructor Details
#initialize(options = {}) ⇒ WrapAround
Takes a hash with these keys and defaults: :left => 0 :top => 0 :right => 0 :bottom => 0
91 92 93 94 95 96 97 98 99 |
# File 'lib/zyps/environmental_factors.rb', line 91 def initialize( = {}) = { :left => 0, :top => 0, :right => 0, :bottom => 0 }.merge() self.left, self.top, self.right, self.bottom = [:left], [:top], [:right], [:bottom] end |
Instance Attribute Details
#bottom ⇒ Object
Y coordinate of bottom boundary.
84 85 86 |
# File 'lib/zyps/environmental_factors.rb', line 84 def bottom @bottom end |
#left ⇒ Object
X coordinate of left boundary.
78 79 80 |
# File 'lib/zyps/environmental_factors.rb', line 78 def left @left end |
#right ⇒ Object
X coordinate of right boundary.
82 83 84 |
# File 'lib/zyps/environmental_factors.rb', line 82 def right @right end |
#top ⇒ Object
Y coordinate of top boundary.
80 81 82 |
# File 'lib/zyps/environmental_factors.rb', line 80 def top @top end |
Instance Method Details
#act(environment) ⇒ Object
If object is beyond a boundary, set its position to that of opposite boundary.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/zyps/environmental_factors.rb', line 102 def act(environment) environment.objects.each do |object| if (object.location.x < @left) then object.location.x = @right elsif (object.location.x > @right) then object.location.x = @left end if (object.location.y > @top) then object.location.y = @bottom elsif (object.location.y < @bottom) then object.location.y = @top end end end |