Class: Collider
- Inherits:
-
Object
- Object
- Collider
- Defined in:
- lib/entities/collider.rb
Overview
class Collider
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #collides?(b) ⇒ Boolean
-
#initialize(x, y, width, height) ⇒ Collider
constructor
A new instance of Collider.
- #update(x, y) ⇒ Object
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
#height ⇒ Object (readonly)
Returns the value of attribute height.
3 4 5 |
# File 'lib/entities/collider.rb', line 3 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
3 4 5 |
# File 'lib/entities/collider.rb', line 3 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
3 4 5 |
# File 'lib/entities/collider.rb', line 3 def x @x end |
#y ⇒ Object (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
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 |