class MiniGL::Block

Represents an object with a rectangular bounding box and the passable property. It is the simplest structure that can be passed as an element of the obst array parameter of the move method.

Attributes

h[R]

The height of the bounding box.

passable[R]

Whether a moving object can pass through this block when coming from below. This is a common feature of platforms in platform games.

w[R]

The width of the bounding box.

x[R]

The x-coordinate of the top left corner of the bounding box.

y[R]

The y-coordinate of the top left corner of the bounding box.

Public Class Methods

new(x, y, w, h, passable = false) click to toggle source

Creates a new block.

Parameters:

x

The x-coordinate of the top left corner of the bounding box.

y

The y-coordinate of the top left corner of the bounding box.

w

The width of the bounding box.

h

The height of the bounding box.

passable

Whether a moving object can pass through this block when

coming from below. This is a common feature of platforms in platform games. Default is false.

# File lib/minigl/movement.rb, line 34
def initialize(x, y, w, h, passable = false)
  @x = x; @y = y; @w = w; @h = h
  @passable = passable
end

Public Instance Methods

bounds() click to toggle source

Returns the bounding box of this block as a Rectangle.

# File lib/minigl/movement.rb, line 40
def bounds
  Rectangle.new @x, @y, @w, @h
end
to_s() click to toggle source
# File lib/minigl/movement.rb, line 44
def to_s
  "Block(#{@x}, #{@y}, #{@w}, #{@h}#{@passable ? ", passable" : ''})"
end