Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 489
» Latest member: stanforddick
» Forum threads: 2,818
» Forum posts: 26,445

Full Statistics

Latest Threads
Attachment error
Forum: Help Me!
Last Post: eoredson
2 hours ago
» Replies: 3
» Views: 38
1990's 3D Doom-Like Walls...
Forum: Programs
Last Post: SquirrelMonkey
2 hours ago
» Replies: 2
» Views: 6
Reading my brainwaves in ...
Forum: Programs
Last Post: SquirrelMonkey
2 hours ago
» Replies: 0
» Views: 11
Playing sound files in QB...
Forum: Programs
Last Post: hsiangch_ong
2 hours ago
» Replies: 8
» Views: 1,080
Masakari - the abandoned ...
Forum: Programs
Last Post: Sanmayce
5 hours ago
» Replies: 2
» Views: 145
Problem with "MOD"
Forum: General Discussion
Last Post: Pete
6 hours ago
» Replies: 5
» Views: 53
New and improved SICK pro...
Forum: Utilities
Last Post: eoredson
6 hours ago
» Replies: 34
» Views: 3,707
which day of the week
Forum: Programs
Last Post: Pete
7 hours ago
» Replies: 25
» Views: 402
Rock Jockey 2.0 is ready ...
Forum: Games
Last Post: NakedApe
9 hours ago
» Replies: 12
» Views: 343
Audio Spectrum Analyser
Forum: Programs
Last Post: Petr
10 hours ago
» Replies: 2
» Views: 48

 
  Indexed files
Posted by: PhilOfPerth - 11-03-2023, 11:21 PM - Forum: Help Me! - Replies (19)

I need to create a file that I can access randomly, by specifying a record-number
I think this requires an Indexed file, but don't know how to create this. 
I would need to access it with something like 
Open "myfile" for input as #1
Input #1, RecNum10 (to access the 10th record).
I can do this by reading from the file 10 times, but this would be slow.
Any suggestions?

Print this item

  Wizard's Castle
Posted by: SMcNeill - 11-03-2023, 02:21 AM - Forum: Games - Replies (2)

