Class: MiniGL::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/minigl/movement.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, w, h, passable = false) ⇒ Block

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.



34
35
36
37
# 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

Instance Attribute Details

#hObject (readonly)

The height of the bounding box.



18
19
20
# File 'lib/minigl/movement.rb', line 18

def h
  @h
end

#passableObject (readonly)

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



22
23
24
# File 'lib/minigl/movement.rb', line 22

def passable
  @passable
end

#wObject (readonly)

The width of the bounding box.



15
16
17
# File 'lib/minigl/movement.rb', line 15

def w
  @w
end

#xObject (readonly)

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



9
10
11
# File 'lib/minigl/movement.rb', line 9

def x
  @x
end

#yObject (readonly)

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



12
13
14
# File 'lib/minigl/movement.rb', line 12

def y
  @y
end

Instance Method Details

#boundsObject

Returns the bounding box of this block as a Rectangle.



40
41
42
# File 'lib/minigl/movement.rb', line 40

def bounds
  Rectangle.new @x, @y, @w, @h
end