' [youtube]https://www.youtube.com/watch?v=gYRrGTC7GtA[/youtube]
mapX = 8
mapY = 8
mapS = 64
Init
drawMap2D
drawRays2D
DrawPlayer
Buttons
dist
= SQR((bx
- ax
) * (bx
- ax
) + (by
- ay
) * (by
- ay
))
ra = pa - DR * 30
IF ra
< 0 THEN ra
= ra
+ 2 * PI
IF ra
> 2 * PI
THEN ra
= ra
- 2 * PI
'--- Check Horizontal Lines ---
dof = 0
disH = 1000000
hx = px
hy = py
'ry = ((INT(py) / 64) * 64) - .0001
ry
= INT(py
/ 64) * 64 - .0001
rx = (py - ry) * aTan + px
yo = -64
xo = -yo * aTan
'ry = ((INT(py) / 64) * 64) + 64
ry
= INT(py
/ 64) * 64 + 64
rx = (py - ry) * aTan + px
yo = 64
xo = -yo * aTan
rx = px
ry = py
dof = 8
'mx = INT(rx) / 64
'my = INT(ry) / 64
mp = my * mapX + mx
'LOCATE 1, 1: PRINT mp; pa;
'_DISPLAY
'IF (mp < mapX * mapY) AND map(mp) = 1 THEN ' -- hit wall
hx = rx
hy = ry
disH = dist(px, py, hx, hy, ra)
dof = 8
rx = rx + xo
ry = ry + yo
dof = dof + 1
'--- Check Vertical Lines ---
dof = 0
disV = 1000000
vx = px
vy = py
'ry = ((INT(py) / 64) * 64) - .0001
rx
= INT(px
/ 64) * 64 - .0001
ry = (px - rx) * nTan + py
xo = -64
yo = -xo * nTan
'ry = ((INT(py) / 64) * 64) + 64
rx
= INT(px
/ 64) * 64 + 64
ry = (px - rx) * nTan + py
xo = 64
yo = -xo * nTan
rx = px
ry = py
dof = 8
'mx = INT(rx) / 64
'my = INT(ry) / 64
mp = my * mapX + mx
'LOCATE 1, 1: PRINT mp; pa;
'_DISPLAY
'IF (mp < mapX * mapY) AND map(mp) = 1 THEN ' -- hit wall
vx = rx
vy = ry
disV = dist(px, py, vx, vy, ra)
dof = 8
rx = rx + xo
ry = ry + yo
dof = dof + 1
IF disV
< disH
THEN ' -- Vertical wall hit rx = vx
ry = vy
disTT = disV
clr = RED
IF disH
< disV
THEN ' -- Horizontal wall hit rx = hx
ry = hy
disTT = disH
clr = DARKRED
LINE (px
, py
)-(rx
, ry
), RED
'--- Draw 3D Walls ---
ca = pa - ra
IF ca
< 0 THEN ca
= ca
+ 2 * PI
IF ca
> 2 * PI
THEN ca
= ca
- 2 * PI
disTT
= disTT
* COS(ca
) ' -- fix fish eye
lineH = mapS * 320 / disTT
IF lineH
> 320 THEN lineH
= 320 ' -- Line height lineO = 160 - lineH / 2 ' -- Line offset
LINE (r
* 8 + 530 - 4, lineO
)-(r
* 8 + 530 + 4, lineH
+ lineO
), clr
, BF
ra = ra + DR
IF ra
< 0 THEN ra
= ra
+ 2 * PI
IF ra
> 2 * PI
THEN ra
= ra
- 2 * PI
IF map
(y
* mapX
+ x
) = 1 THEN clr
= WHITE
ELSE clr
= BLACK
xo = x * mapS
yo = y * mapS
LINE (xo
+ 1, yo
+ 1)-(xo
+ mapS
- 1, yo
+ mapS
- 1), clr
, BF
pa = pa - .1
IF pa
< 0 THEN pa
= pa
+ 2 * PI
pa = pa + .1
IF pa
> 2 * PI
THEN pa
= pa
- 2 * PI
LINE (px
- 4, py
- 4)-(px
+ 4, py
+ 4), YELLOW
, BF
LINE (px
, py
)-(px
+ pdx
* 5, py
+ pdy
* 5), YELLOW
px = 300
py = 300