Code: (Select All)
1000 REM *****************************************************
1005 REM * *
1010 REM * WIZARD'S CASTLE GAME FROM JULY/AUGUST 1980 *
1015 REM * ISSUE OF RECREATIONAL COMPUTING MAGAZINE *
1020 REM * WRITTEN FOR EXIDY SORCERER BY JOSEPH R. POWER *
1025 REM * MODIFIED FOR HEATH MICROSOFT BASIC BY J.F.STETSON *
1026 REM * MODIFIED FOR QB64PE BY STEVE(TM)!! *
1030 REM * *
1035 REM *****************************************************
1040 DEFINT A-Z
1045 DIM C$(34), I$(34), R$(4), W$(8), E$(8)
1050 DIM L(512), C(3, 4), T(8), O(3), R(3)
1080 Y$ = "** PLEASE ANSWER YES OR NO"
1085 NG = 0
1090 REM
1095 REM INITIALIZE ARRAYS
1100 REM
1105 NG = NG + 1
1110 Q = RND(1)
1115 RESTORE
1120 FOR Q = 1 TO 34
1125 READ C$(Q), I$(Q)
1130 NEXT Q
1135 FOR Q = 1 TO 512
1140 L(Q) = 101
1145 NEXT Q
1150 FOR Q = 1 TO 8
1155 READ W$(Q), E$(Q)
1160 NEXT Q
1165 FOR Q = 1 TO 4
1170 READ R$(Q)
1175 NEXT Q
1180 IF NG > 1 GOTO 1250
1185 PRINT CHR$(27); "E"
1190 GOSUB 5375
1195 PRINT TAB(16); "* * * THE WIZARD'S CASTLE * * *"
1200 PRINT
1205 GOSUB 5375
1210 PRINT "MANY CYCLES AGO, IN THE KINGDOM OF N'DIC, THE GNOMIC"
1215 PRINT "WIZARD ZOT FORGED HIS GREAT *ORB OF POWER*. HE SOON"
1220 PRINT "VANISHED, LEAVING BEHIND HIS VAST SUBTERRANEAN CASTLE"
1225 PRINT "FILLED WITH ESURIENT MONSTERS, FABULOUS TREASURES, AND"
1230 PRINT "THE INCREDIBLE *ORB OF ZOT*. FROM THAT TIME HENCE, MANY"
1235 PRINT "A BOLD YOUTH HAS VENTURED INTO THE WIZARD'S CASTLE. AS"
1240 PRINT "OF NOW, *NONE* HAS EVER EMERGED VICTORIOUSLY! BEWARE!!"
1245 PRINT
1250 X = 1: Y = 4
1255 L(FND(1)) = 2
1260 FOR Z = 1 TO 7
1265 FOR Q1 = 1 TO 2
1270 Q = 104
1275 GOSUB 5285
1280 L(FND(Z + 1)) = 103
1285 NEXT Q1
1290 NEXT Z
1295 FOR Z = 1 TO 8
1300 FOR Q = 113 TO 124
1305 GOSUB 5285
1310 NEXT Q
1315 FOR Q1 = 1 TO 3
1320 FOR Q = 105 TO 112
1325 GOSUB 5285
1330 NEXT Q
1335 Q = 125
1340 GOSUB 5285
1345 NEXT Q1
1350 NEXT Z
1355 FOR Q = 126 TO 133
1360 Z = FNA(8)
1365 GOSUB 5285
1370 NEXT Q
1375 Q = 101
1380 FOR A = 1 TO 3
1385 Z = FNA(8)
1390 GOSUB 5285
1395 C(A, 1) = X
1400 C(A, 2) = Y
1405 C(A, 3) = Z
1410 C(A, 4) = 0
1415 NEXT A
1420 RC = 0
1425 ST = 2
1430 DX = 14
1435 R$(3) = "MAN"
1440 Q = 112 + FNA(12)
1445 Z = FNA(8)
1450 GOSUB 5285
1455 R(1) = X
1460 R(2) = Y
1465 R(3) = Z
1470 Q = 109
1475 Z = FNA(8)
1480 GOSUB 5285
1485 O(1) = X
1490 O(2) = Y
1495 O(3) = Z
1500 BF = 0: OT = 8: AV = 0: HT = 0: T = 1: VF = 0: LF = 0
1505 TC = 0: GP = 60: RF = 0: OF = 0: BL = 0: IQ = 8: SX = 0
1510 FOR Q = 1 TO 8
1515 T(Q) = 0
1520 NEXT Q
1525 PRINT CHR$(7);
1530 PRINT "ALL RIGHT, BOLD ONE."
1535 PRINT "YOU MAY BE AN ELF, DWARF, MAN, OR HOBBIT."
1540 GOSUB 5405
1545 FOR Q = 1 TO 4
1550 IF LEFT$(R$(Q), 1) = O$ THEN RC = Q: ST = ST + 2 * Q: DX = DX - 2 * Q
1555 NEXT Q
1560 PRINT
1565 OT = OT + 4 * (RC = 1)
1570 IF RC > 0 THEN R$(3) = "HUMAN": GOTO 1585
1575 PRINT "** THAT WAS INCORRECT. PLEASE TYPE E, D, M, OR H."
1580 GOTO 1535
1585 PRINT "WHICH SEX TO YOU PREFER";
1590 GOSUB 5415
1595 IF O$ = "M" THEN SX = 1: GOTO 1615
1600 IF O$ = "F" GOTO 1615
1605 PRINT "** CUTE "; R$(RC); ", REAL CUTE. TRY M OR F."
1610 GOTO 1585
1615 PRINT
1620 PRINT "OK, "; R$(RC); ", YOU HAVE THE FOLLOWING ATTRIBUTES :"
1625 PRINT "STRENGTH ="; ST; " INTELLIGENCE ="; IQ; " DEXTERITY ="; DX
1630 PRINT "AND"; OT; "OTHER POINTS TO ALLOCATE AS YOU WISH."
1635 PRINT
1640 Z$ = "STRENGTH"
1645 GOSUB 5430
1650 ST = ST + Q
1655 IF OT = 0 GOTO 1695
1660 Z$ = "INTELLIGENCE"
1665 GOSUB 5430
1670 IQ = IQ + Q
1675 IF OT = 0 GOTO 1695
1680 Z$ = "DEXTERITY"
1685 GOSUB 5430
1690 DX = DX + Q
1695 PRINT "OK, "; R$(RC); ", YOU HAVE 60 GOLD PIECES (GP'S)."
1700 Z$ = "ARMOR"
1705 GOSUB 5555
1710 AV = 0: WV = 0: FL = 0: WC = 0
1715 PRINT "PLATE<30> CHAINMAIL<20> LEATHER<10> NOTHING<0>"
1720 GOSUB 5405
1725 IF O$ = "N" GOTO 1755
1730 AV = -3 * (O$ = "P") - 2 * (O$ = "C") - (O$ = "L")
1735 IF AV > 0 GOTO 1755
1740 PRINT
1745 PRINT "** ARE YOU A "; R$(RC); " OR "; C$(FNA(12) + 12); "?"
1750 GOTO 1700
1755 AH = AV * 7: GP = GP - AV * 10
1760 PRINT
1765 PRINT "OK, BOLD "; R$(RC); ", YOU HAVE"; GP; "GP'S LEFT."
1770 Z$ = "WEAPONS"
1775 GOSUB 5555
1780 PRINT "SWORD<30> MACE<20> DAGGER<10> NOTHING<0>"
1785 GOSUB 5405
1790 IF O$ = "N" GOTO 1820
1795 WV = -3 * (O$ = "S") - 2 * (O$ = "M") - (O$ = "D")
1800 IF WV > 0 GOTO 1820
1805 PRINT
1810 PRINT "** IS YOUR IQ REALLY"; IQ; "?"
1815 GOTO 1770
1820 GP = GP - WV * 10
1825 IF GP < 20 GOTO 1855
1830 PRINT
1835 PRINT "DO YOU WANT TO BUY A LAMP FOR 20 GP'S";
1840 GOSUB 5415
1845 IF O$ = "Y" THEN LF = 1: GP = GP - 20: GOTO 1855
1850 IF O$ <> "N" THEN PRINT: PRINT Y$: PRINT: GOTO 1835
1855 PRINT
1860 IF GP < 1 THEN Q = 0: GOTO 1915
1865 PRINT "OK, "; R$(RC); ", YOU HAVE"; GP; "GOLD PIECES LEFT."
1870 PRINT
1875 INPUT "FLARES COST 1 GP EACH. HOW MANY DO YOU WANT"; O$
1880 Q = VAL(O$)
1885 PRINT
1890 IF Q > 0 OR ASC(O$) = 48 GOTO 1910
1895 PRINT "** IF YOU DON'T WANT ANY, JUST TYPE 0 (ZERO)."
1900 PRINT
1905 GOTO 1875
1910 IF Q > GP THEN PRINT "** YOU CAN ONLY AFFORD"; GP; ".": PRINT: GOTO 1875
1915 FL = FL + Q: GP = GP - Q
1920 X = 1: Y = 4: Z = 1
1925 PRINT "OK, "; R$(RC); ", YOU ARE NOW ENTERING THE CASTLE!"
1930 GOTO 3450
1935 REM
1940 REM MAIN PROCESSING LOOP
1945 REM
1950 T = T + 1
1955 IF RF + OF > 0 GOTO 2020
1960 IF C(1, 4) > T(1) THEN T = T + 1
1965 IF C(2, 4) > T(3) THEN GP = GP - FNA(5)
1970 IF GP < 0 THEN GP = 0
1975 IF C(3, 4) <= T(5) GOTO 2020
1980 A = X: B = Y: C = Z
1985 X = FNA(8): Y = FNA(8): Z = FNA(8)
1990 L(FND(Z)) = FNE(L(FND(Z))) + 100
1995 X = A: Y = B: Z = C
2000 IF L(FND(Z)) <> 1 GOTO 2020
2005 FOR Q = 1 TO 3
2010 C(Q, 4) = -(C(Q, 1) = X) * (C(Q, 2) = Y) * (C(Q, 3) = Z)
2015 NEXT Q
2020 IF FNA(5) > 1 GOTO 2165
2025 PRINT
2030 PRINT "YOU ";
2035 Q = FNA(7) + BL
2040 IF Q > 7 THEN Q = 4
2045 ON Q GOSUB 2125, 2065, 2115, 2055, 2135, 2145, 2155
2050 GOTO 2165
2055 PRINT "STEPPED ON A FROG!"
2060 RETURN
2065 PRINT "HEAR ";
2070 ON FNA(4) GOTO 2075, 2085, 2095, 2105
2075 PRINT "A SCREAM!"
2080 RETURN
2085 PRINT "FOOTSTEPS!"
2090 RETURN
2095 PRINT "A WUMPUS!"
2100 RETURN
2105 PRINT "THUNDER!"
2110 RETURN
2115 PRINT "SNEEZED!"
2120 RETURN
2125 PRINT "SEE A BAT FLY BY!"
2130 RETURN
2135 PRINT "SMELL "; C$(12 + FNA(13)); " FRYING!"
2140 RETURN
2145 PRINT "FEEL LIKE YOU'RE BEING WATCHED!"
2150 RETURN
2155 PRINT "HEAR FAINT RUSTLING NOISES!"
2160 RETURN
2165 IF BL + T(4) <> 2 GOTO 2185
2170 PRINT
2175 PRINT C$(29); " CURES YOUR BLINDNESS!"
2180 BL = 0
2185 IF BF + T(6) <> 2 GOTO 2205
2190 PRINT
2195 PRINT C$(31); " DISSOLVES THE BOOK!"
2200 BF = 0
2205 PRINT
2210 LINE INPUT "ENTER YOUR COMMAND : "; O$
2215 IF LEFT$(O$, 2) = "DR" GOTO 2870
2220 O$ = LEFT$(O$, 1)
2225 IF O$ = "N" GOTO 2435
2230 IF (O$ = "S") OR (O$ = "W") OR (O$ = "E") GOTO 2440
2235 IF O$ = "U" GOTO 2465
2240 IF O$ = "D" GOTO 2480
2245 IF O$ = "M" GOTO 2505
2250 IF O$ = "F" THEN ON BL + 1 GOTO 2620, 2505
2255 IF O$ = "L" THEN ON BL + 1 GOTO 2750, 2505
2260 IF O$ = "O" GOTO 2965
2265 IF O$ = "G" THEN ON BL + 1 GOTO 3185, 2505
2270 IF O$ = "T" THEN PRINT: ON RF + 1 GOTO 3315, 3335
2275 IF O$ = "Q" GOTO 3390
2280 IF O$ <> "H" GOTO 2420
2285 PRINT CHR$(27); "E"
2290 PRINT "*** WIZARD'S CASTLE COMMAND AND INFORMATION SUMMARY ***"
2295 PRINT
2300 PRINT "THE FOLLOWING COMMANDS ARE AVAILABLE :"
2305 PRINT
2310 PRINT "H/ELP N/ORTH S/OUTH E/AST W/EST U/P"
2315 PRINT "D/OWN DR/INK M/AP F/LARE L/AMP O/PEN"
2320 PRINT "G/AZE T/ELEPORT Q/UIT"
2325 PRINT
2330 PRINT "THE CONTENTS OF ROOMS ARE AS FOLLOWS :"
2335 PRINT
2340 PRINT ". = EMPTY ROOM B = BOOK C = CHEST"
2345 PRINT "D = STAIRS DOWN E = ENTRANCE/EXIT F = FLARES"
2350 PRINT "G = GOLD PIECES M = MONSTER O = CRYSTAL ORB"
2355 PRINT "P = MAGIC POOL S = SINKHOLE T = TREASURE"
2360 PRINT "U = STAIRS UP V = VENDOR W = WARP/ORB"
2365 PRINT
2370 PRINT "THE BENEFITS OF HAVING TREASURES ARE :"
2375 PRINT
2380 PRINT "RUBY RED - AVOID LETHARGY PALE PEARL - AVOID LEECH"
2385 PRINT "GREEN GEM - AVOID FORGETTING OPAL EYE - CURES BLINDNESS"
2390 PRINT "BLUE FLAME - DISSOLVES BOOKS NORN STONE - NO BENEFIT"
2395 PRINT "PALANTIR - NO BENEFIT SILMARIL - NO BENEFIT"
2400 PRINT
2405 PRINT "PRESS RETURN WHEN READY TO RESUME, "; R$(RC); ".";
2410 LINE INPUT ""; O$
2415 GOTO 1950
2420 PRINT
2425 PRINT "** SILLY "; R$(RC); ", THAT WASN'T A VALID COMMAND!"
2430 GOTO 1950
2435 IF L(FND(Z)) = 2 GOTO 4970
2440 X = X + (O$ = "N") - (O$ = "S")
2445 Y = Y + (O$ = "W") - (O$ = "E")
2450 X = FNB(X)
2455 Y = FNB(Y)
2460 GOTO 3450
2465 IF L(FND(Z)) = 3 THEN Z = Z - 1: GOTO 3450
2470 Z$ = "UP"
2475 GOTO 2490
2480 Z$ = "DOWN"
2485 IF L(FND(Z)) = 4 THEN Z = Z + 1: GOTO 3450
2490 PRINT
2495 PRINT "** THERE ARE NO STAIRS GOING "; Z$; " FROM HERE!"
2500 GOTO 1950
2505 IF BL <> 1 GOTO 2540
2510 PRINT
2515 PRINT "** YOU CAN'T SEE ANYTHING, YOU DUMB "; R$(RC); "!"
2520 GOTO 1950
2525 REM
2530 REM DISPLAY MAP OF CURRENT CASTLE LEVEL
2535 REM
2540 PRINT
2545 A = X: B = Y
2550 FOR X = 1 TO 8
2555 FOR Y = 1 TO 8
2560 Q = L(FND(Z))
2565 IF Q > 99 THEN Q = 34 ' LET Q=Q-100 TO SHOW ROOMS
2570 IF X = A AND Y = B THEN PRINT "<"; I$(Q); "> ";: GOTO 2580
2575 PRINT " "; I$(Q); " ";
2580 NEXT Y
2585 PRINT
2590 PRINT
2595 NEXT X
2600 X = A: Y = B
2605 GOTO 2725
2610 PRINT ") LEVEL"; Z
2615 GOTO 1950
2620 IF FL <> 0 GOTO 2650
2625 PRINT "** HEY, BRIGHT ONE, YOU'RE OUT OF FLARES!"
2630 GOTO 1950
2635 REM
2640 REM DISPLAY ADJACENT ROOM CONTENTS WITH FLARE
2645 REM
2650 PRINT
2655 FL = FL - 1
2660 A = X: B = Y
2665 FOR Q1 = A - 1 TO A + 1
2670 X = FNB(Q1)
2675 FOR Q2 = B - 1 TO B + 1
2680 Y = FNB(Q2)
2685 Q = FNE(L(FND(Z)))
2690 L(FND(Z)) = Q
2695 PRINT " "; I$(Q); " ";
2700 NEXT Q2
2705 PRINT
2710 PRINT
2715 NEXT Q1
2720 X = A: Y = B
2725 GOSUB 5570
2730 GOTO 1950
2735 REM
2740 REM DISPLAY CONTENTS OF ADJACENT ROOM WITH LAMP
2745 REM
2750 IF LF <> 0 GOTO 2770
2755 PRINT
2760 PRINT "** YOU DON'T HAVE A LAMP, "; R$(RC); "!"
2765 GOTO 1950
2770 PRINT
2775 PRINT "WHERE DO YOU WANT TO SHINE THE LAMP (N,S,E,W)";
2780 GOSUB 5415
2785 A = X: B = Y
2790 X = FNB(X + (O$ = "N") - (O$ = "S"))
2795 Y = FNB(Y + (O$ = "W") - (O$ = "E"))
2800 IF A - X + B - Y <> 0 GOTO 2820
2805 PRINT
2810 PRINT "** THAT'S NOT A DIRECTION, "; R$(RC); "!"
2815 GOTO 1950
2820 PRINT
2825 PRINT "THE LAMP SHINES INTO ("; X; ","; Y; ") LEVEL"; Z; "."
2830 PRINT
2835 L(FND(Z)) = FNE(L(FND(Z)))
2840 PRINT "THERE YOU WILL FIND "; C$(L(FND(Z))); "."
2845 X = A: Y = B
2850 GOTO 1950
2855 REM
2860 REM TAKE A DRINK FROM A POOL
2865 REM
2870 IF L(FND(Z)) = 5 GOTO 2890
2875 PRINT
2880 PRINT "** IF YOU WANT A DRINK, FIND A POOL!"
2885 GOTO 1950
2890 Q = FNA(8)
2895 PRINT
2900 PRINT "YOU TAKE A DRINK AND ";
2905 IF Q < 7 THEN PRINT "FEEL ";
2910 ON Q GOTO 2915, 2920, 2925, 2930, 2935, 2940, 2945, 2955
2915 ST = FNC(ST + FNA(3)): PRINT "STRONGER.": GOTO 1950
2920 ST = ST - FNA(3): PRINT "WEAKER.": ON (1 - (ST < 1)) GOTO 1950, 4910
2925 IQ = FNC(IQ + FNA(3)): PRINT "SMARTER.": GOTO 1950
2930 IQ = IQ - FNA(3): PRINT "DUMBER.": ON (1 - (IQ < 1)) GOTO 1950, 4910
2935 DX = FNC(DX + FNA(3)): PRINT "NIMBLER.": GOTO 1950
2940 DX = DX - FNA(3): PRINT "CLUMSIER.": ON (1 - (DX < 1)) GOTO 1950, 4910
2945 Q = FNA(4): IF Q = RC GOTO 2945
2950 RC = Q: PRINT "BECOME A "; R$(RC); ".": GOTO 1950
2955 SX = 1 - SX: PRINT "TURN INTO A ";: IF SX = 0 THEN PRINT "FE";
2960 PRINT "MALE "; R$(RC); "!": GOTO 1950
2965 IF L(FND(Z)) <> 6 GOTO 2985
2970 PRINT
2975 PRINT "YOU OPEN THE CHEST AND"
2980 GOTO 3115
2985 IF L(FND(Z)) <> 12 GOTO 3005
2990 PRINT
2995 PRINT "YOU OPEN THE BOOK AND"
3000 GOTO 3020
3005 PRINT
3010 PRINT "** THE ONLY THING OPENED WAS YOUR BIG MOUTH!"
3015 GOTO 1950
3020 ON FNA(6) GOTO 3025, 3040, 3050, 3060, 3075, 3090
3025 PRINT "FLASH! OH NO! YOU ARE NOW A BLIND "; R$(RC); "!"
3030 BL = 1
3035 GOTO 3105
3040 PRINT "IT'S ANOTHER VOLUME OF ZOT'S POETRY! - YECH!!"
3045 GOTO 3105
3050 PRINT "IT'S AN OLD COPY OF PLAY"; R$(FNA(4)); "!"
3055 GOTO 3105
3060 PRINT "IT'S A MANUAL OF DEXTERITY!"
3065 DX = 18
3070 GOTO 3105
3075 PRINT "IT'S A MANUAL OF STRENGTH!"
3080 ST = 18
3085 GOTO 3105
3090 PRINT "THE BOOK STICKS TO YOUR HANDS -"
3095 PRINT "NOW YOU ARE UNABLE TO DRAW YOUR WEAPON!"
3100 BF = 1
3105 L(FND(Z)) = 1
3110 GOTO 1950
3115 ON FNA(4) GOTO 3120, 3140, 3160, 3140
3120 PRINT "KABOOM! IT EXPLODES!!"
3125 Q = FNA(6)
3130 GOSUB 4860
3135 ON (1 - (ST < 1)) GOTO 3105, 4910
3140 Q = FNA(1000)
3145 PRINT "FIND"; Q; "GOLD PIECES!"
3150 GP = GP + Q
3155 GOTO 3105
3160 PRINT "GAS!! YOU STAGGER FROM THE ROOM!"
3165 L(FND(Z)) = 1
3170 T = T + 20
3175 O$ = MID$("NSEW", FNA(4), 1)
3180 GOTO 2440
3185 IF L(FND(Z)) = 11 GOTO 3205
3190 PRINT
3195 PRINT "** IT'S HARD TO GAZE WITHOUT AN ORB!"
3200 GOTO 1950
3205 PRINT
3210 PRINT "YOU SEE ";
3215 ON FNA(6) GOTO 3220, 3230, 3240, 3250, 3285, 3305
3220 PRINT "YOURSELF IN A BLOODY HEAP!"
3225 ST = ST - FNA(2): ON (1 - (ST < 1)) GOTO 1950, 4910
3230 PRINT "YOURSELF DRINKING FROM A POOL AND BECOMING "; C$(12 + FNA(13)); "!"
3235 GOTO 1950
3240 PRINT C$(12 + FNA(13)); " GAZING BACK AT YOU!"
3245 GOTO 1950
3250 A = X: B = Y: C = Z
3255 X = FNA(8): Y = FNA(8): Z = FNA(8)
3260 Q = FNE(L(FND(Z)))
3265 L(FND(Z)) = Q
3270 PRINT C$(Q); " AT ("; X; ","; Y; ") LEVEL"; Z; "."
3275 X = A: Y = B: Z = C
3280 GOTO 1950
3285 A = FNA(8): B = FNA(8): C = FNA(8)
3290 IF FNA(8) < 4 THEN A = O(1): B = O(2): C = O(3)
3295 PRINT "***THE ORB OF ZOT*** AT ("; A; ","; B; ") LEVEL"; C; "!"
3300 GOTO 1950
3305 PRINT "A SOAP OPERA RERUN!"
3310 GOTO 1950
3315 IF RF <> 0 GOTO 3335
3320 PRINT
3325 PRINT "** YOU CAN'T TELEPORT WITHOUT THE RUNESTAFF!"
3330 GOTO 1950
3335 Z$ = "X-COORDINATE"
3340 GOSUB 5485
3345 X = Q
3350 Z$ = "Y-COORDINATE"
3355 GOSUB 5485
3360 Y = Q
3365 Z$ = "Z-COORDINATE"
3370 GOSUB 5485
3375 Z = Q
3380 O$ = "T"
3385 GOTO 3450
3390 PRINT
3395 PRINT "DO YOU REALLY WANT TO QUIT NOW";
3400 GOSUB 5415
3405 PRINT
3410 IF O$ = "Y" GOTO 3425
3415 PRINT "** THEN DON'T SAY THAT YOU DO!"
3420 GOTO 1950
3425 PRINT
3430 GOTO 5030
3435 REM
3440 REM DISPLAY STATUS INFORMATION
3445 REM
3450 PRINT
3455 IF BL = 0 THEN GOSUB 5570: PRINT
3460 PRINT "STRENGTH ="; ST; " INTELLIGENCE ="; IQ; " DEXTERITY ="; DX
3465 PRINT "TREASURES ="; TC; " FLARES ="; FL; " GOLD PIECES ="; GP
3470 PRINT "WEAPON = "; W$(WV + 1); " ARMOR = "; W$(AV + 5);
3475 IF LF = 1 THEN PRINT " AND A LAMP";
3480 PRINT
3485 WC = 0
3490 Q = FNE(L(FND(Z)))
3495 L(FND(Z)) = Q
3500 Z$ = "YOU NOW HAVE"
3505 PRINT
3510 PRINT "HERE YOU FIND "; C$(Q); "."
3515 IF (Q < 7) OR (Q = 11) OR (Q = 12) GOTO 1950
3520 IF Q = 7 THEN GP = GP + FNA(10): PRINT Z$; GP; ".": GOTO 3105
3525 IF Q = 8 THEN FL = FL + FNA(5): PRINT Z$; FL; ".": GOTO 3105
3530 IF Q > 9 GOTO 3545
3535 IF (O(1) = X) AND (O(2) = Y) AND (O(3) = Z) THEN ON (1 - (O$ = "T")) GOTO 2440, 5175
3540 X = FNA(8): Y = FNA(8): Z = FNA(8): GOTO 3450
3545 IF Q = 10 THEN Z = FNB(Z + 1): GOTO 3450
3550 IF Q <= 25 OR Q >= 34 GOTO 3580
3555 PRINT
3560 PRINT "IT'S NOW YOURS!"
3565 T(Q - 25) = 1
3570 TC = TC + 1
3575 GOTO 3105
3580 A = L(FND(Z)) - 12
3585 WC = 0
3590 IF (A < 13) OR (VF = 1) GOTO 4185
3595 PRINT
3600 PRINT "YOU MAY TRADE WITH, ATTACK, OR IGNORE THE VENDOR."
3605 GOSUB 5405
3610 IF O$ = "I" GOTO 1950
3615 IF O$ <> "A" GOTO 3640
3620 VF = 1
3625 PRINT
3630 PRINT "YOU'LL BE SORRY THAT YOU DID THAT!"
3635 GOTO 4185
3640 IF O$ = "T" GOTO 3660
3645 PRINT
3650 PRINT "** NICE SHOT, "; R$(RC); "!"
3655 GOTO 3595
3660 FOR Q = 1 TO 8
3665 A = FNA(Q * 1500)
3670 IF T(Q) = 0 GOTO 3700
3675 PRINT
3680 PRINT "DO YOU WANT TO SELL "; C$(Q + 25); " FOR"; A; "GP'S";
3685 GOSUB 5415
3690 IF O$ = "Y" THEN TC = TC - 1: T(Q) = 0: GP = GP + A: GOTO 3700
3695 IF O$ <> "N" THEN PRINT Y$: GOTO 3675
3700 NEXT Q
3705 IF GP >= 1000 GOTO 3725
3710 PRINT
3715 PRINT "YOU'RE TOO POOR TO TRADE, "; R$(RC); "."
3720 GOTO 1950
3725 IF GP < 1250 GOTO 3975
3730 PRINT
3735 PRINT "OK, "; R$(RC); ", YOU HAVE"; GP; "GP'S AND "; W$(AV + 5); " ARMOR."
3740 PRINT
3745 Z$ = "ARMOR"
3750 GOSUB 5555
3755 PRINT "NOTHING<0> LEATHER<1250> ";
3760 IF GP > 1499 THEN PRINT "CHAINMAIL<1500> ";
3765 IF GP > 1999 THEN PRINT "PLATE<2000>";
3770 PRINT
3775 GOSUB 5405
3780 PRINT
3785 IF O$ = "N" GOTO 3850
3790 IF O$ = "L" THEN GP = GP - 1250: AV = 1: AH = 7: GOTO 3850
3795 IF O$ <> "C" OR GP >= 1500 GOTO 3810
3800 PRINT "** YOU HAVEN'T GOT THAT MUCH CASH ON HAND!"
3805 GOTO 3740
3810 IF O$ = "C" THEN GP = GP - 1500: AV = 2: AH = 14: GOTO 3850
3815 IF O$ <> "P" OR GP >= 2000 GOTO 3830
3820 PRINT "** YOU CAN'T AFFORD PLATE ARMOR!"
3825 GOTO 3740
3830 IF O$ = "P" THEN GP = GP - 2000: AV = 3: AH = 21: GOTO 3850
3835 PRINT
3840 PRINT "** DON'T BE SILLY. CHOOSE A SELECTION."
3845 GOTO 3770
3850 IF GP < 1250 GOTO 3975
3855 PRINT
3860 PRINT "YOU HAVE"; GP; "GP'S LEFT WITH "; W$(WV + 1); " IN HAND."
3865 PRINT
3870 Z$ = "WEAPON"
3875 GOSUB 5555
3880 PRINT "NOTHING<0> DAGGER<1250> ";
3885 IF GP > 1499 THEN PRINT "MACE<1500> ";
3890 IF GP > 1999 THEN PRINT "SWORD<2000>";
3895 PRINT
3900 GOSUB 5405
3905 PRINT
3910 IF O$ = "N" GOTO 3975
3915 IF O$ = "D" THEN GP = GP - 1250: WV = 1: GOTO 3975
3920 IF O$ <> "M" OR GP >= 1500 GOTO 3935
3925 PRINT "** SORRY SIR, I'M AFRAID I DON'T GIVE CREDIT!"
3930 GOTO 3865
3935 IF O$ = "M" THEN GP = GP - 1500: WV = 2: GOTO 3975
3940 IF O$ <> "S" OR GP >= 2000 GOTO 3960
3945 PRINT "** YOUR DUNGEON EXPRESS CARD - ";
3950 PRINT "YOU LEFT HOME WITHOUT IT!"
3955 GOTO 3865
3960 IF O$ = "S" THEN GP = GP - 2000: WV = 3: GOTO 3975
3965 PRINT "** TRY CHOOSING A SELECTION!"
3970 GOTO 3895
3975 IF GP < 1000 GOTO 1950
3980 Z$ = "STRENGTH"
3985 GOSUB 5525
3990 IF O$ <> "Y" GOTO 4020
3995 GP = GP - 1000
4000 ST = FNC(ST + FNA(6))
4005 Q = ST
4010 GOSUB 5540
4015 GOTO 3975
4020 IF O$ <> "N" THEN PRINT Y$: GOTO 3980
4025 IF GP < 1000 GOTO 1950
4030 Z$ = "INTELLIGENCE"
4035 GOSUB 5525
4040 IF O$ <> "Y" GOTO 4070
4045 GP = GP - 1000
4050 IQ = FNC(IQ + FNA(6))
4055 Q = IQ
4060 GOSUB 5540
4065 GOTO 4025
4070 IF O$ <> "N" THEN PRINT Y$: GOTO 4030
4075 IF GP < 1000 GOTO 1950
4080 Z$ = "DEXTERITY"
4085 GOSUB 5525
4090 IF O$ <> "Y" GOTO 4120
4095 GP = GP - 1000
4100 DX = FNC(DX + FNA(6))
4105 Q = DX
4110 GOSUB 5540
4115 GOTO 4075
4120 IF O$ <> "N" THEN PRINT Y$: GOTO 4080
4125 IF (GP < 1000) OR (LF = 1) GOTO 1950
4130 PRINT
4135 PRINT "DO YOU WANT TO BUY A LAMP FOR 1000 GP'S";
4140 GOSUB 5415
4145 IF O$ <> "Y" GOTO 4175
4150 GP = GP - 1000
4155 LF = 1
4160 PRINT
4165 PRINT "IT'S GUARANTEED TO OUTLIVE YOU!"
4170 GOTO 1950
4175 IF O$ <> "N" THEN PRINT Y$: GOTO 4130
4180 GOTO 1950
4185 Q1 = 1 + INT(A / 2): Q2 = A + 2: Q3 = 1
4190 IF (C(1, 4) > T(1)) OR (BL = 1) OR (DX < FNA(9) + FNA(9)) GOTO 4700
4195 PRINT
4200 PRINT "YOU'RE FACING "; C$(A + 12); "!"
4205 PRINT
4210 PRINT "YOU MAY ATTACK OR RETREAT."
4215 IF Q3 = 1 THEN PRINT "YOU CAN ALSO ATTEMPT A BRIBE."
4220 IF IQ > 14 THEN PRINT "YOU CAN ALSO CAST A SPELL."
4225 PRINT
4230 PRINT "YOUR STRENGTH IS"; ST; "AND YOUR DEXTERITY IS"; DX; "."
4235 GOSUB 5405
4240 IF O$ <> "A" GOTO 4445
4245 IF WV <> 0 GOTO 4265
4250 PRINT
4255 PRINT "** POUNDING ON "; C$(A + 12); " WON'T HURT IT!"
4260 GOTO 4700
4265 IF BF <> 1 GOTO 4285
4270 PRINT
4275 PRINT "** YOU CAN'T BEAT IT TO DEATH WITH A BOOK!"
4280 GOTO 4700
4285 IF DX >= FNA(20) + (3 * BL) GOTO 4305
4290 PRINT
4295 PRINT "YOU MISSED, TOO BAD!"
4300 GOTO 4700
4305 Z$ = RIGHT$(C$(A + 12), LEN(C$(A + 12)) - 2)
4310 IF LEFT$(Z$, 1) = " " THEN Z$ = MID$(Z$, 2)
4315 PRINT
4320 PRINT "YOU HIT THE EVIL "; Z$; "!"
4325 Q2 = Q2 - WV
4330 IF (A <> 9 AND A <> 12) GOTO 4355
4335 IF FNA(8) <> 1 GOTO 4355
4340 PRINT
4345 PRINT "OH NO! YOUR "; W$(WV + 1); " BROKE!"
4350 WV = 0
4355 IF Q2 > 0 GOTO 4700
4360 PRINT
4365 MC = MC - 1
4370 PRINT C$(A + 12); " LIES DEAD AT YOUR FEET!"
4375 IF H > T - 60 GOTO 4395
4380 PRINT
4385 PRINT "YOU SPEND AN HOUR EATING "; C$(A + 12); E$(FNA(8)); "."
4390 H = T
4395 IF X <> R(1) OR Y <> R(2) OR Z <> R(3) THEN ON (1 - (A = 13)) GOTO 4420, 5305
4400 PRINT
4405 PRINT "GREAT ZOT! YOU'VE FOUND THE RUNESTAFF!"; CHR$(7)
4410 R(1) = 0
4415 RF = 1
4420 Q = FNA(1000)
4425 PRINT
4430 PRINT "YOU NOW GET HIS HOARD OF"; Q; "GP'S!"
4435 GP = GP + Q
4440 GOTO 3105
4445 IF O$ = "R" GOTO 4700
4450 IF O$ <> "C" GOTO 4595
4455 IF IQ >= 15 OR Q3 <= 1 GOTO 4475
4460 PRINT
4465 PRINT "** YOU CAN'T CAST A SPELL NOW!"
4470 GOTO 4195
4475 PRINT
4480 PRINT "WHICH SPELL (WEB, FIREBALL, DEATHSPELL)";
4485 GOSUB 5415
4490 PRINT
4495 IF O$ <> "W" GOTO 4515
4500 ST = ST - 1
4505 WC = FNA(8) + 1
4510 ON (1 - (ST < 1)) GOTO 4700, 4910
4515 IF O$ <> "F" GOTO 4560
4520 Q = FNA(7) + FNA(7)
4525 ST = ST - 1
4530 IQ = IQ - 1
4535 IF (IQ < 1) OR (ST < 1) GOTO 4910
4540 PRINT "IT DOES"; Q; "POINTS WORTH OF DAMAGE."
4545 PRINT
4550 Q2 = Q2 - Q
4555 GOTO 4355
4560 IF O$ = "D" GOTO 4580
4565 PRINT
4570 PRINT "** TRY ONE OF THE OPTIONS GIVEN."
4575 GOTO 4195
4580 PRINT "DEATH . . . ";
4585 IF IQ < FNA(4) + 15 THEN PRINT "YOURS!": IQ = 0: GOTO 4910
4590 PRINT "HIS!": Q2 = 0: GOTO 4360
4595 IF O$ = "B" AND Q3 <= 1 GOTO 4615
4600 PRINT
4605 PRINT "** CHOOSE ONE OF THE OPTIONS LISTED."
4610 GOTO 4195
4615 IF TC <> 0 GOTO 4635
4620 PRINT
4625 PRINT "ALL I WANT IS YOUR LIFE!"
4630 GOTO 4700
4635 Q = FNA(8)
4640 IF T(Q) = 0 GOTO 4635
4645 PRINT
4650 PRINT "I WANT "; C$(Q + 25); ". WILL YOU GIVE IT TO ME";
4655 GOSUB 5415
4660 IF O$ = "N" GOTO 4700
4665 IF O$ <> "Y" THEN PRINT Y$: GOTO 4645
4670 T(Q) = 0
4675 TC = TC - 1
4680 PRINT
4685 PRINT "OK, JUST DON'T TELL ANYONE ELSE."
4690 VF = VF + (L(FND(Z)) = 25)
4695 GOTO 1950
4700 Q3 = 2
4705 IF WC <= 0 GOTO 4720
4710 WC = WC - 1
4715 IF WC = 0 THEN PRINT: PRINT "THE WEB JUST BROKE!"
4720 Z$ = RIGHT$(C$(A + 12), LEN(C$(A + 12)) - 2)
4725 IF LEFT$(Z$, 1) = " " THEN Z$ = MID$(Z$, 2)
4730 IF WC <= 0 GOTO 4750
4735 PRINT
4740 PRINT "THE "; Z$; " IS STUCK AND CAN'T ATTACK NOW!"
4745 GOTO 4805
4750 PRINT
4755 PRINT "THE "; Z$; " ATTACKS!"
4760 IF DX < FNA(7) + FNA(7) + FNA(7) + 3 * BL GOTO 4780
4765 PRINT
4770 PRINT "WHAT LUCK, HE MISSED YOU!"
4775 GOTO 4805
4780 PRINT
4785 PRINT "OUCH! HE HIT YOU!"
4790 Q = Q1
4795 GOSUB 4860
4800 IF ST < 1 GOTO 4910
4805 IF O$ <> "R" GOTO 4195
4810 PRINT
4815 PRINT "YOU HAVE ESCAPED!"
4820 PRINT
4825 PRINT "DO YOU WANT TO GO NORTH, SOUTH, EAST, OR WEST";
4830 GOSUB 5415
4835 IF O$ = "N" OR O$ = "S" OR O$ = "E" OR O$ = "W" GOTO 2440
4840 PRINT
4845 PRINT "** DON'T PRESS YOUR LUCK, "; R$(RC); "!"
4850 PRINT
4855 GOTO 4825
4860 IF AV = 0 GOTO 4900
4865 Q = Q - AV
4870 AH = AH - AV
4875 IF Q < 0 THEN AH = AH - Q: Q = 0
4880 IF AH >= 0 GOTO 4900
4885 AH = 0: AV = 0
4890 PRINT
4895 PRINT "YOUR ARMOR HAS BEEN DESTROYED . . . GOOD LUCK!"
4900 ST = ST - Q
4905 RETURN
4910 PRINT CHR$(7)
4915 GOSUB 5375
4920 PRINT "A NOBLE EFFORT, OH FORMERLY LIVING "; R$(RC); "!"
4925 PRINT
4930 PRINT "YOU DIED DUE TO LACK OF ";
4935 IF ST < 1 THEN PRINT "STRENGTH."
4940 IF IQ < 1 THEN PRINT "INTELLIGENCE."
4945 IF DX < 1 THEN PRINT "DEXTERITY."
4950 PRINT
4955 Q3 = 1
4960 PRINT "AT THE TIME YOU DIED, YOU HAD :"
4965 GOTO 5055
4970 Q3 = 0
4975 PRINT
4980 PRINT "YOU LEFT THE CASTLE WITH";
4985 IF OF = 0 THEN PRINT "OUT";
4990 PRINT " THE ORB OF ZOT."
4995 PRINT
5000 IF OF = 0 GOTO 5030
5005 PRINT
5010 PRINT "AN INCREDIBLY GLORIOUS VICTORY!!"
5015 PRINT
5020 PRINT "IN ADDITION, YOU GOT OUT WITH THE FOLLOWING :"
5025 GOTO 5050
5030 PRINT
5035 PRINT "A LESS THAN AWE-INSPIRING DEFEAT."
5040 PRINT
5045 PRINT "WHEN YOU LEFT THE CASTLE, YOU HAD :"
5050 IF Q3 = 0 THEN PRINT "YOUR MISERABLE LIFE!"
5055 FOR Q = 1 TO 8
5060 IF T(Q) = 1 THEN PRINT C$(Q + 25)
5065 NEXT Q
5070 PRINT W$(WV + 1); " AND "; W$(AV + 5);
5075 IF LF = 1 THEN PRINT " AND A LAMP";
5080 PRINT
5085 PRINT "YOU ALSO HAD"; FL; "FLARES AND"; GP; "GOLD PIECES"
5090 IF RF = 1 THEN PRINT "AND THE RUNESTAFF"
5095 PRINT
5100 PRINT "AND IT TOOK YOU"; T; "TURNS!"
5105 PRINT
5110 PRINT "ARE YOU FOOLISH ENOUGH TO WANT TO PLAY AGAIN";
5115 GOSUB 5415
5120 PRINT
5125 IF O$ <> "Y" GOTO 5155
5130 PRINT "SOME "; R$(RC); "S NEVER LEARN!"
5135 PRINT
5140 PRINT "PLEASE BE PATIENT WHILE THE CASTLE IS RESTOCKED."
5145 PRINT
5150 GOTO 1105
5155 IF O$ <> "N" THEN PRINT Y$: GOTO 5110
5160 PRINT "MAYBE DUMB "; R$(RC); " IS NOT SO DUMB AFTER ALL!"
5165 PRINT
5170 GOTO 5580
5175 PRINT
5180 PRINT "GREAT UNMITIGATED ZOT!"
5185 PRINT
5190 PRINT "YOU JUST FOUND ***THE ORB OF ZOT***!"
5195 PRINT
5200 PRINT "THE RUNESTAFF HAS DISAPPEARED!"
5205 RF = 0
5210 OF = 1
5215 O(1) = 0
5220 GOTO 3105
5225 DATA AN EMPTY ROOM,.,THE ENTRANCE,E,STAIRS GOING UP,U
5230 DATA STAIRS GOING DOWN,D,A POOL,P,A CHEST,C,GOLD PIECES,G
5235 DATA FLARES,F,A WARP,W,A SINKHOLE,S,A CRYSTAL ORB,O
5240 DATA A BOOK,B,A KOBOLD,M,AN ORC,M,A WOLF,M,A GOBLIN,M,AN OGRE,M
5245 DATA A TROLL,M,A BEAR,M,A MINOTAUR,M,A GARGOYLE,M,A CHIMERA,M
5250 DATA A BALROG,M,A DRAGON,M,A VENDOR,V,THE RUBY RED,T
5255 DATA THE NORN STONE,T,THE PALE PEARL,T,THE OPAL EYE,T
5260 DATA THE GREEN GEM,T,THE BLUE FLAME,T,THE PALANTIR,T,THE SILMARIL,T
5265 DATA X,"?",NO WEAPON," SANDWICH"
5270 DATA DAGGER," STEW",MACE," SOUP",SWORD," BURGER",NO ARMOR," ROAST"
5275 DATA LEATHER," FILET",CHAINMAIL," TACO",PLATE," PIE"
5280 DATA HOBBIT,ELF,MAN,DWARF
5285 X = FNA(8): Y = FNA(8)
5290 IF L(FND(Z)) <> 101 GOTO 5285
5295 L(FND(Z)) = Q
5300 RETURN
5305 PRINT
5310 PRINT "YOU GET ALL HIS WARES :"
5315 PRINT "PLATE ARMOR"
5320 AV = 3: AH = 21
5325 PRINT "A SWORD"
5330 WV = 3
5335 PRINT "A STRENGTH POTION"
5340 ST = FNC(ST + FNA(6))
5345 PRINT "AN INTELLIGENCE POTION"
5350 IQ = FNC(IQ + FNA(6))
5355 PRINT "A DEXTERITY POTION"
5360 DX = FNC(DX + FNA(6))
5365 IF LF = 0 THEN PRINT "A LAMP": LF = 1
5370 GOTO 4420
5375 FOR Q = 1 TO 64
5380 PRINT "*";
5385 NEXT Q
5390 PRINT
5395 PRINT
5400 RETURN
5405 PRINT
5410 PRINT "YOUR CHOICE";
5415 INPUT O$
5420 O$ = LEFT$(O$, 1)
5425 RETURN
5430 PRINT "HOW MANY POINTS DO YOU WISH TO ADD TO YOUR "; Z$;
5435 INPUT O$
5440 PRINT
5445 Q = VAL(O$)
5450 IF Q = 0 AND ASC(O$) <> 48 THEN Q = -1
5455 IF Q < 0 OR Q > OT OR Q <> INT(Q) THEN PRINT "** ";: GOTO 5430
5460 OT = OT - Q
5465 RETURN
5470 INPUT O$
5475 Q = INT(VAL(O$))
5480 RETURN
5485 PRINT
5490 PRINT Z$;
5495 INPUT O$
5500 Q = INT(VAL(O$))
5505 IF Q > 0 AND Q < 9 THEN RETURN
5510 PRINT
5515 PRINT "** TRY A NUMBER FROM 1 TO 8."
5520 GOTO 5485
5525 PRINT
5530 PRINT "DO YOU WANT TO BUY A POTION OF "; Z$; " FOR 1000 GP'S";
5535 GOTO 5415
5540 PRINT
5545 PRINT "YOUR "; Z$; " IS NOW"; Q; "."
5550 RETURN
5555 PRINT
5560 PRINT "THESE ARE THE TYPES OF "; Z$; " YOU CAN BUY :"
5565 RETURN
5570 PRINT "YOU ARE AT ("; X; ","; Y; ") LEVEL"; Z; "."
5575 RETURN
5580 END

