'=========================================================================== ' Subject: BOUNCING BOXES Date: 04/94 (00:00) ' Author: Michael Teator Code: QB, QBasic, PDS ' Origin: mhscards@aol.com Packet: GRAPHICS.ABC '=========================================================================== ' Bouncer by Michael Teator April 1994 ' ' Sorry for the lack of documentation, this was written quikly as a demo to ' a friend. The program could probably be faster with some creative thinking. ' The move function could be used for almost anything, like a screen saver, or ' maybe a paddleball game. If you want to use it, go ahead, just as long as ' you mention my name somewhere. I have many QBasic creations, but now I'm ' planning on learning C so I won't have time to create anything new. I'll ' just finish the programs I have now and release them on America Online as ' public domain. I will, however, discuss QBasic with anyone that would like ' to. Send me E-Mail at: AOL - Skeptre ' Internet - skeptre@f11.n3626.z1.fidonet.org ' (alternate) - skeptre@aol.com ' Note: the speed checking routine can be deleted below. I added that just ' because I was playing with the moving bar thing and thought it would be ' neat to add. I'm not sure how well it determines the number of boxes to ' use, as I've only run it on my 486DX 33, on which it ends up with 16 boxes ' at an enjoyable speed. Still, even 25 or 30 boxes are interesting. The ' maximum number of boxes is 32,767, but that is limited by the available ' DOS memory. I've tried up to 5000, but its slow and you can't tell the ' boxes apart. 100 is the maximum number that doesn't fill the screen up too ' much. DECLARE FUNCTION Move (xp%, yp%, xra%, yra%, n%) DEFINT A-Z OPTION BASE 1 CONST upleft = 1, upright = 2, downright = 3, downleft = 4 RANDOMIZE TIMER SCREEN 13 ' Speed checking routine PRINT "Please wait while I determine the" ' \ PRINT "number of boxes to use . . ." ' \ PRINT ' | time1! = TIMER ' | a = 220 ' | FOR t = 1 TO 10 ' | c = INT(RND * 15) + 1 ' | COLOR c ' | FOR n = 1 TO 40 ' / FOR i = 4 TO 25 ' | LOCATE i, n: PRINT STRING$(1, a); ' \ NEXT ' \ NEXT ' > Delete this if you don't want it to check your speed. FOR n = 40 TO 1 STEP -1 ' / FOR i = 4 TO 25 ' / LOCATE i, n: PRINT STRING$(1, " "); ' | NEXT ' \ NEXT ' | NEXT ' | time2! = TIMER ' | total! = time2! - time1! ' | score! = 110 / total! ' | ans = INT(score!) ' / GOTO gotans ' / top: PRINT SPACE$(37); LOCATE , 1: PRINT "Current number of boxes:"; ans CLEAR PRINT " " PRINT "Less boxes = faster display. " PRINT " " PRINT "How many boxes would you like (press " PRINT SPACE$(37); LOCATE , 1: INPUT ; "ENTER to end)? ", ans IF ans = 0 THEN SYSTEM gotans: CLS max = ans DIM xr(max), yr(max), x(max), y(max), dir(max) FOR num = 1 TO max xr(num) = INT(RND * 20) yr(num) = INT(RND * 20) x(num) = INT(RND * (320 - xr(num) * 2)) + xr(num) y(num) = INT(RND * (200 - yr(num) * 2)) + yr(num) dir(num) = INT(RND * 4) + 1 NEXT LClr = 16: HiClr = 55 Counter = LClr DO BoxClr = Counter Counter = Counter + 1 IF Counter > HiClr THEN Counter = LClr FOR num = 1 TO max LINE (x(num) - xr(num), y(num) - yr(num))-(x(num) + xr(num), y(num) + yr(num)), BoxClr, B'F dir(num) = Move(x(num), y(num), xr(num), yr(num), dir(num)) SELECT CASE dir(num) CASE downleft: y(num) = y(num) + 1: x(num) = x(num) - 1 CASE upleft: y(num) = y(num) - 1: x(num) = x(num) - 1 CASE downright: y(num) = y(num) + 1: x(num) = x(num) + 1 CASE upright: y(num) = y(num) - 1: x(num) = x(num) + 1 END SELECT NEXT LOOP UNTIL INKEY$ <> "" GOTO top DEFSNG A-Z FUNCTION Move (xp%, yp%, xra%, yra%, n%) DEFINT A-Z ul = yra: ll = xra: bl = 199 - yra: rl = 319 - xra SELECT CASE n CASE upleft IF yp > ul THEN IF xp > ll THEN Move = upleft ELSE Move = upright ELSE IF xp > ll THEN Move = downleft ELSE Move = downright END IF CASE upright IF yp > ul THEN IF xp < rl THEN Move = upright ELSE Move = upleft ELSE IF xp < rl THEN Move = downright ELSE Move = downleft END IF CASE downright IF yp < bl THEN IF xp < rl THEN Move = downright ELSE Move = downleft ELSE IF xp < rl THEN Move = upright ELSE Move = upleft END IF CASE downleft IF yp < bl THEN IF xp > ll THEN Move = downleft ELSE Move = downright ELSE IF xp > ll THEN Move = upleft ELSE Move = upright END IF END SELECT END FUNCTION