Class: GamesAndRpgParadise::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
123
124
125
126
|
# File 'lib/games_and_rpg_paradise/games/pong/gtk/cairo_pong.rb', line 123
def initialize(field, x, y)
super(x, y, 0.05, 0.3)
@field = field
end
|
Instance Method Details
#ball_hit?(ball) ⇒ Boolean
138
139
140
|
# File 'lib/games_and_rpg_paradise/games/pong/gtk/cairo_pong.rb', line 138
def ball_hit?(ball)
ball.y > min_y and ball.y < max_y
end
|
#update(ball) ⇒ Object
128
129
130
131
132
133
134
135
|
# File 'lib/games_and_rpg_paradise/games/pong/gtk/cairo_pong.rb', line 128
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
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/games_and_rpg_paradise/games/pong/gtk/cairo_pong.rb', line 142
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
|