| 
setscreen ("graphics:800;600")
 View.Set ("offscreenonly")
 var x, y, x2, y2 : int %centre position
 var obsx, obsy : int := 300 %obstacle position
 var dx, dy, dx2, dy2 : int := -2 %centre and direction/speed
 const ballradius : int := 20
 
 randint (x, ballradius, maxx - ballradius) %ball1 random starting x-position
 randint (y, ballradius, maxy - ballradius) %ball1 random starting y-position
 
 randint (x2, ballradius, maxx - ballradius) %ball2 random starting x-position
 randint (y2, ballradius, maxy - ballradius) %ball2 random starting y-position
 
 proc obs %obstacles
 drawfillbox (obsx - 50, obsy - 50, obsx + 50, obsy + 50, yellow)
 end obs
 
 proc ball1
 drawfilloval (x, y, ballradius, ballradius, red)
 x += dx
 y += dy
 if x >= maxx - ballradius or x <= ballradius or Math.DistancePointLine (x, y, obsx - 50, obsy + 50, obsx - 50, obsy - 50) <= ballradius or Math.DistancePointLine (x, y, obsx + 50, obsy + 50, obsx
 + 50, obsy - 50) <= ballradius then
 dx := -dx
 elsif y >= maxy - ballradius or y <= ballradius or Math.DistancePointLine (x, y, obsx - 50, obsy + 50, obsx + 50, obsy + 50) <= ballradius or Math.DistancePointLine (x, y, obsx - 50, obsy - 50,
 obsx + 50, obsy - 50) <= ballradius then
 dy := -dy
 elsif Math.Distance (x, y, obsx - 50, obsy + 50) = ballradius or Math.Distance (x, y, obsx - 50, obsy - 50) = ballradius or Math.Distance (x, y, obsx + 50, obsy + 50) = ballradius or
 Math.Distance (x, y, obsx + 50, obsy - 50) = ballradius then
 dx := -dx
 dy := -dy
 end if
 end ball1
 
 proc ball2
 drawfilloval (x2, y2, ballradius, ballradius, white)
 x2 += dx2
 y2 += dy2
 if x2 >= maxx - ballradius or x2 <= ballradius or Math.DistancePointLine (x2, y2, obsx - 50, obsy + 50, obsx - 50, obsy - 50) <= ballradius or Math.DistancePointLine (x2, y2, obsx + 50, obsy +
 50, obsx + 50, obsy - 50) <= ballradius then
 dx2 := -dx2
 elsif y2 >= maxy - ballradius or y2 <= ballradius or Math.DistancePointLine (x2, y2, obsx - 50, obsy + 50, obsx + 50, obsy + 50) <= ballradius or Math.DistancePointLine (x2, y2, obsx - 50, obsy -
 50, obsx + 50, obsy - 50) <= ballradius then
 dy2 := -dy2
 elsif Math.Distance (x2, y2, obsx - 50, obsy + 50) = ballradius or Math.Distance (x2, y2, obsx - 50, obsy - 50) = ballradius or Math.Distance (x2, y2, obsx + 50, obsy + 50) = ballradius or
 Math.Distance (x2, y2, obsx + 50, obsy - 50) = ballradius then
 dx2 := -dx2
 dy2 := -dy2
 end if
 end ball2
 
 loop
 drawfillbox (0, 0, maxx, maxy, black)
 obs
 ball1
 ball2
 View.Update
 delay (5)
 end loop
 
 |