Module: Rong::Elements::Entity
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #bottom ⇒ Object
- #initialize(start_x, start_y) ⇒ Object
- #intersects?(other) ⇒ Boolean
- #left ⇒ Object
- #move_to(x, y) ⇒ Object
- #right ⇒ Object
- #top ⇒ Object
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
5 6 7 |
# File 'lib/rong/elements/entity.rb', line 5 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
5 6 7 |
# File 'lib/rong/elements/entity.rb', line 5 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
4 5 6 |
# File 'lib/rong/elements/entity.rb', line 4 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
4 5 6 |
# File 'lib/rong/elements/entity.rb', line 4 def y @y end |
Instance Method Details
#bottom ⇒ Object
23 24 25 |
# File 'lib/rong/elements/entity.rb', line 23 def bottom y + height / 2 end |
#initialize(start_x, start_y) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/rong/elements/entity.rb', line 7 def initialize(start_x, start_y) self.x = start_x self.y = start_y @height = self.class::HEIGHT @width = self.class::WIDTH end |
#intersects?(other) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rong/elements/entity.rb', line 35 def intersects?(other) if left > other.right return false end if right < other.left return false end if top > other.bottom return false end if bottom < other.top return false end true end |
#left ⇒ Object
27 28 29 |
# File 'lib/rong/elements/entity.rb', line 27 def left x - width / 2 end |
#move_to(x, y) ⇒ Object
14 15 16 17 |
# File 'lib/rong/elements/entity.rb', line 14 def move_to(x, y) self.x = x self.y = y end |
#right ⇒ Object
31 32 33 |
# File 'lib/rong/elements/entity.rb', line 31 def right x + width / 2 end |
#top ⇒ Object
19 20 21 |
# File 'lib/rong/elements/entity.rb', line 19 def top y - height / 2 end |