class Pong::Ball

Attributes

dx[RW]
dy[RW]

Public Class Methods

new(dx=0.02, dy=0.02) click to toggle source
Calls superclass method Pong::CenteredItem::new
# File gtk2/sample/misc/cairo-pong.rb, line 68
def initialize(dx=0.02, dy=0.02)
  super(0.8, 0.5, 0.04, 0.04)
  @dx = dx
  @dy = dy
end

Public Instance Methods

update() click to toggle source
# File gtk2/sample/misc/cairo-pong.rb, line 74
def update
  @x += @dx
  @y += @dy

  # ball bouncing
  if max_y > 1
    @y = 1 - (max_y - 1)
    @dy *= -1
  elsif min_y < 0
    @y -= min_y
    @dy *= -1
  end
  
  if max_x > 1
    @x = 1 - (max_x - 1)
    @dx *= -1
  elsif min_x < 0
    @x -= min_x
    @dx *= -1
  end
end