Class: Rong::Elements::Paddle
- Inherits:
-
Object
- Object
- Rong::Elements::Paddle
- Includes:
- Entity
- Defined in:
- lib/rong/elements/paddle.rb
Constant Summary collapse
- WIDTH =
10
- HEIGHT =
50
- SPEED =
10
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#side ⇒ Object
Returns the value of attribute side.
Attributes included from Entity
Instance Method Summary collapse
- #hit(ball) ⇒ Object
-
#initialize(name, side, start_x, start_y) ⇒ Paddle
constructor
A new instance of Paddle.
- #left? ⇒ Boolean
- #move_down ⇒ Object
- #move_up ⇒ Object
Methods included from Entity
#bottom, #intersects?, #left, #move_to, #right, #top
Constructor Details
#initialize(name, side, start_x, start_y) ⇒ Paddle
Returns a new instance of Paddle.
13 14 15 16 17 |
# File 'lib/rong/elements/paddle.rb', line 13 def initialize(name, side, start_x, start_y) self.name = name self.side = side super(start_x, start_y) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/rong/elements/paddle.rb', line 11 def name @name end |
#side ⇒ Object
Returns the value of attribute side.
11 12 13 |
# File 'lib/rong/elements/paddle.rb', line 11 def side @side end |
Instance Method Details
#hit(ball) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/rong/elements/paddle.rb', line 31 def hit(ball) ball_x = left? ? right : left ball.reflect_x(ball_x) ball.reflect_y if ball.y < y strength = (y - ball.y).abs / (height / 2) ball.angle = 45 * strength end |
#left? ⇒ Boolean
27 28 29 |
# File 'lib/rong/elements/paddle.rb', line 27 def left? side == :left end |
#move_down ⇒ Object
23 24 25 |
# File 'lib/rong/elements/paddle.rb', line 23 def move_down self.y += SPEED end |
#move_up ⇒ Object
19 20 21 |
# File 'lib/rong/elements/paddle.rb', line 19 def move_up self.y -= SPEED end |