FUNCTION FNA (Q)
FNA = 1 + INT(RND(1) * Q)
END FUNCTION
FUNCTION FNB (Q)
FNB = Q + 8 * ((Q = 9) - (Q = 0))
END FUNCTION
FUNCTION FNC (Q)
FNC = -Q * (Q < 19) - 18 * (Q > 18)
END FUNCTION
FUNCTION FND (Q)
SHARED X, Y
FND = 64 * (Q - 1) + 8 * (X - 1) + Y
END FUNCTION
FUNCTION FNE (Q)
FNE = Q + 100 * (Q > 99)
END FUNCTION

Just to showcase how compatible QB64PE is with ancient QBasic code, I translated the above for us. The only change I did?

I turned the native DEF FN statements into actual Functions.

Everything else is still the same as original. Big Grin

Print this item

  Combine Charlies Ghosts with 40 LOC Game
Posted by: bplus - 11-02-2023, 11:59 PM - Forum: Works in Progress - Replies (5)

Here is Charlies cute scrolly ghosts from BAM:
https://basicanywheremachine.neocities.o...s.prod.bas

I modefied this ghost maker into 3subs for drawing ghosts

Code: (Select All)
ghostWidth% = 14
ghostHeight% = 14

ghostBod$ = _
  ".....XXXX....." + _
  "...XXXXXXXX..." + _
  "..XXXXXXXXXX.." + _
  ".XXXXXXXXXXXX." + _
  ".XXXXXXXXXXXX." + _
  ".XXXXXXXXXXXX." + _
  "XXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXX" + _
  "XX.XXX..XXX.XX" + _
  "X...XX..XX...X"
  
