
-----------------------------------
gamer
Fri Apr 09, 2004 4:02 pm

help needed!
-----------------------------------
hi all here i hav a little program with bouncing two balls plus a square in the middle to "block" the balls

questions:
1. if u let the program run for awhile, u'll notice that when the ball hits the square at the corner, the ball does weird things (ex. sliding along the square).......why is this happenin?? how can i fix it?
2. noticing that both balls go at same speed (-2), is it possible if i want to hav one ball go at a random speed? 
3. do i just use math.distance for the two bals to bounce off each other?


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 