'=========================================================================== ' Subject: TRON LIGHTCYCLES FOR FIRSTBASIC Date: 12-22-99 (20:59) ' Author: Zknight Code: FB ' Origin: Zknight@earthlink.net Packet: GAMES.ABC '=========================================================================== ' Zknight Software 1999 << LightCycles >> '----------------------------------------------------------------------- ' Hello, everyone. I'm Zknight and this is my first time submitting ' anything to ABC. This isn't the best game I ever wrote but I thought ' maybe some die-hard Tron junkie might enjoy it. It took me about 2 1/2 ' hours to write. I did very little bug testing but as far as I can tell ' there aren't any major bugs. All the code was writen in FirstBasic ' so it will work with any PowerBasic compiler. As far as playing it ' using Qbasic, you'll have to do some work to it. Well I guess thats ' about it. Have fun with it. '------------------------------------------------------------------------ ' You may use/abuse this program anyway you want, it is public domian. ' When running this program you do so at your own risk. '------------------------------------------------------------------------ ' As far as I know I didn't use anyone elses code, writing this game. ' If I am mistaken I am sorry and I thank you for the code. '------------------------------------------------------------------------ '---------------------------[Start of Program]--------------------------- GameDelay = 50000 'Change this, if it runs to fast or to slow 'the higher the number the longer the delay '50000 works well on my pentium II 400 mghz '----------------------------[Game Set Up]------------------------------- SHARED GDHEAD,BDHEAD,BDX,BDY,GDX,GDY,NORTH,SOUTH,EAST,WEST,SCORE NORTH = 1 'Set up the directions SOUTH = 2 'of movement. EAST = 3 WEST = 4 GDHEAD = NORTH 'Set both cycles BDHEAD = SOUTH 'start up heading. BDX = 320 'Set the actual X & Y BDY = 18 'Coordinates for both GDX = 320 'Cycles at start up. GDY = 477 SCREEN 12 LINE (200,150)-(450,280),13,B 'Draw the start up window LINE (201,151)-(449,279),5,B LINE (202,152)-(448,278),9,B LOCATE 11,31 PRINT " Zknight Software 1999 " '<--- Shameless Plug for me! LOCATE 13,31 PRINT " << LIGHTCYCLES >> " LOCATE 15,31 PRINT "Press any key to begin." 'Game Controls LOCATE 16,31 PRINT "Use Arrow keys to move." LOCATE 17,31 PRINT " Press Escape to Quit. " WHILE Cheat$ = "" 'Wait for user to get ready. Cheat$ = UCASE$(INKEY$) 'Check if its the cheat key WEND CLS LINE (1,16)-(639,479),10,B 'Draw the Game border LINE (2,17)-(638,478),2,B FOR X = 12 TO 637 STEP 15 'Draw the Game grid LINE (X,18)-(X,477),8 NEXT X FOR Y = 18 TO 478 STEP 15 LINE (3,Y)-(637,Y),8 NEXT Y PSET (BDX,BDY),14 ' Put the Cycles in PSET (GDX,GDY),9 ' their starting positions SCORE = 50000 ' Set the score (it counts backwards) RANDOMIZE TIMER LOCATE 1,38 'This just lets the user know PRINT "READY!!" 'know they're about to start DELAY 1 LOCATE 1,38 PRINT " SET!! " DELAY 1 LOCATE 1,38 PRINT " GO!!! " DELAY 1 LOCATE 1,38 PRINT " " '---------------------------[Main Program Loop]------------------------------ DO N$ = INKEY$ 'Get a key press IF N$ = CHR$(27) THEN END 'If Esc then quit IF N$ = CHR$(0) + "H" AND GDHEAD <> SOUTH THEN 'Figure out what key GDHEAD = NORTH 'was pressed and what ELSEIF N$ = CHR$(0) + "P" AND GDHEAD <> NORTH THEN 'direction to move in GDHEAD = SOUTH ELSEIF N$ = CHR$(0) + "K" AND GDHEAD <> EAST THEN GDHEAD = WEST ELSEIF N$ = CHR$(0) + "M" AND GDHEAD <> WEST THEN GDHEAD = EAST END IF BDHEAD = SMARTY (BDX,BDY,BDHEAD) ' Call the A.I. routine CALL MOVEIT (BDX,BDY,BDHEAD,2,NX,NY) ' This calls the routine to BDX = NX:BDY = NY ' move the yellow cycle IF Cheat$ = "T" THEN ' This is a cheat, if the GDHEAD = SMARTY (GDX,GDY,GDHEAD) ' "T" key is pressed at the END IF ' Start Window, the A.I. ' will help you make turns CALL MOVEIT (GDX,GDY,GDHEAD,1,NX,NY) ' This call the routine GDX = NX:GDY = NY ' to move the blue cycle CALL CHECKFORCRASH (GDX,GDY,GDHEAD,1) ' This checks to see if CALL CHECKFORCRASH (BDX,BDY,BDHEAD,2) ' anyone hit anything FOR A = 1 TO GameDelay ' delay to correct speed NEXT A ' problems SCORE = SCORE - 1 ' Set the score LOCATE 1,1 ' Print the current score S$ = "SCORE:" + REMOVE$(STR$(SCORE),ANY " ") PRINT S$ LOOP '------------------------------[Subs & Functions]---------------------------- FUNCTION SMARTY (X,Y,D) 'This is the A.I. IF D = NORTH THEN 'Current direction. IF POINT (X,Y - 2) <> 0 AND POINT (X,Y-2) <> 8 THEN 'Is anything in front V = X 'of the cycle ? WHILE L = 0 OR L = 8 'Whats on the left V = V - 1 'of the cycle & how L = POINT (V,Y) 'far away is it. INCR LEFT WEND V = X WHILE R = 0 OR R = 8 'Whats on the right V = V + 1 'of the cycle & how R = POINT (V,Y) 'how far away is it. INCR RIGHT WEND IF LEFT > RIGHT THEN 'Which side has more SMARTY = WEST:EXIT FUNCTION 'room to move around ELSEIF RIGHT > LEFT THEN 'in. (left or right) SMARTY = EAST:EXIT FUNCTION ELSE 'If the room is the C = INT(RND * 2) + 1 'same on both sides IF C = 1 THEN SMARTY = WEST:EXIT FUNCTION 'pick a side at IF C = 2 THEN SMARTY = EAST:EXIT FUNCTION 'random END IF ELSE SMARTY = NORTH 'If nothing is in front END IF 'of the cycle, just END IF 'keep moving foreward IF D = SOUTH THEN 'Same as above IF POINT (X,Y + 2) <> 0 AND POINT (X,Y + 2) <> 8 THEN V = X WHILE L = 0 OR L = 8 V = V - 1 L = POINT (V,Y) INCR LEFT WEND V = X WHILE R = 0 OR R = 8 V = V + 1 R = POINT (V,Y) INCR RIGHT WEND IF LEFT > RIGHT THEN SMARTY = WEST:EXIT FUNCTION ELSEIF RIGHT > LEFT THEN SMARTY = EAST:EXIT FUNCTION ELSE C = INT(RND * 2) + 1 IF C = 1 THEN SMARTY = WEST:EXIT FUNCTION IF C = 2 THEN SMARTY = EAST:EXIT FUNCTION END IF ELSE SMARTY = SOUTH END IF END IF IF D = EAST THEN 'same as above IF POINT (X + 2,Y) <> 0 AND POINT (X+2,Y) <> 8 THEN H = Y WHILE U = 0 OR U = 8 H = H - 1 U = POINT (X,H) INCR UP WEND H = Y WHILE DN = 0 OR DN = 8 H = H + 1 DN = POINT (X,H) INCR DOWN WEND IF DOWN > UP THEN SMARTY = SOUTH:EXIT FUNCTION ELSEIF UP > DOWN THEN SMARTY = NORTH:EXIT FUNCTION ELSE C = INT(RND * 2) + 1 IF C = 1 THEN SMARTY = NORTH:EXIT FUNCTION IF C = 2 THEN SMARTY = SOUTH:EXIT FUNCTION END IF ELSE SMARTY = EAST END IF END IF IF D = WEST THEN 'same as above IF POINT (X - 2,Y) <> 0 AND POINT(X -2,Y) <> 8 THEN H = Y WHILE U = 0 OR U = 8 H = H - 1 U = POINT (X,H) INCR UP WEND H = Y WHILE DN = 0 OR DN = 8 H = H + 1 DN = POINT (X,H) INCR DOWN WEND IF UP > DOWN THEN SMARTY = NORTH:EXIT FUNCTION ELSEIF DOWN > UP THEN SMARTY = SOUTH:EXIT FUNCTION ELSE C = INT(RND * 2) + 1 IF C = 1 THEN SMARTY = NORTH:EXIT FUNCTION IF C = 1 THEN SMARTY = SOUTH:EXIT FUNCTION END IF ELSE SMARTY = WEST END IF END IF END FUNCTION SUB MOVEIT (X,Y,D,GOB,ZX,ZY) ' Routine to move the cycles IF GOB = 1 THEN C = 9 ' Figure out what color cycle IF GOB = 2 THEN C = 14 ' were going to move IF D = NORTH THEN PSET (X,Y - 1),C:ZY = Y - 1:ZX = X:EXIT SUB 'move it IF D = SOUTH THEN PSET (X,Y + 1),C:ZY = Y + 1:ZX = X:EXIT SUB IF D = EAST THEN PSET (X + 1,Y) ,C:ZX = X + 1:ZY = Y:EXIT SUB IF D = WEST THEN PSET (X - 1,Y) ,C:ZX = X - 1:ZY = Y:EXIT SUB END SUB SUB CHECKFORCRASH (X,Y,D,P) ' This watches for colisions IF D = NORTH THEN C = POINT (X,Y-1) ' it just watches the pixel IF D = SOUTH THEN C = POINT (X,Y+1) ' directly ahead of the cycle IF D = EAST THEN C = POINT (X+1,Y) IF D = WEST THEN C = POINT (X-1,Y) IF C <> 0 AND C <> 8 THEN CALL CRASH (P) ' If someone hits something go ' go to the game ending. The (P) ' shows which player hit something END SUB SUB CRASH (P) LINE (170,200)-(468,280),0,BF 'Draw a window so we can let LINE (170,200)-(468,280),13,B 'the user know who won & what LINE (171,201)-(467,279),5,B 'the score is. LINE (172,202)-(466,278),9,B P1$ = "YOU LOSE!" 'Figure out who won. P2$ = "YOU WIN!!" IF P = 1 THEN SCORE = 0 'If you crashed score = 0 ELSE SCORE = SCORE + 50000 'If you won 50000 bonus END IF S$ = "SCORE:" + STR$(SCORE) 'Get the correct score X = (80 - LEN(P1$)) / 2 'Find the middle of the screen LOCATE 14,X IF P = 1 THEN 'Print who won PRINT P1$ ELSE PRINT P2$ END IF X = (80 - LEN(S$)) / 2 'find the middle of the screen LOCATE 15,X 'print the score PRINT S$ LOCATE 1,1 PRINT S$ + " " BEEP 'Let the user know it's over LOCATE 17,23 'Ask if they want to play again PRINT " Play Again ? (y/n)" N$ = "" DO N$ = UCASE$(INKEY$) 'Get a key IF N$ = "Y" THEN EXIT LOOP ELSEIF N$ = "N" THEN EXIT LOOP ELSEIF N$ = CHR$(27) THEN 'if Esc key then quit SCREEN 0 END END IF LOOP IF N$ = "Y" THEN 'if "Y" key then start over CLS RUN ELSE SCREEN 0 'if "N" key then Quit END END IF END SUB '-----------------------------[End of Program]------------------------------