Class: Rectangle

Inherits:
Object
  • Object
show all
Defined in:
mrb_doc/models/rectangle.rb

Overview

The Rectangle class is used for drawing and also collision checking.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, width, height) ⇒ Rectangle

Creates a new instance of Rectangle

Parameters:

  • x (Integer)
  • y (Integer)
  • width (Integer)
  • height (Integer)


12
13
14
15
16
# File 'mrb_doc/models/rectangle.rb', line 12

def initialize(x, y, width, height)
  # mrb_Rectangle_initialize
  # src/mruby_integration/models/rectangle.cpp
  Rectangle.new
end

Instance Attribute Details

#heightInteger

Returns:

  • (Integer)


4
5
6
# File 'mrb_doc/models/rectangle.rb', line 4

def height
  @height
end

#widthInteger

Returns:

  • (Integer)


4
5
6
# File 'mrb_doc/models/rectangle.rb', line 4

def width
  @width
end

#xInteger

Returns:

  • (Integer)


4
5
6
# File 'mrb_doc/models/rectangle.rb', line 4

def x
  @x
end

#yInteger

Returns:

  • (Integer)


4
5
6
# File 'mrb_doc/models/rectangle.rb', line 4

def y
  @y
end

Instance Method Details

#draw(origin: Vector2::ZERO, rotation: 0, outline: false, thickness: 2, rounded: false, radius: 5, segments: 8, colour: BLACK) ⇒ Rectangle

Draws a rectangle in several configurations

Parameters:

  • origin (Vector2) (defaults to: Vector2::ZERO)
  • rotation (Float) (defaults to: 0)

    only usable when outline and rounded are false

  • outline (Boolean) (defaults to: false)
  • thickness (Integer) (defaults to: 2)

    only used when outline is true

  • rounded (Boolean) (defaults to: false)
  • radius (Float) (defaults to: 5)

    A value between 0.0 and 1.0 and only used when rounded is true

Returns:

Raises:

  • (ArgumentError)

    If the radius is out of bounds



63
64
65
66
67
68
69
70
71
72
73
74
# File 'mrb_doc/models/rectangle.rb', line 63

def draw(
  origin: Vector2::ZERO,
  rotation: 0,
  outline: false,
  thickness: 2,
  rounded: false,
  radius: 5,
  segments: 8,
  colour: BLACK
)
  # src/mruby_integration/models/rectangle.cpp
end

#to_hHash

Return the object represented by a Hash

Returns:

  • (Hash)


44
45
46
47
48
49
50
51
52
# File 'mrb_doc/models/rectangle.rb', line 44

def to_h
  # src/mruby_integration/models/rectangle.cpp
  {
    x: x,
    y: y,
    width: width,
    height: height,
  }
end