Module: Rong::Elements::Entity

Included in:
Ball, Paddle
Defined in:
lib/rong/elements/entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/rong/elements/entity.rb', line 5

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/rong/elements/entity.rb', line 5

def width
  @width
end

#xObject

Returns the value of attribute x.



4
5
6
# File 'lib/rong/elements/entity.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/rong/elements/entity.rb', line 4

def y
  @y
end

Instance Method Details

#bottomObject



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

Returns:

  • (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

#leftObject



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

#rightObject



31
32
33
# File 'lib/rong/elements/entity.rb', line 31

def right
  x + width / 2
end

#topObject



19
20
21
# File 'lib/rong/elements/entity.rb', line 19

def top
  y - height / 2
end