# File gtk2/sample/misc/cairo-pong.rb, line 112 def ball_hit?(ball) ball.y > min_y and ball.y < max_y end
# File gtk2/sample/misc/cairo-pong.rb, line 103 def update(ball) # is the ball coming towards us? if (ball.x < @x and ball.dx > 0) or (ball.x > @x and ball.dx < 0) # move to intercept it @y = ball.y end end
# File gtk2/sample/misc/cairo-pong.rb, line 116 def update_ball(ball) if ball_hit?(ball) if ball.min_x < @x and ball.max_x > min_x # hit our left side ball.x -= (ball.max_x - min_x) ball.dx = -ball.dx elsif ball.max_x > @x and ball.min_x < max_x # hit our right side ball.x += (max_x - ball.min_x) ball.dx = -ball.dx end end end
Generated with the Darkfish Rdoc Generator 2.