
-----------------------------------
petree08
Fri Nov 10, 2006 12:17 pm

Multiple ball colision physics
-----------------------------------
Okay so a while a go i posted a ball physics thingy and it basically blew apple sauce.  
So i went home ant wrote this little thing

it is sooo much better than my other one.








const SIZE := 50
const MID_Y := maxy div 2
const MID_X := maxx div 2
const SPEED := 9
const SIZE_P := 10
const SIZE_C := 5
const DIV_F := 1



var X, Y, Dx, Dy, Sy, Sx, C : array 1 .. SIZE of int
var Length : array 1 .. SIZE of real4
var Key : array char of boolean
var XP, YP, Click : int
setscreen ("graphics:max,max,nobuttonbar,offscreenonly")

process Sound
    sound (100, 100)

end Sound

for Index : 1 .. SIZE
    randint (X (Index), 20, maxx - 20)
    randint (Y (Index), 20, maxy - 20)
    loop
        randint (C (Index), 1, 15)
        exit when C (Index) not= 7
    end loop
    Dx (Index) := 0
    Dy (Index) := 0

end for

XP := MID_X
YP := MID_Y
colorback (7)
loop

    drawfillbox (1, 1, maxx, maxy, 15)
    drawfillbox (20, 20, maxx - 20, maxy - 20, 7)
    mousewhere (XP, YP, Click)
    drawfilloval (XP, YP, SIZE_P, SIZE_P, 0)



    if Click = 1 then
        for Index : 1 .. SIZE
            Dx (Index) := 0
            Dy (Index) := 0
            % drawline (XP, YP, X (Index), Y (Index), 12)
        end for
        % else
        %     for Index : 1 .. SIZE
        %
        %         drawline (XP, YP, X (Index), Y (Index), C (Index))
        %     end for
    end if

    for Index : 1 .. SIZE

        drawfilloval (X (Index), Y (Index), SIZE_C, SIZE_C, C (Index))
        %drawfilloval (X (Index), Y (Index), SIZE_C, SIZE_C, 0)

        if X (Index) > maxx - 20 or X (Index) < 20 then
            Dx (Index) := -Dx (Index)
        end if

        if Y (Index) > maxy - 20 or Y (Index) < 20 then
            Dy (Index) := -Dy (Index)
        end if

        Length (Index) := sqrt (((XP - X (Index)) ** 2) + ((YP - Y (Index)) ** 2))


        if Length (Index) 