ghostEyeballLeft$ = _
  ".............." + _
  ".............." + _
  ".............." + _
  "..XX....XX...." + _
  ".XXXX..XXXX..." + _
  "...XX....XX..." + _
  "...XX....XX..." + _
  "..XX....XX...." + STRING$(6*14,".")
  
ghostEyeballRight$ = _
  ".............." + _
  ".............." + _
  ".............." + _
  "....XX....XX.." + _
  "...XXXX..XXXX." + _
  "...XX....XX..." + _
  "...XX....XX..." + _
  "....XX....XX.." + STRING$(6*14,".")
  
ghostIrisLeft$ = _
  ".............." + _
  ".............." + _
  ".............." + _
  ".............." + _
  ".............." + _
  ".XX....XX....." + _
  ".XX....XX....." + STRING$(7*14,".")
  
ghostIrisRight$ = _
  ".............." + _
  ".............." + _
  ".............." + _
  ".............." + _
  ".............." + _
  ".....XX....XX." + _
  ".....XX....XX." + STRING$(7*14,".")

'??? ??? Main Program ??? ???
  
  SCREEN _NEWIMAGE(300,100,12)
  _ALERT("Click/touch the screen to pause the program.")
  loopCount% = 1
  ➔another_ghost:
      IF loopCount% MOD 3 = 0 THEN _
          ?PrintGhost( _  
              INT(RND*(100)), _
              INT(RND*(_HEIGHT-ghostHeight%)) )
      _DELAY 0.025
      IF _MOUSEBUTTON THEN WHILE _MOUSEBUTTON : WEND
      SCROLL 1,0,FALSE
      loopCount% += 1
  GOTO ➔another_ghost
  END
  
