Post by atomose on Sept 4, 2022 14:29:10 GMT -5
Hi, i would like to know if you have any ideas to improve the main loop, graphics without picture or more possibilities (make a green land, blue sky, clouds etc...)
MY CODE HERE :
ORIGINAL CODE HERE :
MY CODE HERE :
NOMAINWIN
DIM sintable(360)
DIM costable(360)
DIM map$(10)
DIM color$(10)
color$(1)="lightgray"
color$(2)="brown"
color$(3)="red"
color$(4)="darkred"
color$(5)="darkgray"
color$(6)="darkpink"
color$(7)="blue"
color$(8)="darkblue"
color$(9)="cyan"
color$(10)="white"
map$(1) = "111111111111111111"
map$(2) = "100000000000000001"
map$(3) = "100000050000000001"
map$(4) = "105505550000500001"
map$(5) = "105005000000000001"
map$(6) = "105055000000005001"
map$(7) = "100005500000005001"
map$(8) = "155005500050005001"
map$(9) = "155000000000000001"
map$(10)= "111111111111111111"
FOR i = 0 TO 360
sintable(i) = (sin(i * 0.0174)) * 100
NEXT i
FOR i = 0 TO 360
costable(i) = (cos(i * 0.0174)) * 100
NEXT i
WindowHeight=500 : WindowWidth=635
UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
global dy,dx
STATICTEXT #win.1, "use ZQSD/WASD or arrows for moove AND use ''escape'' for exit",150,465,500,30
GRAPHICBOX #win.g 5, 5, 624, 445
OPEN "fps" FOR window_popup AS #win
PRINT #win, "trapclose [quit]"
PRINT #win.g, "setfocus;fill blue"
print #win.1, "!font Times New Roman 9"
posx=22 : posy=22 : angle=0
[raycast]
dy = 0 : dx = 0
call readJStick 1
select case dx
case 1
angle = angle + 7
case -1
angle = (angle + 353) mod 360
case 2
goto [quit]
end select
select case dy
case 1
if (t-62)>0 then
bx = posx - (sintable(((t-62) mod 360)) / 50)
by = posy - (costable(((t-62) mod 360)) / 50)
k = ASC(MID$(map$(int(by/10)),int(bx/10),1))-48
IF k = 0 THEN
posx = posx - (sintable(((t-62) mod 360)) / 50)
posy = posy - (costable(((t-62) mod 360)) / 50)
END IF
end if
case -1
if (t-62)>0 then
bx = posx + (sintable(((t-62) mod 360)) / 50)
by = posy + (costable(((t-62) mod 360)) / 50)
k = ASC(MID$(map$(int(by/10)),int(bx/10),1))-48
IF k = 0 THEN
posx = posx + (sintable(((t-62) mod 360)) / 50)
posy = posy + (costable(((t-62) mod 360)) / 50)
END IF
end if
end select
[raycast2]
dx = 0 : dy = 0
FOR t = angle TO (angle + 124) step 1
xb = sintable(t mod 360) / 360 'nombre angle (augmente résolution avec profondeur + hauteur)
yb = costable(t mod 360) / 360
bx = posx
by = posy
l = 0
do
bx = bx + xb
by = by + yb
l = l + 0.3 ' profondeur
k = ASC(MID$(map$(int(by/10)),int(bx/10),1))-48
LOOP UNTIL (k > 0)
x = (t - angle) * 5 : dd = (1000 / l)
PRINT #win.g, "down"
PRINT #win.g, "place ";x;" ";(100-dd)
PRINT #win.g, "color ";color$(k);"; backcolor ";color$(k)
PRINT #win.g, "boxfilled ";(x+5);" ";(100+dd)
PRINT #win.g, "color ";color$(10);"; backcolor ";color$(10)
PRINT #win.g, "boxfilled ";(x+5);" 0"
PRINT #win.g, "place ";x;" ";(100+dd)
PRINT #win.g, "boxfilled ";(x+5);" 445"
PRINT #win.g, "place ";x;" ";(100-dd)
'optional
PRINT #win.g, "color black"
PRINT #win.g, "goto ";(x+5);" ";(100-dd)
PRINT #win.g, "place ";x;" ";(100+dd)
PRINT #win.g, "goto ";(x+5);" ";(100+dd)
'optional 2
PRINT #win.g, "color lightgray"
PRINT #win.g, "place ";x;" ";(100+dd)
PRINT #win.g, "goto ";x;" ";(100+(dd/0.35))
PRINT #win.g, "up"
NEXT t
goto [raycast]
function GetAsyncKeyState(key)
calldll #user32, "GetAsyncKeyState",key as long,GetAsyncKeyState as long
if GetAsyncKeyState<>0 then GetAsyncKeyState=1
end function
sub readJStick n
if GetAsyncKeyState(_VK_ESCAPE) then dx = 2
if (GetAsyncKeyState(asc("Z")) or GetAsyncKeyState(_VK_UP)) AND (GetAsyncKeyState(asc("Q")) or GetAsyncKeyState(_VK_LEFT)) then dy = -1 : dx = -1
if (GetAsyncKeyState(asc("Z")) or GetAsyncKeyState(_VK_UP)) AND (GetAsyncKeyState(asc("D")) or GetAsyncKeyState(_VK_RIGHT)) then dy = -1 : dx = 1
if GetAsyncKeyState(asc("Z")) or GetAsyncKeyState(_VK_UP) then dy = -1
if GetAsyncKeyState(asc("W")) or GetAsyncKeyState(_VK_UP) then dy = -1
if GetAsyncKeyState(asc("S")) or GetAsyncKeyState(_VK_DOWN) then dy = 1
if GetAsyncKeyState(asc("Q")) or GetAsyncKeyState(_VK_LEFT) then dx = -1
if GetAsyncKeyState(asc("A")) or GetAsyncKeyState(_VK_LEFT) then dx = -1
if GetAsyncKeyState(asc("D")) or GetAsyncKeyState(_VK_RIGHT) then dx = 1
end sub
[quit]
CONFIRM "Do you really want to quit?"; answer$
IF answer$="no" THEN GOTO [raycast]
CLOSE #win : END
ORIGINAL CODE HERE :
DIM sintable(360)
DIM costable(360)
DIM map$(10)
DIM color$(10)
'color table
color$(1)="yellow"
color$(2)="brown"
color$(3)="red"
color$(4)="darkred"
color$(5)="pink"
color$(6)="darkpink"
color$(7)="blue"
color$(8)="darkblue"
color$(9)="cyan"
color$(10)="white"
'map definitions
map$(1) = "1919191919"
map$(2) = "9000000001"
map$(3) = "1000000409"
map$(4) = "9010005001"
map$(5) = "1020040009"
map$(6) = "9030000001"
map$(7) = "1000078009"
map$(8) = "9050087001"
map$(9) = "1060000009"
map$(10)= "9191919191"
'trigonometric tables
FOR i = 0 TO 360
sintable(i) = (sin(i * 0.0174)) * 100
NEXT i
FOR i = 0 TO 360
costable(i) = (cos(i * 0.0174)) * 100
NEXT i
'create window
NOMAINWIN
WindowHeight=260
WindowWidth=320
msg$="Press 'z' to turn left, 'x' to turn right and SPACE to move forward."
STATICTEXT #win, msg$,5,210,300,105
GRAPHICBOX #win.g 5, 5, 300, 205
OPEN "JB Raytaster" FOR window_nf AS #win
PRINT #win, "trapclose [quit]"
PRINT #win.g, "setfocus"
PRINT #win.g, "when characterInput [keypressed]"
posx=22 'px
posy=22 'py
angle=0 'sa
wait
[raycast]
FOR t = angle TO (angle + 59) step 1
xb = sintable(t mod 360) / 100
yb = costable(t mod 360) / 100
bx = posx
by = posy
l = 0
do
bx = bx + xb
by = by + yb
l = l + 1
k = ASC(MID$(map$(int(by/10)),int(bx/10),1))-48
LOOP UNTIL (k > 0)
x = (t - angle) * 5
dd = (1000 / l)
PRINT #win.g, "down"
PRINT #win.g, "place ";x;" ";(100-dd)
PRINT #win.g, "color ";color$(k);"; backcolor ";color$(k)
PRINT #win.g, "boxfilled ";(x+5);" ";(100+dd)
PRINT #win.g, "color ";color$(10);"; backcolor ";color$(10)
PRINT #win.g, "boxfilled ";(x+5);" 0"
PRINT #win.g, "place ";x;" ";(100+dd)
PRINT #win.g, "boxfilled ";(x+5);" 205"
PRINT #win.g, "place ";x;" ";(100-dd)
PRINT #win.g, "color black"
PRINT #win.g, "goto ";(x+5);" ";(100-dd)
PRINT #win.g, "place ";x;" ";(100+dd)
PRINT #win.g, "goto ";(x+5);" ";(100+dd)
PRINT #win.g, "up"
NEXT t
WAIT
[keypressed]
key$ = RIGHT$(UPPER$(Inkey$), 1)
SELECT CASE key$
CASE CHR$(_VK_RIGHT)
angle = angle + 3
CASE CHR$(_VK_LEFT)
angle = (angle + 357) mod 360
CASE CHR$(_VK_UP)
if (t-30)>0 then
bx = posx + (sintable(((t-30) mod 360)) / 50)
by = posy + (costable(((t-30) mod 360)) / 50)
k = ASC(MID$(map$(int(by/10)),int(bx/10),1))-48
IF k = 0 THEN
posx = posx + (sintable(((t-30) mod 360)) / 50)
posy = posy + (costable(((t-30) mod 360)) / 50)
END IF
end if
CASE CHR$(_VK_DOWN)
if (t-30)>0 then
bx = posx - (sintable(((t-30) mod 360)) / 50)
by = posy - (costable(((t-30) mod 360)) / 50)
k = ASC(MID$(map$(int(by/10)),int(bx/10),1))-48
IF k = 0 THEN
posx = posx - (sintable(((t-30) mod 360)) / 50)
posy = posy - (costable(((t-30) mod 360)) / 50)
END IF
end if
END SELECT
GOTO [raycast]
[quit]
CONFIRM "Do you really want to quit?"; answer$
IF answer$="no" THEN GOTO [raycast]
CLOSE #win
END