Hello
I am working through Jonathan S. Harbour and Joshua R. Smith's Book, "Beginner's Guide to DarkBASIC Game Programming." One of the programs is entitled BouncingBall Program. The problem is that I have the code right but for some reason the balls hit the right and bottom wall and then stop. I'm wondering whether this is because A.) I did something wrong, or B.) Since I used DarkBASIC Pro instead of DarkBASIC that some commands are different. If someone could tell me that would be great. Thanks.
Rem Project: BouncingBalls Program
Rem Created: Friday, January 27, 2012
Rem ***** Main Source File *****
`Create some variables
DIM BALLX(30)
DIM BALLY(30)
DIM BALLSIZE(30)
DIM SPEEDX(30)
DIM SPEEDY(30)
DIM COLOR(30)
`Initialize the program
SET DISPLAY MODE 640, 480, 32
SYNC ON
`Initialize the balls
InitializeBalls()
`Start the Main Loop
DO
`Clear Screen
CLS
`Set the border Color
INK RGB(255,255,255), 0
`Draw the Screen Border
DrawRect(0,0,639,479)
`Move and draw the balls
FOR n = 1 to 30
MoveBall(n)
next n
`Redraw the screen
SYNC
LOOP
`End Program
END
FUNCTION InitializeBalls()
FOR n = 1 TO 30
BALLX(n) = RND(640)
BALLY(n) = RND(480)
BALLSIZE(n) = RND(20) + 5
SPEEDX(n) = RND(12) - 6
SPEEDY(n) = RND(12) - 6
COLOR(n) = RGB(RND(256),RND(256),RND(256))
NEXT N
ENDFUNCTION
FUNCTION MoveBall(NUM)
`Move the Ball
BALLX(NUM) = BALLX(NUM) + SPEEDX(NUM)
BALLY(NUM) = BALLY(NUM) + SPEEDY(NUM)
`Check BallX Conditions
IF BALLX(NUM) > 640 - BALLSIZE(NUM)
BALLX(NUM) = 640 - BALLSIZE(NUM)
SPEEDX(NUM) = SPEEDX * -1
ELSE
IF BALLX(NUM) < BALLSIZE(NUM)
BALLX(NUM) = BALLSIZE(NUM)
SPEEDX(NUM) = SPEEDX(NUM) * -1
ENDIF
ENDIF
`Check BallY Conditions
IF BALLY(NUM) > 480 - BALLSIZE(NUM)
BALLY(NUM) = 480 - BALLSIZE(NUM)
SPEEDY(NUM) = SPEEDY * -1
ELSE
IF BALLY(NUM) < BALLSIZE(NUM)
BALLY(NUM) = BALLSIZE(NUM)
SPEEDY(NUM) = SPEEDY(NUM) * -1
ENDIF
ENDIF
`Draw the Ball
INK Color(NUM), 0
CIRCLE BALLX(NUM), BALLY(NUM), BALLSIZE(NUM)
ENDFUNCTION
FUNCTION DRAWRECT(Left,Top,Right,Bottom)
LINE Left, Top, Right, Top
LINE Right, Top, Right, Bottom
Line Right, Bottom, Left, Bottom
Line Left, Bottom, Left, Top
ENDFUNCTION
When we all lend our power together, there is nothing we
can't do!
Please Lend me your STRENGTH!