'??? Subroutines ???

SUB ?PrintGhost(x%,y%)
    bodyColor% = INT(RND*14)+1
    eyeDirection% = INT(RND*2)
    ghostEyeball$ = IFF(eyeDirection%,ghostEyeballLeft$,ghostEyeballRight$)
    ghostIris$ = IFF(eyeDirection%,ghostIrisLeft$,ghostIrisRight$)
    irisColor% = IFF(INT(RND*2), 1, 6)
    FOR thisY = 1 TO ghostHeight%
        FOR thisX = 1 TO ghostWidth%
            IF MID$(ghostBod$, (thisY-1) * ghostWidth% + thisX, 1) <> "." THEN PSET (x% + thisX - 1, y% + thisY - 1), bodyColor%
            IF MID$(ghostEyeball$, (thisY-1) * ghostWidth% + thisX, 1) <> "." THEN PSET (x% + thisX - 1, y% + thisY - 1), 15
            IF MID$(ghostIris$, (thisY-1) * ghostWidth% + thisX, 1) <> "." THEN PSET (x% + thisX - 1, y% + thisY - 1), irisColor%
        NEXT thisX
    NEXT thisY
END SUB

40 (with double parking) LOC QB64 Game:
Code: (Select All)
_Title "40 Line Game Revised" 'b+ mod of some game 2022-03-18 new way to score
Dim As Long sw, sh, goalR, hx, hy, i, hits, score, stars, nEnemies
sw = 640: sh = 480: nEnemies = 35: goalR = -1: hx = 10: hy = 400 ' hero stuff (you)
Dim EX(nEnemies), EY(nEnemies), EC(nEnemies) As _Unsigned Long ' enemy stuff
Screen _NewImage(sw, sh, 32): stars = _NewImage(sw, sh, 32)
For i = 1 To 1000
    PSet (Int(Rnd * sw), Int(Rnd * sh)), _RGB32(55 + Rnd * 200, 55 + Rnd * 200, 55 + Rnd * 200)
