Class: Collider

Inherits:
Object
  • Object
show all
Defined in:
lib/entities/collider.rb

Overview

class Collider

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Collider.



5
6
7
8
9
10
# File 'lib/entities/collider.rb', line 5

def initialize(x, y, width, height)
  @x = x
  @y = y
  @width = width
  @height = height
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



3
4
5
# File 'lib/entities/collider.rb', line 3

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



3
4
5
# File 'lib/entities/collider.rb', line 3

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



3
4
5
# File 'lib/entities/collider.rb', line 3

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



3
4
5
# File 'lib/entities/collider.rb', line 3

def y
  @y
end

Instance Method Details

#collides?(b) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/entities/collider.rb', line 17

def collides?(b)
  (@x + @width * 8) >= (b.x + 3) &&
    (x + 2 <= (b.x + b.width * 8)) &&
    ((y + height * 8) >= b.y + 3) &&
    (y + 2 <= (b.y + b.height * 8))
end

#update(x, y) ⇒ Object



12
13
14
15
# File 'lib/entities/collider.rb', line 12

def update(x, y)
  @x = x
  @y = y
end