Class: Moon::SAT::Box

Inherits:
Object show all
Defined in:
lib/moon/packages/physics/sat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pos = Moon::Vector2.zero, w = 0, h = 0) ⇒ Box

Returns a new instance of Box.


115
116
117
118
119
# File 'lib/moon/packages/physics/sat.rb', line 115

def initialize(pos = Moon::Vector2.zero, w = 0, h = 0)
  @position = pos
  @width = w
  @height = h
end

Instance Attribute Details

#heightInteger Also known as: h

Returns:


111
112
113
# File 'lib/moon/packages/physics/sat.rb', line 111

def height
  @height
end

#positionMoon::Vector2

Returns:


105
106
107
# File 'lib/moon/packages/physics/sat.rb', line 105

def position
  @position
end

#widthInteger Also known as: w

Returns:


107
108
109
# File 'lib/moon/packages/physics/sat.rb', line 107

def width
  @width
end

Instance Method Details

#to_polygonObject


121
122
123
124
125
# File 'lib/moon/packages/physics/sat.rb', line 121

def to_polygon
  Polygon.new(position.dup,
              [Moon::Vector2.zero, Moon::Vector2.new(w, 0),
               Moon::Vector2.new(w, h), Moon::Vector2.new(0, h)])
end