Next
_PutImage , 0, stars
For i = 1 To nEnemies
    EX(i) = Int(Rnd * (sw - 20) + 10): EY(i) = -2 * sh * Rnd + sh: EC(i) = _RGB32(55 + Rnd * 200, 55 + Rnd * 200, 55 + Rnd * 200)
Next
Do
    Cls
    _PutImage , stars, 0
    Print "Hits:"; hits, "Score:"; score
    Line (hx - 10, hy - 10)-Step(20, 20), &HFFFFFF00, BF
    If hx >= sw - 13 And goalR Then score = score + 100: goalR = 0
    If hx <= 13 And goalR = 0 Then score = score + 100: goalR = -1
    For i = 1 To nEnemies ' the enemies
        Circle (EX(i), EY(i)), 10, EC(i)
        If Sqr((EX(i) - hx) ^ 2 + (EY(i) - hy) ^ 2) < 20 Then 'collision
            Sound 2000, 3: hits = hits + 1
            EX(i) = Int(Rnd * 600 + 20): EY(i) = -_Height * Rnd ' move that bad boy!
            If hits = 10 Then Print "Too many hits, goodbye!": _Delay 10
        End If
        EY(i) = EY(i) + Int(Rnd * 5)
        If EY(i) > 470 Then EX(i) = Int(Rnd * 600 + 20): EY(i) = -sh * Rnd
    Next
    If _KeyDown(20480) Then hy = hy + 3
    If _KeyDown(18432) Then hy = hy - 3
    If _KeyDown(19200) Then hx = hx - 3
    If _KeyDown(19712) Then hx = hx + 3
    If hx < 10 Then hx = 10
    If hx > sw - 10 Then hx = sw - 10
    If hy < 10 Then hy = 10
    If hy > sh - 10 Then hy = sh - 10
    _Display
    _Limit 60
Loop Until _KeyDown(27)

I now have this:
Code: (Select All)
Option _Explicit
_Title "Charlies Ghost plus 40 LOC Game" ' bplus confab mod 2023-11-02
'_Title "40 Line Game Revised" 'b+ mod of some game 2022-03-18 new way to score

Dim Shared As Long SW, SH ' screen width and height
SW = 640: SH = 640

'for setup and drawing ghosts, run SetupGhost once
Dim Shared gWidth%, gHeight%, gBod$, ghostEyeballLeft$, ghostEyeballRight$, ghostIrisLeft$, ghostIrisRight$
SetupGhost

' for creating new ghosts x, y, color, eye direction, eye color
Dim Shared As Long NGhosts
NGhosts = 15
Dim Shared As Long GX(1 To NGhosts), GY(1 To NGhosts), GED(1 To NGhosts), GDIR(1 To NGhosts)
Dim Shared As _Unsigned Long GBC(1 To NGhosts), GIC(1 To NGhosts)

Dim As Long goalR, hx, hy, i, hits, score, stars
Dim rr
goalR = -1
hx = SW / 2 - 14: hy = 28 ' hero stuff (you)
For i = 1 To NGhosts
    NewGhost (i), 0
Next

Screen _NewImage(SW, SH, 32): stars = _NewImage(SW, SH, 32)
Randomize Timer

' test debug drawing ghosts , way too small double width and triple height
'For i = 1 To NGhosts
'    Cls
'    DrawGhost 320 - 14, 240 - 28, GBC(i), GED(i), GIC(i) ' ghosts are 28 x 56
'    Sleep
'Next
'End

'setup stars ?
For i = 1 To 1000
    PSet (Int(Rnd * SW), Int(Rnd * SH)), _RGB32(55 + Rnd * 200, 55 + Rnd * 200, 55 + Rnd * 200)
Next
_PutImage , 0, stars

Do
    Cls
    _PutImage , stars, 0
    Print "Hits:"; hits, "Score:"; score
    Line (hx - 14, hy - 26)-Step(28, 52), &HFFFFAA77, BF

    'door
    Line (hx - 10, hy - 22)-(hx - 2, hy - 2), &HFFCC6633, BF
    Line (hx + 2, hy - 22)-(hx + 10, hy - 2), &HFFCC6633, BF
    Line (hx - 10, hy + 2)-(hx + 10, hy + 22), &HFFCC6633, BF
    For rr = 0 To 2 Step .25
        Circle (hx + 12, hy), rr, _RGB32(255 - rr * 125, 255 - rr * 125, 255 - rr * 125)
    Next
    'score the door
    If hy >= SH - 28 And goalR Then score = score + 100: goalR = 0
    If hy <= 28 And goalR = 0 Then score = score + 100: goalR = -1

    For i = 1 To NGhosts ' the enemies
        If Rnd < .025 Then
            If GED(i) Then GED(i) = 0 Else GED(i) = 1
        End If
        DrawGhost GX(i) - 14, GY(i) - 26, GBC(i), GED(i), GIC(i)
        If Abs(GX(i) - hx) < 28 And Abs(GY(i) - hy) < 56 Then 'collision
            Sound 38, 5, , , 2
            hits = hits + 1
            NewGhost i, 1 ' move that bad boy!
            If hits = 10 Then
                Print "Too many hits, goodbye!"
                _Display
                _Delay 10
                End
            End If
        End If
        GX(i) = GX(i) + GDIR(i) * Int(Rnd * 5)
        If (GX(i) > SW + 14 And GDIR(i) > 0) Or (GX(i) < -14 And GDIR(i) < 0) Then
            NewGhost i, 1
        End If
    Next
    If _KeyDown(20480) Then hy = hy + 3
    If _KeyDown(18432) Then hy = hy - 3
    If _KeyDown(19200) Then hx = hx - 3
    If _KeyDown(19712) Then hx = hx + 3
    If hx < 14 Then hx = 14
    If hx > SW - 14 Then hx = SW - 14
    If hy < 26 Then hy = 26
    If hy > SH - 26 Then hy = SH - 26
    _Display
    _Limit 60
Loop Until _KeyDown(27)

Sub NewGhost (i As Long, beyondScreenTF As Long)
    ' a ghost needs a starting place leave safe zone on either edge
    If Rnd < .5 Then GDIR(i) = -1 Else GDIR(i) = 1
    If beyondScreenTF Then
        If GDIR(i) > 0 Then
            GX(i) = -SW * Rnd - 14
        Else
            GX(i) = SW + SW * Rnd + 14
        End If
    Else
        GX(i) = SW * Rnd
    End If
    GY(i) = 56 + 28 + Int((SH - 3 * 56) * Rnd)

    ' a ghost needs a body color
    GBC(i) = _RGB32(155 + Rnd * 100, 155 + Rnd * 100, 155 + Rnd * 100, 80)

    ' a ghost needs an eyedirection
    GED(i) = Int(Rnd * 2)

    ' a ghost needs an iris color
    If Int(Rnd * 2) Then GIC~&(i) = _RGB32(255, 0, 0) Else GIC~&(i) = _RGB32(0, 0, 255)

End Sub

Sub DrawGhost (x%, y%, ghostBodyC~&, EyeDir%, IrisC~&) ' make ghost 28 x 56
    Dim gEyeBall$, gIris$
    Dim As Long yy, xx
    'gEyeball$ = IFF(EyeDir%,ghostEyeballLeft$,ghostEyeballRight$)
    If EyeDir% Then gEyeBall$ = ghostEyeballLeft$ Else gEyeBall$ = ghostEyeballRight$

    'gIris$ = IFF(EyeDir%,ghostIrisLeft$,ghostIrisRight$)
    If EyeDir% Then gIris$ = ghostIrisLeft$ Else gIris$ = ghostIrisRight$

    'irisC~& = IFF(Int(Rnd * 2), 1, 6)

    For yy = 1 To gHeight%
        For xx = 1 To gWidth%
            If Mid$(gBod$, (yy - 1) * gWidth% + xx, 1) <> "." Then
                'PSet (x% + XX - 1, y% + YY - 1), bodyC~&
                Line (x% + (xx - 1) * 2, y% + (yy - 1) * 4)-Step(1, 3), ghostBodyC~&, BF
            End If
            If Mid$(gEyeBall$, (yy - 1) * gWidth% + xx, 1) <> "." Then
                'PSet (x% + XX - 1, y% + YY - 1), _RGB32(255, 255, 255)
                Line (x% + (xx - 1) * 2, y% + (yy - 1) * 3)-Step(1, 2), _RGB32(255, 255, 255), BF
            End If
            If Mid$(gIris$, (yy - 1) * gWidth% + xx, 1) <> "." Then
                'PSet (x% + XX - 1, y% + YY - 1), IrisC~&
                Line (x% + (xx - 1) * 2, y% + (yy - 1) * 3)-Step(1, 2), IrisC~&, BF
            End If
        Next xx
    Next yy
End Sub


Sub SetupGhost
    ' setup shared variables in main, this sub sets the values for them
    'dim shared gWidth%, gHeight%, gBod$, ghostEyeballLeft$, ghostEyeballRight$, ghostIrisLeft$, ghostIrisRight$

    gWidth% = 14
    gHeight% = 14

gBod$ = _
  ".....XXXX....." + _
  "...XXXXXXXX..." + _
  "..XXXXXXXXXX.." + _
  ".XXXXXXXXXXXX." + _
  ".XXXXXXXXXXXX." + _
  ".XXXXXXXXXXXX." + _
  "XXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXX" + _
  "XX.XXX..XXX.XX" + _
  "X...XX..XX...X"

