class MiniGL::Ramp
Represents a ramp, i.e., an inclined structure which allows walking over it while automatically going up or down. It can be imagined as a right triangle, with a side parallel to the x axis and another one parallel to the y axis. You must provide instances of this class (or derived classes) to the ramps
array parameter of the move
method.
Attributes
The height of the ramp.
Whether the ramp is vertically inverted, i.e., the face that is parallel to the x-axis faces up and the sloped face faces down.
Whether the height of the ramp increases from left to right (decreases from left to right when false
).
The width of the ramp.
The x-coordinate of the top left corner of a rectangle that completely (and precisely) encloses the ramp (thought of as a right triangle).
The y-coordinate of the top left corner of the rectangle described in the x
attribute.
Public Class Methods
Creates a new ramp.
Parameters:
- x
-
The x-coordinate of the top left corner of a rectangle that completely (and precisely) encloses the ramp (thought of as a right triangle).
- y
-
The y-coordinate of the top left corner of the rectangle described above.
- w
-
The width of the ramp (which corresponds to the width of the rectangle described above).
- h
-
The height of the ramp (which corresponds to the height of the rectangle described above, and to the difference between the lowest point of the ramp, where it usually meets the floor, and the highest).
- left
-
Whether the height of the ramp increases from left to right. Use
false
for a ramp that goes down from left to right. - inverted
-
Whether the ramp is vertically inverted, i.e., the face that is parallel to the x-axis faces up and the sloped face faces down.
# File lib/minigl/movement.rb, line 99 def initialize(x, y, w, h, left, inverted = false) @x = x @y = y @w = w @h = h @left = left @inverted = inverted @ratio = @h.to_f / @w @factor = @w / Math.sqrt(@w**2 + @h**2) end
Public Instance Methods
Checks if an object is in contact with this ramp (standing over it).
Parameters:
- obj
-
The object to check contact with. It must have the
x
,y
,w
andh
accessible attributes determining its bounding box.
# File lib/minigl/movement.rb, line 115 def contact?(obj) return false if @inverted obj.x + obj.w > @x && obj.x < @x + @w && obj.x.round(6) == get_x(obj).round(6) && obj.y.round(6) == get_y(obj).round(6) end
Checks if an object is intersecting this ramp (inside the corresponding right triangle and at the floor level or above).
Parameters:
- obj
-
The object to check intersection with. It must have the
x
,y
,w
andh
accessible attributes determining its bounding box.
# File lib/minigl/movement.rb, line 126 def intersect?(obj) obj.x + obj.w > @x && obj.x < @x + @w && (@inverted ? obj.y < get_y(obj) && obj.y + obj.h > @y : obj.y > get_y(obj) && obj.y < @y + @h) end