
-----------------------------------
lufthansa747
Thu Dec 03, 2009 10:06 am

better bouncing balls
-----------------------------------
View.Set ("graphics:max;max,offscreenonly,nobuttonbar")
const numBall : int := 500

class ball

    export startUp, drawBall
    var x : int := maxx div 2
    var y : int := maxy div 2
    var radius : int := 10
    var xint, yint : int := 5
    var upState, sideState : int := -1

    procedure startUp (initside, initup : int)
        upState := initup
        sideState := initside
        Draw.FillBox (0, 0, maxx, maxy, black)
        Draw.FillOval (x, y, radius, radius, white)
    end startUp

    procedure drawBall ()
        if x - xint = maxx and sideState > 0 then     % check right wall
            sideState := -sideState
        end if
        if y + yint >= maxy and upState > 0 then     %check top wall
            upState := -upState
        end if
        if y - yint  startUp (Rand.Int (randl, randh), Rand.Int (randl, randh))
end for

loop
    for i : 1 .. numBall
        balls (i) -> drawBall ()
    end for
    View.Update
end loop

you can change the amount of balls and how fast they move buy changing the array size and chaning the randl and randh but -5 and 5 look the coolest
