Class/Module Index [+]

Quicksearch

Pong::Paddle

Public Class Methods

new(field, x, y) click to toggle source
# File gtk2/sample/misc/cairo-pong.rb, line 98
def initialize(field, x, y)
  super(x, y, 0.05, 0.3)
  @field = field
end

Public Instance Methods

ball_hit?(ball) click to toggle source
# File gtk2/sample/misc/cairo-pong.rb, line 112
def ball_hit?(ball)
  ball.y > min_y and ball.y < max_y
end
update(ball) click to toggle source
# 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
update_ball(ball) click to toggle source
# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.