Class: Gtk::Pong::Paddle
Constant Summary
Constants inherited
from CenteredItem
CenteredItem::NAMESPACE
Instance Attribute Summary
Attributes inherited from CenteredItem
#height, #width, #x, #y
Instance Method Summary
collapse
#draw
#max_x, #max_y, #min_x, #min_y
Constructor Details
#initialize(field, x, y) ⇒ Paddle
110
111
112
113
|
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 110
def initialize(field, x, y)
super(x, y, 0.05, 0.3)
@field = field
end
|
Instance Method Details
#ball_hit?(ball) ⇒ Boolean
125
126
127
|
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 125
def ball_hit?(ball)
ball.y > min_y and ball.y < max_y
end
|
#update(ball) ⇒ Object
115
116
117
118
119
120
121
122
|
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 115
def update(ball)
if (ball.x < @x and ball.dx > 0) or
(ball.x > @x and ball.dx < 0)
@y = ball.y
end
end
|
#update_ball(ball) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 129
def update_ball(ball)
if ball_hit?(ball)
if ball.min_x < @x and ball.max_x > min_x ball.x -= (ball.max_x - min_x)
ball.dx = -ball.dx
elsif ball.max_x > @x and ball.min_x < max_x ball.x += (max_x - ball.min_x)
ball.dx = -ball.dx
end
end
end
|