ghostEyeballLeft$ = _
  ".............." + _
  ".............." + _
  ".............." + _
  "..XX....XX...." + _
  ".XXXX..XXXX..." + _
  "...XX....XX..." + _
  "...XX....XX..." + _
  "..XX....XX...." + STRING$(6*14,".")

ghostEyeballRight$ = _
  ".............." + _
  ".............." + _
  ".............." + _
  "....XX....XX.." + _
  "...XXXX..XXXX." + _
  "...XX....XX..." + _
  "...XX....XX..." + _
  "....XX....XX.." + STRING$(6*14,".")

ghostIrisLeft$ = _
  ".............." + _
  ".............." + _
  ".............." + _
  ".............." + _
  ".............." + _
  ".XX....XX....." + _
  ".XX....XX....." + STRING$(7*14,".")

ghostIrisRight$ = _
  ".............." + _
  ".............." + _
  ".............." + _
  ".............." + _
  ".............." + _
  ".....XX....XX." + _
  ".....XX....XX." + STRING$(7*14,".")

End Sub

   

The object is to go from bottom of screen to top or vice versa without running into a ghost, 100 points for every trek, see how many points you can rack up before 10 hits.
ie you don't want any ghosts knocking on your door! ;-))

Print this item

  detecting multitouch touchscreen input (screen taps, buttons, slider bars) ?
Posted by: madscijr - 11-02-2023, 05:40 PM - Forum: General Discussion - Replies (1)

I don't expect this is currently possible, but figured it can't hurt to ask... 
Is this supported in QB64PE or doable via some API hack? 

I'm thinking of applications like 

- input for multiplayer games, e.g. a pong game where each player has a zone of the screen such as top/bottom/left/right edges or top left/top right/bottom left/bottom right quadrants. If we detect a screen press in a given quadrant we use that to reposition the associated player.

- input for musical instruments, e.g. a simple synth with an onscreen keyboard, but also slider controls to bend notes, change various sound parameters, buttons to change waveform, etc., all in realtime and simultaneously. (And later when QB64PE gets multi-channel audio, polyphony.)

I've never done any kind of programming for multitouch input, but multitouch screens are common enough nowadays that I would think there is pretty standard OS level support for them?

Print this item

  QBJS another bplus port
Posted by: bplus - 11-02-2023, 02:09 AM - Forum: QBJS, BAM, and Other BASICs - No Replies

Decorated Skull

Print this item

  _SCREENMOVE _MIDDLE and resolutions
Posted by: NakedApe - 11-01-2023, 10:39 PM - Forum: Help Me! - Replies (14)

Howdy. I want a program to run at 1600x900 on desktops and 1280x720 or 1280x800 on laptops. That seems straightforward enough, but this sub - at the big resolution so far - doesn't actually center the program window on the desktop. Why is _SCREENMOVE _MIDDLE opening this window far to the right and off-screen? Also any suggestions for improving this resolution changing sub will be gladly and humbly accepted. Thanks! Ted
' ------------------------------------------------------------------------------
SUB resolution () '                     first attempt at resolution changer
    '                                             I want 1600x900 on larger screens else 1280x720 or 1280x800 on smaller
    DIM ratio AS SINGLE
  
    IF _DESKTOPWIDTH > 1750 THEN SWIDTH = 1600 ELSE SWIDTH = 1280
    ratio = _DESKTOPWIDTH / _DESKTOPHEIGHT

    IF ratio = 1.6 THEN '               8:5 aspect ratio - 13" macBook
        SHEIGHT = SWIDTH / ratio
    ELSE SHEIGHT = SWIDTH / 1.777 '     16:9 aspect ratio
    END IF

    CLS
    PRINT "Screen Width is"; SWIDTH
    PRINT "Screen Height is"; SHEIGHT
    PRINT "Aspect Ratio is"; ratio;
    _DELAY 3

    SCREEN _NEWIMAGE(SWIDTH, SHEIGHT, 32)

    IF SWIDTH = 1280 THEN '                     laptop mode in fullscreen
        _FULLSCREEN , _SMOOTH
        IF _FULLSCREEN = 0 THEN '               on fullscreen error
            BEEP: CLS
            _FULLSCREEN _OFF
            PRINT "Fullscreen failed. Going native. Press a key."
            SLEEP
            _SCREENMOVE _MIDDLE
        END IF
    END IF

    IF SWIDTH = 1600 THEN _SCREENMOVE _MIDDLE '        I put this here after the SCREEN statement, but it still doesn't center the program window

    CenterX = SWIDTH / 2 '                define screen center points
    CenterY = SHEIGHT / 2 '
END SUB
' ----------------------------------------------------------------------

Print this item

  It might be useful for something
Posted by: MasterGy - 11-01-2023, 10:14 AM - Forum: Programs - Replies (6)

Hello !

A 3D game is being made. For this, it was necessary to write some subprograms.

It can be useful if you want to use it for something.

The program checks whether two segments intersect.



Code: (Select All)

Screen _NewImage(800, 600, 32)

Do
    Cls

    x1 = 800 * Rnd
    y1 = 600 * Rnd

    x2 = 800 * Rnd
    y2 = 600 * Rnd

    x3 = 800 * Rnd
    y3 = 600 * Rnd

    x4 = 800 * Rnd
    y4 = 600 * Rnd

    Color _RGB32(255, 255, 255)
    Locate 1, 1: Print "SPACE to next"


    If IsIntersection(x1, y1, x2, y2, x3, y3, x4, y4) Then
        Color _RGB32(255, 50, 50)
        Locate 3, 10: Print "Intersect !"
    End If



    Line (x1, y1)-(x2, y2)
    Line (x3, y3)-(x4, y4)


    Do: Loop Until InKey$ = " "
Loop


Function IsIntersection (X1, Y1, X2, Y2, X3, Y3, X4, Y4)
    Denominator = (Y4 - Y3) * (X2 - X1) - (X4 - X3) * (Y2 - Y1)
    If Denominator = 0 Then
        IsIntersection = 0
    Else
        Ua = ((X4 - X3) * (Y1 - Y3) - (Y4 - Y3) * (X1 - X3)) / Denominator
        Ub = ((X2 - X1) * (Y1 - Y3) - (Y2 - Y1) * (X1 - X3)) / Denominator
        If Ua >= 0 And Ua <= 1 And Ub >= 0 And Ub <= 1 Then IsIntersection = 1 Else IsIntersection = 0
    End If
End Function





Creates a surface from arbitrary points arranged in a plane. First it forms sections, and then triangles from the sections.
In this code there is a function 'PointInTriangle' which returns TRUE if a point XY is inside a triangle bounded by points X1Y1X2Y2X3Y3.

Code: (Select All)

Randomize Timer
mon = _NewImage(1000, 400, 32)
Screen mon
marg = 50

pontok = 10 'how many points
Dim p(pontok - 1, 2)



For t = 0 To pontok - 1
    p(t, 0) = marg + (_Width - marg * 2) * Rnd
    p(t, 1) = marg + (_Height - marg * 2) * Rnd
    Circle (p(t, 0), p(t, 1)), 7
Next t
Locate 1, 1: Print "points:"; pontok, "Press SPACE to next"


Do: Loop Until InKey$ = " "
Cls
Dim sz(99999, 3)

Do: changing = 0
    For t1 = 0 To pontok - 1


        For t = 0 To pontok - 1: p(t, 2) = 1: Next t
        qq = 0: cdis = 1800 ^ 2
        Do: kovi = 0

            find = -1: mindis = 9999999
            For t = 0 To pontok - 1: If t = t1 Or p(t, 2) = 0 Then _Continue
                disx = p(t, 0) - p(t1, 0): If disx > cdis Then _Continue
                disy = p(t, 1) - p(t1, 1): If disy > cdis Then _Continue
                dis = (disx * disx + disy * disy): If dis > cdis Then _Continue
                If dis < mindis Then mindis = dis: find = t
            Next t


            If find <> -1 Then
                p(find, 2) = 0

                If szc > 0 Then
                    For asz = 0 To szc - 1
                        If (sz(asz, 0) = find And sz(asz, 1) = t1) Or (sz(asz, 0) = t1 And sz(asz, 1) = find) Then kovi = 1: Exit For
                    Next asz


                    If kovi = 0 Then
                        For asz = 0 To szc - 1
                            If (t1 = sz(asz, 0) Or t1 = sz(asz, 1)) = 0 And (find = sz(asz, 0) Or find = sz(asz, 1)) = 0 Then
                                If IsIntersection(p(t1, 0), p(t1, 1), p(find, 0), p(find, 1), p(sz(asz, 0), 0), p(sz(asz, 0), 1), p(sz(asz, 1), 0), p(sz(asz, 1), 1)) Then kovi = 1: Exit For
                            End If
                        Next asz
                    End If
                End If
                If kovi = 0 Then
                    sz(szc, 0) = t1: sz(szc, 1) = find: changing = 1
                    Line (p(sz(szc, 0), 0), p(sz(szc, 0), 1))-(p(sz(szc, 1), 0), p(sz(szc, 1), 1))
                    szc = szc + 1
                    Locate 1, 1: Print "szakaszok:"; szc
                End If
            Else kovi = 0
            End If

        Loop While kovi

    Next t1

Loop While changing
Locate 2, 1: Print "Press SPACE to next"
Do: Loop Until InKey$ = " "


'make triangles
Dim tri(9999, 3)
For s1 = 0 To szc - 1: v(0) = sz(s1, 0): v(1) = sz(s1, 1)
    For s2 = 0 To szc - 1: v(2) = sz(s2, 0): v(3) = sz(s2, 1)
        For s3 = 0 To szc - 1: v(4) = sz(s3, 0): v(5) = sz(s3, 1)
            For t = 0 To 5: ind(t, 1) = -1: Next t: ic = 0: For t1 = 0 To 5: n = 0: For t2 = 0 To 5
                If ind(t2, 0) = v(t1) And ind(t2, 1) <> -1 Then ind(t2, 1) = ind(t2, 1) + 1: n = 1
                Next t2: If n = 0 Then ind(ic, 0) = v(t1): ind(ic, 1) = 1: ic = ic + 1
            Next t1

            If ic = 3 And ind(0, 1) = 2 And ind(1, 1) = 2 And ind(2, 1) = 2 Then
                sort ind(0, 0), ind(1, 0), ind(2, 0)
                ok = 1
                For t = 0 To tr_c - 1
                    If ind(0, 0) = tri(t, 0) And ind(1, 0) = tri(t, 1) And ind(2, 0) = tri(t, 2) Then ok = 0
                Next t

                If ok Then
                    For t = 0 To pontok - 1
                        If t = ind(0, 0) Or t = ind(1, 0) Or t = ind(2, 0) Then _Continue
                        '                        If Abs(p(t, 0) - p(ind(0, 0), 0)) > n Then _Continue
                        '                      If Abs(p(t, 0) - p(ind(0, 0), 0)) > n Then _Continue



                        If PointInTriangle(p(t, 0), p(t, 1), p(ind(0, 0), 0), p(ind(0, 0), 1), p(ind(1, 0), 0), p(ind(1, 0), 1), p(ind(2, 0), 0), p(ind(2, 0), 1)) Then ok = 0: Exit For
                    Next t
                End If

                If ok Then tri(tr_c, 0) = ind(0, 0): tri(tr_c, 1) = ind(1, 0): tri(tr_c, 2) = ind(2, 0): tr_c = tr_c + 1
            End If

