Class: Ruby2D::Rectangle

Inherits:
Quad
  • Object
show all
Defined in:
lib/ruby2d/rectangle.rb

Direct Known Subclasses

Square

Instance Attribute Summary collapse

Attributes inherited from Quad

#c1, #c2, #c3, #c4, #color, #x1, #x2, #x3, #x4, #y1, #y2, #y3, #y4

Attributes included from Renderable

#z

Instance Method Summary collapse

Methods inherited from Quad

#ext_render

Methods included from Renderable

#a, #a=, #add, #b, #b=, #colour, #colour=, #g, #g=, #opacity, #opacity=, #r, #r=, #remove

Constructor Details

#initialize(opts = {}) ⇒ Rectangle

Returns a new instance of Rectangle.



8
9
10
11
12
13
14
15
16
17
# File 'lib/ruby2d/rectangle.rb', line 8

def initialize(opts = {})
  @x = opts[:x] || 0
  @y = opts[:y] || 0
  @z = opts[:z] || 0
  @width = opts[:width] || 200
  @height = opts[:height] || 100
  self.color = opts[:color] || 'white'
  update_coords(@x, @y, @width, @height)
  add
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/ruby2d/rectangle.rb', line 6

def height
  @height
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/ruby2d/rectangle.rb', line 6

def width
  @width
end

#xObject

Returns the value of attribute x.



6
7
8
# File 'lib/ruby2d/rectangle.rb', line 6

def x
  @x
end

#yObject

Returns the value of attribute y.



6
7
8
# File 'lib/ruby2d/rectangle.rb', line 6

def y
  @y
end

Instance Method Details

#contains?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ruby2d/rectangle.rb', line 43

def contains?(x, y)
  @x < x and @x + @width > x and @y < y and @y + @height > y
end