'=========================================================================== ' Subject: VOXEL LANDSCAPE Date: 09-23-98 (22:33) ' Author: Shawn Code: QB, QBasic, PDS ' Origin: TopFiero@aol.com Packet: GRAPHICS.ABC '=========================================================================== ' Voxel terrain generator for QuickBasic/Qbasic. ' This program features more detailed terrain than 3dland.bas. ' This sample was also taken from a graphics engine I use in one of my ' games. The terrain color can be changed further by changing the T variable ' to the value 1 or 2. When the program displays the word DONE, press ' a key to return to the menu. Use this program freely, but please send ' me any revisions or variations. I like to see how others can use this ' idea. I apologize for the routine containing line numbers, but this is ' the easiest way I can convert it to run well in Qbasic. I recommend ' you have a Pentium 133 or faster to run the routine up to speed. Or try ' compiling it. Send questions or comments to TopFiero@aol.com 1 SCREEN 13: CLS : CLEAR 5 GOTO 1000 10 SCREEN 13: CLS 11 PL = 0 12 FOR I = 100 TO 160: PLL = CINT(PL * .67): IF PLL > 60 THEN PLL = 60 13 IF T = 1 THEN PALETTE I, 65536 * PL 14 IF T = 2 THEN PALETTE I, 65536 + 256 * PL 15 IF T = 3 THEN PALETTE I, 65536 + 256 * PLL + PL 17 IF T = 4 THEN PALETTE I, 65536 * PL + 256 * PL + PL 20 PL = PL + 1: NEXT I 21 PL = 0 22 FOR I = 170 TO 230: PLL = PL * 2: IF PLL > 60 THEN PLL = 60 23 PALETTE I, 65536 * PLL + 256 * PL + PL: PL = PL + 1: NEXT I 30 Z = 10 + 300 * RND: ZZ = 100 - 95 * RND: MV = 20 * RND 35 EEE = 100 * RND: IF EEE < 30 THEN GOTO 40 ELSE GOTO 50 40 FOR I = 0 TO 60: LINE (0, 99 - I)-(319, 99 - I), 230 - I: NEXT I 42 LINE (0, 100)-(319, 199), 230, BF 45 GOTO 80 50 FOR I = 0 TO 60: CIRCLE (Z, ZZ), 80 - I, 170 + I 52 PAINT (Z, ZZ), 170 + I, 170 + I 55 NEXT I 80 FOR I = 0 TO 500 81 X = 319 * RND: XX = 190 * RND: XCLR = POINT(X, XX) 82 IF XCLR > 220 THEN GOTO 81 83 IF XCLR > 180 THEN VCLR = (31 - ((220 - XCLR) / 4) * RND) ELSE VCLR = 17 + 13 * RND 85 PSET (X, XX), VCLR: NEXT I 100 DIM Z(320), X(320), CLR(320) 110 Z(0) = 0: X(0) = 100: SZ = 1: CLR(0) = 130 120 FOR I = 1 TO 320: Z(I) = Z(I - 1) + SZ 125 X(I) = X(I - 1) - SZ + (SZ * 2) * RND 127 CLR(I) = CLR(I - 1) - 5 + (10 * RND): IF CLR(I) < 100 THEN CLR(I) = 100 128 IF CLR(I) > 160 THEN CLR(I) = 160 130 LINE (Z(I), X(I))-(Z(I) + SZ, X(I) + SZ), CLR(I), BF: NEXT I 180 CHK = 0 190 SZ = SZ * 1.012 195 Z(0) = 0 - (SZ - 1) * 160: X(0) = X(0) + SZ * RND 200 FOR I = 1 TO 320: Z(I) = Z(I - 1) + SZ 205 X(I) = X(I) - SZ / 4 + SZ * RND: IF X(I) < X(I - 1) - SZ THEN X(I) = X(I - 1) - SZ 207 IF X(I) > X(I - 1) + SZ THEN X(I) = X(I - 1) + SZ 209 IF Z(I) < -1 OR Z(I) > 320 THEN GOTO 220 210 CLR(I) = CLR(I) - 4 + (8 * RND) 211 IF CLR(I) < CLR(I - 1) - 3 THEN CLR(I) = CLR(I - 1) - 3 212 IF CLR(I) > CLR(I - 1) + 3 THEN CLR(I) = CLR(I - 1) + 3 217 IF CLR(I) < 100 THEN CLR(I) = 100 218 IF CLR(I) > 160 THEN CLR(I) = 160 219 LINE (Z(I), X(I))-(Z(I) + SZ + 1, X(I) + SZ + 1), CLR(I), BF 220 IF X(I) > 199 THEN CHK = CHK + 1: IF CHK > 319 THEN GOTO 300 225 NEXT I 230 KY$ = INKEY$: IF KY$ = "" THEN GOTO 240 ELSE GOTO 300 240 CHK = 0: GOTO 190 300 LOCATE 1, 1: PRINT "Done...." 310 KY$ = INKEY$: IF KY$ = "" THEN GOTO 310 350 GOTO 1000 1000 PL = 0 1001 FOR I = 100 TO 160: PALETTE I, 65536 * PL: PL = PL + 1: NEXT I 1020 LOCATE 1, 1 1030 PRINT "Example of Voxel type terrain generation" 1035 PRINT "written in QuickBasic version 4.5." 1040 PRINT "": PRINT " Select color choice:" 1050 PRINT "1 - DESERT" 1055 PRINT "2 - ICE" 1070 PRINT "3 - EXIT" 1080 R = 100 * RND: KY$ = INKEY$: IF KY$ = "1" THEN T = 3: GOTO 1100 1081 IF KY$ = "2" THEN T = 4: GOTO 1100 1084 IF KY$ = "3" THEN END 1085 GOTO 1080 1100 GOTO 10