Next s3, s2, s1
Cls
Print "triangles:"; tr_c


'    If InKey$ = " " Then q = (q + 1) Mod tr_c
For t = 0 To tr_c - 1
    Color _RGB32(255, 255, 255)
    '        If q = t Then Color _RGB32(255 * Rnd, 255 * Rnd, 255 * Rnd)

    'Print tri(t, 0), tri(t, 1), tri(t, 2)

    Line (p(tri(t, 0), 0), p(tri(t, 0), 1))-(p(tri(t, 1), 0), p(tri(t, 1), 1))
    Line (p(tri(t, 0), 0), p(tri(t, 0), 1))-(p(tri(t, 2), 0), p(tri(t, 2), 1))
    Line (p(tri(t, 2), 0), p(tri(t, 2), 1))-(p(tri(t, 1), 0), p(tri(t, 1), 1))


    x = (p(tri(t, 0), 0) + p(tri(t, 1), 0) + p(tri(t, 2), 0)) / 3
    y = (p(tri(t, 0), 1) + p(tri(t, 1), 1) + p(tri(t, 2), 1)) / 3
    Color _RGB32(255 * Rnd, 255 * Rnd, 255 * Rnd)
    Paint (x, y), , _RGB32(255, 255, 255)
    'Circle (x, y), 20 ', _RGB32(255, 255, 255)
Next t








Function IsIntersection (X1, Y1, X2, Y2, X3, Y3, X4, Y4)
    Denominator = (Y4 - Y3) * (X2 - X1) - (X4 - X3) * (Y2 - Y1)
    If Denominator = 0 Then
        IsIntersection = 0
    Else
        Ua = ((X4 - X3) * (Y1 - Y3) - (Y4 - Y3) * (X1 - X3)) / Denominator
        Ub = ((X2 - X1) * (Y1 - Y3) - (Y2 - Y1) * (X1 - X3)) / Denominator
        IsIntersection = Ua >= 0 And Ua <= 1 And Ub >= 0 And Ub <= 1
    End If
End Function

Function PointInTriangle (X, Y, X1, Y1, X2, Y2, X3, Y3)
    D1 = (X - X2) * (Y1 - Y2) - (X1 - X2) * (Y - Y2)
    D2 = (X - X3) * (Y2 - Y3) - (X2 - X3) * (Y - Y3)
    D3 = (X - X1) * (Y3 - Y1) - (X3 - X1) * (Y - Y1)
    PointInTriangle = (D1 > 0 And D2 > 0 And D3 > 0) Or (D1 < 0 And D2 < 0 And D3 < 0)
End Function

Sub sort (a, b, c)
    If a > c Then Swap a, c
    If b > c Then Swap b, c
    If a > b Then Swap a, b
End Sub

Print this item

  Dia de la Muertos
Posted by: James D Jarvis - 10-31-2023, 06:25 PM - Forum: Programs - Replies (3)

Code: (Select All)
'Dia de los Muertos
'adapted from a  conversion by Paul Dunn  of an original by Bazzargh
'$dynamic
Dim S(0), C(0)
Dim klr As _Unsigned Long
Screen _NewImage(800, 600, 32)
Window (-852, -600)-(852, 416)
Do
    klr = _RGB32(255, 0, 0)
    Cls
    k = 360
    ReDim S(k + 1), C(k + 1)
    kv = 220 + r(35)
    For i = 0 To k
        t = i * 2 * _Pi / k
        S(i) = Sin(t)
        C(i) = Cos(t)
        circleBF 0, -i / 2, k * .8, _RGB32(kv, kv, kv)
    Next i
    circleBF 0, 0, k, _RGB32(kv, kv, kv)
    circleBF 120, -60, 80, _RGB32(1, 1, 1)
    circleBF -120, -60, 80, _RGB32(1, 1, 1)


    u = 120: v = -60: d = 2: n = 7: a = 70
    For j = 1 To r(30) + 10 '40

        For t = 0 To k * 2
            z = a * C(((t * n) / d) Mod k)
            x = u + z * C(t Mod k)
            y = v + z * S(t Mod k)
            e = x * x
            rr = Sqr(e + y * y)
            f = y + k
            g = Sqr(e + f * f)
            l = y + 60
            i = x - 120
            h = Sqr(e + f * f)
            If (g < 220 Or rr < k) And (rr <= 380 Or rr <= k) And (rr <= 360 Or rr > 480 Or Abs(x) >= 160 Or Abs(x Mod 32) <= 4 Or rr Mod 48 <= 4) And (j <= 1 Or h >= 90) And (y < -300 Or y >= -150 Or -x * 2 - y >= 180) Then
                circleBF x, y, 2, klr
                circleBF -x, y, 2, klr
            End If
        Next t
        d = r(3): n = r(5) + 2: a = r(80) + 50: u = r(k): v = r(940) - 520
        kv = r(121)
        klr = _RGB32(kv, kv, kv)
    Next j
    Do
        _Limit 60
        kk$ = InKey$
    Loop Until kk$ <> ""
Loop Until kk$ = Chr$(27)




Function r (i)
    r = Int(1 + Rnd * i)
End Function
Sub circleBF (cx As Long, cy As Long, rad As Long, klr As _Unsigned Long)
    rsqrd = rad * rad
    y = -rad
    While y <= rad
        x = Sqr(rsqrd - y * y)
        Line (cx - x, cy + y)-(cx + x, cy + y), klr, BF
        y = y + 1
    Wend
End Sub

Print this item

  Ternary operator
Posted by: Kernelpanic - 10-30-2023, 09:57 PM - Forum: General Discussion - Replies (8)

Can one also integrate the declaration of a library into a function?
The reason for the question is that I wrote a small program that allows one to use the tenary operator from C. If you could put the whole thing into a function, it might be useful for Basic. Maybe.  Huh

The Basic-Program:

Code: (Select All)

'Aufruf des tenaeren Operators in C - 30. Okt. 2023

Option _Explicit

'In QB64 mit "Declare Library" wie angegeben
Declare Library "D:\Lab\QuickBasic64\Extern-nicht-Basic\C-Aufruf\tenaerOp"
  Function tenaerOp& (ByVal N As Long, Byval X As Long)
End Declare

Dim As Long N, X

X = 77

Locate 3, 3
Input "Zahl: ", N

Locate 5, 3
Print Using "Ausgabe: ###"; tenaerOp&(N&, X&)

End

The C part:
Code: (Select All)
//TenaerenOperator von Basic aufrufen - 30. Okt. 2023

#include <stdio.h>
#include <stdlib.h>

long tenaerOp(long eingabe, long x)
{
    long ausgabe;
        
    ausgabe = x > eingabe ? 100 : 200;
    return(ausgabe);    
}

Print this item

  Variable height jump demo
Posted by: TerryRitchie - 10-30-2023, 06:27 PM - Forum: Programs - No Replies

I ran across some javascript code (link at top of code below) that shows how to do a dead simple variable height jump. It's much simpler than the methods I have been using over the years.

Click the mouse inside the window to initiate a jump.
The longer the mouse button is held the higher the jump.

Code: (Select All)
'
' Variable height jump demo
'
' Based on code found at: https://jsfiddle.net/LyM87/
'
' Click the mouse inside the window.
' The longer the mouse button is held the higher the jump.
' Press ESC to exit the program.
'
TYPE BoxTYPE
    positionX AS SINGLE ' x location of box
    positionY AS SINGLE ' y location of box
    velocityX AS SINGLE ' horizontal velocity of box
    velocityY AS SINGLE ' vertical velocity of box
    onGround AS INTEGER ' box on ground (-1 yes, 0 no)
END TYPE

DIM Box AS BoxTYPE '      the box
DIM gravity AS SINGLE '   amount of gravity

Box.positionX = 100 '                                   set initial start values
Box.positionY = 175
Box.velocityX = 4
Box.velocityY = 0
Box.onGround = -1
gravity = .5
SCREEN _NEWIMAGE(200, 200, 32) '                        graphics csreen
DO '                                                    begin main loop

    '+---------------------------------+
    '| Initiate a variable height jump |
    '+---------------------------------+

    WHILE _MOUSEINPUT: WEND '                           get latest mouse update
    IF _MOUSEBUTTON(1) THEN '                           is mouse button down? (start jump)
        IF Box.onGround THEN '                          yes, is box on the ground?
            Box.velocityY = -12 '                       yes, add vertical velocity
            Box.onGround = 0 '                          box is now off the ground
        END IF
    ELSE '                                              no, mouse button has been released (end jump)
        IF Box.velocityY < -6 THEN '                    is vertical velocity above -6?
            Box.velocityY = -6 '                        yes, limit vertical velocity to -6
        END IF
    END IF

    '+---------------------+
    '| Update box position |
    '+---------------------+

    Box.velocityY = Box.velocityY + gravity '           add positive value to vertical velocity
    Box.positionY = Box.positionY + Box.velocityY '     add vertical velocity to box current y location
    Box.positionX = Box.positionX + Box.velocityX '     add horizontal velocity to box current x location
    IF Box.positionY > 175 THEN '                       has box gone below ground?
        Box.positionY = 175 '                           yes, place box on ground
        Box.velocityY = 0 '                             remove vertical velocity
        Box.onGround = -1 '                             box is now on the ground
    END IF
    IF Box.positionX < 10 OR Box.positionX > 190 THEN ' has box reached either side of screen?
        Box.velocityX = -Box.velocityX '                yes, reverse horizontal velocity
    END IF

    '+----------------------------+
    '| Render screen with changes |
    '+----------------------------+

    _LIMIT 30 '                                         30 frames per second
    CLS '                                               clear screen
    LINE (0, 175)-(200, 175) '                          draw ground line
    LINE (Box.positionX - 10, Box.positionY - 20)-(Box.positionX + 10, Box.positionY), , B ' draw box
    _DISPLAY '                                          update screen with changes
LOOP UNTIL _KEYDOWN(27) '                               leave when ESC pressed
SYSTEM '                                                return to OS

Print this item