# Re: walk through matrix: textmode 3d (someone else's)

February 28 2006 at 2:08 AM
Forum Owner

Response to Re: walk through matrix: textmode 3d (someone else's)

'this is that program asked to mac to post on the forum.
'before he saw a lot of garbled text... he's gotta see "the matrix" :)

'for mac et. al, there is now a classic "[b]lue pill" mode- just hit B when program starts.

'this code now runs (much more slowly) in both qb and fb.
'fb is 32bit, so the POKE statements and the DEF SEG were a problem. fixed.

' Ascii Ray Caster with texture mapping
' Using Integer Mathematics for speed
'(modified to look more like matrix)

'modifications for 32bit compatibility are based on this 16bit demo by michael calkins:
'>to change the poke stuff to locate print
'
''DEFINT A-Z
'
''NumOfColumnsPerLine is usually 40 or 80
''LineNum is usually 0 to 24, 0 to 42, or 0 to 49
''ColumnNum is usually 0 to 39 or 0 to 79
'
''blinking is either 0 or -1
''foreground is 0 to 15
''background is 0 to 7
'
'ColorAttrib = foreground OR (background * 16) OR (blinking AND 128)
'
'DEF SEG = &HB800
'
'address = ((LineNum * NumOfColumnsPerLine) + ColumnNum) * 2

DEFINT A-Z: DIM l(16, 16), c(360), s(360), t(16, 16)
FOR y = 1 TO 16
FOR x = 1 TO 16
l(x, y) = VAL(MID\$(l\$, x, 1))
NEXT x
NEXT y
FOR y = 1 TO 16
FOR x = 1 TO 16
t(x - 1, y) = VAL(MID\$(l\$, x, 1))
NEXT x
NEXT y

FOR n = 0 TO 360
s(n) = 100 * SIN(22 / 7 * n / 180)
c(n) = 100 * COS(22 / 7 * n / 180)
NEXT n

CLS
PRINT
PRINT " [b] for blue pill / any other key for red pill": q\$ = INPUT\$(1)
IF LCASE\$(q\$) = "b" THEN classic = 1
q\$ = INKEY\$

x = 5600: y = 4000: f = 0: SCREEN 0: WIDTH 80, 50

main:
'WAIT &H3DA, 8 'removes choppy refresh in graphics in qb, MIGHT still be useful, taking out for now.
FOR s2 = -40 TO 39
r = f + (s2 * 60 \ 80): r = r + 360 * ((r > 360) - (r < 0))
r = r - (c(r) = 0): xi = c(r): yi = s(r): x1 = x: y1 = y:
wallcheck:
x1 = x1 + xi: y1 = y1 + yi
IF l(x1 \ 1600, y1 \ 1600) = 0 THEN GOTO wallcheck

xint = ABS(x1 - INT((x1 + 800) \ 1600) * 1600)
yint = ABS(y1 - INT((y1 + 800) \ 1600) * 1600)
IF xint > yint THEN tc = (x1 - (((x1 \ 1600)) * 1600)) \ 100
IF yint > xint THEN tc = (y1 - (((y1 \ 1600)) * 1600)) \ 100

d = (ABS((x - x1) \ c(r)) * c(ABS(r - f))) * .01
h = (69 * 16 \ d) \ 2

FOR ys = 0 TO 49

COLOR 15

IF ys > 25 - h AND ys < 25 + h THEN

'DUH!
brick = t(tc, INT(ys - (25 - h)) / (h * 2) * 16)
IF classic <> 0 THEN
brick = brick + ABS(brick = 0) * 8
brick = brick + ABS(brick = 2) * 4
END IF
COLOR brick

END IF

IF ys > 24 + h THEN COLOR 2 + 8 * INT(RND * 2): IF classic THEN COLOR 2
IF ys <= 26 - h THEN COLOR 2 + 8 * INT(RND * 2): IF classic THEN COLOR 9

e = e + 1: IF e > 80 THEN e = 1
LOCATE ys + 1, INT(s2 / 1) + 41: PRINT CHR\$(219 - ABS(classic = 0) * INT(RND * 200));

NEXT ys
NEXT s2

q\$ = CHR\$(254) + q\$: k = ASC(MID\$(q\$, LEN(q\$), 1)): f = f + 5 * (k = 75) - 5 * (k = 77)
f = f - 355 * (f = -5) + 360 * (f = 365)
dx = c(f) * (-(k = 72) + (k = 80)): dy = s(f) * (-(k = 72) + (k = 80))
IF l((x + dx) \ 1600, (y + dy) \ 1600) = 0 THEN x = x + dx: y = y + dy
IF INSTR(SPACE\$(1) + CHR\$(27) + "q" + "Q", CHR\$(k)) > 0 THEN SYSTEM ELSE q\$ = INKEY\$: IF q\$ <> CHR\$(27) THEN GOTO main

DATA "1111111111111111"
DATA "1000010000010011"
DATA "1000000111110001"
DATA "1000010010000001"
DATA "1111111010000001"
DATA "1000001011101111"
DATA "1000001000000001"
DATA "1000000011100001"
DATA "1000001010000001"
DATA "1111111011100111"
DATA "1000001000000001"
DATA "1000101101001001"
DATA "1000000101011101"
DATA "1001000000001001"
DATA "1000000100000001"
DATA "1111111111111111"

DATA "0222222202222222"
DATA "0222222202222222"
DATA "0222222202222222"
DATA "0000000000000000"
DATA "2222022222220222"
DATA "2222022222220222"
DATA "2222022222220222"
DATA "0000000000000000"
DATA "0222222202222222"
DATA "0222222202222222"
DATA "0222222202222222"
DATA "0000000000000000"
DATA "2222022222220222"
DATA "2222022222220222"
DATA "2222022222220222"
DATA "0000000000000000"

 Respond to this message

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums