
-----------------------------------
Stormtrooper
Tue Apr 15, 2003 12:58 pm

ball bouncing help
-----------------------------------
ok i made this code and i want the balls to bounce when they hit eachother what should i add to the programm and where to put it? also my 2 balls are in each other how do i make them to be by them selves and move into different directions?


setscreen ("graphics")
var c, dx, dy, r, cx, cy, b, a, d, e, f, g : int := 0
var q : string (1)
var strc : string
var colours : array 0 .. 15 of string := init ("black", "dark blue", "dark green", "dark cyan", "dark red", "dark magneta", "brown", "white", "grey", "blue", "green", "cyan", "red", "magenta", 
    "yellow", "bright white")


loop




    put " Enter Radius of ball 1 and 2 "
    get r, a
    put " Enter a Colour of ball 1 "
    get strc : *
    for i : 0 .. 15
        if strc = colours (i) then
            c := i
        end if
    end for
    put " Enter a Colour of ball 2 "
    get strc : *
    for i : 0 .. 15
        if strc = colours (i) then
            c := i
        end if
    end for
    cx := Rand.Int (r, maxx - r)
    cy := Rand.Int (r, maxy - r)
    dx := 1
    dy := 1
    d := Rand.Int (a, maxx - a)
    e := Rand.Int (a, maxy - a)
    
    f := -1
    g := -1
    loop

        exit when hasch




        drawfilloval (cx, cy, r, r, c)
        delay (10)
        drawfilloval (cx, cy, r, r, white)
        drawfilloval (d, e, a, a, b)
        delay (10)
        drawfilloval (d, e, r, r, white)

        d += f
        e += g

        cx += dx
        cy += dy

        if d >= maxx - a or d = maxx - r or cx  maxy - a or e  maxy - r or cy = 630 or x = 390 or y 